X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-config.c;h=80dde93f76da6b6fc54784ada31170a28cbb739e;hb=4be084408c6d3d7b7f90a2493829c8ce0cebb397;hp=c48c48045679c0d4373dda5af3ec6820f6657e5f;hpb=a76eb15251a08240e91fbffd96eb178bddd82330;p=src%2Fapp-framework-binder.git diff --git a/src/afb-config.c b/src/afb-config.c index c48c4804..80dde93f 100644 --- a/src/afb-config.c +++ b/src/afb-config.c @@ -16,13 +16,14 @@ */ #define _GNU_SOURCE -#define NO_BINDING_VERBOSE_MACRO +#define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO #include #include #include #include #include +#include #include @@ -36,7 +37,7 @@ #error "you should define BINDING_INSTALL_DIR" #endif -#define AFB_VERSION "0.5" +#define AFB_VERSION "0.6" // default #define DEFLT_CNTX_TIMEOUT 3600 // default Client Connection @@ -70,7 +71,6 @@ #define SET_MODE 18 -#define SET_READYFD 19 #define DBUS_CLIENT 20 #define DBUS_SERVICE 21 @@ -85,16 +85,20 @@ #define SET_NO_HTTPD 28 +#define ADD_CALL 'c' +#define SET_TRACEDITF 'D' #define SET_EXEC 'e' #define DISPLAY_HELP 'h' #define SET_QUIET 'q' #define SET_RNDTOKEN 'r' #define SET_TRACEREQ 'T' #define SET_AUTH_TOKEN 't' +#define SET_UPLOAD_DIR 'u' #define DISPLAY_VERSION 'V' #define SET_VERBOSE 'v' +#define SET_WORK_DIR 'w' -#define SHORTOPTS "ehqrT:t:Vv" +#define SHORTOPTS "c:D:ehqrT:t:u:Vvw:" // Command line structure hold cli --command + help text typedef struct { @@ -114,40 +118,44 @@ static AFB_options cliOptions[] = { {SET_BACKGROUND, 0, "daemon", "Get all in background mode"}, {SET_TCP_PORT, 1, "port", "HTTP listening TCP port [default 1234]"}, - {SET_ROOT_DIR, 1, "rootdir", "Root Directory [default $HOME/.AFB]"}, - {SET_ROOT_HTTP, 1, "roothttp", "HTTP Root Directory [default rootdir]"}, + {SET_ROOT_HTTP, 1, "roothttp", "HTTP Root Directory [default no root http (files not served but apis still available)]"}, {SET_ROOT_BASE, 1, "rootbase", "Angular Base Root URL [default /opa]"}, {SET_ROOT_API, 1, "rootapi", "HTML Root API URL [default /api]"}, - {SET_ALIAS, 1, "alias", "Muliple url map outside of rootdir [eg: --alias=/icons:/usr/share/icons]"}, + {SET_ALIAS, 1, "alias", "Multiple url map outside of rootdir [eg: --alias=/icons:/usr/share/icons]"}, {SET_APITIMEOUT, 1, "apitimeout", "Binding API timeout in seconds [default 10]"}, {SET_CNTXTIMEOUT, 1, "cntxtimeout", "Client Session Context Timeout [default 900]"}, {SET_CACHE_TIMEOUT, 1, "cache-eol", "Client cache end of live [default 3600]"}, - {SET_SESSION_DIR, 1, "sessiondir", "Sessions file path [default rootdir/sessions]"}, + {SET_WORK_DIR, 1, "workdir", "Set the working directory [default: $PWD or current working directory]"}, + {SET_UPLOAD_DIR, 1, "uploaddir", "Directory for uploading files [default: workdir]"}, + {SET_ROOT_DIR, 1, "rootdir", "Root Directory of the application [default: workdir]"}, + {SET_SESSION_DIR, 1, "sessiondir", "OBSOLETE (was: Sessions file path)"}, {SET_LDPATH, 1, "ldpaths", "Load bindings from dir1:dir2:... [default = " BINDING_INSTALL_DIR "]"}, + {SO_BINDING, 1, "binding", "Load the binding of path"}, + {SET_AUTH_TOKEN, 1, "token", "Initial Secret [default=no-session, --token= for session without authentication]"}, + {SET_RNDTOKEN, 0, "random-token","Creates a random token"}, {DISPLAY_VERSION, 0, "version", "Display version and copyright"}, {DISPLAY_HELP, 0, "help", "Display this help"}, {SET_MODE, 1, "mode", "Set the mode: either local, remote or global"}, - {SET_READYFD, 1, "readyfd", "Set the #fd to signal when ready"}, {DBUS_CLIENT, 1, "dbus-client", "Bind to an afb service through dbus"}, {DBUS_SERVICE, 1, "dbus-server", "Provides an afb service through dbus"}, {WS_CLIENT, 1, "ws-client", "Bind to an afb service through websocket"}, {WS_SERVICE, 1, "ws-server", "Provides an afb service through websockets"}, - {SO_BINDING, 1, "binding", "Load the binding of path"}, {SET_SESSIONMAX, 1, "session-max", "Max count of session simultaneously [default 10]"}, {SET_TRACEREQ, 1, "tracereq", "Log the requests: no, common, extra, all"}, + {SET_TRACEDITF, 1, "traceditf", "Log the requests: no, common, extra, all"}, + {ADD_CALL, 1, "call", "call at start format of val: API/VERB:json-args"}, {SET_NO_HTTPD, 0, "no-httpd", "Forbids HTTP service"}, {SET_EXEC, 0, "exec", "Execute the remaining arguments"}, - {SET_RNDTOKEN, 0, "random-token","creates a random token"}, {0, 0, NULL, NULL} /* *INDENT-ON* */ @@ -168,6 +176,14 @@ static struct enumdesc tracereq_desc[] = { { NULL, 0 } }; +static struct enumdesc traceditf_desc[] = { + { "no", 0 }, + { "common", afb_hook_flags_ditf_common }, + { "extra", afb_hook_flags_ditf_extra }, + { "all", afb_hook_flags_ditf_all }, + { NULL, 0 } +}; + static struct enumdesc mode_desc[] = { { "local", AFB_MODE_LOCAL }, { "remote", AFB_MODE_REMOTE }, @@ -234,7 +250,7 @@ static void list_add(struct afb_config_list **head, char *value) struct afb_config_list *item; /* - * search tail + * search tail */ item = *head; while (item != NULL) { @@ -243,7 +259,7 @@ static void list_add(struct afb_config_list **head, char *value) } /* - * alloc the item + * alloc the item */ item = malloc(sizeof *item); if (item == NULL) { @@ -252,7 +268,7 @@ static void list_add(struct afb_config_list **head, char *value) } /* - * init the item + * init the item */ *head = item; item->value = value; @@ -423,8 +439,21 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config) list_add(&config->ldpaths, argvalstr(optc)); break; + case ADD_CALL: + list_add(&config->calls, argvalstr(optc)); + break; + case SET_SESSION_DIR: - config->sessiondir = argvalstr(optc); + /* config->sessiondir = argvalstr(optc); */ + WARNING("Obsolete otpion %s ignored", optname(optc)); + break; + + case SET_UPLOAD_DIR: + config->uploaddir = argvalstr(optc); + break; + + case SET_WORK_DIR: + config->workdir = argvalstr(optc); break; case SET_CACHE_TIMEOUT: @@ -449,10 +478,6 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config) config->mode = argvalenum(optc, mode_desc); break; - case SET_READYFD: - config->readyfd = argvalintdec(optc, 0, INT_MAX); - break; - case DBUS_CLIENT: list_add(&config->dbus_clients, argvalstr(optc)); break; @@ -477,6 +502,10 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config) config->tracereq = argvalenum(optc, tracereq_desc); break; + case SET_TRACEDITF: + config->traceditf = argvalenum(optc, traceditf_desc); + break; + case SET_NO_HTTPD: noarg(optc); config->noHttpd = 1; @@ -534,14 +563,16 @@ static void config_set_default(struct afb_config *config) 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); - } - } + /* set directories */ + if (config->workdir == NULL) + config->workdir = "."; + + if (config->rootdir == NULL) + config->rootdir = "."; + + if (config->uploaddir == NULL) + config->uploaddir = "."; + // if no Angular/HTML5 rootbase let's try '/' as default if (config->rootbase == NULL) config->rootbase = "/opa"; @@ -552,16 +583,10 @@ static void config_set_default(struct afb_config *config) if (config->ldpaths == NULL) list_add(&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 no config dir create a default path from uploaddir if (config->console == NULL) { config->console = malloc(512); - strncpy(config->console, config->sessiondir, 512); + strncpy(config->console, config->uploaddir, 512); strncat(config->console, "/AFB-console.out", 512); } } @@ -590,7 +615,8 @@ void afb_config_dump(struct afb_config *config) S(roothttp) S(rootbase) S(rootapi) - S(sessiondir) + S(workdir) + S(uploaddir) S(token) L(aliases) @@ -600,18 +626,19 @@ void afb_config_dump(struct afb_config *config) L(ws_servers) L(so_bindings) L(ldpaths) + L(calls) V(exec) D(httpdPort) B(background) - D(readyfd) D(cacheTimeout) D(apiTimeout) D(cntxTimeout) D(nbSessionMax) E(mode,mode_desc) E(tracereq,tracereq_desc) + E(traceditf,traceditf_desc) B(noHttpd) P("---END-OF-CONFIG---\n");