Tag broadcasted events with UUID and hop
[src/app-framework-binder.git] / src / afb-api-dbus.c
index a988035..139c647 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2018 "IoT.bzh"
+ * Copyright (C) 2015-2019 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-#if defined(WITH_DBUS_TRANSPARENCY)
+#if WITH_DBUS_TRANSPARENCY
 
 #define _GNU_SOURCE
 
@@ -33,8 +33,6 @@
 
 #include <afb/afb-event-x2.h>
 
-#include "afb-systemd.h"
-
 #include "afb-session.h"
 #include "afb-msg-json.h"
 #include "afb-api.h"
 #include "afb-cred.h"
 #include "afb-evt.h"
 #include "afb-xreq.h"
-#include "verbose.h"
 
+#include "verbose.h"
+#include "systemd.h"
+#include "jobs.h"
 
 static const char DEFAULT_PATH_PREFIX[] = "/org/agl/afb/api/";
 
@@ -130,7 +130,8 @@ static struct api_dbus *make_api_dbus_3(int system, const char *path, size_t pat
        }
 
        /* choose the bus */
-       sdbus = (system ? afb_systemd_get_system_bus : afb_systemd_get_user_bus)();
+       jobs_acquire_event_manager();
+       sdbus = (system ? systemd_get_system_bus : systemd_get_user_bus)();
        if (sdbus == NULL)
                goto error2;
 
@@ -634,7 +635,7 @@ error:
 static void afb_api_dbus_server_event_add(void *closure, const char *event, int eventid);
 static void afb_api_dbus_server_event_remove(void *closure, const char *event, int eventid);
 static void afb_api_dbus_server_event_push(void *closure, const char *event, int eventid, struct json_object *object);
-static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, int eventid, struct json_object *object);
+static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, struct json_object *object, const char *uuid);
 
 /* the interface for events broadcasting */
 static const struct afb_evt_itf evt_broadcast_itf = {
@@ -665,7 +666,7 @@ struct origin
        struct afb_cred *cred;
 
        /* the origin */
-       char name[1];
+       char name[];
 };
 
 /* get the credentials for the message */
@@ -709,7 +710,7 @@ static struct origin *afb_api_dbus_server_origin_get(struct api_dbus *api, const
        }
 
        /* not found, create it */
-       origin = malloc(strlen(sender) + sizeof *origin);
+       origin = malloc(strlen(sender) + 1 + sizeof *origin);
        if (origin == NULL)
                errno = ENOMEM;
        else {
@@ -916,7 +917,7 @@ static void afb_api_dbus_server_event_push(void *closure, const char *event, int
        json_object_put(object);
 }
 
-static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, int eventid, struct json_object *object)
+static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, struct json_object *object, const char *uuid)
 {
        int rc;
        struct api_dbus *api;