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;
item->next = NULL;
}
+/*---------------------------------------------------------
+ | helpers for argument scanning
+ +--------------------------------------------------------- */
+
static char *argvalstr(int index)
{
if (optarg == 0) {
}
}
+/*---------------------------------------------------------
+ | Parse option and launch action
+ +--------------------------------------------------------- */
+
static void parse_arguments(int argc, char **argv, struct afb_config *config)
{
char *programName = argv[0];
}
// 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++;
break;
case SET_LDPATH:
- config->ldpaths = argvalstr(optionIndex);
+ list_add(&config->ldpaths, argvalstr(optionIndex));
break;
case SET_SESSION_DIR:
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)
result = calloc(1, sizeof *result);
parse_arguments(argc, argv, result);
+ config_set_default(result);
return result;
}
config->token, afb_apis_count());
afb_api_so_set_timeout(config->apiTimeout);
- if (config->ldpaths) {
- if (afb_api_so_add_pathset(config->ldpaths) < 0) {
- ERROR("initialisation of bindings within %s failed",
- config->ldpaths);
- exit(1);
- }
- }
-
- start_list(config->dbus_clients, afb_api_dbus_add_client,
- "the afb-dbus client");
- start_list(config->ws_clients, afb_api_ws_add_client,
- "the afb-websocket client");
+ start_list(config->dbus_clients, afb_api_dbus_add_client, "the afb-dbus client");
+ start_list(config->ws_clients, afb_api_ws_add_client, "the afb-websocket client");
+ start_list(config->ldpaths, afb_api_so_add_pathset, "the binding path set");
start_list(config->so_bindings, afb_api_so_add_binding, "the binding");
- start_list(config->dbus_servers, afb_api_dbus_add_server,
- "the afb-dbus service");
- start_list(config->ws_servers, afb_api_ws_add_server,
- "the afb-websocket service");
+ start_list(config->dbus_servers, afb_api_dbus_add_server, "the afb-dbus service");
+ start_list(config->ws_servers, afb_api_ws_add_server, "the afb-websocket service");
if (!afb_hreq_init_cookie
(config->httpdPort, config->rootapi, config->cntxTimeout)) {