aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-args.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/afb-args.c')
-rw-r--r--src/afb-args.c64
1 files changed, 46 insertions, 18 deletions
diff --git a/src/afb-args.c b/src/afb-args.c
index 467f0860..b7ef1f59 100644
--- a/src/afb-args.c
+++ b/src/afb-args.c
@@ -58,7 +58,9 @@
/**
* The default timeout of cache in seconds
*/
+#if WITH_LIBMICROHTTPD
#define DEFAULT_CACHE_TIMEOUT 100000
+#endif
/**
* The default maximum count of sessions
@@ -68,17 +70,21 @@
/**
* The default HTTP port to serve
*/
+#if WITH_LIBMICROHTTPD
#define DEFAULT_HTTP_PORT 1234
+#endif
// Define command line option
#define SET_BACKGROUND 1
#define SET_FOREGROUND 2
#define SET_ROOT_DIR 3
+
+#if WITH_LIBMICROHTTPD
#define SET_ROOT_BASE 4
#define SET_ROOT_API 5
#define ADD_ALIAS 6
-
#define SET_CACHE_TIMEOUT 7
+#endif
#if WITH_DYNAMIC_BINDING
#define ADD_LDPATH 10
@@ -93,9 +99,10 @@
#define ADD_WS_CLIENT 16
#define ADD_WS_SERVICE 17
+#if WITH_LIBMICROHTTPD
#define SET_ROOT_HTTP 18
-
#define SET_NO_HTTPD 19
+#endif
#define SET_TRACEEVT 20
#define SET_TRACESES 21
@@ -123,17 +130,21 @@
#define SET_EXEC 'e'
#define GET_HELP 'h'
#define SET_LOG 'l'
-#if defined(WITH_MONITORING_OPTION)
+#if WITH_MONITORING
#define SET_MONITORING 'M'
#endif
#define SET_NAME 'n'
#define SET_OUTPUT 'o'
#define SET_PORT 'p'
#define SET_QUIET 'q'
+#if WITH_LIBMICROHTTPD
#define SET_RANDOM_TOKEN 'r'
+#endif
#define ADD_SET 's'
+#if WITH_LIBMICROHTTPD
#define SET_TOKEN 't'
#define SET_UPLOAD_DIR 'u'
+#endif
#define GET_VERSION 'V'
#define SET_VERBOSE 'v'
#define SET_WORK_DIR 'w'
@@ -161,18 +172,23 @@ static struct option_desc optdefs[] = {
{SET_NAME, 1, "name", "Set the visible name"},
+#if WITH_LIBMICROHTTPD
+ {SET_NO_HTTPD, 0, "no-httpd", "Forbid HTTP service"},
{SET_PORT, 1, "port", "HTTP listening TCP port [default " d2s(DEFAULT_HTTP_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]"},
{ADD_ALIAS, 1, "alias", "Multiple url map outside of rootdir [eg: --alias=/icons:/usr/share/icons]"},
+ {SET_UPLOAD_DIR, 1, "uploaddir", "Directory for uploading files [default: workdir] relative to workdir"},
+ {SET_CACHE_TIMEOUT, 1, "cache-eol", "Client cache end of live [default " d2s(DEFAULT_CACHE_TIMEOUT) "]"},
+ {SET_TOKEN, 1, "token", "Initial Secret [default=random, use --token="" to allow any token]"},
+ {SET_RANDOM_TOKEN, 0, "random-token","Enforce a random token"},
+#endif
{SET_API_TIMEOUT, 1, "apitimeout", "Binding API timeout in seconds [default " d2s(DEFAULT_API_TIMEOUT) "]"},
{SET_SESSION_TIMEOUT, 1, "cntxtimeout", "Client Session Context Timeout [default " d2s(DEFAULT_SESSION_TIMEOUT) "]"},
- {SET_CACHE_TIMEOUT, 1, "cache-eol", "Client cache end of live [default " d2s(DEFAULT_CACHE_TIMEOUT) "]"},
{SET_WORK_DIR, 1, "workdir", "Set the working directory [default: $PWD or current working directory]"},
- {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"},
#if WITH_DYNAMIC_BINDING
@@ -181,8 +197,6 @@ static struct option_desc optdefs[] = {
{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"},
{GET_VERSION, 0, "version", "Display version and copyright"},
{GET_HELP, 0, "help", "Display this help"},
@@ -212,10 +226,9 @@ static struct option_desc optdefs[] = {
{ADD_CALL, 1, "call", "Call at start, format of val: API/VERB:json-args"},
- {SET_NO_HTTPD, 0, "no-httpd", "Forbid HTTP service"},
{SET_EXEC, 0, "exec", "Execute the remaining arguments"},
-#if defined(WITH_MONITORING_OPTION)
+#if WITH_MONITORING
{SET_MONITORING, 0, "monitoring", "Enable HTTP monitoring at <ROOT>/monitoring/"},
#endif
@@ -231,7 +244,7 @@ static struct option_desc optdefs[] = {
/* *INDENT-ON* */
};
-#if defined(WITH_MONITORING_OPTION)
+#if WITH_MONITORING
static const char MONITORING_ALIAS[] = "/monitoring:"BINDING_INSTALL_DIR"/monitoring";
#endif
@@ -239,9 +252,11 @@ static const struct {
int optid;
int valdef;
} default_optint_values[] = {
+#if WITH_LIBMICROHTTPD
{ SET_PORT, DEFAULT_HTTP_PORT },
{ SET_API_TIMEOUT, DEFAULT_API_TIMEOUT },
{ SET_CACHE_TIMEOUT, DEFAULT_CACHE_TIMEOUT },
+#endif
{ SET_SESSION_TIMEOUT, DEFAULT_SESSION_TIMEOUT },
{ SET_SESSIONMAX, DEFAULT_MAX_SESSION_COUNT }
};
@@ -250,11 +265,13 @@ static const struct {
int optid;
const char *valdef;
} default_optstr_values[] = {
- { SET_WORK_DIR, "." },
- { SET_ROOT_DIR, "." },
+#if WITH_LIBMICROHTTPD
{ SET_UPLOAD_DIR, "." },
{ SET_ROOT_BASE, "/opa" },
- { SET_ROOT_API, "/api" }
+ { SET_ROOT_API, "/api" },
+#endif
+ { SET_WORK_DIR, "." },
+ { SET_ROOT_DIR, "." }
};
/**********************************
@@ -344,7 +361,7 @@ static void printVersion(FILE * file)
#endif
"DBUS "
-#if defined(WITH_MONITORING_OPTION)
+#if WITH_MONITORING
"+"
#else
"-"
@@ -546,6 +563,7 @@ static int get_arg_bool(int optid)
return value;
}
+__attribute__((unused))
static void config_del(struct json_object *config, int optid)
{
return json_object_object_del(config, name_of_optid(optid));
@@ -814,7 +832,9 @@ static void parse_arguments_inner(int argc, char **argv, struct json_object *con
case SET_API_TIMEOUT:
case SET_SESSION_TIMEOUT:
+#if WITH_LIBMICROHTTPD
case SET_CACHE_TIMEOUT:
+#endif
config_set_optint(config, optid, 0, INT_MAX);
break;
@@ -823,11 +843,13 @@ static void parse_arguments_inner(int argc, char **argv, struct json_object *con
break;
case SET_ROOT_DIR:
+#if WITH_LIBMICROHTTPD
case SET_ROOT_HTTP:
case SET_ROOT_BASE:
case SET_ROOT_API:
case SET_TOKEN:
case SET_UPLOAD_DIR:
+#endif
case SET_WORK_DIR:
case SET_NAME:
config_set_optstr(config, optid);
@@ -837,7 +859,9 @@ static void parse_arguments_inner(int argc, char **argv, struct json_object *con
case ADD_DBUS_CLIENT:
case ADD_DBUS_SERVICE:
#endif
+#if WITH_LIBMICROHTTPD
case ADD_ALIAS:
+#endif
#if WITH_DYNAMIC_BINDING
case ADD_LDPATH:
case ADD_WEAK_LDPATH:
@@ -854,18 +878,21 @@ static void parse_arguments_inner(int argc, char **argv, struct json_object *con
config_mix2_optstr(config, optid);
break;
-#if defined(WITH_MONITORING_OPTION)
+#if WITH_MONITORING
case SET_MONITORING:
#endif
+#if WITH_LIBMICROHTTPD
case SET_RANDOM_TOKEN:
case SET_NO_HTTPD:
+#endif
#if WITH_DYNAMIC_BINDING
case SET_NO_LDPATH:
#endif
+#if WITH_MONITORING || WITH_LIBMICROHTTPD || WITH_DYNAMIC_BINDING
noarg(optid);
config_set_bool(config, optid, 1);
break;
-
+#endif
case SET_FOREGROUND:
case SET_BACKGROUND:
@@ -992,15 +1019,16 @@ static void fulfill_config(struct json_object *config)
config_set_str(config, default_optstr_values[i].optid, default_optstr_values[i].valdef);
// default AUTH_TOKEN
+#if WITH_LIBMICROHTTPD
if (config_has_bool(config, SET_RANDOM_TOKEN))
config_del(config, SET_TOKEN);
-
+#endif
#if WITH_DYNAMIC_BINDING
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);
#endif
-#if defined(WITH_MONITORING_OPTION)
+#if WITH_MONITORING
if (config_has_bool(config, SET_MONITORING) && !config_has_str(config, ADD_ALIAS, MONITORING_ALIAS))
config_add_str(config, ADD_ALIAS, MONITORING_ALIAS);
#endif