afs-supervisor: Fix typo 13/14313/1
authorJosé Bollo <jose.bollo@iot.bzh>
Wed, 21 Mar 2018 13:55:24 +0000 (14:55 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Wed, 13 Jun 2018 15:13:29 +0000 (17:13 +0200)
Change-Id: Icc3c15f577f04117cdfaf2bcbcc4d15a99d02138
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
CMakeLists.txt
memo-supervisor.txt
src/afb-supervision.c
src/afs-config.c
src/afs-supervision.h
src/afs-supervisor.c

index f60cace..75faf41 100644 (file)
@@ -40,7 +40,7 @@ INCLUDE(CTest)
 set(AGL_DEVEL OFF CACHE BOOL "Activates developping features")
 set(INCLUDE_MONITORING OFF CACHE BOOL "Activates installation of monitoring")
 set(INCLUDE_SUPERVISOR OFF CACHE BOOL "Activates installation of supervisor")
-set(AFS_SURPERVISION_SOCKET "@urn:AGL:afs:supervision:socket" CACHE STRING "Internal socket for supervision")
+set(AFS_SUPERVISION_SOCKET "@urn:AGL:afs:supervision:socket" CACHE STRING "Internal socket for supervision")
 set(AFS_SUPERVISOR_PORT 1619 CACHE STRING "Port of service for the supervisor")
 set(AFS_SUPERVISOR_TOKEN HELLO CACHE STRING "Secret token for the supervisor")
 set(UNITDIR_SYSTEM ${CMAKE_INSTALL_LIBDIR}/systemd/system CACHE STRING "Path to systemd system unit files")
@@ -86,7 +86,9 @@ PKG_CHECK_MODULES(openssl openssl)
 PKG_CHECK_MODULES(uuid uuid)
 PKG_CHECK_MODULES(cynara cynara-client)
 
-ADD_DEFINITIONS("-DAFS_SURPERVISION_SOCKET=\"${AFS_SURPERVISION_SOCKET}\"")
+ADD_DEFINITIONS("-DAFS_SUPERVISION_SOCKET=\"${AFS_SUPERVISION_SOCKET}\"")
+ADD_DEFINITIONS("-DAFS_SUPERVISOR_TOKEN=\"${AFS_SUPERVISOR_TOKEN}\"")
+ADD_DEFINITIONS("-DAFS_SUPERVISOR_PORT=${AFS_SUPERVISOR_PORT}")
 
 IF(AGL_DEVEL)
        ADD_DEFINITIONS(-DAGL_DEVEL)
index 9f996b7..13e9d1d 100644 (file)
@@ -2,12 +2,12 @@
 Run the supervisor on the target for the public IP:
 ---------------------------------------------------
 
-       # afs-supervisor --port 1712 --token HELLO 
+       # afs-supervisor --port 1619 --token HELLO 
 
 Run the client
 --------------
 
-       # afb-client-demo -H host:1712/api?token=HELLO
+       # afb-client-demo -H host:1619/api?token=HELLO
 
 
 verbs that can be run, all are of the API 'supervisor':
index 4d471e8..fa678ee 100644 (file)
 extern struct afb_config *main_config;
 
 /* api and apiset name */
-static const char supervision_apiname[] = AFS_SURPERVISION_APINAME;
-static const char supervisor_apiname[] = AFS_SURPERVISOR_APINAME;
+static const char supervision_apiname[] = AFS_SUPERVISION_APINAME;
+static const char supervisor_apiname[] = AFS_SUPERVISOR_APINAME;
 
 /* path of the supervision socket */
-static const char supervisor_socket_path[] = AFS_SURPERVISION_SOCKET;
+static const char supervisor_socket_path[] = AFS_SUPERVISION_SOCKET;
 
 /* mutual exclusion */
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -176,7 +176,7 @@ static void try_connect_supervisor()
                ERROR("Bad interface of supervisor %s", supervisor_socket_path);
                goto end2;
        }
-       if (strcmp(initiator.interface, AFS_SURPERVISION_INTERFACE_1)) {
+       if (strcmp(initiator.interface, AFS_SUPERVISION_INTERFACE_1)) {
                ERROR("Unknown interface %s for supervisor %s", initiator.interface, supervisor_socket_path);
                goto end2;
        }
index 3cb851b..eee4ccc 100644 (file)
 #include "afs-config.h"
 
 #if !defined(AFB_VERSION)
-#error "you should define AFB_VERSION"
+#  error "you should define AFB_VERSION"
 #endif
 
+#if !defined(AFS_SUPERVISOR_TOKEN)
+#  define AFS_SUPERVISOR_TOKEN    ""
+#endif
+#if !defined(AFS_SUPERVISOR_PORT)
+#  define AFS_SUPERVISOR_PORT     1619
+#endif
+#define _STRINGIFY_(x) #x
+#define STRINGIFY(x) _STRINGIFY_(x)
+
 // default
 #define DEFLT_CNTX_TIMEOUT  32000000   // default Client Connection
                                        // Timeout: few more than one year
@@ -88,7 +97,7 @@ static AFB_options cliOptions[] = {
 
        {SET_NAME,          1, "name",        "Set the visible name"},
 
-       {SET_TCP_PORT,      1, "port",        "HTTP listening TCP port  [default 1234]"},
+       {SET_TCP_PORT,      1, "port",        "HTTP listening TCP port  [default " STRINGIFY(AFS_SUPERVISOR_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]"},
@@ -102,7 +111,7 @@ static AFB_options cliOptions[] = {
        {SET_ROOT_DIR,      1, "rootdir",     "Root Directory of the application [default: workdir]"},
        {SET_SESSION_DIR,   1, "sessiondir",  "OBSOLETE (was: Sessions file path)"},
 
-       {SET_AUTH_TOKEN,    1, "token",       "Initial Secret [default=random, use --token="" to allow any token]"},
+       {SET_AUTH_TOKEN,    1, "token",       "Initial Secret [default=" AFS_SUPERVISOR_TOKEN ", use --token="" to allow any token]"},
 
        {DISPLAY_VERSION,   0, "version",     "Display version and copyright"},
        {DISPLAY_HELP,      0, "help",        "Display this help"},
@@ -335,7 +344,7 @@ static void fulfill_config(struct afs_config *config)
 {
        // default HTTP port
        if (config->httpdPort == 0)
-               config->httpdPort = 1234;
+               config->httpdPort = AFS_SUPERVISOR_PORT;
 
        // default binding API timeout
        if (config->apiTimeout == 0)
@@ -369,6 +378,9 @@ static void fulfill_config(struct afs_config *config)
 
        if (config->rootapi == NULL)
                config->rootapi = "/api";
+
+       if (config->token == NULL)
+               config->token = AFS_SUPERVISOR_TOKEN;
 }
 
 void afs_config_dump(struct afs_config *config)
index fe3d271..bee40a1 100644 (file)
  * anyone to create a such socket and usurpate the
  * supervisor.
  */
-#if !defined(AFS_SURPERVISION_SOCKET)
-#  define AFS_SURPERVISION_SOCKET "@urn:AGL:afs:supervision:socket" /* abstract */
+#if !defined(AFS_SUPERVISION_SOCKET)
+#  define AFS_SUPERVISION_SOCKET "@urn:AGL:afs:supervision:socket" /* abstract */
 #endif
 
 /*
  * generated using
  * uuid -v 5 ns:URL urn:AGL:afs:supervision:interface:1
  */
-#define AFS_SURPERVISION_INTERFACE_1 "86040e8d-eee5-5900-a129-3edb8da3ed46"
+#define AFS_SUPERVISION_INTERFACE_1 "86040e8d-eee5-5900-a129-3edb8da3ed46"
 
 
 /**
@@ -45,5 +45,5 @@ struct afs_supervision_initiator
        char extra[27];         /**< zero terminated extra computed here to be 64-37 */
 };
 
-#define AFS_SURPERVISION_APINAME      "$"
-#define AFS_SURPERVISOR_APINAME       "supervisor"
+#define AFS_SUPERVISION_APINAME      "$"
+#define AFS_SUPERVISOR_APINAME       "supervisor"
index acad792..62adf9b 100644 (file)
@@ -60,14 +60,14 @@ struct supervised
 };
 
 /* api and apiset name */
-static const char supervision_apiname[] = AFS_SURPERVISION_APINAME;
-static const char supervisor_apiname[] = AFS_SURPERVISOR_APINAME;
+static const char supervision_apiname[] = AFS_SUPERVISION_APINAME;
+static const char supervisor_apiname[] = AFS_SUPERVISOR_APINAME;
 
 /* the empty apiset */
 static struct afb_apiset *empty_apiset;
 
 /* supervision socket path */
-static const char supervision_socket_path[] = AFS_SURPERVISION_SOCKET;
+static const char supervision_socket_path[] = AFS_SUPERVISION_SOCKET;
 static struct fdev *supervision_fdev;
 
 /* global mutex */
@@ -137,7 +137,7 @@ static int send_initiator(int fd, const char *command)
 
        /* set  */
        memset(&asi, 0, sizeof asi);
-       strcpy(asi.interface, AFS_SURPERVISION_INTERFACE_1);
+       strcpy(asi.interface, AFS_SUPERVISION_INTERFACE_1);
        if (command)
                strncpy(asi.extra, command, sizeof asi.extra - 1);