From 62ccd6ca6a236fcba254f7c5a482ac33569a3f8b Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Wed, 11 Aug 2004 22:36:28 +0000 Subject: [PATCH] Added ap_proxy_connection_create function that makes conn_rec for opened connection. It is used bt http(s) and ftp for bounding the backend connection to client connection with the same id's. Submitted by: mturk git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@104597 13f79535-47bb-0310-9956-ffa450edef68 --- modules/proxy/mod_proxy.h | 3 +- modules/proxy/proxy_util.c | 69 +++++++++++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 58f9befc31..4002c6f37b 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -364,7 +364,8 @@ PROXY_DECLARE(apr_status_t) ap_proxy_destroy_connection(proxy_conn_rec *conn); PROXY_DECLARE(apr_status_t) ap_proxy_close_connection(proxy_conn_rec *conn); PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function, proxy_conn_rec *conn, proxy_worker *worker, proxy_server_conf *conf, server_rec *s); - +PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function, proxy_conn_rec *conn, + proxy_server_conf *conf, conn_rec *c, server_rec *s); /* For proxy_util */ extern module PROXY_DECLARE_DATA proxy_module; diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 9cbd1937e2..4546ef653e 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -1636,9 +1636,70 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function, backend_addr = backend_addr->next; continue; } - conn->sock = newsock; - conn->worker = worker; - connected = 1; + + conn->sock = newsock; + conn->worker = worker; + /* XXX: the hostname will go from proxy_conn_rec + * keep for now. + * We will 'optimize' later, both code and unneeded data + */ + conn->hostname = worker->hostname; + connected = 1; } - return connected ? 0 : 1; + return connected ? OK : DECLINED; +} + +PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function, + proxy_conn_rec *conn, + proxy_server_conf *conf, + conn_rec *c, + server_rec *s) +{ + proxy_worker *worker = conn->worker; + apr_sockaddr_t *backend_addr = worker->cp->addr; + + /* The socket is now open, create a new backend server connection + * + */ + conn->connection = ap_run_create_connection(c->pool, s, conn->sock, + c->id, c->sbh, + c->bucket_alloc); + + if (!conn->connection) { + /* the peer reset the connection already; ap_run_create_connection() + * closed the socket + */ + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, + s, "proxy: %s: an error occurred creating a " + "new connection to %pI (%s)", proxy_function, + backend_addr, conn->hostname); + /* XXX: Will be closed when proxy_conn is closed */ + apr_socket_close(conn->sock); + conn->sock = NULL; + return HTTP_INTERNAL_SERVER_ERROR; + } + + /* For ssl connection to backend */ + if (conn->is_ssl) { + if (!ap_proxy_ssl_enable(conn->connection)) { + ap_log_error(APLOG_MARK, APLOG_ERR, 0, + s, "proxy: %s: failed to enable ssl support " + "for %pI (%s)", proxy_function, + backend_addr, conn->hostname); + return HTTP_INTERNAL_SERVER_ERROR; + } + } + else { + /* TODO: See if this will break FTP */ + ap_proxy_ssl_disable(conn->connection); + } + + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, + "proxy: %s: connection complete to %pI (%s)", + proxy_function, backend_addr, conn->hostname); + + /* set up the connection filters */ + ap_run_pre_connection(conn->connection, conn->sock); + + return OK; } -- 2.40.0