apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: apr-util/src/hooks ap_hooks.c
Date Tue, 02 Jan 2001 17:41:54 GMT
ben         01/01/02 09:41:52

  Modified:    .        CHANGES
               modules/experimental config.m4
               server   config.c
               include  ap_hooks.h
               src/hooks ap_hooks.c
  Added:       include  ap_generic_hook.h
               modules/experimental mod_case_filter.c
                        mod_generic_hook_export.c mod_generic_hook_export.h
                        mod_generic_hook_import.c
  Log:
  Generic hooks (and a demo content filter module).
  
  Revision  Changes    Path
  1.31      +2 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- CHANGES	2000/12/31 19:19:06	1.30
  +++ CHANGES	2001/01/02 17:41:21	1.31
  @@ -1,5 +1,7 @@
   Changes with Apache 2.0b1
   
  +  *) Add generic hooks. [Ben Laurie]
  +
     *) Use a real pool to dup the error log descriptor.  [Ryan Bloom]
   
     *) Fix a segfault caused by mod_ext_filter when the external filter 
  
  
  
  1.1                  httpd-2.0/include/ap_generic_hook.h
  
  Index: ap_generic_hook.h
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #ifndef APACHE_AP_GENERIC_HOOK_H
  #define APACHE_AP_GENERIC_HOOK_H
  
  #include "apr_tables.h"
  
  /**
   * @package Apache hooks functions
   */
  
  #define AP_DECLARE_GENERIC_HOOK(link,ret,name,args) \
  typedef ret HOOK_##name args;
  
  AP_DECLARE(void) ap_hook_generic(const char *szName,void (*pfn)(void),
  				 const char * const *aszPre,
  				 const char * const *aszSucc,int nOrder);
  
  /**
   * Hook to a generic hook.
   *
   * @param name The name of the hook
   * @param pfn A pointer to a function that will be called
   * @param aszPre a NULL-terminated array of strings that name modules whose hooks should
precede this one
   * @param aszSucc a NULL-terminated array of strings that name modules whose hooks should
succeed this one
   * @param nOrder an integer determining order before honouring aszPre and aszSucc (for example
HOOK_MIDDLE)
   */
  
  #define AP_HOOK_GENERIC(name,pfn,aszPre,aszSucc,nOrder) \
      ((void (*)(const char *,HOOK_##name *,const char * const *, \
  	       const char * const *,int))&ap_hook_generic)(#name,pfn,aszPre, \
  							   aszSucc, nOrder)
  
  apr_array_header_t *ap_generic_hook_get(const char *szName);
  
  /**
   * Implement a generic hook that runs until one of the functions
   * returns something other than OK or DECLINE.
   *
   * @param ret The type of the return value of the hook
   * @param name The name of the hook
   * @param args_decl The declaration of the arguments for the hook
   * @param args_used The names for the arguments for the hook
   * @deffunc int AP_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL(link, name, args_decl, args_use)
   */
  #define AP_IMPLEMENT_GENERIC_HOOK_RUN_ALL(ret,name,args_decl,args_use,ok,decline) \
  AP_DECLARE(ret) ap_run_##name args_decl \
      { \
      LINK_##name *pHook; \
      int n; \
      ret rv; \
      apr_array_header_t *pHookArray=ap_generic_hook_get(#name); \
  \
      if(!pHookArray) \
  	return ok; \
  \
      pHook=(LINK_##name *)pHookArray->elts; \
      for(n=0 ; n < pHookArray->nelts ; ++n) \
  	{ \
  	rv=pHook[n].pFunc args_use; \
  \
  	if(rv != ok && rv != decline) \
  	    return rv; \
  	} \
      return ok; \
      }
  
  #endif /* def APACHE_AP_GENERIC_HOOK_H */
  
  
  
  1.5       +3 -0      httpd-2.0/modules/experimental/config.m4
  
  Index: config.m4
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/experimental/config.m4,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- config.m4	2000/12/11 19:02:14	1.4
  +++ config.m4	2001/01/02 17:41:31	1.5
  @@ -5,5 +5,8 @@
   APACHE_MODULE(cache, dynamic file caching, , , no)
   APACHE_MODULE(disk_cache, disk caching module, , , no)
   APACHE_MODULE(ext_filter, external filter module, , , no)
  +APACHE_MODULE(case_filter, example uppercase conversion filter, , , no)
  +APACHE_MODULE(generic_hook_export, example hook exporter, , , no)
  +APACHE_MODULE(generic_hook_import, example hook importer, , , no)
   
   APACHE_MODPATH_FINISH
  
  
  
  1.1                  httpd-2.0/modules/experimental/mod_case_filter.c
  
  Index: mod_case_filter.c
  ===================================================================
  // Ben messing around...
  
  #include "httpd.h"
  #include "http_config.h"
  #include "apr_general.h"
  #include "util_filter.h"
  #include "ap_buckets.h"
  #include "http_request.h"
  
  static const char s_szCaseFilterName[]="CaseFilter";
  module case_filter_module;
  
  typedef struct
      {
      int bEnabled;
      } CaseFilterConfig;
  
  static void *CaseFilterCreateServerConfig(apr_pool_t *p,server_rec *s)
      {
      CaseFilterConfig *pConfig=apr_pcalloc(p,sizeof *pConfig);
  
      pConfig->bEnabled=0;
  
      return pConfig;
      }
  
  static void CaseFilterInsertFilter(request_rec *r)
      {
      CaseFilterConfig *pConfig=ap_get_module_config(r->server->module_config,
  						   &case_filter_module);
  
      if(!pConfig->bEnabled)
  	return;
  
      ap_add_output_filter(s_szCaseFilterName,NULL,r,r->connection);
      }
  
  static apr_status_t CaseFilterOutFilter(ap_filter_t *f,
  					ap_bucket_brigade *pbbIn)
      {
      ap_bucket *pbktIn;
      ap_bucket_brigade *pbbOut;
  
      // XXX: is this the most appropriate pool?
      pbbOut=ap_brigade_create(f->r->pool);
      AP_BRIGADE_FOREACH(pbktIn,pbbIn)
  	{
  	const char *data;
  	apr_size_t len;
  	char *buf;
  	apr_size_t n;
  	ap_bucket *pbktOut;
  
  	if(AP_BUCKET_IS_EOS(pbktIn))
  	    {
  	    // XXX: why can't I reuse pbktIn???
  	    ap_bucket *pbktEOS=ap_bucket_create_eos();
  	    AP_BRIGADE_INSERT_TAIL(pbbOut,pbktEOS);
  	    break;
  	    }
  
  	// read
  	ap_bucket_read(pbktIn,&data,&len,1);
  
  	// write
  	buf=apr_palloc(f->r->pool,len);
  	for(n=0 ; n < len ; ++n)
  	    buf[n]=toupper(data[n]);
  
  	// XXX: should we use a heap bucket instead? Or a transient (in
  	// which case we need a separate brigade for each bucket)?
  	pbktOut=ap_bucket_create_pool(buf,len,f->r->pool);
  	AP_BRIGADE_INSERT_TAIL(pbbOut,pbktOut);
  	}
  
      // XXX: is there any advantage to passing a brigade for each bucket?
      return ap_pass_brigade(f->next,pbbOut);
      }
  
  static const char *CaseFilterEnable(cmd_parms *cmd, void *dummy, int arg)
      {
      CaseFilterConfig *pConfig=ap_get_module_config(cmd->server->module_config,
  						   &case_filter_module);
      pConfig->bEnabled=arg;
  
      return NULL;
      }
  
  static const command_rec CaseFilterCmds[] = 
      {
      AP_INIT_FLAG("CaseFilter", CaseFilterEnable, NULL, RSRC_CONF,
                   "Run a case filter on this host"),
      { NULL }
      };
  
  static void CaseFilterRegisterHooks(void)
      {
      ap_hook_insert_filter(CaseFilterInsertFilter,NULL,NULL,AP_HOOK_MIDDLE);
      ap_register_output_filter(s_szCaseFilterName,CaseFilterOutFilter,
  			      AP_FTYPE_CONTENT);
      }
  
  module case_filter_module =
  {
      STANDARD20_MODULE_STUFF,
      NULL,
      NULL,
      CaseFilterCreateServerConfig,
      NULL,
      CaseFilterCmds,
      NULL,
      CaseFilterRegisterHooks
  };
  
  
  
  1.1                  httpd-2.0/modules/experimental/mod_generic_hook_export.c
  
  Index: mod_generic_hook_export.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "httpd.h"
  #include "http_config.h"
  #include "mod_generic_hook_export.h"
  #include "http_protocol.h"
  
  AP_IMPLEMENT_GENERIC_HOOK_RUN_ALL(int,generic_hook_test,(const char *szStr),
  				  (szStr),OK,DECLINED)
  
  static int ExportLogTransaction(request_rec *r)
  {
      return ap_run_generic_hook_test(r->the_request);
  }
  
  static void ExportRegisterHooks(void)
  {
      ap_hook_log_transaction(ExportLogTransaction,NULL,NULL,AP_HOOK_MIDDLE);
  }
  
  module generic_hook_export_module =
  {
      STANDARD20_MODULE_STUFF,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      ExportRegisterHooks
  };
  
  
  
  1.1                  httpd-2.0/modules/experimental/mod_generic_hook_export.h
  
  Index: mod_generic_hook_export.h
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #ifndef MOD_GENERIC_HOOK_EXPORT_H
  #define MOD_GENERIC_HOOK_EXPORT_H
  
  #include "ap_generic_hook.h"
  
  AP_DECLARE_HOOK(int,generic_hook_test,(const char *))
  
  #endif /* def MOD_GENERIC_HOOK_EXPORT_H */
  
  
  
  1.1                  httpd-2.0/modules/experimental/mod_generic_hook_import.c
  
  Index: mod_generic_hook_import.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "httpd.h"
  #include "http_config.h"
  #include "http_log.h"
  #include "mod_generic_hook_export.h"
  
  static int ImportGenericHookTestHook(const char *szStr)
  {
      ap_log_error(APLOG_MARK,APLOG_ERR,OK,NULL,"Generic hook test said: %s",
  		 szStr);
  
      return OK;
  }
  
  static void ImportRegisterHooks(void)
  {
      AP_HOOK_GENERIC(generic_hook_test,ImportGenericHookTestHook,NULL,NULL,
  		    AP_HOOK_MIDDLE);
  }
  
  module generic_hook_import_module=
  {
      STANDARD20_MODULE_STUFF,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      ImportRegisterHooks
  };
  
  
  
  1.91      +1 -1      httpd-2.0/server/config.c
  
  Index: config.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/config.c,v
  retrieving revision 1.90
  retrieving revision 1.91
  diff -u -r1.90 -r1.91
  --- config.c	2001/01/01 00:13:41	1.90
  +++ config.c	2001/01/02 17:41:38	1.91
  @@ -424,7 +424,7 @@
   	    printf("Registering hooks for %s\n",m->name);
   	    ap_debug_module_hooks=1;
   	    }
  -	ap_debug_module_name=m->name;
  +	ap_current_hooking_module=m->name;
   	m->register_hooks();
   	}
       }
  
  
  
  1.30      +2 -2      apr-util/include/ap_hooks.h
  
  Index: ap_hooks.h
  ===================================================================
  RCS file: /home/cvs/apr-util/include/ap_hooks.h,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- ap_hooks.h	2000/12/21 18:06:13	1.29
  +++ ap_hooks.h	2001/01/02 17:41:44	1.30
  @@ -98,7 +98,7 @@
       pHook->aszPredecessors=aszPre; \
       pHook->aszSuccessors=aszSucc; \
       pHook->nOrder=nOrder; \
  -    pHook->szName=ap_debug_module_name; \
  +    pHook->szName=ap_current_hooking_module; \
       if(ap_debug_module_hooks) \
   	ap_show_hook(#name,aszPre,aszSucc); \
       }
  @@ -226,7 +226,7 @@
    * The name of the module that is currently registering a function
    * @defvar apr_pool_t *ap_debug_module_name
    */ 
  -extern APU_DECLARE_DATA const char *ap_debug_module_name;
  +extern APU_DECLARE_DATA const char *ap_current_hooking_module;
   
   /**
    * Register a hook function to be sorted
  
  
  
  1.26      +53 -4     apr-util/src/hooks/ap_hooks.c
  
  Index: ap_hooks.c
  ===================================================================
  RCS file: /home/cvs/apr-util/src/hooks/ap_hooks.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ap_hooks.c	2000/12/22 16:54:59	1.25
  +++ ap_hooks.c	2001/01/02 17:41:49	1.26
  @@ -60,6 +60,7 @@
   #include "apr_tables.h"
   #include "apr.h"
   #include "ap_hooks.h"
  +#include "apr_hash.h"
   
   #if APR_HAVE_STRINGS_H
   #include <strings.h>
  @@ -71,7 +72,7 @@
   
   APU_DECLARE_DATA apr_pool_t *ap_global_hook_pool = NULL;
   APU_DECLARE_DATA int ap_debug_module_hooks = 0;
  -APU_DECLARE_DATA const char *ap_debug_module_name = NULL;
  +APU_DECLARE_DATA const char *ap_current_hooking_module = NULL;
   
   /* NB: This must echo the LINK_##name structure */
   typedef struct
  @@ -178,7 +179,8 @@
       return pHead;
   }
   
  -static apr_array_header_t *sort_hook(apr_array_header_t *pHooks,const char *szName)
  +static apr_array_header_t *sort_hook(apr_array_header_t *pHooks,
  +				     const char *szName)
   {
       apr_pool_t *p;
       TSort *pSort;
  @@ -212,7 +214,7 @@
   } HookSortEntry;
   
   APU_DECLARE(void) ap_hook_sort_register(const char *szHookName,
  -                                      apr_array_header_t **paHooks)
  +					apr_array_header_t **paHooks)
   {
       HookSortEntry *pEntry;
   
  @@ -233,6 +235,8 @@
       }
   }
       
  +static apr_hash_t *s_phGenericHooks;
  +
   APU_DECLARE(void) ap_hook_deregister_all(void)
   {
       int n;    
  @@ -242,10 +246,11 @@
           *pEntry->paHooks=NULL;
       }
       s_aHooksToSort=NULL;
  +    s_phGenericHooks=NULL;
   }
   
   APU_DECLARE(void) ap_show_hook(const char *szName,const char * const *aszPre,
  -		             const char * const *aszSucc)
  +			       const char * const *aszSucc)
   {
       int nFirst;
   
  @@ -275,6 +280,50 @@
   	fputc(')',stdout);
       }
       fputc('\n',stdout);
  +}
  +
  +/* Generic hook support */
  +
  +AP_DECLARE_EXTERNAL_HOOK(APU,void,_generic,(void))
  +
  +APU_DECLARE(apr_array_header_t *) ap_generic_hook_get(const char *szName)
  +{
  +    apr_array_header_t **ppArray;
  +
  +    if(!s_phGenericHooks)
  +	return NULL;
  +    ppArray=apr_hash_get(s_phGenericHooks,szName,strlen(szName));
  +    if(!ppArray)
  +	return NULL;
  +    return *ppArray;
  +}
  +
  +APU_DECLARE(void) ap_hook_generic(const char *szName,void (*pfn)(void),
  +				  const char * const *aszPre,
  +				  const char * const *aszSucc,int nOrder)
  +{
  +    apr_array_header_t *pArray=ap_generic_hook_get(szName);
  +    LINK__generic *pHook;
  +
  +    if(!pArray) {
  +	apr_array_header_t **ppArray;
  +
  +	pArray=apr_make_array(ap_global_hook_pool,1,sizeof(LINK__generic));
  +	if(!s_phGenericHooks)
  +	    s_phGenericHooks=apr_make_hash(ap_global_hook_pool);
  +	ppArray=apr_palloc(ap_global_hook_pool,sizeof *ppArray);
  +	*ppArray=pArray;
  +	apr_hash_set(s_phGenericHooks,szName,strlen(szName),ppArray);
  +	ap_hook_sort_register(szName,ppArray);
  +    }
  +    pHook=apr_push_array(pArray);
  +    pHook->pFunc=pfn;
  +    pHook->aszPredecessors=aszPre;
  +    pHook->aszSuccessors=aszSucc;
  +    pHook->nOrder=nOrder;
  +    pHook->szName=ap_current_hooking_module;
  +    if(ap_debug_module_hooks)
  +	ap_show_hook(szName,aszPre,aszSucc);
   }
   
   #if 0
  
  
  

Mime
View raw message