afb-config Copies the values of option --exec
[src/app-framework-binder.git] / src / afb-config.c
1 /*
2  * Copyright (C) 2015, 2016, 2017 "IoT.bzh"
3  * Author José Bollo <jose.bollo@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #define _GNU_SOURCE
19 #define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <getopt.h>
25 #include <limits.h>
26 #include <unistd.h>
27
28 #include "verbose.h"
29 #include "afb-config.h"
30 #include "afb-hook.h"
31
32 #include <afb/afb-binding-v1.h>
33
34 #if !defined(BINDING_INSTALL_DIR)
35 #error "you should define BINDING_INSTALL_DIR"
36 #endif
37
38 #define AFB_VERSION    "0.6"
39
40 // default
41 #define DEFLT_CNTX_TIMEOUT  3600        // default Client Connection
42                                         // Timeout
43 #define DEFLT_API_TIMEOUT   20          // default Plugin API Timeout [0=NoLimit
44                                         // for Debug Only]
45 #define DEFLT_CACHE_TIMEOUT 100000      // default Static File Chache
46                                         // [Client Side Cache
47                                         // 100000~=1day]
48 #define CTX_NBCLIENTS       10          // allow a default of 10 authenticated
49                                         // clients
50
51
52 // Define command line option
53 #define SET_BACKGROUND     2
54 #define SET_FORGROUND      3
55
56 #define SET_ROOT_DIR       6
57 #define SET_ROOT_BASE      7
58 #define SET_ROOT_API       8
59 #define SET_ALIAS          9
60
61 #define SET_CACHE_TIMEOUT  10
62 #define SET_SESSION_DIR    11
63
64 #define SET_LDPATH         13
65 #define SET_APITIMEOUT     14
66 #define SET_CNTXTIMEOUT    15
67 #define SET_WEAK_LDPATH    16
68 #define NO_LDPATH          17
69
70 #define SET_MODE           18
71
72 #define DBUS_CLIENT        20
73 #define DBUS_SERVICE       21
74 #define SO_BINDING         22
75
76 #define SET_SESSIONMAX     23
77
78 #define WS_CLIENT          24
79 #define WS_SERVICE         25
80
81 #define SET_ROOT_HTTP      26
82
83 #define SET_NO_HTTPD       28
84
85 #define ADD_CALL           'c'
86 #define SET_TRACEDITF      'D'
87 #define SET_TRACEEVT       'E'
88 #define SET_EXEC           'e'
89 #define DISPLAY_HELP       'h'
90 #if defined(WITH_MONITORING_OPTION)
91 #define SET_MONITORING     'M'
92 #endif
93 #define SET_NAME           'n'
94 #define SET_TCP_PORT       'p'
95 #define SET_QUIET          'q'
96 #define SET_RNDTOKEN       'r'
97 #define SET_TRACESVC       'S'
98 #define SET_TRACEREQ       'T'
99 #define SET_AUTH_TOKEN     't'
100 #define SET_UPLOAD_DIR     'u'
101 #define DISPLAY_VERSION    'V'
102 #define SET_VERBOSE        'v'
103 #define SET_WORK_DIR       'w'
104
105 const char shortopts[] =
106         "c:D:E:ehn:p:qrT:t:u:Vvw:"
107 #if defined(WITH_MONITORING_OPTION)
108         "M"
109 #endif
110 ;
111
112 // Command line structure hold cli --command + help text
113 typedef struct {
114         int val;                // command number within application
115         int has_arg;            // command number within application
116         char *name;             // command as used in --xxxx cli
117         char *help;             // help text
118 } AFB_options;
119
120 // Supported option
121 static AFB_options cliOptions[] = {
122 /* *INDENT-OFF* */
123         {SET_VERBOSE,       0, "verbose",     "Verbose Mode, repeat to increase verbosity"},
124         {SET_QUIET,         0, "quiet",       "Quiet Mode, repeat to decrease verbosity"},
125
126         {SET_FORGROUND,     0, "foreground",  "Get all in foreground mode"},
127         {SET_BACKGROUND,    0, "daemon",      "Get all in background mode"},
128
129         {SET_NAME,          1, "name",        "Set the visible name"},
130
131         {SET_TCP_PORT,      1, "port",        "HTTP listening TCP port  [default 1234]"},
132         {SET_ROOT_HTTP,     1, "roothttp",    "HTTP Root Directory [default no root http (files not served but apis still available)]"},
133         {SET_ROOT_BASE,     1, "rootbase",    "Angular Base Root URL [default /opa]"},
134         {SET_ROOT_API,      1, "rootapi",     "HTML Root API URL [default /api]"},
135         {SET_ALIAS,         1, "alias",       "Multiple url map outside of rootdir [eg: --alias=/icons:/usr/share/icons]"},
136
137         {SET_APITIMEOUT,    1, "apitimeout",  "Binding API timeout in seconds [default 10]"},
138         {SET_CNTXTIMEOUT,   1, "cntxtimeout", "Client Session Context Timeout [default 900]"},
139         {SET_CACHE_TIMEOUT, 1, "cache-eol",   "Client cache end of live [default 3600]"},
140
141         {SET_WORK_DIR,      1, "workdir",     "Set the working directory [default: $PWD or current working directory]"},
142         {SET_UPLOAD_DIR,    1, "uploaddir",   "Directory for uploading files [default: workdir]"},
143         {SET_ROOT_DIR,      1, "rootdir",     "Root Directory of the application [default: workdir]"},
144         {SET_SESSION_DIR,   1, "sessiondir",  "OBSOLETE (was: Sessions file path)"},
145
146         {SET_LDPATH,        1, "ldpaths",     "Load bindings from dir1:dir2:... [default = " BINDING_INSTALL_DIR "]"},
147         {SO_BINDING,        1, "binding",     "Load the binding of path"},
148         {SET_WEAK_LDPATH,   1, "weak-ldpaths","Same as --ldpaths but ignore errors"},
149         {NO_LDPATH,         0, "no-ldpaths",  "Discard default ldpaths loading"},
150
151         {SET_AUTH_TOKEN,    1, "token",       "Initial Secret [default=no-session, --token= for session without authentication]"},
152         {SET_RNDTOKEN,      0, "random-token","Enforce a random token"},
153
154         {DISPLAY_VERSION,   0, "version",     "Display version and copyright"},
155         {DISPLAY_HELP,      0, "help",        "Display this help"},
156
157         {SET_MODE,          1, "mode",        "Set the mode: either local, remote or global"},
158
159         {DBUS_CLIENT,       1, "dbus-client", "Bind to an afb service through dbus"},
160         {DBUS_SERVICE,      1, "dbus-server", "Provides an afb service through dbus"},
161         {WS_CLIENT,         1, "ws-client",   "Bind to an afb service through websocket"},
162         {WS_SERVICE,        1, "ws-server",   "Provides an afb service through websockets"},
163
164         {SET_SESSIONMAX,    1, "session-max", "Max count of session simultaneously [default 10]"},
165
166         {SET_TRACEREQ,      1, "tracereq",    "Log the requests: no, common, extra, all"},
167         {SET_TRACEDITF,     1, "traceditf",   "Log the requests: no, common, extra, all"},
168         {SET_TRACESVC,      1, "tracesvc",    "Log the requests: no, all"},
169         {SET_TRACEEVT,      1, "traceevt",    "Log the requests: no, common, extra, all"},
170
171         {ADD_CALL,          1, "call",        "call at start format of val: API/VERB:json-args"},
172
173         {SET_NO_HTTPD,      0, "no-httpd",    "Forbids HTTP service"},
174         {SET_EXEC,          0, "exec",        "Execute the remaining arguments"},
175
176 #if defined(WITH_MONITORING_OPTION)
177         {SET_MONITORING,    0, "monitoring",  "enable HTTP monitoring at <ROOT>/monitoring/"},
178 #endif
179         {0, 0, NULL, NULL}
180 /* *INDENT-ON* */
181 };
182
183
184 struct enumdesc
185 {
186         const char *name;
187         int value;
188 };
189
190 static struct enumdesc tracereq_desc[] = {
191         { "no",     0 },
192         { "common", afb_hook_flags_req_common },
193         { "extra",  afb_hook_flags_req_extra },
194         { "all",    afb_hook_flags_req_all },
195         { NULL, 0 }
196 };
197
198 static struct enumdesc traceditf_desc[] = {
199         { "no",     0 },
200         { "common", afb_hook_flags_ditf_common },
201         { "extra",  afb_hook_flags_ditf_extra },
202         { "all",    afb_hook_flags_ditf_all },
203         { NULL, 0 }
204 };
205
206 static struct enumdesc tracesvc_desc[] = {
207         { "no",     0 },
208         { "all",    afb_hook_flags_svc_all },
209         { NULL, 0 }
210 };
211
212 static struct enumdesc traceevt_desc[] = {
213         { "no",     0 },
214         { "common", afb_hook_flags_evt_common },
215         { "extra",  afb_hook_flags_evt_extra },
216         { "all",    afb_hook_flags_evt_all },
217         { NULL, 0 }
218 };
219
220 static struct enumdesc mode_desc[] = {
221         { "local",  AFB_MODE_LOCAL },
222         { "remote", AFB_MODE_REMOTE },
223         { "global", AFB_MODE_GLOBAL },
224         { NULL, 0 }
225 };
226
227 /*----------------------------------------------------------
228  | printversion
229  |   print version and copyright
230  +--------------------------------------------------------- */
231 static void printVersion(FILE * file)
232 {
233         fprintf(file, "\n----------------------------------------- \n");
234         fprintf(file, "  AFB [Application Framework Binder] version=%s |\n",
235                 AFB_VERSION);
236         fprintf(file, " \n");
237         fprintf(file,
238                 "  Copyright (C) 2015, 2016, 2017 \"IoT.bzh\" [fulup -at- iot.bzh]\n");
239         fprintf(file, "  AFB comes with ABSOLUTELY NO WARRANTY.\n");
240         fprintf(file, "  Licence Apache 2\n\n");
241 }
242
243 /*----------------------------------------------------------
244  | printHelp
245  |   print information from long option array
246  +--------------------------------------------------------- */
247
248 static void printHelp(FILE * file, const char *name)
249 {
250         int ind;
251         char command[50];
252
253         fprintf(file, "%s:\nallowed options\n", name);
254         for (ind = 0; cliOptions[ind].name != NULL; ind++) {
255                 strcpy(command, cliOptions[ind].name);
256                 if (cliOptions[ind].has_arg)
257                         strcat(command, "=xxxx");
258                 fprintf(file, "  --%-15s %s\n", command, cliOptions[ind].help);
259         }
260         fprintf(file,
261                 "Example:\n  %s  --verbose --port=1234 --token='azerty' --ldpaths=build/bindings:/usr/lib64/agl/bindings\n",
262                 name);
263 }
264
265
266 /*----------------------------------------------------------
267  |   adds a string to the list
268  +--------------------------------------------------------- */
269 static void list_add(struct afb_config_list **head, char *value)
270 {
271         struct afb_config_list *item;
272
273         /*
274          * search tail
275          */
276         item = *head;
277         while (item != NULL) {
278                 head = &item->next;
279                 item = item->next;
280         }
281
282         /*
283          * alloc the item
284          */
285         item = malloc(sizeof *item);
286         if (item == NULL) {
287                 ERROR("out of memory");
288                 exit(1);
289         }
290
291         /*
292          * init the item
293          */
294         *head = item;
295         item->value = value;
296         item->next = NULL;
297 }
298
299 /*---------------------------------------------------------
300  |   helpers for argument scanning
301  +--------------------------------------------------------- */
302
303 static const char *name_of_option(int optc)
304 {
305         AFB_options *o = cliOptions;
306         while (o->name && o->val != optc)
307                 o++;
308         return o->name ? : "<unknown-option-name>";
309 }
310
311 static const char *current_argument(int optc)
312 {
313         if (optarg == 0) {
314                 ERROR("option [--%s] needs a value i.e. --%s=xxx",
315                       name_of_option(optc), name_of_option(optc));
316                 exit(1);
317         }
318         return optarg;
319 }
320
321 static char *argvalstr(int optc)
322 {
323         char *result = strdup(current_argument(optc));
324         if (result == NULL) {
325                 ERROR("can't alloc memory");
326                 exit(1);
327         }
328         return result;
329 }
330
331 static int argvalenum(int optc, struct enumdesc *desc)
332 {
333         int i;
334         size_t len;
335         char *list;
336         const char *name = current_argument(optc);
337
338         i = 0;
339         while(desc[i].name && strcmp(desc[i].name, name))
340                 i++;
341         if (!desc[i].name) {
342                 len = 0;
343                 i = 0;
344                 while(desc[i].name)
345                         len += strlen(desc[i++].name);
346                 list = malloc(len + i + i);
347                 if (!i || !list)
348                         ERROR("option [--%s] bad value (found %s)",
349                                 name_of_option(optc), name);
350                 else {
351                         i = 0;
352                         strcpy(list, desc[i].name ? : "");
353                         while(desc[++i].name)
354                                 strcat(strcat(list, ", "), desc[i].name);
355                         ERROR("option [--%s] bad value, only accepts values %s (found %s)",
356                                 name_of_option(optc), list, name);
357                 }
358                 free(list);
359                 exit(1);
360         }
361         return desc[i].value;
362 }
363
364 static int argvalint(int optc, int mini, int maxi, int base)
365 {
366         const char *beg, *end;
367         long int val;
368         beg = current_argument(optc);
369         val = strtol(beg, (char**)&end, base);
370         if (*end || end == beg) {
371                 ERROR("option [--%s] requires a valid integer (found %s)",
372                         name_of_option(optc), beg);
373                 exit(1);
374         }
375         if (val < (long int)mini || val > (long int)maxi) {
376                 ERROR("option [--%s] value out of bounds (not %d<=%ld<=%d)",
377                         name_of_option(optc), mini, val, maxi);
378                 exit(1);
379         }
380         return (int)val;
381 }
382
383 static int argvalintdec(int optc, int mini, int maxi)
384 {
385         return argvalint(optc, mini, maxi, 10);
386 }
387
388 static void noarg(int optc)
389 {
390         if (optarg != 0) {
391                 ERROR("option [--%s] need no value (found %s)", name_of_option(optc), optarg);
392                 exit(1);
393         }
394 }
395
396 static char **make_exec(char **argv)
397 {
398         char **result, *iter;
399         size_t length;
400         int i;
401
402         length = 0;
403         for (i = 0 ; argv[i] ; i++)
404                 length += strlen(argv[i]) + 1;
405
406         result = malloc(length + ((unsigned)(i + 1)) * sizeof *result);
407         if (result == NULL) {
408                 ERROR("can't alloc memory");
409                 exit(1);
410         }
411
412         iter = (char*)&result[i+1];
413         for (i = 0 ; argv[i] ; i++) {
414                 result[i] = iter;
415                 iter = stpcpy(iter, argv[i]) + 1;
416         }
417         result[i] = NULL;
418         return result;
419 }
420
421 /*---------------------------------------------------------
422  |   Parse option and launch action
423  +--------------------------------------------------------- */
424
425 static void parse_arguments(int argc, char **argv, struct afb_config *config)
426 {
427         char *programName = argv[0];
428         int optc, ind;
429         int nbcmd;
430         struct option *gnuOptions;
431
432         // ------------------ Process Command Line -----------------------
433
434         // build GNU getopt info from cliOptions
435         nbcmd = sizeof(cliOptions) / sizeof(AFB_options);
436         gnuOptions = malloc(sizeof(*gnuOptions) * (unsigned)nbcmd);
437         for (ind = 0; ind < nbcmd; ind++) {
438                 gnuOptions[ind].name = cliOptions[ind].name;
439                 gnuOptions[ind].has_arg = cliOptions[ind].has_arg;
440                 gnuOptions[ind].flag = 0;
441                 gnuOptions[ind].val = cliOptions[ind].val;
442         }
443
444         // get all options from command line
445         while ((optc = getopt_long(argc, argv, shortopts, gnuOptions, NULL)) != EOF) {
446                 switch (optc) {
447                 case SET_VERBOSE:
448                         verbosity++;
449                         break;
450
451                 case SET_QUIET:
452                         verbosity--;
453                         break;
454
455                 case SET_TCP_PORT:
456                         config->httpdPort = argvalintdec(optc, 1024, 32767);
457                         break;
458
459                 case SET_APITIMEOUT:
460                         config->apiTimeout = argvalintdec(optc, 0, INT_MAX);
461                         break;
462
463                 case SET_CNTXTIMEOUT:
464                         config->cntxTimeout = argvalintdec(optc, 0, INT_MAX);
465                         break;
466
467                 case SET_ROOT_DIR:
468                         config->rootdir = argvalstr(optc);
469                         INFO("Forcing Rootdir=%s", config->rootdir);
470                         break;
471
472                 case SET_ROOT_HTTP:
473                         config->roothttp = argvalstr(optc);
474                         INFO("Forcing Root HTTP=%s", config->roothttp);
475                         break;
476
477                 case SET_ROOT_BASE:
478                         config->rootbase = argvalstr(optc);
479                         INFO("Forcing Rootbase=%s", config->rootbase);
480                         break;
481
482                 case SET_ROOT_API:
483                         config->rootapi = argvalstr(optc);
484                         INFO("Forcing Rootapi=%s", config->rootapi);
485                         break;
486
487                 case SET_ALIAS:
488                         list_add(&config->aliases, argvalstr(optc));
489                         break;
490
491                 case SET_AUTH_TOKEN:
492                         config->token = argvalstr(optc);
493                         break;
494
495                 case SET_LDPATH:
496                         list_add(&config->ldpaths, argvalstr(optc));
497                         break;
498
499                 case SET_WEAK_LDPATH:
500                         list_add(&config->weak_ldpaths, argvalstr(optc));
501                         break;
502
503                 case NO_LDPATH:
504                         noarg(optc);
505                         config->no_ldpaths = 1;
506                         break;
507
508                 case ADD_CALL:
509                         list_add(&config->calls, argvalstr(optc));
510                         break;
511
512                 case SET_SESSION_DIR:
513                         /* config->sessiondir = argvalstr(optc); */
514                         WARNING("Obsolete option %s ignored", name_of_option(optc));
515                         break;
516
517                 case SET_UPLOAD_DIR:
518                         config->uploaddir = argvalstr(optc);
519                         break;
520
521                 case SET_WORK_DIR:
522                         config->workdir = argvalstr(optc);
523                         break;
524
525                 case SET_CACHE_TIMEOUT:
526                         config->cacheTimeout = argvalintdec(optc, 0, INT_MAX);
527                         break;
528
529                 case SET_SESSIONMAX:
530                         config->nbSessionMax = argvalintdec(optc, 1, INT_MAX);
531                         break;
532
533                 case SET_FORGROUND:
534                         noarg(optc);
535                         config->background = 0;
536                         break;
537
538                 case SET_BACKGROUND:
539                         noarg(optc);
540                         config->background = 1;
541                         break;
542
543                 case SET_NAME:
544                         config->name = argvalstr(optc);
545                         break;
546
547                 case SET_MODE:
548                         config->mode = argvalenum(optc, mode_desc);
549                         break;
550
551                 case DBUS_CLIENT:
552                         list_add(&config->dbus_clients, argvalstr(optc));
553                         break;
554
555                 case DBUS_SERVICE:
556                         list_add(&config->dbus_servers, argvalstr(optc));
557                         break;
558
559                 case WS_CLIENT:
560                         list_add(&config->ws_clients, argvalstr(optc));
561                         break;
562
563                 case WS_SERVICE:
564                         list_add(&config->ws_servers, argvalstr(optc));
565                         break;
566
567                 case SO_BINDING:
568                         list_add(&config->so_bindings, argvalstr(optc));
569                         break;
570
571                 case SET_TRACEREQ:
572                         config->tracereq = argvalenum(optc, tracereq_desc);
573                         break;
574
575                 case SET_TRACEDITF:
576                         config->traceditf = argvalenum(optc, traceditf_desc);
577                         break;
578
579                 case SET_TRACESVC:
580                         config->tracesvc = argvalenum(optc, tracesvc_desc);
581                         break;
582
583                 case SET_TRACEEVT:
584                         config->traceevt = argvalenum(optc, traceevt_desc);
585                         break;
586
587                 case SET_NO_HTTPD:
588                         noarg(optc);
589                         config->noHttpd = 1;
590                         break;
591
592                 case SET_EXEC:
593                         config->exec = make_exec(&argv[optind]);
594                         optind = argc; /* stop option scanning */
595                         break;
596
597                 case SET_RNDTOKEN:
598                         config->random_token = 1;
599                         break;
600
601 #if defined(WITH_MONITORING_OPTION)
602                 case SET_MONITORING:
603                         config->monitoring = 1;
604                         break;
605 #endif
606
607                 case DISPLAY_VERSION:
608                         noarg(optc);
609                         printVersion(stdout);
610                         exit(0);
611
612                 case DISPLAY_HELP:
613                         printHelp(stdout, programName);
614                         exit(0);
615
616                 default:
617                         exit(1);
618                 }
619         }
620         free(gnuOptions);
621 }
622
623 static void fulfill_config(struct afb_config *config)
624 {
625         // default HTTP port
626         if (config->httpdPort == 0)
627                 config->httpdPort = 1234;
628
629         // default binding API timeout
630         if (config->apiTimeout == 0)
631                 config->apiTimeout = DEFLT_API_TIMEOUT;
632
633         // default AUTH_TOKEN
634         if (config->random_token)
635                 config->token = NULL;
636
637         // cache timeout default one hour
638         if (config->cacheTimeout == 0)
639                 config->cacheTimeout = DEFLT_CACHE_TIMEOUT;
640
641         // cache timeout default one hour
642         if (config->cntxTimeout == 0)
643                 config->cntxTimeout = DEFLT_CNTX_TIMEOUT;
644
645         // max count of sessions
646         if (config->nbSessionMax == 0)
647                 config->nbSessionMax = CTX_NBCLIENTS;
648
649         /* set directories */
650         if (config->workdir == NULL)
651                 config->workdir = ".";
652
653         if (config->rootdir == NULL)
654                 config->rootdir = ".";
655
656         if (config->uploaddir == NULL)
657                 config->uploaddir = ".";
658
659         // if no Angular/HTML5 rootbase let's try '/' as default
660         if (config->rootbase == NULL)
661                 config->rootbase = "/opa";
662
663         if (config->rootapi == NULL)
664                 config->rootapi = "/api";
665
666         if (config->ldpaths == NULL && config->weak_ldpaths == NULL && !config->no_ldpaths)
667                 list_add(&config->ldpaths, BINDING_INSTALL_DIR);
668
669 #if defined(WITH_MONITORING_OPTION)
670         if (config->monitoring)
671                 list_add(&config->aliases, strdup("/monitoring:"BINDING_INSTALL_DIR"/monitoring"));
672 #endif
673
674         // if no config dir create a default path from uploaddir
675         if (config->console == NULL) {
676                 config->console = malloc(512);
677                 strncpy(config->console, config->uploaddir, 512);
678                 strncat(config->console, "/AFB-console.out", 512);
679         }
680 }
681
682 void afb_config_dump(struct afb_config *config)
683 {
684         struct afb_config_list *l;
685         struct enumdesc *e;
686         char **v;
687
688 #define NN(x)   (x)?:""
689 #define P(...)  fprintf(stderr, __VA_ARGS__)
690 #define PF(x)   P("-- %15s: ", #x)
691 #define PE      P("\n")
692 #define S(x)    PF(x);P("%s",NN(config->x));PE;
693 #define D(x)    PF(x);P("%d",config->x);PE;
694 #define H(x)    PF(x);P("%x",config->x);PE;
695 #define B(x)    PF(x);P("%s",config->x?"yes":"no");PE;
696 #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;
697 #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);}
698 #define V(x)    P("-- %15s:", #x);for(v=config->x;v&&*v;v++)P(" %s",*v); PE;
699
700         P("---BEGIN-OF-CONFIG---\n");
701         S(console)
702         S(rootdir)
703         S(roothttp)
704         S(rootbase)
705         S(rootapi)
706         S(workdir)
707         S(uploaddir)
708         S(token)
709         S(name)
710
711         L(aliases)
712         L(dbus_clients)
713         L(dbus_servers)
714         L(ws_clients)
715         L(ws_servers)
716         L(so_bindings)
717         L(ldpaths)
718         L(weak_ldpaths)
719         L(calls)
720
721         V(exec)
722
723         D(httpdPort)
724         D(cacheTimeout)
725         D(apiTimeout)
726         D(cntxTimeout)
727         D(nbSessionMax)
728
729         E(mode,mode_desc)
730         E(tracereq,tracereq_desc)
731         E(traceditf,traceditf_desc)
732         E(tracesvc,tracesvc_desc)
733         E(traceevt,traceevt_desc)
734
735         B(no_ldpaths)
736         B(noHttpd)
737         B(background)
738         B(monitoring)
739         B(random_token)
740         P("---END-OF-CONFIG---\n");
741
742 #undef V
743 #undef E
744 #undef L
745 #undef B
746 #undef H
747 #undef D
748 #undef S
749 #undef PE
750 #undef PF
751 #undef P
752 #undef NN
753 }
754
755 struct afb_config *afb_config_parse_arguments(int argc, char **argv)
756 {
757         struct afb_config *result;
758
759         result = calloc(1, sizeof *result);
760
761         parse_arguments(argc, argv, result);
762         fulfill_config(result);
763         if (verbosity >= 3)
764                 afb_config_dump(result);
765         return result;
766 }
767