Add backward compatibility and remarks
[src/app-framework-binder.git] / src / afb-config.c
index de02547..dc3388e 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #define _GNU_SOURCE
-#define NO_BINDING_VERBOSE_MACRO
+#define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -31,7 +31,7 @@
 #include "afb-config.h"
 #include "afb-hook.h"
 
-#include <afb/afb-binding.h>
+#include <afb/afb-binding-v1.h>
 
 #if !defined(BINDING_INSTALL_DIR)
 #error "you should define BINDING_INSTALL_DIR"
@@ -71,7 +71,6 @@
 
 
 #define SET_MODE           18
-#define SET_READYFD        19
 
 #define DBUS_CLIENT        20
 #define DBUS_SERVICE       21
 
 #define SET_NO_HTTPD       28
 
+#define ADD_CALL           'c'
+#define SET_TRACEDITF      'D'
 #define SET_EXEC           'e'
 #define DISPLAY_HELP       'h'
 #define SET_QUIET          'q'
 #define SET_RNDTOKEN       'r'
+#define SET_TRACESVC       'S'
 #define SET_TRACEREQ       'T'
 #define SET_AUTH_TOKEN     't'
 #define SET_UPLOAD_DIR     'u'
@@ -97,7 +99,7 @@
 #define SET_VERBOSE        'v'
 #define SET_WORK_DIR       'w'
 
-#define SHORTOPTS      "ehqrT:t:u:Vvw:"
+#define SHORTOPTS      "c:D:ehqrT:t:u:Vvw:"
 
 // Command line structure hold cli --command + help text
 typedef struct {
@@ -117,10 +119,10 @@ static AFB_options cliOptions[] = {
        {SET_BACKGROUND,    0, "daemon",      "Get all in background mode"},
 
        {SET_TCP_PORT,      1, "port",        "HTTP listening TCP port  [default 1234]"},
-       {SET_ROOT_HTTP,     1, "roothttp",    "HTTP Root Directory [default rootdir]"},
+       {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]"},
-       {SET_ALIAS,         1, "alias",       "Muliple url map outside of rootdir [eg: --alias=/icons:/usr/share/icons]"},
+       {SET_ALIAS,         1, "alias",       "Multiple url map outside of rootdir [eg: --alias=/icons:/usr/share/icons]"},
 
        {SET_APITIMEOUT,    1, "apitimeout",  "Binding API timeout in seconds [default 10]"},
        {SET_CNTXTIMEOUT,   1, "cntxtimeout", "Client Session Context Timeout [default 900]"},
@@ -141,7 +143,6 @@ static AFB_options cliOptions[] = {
        {DISPLAY_HELP,      0, "help",        "Display this help"},
 
        {SET_MODE,          1, "mode",        "Set the mode: either local, remote or global"},
-       {SET_READYFD,       1, "readyfd",     "Set the #fd to signal when ready"},
 
        {DBUS_CLIENT,       1, "dbus-client", "Bind to an afb service through dbus"},
        {DBUS_SERVICE,      1, "dbus-server", "Provides an afb service through dbus"},
@@ -151,6 +152,9 @@ static AFB_options cliOptions[] = {
        {SET_SESSIONMAX,    1, "session-max", "Max count of session simultaneously [default 10]"},
 
        {SET_TRACEREQ,      1, "tracereq",    "Log the requests: no, common, extra, all"},
+       {SET_TRACEDITF,     1, "traceditf",   "Log the requests: no, common, extra, all"},
+       {SET_TRACESVC,      1, "tracesvc",    "Log the requests: no, all"},
+       {ADD_CALL,          1, "call",        "call at start format of val: API/VERB:json-args"},
 
        {SET_NO_HTTPD,      0, "no-httpd",    "Forbids HTTP service"},
        {SET_EXEC,          0, "exec",        "Execute the remaining arguments"},
@@ -174,6 +178,20 @@ static struct enumdesc tracereq_desc[] = {
        { NULL, 0 }
 };
 
+static struct enumdesc traceditf_desc[] = {
+       { "no",     0 },
+       { "common", afb_hook_flags_ditf_common },
+       { "extra",  afb_hook_flags_ditf_extra },
+       { "all",    afb_hook_flags_ditf_all },
+       { NULL, 0 }
+};
+
+static struct enumdesc tracesvc_desc[] = {
+       { "no",     0 },
+       { "all",    afb_hook_flags_svc_all },
+       { NULL, 0 }
+};
+
 static struct enumdesc mode_desc[] = {
        { "local",  AFB_MODE_LOCAL },
        { "remote", AFB_MODE_REMOTE },
@@ -240,7 +258,7 @@ static void list_add(struct afb_config_list **head, char *value)
        struct afb_config_list *item;
 
        /*
-        * search tail 
+        * search tail
         */
        item = *head;
        while (item != NULL) {
@@ -249,7 +267,7 @@ static void list_add(struct afb_config_list **head, char *value)
        }
 
        /*
-        * alloc the item 
+        * alloc the item
         */
        item = malloc(sizeof *item);
        if (item == NULL) {
@@ -258,7 +276,7 @@ static void list_add(struct afb_config_list **head, char *value)
        }
 
        /*
-        * init the item 
+        * init the item
         */
        *head = item;
        item->value = value;
@@ -429,6 +447,10 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config)
                        list_add(&config->ldpaths, argvalstr(optc));
                        break;
 
+               case ADD_CALL:
+                       list_add(&config->calls, argvalstr(optc));
+                       break;
+
                case SET_SESSION_DIR:
                        /* config->sessiondir = argvalstr(optc); */
                        WARNING("Obsolete otpion %s ignored", optname(optc));
@@ -464,10 +486,6 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config)
                        config->mode = argvalenum(optc, mode_desc);
                        break;
 
-               case SET_READYFD:
-                       config->readyfd = argvalintdec(optc, 0, INT_MAX);
-                       break;
-
                case DBUS_CLIENT:
                        list_add(&config->dbus_clients, argvalstr(optc));
                        break;
@@ -492,6 +510,14 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config)
                        config->tracereq = argvalenum(optc, tracereq_desc);
                        break;
 
+               case SET_TRACEDITF:
+                       config->traceditf = argvalenum(optc, traceditf_desc);
+                       break;
+
+               case SET_TRACESVC:
+                       config->tracesvc = argvalenum(optc, tracesvc_desc);
+                       break;
+
                case SET_NO_HTTPD:
                        noarg(optc);
                        config->noHttpd = 1;
@@ -551,13 +577,13 @@ static void config_set_default(struct afb_config *config)
 
        /* set directories */
        if (config->workdir == NULL)
-               config->workdir = get_current_dir_name();
+               config->workdir = ".";
 
        if (config->rootdir == NULL)
-               config->rootdir = config->workdir;
+               config->rootdir = ".";
 
        if (config->uploaddir == NULL)
-               config->uploaddir = config->workdir;
+               config->uploaddir = ".";
 
        // if no Angular/HTML5 rootbase let's try '/' as default
        if (config->rootbase == NULL)
@@ -612,18 +638,19 @@ void afb_config_dump(struct afb_config *config)
        L(ws_servers)
        L(so_bindings)
        L(ldpaths)
+       L(calls)
 
        V(exec)
 
        D(httpdPort)
        B(background)
-       D(readyfd)
        D(cacheTimeout)
        D(apiTimeout)
        D(cntxTimeout)
        D(nbSessionMax)
        E(mode,mode_desc)
        E(tracereq,tracereq_desc)
+       E(traceditf,traceditf_desc)
        B(noHttpd)
        P("---END-OF-CONFIG---\n");