+// load config from disk and merge with CLI option
+static AFB_error config_set_default (AFB_session * session)
+{
+ static char cacheTimeout [10];
+
+ // default HTTP port
+ if (session->config->httpdPort == 0) session->config->httpdPort=1234;
+
+ // default Plugin API timeout
+ if (session->config->apiTimeout == 0) session->config->apiTimeout=DEFLT_API_TIMEOUT;
+
+ // default AUTH_TOKEN
+ if (session->config->token == NULL) session->config->token= DEFLT_AUTH_TOKEN;
+
+ // cache timeout default one hour
+ if (session->config->cacheTimeout == 0) session->config->cacheTimeout=DEFLT_CACHE_TIMEOUT;
+
+ // cache timeout default one hour
+ if (session->config->cntxTimeout == 0) session->config->cntxTimeout=DEFLT_CNTX_TIMEOUT;
+
+ if (session->config->rootdir == NULL) {
+ session->config->rootdir = getenv("AFBDIR");
+ if (session->config->rootdir == NULL) {
+ session->config->rootdir = malloc (512);
+ strncpy (session->config->rootdir, getenv("HOME"),512);
+ strncat (session->config->rootdir, "/.AFB",512);
+ }
+ // if directory does not exist createit
+ mkdir (session->config->rootdir, O_RDWR | S_IRWXU | S_IRGRP);
+ }
+
+ // if no Angular/HTML5 rootbase let's try '/' as default
+ if (session->config->rootbase == NULL) {
+ session->config->rootbase = "/opa";
+ }
+
+ if (session->config->rootapi == NULL) {
+ session->config->rootapi = "/api";
+ }
+
+ if (session->config->ldpaths == NULL) {
+ session->config->ldpaths = PLUGIN_INSTALL_DIR;
+ }
+
+ // if no session dir create a default path from rootdir
+ if (session->config->sessiondir == NULL) {
+ session->config->sessiondir = malloc (512);
+ strncpy (session->config->sessiondir, session->config->rootdir, 512);
+ strncat (session->config->sessiondir, "/sessions",512);
+ }
+
+ // if no config dir create a default path from sessiondir
+ if (session->config->console == NULL) {
+ session->config->console = malloc (512);
+ strncpy (session->config->console, session->config->sessiondir, 512);
+ strncat (session->config->console, "/AFB-console.out",512);
+ }
+
+ // cacheTimeout is an integer but HTTPd wants it as a string
+ snprintf (cacheTimeout, sizeof (cacheTimeout),"%d", session->config->cacheTimeout);
+ session->cacheTimeout = cacheTimeout; // httpd uses cacheTimeout string version
+
+ return AFB_SUCCESS;