Functions of class afb_req

Function afb_req_logmask

/**
 * Get the logmask of the 'req'.
 *
 * @param req the req whose logmask is to be returned
 *
 * @return logmask of the req.
 */
int
afb_req_logmask(
	afb_req_t req
);

Function afb_req_wants_log_level

/**
 * Is the log message of 'level (as defined for syslog) required for the
 * request 'req'?
 *
 * @param req the request
 * @param level the level to check as defined for syslog:
 *
 *      EMERGENCY         0        System is unusable
 *      ALERT             1        Action must be taken immediately
 *      CRITICAL          2        Critical conditions
 *      ERROR             3        Error conditions
 *      WARNING           4        Warning conditions
 *      NOTICE            5        Normal but significant condition
 *      INFO              6        Informational
 *      DEBUG             7        Debug-level messages
 *
 * @return 0 if not required or a value not null if required
 *
 * @see syslog
 */
int
afb_req_wants_log_level(
	afb_req_t req,
	int level
);

Function afb_req_is_valid

/**
 * Checks whether the request 'req' is valid or not.
 *
 * @param req the request to check
 *
 * @return 0 if not valid or 1 if valid.
 */
int
afb_req_is_valid(
	afb_req_t req
);

Function afb_req_get_api

/**
 * Retrieves the api that serves the request
 *
 * @param req the request whose serving api is queried
 *
 * @return the api serving the request
 */
afb_api_t
afb_req_get_api(
	afb_req_t req
);

Function afb_req_get_vcbdata

/**
 * Retrieves the callback data of the verb. This callback data is set
 * when the verb is created.
 *
 * @param req whose verb vcbdata is queried
 *
 * @return the callback data attached to the verb description
 */
void *
afb_req_get_vcbdata(
	afb_req_t req
);

Function afb_req_get_called_api

/**
 * Retrieve the name of the called api.
 *
 * @param req the request
 *
 * @return the name of the called api
 *
 * @see afb_alias_api
 */
const char *
afb_req_get_called_api(
	afb_req_t req
);

Function afb_req_get_called_verb

/**
 * Retrieve the name of the called verb
 *
 * @param req the request
 *
 * @return the name of the called verb
 */
const char *
afb_req_get_called_verb(
	afb_req_t req
);

Function afb_req_addref

/**
 * Increments the count of references of 'req'.
 *
 * @param req the request
 *
 * @return returns the request req
 */
afb_req_t
afb_req_addref(
	afb_req_t req
);

Function afb_req_unref

/**
 * Decrement the count of references of 'req'.
 *
 * @param req the request
 */
void
afb_req_unref(
	afb_req_t req
);

Function afb_req_vverbose

/**
 * Send associated to 'req' a message described by 'fmt' and its 'args'
 * to the journal for the verbosity 'level'.
 *
 * 'file', 'line' and 'func' are indicators of position of the code in source files
 * (see macros __FILE__, __LINE__ and __func__).
 *
 * 'level' is defined by syslog standard:
 *      EMERGENCY         0        System is unusable
 *      ALERT             1        Action must be taken immediately
 *      CRITICAL          2        Critical conditions
 *      ERROR             3        Error conditions
 *      WARNING           4        Warning conditions
 *      NOTICE            5        Normal but significant condition
 *      INFO              6        Informational
 *      DEBUG             7        Debug-level messages
 *
 * @param req the request
 * @param level the level of the message
 * @param file the source filename that emits the message or NULL
 * @param line the line number in the source filename that emits the message
 * @param func the name of the function that emits the message or NULL
 * @param fmt the message format as for printf
 * @param args the arguments to the format 'fmt'
 *
 * @see printf
 * @see afb_req_verbose
 */
void
afb_req_vverbose(
	afb_req_t req,
	int level, const char *file,
	int line,
	const char * func,
	const char *fmt,
	va_list args
);

Function afb_req_verbose

/**
 * Send associated to 'req' a message described by 'fmt' and following parameters
 * to the journal for the verbosity 'level'.
 *
 * 'file', 'line' and 'func' are indicators of position of the code in source files
 * (see macros __FILE__, __LINE__ and __func__).
 *
 * 'level' is defined by syslog standard:
 *      EMERGENCY         0        System is unusable
 *      ALERT             1        Action must be taken immediately
 *      CRITICAL          2        Critical conditions
 *      ERROR             3        Error conditions
 *      WARNING           4        Warning conditions
 *      NOTICE            5        Normal but significant condition
 *      INFO              6        Informational
 *      DEBUG             7        Debug-level messages
 *
 * @param req the request
 * @param level the level of the message
 * @param file the source filename that emits the message or NULL
 * @param line the line number in the source filename that emits the message
 * @param func the name of the function that emits the message or NULL
 * @param fmt the message format as for printf
 * @param ... the arguments of the format 'fmt'
 *
 * @see printf
 * @see afb_req_vverbose
 */
void
afb_req_verbose(
	afb_req_t req,
	int level, const char *file,
	int line,
	const char * func,
	const char *fmt,
	...
);

Function afb_req_context

/**
 * Manage the pointer stored by the binding for the client session of 'req'.
 *
 * If no previous pointer is stored or if 'replace' is not zero, a new value
 * is generated using the function 'create_context' called with the 'closure'.
 * If 'create_context' is NULL the generated value is 'closure'.
 *
 * When a value is created, the function 'free_context' is recorded and will
 * be called (with the created value as argument) to free the created value when
 * it is not more used.
 *
 * This function is atomic: it ensures that 2 threads will not race together.
 *
 * @param req the request
 * @param replace if not zero an existing value is replaced
 * @param create_context the creation function or NULL
 * @param free_context the destroying function or NULL
 * @param closure the closure to the creation function
 *
 * @return the stored value
 */
void *
afb_req_context(
	afb_req_t req,
	int replace,
	void *(*create_context)(void *closure),
	void (*free_context)(void*),
	void *closure
);

Function afb_req_context_get

/**
 * Gets the pointer stored by the binding for the session of 'req'.
 * When the binding has not yet recorded a pointer, NULL is returned.
 *
 * Shortcut for: afb_req_context(req, 0, NULL, NULL, NULL)
 *
 * @param req the request
 *
 * @return the previously stored value
 */
void *
afb_req_context_get(
	afb_req_t req
);

Function afb_req_context_set

/**
 * Stores for the binding the pointer 'context' to the session of 'req'.
 * The function 'free_context' will be called when the session is closed
 * or if binding stores an other pointer.
 *
 * Shortcut for: afb_req_context(req, 1, NULL, free_context, context)
 *
 *
 * @param req the request
 * @param context the context value to store
 * @param free_context the cleaning function for the stored context (can be NULL)
 */
void
afb_req_context_set(
	afb_req_t req,
	void *context,
	void (*free_context)(void*)
);

Function afb_req_context_clear

/**
 * Frees the pointer stored by the binding for the session of 'req'
 * and sets it to NULL.
 *
 * Shortcut for: afb_req_context_set(req, NULL, NULL)
 *
 * @param req the request
 */
void
afb_req_context_clear(
	afb_req_t req
);

Function afb_req_session_close

/**
 * Closes the session associated with 'req'
 * and delete all associated contexts.
 *
 * @param req the request
 */
void
afb_req_session_close(
	afb_req_t req
);

Function afb_req_session_set_LOA

/**
 * Sets the level of assurance of the session of 'req'
 * to 'level'. The effect of this function is subject of
 * security policies.
 *
 * @param req the request
 * @param level of assurance from 0 to 7
 *
 * @return 0 on success or -1 if failed.
 */
int
afb_req_session_set_LOA(
	afb_req_t req,
	unsigned level
);

Function afb_req_session_get_LOA

/**
 * Gets the current level of assurance of the session of 'req'.
 *
 * @param req the request
 *
 * @return the current LOA, a value of 0 to 7
 */
unsigned
afb_req_session_get_LOA(
	afb_req_t req
);

Function afb_req_subscribe

/**
 * Establishes for the client link identified by 'req' a subscription
 * to the 'event'.
 *
 * Establishing subscription MUST be called BEFORE replying to the request.
 *
 * @param req the request
 * @param event the event to subscribe
 *
 * @return 0 in case of successful subscription or -1 in case of error.
 */
int
afb_req_subscribe(
	afb_req_t req,
	afb_event_t event
);

Function afb_req_unsubscribe

/**
 * Revokes the subscription established to the 'event' for the client
 * link identified by 'req'.
 * Returns 0 in case of successful subscription or -1 in case of error.
 *
 * Revoking subscription MUST be called BEFORE replying to the request.
 *
 * @param req the request
 * @param event the event to revoke
 *
 * @return 0 in case of successful subscription or -1 in case of error.
 */
int
afb_req_unsubscribe(
	afb_req_t req,
	afb_event_t event
);

Function afb_req_check_permission

/**
 * Check whether the 'permission' is granted or not to the client
 * identified by 'req'.
 *
 * @param req the request
 * @param permission string to check
 * @param callback that receive the result of the check
 * @param closure closure for the callback
 */
void
afb_req_check_permission(
	afb_req_t req,
	const char *permission,
	afb_check_callback_t callback,
	void *closure
);

Function afb_req_get_client_info

/**
 * Get informations about the client of the
 * request 'req'.
 *
 * Returns an object with client informations:
 *  {
 *    "pid": int, "uid": int, "gid": int,
 *    "label": string, "id": string, "user": string,
 *    "uuid": string, "LOA": int
 *  }
 *
 * If some of this information can't be computed, the field of the return
 * object will not be set at all.
 *
 * @param req the request
 *
 * @return a JSON object that must be freed using @ref json_object_put
 */
struct json_object *
afb_req_get_client_info(
	afb_req_t req
);

Function afb_req_parameters

/**
 * Get the parameters of the request
 *
 * @param req      the request
 * @param params   pointer where to store the address to the array of data parameters
 *                 (can be NULL)
 *
 * @return the count of parameters
 */
unsigned
afb_req_parameters(
	afb_req_t req,
	afb_data_t const **params
);

Function afb_req_reply

/**
 * Reply to the request
 *
 * NOTE: For convenience, the function calls 'afb_data_unref' for items of
 * 'replies'. Thus, in the case where some data of 'replies' should remain
 * available after the function returns, the function 'afb_data_addref'
 * shall be used on such items before the call.
 *
 * @param req      the request
 * @param status   an integer status
 * @param nreplies count of replied data
 * @param replies  array of the replied data if any (can be NULL when nparams is 0)
 */
void
afb_req_reply(
	afb_req_t req,
	int status,
	unsigned nreplies,
	afb_data_t const *replies
);

Function afb_req_subcall

/**
 * Calls the 'verb' of the 'api' with the parameters 'params' and 'verb' in the name of the binding.
 * The result of the call is delivered to the 'callback' function with the 'callback_closure'.
 *
 * NOTE: For convenience, the function calls 'afb_data_unref' for items of
 * 'params'. Thus, in the case where some data of 'params' should remain
 * available after the function returns, the function 'afb_data_addref'
 * shall be used on such items before the call.
 *
 * The 'callback' receives 5 arguments:
 *  1. 'closure'  the user defined closure pointer 'closure',
 *  2. 'status'   the replied status
 *  3. 'nreplies' the count of replied data
 *  4. 'replies'  the array of replied data
 *  5. 'req'      the req
 *
 * NOTE: For convenience, the data received by the callback function in the
 * array 'replies' are released automatically after the return of the
 * callback. Thus, in the case where some data of 'replies' should remain
 * available after the end of the callback, the function 'afb_data_addref'
 * shall be used on such items to keep them alive after end of callback.
 *
 * @param req      The request
 * @param apiname  The api name of the method to call
 * @param verbname The verb name of the method to call
 * @param nparams  count of parameter data
 * @param params   array of parameter data (can be NULL when nparams is zero)
 * @param flags    The bit field of flags for the subcall as defined by @ref afb_req_subcall_flags
 * @param callback The to call on completion
 * @param closure  The closure to pass to the callback
 *
 * @see also 'afb_req_subcall_sync'
 */
void
afb_req_subcall(
	afb_req_t req,
	const char *apiname,
	const char *verbname,
	unsigned nparams,
	afb_data_t const params[],
	int flags,
	afb_subcall_callback_t callback,
	void *closure
);

Function afb_req_subcall_sync

/**
 * Makes a call to the method of name 'api' / 'verb' with the parameters 'params'.
 * This call is made in the context of the request 'req'.
 * This call is synchronous, it waits untill completion of the request.
 * It returns 0 on success or a negative value on error answer.
 *
 * At call, the value pointed by nreplies must be the count of data
 * of the array replies. The values in replies are not used at call and
 * can be anything of anyvalue, the caller does not care or use it.
 *
 * NOTE: For convenience, the function calls 'afb_data_unref' for items of
 * 'params'. Thus, in the case where some data of 'params' should remain
 * available after the function returns, the function 'afb_data_addref'
 * shall be used on such items before the call.
 *
 * At return, status receives the reply status, nreplies receives the count
 * of value replied and stored in the array replies.
 *
 * NOTE: The data returned by the call in the array replies MUST be released
 * by the caller using 'afb_data_unref' or 'afb_data_array_unref'.
 *
 * If the array 'replies' is too small to receive all the replied data, the
 * reply is truncated to the count of 'replies' (indicated by 'nreplies'),
 * the remaining data replied are ignored.
 *
 * @param req      The request
 * @param apiname  The api name of the method to call
 * @param verbname The verb name of the method to call
 * @param nparams  count of parameter data
 * @param params   array of parameter data (can be NULL when nparams is zero)
 * @param flags    The bit field of flags for the subcall as defined by @ref afb_req_subcall_flags
 * @param status   the replied status of the call
 * @param nreplies at call, size of params, at return, count of data in replies
 * @param replies  where to store the replied data
 *
 * @return 0 in case of success or -1 in case of error
 */
int
afb_req_subcall_sync(
	afb_req_t req,
	const char *apiname,
	const char *verbname,
	unsigned nparams,
	afb_data_t const params[],
	int flags,
	int *status,
	unsigned *nreplies,
	afb_data_t replies[]
);