3 title: Functions of class afb_req
5 https://git.automotivelinux.org/src/app-framework-binder/plain/docs/reference-v3/func-req.md?h=master
8 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/apis_services/master/app-framework-binder-developer-guides-api-services-book.yml -->
10 Functions of class **afb_req**
11 ============================
19 * Checks whether the request 'req' is valid or not.
21 * @param req the request to check
23 * @return 0 if not valid or 1 if valid.
33 * Retrieves the api that serves the request
35 * @param req the request whose serving api is queried
37 * @return the api serving the request
39 afb_api_t afb_req_get_api(
43 ### afb_req_get_vcbdata
47 * Retrieves the callback data of the verb. This callback data is set
48 * when the verb is created.
50 * @param req whose verb vcbdata is queried
52 * @return the callback data attached to the verb description
54 void *afb_req_get_vcbdata(
58 ### afb_req_get_called_api
62 * Retrieve the name of the called api.
64 * @param req the request
66 * @return the name of the called api
68 * @see afb_api_new_api
69 * @see afb_api_add_alias
71 const char *afb_req_get_called_api(
75 ### afb_req_get_called_verb
79 * Retrieve the name of the called verb
81 * @param req the request
83 * @return the name of the called verb
85 const char *afb_req_get_called_verb(
93 * Increments the count of references of 'req'.
95 * @param req the request
97 * @return returns the request req
99 afb_req_t *afb_req_addref(
107 * Decrement the count of references of 'req'.
109 * @param req the request
118 ### afb_req_wants_log_level
122 * Is the log message of 'level (as defined for syslog) required for the
125 * @param req the request
126 * @param level the level to check as defined for syslog:
128 * EMERGENCY 0 System is unusable
129 * ALERT 1 Action must be taken immediately
130 * CRITICAL 2 Critical conditions
131 * ERROR 3 Error conditions
132 * WARNING 4 Warning conditions
133 * NOTICE 5 Normal but significant condition
134 * INFO 6 Informational
135 * DEBUG 7 Debug-level messages
137 * @return 0 if not required or a value not null if required
141 int afb_req_wants_log_level(
150 * Send associated to 'req' a message described by 'fmt' and its 'args'
151 * to the journal for the verbosity 'level'.
153 * 'file', 'line' and 'func' are indicators of position of the code in source files
154 * (see macros __FILE__, __LINE__ and __func__).
156 * 'level' is defined by syslog standard:
157 * EMERGENCY 0 System is unusable
158 * ALERT 1 Action must be taken immediately
159 * CRITICAL 2 Critical conditions
160 * ERROR 3 Error conditions
161 * WARNING 4 Warning conditions
162 * NOTICE 5 Normal but significant condition
163 * INFO 6 Informational
164 * DEBUG 7 Debug-level messages
166 * @param req the request
167 * @param level the level of the message
168 * @param file the source filename that emits the message or NULL
169 * @param line the line number in the source filename that emits the message
170 * @param func the name of the function that emits the message or NULL
171 * @param fmt the message format as for printf
172 * @param args the arguments to the format
175 * @see afb_req_verbose
177 void afb_req_vverbose(
179 int level, const char *file,
190 * Send associated to 'req' a message described by 'fmt' and following parameters
191 * to the journal for the verbosity 'level'.
193 * 'file', 'line' and 'func' are indicators of position of the code in source files
194 * (see macros __FILE__, __LINE__ and __func__).
196 * 'level' is defined by syslog standard:
197 * EMERGENCY 0 System is unusable
198 * ALERT 1 Action must be taken immediately
199 * CRITICAL 2 Critical conditions
200 * ERROR 3 Error conditions
201 * WARNING 4 Warning conditions
202 * NOTICE 5 Normal but significant condition
203 * INFO 6 Informational
204 * DEBUG 7 Debug-level messages
206 * @param req the request
207 * @param level the level of the message
208 * @param file the source filename that emits the message or NULL
209 * @param line the line number in the source filename that emits the message
210 * @param func the name of the function that emits the message or NULL
211 * @param fmt the message format as for printf
212 * @param ... the arguments of the format 'fmt'
216 void afb_req_verbose(
218 int level, const char *file,
225 ## Arguments/parameters function
231 * Gets from the request 'req' the argument of 'name'.
233 * Returns a PLAIN structure of type 'struct afb_arg'.
235 * When the argument of 'name' is not found, all fields of result are set to NULL.
237 * When the argument of 'name' is found, the fields are filled,
238 * in particular, the field 'result.name' is set to 'name'.
240 * There is a special name value: the empty string.
241 * The argument of name "" is defined only if the request was made using
242 * an HTTP POST of Content-Type "application/json". In that case, the
243 * argument of name "" receives the value of the body of the HTTP request.
245 * @param req the request
246 * @param name the name of the argument to get
248 * @return a structure describing the retrieved argument for the request
253 struct afb_arg afb_req_get(
262 * Gets from the request 'req' the string value of the argument of 'name'.
263 * Returns NULL if when there is no argument of 'name'.
264 * Returns the value of the argument of 'name' otherwise.
266 * Shortcut for: afb_req_get(req, name).value
268 * @param req the request
269 * @param name the name of the argument's value to get
271 * @return the value as a string or NULL
276 const char *afb_req_value(
285 * Gets from the request 'req' the path for file attached to the argument of 'name'.
286 * Returns NULL if when there is no argument of 'name' or when there is no file.
287 * Returns the path of the argument of 'name' otherwise.
289 * Shortcut for: afb_req_get(req, name).path
291 * @param req the request
292 * @param name the name of the argument's path to get
294 * @return the path if any or NULL
299 const char *afb_req_path(
308 * Gets from the request 'req' the json object hashing the arguments.
310 * The returned object must not be released using 'json_object_put'.
312 * @param req the request
314 * @return the JSON object of the query
320 struct json_object *afb_req_json(
326 The functions **success** and **fail** are still supported.
327 These functions are now implemented as the following macros:
330 #define afb_req_success(r,o,i) afb_req_reply(r,o,NULL,i)
331 #define afb_req_success_f(r,o,...) afb_req_reply_f(r,o,NULL,__VA_ARGS__)
332 #define afb_req_success_v(r,o,f,v) afb_req_reply_v(r,o,NULL,f,v)
333 #define afb_req_fail(r,e,i) afb_req_reply(r,NULL,e,i)
334 #define afb_req_fail_f(r,e,...) afb_req_reply_f(r,NULL,e,__VA_ARGS__)
335 #define afb_req_fail_v(r,e,f,v) afb_req_reply_v(r,NULL,e,f,v)
343 * Sends a reply to the request 'req'.
345 * The status of the reply is set to 'error' (that must be NULL on success).
346 * Its send the object 'obj' (can be NULL) with an
347 * informational comment 'info (can also be NULL).
349 * For convenience, the function calls 'json_object_put' for 'obj'.
350 * Thus, in the case where 'obj' should remain available after
351 * the function returns, the function 'json_object_get' shall be used.
353 * @param req the request
354 * @param obj the replied object or NULL
355 * @param error the error message if it is a reply error or NULL
356 * @param info an informative text or NULL
358 * @see afb_req_reply_v
359 * @see afb_req_reply_f
363 struct json_object *obj,
372 * Same as 'afb_req_reply_f' but the arguments to the format 'info'
373 * are given as a variable argument list instance.
375 * For convenience, the function calls 'json_object_put' for 'obj'.
376 * Thus, in the case where 'obj' should remain available after
377 * the function returns, the function 'json_object_get' shall be used.
379 * @param req the request
380 * @param obj the replied object or NULL
381 * @param error the error message if it is a reply error or NULL
382 * @param info an informative text containing a format as for vprintf
383 * @param args the va_list of arguments to the format as for vprintf
386 * @see afb_req_reply_f
389 void afb_req_reply_v(
391 struct json_object *obj,
401 * Same as 'afb_req_reply' but the 'info' is a formatting
402 * string followed by arguments.
404 * For convenience, the function calls 'json_object_put' for 'obj'.
405 * Thus, in the case where 'obj' should remain available after
406 * the function returns, the function 'json_object_get' shall be used.
408 * @param req the request
409 * @param obj the replied object or NULL
410 * @param error the error message if it is a reply error or NULL
411 * @param info an informative text containing a format as for printf
412 * @param ... the arguments to the format as for printf
415 * @see afb_req_reply_v
418 void afb_req_reply_f(
420 struct json_object *obj,
434 * Calls the 'verb' of the 'api' with the arguments 'args' and 'verb' in the name of the binding.
435 * The result of the call is delivered to the 'callback' function with the 'callback_closure'.
437 * For convenience, the function calls 'json_object_put' for 'args'.
438 * Thus, in the case where 'args' should remain available after
439 * the function returns, the function 'json_object_get' shall be used.
441 * The 'callback' receives 5 arguments:
442 * 1. 'closure' the user defined closure pointer 'closure',
443 * 2. 'object' a JSON object returned (can be NULL)
444 * 3. 'error' a string not NULL in case of error
445 * 4. 'info' a string handling some info (can be NULL)
448 * NOTE: For convenience, *json_object_put* is called on 'object' after the
449 * callback returns. So, it is wrong to call *json_object_put* in the callback.
451 * @param req The request
452 * @param api The api name of the method to call
453 * @param verb The verb name of the method to call
454 * @param args The arguments to pass to the method
455 * @param flags The bit field of flags for the subcall as defined by @ref afb_req_subcall_flags_t
456 * @param callback The to call on completion
457 * @param closure The closure to pass to the callback
459 * The flags are any combination of the following values:
461 * - afb_req_x2_subcall_catch_events = 1
463 * the calling API wants to receive the events from subscription
465 * - afb_req_x2_subcall_pass_events = 2
467 * the original request will receive the events from subscription
469 * - afb_req_x2_subcall_on_behalf = 4
471 * the calling API wants to use the credentials of the original request
473 * - afb_req_x2_subcall_api_session = 8
475 * the calling API wants to use its session instead of the one of the
478 * @see also 'afb_req_subcall_sync'
480 void afb_req_subcall(
484 struct json_object *args,
488 struct json_object *object,
495 ### afb_req_subcall_sync
499 * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
500 * This call is made in the context of the request 'req'.
501 * This call is synchronous, it waits untill completion of the request.
502 * It returns 0 on success or a negative value on error answer.
504 * For convenience, the function calls 'json_object_put' for 'args'.
505 * Thus, in the case where 'args' should remain available after
506 * the function returns, the function 'json_object_get' shall be used.
509 * - 'afb_req_subcall_req' that is convenient to keep request alive automatically.
510 * - 'afb_req_subcall' that doesn't keep request alive automatically.
512 * @param req The request
513 * @param api The api name of the method to call
514 * @param verb The verb name of the method to call
515 * @param args The arguments to pass to the method
516 * @param flags The bit field of flags for the subcall as defined by @ref afb_req_subcall_flags
517 * @param object a pointer where the replied JSON object is stored must be freed using @ref json_object_put (can be NULL)
518 * @param error a pointer where a copy of the replied error is stored must be freed using @ref free (can be NULL)
519 * @param info a pointer where a copy of the replied info is stored must be freed using @ref free (can be NULL)
521 * @return 0 in case of success or -1 in case of error
523 int afb_req_subcall_sync(
527 struct json_object *args,
529 struct json_object **object,
536 ### afb_req_subscribe
540 * Establishes for the client link identified by 'req' a subscription
543 * Establishing subscription MUST be called BEFORE replying to the request.
545 * @param req the request
546 * @param event the event to subscribe
548 * @return 0 in case of successful subscription or -1 in case of error.
550 int afb_req_subscribe(
555 ### afb_req_unsubscribe
559 * Revokes the subscription established to the 'event' for the client
560 * link identified by 'req'.
561 * Returns 0 in case of successful subscription or -1 in case of error.
563 * Revoking subscription MUST be called BEFORE replying to the request.
565 * @param req the request
566 * @param event the event to revoke
568 * @return 0 in case of successful subscription or -1 in case of error.
570 int afb_req_unsubscribe(
581 * Manage the pointer stored by the binding for the client session of 'req'.
583 * If no previous pointer is stored or if 'replace' is not zero, a new value
584 * is generated using the function 'create_context' called with the 'closure'.
585 * If 'create_context' is NULL the generated value is 'closure'.
587 * When a value is created, the function 'free_context' is recorded and will
588 * be called (with the created value as argument) to free the created value when
589 * it is not more used.
591 * This function is atomic: it ensures that 2 threads will not race together.
593 * @param req the request
594 * @param replace if not zero an existing value is replaced
595 * @param create_context the creation function or NULL
596 * @param free_context the destroying function or NULL
597 * @param closure the closure to the creation function
599 * @return the stored value
601 void *afb_req_context(
604 void *(*create_context)(void *closure),
605 void (*free_context)(void*),
609 ### afb_req_context_get
613 * Gets the pointer stored by the binding for the session of 'req'.
614 * When the binding has not yet recorded a pointer, NULL is returned.
616 * Shortcut for: afb_req_context(req, 0, NULL, NULL, NULL)
618 * @param req the request
620 * @return the previously stored value
622 void *afb_req_context_get(
626 ### afb_req_context_set
630 * Stores for the binding the pointer 'context' to the session of 'req'.
631 * The function 'free_context' will be called when the session is closed
632 * or if binding stores an other pointer.
634 * Shortcut for: afb_req_context(req, 1, NULL, free_context, context)
637 * @param req the request
638 * @param context the context value to store
639 * @param free_context the cleaning function for the stored context (can be NULL)
641 void afb_req_context_set(
644 void (*free_context)(void*));
647 ### afb_req_context_clear
651 * Frees the pointer stored by the binding for the session of 'req'
652 * and sets it to NULL.
654 * Shortcut for: afb_req_context_set(req, NULL, NULL)
656 * @param req the request
658 void afb_req_context_clear(
662 ### afb_req_session_close
666 * Closes the session associated with 'req'
667 * and delete all associated contexts.
669 * @param req the request
671 void afb_req_session_close(
675 ### afb_req_session_set_LOA
679 * Sets the level of assurance of the session of 'req'
680 * to 'level'. The effect of this function is subject of
683 * @param req the request
684 * @param level of assurance from 0 to 7
686 * @return 0 on success or -1 if failed.
688 int afb_req_session_set_LOA(
693 ## Credential/client functions
695 ### afb_req_has_permission
699 * Check whether the 'permission' is granted or not to the client
700 * identified by 'req'.
702 * @param req the request
703 * @param permission string to check
705 * @return 1 if the permission is granted or 0 otherwise.
707 int afb_req_has_permission(
709 const char *permission);
712 ### afb_req_get_application_id
716 * Get the application identifier of the client application for the
719 * Returns the application identifier or NULL when the application
720 * can not be identified.
722 * The returned value if not NULL must be freed by the caller
724 * @param req the request
726 * @return the string for the application id of the client MUST BE FREED
728 char *afb_req_get_application_id(
736 * Get the user identifier (UID) of the client for the
739 * @param req the request
741 * @return -1 when the application can not be identified or the unix uid.
748 ### afb_req_get_client_info
752 * Get informations about the client of the
755 * Returns an object with client informations:
757 * "pid": int, "uid": int, "gid": int,
758 * "label": string, "id": string, "user": string,
759 * "uuid": string, "LOA": int
762 * If some of this information can't be computed, the field of the return
763 * object will not be set at all.
765 * @param req the request
767 * @return a JSON object that must be freed using @ref json_object_put
769 struct json_object *afb_req_get_client_info(
775 ### afb_req_subcall_legacy
779 * @deprecated use @ref afb_req_subcall
781 * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
782 * This call is made in the context of the request 'req'.
783 * On completion, the function 'callback' is invoked with the
784 * 'closure' given at call and two other parameters: 'iserror' and 'result'.
785 * 'status' is 0 on success or negative when on an error reply.
786 * 'result' is the json object of the reply, you must not call json_object_put
789 * For convenience, the function calls 'json_object_put' for 'args'.
790 * Thus, in the case where 'args' should remain available after
791 * the function returns, the function 'json_object_get' shall be used.
793 * @param req the request
794 * @param api the name of the api to call
795 * @param verb the name of the verb to call
796 * @param args the arguments of the call as a JSON object
797 * @param callback the call back that will receive the reply
798 * @param closure the closure passed back to the callback
800 * @see afb_req_subcall
801 * @see afb_req_subcall_sync
803 void afb_req_subcall_legacy(
807 struct json_object *args,
811 struct json_object *result,
816 ### afb_req_subcall_sync_legacy
820 * @deprecated use @ref afb_req_subcall_sync
822 * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
823 * This call is made in the context of the request 'req'.
824 * This call is synchronous, it waits until completion of the request.
825 * It returns 0 on success or a negative value on error answer.
826 * The object pointed by 'result' is filled and must be released by the caller
827 * after its use by calling 'json_object_put'.
829 * For convenience, the function calls 'json_object_put' for 'args'.
830 * Thus, in the case where 'args' should remain available after
831 * the function returns, the function 'json_object_get' shall be used.
833 * @param req the request
834 * @param api the name of the api to call
835 * @param verb the name of the verb to call
836 * @param args the arguments of the call as a JSON object
837 * @param result the pointer to the JSON object pointer that will receive the result
839 * @return 0 on success or a negative value on error answer.
841 * @see afb_req_subcall
842 * @see afb_req_subcall_sync
844 int afb_req_subcall_sync_legacy(
848 struct json_object *args,
849 struct json_object **result);