Main Page | Modules | Namespace List | Data Structures | File List | Data Fields | Globals | Related Pages

apr_hooks.h

Go to the documentation of this file.
00001 /* ====================================================================
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
00005  * reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  * 3. The end-user documentation included with the redistribution,
00020  *    if any, must include the following acknowledgment:
00021  *       "This product includes software developed by the
00022  *        Apache Software Foundation (http://www.apache.org/)."
00023  *    Alternately, this acknowledgment may appear in the software itself,
00024  *    if and wherever such third-party acknowledgments normally appear.
00025  *
00026  * 4. The names "Apache" and "Apache Software Foundation" must
00027  *    not be used to endorse or promote products derived from this
00028  *    software without prior written permission. For written
00029  *    permission, please contact apache@apache.org.
00030  *
00031  * 5. Products derived from this software may not be called "Apache",
00032  *    nor may "Apache" appear in their name, without prior written
00033  *    permission of the Apache Software Foundation.
00034  *
00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  * ====================================================================
00048  *
00049  * This software consists of voluntary contributions made by many
00050  * individuals on behalf of the Apache Software Foundation.  For more
00051  * information on the Apache Software Foundation, please see
00052  * <http://www.apache.org/>.
00053  */
00054 
00055 #ifndef APR_HOOKS_H
00056 #define APR_HOOKS_H
00057 
00058 #include "apu.h"
00059 /* For apr_array_header_t */
00060 #include "apr_tables.h"
00061 
00067 #ifdef __cplusplus
00068 extern "C" {
00069 #endif
00070 
00076 #define APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \
00077 link##_DECLARE(apr_array_header_t *) ns##_hook_get_##name(void)
00078 
00080 #define APR_DECLARE_EXTERNAL_HOOK(ns,link,ret,name,args) \
00081 typedef ret ns##_HOOK_##name##_t args; \
00082 link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf, \
00083                                       const char * const *aszPre, \
00084                                       const char * const *aszSucc, int nOrder); \
00085 link##_DECLARE(ret) ns##_run_##name args; \
00086 APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name); \
00087 typedef struct ns##_LINK_##name##_t \
00088     { \
00089     ns##_HOOK_##name##_t *pFunc; \
00090     const char *szName; \
00091     const char * const *aszPredecessors; \
00092     const char * const *aszSuccessors; \
00093     int nOrder; \
00094     } ns##_LINK_##name##_t;
00095 
00097 #define APR_HOOK_STRUCT(members) \
00098 static struct { members } _hooks;
00099 
00101 #define APR_HOOK_LINK(name) \
00102     apr_array_header_t *link_##name;
00103 
00105 #define APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
00106 link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf,const char * const *aszPre, \
00107                                       const char * const *aszSucc,int nOrder) \
00108     { \
00109     ns##_LINK_##name##_t *pHook; \
00110     if(!_hooks.link_##name) \
00111         { \
00112         _hooks.link_##name=apr_array_make(apr_hook_global_pool,1,sizeof(ns##_LINK_##name##_t)); \
00113         apr_hook_sort_register(#name,&_hooks.link_##name); \
00114         } \
00115     pHook=apr_array_push(_hooks.link_##name); \
00116     pHook->pFunc=pf; \
00117     pHook->aszPredecessors=aszPre; \
00118     pHook->aszSuccessors=aszSucc; \
00119     pHook->nOrder=nOrder; \
00120     pHook->szName=apr_hook_debug_current; \
00121     if(apr_hook_debug_enabled) \
00122         apr_hook_debug_show(#name,aszPre,aszSucc); \
00123     } \
00124     APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \
00125     { \
00126         return _hooks.link_##name; \
00127     }
00128 
00141 #define APR_IMPLEMENT_EXTERNAL_HOOK_VOID(ns,link,name,args_decl,args_use) \
00142 APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
00143 link##_DECLARE(void) ns##_run_##name args_decl \
00144     { \
00145     ns##_LINK_##name##_t *pHook; \
00146     int n; \
00147 \
00148     if(!_hooks.link_##name) \
00149         return; \
00150 \
00151     pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
00152     for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
00153         pHook[n].pFunc args_use; \
00154     }
00155 
00156 /* FIXME: note that this returns ok when nothing is run. I suspect it should
00157    really return decline, but that breaks Apache currently - Ben
00158 */
00174 #define APR_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL(ns,link,ret,name,args_decl,args_use,ok,decline) \
00175 APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
00176 link##_DECLARE(ret) ns##_run_##name args_decl \
00177     { \
00178     ns##_LINK_##name##_t *pHook; \
00179     int n; \
00180     ret rv; \
00181 \
00182     if(!_hooks.link_##name) \
00183         return ok; \
00184 \
00185     pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
00186     for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
00187         { \
00188         rv=pHook[n].pFunc args_use; \
00189 \
00190         if(rv != ok && rv != decline) \
00191             return rv; \
00192         } \
00193     return ok; \
00194     }
00195 
00196 
00211 #define APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(ns,link,ret,name,args_decl,args_use,decline) \
00212 APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
00213 link##_DECLARE(ret) ns##_run_##name args_decl \
00214     { \
00215     ns##_LINK_##name##_t *pHook; \
00216     int n; \
00217     ret rv; \
00218 \
00219     if(!_hooks.link_##name) \
00220         return decline; \
00221 \
00222     pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
00223     for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
00224         { \
00225         rv=pHook[n].pFunc args_use; \
00226 \
00227         if(rv != decline) \
00228             return rv; \
00229         } \
00230     return decline; \
00231     }
00232 
00233     /* Hook orderings */
00235 #define APR_HOOK_REALLY_FIRST   (-10)
00236 
00237 #define APR_HOOK_FIRST          0
00238 
00239 #define APR_HOOK_MIDDLE         10
00240 
00241 #define APR_HOOK_LAST           20
00242 
00243 #define APR_HOOK_REALLY_LAST    30
00244 
00248 APU_DECLARE_DATA extern apr_pool_t *apr_hook_global_pool;
00249 
00251 APU_DECLARE_DATA extern apr_pool_t *apr_global_hook_pool;
00252 
00257 APU_DECLARE_DATA extern int apr_hook_debug_enabled;
00258 
00260 APU_DECLARE_DATA extern int apr_debug_module_hooks;
00261 
00265 APU_DECLARE_DATA extern const char *apr_hook_debug_current;
00266 
00268 APU_DECLARE_DATA extern const char *apr_current_hooking_module;
00269 
00275 APU_DECLARE(void) apr_hook_sort_register(const char *szHookName, 
00276                                         apr_array_header_t **aHooks);
00280 APU_DECLARE(void) apr_hook_sort_all(void);
00281 
00283 APU_DECLARE(void) apr_sort_hooks(void);
00284 
00292 APU_DECLARE(void) apr_hook_debug_show(const char *szName,
00293                                       const char * const *aszPre,
00294                                       const char * const *aszSucc);
00295 
00297 APU_DECLARE(void) apr_show_hook(const char *szName,
00298                                 const char * const *aszPre,
00299                                 const char * const *aszSucc);
00300 
00304 APU_DECLARE(void) apr_hook_deregister_all(void);
00305 
00307 #ifdef __cplusplus
00308 }
00309 #endif
00310 
00311 #endif /* APR_HOOKS_H */

Generated on Wed Dec 8 00:35:22 2010 for Apache Portable Runtime Utility Library by  doxygen 1.3.9.1