+ // default AUTH_TOKEN
+ if (config->random_token)
+ config->token = NULL;
+
+ // 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;
+
+ /* 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";
+
+ if (config->rootapi == NULL)
+ config->rootapi = "/api";
+
+ if (config->ldpaths == NULL && config->weak_ldpaths == NULL && !config->no_ldpaths)
+ list_add(&config->ldpaths, BINDING_INSTALL_DIR);
+
+#if defined(WITH_MONITORING_OPTION)
+ if (config->monitoring)
+ list_add(&config->aliases, strdup("/monitoring:"BINDING_INSTALL_DIR"/monitoring"));
+#endif
+
+ // if no config dir create a default path from uploaddir
+ if (config->console == NULL) {
+ config->console = malloc(512);
+ strncpy(config->console, config->uploaddir, 512);
+ strncat(config->console, "/AFB-console.out", 512);
+ }
+}
+
+void afb_config_dump(struct afb_config *config)
+{
+ struct afb_config_list *l;
+ struct enumdesc *e;
+ char **v;
+
+#define NN(x) (x)?:""
+#define P(...) fprintf(stderr, __VA_ARGS__)
+#define PF(x) P("-- %15s: ", #x)
+#define PE P("\n")
+#define S(x) PF(x);P("%s",NN(config->x));PE;
+#define D(x) PF(x);P("%d",config->x);PE;
+#define H(x) PF(x);P("%x",config->x);PE;
+#define B(x) PF(x);P("%s",config->x?"yes":"no");PE;
+#define L(x) PF(x);l=config->x;if(l){P("%s\n",NN(l->value));for(l=l->next;l;l=l->next)P("-- %15s %s\n","",NN(l->value));}else PE;
+#define E(x,d) for(e=d;e->name&&e->value!=config->x;e++);if(e->name){PF(x);P("%s",e->name);PE;}else{D(x);}
+#define V(x) P("-- %15s:", #x);for(v=config->x;v&&*v;v++)P(" %s",*v); PE;
+
+ P("---BEGIN-OF-CONFIG---\n");
+ S(console)
+ S(rootdir)
+ S(roothttp)
+ S(rootbase)
+ S(rootapi)
+ S(workdir)
+ S(uploaddir)
+ S(token)
+ S(name)
+
+ L(aliases)
+ L(dbus_clients)
+ L(dbus_servers)
+ L(ws_clients)
+ L(ws_servers)
+ L(so_bindings)
+ L(ldpaths)
+ L(weak_ldpaths)
+ L(calls)
+
+ V(exec)
+
+ D(httpdPort)
+ D(cacheTimeout)
+ D(apiTimeout)
+ D(cntxTimeout)
+ D(nbSessionMax)
+
+ E(mode,mode_desc)
+ E(tracereq,tracereq_desc)
+ E(traceditf,traceditf_desc)
+ E(tracesvc,tracesvc_desc)
+ E(traceevt,traceevt_desc)
+
+ B(no_ldpaths)
+ B(noHttpd)
+ B(background)
+ B(monitoring)
+ B(random_token)
+ P("---END-OF-CONFIG---\n");
+
+#undef V
+#undef E
+#undef L
+#undef B
+#undef H
+#undef D
+#undef S
+#undef PE
+#undef PF
+#undef P
+#undef NN
+}
+
+static void on_environment_list(struct afb_config_list **to, const char *name)
+{
+ char *value = getenv(name);
+
+ if (value)
+ list_add(to, value);
+}
+
+static void on_environment_enum(int *to, const char *name, struct enumdesc *desc)
+{
+ char *value = getenv(name);
+
+ if (value) {
+ while (desc->name) {
+ if (strcmp(desc->name, value))
+ desc++;
+ else {
+ *to = desc->value;
+ return;
+ }
+ }
+ WARNING("Unknown value %s for environment variable %s, ignored", value, name);
+ }
+}
+
+static void parse_environment(struct afb_config *config)
+{
+ on_environment_enum(&config->tracereq, "AFB_TRACEREQ", tracereq_desc);
+ on_environment_enum(&config->traceditf, "AFB_TRACEDITF", traceditf_desc);
+ on_environment_enum(&config->tracesvc, "AFB_TRACESVC", tracesvc_desc);
+ on_environment_enum(&config->traceevt, "AFB_TRACEEVT", traceevt_desc);
+ on_environment_list(&config->ldpaths, "AFB_LDPATHS");