X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fsession.c;h=ddff2c3e59cfc417bb68b96e71d26edff8243ae1;hb=5f65a54eda6644f3e151c4f60ae88d9e163abcba;hp=e0d0a8e64ea05431fd361e9a7b868fbf6251942a;hpb=7e0abe76db7b90369429bf387d7aad0fb5a42328;p=src%2Fapp-framework-binder.git diff --git a/src/session.c b/src/session.c index e0d0a8e6..ddff2c3e 100644 --- a/src/session.c +++ b/src/session.c @@ -196,30 +196,11 @@ static void ctxStoreCleanUp (time_t now) } } -// This function will return exiting client context or newly created client context -struct AFB_clientCtx *ctxClientGetSession (const char *uuid, int *created) +static struct AFB_clientCtx *new_context (const char *uuid, int timeout, time_t now) { struct AFB_clientCtx *clientCtx; - time_t now; - - /* cleaning */ - now = NOW; - ctxStoreCleanUp (now); - - /* search for an existing one not too old */ - if (uuid != NULL) { - if (strlen(uuid) >= sizeof clientCtx->uuid) { - errno = EINVAL; - goto error; - } - clientCtx = ctxStoreSearch(uuid); - if (clientCtx != NULL) { - *created = 0; - goto found; - } - } - /* returns a new one */ + /* allocates a new one */ clientCtx = calloc(1, sizeof(struct AFB_clientCtx) + ((unsigned)sessions.apicount * sizeof(*clientCtx->values))); if (clientCtx == NULL) { errno = ENOMEM; @@ -231,6 +212,10 @@ struct AFB_clientCtx *ctxClientGetSession (const char *uuid, int *created) if (uuid == NULL) { new_uuid(clientCtx->uuid); } else { + if (strlen(uuid) >= sizeof clientCtx->uuid) { + errno = EINVAL; + goto error2; + } strcpy(clientCtx->uuid, uuid); } @@ -241,11 +226,9 @@ struct AFB_clientCtx *ctxClientGetSession (const char *uuid, int *created) errno = ENOMEM; goto error2; } - *created = 1; -found: clientCtx->access = now; - clientCtx->refcount++; + clientCtx->refcount = 1; return clientCtx; error2: @@ -254,6 +237,48 @@ error: return NULL; } +struct AFB_clientCtx *ctxClientCreate (const char *uuid, int timeout) +{ + time_t now; + + /* cleaning */ + now = NOW; + ctxStoreCleanUp (now); + + /* search for an existing one not too old */ + if (uuid != NULL && ctxStoreSearch(uuid) != NULL) { + errno = EEXIST; + return NULL; + } + + return new_context(uuid, timeout, now); +} + +// This function will return exiting client context or newly created client context +struct AFB_clientCtx *ctxClientGetSession (const char *uuid, int *created) +{ + struct AFB_clientCtx *clientCtx; + time_t now; + + /* cleaning */ + now = NOW; + ctxStoreCleanUp (now); + + /* search for an existing one not too old */ + if (uuid != NULL) { + clientCtx = ctxStoreSearch(uuid); + if (clientCtx != NULL) { + *created = 0; + clientCtx->access = now; + clientCtx->refcount++; + return clientCtx; + } + } + + *created = 1; + return new_context(uuid, sessions.timeout, now); +} + struct AFB_clientCtx *ctxClientAddRef(struct AFB_clientCtx *clientCtx) { if (clientCtx != NULL)