From 0a9f4ce88747e4892335b3a7fc481850f6e6a07f Mon Sep 17 00:00:00 2001 From: Graham Leggett Date: Fri, 13 Apr 2001 23:56:04 +0000 Subject: [PATCH] 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 --- modules/proxy/mod_proxy.c | 13 +++++++++++-- modules/proxy/mod_proxy.h | 21 ++++++++++++++------- modules/proxy/proxy_connect.c | 18 +++++++++++++++++- modules/proxy/proxy_ftp.c | 21 +++++++++++++++++++-- modules/proxy/proxy_http.c | 22 ++++++++++++++++++++-- 5 files changed, 81 insertions(+), 14 deletions(-) diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index fdab3b31bc..33004834c3 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -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", diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 2838986eff..f349394d2e 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -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 #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*/ diff --git a/modules/proxy/proxy_connect.c b/modules/proxy/proxy_connect.c index 9658b6c959..133d510a0f 100644 --- a/modules/proxy/proxy_connect.c +++ b/modules/proxy/proxy_connect.c @@ -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 */ +}; diff --git a/modules/proxy/proxy_ftp.c b/modules/proxy/proxy_ftp.c index 8d693b3d77..effa19aeac 100644 --- a/modules/proxy/proxy_ftp.c +++ b/modules/proxy/proxy_ftp.c @@ -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 ] */ -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 */ +}; diff --git a/modules/proxy/proxy_http.c b/modules/proxy/proxy_http.c index 5fd9f92a0b..9b1411fc81 100644 --- a/modules/proxy/proxy_http.c +++ b/modules/proxy/proxy_http.c @@ -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 */ +}; -- 2.40.0