+
+ /* allocates a new one */
+ clientCtx = calloc(1, sizeof(struct AFB_clientCtx) + ((unsigned)sessions.apicount * sizeof(*clientCtx->values)));
+ if (clientCtx == NULL) {
+ errno = ENOMEM;
+ goto error;
+ }
+ clientCtx->values = (void*)(clientCtx + 1);
+
+ /* generate the uuid */
+ if (uuid == NULL) {
+ new_uuid(clientCtx->uuid);
+ } else {
+ if (strlen(uuid) >= sizeof clientCtx->uuid) {
+ errno = EINVAL;
+ goto error2;
+ }
+ strcpy(clientCtx->uuid, uuid);
+ }
+
+ /* init the token */
+ strcpy(clientCtx->token, sessions.initok);
+ clientCtx->timeout = timeout;
+ if (timeout != 0)
+ clientCtx->expiration = now + timeout;
+ else {
+ clientCtx->expiration = (time_t)(~(time_t)0);
+ if (clientCtx->expiration < 0)
+ clientCtx->expiration = (time_t)(((unsigned long long)clientCtx->expiration) >> 1);
+ }
+ if (!ctxStoreAdd (clientCtx)) {
+ errno = ENOMEM;
+ goto error2;
+ }
+
+ clientCtx->access = now;
+ clientCtx->refcount = 1;
+ return clientCtx;
+
+error2:
+ free(clientCtx);
+error:
+ return NULL;
+}
+
+struct AFB_clientCtx *ctxClientCreate (const char *uuid, int timeout)
+{