2 * Copyright (C) 2015, 2016, 2017 "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.
19 #define NO_PLUGIN_VERBOSE_MACRO
27 #include <systemd/sd-bus.h>
28 #include <json-c/json.h>
30 #include <afb/afb-req-itf.h>
32 #include "afb-common.h"
34 #include "afb-session.h"
35 #include "afb-msg-json.h"
37 #include "afb-apiset.h"
38 #include "afb-api-dbus.h"
39 #include "afb-context.h"
45 static const char DEFAULT_PATH_PREFIX[] = "/org/agl/afb/api/";
52 * The path given are of the form
53 * system:/org/agl/afb/api/...
55 * user:/org/agl/afb/api/...
59 struct sd_bus *sdbus; /* the bus */
60 char *path; /* path of the object for the API */
61 char *name; /* name/interface of the object */
62 char *api; /* api name of the interface */
65 struct sd_bus_slot *slot_broadcast;
66 struct sd_bus_slot *slot_event;
67 struct dbus_event *events;
68 struct dbus_memo *memos;
71 struct sd_bus_slot *slot_call;
72 struct afb_evt_listener *listener; /* listener for broadcasted events */
73 struct origin *origins;
74 struct afb_apiset *apiset;
82 /******************* common part **********************************/
85 * create a structure api_dbus connected on either the system
86 * bus if 'system' is not null or on the user bus. The connection
87 * is established for either emiting/receiving on 'path' being of length
90 static struct api_dbus *make_api_dbus_3(int system, const char *path, size_t pathlen)
96 /* allocates the structure */
97 api = calloc(1, sizeof *api + 1 + pathlen + pathlen);
103 /* init the structure's strings */
105 /* path is copied after the struct */
106 api->path = (void*)(api+1);
107 strcpy(api->path, path);
109 /* api name is at the end of the path */
110 api->api = strrchr(api->path, '/');
111 if (api->api == NULL) {
116 if (!afb_api_is_valid_name(api->api)) {
121 /* the name/interface is copied after the path */
122 api->name = &api->path[pathlen + 1];
123 strcpy(api->name, &path[1]);
124 ptr = strchr(api->name, '/');
127 ptr = strchr(ptr, '/');
131 sdbus = (system ? afb_common_get_system_bus : afb_common_get_user_bus)();
145 * create a structure api_dbus connected on either the system
146 * bus if 'system' is not null or on the user bus. The connection
147 * is established for either emiting/receiving on 'path'.
148 * If 'path' is not absolute, it is prefixed with DEFAULT_PATH_PREFIX.
150 static struct api_dbus *make_api_dbus_2(int system, const char *path)
155 /* check the length of the path */
162 /* if the path is absolute, creation now */
164 return make_api_dbus_3(system, path, len);
166 /* compute the path prefixed with DEFAULT_PATH_PREFIX */
167 assert(strlen(DEFAULT_PATH_PREFIX) > 0);
168 assert(DEFAULT_PATH_PREFIX[strlen(DEFAULT_PATH_PREFIX) - 1] == '/');
169 len += strlen(DEFAULT_PATH_PREFIX);
170 ptr = alloca(len + 1);
171 strcpy(stpcpy(ptr, DEFAULT_PATH_PREFIX), path);
173 /* creation for prefixed path */
174 return make_api_dbus_3(system, ptr, len);
178 * create a structure api_dbus connected either emiting/receiving
180 * The path can be prefixed with "system:" or "user:" to select
181 * either the user or the system D-Bus. If none is set then user's
183 * If remaining 'path' is not absolute, it is prefixed with
184 * DEFAULT_PATH_PREFIX.
186 static struct api_dbus *make_api_dbus(const char *path)
191 /* retrieves the prefix "scheme-like" part */
192 ptr = strchr(path, ':');
194 return make_api_dbus_2(0, path);
196 /* check the prefix part */
197 preflen = (size_t)(ptr - path);
198 if (strncmp(path, "system", preflen) == 0)
199 return make_api_dbus_2(1, ptr + 1);
201 if (strncmp(path, "user", preflen) == 0)
202 return make_api_dbus_2(0, ptr + 1);
204 /* TODO: connect to a foreign D-Bus? */
209 static void destroy_api_dbus(struct api_dbus *api)
214 /******************* client part **********************************/
217 * structure for recording query data
220 struct dbus_memo *next; /* the next memo */
221 struct api_dbus *api; /* the dbus api */
222 struct afb_xreq *xreq; /* the request */
223 uint64_t msgid; /* the message identifier */
228 struct dbus_event *next;
229 struct afb_event event;
234 /* allocates and init the memorizing data */
235 static struct dbus_memo *api_dbus_client_memo_make(struct api_dbus *api, struct afb_xreq *xreq)
237 struct dbus_memo *memo;
239 memo = malloc(sizeof *memo);
241 afb_xreq_addref(xreq);
245 memo->next = api->client.memos;
246 api->client.memos = memo;
251 /* free and release the memorizing data */
252 static void api_dbus_client_memo_destroy(struct dbus_memo *memo)
254 struct dbus_memo **prv;
256 prv = &memo->api->client.memos;
257 while (*prv != NULL) {
265 afb_xreq_unref(memo->xreq);
269 /* search a memorized request */
270 static struct dbus_memo *api_dbus_client_memo_search(struct api_dbus *api, uint64_t msgid)
272 struct dbus_memo *memo;
274 memo = api->client.memos;
275 while (memo != NULL && memo->msgid != msgid)
281 /* callback when received answer */
282 static int api_dbus_client_on_reply(sd_bus_message *message, void *userdata, sd_bus_error *ret_error)
285 struct dbus_memo *memo;
286 const char *first, *second;
290 /* retrieve the recorded data */
294 rc = sd_bus_message_read(message, "yssu", &type, &first, &second, &flags);
296 /* failing to have the answer */
297 afb_xreq_fail(memo->xreq, "error", "dbus error");
299 /* report the answer */
300 memo->xreq->context.flags = (unsigned)flags;
303 afb_xreq_success(memo->xreq, json_tokener_parse(first), *second ? second : NULL);
306 afb_xreq_fail(memo->xreq, first, *second ? second : NULL);
309 afb_xreq_fail(memo->xreq, "error", "dbus link broken");
313 api_dbus_client_memo_destroy(memo);
317 /* on call, propagate it to the dbus service */
318 static void api_dbus_client_call(void *closure, struct afb_xreq *xreq)
320 struct api_dbus *api = closure;
323 struct dbus_memo *memo;
324 struct sd_bus_message *msg;
326 /* create the recording data */
327 memo = api_dbus_client_memo_make(api, xreq);
329 afb_xreq_fail(xreq, "error", "out of memory");
333 /* creates the message */
335 rc = sd_bus_message_new_method_call(api->sdbus, &msg, api->name, api->path, api->name, xreq->verb);
339 rc = sd_bus_message_append(msg, "ssu",
340 afb_xreq_raw(xreq, &size),
341 afb_session_uuid(xreq->context.session),
342 (uint32_t)xreq->context.flags);
347 rc = sd_bus_call_async(api->sdbus, NULL, msg, api_dbus_client_on_reply, memo, (uint64_t)-1);
351 rc = sd_bus_message_get_cookie(msg, &memo->msgid);
356 /* if there was an error report it directly */
358 afb_xreq_fail(xreq, "error", "dbus error");
359 api_dbus_client_memo_destroy(memo);
361 sd_bus_message_unref(msg);
364 /* receives broadcasted events */
365 static int api_dbus_client_on_broadcast_event(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
367 struct json_object *object;
368 const char *event, *data;
369 int rc = sd_bus_message_read(m, "ss", &event, &data);
371 ERROR("unreadable broadcasted event");
373 object = json_tokener_parse(data);
374 afb_evt_broadcast(event, object);
379 /* search the event */
380 static struct dbus_event *api_dbus_client_event_search(struct api_dbus *api, int id, const char *name)
382 struct dbus_event *ev;
384 ev = api->client.events;
385 while (ev != NULL && (ev->id != id || 0 != strcmp(afb_evt_event_name(ev->event), name)))
392 static void api_dbus_client_event_create(struct api_dbus *api, int id, const char *name)
394 struct dbus_event *ev;
396 /* check conflicts */
397 ev = api_dbus_client_event_search(api, id, name);
403 /* no conflict, try to add it */
404 ev = malloc(sizeof *ev);
406 ev->event = afb_evt_create_event(name);
407 if (ev->event.closure == NULL)
412 ev->next = api->client.events;
413 api->client.events = ev;
417 ERROR("can't create event %s, out of memory", name);
420 /* removes an event */
421 static void api_dbus_client_event_drop(struct api_dbus *api, int id, const char *name)
423 struct dbus_event *ev, **prv;
425 /* retrieves the event */
426 ev = api_dbus_client_event_search(api, id, name);
428 ERROR("event %s not found", name);
432 /* decrease the reference count */
436 /* unlinks the event */
437 prv = &api->client.events;
442 /* destroys the event */
443 afb_event_drop(ev->event);
448 static void api_dbus_client_event_push(struct api_dbus *api, int id, const char *name, const char *data)
450 struct json_object *object;
451 struct dbus_event *ev;
453 /* retrieves the event */
454 ev = api_dbus_client_event_search(api, id, name);
456 ERROR("event %s not found", name);
460 /* destroys the event */
461 object = json_tokener_parse(data);
462 afb_event_push(ev->event, object);
465 /* subscribes an event */
466 static void api_dbus_client_event_subscribe(struct api_dbus *api, int id, const char *name, uint64_t msgid)
469 struct dbus_event *ev;
470 struct dbus_memo *memo;
472 /* retrieves the event */
473 ev = api_dbus_client_event_search(api, id, name);
475 ERROR("event %s not found", name);
479 /* retrieves the memo */
480 memo = api_dbus_client_memo_search(api, msgid);
482 ERROR("message not found");
486 /* subscribe the request to the event */
487 rc = afb_xreq_subscribe(memo->xreq, ev->event);
489 ERROR("can't subscribe: %m");
492 /* unsubscribes an event */
493 static void api_dbus_client_event_unsubscribe(struct api_dbus *api, int id, const char *name, uint64_t msgid)
496 struct dbus_event *ev;
497 struct dbus_memo *memo;
499 /* retrieves the event */
500 ev = api_dbus_client_event_search(api, id, name);
502 ERROR("event %s not found", name);
506 /* retrieves the memo */
507 memo = api_dbus_client_memo_search(api, msgid);
509 ERROR("message not found");
513 /* unsubscribe the request from the event */
514 rc = afb_xreq_unsubscribe(memo->xreq, ev->event);
516 ERROR("can't unsubscribe: %m");
519 /* receives calls for event */
520 static int api_dbus_client_on_manage_event(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
522 const char *eventname, *data;
526 struct api_dbus *api;
529 /* check if expected message */
531 if (0 != strcmp(api->name, sd_bus_message_get_interface(m)))
532 return 0; /* not the expected interface */
533 if (0 != strcmp("event", sd_bus_message_get_member(m)))
534 return 0; /* not the expected member */
535 if (sd_bus_message_get_expect_reply(m))
536 return 0; /* not the expected type of message */
538 /* reads the message */
539 rc = sd_bus_message_read(m, "yisst", &order, &eventid, &eventname, &data, &msgid);
541 ERROR("unreadable event");
545 /* what is the order ? */
546 switch ((char)order) {
547 case '+': /* creates the event */
548 api_dbus_client_event_create(api, eventid, eventname);
550 case '-': /* drops the event */
551 api_dbus_client_event_drop(api, eventid, eventname);
553 case '!': /* pushs the event */
554 api_dbus_client_event_push(api, eventid, eventname, data);
556 case 'S': /* subscribe event for a request */
557 api_dbus_client_event_subscribe(api, eventid, eventname, msgid);
559 case 'U': /* unsubscribe event for a request */
560 api_dbus_client_event_unsubscribe(api, eventid, eventname, msgid);
563 /* unexpected order */
564 ERROR("unexpected order '%c' received", (char)order);
570 static struct afb_api_itf dbus_api_itf = {
571 .call = api_dbus_client_call
574 /* adds a afb-dbus-service client api */
575 int afb_api_dbus_add_client(const char *path, struct afb_apiset *apiset)
578 struct api_dbus *api;
579 struct afb_api afb_api;
582 /* create the dbus client api */
583 api = make_api_dbus(path);
587 /* connect to broadcasted events */
588 rc = asprintf(&match, "type='signal',path='%s',interface='%s',member='broadcast'", api->path, api->name);
591 ERROR("out of memory");
594 rc = sd_bus_add_match(api->sdbus, &api->client.slot_broadcast, match, api_dbus_client_on_broadcast_event, api);
598 ERROR("can't add dbus match %s for %s", api->path, api->name);
602 /* connect to event management */
603 rc = sd_bus_add_object(api->sdbus, &api->client.slot_event, api->path, api_dbus_client_on_manage_event, api);
606 ERROR("can't add dbus object %s for %s", api->path, api->name);
610 /* record it as an API */
611 afb_api.closure = api;
612 afb_api.itf = &dbus_api_itf;
613 if (afb_apiset_add(apiset, api->api, afb_api) < 0)
619 destroy_api_dbus(api);
624 /******************* event structures for server part **********************************/
626 static void afb_api_dbus_server_event_add(void *closure, const char *event, int eventid);
627 static void afb_api_dbus_server_event_remove(void *closure, const char *event, int eventid);
628 static void afb_api_dbus_server_event_push(void *closure, const char *event, int eventid, struct json_object *object);
629 static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, int eventid, struct json_object *object);
631 /* the interface for events broadcasting */
632 static const struct afb_evt_itf evt_broadcast_itf = {
633 .broadcast = afb_api_dbus_server_event_broadcast,
636 /* the interface for events pushing */
637 static const struct afb_evt_itf evt_push_itf = {
638 .push = afb_api_dbus_server_event_push,
639 .add = afb_api_dbus_server_event_add,
640 .remove = afb_api_dbus_server_event_remove
643 /******************* origin description part for server *****************************/
647 /* link to next different origin */
650 /* the server dbus-api */
651 struct api_dbus *api;
653 /* count of references */
656 /* credentials of the origin */
657 struct afb_cred *cred;
663 /* get the credentials for the message */
664 static void init_origin_creds(struct origin *origin)
673 rc = sd_bus_get_name_creds(origin->api->sdbus, origin->name,
674 SD_BUS_CREDS_PID|SD_BUS_CREDS_UID|SD_BUS_CREDS_GID|SD_BUS_CREDS_SELINUX_CONTEXT,
679 afb_cred_unref(origin->cred);
680 sd_bus_creds_get_uid(c, &uid);
681 sd_bus_creds_get_gid(c, &gid);
682 sd_bus_creds_get_pid(c, &pid);
683 sd_bus_creds_get_selinux_context(c, &context);
684 origin->cred = afb_cred_create(uid, gid, pid, context);
685 sd_bus_creds_unref(c);
689 static struct origin *afb_api_dbus_server_origin_get(struct api_dbus *api, const char *sender)
691 struct origin *origin;
693 /* searchs for an existing origin */
694 origin = api->server.origins;
695 while (origin != NULL) {
696 if (0 == strcmp(origin->name, sender)) {
700 origin = origin->next;
703 /* not found, create it */
704 origin = malloc(strlen(sender) + sizeof *origin);
709 origin->refcount = 1;
710 strcpy(origin->name, sender);
711 init_origin_creds(origin);
712 origin->next = api->server.origins;
713 api->server.origins = origin;
718 static void afb_api_dbus_server_origin_unref(struct origin *origin)
720 if (!--origin->refcount) {
723 prv = &origin->api->server.origins;
724 while(*prv != origin)
727 afb_cred_unref(origin->cred);
734 /* link to next different origin */
735 struct origin *origin;
737 /* the listener of events */
738 struct afb_evt_listener *listener;
741 static void afb_api_dbus_server_listener_free(struct listener *listener)
743 afb_evt_listener_unref(listener->listener);
744 afb_api_dbus_server_origin_unref(listener->origin);
748 static struct listener *afb_api_dbus_server_listener_get(struct api_dbus *api, const char *sender, struct afb_session *session)
751 struct listener *listener;
752 struct origin *origin;
755 origin = afb_api_dbus_server_origin_get(api, sender);
759 /* retrieves the stored listener */
760 listener = afb_session_get_cookie(session, origin);
761 if (listener != NULL) {
763 afb_api_dbus_server_origin_unref(origin);
767 /* creates the listener */
768 listener = malloc(sizeof *listener);
769 if (listener == NULL)
772 listener->origin = origin;
773 listener->listener = afb_evt_listener_create(&evt_push_itf, origin);
774 if (listener->listener != NULL) {
775 rc = afb_session_set_cookie(session, origin, listener, (void*)afb_api_dbus_server_listener_free);
778 afb_evt_listener_unref(listener->listener);
782 afb_api_dbus_server_origin_unref(origin);
786 /******************* dbus request part for server *****************/
789 * Structure for a dbus request
792 struct afb_xreq xreq; /**< the xreq of the request */
793 sd_bus_message *message; /**< the incoming request message */
794 const char *request; /**< the readen request as string */
795 struct json_object *json; /**< the readen request as object */
796 struct listener *listener; /**< the listener for events */
799 /* decrement the reference count of the request and free/release it on falling to null */
800 static void dbus_req_destroy(struct afb_xreq *xreq)
802 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
804 afb_context_disconnect(&dreq->xreq.context);
805 json_object_put(dreq->json);
806 sd_bus_message_unref(dreq->message);
810 /* get the object of the request */
811 static struct json_object *dbus_req_json(struct afb_xreq *xreq)
813 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
818 /* get the argument of the request of 'name' */
819 static void dbus_req_reply(struct dbus_req *dreq, uint8_t type, const char *first, const char *second)
822 rc = sd_bus_reply_method_return(dreq->message,
823 "yssu", type, first ? : "", second ? : "", (uint32_t)dreq->xreq.context.flags);
825 ERROR("sending the reply failed");
828 static void dbus_req_success(struct afb_xreq *xreq, struct json_object *obj, const char *info)
830 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
832 dbus_req_reply(dreq, RETOK, json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN), info);
835 static void dbus_req_fail(struct afb_xreq *xreq, const char *status, const char *info)
837 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
839 dbus_req_reply(dreq, RETERR, status, info);
842 static void afb_api_dbus_server_event_send(struct origin *origin, char order, const char *event, int eventid, const char *data, uint64_t msgid);
844 static int dbus_req_subscribe(struct afb_xreq *xreq, struct afb_event event)
846 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
850 rc = afb_evt_add_watch(dreq->listener->listener, event);
851 sd_bus_message_get_cookie(dreq->message, &msgid);
852 afb_api_dbus_server_event_send(dreq->listener->origin, 'S', afb_evt_event_name(event), afb_evt_event_id(event), "", msgid);
856 static int dbus_req_unsubscribe(struct afb_xreq *xreq, struct afb_event event)
858 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
862 sd_bus_message_get_cookie(dreq->message, &msgid);
863 afb_api_dbus_server_event_send(dreq->listener->origin, 'U', afb_evt_event_name(event), afb_evt_event_id(event), "", msgid);
864 rc = afb_evt_remove_watch(dreq->listener->listener, event);
868 const struct afb_xreq_query_itf afb_api_dbus_xreq_itf = {
869 .json = dbus_req_json,
870 .success = dbus_req_success,
871 .fail = dbus_req_fail,
872 .unref = dbus_req_destroy,
873 .subscribe = dbus_req_subscribe,
874 .unsubscribe = dbus_req_unsubscribe
877 /******************* server part **********************************/
879 static void afb_api_dbus_server_event_send(struct origin *origin, char order, const char *event, int eventid, const char *data, uint64_t msgid)
882 struct api_dbus *api;
883 struct sd_bus_message *msg;
888 rc = sd_bus_message_new_method_call(api->sdbus, &msg, origin->name, api->path, api->name, "event");
892 rc = sd_bus_message_append(msg, "yisst", (uint8_t)order, (int32_t)eventid, event, data, msgid);
896 rc = sd_bus_send(api->sdbus, msg, NULL); /* NULL for cookie implies no expected reply */
901 ERROR("error while send event %c%s(%d) to %s", order, event, eventid, origin->name);
903 sd_bus_message_unref(msg);
906 static void afb_api_dbus_server_event_add(void *closure, const char *event, int eventid)
908 afb_api_dbus_server_event_send(closure, '+', event, eventid, "", 0);
911 static void afb_api_dbus_server_event_remove(void *closure, const char *event, int eventid)
913 afb_api_dbus_server_event_send(closure, '-', event, eventid, "", 0);
916 static void afb_api_dbus_server_event_push(void *closure, const char *event, int eventid, struct json_object *object)
918 const char *data = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN);
919 afb_api_dbus_server_event_send(closure, '!', event, eventid, data, 0);
920 json_object_put(object);
923 static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, int eventid, struct json_object *object)
926 struct api_dbus *api;
929 rc = sd_bus_emit_signal(api->sdbus, api->path, api->name, "broadcast",
930 "ss", event, json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN));
932 ERROR("error while broadcasting event %s", event);
933 json_object_put(object);
936 /* called when the object for the service is called */
937 static int api_dbus_server_on_object_called(sd_bus_message *message, void *userdata, sd_bus_error *ret_error)
942 struct dbus_req *dreq;
943 struct api_dbus *api = userdata;
945 struct afb_session *session;
946 struct listener *listener;
948 /* check the interface */
949 if (strcmp(sd_bus_message_get_interface(message), api->name) != 0)
953 method = sd_bus_message_get_member(message);
955 /* create the request */
956 dreq = calloc(1 , sizeof *dreq);
961 rc = sd_bus_message_read(message, "ssu", &dreq->request, &uuid, &flags);
963 sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_SIGNATURE, "invalid signature");
967 /* connect to the context */
968 afb_xreq_init(&dreq->xreq, &afb_api_dbus_xreq_itf);
969 if (afb_context_connect(&dreq->xreq.context, uuid, NULL) < 0)
971 session = dreq->xreq.context.session;
973 /* get the listener */
974 listener = afb_api_dbus_server_listener_get(api, sd_bus_message_get_sender(message), session);
975 if (listener == NULL)
978 /* fulfill the request and emit it */
979 dreq->xreq.context.flags = flags;
980 dreq->message = sd_bus_message_ref(message);
981 dreq->json = json_tokener_parse(dreq->request);
982 if (dreq->json == NULL && strcmp(dreq->request, "null")) {
983 /* lazy error detection of json request. Is it to improve? */
984 dreq->json = json_object_new_string(dreq->request);
986 dreq->listener = listener;
987 dreq->xreq.api = api->api;
988 dreq->xreq.verb = method;
989 afb_xreq_process(&dreq->xreq, api->server.apiset);
993 sd_bus_reply_method_errorf(message, SD_BUS_ERROR_NO_MEMORY, "out of memory");
999 /* create the service */
1000 int afb_api_dbus_add_server(const char *path, struct afb_apiset *apiset)
1003 struct api_dbus *api;
1005 /* get the dbus api object connected */
1006 api = make_api_dbus(path);
1010 /* request the service object name */
1011 rc = sd_bus_request_name(api->sdbus, api->name, 0);
1014 ERROR("can't register name %s", api->name);
1018 /* connect the service to the dbus object */
1019 rc = sd_bus_add_object(api->sdbus, &api->server.slot_call, api->path, api_dbus_server_on_object_called, api);
1022 ERROR("can't add dbus object %s for %s", api->path, api->name);
1025 INFO("afb service over dbus installed, name %s, path %s", api->name, api->path);
1027 api->server.listener = afb_evt_listener_create(&evt_broadcast_itf, api);
1028 api->server.apiset = afb_apiset_addref(apiset);
1031 sd_bus_release_name(api->sdbus, api->name);
1033 destroy_api_dbus(api);