Author: jfclere
Date: Tue Jun 12 08:32:10 2007
New Revision: 546531

URL: http://svn.apache.org/viewvc?view=rev&rev=546531
Log:
Add ForwardURIProxy to the URl handling option.
common/jk_url.c is just a porting of the routines
from proxy_util.c (Apache httpd).

Added:
    tomcat/connectors/trunk/jk/native/common/jk_url.c
    tomcat/connectors/trunk/jk/native/common/jk_url.h
Modified:
    tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c
    tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c
    tomcat/connectors/trunk/jk/native/common/jk_global.h
    tomcat/connectors/trunk/jk/native/common/list.mk.in

Modified: tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c?view=diff&rev=546531&r1=546530&r2=546531
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c Tue Jun 12 08:32:10 
2007
@@ -60,6 +60,7 @@
 #include "jk_uri_worker_map.h"
 #include "jk_ajp13.h"
 #include "jk_shm.h"
+#include "jk_url.h"
 
 #define JK_LOG_DEF_FILE             ("logs/mod_jk.log")
 #define JK_SHM_DEF_FILE             ("logs/jk-runtime-status")
@@ -519,6 +520,7 @@
     request_rec *r = private_data->r;
     char *ssl_temp = NULL;
     s->route = NULL;        /* Used for sticky session routing */
+    int size;
 
     /* Copy in function pointers (which are really methods) */
     s->start_response = ws_start_response;
@@ -627,6 +629,13 @@
         s->req_uri = r->uri;
         break;
 
+    case JK_OPT_FWDURIPROXY:
+        size = strlen(r->uri);
+        s->req_uri = ap_palloc(r->pool, size * 3 + 1);
+        jk_canonenc(s->req_uri, r->uri, size, enc_path, 0,
+                    JK_PROXYREQ_REVERSE);
+        break;
+
     case JK_OPT_FWDURIESCAPED:
         s->req_uri = ap_escape_uri(r->pool, r->uri);
         break;
@@ -1725,6 +1734,10 @@
         }
         else if (!strcasecmp(w, "ForwardURIEscaped")) {
             opt = JK_OPT_FWDURIESCAPED;
+            mask = JK_OPT_FWDURIMASK;
+        }
+        else if (!strcasecmp(w, "ForwardURIProxy")) {
+            opt = JK_OPT_FWDURIPROXY;
             mask = JK_OPT_FWDURIMASK;
         }
         else if (!strcasecmp(w, "ForwardDirectories")) {

Modified: tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c?view=diff&rev=546531&r1=546530&r2=546531
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c Tue Jun 12 08:32:10 
2007
@@ -102,6 +102,7 @@
 #include "jk_util.h"
 #include "jk_worker.h"
 #include "jk_shm.h"
+#include "jk_url.h"
 
 #define JK_LOG_DEF_FILE             ("logs/mod_jk.log")
 #define JK_SHM_DEF_FILE             ("logs/jk-runtime-status")
@@ -539,6 +540,7 @@
     request_rec *r = private_data->r;
 
     char *ssl_temp = NULL;
+    int size;
     s->route = NULL;        /* Used for sticky session routing */
 
     /* Copy in function pointers (which are really methods) */
@@ -655,6 +657,13 @@
         s->req_uri = r->uri;
         break;
 
+    case JK_OPT_FWDURIPROXY:
+        size = strlen(r->uri);
+        s->req_uri = apr_palloc(r->pool, size * 3 + 1);
+        jk_canonenc(s->req_uri, r->uri, size, enc_path, 0, 
+                    JK_PROXYREQ_REVERSE);
+        break;
+
     case JK_OPT_FWDURIESCAPED:
         s->req_uri = ap_escape_uri(r->pool, r->uri);
         break;
@@ -1758,6 +1767,10 @@
         }
         else if (!strcasecmp(w, "ForwardURIEscaped")) {
             opt = JK_OPT_FWDURIESCAPED;
+            mask = JK_OPT_FWDURIMASK;
+        }
+        else if (!strcasecmp(w, "ForwardURIProxy")) {
+            opt = JK_OPT_FWDURIPROXY;
             mask = JK_OPT_FWDURIMASK;
         }
         else if (!strcasecmp(w, "ForwardDirectories")) {

Modified: tomcat/connectors/trunk/jk/native/common/jk_global.h
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_global.h?view=diff&rev=546531&r1=546530&r2=546531
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_global.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_global.h Tue Jun 12 08:32:10 
2007
@@ -228,15 +228,16 @@
  * JK options
  */
 
-#define JK_OPT_FWDURIMASK           0x0003
+#define JK_OPT_FWDURIMASK           0x0007
 
 #define JK_OPT_FWDURICOMPAT         0x0001
 #define JK_OPT_FWDURICOMPATUNPARSED 0x0002
 #define JK_OPT_FWDURIESCAPED        0x0003
+#define JK_OPT_FWDURIPROXY          0x0004
 
-#define JK_OPT_FWDURIDEFAULT        JK_OPT_FWDURICOMPAT
+#define JK_OPT_FWDURIDEFAULT        JK_OPT_FWDURIPROXY
 
-#define JK_OPT_FWDKEYSIZE           0x0004
+#define JK_OPT_FWDKEYSIZE           0x0200
 
 #define JK_OPT_FWDDIRS              0x0008
 /* Forward local instead remote address */

Added: tomcat/connectors/trunk/jk/native/common/jk_url.c
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_url.c?view=auto&rev=546531
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_url.c (added)
+++ tomcat/connectors/trunk/jk/native/common/jk_url.c Tue Jun 12 08:32:10 2007
@@ -0,0 +1,218 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/***************************************************************************
+ * Description: URL manupilation subroutines. (ported from mod_proxy).     *
+ * Version:     $Revision: 531816 $                                        *
+ ***************************************************************************/
+
+#include "jk_global.h"
+#include "jk_url.h"
+
+#ifdef HAVE_APR
+#define JK_ISXDIGIT(x) apr_isxdigit((x))
+#define JK_ISDIGIT(x)  apr_isdigit((x))
+#define JK_ISUPPER(x)  apr_isupper((x))
+#define JK_ISALNUM(x)  apr_isalnum((x))
+#else
+#define JK_ISXDIGIT(x) isxdigit((int)(unsigned char)((x)))
+#define JK_ISDIGIT(x)  isdigit((int)(unsigned char)((x)))
+#define JK_ISUPPER(x)  isupper((int)(unsigned char)((x)))
+#define JK_ISALNUM(x)  isalnum((int)(unsigned char)((x)))
+#endif
+
+/* already called in the knowledge that the characters are hex digits */
+static  int jk_hex2c(const char *x)
+{
+    int i, ch;
+
+#if !CHARSET_EBCDIC
+    ch = x[0];
+    if (JK_ISDIGIT(ch)) {
+        i = ch - '0';
+    }
+    else if (JK_ISUPPER(ch)) {
+        i = ch - ('A' - 10);
+    }
+    else {
+        i = ch - ('a' - 10);
+    }
+    i <<= 4;
+
+    ch = x[1];
+    if (JK_ISDIGIT(ch)) {
+        i += ch - '0';
+    }
+    else if (JK_ISUPPER(ch)) {
+        i += ch - ('A' - 10);
+    }
+    else {
+        i += ch - ('a' - 10);
+    }
+    return i;
+#else /*CHARSET_EBCDIC*/
+    /*
+     * we assume that the hex value refers to an ASCII character
+     * so convert to EBCDIC so that it makes sense locally;
+     *
+     * example:
+     *
+     * client specifies %20 in URL to refer to a space char;
+     * at this point we're called with EBCDIC "20"; after turning
+     * EBCDIC "20" into binary 0x20, we then need to assume that 0x20
+     * represents an ASCII char and convert 0x20 to EBCDIC, yielding
+     * 0x40
+     */
+    char buf[1];
+
+    if (1 == sscanf(x, "%2x", &i)) {
+        buf[0] = i & 0xFF;
+        jk_xlate_from_ascii(buf, 1);
+        return buf[0];
+    }
+    else {
+        return 0;
+    }
+#endif /*CHARSET_EBCDIC*/
+}
+
+static void jk_c2hex(int ch, char *x)
+{
+#if !CHARSET_EBCDIC
+    int i;
+
+    x[0] = '%';
+    i = (ch & 0xF0) >> 4;
+    if (i >= 10) {
+        x[1] = ('A' - 10) + i;
+    }
+    else {
+        x[1] = '0' + i;
+    }
+
+    i = ch & 0x0F;
+    if (i >= 10) {
+        x[2] = ('A' - 10) + i;
+    }
+    else {
+        x[2] = '0' + i;
+    }
+#else /*CHARSET_EBCDIC*/
+    static const char ntoa[] = { "0123456789ABCDEF" };
+    char buf[1];
+
+    ch &= 0xFF;
+
+    buf[0] = ch;
+    jk_xlate_to_ascii(buf, 1);
+
+    x[0] = '%';
+    x[1] = ntoa[(buf[0] >> 4) & 0x0F];
+    x[2] = ntoa[buf[0] & 0x0F];
+    x[3] = '\0';
+#endif /*CHARSET_EBCDIC*/
+}
+
+/*
+ * canonicalise a URL-encoded string
+ */
+
+/*
+ * Convert a URL-encoded string to canonical form.
+ * It decodes characters which need not be encoded,
+ * and encodes those which must be encoded, and does not touch
+ * those which must not be touched.
+ */
+char * jk_canonenc(char *y, const char *x, int len,
+                                       enum enctype t, int forcedec,
+                                       int proxyreq)
+{
+    int i, j, ch;
+    char *allowed;  /* characters which should not be encoded */
+    char *reserved; /* characters which much not be en/de-coded */
+
+/*
+ * N.B. in addition to :@&=, this allows ';' in an http path
+ * and '?' in an ftp path -- this may be revised
+ *
+ * Also, it makes a '+' character in a search string reserved, as
+ * it may be form-encoded. (Although RFC 1738 doesn't allow this -
+ * it only permits ; / ? : @ = & as reserved chars.)
+ */
+    if (t == enc_path) {
+        allowed = "~$-_.+!*'(),;:@&=";
+    }
+    else if (t == enc_search) {
+        allowed = "$-_.!*'(),;:@&=";
+    }
+    else if (t == enc_user) {
+        allowed = "$-_.+!*'(),;@&=";
+    }
+    else if (t == enc_fpath) {
+        allowed = "$-_.+!*'(),?:@&=";
+    }
+    else {            /* if (t == enc_parm) */
+        allowed = "$-_.+!*'(),?/:@&=";
+    }
+
+    if (t == enc_path) {
+        reserved = "/";
+    }
+    else if (t == enc_search) {
+        reserved = "+";
+    }
+    else {
+        reserved = "";
+    }
+
+    /* y = apr_palloc(p, 3 * len + 1); */
+
+    for (i = 0, j = 0; i < len; i++, j++) {
+/* always handle '/' first */
+        ch = x[i];
+        if (strchr(reserved, ch)) {
+            y[j] = ch;
+            continue;
+        }
+/*
+ * decode it if not already done. do not decode reverse proxied URLs
+ * unless specifically forced
+ */
+        if ((forcedec || (proxyreq && proxyreq != JK_PROXYREQ_REVERSE)) && ch 
== '%') {
+            if (!JK_ISXDIGIT(x[i + 1]) || !JK_ISXDIGIT(x[i + 2])) {
+                return NULL;
+            }
+            ch = jk_hex2c(&x[i + 1]);
+            i += 2;
+            if (ch != 0 && strchr(reserved, ch)) {  /* keep it encoded */
+                jk_c2hex(ch, &y[j]);
+                j += 2;
+                continue;
+            }
+        }
+/* recode it, if necessary */
+        if (!JK_ISALNUM(ch) && !strchr(allowed, ch)) {
+            jk_c2hex(ch, &y[j]);
+            j += 2;
+        }
+        else {
+            y[j] = ch;
+        }
+    }
+    y[j] = '\0';
+    return y;
+}

Added: tomcat/connectors/trunk/jk/native/common/jk_url.h
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_url.h?view=auto&rev=546531
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_url.h (added)
+++ tomcat/connectors/trunk/jk/native/common/jk_url.h Tue Jun 12 08:32:10 2007
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/***************************************************************************
+ * Description: URL manupilation subroutines header file. (mod_proxy)      *
+ * Version:     $Revision: 500534 $                                        *
+ ***************************************************************************/
+#ifndef _JK_URL_H
+#define _JK_URL_H
+
+#include "jk_global.h"
+#include "jk_pool.h"
+#include "jk_util.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif                          /* __cplusplus */
+
+/* for proxy_canonenc() */
+enum enctype {
+    enc_path, enc_search, enc_user, enc_fpath, enc_parm
+};
+
+#define JK_PROXYREQ_NONE 0         /**< No proxy */
+#define JK_PROXYREQ_PROXY 1        /**< Standard proxy */
+#define JK_PROXYREQ_REVERSE 2      /**< Reverse proxy */
+#define JK_PROXYREQ_RESPONSE 3     /**< Origin response */
+
+/*
+ * Do a canonical encoding of the x url y contains the result
+ * and should have a size of at least 3 * len + 1 bytes.
+ */
+char * jk_canonenc(char *y, const char *x, int len,
+                   enum enctype t, int forcedec, int proxyreq);
+
+#ifdef __cplusplus
+}
+#endif  /* __cplusplus */
+#endif  /* _JK_URL_H */

Modified: tomcat/connectors/trunk/jk/native/common/list.mk.in
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/list.mk.in?view=diff&rev=546531&r1=546530&r2=546531
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/list.mk.in (original)
+++ tomcat/connectors/trunk/jk/native/common/list.mk.in Tue Jun 12 08:32:10 2007
@@ -8,4 +8,5 @@
                 ${JK}jk_ajp14${OEXT} ${JK}jk_ajp14_worker${OEXT} \
                 ${JK}jk_md5${OEXT} ${JK}jk_shm${OEXT} @JK_JNI_WORKER@ \
                 ${JK}jk_ajp_common${OEXT} ${JK}jk_context${OEXT} \
+                ${JK}jk_url${OEXT} \
                 ${JK}jk_status${OEXT}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to