154359Sroberto/* Licensed to the Apache Software Foundation (ASF) under one or more
254359Sroberto * contributor license agreements.  See the NOTICE file distributed with
354359Sroberto * this work for additional information regarding copyright ownership.
454359Sroberto * The ASF licenses this file to You under the Apache License, Version 2.0
554359Sroberto * (the "License"); you may not use this file except in compliance with
654359Sroberto * the License.  You may obtain a copy of the License at
754359Sroberto *
854359Sroberto *     http://www.apache.org/licenses/LICENSE-2.0
954359Sroberto *
1054359Sroberto * Unless required by applicable law or agreed to in writing, software
1154359Sroberto * distributed under the License is distributed on an "AS IS" BASIS,
1254359Sroberto * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1354359Sroberto * See the License for the specific language governing permissions and
1454359Sroberto * limitations under the License.
1554359Sroberto */
1654359Sroberto/**
1754359Sroberto * @file apr_optional_hooks.h
1854359Sroberto * @brief Apache optional hook functions
1954359Sroberto */
2054359Sroberto
2154359Sroberto
2254359Sroberto#ifndef APR_OPTIONAL_HOOK_H
2354359Sroberto#define APR_OPTIONAL_HOOK_H
2454359Sroberto
2554359Sroberto#include "apr_tables.h"
2654359Sroberto
2754359Sroberto#ifdef __cplusplus
2854359Srobertoextern "C" {
2954359Sroberto#endif
3054359Sroberto/**
3154359Sroberto * @defgroup APR_Util_OPT_HOOK Optional Hook Functions
3254359Sroberto * @ingroup APR_Util_Hook
3354359Sroberto * @{
3454359Sroberto */
3554359Sroberto/**
3654359Sroberto * Function to implement the APR_OPTIONAL_HOOK Macro
3754359Sroberto * @internal
3854359Sroberto * @see APR_OPTIONAL_HOOK
3954359Sroberto *
4054359Sroberto * @param szName The name of the hook
4154359Sroberto * @param pfn A pointer to a function that will be called
4254359Sroberto * @param aszPre a NULL-terminated array of strings that name modules whose hooks should precede this one
4354359Sroberto * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should succeed this one
4454359Sroberto * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example HOOK_MIDDLE)
4554359Sroberto */
4654359Sroberto
4754359Sroberto
4854359SrobertoAPU_DECLARE(void) apr_optional_hook_add(const char *szName,void (*pfn)(void),
4954359Sroberto					const char * const *aszPre,
5054359Sroberto					const char * const *aszSucc,
5154359Sroberto					int nOrder);
5254359Sroberto
5354359Sroberto/**
5454359Sroberto * Hook to an optional hook.
5554359Sroberto *
5654359Sroberto * @param ns The namespace prefix of the hook functions
5754359Sroberto * @param name The name of the hook
5854359Sroberto * @param pfn A pointer to a function that will be called
5954359Sroberto * @param aszPre a NULL-terminated array of strings that name modules whose hooks should precede this one
6054359Sroberto * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should succeed this one
6154359Sroberto * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example HOOK_MIDDLE)
6254359Sroberto */
6354359Sroberto
6454359Sroberto#define APR_OPTIONAL_HOOK(ns,name,pfn,aszPre,aszSucc,nOrder) do { \
6554359Sroberto  ns##_HOOK_##name##_t *apu__hook = pfn; \
6654359Sroberto  apr_optional_hook_add(#name,(void (*)(void))apu__hook,aszPre, aszSucc, nOrder); \
6754359Sroberto} while (0)
6854359Sroberto
6954359Sroberto/**
7054359Sroberto * @internal
7154359Sroberto * @param szName - the name of the function
7254359Sroberto * @return the hook structure for a given hook
7354359Sroberto */
7454359SrobertoAPU_DECLARE(apr_array_header_t *) apr_optional_hook_get(const char *szName);
7554359Sroberto
7654359Sroberto/**
7754359Sroberto * Implement an optional hook that runs until one of the functions
7854359Sroberto * returns something other than OK or DECLINE.
7954359Sroberto *
8054359Sroberto * @param ns The namespace prefix of the hook functions
8154359Sroberto * @param link The linkage declaration prefix of the hook
8254359Sroberto * @param ret The type of the return value of the hook
8354359Sroberto * @param ret The type of the return value of the hook
8454359Sroberto * @param name The name of the hook
8554359Sroberto * @param args_decl The declaration of the arguments for the hook
8654359Sroberto * @param args_use The names for the arguments for the hook
8754359Sroberto * @param ok Success value
8854359Sroberto * @param decline Decline value
8954359Sroberto */
9054359Sroberto#define APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ns,link,ret,name,args_decl,args_use,ok,decline) \
9154359Srobertolink##_DECLARE(ret) ns##_run_##name args_decl \
9254359Sroberto    { \
9354359Sroberto    ns##_LINK_##name##_t *pHook; \
9454359Sroberto    int n; \
9554359Sroberto    ret rv; \
9654359Sroberto    apr_array_header_t *pHookArray=apr_optional_hook_get(#name); \
9754359Sroberto\
9854359Sroberto    if(!pHookArray) \
9954359Sroberto	return ok; \
10054359Sroberto\
10154359Sroberto    pHook=(ns##_LINK_##name##_t *)pHookArray->elts; \
10254359Sroberto    for(n=0 ; n < pHookArray->nelts ; ++n) \
10354359Sroberto	{ \
10454359Sroberto	rv=(pHook[n].pFunc)args_use; \
10554359Sroberto\
10654359Sroberto	if(rv != ok && rv != decline) \
10754359Sroberto	    return rv; \
10854359Sroberto	} \
10954359Sroberto    return ok; \
11054359Sroberto    }
11154359Sroberto
11254359Sroberto/** @} */
11354359Sroberto#ifdef __cplusplus
11454359Sroberto}
11554359Sroberto#endif
11654359Sroberto
11754359Sroberto#endif /* APR_OPTIONAL_HOOK_H */
11854359Sroberto