From 431d1c4f25141a7b2f0a8df69b13ab1b4f1e3309 Mon Sep 17 00:00:00 2001
From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net>
Date: Sat, 21 Dec 2019 16:37:57 +0700
Subject: [PATCH] [*] Replacement of macro to functions for app name and dirs

---
 CMakeLists.txt                 |   3 +-
 libdap                         |   2 +-
 libdap-chain-global-db         |   2 +-
 libdap-chain-mempool           |   2 +-
 libdap-chain-net               |   2 +-
 libdap-chain-net-srv-vpn       |   2 +-
 libdap-chain-wallet            |   2 +-
 libdap-server                  |   2 +-
 libdap-server-core             |   2 +-
 libdap-server-http-db-auth     |   2 +-
 libdap-stream                  |   2 +-
 libdap-stream-ch-chain         |   2 +-
 libdap-stream-ch-chain-net-srv |   2 +-
 sources/dap_defines.h          |  27 --------
 sources/main.c                 |  49 ++++++++------
 sources/main_node_cli.c        |  39 +++++++----
 sources/main_node_tool.c       | 119 +++++++++++++++++----------------
 17 files changed, 128 insertions(+), 133 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 463124b..06ea6fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,7 +52,7 @@ SET( CPACK_GENERATOR "DEB")
 SET( CPACK_PACKAGE_NAME  "${PROJECT_NAME}")
 SET( CPACK_PACKAGE_VERSION_MAJOR 2)
 SET( CPACK_PACKAGE_VERSION_MINOR 8)
-SET( CPACK_PACKAGE_VERSION_PATCH 11)
+SET( CPACK_PACKAGE_VERSION_PATCH 12)
 
 SET( CPACK_SYSTEM_NAME "debian-9.9-amd64")
 SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}")
@@ -121,6 +121,7 @@ if(UNIX)
 
   if (ANDROID)
       set(_CCOPT "${_CCOPT} -fforce-enable-int128 -std=gnu11")
+      add_definitions ("-DDAP_OS_ANDROID -DDAP_OS_UNIX")
   endif()
 
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
diff --git a/libdap b/libdap
index ee6e861..c45b23f 160000
--- a/libdap
+++ b/libdap
@@ -1 +1 @@
-Subproject commit ee6e8617e1f589b45f15e327ed18cddfa87915f8
+Subproject commit c45b23f126e7528dab2a5dc592cdaf463b01744f
diff --git a/libdap-chain-global-db b/libdap-chain-global-db
index 03b41ed..2d066f3 160000
--- a/libdap-chain-global-db
+++ b/libdap-chain-global-db
@@ -1 +1 @@
-Subproject commit 03b41edde4c1d9fea442bc8c2d290b2a70d00431
+Subproject commit 2d066f3c6a38310f42444b3bec78889bea2ca7c0
diff --git a/libdap-chain-mempool b/libdap-chain-mempool
index a063222..6230d94 160000
--- a/libdap-chain-mempool
+++ b/libdap-chain-mempool
@@ -1 +1 @@
-Subproject commit a063222c80bc25cf70fdb3b6391f202bb2c08c65
+Subproject commit 6230d941f19b67f208793fa4c321a785e0df8760
diff --git a/libdap-chain-net b/libdap-chain-net
index 18cf7bd..a3646f9 160000
--- a/libdap-chain-net
+++ b/libdap-chain-net
@@ -1 +1 @@
-Subproject commit 18cf7bd0c4cc25dd03c55e27be6fe9cd9a834c4a
+Subproject commit a3646f9eb51b892bd92bd30d16e0c97e5ae1dbcb
diff --git a/libdap-chain-net-srv-vpn b/libdap-chain-net-srv-vpn
index e352c98..80082cc 160000
--- a/libdap-chain-net-srv-vpn
+++ b/libdap-chain-net-srv-vpn
@@ -1 +1 @@
-Subproject commit e352c9880d2873b2041add005ea492ef58cf3c51
+Subproject commit 80082cc1d12437ef96103c6a4765013f1528fd86
diff --git a/libdap-chain-wallet b/libdap-chain-wallet
index 1d23760..881cadb 160000
--- a/libdap-chain-wallet
+++ b/libdap-chain-wallet
@@ -1 +1 @@
-Subproject commit 1d23760cc25190ff114eac4cab212459360936f8
+Subproject commit 881cadba56a912e9ec52f5f10d8cc9ec510f556b
diff --git a/libdap-server b/libdap-server
index bc2eeb2..0f224b4 160000
--- a/libdap-server
+++ b/libdap-server
@@ -1 +1 @@
-Subproject commit bc2eeb22af9852cce12079b755b6afa277d5be4e
+Subproject commit 0f224b4de595d688cbbac6c2616286b8079eba88
diff --git a/libdap-server-core b/libdap-server-core
index 3536156..8ed6c9d 160000
--- a/libdap-server-core
+++ b/libdap-server-core
@@ -1 +1 @@
-Subproject commit 3536156bde9494a0215d56283c0739c80b87ffe4
+Subproject commit 8ed6c9dee385a9178c4b07b097e62e62ecfb6923
diff --git a/libdap-server-http-db-auth b/libdap-server-http-db-auth
index c03c689..d1e5f6a 160000
--- a/libdap-server-http-db-auth
+++ b/libdap-server-http-db-auth
@@ -1 +1 @@
-Subproject commit c03c689e1cf6b7e68b0033c0bc1f745c7c64a46d
+Subproject commit d1e5f6abc9d394b53beb06a2566dd3ae52be92e8
diff --git a/libdap-stream b/libdap-stream
index 2ce04a6..4781932 160000
--- a/libdap-stream
+++ b/libdap-stream
@@ -1 +1 @@
-Subproject commit 2ce04a6339c956d240fcb7d9f1347a0e49dd74cc
+Subproject commit 4781932c88e82e1fe38f8859ef56a8367f580d4b
diff --git a/libdap-stream-ch-chain b/libdap-stream-ch-chain
index 80d7aa0..9933103 160000
--- a/libdap-stream-ch-chain
+++ b/libdap-stream-ch-chain
@@ -1 +1 @@
-Subproject commit 80d7aa0f4f7dd221110923a254d306c5564c5392
+Subproject commit 9933103d507a0fb1c2af1fe1df9ecb3da41c909e
diff --git a/libdap-stream-ch-chain-net-srv b/libdap-stream-ch-chain-net-srv
index e70339a..1f34d25 160000
--- a/libdap-stream-ch-chain-net-srv
+++ b/libdap-stream-ch-chain-net-srv
@@ -1 +1 @@
-Subproject commit e70339a6784aa37b0923804330dbdccae770556d
+Subproject commit 1f34d25645ec14af02ea9e79df4acdf4256f0682
diff --git a/sources/dap_defines.h b/sources/dap_defines.h
index 2cdb23f..3f59c93 100644
--- a/sources/dap_defines.h
+++ b/sources/dap_defines.h
@@ -1,29 +1,2 @@
 #pragma once
 
-#define NODE_NETNAME "cellframe"
-#define DAP_APP_NAME NODE_NETNAME "-node"
-
-//#ifdef _WIN32
-//  #define SYSTEM_PREFIX "%USERPROFILE%/opt/"DAP_APP_NAME
-//#else
-#ifdef __ANDROID__
-    #define ANDROID_STORAGE_PATH "/storage/emulated/0"
-    #define SYSTEM_PREFIX ANDROID_STORAGE_PATH "/opt/" DAP_APP_NAME
-#else
-  #define SYSTEM_PREFIX "/opt/" DAP_APP_NAME
-#endif
-//  #define SYSTEM_PREFIX "opt/"DAP_APP_NAME
-//#endif
-
-#define LOCAL_PREFIX "~/." DAP_APP_NAME
-
-#define SYSTEM_CONFIGS_DIR SYSTEM_PREFIX"/etc"
-#define LOCAL_CONFIGS_DIR LOCAL_PREFIX"/etc"
-#define SYSTEM_LOGS_DIR SYSTEM_PREFIX"/var/log"
-#define SYSTEM_LOGS_PATH SYSTEM_LOGS_DIR "/" DAP_APP_NAME ".log"
-
-#define SYSTEM_CONFIG_GLOBAL_FILENAME SYSTEM_PREFIX"/etc/" DAP_APP_NAME".cfg"
-#define LOCAL_CONFIG_GLOBAL LOCAL_PREFIX"/etc/" DAP_APP_NAME".cfg"
-
-#define SYSTEM_PID_FILE_PATH SYSTEM_PREFIX"/run/" DAP_APP_NAME".pid"
-#define LOCAL_PID_FILE_PATH SYSTEM_PREFIX"/run/" DAP_APP_NAME".pid"
diff --git a/sources/main.c b/sources/main.c
index dd9b5cc..f471dcd 100755
--- a/sources/main.c
+++ b/sources/main.c
@@ -53,7 +53,7 @@
     #include "registry.h"
     void  S_SetExceptionFilter( void );
 #endif
-
+#include "dap_common.h"
 #include "dap_config.h"
 #include "dap_server.h"
 #include "dap_http.h"
@@ -131,7 +131,9 @@
 void parse_args( int argc, const char **argv );
 void exit_if_server_already_running( void );
 
-static char s_pid_file_path[MAX_PATH];
+static char *s_config_dir = NULL;
+static char *s_pid_file_path = NULL;
+static char *s_log_file_path = NULL;
 static void s_auth_callback(enc_http_delegate_t *a_delegate, void * a_arg);
 
 #ifdef __ANDROID__
@@ -145,40 +147,43 @@ int main( int argc, const char **argv )
 	bool bServerEnabled = true;
 	int rc = 0;
 
+    dap_set_appname("cellframe-node");
 	#if defined(_WIN32) && defined(NDEBUG)
 		S_SetExceptionFilter( );
 	#endif
 
     {
-        char l_log_file_path [ MAX_PATH ];
 #ifdef _WIN32
-        dap_sprintf(s_sys_dir_path, "%s/%s", regGetUsrPath(), DAP_APP_NAME);
-        l_sys_dir_path_len = strlen(s_sys_dir_path);
-        memcpy(l_log_file_path, s_sys_dir_path, l_sys_dir_path_len);
-        memcpy(s_pid_file_path, s_sys_dir_path, l_sys_dir_path_len);
+        s_sys_dir_path =dap_strdup_printf("%s/%s", regGetUsrPath(), dap_get_appname());
+#elif DAP_OS_MAC
+        s_sys_dir_path =dap_strdup_printf( "/Applications/%s.app/Contents/Resources", dap_get_appname());
+#elif DAP_OS_ANDROID
+        s_sys_dir_path = dap_strdup_printf("/storage/emulated/0/opt/%s",dap_get_appname());
+#elif DAP_OS_UNIX
+        g_sys_dir_path =dap_strdup_printf("/opt/%s", dap_get_appname());
 #endif
-        dap_snprintf( l_log_file_path + l_sys_dir_path_len , sizeof ( l_log_file_path ), "%s", SYSTEM_LOGS_PATH );
+        g_sys_dir_path_len = strlen(g_sys_dir_path);
 
-        dap_mkdir_with_parents( SYSTEM_LOGS_DIR );
+        s_config_dir = dap_strdup_printf ("%s/etc", g_sys_dir_path );
+        s_log_file_path = dap_strdup_printf ("%s/var/log/%s.log", g_sys_dir_path,dap_get_appname());
 
-        if ( dap_common_init( DAP_APP_NAME, l_log_file_path ) != 0 ) {
+        dap_mkdir_with_parents( s_log_file_path );
+
+        if ( dap_common_init( dap_get_appname(), s_log_file_path ) != 0 ) {
             printf( "Fatal Error: Can't init common functions module" );
             return -2;
         }
-        dap_snprintf(s_sys_dir_path + l_sys_dir_path_len, sizeof( s_sys_dir_path ), "%s", SYSTEM_CONFIGS_DIR);
-        dap_config_init( s_sys_dir_path );
-        memset(s_sys_dir_path + l_sys_dir_path_len, '\0', MAX_PATH - l_sys_dir_path_len);
-        if ( (g_config = dap_config_open(DAP_APP_NAME)) == NULL ) {
+        dap_config_init( s_config_dir );
+        if ( (g_config = dap_config_open(dap_get_appname())) == NULL ) {
             log_it( L_CRITICAL,"Can't init general configurations" );
             return -1;
         }
-        dap_sprintf(s_pid_file_path + l_sys_dir_path_len, "%s", dap_config_get_item_str_default( g_config,
-                                                                                   "resources",
-                                                                                   "pid_path","/tmp") );
+        s_pid_file_path = dap_config_get_item_str_default( g_config,  "resources", "pid_path","/tmp") ;
+        dap_mkdir_with_parents( s_pid_file_path );
     }
     log_it(L_DEBUG, "Parsing command line args");
-	parse_args( argc, argv );
-	#ifdef _WIN32
+    parse_args( argc, argv );
+    #ifdef _WIN32
         CreateMutexW( NULL, FALSE, (WCHAR *) L"DAP_CELLFRAME_NODE_74E9201D33F7F7F684D2FEF1982799A79B6BF94B568446A8D1DE947B00E3C75060F3FD5BF277592D02F77D7E50935E56" );
 	#endif
 
@@ -344,7 +349,7 @@ int main( int argc, const char **argv )
     if (sig_unix_handler_init(dap_config_get_item_str_default(g_config,
                                                               "resources",
                                                               "pid_path",
-                                                              SYSTEM_PID_FILE_PATH)) != 0) {
+                                                              "/tmp")) != 0) {
         log_it(L_CRITICAL,"Can't init sig unix handler module");
         return -12;
     }
@@ -378,7 +383,7 @@ int main( int argc, const char **argv )
         // TCP-specific things
 		if ( dap_config_get_item_int32_default(g_config, "server", "listen_port_tcp",-1) > 0) {
             // Init HTTP-specific values
-	    	dap_http_new( l_server, DAP_APP_NAME );
+            dap_http_new( l_server, dap_get_appname() );
 
 	        // Handshake URL
 	        enc_http_add_proc( DAP_HTTP(l_server), ENC_HTTP_URL );
@@ -502,7 +507,7 @@ void parse_args( int argc, const char **argv ) {
         	break;
       	}
 
-      	default:
+        default:
         log_it( L_WARNING, "Unknown option from command line" );
 		}
 	}
diff --git a/sources/main_node_cli.c b/sources/main_node_cli.c
index f0e8aa0..885650c 100644
--- a/sources/main_node_cli.c
+++ b/sources/main_node_cli.c
@@ -29,6 +29,8 @@
 
 //#include "dap_client.h"
 #include "dap_common.h"
+#include "dap_file_utils.h"
+#include "dap_strfuncs.h"
 #include "dap_chain_node_cli.h"
 #include "main_node_cli.h"
 #include "main_node_cli_net.h"
@@ -189,25 +191,38 @@ int shell_reader_loop()
 int cellframe_node__cli_Main(int argc, const char *argv[])
 #else
 
+static char * s_config_dir = NULL;
+static char * s_log_file_path= NULL;
 int main(int argc, const char *argv[])
 #endif
 {
-#if defined (_WIN32)
-    dap_sprintf(s_sys_dir_path, "%s/%s", regGetUsrPath(), DAP_APP_NAME);
-    l_sys_dir_path_len = strlen(s_sys_dir_path);
+    dap_set_appname("cellframe-node-cli");
+
+#ifdef _WIN32
+    s_sys_dir_path =dap_strdup_printf("%s/%s", regGetUsrPath(), dap_get_appname());
+#elif DAP_OS_MAC
+    s_sys_dir_path =dap_strdup_printf( "/Applications/%s.app/Contents/Resources", dap_get_appname());
+#elif DAP_OS_ANDROID
+    s_sys_dir_path = dap_strdup_printf("/storage/emulated/0/opt/%s",dap_get_appname());
+#elif DAP_OS_UNIX
+    g_sys_dir_path =dap_strdup_printf("/opt/%s", dap_get_appname());
 #endif
+    g_sys_dir_path_len = strlen(g_sys_dir_path);
 
-    //    set_default_locale();
-    //    command_execution_string = shell_script_filename = (char *) NULL;
+    s_config_dir = dap_strdup_printf ("%s/etc", g_sys_dir_path );
+    s_log_file_path = dap_strdup_printf ("%s/var/log/%s.log", g_sys_dir_path,dap_get_appname());
 
-    memcpy(s_sys_dir_path + l_sys_dir_path_len, SYSTEM_CONFIGS_DIR, sizeof(SYSTEM_CONFIGS_DIR) );
-    dap_common_init( DAP_APP_NAME " Console interface", NULL );
+    dap_mkdir_with_parents( s_log_file_path );
+
+    if ( dap_common_init( dap_get_appname(), s_log_file_path ) != 0 ) {
+        printf( "Fatal Error: Can't init common functions module" );
+        return -2;
+    }
     dap_log_level_set( L_CRITICAL );
-    dap_config_init( s_sys_dir_path );
-    memset(s_sys_dir_path + l_sys_dir_path_len, '\0', MAX_PATH - l_sys_dir_path_len);
+    dap_config_init( s_config_dir );
 
-    if((g_config = dap_config_open(DAP_APP_NAME)) == NULL) {
-        printf("Can't init general configurations " DAP_APP_NAME ".cfg\n");
+    if((g_config = dap_config_open(dap_get_appname())) == NULL) {
+        printf("Can't init general configurations %s.cfg\n", dap_get_appname());
         exit(-1);
     }
 
@@ -215,7 +230,7 @@ int main(int argc, const char *argv[])
     cparam = node_cli_connect();
     if(!cparam)
     {
-        printf("Can't connected to " DAP_APP_NAME "\n");
+        printf("Can't connected to %s\n",dap_get_appname());
         exit(-1);
     }
 
diff --git a/sources/main_node_tool.c b/sources/main_node_tool.c
index ba50ef1..b610278 100644
--- a/sources/main_node_tool.c
+++ b/sources/main_node_tool.c
@@ -87,7 +87,6 @@
 #ifdef _WIN32
 #include "registry.h"
 #endif
-#define DAP_APP_NAME NODE_NETNAME "-node"
 
 #define ENC_HTTP_URL "/enc_init"
 #define STREAM_CTL_URL "/stream_ctl"
@@ -104,7 +103,8 @@ static int s_init( int argc, const char * argv[] );
 static void s_help( );
 
 static char s_system_ca_dir[MAX_PATH];
-static const char *s_appname = "cellframe-node-tool";
+static char * s_config_dir = NULL;
+static char * s_log_file_path= NULL;
 
 #ifdef __ANDROID__
 int cellframe_node_tool_Main(int argc, const char **argv)
@@ -163,7 +163,7 @@ int main(int argc, const char **argv)
 #ifdef _WIN32
         dap_stpcpy(l_wallets_path, s_sys_dir_path);
 #endif
-        dap_sprintf(l_wallets_path + l_sys_dir_path_len, "%s", dap_config_get_item_str(g_config, "resources", "wallets_path"));
+        dap_sprintf(l_wallets_path + g_sys_dir_path_len, "%s", dap_config_get_item_str(g_config, "resources", "wallets_path"));
         l_wallet = dap_chain_wallet_create( l_wallet_name, l_wallets_path, l_sig_type );
     }
     else if ( strcmp( argv[2],"sign_file") == 0 ) {
@@ -178,7 +178,7 @@ int main(int argc, const char **argv)
 #ifdef _WIN32
         dap_stpcpy(l_wallets_path, s_sys_dir_path);
 #endif
-        dap_sprintf(l_wallets_path + l_sys_dir_path_len, "%s", dap_config_get_item_str(g_config, "resources", "wallets_path"));
+        dap_sprintf(l_wallets_path + g_sys_dir_path_len, "%s", dap_config_get_item_str(g_config, "resources", "wallets_path"));
       dap_chain_wallet_t *l_wallet = dap_chain_wallet_open( argv[3], l_wallets_path);
       if ( !l_wallet ) {
         log_it(L_ERROR,"Can't open wallet \"%s\"",argv[3]);
@@ -367,88 +367,89 @@ int main(int argc, const char **argv)
  */
 static int s_init( int argc, const char **argv )
 {
-    char l_log_file_path[MAX_PATH];
-    l_sys_dir_path_len = 0;
+    dap_set_appname("cellframe-node-tool");
 
 #ifdef _WIN32
-    dap_sprintf(s_sys_dir_path, "%s/%s", regGetUsrPath(), DAP_APP_NAME);
-    l_sys_dir_path_len = strlen(s_sys_dir_path);
-    memcpy(s_system_ca_dir, s_sys_dir_path, l_sys_dir_path_len);
-    memcpy(l_log_file_path, s_sys_dir_path, l_sys_dir_path_len);
+    s_sys_dir_path =dap_strdup_printf("%s/%s", regGetUsrPath(), dap_get_appname());
+#elif DAP_OS_MAC
+    s_sys_dir_path =dap_strdup_printf( "/Applications/%s.app/Contents/Resources", dap_get_appname());
+#elif DAP_OS_ANDROID
+    s_sys_dir_path = dap_strdup_printf("/storage/emulated/0/opt/%s",dap_get_appname());
+#elif DAP_OS_UNIX
+    g_sys_dir_path =dap_strdup_printf("/opt/%s", dap_get_appname());
 #endif
+    g_sys_dir_path_len = strlen(g_sys_dir_path);
 
-    memcpy(l_log_file_path + l_sys_dir_path_len, SYSTEM_LOGS_DIR, sizeof(SYSTEM_LOGS_DIR));
-    dap_sprintf(l_log_file_path + l_sys_dir_path_len + sizeof(SYSTEM_LOGS_DIR) - 1, "/%s_tool_logs.txt", DAP_APP_NAME);
+    s_config_dir = dap_strdup_printf ("%s/etc", g_sys_dir_path );
+    s_log_file_path = dap_strdup_printf ("%s/var/log/%s.log", g_sys_dir_path,dap_get_appname());
 
-    if (dap_common_init(DAP_APP_NAME, l_log_file_path) != 0) {
-        printf("Fatal Error: Can't init common functions module");
+    dap_mkdir_with_parents( s_log_file_path );
+
+    if ( dap_common_init( dap_get_appname(), s_log_file_path ) != 0 ) {
+        printf( "Fatal Error: Can't init common functions module" );
         return -2;
     }
+    dap_log_level_set( L_CRITICAL );
+    dap_config_init( s_config_dir );
 
-    memcpy(s_sys_dir_path + l_sys_dir_path_len, SYSTEM_CONFIGS_DIR, sizeof(SYSTEM_CONFIGS_DIR));
-    dap_config_init( s_sys_dir_path );
-    memset(s_sys_dir_path + l_sys_dir_path_len, '\0', MAX_PATH - l_sys_dir_path_len);
-
-    //dap_sprintf(s_system_ca_dir + l_sys_dir_path_len, "%s", l_ca_folders[i]);
-
-  if ( (g_config = dap_config_open(DAP_APP_NAME)) == NULL ) {
-    log_it( L_ERROR, "Can't init general configurations" );
-    return -1;
-  }
+    if((g_config = dap_config_open(dap_get_appname())) == NULL) {
+        printf("Can't init general configurations %s.cfg\n", dap_get_appname());
+        exit(-1);
+    }
 
-  if ( dap_chain_init() != 0 ) {
-    log_it( L_ERROR, "Can't chain module" );
-    return -3;
-  }
+    if ( dap_chain_init() != 0 ) {
+        log_it( L_ERROR, "Can't chain module" );
+        return -3;
+    }
 
-  if ( dap_cert_init() != 0 ) {
-    log_it( L_ERROR, "Can't chain certificate storage module" );
-    return -4;
-  }
+    if ( dap_cert_init() != 0 ) {
+        log_it( L_ERROR, "Can't chain certificate storage module" );
+        return -4;
+    }
 
-  if ( dap_chain_wallet_init() != 0 ) {
-    log_it( L_ERROR, "Can't chain wallet storage module" );
-    return -5;
-  }
+    if ( dap_chain_wallet_init() != 0 ) {
+        log_it( L_ERROR, "Can't chain wallet storage module" );
+        return -5;
+    }
 
- /* if ( dap_server_init(0) != 0 ) {
+    /* if ( dap_server_init(0) != 0 ) {
     log_it( L_ERROR, "Can't server module" );
     return -6;
-  }
+    }
 
-  if ( dap_stream_init(false) != 0 ) {
+    if ( dap_stream_init(false) != 0 ) {
     log_it( L_ERROR, "Can't init stream module" );
     return -7;
-  }
+    }
 
-  if ( dap_stream_ch_init() != 0 ) {
+    if ( dap_stream_ch_init() != 0 ) {
     log_it( L_ERROR, "Can't init stream ch module" );
     return -8;
-  }
+    }
 
-  if ( dap_stream_ch_chain_init() != 0 ) {
+    if ( dap_stream_ch_chain_init() != 0 ) {
     log_it( L_ERROR, "Can't init stream ch chain module" );
     return -9;
-  }
+    }
 
-  if ( dap_stream_ch_chain_net_init() != 0 ) {
+    if ( dap_stream_ch_chain_net_init() != 0 ) {
     log_it( L_ERROR, "Can't init stream ch chain net module" );
     return -10;
-  }
+    }
 
-  if ( dap_stream_ch_chain_net_srv_init() != 0 ) {
+    if ( dap_stream_ch_chain_net_srv_init() != 0 ) {
     log_it( L_ERROR, "Can't init stream ch chain net srv module" );
     return -11;
-  }
+    }
 
-  if ( dap_client_init() != 0 ) {
+    if ( dap_client_init() != 0 ) {
     log_it( L_ERROR, "Can't chain wallet storage module" );
     return -12;
-  } */
+    } */
 
     uint16_t l_ca_folders_size = 0;
     char **l_ca_folders = dap_config_get_array_str(g_config, "resources", "ca_folders", &l_ca_folders_size);
-    memcpy(s_system_ca_dir + l_sys_dir_path_len, l_ca_folders[0], strlen(l_ca_folders[0]));
+    memcpy(s_system_ca_dir + g_sys_dir_path_len, l_ca_folders[0], strlen(l_ca_folders[0]));
     return 0;
 }
 
@@ -463,27 +464,27 @@ static void s_help()
 #endif
 
   printf( "\n" );
-  printf( "%s usage:\n\n", s_appname );
+  printf( "%s usage:\n\n", dap_get_appname() );
 
   printf(" * Create new key wallet and generate signatures with same names plus index \n" );
-  printf("\t%s wallet create <network name> <wallet name> <signature type> [<signature type 2>[...<signature type N>]]\n\n", s_appname );
+  printf("\t%s wallet create <network name> <wallet name> <signature type> [<signature type 2>[...<signature type N>]]\n\n", dap_get_appname() );
 
   printf(" * Create new key wallet from existent certificates in the system\n");
-  printf("\t%s wallet create_from <network name> <wallet name> <wallet ca1> [<wallet ca2> [...<wallet caN>]]\n\n", s_appname );
+  printf("\t%s wallet create_from <network name> <wallet name> <wallet ca1> [<wallet ca2> [...<wallet caN>]]\n\n", dap_get_appname() );
 
   printf(" * Create new key file with randomly produced key stored in\n");
-  printf("\t%s cert create <cert name> <key type> [<key length>]\n\n", s_appname );
+  printf("\t%s cert create <cert name> <key type> [<key length>]\n\n", dap_get_appname() );
 
   printf(" * Dump cert data stored in <file path>\n");
-  printf("\t%s cert dump <cert name>\n\n", s_appname );
+  printf("\t%s cert dump <cert name>\n\n", dap_get_appname() );
 
   printf(" * Sign some data with cert \n");
-  printf("\t%s cert sign <cert name> <data file path> <sign file output> [<sign data length>] [<sign data offset>]\n\n", s_appname );
+  printf("\t%s cert sign <cert name> <data file path> <sign file output> [<sign data length>] [<sign data offset>]\n\n", dap_get_appname() );
 
   printf(" * Create pkey from <cert name> and store it on <pkey path>\n");
-  printf("\t%s cert create_pkey <cert name> <pkey path>\n\n", s_appname );
+  printf("\t%s cert create_pkey <cert name> <pkey path>\n\n", dap_get_appname() );
 
   printf(" * Export only public key from <cert name> and stores it \n");
-  printf("\t%s cert create_cert_pkey <cert name> <new cert name>\n\n",s_appname);
+  printf("\t%s cert create_cert_pkey <cert name> <new cert name>\n\n",dap_get_appname());
 
 }
-- 
GitLab