Commit 47716559 authored by Graham Leggett's avatar Graham Leggett
Browse files

Initial support for proxy protocol handler sub-modules. Work continues.

PR:
Obtained from:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@88853 13f79535-47bb-0310-9956-ffa450edef68
parent de754a58
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -60,6 +60,15 @@

#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, const char *scheme, apr_port_t def_port),(r,url,scheme,def_port),DECLINED)


/*
 * A Web proxy module. Stages:
 *
@@ -206,7 +215,7 @@ static int proxy_fixup(request_rec *r)
    if (strncasecmp(url, "http:", 5) == 0)
	return ap_proxy_http_canon(r, url + 5, "http", DEFAULT_HTTP_PORT);
    else if (strncasecmp(url, "ftp:", 4) == 0)
	return ap_proxy_ftp_canon(r, url + 4);
	return ap_proxy_ftp_canon(r, url + 4, NULL, 0);

    p = strchr(url, ':');
    if (p == NULL || p == url)
@@ -399,7 +408,7 @@ static int proxy_handler(request_rec *r)
    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);
	return ap_proxy_ftp_handler(r, url, NULL, 0);
    else {
        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
		     "Neither CONNECT, HTTP or FTP for %s",
+14 −7
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@
#include "apr_md5.h"
#include "apr_pools.h"
#include "apr_strings.h"
#include "apr_hooks.h"

#include "httpd.h"
#include "http_config.h"
@@ -119,10 +120,8 @@
#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
@@ -208,12 +207,12 @@ typedef struct {
/* proxy_connect.c */

int ap_proxy_connect_handler(request_rec *r, char *url,
			  const char *proxyhost, int proxyport);
			  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);
int ap_proxy_ftp_canon(request_rec *r, char *url, const char *scheme, apr_port_t def_port);
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);

@@ -221,9 +220,9 @@ apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f,
/* proxy_http.c */

int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme,
		     int def_port);
		     apr_port_t def_port);
int ap_proxy_http_handler(request_rec *r, char *url,
		       const char *proxyhost, int proxyport);
		       const char *proxyhost, apr_port_t proxyport);

/* proxy_util.c */

@@ -251,4 +250,12 @@ int ap_proxy_pre_http_connection(conn_rec *c, request_rec *r);
apr_status_t ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, char *buff, size_t bufflen, int *eos);
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, const char *scheme, apr_port_t def_port))


#endif /*MOD_PROXY_H*/
+17 −1
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@

#include "mod_proxy.h"

module AP_MODULE_DECLARE_DATA proxy_connect_module;

/*  
 * This handles Netscape CONNECT method secure proxy requests.
@@ -100,7 +101,7 @@ allowed_port(proxy_server_conf *conf, int port)
}

int ap_proxy_connect_handler(request_rec *r, char *url,
			  const char *proxyname, int proxyport)
			  const char *proxyname, apr_port_t proxyport)
{
    apr_pool_t *p = r->pool;
    apr_socket_t *sock;
@@ -383,3 +384,18 @@ int ap_proxy_connect_handler(request_rec *r, char *url,

    return OK;
}

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);
}

module AP_MODULE_DECLARE_DATA proxy_connect_module = {
    STANDARD20_MODULE_STUFF,
    NULL,		/* create per-directory config structure */
    NULL,		/* merge per-directory config structures */
    NULL,		/* create per-server config structure */
    NULL,		/* merge per-server config structures */
    NULL,		/* command apr_table_t */
    ap_proxy_connect_register_hook	/* register hooks */
};
+19 −2
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@

#define AUTODETECT_PWD

module AP_MODULE_DECLARE_DATA proxy_ftp_module;

/*
 * Decodes a '%' escaped string, and returns the number of characters
@@ -112,7 +113,7 @@ static int ftp_check_string(const char *x)
/*
 * Canonicalise ftp URLs.
 */
int ap_proxy_ftp_canon(request_rec *r, char *url)
int ap_proxy_ftp_canon(request_rec *r, char *url, const char *scheme, apr_port_t def_port)
{
    char *user, *password, *host, *path, *parms, *strp, sport[7];
    apr_pool_t *p = r->pool;
@@ -504,7 +505,7 @@ static int ftp_unauthorized (request_rec *r, int log_it)
 * PASV added by Chuck
 * Filters by [Graham Leggett <minfrin@sharp.fm>]
 */
int ap_proxy_ftp_handler(request_rec *r, char *url)
int ap_proxy_ftp_handler(request_rec *r, char *url, const char *proxyhost, apr_port_t proxyport)
{
    apr_pool_t *p = r->pool;
    conn_rec *c = r->connection;
@@ -1607,3 +1608,19 @@ int ap_proxy_ftp_handler(request_rec *r, char *url)
    apr_brigade_destroy(bb);
    return OK;
}

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);
}

module AP_MODULE_DECLARE_DATA proxy_ftp_module = {
    STANDARD20_MODULE_STUFF,
    NULL,		/* create per-directory config structure */
    NULL,		/* merge per-directory config structures */
    NULL,		/* create per-server config structure */
    NULL,		/* merge per-server config structures */
    NULL,		/* command apr_table_t */
    ap_proxy_ftp_register_hook	/* register hooks */
};
+20 −2
Original line number Diff line number Diff line
@@ -60,13 +60,15 @@

#include "mod_proxy.h"

module AP_MODULE_DECLARE_DATA proxy_http_module;

/*
 * 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, const char *scheme, int def_port)
int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme, apr_port_t def_port)
{
    char *host, *path, *search, sport[7];
    const char *err;
@@ -166,7 +168,7 @@ static void ap_proxy_clear_connection(apr_pool_t *p, apr_table_t *headers)
 * route.)
 */
int ap_proxy_http_handler(request_rec *r, char *url,
		       const char *proxyname, int proxyport)
		       const char *proxyname, apr_port_t proxyport)
{
    request_rec *rp;
    const char *connectname;
@@ -767,3 +769,19 @@ int ap_proxy_http_handler(request_rec *r, char *url,

    return OK;
}

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);
}

module AP_MODULE_DECLARE_DATA proxy_http_module = {
    STANDARD20_MODULE_STUFF,
    NULL,		/* create per-directory config structure */
    NULL,		/* merge per-directory config structures */
    NULL,		/* create per-server config structure */
    NULL,		/* merge per-server config structures */
    NULL,		/* command apr_table_t */
    ap_proxy_http_register_hook	/* register hooks */
};