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