Fedora 30 packaging fix issu
[src/app-framework-binder.git] / src / afb-hook.h
1 /*
2  * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
3  * Author José Bollo <jose.bollo@iot.bzh>
4  *
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
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #pragma once
19
20 #include <stdarg.h>
21 #include <time.h>
22
23 struct req;
24 struct afb_context;
25 struct json_object;
26 struct afb_arg;
27 struct afb_event_x2;
28 struct afb_verb_v2;
29 struct afb_verb_v3;
30 struct afb_session;
31 struct afb_xreq;
32 struct afb_export;
33 struct afb_stored_req;
34 struct sd_bus;
35 struct sd_event;
36 struct afb_hook_xreq;
37 struct afb_hook_api;
38 struct afb_hook_evt;
39 struct afb_hook_session;
40 struct afb_hook_global;
41
42 /*********************************************************
43 * section hookid
44 *********************************************************/
45 struct afb_hookid
46 {
47         unsigned id;            /* id of the hook event */
48         struct timespec time;   /* time of the hook event */
49 };
50
51 /*********************************************************
52 * section hooking xreq
53 *********************************************************/
54
55 /* individual flags */
56 #define afb_hook_flag_req_begin                 0x00000001
57 #define afb_hook_flag_req_end                   0x00000002
58 #define afb_hook_flag_req_json                  0x00000004
59 #define afb_hook_flag_req_get                   0x00000008
60 #define afb_hook_flag_req_reply                 0x00000010
61 #define afb_hook_flag_req_get_client_info       0x00000020
62 #define afb_hook_flag_req_legacy_context_get    0x00000040
63 #define afb_hook_flag_req_legacy_context_set    0x00000080
64 #define afb_hook_flag_req_addref                0x00000100
65 #define afb_hook_flag_req_unref                 0x00000200
66 #define afb_hook_flag_req_session_close         0x00000400
67 #define afb_hook_flag_req_session_set_LOA       0x00000800
68 #define afb_hook_flag_req_subscribe             0x00001000
69 #define afb_hook_flag_req_unsubscribe           0x00002000
70 #define afb_hook_flag_req_subcall               0x00004000
71 #define afb_hook_flag_req_subcall_result        0x00008000
72 #define afb_hook_flag_req_subcallsync           0x00010000
73 #define afb_hook_flag_req_subcallsync_result    0x00020000
74 #define afb_hook_flag_req_vverbose              0x00040000
75 #define afb_hook_flag_req_legacy_store          0x00080000
76 #define afb_hook_flag_req_legacy_unstore        0x00100000
77 #define afb_hook_flag_req_has_permission        0x00200000
78 #define afb_hook_flag_req_get_application_id    0x00400000
79 #define afb_hook_flag_req_context_make          0x00800000
80 #define afb_hook_flag_req_get_uid               0x01000000
81
82 /* common flags */
83 #define afb_hook_flags_req_life         (afb_hook_flag_req_begin|afb_hook_flag_req_end)
84 #define afb_hook_flags_req_args         (afb_hook_flag_req_json|afb_hook_flag_req_get)
85 #define afb_hook_flags_req_session      (afb_hook_flag_req_session_close|afb_hook_flag_req_session_set_LOA)
86 #define afb_hook_flags_req_event        (afb_hook_flag_req_subscribe|afb_hook_flag_req_unsubscribe)
87 #define afb_hook_flags_req_subcalls     (afb_hook_flag_req_subcall|afb_hook_flag_req_subcall_result\
88                                         |afb_hook_flag_req_subcallsync|afb_hook_flag_req_subcallsync_result)
89 #define afb_hook_flags_req_security     (afb_hook_flag_req_has_permission|afb_hook_flag_req_get_application_id\
90                                         |afb_hook_flag_req_get_uid|afb_hook_flag_req_get_client_info)
91
92 /* extra flags */
93 #define afb_hook_flags_req_ref          (afb_hook_flag_req_addref|afb_hook_flag_req_unref)
94 #define afb_hook_flags_req_context      (afb_hook_flag_req_legacy_context_get|afb_hook_flag_req_legacy_context_set\
95                                         |afb_hook_flag_req_context_make)
96 #define afb_hook_flags_req_stores       (afb_hook_flag_req_legacy_store|afb_hook_flag_req_legacy_unstore)
97
98 /* predefined groups */
99 #define afb_hook_flags_req_common       (afb_hook_flags_req_life|afb_hook_flags_req_args|afb_hook_flag_req_reply\
100                                         |afb_hook_flags_req_session|afb_hook_flags_req_event|afb_hook_flags_req_subcalls\
101                                         |afb_hook_flag_req_vverbose|afb_hook_flags_req_security)
102 #define afb_hook_flags_req_extra        (afb_hook_flags_req_common|afb_hook_flags_req_ref|afb_hook_flags_req_context\
103                                         |afb_hook_flags_req_stores)
104 #define afb_hook_flags_req_all          (afb_hook_flags_req_extra)
105
106 struct afb_hook_xreq_itf {
107         void (*hook_xreq_begin)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq);
108         void (*hook_xreq_end)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq);
109         void (*hook_xreq_json)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *obj);
110         void (*hook_xreq_get)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *name, struct afb_arg arg);
111         void (*hook_xreq_reply)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *obj, const char *error, const char *info);
112         void (*hook_xreq_legacy_context_get)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, void *value);
113         void (*hook_xreq_legacy_context_set)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, void *value, void (*free_value)(void*));
114         void (*hook_xreq_addref)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq);
115         void (*hook_xreq_unref)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq);
116         void (*hook_xreq_session_close)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq);
117         void (*hook_xreq_session_set_LOA)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, unsigned level, int result);
118         void (*hook_xreq_subscribe)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_event_x2 *event_x2, int result);
119         void (*hook_xreq_unsubscribe)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_event_x2 *event_x2, int result);
120         void (*hook_xreq_subcall)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
121         void (*hook_xreq_subcall_result)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *object, const char *error, const char *info);
122         void (*hook_xreq_subcallsync)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
123         void (*hook_xreq_subcallsync_result)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int status, struct json_object *object, const char *error, const char *info);
124         void (*hook_xreq_vverbose)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args);
125         void (*hook_xreq_legacy_store)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_stored_req *sreq);
126         void (*hook_xreq_legacy_unstore)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq);
127         void (*hook_xreq_has_permission)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *permission, int result);
128         void (*hook_xreq_get_application_id)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, char *result);
129         void (*hook_xreq_context_make)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int replace, void *(*create_value)(void*), void (*free_value)(void*), void *create_closure, void *result);
130         void (*hook_xreq_get_uid)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int result);
131         void (*hook_xreq_get_client_info)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *result);
132 };
133
134 extern void afb_hook_init_xreq(struct afb_xreq *xreq);
135
136 extern struct afb_hook_xreq *afb_hook_create_xreq(const char *api, const char *verb, struct afb_session *session, int flags, struct afb_hook_xreq_itf *itf, void *closure);
137 extern struct afb_hook_xreq *afb_hook_addref_xreq(struct afb_hook_xreq *spec);
138 extern void afb_hook_unref_xreq(struct afb_hook_xreq *spec);
139
140 /* hooks for xreq */
141 extern void afb_hook_xreq_begin(const struct afb_xreq *xreq);
142 extern void afb_hook_xreq_end(const struct afb_xreq *xreq);
143 extern struct json_object *afb_hook_xreq_json(const struct afb_xreq *xreq, struct json_object *obj);
144 extern struct afb_arg afb_hook_xreq_get(const struct afb_xreq *xreq, const char *name, struct afb_arg arg);
145 extern void afb_hook_xreq_reply(const struct afb_xreq *xreq, struct json_object *obj, const char *error, const char *info);
146 extern void *afb_hook_xreq_legacy_context_get(const struct afb_xreq *xreq, void *value);
147 extern void afb_hook_xreq_legacy_context_set(const struct afb_xreq *xreq, void *value, void (*free_value)(void*));
148 extern void afb_hook_xreq_addref(const struct afb_xreq *xreq);
149 extern void afb_hook_xreq_unref(const struct afb_xreq *xreq);
150 extern void afb_hook_xreq_session_close(const struct afb_xreq *xreq);
151 extern int afb_hook_xreq_session_set_LOA(const struct afb_xreq *xreq, unsigned level, int result);
152 extern int afb_hook_xreq_subscribe(const struct afb_xreq *xreq, struct afb_event_x2 *event_x2, int result);
153 extern int afb_hook_xreq_unsubscribe(const struct afb_xreq *xreq, struct afb_event_x2 *event_x2, int result);
154 extern void afb_hook_xreq_subcall(const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, int flags);
155 extern void afb_hook_xreq_subcall_result(const struct afb_xreq *xreq, struct json_object *object, const char *error, const char *info);
156 extern void afb_hook_xreq_subcallsync(const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, int flags);
157 extern int afb_hook_xreq_subcallsync_result(const struct afb_xreq *xreq, int status, struct json_object *object, const char *error, const char *info);
158 extern void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args);
159 extern void afb_hook_xreq_legacy_store(const struct afb_xreq *xreq, struct afb_stored_req *sreq);
160 extern void afb_hook_xreq_legacy_unstore(const struct afb_xreq *xreq);
161 extern int afb_hook_xreq_has_permission(const struct afb_xreq *xreq, const char *permission, int result);
162 extern char *afb_hook_xreq_get_application_id(const struct afb_xreq *xreq, char *result);
163 extern void *afb_hook_xreq_context_make(const struct afb_xreq *xreq, int replace, void *(*create_value)(void*), void (*free_value)(void*), void *create_closure, void *result);
164 extern int afb_hook_xreq_get_uid(const struct afb_xreq *xreq, int result);
165 extern struct json_object *afb_hook_xreq_get_client_info(const struct afb_xreq *xreq, struct json_object *result);
166
167 /*********************************************************
168 * section hooking apis
169 *********************************************************/
170
171 #define afb_hook_flag_api_vverbose                      0x00000001
172 #define afb_hook_flag_api_get_event_loop                0x00000002
173 #define afb_hook_flag_api_get_user_bus                  0x00000004
174 #define afb_hook_flag_api_get_system_bus                0x00000008
175 #define afb_hook_flag_api_rootdir_get_fd                0x00000010
176 #define afb_hook_flag_api_rootdir_open_locale           0x00000020
177 #define afb_hook_flag_api_queue_job                     0x00000040
178 #define afb_hook_flag_api_require_api                   0x00000080
179 #define afb_hook_flag_api_add_alias                     0x00000100
180 #define afb_hook_flag_api_event_broadcast               0x00000200
181 #define afb_hook_flag_api_event_make                    0x00000400
182 #define afb_hook_flag_api_new_api                       0x00000800
183 #define afb_hook_flag_api_api_set_verbs                 0x00001000
184 #define afb_hook_flag_api_api_add_verb                  0x00002000
185 #define afb_hook_flag_api_api_del_verb                  0x00004000
186 #define afb_hook_flag_api_api_set_on_event              0x00008000
187 #define afb_hook_flag_api_api_set_on_init               0x00010000
188 #define afb_hook_flag_api_api_seal                      0x00020000
189 #define afb_hook_flag_api_event_handler_add             0x00040000
190 #define afb_hook_flag_api_event_handler_del             0x00080000
191 #define afb_hook_flag_api_call                          0x00100000
192 #define afb_hook_flag_api_callsync                      0x00200000
193 #define afb_hook_flag_api_class_provide                 0x00400000
194 #define afb_hook_flag_api_class_require                 0x00800000
195 #define afb_hook_flag_api_delete_api                    0x01000000
196 #define afb_hook_flag_api_start                         0x02000000
197 #define afb_hook_flag_api_on_event                      0x04000000
198 #define afb_hook_flag_api_legacy_unstore_req            0x08000000
199 #define afb_hook_flag_api_on_event_handler              0x10000000
200 #define afb_hook_flag_api_settings                      0x20000000
201
202 /* common flags */
203 /* extra flags */
204 /* predefined groups */
205
206 #define afb_hook_flags_api_common       (afb_hook_flag_api_vverbose\
207                                         |afb_hook_flag_api_event_broadcast\
208                                         |afb_hook_flag_api_event_make\
209                                         |afb_hook_flag_api_call\
210                                         |afb_hook_flag_api_callsync\
211                                         |afb_hook_flag_api_start\
212                                         |afb_hook_flag_api_queue_job\
213                                         |afb_hook_flag_api_settings)
214
215
216 #define afb_hook_flags_api_extra        (afb_hook_flag_api_get_event_loop\
217                                         |afb_hook_flag_api_get_user_bus\
218                                         |afb_hook_flag_api_get_system_bus\
219                                         |afb_hook_flag_api_rootdir_get_fd\
220                                         |afb_hook_flag_api_rootdir_open_locale\
221                                         |afb_hook_flag_api_legacy_unstore_req)
222
223
224 #define afb_hook_flags_api_api          (afb_hook_flag_api_new_api\
225                                         |afb_hook_flag_api_api_set_verbs\
226                                         |afb_hook_flag_api_api_add_verb\
227                                         |afb_hook_flag_api_api_del_verb\
228                                         |afb_hook_flag_api_api_set_on_event\
229                                         |afb_hook_flag_api_api_set_on_init\
230                                         |afb_hook_flag_api_api_seal\
231                                         |afb_hook_flag_api_class_provide\
232                                         |afb_hook_flag_api_class_require\
233                                         |afb_hook_flag_api_require_api\
234                                         |afb_hook_flag_api_add_alias\
235                                         |afb_hook_flag_api_delete_api)
236
237 #define afb_hook_flags_api_event        (afb_hook_flag_api_event_broadcast\
238                                         |afb_hook_flag_api_event_make\
239                                         |afb_hook_flag_api_event_handler_add\
240                                         |afb_hook_flag_api_event_handler_del\
241                                         |afb_hook_flag_api_on_event\
242                                         |afb_hook_flag_api_on_event_handler)
243
244 #define afb_hook_flags_api_all          (afb_hook_flags_api_common\
245                                         |afb_hook_flags_api_extra\
246                                         |afb_hook_flags_api_api\
247                                         |afb_hook_flags_api_event)
248
249 /*********************************************************
250 *********************************************************/
251 #define afb_hook_flags_api_svc_all      (afb_hook_flag_api_start|afb_hook_flag_api_start\
252                                         |afb_hook_flag_api_on_event|afb_hook_flag_api_on_event\
253                                         |afb_hook_flag_api_call|afb_hook_flag_api_call\
254                                         |afb_hook_flag_api_callsync|afb_hook_flag_api_callsync)
255
256 #define afb_hook_flags_api_ditf_common  (afb_hook_flag_api_vverbose\
257                                         |afb_hook_flag_api_event_make\
258                                         |afb_hook_flag_api_event_broadcast\
259                                         |afb_hook_flag_api_event_broadcast\
260                                         |afb_hook_flag_api_add_alias)
261
262 #define afb_hook_flags_api_ditf_extra   (afb_hook_flag_api_get_event_loop\
263                                         |afb_hook_flag_api_get_user_bus\
264                                         |afb_hook_flag_api_get_system_bus\
265                                         |afb_hook_flag_api_rootdir_get_fd\
266                                         |afb_hook_flag_api_rootdir_open_locale\
267                                         |afb_hook_flag_api_queue_job\
268                                         |afb_hook_flag_api_legacy_unstore_req\
269                                         |afb_hook_flag_api_require_api\
270                                         |afb_hook_flag_api_require_api)
271
272 #define afb_hook_flags_api_ditf_all     (afb_hook_flags_api_ditf_common|afb_hook_flags_api_ditf_extra)
273 /*********************************************************
274 *********************************************************/
275
276
277 struct afb_hook_api_itf {
278         void (*hook_api_event_broadcast_before)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct json_object *object);
279         void (*hook_api_event_broadcast_after)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct json_object *object, int result);
280         void (*hook_api_get_event_loop)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct sd_event *result);
281         void (*hook_api_get_user_bus)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct sd_bus *result);
282         void (*hook_api_get_system_bus)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct sd_bus *result);
283         void (*hook_api_vverbose)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int level, const char *file, int line, const char *function, const char *fmt, va_list args);
284         void (*hook_api_event_make)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct afb_event_x2 *result);
285         void (*hook_api_rootdir_get_fd)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result);
286         void (*hook_api_rootdir_open_locale)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *filename, int flags, const char *locale, int result);
287         void (*hook_api_queue_job)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result);
288         void (*hook_api_legacy_unstore_req)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct afb_stored_req *sreq);
289         void (*hook_api_require_api)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, int initialized);
290         void (*hook_api_require_api_result)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, int initialized, int result);
291         void (*hook_api_add_alias)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *oldname, const char *newname, int result);
292         void (*hook_api_start_before)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export);
293         void (*hook_api_start_after)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int status);
294         void (*hook_api_on_event_before)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int event_x2, struct json_object *object);
295         void (*hook_api_on_event_after)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int event_x2, struct json_object *object);
296         void (*hook_api_call)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *api, const char *verb, struct json_object *args);
297         void (*hook_api_call_result)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct json_object *object, const char *error, const char *info);
298         void (*hook_api_callsync)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *api, const char *verb, struct json_object *args);
299         void (*hook_api_callsync_result)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, struct json_object *object, const char *error, const char *info);
300         void (*hook_api_new_api_before)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *api, const char *info, int noconcurrency);
301         void (*hook_api_new_api_after)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *api);
302         void (*hook_api_api_set_verbs_v2)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const struct afb_verb_v2 *verbs);
303         void (*hook_api_api_set_verbs_v3)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const struct afb_verb_v3 *verbs);
304         void (*hook_api_api_add_verb)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *verb, const char *info, int glob);
305         void (*hook_api_api_del_verb)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *verb);
306         void (*hook_api_api_set_on_event)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result);
307         void (*hook_api_api_set_on_init)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result);
308         void (*hook_api_api_seal)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export);
309         void (*hook_api_event_handler_add)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *pattern);
310         void (*hook_api_event_handler_del)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *pattern);
311         void (*hook_api_class_provide)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *name);
312         void (*hook_api_class_require)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result, const char *name);
313         void (*hook_api_delete_api)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result);
314         void (*hook_api_on_event_handler_before)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int event_x2, struct json_object *object, const char *pattern);
315         void (*hook_api_on_event_handler_after)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int event_x2, struct json_object *object, const char *pattern);
316         void (*hook_api_settings)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct json_object *object);
317 };
318
319 extern void afb_hook_api_event_broadcast_before(const struct afb_export *export, const char *name, struct json_object *object);
320 extern int afb_hook_api_event_broadcast_after(const struct afb_export *export, const char *name, struct json_object *object, int result);
321 extern struct sd_event *afb_hook_api_get_event_loop(const struct afb_export *export, struct sd_event *result);
322 extern struct sd_bus *afb_hook_api_get_user_bus(const struct afb_export *export, struct sd_bus *result);
323 extern struct sd_bus *afb_hook_api_get_system_bus(const struct afb_export *export, struct sd_bus *result);
324 extern void afb_hook_api_vverbose(const struct afb_export *export, int level, const char *file, int line, const char *function, const char *fmt, va_list args);
325 extern struct afb_event_x2 *afb_hook_api_event_make(const struct afb_export *export, const char *name, struct afb_event_x2 *result);
326 extern int afb_hook_api_rootdir_get_fd(const struct afb_export *export, int result);
327 extern int afb_hook_api_rootdir_open_locale(const struct afb_export *export, const char *filename, int flags, const char *locale, int result);
328 extern int afb_hook_api_queue_job(const struct afb_export *export, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result);
329 extern void afb_hook_api_legacy_unstore_req(const struct afb_export *export, struct afb_stored_req *sreq);
330 extern void afb_hook_api_require_api(const struct afb_export *export, const char *name, int initialized);
331 extern int afb_hook_api_require_api_result(const struct afb_export *export, const char *name, int initialized, int result);
332 extern int afb_hook_api_add_alias(const struct afb_export *export, const char *api, const char *alias, int result);
333 extern void afb_hook_api_start_before(const struct afb_export *export);
334 extern int afb_hook_api_start_after(const struct afb_export *export, int status);
335 extern void afb_hook_api_on_event_before(const struct afb_export *export, const char *event, int event_x2, struct json_object *object);
336 extern void afb_hook_api_on_event_after(const struct afb_export *export, const char *event, int event_x2, struct json_object *object);
337 extern void afb_hook_api_call(const struct afb_export *export, const char *api, const char *verb, struct json_object *args);
338 extern void afb_hook_api_call_result(const struct afb_export *export, struct json_object *object, const char *error, const char *info);
339 extern void afb_hook_api_callsync(const struct afb_export *export, const char *api, const char *verb, struct json_object *args);
340 extern int afb_hook_api_callsync_result(const struct afb_export *export, int result, struct json_object *object, const char *error, const char *info);
341 extern void afb_hook_api_new_api_before(const struct afb_export *export, const char *api, const char *info, int noconcurrency);
342 extern int afb_hook_api_new_api_after(const struct afb_export *export, int result, const char *api);
343 extern int afb_hook_api_api_set_verbs_v2(const struct afb_export *export, int result, const struct afb_verb_v2 *verbs);
344 extern int afb_hook_api_api_set_verbs_v3(const struct afb_export *export, int result, const struct afb_verb_v3 *verbs);
345 extern int afb_hook_api_api_add_verb(const struct afb_export *export, int result, const char *verb, const char *info, int glob);
346 extern int afb_hook_api_api_del_verb(const struct afb_export *export, int result, const char *verb);
347 extern int afb_hook_api_api_set_on_event(const struct afb_export *export, int result);
348 extern int afb_hook_api_api_set_on_init(const struct afb_export *export, int result);
349 extern void afb_hook_api_api_seal(const struct afb_export *export);
350 extern int afb_hook_api_event_handler_add(const struct afb_export *export, int result, const char *pattern);
351 extern int afb_hook_api_event_handler_del(const struct afb_export *export, int result, const char *pattern);
352 extern int afb_hook_api_class_provide(const struct afb_export *export, int result, const char *name);
353 extern int afb_hook_api_class_require(const struct afb_export *export, int result, const char *name);
354 extern int afb_hook_api_delete_api(const struct afb_export *export, int result);
355 extern void afb_hook_api_on_event_handler_before(const struct afb_export *export, const char *event, int event_x2, struct json_object *object, const char *pattern);
356 extern void afb_hook_api_on_event_handler_after(const struct afb_export *export, const char *event, int event_x2, struct json_object *object, const char *pattern);
357 extern struct json_object *afb_hook_api_settings(const struct afb_export *export, struct json_object *object);
358
359 extern int afb_hook_flags_api(const char *api);
360 extern struct afb_hook_api *afb_hook_create_api(const char *api, int flags, struct afb_hook_api_itf *itf, void *closure);
361 extern struct afb_hook_api *afb_hook_addref_api(struct afb_hook_api *hook);
362 extern void afb_hook_unref_api(struct afb_hook_api *hook);
363
364 /*********************************************************
365 * section hooking evt (event interface)
366 *********************************************************/
367
368 #define afb_hook_flag_evt_create                        0x000001
369 #define afb_hook_flag_evt_push_before                   0x000002
370 #define afb_hook_flag_evt_push_after                    0x000004
371 #define afb_hook_flag_evt_broadcast_before              0x000008
372 #define afb_hook_flag_evt_broadcast_after               0x000010
373 #define afb_hook_flag_evt_name                          0x000020
374 #define afb_hook_flag_evt_addref                        0x000040
375 #define afb_hook_flag_evt_unref                         0x000080
376
377 #define afb_hook_flags_evt_common       (afb_hook_flag_evt_push_before|afb_hook_flag_evt_broadcast_before)
378 #define afb_hook_flags_evt_extra        (afb_hook_flags_evt_common\
379                                         |afb_hook_flag_evt_push_after|afb_hook_flag_evt_broadcast_after\
380                                         |afb_hook_flag_evt_create\
381                                         |afb_hook_flag_evt_addref|afb_hook_flag_evt_unref)
382 #define afb_hook_flags_evt_all          (afb_hook_flags_evt_extra|afb_hook_flag_evt_name)
383
384 struct afb_hook_evt_itf {
385         void (*hook_evt_create)(void *closure, const struct afb_hookid *hookid, const char *evt, int id);
386         void (*hook_evt_push_before)(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj);
387         void (*hook_evt_push_after)(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj, int result);
388         void (*hook_evt_broadcast_before)(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj);
389         void (*hook_evt_broadcast_after)(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj, int result);
390         void (*hook_evt_name)(void *closure, const struct afb_hookid *hookid, const char *evt, int id, const char *result);
391         void (*hook_evt_addref)(void *closure, const struct afb_hookid *hookid, const char *evt, int id);
392         void (*hook_evt_unref)(void *closure, const struct afb_hookid *hookid, const char *evt, int id);
393 };
394
395 extern void afb_hook_evt_create(const char *evt, int id);
396 extern void afb_hook_evt_push_before(const char *evt, int id, struct json_object *obj);
397 extern int afb_hook_evt_push_after(const char *evt, int id, struct json_object *obj, int result);
398 extern void afb_hook_evt_broadcast_before(const char *evt, int id, struct json_object *obj);
399 extern int afb_hook_evt_broadcast_after(const char *evt, int id, struct json_object *obj, int result);
400 extern void afb_hook_evt_name(const char *evt, int id, const char *result);
401 extern void afb_hook_evt_addref(const char *evt, int id);
402 extern void afb_hook_evt_unref(const char *evt, int id);
403
404 extern int afb_hook_flags_evt(const char *name);
405 extern struct afb_hook_evt *afb_hook_create_evt(const char *pattern, int flags, struct afb_hook_evt_itf *itf, void *closure);
406 extern struct afb_hook_evt *afb_hook_addref_evt(struct afb_hook_evt *hook);
407 extern void afb_hook_unref_evt(struct afb_hook_evt *hook);
408
409 /*********************************************************
410 * section hooking session (session interface)
411 *********************************************************/
412
413 #define afb_hook_flag_session_create                    0x000001
414 #define afb_hook_flag_session_close                     0x000002
415 #define afb_hook_flag_session_destroy                   0x000004
416 #define afb_hook_flag_session_renew                     0x000008
417 #define afb_hook_flag_session_addref                    0x000010
418 #define afb_hook_flag_session_unref                     0x000020
419
420 #define afb_hook_flags_session_common   (afb_hook_flag_session_create|afb_hook_flag_session_close\
421                                         |afb_hook_flag_session_renew)
422 #define afb_hook_flags_session_all      (afb_hook_flags_session_common|afb_hook_flag_session_destroy\
423                                         |afb_hook_flag_session_addref|afb_hook_flag_session_unref)
424
425 struct afb_hook_session_itf {
426         void (*hook_session_create)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
427         void (*hook_session_close)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
428         void (*hook_session_destroy)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
429         void (*hook_session_renew)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
430         void (*hook_session_addref)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
431         void (*hook_session_unref)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
432 };
433
434 extern void afb_hook_session_create(struct afb_session *session);
435 extern void afb_hook_session_close(struct afb_session *session);
436 extern void afb_hook_session_destroy(struct afb_session *session);
437 extern void afb_hook_session_renew(struct afb_session *session);
438 extern void afb_hook_session_addref(struct afb_session *session);
439 extern void afb_hook_session_unref(struct afb_session *session);
440
441 extern struct afb_hook_session *afb_hook_create_session(const char *pattern, int flags, struct afb_hook_session_itf *itf, void *closure);
442 extern struct afb_hook_session *afb_hook_addref_session(struct afb_hook_session *hook);
443 extern void afb_hook_unref_session(struct afb_hook_session *hook);
444
445 /*********************************************************
446 * section hooking global (global interface)
447 *********************************************************/
448
449 #define afb_hook_flag_global_vverbose                   0x000001
450
451 #define afb_hook_flags_global_all       (afb_hook_flag_global_vverbose)
452
453 struct afb_hook_global_itf {
454         void (*hook_global_vverbose)(void *closure, const struct afb_hookid *hookid, int level, const char *file, int line, const char *function, const char *fmt, va_list args);
455 };
456
457 extern struct afb_hook_global *afb_hook_create_global(int flags, struct afb_hook_global_itf *itf, void *closure);
458 extern struct afb_hook_global *afb_hook_addref_global(struct afb_hook_global *hook);
459 extern void afb_hook_unref_global(struct afb_hook_global *hook);
460
461