From da61b6ea09f77ea5a8ff6cb79b440db858980211 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Fri, 10 Jun 2016 19:10:29 +0200 Subject: [PATCH] session: allows individual timeout MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ibc3412c5a5dd50c23a7b035941d4aed278b62039 Signed-off-by: José Bollo --- src/session.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/session.c b/src/session.c index ddff2c3e..cbf883c6 100644 --- a/src/session.c +++ b/src/session.c @@ -42,6 +42,7 @@ struct AFB_clientCtx { unsigned refcount; unsigned loa; + int timeout; time_t expiration; // expiration time of the token time_t access; char uuid[37]; // long term authentication of remote client @@ -221,7 +222,14 @@ static struct AFB_clientCtx *new_context (const char *uuid, int timeout, time_t /* init the token */ strcpy(clientCtx->token, sessions.initok); - clientCtx->expiration = now + sessions.timeout; + 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; @@ -337,7 +345,8 @@ void ctxTokenNew (struct AFB_clientCtx *clientCtx) new_uuid(clientCtx->token); // keep track of time for session timeout and further clean up - clientCtx->expiration = NOW + sessions.timeout; + if (clientCtx->timeout != 0) + clientCtx->expiration = NOW + clientCtx->timeout; } const char *ctxClientGetUuid (struct AFB_clientCtx *clientCtx) -- 2.16.6