Fix warnings due to json-c evolution
[src/app-framework-binder.git] / docs / afb-binding-references.md
1 # Binding Reference
2
3 ## Structure for declaring binding
4
5 ### afb_binding_t
6
7 The main structure, of type **afb_binding_t**, for describing the binding
8 must be exported under the name **afbBindingExport**.
9
10 This structure is defined as below.
11
12 ```C
13 typedef struct afb_binding_v3 afb_binding_t;
14 ```
15
16 Where:
17
18 ```C
19 /**
20  * Description of the bindings of type version 3
21  */
22 struct afb_binding_v3
23 {
24         /** api name for the binding, can't be NULL */
25         const char *api;
26
27         /** textual specification of the binding, can be NULL */
28         const char *specification;
29
30         /** some info about the api, can be NULL */
31         const char *info;
32
33         /** array of descriptions of verbs terminated by a NULL name, can be NULL */
34         const struct afb_verb_v3 *verbs;
35
36         /** callback at load of the binding */
37         int (*preinit)(struct afb_api_x3 *api);
38
39         /** callback for starting the service */
40         int (*init)(struct afb_api_x3 *api);
41
42         /** callback for handling events */
43         void (*onevent)(struct afb_api_x3 *api, const char *event, struct json_object *object);
44
45         /** userdata for afb_api_x3 */
46         void *userdata;
47
48         /** space separated list of provided class(es) */
49         const char *provide_class;
50
51         /** space separated list of required class(es) */
52         const char *require_class;
53
54         /** space separated list of required API(es) */
55         const char *require_api;
56
57         /** avoids concurrent requests to verbs */
58         unsigned noconcurrency: 1;
59 };
60 ```
61
62 ### struct afb_verb_t
63
64 Each verb is described with a structure of type **afb_verb_t**
65 defined below:
66
67 ```C
68 typedef struct afb_verb_v3 afb_verb_t;
69 ```
70
71 ```C
72 /**
73  * Description of one verb as provided for binding API version 3
74  */
75 struct afb_verb_v3
76 {
77         /** name of the verb, NULL only at end of the array */
78         const char *verb;
79
80         /** callback function implementing the verb */
81         void (*callback)(afb_req_t_x2 *req);
82
83         /** required authorization, can be NULL */
84         const struct afb_auth *auth;
85
86         /** some info about the verb, can be NULL */
87         const char *info;
88
89         /**< data for the verb callback */
90         void *vcbdata;
91
92         /** authorization and session requirements of the verb */
93         uint16_t session;
94
95         /** is the verb glob name */
96         uint16_t glob: 1;
97 };
98 ```
99
100 The **session** flags is one of the constant defined below:
101
102 - AFB_SESSION_NONE : no flag, synonym to 0
103 - AFB_SESSION_LOA_0 : Requires the LOA to be 0 or more, synonym to 0 or AFB_SESSION_NONE
104 - AFB_SESSION_LOA_1 : Requires the LOA to be 1 or more
105 - AFB_SESSION_LOA_2 : Requires the LOA to be 2 or more
106 - AFB_SESSION_LOA_3 : Requires the LOA to be 3 or more
107 - AFB_SESSION_CHECK : Requires the token to be set and valid
108 - AFB_SESSION_REFRESH : Implies a token refresh
109 - AFB_SESSION_CLOSE : Implies closing the session after request processed
110
111 The LOA (Level Of Assurance) is set, by binding api, using the function **afb_req_session_set_LOA**.
112
113 The session can be closed, by binding api, using the function **afb_req_session_close**.
114
115 ### afb_auth_t and afb_auth_type_t
116
117 The structure **afb_auth_t** is used within verb description to
118 set security requirements.  
119 The interpretation of the structure depends on the value of the field **type**.
120
121 ```C
122 typedef struct afb_auth afb_auth_t;
123
124 /**
125  * Definition of an authorization entry
126  */
127 struct afb_auth
128 {
129         /** type of entry @see afb_auth_type */
130         enum afb_auth_type type;
131         
132         union {
133                 /** text when @ref type == @ref afb_auth_Permission */
134                 const char *text;
135                 
136                 /** level of assurancy when @ref type ==  @ref afb_auth_LOA */
137                 unsigned loa;
138                 
139                 /** first child when @ref type in { @ref afb_auth_Or, @ref afb_auth_And, @ref afb_auth_Not } */
140                 const struct afb_auth *first;
141         };
142         
143         /** second child when @ref type in { @ref afb_auth_Or, @ref afb_auth_And } */
144         const struct afb_auth *next;
145 };
146
147 ```
148
149 The possible values for **type** is defined here:
150
151 ```C
152 typedef enum afb_auth_type afb_auth_type_t;
153
154 /**
155  * Enumeration  for authority (Session/Token/Assurance) definitions.
156  *
157  * @see afb_auth
158  */
159 enum afb_auth_type
160 {
161         /** never authorized, no data */
162         afb_auth_No = 0,
163
164         /** authorized if token valid, no data */
165         afb_auth_Token,
166
167         /** authorized if LOA greater than data 'loa' */
168         afb_auth_LOA,
169
170         /** authorized if permission 'text' is granted */
171         afb_auth_Permission,
172
173         /** authorized if 'first' or 'next' is authorized */
174         afb_auth_Or,
175
176         /** authorized if 'first' and 'next' are authorized */
177         afb_auth_And,
178
179         /** authorized if 'first' is not authorized */
180         afb_auth_Not,
181
182         /** always authorized, no data */
183         afb_auth_Yes
184 };
185 ```
186
187 Example:
188
189 ```C
190 static const afb_auth_t myauth[] = {
191     { .type = afb_auth_Permission, .text = "urn:AGL:permission:me:public:set" },
192     { .type = afb_auth_Permission, .text = "urn:AGL:permission:me:public:get" },
193     { .type = afb_auth_Or, .first = &myauth[1], .next = &myauth[0] }
194 };
195 ```
196
197 ## Functions of class afb_daemon
198
199 The 3 following functions are linked to libsystemd.  
200 They allow use of **sd_event** features and access
201 to **sd_bus** features.
202
203 ```C
204 /*
205  * Retrieves the common systemd's event loop of AFB 
206  * 
207  */
208 struct sd_event *afb_daemon_get_event_loop();
209
210 /*
211  * Retrieves the common systemd's user/session d-bus of AFB if active
212  */
213 struct sd_bus *afb_daemon_get_user_bus();
214
215 /*
216  * Retrieves the common systemd's system d-bus of AFB if active or NULL
217  */
218 struct sd_bus *afb_daemon_get_system_bus();
219 ```
220
221 The 2 following functions are linked to event management.  
222 Broadcasting an event send it to any possible listener.
223
224 ```C
225 /*
226  * Broadcasts widely the event of 'name' with the data 'object'.
227  * 'object' can be NULL.
228  *
229  * For convenience, the function calls 'json_object_put' for 'object'.
230  * Thus, in the case where 'object' should remain available after
231  * the function returns, the function 'json_object_get' shall be used.
232  *
233  * Calling this function is only forbidden during preinit.
234  *
235  * Returns the count of clients that received the event.
236  */
237 int afb_daemon_broadcast_event(const char *name, struct json_object *object);
238
239 /*
240  * Creates an event of 'name' and returns it.
241  *
242  * Calling this function is only forbidden during preinit.
243  *
244  * See afb_event_is_valid to check if there is an error.
245  */
246 afb_event_t afb_daemon_make_event(const char *name);
247 ```
248
249 The following function is used by logging macros and should normally
250 not be used.  
251 Instead, you should use the macros:
252
253 - **AFB\_ERROR**
254 - **AFB\_WARNING**
255 - **AFB\_NOTICE**
256 - **AFB\_INFO**
257 - **AFB\_DEBUG**
258
259 ```C
260 /*
261  * Send a message described by 'fmt' and following parameters
262  * to the journal for the verbosity 'level'.
263  *
264  * 'file', 'line' and 'func' are indicators of position of the code in source files
265  * (see macros __FILE__, __LINE__ and __func__).
266  *
267  * 'level' is defined by syslog standard:
268  *      EMERGENCY         0        System is unusable
269  *      ALERT             1        Action must be taken immediately
270  *      CRITICAL          2        Critical conditions
271  *      ERROR             3        Error conditions
272  *      WARNING           4        Warning conditions
273  *      NOTICE            5        Normal but significant condition
274  *      INFO              6        Informational
275  *      DEBUG             7        Debug-level messages
276  */
277 void afb_daemon_verbose(int level, const char *file, int line, const char * func, const char *fmt, ...);
278 ```
279
280 The 2 following functions MUST be used to access data of the bindings.
281
282 ```C
283 /*
284  * Get the root directory file descriptor. This file descriptor can
285  * be used with functions 'openat', 'fstatat', ...
286  */
287 int afb_daemon_rootdir_get_fd();
288
289 /*
290  * Opens 'filename' within the root directory with 'flags' (see function openat)
291  * using the 'locale' definition (example: "jp,en-US") that can be NULL.
292  * Returns the file descriptor or -1 in case of error.
293  */
294 int afb_daemon_rootdir_open_locale(const char *filename, int flags, const char *locale);
295 ```
296
297 The following function is used to queue jobs.
298
299 ```C
300 /*
301  * Queue the job defined by 'callback' and 'argument' for being executed asynchronously
302  * in this thread (later) or in an other thread.
303  * If 'group' is not NUL, the jobs queued with a same value (as the pointer value 'group')
304  * are executed in sequence in the order of there submission.
305  * If 'timeout' is not 0, it represent the maximum execution time for the job in seconds.
306  * At first, the job is called with 0 as signum and the given argument.
307  * The job is executed with the monitoring of its time and some signals like SIGSEGV and
308  * SIGFPE. When a such signal is catched, the job is terminated and re-executed but with
309  * signum being the signal number (SIGALRM when timeout expired).
310  *
311  * Returns 0 in case of success or -1 in case of error.
312  */
313 int afb_daemon_queue_job(void (*callback)(int signum, void *arg), void *argument, void *group, int timeout)
314 ```
315
316 The following function must be used when a binding depends on other
317 bindings at its initialization.
318
319 ```C
320 /*
321  * Tells that it requires the API of "name" to exist
322  * and if 'initialized' is not null to be initialized.
323  * Calling this function is only allowed within init.
324  * Returns 0 in case of success or -1 in case of error.
325  */
326 int afb_daemon_require_api(const char *name, int initialized)
327 ```
328
329 This function allows to give a different name to the binding.
330 It can be called during pre-init.
331
332 ```C
333 /*
334  * Set the name of the API to 'name'.
335  * Calling this function is only allowed within preinit.
336  * Returns 0 in case of success or -1 in case of error.
337  */
338 int afb_daemon_rename_api(const char *name);
339 ```
340
341 ## Functions of class afb_service
342
343 The following functions allow services to call verbs of other
344 bindings for themselves.
345
346 ```C
347 /**
348  * Calls the 'verb' of the 'api' with the arguments 'args' and 'verb' in the name of the binding.
349  * The result of the call is delivered to the 'callback' function with the 'callback_closure'.
350  *
351  * For convenience, the function calls 'json_object_put' for 'args'.
352  * Thus, in the case where 'args' should remain available after
353  * the function returns, the function 'json_object_get' shall be used.
354  *
355  * The 'callback' receives 3 arguments:
356  *  1. 'closure' the user defined closure pointer 'callback_closure',
357  *  2. 'status' a status being 0 on success or negative when an error occured,
358  *  2. 'result' the resulting data as a JSON object.
359  *
360  * @param api      The api name of the method to call
361  * @param verb     The verb name of the method to call
362  * @param args     The arguments to pass to the method
363  * @param callback The to call on completion
364  * @param callback_closure The closure to pass to the callback
365  *
366  * @see also 'afb_req_subcall'
367  */
368 void afb_service_call(
369     const char *api,
370     const char *verb,
371     struct json_object *args,
372     void (*callback)(void*closure, int status, struct json_object *result),
373     void *callback_closure);
374
375 /**
376  * Calls the 'verb' of the 'api' with the arguments 'args' and 'verb' in the name of the binding.
377  * 'result' will receive the response.
378  *
379  * For convenience, the function calls 'json_object_put' for 'args'.
380  * Thus, in the case where 'args' should remain available after
381  * the function returns, the function 'json_object_get' shall be used.
382  *
383  * @param api      The api name of the method to call
384  * @param verb     The verb name of the method to call
385  * @param args     The arguments to pass to the method
386  * @param result   Where to store the result - should call json_object_put on it -
387  *
388  * @returns 0 in case of success or a negative value in case of error.
389  *
390  * @see also 'afb_req_subcall'
391  */
392 int afb_service_call_sync(
393     const char *api,
394     const char *verb,
395     struct json_object *args,
396     struct json_object **result);
397 ```
398
399 ## Functions of class afb_event
400
401 This function checks whether the event is valid.  
402 It must be used when creating events.
403
404 ```C
405 /*
406  * Checks wether the 'event' is valid or not.
407  *
408  * Returns 0 if not valid or 1 if valid.
409  */
410 int afb_event_is_valid(afb_event_t event);
411 ```
412
413 The two following functions are used to broadcast or push
414 event with its data.
415
416 ```C
417 /*
418  * Broadcasts widely the 'event' with the data 'object'.
419  * 'object' can be NULL.
420  *
421  * For convenience, the function calls 'json_object_put' for 'object'.
422  * Thus, in the case where 'object' should remain available after
423  * the function returns, the function 'json_object_get' shall be used.
424  *
425  * Returns the count of clients that received the event.
426  */
427 int afb_event_broadcast(afb_event_t event, struct json_object *object);
428
429 /*
430  * Pushes the 'event' with the data 'object' to its observers.
431  * 'object' can be NULL.
432  *
433  * For convenience, the function calls 'json_object_put' for 'object'.
434  * Thus, in the case where 'object' should remain available after
435  * the function returns, the function 'json_object_get' shall be used.
436  *
437  * Returns the count of clients that received the event.
438  */
439 int afb_event_push(afb_event_t event, struct json_object *object);
440 ```
441
442 The following function remove one reference to the event.
443
444 ```C
445 /*
446  * Decrease the reference count of the event.
447  * After calling this function, the event
448  * MUST NOT BE USED ANYMORE.
449  */
450 void afb_event_unref(afb_event_t event);
451 ```
452
453 The following function add one reference to the event.
454
455 ```C
456 /*
457  * Decrease the reference count of the event.
458  * After calling this function, the event
459  * MUST NOT BE USED ANYMORE.
460  */
461 void afb_event_unref(afb_event_t event);
462 ```
463
464 This function allows to retrieve the exact name of the event.
465
466 ```C
467 /*
468  * Gets the name associated to the 'event'.
469  */
470 const char *afb_event_name(afb_event_t event);
471 ```
472
473 ## Functions of class afb_req
474
475 This function checks the validity of the **req**.
476
477 ```C
478 /*
479  * Checks wether the request 'req' is valid or not.
480  *
481  * Returns 0 if not valid or 1 if valid.
482  */
483 int afb_req_is_valid(afb_req_t req);
484 ```
485
486 The following functions retrieves parameters of the request.
487
488 ```C
489 /*
490  * Gets from the request 'req' the argument of 'name'.
491  * Returns a PLAIN structure of type 'struct afb_arg'.
492  * When the argument of 'name' is not found, all fields of result are set to NULL.
493  * When the argument of 'name' is found, the fields are filled,
494  * in particular, the field 'result.name' is set to 'name'.
495  *
496  * There is a special name value: the empty string.
497  * The argument of name "" is defined only if the request was made using
498  * an HTTP POST of Content-Type "application/json". In that case, the
499  * argument of name "" receives the value of the body of the HTTP request.
500  */
501 afb_arg_t afb_req_get(afb_req_t req, const char *name);
502
503 /*
504  * Gets from the request 'req' the string value of the argument of 'name'.
505  * Returns NULL if when there is no argument of 'name'.
506  * Returns the value of the argument of 'name' otherwise.
507  *
508  * Shortcut for: afb_req_get(req, name).value
509  */
510 const char *afb_req_value(afb_req_t req, const char *name);
511
512 /*
513  * Gets from the request 'req' the path for file attached to the argument of 'name'.
514  * Returns NULL if when there is no argument of 'name' or when there is no file.
515  * Returns the path of the argument of 'name' otherwise.
516  *
517  * Shortcut for: afb_req_get(req, name).path
518  */
519 const char *afb_req_path(afb_req_t req, const char *name);
520
521 /*
522  * Gets from the request 'req' the json object hashing the arguments.
523  * The returned object must not be released using 'json_object_put'.
524  */
525 struct json_object *afb_req_json(afb_req_t req);
526 ```
527
528 The following functions emit the reply to the request.
529
530 ```C
531 /*
532  * Sends a reply of kind success to the request 'req'.
533  * The status of the reply is automatically set to "success".
534  * Its send the object 'obj' (can be NULL) with an
535  * informationnal comment 'info (can also be NULL).
536  *
537  * For convenience, the function calls 'json_object_put' for 'obj'.
538  * Thus, in the case where 'obj' should remain available after
539  * the function returns, the function 'json_object_get' shall be used.
540  */
541 void afb_req_success(afb_req_t req, struct json_object *obj, const char *info);
542
543 /*
544  * Same as 'afb_req_success' but the 'info' is a formatting
545  * string followed by arguments.
546  *
547  * For convenience, the function calls 'json_object_put' for 'obj'.
548  * Thus, in the case where 'obj' should remain available after
549  * the function returns, the function 'json_object_get' shall be used.
550  */
551 void afb_req_success_f(afb_req_t req, struct json_object *obj, const char *info, ...);
552
553 /*
554  * Same as 'afb_req_success_f' but the arguments to the format 'info'
555  * are given as a variable argument list instance.
556  *
557  * For convenience, the function calls 'json_object_put' for 'obj'.
558  * Thus, in the case where 'obj' should remain available after
559  * the function returns, the function 'json_object_get' shall be used.
560  */
561 void afb_req_success_v(afb_req_t req, struct json_object *obj, const char *info, va_list args);
562
563 /*
564  * Sends a reply of kind failure to the request 'req'.
565  * The status of the reply is set to 'status' and an
566  * informational comment 'info' (can also be NULL) can be added.
567  *
568  * Note that calling afb_req_fail("success", info) is equivalent
569  * to call afb_req_success(NULL, info). Thus even if possible it
570  * is strongly recommended to NEVER use "success" for status.
571  */
572 void afb_req_fail(afb_req_t req, const char *status, const char *info);
573
574 /*
575  * Same as 'afb_req_fail' but the 'info' is a formatting
576  * string followed by arguments.
577  */
578 void afb_req_fail_f(afb_req_t req, const char *status, const char *info, ...);
579
580 /*
581  * Same as 'afb_req_fail_f' but the arguments to the format 'info'
582  * are given as a variable argument list instance.
583  */
584 void afb_req_fail_v(afb_req_t req, const char *status, const char *info, va_list args);
585 ```
586
587 The following functions handle the session data.
588
589 ```C
590 /*
591  * Gets the pointer stored by the binding for the session of 'req'.
592  * When the binding has not yet recorded a pointer, NULL is returned.
593  */
594 void *afb_req_context_get(afb_req_t req);
595
596 /*
597  * Stores for the binding the pointer 'context' to the session of 'req'.
598  * The function 'free_context' will be called when the session is closed
599  * or if binding stores an other pointer.
600  */
601 void afb_req_context_set(afb_req_t req, void *context, void (*free_context)(void*));
602
603 /*
604  * Gets the pointer stored by the binding for the session of 'req'.
605  * If the stored pointer is NULL, indicating that no pointer was
606  * already stored, afb_req_context creates a new context by calling
607  * the function 'create_context' and stores it with the freeing function
608  * 'free_context'.
609  */
610 void *afb_req_context(afb_req_t req, void *(*create_context)(), void (*free_context)(void*));
611
612 /*
613  * Frees the pointer stored by the binding for the session of 'req'
614  * and sets it to NULL.
615  *
616  * Shortcut for: afb_req_context_set(req, NULL, NULL)
617  */
618 void afb_req_context_clear(afb_req_t req);
619
620 /*
621  * Closes the session associated with 'req'
622  * and delete all associated contexts.
623  */
624 void afb_req_session_close(afb_req_t req);
625
626 /*
627  * Sets the level of assurance of the session of 'req'
628  * to 'level'. The effect of this function is subject of
629  * security policies.
630  * Returns 1 on success or 0 if failed.
631  */
632 int afb_req_session_set_LOA(afb_req_t req, unsigned level);
633 ```
634
635 The 4 following functions must be used for asynchronous handling requests.
636
637 ```C
638 /*
639  * Adds one to the count of references of 'req'.
640  * This function MUST be called by asynchronous implementations
641  * of verbs if no reply was sent before returning.
642  */
643 void afb_req_addref(afb_req_t req);
644
645 /*
646  * Substracts one to the count of references of 'req'.
647  * This function MUST be called by asynchronous implementations
648  * of verbs after sending the asynchronous reply.
649  */
650 void afb_req_unref(afb_req_t req);
651
652 /*
653  * Stores 'req' on heap for asynchronous use.
654  * Returns a handler to the stored 'req' or NULL on memory depletion.
655  * The count of reference to 'req' is incremented on success
656  * (see afb_req_addref).
657  */
658 struct afb_stored_req *afb_req_store(afb_req_t req);
659
660 /*
661  * Retrieves the afb_req stored at 'sreq'.
662  * Returns the stored request.
663  * The count of reference is UNCHANGED, thus, the
664  * function 'afb_req_unref' should be called on the result
665  * after that the asynchronous reply if sent.
666  */
667 afb_req_t afb_req_unstore(struct afb_stored_req *sreq);
668 ```
669
670 The two following functions are used to associate client with events
671 (subscription).
672
673 ```C
674 /*
675  * Establishes for the client link identified by 'req' a subscription
676  * to the 'event'.
677  * Returns 0 in case of successful subscription or -1 in case of error.
678  */
679 int afb_req_subscribe(afb_req_t req, afb_event_t event);
680
681 /*
682  * Revokes the subscription established to the 'event' for the client
683  * link identified by 'req'.
684  * Returns 0 in case of successful subscription or -1 in case of error.
685  */
686 int afb_req_unsubscribe(afb_req_t req, afb_event_t event);
687 ```
688
689 The following functions must be used to make request in the name of the
690 client (with its permissions).
691
692 ```C
693 /*
694  * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
695  * This call is made in the context of the request 'req'.
696  * On completion, the function 'callback' is invoked with the
697  * 'closure' given at call and two other parameters: 'iserror' and 'result'.
698  * 'status' is 0 on success or negative when on an error reply.
699  * 'result' is the json object of the reply, you must not call json_object_put
700  * on the result.
701  *
702  * For convenience, the function calls 'json_object_put' for 'args'.
703  * Thus, in the case where 'args' should remain available after
704  * the function returns, the function 'json_object_get' shall be used.
705  *
706  * See also:
707  *  - 'afb_req_subcall_req' that is convenient to keep request alive automatically.
708  *  - 'afb_req_subcall_sync' the synchronous version
709  */
710 void afb_req_subcall(
711                 afb_req_t req,
712                 const char *api,
713                 const char *verb,
714                 struct json_object *args,
715                 void (*callback)(void *closure, int status, struct json_object *result),
716                 void *closure);
717
718 /*
719  * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
720  * This call is made in the context of the request 'req'.
721  * On completion, the function 'callback' is invoked with the
722  * original request 'req', the 'closure' given at call and two
723  * other parameters: 'iserror' and 'result'.
724  * 'status' is 0 on success or negative when on an error reply.
725  * 'result' is the json object of the reply, you must not call json_object_put
726  * on the result.
727  *
728  * For convenience, the function calls 'json_object_put' for 'args'.
729  * Thus, in the case where 'args' should remain available after
730  * the function returns, the function 'json_object_get' shall be used.
731  *
732  * See also:
733  *  - 'afb_req_subcall' that doesn't keep request alive automatically.
734  *  - 'afb_req_subcall_sync' the synchronous version
735  */
736 static inline void afb_req_subcall_req(afb_req_t req, const char *api, const char *verb, struct json_object *args, void (*callback)(void *closure, int iserror, struct json_object *result, afb_req_t req), void *closure)
737 {
738         req.itf->subcall_req(req.closure, api, verb, args, callback, closure);
739 }
740
741 /*
742  * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
743  * This call is made in the context of the request 'req'.
744  * This call is synchronous, it waits untill completion of the request.
745  * It returns 0 on success or a negative value on error answer.
746  * The object pointed by 'result' is filled and must be released by the caller
747  * after its use by calling 'json_object_put'.
748  *
749  * For convenience, the function calls 'json_object_put' for 'args'.
750  * Thus, in the case where 'args' should remain available after
751  * the function returns, the function 'json_object_get' shall be used.
752  *
753  * See also:
754  *  - 'afb_req_subcall_req' that is convenient to keep request alive automatically.
755  *  - 'afb_req_subcall' that doesn't keep request alive automatically.
756  */
757 int afb_req_subcall_sync(
758                 afb_req_t req,
759                 const char *api,
760                 const char *verb,
761                 struct json_object *args,
762                 struct json_object **result);
763 ```
764
765 The following function is used by logging macros and should normally
766 not be used.  
767 Instead, you should use the macros:
768
769 - **AFB_REQ_ERROR**
770 - **AFB_REQ_WARNING**
771 - **AFB_REQ_NOTICE**
772 - **AFB_REQ_INFO**
773 - **AFB_REQ_DEBUG**
774
775 ```C
776 /*
777  * Send associated to 'req' a message described by 'fmt' and following parameters
778  * to the journal for the verbosity 'level'.
779  *
780  * 'file', 'line' and 'func' are indicators of position of the code in source files
781  * (see macros __FILE__, __LINE__ and __func__).
782  *
783  * 'level' is defined by syslog standard:
784  *      EMERGENCY         0        System is unusable
785  *      ALERT             1        Action must be taken immediately
786  *      CRITICAL          2        Critical conditions
787  *      ERROR             3        Error conditions
788  *      WARNING           4        Warning conditions
789  *      NOTICE            5        Normal but significant condition
790  *      INFO              6        Informational
791  *      DEBUG             7        Debug-level messages
792  */
793 void afb_req_verbose(afb_req_t req, int level, const char *file, int line, const char * func, const char *fmt, ...);
794 ```
795
796 The functions below allow a binding involved in the platform security
797 to explicitely check a permission of a client or to get the calling
798 application identity.
799
800 ```C
801 /*
802  * Check whether the 'permission' is granted or not to the client
803  * identified by 'req'.
804  *
805  * Returns 1 if the permission is granted or 0 otherwise.
806  */
807 int afb_req_has_permission(afb_req_t req, const char *permission);
808
809 /*
810  * Get the application identifier of the client application for the
811  * request 'req'.
812  *
813  * Returns the application identifier or NULL when the application
814  * can not be identified.
815  *
816  * The returned value if not NULL must be freed by the caller
817  */
818 char *afb_req_get_application_id(afb_req_t req);
819
820 /*
821  * Get the user identifier (UID) of the client application for the
822  * request 'req'.
823  *
824  * Returns -1 when the application can not be identified.
825  */
826 int afb_req_get_uid(afb_req_t req);
827 ```
828
829 ## Logging macros
830
831 The following macros must be used for logging:
832
833 ```C
834 AFB_ERROR(fmt,...)
835 AFB_WARNING(fmt,...)
836 AFB_NOTICE(fmt,...)
837 AFB_INFO(fmt,...)
838 AFB_DEBUG(fmt,...)
839 ```
840
841 The following macros can be used for logging in the context
842 of a request **req** of type **afb_req**:
843
844 ```C
845 AFB_REQ_ERROR(req,fmt,...)
846 AFB_REQ_WARNING(req,fmt,...)
847 AFB_REQ_NOTICE(req,fmt,...)
848 AFB_REQ_INFO(req,fmt,...)
849 AFB_REQ_DEBUG(req,fmt,...)
850 ```
851
852 By default, the logging macros add file, line and function
853 indication.