From 8a697835fe5b90c62d65f941ad0c4a9c5c7d9f87 Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Wed, 14 Nov 2001 21:18:47 +0000 Subject: [PATCH] Get the proxy module compiling again. This is a hack to get past the current compiler errors. Basically, the core now puts the socket in the conn_rec->conn_config vector. The proxy grabs that socket and uses it where it used to use the client_socket field from the conn_rec. Long-term, all of the direct socket communication needs to be removed, and this should go through a filter stack. Short-term, this gets the proxy working again. I have tested http and connect, but I haven't looked at the FTP proxy, although it does compile now. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@91952 13f79535-47bb-0310-9956-ffa450edef68 --- modules/proxy/proxy_connect.c | 26 +++++++++++++++++++++----- modules/proxy/proxy_ftp.c | 12 +++++++----- modules/proxy/proxy_http.c | 8 +++++--- server/core.c | 1 + 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/modules/proxy/proxy_connect.c b/modules/proxy/proxy_connect.c index 218b33265f..2b4df9f968 100644 --- a/modules/proxy/proxy_connect.c +++ b/modules/proxy/proxy_connect.c @@ -128,6 +128,7 @@ int ap_proxy_connect_handler(request_rec *r, proxy_server_conf *conf, apr_status_t err, rv; apr_size_t i, o, nbytes; char buffer[HUGE_STRING_LEN]; + apr_socket_t *client_socket = ap_get_module_config(r->connection->conn_config, &core_module); apr_pollfd_t *pollfd; apr_int32_t pollcnt; @@ -305,10 +306,19 @@ int ap_proxy_connect_handler(request_rec *r, proxy_server_conf *conf, "proxy: CONNECT: Returning 200 OK Status"); nbytes = apr_snprintf(buffer, sizeof(buffer), "HTTP/1.0 200 Connection Established" CRLF); - apr_send(r->connection->client_socket, buffer, &nbytes); + apr_send(client_socket, buffer, &nbytes); nbytes = apr_snprintf(buffer, sizeof(buffer), "Proxy-agent: %s" CRLF CRLF, ap_get_server_version()); +#if 0 + /* This is safer code, but it doesn't work yet. I'm leaving it + * here so that I can fix it later. + */ apr_send(r->connection->client_socket, buffer, &nbytes); + r->status = HTTP_OK; + r->header_only = 1; + apr_table_set(r->headers_out, "Proxy-agent: %s", ap_get_server_version()); + ap_rflush(r); +#endif } ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server, @@ -331,7 +341,7 @@ int ap_proxy_connect_handler(request_rec *r, proxy_server_conf *conf, } /* Add client side to the poll */ - apr_poll_socket_add(pollfd, r->connection->client_socket, APR_POLLIN); + apr_poll_socket_add(pollfd, client_socket, APR_POLLIN); /* Add the server side to the poll */ apr_poll_socket_add(pollfd, sock, APR_POLLIN); @@ -359,7 +369,13 @@ int ap_proxy_connect_handler(request_rec *r, proxy_server_conf *conf, while(i > 0) { nbytes = i; - if (apr_send(r->connection->client_socket, buffer + o, &nbytes) != APR_SUCCESS) + /* This is just plain wrong. No module should ever write directly + * to the client. For now, this works, but this is high on my list of + * things to fix. The correct line is: + * if ((nbytes = ap_rwrite(buffer + o, nbytes, r)) < 0) + * rbb + */ + if (apr_send(client_socket, buffer + o, &nbytes) != APR_SUCCESS) break; o += nbytes; i -= nbytes; @@ -372,12 +388,12 @@ int ap_proxy_connect_handler(request_rec *r, proxy_server_conf *conf, break; - apr_poll_revents_get(&pollevent, r->connection->client_socket, pollfd); + apr_poll_revents_get(&pollevent, client_socket, pollfd); if (pollevent & APR_POLLIN) { /* ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server, "proxy: CONNECT: client was set");*/ nbytes = sizeof(buffer); - if (apr_recv(r->connection->client_socket, buffer, &nbytes) == APR_SUCCESS) { + if (apr_recv(client_socket, buffer, &nbytes) == APR_SUCCESS) { o = 0; i = nbytes; while(i > 0) diff --git a/modules/proxy/proxy_ftp.c b/modules/proxy/proxy_ftp.c index 1c505809e1..7748a3d587 100644 --- a/modules/proxy/proxy_ftp.c +++ b/modules/proxy/proxy_ftp.c @@ -556,6 +556,7 @@ int ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf, int one = 1; char *size = NULL; apr_off_t readbytes = -1; + apr_socket_t *origin_sock; /* stuff for PASV mode */ int connect = 0, use_port = 0; @@ -584,6 +585,7 @@ int ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf, backend->port = 0; ap_set_module_config(c->conn_config, &proxy_ftp_module, backend); } + origin_sock = ap_get_module_config(backend->connection->conn_config, &core_module); /* @@ -745,7 +747,7 @@ int ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf, } /* the socket is now open, create a new connection */ - origin = ap_new_connection(p, r->server, sock, r->connection->id); + origin = ap_run_create_connection(p, r->server, sock, r->connection->id); if (!origin) { /* the peer reset the connection already; ap_new_connection() * closed the socket */ @@ -757,7 +759,7 @@ int ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf, /* if a keepalive connection is floating around, close it first! */ /* we might support ftp keepalives later, but not now... */ if (backend->connection) { - apr_socket_close(backend->connection->client_socket); + apr_socket_close(origin_sock); backend->connection = NULL; } @@ -1548,7 +1550,7 @@ int ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf, } /* the transfer socket is now open, create a new connection */ - remote = ap_new_connection(p, r->server, remote_sock, r->connection->id); + remote = ap_run_create_connection(p, r->server, remote_sock, r->connection->id); if (!remote) { /* the peer reset the connection already; ap_new_connection() * closed the socket */ @@ -1597,7 +1599,7 @@ int ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf, } } ap_flush_conn(remote); - apr_socket_close(remote->client_socket); + apr_socket_close(remote_sock); ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server, "proxy: FTP: Closing Data connection."); rc = ftp_getrc_msg(origin, cbb, buffer, sizeof(buffer)); @@ -1632,7 +1634,7 @@ int ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf, ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server, "proxy: FTP: %d %s", rc, buffer); ap_flush_conn(origin); - apr_socket_close(origin->client_socket); + apr_socket_close(origin_sock); apr_brigade_destroy(bb); return OK; } diff --git a/modules/proxy/proxy_http.c b/modules/proxy/proxy_http.c index 40659e6fbe..e74dfd19e5 100644 --- a/modules/proxy/proxy_http.c +++ b/modules/proxy/proxy_http.c @@ -276,6 +276,7 @@ apr_status_t ap_proxy_http_create_connection(apr_pool_t *p, request_rec *r, const char *proxyname) { int failed=0, new=0; apr_status_t rv; + apr_socket_t *client_socket; /* We have determined who to connect to. Now make the connection, supporting * a KeepAlive connection. @@ -290,6 +291,7 @@ apr_status_t ap_proxy_http_create_connection(apr_pool_t *p, request_rec *r, */ /* see memory note above */ if (backend->connection) { + client_socket = ap_get_module_config(backend->connection->conn_config, &core_module);; if ((backend->connection->id == c->id) && (backend->port == p_conn->port) && (backend->hostname) && @@ -302,7 +304,7 @@ apr_status_t ap_proxy_http_create_connection(apr_pool_t *p, request_rec *r, " changed (close old socket (%s/%s, %d/%d))", p_conn->name, backend->hostname, p_conn->port, backend->port); - apr_socket_close(backend->connection->client_socket); + apr_socket_close(client_socket); backend->connection = NULL; } } @@ -317,7 +319,7 @@ apr_status_t ap_proxy_http_create_connection(apr_pool_t *p, request_rec *r, /* use previous keepalive socket */ *origin = backend->connection; - p_conn->sock = (*origin)->client_socket; + p_conn->sock = client_socket; new = 0; /* reset the connection filters */ @@ -412,7 +414,7 @@ apr_status_t ap_proxy_http_create_connection(apr_pool_t *p, request_rec *r, "proxy: socket is connected"); /* the socket is now open, create a new backend server connection */ - *origin = ap_new_connection(c->pool, r->server, p_conn->sock, + *origin = ap_run_create_connection(c->pool, r->server, p_conn->sock, r->connection->id); if (!origin) { /* the peer reset the connection already; ap_new_connection() diff --git a/server/core.c b/server/core.c index 1209cf545a..8b37a810df 100644 --- a/server/core.c +++ b/server/core.c @@ -3324,6 +3324,7 @@ static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *server, apr_pool_cleanup_register(ptrans, net, ap_lingering_close, apr_pool_cleanup_null); + ap_set_module_config(net->c->conn_config, &core_module, csd); ap_add_input_filter("CORE_IN", net, NULL, net->c); ap_add_output_filter("CORE", net, NULL, net->c); return net->c; -- 2.40.0