diff --git a/CMakeLists.txt b/CMakeLists.txt index e16bb15..3e1480f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,6 +205,7 @@ ExternalProject_Add(libseshat add_library(liblibseshat STATIC SHARED IMPORTED) add_dependencies(liblibseshat libseshat) include_directories(${INCLUDE_DIR}/libseshat) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_SESHAT ") endif (ENABLE_SESHAT) if (ENABLE_CJWT) @@ -235,6 +236,7 @@ include_directories(${INCLUDE_DIR} ) endif (UCLIBC) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_CJWT ") endif (ENABLE_CJWT) if (BUILD_TESTING) diff --git a/src/config.c b/src/config.c index bb8d081..cdda0ee 100644 --- a/src/config.c +++ b/src/config.c @@ -128,10 +128,14 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg) {"webpa-inteface-used", required_argument, 0, 'i'}, {"parodus-local-url", required_argument, 0, 'l'}, {"partner-id", required_argument, 0, 'p'}, - {"seshat-url", required_argument, 0, 'e'}, - {"dns-id", required_argument, 0, 'D'}, +#ifdef ENABLE_SESHAT + {"seshat-url", required_argument, 0, 'e'}, +#endif +#ifdef ENABLE_CJWT + {"dns-id", required_argument, 0, 'D'}, {JWT_ALGORITHM, required_argument, 0, 'a'}, - {JWT_KEY, required_argument, 0, 'k'}, + {JWT_KEY, required_argument, 0, 'k'}, +#endif {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ @@ -168,12 +172,12 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg) abort (); } break; - +#ifdef ENABLE_SESHAT case 'e': parStrncpy(cfg->seshat_url, optarg,sizeof(cfg->seshat_url)); ParodusInfo("seshat_url is %s\n",cfg->seshat_url); break; - +#endif case 'r': parStrncpy(cfg->hw_last_reboot_reason, optarg,sizeof(cfg->hw_last_reboot_reason)); ParodusInfo("hw_last_reboot_reason is %s\n",cfg->hw_last_reboot_reason); @@ -213,6 +217,7 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg) parStrncpy(cfg->local_url, optarg,sizeof(cfg->local_url)); ParodusInfo("parodus local_url is %s\n",cfg->local_url); break; +#ifdef ENABLE_CJWT case 'D': // like 'fabric' or 'test' // this parameter is used, along with the hw_mac parameter @@ -235,7 +240,7 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg) } ParodusInfo("jwt_key is %s\n",cfg->jwt_key); break; - +#endif case 'p': parStrncpy(cfg->partner_id, optarg,sizeof(cfg->partner_id)); ParodusInfo("partner_id is %s\n",cfg->partner_id); @@ -349,17 +354,6 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg) } - if( strlen(pConfig->dns_id) !=0) - { - parStrncpy(cfg->dns_id, pConfig->dns_id,sizeof(cfg->dns_id)); - } - else - { - ParodusInfo("parodus dns-id is NULL. adding default\n"); - parStrncpy(cfg->dns_id, DNS_ID,sizeof(cfg->dns_id)); - - } - if( strlen(pConfig->partner_id) !=0) { parStrncpy(cfg->partner_id, pConfig->partner_id,sizeof(cfg->partner_id)); @@ -368,7 +362,7 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg) { ParodusPrint("partner_id is NULL. read from tmp file\n"); } - +#ifdef ENABLE_SESHAT if( strlen(pConfig->seshat_url) !=0) { parStrncpy(cfg->seshat_url, pConfig->seshat_url,sizeof(cfg->seshat_url)); @@ -376,7 +370,19 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg) else { ParodusInfo("seshat_url is NULL. Read from tmp file\n"); - } + } +#endif +#ifdef ENABLE_CJWT + if( strlen(pConfig->dns_id) !=0) + { + parStrncpy(cfg->dns_id, pConfig->dns_id,sizeof(cfg->dns_id)); + } + else + { + ParodusInfo("parodus dns-id is NULL. adding default\n"); + parStrncpy(cfg->dns_id, DNS_ID,sizeof(cfg->dns_id)); + } + if(strlen(pConfig->jwt_key )!=0) { parStrncpy(cfg->jwt_key, pConfig->jwt_key,sizeof(cfg->jwt_key)); @@ -396,7 +402,7 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg) parStrncpy(cfg->jwt_algo, "\0", sizeof(cfg->jwt_algo)); ParodusPrint("jwt_algo is NULL. set to empty\n"); } - +#endif cfg->boot_time = pConfig->boot_time; cfg->secureFlag = 1; cfg->webpa_ping_timeout = pConfig->webpa_ping_timeout; diff --git a/src/config.h b/src/config.h index 944b27f..30439c0 100644 --- a/src/config.h +++ b/src/config.h @@ -36,10 +36,12 @@ extern "C" { #define PROTOCOL_VALUE "PARODUS-2.0" #define WEBPA_PATH_URL "/api/v2/device" +#ifdef ENABLE_CJWT #define JWT_ALGORITHM "jwt-algo" #define JWT_KEY "jwt-key" -#define PARODUS_UPSTREAM "tcp://127.0.0.1:6666" #define DNS_ID "fabric" +#endif +#define PARODUS_UPSTREAM "tcp://127.0.0.1:6666" /*----------------------------------------------------------------------------*/ /* Data Structures */ @@ -62,12 +64,16 @@ typedef struct char webpa_protocol[32]; char webpa_uuid[64]; unsigned int secureFlag; - char dns_id[64]; char local_url[124]; char partner_id[64]; +#ifdef ENABLE_SESHAT char seshat_url[128]; +#endif +#ifdef ENABLE_CJWT + char dns_id[64]; char jwt_algo[32]; // bit mask set for each allowed algorithm char jwt_key[4096]; // may be read in from a pem file +#endif } ParodusCfg; /*----------------------------------------------------------------------------*/ diff --git a/tests/test_config.c b/tests/test_config.c index ee1216a..085989c 100644 --- a/tests/test_config.c +++ b/tests/test_config.c @@ -53,7 +53,9 @@ void test_setParodusConfig() parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol)); parStrncpy(cfg.webpa_uuid , "1234567-345456546", sizeof(cfg.webpa_uuid)); parStrncpy(cfg.partner_id , "comcast", sizeof(cfg.partner_id)); +#ifdef ENABLE_SESHAT parStrncpy(cfg.seshat_url, "ipc://tmp/seshat_service.url", sizeof(cfg.seshat_url)); +#endif cfg.secureFlag = 1; cfg.boot_time = 423457; cfg.webpa_ping_timeout = 30; @@ -74,9 +76,9 @@ void test_setParodusConfig() assert_string_equal(cfg.webpa_protocol, temp->webpa_protocol); assert_string_equal(cfg.webpa_uuid, temp->webpa_uuid); assert_string_equal(cfg.partner_id, temp->partner_id); +#ifdef ENABLE_SESHAT assert_string_equal(cfg.seshat_url, temp->seshat_url); - - +#endif assert_int_equal((int) cfg.secureFlag, (int) temp->secureFlag); assert_int_equal((int) cfg.boot_time, (int) temp->boot_time); assert_int_equal((int) cfg.webpa_ping_timeout, (int) temp->webpa_ping_timeout); @@ -99,6 +101,9 @@ void test_getParodusConfig() void test_parseCommandLine() { int argc =K_argc; +#ifndef ENABLE_SESHAT + argc = argc - 1; +#endif char * command[argc+1]; int i = 0; @@ -116,7 +121,9 @@ void test_parseCommandLine() command[i++] = "--boot-time=1234"; command[i++] = "--parodus-local-url=tcp://127.0.0.1:6666"; command[i++] = "--partner-id=cox"; +#ifdef ENABLE_SESHAT command[i++] = "--seshat-url=ipc://127.0.0.1:7777"; +#endif command[i] = '\0'; ParodusCfg parodusCfg; @@ -137,7 +144,9 @@ void test_parseCommandLine() assert_int_equal( (int) parodusCfg.boot_time,1234); assert_string_equal( parodusCfg.local_url,"tcp://127.0.0.1:6666"); assert_string_equal( parodusCfg.partner_id,"cox"); +#ifdef ENABLE_SESHAT assert_string_equal( parodusCfg.seshat_url, "ipc://127.0.0.1:7777"); +#endif } @@ -149,6 +158,9 @@ void test_parseCommandLineNull() void err_parseCommandLine() { int argc =K_argc; +#ifndef ENABLE_SESHAT + argc = argc - 1; +#endif char * command[20]={'\0'}; command[0] = "parodus";