1251876Speter/* Licensed to the Apache Software Foundation (ASF) under one or more
2251876Speter * contributor license agreements.  See the NOTICE file distributed with
3251876Speter * this work for additional information regarding copyright ownership.
4251876Speter * The ASF licenses this file to You under the Apache License, Version 2.0
5251876Speter * (the "License"); you may not use this file except in compliance with
6251876Speter * the License.  You may obtain a copy of the License at
7251876Speter *
8251876Speter *     http://www.apache.org/licenses/LICENSE-2.0
9251876Speter *
10251876Speter * Unless required by applicable law or agreed to in writing, software
11251876Speter * distributed under the License is distributed on an "AS IS" BASIS,
12251876Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13251876Speter * See the License for the specific language governing permissions and
14251876Speter * limitations under the License.
15251876Speter */
16251876Speter/**
17251876Speter * @file apr_optional_hooks.h
18251876Speter * @brief Apache optional hook functions
19251876Speter */
20251876Speter
21251876Speter
22251876Speter#ifndef APR_OPTIONAL_HOOK_H
23251876Speter#define APR_OPTIONAL_HOOK_H
24251876Speter
25251876Speter#include "apr_tables.h"
26251876Speter
27251876Speter#ifdef __cplusplus
28251876Speterextern "C" {
29251876Speter#endif
30251876Speter/**
31251876Speter * @defgroup APR_Util_OPT_HOOK Optional Hook Functions
32251876Speter * @ingroup APR_Util_Hook
33251876Speter * @{
34251876Speter */
35251876Speter/**
36262253Speter * Function to implement the APR_OPTIONAL_HOOK Macro
37251876Speter * @internal
38251876Speter * @see APR_OPTIONAL_HOOK
39251876Speter *
40262253Speter * @param szName The name of the hook
41251876Speter * @param pfn A pointer to a function that will be called
42251876Speter * @param aszPre a NULL-terminated array of strings that name modules whose hooks should precede this one
43251876Speter * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should succeed this one
44251876Speter * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example HOOK_MIDDLE)
45251876Speter */
46251876Speter
47251876Speter
48251876SpeterAPU_DECLARE(void) apr_optional_hook_add(const char *szName,void (*pfn)(void),
49251876Speter					const char * const *aszPre,
50251876Speter					const char * const *aszSucc,
51251876Speter					int nOrder);
52251876Speter
53251876Speter/**
54251876Speter * Hook to an optional hook.
55251876Speter *
56251876Speter * @param ns The namespace prefix of the hook functions
57251876Speter * @param name The name of the hook
58251876Speter * @param pfn A pointer to a function that will be called
59251876Speter * @param aszPre a NULL-terminated array of strings that name modules whose hooks should precede this one
60251876Speter * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should succeed this one
61251876Speter * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example HOOK_MIDDLE)
62251876Speter */
63251876Speter
64251876Speter#define APR_OPTIONAL_HOOK(ns,name,pfn,aszPre,aszSucc,nOrder) do { \
65251876Speter  ns##_HOOK_##name##_t *apu__hook = pfn; \
66251876Speter  apr_optional_hook_add(#name,(void (*)(void))apu__hook,aszPre, aszSucc, nOrder); \
67251876Speter} while (0)
68251876Speter
69251876Speter/**
70251876Speter * @internal
71251876Speter * @param szName - the name of the function
72251876Speter * @return the hook structure for a given hook
73251876Speter */
74251876SpeterAPU_DECLARE(apr_array_header_t *) apr_optional_hook_get(const char *szName);
75251876Speter
76251876Speter/**
77251876Speter * Implement an optional hook that runs until one of the functions
78251876Speter * returns something other than OK or DECLINE.
79251876Speter *
80251876Speter * @param ns The namespace prefix of the hook functions
81251876Speter * @param link The linkage declaration prefix of the hook
82251876Speter * @param ret The type of the return value of the hook
83251876Speter * @param ret The type of the return value of the hook
84251876Speter * @param name The name of the hook
85251876Speter * @param args_decl The declaration of the arguments for the hook
86251876Speter * @param args_use The names for the arguments for the hook
87251876Speter * @param ok Success value
88251876Speter * @param decline Decline value
89251876Speter */
90251876Speter#define APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ns,link,ret,name,args_decl,args_use,ok,decline) \
91251876Speterlink##_DECLARE(ret) ns##_run_##name args_decl \
92251876Speter    { \
93251876Speter    ns##_LINK_##name##_t *pHook; \
94251876Speter    int n; \
95251876Speter    ret rv; \
96251876Speter    apr_array_header_t *pHookArray=apr_optional_hook_get(#name); \
97251876Speter\
98251876Speter    if(!pHookArray) \
99251876Speter	return ok; \
100251876Speter\
101251876Speter    pHook=(ns##_LINK_##name##_t *)pHookArray->elts; \
102251876Speter    for(n=0 ; n < pHookArray->nelts ; ++n) \
103251876Speter	{ \
104251876Speter	rv=(pHook[n].pFunc)args_use; \
105251876Speter\
106251876Speter	if(rv != ok && rv != decline) \
107251876Speter	    return rv; \
108251876Speter	} \
109251876Speter    return ok; \
110251876Speter    }
111251876Speter
112251876Speter/** @} */
113251876Speter#ifdef __cplusplus
114251876Speter}
115251876Speter#endif
116251876Speter
117251876Speter#endif /* APR_OPTIONAL_HOOK_H */
118