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