afb-stub-ws: Allow unordered process of messages
[src/app-framework-binder.git] / src / afs-config.c
index 3cb851b..2d42968 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2018 "IoT.bzh"
+ * Copyright (C) 2015-2019 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
 #include "afs-config.h"
 
 #if !defined(AFB_VERSION)
-#error "you should define AFB_VERSION"
+#  error "you should define AFB_VERSION"
 #endif
 
+#if !defined(AFS_SUPERVISOR_TOKEN)
+#  define AFS_SUPERVISOR_TOKEN    ""
+#endif
+#if !defined(AFS_SUPERVISOR_PORT)
+#  define AFS_SUPERVISOR_PORT     1619
+#endif
+#define _STRINGIFY_(x) #x
+#define STRINGIFY(x) _STRINGIFY_(x)
+
 // default
 #define DEFLT_CNTX_TIMEOUT  32000000   // default Client Connection
                                        // Timeout: few more than one year
@@ -62,6 +71,7 @@
 #define SET_NAME           'n'
 #define SET_TCP_PORT       'p'
 #define SET_QUIET          'q'
+#define WS_SERVICE         's'
 #define SET_AUTH_TOKEN     't'
 #define SET_UPLOAD_DIR     'u'
 #define DISPLAY_VERSION    'V'
@@ -69,7 +79,7 @@
 #define SET_WORK_DIR       'w'
 
 const char shortopts[] =
-       "hn:p:qrt:u:Vvw:"
+       "hn:p:qrs:t:u:Vvw:"
 ;
 
 // Command line structure hold cli --command + help text
@@ -88,7 +98,7 @@ static AFB_options cliOptions[] = {
 
        {SET_NAME,          1, "name",        "Set the visible name"},
 
-       {SET_TCP_PORT,      1, "port",        "HTTP listening TCP port  [default 1234]"},
+       {SET_TCP_PORT,      1, "port",        "HTTP listening TCP port  [default " STRINGIFY(AFS_SUPERVISOR_PORT) "]"},
        {SET_ROOT_HTTP,     1, "roothttp",    "HTTP Root Directory [default no root http (files not served but apis still available)]"},
        {SET_ROOT_BASE,     1, "rootbase",    "Angular Base Root URL [default /opa]"},
        {SET_ROOT_API,      1, "rootapi",     "HTML Root API URL [default /api]"},
@@ -102,8 +112,9 @@ static AFB_options cliOptions[] = {
        {SET_ROOT_DIR,      1, "rootdir",     "Root Directory of the application [default: workdir]"},
        {SET_SESSION_DIR,   1, "sessiondir",  "OBSOLETE (was: Sessions file path)"},
 
-       {SET_AUTH_TOKEN,    1, "token",       "Initial Secret [default=random, use --token="" to allow any token]"},
+       {SET_AUTH_TOKEN,    1, "token",       "Initial Secret [default=" AFS_SUPERVISOR_TOKEN ", use --token="" to allow any token]"},
 
+       {WS_SERVICE,        1, "ws-server",   "Provide supervisor as websocket"},
        {DISPLAY_VERSION,   0, "version",     "Display version and copyright"},
        {DISPLAY_HELP,      0, "help",        "Display this help"},
 
@@ -130,7 +141,7 @@ static void printVersion(FILE * file)
                "\n"
                "  afs-supervisor [Application Framework Supervisor] version="AFB_VERSION"\n"
                "\n"
-               "  Copyright (C) 2015-2018 \"IoT.bzh\"\n"
+               "  Copyright (C) 2015-2019 \"IoT.bzh\"\n"
                "  afs-supervisor comes with ABSOLUTELY NO WARRANTY.\n"
                "  Licence Apache 2\n"
                "\n";
@@ -252,11 +263,11 @@ static void parse_arguments(int argc, char **argv, struct afs_config *config)
        while ((optc = getopt_long(argc, argv, shortopts, gnuOptions, NULL)) != EOF) {
                switch (optc) {
                case SET_VERBOSE:
-                       verbosity++;
+                       verbose_inc();
                        break;
 
                case SET_QUIET:
-                       verbosity--;
+                       verbose_dec();
                        break;
 
                case SET_TCP_PORT:
@@ -315,6 +326,10 @@ static void parse_arguments(int argc, char **argv, struct afs_config *config)
                        config->name = argvalstr(optc);
                        break;
 
+               case WS_SERVICE:
+                       config->ws_server = argvalstr(optc);
+                       break;
+
                case DISPLAY_VERSION:
                        noarg(optc);
                        printVersion(stdout);
@@ -335,7 +350,7 @@ static void fulfill_config(struct afs_config *config)
 {
        // default HTTP port
        if (config->httpdPort == 0)
-               config->httpdPort = 1234;
+               config->httpdPort = AFS_SUPERVISOR_PORT;
 
        // default binding API timeout
        if (config->apiTimeout == 0)
@@ -369,6 +384,9 @@ static void fulfill_config(struct afs_config *config)
 
        if (config->rootapi == NULL)
                config->rootapi = "/api";
+
+       if (config->token == NULL)
+               config->token = AFS_SUPERVISOR_TOKEN;
 }
 
 void afs_config_dump(struct afs_config *config)
@@ -389,6 +407,7 @@ void afs_config_dump(struct afs_config *config)
        S(uploaddir)
        S(token)
        S(name)
+       S(ws_server)
 
        D(httpdPort)
        D(cacheTimeout)
@@ -422,7 +441,7 @@ struct afs_config *afs_config_parse_arguments(int argc, char **argv)
        parse_environment(result);
        parse_arguments(argc, argv, result);
        fulfill_config(result);
-       if (verbosity >= 3)
+       if (verbose_wants(Log_Level_Info))
                afs_config_dump(result);
        return result;
 }