Apache Portable Runtime
apr_optional_hooks.h
Go to the documentation of this file.
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /**
17  * @file apr_optional_hooks.h
18  * @brief Apache optional hook functions
19  */
20 
21 
22 #ifndef APR_OPTIONAL_HOOK_H
23 #define APR_OPTIONAL_HOOK_H
24 
25 #include "apr_tables.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 /**
31  * @defgroup APR_Util_OPT_HOOK Optional Hook Functions
32  * @ingroup APR_Util_Hook
33  * @{
34  */
35 /**
36  * Function to implement the APR_OPTIONAL_HOOK Macro
37  * @internal
38  * @see APR_OPTIONAL_HOOK
39  *
40  * @param szName 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 
48 APR_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  */
74 APR_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) \
91 link##_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 */
void apr_optional_hook_add(const char *szName, void(*pfn)(void), const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition: apr_tables.h:62
APR Table library.
#define APR_DECLARE(type)
Definition: apr.h:500