ValvulaRequestRegistry* valvula_ctx_register_request_handler ( ValvulaCtx ctx,
const char *  identifier,
ValvulaProcessRequest  process_handler,
int  priority,
int  port,
axlPointer  user_data 

Allows to register a new process handler with the provided priority under the given port.

The process handler is a function that is called every time a request has to be resolved. For that, Valvula's engine uses the port to know if the handler must be called and the priority.

The port is an indication about when the handler should be considered for execution. In the case -1 is provided, then the handler is always considered. In the case a number is provided, then that number is compared with the listener's port where the request was received. If it matches, then it is considered for execution (according to its priority).

You can use the same port or -1 for all your handlers and all handlers will be considered, considering their priority.

The priority value, that can be a value between 1 and 32768, is an indication to Valvula's engine about what handler must be called first. A priority of 1 is higher than 32768, that is, a handler with priority 1 is called first a handler with priority 32768.

ctxThe context where the operation takes place.
identifierThis is a textual string that identifies this handler and provides information about its source. This info is used by the system to now what module or what does this handler (when you use valvulad -s to show stats).
process_handlerThe handler that is going to be registered.
priorityThe priority to give to the handler (between 1 and 32768).
portThe port to restrict the handler or -1 to have it executed in all ports.
user_dataUser defined pointer to be passed to the process_handler when it is called.
A registry pointer that represents the registry of this handler in this context. You can use this reference to remove the handler or query its settings. The function returns NULL in case of a failure while registering the handler.

References valvula_hash_new(), valvula_hash_replace_full(), valvula_mutex_create(), valvula_mutex_lock(), and valvula_mutex_unlock().