+void ctxClientSetLOA (struct AFB_clientCtx *clientCtx, unsigned loa)
+{
+ assert(clientCtx != NULL);
+ clientCtx->loa = loa;
+}
+
+void *ctxClientValueGet(struct AFB_clientCtx *clientCtx, int index)
+{
+ assert(clientCtx != NULL);
+ assert(index >= 0);
+ assert(index < sessions.apicount);
+ return clientCtx->values[index].value;
+}
+
+void ctxClientValueSet(struct AFB_clientCtx *clientCtx, int index, void *value, void (*free_value)(void*))
+{
+ struct client_value prev;
+ assert(clientCtx != NULL);
+ assert(index >= 0);
+ assert(index < sessions.apicount);
+ prev = clientCtx->values[index];
+ clientCtx->values[index] = (struct client_value){.value = value, .free_value = free_value};
+ if (prev.value != NULL && prev.value != value && prev.free_value != NULL)
+ prev.free_value(prev.value);
+}
+
+void *ctxClientCookieGet(struct AFB_clientCtx *clientCtx, const void *key)
+{
+ struct cookie *cookie;
+
+ cookie = clientCtx->cookies;
+ while(cookie != NULL) {
+ if (cookie->key == key)
+ return cookie->value;
+ cookie = cookie->next;
+ }
+ return NULL;
+}
+
+int ctxClientCookieSet(struct AFB_clientCtx *clientCtx, const void *key, void *value, void (*free_value)(void*))
+{
+ struct cookie *cookie;
+
+ /* search for a replacement */
+ cookie = clientCtx->cookies;
+ while(cookie != NULL) {
+ if (cookie->key == key) {
+ if (cookie->value != NULL && cookie->value != value && cookie->free_value != NULL)
+ cookie->free_value(cookie->value);
+ cookie->value = value;
+ cookie->free_value = free_value;
+ return 0;
+ }
+ cookie = cookie->next;
+ }
+
+ /* allocates */
+ cookie = malloc(sizeof *cookie);
+ if (cookie == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ cookie->key = key;
+ cookie->value = value;
+ cookie->free_value = free_value;
+ cookie->next = clientCtx->cookies;
+ clientCtx->cookies = cookie;
+ return 0;