return NULL;
}
+/* Creates a new session with 'timeout' */
struct afb_session *afb_session_create (int timeout)
{
time_t now;
return make_session(NULL, timeout, now);
}
-// This function will return exiting session or newly created session
+/* Searchs the session of 'uuid' */
+struct afb_session *afb_session_search (const char *uuid)
+{
+ time_t now;
+
+ /* cleaning */
+ now = NOW;
+ cleanup (now);
+ return search(uuid);
+
+}
+
+/* This function will return exiting session or newly created session */
struct afb_session *afb_session_get (const char *uuid, int *created)
{
struct afb_session *session;
/* search for an existing one not too old */
if (uuid != NULL) {
session = search(uuid);
- if (!created)
- return session;
if (session != NULL) {
- *created = 0;
+ if (created)
+ *created = 0;
session->access = now;
session->refcount++;
return session;
}
}
+ /* no existing session found, create it */
+ session = make_session(uuid, sessions.timeout, now);
if (created)
- *created = 1;
+ *created = !!session;
- return make_session(uuid, sessions.timeout, now);
+ return session;
}
struct afb_session *afb_session_addref(struct afb_session *session)
extern const char *afb_session_initial_token();
extern struct afb_session *afb_session_create (int timeout);
+extern struct afb_session *afb_session_search (const char *uuid);
extern struct afb_session *afb_session_get (const char *uuid, int *created);
extern const char *afb_session_uuid (struct afb_session *session);
static struct afb_session *trace_get_session_by_uuid(struct afb_trace *trace, const char *uuid, int alloc)
{
struct cookie cookie;
- int created;
- cookie.session = afb_session_get(uuid, alloc ? &created : NULL);
- if (cookie.session) {
- cookie.trace = trace;
- afb_session_cookie(cookie.session, cookie.trace, session_open, session_closed, &cookie, 0);
+ if (!alloc)
+ cookie.session = afb_session_search(uuid);
+ else {
+ cookie.session = afb_session_get(uuid, NULL);
+ if (cookie.session) {
+ cookie.trace = trace;
+ afb_session_cookie(cookie.session, cookie.trace, session_open, session_closed, &cookie, 0);
+ }
}
return cookie.session;
}