fix dbus disconnection on error
[src/app-framework-binder.git] / src / session.c
index d586e51..46db9ce 100644 (file)
 #include <assert.h>
 #include <errno.h>
 
-#include <json.h>
+#include <json-c/json.h>
 
 #include "session.h"
+#include "verbose.h"
 
 #define NOW (time(NULL))
 
@@ -82,13 +83,18 @@ static void ctxUuidFreeCB (struct AFB_clientCtx *client)
 // Create a new store in RAM, not that is too small it will be automatically extended
 void ctxStoreInit (int max_session_count, int timeout, const char *initok, int context_count)
 {
+
        // let's create as store as hashtable does not have any
        sessions.store = calloc (1 + (unsigned)max_session_count, sizeof(struct AFB_clientCtx));
        sessions.max = max_session_count;
        sessions.timeout = timeout;
        sessions.apicount = context_count;
+        if (!initok) {
+               ERROR("\"--token=\" parameter is mandatory");
+               exit(1);
+       }
        if (strlen(initok) >= sizeof(sessions.store[0]->token)) {
-               fprintf(stderr, "Error: initial token '%s' too long (max length 36)", initok);
+               ERROR("initial token '%s' too long (max length 36)", initok);
                exit(1);
        }
        sessions.initok = initok;
@@ -145,8 +151,6 @@ static int ctxStoreAdd (struct AFB_clientCtx *client)
 
     assert (client != NULL);
 
-    //fprintf (stderr, "ctxStoreAdd request uuid=%s count=%d\n", client->uuid, sessions.count);
-
     pthread_mutex_lock(&sessions.mutex);
 
     for (idx=0; idx < sessions.max; idx++) {