Change-Id: I51b7c20ffe2a1fecf1471522df0aa66d81dcaec1
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
if (session->config->ldpaths)
afb_apis_add_pathset(session->config->ldpaths);
if (session->config->ldpaths)
afb_apis_add_pathset(session->config->ldpaths);
- ctxStoreInit(CTX_NBCLIENTS);
+ ctxStoreInit(CTX_NBCLIENTS, session->config->cntxTimeout, afb_apis_count());
install_error_handlers();
install_error_handlers();
AFB_clientCtx **store; // sessions store
int count; // current number of sessions
int max;
AFB_clientCtx **store; // sessions store
int count; // current number of sessions
int max;
+ int timeout;
+ int apicount;
} sessions;
static const char key_uuid[] = "uuid";
} sessions;
static const char key_uuid[] = "uuid";
// Free context [XXXX Should be protected again memory abort XXXX]
static void ctxUuidFreeCB (AFB_clientCtx *client)
{
// Free context [XXXX Should be protected again memory abort XXXX]
static void ctxUuidFreeCB (AFB_clientCtx *client)
{
// If application add a handle let's free it now
if (client->contexts != NULL) {
// If application add a handle let's free it now
if (client->contexts != NULL) {
- cnt = afb_apis_count();
// Free client handle with a standard Free function, with app callback or ignore it
// Free client handle with a standard Free function, with app callback or ignore it
- for (idx=0; idx < cnt; idx ++) {
+ for (idx=0; idx < sessions.apicount; idx ++) {
if (client->contexts[idx] != NULL) {
afb_apis_free_context(idx, client->contexts[idx]);
}
if (client->contexts[idx] != NULL) {
afb_apis_free_context(idx, client->contexts[idx]);
}
}
// Create a new store in RAM, not that is too small it will be automatically extended
}
// Create a new store in RAM, not that is too small it will be automatically extended
-void ctxStoreInit (int nbSession)
+void ctxStoreInit (int nbSession, int timeout, int apicount)
{
// let's create as store as hashtable does not have any
sessions.store = calloc (1 + (unsigned)nbSession, sizeof(AFB_clientCtx));
sessions.max = nbSession;
{
// let's create as store as hashtable does not have any
sessions.store = calloc (1 + (unsigned)nbSession, sizeof(AFB_clientCtx));
sessions.max = nbSession;
+ sessions.timeout = timeout;
+ sessions.apicount = apicount;
}
static AFB_clientCtx *ctxStoreSearch (const char* uuid)
}
static AFB_clientCtx *ctxStoreSearch (const char* uuid)
clientCtx = ctxStoreSearch (uuid);
if (clientCtx) {
clientCtx = ctxStoreSearch (uuid);
if (clientCtx) {
- if (ctxStoreTooOld (clientCtx, request->config->cntxTimeout)) {
+ if (ctxStoreTooOld (clientCtx, sessions.timeout)) {
// this session is too old let's delete it
ctxStoreDel (clientCtx);
clientCtx = NULL;
// this session is too old let's delete it
ctxStoreDel (clientCtx);
clientCtx = NULL;
// we have no session let's create one otherwise let's clean any exiting values
if (clientCtx == NULL) {
clientCtx = calloc(1, sizeof(AFB_clientCtx)); // init NULL clientContext
// we have no session let's create one otherwise let's clean any exiting values
if (clientCtx == NULL) {
clientCtx = calloc(1, sizeof(AFB_clientCtx)); // init NULL clientContext
- clientCtx->contexts = calloc ((unsigned)afb_apis_count(), sizeof (void*));
+ clientCtx->contexts = calloc ((unsigned)sessions.apicount, sizeof (void*));
}
uuid_generate(newuuid); // create a new UUID
uuid_unparse_lower(newuuid, clientCtx->uuid);
// if table is full at 50% let's clean it up
}
uuid_generate(newuuid); // create a new UUID
uuid_unparse_lower(newuuid, clientCtx->uuid);
// if table is full at 50% let's clean it up
- if(sessions.count > (sessions.max / 2)) ctxStoreGarbage(request->config->cntxTimeout);
+ if(sessions.count > (sessions.max / 2)) ctxStoreGarbage(sessions.timeout);
// finally add uuid into hashtable
if (AFB_SUCCESS != ctxStoreAdd (clientCtx)) {
// finally add uuid into hashtable
if (AFB_SUCCESS != ctxStoreAdd (clientCtx)) {
return AFB_FALSE;
// compare current token with previous one
return AFB_FALSE;
// compare current token with previous one
- if ((0 == strcmp (token, clientCtx->token)) && (!ctxStoreTooOld (clientCtx, request->config->cntxTimeout))) {
+ if ((0 == strcmp (token, clientCtx->token)) && (!ctxStoreTooOld (clientCtx, sessions.timeout))) {
extern AFB_error ctxTokenCheck (AFB_clientCtx *clientCtx, AFB_request *request);
extern AFB_error ctxTokenReset (AFB_clientCtx *clientCtx, AFB_request *request);
extern AFB_clientCtx *ctxClientGet (AFB_request *request);
extern AFB_error ctxTokenCheck (AFB_clientCtx *clientCtx, AFB_request *request);
extern AFB_error ctxTokenReset (AFB_clientCtx *clientCtx, AFB_request *request);
extern AFB_clientCtx *ctxClientGet (AFB_request *request);
-extern void ctxStoreInit (int);
+extern void ctxStoreInit (int nbSession, int timeout, int apicount);