/* canonicalise each specific scheme */
if (strncasecmp(url, "http:", 5) == 0)
return ap_proxy_http_canon(r, url + 5, "http", DEFAULT_HTTP_PORT);
-#if FTP
else if (strncasecmp(url, "ftp:", 4) == 0)
return ap_proxy_ftp_canon(r, url + 4);
-#endif
p = strchr(url, ':');
if (p == NULL || p == url)
return ap_proxy_connect_handler(r, url, NULL, 0);
if (strcasecmp(scheme, "http") == 0)
return ap_proxy_http_handler(r, url, NULL, 0);
-#if FTP
if (strcasecmp(scheme, "ftp") == 0)
return ap_proxy_ftp_handler(r, url);
-#endif
else {
ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
"Neither CONNECT, HTTP or FTP for %s",
ap_hook_handler(proxy_handler, NULL, NULL, APR_HOOK_FIRST);
/* filename-to-URI translation */
ap_hook_translate_name(proxy_trans, NULL, NULL, APR_HOOK_FIRST);
-#ifdef FTP
+#ifdef FTP_FILTER
/* filters */
ap_register_output_filter("PROXY_SEND_DIR", ap_proxy_send_dir_filter, AP_FTYPE_CONNECTION);
#endif
apr_bucket *e;
apr_bucket_brigade *bb = apr_brigade_create(c->pool);
+
bb = apr_brigade_create(c->pool);
/* Tell http_filter to grab the data one line at a time. */
c->remain = 0;
ap_get_brigade(c->input_filters, bb, AP_MODE_BLOCKING);
+
+/* FIXME: When reading the initial server response to the connect, there
+ * is a hang at this point...
+ */
+
e = APR_BRIGADE_FIRST(bb);
apr_bucket_read(e, (const char **)&response, &len, APR_BLOCK_READ);
if (len == -1) {
{
apr_pool_t *p = r->pool;
apr_socket_t *sock, *local_sock, *remote_sock;
- apr_sockaddr_t *uri_addr, *connect_addr;
+ apr_sockaddr_t *connect_addr;
conn_rec *origin, *remote;
int err;
apr_bucket *e;
char *buf, *pasv, *connectname;
apr_port_t connectport;
char buffer[MAX_STRING_LEN];
-
char *path, *strp, *parms;
char *cwd = NULL;
char *user = NULL;
"proxy: FTP connecting %s to %s:%d", url, connectname, connectport);
/* do a DNS lookup for the destination host */
- err = apr_sockaddr_info_get(&uri_addr, connectname, APR_UNSPEC, connectport, 0, p);
+ err = apr_sockaddr_info_get(&connect_addr, connectname, APR_UNSPEC, connectport, 0, p);
/* check if ProxyBlock directive on this host */
- if (OK != ap_proxy_checkproxyblock(r, conf, uri_addr)) {
+ if (OK != ap_proxy_checkproxyblock(r, conf, connect_addr)) {
return ap_proxyerror(r, HTTP_FORBIDDEN,
"Connect to remote machine blocked");
}
-//return HTTP_NOT_IMPLEMENTED;
/*
* II: Make the Connection
connectname, NULL));
}
+
if ((apr_socket_create(&sock, APR_INET, SOCK_STREAM, r->pool)) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"proxy: error creating socket");
/* handle a permanent error from the above loop */
if (failed) {
apr_socket_close(sock);
- return ap_proxyerror(r, HTTP_BAD_GATEWAY, apr_pstrcat(r->pool,
- "Could not connect to remote machine: ",
- r->parsed_uri.hostname, NULL));
+ return ap_proxyerror(r, HTTP_BAD_GATEWAY, apr_psprintf(r->pool,
+ "Could not connect to remote machine: %s port %d",
+ connectname, connectport));
}
}
*/
/* set up the connection filters */
- ap_proxy_pre_http_connection(origin);
+ ap_proxy_pre_http_connection(origin, NULL);
/* possible results: */
/* 120 Service ready in nnn minutes. */
/* 220 Service ready for new user. */
/* 421 Service not available, closing control connection. */
i = ftp_getrc_msg(origin, buffer, sizeof(buffer));
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, NULL,
- "FTP: initial connect returned status %d", i);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "FTP: initial connect returned status %d", i);
if (i == -1) {
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
+return HTTP_NOT_IMPLEMENTED;
#if 0
if (i == 120) {
/* RFC2068 states:
}
/* set up the connection filters */
- ap_proxy_pre_http_connection(remote);
+ ap_proxy_pre_http_connection(remote, NULL);
/*
/* send response */
r->sent_bodyct = 1;
+#ifdef FTP_FILTER
if (parms[0] == 'd') {
/* insert directory filter */
ap_add_output_filter("PROXY_SEND_DIR", NULL, r, r->connection);
}
+#endif
/* send body */
if (!r->header_only) {
return HTTP_INTERNAL_SERVER_ERROR;
}
conf->id = r->connection->id;
- /* allocate this out of the connection pool - the check on r->connection->id makes
- * sure that this string does not live past the connection lifetime */
- conf->connectname = apr_pstrdup(r->connection->pool, connectname);
+ /* allocate this out of the config pool */
+ conf->connectname = apr_pstrdup(r->server->process->pconf, connectname);
conf->connectport = connectport;
conf->client_socket = sock;
*/
/* set up the connection filters */
- ap_proxy_pre_http_connection(origin);
+ ap_proxy_pre_http_connection(origin, NULL);
/* strip connection listed hop-by-hop headers from the request */
/* even though in theory a connection: close coming from the client
ap_get_brigade(origin->input_filters, bb, AP_MODE_BLOCKING);
e = APR_BRIGADE_FIRST(bb);
- /* XXX FIXME: a bug exists where apr_bucket_read() is returning
- * len=0 when the response line is expected... we try it up to
- * 5 times - this has not fixed the problem though.
- */
i = 5;
len = 0;
while (!len && i--) {
APR_BRIGADE_INSERT_TAIL(bb, e);
}
-/* XXX FIXME - what about 304 et al responses that have no body and no content-length? */
/* send body */
if (!r->header_only) {
const char *buf;
}
/* set up the minimal filter set */
-int ap_proxy_pre_http_connection(conn_rec *c)
+int ap_proxy_pre_http_connection(conn_rec *c, request_rec *r)
{
- ap_add_input_filter("HTTP_IN", NULL, NULL, c);
- ap_add_input_filter("CORE_IN", NULL, NULL, c);
- ap_add_output_filter("CORE", NULL, NULL, c);
+ ap_add_input_filter("HTTP_IN", NULL, r, c);
+ ap_add_input_filter("CORE_IN", NULL, r, c);
+ ap_add_output_filter("CORE", NULL, r, c);
return OK;
}