APACHE_MODPATH_INIT(proxy)
-proxy_objs="mod_proxy.lo proxy_connect.lo proxy_ftp.lo proxy_http.lo proxy_util.lo"
+if test "$enable_proxy" = "no"; then
+ proxy_mods_enable=no
+else
+ proxy_mods_enable=yes
+fi
+APACHE_MODULE(dav_fs, DAV provider for the filesystem, $dav_fs_objects, ,$dav_fs_enable)
+proxy_objs="mod_proxy.lo proxy_util.lo"
APACHE_MODULE(proxy, Apache proxy module, $proxy_objs, , no)
+proxy_connect_objs="proxy_connect.lo proxy_util.lo"
+APACHE_MODULE(proxy_connect, Apache proxy CONNECT module, $proxy_connect_objs, , $proxy_mods_enable)
+proxy_ftp_objs="proxy_ftp.lo proxy_util.lo"
+APACHE_MODULE(proxy_ftp, Apache proxy FTP module, $proxy_ftp_objs, , $proxy_mods_enable)
+proxy_http_objs="proxy_http.lo proxy_util.lo"
+APACHE_MODULE(proxy_http, Apache proxy HTTP module, $proxy_http_objs, , $proxy_mods_enable)
+
+
APACHE_MODPATH_FINISH
#include "mod_proxy.h"
-APR_HOOK_STRUCT(
- APR_HOOK_LINK(proxy_scheme_handler)
- APR_HOOK_LINK(proxy_canon_handler)
-)
-
-AP_IMPLEMENT_HOOK_RUN_FIRST(int, proxy_scheme_handler, (request_rec *r, char *url, const char *proxyhost, apr_port_t proxyport),(r,url,proxyhost,proxyport),DECLINED)
-AP_IMPLEMENT_HOOK_RUN_FIRST(int, proxy_canon_handler, (request_rec *r, char *url),(r,url),DECLINED)
+extern module AP_MODULE_DECLARE_DATA proxy_module;
/*
url = &r->filename[6];
/* canonicalise each specific scheme */
- if ((access_status = ap_run_proxy_canon_handler(r, url))) {
+ if ((access_status = proxy_run_canon_handler(r, url))) {
return access_status;
}
ap_get_module_config(sconf, &proxy_module);
apr_array_header_t *proxies = conf->proxies;
struct proxy_remote *ents = (struct proxy_remote *) proxies->elts;
- int i, rc;
+ int i, rc, access_status;
int direct_connect = 0;
const char *str;
long maxfwd;
#endif
}
-/* firstly, try a proxy, unless a NoProxy directive is active */
-
- if (!direct_connect)
+ /* firstly, try a proxy, unless a NoProxy directive is active */
+ if (!direct_connect) {
for (i = 0; i < proxies->nelts; i++) {
p2 = ap_strchr_c(ents[i].scheme, ':'); /* is it a partial URL? */
if (strcmp(ents[i].scheme, "*") == 0 ||
(p2 == NULL && strcasecmp(scheme, ents[i].scheme) == 0) ||
(p2 != NULL &&
- strncasecmp(url, ents[i].scheme, strlen(ents[i].scheme)) == 0)) {
- /* CONNECT is a special method that bypasses the normal
- * proxy code.
- */
- if (r->method_number == M_CONNECT)
- rc = ap_proxy_connect_handler(r, url, ents[i].hostname,
- ents[i].port);
-/* we only know how to handle communication to a proxy via http */
- else if (strcasecmp(ents[i].protocol, "http") == 0)
- rc = ap_proxy_http_handler(r, url, ents[i].hostname,
- ents[i].port);
- else
- rc = DECLINED;
+ strncasecmp(url, ents[i].scheme, strlen(ents[i].scheme)) == 0)) {
+
+ /* handle the scheme */
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
+ "Trying to run scheme_handler against proxy");
+ access_status = proxy_run_scheme_handler(r, conf, url, NULL, 0);
/* an error or success */
- if (rc != DECLINED && rc != HTTP_BAD_GATEWAY)
- return rc;
+ if (access_status != DECLINED && access_status != HTTP_BAD_GATEWAY) {
+ return access_status;
+ }
/* we failed to talk to the upstream proxy */
}
}
+ }
+
+ /* otherwise, try it direct */
+ /* N.B. what if we're behind a firewall, where we must use a proxy or
+ * give up??
+ */
-/* otherwise, try it direct */
-/* N.B. what if we're behind a firewall, where we must use a proxy or
- * give up??
- */
/* handle the scheme */
- if (r->method_number == M_CONNECT)
- return ap_proxy_connect_handler(r, url, NULL, 0);
- if (strcasecmp(scheme, "http") == 0)
- return ap_proxy_http_handler(r, url, NULL, 0);
- if (strcasecmp(scheme, "ftp") == 0)
- return ap_proxy_ftp_handler(r, url, NULL, 0);
- else {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
+ "Trying to run scheme_handler");
+ access_status = proxy_run_scheme_handler(r, conf, url, NULL, 0);
+ if (DECLINED == access_status) {
ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
"Neither CONNECT, HTTP or FTP for %s",
r->uri);
return HTTP_FORBIDDEN;
}
+ return access_status;
}
/* -------------------------------------------------------------- */
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);
- /* filters */
- ap_register_output_filter("PROXY_SEND_DIR", ap_proxy_send_dir_filter, AP_FTYPE_CONTENT);
/* fixups */
ap_hook_fixups(proxy_fixup, NULL, NULL, APR_HOOK_FIRST);
/* post read_request handling */
proxy_cmds, /* command table */
register_hooks
};
+
+APR_HOOK_STRUCT(
+ APR_HOOK_LINK(scheme_handler)
+ APR_HOOK_LINK(canon_handler)
+)
+
+APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, scheme_handler,
+ (request_rec *r, proxy_server_conf *conf,
+ char *url, const char *proxyhost,
+ apr_port_t proxyport),(r,conf,url,
+ proxyhost,proxyport),DECLINED)
+APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, canon_handler,
+ (request_rec *r, char *url),(r,
+ url),DECLINED)
#define CORE_PRIVATE
+#include "apr_hooks.h"
#include "apr.h"
#include "apr_compat.h"
#include "apr_lib.h"
#include "apr_md5.h"
#include "apr_pools.h"
#include "apr_strings.h"
-#include "apr_hooks.h"
#include "httpd.h"
#include "http_config.h"
#include <arpa/inet.h>
#endif
-extern module AP_MODULE_DECLARE_DATA proxy_module;
-
/* for proxy_canonenc() */
enum enctype {
enc_path, enc_search, enc_user, enc_fpath, enc_parm
} proxy_completion;
-/* Function prototypes */
-
-/* proxy_connect.c */
-
-int ap_proxy_connect_canon(request_rec *r, char *url);
-int ap_proxy_connect_handler(request_rec *r, char *url,
- const char *proxyhost, apr_port_t proxyport);
-
-/* proxy_ftp.c */
-
-int ap_proxy_ftp_canon(request_rec *r, char *url);
-int ap_proxy_ftp_handler(request_rec *r, char *url, const char *proxyhost, apr_port_t proxyport);
-apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f,
- apr_bucket_brigade *bb);
-
+/* hooks */
-/* proxy_http.c */
+/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
+ * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
+ */
+#if !defined(WIN32)
+#define PROXY_DECLARE(type) type
+#define PROXY_DECLARE_NONSTD(type) type
+#define PROXY_DECLARE_DATA
+#elif defined(PROXY_DECLARE_STATIC)
+#define PROXY_DECLARE(type) type __stdcall
+#define PROXY_DECLARE_NONSTD(type) type
+#define PROXY_DECLARE_DATA
+#elif defined(PROXY_DECLARE_EXPORT)
+#define PROXY_DECLARE(type) __declspec(dllexport) type __stdcall
+#define PROXY_DECLARE_NONSTD(type) __declspec(dllexport) type
+#define PROXY_DECLARE_DATA __declspec(dllexport)
+#else
+#define PROXY_DECLARE(type) __declspec(dllimport) type __stdcall
+#define PROXY_DECLARE_NONSTD(type) __declspec(dllimport) type
+#define PROXY_DECLARE_DATA __declspec(dllimport)
+#endif
-int ap_proxy_http_canon(request_rec *r, char *url);
-int ap_proxy_http_handler(request_rec *r, char *url,
- const char *proxyhost, apr_port_t proxyport);
+APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r,
+ proxy_server_conf *conf, char *url,
+ const char *proxyhost, apr_port_t proxyport))
+APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r,
+ char *url))
/* proxy_util.c */
void ap_proxy_reset_output_filters(conn_rec *c);
-/* hooks */
-
-
-AP_DECLARE_HOOK(int, proxy_scheme_handler, (request_rec *r, char *url, const char *proxyhost, apr_port_t proxyport))
-AP_DECLARE_HOOK(int, proxy_canon_handler, (request_rec *r, char *url))
-
-
#endif /*MOD_PROXY_H*/
module AP_MODULE_DECLARE_DATA proxy_connect_module;
+PROXY_DECLARE (int) ap_proxy_connect_canon(request_rec *r, char *url);
+PROXY_DECLARE (int) ap_proxy_connect_handler(request_rec *r, proxy_server_conf *conf,
+ char *url, const char *proxyname,
+ apr_port_t proxyport);
+
/*
* This handles Netscape CONNECT method secure proxy requests.
* A connection is opened to the specified host and data is
}
/* canonicalise CONNECT URLs. */
-int ap_proxy_connect_canon(request_rec *r, char *url)
+PROXY_DECLARE (int) ap_proxy_connect_canon(request_rec *r, char *url)
{
if (r->method_number != M_CONNECT) {
return DECLINED;
}
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "proxy: CONNECT: canonicalising URL %s", url);
return OK;
}
/* CONNECT handler */
-int ap_proxy_connect_handler(request_rec *r, char *url,
- const char *proxyname, apr_port_t proxyport)
+PROXY_DECLARE (int) ap_proxy_connect_handler(request_rec *r, proxy_server_conf *conf,
+ char *url, const char *proxyname,
+ apr_port_t proxyport)
{
apr_pool_t *p = r->pool;
apr_socket_t *sock;
const char *connectname;
int connectport = 0;
- void *sconf = r->server->module_config;
- proxy_server_conf *conf =
- (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
-
/* is this for us? */
if (r->method_number != M_CONNECT) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "proxy: CONNECT: rejecting URL %s", url);
return DECLINED;
}
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "proxy: CONNECT: serving URL %s", url);
+
/*
* Step One: Determine Who To Connect To
static void ap_proxy_connect_register_hook(apr_pool_t *p)
{
- ap_hook_proxy_scheme_handler(ap_proxy_connect_handler, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_proxy_canon_handler(ap_proxy_connect_canon, NULL, NULL, APR_HOOK_MIDDLE);
+ proxy_hook_scheme_handler(ap_proxy_connect_handler, NULL, NULL, APR_HOOK_MIDDLE);
+ proxy_hook_canon_handler(ap_proxy_connect_canon, NULL, NULL, APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA proxy_connect_module = {
module AP_MODULE_DECLARE_DATA proxy_ftp_module;
+PROXY_DECLARE (int) ap_proxy_ftp_canon(request_rec *r, char *url);
+PROXY_DECLARE (int) ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf,
+ char *url, const char *proxyhost,
+ apr_port_t proxyport);
+apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f,
+ apr_bucket_brigade *bb);
+
+
/*
* Decodes a '%' escaped string, and returns the number of characters
*/
/*
* Canonicalise ftp URLs.
*/
-int ap_proxy_ftp_canon(request_rec *r, char *url)
+PROXY_DECLARE (int) ap_proxy_ftp_canon(request_rec *r, char *url)
{
char *user, *password, *host, *path, *parms, *strp, sport[7];
apr_pool_t *p = r->pool;
}
def_port = ap_default_port_for_scheme("ftp");
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "proxy: FTP: canonicalising URL %s", url);
+
port = def_port;
err = ap_proxy_canon_netloc(p, &url, &user, &password, &host, &port);
if (err)
* PASV added by Chuck
* Filters by [Graham Leggett <minfrin@sharp.fm>]
*/
-int ap_proxy_ftp_handler(request_rec *r, char *url, const char *proxyhost, apr_port_t proxyport)
+PROXY_DECLARE (int) ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf,
+ char *url, const char *proxyhost,
+ apr_port_t proxyport)
{
apr_pool_t *p = r->pool;
conn_rec *c = r->connection;
+ proxy_conn_rec *backend;
apr_socket_t *sock, *local_sock, *remote_sock;
apr_sockaddr_t *connect_addr;
apr_status_t rv;
int connect = 0, use_port = 0;
char dates[AP_RFC822_DATE_LEN];
- void *sconf = r->server->module_config;
- proxy_server_conf *conf =
- (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+ /* is this for us? */
+ if (proxyhost) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "proxy: FTP: rejecting URL %s - proxyhost %s specified:", url, proxyhost);
+ return DECLINED; /* proxy connections are via HTTP */
+ }
+ if (strncasecmp(url, "ftp:", 4)) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "proxy: FTP: rejecting URL %s - not ftp:", url);
+ return DECLINED; /* only interested in FTP */
+ }
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "proxy: FTP: serving URL %s", url);
- proxy_conn_rec *backend =
- (proxy_conn_rec *) ap_get_module_config(c->conn_config, &proxy_module);
+ /* create space for state information */
+ backend = (proxy_conn_rec *) ap_get_module_config(c->conn_config, &proxy_ftp_module);
if (!backend) {
backend = ap_pcalloc(c->pool, sizeof(proxy_conn_rec));
backend->connection = NULL;
backend->hostname = NULL;
backend->port = 0;
- ap_set_module_config(c->conn_config, &proxy_module, backend);
+ ap_set_module_config(c->conn_config, &proxy_ftp_module, backend);
}
static void ap_proxy_ftp_register_hook(apr_pool_t *p)
{
- ap_hook_proxy_scheme_handler(ap_proxy_ftp_handler, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_proxy_canon_handler(ap_proxy_ftp_canon, NULL, NULL, APR_HOOK_MIDDLE);
+ /* hooks */
+ proxy_hook_scheme_handler(ap_proxy_ftp_handler, NULL, NULL, APR_HOOK_MIDDLE);
+ proxy_hook_canon_handler(ap_proxy_ftp_canon, NULL, NULL, APR_HOOK_MIDDLE);
+ /* filters */
+ ap_register_output_filter("PROXY_SEND_DIR", ap_proxy_send_dir_filter, AP_FTYPE_CONTENT);
}
module AP_MODULE_DECLARE_DATA proxy_ftp_module = {
module AP_MODULE_DECLARE_DATA proxy_http_module;
+PROXY_DECLARE (int) ap_proxy_http_canon(request_rec *r, char *url);
+PROXY_DECLARE (int) ap_proxy_http_handler(request_rec *r, proxy_server_conf *conf,
+ char *url, const char *proxyname,
+ apr_port_t proxyport);
+
+
/*
* Canonicalise http-like URLs.
* scheme is the scheme for the URL
* url is the URL starting with the first '/'
* def_port is the default port for this scheme.
*/
-int ap_proxy_http_canon(request_rec *r, char *url)
+PROXY_DECLARE (int) ap_proxy_http_canon(request_rec *r, char *url)
{
char *host, *path, *search, sport[7];
const char *err;
}
def_port = ap_default_port_for_scheme(scheme);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "proxy: HTTP: canonicalising URL %s", url);
+
/* do syntatic check.
* We break the URL into host, port, path, search
*/
return OK;
}
-static const char *ap_proxy_location_reverse_map(request_rec *r, const char *url)
+static const char *ap_proxy_location_reverse_map(request_rec *r, proxy_server_conf *conf, const char *url)
{
- void *sconf;
- proxy_server_conf *conf;
struct proxy_alias *ent;
int i, l1, l2;
char *u;
/* XXX FIXME: Make sure this handled the ambiguous case of the :80
* after the hostname */
- sconf = r->server->module_config;
- conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
l1 = strlen(url);
ent = (struct proxy_alias *)conf->raliases->elts;
for (i = 0; i < conf->raliases->nelts; i++) {
* we return DECLINED so that we can try another proxy. (Or the direct
* route.)
*/
-int ap_proxy_http_handler(request_rec *r, char *url,
- const char *proxyname, apr_port_t proxyport)
+PROXY_DECLARE (int) ap_proxy_http_handler(request_rec *r, proxy_server_conf *conf,
+ char *url, const char *proxyname,
+ apr_port_t proxyport)
{
request_rec *rp;
const char *connectname;
char *buf;
conn_rec *origin;
uri_components uri;
-
- void *sconf = r->server->module_config;
- proxy_server_conf *conf =
- (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+ proxy_conn_rec *backend;
/* Note: Memory pool allocation.
* A downstream keepalive connection is always connected to the existence
apr_bucket *e;
apr_bucket_brigade *bb = apr_brigade_create(p);
- proxy_conn_rec *backend =
- (proxy_conn_rec *) ap_get_module_config(c->conn_config, &proxy_module);
+ /* is it for us? */
+ if (strncasecmp(url, "http:", 5)) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "proxy: HTTP: rejecting URL %s", url);
+ return DECLINED; /* only interested in HTTP */
+ }
+ ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
+ "proxy: HTTP: serving URL %s", url);
+
+ /* create space for state information */
+ backend = (proxy_conn_rec *) ap_get_module_config(c->conn_config, &proxy_http_module);
if (!backend) {
backend = ap_pcalloc(c->pool, sizeof(proxy_conn_rec));
backend->connection = NULL;
backend->hostname = NULL;
backend->port = 0;
- ap_set_module_config(c->conn_config, &proxy_module, backend);
+ ap_set_module_config(c->conn_config, &proxy_http_module, backend);
}
/*
{
const char *buf;
if ((buf = apr_table_get(r->headers_out, "Location")) != NULL) {
- apr_table_set(r->headers_out, "Location", ap_proxy_location_reverse_map(r, buf));
+ apr_table_set(r->headers_out, "Location", ap_proxy_location_reverse_map(r, conf, buf));
}
if ((buf = apr_table_get(r->headers_out, "Content-Location")) != NULL) {
- apr_table_set(r->headers_out, "Content-Location", ap_proxy_location_reverse_map(r, buf));
+ apr_table_set(r->headers_out, "Content-Location", ap_proxy_location_reverse_map(r, conf, buf));
}
if ((buf = apr_table_get(r->headers_out, "URI")) != NULL) {
- apr_table_set(r->headers_out, "URI", ap_proxy_location_reverse_map(r, buf));
+ apr_table_set(r->headers_out, "URI", ap_proxy_location_reverse_map(r, conf, buf));
}
}
static void ap_proxy_http_register_hook(apr_pool_t *p)
{
- ap_hook_proxy_scheme_handler(ap_proxy_http_handler, NULL, NULL, APR_HOOK_FIRST);
- ap_hook_proxy_canon_handler(ap_proxy_http_canon, NULL, NULL, APR_HOOK_FIRST);
+ proxy_hook_scheme_handler(ap_proxy_http_handler, NULL, NULL, APR_HOOK_FIRST);
+ proxy_hook_canon_handler(ap_proxy_http_canon, NULL, NULL, APR_HOOK_FIRST);
}
module AP_MODULE_DECLARE_DATA proxy_http_module = {