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/15 19:15:29 UTC

cvs commit: httpd-proxy/module-2.0 config.m4 mod_proxy.c mod_proxy.h proxy_connect.c proxy_ftp.c proxy_http.c

minfrin     01/04/15 10:15:29

  Modified:    .        CHANGES STATUS
               module-2.0 config.m4 mod_proxy.c mod_proxy.h proxy_connect.c
                        proxy_ftp.c proxy_http.c
  Log:
  Split each individual proxy protocol into separate modules.
  
  Revision  Changes    Path
  1.26      +3 -0      httpd-proxy/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-proxy/CHANGES,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- CHANGES	2001/04/13 15:51:32	1.25
  +++ CHANGES	2001/04/15 17:15:28	1.26
  @@ -1,6 +1,9 @@
   
   mod_proxy changes for 2.0.15 current
   
  +  *) Split each individual proxy protocol into separate modules.
  +     [Graham Leggett <mi...@sharp.fm>]
  +
     *) Added Max-Forwards support for all request types so as to prevent
        loops.
        [Graham Leggett <mi...@sharp.fm>]
  
  
  
  1.15      +3 -3      httpd-proxy/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/httpd-proxy/STATUS,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- STATUS	2001/04/12 01:57:47	1.14
  +++ STATUS	2001/04/15 17:15:28	1.15
  @@ -1,5 +1,5 @@
   HTTPD PROXY STATUS:
  -Last modified at [$Date: 2001/04/12 01:57:47 $]
  +Last modified at [$Date: 2001/04/15 17:15:28 $]
   
   Release:
   
  @@ -90,11 +90,11 @@
   
   2.0
   
  -    * finish conversion of proxy_ftp.c
  +    * none
   
   2.0+
   
  -    * proxy redesign (mod_proxy.c as filter, etc.) after POC
  +    * none
   
   Documentation that needs editing:
   
  
  
  
  1.10      +15 -1     httpd-proxy/module-2.0/config.m4
  
  Index: config.m4
  ===================================================================
  RCS file: /home/cvs/httpd-proxy/module-2.0/config.m4,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- config.m4	2001/04/05 23:48:43	1.9
  +++ config.m4	2001/04/15 17:15:29	1.10
  @@ -2,8 +2,22 @@
   
   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
  
  
  
  1.43      +39 -40    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.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- mod_proxy.c	2001/04/14 07:02:59	1.42
  +++ mod_proxy.c	2001/04/15 17:15:29	1.43
  @@ -60,15 +60,9 @@
   
   #include "mod_proxy.h"
   
  -APR_HOOK_STRUCT(
  -	APR_HOOK_LINK(proxy_scheme_handler)
  -	APR_HOOK_LINK(proxy_canon_handler)
  -)
  +extern module AP_MODULE_DECLARE_DATA proxy_module;
   
  -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)
   
  -
   /*
    * A Web proxy module. Stages:
    *
  @@ -213,7 +207,7 @@
       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;
       }
   
  @@ -276,7 +270,7 @@
           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;
  @@ -359,53 +353,46 @@
   		     r->uri);
   #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;
   }
   
   /* -------------------------------------------------------------- */
  @@ -749,8 +736,6 @@
       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 */
  @@ -767,3 +752,17 @@
       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)
  
  
  
  1.50      +27 -29    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.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- mod_proxy.h	2001/04/14 07:02:59	1.49
  +++ mod_proxy.h	2001/04/15 17:15:29	1.50
  @@ -81,6 +81,7 @@
   
   #define CORE_PRIVATE
   
  +#include "apr_hooks.h"
   #include "apr.h"
   #include "apr_compat.h"
   #include "apr_lib.h"
  @@ -89,7 +90,6 @@
   #include "apr_md5.h"
   #include "apr_pools.h"
   #include "apr_strings.h"
  -#include "apr_hooks.h"
   
   #include "httpd.h"
   #include "http_config.h"
  @@ -120,8 +120,6 @@
   #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
  @@ -201,28 +199,35 @@
           int content_length; /* length of the content */
   } 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 */
   
  @@ -249,13 +254,6 @@
   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))
   
   
   #endif /*MOD_PROXY_H*/
  
  
  
  1.42      +18 -9     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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- proxy_connect.c	2001/04/14 07:02:59	1.41
  +++ proxy_connect.c	2001/04/15 17:15:29	1.42
  @@ -64,6 +64,11 @@
   
   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
  @@ -101,19 +106,22 @@
   }
   
   /* 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;
  @@ -130,14 +138,15 @@
       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
  @@ -403,8 +412,8 @@
   
   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 = {
  
  
  
  1.48      +37 -10    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.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- proxy_ftp.c	2001/04/14 07:02:59	1.47
  +++ proxy_ftp.c	2001/04/15 17:15:29	1.48
  @@ -64,6 +64,14 @@
   
   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
    */
  @@ -113,7 +121,7 @@
   /*
    * 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;
  @@ -129,6 +137,9 @@
       }
       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)
  @@ -514,10 +525,13 @@
    * PASV added by Chuck
    * Filters by [Graham Leggett <mi...@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;
  @@ -541,18 +555,28 @@
       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);
       }
   
   
  @@ -1620,8 +1644,11 @@
   
   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 = {
  
  
  
  1.61      +32 -20    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.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- proxy_http.c	2001/04/14 07:03:00	1.60
  +++ proxy_http.c	2001/04/15 17:15:29	1.61
  @@ -62,13 +62,19 @@
   
   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;
  @@ -89,6 +95,9 @@
       }
       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
        */
  @@ -125,10 +134,8 @@
       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;
  @@ -136,8 +143,6 @@
       /* 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++) {
  @@ -182,8 +187,9 @@
    * 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;
  @@ -200,11 +206,8 @@
       char *buf;
       conn_rec *origin;
       uri_components uri;
  +    proxy_conn_rec *backend;
   
  -    void *sconf = r->server->module_config;
  -    proxy_server_conf *conf =
  -    (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
  -
       /* Note: Memory pool allocation.
        * A downstream keepalive connection is always connected to the existence
        * (or not) of an upstream keepalive connection. If this is not done then
  @@ -223,14 +226,23 @@
       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);
       }
   
       /*
  @@ -697,13 +709,13 @@
       {
   	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));
   	}
       }
   
  @@ -787,8 +799,8 @@
   
   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 = {