- // function will exit process in case of error !!!
- table=lh_table_new (nbSession, "CtxClient", ctxUuidFreeCB, ctxUuidHashCB, ctxUuidCompCB);
- return (table);
+ pthread_mutex_lock(&mutexHash);
+ if (hsearch_r(item, FIND, &pitem, &sessions)) {
+ pthread_mutex_unlock(&mutexHash);
+ return (AFB_clientCtx*) pitem->data;
+ }
+ pthread_mutex_unlock(&mutexHash);
+ return NULL;
+}
+
+// Reference http://stackoverflow.com/questions/25971505/how-to-delete-element-from-hsearch
+void ctxStoreAdd (AFB_clientCtx *client) {
+ ENTRY item = {client->uuid, (void*)client};
+ ENTRY *pitem = &item;
+
+ pthread_mutex_lock(&mutexHash);
+ if (hsearch_r(item, ENTER, &pitem, &sessions)) {
+ // printf ("storing uuid=%s\n", client->uuid);
+ pitem->data = (void *)client;
+ }
+ pthread_mutex_unlock(&mutexHash);
+}
+
+void ctxStoreDel (AFB_clientCtx *client) {
+ ENTRY item = {client->uuid};
+ ENTRY *pitem = &item;
+
+ pthread_mutex_lock(&mutexHash);
+ if (hsearch_r(item, FIND, &pitem, &sessions)) {
+ pitem->data = NULL;
+ }
+ pthread_mutex_unlock(&mutexHash);