ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_type_checker(choices_select, NULL, NULL, APR_HOOK_FIRST);
These modules can use APR_HOOK_FIRST or APR_HOOK_LAST. The values APR_HOOK_REALLY_FIRST and APR_HOOK_REALLY_LAST
are also available, although they are seldom appropriate and may give unexpected behavior. For example, a REALLY_LAST
function may never run if it follows an Apache standard function that never returns DECLINED.
The two NULL values are the predecessors and successors of our function, and they offer fine control. They offer
the opportunity to name other modules explicitly. They are appropriate for closely related modules whose functions,
if both modules are present, must run in a particular order. These arguments take the form of a
NULL-terminated list of modules that must run before or after ours.
static void register_hooks(apr_pool_t *p)
{
static const char * const aszPre[]={ "mod_authz_owner.c", NULL };
ap_hook_auth_checker(check_user_access, aszPre,
NULL, APR_HOOK_MIDDLE);
}
Exporting an Optional Hook
1. APR_DECLARE_EXTERNAL_HOOK(authz_dbd, AP, int, client_login,
(request_rec *r, int code, const char *action))
2. APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(authz_dbd, AP, int, client_login,
(request_rec *r, int code, const char *action),
(r, code, action), OK, DECLINED)
3.there is a call to run the functions registered for the hook in the function implementing.
static int authz_dbd_login(request_rec *r, authz_dbd_cfg *cfg, const char *action)
{
/* code omitted -- perform database login/logout */
if (successful) {
authz_dbd_run_client_login(r, code, action);
}
return code ;
}
Now a module implementing this hook a function straight.
static int client_cookie(request_rec *r, int code, const char *action) {
if (strcmp(action, "login") == 0) {
/* Set authentication token in client session cookie */
}
else if (strcmp(action, "logout") == 0) {
/* Clear session cookie */
}
return OK;
}
static void register_hooks(apr_pool_t *pool) {
APR_OPTIONAL_HOOK(authz_dbd, client_login, client_cookie,
NULL, NULL, APR_HOOK_MIDDLE);
}
We could have implemented this function as a non-optional hook, by replacing the macro
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL with APR_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL from apr_hooks.h.
ap_hook_type_checker(choices_select, NULL, NULL, APR_HOOK_FIRST);
These modules can use APR_HOOK_FIRST or APR_HOOK_LAST. The values APR_HOOK_REALLY_FIRST and APR_HOOK_REALLY_LAST
are also available, although they are seldom appropriate and may give unexpected behavior. For example, a REALLY_LAST
function may never run if it follows an Apache standard function that never returns DECLINED.
The two NULL values are the predecessors and successors of our function, and they offer fine control. They offer
the opportunity to name other modules explicitly. They are appropriate for closely related modules whose functions,
if both modules are present, must run in a particular order. These arguments take the form of a
NULL-terminated list of modules that must run before or after ours.
static void register_hooks(apr_pool_t *p)
{
static const char * const aszPre[]={ "mod_authz_owner.c", NULL };
ap_hook_auth_checker(check_user_access, aszPre,
NULL, APR_HOOK_MIDDLE);
}
Exporting an Optional Hook
1. APR_DECLARE_EXTERNAL_HOOK(authz_dbd, AP, int, client_login,
(request_rec *r, int code, const char *action))
2. APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(authz_dbd, AP, int, client_login,
(request_rec *r, int code, const char *action),
(r, code, action), OK, DECLINED)
3.there is a call to run the functions registered for the hook in the function implementing.
static int authz_dbd_login(request_rec *r, authz_dbd_cfg *cfg, const char *action)
{
/* code omitted -- perform database login/logout */
if (successful) {
authz_dbd_run_client_login(r, code, action);
}
return code ;
}
Now a module implementing this hook a function straight.
static int client_cookie(request_rec *r, int code, const char *action) {
if (strcmp(action, "login") == 0) {
/* Set authentication token in client session cookie */
}
else if (strcmp(action, "logout") == 0) {
/* Clear session cookie */
}
return OK;
}
static void register_hooks(apr_pool_t *pool) {
APR_OPTIONAL_HOOK(authz_dbd, client_login, client_cookie,
NULL, NULL, APR_HOOK_MIDDLE);
}
We could have implemented this function as a non-optional hook, by replacing the macro
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL with APR_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL from apr_hooks.h.