1 Functions of class **afb_req_t**
2 ============================
10 * Checks whether the request 'req' is valid or not.
12 * @param req the request to check
14 * @return 0 if not valid or 1 if valid.
24 * Retrieves the api that serves the request
26 * @param req the request whose serving api is queried
28 * @return the api serving the request
30 afb_api_t afb_req_get_api(
34 ### afb_req_get_vcbdata
38 * Retrieves the callback data of the verb. This callback data is set
39 * when the verb is created.
41 * @param req whose verb vcbdata is queried
43 * @return the callback data attached to the verb description
45 void *afb_req_get_vcbdata(
49 ### afb_req_get_called_api
53 * Retrieve the name of the called api.
55 * @param req the request
57 * @return the name of the called api
59 * @see afb_api_new_api
60 * @see afb_api_add_alias
62 const char *afb_req_get_called_api(
66 ### afb_req_get_called_verb
70 * Retrieve the name of the called verb
72 * @param req the request
74 * @return the name of the called verb
76 const char *afb_req_get_called_verb(
84 * Increments the count of references of 'req'.
86 * @param req the request
88 * @return returns the request req
90 afb_req_t*afb_req_addref(
98 * Decrement the count of references of 'req'.
100 * @param req the request
109 ### afb_req_wants_log_level
113 * Is the log message of 'level (as defined for syslog) required for the
116 * @param req the request
117 * @param level the level to check as defined for syslog:
119 * EMERGENCY 0 System is unusable
120 * ALERT 1 Action must be taken immediately
121 * CRITICAL 2 Critical conditions
122 * ERROR 3 Error conditions
123 * WARNING 4 Warning conditions
124 * NOTICE 5 Normal but significant condition
125 * INFO 6 Informational
126 * DEBUG 7 Debug-level messages
128 * @return 0 if not required or a value not null if required
132 int afb_req_wants_log_level(
141 * Send associated to 'req' a message described by 'fmt' and its 'args'
142 * to the journal for the verbosity 'level'.
144 * 'file', 'line' and 'func' are indicators of position of the code in source files
145 * (see macros __FILE__, __LINE__ and __func__).
147 * 'level' is defined by syslog standard:
148 * EMERGENCY 0 System is unusable
149 * ALERT 1 Action must be taken immediately
150 * CRITICAL 2 Critical conditions
151 * ERROR 3 Error conditions
152 * WARNING 4 Warning conditions
153 * NOTICE 5 Normal but significant condition
154 * INFO 6 Informational
155 * DEBUG 7 Debug-level messages
157 * @param req the request
158 * @param level the level of the message
159 * @param file the source filename that emits the message or NULL
160 * @param line the line number in the source filename that emits the message
161 * @param func the name of the function that emits the message or NULL
162 * @param fmt the message format as for printf
163 * @param args the arguments to the format
166 * @see afb_req_verbose
168 void afb_req_vverbose(
170 int level, const char *file,
181 * Send associated to 'req' a message described by 'fmt' and following parameters
182 * to the journal for the verbosity 'level'.
184 * 'file', 'line' and 'func' are indicators of position of the code in source files
185 * (see macros __FILE__, __LINE__ and __func__).
187 * 'level' is defined by syslog standard:
188 * EMERGENCY 0 System is unusable
189 * ALERT 1 Action must be taken immediately
190 * CRITICAL 2 Critical conditions
191 * ERROR 3 Error conditions
192 * WARNING 4 Warning conditions
193 * NOTICE 5 Normal but significant condition
194 * INFO 6 Informational
195 * DEBUG 7 Debug-level messages
197 * @param req the request
198 * @param level the level of the message
199 * @param file the source filename that emits the message or NULL
200 * @param line the line number in the source filename that emits the message
201 * @param func the name of the function that emits the message or NULL
202 * @param fmt the message format as for printf
203 * @param ... the arguments of the format 'fmt'
207 void afb_req_verbose(
209 int level, const char *file,
216 ## Arguments/parameters function
222 * Gets from the request 'req' the argument of 'name'.
224 * Returns a PLAIN structure of type 'struct afb_arg'.
226 * When the argument of 'name' is not found, all fields of result are set to NULL.
228 * When the argument of 'name' is found, the fields are filled,
229 * in particular, the field 'result.name' is set to 'name'.
231 * There is a special name value: the empty string.
232 * The argument of name "" is defined only if the request was made using
233 * an HTTP POST of Content-Type "application/json". In that case, the
234 * argument of name "" receives the value of the body of the HTTP request.
236 * @param req the request
237 * @param name the name of the argument to get
239 * @return a structure describing the retrieved argument for the request
244 struct afb_arg afb_req_get(
253 * Gets from the request 'req' the string value of the argument of 'name'.
254 * Returns NULL if when there is no argument of 'name'.
255 * Returns the value of the argument of 'name' otherwise.
257 * Shortcut for: afb_req_get(req, name).value
259 * @param req the request
260 * @param name the name of the argument's value to get
262 * @return the value as a string or NULL
267 const char *afb_req_value(
276 * Gets from the request 'req' the path for file attached to the argument of 'name'.
277 * Returns NULL if when there is no argument of 'name' or when there is no file.
278 * Returns the path of the argument of 'name' otherwise.
280 * Shortcut for: afb_req_get(req, name).path
282 * @param req the request
283 * @param name the name of the argument's path to get
285 * @return the path if any or NULL
290 const char *afb_req_path(
299 * Gets from the request 'req' the json object hashing the arguments.
301 * The returned object must not be released using 'json_object_put'.
303 * @param req the request
305 * @return the JSON object of the query
311 struct json_object *afb_req_json(
317 The functions **success** and **fail** are still supported.
318 These functions are now implemented as the following macros:
321 #define afb_req_success(r,o,i) afb_req_reply(r,o,NULL,i)
322 #define afb_req_success_f(r,o,...) afb_req_reply_f(r,o,NULL,__VA_ARGS__)
323 #define afb_req_success_v(r,o,f,v) afb_req_reply_v(r,o,NULL,f,v)
324 #define afb_req_fail(r,e,i) afb_req_reply(r,NULL,e,i)
325 #define afb_req_fail_f(r,e,...) afb_req_reply_f(r,NULL,e,__VA_ARGS__)
326 #define afb_req_fail_v(r,e,f,v) afb_req_reply_v(r,NULL,e,f,v)
334 * Sends a reply to the request 'req'.
336 * The status of the reply is set to 'error' (that must be NULL on success).
337 * Its send the object 'obj' (can be NULL) with an
338 * informational comment 'info (can also be NULL).
340 * For convenience, the function calls 'json_object_put' for 'obj'.
341 * Thus, in the case where 'obj' should remain available after
342 * the function returns, the function 'json_object_get' shall be used.
344 * @param req the request
345 * @param obj the replied object or NULL
346 * @param error the error message if it is a reply error or NULL
347 * @param info an informative text or NULL
349 * @see afb_req_reply_v
350 * @see afb_req_reply_f
354 struct json_object *obj,
363 * Same as 'afb_req_reply_f' but the arguments to the format 'info'
364 * are given as a variable argument list instance.
366 * For convenience, the function calls 'json_object_put' for 'obj'.
367 * Thus, in the case where 'obj' should remain available after
368 * the function returns, the function 'json_object_get' shall be used.
370 * @param req the request
371 * @param obj the replied object or NULL
372 * @param error the error message if it is a reply error or NULL
373 * @param info an informative text containing a format as for vprintf
374 * @param args the va_list of arguments to the format as for vprintf
377 * @see afb_req_reply_f
380 void afb_req_reply_v(
382 struct json_object *obj,
392 * Same as 'afb_req_reply' but the 'info' is a formatting
393 * string followed by arguments.
395 * For convenience, the function calls 'json_object_put' for 'obj'.
396 * Thus, in the case where 'obj' should remain available after
397 * the function returns, the function 'json_object_get' shall be used.
399 * @param req the request
400 * @param obj the replied object or NULL
401 * @param error the error message if it is a reply error or NULL
402 * @param info an informative text containing a format as for printf
403 * @param ... the arguments to the format as for printf
406 * @see afb_req_reply_v
409 void afb_req_reply_f(
411 struct json_object *obj,
425 * Calls the 'verb' of the 'api' with the arguments 'args' and 'verb' in the name of the binding.
426 * The result of the call is delivered to the 'callback' function with the 'callback_closure'.
428 * For convenience, the function calls 'json_object_put' for 'args'.
429 * Thus, in the case where 'args' should remain available after
430 * the function returns, the function 'json_object_get' shall be used.
432 * The 'callback' receives 5 arguments:
433 * 1. 'closure' the user defined closure pointer 'closure',
434 * 2. 'object' a JSON object returned (can be NULL)
435 * 3. 'error' a string not NULL in case of error
436 * 4. 'info' a string handling some info (can be NULL)
439 * @param req The request
440 * @param api The api name of the method to call
441 * @param verb The verb name of the method to call
442 * @param args The arguments to pass to the method
443 * @param flags The bit field of flags for the subcall as defined by @ref afb_req_subcall_flags_t
444 * @param callback The to call on completion
445 * @param closure The closure to pass to the callback
447 * The flags are any combination of the following values:
449 * - afb_req_x2_subcall_catch_events = 1
451 * the calling API wants to receive the events from subscription
453 * - afb_req_x2_subcall_pass_events = 2
455 * the original request will receive the events from subscription
457 * - afb_req_x2_subcall_on_behalf = 4
459 * the calling API wants to use the credentials of the original request
461 * - afb_req_x2_subcall_api_session = 8
463 * the calling API wants to use its session instead of the one of the
466 * @see also 'afb_req_subcall_sync'
468 void afb_req_subcall(
472 struct json_object *args,
476 struct json_object *object,
483 ### afb_req_subcall_sync
487 * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
488 * This call is made in the context of the request 'req'.
489 * This call is synchronous, it waits untill completion of the request.
490 * It returns 0 on success or a negative value on error answer.
492 * For convenience, the function calls 'json_object_put' for 'args'.
493 * Thus, in the case where 'args' should remain available after
494 * the function returns, the function 'json_object_get' shall be used.
497 * - 'afb_req_subcall_req' that is convenient to keep request alive automatically.
498 * - 'afb_req_subcall' that doesn't keep request alive automatically.
500 * @param req The request
501 * @param api The api name of the method to call
502 * @param verb The verb name of the method to call
503 * @param args The arguments to pass to the method
504 * @param flags The bit field of flags for the subcall as defined by @ref afb_req_subcall_flags
505 * @param object a pointer where the replied JSON object is stored must be freed using @ref json_object_put (can be NULL)
506 * @param error a pointer where a copy of the replied error is stored must be freed using @ref free (can be NULL)
507 * @param info a pointer where a copy of the replied info is stored must be freed using @ref free (can be NULL)
509 * @return 0 in case of success or -1 in case of error
511 int afb_req_subcall_sync(
515 struct json_object *args,
517 struct json_object **object,
524 ### afb_req_subscribe
528 * Establishes for the client link identified by 'req' a subscription
531 * Establishing subscription MUST be called BEFORE replying to the request.
533 * @param req the request
534 * @param event the event to subscribe
536 * @return 0 in case of successful subscription or -1 in case of error.
538 int afb_req_subscribe(
543 ### afb_req_unsubscribe
547 * Revokes the subscription established to the 'event' for the client
548 * link identified by 'req'.
549 * Returns 0 in case of successful subscription or -1 in case of error.
551 * Revoking subscription MUST be called BEFORE replying to the request.
553 * @param req the request
554 * @param event the event to revoke
556 * @return 0 in case of successful subscription or -1 in case of error.
558 int afb_req_unsubscribe(
569 * Manage the pointer stored by the binding for the client session of 'req'.
571 * If no previous pointer is stored or if 'replace' is not zero, a new value
572 * is generated using the function 'create_context' called with the 'closure'.
573 * If 'create_context' is NULL the generated value is 'closure'.
575 * When a value is created, the function 'free_context' is recorded and will
576 * be called (with the created value as argument) to free the created value when
577 * it is not more used.
579 * This function is atomic: it ensures that 2 threads will not race together.
581 * @param req the request
582 * @param replace if not zero an existing value is replaced
583 * @param create_context the creation function or NULL
584 * @param free_context the destroying function or NULL
585 * @param closure the closure to the creation function
587 * @return the stored value
589 void *afb_req_context(
592 void *(*create_context)(void *closure),
593 void (*free_context)(void*),
597 ### afb_req_context_get
601 * Gets the pointer stored by the binding for the session of 'req'.
602 * When the binding has not yet recorded a pointer, NULL is returned.
604 * Shortcut for: afb_req_context(req, 0, NULL, NULL, NULL)
606 * @param req the request
608 * @return the previously stored value
610 void *afb_req_context_get(
614 ### afb_req_context_set
618 * Stores for the binding the pointer 'context' to the session of 'req'.
619 * The function 'free_context' will be called when the session is closed
620 * or if binding stores an other pointer.
622 * Shortcut for: afb_req_context(req, 1, NULL, free_context, context)
625 * @param req the request
626 * @param context the context value to store
627 * @param free_context the cleaning function for the stored context (can be NULL)
629 void afb_req_context_set(
632 void (*free_context)(void*));
635 ### afb_req_context_clear
639 * Frees the pointer stored by the binding for the session of 'req'
640 * and sets it to NULL.
642 * Shortcut for: afb_req_context_set(req, NULL, NULL)
644 * @param req the request
646 void afb_req_context_clear(
650 ### afb_req_session_close
654 * Closes the session associated with 'req'
655 * and delete all associated contexts.
657 * @param req the request
659 void afb_req_session_close(
663 ### afb_req_session_set_LOA
667 * Sets the level of assurance of the session of 'req'
668 * to 'level'. The effect of this function is subject of
671 * @param req the request
672 * @param level of assurance from 0 to 7
674 * @return 0 on success or -1 if failed.
676 int afb_req_session_set_LOA(
681 ## Credential/client functions
683 ### afb_req_has_permission
687 * Check whether the 'permission' is granted or not to the client
688 * identified by 'req'.
690 * @param req the request
691 * @param permission string to check
693 * @return 1 if the permission is granted or 0 otherwise.
695 int afb_req_has_permission(
697 const char *permission);
700 ### afb_req_get_application_id
704 * Get the application identifier of the client application for the
707 * Returns the application identifier or NULL when the application
708 * can not be identified.
710 * The returned value if not NULL must be freed by the caller
712 * @param req the request
714 * @return the string for the application id of the client MUST BE FREED
716 char *afb_req_get_application_id(
724 * Get the user identifier (UID) of the client for the
727 * @param req the request
729 * @return -1 when the application can not be identified or the unix uid.
736 ### afb_req_get_client_info
740 * Get informations about the client of the
743 * Returns an object with client informations:
745 * "pid": int, "uid": int, "gid": int,
746 * "label": string, "id": string, "user": string,
747 * "uuid": string, "LOA": int
750 * If some of this information can't be computed, the field of the return
751 * object will not be set at all.
753 * @param req the request
755 * @return a JSON object that must be freed using @ref json_object_put
757 struct json_object *afb_req_get_client_info(
763 ### afb_req_subcall_legacy
767 * @deprecated use @ref afb_req_subcall
769 * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
770 * This call is made in the context of the request 'req'.
771 * On completion, the function 'callback' is invoked with the
772 * 'closure' given at call and two other parameters: 'iserror' and 'result'.
773 * 'status' is 0 on success or negative when on an error reply.
774 * 'result' is the json object of the reply, you must not call json_object_put
777 * For convenience, the function calls 'json_object_put' for 'args'.
778 * Thus, in the case where 'args' should remain available after
779 * the function returns, the function 'json_object_get' shall be used.
781 * @param req the request
782 * @param api the name of the api to call
783 * @param verb the name of the verb to call
784 * @param args the arguments of the call as a JSON object
785 * @param callback the call back that will receive the reply
786 * @param closure the closure passed back to the callback
788 * @see afb_req_subcall
789 * @see afb_req_subcall_sync
791 void afb_req_subcall_legacy(
795 struct json_object *args,
799 struct json_object *result,
804 ### afb_req_subcall_sync_legacy
808 * @deprecated use @ref afb_req_subcall_sync
810 * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
811 * This call is made in the context of the request 'req'.
812 * This call is synchronous, it waits until completion of the request.
813 * It returns 0 on success or a negative value on error answer.
814 * The object pointed by 'result' is filled and must be released by the caller
815 * after its use by calling 'json_object_put'.
817 * For convenience, the function calls 'json_object_put' for 'args'.
818 * Thus, in the case where 'args' should remain available after
819 * the function returns, the function 'json_object_get' shall be used.
821 * @param req the request
822 * @param api the name of the api to call
823 * @param verb the name of the verb to call
824 * @param args the arguments of the call as a JSON object
825 * @param result the pointer to the JSON object pointer that will receive the result
827 * @return 0 on success or a negative value on error answer.
829 * @see afb_req_subcall
830 * @see afb_req_subcall_sync
832 int afb_req_subcall_sync_legacy(
836 struct json_object *args,
837 struct json_object **result);