aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-config.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-01-04 16:50:13 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2017-01-04 16:50:13 +0100
commit8732499a619cf99388a0afbd8807981d2b00a314 (patch)
tree672fe6fc0f1e9a90e940f96edf6d0ddfa012bd44 /src/afb-config.c
parent0af860df66cded39478fd6690dea4ce0f8b7c799 (diff)
allows to repeat option --ldpaths
Change-Id: Id07b02eaef35732416de2fb1c6b24f3f75979ed6 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-config.c')
-rw-r--r--src/afb-config.c145
1 files changed, 75 insertions, 70 deletions
diff --git a/src/afb-config.c b/src/afb-config.c
index bd9a4344..ebe44b9c 100644
--- a/src/afb-config.c
+++ b/src/afb-config.c
@@ -196,74 +196,13 @@ static void printHelp(FILE * file, const char *name)
fprintf(file, " --%-15s %s\n", command, cliOptions[ind].help);
}
fprintf(file,
- "Example:\n %s\\\n --verbose --port=1234 --token='azerty' --ldpaths=build/bindings:/usr/lib64/agl/bindings\n",
+ "Example:\n %s --verbose --port=1234 --token='azerty' --ldpaths=build/bindings:/usr/lib64/agl/bindings\n",
name);
}
-// load config from disk and merge with CLI option
-static void config_set_default(struct afb_config *config)
-{
- // default HTTP port
- if (config->httpdPort == 0)
- config->httpdPort = 1234;
-
- // default binding API timeout
- if (config->apiTimeout == 0)
- config->apiTimeout = DEFLT_API_TIMEOUT;
-
- // default AUTH_TOKEN
- if (config->token == NULL)
- config->token = DEFLT_AUTH_TOKEN;
-
- // cache timeout default one hour
- if (config->cacheTimeout == 0)
- config->cacheTimeout = DEFLT_CACHE_TIMEOUT;
-
- // cache timeout default one hour
- if (config->cntxTimeout == 0)
- config->cntxTimeout = DEFLT_CNTX_TIMEOUT;
-
- // max count of sessions
- if (config->nbSessionMax == 0)
- config->nbSessionMax = CTX_NBCLIENTS;
-
- if (config->rootdir == NULL) {
- config->rootdir = getenv("AFBDIR");
- if (config->rootdir == NULL) {
- config->rootdir = malloc(512);
- strncpy(config->rootdir, getenv("HOME"), 512);
- strncat(config->rootdir, "/.AFB", 512);
- }
- }
- // if no Angular/HTML5 rootbase let's try '/' as default
- if (config->rootbase == NULL)
- config->rootbase = "/opa";
-
- if (config->rootapi == NULL)
- config->rootapi = "/api";
-
- if (config->ldpaths == NULL)
- config->ldpaths = BINDING_INSTALL_DIR;
-
- // if no session dir create a default path from rootdir
- if (config->sessiondir == NULL) {
- config->sessiondir = malloc(512);
- strncpy(config->sessiondir, config->rootdir, 512);
- strncat(config->sessiondir, "/sessions", 512);
- }
- // if no config dir create a default path from sessiondir
- if (config->console == NULL) {
- config->console = malloc(512);
- strncpy(config->console, config->sessiondir, 512);
- strncat(config->console, "/AFB-console.out", 512);
- }
-}
-
-/*---------------------------------------------------------
- | main
- | Parse option and launch action
+/*----------------------------------------------------------
+ | adds a string to the list
+--------------------------------------------------------- */
-
static void list_add(struct afb_config_list **head, char *value)
{
struct afb_config_list *item;
@@ -294,6 +233,10 @@ static void list_add(struct afb_config_list **head, char *value)
item->next = NULL;
}
+/*---------------------------------------------------------
+ | helpers for argument scanning
+ +--------------------------------------------------------- */
+
static char *argvalstr(int index)
{
if (optarg == 0) {
@@ -368,6 +311,10 @@ static void noarg(int index)
}
}
+/*---------------------------------------------------------
+ | Parse option and launch action
+ +--------------------------------------------------------- */
+
static void parse_arguments(int argc, char **argv, struct afb_config *config)
{
char *programName = argv[0];
@@ -394,9 +341,7 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config)
}
// get all options from command line
- while ((optc =
- getopt_long(argc, argv, "vsp?", gnuOptions, &optionIndex))
- != EOF) {
+ while ((optc = getopt_long(argc, argv, "", gnuOptions, &optionIndex)) != EOF) {
switch (optc) {
case SET_VERBOSE:
verbosity++;
@@ -443,7 +388,7 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config)
break;
case SET_LDPATH:
- config->ldpaths = argvalstr(optionIndex);
+ list_add(&config->ldpaths, argvalstr(optionIndex));
break;
case SET_SESSION_DIR:
@@ -506,14 +451,73 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config)
break;
case DISPLAY_HELP:
- default:
printHelp(stdout, programName);
exit(0);
+
+ default:
+ exit(1);
}
}
free(gnuOptions);
+}
+
+// load config from disk and merge with CLI option
+static void config_set_default(struct afb_config *config)
+{
+ // default HTTP port
+ if (config->httpdPort == 0)
+ config->httpdPort = 1234;
+
+ // default binding API timeout
+ if (config->apiTimeout == 0)
+ config->apiTimeout = DEFLT_API_TIMEOUT;
+
+ // default AUTH_TOKEN
+ if (config->token == NULL)
+ config->token = DEFLT_AUTH_TOKEN;
+
+ // cache timeout default one hour
+ if (config->cacheTimeout == 0)
+ config->cacheTimeout = DEFLT_CACHE_TIMEOUT;
+
+ // cache timeout default one hour
+ if (config->cntxTimeout == 0)
+ config->cntxTimeout = DEFLT_CNTX_TIMEOUT;
+
+ // max count of sessions
+ if (config->nbSessionMax == 0)
+ config->nbSessionMax = CTX_NBCLIENTS;
+
+ if (config->rootdir == NULL) {
+ config->rootdir = getenv("AFBDIR");
+ if (config->rootdir == NULL) {
+ config->rootdir = malloc(512);
+ strncpy(config->rootdir, getenv("HOME"), 512);
+ strncat(config->rootdir, "/.AFB", 512);
+ }
+ }
+ // if no Angular/HTML5 rootbase let's try '/' as default
+ if (config->rootbase == NULL)
+ config->rootbase = "/opa";
+
+ if (config->rootapi == NULL)
+ config->rootapi = "/api";
+
+ if (config->ldpaths == NULL)
+ list_add(&config->ldpaths, BINDING_INSTALL_DIR);
- config_set_default(config);
+ // if no session dir create a default path from rootdir
+ if (config->sessiondir == NULL) {
+ config->sessiondir = malloc(512);
+ strncpy(config->sessiondir, config->rootdir, 512);
+ strncat(config->sessiondir, "/sessions", 512);
+ }
+ // if no config dir create a default path from sessiondir
+ if (config->console == NULL) {
+ config->console = malloc(512);
+ strncpy(config->console, config->sessiondir, 512);
+ strncat(config->console, "/AFB-console.out", 512);
+ }
}
struct afb_config *afb_config_parse_arguments(int argc, char **argv)
@@ -523,5 +527,6 @@ struct afb_config *afb_config_parse_arguments(int argc, char **argv)
result = calloc(1, sizeof *result);
parse_arguments(argc, argv, result);
+ config_set_default(result);
return result;
}