Allow detection of session closure
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 31 Mar 2017 09:55:20 +0000 (11:55 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 31 Mar 2017 09:55:20 +0000 (11:55 +0200)
In some case it can be good to have a function called
when the session closes. This is the case when a binding
records an item in the context. With this modification
the recorded item can be simply NULL.

Change-Id: I5e23f00eb2a6e2639fdeea15f9dea79c7df9dfbb
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-session.c

index 07092ce..bc1c1c5 100644 (file)
@@ -98,7 +98,7 @@ static void free_data (struct afb_session *session)
                session->cookies[idx] = NULL;
                while (cookie != NULL) {
                        next = cookie->next;
-                       if (cookie->value != NULL && cookie->freecb != NULL)
+                       if (cookie->freecb != NULL)
                                cookie->freecb(cookie->value);
                        free(cookie);
                        cookie = next;
@@ -420,7 +420,7 @@ int afb_session_set_cookie(struct afb_session *session, const void *key, void *v
        cookie = session->cookies[idx];
        while(cookie != NULL) {
                if (cookie->key == key) {
-                       if (cookie->value != NULL && cookie->value != value && cookie->freecb != NULL)
+                       if (cookie->value != value && cookie->freecb)
                                cookie->freecb(cookie->value);
                        cookie->value = value;
                        cookie->freecb = freecb;