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