1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
7 This file is part of systemd.
9 Copyright 2013 Lennart Poettering
11 systemd is free software; you can redistribute it and/or modify it
12 under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 2.1 of the License, or
14 (at your option) any later version.
16 systemd is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 #include <sys/types.h>
29 #include "sd-bus-protocol.h"
36 * - add page donation logic
37 * - api for appending/reading fixed arrays
38 * - merge busctl into systemctl or so?
39 * - default policy (allow uid == 0 and our own uid)
41 * - enforce alignment of pointers passed in
42 * - negotiation for attach attributes
45 typedef struct sd_bus sd_bus;
46 typedef struct sd_bus_message sd_bus_message;
54 typedef int (*sd_bus_message_handler_t)(sd_bus *bus, int ret, sd_bus_message *m, void *userdata);
58 int sd_bus_open_system(sd_bus **ret);
59 int sd_bus_open_user(sd_bus **ret);
61 int sd_bus_new(sd_bus **ret);
62 int sd_bus_set_address(sd_bus *bus, const char *address);
63 int sd_bus_set_fd(sd_bus *bus, int input_fd, int output_fd);
64 int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]);
65 int sd_bus_set_bus_client(sd_bus *bus, int b);
66 int sd_bus_set_server(sd_bus *bus, int b, sd_id128_t server_id);
67 int sd_bus_set_anonymous(sd_bus *bus, int b);
68 int sd_bus_set_negotiate_fds(sd_bus *bus, int b);
69 int sd_bus_start(sd_bus *ret);
71 void sd_bus_close(sd_bus *bus);
73 sd_bus *sd_bus_ref(sd_bus *bus);
74 sd_bus *sd_bus_unref(sd_bus *bus);
76 int sd_bus_is_open(sd_bus *bus);
77 int sd_bus_can_send(sd_bus *bus, char type);
78 int sd_bus_get_server_id(sd_bus *bus, sd_id128_t *peer);
80 int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *serial);
81 int sd_bus_send_with_reply(sd_bus *bus, sd_bus_message *m, sd_bus_message_handler_t callback, void *userdata, uint64_t usec, uint64_t *serial);
82 int sd_bus_send_with_reply_cancel(sd_bus *bus, uint64_t serial);
83 int sd_bus_send_with_reply_and_block(sd_bus *bus, sd_bus_message *m, uint64_t usec, sd_bus_error *error, sd_bus_message **r);
85 int sd_bus_get_fd(sd_bus *bus);
86 int sd_bus_get_events(sd_bus *bus);
87 int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec);
88 int sd_bus_process(sd_bus *bus, sd_bus_message **r);
89 int sd_bus_wait(sd_bus *bus, uint64_t timeout_usec);
90 int sd_bus_flush(sd_bus *bus);
92 int sd_bus_add_filter(sd_bus *bus, sd_bus_message_handler_t callback, void *userdata);
93 int sd_bus_remove_filter(sd_bus *bus, sd_bus_message_handler_t callback, void *userdata);
95 int sd_bus_add_object(sd_bus *bus, const char *path, sd_bus_message_handler_t callback, void *userdata);
96 int sd_bus_remove_object(sd_bus *bus, const char *path, sd_bus_message_handler_t callback, void *userdata);
98 int sd_bus_add_fallback(sd_bus *bus, const char *prefix, sd_bus_message_handler_t callback, void *userdata);
99 int sd_bus_remove_fallback(sd_bus *bus, const char *prefix, sd_bus_message_handler_t callback, void *userdata);
101 int sd_bus_add_match(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata);
102 int sd_bus_remove_match(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata);
106 int sd_bus_message_new_signal(sd_bus *bus, const char *path, const char *interface, const char *member, sd_bus_message **m);
107 int sd_bus_message_new_method_call(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_message **m);
108 int sd_bus_message_new_method_return(sd_bus *bus, sd_bus_message *call, sd_bus_message **m);
109 int sd_bus_message_new_method_error(sd_bus *bus, sd_bus_message *call, const sd_bus_error *e, sd_bus_message **m);
111 sd_bus_message* sd_bus_message_ref(sd_bus_message *m);
112 sd_bus_message* sd_bus_message_unref(sd_bus_message *m);
114 int sd_bus_message_get_type(sd_bus_message *m, uint8_t *type);
115 int sd_bus_message_get_serial(sd_bus_message *m, uint64_t *serial);
116 int sd_bus_message_get_reply_serial(sd_bus_message *m, uint64_t *serial);
117 int sd_bus_message_get_no_reply(sd_bus_message *m);
119 const char *sd_bus_message_get_path(sd_bus_message *m);
120 const char *sd_bus_message_get_interface(sd_bus_message *m);
121 const char *sd_bus_message_get_member(sd_bus_message *m);
122 const char *sd_bus_message_get_destination(sd_bus_message *m);
123 const char *sd_bus_message_get_sender(sd_bus_message *m);
124 const sd_bus_error *sd_bus_message_get_error(sd_bus_message *m);
126 int sd_bus_message_get_monotonic_timestamp(sd_bus_message *m, uint64_t *usec);
127 int sd_bus_message_get_realtime_timestamp(sd_bus_message *m, uint64_t *usec);
128 int sd_bus_message_get_uid(sd_bus_message *m, uid_t *uid);
129 int sd_bus_message_get_gid(sd_bus_message *m, gid_t *gid);
130 int sd_bus_message_get_pid(sd_bus_message *m, pid_t *pid);
131 int sd_bus_message_get_tid(sd_bus_message *m, pid_t *tid);
132 int sd_bus_message_get_pid_starttime(sd_bus_message *m, uint64_t *usec);
133 int sd_bus_message_get_selinux_context(sd_bus_message *m, const char **r);
134 int sd_bus_message_get_comm(sd_bus_message *m, const char **r);
135 int sd_bus_message_get_tid_comm(sd_bus_message *m, const char **r);
136 int sd_bus_message_get_exe(sd_bus_message *m, const char **r);
137 int sd_bus_message_get_cgroup(sd_bus_message *m, const char **r);
138 int sd_bus_message_get_cmdline(sd_bus_message *m, char ***cmdline);
139 int sd_bus_message_get_unit(sd_bus_message *m, const char **unit);
140 int sd_bus_message_get_user_unit(sd_bus_message *m, const char **unit);
141 int sd_bus_message_get_session(sd_bus_message *m, const char **session);
143 int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const char *member);
144 int sd_bus_message_is_method_call(sd_bus_message *m, const char *interface, const char *member);
145 int sd_bus_message_is_method_error(sd_bus_message *m, const char *name);
147 int sd_bus_message_set_no_reply(sd_bus_message *m, int b);
148 int sd_bus_message_set_destination(sd_bus_message *m, const char *destination);
150 int sd_bus_message_append(sd_bus_message *m, const char *types, ...);
151 int sd_bus_message_append_basic(sd_bus_message *m, char type, const void *p);
152 int sd_bus_message_open_container(sd_bus_message *m, char type, const char *contents);
153 int sd_bus_message_close_container(sd_bus_message *m);
155 int sd_bus_message_read(sd_bus_message *m, const char *types, ...);
156 int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p);
157 int sd_bus_message_enter_container(sd_bus_message *m, char type, const char *contents);
158 int sd_bus_message_exit_container(sd_bus_message *m);
159 int sd_bus_message_peek_type(sd_bus_message *m, char *type, const char **contents);
160 int sd_bus_message_rewind(sd_bus_message *m, int complete);
162 /* Convenience calls */
164 int sd_bus_emit_signal(sd_bus *bus, const char *path, const char *interface, const char *member, const char *types, ...);
165 int sd_bus_call_method(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *types, ...);
166 int sd_bus_reply_method_return(sd_bus *bus, sd_bus_message *call, const char *types, ...);
167 int sd_bus_reply_method_error(sd_bus *bus, sd_bus_message *call, const sd_bus_error *e);
171 int sd_bus_get_unique_name(sd_bus *bus, const char **unique);
172 int sd_bus_request_name(sd_bus *bus, const char *name, int flags);
173 int sd_bus_release_name(sd_bus *bus, const char *name);
174 int sd_bus_list_names(sd_bus *bus, char ***l);
175 int sd_bus_get_owner(sd_bus *bus, const char *name, char **owner);
176 int sd_bus_get_owner_uid(sd_bus *bus, const char *name, uid_t *uid);
177 int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid);
179 /* Error structures */
181 #define SD_BUS_ERROR_NULL ((sd_bus_error) {NULL, NULL, 0})
182 #define SD_BUS_ERROR_MAKE(name, message) ((sd_bus_error) {(name), (message), 0})
184 void sd_bus_error_free(sd_bus_error *e);
185 int sd_bus_error_set(sd_bus_error *e, const char *name, const char *format, ...);
186 void sd_bus_error_set_const(sd_bus_error *e, const char *name, const char *message);
187 int sd_bus_error_copy(sd_bus_error *dest, const sd_bus_error *e);
188 int sd_bus_error_is_set(const sd_bus_error *e);
189 int sd_bus_error_has_name(const sd_bus_error *e, const char *name);