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