#include <json-c/json.h>
#include "afb-session.h"
+#include "afb-hook.h"
#include "verbose.h"
#define SIZEUUID 37
/* 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;
/* destroy the 'session' */
static void session_destroy (struct afb_session *session)
{
+ afb_hook_session_destroy(session);
pthread_mutex_destroy(&session->mutex);
free(session);
}
return NULL;
}
+ afb_hook_session_create(session);
+
return session;
}
return 0;
}
+/**
+ * Iterate the sessions and call 'callback' with
+ * the 'closure' for each session.
+ */
+void afb_session_foreach(void (*callback)(void *closure, struct afb_session *session), void *closure)
+{
+ struct afb_session *session;
+ int idx;
+
+ /* Loop on Sessions Table and remove anything that is older than timeout */
+ sessionset_lock();
+ for (idx = 0 ; idx < HEADCOUNT; idx++) {
+ session = sessions.heads[idx];
+ while (session) {
+ if (!session->closed)
+ callback(closure, session);
+ session = session->next;
+ }
+ }
+ sessionset_unlock();
+}
+
/**
* Cleanup the sessionset of its closed or expired sessions
*/
/* 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_addref(session);
+ session->refcount++;
+ session_unlock(session);
+ }
return 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) {
/* 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' */