aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-06-10 19:10:29 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-06-10 19:10:29 +0200
commitda61b6ea09f77ea5a8ff6cb79b440db858980211 (patch)
tree9d5695516cc12728637fae3bd4f1e3dc76518fa3
parent5f65a54eda6644f3e151c4f60ae88d9e163abcba (diff)
session: allows individual timeout
Change-Id: Ibc3412c5a5dd50c23a7b035941d4aed278b62039 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/session.c13
1 files 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)