From 400331c1921a1e8388551b4221b8cb835c06cf21 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Mon, 12 Feb 2018 09:12:47 +0100 Subject: [PATCH] afb-session: Insert call to hooking MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I7d91b133761c7c751300bf1344321e295cce1bc3 Signed-off-by: José Bollo --- src/afb-session.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/afb-session.c b/src/afb-session.c index 88d5b0d2..dfa383b1 100644 --- a/src/afb-session.c +++ b/src/afb-session.c @@ -29,6 +29,7 @@ #include #include "afb-session.h" +#include "afb-hook.h" #include "verbose.h" #define SIZEUUID 37 @@ -189,9 +190,13 @@ static void session_close(struct afb_session *session) /* close only one time */ if (!session->closed) { + /* close it now */ session->closed = 1; - /* free cookies */ + /* emit the hook */ + afb_hook_session_close(session); + + /* release cookies */ for (idx = 0 ; idx < COOKIECOUNT ; idx++) { while ((cookie = session->cookies[idx])) { session->cookies[idx] = cookie->next; @@ -206,6 +211,7 @@ static void session_close(struct afb_session *session) /* destroy the 'session' */ static void session_destroy (struct afb_session *session) { + afb_hook_session_destroy(session); pthread_mutex_destroy(&session->mutex); free(session); } @@ -271,6 +277,8 @@ static struct afb_session *session_add(const char *uuid, int timeout, time_t now return NULL; } + afb_hook_session_create(session); + return session; } @@ -419,8 +427,12 @@ end: /* increase the use count on 'session' (can be NULL) */ struct afb_session *afb_session_addref(struct afb_session *session) { - if (session != NULL) - __atomic_add_fetch(&session->refcount, 1, __ATOMIC_RELAXED); + if (session != NULL) { + afb_hook_session_unref(session); + afb_hook_session_addref(session); + session->refcount++; + session_unlock(session); + } return session; } @@ -431,7 +443,8 @@ void afb_session_unref(struct afb_session *session) return; session_lock(session); - if (!__atomic_sub_fetch(&session->refcount, 1, __ATOMIC_RELAXED)) { + afb_hook_session_unref(session); + if (!--session->refcount) { if (session->autoclose) session_close(session); if (session->notinset) { @@ -489,11 +502,11 @@ int afb_session_check_token (struct afb_session *session, const char *token) /* generate a new token and update client context */ void afb_session_new_token (struct afb_session *session) { - /* Old token was valid let's regenerate a new one */ + session_unlock(session); new_uuid(session->token); - - /* keep track of time for session timeout and further clean up */ session_update_expiration(session, NOW); + afb_hook_session_renew(session); + session_unlock(session); } /* Returns the uuid of 'session' */ -- 2.16.6