2 * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
3 * Author José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
29 #include <json-c/json.h>
30 #if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
31 #define JSON_C_TO_STRING_NOSLASHESCAPE 0
34 #define AFB_BINDING_VERSION 3
35 #include <afb/afb-binding.h>
38 #include "afb-hook-flags.h"
40 #include "afb-session.h"
42 #include "afb-export.h"
44 #include "afb-session.h"
45 #include "afb-trace.h"
47 #include "wrap-json.h"
50 /*******************************************************************************/
51 /***** default names *****/
52 /*******************************************************************************/
54 #if !defined(DEFAULT_EVENT_NAME)
55 # define DEFAULT_EVENT_NAME "trace"
57 #if !defined(DEFAULT_TAG_NAME)
58 # define DEFAULT_TAG_NAME "trace"
61 /*******************************************************************************/
63 /*******************************************************************************/
67 struct tag *next; /* link to the next */
68 char tag[1]; /* name of the tag */
71 /* struct for events */
73 struct event *next; /* link to the next event */
74 struct afb_evtid *evtid; /* the event */
77 /* struct for sessions */
79 struct afb_session *session; /* the session */
80 struct afb_trace *trace; /* the tracer */
83 /* struct for recording hooks */
85 struct hook *next; /* link to next hook */
86 void *handler; /* the handler of the hook */
87 struct event *event; /* the associated event */
88 struct tag *tag; /* the associated tag */
89 struct afb_session *session; /* the associated session */
95 Trace_Type_Xreq, /* xreq hooks */
96 Trace_Type_Api, /* api hooks */
97 Trace_Type_Evt, /* evt hooks */
98 Trace_Type_Session, /* session hooks */
99 Trace_Type_Global, /* global hooks */
100 #if !defined(REMOVE_LEGACY_TRACE)
101 Trace_Legacy_Type_Ditf, /* export hooks */
102 Trace_Legacy_Type_Svc, /* export hooks */
104 Trace_Type_Count, /* count of types of hooks */
110 int refcount; /* reference count */
111 pthread_mutex_t mutex; /* concurrency management */
112 const char *apiname; /* api name for events */
113 struct afb_session *bound; /* bound to session */
114 struct event *events; /* list of events */
115 struct tag *tags; /* list of tags */
116 struct hook *hooks[Trace_Type_Count]; /* hooks */
119 /*******************************************************************************/
120 /***** utility functions *****/
121 /*******************************************************************************/
123 static void ctxt_error(char **errors, const char *format, ...)
131 va_start(ap, format);
132 len = vsnprintf(buffer, sizeof buffer, format, ap);
134 if (len > (int)(sizeof buffer - 2))
135 len = (int)(sizeof buffer - 2);
136 buffer[len++] = '\n';
140 sz = errs ? strlen(errs) : 0;
141 errs = realloc(errs, sz + (size_t)len);
143 memcpy(errs + sz, buffer, len);
149 static struct json_object *timestamp(const struct afb_hookid *hookid)
151 #if JSON_C_MAJOR_VERSION > 0 || JSON_C_MINOR_VERSION >= 12
154 snprintf(ts, sizeof ts, "%llu.%06lu",
155 (long long unsigned)hookid->time.tv_sec,
156 (long unsigned)((hookid->time.tv_nsec + 500) / 1000));
158 return json_object_new_double_s(0.0f, ts); /* the real value isn't used */
160 return json_object_new_double((double)hookid->time.tv_sec +
161 (double)hookid->time.tv_nsec * .000000001);
165 /* verbosity level name or NULL */
166 static const char *verbosity_level_name(int level)
168 static const char *names[] = {
176 return level >= Log_Level_Error && level <= Log_Level_Debug ? names[level - Log_Level_Error] : NULL;
180 static void emit(void *closure, const struct afb_hookid *hookid, const char *type, const char *fmt1, const char *fmt2, va_list ap2, ...)
182 struct hook *hook = closure;
183 struct json_object *data, *data1, *data2;
186 data1 = data2 = data = NULL;
188 wrap_json_vpack(&data1, fmt1, ap1);
191 wrap_json_vpack(&data2, fmt2, ap2);
193 wrap_json_pack(&data, "{so ss ss si so so*}",
194 "time", timestamp(hookid),
195 "tag", hook->tag->tag,
197 "id", (int)(hookid->id & INT_MAX),
201 afb_evt_evtid_push(hook->event->evtid, data);
204 /*******************************************************************************/
205 /***** trace the requests *****/
206 /*******************************************************************************/
208 static void hook_xreq(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *action, const char *format, ...)
210 struct json_object *cred = NULL;
211 const char *session = NULL;
214 if (xreq->context.session)
215 session = afb_session_uuid(xreq->context.session);
218 wrap_json_pack(&cred, "{si ss si si ss* ss*}",
219 "uid", (int)xreq->cred->uid,
220 "user", xreq->cred->user,
221 "gid", (int)xreq->cred->gid,
222 "pid", (int)xreq->cred->pid,
223 "label", xreq->cred->label,
226 va_start(ap, format);
227 emit(closure, hookid, "request", "{si ss ss ss so* ss*}", format, ap,
228 "index", xreq->hookindex,
229 "api", xreq->request.called_api,
230 "verb", xreq->request.called_verb,
237 static void hook_xreq_begin(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq)
239 hook_xreq(closure, hookid, xreq, "begin", "{sO?}",
240 "json", afb_xreq_unhooked_json((struct afb_xreq*)xreq));
243 static void hook_xreq_end(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq)
245 hook_xreq(closure, hookid, xreq, "end", NULL);
248 static void hook_xreq_json(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *obj)
250 hook_xreq(closure, hookid, xreq, "json", "{sO?}",
254 static void hook_xreq_get(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *name, struct afb_arg arg)
256 hook_xreq(closure, hookid, xreq, "get", "{ss? ss? ss? ss?}",
263 static void hook_xreq_reply(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *obj, const char *error, const char *info)
265 hook_xreq(closure, hookid, xreq, "reply", "{sO? ss? ss?}",
271 static void hook_xreq_context_get(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, void *value)
273 hook_xreq(closure, hookid, xreq, "context_get", NULL);
276 static void hook_xreq_context_set(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, void *value, void (*free_value)(void*))
278 hook_xreq(closure, hookid, xreq, "context_set", NULL);
281 static void hook_xreq_addref(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq)
283 hook_xreq(closure, hookid, xreq, "addref", NULL);
286 static void hook_xreq_unref(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq)
288 hook_xreq(closure, hookid, xreq, "unref", NULL);
291 static void hook_xreq_session_close(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq)
293 hook_xreq(closure, hookid, xreq, "session_close", NULL);
296 static void hook_xreq_session_set_LOA(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, unsigned level, int result)
298 hook_xreq(closure, hookid, xreq, "session_set_LOA", "{si si}",
303 static void hook_xreq_subscribe(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_event_x2 *event, int result)
305 hook_xreq(closure, hookid, xreq, "subscribe", "{s{ss si} si}",
307 "name", afb_evt_event_x2_fullname(event),
308 "id", afb_evt_event_x2_id(event),
312 static void hook_xreq_unsubscribe(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_event_x2 *event, int result)
314 hook_xreq(closure, hookid, xreq, "unsubscribe", "{s{ss? si} si}",
316 "name", afb_evt_event_x2_fullname(event),
317 "id", afb_evt_event_x2_id(event),
321 static void hook_xreq_subcall(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args)
323 hook_xreq(closure, hookid, xreq, "subcall", "{ss? ss? sO?}",
329 static void hook_xreq_subcall_result(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *object, const char *error, const char *info)
331 hook_xreq(closure, hookid, xreq, "subcall_result", "{sO? ss? ss?}",
337 static void hook_xreq_subcallsync(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args)
339 hook_xreq(closure, hookid, xreq, "subcallsync", "{ss? ss? sO?}",
345 static void hook_xreq_subcallsync_result(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int status, struct json_object *object, const char *error, const char *info)
347 hook_xreq(closure, hookid, xreq, "subcallsync_result", "{si sO? ss? ss?}",
354 static void hook_xreq_vverbose(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args)
356 struct json_object *pos;
365 len = vasprintf(&msg, fmt, ap);
369 wrap_json_pack(&pos, "{ss si ss*}", "file", file, "line", line, "function", func);
371 hook_xreq(closure, hookid, xreq, "vverbose", "{si ss* ss? so*}",
373 "type", verbosity_level_name(level),
374 len < 0 ? "format" : "message", len < 0 ? fmt : msg,
380 static void hook_xreq_store(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_stored_req *sreq)
382 hook_xreq(closure, hookid, xreq, "store", NULL);
385 static void hook_xreq_unstore(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq)
387 hook_xreq(closure, hookid, xreq, "unstore", NULL);
390 static void hook_xreq_has_permission(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *permission, int result)
392 hook_xreq(closure, hookid, xreq, "has_permission", "{ss sb}",
393 "permission", permission,
397 static void hook_xreq_get_application_id(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, char *result)
399 hook_xreq(closure, hookid, xreq, "get_application_id", "{ss?}",
403 static void hook_xreq_context_make(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int replace, void *(*create_value)(void*), void (*free_value)(void*), void *create_closure, void *result)
405 char pc[50], pf[50], pv[50], pr[50];
406 snprintf(pc, sizeof pc, "%p", create_value);
407 snprintf(pf, sizeof pf, "%p", free_value);
408 snprintf(pv, sizeof pv, "%p", create_closure);
409 snprintf(pr, sizeof pr, "%p", result);
410 hook_xreq(closure, hookid, xreq, "context_make", "{sb ss ss ss ss}",
418 static void hook_xreq_get_uid(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int result)
420 hook_xreq(closure, hookid, xreq, "get_uid", "{si}",
424 static void hook_xreq_get_client_info(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *result)
426 hook_xreq(closure, hookid, xreq, "get_client_info", "{sO}",
430 static struct afb_hook_xreq_itf hook_xreq_itf = {
431 .hook_xreq_begin = hook_xreq_begin,
432 .hook_xreq_end = hook_xreq_end,
433 .hook_xreq_json = hook_xreq_json,
434 .hook_xreq_get = hook_xreq_get,
435 .hook_xreq_reply = hook_xreq_reply,
436 .hook_xreq_legacy_context_get = hook_xreq_context_get,
437 .hook_xreq_legacy_context_set = hook_xreq_context_set,
438 .hook_xreq_addref = hook_xreq_addref,
439 .hook_xreq_unref = hook_xreq_unref,
440 .hook_xreq_session_close = hook_xreq_session_close,
441 .hook_xreq_session_set_LOA = hook_xreq_session_set_LOA,
442 .hook_xreq_subscribe = hook_xreq_subscribe,
443 .hook_xreq_unsubscribe = hook_xreq_unsubscribe,
444 .hook_xreq_subcall = hook_xreq_subcall,
445 .hook_xreq_subcall_result = hook_xreq_subcall_result,
446 .hook_xreq_subcallsync = hook_xreq_subcallsync,
447 .hook_xreq_subcallsync_result = hook_xreq_subcallsync_result,
448 .hook_xreq_vverbose = hook_xreq_vverbose,
449 .hook_xreq_legacy_store = hook_xreq_store,
450 .hook_xreq_legacy_unstore = hook_xreq_unstore,
451 .hook_xreq_has_permission = hook_xreq_has_permission,
452 .hook_xreq_get_application_id = hook_xreq_get_application_id,
453 .hook_xreq_context_make = hook_xreq_context_make,
454 .hook_xreq_get_uid = hook_xreq_get_uid,
455 .hook_xreq_get_client_info = hook_xreq_get_client_info,
458 /*******************************************************************************/
459 /***** trace the api interface *****/
460 /*******************************************************************************/
462 static void hook_api(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *action, const char *format, ...)
466 va_start(ap, format);
467 emit(closure, hookid, "api", "{ss ss}", format, ap,
468 "api", afb_export_apiname(export),
473 static void hook_api_event_broadcast_before(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct json_object *object)
475 hook_api(closure, hookid, export, "event_broadcast_before", "{ss sO?}",
476 "name", name, "data", object);
479 static void hook_api_event_broadcast_after(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct json_object *object, int result)
481 hook_api(closure, hookid, export, "event_broadcast_after", "{ss sO? si}",
482 "name", name, "data", object, "result", result);
485 static void hook_api_get_event_loop(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct sd_event *result)
487 hook_api(closure, hookid, export, "get_event_loop", NULL);
490 static void hook_api_get_user_bus(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct sd_bus *result)
492 hook_api(closure, hookid, export, "get_user_bus", NULL);
495 static void hook_api_get_system_bus(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct sd_bus *result)
497 hook_api(closure, hookid, export, "get_system_bus", NULL);
500 static void hook_api_vverbose(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int level, const char *file, int line, const char *function, const char *fmt, va_list args)
502 struct json_object *pos;
511 len = vasprintf(&msg, fmt, ap);
515 wrap_json_pack(&pos, "{ss si ss*}", "file", file, "line", line, "function", function);
517 hook_api(closure, hookid, export, "vverbose", "{si ss* ss? so*}",
519 "type", verbosity_level_name(level),
520 len < 0 ? "format" : "message", len < 0 ? fmt : msg,
526 static void hook_api_event_make(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct afb_event_x2 *result)
528 hook_api(closure, hookid, export, "event_make", "{ss ss si}",
529 "name", name, "event", afb_evt_event_x2_fullname(result), "id", afb_evt_event_x2_id(result));
532 static void hook_api_rootdir_get_fd(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result)
534 char path[PATH_MAX], proc[100];
535 const char *key, *val;
539 snprintf(proc, sizeof proc, "/proc/self/fd/%d", result);
540 s = readlink(proc, path, sizeof path);
541 path[s < 0 ? 0 : s >= sizeof path ? sizeof path - 1 : s] = 0;
546 val = strerror(errno);
549 hook_api(closure, hookid, export, "rootdir_get_fd", "{ss}", key, val);
552 static void hook_api_rootdir_open_locale(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *filename, int flags, const char *locale, int result)
554 char path[PATH_MAX], proc[100];
555 const char *key, *val;
559 snprintf(proc, sizeof proc, "/proc/self/fd/%d", result);
560 s = readlink(proc, path, sizeof path);
561 path[s < 0 ? 0 : s >= sizeof path ? sizeof path - 1 : s] = 0;
566 val = strerror(errno);
569 hook_api(closure, hookid, export, "rootdir_open_locale", "{ss si ss* ss}",
576 static void hook_api_queue_job(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result)
578 hook_api(closure, hookid, export, "queue_job", "{ss}", "result", result);
581 static void hook_api_unstore_req(void * closure, const struct afb_hookid *hookid, const struct afb_export *export, struct afb_stored_req *sreq)
583 hook_api(closure, hookid, export, "unstore_req", NULL);
586 static void hook_api_require_api(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, int initialized)
588 hook_api(closure, hookid, export, "require_api", "{ss sb}", "name", name, "initialized", initialized);
591 static void hook_api_require_api_result(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, int initialized, int result)
593 hook_api(closure, hookid, export, "require_api_result", "{ss sb si}", "name", name, "initialized", initialized, "result", result);
596 static void hook_api_add_alias_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *api, const char *alias, int result)
598 hook_api(closure, hookid, export, "add_alias", "{si ss? ss}", "status", result, "api", api, "alias", alias);
601 static void hook_api_start_before(void *closure, const struct afb_hookid *hookid, const struct afb_export *export)
603 hook_api(closure, hookid, export, "start_before", NULL);
606 static void hook_api_start_after(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int status)
608 hook_api(closure, hookid, export, "start_after", "{si}", "result", status);
611 static void hook_api_on_event_before(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int evtid, struct json_object *object)
613 hook_api(closure, hookid, export, "on_event_before", "{ss si sO*}",
614 "event", event, "id", evtid, "data", object);
617 static void hook_api_on_event_after(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int evtid, struct json_object *object)
619 hook_api(closure, hookid, export, "on_event_after", "{ss si sO?}",
620 "event", event, "id", evtid, "data", object);
623 static void hook_api_call(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *api, const char *verb, struct json_object *args)
625 hook_api(closure, hookid, export, "call", "{ss ss sO?}",
626 "api", api, "verb", verb, "args", args);
629 static void hook_api_call_result(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct json_object *object, const char *error, const char *info)
631 hook_api(closure, hookid, export, "call_result", "{sO? ss? ss?}",
632 "object", object, "error", error, "info", info);
635 static void hook_api_callsync(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *api, const char *verb, struct json_object *args)
637 hook_api(closure, hookid, export, "callsync", "{ss ss sO?}",
638 "api", api, "verb", verb, "args", args);
641 static void hook_api_callsync_result(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int status, struct json_object *object, const char *error, const char *info)
643 hook_api(closure, hookid, export, "callsync_result", "{si sO? ss? ss?}",
644 "status", status, "object", object, "error", error, "info", info);
647 static void hook_api_new_api_before(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *api, const char *info, int noconcurrency)
649 hook_api(closure, hookid, export, "new_api.before", "{ss ss? sb}",
650 "api", api, "info", info, "noconcurrency", noconcurrency);
653 static void hook_api_new_api_after(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *api)
655 hook_api(closure, hookid, export, "new_api.after", "{si ss}",
656 "status", result, "api", api);
659 static void hook_api_api_set_verbs_v2(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const struct afb_verb_v2 *verbs)
661 hook_api(closure, hookid, export, "set_verbs_v2", "{si}", "status", result);
664 static void hook_api_api_set_verbs_v3(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const struct afb_verb_v3 *verbs)
666 hook_api(closure, hookid, export, "set_verbs_v3", "{si}", "status", result);
670 static void hook_api_api_add_verb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *verb, const char *info, int glob)
672 hook_api(closure, hookid, export, "add_verb", "{si ss ss? sb}", "status", result, "verb", verb, "info", info, "glob", glob);
675 static void hook_api_api_del_verb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *verb)
677 hook_api(closure, hookid, export, "del_verb", "{si ss}", "status", result, "verb", verb);
680 static void hook_api_api_set_on_event(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result)
682 hook_api(closure, hookid, export, "set_on_event", "{si}", "status", result);
685 static void hook_api_api_set_on_init(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result)
687 hook_api(closure, hookid, export, "set_on_init", "{si}", "status", result);
690 static void hook_api_api_seal(void *closure, const struct afb_hookid *hookid, const struct afb_export *export)
692 hook_api(closure, hookid, export, "seal", NULL);
695 static void hook_api_event_handler_add(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *pattern)
697 hook_api(closure, hookid, export, "event_handler_add", "{si ss?}", "status", result, "pattern", pattern);
700 static void hook_api_event_handler_del(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *pattern)
702 hook_api(closure, hookid, export, "event_handler_del", "{si ss?}", "status", result, "pattern", pattern);
705 static void hook_api_class_provide(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *name)
707 hook_api(closure, hookid, export, "class_provide", "{si ss?}", "status", result, "name", name);
710 static void hook_api_class_require(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *name)
712 hook_api(closure, hookid, export, "class_require", "{si ss?}", "status", result, "name", name);
715 static void hook_api_delete_api(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result)
717 hook_api(closure, hookid, export, "delete_api", "{si}", "status", result);
720 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)
722 hook_api(closure, hookid, export, "on_event_handler.before",
723 "{ss ss sO?}", "pattern", pattern, "event", event, "data", object);
726 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)
728 hook_api(closure, hookid, export, "on_event_handler.after",
729 "{ss ss sO?}", "pattern", pattern, "event", event, "data", object);
732 static void hook_api_settings(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct json_object *object)
734 hook_api(closure, hookid, export, "settings", "{sO}", "settings", object);
737 static struct afb_hook_api_itf hook_api_itf = {
738 .hook_api_event_broadcast_before = hook_api_event_broadcast_before,
739 .hook_api_event_broadcast_after = hook_api_event_broadcast_after,
740 .hook_api_get_event_loop = hook_api_get_event_loop,
741 .hook_api_get_user_bus = hook_api_get_user_bus,
742 .hook_api_get_system_bus = hook_api_get_system_bus,
743 .hook_api_vverbose = hook_api_vverbose,
744 .hook_api_event_make = hook_api_event_make,
745 .hook_api_rootdir_get_fd = hook_api_rootdir_get_fd,
746 .hook_api_rootdir_open_locale = hook_api_rootdir_open_locale,
747 .hook_api_queue_job = hook_api_queue_job,
748 .hook_api_legacy_unstore_req = hook_api_unstore_req,
749 .hook_api_require_api = hook_api_require_api,
750 .hook_api_require_api_result = hook_api_require_api_result,
751 .hook_api_add_alias = hook_api_add_alias_cb,
752 .hook_api_start_before = hook_api_start_before,
753 .hook_api_start_after = hook_api_start_after,
754 .hook_api_on_event_before = hook_api_on_event_before,
755 .hook_api_on_event_after = hook_api_on_event_after,
756 .hook_api_call = hook_api_call,
757 .hook_api_call_result = hook_api_call_result,
758 .hook_api_callsync = hook_api_callsync,
759 .hook_api_callsync_result = hook_api_callsync_result,
760 .hook_api_new_api_before = hook_api_new_api_before,
761 .hook_api_new_api_after = hook_api_new_api_after,
762 .hook_api_api_set_verbs_v2 = hook_api_api_set_verbs_v2,
763 .hook_api_api_set_verbs_v3 = hook_api_api_set_verbs_v3,
764 .hook_api_api_add_verb = hook_api_api_add_verb,
765 .hook_api_api_del_verb = hook_api_api_del_verb,
766 .hook_api_api_set_on_event = hook_api_api_set_on_event,
767 .hook_api_api_set_on_init = hook_api_api_set_on_init,
768 .hook_api_api_seal = hook_api_api_seal,
769 .hook_api_event_handler_add = hook_api_event_handler_add,
770 .hook_api_event_handler_del = hook_api_event_handler_del,
771 .hook_api_class_provide = hook_api_class_provide,
772 .hook_api_class_require = hook_api_class_require,
773 .hook_api_delete_api = hook_api_delete_api,
774 .hook_api_on_event_handler_before = hook_api_on_event_handler_before,
775 .hook_api_on_event_handler_after = hook_api_on_event_handler_after,
776 .hook_api_settings = hook_api_settings,
779 /*******************************************************************************/
780 /***** trace the events *****/
781 /*******************************************************************************/
783 static void hook_evt(void *closure, const struct afb_hookid *hookid, const char *evt, int id, const char *action, const char *format, ...)
787 va_start(ap, format);
788 emit(closure, hookid, "event", "{si ss ss}", format, ap,
795 static void hook_evt_create(void *closure, const struct afb_hookid *hookid, const char *evt, int id)
797 hook_evt(closure, hookid, evt, id, "create", NULL);
800 static void hook_evt_push_before(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj)
802 hook_evt(closure, hookid, evt, id, "push_before", "{sO*}", "data", obj);
806 static void hook_evt_push_after(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj, int result)
808 hook_evt(closure, hookid, evt, id, "push_after", "{sO* si}", "data", obj, "result", result);
811 static void hook_evt_broadcast_before(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj)
813 hook_evt(closure, hookid, evt, id, "broadcast_before", "{sO*}", "data", obj);
816 static void hook_evt_broadcast_after(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj, int result)
818 hook_evt(closure, hookid, evt, id, "broadcast_after", "{sO* si}", "data", obj, "result", result);
821 static void hook_evt_name(void *closure, const struct afb_hookid *hookid, const char *evt, int id, const char *result)
823 hook_evt(closure, hookid, evt, id, "name", "{ss}", "result", result);
826 static void hook_evt_addref(void *closure, const struct afb_hookid *hookid, const char *evt, int id)
828 hook_evt(closure, hookid, evt, id, "addref", NULL);
831 static void hook_evt_unref(void *closure, const struct afb_hookid *hookid, const char *evt, int id)
833 hook_evt(closure, hookid, evt, id, "unref", NULL);
836 static struct afb_hook_evt_itf hook_evt_itf = {
837 .hook_evt_create = hook_evt_create,
838 .hook_evt_push_before = hook_evt_push_before,
839 .hook_evt_push_after = hook_evt_push_after,
840 .hook_evt_broadcast_before = hook_evt_broadcast_before,
841 .hook_evt_broadcast_after = hook_evt_broadcast_after,
842 .hook_evt_name = hook_evt_name,
843 .hook_evt_addref = hook_evt_addref,
844 .hook_evt_unref = hook_evt_unref
847 /*******************************************************************************/
848 /***** trace the sessions *****/
849 /*******************************************************************************/
851 static void hook_session(void *closure, const struct afb_hookid *hookid, struct afb_session *session, const char *action, const char *format, ...)
855 va_start(ap, format);
856 emit(closure, hookid, "session", "{ss ss}", format, ap,
857 "uuid", afb_session_uuid(session),
862 static void hook_session_create(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
864 hook_session(closure, hookid, session, "create", "{ss}", "token", afb_session_token(session));
867 static void hook_session_close(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
869 hook_session(closure, hookid, session, "close", NULL);
872 static void hook_session_destroy(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
874 hook_session(closure, hookid, session, "destroy", NULL);
877 static void hook_session_renew(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
879 hook_session(closure, hookid, session, "renew", "{ss}", "token", afb_session_token(session));
882 static void hook_session_addref(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
884 hook_session(closure, hookid, session, "addref", NULL);
887 static void hook_session_unref(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
889 hook_session(closure, hookid, session, "unref", NULL);
892 static struct afb_hook_session_itf hook_session_itf = {
893 .hook_session_create = hook_session_create,
894 .hook_session_close = hook_session_close,
895 .hook_session_destroy = hook_session_destroy,
896 .hook_session_renew = hook_session_renew,
897 .hook_session_addref = hook_session_addref,
898 .hook_session_unref = hook_session_unref
901 /*******************************************************************************/
902 /***** trace the globals *****/
903 /*******************************************************************************/
905 static void hook_global(void *closure, const struct afb_hookid *hookid, const char *action, const char *format, ...)
909 va_start(ap, format);
910 emit(closure, hookid, "global", "{ss}", format, ap, "action", action);
914 static void hook_global_vverbose(void *closure, const struct afb_hookid *hookid, int level, const char *file, int line, const char *function, const char *fmt, va_list args)
916 struct json_object *pos;
925 len = vasprintf(&msg, fmt, ap);
929 wrap_json_pack(&pos, "{ss si ss*}", "file", file, "line", line, "function", function);
931 hook_global(closure, hookid, "vverbose", "{si ss* ss? so*}",
933 "type", verbosity_level_name(level),
934 len < 0 ? "format" : "message", len < 0 ? fmt : msg,
940 static struct afb_hook_global_itf hook_global_itf = {
941 .hook_global_vverbose = hook_global_vverbose,
944 /*******************************************************************************/
945 /***** abstract types *****/
946 /*******************************************************************************/
952 void (*unref)(void*);
953 int (*get_flag)(const char*);
955 abstracting[Trace_Type_Count] =
960 .unref = (void(*)(void*))afb_hook_unref_xreq,
961 .get_flag = afb_hook_flags_xreq_from_text
966 .unref = (void(*)(void*))afb_hook_unref_api,
967 .get_flag = afb_hook_flags_api_from_text
972 .unref = (void(*)(void*))afb_hook_unref_evt,
973 .get_flag = afb_hook_flags_evt_from_text
975 [Trace_Type_Session] =
978 .unref = (void(*)(void*))afb_hook_unref_session,
979 .get_flag = afb_hook_flags_session_from_text
981 [Trace_Type_Global] =
984 .unref = (void(*)(void*))afb_hook_unref_global,
985 .get_flag = afb_hook_flags_global_from_text
987 #if !defined(REMOVE_LEGACY_TRACE)
988 [Trace_Legacy_Type_Ditf] =
991 .unref = (void(*)(void*))afb_hook_unref_api,
992 .get_flag = afb_hook_flags_legacy_ditf_from_text
994 [Trace_Legacy_Type_Svc] =
997 .unref = (void(*)(void*))afb_hook_unref_api,
998 .get_flag = afb_hook_flags_legacy_svc_from_text
1003 /*******************************************************************************/
1004 /***** handle trace data *****/
1005 /*******************************************************************************/
1007 /* drop hooks of 'trace' matching 'tag' and 'event' and 'session' */
1008 static void trace_unhook(struct afb_trace *trace, struct tag *tag, struct event *event, struct afb_session *session)
1011 struct hook *hook, **prev;
1013 /* remove any event */
1014 for (i = 0 ; i < Trace_Type_Count ; i++) {
1015 prev = &trace->hooks[i];
1016 while ((hook = *prev)) {
1017 if ((tag && tag != hook->tag)
1018 || (event && event != hook->event)
1019 || (session && session != hook->session))
1023 abstracting[i].unref(hook->handler);
1030 /* cleanup: removes unused tags, events and sessions of the 'trace' */
1031 static void trace_cleanup(struct afb_trace *trace)
1035 struct tag *tag, **ptag;
1036 struct event *event, **pevent;
1039 ptag = &trace->tags;
1040 while ((tag = *ptag)) {
1041 /* search for tag */
1042 for (hook = NULL, i = 0 ; !hook && i < Trace_Type_Count ; i++)
1043 for (hook = trace->hooks[i] ; hook && hook->tag != tag ; hook = hook->next);
1044 /* keep or free whether used or not */
1053 pevent = &trace->events;
1054 while ((event = *pevent)) {
1055 /* search for event */
1056 for (hook = NULL, i = 0 ; !hook && i < Trace_Type_Count ; i++)
1057 for (hook = trace->hooks[i] ; hook && hook->event != event ; hook = hook->next);
1058 /* keep or free whether used or not */
1060 pevent = &event->next;
1062 *pevent = event->next;
1063 afb_evt_evtid_unref(event->evtid);
1070 * Get the tag of 'name' within 'trace'.
1071 * If 'alloc' isn't zero, create the tag and add it.
1073 static struct tag *trace_get_tag(struct afb_trace *trace, const char *name, int alloc)
1077 /* search the tag of 'name' */
1079 while (tag && strcmp(name, tag->tag))
1082 if (!tag && alloc) {
1083 /* creation if needed */
1084 tag = malloc(sizeof * tag + strlen(name));
1086 strcpy(tag->tag, name);
1087 tag->next = trace->tags;
1095 * Get the event of 'name' within 'trace'.
1096 * If 'alloc' isn't zero, create the event and add it.
1098 static struct event *trace_get_event(struct afb_trace *trace, const char *name, int alloc)
1100 struct event *event;
1102 /* search the event */
1103 event = trace->events;
1104 while (event && strcmp(afb_evt_evtid_name(event->evtid), name))
1105 event = event->next;
1107 if (!event && alloc) {
1108 event = malloc(sizeof * event);
1110 event->evtid = afb_evt_evtid_create2(trace->apiname, name);
1112 event->next = trace->events;
1113 trace->events = event;
1124 * called on session closing
1126 static void session_closed(void *item)
1128 struct cookie *cookie = item;
1130 pthread_mutex_lock(&cookie->trace->mutex);
1131 trace_unhook(cookie->trace, NULL, NULL, cookie->session);
1132 pthread_mutex_unlock(&cookie->trace->mutex);
1137 * records the cookie of session for tracking close
1139 static void *session_open(void *closure)
1141 struct cookie *param = closure, *cookie;
1142 cookie = malloc(sizeof *cookie);
1149 * Get the session of 'uuid' within 'trace'.
1150 * If 'alloc' isn't zero, create the session and add it.
1152 static struct afb_session *trace_get_session_by_uuid(struct afb_trace *trace, const char *uuid, int alloc)
1154 struct cookie cookie;
1157 cookie.session = afb_session_search(uuid);
1159 cookie.session = afb_session_get(uuid, AFB_SESSION_TIMEOUT_DEFAULT, NULL);
1160 if (cookie.session) {
1161 cookie.trace = trace;
1162 afb_session_cookie(cookie.session, cookie.trace, session_open, session_closed, &cookie, 0);
1165 return cookie.session;
1168 static struct hook *trace_make_detached_hook(struct afb_trace *trace, const char *event, const char *tag)
1172 tag = tag ?: DEFAULT_TAG_NAME;
1173 event = event ?: DEFAULT_EVENT_NAME;
1174 hook = malloc(sizeof *hook);
1176 hook->tag = trace_get_tag(trace, tag, 1);
1177 hook->event = trace_get_event(trace, event, 1);
1178 hook->session = NULL;
1179 hook->handler = NULL;
1184 static void trace_attach_hook(struct afb_trace *trace, struct hook *hook, enum trace_type type)
1186 hook->next = trace->hooks[type];
1187 trace->hooks[type] = hook;
1190 /*******************************************************************************/
1191 /***** handle client requests *****/
1192 /*******************************************************************************/
1196 struct afb_trace *trace;
1203 struct context *context;
1207 const char *apiname;
1208 const char *verbname;
1209 const char *pattern;
1210 int flags[Trace_Type_Count];
1213 static void addhook(struct desc *desc, enum trace_type type)
1216 struct afb_session *session;
1217 struct afb_session *bind;
1218 struct afb_trace *trace = desc->context->trace;
1220 /* check permission for bound traces */
1221 bind = trace->bound;
1223 if (type != Trace_Type_Xreq) {
1224 ctxt_error(&desc->context->errors, "tracing %s is forbidden", abstracting[type].name);
1228 ctxt_error(&desc->context->errors, "setting session is forbidden");
1233 /* allocate the hook */
1234 hook = trace_make_detached_hook(trace, desc->name, desc->tag);
1236 ctxt_error(&desc->context->errors, "allocation of hook failed");
1240 /* create the hook handler */
1242 case Trace_Type_Xreq:
1244 session = afb_session_addref(bind);
1246 session = trace_get_session_by_uuid(trace, desc->uuid, 1);
1248 ctxt_error(&desc->context->errors, "allocation of session failed");
1253 hook->handler = afb_hook_create_xreq(desc->apiname, desc->verbname, session,
1254 desc->flags[type], &hook_xreq_itf, hook);
1255 afb_session_unref(session);
1257 case Trace_Type_Api:
1258 hook->handler = afb_hook_create_api(desc->apiname, desc->flags[type], &hook_api_itf, hook);
1260 case Trace_Type_Evt:
1261 hook->handler = afb_hook_create_evt(desc->pattern, desc->flags[type], &hook_evt_itf, hook);
1263 case Trace_Type_Session:
1264 hook->handler = afb_hook_create_session(desc->uuid, desc->flags[type], &hook_session_itf, hook);
1266 case Trace_Type_Global:
1267 hook->handler = afb_hook_create_global(desc->flags[type], &hook_global_itf, hook);
1272 if (!hook->handler) {
1273 ctxt_error(&desc->context->errors, "creation of hook failed");
1278 /* attach and activate the hook */
1279 afb_req_subscribe(desc->context->req, afb_evt_event_x2_from_evtid(hook->event->evtid));
1280 trace_attach_hook(trace, hook, type);
1283 static void addhooks(struct desc *desc)
1287 #if !defined(REMOVE_LEGACY_TRACE)
1288 desc->flags[Trace_Type_Api] |= desc->flags[Trace_Legacy_Type_Ditf] | desc->flags[Trace_Legacy_Type_Svc];
1289 desc->flags[Trace_Legacy_Type_Ditf] = desc->flags[Trace_Legacy_Type_Svc] = 0;
1292 for (i = 0 ; i < Trace_Type_Count ; i++) {
1298 static void add_flags(void *closure, struct json_object *object, enum trace_type type)
1301 const char *name, *queried;
1302 struct desc *desc = closure;
1304 if (wrap_json_unpack(object, "s", &name))
1305 ctxt_error(&desc->context->errors, "unexpected %s value %s",
1306 abstracting[type].name,
1307 json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
1309 queried = (name[0] == '*' && !name[1]) ? "all" : name;
1310 value = abstracting[type].get_flag(queried);
1312 desc->flags[type] |= value;
1314 ctxt_error(&desc->context->errors, "unknown %s name %s",
1315 abstracting[type].name, name);
1319 static void add_xreq_flags(void *closure, struct json_object *object)
1321 add_flags(closure, object, Trace_Type_Xreq);
1324 #if !defined(REMOVE_LEGACY_TRACE)
1325 static void legacy_add_ditf_flags(void *closure, struct json_object *object)
1327 add_flags(closure, object, Trace_Legacy_Type_Ditf);
1330 static void legacy_add_svc_flags(void *closure, struct json_object *object)
1332 add_flags(closure, object, Trace_Legacy_Type_Svc);
1336 static void add_api_flags(void *closure, struct json_object *object)
1338 add_flags(closure, object, Trace_Type_Api);
1341 static void add_evt_flags(void *closure, struct json_object *object)
1343 add_flags(closure, object, Trace_Type_Evt);
1346 static void add_session_flags(void *closure, struct json_object *object)
1348 add_flags(closure, object, Trace_Type_Session);
1351 static void add_global_flags(void *closure, struct json_object *object)
1353 add_flags(closure, object, Trace_Type_Global);
1357 static void add(void *closure, struct json_object *object)
1361 struct json_object *request, *event, *sub, *global, *session, *api;
1362 #if !defined(REMOVE_LEGACY_TRACE)
1363 struct json_object *daemon, *service;
1366 memcpy (&desc, closure, sizeof desc);
1367 request = event = sub = global = session = api = NULL;
1368 #if !defined(REMOVE_LEGACY_TRACE)
1369 daemon = service = NULL;
1372 rc = wrap_json_unpack(object, "{s?s s?s s?s s?s s?s s?s s?o s?o s?o s?o s?o s?o s?o}",
1375 "apiname", &desc.apiname,
1376 "verbname", &desc.verbname,
1378 "pattern", &desc.pattern,
1380 "request", &request,
1381 #if !defined(REMOVE_LEGACY_TRACE)
1383 "service", &service,
1386 "session", &session,
1392 if (desc.apiname && desc.apiname[0] == '*' && !desc.apiname[1])
1393 desc.apiname = NULL;
1395 if (desc.verbname && desc.verbname[0] == '*' && !desc.verbname[1])
1396 desc.verbname = NULL;
1398 if (desc.uuid && desc.uuid[0] == '*' && !desc.uuid[1])
1401 /* get what is expected */
1403 wrap_json_optarray_for_all(request, add_xreq_flags, &desc);
1406 wrap_json_optarray_for_all(api, add_api_flags, &desc);
1408 #if !defined(REMOVE_LEGACY_TRACE)
1410 wrap_json_optarray_for_all(daemon, legacy_add_ditf_flags, &desc);
1413 wrap_json_optarray_for_all(service, legacy_add_svc_flags, &desc);
1417 wrap_json_optarray_for_all(event, add_evt_flags, &desc);
1420 wrap_json_optarray_for_all(session, add_session_flags, &desc);
1423 wrap_json_optarray_for_all(global, add_global_flags, &desc);
1427 wrap_json_optarray_for_all(sub, add, &desc);
1432 wrap_json_optarray_for_all(object, add_xreq_flags, &desc);
1437 /* drop hooks of given tag */
1438 static void drop_tag(void *closure, struct json_object *object)
1441 struct context *context = closure;
1445 rc = wrap_json_unpack(object, "s", &name);
1447 ctxt_error(&context->errors, "unexpected tag value %s", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
1449 tag = trace_get_tag(context->trace, name, 0);
1451 ctxt_error(&context->errors, "tag %s not found", name);
1453 trace_unhook(context->trace, tag, NULL, NULL);
1457 /* drop hooks of given event */
1458 static void drop_event(void *closure, struct json_object *object)
1461 struct context *context = closure;
1462 struct event *event;
1465 rc = wrap_json_unpack(object, "s", &name);
1467 ctxt_error(&context->errors, "unexpected event value %s", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
1469 event = trace_get_event(context->trace, name, 0);
1471 ctxt_error(&context->errors, "event %s not found", name);
1473 trace_unhook(context->trace, NULL, event, NULL);
1477 /* drop hooks of given session */
1478 static void drop_session(void *closure, struct json_object *object)
1481 struct context *context = closure;
1482 struct afb_session *session;
1485 rc = wrap_json_unpack(object, "s", &uuid);
1487 ctxt_error(&context->errors, "unexpected session value %s", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
1489 session = trace_get_session_by_uuid(context->trace, uuid, 0);
1491 ctxt_error(&context->errors, "session %s not found", uuid);
1493 trace_unhook(context->trace, NULL, NULL, session);
1494 afb_session_unref(session);
1499 /*******************************************************************************/
1500 /***** public interface *****/
1501 /*******************************************************************************/
1503 /* allocates an afb_trace instance */
1504 struct afb_trace *afb_trace_create(const char *apiname, struct afb_session *bound)
1506 struct afb_trace *trace;
1510 trace = calloc(1, sizeof *trace);
1512 trace->refcount = 1;
1513 trace->bound = bound;
1514 trace->apiname = apiname;
1515 pthread_mutex_init(&trace->mutex, NULL);
1520 /* add a reference to the trace */
1521 void afb_trace_addref(struct afb_trace *trace)
1523 __atomic_add_fetch(&trace->refcount, 1, __ATOMIC_RELAXED);
1526 /* drop one reference to the trace */
1527 void afb_trace_unref(struct afb_trace *trace)
1529 if (trace && !__atomic_sub_fetch(&trace->refcount, 1, __ATOMIC_RELAXED)) {
1531 trace_unhook(trace, NULL, NULL, NULL);
1532 trace_cleanup(trace);
1533 pthread_mutex_destroy(&trace->mutex);
1539 int afb_trace_add(afb_req_t req, struct json_object *args, struct afb_trace *trace)
1541 struct context context;
1544 memset(&context, 0, sizeof context);
1545 context.trace = trace;
1548 memset(&desc, 0, sizeof desc);
1549 desc.context = &context;
1551 pthread_mutex_lock(&trace->mutex);
1552 wrap_json_optarray_for_all(args, add, &desc);
1553 pthread_mutex_unlock(&trace->mutex);
1555 if (!context.errors)
1558 afb_req_fail(req, "error-detected", context.errors);
1559 free(context.errors);
1564 int afb_trace_drop(afb_req_t req, struct json_object *args, struct afb_trace *trace)
1567 struct context context;
1568 struct json_object *tags, *events, *uuids;
1570 memset(&context, 0, sizeof context);
1571 context.trace = trace;
1574 /* special: boolean value */
1575 if (!wrap_json_unpack(args, "b", &rc)) {
1577 pthread_mutex_lock(&trace->mutex);
1578 trace_unhook(trace, NULL, NULL, NULL);
1579 trace_cleanup(trace);
1580 pthread_mutex_unlock(&trace->mutex);
1585 tags = events = uuids = NULL;
1586 rc = wrap_json_unpack(args, "{s?o s?o s?o}",
1591 if (rc < 0 || !(events || tags || uuids)) {
1592 afb_req_fail(req, "error-detected", "bad drop arguments");
1596 pthread_mutex_lock(&trace->mutex);
1599 wrap_json_optarray_for_all(tags, drop_tag, &context);
1602 wrap_json_optarray_for_all(events, drop_event, &context);
1605 wrap_json_optarray_for_all(uuids, drop_session, &context);
1607 trace_cleanup(trace);
1609 pthread_mutex_unlock(&trace->mutex);
1611 if (!context.errors)
1614 afb_req_fail(req, "error-detected", context.errors);
1615 free(context.errors);