]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Make hooks work for the *_canon() functions. Work continues.
authorGraham Leggett <minfrin@apache.org>
Sat, 14 Apr 2001 07:03:00 +0000 (07:03 +0000)
committerGraham Leggett <minfrin@apache.org>
Sat, 14 Apr 2001 07:03:00 +0000 (07:03 +0000)
PR:
Obtained from:
Reviewed by:

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@88854 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/mod_proxy.c
modules/proxy/mod_proxy.h
modules/proxy/proxy_connect.c
modules/proxy/proxy_ftp.c
modules/proxy/proxy_http.c
modules/proxy/proxy_util.c

index 33004834c3f0df42db08f1af8f44816371b7f8d8..64df4e44c0182272eedd4f85e8e04fa3b27fa8ce 100644 (file)
@@ -66,7 +66,7 @@ APR_HOOK_STRUCT(
 )
 
 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)
+AP_IMPLEMENT_HOOK_RUN_FIRST(int, proxy_canon_handler, (request_rec *r, char *url),(r,url),DECLINED)
 
 
 /*
@@ -205,17 +205,17 @@ static int proxy_trans(request_rec *r)
 static int proxy_fixup(request_rec *r)
 {
     char *url, *p;
+    int access_status;
 
     if (!r->proxyreq || strncmp(r->filename, "proxy:", 6) != 0)
        return DECLINED;
 
     url = &r->filename[6];
 
-/* canonicalise each specific scheme */
-    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, NULL, 0);
+    /* canonicalise each specific scheme */
+    if ((access_status = ap_run_proxy_canon_handler(r, url))) {
+       return access_status;
+    }
 
     p = strchr(url, ':');
     if (p == NULL || p == url)
@@ -279,7 +279,6 @@ static int proxy_handler(request_rec *r)
     int i, rc;
     int direct_connect = 0;
     const char *str;
-    const char *pragma, *auth, *imstr;
     long maxfwd;
 
     /* is this for us? */
@@ -332,14 +331,6 @@ static int proxy_handler(request_rec *r)
     if (p == NULL)
        return HTTP_BAD_REQUEST;
 
-    pragma = apr_table_get(r->headers_in, "Pragma");
-    auth = apr_table_get(r->headers_in, "Authorization");
-    imstr = apr_table_get(r->headers_in, "If-Modified-Since");
-
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, NULL,
-                 "Request for %s, pragma=%s, auth=%s, imstr=%s", url,
-                 pragma, auth, imstr);
-
     /* If the host doesn't have a domain name, add one and redirect. */
     if (conf->domain != NULL) {
        rc = proxy_needsdomain(r, url, conf->domain);
index f349394d2e06f7c1362d59462c5d00c650ab8a6b..f092d8271b14383259815552edede6fccf85590c 100644 (file)
@@ -206,12 +206,13 @@ typedef struct {
 
 /* 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, const char *scheme, apr_port_t def_port);
+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);
@@ -219,8 +220,7 @@ 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,
-                    apr_port_t def_port);
+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);
 
@@ -232,7 +232,7 @@ void ap_proxy_c2hex(int ch, char *x);
 char *ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
                        int isenc);
 char *ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
-                        char **passwordp, char **hostp, int *port);
+                        char **passwordp, char **hostp, apr_port_t *port);
 const char *ap_proxy_date_canon(apr_pool_t *p, const char *x);
 apr_table_t *ap_proxy_read_headers(request_rec *r, request_rec *rp, char *buffer, int size, conn_rec *c);
 int ap_proxy_liststr(const char *list, const char *val);
@@ -255,7 +255,7 @@ void ap_proxy_reset_output_filters(conn_rec *c);
 
 
 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))
+AP_DECLARE_HOOK(int, proxy_canon_handler, (request_rec *r, char *url))
 
 
 #endif /*MOD_PROXY_H*/
index 133d510a0f2aed4e4bf384e5b065f6d6d1f58b9c..84caf3765f3d6576ed4186c374733cb8fd95972a 100644 (file)
@@ -100,6 +100,18 @@ allowed_port(proxy_server_conf *conf, int port)
     return 0;
 }
 
+/* canonicalise CONNECT URLs. */
+int ap_proxy_connect_canon(request_rec *r, char *url)
+{
+
+    if (r->method_number != M_CONNECT) {
+       return DECLINED;
+    }
+
+    return OK;
+}
+
+/* CONNECT handler */
 int ap_proxy_connect_handler(request_rec *r, char *url,
                          const char *proxyname, apr_port_t proxyport)
 {
@@ -122,6 +134,10 @@ int ap_proxy_connect_handler(request_rec *r, char *url,
     proxy_server_conf *conf =
     (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
 
+    /* is this for us? */
+    if (r->method_number != M_CONNECT) {
+       return DECLINED;
+    }
 
     /*
      * Step One: Determine Who To Connect To
@@ -388,6 +404,7 @@ int ap_proxy_connect_handler(request_rec *r, char *url,
 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);
 }
 
 module AP_MODULE_DECLARE_DATA proxy_connect_module = {
index effa19aeac72643049a734e726d04b6dec19acc9..ba68475edbd7dd0689ce1c7f6327da6399ac6562 100644 (file)
@@ -113,14 +113,23 @@ static int ftp_check_string(const char *x)
 /*
  * Canonicalise ftp URLs.
  */
-int ap_proxy_ftp_canon(request_rec *r, char *url, const char *scheme, apr_port_t def_port)
+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;
     const char *err;
-    int port;
+    apr_port_t port, def_port;
 
-    port = DEFAULT_FTP_PORT;
+    /* */
+    if (strncasecmp(url, "ftp:", 4) == 0) {
+       url += 4;
+    }
+    else {
+       return DECLINED;
+    }
+    def_port = ap_default_port_for_scheme("ftp");
+
+    port = def_port;
     err = ap_proxy_canon_netloc(p, &url, &user, &password, &host, &port);
     if (err)
        return HTTP_BAD_REQUEST;
@@ -129,12 +138,12 @@ int ap_proxy_ftp_canon(request_rec *r, char *url, const char *scheme, apr_port_t
     if (password != NULL && !ftp_check_string(password))
        return HTTP_BAD_REQUEST;
 
-/* now parse path/parameters args, according to rfc1738 */
-/* N.B. if this isn't a true proxy request, then the URL path
- * (but not query args) has already been decoded.
- * This gives rise to the problem of a ; being decoded into the
- * path.
- */
+    /* now parse path/parameters args, according to rfc1738 */
+    /* N.B. if this isn't a true proxy request, then the URL path
    * (but not query args) has already been decoded.
    * This gives rise to the problem of a ; being decoded into the
    * path.
    */
     strp = strchr(url, ';');
     if (strp != NULL) {
        *(strp++) = '\0';
@@ -170,7 +179,7 @@ int ap_proxy_ftp_canon(request_rec *r, char *url, const char *scheme, apr_port_t
 
 /* now, rebuild URL */
 
-    if (port != DEFAULT_FTP_PORT)
+    if (port != def_port)
        apr_snprintf(sport, sizeof(sport), ":%d", port);
     else
        sport[0] = '\0';
index 9b1411fc81abcc20d5b5161239e2ed210c4cc2c2..8e24dd848da08270655d8d8f91eacfff64779e40 100644 (file)
@@ -68,25 +68,40 @@ module AP_MODULE_DECLARE_DATA proxy_http_module;
  *  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, apr_port_t def_port)
+int ap_proxy_http_canon(request_rec *r, char *url)
 {
     char *host, *path, *search, sport[7];
     const char *err;
-    int port;
+    const char *scheme;
+    apr_port_t port, def_port;
 
-/* do syntatic check.
- * We break the URL into host, port, path, search
- */
+    /* ap_default_port_for_scheme() */
+    if (strncasecmp(url, "http:", 5) == 0) {
+       url += 5;
+       scheme = "http";
+    }
+    else if (strncasecmp(url, "https:", 6) == 0) {
+       url += 6;
+       scheme = "https:";
+    }
+    else {
+       return DECLINED;
+    }
+    def_port = ap_default_port_for_scheme(scheme);
+
+    /* do syntatic check.
+     * We break the URL into host, port, path, search
+     */
     port = def_port;
     err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
     if (err)
        return HTTP_BAD_REQUEST;
 
-/* now parse path/search args, according to rfc1738 */
-/* N.B. if this isn't a true proxy request, then the URL _path_
- * has already been decoded.  True proxy requests have r->uri
- * == r->unparsed_uri, and no others have that property.
- */
+    /* now parse path/search args, according to rfc1738 */
+    /* N.B. if this isn't a true proxy request, then the URL _path_
    * has already been decoded.  True proxy requests have r->uri
    * == r->unparsed_uri, and no others have that property.
    */
     if (r->uri == r->unparsed_uri) {
        search = strchr(url, '?');
        if (search != NULL)
@@ -95,7 +110,7 @@ int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme, apr_port_
     else
        search = r->args;
 
-/* process path */
+    /* process path */
     path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, r->proxyreq);
     if (path == NULL)
        return HTTP_BAD_REQUEST;
index 8a99573764bbc5e55217f2ccbf779cc6fa0d4870..f7c173eebc37de64f090037a7086e46f4acb5c16 100644 (file)
@@ -209,9 +209,9 @@ char *ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
  */
 char *
      ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
-                       char **passwordp, char **hostp, int *port)
+                       char **passwordp, char **hostp, apr_port_t *port)
 {
-    int i;
+    apr_port_t i;
     char *strp, *host, *url = *urlp;
     char *user = NULL, *password = NULL;
 
@@ -635,7 +635,7 @@ static const char *
      proxy_get_host_of_request(request_rec *r)
 {
     char *url, *user = NULL, *password = NULL, *err, *host;
-    int port = -1;
+    apr_port_t port = -1;
 
     if (r->hostname != NULL)
        return r->hostname;