- // if table is full at 50% let's clean it up
- if(sessions.count > (sessions.max / 2)) ctxStoreGarbage(request->config->cntxTimeout);
-
- // finally add uuid into hashtable
- if (AFB_SUCCESS != ctxStoreAdd (clientCtx)) {
- free (clientCtx);
- return NULL;
- }
-
- // if (verbose) fprintf (stderr, "ctxClientGet New uuid=[%s] token=[%s] timestamp=%d\n", clientCtx->uuid, clientCtx->token, clientCtx->timeStamp);
- request->context = clientCtx->contexts[idx];
- request->handle = clientCtx->plugins[idx]->handle;
- request->uuid=clientCtx->uuid;
- return clientCtx;
+ /* mimic old behaviour */
+ if (sessions.initok == NULL)
+ return NULL;
+
+ /* check the uuid if given */
+ if (uuid != NULL && 1 + strlen(uuid) >= sizeof clientCtx->uuid)
+ return NULL;
+
+ /* returns a new one */
+ clientCtx = calloc(1, sizeof(struct AFB_clientCtx)); // init NULL clientContext
+ if (clientCtx != NULL) {
+ clientCtx->contexts = calloc ((unsigned)sessions.apicount, sizeof (void*));
+ if (clientCtx->contexts != NULL) {
+ /* generate the uuid */
+ if (uuid == NULL) {
+ uuid_generate(newuuid);
+ uuid_unparse_lower(newuuid, clientCtx->uuid);
+ } else {
+ strcpy(clientCtx->uuid, uuid);
+ }
+ strcpy(clientCtx->token, sessions.initok);
+ clientCtx->expiration = now + sessions.timeout;
+ clientCtx->refcount = 1;
+ if (ctxStoreAdd (clientCtx))
+ return clientCtx;
+ free(clientCtx->contexts);
+ }
+ free(clientCtx);
+ }
+ return NULL;