Improves naming of session's module
[src/app-framework-binder.git] / src / afb-hook.c
index 2dfd1b1..d5c534d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 "IoT.bzh"
+ * Copyright (C) 2016, 2017 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
 
 #include "afb-context.h"
 #include "afb-hook.h"
-#include "session.h"
+#include "afb-session.h"
 #include "verbose.h"
 
 /*
- * Trace 
+ * Definition of a hook
  */
 struct afb_hook {
        struct afb_hook *next; /* next hook */
        unsigned refcount; /* reference count */
-       char *api; 
-       char *verb;
-       struct AFB_clientCtx *session;
+       char *api; /* api hooked or NULL for any */
+       char *verb; /* verb hooked or NULL for any */
+       struct afb_session *session; /* session hooked or NULL if any */
        unsigned flags; /* hook flags */
-       struct afb_hook_req_itf *reqitf;
-       void *closure;
+       struct afb_hook_req_itf *reqitf; /* interface of hook */
+       void *closure; /* closure for callbacks */
 };
 
+/*
+ * Link hooks to a hooked request
+ */
 struct hook_req_observer {
-       struct afb_hook *hook;
-       struct hook_req_observer *next;
+       struct afb_hook *hook; /* the hook */
+       struct hook_req_observer *next; /* the next observer */
 };
 
 /*
@@ -70,8 +73,10 @@ struct hook_subcall {
        void *cb_closure; /* cient closure */
 };
 
+/* counter of hooking */
 static unsigned hook_count = 0;
 
+/* list of hooks */
 static struct afb_hook *list_of_hooks = NULL;
 
 /******************************************************************************
@@ -521,7 +526,7 @@ struct afb_req afb_hook_req_call(struct afb_req req, struct afb_context *context
        return req;
 }
 
-struct afb_hook *afb_hook_req_create(const char *api, const char *verb, struct AFB_clientCtx *session, unsigned flags, struct afb_hook_req_itf *itf, void *closure)
+struct afb_hook *afb_hook_req_create(const char *api, const char *verb, struct afb_session *session, unsigned flags, struct afb_hook_req_itf *itf, void *closure)
 {
        struct afb_hook *hook;
 
@@ -531,13 +536,13 @@ struct afb_hook *afb_hook_req_create(const char *api, const char *verb, struct A
 
        hook->api = api ? strdup(api) : NULL;
        hook->verb = verb ? strdup(verb) : NULL;
-       hook->session = session ? ctxClientAddRef(session) : NULL;
+       hook->session = session ? afb_session_addref(session) : NULL;
 
        if ((api && !hook->api) || (verb && !hook->verb)) {
                free(hook->api);
                free(hook->verb);
                if (hook->session)
-                       ctxClientUnref(hook->session);
+                       afb_session_unref(hook->session);
                free(hook);
                return NULL;
        }
@@ -572,7 +577,7 @@ void afb_hook_unref(struct afb_hook *hook)
                free(hook->api);
                free(hook->verb);
                if (hook->session)
-                       ctxClientUnref(hook->session);
+                       afb_session_unref(hook->session);
                free(hook);
        }
 }