Update copyright dates
[src/app-framework-binder.git] / src / afb-args.c
index 1dc2e6c..c669fcd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2019 "IoT.bzh"
+ * Copyright (C) 2015-2020 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,9 +38,6 @@
 #define _d2s_(x)  #x
 #define d2s(x)    _d2s_(x)
 
-#if !defined(BINDING_INSTALL_DIR)
-#error "you should define BINDING_INSTALL_DIR"
-#endif
 #if !defined(AFB_VERSION)
 #error "you should define AFB_VERSION"
 #endif
 
 #define SET_CACHE_TIMEOUT    7
 
-#define AUTO_WS              8
-#define AUTO_LINK            9
-
+#if WITH_DYNAMIC_BINDING
 #define ADD_LDPATH          10
-#define SET_API_TIMEOUT     11
-#define SET_SESSION_TIMEOUT 12
-#define ADD_WEAK_LDPATH     13
-#define SET_NO_LDPATH       14
+#define ADD_WEAK_LDPATH     11
+#define SET_NO_LDPATH       12
+#endif
+#define SET_API_TIMEOUT     13
+#define SET_SESSION_TIMEOUT 14
 
 #define SET_SESSIONMAX      15
 
 #endif
 
 #define ADD_AUTO_API       'A'
+#if WITH_DYNAMIC_BINDING
 #define ADD_BINDING        'b'
+#endif
 #define SET_CONFIG         'C'
 #define SET_COLOR          'c'
 #define SET_DAEMON         'D'
 #define SET_EXEC           'e'
 #define GET_HELP           'h'
+#define ADD_INTERFACE      'i'
 #define SET_LOG            'l'
 #if defined(WITH_MONITORING_OPTION)
 #define SET_MONITORING     'M'
@@ -160,7 +159,8 @@ static struct option_desc optdefs[] = {
 
        {SET_NAME,            1, "name",        "Set the visible name"},
 
-       {SET_PORT,            1, "port",        "HTTP listening TCP port  [default " d2s(DEFAULT_HTTP_PORT) "]"},
+       {SET_PORT,            1, "port",        "HTTP listening TCP port of all interfaces [default " d2s(DEFAULT_HTTP_PORT) "]"},
+       {ADD_INTERFACE,       1, "interface",   "Add HTTP listening interface (ex: tcp:localhost:8080)"},
        {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]"},
@@ -174,11 +174,17 @@ static struct option_desc optdefs[] = {
        {SET_UPLOAD_DIR,      1, "uploaddir",   "Directory for uploading files [default: workdir] relative to workdir"},
        {SET_ROOT_DIR,        1, "rootdir",     "Root Directory of the application [default: workdir] relative to workdir"},
 
-       {ADD_LDPATH,          1, "ldpaths",     "Load bindings from dir1:dir2:... [default = " BINDING_INSTALL_DIR "]"},
+#if WITH_DYNAMIC_BINDING
+
+       {ADD_LDPATH,          1, "ldpaths",     "Load bindings from dir1:dir2:..."
+#if defined(INTRINSIC_BINDING_DIR)
+                                               "[default = " INTRINSIC_BINDING_DIR "]"
+#endif
+                                               },
        {ADD_BINDING,         1, "binding",     "Load the binding of path"},
        {ADD_WEAK_LDPATH,     1, "weak-ldpaths","Same as --ldpaths but ignore errors"},
        {SET_NO_LDPATH,       0, "no-ldpaths",  "Discard default ldpaths loading"},
-
+#endif
        {SET_TOKEN,           1, "token",       "Initial Secret [default=random, use --token="" to allow any token]"},
        {SET_RANDOM_TOKEN,    0, "random-token","Enforce a random token"},
 
@@ -230,14 +236,13 @@ static struct option_desc optdefs[] = {
 };
 
 #if defined(WITH_MONITORING_OPTION)
-static const char MONITORING_ALIAS[] = "/monitoring:"BINDING_INSTALL_DIR"/monitoring";
+static const char MONITORING_ALIAS[] = "/monitoring:"INTRINSIC_BINDING_DIR"/monitoring";
 #endif
 
 static const struct {
        int optid;
        int valdef;
 } default_optint_values[] = {
-       { SET_PORT,             DEFAULT_HTTP_PORT },
        { SET_API_TIMEOUT,      DEFAULT_API_TIMEOUT },
        { SET_CACHE_TIMEOUT,    DEFAULT_CACHE_TIMEOUT },
        { SET_SESSION_TIMEOUT,  DEFAULT_SESSION_TIMEOUT },
@@ -362,37 +367,35 @@ static void printVersion(FILE * file)
 #endif
                "HOOK "
 
-#if WITH_TRACE
+#if WITH_AFB_TRACE
                "+"
 #else
                "-"
 #endif
                "TRACE "
 
-               "[BINDINGS "
-#if WITH_LEGACY_BINDING_V1
+               "["
+#if WITH_DYNAMIC_BINDING
                "+"
 #else
                "-"
 #endif
-               "V1 "
+               "BINDINGS "
+#if WITH_LEGACY_BINDING_V1
+               "+V1 "
+#endif
 #if WITH_LEGACY_BINDING_VDYN
-               "+"
-#else
-               "-"
+               "+VDYN "
 #endif
-               "VDYN "
 #if WITH_LEGACY_BINDING_V2
-               "+"
-#else
-               "-"
+               "+V2 "
 #endif
-               "V2 +V3]\n"
+               "+V3]\n"
                "\n",
                AFB_VERSION
        );
        fprintf(file,
-               "  Copyright (C) 2015-2019 \"IoT.bzh\"\n"
+               "  Copyright (C) 2015-2020 \"IoT.bzh\"\n"
                "  AFB comes with ABSOLUTELY NO WARRANTY.\n"
                "  Licence Apache 2\n"
                "\n");
@@ -426,7 +429,11 @@ static void printHelp(FILE * file, const char *name)
        fprintf(file,
                "Example:\n  %s  --verbose --port="
                d2s(DEFAULT_HTTP_PORT)
-               " --token='azerty' --ldpaths=build/bindings:/usr/lib64/agl/bindings\n",
+               " --token='azerty'"
+#if WITH_DYNAMIC_BINDING
+               " --ldpaths=build/bindings:/usr/lib64/agl/bindings"
+#endif
+               "\n",
                name);
 }
 
@@ -826,13 +833,16 @@ static void parse_arguments_inner(int argc, char **argv, struct json_object *con
                case ADD_DBUS_SERVICE:
 #endif
                case ADD_ALIAS:
+#if WITH_DYNAMIC_BINDING
                case ADD_LDPATH:
                case ADD_WEAK_LDPATH:
+               case ADD_BINDING:
+#endif
                case ADD_CALL:
                case ADD_WS_CLIENT:
                case ADD_WS_SERVICE:
-               case ADD_BINDING:
                case ADD_AUTO_API:
+               case ADD_INTERFACE:
                        config_add_optstr(config, optid);
                        break;
 
@@ -845,7 +855,9 @@ static void parse_arguments_inner(int argc, char **argv, struct json_object *con
 #endif
                case SET_RANDOM_TOKEN:
                case SET_NO_HTTPD:
+#if WITH_DYNAMIC_BINDING
                case SET_NO_LDPATH:
+#endif
                        noarg(optid);
                        config_set_bool(config, optid, 1);
                        break;
@@ -975,12 +987,17 @@ static void fulfill_config(struct json_object *config)
                if (!config_has(config, default_optstr_values[i].optid))
                        config_set_str(config, default_optstr_values[i].optid, default_optstr_values[i].valdef);
 
+       if (!config_has(config, SET_PORT) && !config_has(config, ADD_INTERFACE) && !config_has_bool(config, SET_NO_HTTPD))
+               config_set_int(config, SET_PORT, DEFAULT_HTTP_PORT);
+
        // default AUTH_TOKEN
        if (config_has_bool(config, SET_RANDOM_TOKEN))
                config_del(config, SET_TOKEN);
 
+#if WITH_DYNAMIC_BINDING && defined(INTRINSIC_BINDING_DIR)
        if (!config_has(config, ADD_LDPATH) && !config_has(config, ADD_WEAK_LDPATH) && !config_has_bool(config, SET_NO_LDPATH))
-               config_add_str(config, ADD_LDPATH, BINDING_INSTALL_DIR);
+               config_add_str(config, ADD_LDPATH, INTRINSIC_BINDING_DIR);
+#endif
 
 #if defined(WITH_MONITORING_OPTION)
        if (config_has_bool(config, SET_MONITORING) && !config_has_str(config, ADD_ALIAS, MONITORING_ALIAS))
@@ -1040,7 +1057,9 @@ static void parse_environment(struct json_object *config)
        on_environment_enum(config, SET_TRACESVC, "AFB_TRACESVC", afb_hook_flags_legacy_svc_from_text);
 #endif
 #endif
+#if WITH_DYNAMIC_BINDING
        on_environment(config, ADD_LDPATH, "AFB_LDPATHS", config_add_str);
+#endif
        on_environment(config, ADD_SET, "AFB_SET", config_mix2_str);
        on_environment_bool(config, SET_TRAP_FAULTS, "AFB_TRAP_FAULTS");
 }