X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fsession.c;h=e30688ab3e2e5939b0fe3b55ec3fd5403ca8ac64;hb=68a8eaafe5f43480f29308bfd2ec12ad54da43f1;hp=da2294bc2a285dc0153029a24a7f709ae0201b52;hpb=fb230eee946673ed5ebe9659d623c2a06d0a80ce;p=src%2Fapp-framework-binder.git diff --git a/src/session.c b/src/session.c index da2294bc..e30688ab 100644 --- a/src/session.c +++ b/src/session.c @@ -63,13 +63,13 @@ static void ctxUuidFreeCB (struct AFB_clientCtx *client) } // Create a new store in RAM, not that is too small it will be automatically extended -void ctxStoreInit (int nbSession, int timeout, int apicount, const char *initok) +void ctxStoreInit (int nbSession, int timeout, const char *initok) { // let's create as store as hashtable does not have any sessions.store = calloc (1 + (unsigned)nbSession, sizeof(struct AFB_clientCtx)); sessions.max = nbSession; sessions.timeout = timeout; - sessions.apicount = apicount; + sessions.apicount = afb_apis_count(); if (strlen(initok) >= 37) { fprintf(stderr, "Error: initial token '%s' too long (max length 36)", initok); exit(1); @@ -184,11 +184,13 @@ struct AFB_clientCtx *ctxClientGetForUuid (const char *uuid) } /* mimic old behaviour */ +/* +TODO remove? not remove? if (sessions.initok == NULL) return NULL; - +*/ /* check the uuid if given */ - if (uuid != NULL && 1 + strlen(uuid) >= sizeof clientCtx->uuid) + if (uuid != NULL && strlen(uuid) >= sizeof clientCtx->uuid) return NULL; /* returns a new one */ @@ -243,7 +245,7 @@ void ctxClientClose (struct AFB_clientCtx *clientCtx) } // Sample Generic Ping Debug API -int ctxTokenCheck (struct AFB_clientCtx *clientCtx, const char *token) +int ctxTokenCheckLen (struct AFB_clientCtx *clientCtx, const char *token, size_t length) { assert(clientCtx != NULL); assert(token != NULL); @@ -252,13 +254,20 @@ int ctxTokenCheck (struct AFB_clientCtx *clientCtx, const char *token) if (ctxStoreTooOld (clientCtx, NOW)) return 0; - if (!clientCtx->token[0] || 0 == strcmp (token, clientCtx->token)) { - clientCtx->created = 1; /* creates by default */ - return 1; - } + if (clientCtx->token[0] && (length >= sizeof(clientCtx->token) || strncmp (token, clientCtx->token, length) || clientCtx->token[length])) + return 0; + + clientCtx->created = 1; /* creates by default */ + return 1; +} + +// Sample Generic Ping Debug API +int ctxTokenCheck (struct AFB_clientCtx *clientCtx, const char *token) +{ + assert(clientCtx != NULL); + assert(token != NULL); - // Token is not valid let move level of assurance to zero and free attached client handle - return 0; + return ctxTokenCheckLen(clientCtx, token, strlen(token)); } // generate a new token and update client context