From 0890cefa1108aa409d6e6b3cf2f7517b3a6cc5f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Tue, 9 Feb 2016 10:23:41 +0100 Subject: [PATCH] Adds a new option: mode MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The option mode can have 3 values: local, remote, global. It indicates wether the daemon serves: - loopback (local) - external interface (remote) - both (global) Change-Id: Ibd6c25da692e607b8e0ce793da11cca88db050a2 Signed-off-by: José Bollo --- include/local-def.h | 2 ++ src/main.c | 76 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/include/local-def.h b/include/local-def.h index f7ddeeb4..bf353e94 100644 --- a/include/local-def.h +++ b/include/local-def.h @@ -108,6 +108,7 @@ typedef struct { } AFB_errorT; typedef enum {AFB_POST_NONE=0, AFB_POST_JSON, AFB_POST_FORM, AFB_POST_EMPTY} AFB_PostType; +typedef enum {AFB_MODE_LOCAL=0, AFB_MODE_REMOTE, AFB_MODE_GLOBAL} AFB_Mode; // Post Upload File Handle typedef struct { @@ -184,6 +185,7 @@ typedef struct { int cntxTimeout; // Client Session Context timeout int pluginCount; // loaded plugins count AFB_aliasdir *aliasdir; // alias mapping for icons,apps,... + AFB_Mode mode; // mode of listening } AFB_config; typedef struct { diff --git a/src/main.c b/src/main.c index b17435ec..533776a1 100644 --- a/src/main.c +++ b/src/main.c @@ -50,34 +50,36 @@ static sigjmp_buf exitPoint; // context save for set/longjmp // Define command line option - #define SET_VERBOSE 101 - #define SET_BACKGROUND 105 - #define SET_FORGROUND 106 - #define KILL_PREV_EXIT 107 - #define KILL_PREV_REST 108 - #define SET_FAKE_MOD 109 - - #define SET_TCP_PORT 120 - #define SET_ROOT_DIR 121 - #define SET_ROOT_BASE 122 - #define SET_ROOT_API 123 - #define SET_ROOT_ALIAS 124 - - #define SET_CACHE_TO 130 - #define SET_USERID 131 - #define SET_PID_FILE 132 - #define SET_SESSION_DIR 133 - #define SET_CONFIG_FILE 134 - #define SET_CONFIG_SAVE 135 - #define SET_CONFIG_EXIT 138 - - #define SET_AUTH_TOKEN 141 - #define SET_LDPATH 142 - #define SET_APITIMEOUT 143 - #define SET_CNTXTIMEOUT 144 - - #define DISPLAY_VERSION 150 - #define DISPLAY_HELP 151 +#define SET_VERBOSE 101 +#define SET_BACKGROUND 105 +#define SET_FORGROUND 106 +#define KILL_PREV_EXIT 107 +#define KILL_PREV_REST 108 +#define SET_FAKE_MOD 109 + +#define SET_TCP_PORT 120 +#define SET_ROOT_DIR 121 +#define SET_ROOT_BASE 122 +#define SET_ROOT_API 123 +#define SET_ROOT_ALIAS 124 + +#define SET_CACHE_TO 130 +#define SET_USERID 131 +#define SET_PID_FILE 132 +#define SET_SESSION_DIR 133 +#define SET_CONFIG_FILE 134 +#define SET_CONFIG_SAVE 135 +#define SET_CONFIG_EXIT 138 + +#define SET_AUTH_TOKEN 141 +#define SET_LDPATH 142 +#define SET_APITIMEOUT 143 +#define SET_CNTXTIMEOUT 144 + +#define DISPLAY_VERSION 150 +#define DISPLAY_HELP 151 + +#define SET_MODE 160 // Supported option @@ -111,6 +113,8 @@ static AFB_options cliOptions [] = { {DISPLAY_VERSION ,0,"version" , "Display version and copyright"}, {DISPLAY_HELP ,0,"help" , "Display this help"}, + + {SET_MODE ,1,"mode" , "set the mode: either local, remote or global"}, {0, 0, 0} }; @@ -413,6 +417,15 @@ int main(int argc, char *argv[]) { session->killPrevious = 2; break; + case SET_MODE: + if (optarg == 0) goto needValueForOption; + /* TODO setting directly session->config isn't the expected path but... see configLoadFile, configStoreFile (JOBOL) */ + if (!strcmp(optarg, "local")) session->config->mode = AFB_MODE_LOCAL; + else if (!strcmp(optarg, "remote")) session->config->mode = AFB_MODE_REMOTE; + else if (!strcmp(optarg, "global")) session->config->mode = AFB_MODE_GLOBAL; + else goto badMode; + break; + case DISPLAY_VERSION: if (optarg != 0) goto noValueForOption; printVersion(); @@ -440,7 +453,7 @@ int main(int argc, char *argv[]) { if ((session->background == 0) && (session->foreground == 0)) session->foreground=1; // open syslog if ever needed - openlog("AGB-log", 0, LOG_DAEMON); + openlog("AFB-log", 0, LOG_DAEMON); // -------------- Try to kill any previous process if asked --------------------- if (session->killPrevious) { @@ -615,6 +628,11 @@ notAnInteger: ,gnuOptions[optionIndex].name, gnuOptions[optionIndex].name); exit (-1); +badMode: + fprintf (stderr,"\nERR:AFB-daemon option [--%s] only accepts local, global or remote.\n\n" + ,gnuOptions[optionIndex].name); + exit (-1); + exitOnSignal: fprintf (stderr,"\n%s INF:AFB-daemon pid=%d received exit signal (Hopefully crtl-C or --kill-previous !!!)\n\n" ,configTime(), getpid()); -- 2.16.6