X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fsession.c;h=16dc836903021bef8cfd9f36bf9ebf496d4ebd84;hb=a4487d8a46d3e4400bf73ce817fa1a34cde31a6f;hp=667738c484a9c174770f539bb2521d15db45c40c;hpb=e33f64f9e2352665f68ea9e7c16c11330beae625;p=src%2Fapp-framework-binder.git diff --git a/src/session.c b/src/session.c index 667738c4..16dc8369 100644 --- a/src/session.c +++ b/src/session.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 "IoT.bzh" + * Copyright (C) 2015, 2016 "IoT.bzh" * Author "Fulup Ar Foll" * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -48,6 +48,7 @@ struct afb_event_listener_list struct AFB_clientCtx { unsigned refcount; + unsigned loa; time_t expiration; // expiration time of the token time_t access; char uuid[37]; // long term authentication of remote client @@ -276,6 +277,7 @@ void ctxClientUnref(struct AFB_clientCtx *clientCtx) --clientCtx->refcount; if (clientCtx->refcount == 0 && clientCtx->uuid[0] == 0) { ctxStoreDel (clientCtx); + free(clientCtx); } } } @@ -284,8 +286,16 @@ void ctxClientUnref(struct AFB_clientCtx *clientCtx) void ctxClientClose (struct AFB_clientCtx *clientCtx) { assert(clientCtx != NULL); - ctxUuidFreeCB (clientCtx); - clientCtx->uuid[0] = 0; + if (clientCtx->uuid[0] != 0) { + clientCtx->uuid[0] = 0; + ctxUuidFreeCB (clientCtx); + while(clientCtx->listeners != NULL) + ctxClientEventListenerRemove(clientCtx, clientCtx->listeners->listener); + if (clientCtx->refcount == 0) { + ctxStoreDel (clientCtx); + free(clientCtx); + } + } } // Sample Generic Ping Debug API @@ -425,6 +435,18 @@ const char *ctxClientGetToken (struct AFB_clientCtx *clientCtx) return clientCtx->token; } +unsigned ctxClientGetLOA (struct AFB_clientCtx *clientCtx) +{ + assert(clientCtx != NULL); + return clientCtx->loa; +} + +void ctxClientSetLOA (struct AFB_clientCtx *clientCtx, unsigned loa) +{ + assert(clientCtx != NULL); + clientCtx->loa = loa; +} + void *ctxClientValueGet(struct AFB_clientCtx *clientCtx, int index) { assert(clientCtx != NULL); @@ -441,6 +463,6 @@ void ctxClientValueSet(struct AFB_clientCtx *clientCtx, int index, void *value, assert(index < sessions.apicount); prev = clientCtx->values[index]; clientCtx->values[index] = (struct client_value){.value = value, .free_value = free_value}; - if (prev.value != NULL && prev.free_value != NULL) + if (prev.value != NULL && prev.value != value && prev.free_value != NULL) prev.free_value(prev.value); }