You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by mi...@apache.org on 2001/04/06 12:44:10 UTC
cvs commit: httpd-proxy/module-2.0 mod_proxy.c mod_proxy.h proxy_connect.c proxy_ftp.c proxy_http.c proxy_util.c
minfrin 01/04/06 03:44:10
Modified: . CHANGES
module-2.0 mod_proxy.c mod_proxy.h proxy_connect.c
proxy_ftp.c proxy_http.c proxy_util.c
Log:
Converted send_dir() to ap_proxy_send_dir_filter() in proxy_ftp.c.
Fixed up the header files
Revision Changes Path
1.17 +3 -0 httpd-proxy/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/httpd-proxy/CHANGES,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- CHANGES 2001/04/05 21:27:50 1.16
+++ CHANGES 2001/04/06 10:44:06 1.17
@@ -1,6 +1,9 @@
mod_proxy changes for 2.0.15 current
+ *) Converted send_dir() to ap_proxy_send_dir_filter() in proxy_ftp.c.
+ [Graham Leggett <mi...@sharp.fm>]
+
*) Major rework of ap_proxy_ftp_handler() to use filters (begone foul
BUFF!!!). It compiles, but is untested, and the build environment needs
to be fixed to include proxy_ftp.c.
1.34 +12 -30 httpd-proxy/module-2.0/mod_proxy.c
Index: mod_proxy.c
===================================================================
RCS file: /home/cvs/httpd-proxy/module-2.0/mod_proxy.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- mod_proxy.c 2001/04/05 18:53:04 1.33
+++ mod_proxy.c 2001/04/06 10:44:07 1.34
@@ -58,29 +58,6 @@
#include "mod_proxy.h"
-#define CORE_PRIVATE
-
-#include "http_log.h"
-#include "http_vhost.h"
-#include "http_request.h"
-#include "util_date.h"
-#include "mod_core.h"
-
-/* Some WWW schemes and their default ports; this is basically /etc/services */
-/* This will become global when the protocol abstraction comes */
-static struct proxy_services defports[] =
-{
- {"http", DEFAULT_HTTP_PORT},
- {"ftp", DEFAULT_FTP_PORT},
- {"https", DEFAULT_HTTPS_PORT},
- {"gopher", DEFAULT_GOPHER_PORT},
- {"nntp", DEFAULT_NNTP_PORT},
- {"wais", DEFAULT_WAIS_PORT},
- {"snews", DEFAULT_SNEWS_PORT},
- {"prospero", DEFAULT_PROSPERO_PORT},
- {NULL, -1} /* unknown port */
-};
-
/*
* A Web proxy module. Stages:
*
@@ -476,14 +453,19 @@
(proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
struct proxy_remote *new;
char *p, *q;
- char *r, *f;
+ char *r, *f, *scheme;
int port;
r = apr_pstrdup(cmd->pool, r1);
+ scheme = apr_pstrdup(cmd->pool, r1);
f = apr_pstrdup(cmd->pool, f1);
p = strchr(r, ':');
- if (p == NULL || p[1] != '/' || p[2] != '/' || p[3] == '\0')
+ if (p == NULL || p[1] != '/' || p[2] != '/' || p[3] == '\0') {
return "ProxyRemote: Bad syntax for a remote proxy server";
+ }
+ else {
+ scheme[p-r] = 0;
+ }
q = strchr(p + 3, ':');
if (q != NULL) {
if (sscanf(q + 1, "%u", &port) != 1 || port > 65535)
@@ -498,11 +480,7 @@
ap_str_tolower(p + 3); /* lowercase hostname */
if (port == -1) {
- int i;
- for (i = 0; defports[i].scheme != NULL; i++)
- if (strcasecmp(defports[i].scheme, r) == 0)
- break;
- port = defports[i].port;
+ port = ap_default_port_for_scheme(scheme);
}
new = apr_array_push(conf->proxies);
@@ -743,6 +721,10 @@
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
+ /* filters */
+ ap_register_output_filter("PROXY_SEND_DIR", ap_proxy_send_dir_filter, AP_FTYPE_CONNECTION);
+#endif
/* fixups */
ap_hook_fixups(proxy_fixup, NULL, NULL, APR_HOOK_FIRST);
/* post read_request handling */
1.34 +29 -16 httpd-proxy/module-2.0/mod_proxy.h
Index: mod_proxy.h
===================================================================
RCS file: /home/cvs/httpd-proxy/module-2.0/mod_proxy.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- mod_proxy.h 2001/04/05 18:53:04 1.33
+++ mod_proxy.h 2001/04/06 10:44:07 1.34
@@ -65,12 +65,8 @@
/*
- Note that the Explain() stuff is not yet complete.
Also note numerous FIXMEs and CHECKMEs which should be eliminated.
- If TESTING is set, then garbage collection doesn't delete ... probably a good
- idea when hacking.
-
This code is once again experimental!
Things to do:
@@ -83,13 +79,33 @@
*/
-#define TESTING 0
-#undef EXPLAIN
+#define CORE_PRIVATE
+#include "apr.h"
#include "apr_compat.h"
#include "apr_lib.h"
#include "apr_strings.h"
+#include "apr_buckets.h"
+#include "apr_md5.h"
+#include "apr_pools.h"
+#include "apr_strings.h"
+
+#include "util_filter.h"
+#include "util_date.h"
+#include "util_uri.h"
+#include "httpd.h"
+#include "http_config.h"
+#include "http_protocol.h"
+#include "ap_config.h"
+#include "http_log.h"
+#include "http_main.h"
+#include "http_core.h"
+#include "http_connection.h"
+#include "http_vhost.h"
+#include "http_request.h"
+#include "mod_core.h"
+
#if APR_HAVE_NETDB_H
#include <netdb.h>
#endif
@@ -103,10 +119,6 @@
#include <arpa/inet.h>
#endif
-#include "httpd.h"
-#include "http_config.h"
-#include "http_protocol.h"
-
extern module AP_MODULE_DECLARE_DATA proxy_module;
@@ -116,15 +128,13 @@
enc_path, enc_search, enc_user, enc_fpath, enc_parm
};
-#define HDR_APP (0) /* append header, for proxy_add_header() */
-#define HDR_REP (1) /* replace header, for proxy_add_header() */
-
#if APR_CHARSET_EBCDIC
#define CRLF "\r\n"
#else /*APR_CHARSET_EBCDIC*/
#define CRLF "\015\012"
#endif /*APR_CHARSET_EBCDIC*/
+#if 0
#define DEFAULT_FTP_DATA_PORT 20
#define DEFAULT_FTP_PORT 21
#define DEFAULT_GOPHER_PORT 70
@@ -135,11 +145,15 @@
#define DEFAULT_PROSPERO_PORT 1525 /* WARNING: conflict w/Oracle */
#define DEFAULT_CACHE_COMPLETION (0.9)
+#endif
+
+#if 0
/* Some WWW schemes and their default ports; this is basically /etc/services */
struct proxy_services {
const char *scheme;
int port;
};
+#endif
/* static information about a remote proxy */
struct proxy_remote {
@@ -212,10 +226,9 @@
/* proxy_ftp.c */
-#if FTP
int ap_proxy_ftp_canon(request_rec *r, char *url);
-int ap_proxy_ftp_handler(request_rec *r, ap_cache_el *c, char *url);
-#endif
+int ap_proxy_ftp_handler(request_rec *r, char *url);
+apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f, apr_bucket_brigade *bb, ap_input_mode_t mode);
/* proxy_http.c */
1.25 +2 -10 httpd-proxy/module-2.0/proxy_connect.c
Index: proxy_connect.c
===================================================================
RCS file: /home/cvs/httpd-proxy/module-2.0/proxy_connect.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- proxy_connect.c 2001/04/04 18:47:42 1.24
+++ proxy_connect.c 2001/04/06 10:44:07 1.25
@@ -59,13 +59,12 @@
/* CONNECT method for Apache proxy */
#include "mod_proxy.h"
-#include "http_log.h"
-#include "http_main.h"
-#include "apr_strings.h"
+#if 0
#ifdef HAVE_BSTRING_H
#include <bstring.h> /* for IRIX, FD_SET calls bzero() */
#endif
+#endif
/*
* This handles Netscape CONNECT method secure proxy requests.
@@ -79,13 +78,6 @@
* If proxyhost and proxyport are set, we send a CONNECT to
* the specified proxy..
*
- * FIXME: this is bad, because it does its own socket I/O
- * instead of using the I/O in buff.c. However,
- * the I/O in buff.c blocks on reads, and because
- * this function doesn't know how much data will
- * be sent either way (or when) it can't use blocking
- * I/O. This may be very implementation-specific
- * (to Linux). Any suggestions?
* FIXME: this doesn't log the number of bytes sent, but
* that may be okay, since the data is supposed to
* be transparent. In fact, this doesn't log at all
1.33 +59 -71 httpd-proxy/module-2.0/proxy_ftp.c
Index: proxy_ftp.c
===================================================================
RCS file: /home/cvs/httpd-proxy/module-2.0/proxy_ftp.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- proxy_ftp.c 2001/04/05 21:27:50 1.32
+++ proxy_ftp.c 2001/04/06 10:44:07 1.33
@@ -58,23 +58,10 @@
/* FTP routines for Apache proxy */
-#define CORE_PRIVATE
-
#include "mod_proxy.h"
-#include "apr_strings.h"
-#include "apr_buckets.h"
-#include "util_filter.h"
-#include "ap_config.h"
-#include "http_log.h"
-#include "http_main.h"
-#include "http_core.h"
-#include "http_connection.h"
-#include "util_date.h"
#define AUTODETECT_PWD
-int ap_proxy_ftp_canon(request_rec *r, char *url);
-int ap_proxy_ftp_handler(request_rec *r, char *url);
/*
* Decodes a '%' escaped string, and returns the number of characters
@@ -252,33 +239,41 @@
return status;
}
-/* this piece needs some serious overhauling */
-#if 0
-static long int send_dir(BUFF *f, request_rec *r, ap_cache_el *c, char *cwd)
+/* this is a filter that turns a raw ASCII directory listing into pretty HTML */
+
+/* ideally, mod_proxy should simply send the raw directory list up the filter
+ * stack to mod_autoindex, which in theory should turn the raw ascii into
+ * pretty html along with all the bells and whistles it provides...
+ *
+ * all in good time...! :)
+ */
+
+apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f, apr_bucket_brigade *bb, ap_input_mode_t mode)
{
- char buf[IOBUFSIZE];
- char buf2[IOBUFSIZE];
+ conn_rec *c = f->r->connection;
+ apr_pool_t *p = f->r->pool;
+ apr_bucket *e;
+ char buf[MAX_STRING_LEN];
+ char buf2[MAX_STRING_LEN];
+
char *filename;
int searchidx = 0;
char *searchptr = NULL;
int firstfile = 1;
- apr_ssize_t cntr;
- unsigned long total_bytes_sent = 0;
- register int n, o, w;
- conn_rec *con = r->connection;
+ register int n;
char *dir, *path, *reldir, *site;
- apr_file_t *cachefp = NULL;
+
+ char *cwd = NULL;
+
- if(c) ap_cache_el_data(c, &cachefp);
-
/* Save "scheme://site" prefix without password */
- site = ap_unparse_uri_components(r->pool, &r->parsed_uri, UNP_OMITPASSWORD|UNP_OMITPATHINFO);
+ site = ap_unparse_uri_components(p, &f->r->parsed_uri, UNP_OMITPASSWORD|UNP_OMITPATHINFO);
/* ... and path without query args */
- path = ap_unparse_uri_components(r->pool, &r->parsed_uri, UNP_OMITSITEPART|UNP_OMITQUERY);
+ path = ap_unparse_uri_components(p, &f->r->parsed_uri, UNP_OMITSITEPART|UNP_OMITQUERY);
(void)decodeenc(path);
/* Copy path, strip (all except the last) trailing slashes */
- path = dir = apr_pstrcat(r->pool, path, "/", NULL);
+ path = dir = apr_pstrcat(p, path, "/", NULL);
while ((n = strlen(path)) > 1 && path[n-1] == '/' && path[n-2] == '/')
path[n-1] = '\0';
@@ -289,7 +284,9 @@
"<BODY><H2>Directory of "
"<A HREF=\"/\">%s</A>/",
site, path, site, path, site);
- total_bytes_sent += ap_proxy_bputs2(buf, con->client_socket, c);
+
+ e = apr_bucket_pool_create(buf, n, p);
+ APR_BRIGADE_INSERT_TAIL(bb, e);
while ((dir = strchr(dir+1, '/')) != NULL)
{
@@ -299,31 +296,32 @@
else
++reldir;
/* print "path/" component */
- apr_snprintf(buf, sizeof(buf), "<A HREF=\"/%s/\">%s</A>/", path+1, reldir);
- total_bytes_sent += ap_proxy_bputs2(buf, con->client_socket, c);
+ n = apr_snprintf(buf, sizeof(buf), "<A HREF=\"/%s/\">%s</A>/", path+1, reldir);
+ e = apr_bucket_pool_create(buf, n, p);
+ APR_BRIGADE_INSERT_TAIL(bb, e);
*dir = '/';
}
/* If the caller has determined the current directory, and it differs */
/* from what the client requested, then show the real name */
if (cwd == NULL || strncmp (cwd, path, strlen(cwd)) == 0) {
- apr_snprintf(buf, sizeof(buf), "</H2>\n<HR><PRE>");
+ n = apr_snprintf(buf, sizeof(buf), "</H2>\n<HR><PRE>");
} else {
- apr_snprintf(buf, sizeof(buf), "</H2>\n(%s)\n<HR><PRE>", cwd);
+ n = apr_snprintf(buf, sizeof(buf), "</H2>\n(%s)\n<HR><PRE>", cwd);
}
- total_bytes_sent += ap_proxy_bputs2(buf, con->client_socket, c);
+ e = apr_bucket_pool_create(buf, n, p);
+ APR_BRIGADE_INSERT_TAIL(bb, e);
+
+ e = apr_bucket_flush_create();
+ APR_BRIGADE_INSERT_TAIL(bb, e);
- while (!con->aborted) {
- n = ap_bgets(buf, sizeof buf, f);
+ while (!c->aborted) {
+ n = ap_getline(buf, sizeof(buf), f->r, 0);
if (n == -1) { /* input error */
- if (c != NULL) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "proxy: error reading from cache");
- ap_proxy_cache_error(&c);
- }
break;
}
- if (n == 0)
+ if (n == 0) {
break; /* EOF */
+ }
if (buf[0] == 'l' && (filename=strstr(buf, " -> ")) != NULL) {
char *link_ptr = filename;
@@ -375,38 +373,27 @@
n = strlen(buf);
}
- o = 0;
- total_bytes_sent += n;
+ e = apr_bucket_pool_create(buf, n, p);
+ APR_BRIGADE_INSERT_TAIL(bb, e);
+ e = apr_bucket_flush_create();
+ APR_BRIGADE_INSERT_TAIL(bb, e);
- cntr = n;
- if (cachefp && apr_file_write(cachefp, buf, &cntr) != APR_SUCCESS) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "proxy: error writing to cache");
- ap_proxy_cache_error(&c);
- cachefp = NULL;
- }
-
- while (n && !r->connection->aborted) {
- cntr = n;
- w = apr_send(con->client_socket, &buf[o], &cntr);
- if (w <= 0)
- break;
- n -= w;
- o += w;
- }
}
+
+ n = apr_snprintf(buf, sizeof(buf), "</PRE><HR>\n%s</BODY></HTML>\n", ap_psignature("", f->r));
+ e = apr_bucket_pool_create(buf, n, p);
+ APR_BRIGADE_INSERT_TAIL(bb, e);
+
+ e = apr_bucket_eos_create();
+ APR_BRIGADE_INSERT_TAIL(bb, e);
- total_bytes_sent += ap_proxy_bputs2("</PRE><HR>\n", con->client_socket, c);
- total_bytes_sent += ap_proxy_bputs2(ap_psignature("", r), con->client_socket, c);
- total_bytes_sent += ap_proxy_bputs2("</BODY></HTML>\n", con->client_socket, c);
-
-/* Flushing the actual socket doesn't make much sense, because we don't
- * buffer it yet.
- ap_flush(con->client);
+/* probably not necessary */
+/* e = apr_bucket_flush_create();
+ APR_BRIGADE_INSERT_TAIL(bb, e);
*/
- return total_bytes_sent;
+
+ return APR_SUCCESS;
}
-#endif
/* Common routine for failed authorization (i.e., missing or wrong password)
* to an ftp service. This causes most browsers to retry the request
@@ -485,6 +472,7 @@
if (r->method_number != M_GET)
return HTTP_NOT_IMPLEMENTED;
+
/* We break the URL into host, port, path-search */
connectname = r->parsed_uri.hostname;
connectport = (r->parsed_uri.port != 0)
@@ -542,6 +530,7 @@
"Connect to remote machine blocked");
}
+//return HTTP_NOT_IMPLEMENTED;
/*
* II: Make the Connection
@@ -1346,9 +1335,8 @@
if (parms[0] == 'd') {
/* insert directory filter */
-/* send_dir(data, r, c, cwd); */
+ ap_add_output_filter("PROXY_SEND_DIR", NULL, r, r->connection);
}
-
/* send body */
if (!r->header_only) {
1.43 +0 -11 httpd-proxy/module-2.0/proxy_http.c
Index: proxy_http.c
===================================================================
RCS file: /home/cvs/httpd-proxy/module-2.0/proxy_http.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- proxy_http.c 2001/04/06 01:59:26 1.42
+++ proxy_http.c 2001/04/06 10:44:08 1.43
@@ -58,18 +58,7 @@
/* HTTP routines for Apache proxy */
-#define CORE_PRIVATE
-
#include "mod_proxy.h"
-#include "apr_strings.h"
-#include "apr_buckets.h"
-#include "util_filter.h"
-#include "ap_config.h"
-#include "http_log.h"
-#include "http_main.h"
-#include "http_core.h"
-#include "http_connection.h"
-#include "util_date.h"
/*
* Canonicalise http-like URLs.
1.48 +1 -10 httpd-proxy/module-2.0/proxy_util.c
Index: proxy_util.c
===================================================================
RCS file: /home/cvs/httpd-proxy/module-2.0/proxy_util.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- proxy_util.c 2001/04/05 18:53:04 1.47
+++ proxy_util.c 2001/04/06 10:44:08 1.48
@@ -56,18 +56,9 @@
* University of Illinois, Urbana-Champaign.
*/
-#define CORE_PRIVATE
-
/* Utility routines for Apache proxy */
#include "mod_proxy.h"
-#include "http_core.h"
-#include "http_main.h"
-#include "http_log.h"
-#include "util_uri.h"
-#include "util_date.h" /* get ap_checkmask() decl. */
-#include "apr_md5.h"
-#include "apr_pools.h"
-#include "apr_strings.h"
+
static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
static int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);