summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Fritsch <sf@apache.org>2012-02-04 09:44:19 +0000
committerStefan Fritsch <sf@apache.org>2012-02-04 09:44:19 +0000
commit1bbff8f19b416a8247bfe79ee6c5c0119d0aba19 (patch)
treef33c2bd4d14aae7e8c0a2480205b7e22d15cc738
parentd4da55ab6aa06dc38f67ec47b0e64fcc30dfec0b (diff)
downloadhttpd-1bbff8f19b416a8247bfe79ee6c5c0119d0aba19.tar.gz
Replace ap_create_core_ctx()/ap_core_ctx_get_bb() with a hook
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1240470 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--include/ap_mmn.h4
-rw-r--r--include/http_core.h29
-rw-r--r--include/httpd.h12
-rw-r--r--server/core.c17
-rw-r--r--server/core_filters.c23
-rw-r--r--server/mpm/winnt/child.c43
-rw-r--r--server/mpm/winnt/mpm_winnt.c2
-rw-r--r--server/mpm/winnt/mpm_winnt.h4
8 files changed, 74 insertions, 60 deletions
diff --git a/include/ap_mmn.h b/include/ap_mmn.h
index 3d6547d22d..b95600f4a1 100644
--- a/include/ap_mmn.h
+++ b/include/ap_mmn.h
@@ -390,12 +390,14 @@
* ap_core_ctx_get_bb(), move core_net rec definition
* to http_core.h
* 20120201.0 (2.5.0-dev) Bump MODULE_MAGIC_COOKIE to "AP25"!
+ * 20120204.0 (2.5.0-dev) Remove ap_create_core_ctx(), ap_core_ctx_get_bb();
+ * add insert_network_bucket hook, AP_DECLINED
*/
#define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
#ifndef MODULE_MAGIC_NUMBER_MAJOR
-#define MODULE_MAGIC_NUMBER_MAJOR 20120201
+#define MODULE_MAGIC_NUMBER_MAJOR 20120204
#endif
#define MODULE_MAGIC_NUMBER_MINOR 0 /* 0...n */
diff --git a/include/http_core.h b/include/http_core.h
index 485f276353..8cbedc11c3 100644
--- a/include/http_core.h
+++ b/include/http_core.h
@@ -704,24 +704,17 @@ typedef struct core_net_rec {
} core_net_rec;
/**
- * Allocate and fill the core_ctx_t for the core input filter, but don't
- * create a bucket with the input socket.
- * Normally this is done automatically when the core input filter is called
- * for the first time, but MPMs or protocol modules that need to do special
- * socket setup can call this function to do the initialization earlier.
- * They must add the input socket bucket to the core input filter's bucket
- * brigade, see ap_core_ctx_get_bb().
- * @param c The conn_rec of the connection
- * @return The core_ctx_t to be stored in core_net_rec->in_ctx
- */
-AP_DECLARE(core_ctx_t *) ap_create_core_ctx(conn_rec *c);
-
-/**
- * Accessor for the core input filter's bucket brigade
- * @param c The core_ctx_t to get the brigade from
- * @return The bucket brigade
- */
-AP_DECLARE(apr_bucket_brigade *) ap_core_ctx_get_bb(core_ctx_t *ctx);
+ * Insert the network bucket into the core input filter's input brigade.
+ * This hook is intended for MPMs or protocol modules that need to do special
+ * socket setup.
+ * @param c The connection
+ * @param bb The brigade to insert the bucket into
+ * @param socket The socket to put into a bucket
+ * @return AP_DECLINED if the current function does not handle this connection,
+ * APR_SUCCESS or an error otherwise.
+ */
+AP_DECLARE_HOOK(apr_status_t, insert_network_bucket,
+ (conn_rec *c, apr_bucket_brigade *bb, apr_socket_t *socket))
/* ----------------------------------------------------------------------
*
diff --git a/include/httpd.h b/include/httpd.h
index 9fe782d9c9..6ffdef2e17 100644
--- a/include/httpd.h
+++ b/include/httpd.h
@@ -386,6 +386,18 @@ extern "C" {
#endif
/**
+ * @defgroup APACHE_APR_STATUS_T HTTPD specific values of apr_status_t
+ * @{
+ */
+#define AP_START_USERERR (APR_OS_START_USERERR + 2000)
+#define AP_USERERR_LEN 1000
+
+/** The function declines to handle the request */
+#define AP_DECLINED (AP_START_USERERR + 0)
+
+/** @} */
+
+/**
* @brief The numeric version information is broken out into fields within this
* structure.
*/
diff --git a/server/core.c b/server/core.c
index eb8147b84c..e96eaa3cd9 100644
--- a/server/core.c
+++ b/server/core.c
@@ -82,12 +82,18 @@
APR_HOOK_STRUCT(
APR_HOOK_LINK(get_mgmt_items)
+ APR_HOOK_LINK(insert_network_bucket)
)
AP_IMPLEMENT_HOOK_RUN_ALL(int, get_mgmt_items,
(apr_pool_t *p, const char *val, apr_hash_t *ht),
(p, val, ht), OK, DECLINED)
+AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, insert_network_bucket,
+ (conn_rec *c, apr_bucket_brigade *bb,
+ apr_socket_t *socket),
+ (c, bb, socket), AP_DECLINED)
+
/* Server core module... This module provides support for really basic
* server operations, including options and commands which control the
* operation of other modules. Consider this the bureaucracy module.
@@ -4729,6 +4735,15 @@ AP_DECLARE(apr_uint32_t) ap_random_pick(apr_uint32_t min, apr_uint32_t max)
return number;
}
+static apr_status_t core_insert_network_bucket(conn_rec *c,
+ apr_bucket_brigade *bb,
+ apr_socket_t *socket)
+{
+ apr_bucket *e = apr_bucket_socket_create(socket, c->bucket_alloc);
+ APR_BRIGADE_INSERT_TAIL(bb, e);
+ return APR_SUCCESS;
+}
+
static void core_dump_config(apr_pool_t *p, server_rec *s)
{
core_server_config *sconf = ap_get_core_module_config(s->module_config);
@@ -4803,6 +4818,8 @@ static void register_hooks(apr_pool_t *p)
APR_HOOK_MIDDLE);
ap_hook_pre_mpm(ap_create_scoreboard, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_status(ap_core_child_status, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_insert_network_bucket(core_insert_network_bucket, NULL, NULL,
+ APR_HOOK_REALLY_LAST);
/* register the core's insert_filter hook and register core-provided
* filters
diff --git a/server/core_filters.c b/server/core_filters.c
index 1c783aafa7..18a32dde22 100644
--- a/server/core_filters.c
+++ b/server/core_filters.c
@@ -91,24 +91,10 @@ struct core_filter_ctx {
};
-AP_DECLARE(core_ctx_t *) ap_create_core_ctx(conn_rec *c)
-{
- core_ctx_t *ctx = apr_palloc(c->pool, sizeof(*ctx));
- ctx->b = apr_brigade_create(c->pool, c->bucket_alloc);
- ctx->tmpbb = apr_brigade_create(c->pool, c->bucket_alloc);
- return ctx;
-}
-
-AP_DECLARE(apr_bucket_brigade *) ap_core_ctx_get_bb(core_ctx_t *ctx)
-{
- return ctx->b;
-}
-
apr_status_t ap_core_input_filter(ap_filter_t *f, apr_bucket_brigade *b,
ap_input_mode_t mode, apr_read_type_e block,
apr_off_t readbytes)
{
- apr_bucket *e;
apr_status_t rv;
core_net_rec *net = f->ctx;
core_ctx_t *ctx = net->in_ctx;
@@ -131,10 +117,13 @@ apr_status_t ap_core_input_filter(ap_filter_t *f, apr_bucket_brigade *b,
if (!ctx)
{
- net->in_ctx = ctx = ap_create_core_ctx(f->c);
+ net->in_ctx = ctx = apr_palloc(f->c->pool, sizeof(*ctx));
+ ctx->b = apr_brigade_create(f->c->pool, f->c->bucket_alloc);
+ ctx->tmpbb = apr_brigade_create(f->c->pool, f->c->bucket_alloc);
/* seed the brigade with the client socket. */
- e = apr_bucket_socket_create(net->client_socket, f->c->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(ctx->b, e);
+ rv = ap_run_insert_network_bucket(f->c, ctx->b, net->client_socket);
+ if (rv != APR_SUCCESS)
+ return rv;
}
else if (APR_BRIGADE_EMPTY(ctx->b)) {
return APR_EOF;
diff --git a/server/mpm/winnt/child.c b/server/mpm/winnt/child.c
index 30a525a8a8..2e42071fed 100644
--- a/server/mpm/winnt/child.c
+++ b/server/mpm/winnt/child.c
@@ -736,6 +736,23 @@ static winnt_conn_ctx_t *winnt_get_connection(winnt_conn_ctx_t *context)
return context;
}
+apr_status_t winnt_insert_network_bucket(conn_rec *c,
+ apr_bucket_brigade *bb,
+ apr_socket_t *socket)
+{
+ apr_bucket *e;
+ winnt_conn_ctx_t *context = ap_get_module_config(c->conn_config,
+ &mpm_winnt_module);
+ if (context == NULL || (e = context->overlapped.Pointer) == NULL)
+ return AP_DECLINED;
+
+ /* seed the brigade with AcceptEx read heap bucket */
+ APR_BRIGADE_INSERT_HEAD(bb, e);
+ /* also seed the brigade with the client socket. */
+ e = apr_bucket_socket_create(socket, c->bucket_alloc);
+ APR_BRIGADE_INSERT_TAIL(bb, e);
+ return APR_SUCCESS;
+}
/*
* worker_main()
@@ -810,31 +827,9 @@ static DWORD __stdcall worker_main(void *thread_num_val)
{
apr_bucket_free(e);
}
- else if (e)
+ else
{
- core_net_rec *net;
- ap_filter_t *filt;
-
- filt = c->input_filters;
- while ((strcmp(filt->frec->name, "core_in") != 0) && filt->next)
- filt = filt->next;
- net = filt->ctx;
-
- if (net->in_ctx == NULL)
- {
- core_ctx_t *ctx = ap_create_core_ctx(c);
- apr_bucket_brigade *bb = ap_core_ctx_get_bb(ctx);
-
- /* seed the brigade with AcceptEx read heap bucket */
- e = context->overlapped.Pointer;
- APR_BRIGADE_INSERT_HEAD(bb, e);
-
- /* also seed the brigade with the client socket. */
- e = apr_bucket_socket_create(net->client_socket,
- c->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(bb, e);
- net->in_ctx = ctx;
- }
+ ap_set_module_config(c->conn_config, &mpm_winnt_module, context);
}
if (!c->aborted)
diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c
index cdf7cac640..4f6f8fe550 100644
--- a/server/mpm/winnt/mpm_winnt.c
+++ b/server/mpm/winnt/mpm_winnt.c
@@ -1758,6 +1758,8 @@ static void winnt_hooks(apr_pool_t *p)
ap_hook_mpm(winnt_run, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_mpm_query(winnt_query, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_mpm_get_name(winnt_get_name, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_insert_network_bucket(winnt_insert_network_bucket, NULL, NULL,
+ APR_HOOK_MIDDLE);
}
AP_DECLARE_MODULE(mpm_winnt) = {
diff --git a/server/mpm/winnt/mpm_winnt.h b/server/mpm/winnt/mpm_winnt.h
index 43adda994c..78962ddf6e 100644
--- a/server/mpm/winnt/mpm_winnt.h
+++ b/server/mpm/winnt/mpm_winnt.h
@@ -67,6 +67,7 @@ void mpm_nt_eventlog_stderr_flush(void);
/* From mpm_winnt.c: */
+extern module AP_MODULE_DECLARE_DATA mpm_winnt_module;
extern int ap_threads_per_child;
extern DWORD my_pid;
@@ -92,6 +93,9 @@ void hold_console_open_on_error(void);
/* From child.c: */
void child_main(apr_pool_t *pconf);
+apr_status_t winnt_insert_network_bucket(conn_rec *c,
+ apr_bucket_brigade *bb,
+ apr_socket_t *socket);
#endif /* APACHE_MPM_WINNT_H */
/** @} */