X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fsession.c;h=a5a00406450706c99b043ae801ce83a4040cf9b1;hb=d00571d3c5365f40e7ec2ec3ab0f636afa0db480;hp=cd5b09f70508e0f53bd015c2602325b982293481;hpb=e7c246a1b0d30b8156c7033061a61ecb5d2bdfc8;p=src%2Fapp-framework-binder.git diff --git a/src/session.c b/src/session.c index cd5b09f7..a5a00406 100644 --- a/src/session.c +++ b/src/session.c @@ -270,7 +270,7 @@ PUBLIC json_object * sessionToDisk (AFB_session *session, AFB_request *request, // info is a valid AFB_info type if (!json_object_object_get_ex (info, "jtype", &jtype)) { - response = jsonNewMessage (AFB_EMPTY,"sndcard=%s session=%s No 'AFB_type' args=%s", request->plugin, name, request->post); + response = jsonNewMessage (AFB_EMPTY,"sndcard=%s session=%s No 'AFB_pluginT' args=%s", request->plugin, name, request->post); goto OnErrorExit; } @@ -379,17 +379,19 @@ PUBLIC int ctxStoreGarbage (struct lh_table *lht, const int timeout) { } // This function will return exiting client context or newly created client context -PUBLIC int ctxClientGet (AFB_request *request) { +PUBLIC AFB_error ctxClientGet (AFB_request *request) { static int cid=0; AFB_clientCtx *clientCtx=NULL; const char *uuid; uuid_t newuuid; int ret; - // if client session store is null create it - if (clientCtxs == NULL) { + if (request->config->token == NULL) return AFB_EMPTY; + + // if client session store is null create it + if (clientCtxs == NULL) { clientCtxs= ctxStoreCreate(CTX_NBCLIENTS); - } + } // Check if client as a context or not inside the URL uuid = MHD_lookup_connection_value(request->connection, MHD_GET_ARGUMENT_KIND, "uuid"); @@ -424,18 +426,21 @@ PUBLIC int ctxClientGet (AFB_request *request) { if(clientCtxs->count > (clientCtxs->size*0.5)) ctxStoreGarbage(clientCtxs, request->config->cntxTimeout); // finally add uuid into hashtable - ret= lh_table_insert (clientCtxs, (void*)clientCtx->uuid, clientCtx); + ret=lh_table_insert (clientCtxs, (void*)clientCtx->uuid, clientCtx); + if (ret < 0) return (AFB_FAIL); - if (verbose) fprintf (stderr, "ctxClientGet New uuid=[%s] token=[%s] timestamp=%d\n", clientCtx->uuid, clientCtx->token, clientCtx->timeStamp); - + if (verbose) fprintf (stderr, "ctxClientGet New uuid=[%s] token=[%s] timestamp=%d\n", clientCtx->uuid, clientCtx->token, clientCtx->timeStamp); request->client = clientCtx; - return (ret); + + return (AFB_SUCCESS); } // Sample Generic Ping Debug API PUBLIC AFB_error ctxTokenCheck (AFB_request *request) { const char *token; + if (request->client == NULL) return AFB_EMPTY; + // this time have to extract token from query list token = MHD_lookup_connection_value(request->connection, MHD_GET_ARGUMENT_KIND, "token"); @@ -444,32 +449,36 @@ PUBLIC AFB_error ctxTokenCheck (AFB_request *request) { // compare current token with previous one if ((0 == strcmp (token, request->client->token)) && (!ctxStoreToOld (request->client, request->config->cntxTimeout))) { - return (AFB_TRUE); + return (AFB_SUCCESS); } // Token is not valid let move level of assurance to zero and free attached client handle - return (AFB_FALSE); + return (AFB_FAIL); } // Free Client Session Context -PUBLIC int ctxTokenReset (AFB_request *request) { +PUBLIC AFB_error ctxTokenReset (AFB_request *request) { struct lh_entry* entry; int ret; - + + if (request->client == NULL) return AFB_EMPTY; + entry = lh_table_lookup_entry (clientCtxs, request->client->uuid); - if (entry == NULL) return FALSE; + if (entry == NULL) return AFB_FALSE; lh_table_delete_entry (clientCtxs, entry); - return (TRUE); + return (AFB_SUCCESS); } // generate a new token -PUBLIC char* ctxTokenCreate (AFB_request *request) { +PUBLIC AFB_error ctxTokenCreate (AFB_request *request) { int oldTnkValid; const char *ornew; uuid_t newuuid; + if (request->client == NULL) return AFB_EMPTY; + // create a UUID as token value uuid_generate(newuuid); uuid_unparse_lower(newuuid, request->client->token); @@ -478,15 +487,17 @@ PUBLIC char* ctxTokenCreate (AFB_request *request) { request->client->timeStamp=time(NULL); // Token is also store in context but it might be convenient for plugin to access it directly - return (request->client->token); + return (AFB_SUCCESS); } // generate a new token and update client context -PUBLIC char* ctxTokenRefresh (AFB_request *request) { +PUBLIC AFB_error ctxTokenRefresh (AFB_request *request) { int oldTnkValid; const char *oldornew; uuid_t newuuid; + + if (request->client == NULL) return AFB_EMPTY; // Check if the old token is valid oldTnkValid= ctxTokenCheck (request); @@ -498,7 +509,7 @@ PUBLIC char* ctxTokenRefresh (AFB_request *request) { } // No existing token and no request to create one - if (oldTnkValid != TRUE) return NULL; + if (oldTnkValid != TRUE) return AFB_WARNING; return (ctxTokenCreate (request)); }