+STATIC AFB_error ctxStoreDel (AFB_clientCtx *client) {
+ int idx;
+ int status;
+ if (client == NULL) return (AFB_FAIL);
+
+ //fprintf (stderr, "ctxStoreDel request uuid=%s count=%d\n", client->uuid, sessions.count);
+
+ pthread_mutex_lock(&sessions.mutex);
+
+ for (idx=0; idx < sessions.max; idx++) {
+ if (sessions.store[idx] && (0 == strcmp (client->uuid, sessions.store[idx]->uuid))) break;
+ }
+
+ if (idx == sessions.max) status=AFB_FAIL;
+ else {
+ sessions.count --;
+ sessions.store[idx]=NULL;
+ status=AFB_SUCCESS;
+ }
+
+ pthread_mutex_unlock(&sessions.mutex);
+
+ return (status);
+
+ // plugin registered a callback let's release semaphore and cleanup now
+ if ((client->plugin->freeCtxCB != NULL) && client->ctx) client->plugin->freeCtxCB(client);
+}
+
+STATIC AFB_error ctxStoreAdd (AFB_clientCtx *client) {
+ int idx;
+ int status;
+ if (client == NULL) return (AFB_FAIL);
+
+ //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++) {
+ if (NULL == sessions.store[idx]) break;
+ }
+
+ if (idx == sessions.max) status=AFB_FAIL;
+ else {
+ status=AFB_SUCCESS;
+ sessions.count ++;
+ sessions.store[idx]= client;
+ }
+
+ pthread_mutex_unlock(&sessions.mutex);
+
+ return (status);
+}
+
+// Check if context timeout or not
+STATIC int ctxStoreToOld (AFB_clientCtx *ctx, int timeout) {
+ int res;
+ time_t now = time(NULL);
+ res = ((ctx->timeStamp + timeout) <= now);