Skip to content
Snippets Groups Projects
Commit 43ab6e8c authored by alexander.lysikov's avatar alexander.lysikov
Browse files

added receiving the return code from command and function exit(ret_code)

parent 39eaec16
No related branches found
No related tags found
No related merge requests found
...@@ -183,7 +183,7 @@ int main(int argc, const char * argv[]) ...@@ -183,7 +183,7 @@ int main(int argc, const char * argv[])
if(!cparam) if(!cparam)
{ {
printf("Can't connected to kelvin-node\n"); printf("Can't connected to kelvin-node\n");
exit(0); exit(-1);
} }
/*{ /*{
printf("start node_cli_post_command()\n"); printf("start node_cli_post_command()\n");
......
/* /*
* Authors: * Authors:
* Dmitriy A. Gearasimov <kahovski@gmail.com> * Dmitriy A. Gearasimov <kahovski@gmail.com>
* Alexander Lysikov <alexander.lysikov@demlabs.net>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc * DeM Labs Open source community https://github.com/demlabsinc
* Copyright (c) 2017-2019 * Copyright (c) 2017-2019
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
#include <assert.h> #include <assert.h>
#include <sys/socket.h> #include <sys/socket.h>
#include "dap_common.h" #include "dap_common.h"
#include "dap_strfuncs.h"
#include "dap_chain_node_cli.h" // for UNIX_SOCKET_FILE #include "dap_chain_node_cli.h" // for UNIX_SOCKET_FILE
#include "main_node_cli_net.h" #include "main_node_cli_net.h"
...@@ -156,24 +158,35 @@ int node_cli_post_command(connect_param *conn, cmd_state *cmd) ...@@ -156,24 +158,35 @@ int node_cli_post_command(connect_param *conn, cmd_state *cmd)
} }
} }
} }
add_mem_data((uint8_t**) &post_data, &post_data_len, "\r\n\r\n", 4); add_mem_data((uint8_t**) &post_data, &post_data_len, "\r\n\r\n", 4);
if(post_data) if (post_data)
ret = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data); // data for POST request ret = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data); // data for POST request
if(post_data_len >= 0) if (post_data_len >= 0)
ret = curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long )post_data_len); // if need a lot to send: CURLOPT_POSTFIELDSIZE_LARGE ret = curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,
// sending request and receiving the http page (filling cmd) (long )post_data_len); // if need a lot to send: CURLOPT_POSTFIELDSIZE_LARGE
//printf("cmd='%s'\n", cmd->cmd_name); // sending request and receiving the http page (filling cmd)
ret = curl_easy_perform(curl); // curl_easy_send //printf("cmd='%s'\n", cmd->cmd_name);
//printf("res=%s(err_code=%d) ret='%s'\n", (!ret) ? "OK" : "Err", ret, (cmd->cmd_res) ? cmd->cmd_res : "-"); ret = curl_easy_perform(curl); // curl_easy_send
if(ret != CURLE_OK)
printf("Error (err_code=%d)\n", ret); if (ret != CURLE_OK) {
printf("%s\n", (cmd->cmd_res) ? cmd->cmd_res : "no response"); printf("Error (err_code=%d)\n", ret);
DAP_DELETE(post_data); exit(-1);
return ret; }
//} int l_err_code = -1;
//else if (cmd->cmd_res) {
// printf("%s\n", "no parameters"); char **l_str = dap_strsplit(cmd->cmd_res, "\r\n", 1);
return -1; int l_cnt = dap_str_countv(l_str);
char *l_str_reply = NULL;
if (l_cnt == 2) {
l_err_code = strtol(l_str[0], NULL, 10);
l_str_reply = l_str[1];
}
printf("%s\n", (l_str_reply) ? l_str_reply : "no response");
dap_strfreev(l_str);
}
DAP_DELETE(post_data);
exit(l_err_code);
return 0;
} }
int node_cli_desconnect(connect_param *param) int node_cli_desconnect(connect_param *param)
...@@ -185,4 +198,5 @@ int node_cli_desconnect(connect_param *param) ...@@ -185,4 +198,5 @@ int node_cli_desconnect(connect_param *param)
} }
curl_global_cleanup(); curl_global_cleanup();
return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment