apr_optional_hooks.h revision 251876
1122592Ssam/* Licensed to the Apache Software Foundation (ASF) under one or more 2122592Ssam * contributor license agreements. See the NOTICE file distributed with 3122592Ssam * this work for additional information regarding copyright ownership. 4122592Ssam * The ASF licenses this file to You under the Apache License, Version 2.0 5122592Ssam * (the "License"); you may not use this file except in compliance with 6122592Ssam * the License. You may obtain a copy of the License at 7122592Ssam * 8122592Ssam * http://www.apache.org/licenses/LICENSE-2.0 9122592Ssam * 10122592Ssam * Unless required by applicable law or agreed to in writing, software 11122592Ssam * distributed under the License is distributed on an "AS IS" BASIS, 12122592Ssam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13122592Ssam * See the License for the specific language governing permissions and 14122592Ssam * limitations under the License. 15122592Ssam */ 16122592Ssam/** 17122592Ssam * @file apr_optional_hooks.h 18122592Ssam * @brief Apache optional hook functions 19122592Ssam */ 20122592Ssam 21122592Ssam 22122592Ssam#ifndef APR_OPTIONAL_HOOK_H 23122592Ssam#define APR_OPTIONAL_HOOK_H 24122592Ssam 25#include "apr_tables.h" 26 27#ifdef __cplusplus 28extern "C" { 29#endif 30/** 31 * @defgroup APR_Util_OPT_HOOK Optional Hook Functions 32 * @ingroup APR_Util_Hook 33 * @{ 34 */ 35/** 36 * Function to implemnt the APR_OPTIONAL_HOOK Macro 37 * @internal 38 * @see APR_OPTIONAL_HOOK 39 * 40 * @param name The name of the hook 41 * @param pfn A pointer to a function that will be called 42 * @param aszPre a NULL-terminated array of strings that name modules whose hooks should precede this one 43 * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should succeed this one 44 * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example HOOK_MIDDLE) 45 */ 46 47 48APU_DECLARE(void) apr_optional_hook_add(const char *szName,void (*pfn)(void), 49 const char * const *aszPre, 50 const char * const *aszSucc, 51 int nOrder); 52 53/** 54 * Hook to an optional hook. 55 * 56 * @param ns The namespace prefix of the hook functions 57 * @param name The name of the hook 58 * @param pfn A pointer to a function that will be called 59 * @param aszPre a NULL-terminated array of strings that name modules whose hooks should precede this one 60 * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should succeed this one 61 * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example HOOK_MIDDLE) 62 */ 63 64#define APR_OPTIONAL_HOOK(ns,name,pfn,aszPre,aszSucc,nOrder) do { \ 65 ns##_HOOK_##name##_t *apu__hook = pfn; \ 66 apr_optional_hook_add(#name,(void (*)(void))apu__hook,aszPre, aszSucc, nOrder); \ 67} while (0) 68 69/** 70 * @internal 71 * @param szName - the name of the function 72 * @return the hook structure for a given hook 73 */ 74APU_DECLARE(apr_array_header_t *) apr_optional_hook_get(const char *szName); 75 76/** 77 * Implement an optional hook that runs until one of the functions 78 * returns something other than OK or DECLINE. 79 * 80 * @param ns The namespace prefix of the hook functions 81 * @param link The linkage declaration prefix of the hook 82 * @param ret The type of the return value of the hook 83 * @param ret The type of the return value of the hook 84 * @param name The name of the hook 85 * @param args_decl The declaration of the arguments for the hook 86 * @param args_use The names for the arguments for the hook 87 * @param ok Success value 88 * @param decline Decline value 89 */ 90#define APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ns,link,ret,name,args_decl,args_use,ok,decline) \ 91link##_DECLARE(ret) ns##_run_##name args_decl \ 92 { \ 93 ns##_LINK_##name##_t *pHook; \ 94 int n; \ 95 ret rv; \ 96 apr_array_header_t *pHookArray=apr_optional_hook_get(#name); \ 97\ 98 if(!pHookArray) \ 99 return ok; \ 100\ 101 pHook=(ns##_LINK_##name##_t *)pHookArray->elts; \ 102 for(n=0 ; n < pHookArray->nelts ; ++n) \ 103 { \ 104 rv=(pHook[n].pFunc)args_use; \ 105\ 106 if(rv != ok && rv != decline) \ 107 return rv; \ 108 } \ 109 return ok; \ 110 } 111 112/** @} */ 113#ifdef __cplusplus 114} 115#endif 116 117#endif /* APR_OPTIONAL_HOOK_H */ 118