summaryrefslogtreecommitdiff
path: root/modules/http/http_core.c
diff options
context:
space:
mode:
authorArno Töll <debian@toell.net>2012-01-08 22:53:17 +0100
committerArno Töll <debian@toell.net>2012-01-08 22:53:17 +0100
commite072a2dd866b7cb9f14319b80326a4e7fd16fcdf (patch)
treea49dfc56d94a26011fe157835ff6cbe14edbd8a9 /modules/http/http_core.c
parent0890390c00801651d08d3794e13b31a5dabbf5ef (diff)
downloadapache2-e072a2dd866b7cb9f14319b80326a4e7fd16fcdf.tar.gz
Imported Upstream version 2.3.16-beta
Diffstat (limited to 'modules/http/http_core.c')
-rw-r--r--modules/http/http_core.c154
1 files changed, 87 insertions, 67 deletions
diff --git a/modules/http/http_core.c b/modules/http/http_core.c
index be1e1138..663810a5 100644
--- a/modules/http/http_core.c
+++ b/modules/http/http_core.c
@@ -20,7 +20,6 @@
#define APR_WANT_STRFUNC
#include "apr_want.h"
-#define CORE_PRIVATE
#include "httpd.h"
#include "http_config.h"
#include "http_connection.h"
@@ -42,44 +41,45 @@ AP_DECLARE_DATA ap_filter_rec_t *ap_chunk_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_http_outerror_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_byterange_filter_handle;
-static int ap_process_http_connection(conn_rec *c);
+AP_DECLARE_DATA const char *ap_multipart_boundary;
+
+/* If we are using an MPM That Supports Async Connections,
+ * use a different processing function
+ */
+static int async_mpm = 0;
static const char *set_keep_alive_timeout(cmd_parms *cmd, void *dummy,
const char *arg)
{
- const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
+ apr_interval_time_t timeout;
+ const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
if (err != NULL) {
return err;
}
- cmd->server->keep_alive_timeout = apr_time_from_sec(atoi(arg));
+ /* Stolen from mod_proxy.c */
+ if (ap_timeout_parameter_parse(arg, &timeout, "s") != APR_SUCCESS)
+ return "KeepAliveTimeout has wrong format";
+ cmd->server->keep_alive_timeout = timeout;
return NULL;
}
static const char *set_keep_alive(cmd_parms *cmd, void *dummy,
- const char *arg)
+ int arg)
{
- const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
+ const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
if (err != NULL) {
return err;
}
- /* We've changed it to On/Off, but used to use numbers
- * so we accept anything but "Off" or "0" as "On"
- */
- if (!strcasecmp(arg, "off") || !strcmp(arg, "0")) {
- cmd->server->keep_alive = 0;
- }
- else {
- cmd->server->keep_alive = 1;
- }
+ cmd->server->keep_alive = arg;
return NULL;
}
static const char *set_keep_alive_max(cmd_parms *cmd, void *dummy,
const char *arg)
{
- const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
+ const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
if (err != NULL) {
return err;
}
@@ -94,21 +94,21 @@ static const command_rec http_cmds[] = {
AP_INIT_TAKE1("MaxKeepAliveRequests", set_keep_alive_max, NULL, RSRC_CONF,
"Maximum number of Keep-Alive requests per connection, "
"or 0 for infinite"),
- AP_INIT_TAKE1("KeepAlive", set_keep_alive, NULL, RSRC_CONF,
+ AP_INIT_FLAG("KeepAlive", set_keep_alive, NULL, RSRC_CONF,
"Whether persistent connections should be On or Off"),
{ NULL }
};
static const char *http_scheme(const request_rec *r)
{
- /*
- * The http module shouldn't return anything other than
+ /*
+ * The http module shouldn't return anything other than
* "http" (the default) or "https".
*/
if (r->server->server_scheme &&
(strcmp(r->server->server_scheme, "https") == 0))
return "https";
-
+
return "http";
}
@@ -117,7 +117,7 @@ static apr_port_t http_port(const request_rec *r)
if (r->server->server_scheme &&
(strcmp(r->server->server_scheme, "https") == 0))
return DEFAULT_HTTPS_PORT;
-
+
return DEFAULT_HTTP_PORT;
}
@@ -126,14 +126,11 @@ static int ap_process_http_async_connection(conn_rec *c)
request_rec *r;
conn_state_t *cs = c->cs;
- if (c->clogging_input_filters) {
- return ap_process_http_connection(c);
- }
-
+ AP_DEBUG_ASSERT(cs != NULL);
AP_DEBUG_ASSERT(cs->state == CONN_STATE_READ_REQUEST_LINE);
while (cs->state == CONN_STATE_READ_REQUEST_LINE) {
- ap_update_child_status(c->sbh, SERVER_BUSY_READ, NULL);
+ ap_update_child_status_from_conn(c->sbh, SERVER_BUSY_READ, c);
if ((r = ap_read_request(c))) {
@@ -141,25 +138,24 @@ static int ap_process_http_async_connection(conn_rec *c)
/* process the request if it was read without error */
ap_update_child_status(c->sbh, SERVER_BUSY_WRITE, r);
- if (r->status == HTTP_OK)
- ap_process_request(r);
-
- if (ap_extended_status)
- ap_increment_counts(c->sbh, r);
+ if (r->status == HTTP_OK) {
+ cs->state = CONN_STATE_HANDLER;
+ ap_process_async_request(r);
+ /* After the call to ap_process_request, the
+ * request pool may have been deleted. We set
+ * r=NULL here to ensure that any dereference
+ * of r that might be added later in this function
+ * will result in a segfault immediately instead
+ * of nondeterministic failures later.
+ */
+ r = NULL;
+ }
- if (c->keepalive != AP_CONN_KEEPALIVE || c->aborted
- || ap_graceful_stop_signalled()) {
+ if (cs->state != CONN_STATE_WRITE_COMPLETION &&
+ cs->state != CONN_STATE_SUSPENDED) {
+ /* Something went wrong; close the connection */
cs->state = CONN_STATE_LINGER;
}
- else if (!c->data_in_input_filters) {
- cs->state = CONN_STATE_CHECK_REQUEST_LINE_READABLE;
- }
-
- /* else we are pipelining. Stay in READ_REQUEST_LINE state
- * and stay in the loop
- */
-
- apr_pool_destroy(r->pool);
}
else { /* ap_read_request failed - client may have closed */
cs->state = CONN_STATE_LINGER;
@@ -169,40 +165,54 @@ static int ap_process_http_async_connection(conn_rec *c)
return OK;
}
-static int ap_process_http_connection(conn_rec *c)
+static int ap_process_http_sync_connection(conn_rec *c)
{
request_rec *r;
+ conn_state_t *cs = c->cs;
apr_socket_t *csd = NULL;
+ int mpm_state = 0;
/*
* Read and process each request found on our connection
* until no requests are left or we decide to close.
*/
- ap_update_child_status(c->sbh, SERVER_BUSY_READ, NULL);
+ ap_update_child_status_from_conn(c->sbh, SERVER_BUSY_READ, c);
while ((r = ap_read_request(c)) != NULL) {
c->keepalive = AP_CONN_UNKNOWN;
/* process the request if it was read without error */
ap_update_child_status(c->sbh, SERVER_BUSY_WRITE, r);
- if (r->status == HTTP_OK)
+ if (r->status == HTTP_OK) {
+ if (cs)
+ cs->state = CONN_STATE_HANDLER;
ap_process_request(r);
-
- if (ap_extended_status)
- ap_increment_counts(c->sbh, r);
+ /* After the call to ap_process_request, the
+ * request pool will have been deleted. We set
+ * r=NULL here to ensure that any dereference
+ * of r that might be added later in this function
+ * will result in a segfault immediately instead
+ * of nondeterministic failures later.
+ */
+ r = NULL;
+ }
if (c->keepalive != AP_CONN_KEEPALIVE || c->aborted)
break;
- ap_update_child_status(c->sbh, SERVER_BUSY_KEEPALIVE, r);
- apr_pool_destroy(r->pool);
+ ap_update_child_status(c->sbh, SERVER_BUSY_KEEPALIVE, NULL);
- if (ap_graceful_stop_signalled())
+ if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state)) {
break;
+ }
+
+ if (mpm_state == AP_MPMQ_STOPPING) {
+ break;
+ }
if (!csd) {
- csd = ap_get_module_config(c->conn_config, &core_module);
+ csd = ap_get_conn_socket(c);
}
apr_socket_opt_set(csd, APR_INCOMPLETE_READ, 1);
apr_socket_timeout_set(csd, c->base_server->keep_alive_timeout);
@@ -212,6 +222,16 @@ static int ap_process_http_connection(conn_rec *c)
return OK;
}
+static int ap_process_http_connection(conn_rec *c)
+{
+ if (async_mpm && !c->clogging_input_filters) {
+ return ap_process_http_async_connection(c);
+ }
+ else {
+ return ap_process_http_sync_connection(c);
+ }
+}
+
static int http_create_request(request_rec *r)
{
if (!r->main && !r->prev) {
@@ -237,23 +257,23 @@ static int http_send_options(request_rec *r)
return DECLINED;
}
-static void register_hooks(apr_pool_t *p)
+static int http_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
- /**
- * If we ae using an MPM That Supports Async Connections,
- * use a different processing function
- */
- int async_mpm = 0;
- if (ap_mpm_query(AP_MPMQ_IS_ASYNC, &async_mpm) == APR_SUCCESS
- && async_mpm == 1) {
- ap_hook_process_connection(ap_process_http_async_connection, NULL,
- NULL, APR_HOOK_REALLY_LAST);
- }
- else {
- ap_hook_process_connection(ap_process_http_connection, NULL, NULL,
- APR_HOOK_REALLY_LAST);
+ apr_uint64_t val;
+ if (ap_mpm_query(AP_MPMQ_IS_ASYNC, &async_mpm) != APR_SUCCESS) {
+ async_mpm = 0;
}
+ ap_random_insecure_bytes(&val, sizeof(val));
+ ap_multipart_boundary = apr_psprintf(p, "%0" APR_UINT64_T_HEX_FMT, val);
+ return OK;
+}
+
+static void register_hooks(apr_pool_t *p)
+{
+ ap_hook_post_config(http_post_config, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_process_connection(ap_process_http_connection, NULL, NULL,
+ APR_HOOK_REALLY_LAST);
ap_hook_map_to_storage(ap_send_http_trace,NULL,NULL,APR_HOOK_MIDDLE);
ap_hook_map_to_storage(http_send_options,NULL,NULL,APR_HOOK_MIDDLE);
ap_hook_http_scheme(http_scheme,NULL,NULL,APR_HOOK_REALLY_LAST);
@@ -277,7 +297,7 @@ static void register_hooks(apr_pool_t *p)
ap_method_registry_init(p);
}
-module AP_MODULE_DECLARE_DATA http_module = {
+AP_DECLARE_MODULE(http) = {
STANDARD20_MODULE_STUFF,
NULL, /* create per-directory config structure */
NULL, /* merge per-directory config structures */