summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/afb-overview.md55
-rw-r--r--src/afb-config.c60
-rw-r--r--src/afb-config.h3
-rw-r--r--src/main.c17
4 files changed, 99 insertions, 36 deletions
diff --git a/doc/afb-overview.md b/doc/afb-overview.md
index 6272b5d2..78ef8c34 100644
--- a/doc/afb-overview.md
+++ b/doc/afb-overview.md
@@ -116,13 +116,31 @@ The launch options for binder **afb-daemon** are:
Increases the verbosity, can be repeated
+ --quiet
+
+ Decreases the verbosity, can be repeated
+
--port=xxxx
HTTP listening TCP port [default 1234]
+ --workdir=xxxx
+
+ Directory where the daemon must run [default: $PWD if defined
+ or the current working directory]
+
+ --uploaddir=xxxx
+
+ Directory where uploaded files are temporarily stored [default: workdir]
+
--rootdir=xxxx
- HTTP Root Directory [default $AFBDIR or else $HOME/.AFB]
+ Root directory of the application to serve [default: workdir]
+
+ --roothttp=xxxx
+
+ Directory of HTTP served files. If not set, files are not served
+ but apis are still accessibles.
--rootbase=xxxx
@@ -149,6 +167,10 @@ The launch options for binder **afb-daemon** are:
This option can be repeated.
+ --no-httpd
+
+ Tells to not start the HTTP server.
+
--apitimeout=xxxx
binding API timeout in seconds [default 20]
@@ -164,10 +186,6 @@ The launch options for binder **afb-daemon** are:
Client cache end of live [default 100000 that is 27,7 hours]
- --sessiondir=xxxx
-
- Sessions file path [default rootdir/sessions]
-
--session-max=xxxx
Maximum count of simultaneous sessions [default 10]
@@ -196,6 +214,10 @@ The launch options for binder **afb-daemon** are:
If set to the empty string, then any initial token is accepted.
+ --random-token
+
+ Generate a random starting token. See option --exec.
+
--mode=xxxx
Set the mode: either local, remote or global.
@@ -224,6 +246,20 @@ The launch options for binder **afb-daemon** are:
The name xxxx must be the name of an API defined by a binding.
This API is exported through DBUS.
+ --ws-client=xxxx
+
+ Transparent binding to a binder afb-daemon service through a WebSocket.
+
+ The value of xxxx is either a unix naming socket, of the form "unix:path/api",
+ or an internet socket, of the form "host:port/api".
+
+ --ws-server=xxxx
+
+ Provides a binder afb-daemon service through WebSocket.
+
+ The value of xxxx is either a unix naming socket, of the form "unix:path/api",
+ or an internet socket, of the form "host:port/api".
+
--foreground
Get all in foreground mode (default)
@@ -243,6 +279,15 @@ The launch options for binder **afb-daemon** are:
The sequences @p, @t and @@ of the arguments are replaced
with the port, the token and @.
+ --tracereq=xxxx
+
+ Trace the processing of requests in the log file.
+
+ Valid values are 'no' (default), 'common', 'extra' or 'all'.
+
+
+
+
Future development of afb-daemon
--------------------------------
diff --git a/src/afb-config.c b/src/afb-config.c
index c48c4804..de025473 100644
--- a/src/afb-config.c
+++ b/src/afb-config.c
@@ -23,6 +23,7 @@
#include <string.h>
#include <getopt.h>
#include <limits.h>
+#include <unistd.h>
#include <uuid/uuid.h>
@@ -36,7 +37,7 @@
#error "you should define BINDING_INSTALL_DIR"
#endif
-#define AFB_VERSION "0.5"
+#define AFB_VERSION "0.6"
// default
#define DEFLT_CNTX_TIMEOUT 3600 // default Client Connection
@@ -91,10 +92,12 @@
#define SET_RNDTOKEN 'r'
#define SET_TRACEREQ 'T'
#define SET_AUTH_TOKEN 't'
+#define SET_UPLOAD_DIR 'u'
#define DISPLAY_VERSION 'V'
#define SET_VERBOSE 'v'
+#define SET_WORK_DIR 'w'
-#define SHORTOPTS "ehqrT:t:Vv"
+#define SHORTOPTS "ehqrT:t:u:Vvw:"
// Command line structure hold cli --command + help text
typedef struct {
@@ -114,7 +117,6 @@ 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_DIR, 1, "rootdir", "Root Directory [default $HOME/.AFB]"},
{SET_ROOT_HTTP, 1, "roothttp", "HTTP Root Directory [default rootdir]"},
{SET_ROOT_BASE, 1, "rootbase", "Angular Base Root URL [default /opa]"},
{SET_ROOT_API, 1, "rootapi", "HTML Root API URL [default /api]"},
@@ -124,10 +126,16 @@ static AFB_options cliOptions[] = {
{SET_CNTXTIMEOUT, 1, "cntxtimeout", "Client Session Context Timeout [default 900]"},
{SET_CACHE_TIMEOUT, 1, "cache-eol", "Client cache end of live [default 3600]"},
- {SET_SESSION_DIR, 1, "sessiondir", "Sessions file path [default rootdir/sessions]"},
+ {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]"},
+ {SET_ROOT_DIR, 1, "rootdir", "Root Directory of the application [default: workdir]"},
+ {SET_SESSION_DIR, 1, "sessiondir", "OBSOLETE (was: Sessions file path)"},
{SET_LDPATH, 1, "ldpaths", "Load bindings from dir1:dir2:... [default = " BINDING_INSTALL_DIR "]"},
+ {SO_BINDING, 1, "binding", "Load the binding of path"},
+
{SET_AUTH_TOKEN, 1, "token", "Initial Secret [default=no-session, --token= for session without authentication]"},
+ {SET_RNDTOKEN, 0, "random-token","Creates a random token"},
{DISPLAY_VERSION, 0, "version", "Display version and copyright"},
{DISPLAY_HELP, 0, "help", "Display this help"},
@@ -139,7 +147,6 @@ static AFB_options cliOptions[] = {
{DBUS_SERVICE, 1, "dbus-server", "Provides an afb service through dbus"},
{WS_CLIENT, 1, "ws-client", "Bind to an afb service through websocket"},
{WS_SERVICE, 1, "ws-server", "Provides an afb service through websockets"},
- {SO_BINDING, 1, "binding", "Load the binding of path"},
{SET_SESSIONMAX, 1, "session-max", "Max count of session simultaneously [default 10]"},
@@ -147,7 +154,6 @@ static AFB_options cliOptions[] = {
{SET_NO_HTTPD, 0, "no-httpd", "Forbids HTTP service"},
{SET_EXEC, 0, "exec", "Execute the remaining arguments"},
- {SET_RNDTOKEN, 0, "random-token","creates a random token"},
{0, 0, NULL, NULL}
/* *INDENT-ON* */
@@ -424,7 +430,16 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config)
break;
case SET_SESSION_DIR:
- config->sessiondir = argvalstr(optc);
+ /* config->sessiondir = argvalstr(optc); */
+ WARNING("Obsolete otpion %s ignored", optname(optc));
+ break;
+
+ case SET_UPLOAD_DIR:
+ config->uploaddir = argvalstr(optc);
+ break;
+
+ case SET_WORK_DIR:
+ config->workdir = argvalstr(optc);
break;
case SET_CACHE_TIMEOUT:
@@ -534,14 +549,16 @@ static void config_set_default(struct afb_config *config)
if (config->nbSessionMax == 0)
config->nbSessionMax = CTX_NBCLIENTS;
- if (config->rootdir == NULL) {
- config->rootdir = getenv("AFBDIR");
- if (config->rootdir == NULL) {
- config->rootdir = malloc(512);
- strncpy(config->rootdir, getenv("HOME"), 512);
- strncat(config->rootdir, "/.AFB", 512);
- }
- }
+ /* set directories */
+ if (config->workdir == NULL)
+ config->workdir = get_current_dir_name();
+
+ if (config->rootdir == NULL)
+ config->rootdir = config->workdir;
+
+ if (config->uploaddir == NULL)
+ config->uploaddir = config->workdir;
+
// if no Angular/HTML5 rootbase let's try '/' as default
if (config->rootbase == NULL)
config->rootbase = "/opa";
@@ -552,16 +569,10 @@ static void config_set_default(struct afb_config *config)
if (config->ldpaths == NULL)
list_add(&config->ldpaths, BINDING_INSTALL_DIR);
- // if no session dir create a default path from rootdir
- if (config->sessiondir == NULL) {
- config->sessiondir = malloc(512);
- strncpy(config->sessiondir, config->rootdir, 512);
- strncat(config->sessiondir, "/sessions", 512);
- }
- // if no config dir create a default path from sessiondir
+ // if no config dir create a default path from uploaddir
if (config->console == NULL) {
config->console = malloc(512);
- strncpy(config->console, config->sessiondir, 512);
+ strncpy(config->console, config->uploaddir, 512);
strncat(config->console, "/AFB-console.out", 512);
}
}
@@ -590,7 +601,8 @@ void afb_config_dump(struct afb_config *config)
S(roothttp)
S(rootbase)
S(rootapi)
- S(sessiondir)
+ S(workdir)
+ S(uploaddir)
S(token)
L(aliases)
diff --git a/src/afb-config.h b/src/afb-config.h
index eb76abe8..43b550db 100644
--- a/src/afb-config.h
+++ b/src/afb-config.h
@@ -32,7 +32,8 @@ struct afb_config {
char *roothttp; // directory for http files
char *rootbase; // Angular HTML5 base URL
char *rootapi; // Base URL for REST APIs
- char *sessiondir; // where to store mixer session files
+ char *workdir; // where to run the program
+ char *uploaddir; // where to store transient files
char *token; // initial authentication token [default NULL no session]
struct afb_config_list *aliases;
diff --git a/src/main.c b/src/main.c
index d2a08422..774a5f0e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -202,8 +202,8 @@ static struct afb_hsrv *start_http_server()
int rc;
struct afb_hsrv *hsrv;
- if (afb_hreq_init_download_path("/tmp")) { /* TODO: sessiondir? */
- ERROR("unable to set the tmp directory");
+ if (afb_hreq_init_download_path(config->uploaddir)) {
+ ERROR("unable to set the upload directory %s", config->uploaddir);
return NULL;
}
@@ -220,8 +220,7 @@ static struct afb_hsrv *start_http_server()
return NULL;
}
- NOTICE("Waiting port=%d rootdir=%s", config->httpdPort,
- config->rootdir);
+ NOTICE("Waiting port=%d rootdir=%s", config->httpdPort, config->rootdir);
NOTICE("Browser URL= http:/*localhost:%d", config->httpdPort);
rc = afb_hsrv_start(hsrv, (uint16_t) config->httpdPort, 15);
@@ -369,6 +368,12 @@ int main(int argc, char *argv[])
exit(1);
}
+ mkdir(config->workdir, S_IRWXU | S_IRGRP | S_IXGRP);
+ if (chdir(config->workdir) < 0) {
+ ERROR("Can't enter working dir %s", config->workdir);
+ exit(1);
+ }
+
afb_session_init(config->nbSessionMax, config->cntxTimeout, config->token, afb_apis_count());
afb_api_so_set_timeout(config->apiTimeout);
@@ -388,8 +393,8 @@ int main(int argc, char *argv[])
ERROR("failed to initialise signal handlers");
return 1;
}
- // if directory does not exist createit
- mkdir(config->rootdir, O_RDWR | S_IRWXU | S_IRGRP);
+
+ // set the root dir
if (afb_common_rootdir_set(config->rootdir) < 0) {
ERROR("failed to set common root directory");
return 1;