apr_optional_hooks.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef APR_OPTIONAL_HOOK_H
  21. #define APR_OPTIONAL_HOOK_H
  22. #include "apr_tables.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /**
  27. * @defgroup APR_Util_OPT_HOOK Optional Hook Functions
  28. * @ingroup APR_Util_Hook
  29. * @{
  30. */
  31. /**
  32. * Function to implement the APR_OPTIONAL_HOOK Macro
  33. * @internal
  34. * @see APR_OPTIONAL_HOOK
  35. *
  36. * @param szName The name of the hook
  37. * @param pfn A pointer to a function that will be called
  38. * @param aszPre a NULL-terminated array of strings that name modules whose hooks should precede this one
  39. * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should succeed this one
  40. * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example HOOK_MIDDLE)
  41. */
  42. APU_DECLARE(void) apr_optional_hook_add(const char *szName,void (*pfn)(void),
  43. const char * const *aszPre,
  44. const char * const *aszSucc,
  45. int nOrder);
  46. /**
  47. * Hook to an optional hook.
  48. *
  49. * @param ns The namespace prefix of the hook functions
  50. * @param name The name of the hook
  51. * @param pfn A pointer to a function that will be called
  52. * @param aszPre a NULL-terminated array of strings that name modules whose hooks should precede this one
  53. * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should succeed this one
  54. * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example HOOK_MIDDLE)
  55. */
  56. #define APR_OPTIONAL_HOOK(ns,name,pfn,aszPre,aszSucc,nOrder) do { \
  57. ns##_HOOK_##name##_t *apu__hook = pfn; \
  58. apr_optional_hook_add(#name,(void (*)(void))apu__hook,aszPre, aszSucc, nOrder); \
  59. } while (0)
  60. /**
  61. * @internal
  62. * @param szName - the name of the function
  63. * @return the hook structure for a given hook
  64. */
  65. APU_DECLARE(apr_array_header_t *) apr_optional_hook_get(const char *szName);
  66. /**
  67. * Implement an optional hook that runs until one of the functions
  68. * returns something other than OK or DECLINE.
  69. *
  70. * @param ns The namespace prefix of the hook functions
  71. * @param link The linkage declaration prefix of the hook
  72. * @param ret The type of the return value of the hook
  73. * @param ret The type of the return value of the hook
  74. * @param name The name of the hook
  75. * @param args_decl The declaration of the arguments for the hook
  76. * @param args_use The names for the arguments for the hook
  77. * @param ok Success value
  78. * @param decline Decline value
  79. */
  80. #define APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ns,link,ret,name,args_decl,args_use,ok,decline) \
  81. link##_DECLARE(ret) ns##_run_##name args_decl \
  82. { \
  83. ns##_LINK_##name##_t *pHook; \
  84. int n; \
  85. ret rv; \
  86. apr_array_header_t *pHookArray=apr_optional_hook_get(#name); \
  87. \
  88. if(!pHookArray) \
  89. return ok; \
  90. \
  91. pHook=(ns##_LINK_##name##_t *)pHookArray->elts; \
  92. for(n=0 ; n < pHookArray->nelts ; ++n) \
  93. { \
  94. rv=(pHook[n].pFunc)args_use; \
  95. \
  96. if(rv != ok && rv != decline) \
  97. return rv; \
  98. } \
  99. return ok; \
  100. }
  101. /** @} */
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif /* APR_OPTIONAL_HOOK_H */