afb-session: redefine the function 'afb_session_create'
authorJosé Bollo <jose.bollo@iot.bzh>
Mon, 6 Nov 2017 12:10:55 +0000 (13:10 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 6 Nov 2017 12:10:55 +0000 (13:10 +0100)
Change-Id: Ib8a66af30ea2438248adb66c9a95ac82663ec223
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-export.c
src/afb-session.c
src/afb-session.h
src/main.c

index ea783b8..3a898bb 100644 (file)
@@ -1072,7 +1072,7 @@ static struct afb_export *create(struct afb_apiset *apiset, const char *apiname,
 
        /* session shared with other exports */
        if (common_session == NULL) {
-               common_session = afb_session_create (NULL, 0);
+               common_session = afb_session_create (0);
                if (common_session == NULL)
                        return NULL;
        }
@@ -1181,7 +1181,7 @@ struct afb_binding_interface_v1 *afb_export_get_interface_v1(struct afb_export *
 int afb_export_unshare_session(struct afb_export *export)
 {
        if (export->session == common_session) {
-               export->session = afb_session_create (NULL, 0);
+               export->session = afb_session_create (0);
                if (export->session)
                        afb_session_unref(common_session);
                else {
index 77a20fa..2b649ef 100644 (file)
@@ -250,7 +250,7 @@ static struct afb_session *make_session (const char *uuid, int timeout, time_t n
 
        /* generate the uuid */
        if (uuid == NULL) {
-               new_uuid(session->uuid);
+               do { new_uuid(session->uuid); } while(search(session->uuid));
        } else {
                if (strlen(uuid) >= sizeof session->uuid) {
                        errno = EINVAL;
@@ -284,7 +284,7 @@ error:
        return NULL;
 }
 
-struct afb_session *afb_session_create (const char *uuid, int timeout)
+struct afb_session *afb_session_create (int timeout)
 {
        time_t now;
 
@@ -292,13 +292,7 @@ struct afb_session *afb_session_create (const char *uuid, int timeout)
        now = NOW;
        cleanup (now);
 
-       /* search for an existing one not too old */
-       if (uuid != NULL && search(uuid) != NULL) {
-               errno = EEXIST;
-               return NULL;
-       }
-
-       return make_session(uuid, timeout, now);
+       return make_session(NULL, timeout, now);
 }
 
 // This function will return exiting session or newly created session
index b5dc394..c76d676 100644 (file)
@@ -22,7 +22,7 @@ struct afb_session;
 extern void afb_session_init(int max_session_count, int timeout, const char *initok);
 extern const char *afb_session_initial_token();
 
-extern struct afb_session *afb_session_create (const char *uuid, int timeout);
+extern struct afb_session *afb_session_create (int timeout);
 extern struct afb_session *afb_session_get (const char *uuid, int *created);
 extern const char *afb_session_uuid (struct afb_session *session);
 
index b5b0023..150b781 100644 (file)
@@ -525,7 +525,7 @@ static void run_startup_calls()
        list = config->calls;
        if (list) {
                sreq = calloc(1, sizeof *sreq);
-               sreq->session = afb_session_create("startup", 3600);
+               sreq->session = afb_session_create(3600);
                sreq->current = list;
                startup_call_current(sreq);
        }