Update copyright dates
[src/app-framework-binder.git] / src / afb-trace.c
index 802015f..79c7e03 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2019 "IoT.bzh"
+ * Copyright (C) 2015-2020 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -67,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 */
@@ -199,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,
@@ -221,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);
 }
@@ -853,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)
@@ -866,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);
@@ -885,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
 };
@@ -1073,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;