Loading...
Searching...
No Matches
apr_hooks.h
Go to the documentation of this file.
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APR_HOOKS_H
#define APR_HOOKS_H
#include "apu.h"
/* For apr_array_header_t */
#include "apr_tables.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef APR_HOOK_PROBES_ENABLED
#define APR_HOOK_INT_DCL_UD void *ud = NULL
#else
#define APR_HOOK_INT_DCL_UD
#define APR_HOOK_PROBE_ENTRY(ud,ns,name,args)
#define APR_HOOK_PROBE_RETURN(ud,ns,name,rv,args)
#define APR_HOOK_PROBE_INVOKE(ud,ns,name,src,args)
#define APR_HOOK_PROBE_COMPLETE(ud,ns,name,src,rv,args)
#endif
#define APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \
link##_DECLARE(apr_array_header_t *) ns##_hook_get_##name(void)
#define APR_DECLARE_EXTERNAL_HOOK(ns,link,ret,name,args) \
typedef ret ns##_HOOK_##name##_t args; \
link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf, \
const char * const *aszPre, \
const char * const *aszSucc, int nOrder); \
link##_DECLARE(ret) ns##_run_##name args; \
APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name); \
typedef struct ns##_LINK_##name##_t \
{ \
ns##_HOOK_##name##_t *pFunc; \
const char *szName; \
const char * const *aszPredecessors; \
const char * const *aszSuccessors; \
int nOrder; \
} ns##_LINK_##name##_t;
#define APR_HOOK_STRUCT(members) \
static struct { members } _hooks;
#define APR_HOOK_LINK(name) \
apr_array_header_t *link_##name;
#define APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf,const char * const *aszPre, \
const char * const *aszSucc,int nOrder) \
{ \
ns##_LINK_##name##_t *pHook; \
if(!_hooks.link_##name) \
{ \
_hooks.link_##name=apr_array_make(apr_hook_global_pool,1,sizeof(ns##_LINK_##name##_t)); \
apr_hook_sort_register(#name,&_hooks.link_##name); \
} \
pHook=apr_array_push(_hooks.link_##name); \
pHook->pFunc=pf; \
pHook->aszPredecessors=aszPre; \
pHook->aszSuccessors=aszSucc; \
pHook->nOrder=nOrder; \
pHook->szName=apr_hook_debug_current; \
if(apr_hook_debug_enabled) \
apr_hook_debug_show(#name,aszPre,aszSucc); \
} \
APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \
{ \
return _hooks.link_##name; \
}
#define APR_IMPLEMENT_EXTERNAL_HOOK_VOID(ns,link,name,args_decl,args_use) \
APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
link##_DECLARE(void) ns##_run_##name args_decl \
{ \
ns##_LINK_##name##_t *pHook; \
int n; \
APR_HOOK_INT_DCL_UD; \
\
APR_HOOK_PROBE_ENTRY(ud, ns, name, args_use); \
\
if(_hooks.link_##name) \
{ \
pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
{ \
APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName, args_use); \
pHook[n].pFunc args_use; \
APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, 0, args_use); \
} \
} \
\
APR_HOOK_PROBE_RETURN(ud, ns, name, 0, args_use); \
\
}
/* FIXME: note that this returns ok when nothing is run. I suspect it should
really return decline, but that breaks Apache currently - Ben
*/
#define APR_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL(ns,link,ret,name,args_decl,args_use,ok,decline) \
APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
link##_DECLARE(ret) ns##_run_##name args_decl \
{ \
ns##_LINK_##name##_t *pHook; \
int n; \
ret rv = ok; \
APR_HOOK_INT_DCL_UD; \
\
APR_HOOK_PROBE_ENTRY(ud, ns, name, args_use); \
\
if(_hooks.link_##name) \
{ \
pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
{ \
APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName, args_use); \
rv=pHook[n].pFunc args_use; \
APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, rv, args_use); \
if(rv != ok && rv != decline) \
break; \
rv = ok; \
} \
} \
\
APR_HOOK_PROBE_RETURN(ud, ns, name, rv, args_use); \
\
return rv; \
}
#define APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(ns,link,ret,name,args_decl,args_use,decline) \
APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
link##_DECLARE(ret) ns##_run_##name args_decl \
{ \
ns##_LINK_##name##_t *pHook; \
int n; \
ret rv = decline; \
APR_HOOK_INT_DCL_UD; \
\
APR_HOOK_PROBE_ENTRY(ud, ns, name, args_use); \
\
if(_hooks.link_##name) \
{ \
pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
{ \
APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName, args_use); \
rv=pHook[n].pFunc args_use; \
APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, rv, args_use); \
\
if(rv != decline) \
break; \
} \
} \
\
APR_HOOK_PROBE_RETURN(ud, ns, name, rv, args_use); \
\
return rv; \
}
/* Hook orderings */
#define APR_HOOK_REALLY_FIRST (-10)
#define APR_HOOK_FIRST 0
#define APR_HOOK_MIDDLE 10
#define APR_HOOK_LAST 20
#define APR_HOOK_REALLY_LAST 30
APU_DECLARE_DATA extern apr_pool_t *apr_hook_global_pool;
APU_DECLARE_DATA extern int apr_hook_debug_enabled;
APU_DECLARE_DATA extern const char *apr_hook_debug_current;
APU_DECLARE(void) apr_hook_sort_register(const char *szHookName,
apr_array_header_t **aHooks);
APU_DECLARE(void) apr_hook_sort_all(void);
APU_DECLARE(void) apr_hook_debug_show(const char *szName,
const char * const *aszPre,
const char * const *aszSucc);
APU_DECLARE(void) apr_hook_deregister_all(void);
#ifdef __cplusplus
}
#endif
#endif /* APR_HOOKS_H */
apr_hook_sort_register
void apr_hook_sort_register(const char *szHookName, apr_array_header_t **aHooks)
apr_hook_debug_show
void apr_hook_debug_show(const char *szName, const char *const *aszPre, const char *const *aszSucc)
apr_hook_sort_all
void apr_hook_sort_all(void)
apr_hook_debug_current
const char * apr_hook_debug_current
apr_hook_debug_enabled
int apr_hook_debug_enabled
apr_hook_deregister_all
void apr_hook_deregister_all(void)
apr_hook_global_pool
apr_pool_t * apr_hook_global_pool