int timeout;
time_t expiration; // expiration time of the token
pthread_mutex_t mutex;
+ struct cookie *cookies[COOKEYCOUNT];
char idx;
char uuid[SIZEUUID]; // long term authentication of remote client
char token[SIZEUUID]; // short term authentication of remote client
- struct cookie *cookies[COOKEYCOUNT];
};
// Session UUID are store in a simple array [for 10 sessions this should be enough]
}
// Free context [XXXX Should be protected again memory abort XXXX]
-static void remove_all_cookies(struct afb_session *session)
+static void close_session(struct afb_session *session)
{
int idx;
- struct cookie *cookie, *next;
+ struct cookie *cookie;
- // free cookies
+ /* free cookies */
for (idx = 0 ; idx < COOKEYCOUNT ; idx++) {
- cookie = session->cookies[idx];
- session->cookies[idx] = NULL;
- while (cookie != NULL) {
- next = cookie->next;
+ while ((cookie = session->cookies[idx])) {
+ session->cookies[idx] = cookie->next;
if (cookie->freecb != NULL)
cookie->freecb(cookie->value);
free(cookie);
- cookie = next;
}
}
}
assert (session != NULL);
- remove_all_cookies(session);
+ close_session(session);
pthread_mutex_lock(&sessions.mutex);
prv = &sessions.heads[(int)session->idx];
while (*prv)
strcpy(session->token, sessions.initok);
session->timeout = timeout;
session->expiration = expiration;
+
+ /* link */
session->idx = (char)idx;
session->next = sessions.heads[idx];
sessions.heads[idx] = session;
pthread_mutex_lock(&session->mutex);
if (session->uuid[0] != 0) {
session->uuid[0] = 0;
- remove_all_cookies(session);
- if (session->refcount == 0) {
+ if (session->refcount)
+ close_session(session);
+ else {
destroy (session);
return;
}