X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-trace.c;h=79c7e0355a16589d6fd8f1e1894536710353db6e;hb=65353dce81a629e042800bb7b86fcd869a76727e;hp=3f773953256c99c616009e86d2e1f7e4bd250799;hpb=f96bbb49cc9bcd81693300191cf7a01b879fd83d;p=src%2Fapp-framework-binder.git diff --git a/src/afb-trace.c b/src/afb-trace.c index 3f773953..79c7e035 100644 --- a/src/afb-trace.c +++ b/src/afb-trace.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017, 2018 "IoT.bzh" + * Copyright (C) 2015-2020 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,6 +15,8 @@ * limitations under the License. */ +#if WITH_AFB_HOOK && WITH_AFB_TRACE + #define _GNU_SOURCE #include @@ -65,7 +67,7 @@ /* struct for tags */ struct tag { struct tag *next; /* link to the next */ - char tag[1]; /* name of the tag */ + char tag[]; /* name of the tag */ }; /* struct for events */ @@ -148,18 +150,8 @@ static void ctxt_error(char **errors, const char *format, ...) /* timestamp */ static struct json_object *timestamp(const struct afb_hookid *hookid) { -#if JSON_C_MAJOR_VERSION > 0 || JSON_C_MINOR_VERSION >= 12 - char ts[50]; - - snprintf(ts, sizeof ts, "%llu.%06lu", - (long long unsigned)hookid->time.tv_sec, - (long unsigned)((hookid->time.tv_nsec + 500) / 1000)); - - return json_object_new_double_s(0.0f, ts); /* the real value isn't used */ -#else return json_object_new_double((double)hookid->time.tv_sec + (double)hookid->time.tv_nsec * .000000001); -#endif } /* verbosity level name or NULL */ @@ -207,21 +199,23 @@ static void emit(void *closure, const struct afb_hookid *hookid, const char *typ static void hook_xreq(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *action, const char *format, ...) { - struct json_object *cred = NULL; + struct afb_cred *cred; + struct json_object *jcred = NULL; const char *session = NULL; va_list ap; if (xreq->context.session) session = afb_session_uuid(xreq->context.session); - if (xreq->cred) - wrap_json_pack(&cred, "{si ss si si ss* ss*}", - "uid", (int)xreq->cred->uid, - "user", xreq->cred->user, - "gid", (int)xreq->cred->gid, - "pid", (int)xreq->cred->pid, - "label", xreq->cred->label, - "id", xreq->cred->id + cred = xreq->context.credentials; + if (cred) + wrap_json_pack(&jcred, "{si ss si si ss* ss*}", + "uid", (int)cred->uid, + "user", cred->user, + "gid", (int)cred->gid, + "pid", (int)cred->pid, + "label", cred->label, + "id", cred->id ); va_start(ap, format); emit(closure, hookid, "request", "{si ss ss ss so* ss*}", format, ap, @@ -229,7 +223,7 @@ static void hook_xreq(void *closure, const struct afb_hookid *hookid, const stru "api", xreq->request.called_api, "verb", xreq->request.called_verb, "action", action, - "credentials", cred, + "credentials", jcred, "session", session); va_end(ap); } @@ -717,6 +711,23 @@ static void hook_api_delete_api(void *closure, const struct afb_hookid *hookid, hook_api(closure, hookid, export, "delete_api", "{si}", "status", result); } +static void hook_api_on_event_handler_before(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int event_x2, struct json_object *object, const char *pattern) +{ + hook_api(closure, hookid, export, "on_event_handler.before", + "{ss ss sO?}", "pattern", pattern, "event", event, "data", object); +} + +static void hook_api_on_event_handler_after(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int event_x2, struct json_object *object, const char *pattern) +{ + hook_api(closure, hookid, export, "on_event_handler.after", + "{ss ss sO?}", "pattern", pattern, "event", event, "data", object); +} + +static void hook_api_settings(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct json_object *object) +{ + hook_api(closure, hookid, export, "settings", "{sO}", "settings", object); +} + static struct afb_hook_api_itf hook_api_itf = { .hook_api_event_broadcast_before = hook_api_event_broadcast_before, .hook_api_event_broadcast_after = hook_api_event_broadcast_after, @@ -754,6 +765,9 @@ static struct afb_hook_api_itf hook_api_itf = { .hook_api_class_provide = hook_api_class_provide, .hook_api_class_require = hook_api_class_require, .hook_api_delete_api = hook_api_delete_api, + .hook_api_on_event_handler_before = hook_api_on_event_handler_before, + .hook_api_on_event_handler_after = hook_api_on_event_handler_after, + .hook_api_settings = hook_api_settings, }; /*******************************************************************************/ @@ -841,7 +855,7 @@ static void hook_session(void *closure, const struct afb_hookid *hookid, struct static void hook_session_create(void *closure, const struct afb_hookid *hookid, struct afb_session *session) { - hook_session(closure, hookid, session, "create", "{ss}", "token", afb_session_token(session)); + hook_session(closure, hookid, session, "create", NULL); } static void hook_session_close(void *closure, const struct afb_hookid *hookid, struct afb_session *session) @@ -854,11 +868,6 @@ static void hook_session_destroy(void *closure, const struct afb_hookid *hookid, hook_session(closure, hookid, session, "destroy", NULL); } -static void hook_session_renew(void *closure, const struct afb_hookid *hookid, struct afb_session *session) -{ - hook_session(closure, hookid, session, "renew", "{ss}", "token", afb_session_token(session)); -} - static void hook_session_addref(void *closure, const struct afb_hookid *hookid, struct afb_session *session) { hook_session(closure, hookid, session, "addref", NULL); @@ -873,7 +882,6 @@ static struct afb_hook_session_itf hook_session_itf = { .hook_session_create = hook_session_create, .hook_session_close = hook_session_close, .hook_session_destroy = hook_session_destroy, - .hook_session_renew = hook_session_renew, .hook_session_addref = hook_session_addref, .hook_session_unref = hook_session_unref }; @@ -1061,7 +1069,7 @@ static struct tag *trace_get_tag(struct afb_trace *trace, const char *name, int if (!tag && alloc) { /* creation if needed */ - tag = malloc(sizeof * tag + strlen(name)); + tag = malloc(sizeof * tag + 1 + strlen(name)); if (tag) { strcpy(tag->tag, name); tag->next = trace->tags; @@ -1595,3 +1603,5 @@ int afb_trace_drop(afb_req_t req, struct json_object *args, struct afb_trace *tr free(context.errors); return -1; } + +#endif