From 3549364727a8066eb7a8acdb3445275e3f9e627b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Al=D0=B5x=D0=B0nder=20Lysik=D0=BEv?= <alexander.lysikov@demlabs.net> Date: Thu, 7 May 2020 16:00:18 +0500 Subject: [PATCH] added com_news() --- modules/net/dap_chain_node_cli_cmd.c | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c index 2d2a9b7752..ad07d981cb 100644 --- a/modules/net/dap_chain_node_cli_cmd.c +++ b/modules/net/dap_chain_node_cli_cmd.c @@ -3741,6 +3741,51 @@ int com_print_log(int argc, char ** argv, void *arg_func, char **str_reply) return 0; } +/** + * Add News for VPN clients + * news [-text <news text> | -file <filename with news>] -lang <language code> + */ +int com_news(int a_argc, char ** a_argv, void *a_arg_func, char **a_str_reply) +{ + int arg_index = 1; + const char * l_str_lang = NULL; + const char * l_str_text = NULL; + const char * l_str_file = NULL; + dap_chain_node_cli_find_option_val(a_argv, arg_index, a_argc, "-lang", &l_str_lang); + dap_chain_node_cli_find_option_val(a_argv, arg_index, a_argc, "-text", &l_str_text); + dap_chain_node_cli_find_option_val(a_argv, arg_index, a_argc, "-file", &l_str_file); + if(!l_str_text && !l_str_file) { + dap_chain_node_cli_set_reply_text(a_str_reply, "no source of news, add parameter -text or -file"); + return -1; + } + byte_t *l_data_news; + size_t l_data_news_len = 0; + const char *l_from = NULL; + + if(l_str_text) { + l_data_news = (byte_t*) l_str_text; + l_data_news_len = dap_strlen(l_str_text); + l_from = "text"; + } + else if(l_str_file) { + if(dap_file_get_contents(l_str_file, &l_data_news,&l_data_news_len)) { + l_from = "file"; + } + else{ + dap_chain_node_cli_set_reply_text(a_str_reply, "Can't read file %s", l_str_file); + return -2; + } + } + + int l_res = dap_chain_net_news_write(l_str_lang, l_data_news, l_data_news_len); + if(l_res){ + dap_chain_node_cli_set_reply_text(a_str_reply, "Error, News cannot be added from %s", l_from); + return -3; + } + dap_chain_node_cli_set_reply_text(a_str_reply, "News added from %s successfully", l_from); + return 0; +} + /** * vpn_client command * -- GitLab