diff --git a/sources/main_node_cli.c b/sources/main_node_cli.c index 4f9937a4f4ef81dd1d4e5a000e214c96923f9a42..5b26d71e4bdc234ae5874c1ff0c9d911223adccb 100755 --- a/sources/main_node_cli.c +++ b/sources/main_node_cli.c @@ -183,7 +183,7 @@ int main(int argc, const char * argv[]) if(!cparam) { printf("Can't connected to kelvin-node\n"); - exit(0); + exit(-1); } /*{ printf("start node_cli_post_command()\n"); diff --git a/sources/main_node_cli_net.c b/sources/main_node_cli_net.c index 472c9b48e740468f3223e4e3fabb383227b0343c..65a87bd7d5137be7b09594886c2f4a7310156601 100755 --- a/sources/main_node_cli_net.c +++ b/sources/main_node_cli_net.c @@ -1,6 +1,7 @@ /* * Authors: * Dmitriy A. Gearasimov <kahovski@gmail.com> + * Alexander Lysikov <alexander.lysikov@demlabs.net> * DeM Labs Inc. https://demlabs.net * DeM Labs Open source community https://github.com/demlabsinc * Copyright (c) 2017-2019 @@ -30,6 +31,7 @@ #include <assert.h> #include <sys/socket.h> #include "dap_common.h" +#include "dap_strfuncs.h" #include "dap_chain_node_cli.h" // for UNIX_SOCKET_FILE #include "main_node_cli_net.h" @@ -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); - if(post_data) - ret = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data); // data for POST request - 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 - // sending request and receiving the http page (filling cmd) - //printf("cmd='%s'\n", cmd->cmd_name); - ret = curl_easy_perform(curl); // curl_easy_send - //printf("res=%s(err_code=%d) ret='%s'\n", (!ret) ? "OK" : "Err", ret, (cmd->cmd_res) ? cmd->cmd_res : "-"); - if(ret != CURLE_OK) - printf("Error (err_code=%d)\n", ret); - printf("%s\n", (cmd->cmd_res) ? cmd->cmd_res : "no response"); - DAP_DELETE(post_data); - return ret; - //} - //else - // printf("%s\n", "no parameters"); - return -1; + add_mem_data((uint8_t**) &post_data, &post_data_len, "\r\n\r\n", 4); + if (post_data) + ret = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data); // data for POST request + 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 + // sending request and receiving the http page (filling cmd) + //printf("cmd='%s'\n", cmd->cmd_name); + ret = curl_easy_perform(curl); // curl_easy_send + + if (ret != CURLE_OK) { + printf("Error (err_code=%d)\n", ret); + exit(-1); + } + int l_err_code = -1; + if (cmd->cmd_res) { + char **l_str = dap_strsplit(cmd->cmd_res, "\r\n", 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) @@ -185,4 +198,5 @@ int node_cli_desconnect(connect_param *param) } curl_global_cleanup(); + return 0; }