ben 01/01/27 09:50:49
Modified: . CHANGES
include http_config.h
modules/experimental config.m4
server config.c main.c
hooks apr_hooks.c
Added: modules/experimental mod_optional_fn_export.c
mod_optional_fn_export.h mod_optional_fn_import.c
include apr_optional.h
Log:
Add support for type-safe optional functions.
Revision Changes Path
1.56 +5 -0 httpd-2.0/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/httpd-2.0/CHANGES,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- CHANGES 2001/01/27 07:13:38 1.55
+++ CHANGES 2001/01/27 17:50:43 1.56
@@ -1,5 +1,10 @@
Changes with Apache 2.0b1
+ *) Support for typedsafe optional functions - that is functions exported by
+ optional modules, which, therefore, may or may not be present, depending
+ on configuration. See the experimental modules
mod_optional_fn_{ex,im}port
+ for sample code. [Ben Laurie]
+
*) filters can now report an HTTP error to the server. This is done
by sending a brigade where the first bucket is an error_bucket.
This bucket is a simple bucket that stores an HTTP error and
1.61 +8 -0 httpd-2.0/include/http_config.h
Index: http_config.h
===================================================================
RCS file: /home/cvs/httpd-2.0/include/http_config.h,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- http_config.h 2001/01/21 22:14:14 1.60
+++ http_config.h 2001/01/27 17:50:44 1.61
@@ -1001,6 +1001,14 @@
*/
AP_DECLARE_HOOK(int,handler,(request_rec *))
+/**
+ * Retrieve the optional functions for each module.
+ * This is run immediately before the server starts. Optional functions
should
+ * be registered during the hook registration phase.
+ * @deffunc void ap_run_optional_fn_retrieve(void)
+ */
+AP_DECLARE_HOOK(void,optional_fn_retrieve,(void))
+
#ifdef __cplusplus
}
#endif
1.6 +2 -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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- config.m4 2001/01/02 17:41:31 1.5
+++ config.m4 2001/01/27 17:50:45 1.6
@@ -8,5 +8,7 @@
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_MODULE(optional_fn_import, example optional function importer, , , no)
+APACHE_MODULE(optional_fn_export, example optional function exporter, , , no)
APACHE_MODPATH_FINISH
1.1 httpd-2.0/modules/experimental/mod_optional_fn_export.c
Index: mod_optional_fn_export.c
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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_optional_fn_export.h"
/* The alert will note a strange mirror-image style resemblance to
* mod_generic_hook_import.c. Yes, I _did_ mean import. Think about it.
*/
static int TestOptionalFn(const char *szStr)
{
ap_log_error(APLOG_MARK,APLOG_ERR,OK,NULL,
"Optional function test said: %s",szStr);
return OK;
}
static void ExportRegisterHooks(apr_pool_t *p)
{
APR_REGISTER_OPTIONAL_FN(TestOptionalFn);
}
module optional_fn_export_module=
{
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
ExportRegisterHooks
};
1.1 httpd-2.0/modules/experimental/mod_optional_fn_export.h
Index: mod_optional_fn_export.h
===================================================================
#include "apr_optional.h"
APR_DECLARE_OPTIONAL_FN(int,TestOptionalFn,(const char *))
1.1 httpd-2.0/modules/experimental/mod_optional_fn_import.c
Index: mod_optional_fn_import.c
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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_optional_fn_export.h"
#include "http_protocol.h"
/* The alert will note a strange mirror-image style resemblance to
* mod_generic_hook_export.c. Yes, I _did_ mean export. Think about it.
*/
static APR_OPTIONAL_FN_TYPE(TestOptionalFn) *pfn;
static int ImportLogTransaction(request_rec *r)
{
if(pfn)
return pfn(r->the_request);
return DECLINED;
}
void ImportFnRetrieve(void)
{
pfn=APR_RETRIEVE_OPTIONAL_FN(TestOptionalFn);
}
static void ImportRegisterHooks(apr_pool_t *p)
{
ap_hook_log_transaction(ImportLogTransaction,NULL,NULL,APR_HOOK_MIDDLE);
ap_hook_optional_fn_retrieve(ImportFnRetrieve,NULL,NULL,APR_HOOK_MIDDLE);
}
module optional_fn_import_module =
{
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
ImportRegisterHooks
};
1.107 +3 -0 httpd-2.0/server/config.c
Index: config.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/config.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -r1.106 -r1.107
--- config.c 2001/01/24 22:52:52 1.106
+++ config.c 2001/01/27 17:50:47 1.107
@@ -116,6 +116,7 @@
APR_HOOK_LINK(open_logs)
APR_HOOK_LINK(child_init)
APR_HOOK_LINK(handler)
+ APR_HOOK_LINK(optional_fn_retrieve)
)
AP_IMPLEMENT_HOOK_RUN_ALL(int,header_parser,
@@ -134,6 +135,8 @@
AP_IMPLEMENT_HOOK_RUN_FIRST(int,handler,(request_rec *r),
(r),DECLINED)
+
+AP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve,(void),())
/****************************************************************
*
1.87 +2 -0 httpd-2.0/server/main.c
Index: main.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/main.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -r1.86 -r1.87
--- main.c 2001/01/21 05:26:45 1.86
+++ main.c 2001/01/27 17:50:47 1.87
@@ -426,6 +426,8 @@
ap_post_config_hook(pconf, plog, ptemp, server_conf);
apr_destroy_pool(ptemp);
+ ap_run_optional_fn_retrieve();
+
if (ap_mpm_run(pconf, plog, server_conf)) break;
}
destroy_and_exit_process(process, 0);
1.32 +22 -0 apr-util/hooks/apr_hooks.c
Index: apr_hooks.c
===================================================================
RCS file: /home/cvs/apr-util/hooks/apr_hooks.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- apr_hooks.c 2001/01/24 22:52:54 1.31
+++ apr_hooks.c 2001/01/27 17:50:48 1.32
@@ -62,6 +62,7 @@
#include "apr_hooks.h"
#include "apr_hash.h"
#include "apr_generic_hook.h"
+#include "apr_optional.h"
#if APR_HAVE_STRINGS_H
#include <strings.h>
@@ -237,6 +238,7 @@
}
static apr_hash_t *s_phGenericHooks;
+static apr_hash_t *s_phOptionalFunctions;
APU_DECLARE(void) apr_hook_deregister_all(void)
{
@@ -248,6 +250,7 @@
}
s_aHooksToSort=NULL;
s_phGenericHooks=NULL;
+ s_phOptionalFunctions=NULL;
}
APU_DECLARE(void) apr_show_hook(const char *szName,const char * const
*aszPre,
@@ -325,6 +328,25 @@
pHook->szName=apr_current_hooking_module;
if(apr_debug_module_hooks)
apr_show_hook(szName,aszPre,aszSucc);
+}
+
+/* optional function support */
+
+void (*apr_retrieve_optional_fn(const char *szName))(void)
+{
+ void (*pfn)(void);
+
+ if(!s_phOptionalFunctions)
+ return NULL;
+ return apr_hash_get(s_phOptionalFunctions,szName,strlen(szName));
+}
+
+APU_DECLARE(void) apr_register_optional_fn(const char *szName,
+ void (*pfn)(void))
+{
+ if(!s_phOptionalFunctions)
+ s_phOptionalFunctions=apr_make_hash(apr_global_hook_pool);
+ apr_hash_set(s_phOptionalFunctions,szName,strlen(szName),pfn);
}
#if 0
1.1 apr-util/include/apr_optional.h
Index: apr_optional.h
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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/>.
*/
/*
* Typesafe registration and retrieval of functions that may not be present
* (i.e. functions exported by optional modules)
*/
/**
* The type of an optional function.
* @param name The name of the function
*/
#define APR_OPTIONAL_FN_TYPE(name) apr_OFN_##name##_t
/**
* Declare an optional function.
* @param ret The return type of the function
* @param name The name of the function
* @param args The function arguments (including brackets)
*/
#define APR_DECLARE_OPTIONAL_FN(ret,name,args) \
typedef ret APR_OPTIONAL_FN_TYPE(name) args;
/* Private function! DO NOT USE! */
void apr_register_optional_fn(const char *szName,void (*pfn)(void));
/**
* Register an optional function. This can be later retrieved, type-safely, by
* name. Like all global functions, the name must be unique. Note that,
* confusingly but correctly, the function itself can be static!
* @param name The name of the function
*/
#define APR_REGISTER_OPTIONAL_FN(name) \
((void (*)(const char *,APR_OPTIONAL_FN_TYPE(name)
*))&apr_register_optional_fn)(#name,name)
/* Private function! DO NOT USE! */
void (*apr_retrieve_optional_fn(const char *szName))(void);
/**
* Retrieve an optional function. Returns NULL if the function is not present.
* @param name The name of the function
*/
#define APR_RETRIEVE_OPTIONAL_FN(name) \
(APR_OPTIONAL_FN_TYPE(name) *)apr_retrieve_optional_fn(#name)