aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-session.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-03-27 14:24:46 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-03-27 14:27:52 +0200
commit3bf52bb36ed428d0a7b947519fbccc7c376fd4a9 (patch)
tree88f6b06b74a7e2cd63abe128c4959a87465f683b /src/afb-session.c
parent8ab18c9dd70205755b67001ce27a499c0196ad63 (diff)
Replace session's value with sessions's cookies
This is a simplifaction with the benefits of only allocating needed memory and avoiding to create indexes on apis (path to dynanic?). Conversely it replaces a direct access with a linear search. Change-Id: Ibb130528ad8f23dfd6b420c228f51e181efb2664 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-session.c')
-rw-r--r--src/afb-session.c42
1 files changed, 2 insertions, 40 deletions
diff --git a/src/afb-session.c b/src/afb-session.c
index db81457c..13b9505e 100644
--- a/src/afb-session.c
+++ b/src/afb-session.c
@@ -33,12 +33,6 @@
#define NOW (time(NULL))
-struct value
-{
- void *value;
- void (*freecb)(void*);
-};
-
struct cookie
{
struct cookie *next;
@@ -56,7 +50,6 @@ struct afb_session
time_t access;
char uuid[37]; // long term authentication of remote client
char token[37]; // short term authentication of remote client
- struct value *values;
struct cookie *cookies;
};
@@ -67,7 +60,6 @@ static struct {
int count; // current number of sessions
int max;
int timeout;
- int apicount;
char initok[37];
} sessions;
@@ -82,16 +74,8 @@ static void new_uuid(char uuid[37])
// Free context [XXXX Should be protected again memory abort XXXX]
static void free_data (struct afb_session *session)
{
- int idx;
struct cookie *cookie;
- // If application add a handle let's free it now
- assert (session->values != NULL);
-
- // Free session handle with a standard Free function, with app callback or ignore it
- for (idx=0; idx < sessions.apicount; idx ++)
- afb_session_set_value(session, idx, NULL, NULL);
-
// free cookies
cookie = session->cookies;
while (cookie != NULL) {
@@ -104,13 +88,12 @@ static void free_data (struct afb_session *session)
}
// Create a new store in RAM, not that is too small it will be automatically extended
-void afb_session_init (int max_session_count, int timeout, const char *initok, int context_count)
+void afb_session_init (int max_session_count, int timeout, const char *initok)
{
// let's create as store as hashtable does not have any
sessions.store = calloc (1 + (unsigned)max_session_count, sizeof(struct afb_session));
sessions.max = max_session_count;
sessions.timeout = timeout;
- sessions.apicount = context_count;
if (initok == NULL)
/* without token, a secret is made to forbid creation of sessions */
new_uuid(sessions.initok);
@@ -223,12 +206,11 @@ static struct afb_session *make_session (const char *uuid, int timeout, time_t n
struct afb_session *session;
/* allocates a new one */
- session = calloc(1, sizeof(struct afb_session) + ((unsigned)sessions.apicount * sizeof(*session->values)));
+ session = calloc(1, sizeof(struct afb_session));
if (session == NULL) {
errno = ENOMEM;
goto error;
}
- session->values = (void*)(session + 1);
/* generate the uuid */
if (uuid == NULL) {
@@ -394,26 +376,6 @@ void afb_session_set_LOA (struct afb_session *session, unsigned loa)
session->loa = loa;
}
-void *afb_session_get_value(struct afb_session *session, int index)
-{
- assert(session != NULL);
- assert(index >= 0);
- assert(index < sessions.apicount);
- return session->values[index].value;
-}
-
-void afb_session_set_value(struct afb_session *session, int index, void *value, void (*freecb)(void*))
-{
- struct value prev;
- assert(session != NULL);
- assert(index >= 0);
- assert(index < sessions.apicount);
- prev = session->values[index];
- session->values[index] = (struct value){.value = value, .freecb = freecb};
- if (prev.value != NULL && prev.value != value && prev.freecb != NULL)
- prev.freecb(prev.value);
-}
-
void *afb_session_get_cookie(struct afb_session *session, const void *key)
{
struct cookie *cookie;