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-event.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_eventid *eventid;
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_unhooked_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_unhooked_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->request.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 eventid */
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_eventid_fullname(ev->eventid), name)))
391 /* adds an eventid */
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->eventid = afb_evt_eventid_create(name);
407 if (ev->eventid == 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 eventid */
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_evt_eventid_unref(ev->eventid);
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_evt_eventid_push(ev->eventid, 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->eventid);
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->eventid);
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 afb_api.group = NULL;
614 if (afb_apiset_add(apiset, api->api, afb_api) < 0)
620 destroy_api_dbus(api);
625 /******************* event structures for server part **********************************/
627 static void afb_api_dbus_server_event_add(void *closure, const char *event, int eventid);
628 static void afb_api_dbus_server_event_remove(void *closure, const char *event, int eventid);
629 static void afb_api_dbus_server_event_push(void *closure, const char *event, int eventid, struct json_object *object);
630 static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, int eventid, struct json_object *object);
632 /* the interface for events broadcasting */
633 static const struct afb_evt_itf evt_broadcast_itf = {
634 .broadcast = afb_api_dbus_server_event_broadcast,
637 /* the interface for events pushing */
638 static const struct afb_evt_itf evt_push_itf = {
639 .push = afb_api_dbus_server_event_push,
640 .add = afb_api_dbus_server_event_add,
641 .remove = afb_api_dbus_server_event_remove
644 /******************* origin description part for server *****************************/
648 /* link to next different origin */
651 /* the server dbus-api */
652 struct api_dbus *api;
654 /* count of references */
657 /* credentials of the origin */
658 struct afb_cred *cred;
664 /* get the credentials for the message */
665 static void init_origin_creds(struct origin *origin)
674 rc = sd_bus_get_name_creds(origin->api->sdbus, origin->name,
675 SD_BUS_CREDS_PID|SD_BUS_CREDS_UID|SD_BUS_CREDS_GID|SD_BUS_CREDS_SELINUX_CONTEXT,
680 afb_cred_unref(origin->cred);
681 sd_bus_creds_get_uid(c, &uid);
682 sd_bus_creds_get_gid(c, &gid);
683 sd_bus_creds_get_pid(c, &pid);
684 sd_bus_creds_get_selinux_context(c, &context);
685 origin->cred = afb_cred_create(uid, gid, pid, context);
686 sd_bus_creds_unref(c);
690 static struct origin *afb_api_dbus_server_origin_get(struct api_dbus *api, const char *sender)
692 struct origin *origin;
694 /* searchs for an existing origin */
695 origin = api->server.origins;
696 while (origin != NULL) {
697 if (0 == strcmp(origin->name, sender)) {
701 origin = origin->next;
704 /* not found, create it */
705 origin = malloc(strlen(sender) + sizeof *origin);
710 origin->refcount = 1;
711 strcpy(origin->name, sender);
712 init_origin_creds(origin);
713 origin->next = api->server.origins;
714 api->server.origins = origin;
719 static void afb_api_dbus_server_origin_unref(struct origin *origin)
721 if (!--origin->refcount) {
724 prv = &origin->api->server.origins;
725 while(*prv != origin)
728 afb_cred_unref(origin->cred);
735 /* link to next different origin */
736 struct origin *origin;
738 /* the listener of events */
739 struct afb_evt_listener *listener;
742 static void afb_api_dbus_server_listener_free(struct listener *listener)
744 afb_evt_listener_unref(listener->listener);
745 afb_api_dbus_server_origin_unref(listener->origin);
749 static struct listener *afb_api_dbus_server_listener_get(struct api_dbus *api, const char *sender, struct afb_session *session)
752 struct listener *listener;
753 struct origin *origin;
756 origin = afb_api_dbus_server_origin_get(api, sender);
760 /* retrieves the stored listener */
761 listener = afb_session_get_cookie(session, origin);
762 if (listener != NULL) {
764 afb_api_dbus_server_origin_unref(origin);
768 /* creates the listener */
769 listener = malloc(sizeof *listener);
770 if (listener == NULL)
773 listener->origin = origin;
774 listener->listener = afb_evt_listener_create(&evt_push_itf, origin);
775 if (listener->listener != NULL) {
776 rc = afb_session_set_cookie(session, origin, listener, (void*)afb_api_dbus_server_listener_free);
779 afb_evt_listener_unref(listener->listener);
783 afb_api_dbus_server_origin_unref(origin);
787 /******************* dbus request part for server *****************/
790 * Structure for a dbus request
793 struct afb_xreq xreq; /**< the xreq of the request */
794 sd_bus_message *message; /**< the incoming request message */
795 const char *request; /**< the readen request as string */
796 struct json_object *json; /**< the readen request as object */
797 struct listener *listener; /**< the listener for events */
800 /* decrement the reference count of the request and free/release it on falling to null */
801 static void dbus_req_destroy(struct afb_xreq *xreq)
803 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
805 afb_context_disconnect(&dreq->xreq.context);
806 json_object_put(dreq->json);
807 sd_bus_message_unref(dreq->message);
811 /* get the object of the request */
812 static struct json_object *dbus_req_json(struct afb_xreq *xreq)
814 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
819 /* get the argument of the request of 'name' */
820 static void dbus_req_reply(struct dbus_req *dreq, uint8_t type, const char *first, const char *second)
823 rc = sd_bus_reply_method_return(dreq->message,
824 "yssu", type, first ? : "", second ? : "", (uint32_t)dreq->xreq.context.flags);
826 ERROR("sending the reply failed");
829 static void dbus_req_success(struct afb_xreq *xreq, struct json_object *obj, const char *info)
831 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
833 dbus_req_reply(dreq, RETOK, json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN), info);
836 static void dbus_req_fail(struct afb_xreq *xreq, const char *status, const char *info)
838 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
840 dbus_req_reply(dreq, RETERR, status, info);
843 static void afb_api_dbus_server_event_send(struct origin *origin, char order, const char *event, int eventid, const char *data, uint64_t msgid);
845 static int dbus_req_subscribe(struct afb_xreq *xreq, struct afb_eventid *eventid)
847 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
851 rc = afb_evt_eventid_add_watch(dreq->listener->listener, eventid);
852 sd_bus_message_get_cookie(dreq->message, &msgid);
853 afb_api_dbus_server_event_send(dreq->listener->origin, 'S', afb_evt_eventid_fullname(eventid), afb_evt_eventid_id(eventid), "", msgid);
857 static int dbus_req_unsubscribe(struct afb_xreq *xreq, struct afb_eventid *eventid)
859 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
863 sd_bus_message_get_cookie(dreq->message, &msgid);
864 afb_api_dbus_server_event_send(dreq->listener->origin, 'U', afb_evt_eventid_fullname(eventid), afb_evt_eventid_id(eventid), "", msgid);
865 rc = afb_evt_eventid_remove_watch(dreq->listener->listener, eventid);
869 const struct afb_xreq_query_itf afb_api_dbus_xreq_itf = {
870 .json = dbus_req_json,
871 .success = dbus_req_success,
872 .fail = dbus_req_fail,
873 .unref = dbus_req_destroy,
874 .subscribe = dbus_req_subscribe,
875 .unsubscribe = dbus_req_unsubscribe
878 /******************* server part **********************************/
880 static void afb_api_dbus_server_event_send(struct origin *origin, char order, const char *event, int eventid, const char *data, uint64_t msgid)
883 struct api_dbus *api;
884 struct sd_bus_message *msg;
889 rc = sd_bus_message_new_method_call(api->sdbus, &msg, origin->name, api->path, api->name, "event");
893 rc = sd_bus_message_append(msg, "yisst", (uint8_t)order, (int32_t)eventid, event, data, msgid);
897 rc = sd_bus_send(api->sdbus, msg, NULL); /* NULL for cookie implies no expected reply */
902 ERROR("error while send event %c%s(%d) to %s", order, event, eventid, origin->name);
904 sd_bus_message_unref(msg);
907 static void afb_api_dbus_server_event_add(void *closure, const char *event, int eventid)
909 afb_api_dbus_server_event_send(closure, '+', event, eventid, "", 0);
912 static void afb_api_dbus_server_event_remove(void *closure, const char *event, int eventid)
914 afb_api_dbus_server_event_send(closure, '-', event, eventid, "", 0);
917 static void afb_api_dbus_server_event_push(void *closure, const char *event, int eventid, struct json_object *object)
919 const char *data = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN);
920 afb_api_dbus_server_event_send(closure, '!', event, eventid, data, 0);
921 json_object_put(object);
924 static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, int eventid, struct json_object *object)
927 struct api_dbus *api;
930 rc = sd_bus_emit_signal(api->sdbus, api->path, api->name, "broadcast",
931 "ss", event, json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN));
933 ERROR("error while broadcasting event %s", event);
934 json_object_put(object);
937 /* called when the object for the service is called */
938 static int api_dbus_server_on_object_called(sd_bus_message *message, void *userdata, sd_bus_error *ret_error)
943 struct dbus_req *dreq;
944 struct api_dbus *api = userdata;
946 struct afb_session *session;
947 struct listener *listener;
949 /* check the interface */
950 if (strcmp(sd_bus_message_get_interface(message), api->name) != 0)
954 method = sd_bus_message_get_member(message);
956 /* create the request */
957 dreq = calloc(1 , sizeof *dreq);
962 rc = sd_bus_message_read(message, "ssu", &dreq->request, &uuid, &flags);
964 sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_SIGNATURE, "invalid signature");
968 /* connect to the context */
969 afb_xreq_init(&dreq->xreq, &afb_api_dbus_xreq_itf);
970 if (afb_context_connect(&dreq->xreq.context, uuid, NULL) < 0)
972 session = dreq->xreq.context.session;
974 /* get the listener */
975 listener = afb_api_dbus_server_listener_get(api, sd_bus_message_get_sender(message), session);
976 if (listener == NULL)
979 /* fulfill the request and emit it */
980 dreq->xreq.context.flags = flags;
981 dreq->message = sd_bus_message_ref(message);
982 dreq->json = json_tokener_parse(dreq->request);
983 if (dreq->json == NULL && strcmp(dreq->request, "null")) {
984 /* lazy error detection of json request. Is it to improve? */
985 dreq->json = json_object_new_string(dreq->request);
987 dreq->listener = listener;
988 dreq->xreq.request.api = api->api;
989 dreq->xreq.request.verb = method;
990 afb_xreq_process(&dreq->xreq, api->server.apiset);
994 sd_bus_reply_method_errorf(message, SD_BUS_ERROR_NO_MEMORY, "out of memory");
1000 /* create the service */
1001 int afb_api_dbus_add_server(const char *path, struct afb_apiset *apiset)
1004 struct api_dbus *api;
1006 /* get the dbus api object connected */
1007 api = make_api_dbus(path);
1011 /* request the service object name */
1012 rc = sd_bus_request_name(api->sdbus, api->name, 0);
1015 ERROR("can't register name %s", api->name);
1019 /* connect the service to the dbus object */
1020 rc = sd_bus_add_object(api->sdbus, &api->server.slot_call, api->path, api_dbus_server_on_object_called, api);
1023 ERROR("can't add dbus object %s for %s", api->path, api->name);
1026 INFO("afb service over dbus installed, name %s, path %s", api->name, api->path);
1028 api->server.listener = afb_evt_listener_create(&evt_broadcast_itf, api);
1029 api->server.apiset = afb_apiset_addref(apiset);
1032 sd_bus_release_name(api->sdbus, api->name);
1034 destroy_api_dbus(api);