00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 /** 00017 * @file apr_optional_hooks.h 00018 * @brief Apache optional hook functions 00019 */ 00020 00021 00022 #ifndef APR_OPTIONAL_HOOK_H 00023 #define APR_OPTIONAL_HOOK_H 00024 00025 #include "apr_tables.h" 00026 00027 #ifdef __cplusplus 00028 extern "C" { 00029 #endif 00030 /** 00031 * @defgroup APR_Util_OPT_HOOK Optional Hook Functions 00032 * @ingroup APR_Util_Hook 00033 * @{ 00034 */ 00035 /** 00036 * Function to implemnt the APR_OPTIONAL_HOOK Macro 00037 * @internal 00038 * @see APR_OPTIONAL_HOOK 00039 * 00040 * @param name The name of the hook 00041 * @param pfn A pointer to a function that will be called 00042 * @param aszPre a NULL-terminated array of strings that name modules whose hooks should precede this one 00043 * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should succeed this one 00044 * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example HOOK_MIDDLE) 00045 */ 00046 00047 00048 APU_DECLARE(void) apr_optional_hook_add(const char *szName,void (*pfn)(void), 00049 const char * const *aszPre, 00050 const char * const *aszSucc, 00051 int nOrder); 00052 00053 /** 00054 * Hook to an optional hook. 00055 * 00056 * @param ns The namespace prefix of the hook functions 00057 * @param name The name of the hook 00058 * @param pfn A pointer to a function that will be called 00059 * @param aszPre a NULL-terminated array of strings that name modules whose hooks should precede this one 00060 * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should succeed this one 00061 * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example HOOK_MIDDLE) 00062 */ 00063 00064 #define APR_OPTIONAL_HOOK(ns,name,pfn,aszPre,aszSucc,nOrder) do { \ 00065 ns##_HOOK_##name##_t *apu__hook = pfn; \ 00066 apr_optional_hook_add(#name,(void (*)(void))apu__hook,aszPre, aszSucc, nOrder); \ 00067 } while (0) 00068 00069 /** 00070 * @internal 00071 * @param szName - the name of the function 00072 * @return the hook structure for a given hook 00073 */ 00074 APU_DECLARE(apr_array_header_t *) apr_optional_hook_get(const char *szName); 00075 00076 /** 00077 * Implement an optional hook that runs until one of the functions 00078 * returns something other than OK or DECLINE. 00079 * 00080 * @param ns The namespace prefix of the hook functions 00081 * @param link The linkage declaration prefix of the hook 00082 * @param ret The type of the return value of the hook 00083 * @param ret The type of the return value of the hook 00084 * @param name The name of the hook 00085 * @param args_decl The declaration of the arguments for the hook 00086 * @param args_use The names for the arguments for the hook 00087 * @param ok Success value 00088 * @param decline Decline value 00089 */ 00090 #define APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ns,link,ret,name,args_decl,args_use,ok,decline) \ 00091 link##_DECLARE(ret) ns##_run_##name args_decl \ 00092 { \ 00093 ns##_LINK_##name##_t *pHook; \ 00094 int n; \ 00095 ret rv; \ 00096 apr_array_header_t *pHookArray=apr_optional_hook_get(#name); \ 00097 \ 00098 if(!pHookArray) \ 00099 return ok; \ 00100 \ 00101 pHook=(ns##_LINK_##name##_t *)pHookArray->elts; \ 00102 for(n=0 ; n < pHookArray->nelts ; ++n) \ 00103 { \ 00104 rv=(pHook[n].pFunc)args_use; \ 00105 \ 00106 if(rv != ok && rv != decline) \ 00107 return rv; \ 00108 } \ 00109 return ok; \ 00110 } 00111 00112 /** @} */ 00113 #ifdef __cplusplus 00114 } 00115 #endif 00116 00117 #endif /* APR_OPTIONAL_HOOK_H */