session: allows individual timeout 45/5945/1
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 10 Jun 2016 17:10:29 +0000 (19:10 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 10 Jun 2016 17:10:29 +0000 (19:10 +0200)
Change-Id: Ibc3412c5a5dd50c23a7b035941d4aed278b62039
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/session.c

index ddff2c3..cbf883c 100644 (file)
@@ -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)