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;
"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,
}
/* 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);
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;
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)
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;
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);
/*
}
/* 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 */
/* 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;
}
}
/* 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 */
}
}
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));
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;
}
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.
*/
/* 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) &&
" 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;
}
}
/* use previous keepalive socket */
*origin = backend->connection;
- p_conn->sock = (*origin)->client_socket;
+ p_conn->sock = client_socket;
new = 0;
/* reset the connection filters */
"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()
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;