summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-08-11 17:00:08 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2018-01-31 14:55:56 +0100
commit379b11154f301a30e79154c0af1ef1f257149efa (patch)
tree76828461e837af1b65673a4aa5d97f03159af208
parentc3249e6aa03ef10494a2a4a170bbed0cfc38a83e (diff)
afb-hook: Allow to unhook some apis
The apis starting with a $ (dollar) will not be tracked by hooks Change-Id: I3b83458c288ef1eb27993d4c71785b32e5a72deb Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-api.h5
-rw-r--r--src/afb-hook.c75
2 files changed, 47 insertions, 33 deletions
diff --git a/src/afb-api.h b/src/afb-api.h
index dd5d4e0c..a9de8434 100644
--- a/src/afb-api.h
+++ b/src/afb-api.h
@@ -39,3 +39,8 @@ struct afb_api
};
extern int afb_api_is_valid_name(const char *name);
+
+#define AFB_API_UNHOOKABLE_PREFIX_CHAR '$'
+#define AFB_API_UNHOOKABLE_PREFIX_STRING "$"
+#define afb_api_is_hookable(api) ((api)[0] != AFB_API_UNHOOKABLE_PREFIX_CHAR)
+
diff --git a/src/afb-hook.c b/src/afb-hook.c
index 54058dea..b5dbe154 100644
--- a/src/afb-hook.c
+++ b/src/afb-hook.c
@@ -38,6 +38,7 @@
#include "afb-xreq.h"
#include "afb-export.h"
#include "afb-evt.h"
+#include "afb-api.h"
#include "verbose.h"
/**
@@ -582,19 +583,21 @@ void afb_hook_init_xreq(struct afb_xreq *xreq)
/* scan hook list to get the expected flags */
flags = 0;
- pthread_rwlock_rdlock(&rwlock);
- hook = list_of_xreq_hooks;
- while (hook) {
- f = hook->flags & afb_hook_flags_req_all;
- add = f != 0
- && (!hook->session || hook->session == xreq->context.session)
- && (!hook->api || !strcasecmp(hook->api, xreq->request.api))
- && (!hook->verb || !strcasecmp(hook->verb, xreq->request.verb));
- if (add)
- flags |= f;
- hook = hook->next;
+ if (afb_api_is_hookable(xreq->request.api)) {
+ pthread_rwlock_rdlock(&rwlock);
+ hook = list_of_xreq_hooks;
+ while (hook) {
+ f = hook->flags & afb_hook_flags_req_all;
+ add = f != 0
+ && (!hook->session || hook->session == xreq->context.session)
+ && (!hook->api || !strcasecmp(hook->api, xreq->request.api))
+ && (!hook->verb || !strcasecmp(hook->verb, xreq->request.verb));
+ if (add)
+ flags |= f;
+ hook = hook->next;
+ }
+ pthread_rwlock_unlock(&rwlock);
}
- pthread_rwlock_unlock(&rwlock);
/* store the hooking data */
xreq->hookflags = flags;
@@ -919,15 +922,17 @@ int afb_hook_flags_ditf(const char *api)
int flags;
struct afb_hook_ditf *hook;
- pthread_rwlock_rdlock(&rwlock);
flags = 0;
- hook = list_of_ditf_hooks;
- while (hook) {
- if (!api || !hook->api || !strcasecmp(hook->api, api))
- flags |= hook->flags;
- hook = hook->next;
+ if (!api || afb_api_is_hookable(api)) {
+ pthread_rwlock_rdlock(&rwlock);
+ hook = list_of_ditf_hooks;
+ while (hook) {
+ if (!api || !hook->api || !strcasecmp(hook->api, api))
+ flags |= hook->flags;
+ hook = hook->next;
+ }
+ pthread_rwlock_unlock(&rwlock);
}
- pthread_rwlock_unlock(&rwlock);
return flags;
}
@@ -1131,15 +1136,17 @@ int afb_hook_flags_svc(const char *api)
int flags;
struct afb_hook_svc *hook;
- pthread_rwlock_rdlock(&rwlock);
flags = 0;
- hook = list_of_svc_hooks;
- while (hook) {
- if (!api || !hook->api || !strcasecmp(hook->api, api))
- flags |= hook->flags;
- hook = hook->next;
+ if (!api || afb_api_is_hookable(api)) {
+ pthread_rwlock_rdlock(&rwlock);
+ hook = list_of_svc_hooks;
+ while (hook) {
+ if (!api || !hook->api || !strcasecmp(hook->api, api))
+ flags |= hook->flags;
+ hook = hook->next;
+ }
+ pthread_rwlock_unlock(&rwlock);
}
- pthread_rwlock_unlock(&rwlock);
return flags;
}
@@ -1343,15 +1350,17 @@ int afb_hook_flags_evt(const char *name)
int flags;
struct afb_hook_evt *hook;
- pthread_rwlock_rdlock(&rwlock);
flags = 0;
- hook = list_of_evt_hooks;
- while (hook) {
- if (!name || !hook->pattern || !fnmatch(hook->pattern, name, FNM_CASEFOLD))
- flags |= hook->flags;
- hook = hook->next;
+ if (!name || afb_api_is_hookable(name)) {
+ pthread_rwlock_rdlock(&rwlock);
+ hook = list_of_evt_hooks;
+ while (hook) {
+ if (!name || !hook->pattern || !fnmatch(hook->pattern, name, FNM_CASEFOLD))
+ flags |= hook->flags;
+ hook = hook->next;
+ }
+ pthread_rwlock_unlock(&rwlock);
}
- pthread_rwlock_unlock(&rwlock);
return flags;
}