diff --git a/dap_chain_net.c b/dap_chain_net.c index dda95d6c0558a47d40d55235942922723b9a9402..32304a2eb8cef1ff80400504638c456fe76ce8da 100644 --- a/dap_chain_net.c +++ b/dap_chain_net.c @@ -127,7 +127,7 @@ static void s_net_proc_kill( dap_chain_net_t * a_net ); static void s_gbd_history_callback_notify (void * a_arg,const char a_op_code, const char * a_prefix, const char * a_group, const char * a_key, const void * a_value, const size_t a_value_len); -static int s_cli_net(int argc, const char ** argv, char **str_reply); +static int s_cli_net(int argc, char ** argv, char **str_reply); static bool s_seed_mode = false; /** @@ -667,7 +667,7 @@ int dap_chain_net_init() * @param str_reply * @return */ -static int s_cli_net(int argc, const char ** argv, char **a_str_reply) +static int s_cli_net(int argc, char ** argv, char **a_str_reply) { int arg_index=1; dap_chain_net_t * l_net; @@ -720,11 +720,11 @@ static int s_cli_net(int argc, const char ** argv, char **a_str_reply) time_t l_ts_now = time(NULL); l_ts_now -= strtol( l_prev_sec_str, NULL,10 ); localtime_r(&l_ts_now, &l_from_tm ); - }else if ( l_from_str == NULL ){ // If not set '-from' we set up current time minus 10 seconds + }/*else if ( l_from_str == NULL ){ // If not set '-from' we set up current time minus 10 seconds time_t l_ts_now = time(NULL); l_ts_now -= 10; localtime_r(&l_ts_now, &l_from_tm ); - } + }*/ // Form timestamps from/to time_t l_from_ts = mktime(&l_from_tm); diff --git a/dap_chain_node_cli.c b/dap_chain_node_cli.c index 4764281feb0d0bb49672e5dee44f42719488ac27..a65be2bba8258c573e80b3100f96c5b938ba79d7 100644 --- a/dap_chain_node_cli.c +++ b/dap_chain_node_cli.c @@ -232,7 +232,6 @@ static void* thread_one_client_func(void *args) int str_len, marker = 0; int timeout = 5000; // 5 sec - char **argv = NULL; int argc = 0; dap_list_t *cmd_param_list = NULL; while(1) @@ -291,16 +290,18 @@ static void* thread_one_client_func(void *args) log_it(L_INFO, "execute command=%s", str_cmd); // exec command - char **argv = dap_strsplit(str_cmd, ";", -1); + char **l_argv = dap_strsplit(str_cmd, ";", -1); // Call the command function - if(l_cmd && l_cmd->func) - res = (*(l_cmd->func))(argc, (const char **) argv, &str_reply); - else { + if(l_cmd && l_argv && l_cmd->func) + res = (*(l_cmd->func))(argc, l_argv, &str_reply); + else if (l_cmd){ + log_it(L_WARNING,"NULL arguments for input for command \"%s\"", str_cmd); + }else { log_it(L_WARNING,"No function for command \"%s\" but it registred?!", str_cmd); } // find '-verbose' command - l_verbose = dap_chain_node_cli_find_option_val(argv, 1, argc, "-verbose", NULL); - dap_strfreev(argv); + l_verbose = dap_chain_node_cli_find_option_val(l_argv, 1, argc, "-verbose", NULL); + dap_strfreev(l_argv); } else { str_reply = dap_strdup_printf("can't recognize command=%s", str_cmd); log_it(L_ERROR, str_reply); @@ -385,16 +386,17 @@ void dap_chain_node_cli_set_reply_text(char **str_reply, const char *str, ...) * * return index of string in argv, or 0 if not found */ -int dap_chain_node_cli_find_option_val(const char** argv, int arg_start, int arg_end, const char *opt_name, const char **opt_value) +int dap_chain_node_cli_find_option_val( char** argv, int arg_start, int arg_end, const char *opt_name, const char **opt_value) { int arg_index = arg_start; const char *arg_string; while(arg_index < arg_end) { - arg_string = argv[arg_index]; + char * l_argv_cur = argv[arg_index]; + arg_string = l_argv_cur; // find opt_name - if(arg_string && opt_name && !strcmp(arg_string, opt_name)) { + if(arg_string && opt_name && arg_string[0] && opt_name[0] && !strcmp(arg_string, opt_name)) { // find opt_value if(opt_value) { arg_string = argv[++arg_index]; diff --git a/dap_chain_node_cli.h b/dap_chain_node_cli.h index f41b637254e1a356306010738f4e3f4df4e07ceb..327819df15239d63e64893c60a6ca082e834b9e9 100644 --- a/dap_chain_node_cli.h +++ b/dap_chain_node_cli.h @@ -31,7 +31,7 @@ #define UNIX_SOCKET_FILE "/opt/kelvin-node/var/run/node_cli.sock" //#define UNIX_SOCKET_FILE "/var/run/node_cli.sock" -typedef int cmdfunc_t(int argc, const char ** argv, char **str_reply); +typedef int cmdfunc_t(int argc, char ** argv, char **str_reply); typedef struct dap_chain_node_cmd_item{ char name[32]; /* User printable name of the function. */ @@ -51,7 +51,7 @@ void dap_chain_node_cli_cmd_item_create(const char * a_name, cmdfunc_t *a_func, void dap_chain_node_cli_set_reply_text(char **str_reply, const char *str, ...); -int dap_chain_node_cli_find_option_val(const char** argv, int arg_start, int arg_end, const char *opt_name, const char **opt_value); +int dap_chain_node_cli_find_option_val( char** argv, int arg_start, int arg_end, const char *opt_name, const char **opt_value); /** diff --git a/dap_chain_node_cli_cmd.c b/dap_chain_node_cli_cmd.c index ae697a231196ea3fa478af65d5ecdf1ada659a82..03a711d720cff58d9ea10b040ae46f0d9eb489ea 100644 --- a/dap_chain_node_cli_cmd.c +++ b/dap_chain_node_cli_cmd.c @@ -546,7 +546,7 @@ static int node_info_dump_with_reply(dap_chain_net_t * a_net, dap_chain_node_add * * return 0 OK, -1 Err */ -int com_global_db(int a_argc, const char ** a_argv, char **a_str_reply) +int com_global_db(int a_argc, char ** a_argv, char **a_str_reply) { enum { CMD_NONE, CMD_ADD, CMD_DEL, CMD_LINK }; @@ -652,7 +652,7 @@ int com_global_db(int a_argc, const char ** a_argv, char **a_str_reply) /** * Node command */ -int com_node(int a_argc, const char ** a_argv, char **a_str_reply) +int com_node(int a_argc, char ** a_argv, char **a_str_reply) { enum { CMD_NONE, CMD_ALIAS, CMD_HANDSHAKE, CMD_CONNECT , CMD_DUMP @@ -849,7 +849,7 @@ int com_node(int a_argc, const char ** a_argv, char **a_str_reply) if(alias_str && !l_node_addr.uint64) { dap_chain_node_addr_t *address_tmp = dap_chain_node_addr_get_by_alias(l_net,alias_str); if(address_tmp) { - memcpy(&l_node_addr, address_tmp, sizeof(address_tmp)); + memcpy(&l_node_addr, address_tmp, sizeof(*address_tmp)); DAP_DELETE(address_tmp); } else { @@ -909,7 +909,7 @@ int com_node(int a_argc, const char ** a_argv, char **a_str_reply) * * return 0 OK, -1 Err */ -int com_traceroute(int argc, const char** argv, char **str_reply) +int com_traceroute(int argc, char** argv, char **str_reply) { const char *addr = NULL; int hops = 0, time_usec = 0; @@ -985,7 +985,7 @@ int com_traceroute(int argc, const char** argv, char **str_reply) * * return 0 OK, -1 Err */ -int com_tracepath(int argc, const char** argv, char **str_reply) +int com_tracepath(int argc, char** argv, char **str_reply) { const char *addr = NULL; int hops = 0, time_usec = 0; @@ -1056,7 +1056,7 @@ int com_tracepath(int argc, const char** argv, char **str_reply) * * return 0 OK, -1 Err */ -int com_ping(int argc, const char** argv, char **str_reply) +int com_ping(int argc, char** argv, char **str_reply) { int n = 4; if(argc < 2) { @@ -1112,7 +1112,7 @@ int com_ping(int argc, const char** argv, char **str_reply) /** * Help command */ -int com_help(int argc, const char ** argv, char **str_reply) +int com_help(int argc, char ** argv, char **str_reply) { if(argc > 1) { log_it(L_DEBUG, "Help for command %s", argv[1]); @@ -1148,7 +1148,7 @@ int com_help(int argc, const char ** argv, char **str_reply) * * Wallet info */ -int com_tx_wallet(int argc, const char ** argv, char **str_reply) +int com_tx_wallet(int argc, char ** argv, char **str_reply) { const char *c_wallets_path = dap_config_get_item_str(g_config, "general", "wallets_path"); // Get address of wallet @@ -1317,7 +1317,7 @@ int com_tx_wallet(int argc, const char ** argv, char **str_reply) * @param l_net * @return */ -int dap_chain_node_cli_cmd_values_parse_net_chain(int *a_arg_index, int argc, const char ** argv, char ** a_str_reply, +int dap_chain_node_cli_cmd_values_parse_net_chain(int *a_arg_index, int argc, char ** argv, char ** a_str_reply, dap_chain_t ** a_chain, dap_chain_net_t ** a_net) { const char * l_chain_str = NULL; @@ -1365,7 +1365,7 @@ int dap_chain_node_cli_cmd_values_parse_net_chain(int *a_arg_index, int argc, co * @param str_reply * @return */ -int com_token_decl_sign(int argc, const char ** argv, char ** a_str_reply) +int com_token_decl_sign(int argc, char ** argv, char ** a_str_reply) { int arg_index = 1; @@ -1538,7 +1538,7 @@ int com_token_decl_sign(int argc, const char ** argv, char ** a_str_reply) * @param str_reply * @return */ -int com_mempool_list(int argc, const char ** argv, char ** a_str_reply) +int com_mempool_list(int argc, char ** argv, char ** a_str_reply) { int arg_index = 1; dap_chain_t * l_chain = NULL; @@ -1585,7 +1585,7 @@ int com_mempool_list(int argc, const char ** argv, char ** a_str_reply) * @param a_str_reply * @return */ -int com_mempool_delete(int argc, const char ** argv, char ** a_str_reply) +int com_mempool_delete(int argc, char ** argv, char ** a_str_reply) { int arg_index = 1; dap_chain_t * l_chain = NULL; @@ -1627,7 +1627,7 @@ int com_mempool_delete(int argc, const char ** argv, char ** a_str_reply) * @param a_str_reply * @return */ -int com_mempool_proc(int argc, const char ** argv, char ** a_str_reply) +int com_mempool_proc(int argc, char ** argv, char ** a_str_reply) { int arg_index = 1; dap_chain_t * l_chain; @@ -1678,7 +1678,7 @@ int com_mempool_proc(int argc, const char ** argv, char ** a_str_reply) * @param str_reply * @return */ -int com_token_decl(int argc, const char ** argv, char ** str_reply) +int com_token_decl(int argc, char ** argv, char ** str_reply) { int arg_index = 1; const char *str_tmp = NULL; @@ -1841,7 +1841,7 @@ int com_token_decl(int argc, const char ** argv, char ** str_reply) * @param str_reply * @return */ -int com_token_emit(int argc, const char ** argv, char ** str_reply) +int com_token_emit(int argc, char ** argv, char ** str_reply) { int arg_index = 1; const char *str_tmp = NULL; @@ -2075,7 +2075,7 @@ int com_token_emit(int argc, const char ** argv, char ** str_reply) * * Create transaction */ -int com_tx_cond_create(int argc, const char ** argv, char **str_reply) +int com_tx_cond_create(int argc, char ** argv, char **str_reply) { (void) argc; // test @@ -2123,7 +2123,7 @@ int com_tx_cond_create(int argc, const char ** argv, char **str_reply) * * Create transaction */ -int com_tx_create(int argc, const char ** argv, char **str_reply) +int com_tx_create(int argc, char ** argv, char **str_reply) { int arg_index = 1; int cmd_num = 1; @@ -2231,11 +2231,9 @@ int com_tx_create(int argc, const char ** argv, char **str_reply) dap_string_append_printf(string_ret, "transfer=%s\n", (res == 0) ? "Ok" : (res == -2) ? "False, not enough funds for transfer" : "False"); - char *str_ret_tmp = dap_string_free(string_ret, false); - char *str_ret = strdup(str_ret_tmp); - dap_chain_node_cli_set_reply_text(str_reply, str_ret); + dap_chain_node_cli_set_reply_text(str_reply, string_ret->str); + dap_string_free(string_ret, false); - DAP_DELETE(str_ret_tmp); DAP_DELETE(addr_to); DAP_DELETE(addr_fee); dap_chain_wallet_close(l_wallet); @@ -2247,7 +2245,7 @@ int com_tx_create(int argc, const char ** argv, char **str_reply) * * Verifing transaction */ -int com_tx_verify(int argc, const char ** argv, char **str_reply) +int com_tx_verify(int argc, char ** argv, char **str_reply) { if(argc > 1) { if(str_reply) @@ -2264,7 +2262,7 @@ int com_tx_verify(int argc, const char ** argv, char **str_reply) * Print log info * print_log [ts_after <timestamp >] [limit <line numbers>] */ -int com_print_log(int argc, const char ** argv, char **str_reply) +int com_print_log(int argc, char ** argv, char **str_reply) { int arg_index = 1; const char * l_str_ts_after = NULL; diff --git a/dap_chain_node_cli_cmd.h b/dap_chain_node_cli_cmd.h index 6066504b2027af2751fff27d585d92041d8e00e7..aa650f4018da9216e44625538ca5df03224cfd6f 100644 --- a/dap_chain_node_cli_cmd.h +++ b/dap_chain_node_cli_cmd.h @@ -38,60 +38,60 @@ dap_chain_node_addr_t* dap_chain_node_addr_get_by_alias(dap_chain_net_t * a_net, const char *alias); -int dap_chain_node_cli_cmd_values_parse_net_chain(int *a_arg_index,int argc, const char ** argv, char ** a_str_reply, +int dap_chain_node_cli_cmd_values_parse_net_chain(int *a_arg_index,int argc, char ** argv, char ** a_str_reply, dap_chain_t ** a_chain, dap_chain_net_t ** a_net); /** * global_db command */ -int com_global_db(int argc, const char ** argv, char **str_reply); +int com_global_db(int argc, char ** argv, char **str_reply); /** * Node command */ -int com_node(int argc, const char ** argv, char **str_reply); +int com_node(int argc, char ** argv, char **str_reply); /** * Traceroute command * * return 0 OK, -1 Err */ -int com_traceroute(int argc, const char** argv, char **str_reply); +int com_traceroute(int argc, char** argv, char **str_reply); /** * Tracepath command * * return 0 OK, -1 Err */ -int com_tracepath(int argc, const char** argv, char **str_reply); +int com_tracepath(int argc, char** argv, char **str_reply); /** * Ping command * * return 0 OK, -1 Err */ -int com_ping(int argc, const char** argv, char **str_reply); +int com_ping(int argc, char** argv, char **str_reply); /** * Help command */ -int com_help(int argc, const char ** argv, char **str_reply); +int com_help(int argc, char ** argv, char **str_reply); /** * Token declaration */ -int com_token_decl ( int argc, const char ** argv, char ** str_reply); +int com_token_decl ( int argc, char ** argv, char ** str_reply); /** * Token declaration add sign */ -int com_token_decl_sign ( int argc, const char ** argv, char ** str_reply); +int com_token_decl_sign ( int argc, char ** argv, char ** str_reply); /** * Token emission */ -int com_token_emit (int argc, const char ** argv, char ** str_reply); +int com_token_emit (int argc, char ** argv, char ** str_reply); /** @@ -99,27 +99,27 @@ int com_token_emit (int argc, const char ** argv, char ** str_reply); * * Wallet info */ -int com_tx_wallet(int argc, const char ** argv, char **str_reply); +int com_tx_wallet(int argc, char ** argv, char **str_reply); /** * com_tx_create command * * Create transaction */ -int com_tx_create(int argc, const char ** argv, char **str_reply); -int com_tx_cond_create(int argc, const char ** argv, char **str_reply); +int com_tx_create(int argc, char ** argv, char **str_reply); +int com_tx_cond_create(int argc, char ** argv, char **str_reply); /** * tx_verify command * * Verifing transaction */ -int com_tx_verify(int argc, const char ** argv, char **str_reply); +int com_tx_verify(int argc, char ** argv, char **str_reply); // Print log info -int com_print_log(int argc, const char ** argv, char **str_reply); +int com_print_log(int argc, char ** argv, char **str_reply); -int com_mempool_delete(int argc, const char ** argv, char ** a_str_reply); -int com_mempool_list(int argc, const char ** argv, char ** a_str_reply); -int com_mempool_proc(int argc, const char ** argv, char ** a_str_reply); +int com_mempool_delete(int argc, char ** argv, char ** a_str_reply); +int com_mempool_list(int argc, char ** argv, char ** a_str_reply); +int com_mempool_proc(int argc, char ** argv, char ** a_str_reply);