tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/native2/server/isapi iis.h jk_isapi_plugin.c jk_service_iis.c
Date Fri, 19 Apr 2002 00:20:14 GMT
nacho       02/04/18 17:20:14

  Modified:    jk/native2/server/isapi iis.h jk_isapi_plugin.c
                        jk_service_iis.c
  Log:
  * Work in progess..
  
  jk_service_iis..c compiles.. i think it's almost done..
  
  Revision  Changes    Path
  1.2       +145 -6    jakarta-tomcat-connectors/jk/native2/server/isapi/iis.h
  
  Index: iis.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/server/isapi/iis.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- iis.h	18 Apr 2002 15:03:32 -0000	1.1
  +++ iis.h	19 Apr 2002 00:20:13 -0000	1.2
  @@ -1,4 +1,63 @@
  -//static jk_worker_env_t worker_env;
  +/* ========================================================================= *
  + *                                                                           *
  + *                 The Apache Software License,  Version 1.1                 *
  + *                                                                           *
  + *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
  + *                           All rights reserved.                            *
  + *                                                                           *
  + * ========================================================================= *
  + *                                                                           *
  + * Redistribution and use in source and binary forms,  with or without modi- *
  + * fication, are permitted provided that the following conditions are met:   *
  + *                                                                           *
  + * 1. Redistributions of source code  must retain the above copyright notice *
  + *    notice, this list of conditions and the following disclaimer.          *
  + *                                                                           *
  + * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
  + *    notice,  this list of conditions  and the following  disclaimer in the *
  + *    documentation and/or other materials provided with the distribution.   *
  + *                                                                           *
  + * 3. The end-user documentation  included with the redistribution,  if any, *
  + *    must include the following acknowlegement:                             *
  + *                                                                           *
  + *       "This product includes  software developed  by the Apache  Software *
  + *        Foundation <http://www.apache.org/>."                              *
  + *                                                                           *
  + *    Alternately, this acknowlegement may appear in the software itself, if *
  + *    and wherever such third-party acknowlegements normally appear.         *
  + *                                                                           *
  + * 4. The names  "The  Jakarta  Project",  "Jk",  and  "Apache  Software     *
  + *    Foundation"  must not be used  to endorse or promote  products derived *
  + *    from this  software without  prior  written  permission.  For  written *
  + *    permission, please contact <apache@apache.org>.                        *
  + *                                                                           *
  + * 5. Products derived from this software may not be called "Apache" nor may *
  + *    "Apache" appear in their names without prior written permission of the *
  + *    Apache Software Foundation.                                            *
  + *                                                                           *
  + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
  + * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
  + * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
  + * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
  + * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
  + * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
  + * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
  + * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
  + * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
  + * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
  + * POSSIBILITY OF SUCH DAMAGE.                                               *
  + *                                                                           *
  + * ========================================================================= *
  + *                                                                           *
  + * This software  consists of voluntary  contributions made  by many indivi- *
  + * duals on behalf of the  Apache Software Foundation.  For more information *
  + * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
  + *                                                                           *
  + * ========================================================================= */
  +
  +#ifndef IIS_H
  +#define IIS_H
  +
   #define _WIN32_WINNT 0x0400
   
   #include <httpext.h>
  @@ -9,9 +68,14 @@
   //#include "jk_util.h"
   #include "jk_pool.h"
   
  +#ifdef __cplusplus
  +extern "C" {
  +#endif /* __cplusplus */
  +
  +
  +
   struct isapi_private_data {
  -    jk_pool_t p;
  -    
  +    jk_pool_t p;    
       int request_started;
       unsigned bytes_read_so_far;
       LPEXTENSION_CONTROL_BLOCK  lpEcb;
  @@ -20,12 +84,87 @@
   
   
   
  -static int JK_METHOD start_response(jk_env_t *env, jk_ws_service_t *s );
  +#define VERSION_STRING "Jakarta/ISAPI/1.2Dev"
  +
  +#define DEFAULT_WORKER_NAME ("ajp13")
  +/*
  + * We use special headers to pass values from the filter to the 
  + * extension. These values are:
  + *
  + * 1. The real URI before redirection took place
  + * 2. The name of the worker to be used.
  + * 3. The contents of the Translate header, if any
  + *
  + */
  +#define URI_HEADER_NAME         ("TOMCATURI:")
  +#define QUERY_HEADER_NAME       ("TOMCATQUERY:")
  +#define WORKER_HEADER_NAME      ("TOMCATWORKER:")
  +#define TOMCAT_TRANSLATE_HEADER_NAME ("TOMCATTRANSLATE:")
  +#define CONTENT_LENGTH          ("CONTENT_LENGTH:")
  +
  +#define HTTP_URI_HEADER_NAME     ("HTTP_TOMCATURI")
  +#define HTTP_QUERY_HEADER_NAME   ("HTTP_TOMCATQUERY")
  +#define HTTP_WORKER_HEADER_NAME  ("HTTP_TOMCATWORKER")
  +
  +#define REGISTRY_LOCATION       ("Software\\Apache Software Foundation\\Jakarta Isapi Redirector\\1.2")
  +#define EXTENSION_URI_TAG       ("extension_uri")
  +
  +#define URI_SELECT_TAG          ("uri_select")
  +
  +#define URI_SELECT_PARSED_VERB      ("parsed")
  +#define URI_SELECT_UNPARSED_VERB    ("unparsed")
  +#define URI_SELECT_ESCAPED_VERB     ("escaped")
  +
  +#define BAD_REQUEST		-1
  +#define BAD_PATH		-2
  +#define MAX_SERVERNAME			128
  +
  +
  +#define GET_SERVER_VARIABLE_VALUE(name, place) {    \
  +    (place) = NULL;                                   \
  +    huge_buf_sz = sizeof(huge_buf);                 \
  +    if (get_server_value(private_data->lpEcb,        \
  +                        (name),                     \
  +                        huge_buf,                   \
  +                        huge_buf_sz,                \
  +                        "")) {                      \
  +        (place) = private_data->p.pstrdup(env,&private_data->p,huge_buf);   \
  +    }   \
  +}\
  +
  +#define GET_SERVER_VARIABLE_VALUE_INT(name, place, def) {   \
  +    huge_buf_sz = sizeof(huge_buf);                 \
  +    if (get_server_value(private_data->lpEcb,        \
  +                        (name),                     \
  +                        huge_buf,                   \
  +                        huge_buf_sz,                \
  +                        "")) {                      \
  +        (place) = atoi(huge_buf);                   \
  +        if (0 == (place)) {                          \
  +            (place) = def;                          \
  +        }                                           \
  +    } else {    \
  +        (place) = def;  \
  +    }           \
  +}\
   
  -static int JK_METHOD read(jk_env_t *env, jk_ws_service_t *s,
  +
  +static int JK_METHOD jk2_service_iis_head(jk_env_t *env, jk_ws_service_t *s );
  +
  +static int JK_METHOD jk2_service_iis_read(jk_env_t *env, jk_ws_service_t *s,
                             void *b, unsigned len,
                             unsigned *actually_read);
   
  -static int JK_METHOD write(jk_env_t *env,jk_ws_service_t *s,
  +static int JK_METHOD jk2_service_iis_write(jk_env_t *env,jk_ws_service_t *s,
                              const void *b,
                              unsigned l);
  +
  +static int JK_METHOD jk2_service_iis_init_ws_service( struct jk_env *env, jk_ws_service_t
*_this,
  +                 struct jk_worker *w, void *serverObj );
  +
  +
  +#ifdef __cplusplus
  +}
  +#endif /* __cplusplus */
  +
  +#endif 
  
  
  
  1.2       +5 -226    jakarta-tomcat-connectors/jk/native2/server/isapi/jk_isapi_plugin.c
  
  Index: jk_isapi_plugin.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/server/isapi/jk_isapi_plugin.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- jk_isapi_plugin.c	18 Apr 2002 19:46:31 -0000	1.1
  +++ jk_isapi_plugin.c	19 Apr 2002 00:20:13 -0000	1.2
  @@ -60,7 +60,7 @@
    * Author:      Gal Shachor <shachor@il.ibm.com>                           *
    * Author:      Larry Isaacs <larryi@apache.org>                           *
    * Author:      Ignacio J. Ortega <nacho@apache.org>                       *
  - * Version:     $Revision: 1.1 $                                           *
  + * Version:     $Revision: 1.2 $                                           *
    ***************************************************************************/
   
   // This define is needed to include wincrypt,h, needed to get client certificates
  @@ -83,69 +83,6 @@
   
   #define jk_log(a,b,c)
   
  -#define VERSION_STRING "Jakarta/ISAPI/2.0Dev"
  -
  -#define DEFAULT_WORKER_NAME ("ajp13")
  -/*
  - * We use special headers to pass values from the filter to the 
  - * extension. These values are:
  - *
  - * 1. The real URI before redirection took place
  - * 2. The name of the worker to be used.
  - * 3. The contents of the Translate header, if any
  - *
  - */
  -#define URI_HEADER_NAME         ("TOMCATURI:")
  -#define QUERY_HEADER_NAME       ("TOMCATQUERY:")
  -#define WORKER_HEADER_NAME      ("TOMCATWORKER:")
  -#define TOMCAT_TRANSLATE_HEADER_NAME ("TOMCATTRANSLATE:")
  -#define CONTENT_LENGTH          ("CONTENT_LENGTH:")
  -
  -#define HTTP_URI_HEADER_NAME     ("HTTP_TOMCATURI")
  -#define HTTP_QUERY_HEADER_NAME   ("HTTP_TOMCATQUERY")
  -#define HTTP_WORKER_HEADER_NAME  ("HTTP_TOMCATWORKER")
  -
  -#define REGISTRY_LOCATION       ("Software\\Apache Software Foundation\\Jakarta Isapi Redirector\\1.0")
  -#define EXTENSION_URI_TAG       ("extension_uri")
  -
  -#define URI_SELECT_TAG          ("uri_select")
  -
  -#define URI_SELECT_PARSED_VERB      ("parsed")
  -#define URI_SELECT_UNPARSED_VERB    ("unparsed")
  -#define URI_SELECT_ESCAPED_VERB     ("escaped")
  -
  -#define BAD_REQUEST		-1
  -#define BAD_PATH		-2
  -#define MAX_SERVERNAME			128
  -
  -
  -#define GET_SERVER_VARIABLE_VALUE(name, place) {    \
  -    (place) = NULL;                                   \
  -    huge_buf_sz = sizeof(huge_buf);                 \
  -    if (get_server_value(private_data->lpEcb,        \
  -                        (name),                     \
  -                        huge_buf,                   \
  -                        huge_buf_sz,                \
  -                        "")) {                      \
  -        (place) = jk_pool_strdup(&private_data->p, huge_buf);   \
  -    }   \
  -}\
  -
  -#define GET_SERVER_VARIABLE_VALUE_INT(name, place, def) {   \
  -    huge_buf_sz = sizeof(huge_buf);                 \
  -    if (get_server_value(private_data->lpEcb,        \
  -                        (name),                     \
  -                        huge_buf,                   \
  -                        huge_buf_sz,                \
  -                        "")) {                      \
  -        (place) = atoi(huge_buf);                   \
  -        if (0 == (place)) {                          \
  -            (place) = def;                          \
  -        }                                           \
  -    } else {    \
  -        (place) = def;  \
  -    }           \
  -}\
   
   static char  ini_file_name[MAX_PATH];
   static int   using_ini_file = JK_FALSE;
  @@ -155,8 +92,6 @@
   
   static jk_workerEnv_t *workerEnv;
   static jk_logger_t *logger = NULL; 
  -static char *SERVER_NAME = "SERVER_NAME";
  -static char *SERVER_SOFTWARE = "SERVER_SOFTWARE";
   
   
   static char extension_uri[INTERNET_MAX_URL_LENGTH] = "/jakarta/isapi_redirector2.dll";
  @@ -202,164 +137,6 @@
                                 int len);
   
   
  -static char x2c(const char *what)
  -{
  -    register char digit;
  -
  -    digit = ((what[0] >= 'A') ? ((what[0] & 0xdf) - 'A') + 10 : (what[0] - '0'));
  -    digit *= 16;
  -    digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A') + 10 : (what[1] - '0'));
  -    return (digit);
  -}
  -
  -static int unescape_url(char *url)
  -{
  -    register int x, y, badesc, badpath;
  -
  -    badesc = 0;
  -    badpath = 0;
  -    for (x = 0, y = 0; url[y]; ++x, ++y) {
  -        if (url[y] != '%')
  -            url[x] = url[y];
  -        else {
  -            if (!isxdigit(url[y + 1]) || !isxdigit(url[y + 2])) {
  -                badesc = 1;
  -                url[x] = '%';
  -            }
  -            else {
  -                url[x] = x2c(&url[y + 1]);
  -                y += 2;
  -                if (url[x] == '/' || url[x] == '\0')
  -                    badpath = 1;
  -            }
  -        }
  -    }
  -    url[x] = '\0';
  -    if (badesc)
  -            return BAD_REQUEST;
  -    else if (badpath)
  -            return BAD_PATH;
  -    else
  -            return 0;
  -}
  -
  -static void getparents(char *name)
  -{
  -    int l, w;
  -
  -    /* Four paseses, as per RFC 1808 */
  -    /* a) remove ./ path segments */
  -
  -    for (l = 0, w = 0; name[l] != '\0';) {
  -        if (name[l] == '.' && name[l + 1] == '/' && (l == 0 || name[l -
1] == '/'))
  -            l += 2;
  -        else
  -            name[w++] = name[l++];
  -    }
  -
  -    /* b) remove trailing . path, segment */
  -    if (w == 1 && name[0] == '.')
  -        w--;
  -    else if (w > 1 && name[w - 1] == '.' && name[w - 2] == '/')
  -        w--;
  -    name[w] = '\0';
  -
  -    /* c) remove all xx/../ segments. (including leading ../ and /../) */
  -    l = 0;
  -
  -    while (name[l] != '\0') {
  -        if (name[l] == '.' && name[l + 1] == '.' && name[l + 2] == '/'
&&
  -            (l == 0 || name[l - 1] == '/')) {
  -            register int m = l + 3, n;
  -
  -            l = l - 2;
  -            if (l >= 0) {
  -                while (l >= 0 && name[l] != '/')
  -                    l--;
  -                l++;
  -            }
  -            else
  -                l = 0;
  -            n = l;
  -            while ((name[n] = name[m]))
  -                (++n, ++m);
  -        }
  -        else
  -            ++l;
  -    }
  -
  -    /* d) remove trailing xx/.. segment. */
  -    if (l == 2 && name[0] == '.' && name[1] == '.')
  -        name[0] = '\0';
  -    else if (l > 2 && name[l - 1] == '.' && name[l - 2] == '.' &&
name[l - 3] == '/') {
  -        l = l - 4;
  -        if (l >= 0) {
  -            while (l >= 0 && name[l] != '/')
  -                l--;
  -            l++;
  -        }
  -        else
  -            l = 0;
  -        name[l] = '\0';
  -    }
  -}
  -
  -/* Apache code to escape a URL */
  -
  -#define T_OS_ESCAPE_PATH	(4)
  -
  -static const unsigned char test_char_table[256] = {
  -    0,14,14,14,14,14,14,14,14,14,15,14,14,14,14,14,14,14,14,14,
  -    14,14,14,14,14,14,14,14,14,14,14,14,14,0,7,6,1,6,1,1,
  -    9,9,1,0,8,0,0,10,0,0,0,0,0,0,0,0,0,0,8,15,
  -    15,8,15,15,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  -    0,0,0,0,0,0,0,0,0,0,0,15,15,15,7,0,7,0,0,0,
  -    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  -    0,0,0,15,7,15,1,14,6,6,6,6,6,6,6,6,6,6,6,6,
  -    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  -    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  -    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  -    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  -    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  -    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6 
  -};
  -
  -#define TEST_CHAR(c, f)	(test_char_table[(unsigned)(c)] & (f))
  -
  -static const char c2x_table[] = "0123456789abcdef";
  -
  -static unsigned char *c2x(unsigned what, unsigned char *where)
  -{
  -    *where++ = '%';
  -    *where++ = c2x_table[what >> 4];
  -    *where++ = c2x_table[what & 0xf];
  -    return where;
  -}
  -
  -static int escape_url(const char *path, char *dest, int destsize)
  -{
  -    const unsigned char *s = (const unsigned char *)path;
  -    unsigned char *d = (unsigned char *)dest;
  -    unsigned char *e = dest + destsize - 1;
  -    unsigned char *ee = dest + destsize - 3;
  -    unsigned c;
  -
  -    while ((c = *s)) {
  -	if (TEST_CHAR(c, T_OS_ESCAPE_PATH)) {
  -            if (d >= ee )
  -                return JK_FALSE;
  -	    d = c2x(c, d);
  -	}
  -	else {
  -            if (d >= e )
  -                return JK_FALSE;
  -	    *d++ = c;
  -	}
  -	++s;
  -    }
  -    *d = '\0';
  -    return JK_TRUE;
  -}
   
   static int uri_is_web_inf(char *uri)
   {
  @@ -1023,7 +800,9 @@
   
   /** Basic initialization for jk2.
    */
  -static void jk2_create_workerEnv(apr_pool_t *p, server_rec *s) {
  +
  +
  +static void jk2_create_workerEnv(apr_pool_t *p /*, server_rec *s*/) {
       jk_env_t *env;
       jk_logger_t *l;
       jk_pool_t *globalPool;
  @@ -1081,7 +860,7 @@
       workerEnv->_private = s;
   }
   
  -static void *jk2_create_config(apr_pool_t *p, server_rec *s)
  +static void *jk2_create_config(apr_pool_t *p /*, server_rec *s*/)
   {
       jk_uriEnv_t *newUri;
       jk_bean_t *jkb;
  
  
  
  1.2       +311 -150  jakarta-tomcat-connectors/jk/native2/server/isapi/jk_service_iis.c
  
  Index: jk_service_iis.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/server/isapi/jk_service_iis.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- jk_service_iis.c	18 Apr 2002 15:03:32 -0000	1.1
  +++ jk_service_iis.c	19 Apr 2002 00:20:13 -0000	1.2
  @@ -60,7 +60,7 @@
    * Author:      Gal Shachor <shachor@il.ibm.com>                           
    *              Henri Gomez <hgomez@slib.fr> 
    *				Ignacio J. Ortega <nacho@apache.org>
  - * Version:     $Revision: 1.1 $                                           
  + * Version:     $Revision: 1.2 $                                           
    */
   
   // This define is needed to include wincrypt,h, needed to get client certificates
  @@ -81,7 +81,242 @@
   #include "iis.h"
   //#include "jk_uri_worker_map.h"
   
  -#define jk_log(a,b,c)
  +
  +static char *SERVER_NAME = "SERVER_NAME";
  +static char *SERVER_SOFTWARE = "SERVER_SOFTWARE";
  +
  +static const char begin_cert [] = 
  +	"-----BEGIN CERTIFICATE-----\r\n";
  +
  +static const char end_cert [] = 
  +	"-----END CERTIFICATE-----\r\n";
  +
  +static const char basis_64[] =
  +    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  +
  +static int base64_encode_cert_len(int len)
  +{
  +	int n = ((len + 2) / 3 * 4) + 1; // base64 encoded size
  +	n += (n + 63 / 64) * 2; // add CRLF's
  +	n += sizeof(begin_cert) + sizeof(end_cert) - 2;  // add enclosing strings.
  +    return n;
  +}
  +
  +static int base64_encode_cert(char *encoded,
  +                              const unsigned char *string, int len)
  +{
  +    int i,c;
  +    char *p;
  +	const char *t;
  +
  +    p = encoded;
  +
  +	t = begin_cert;
  +	while (*t != '\0')
  +		*p++ = *t++;
  +
  +    c = 0;
  +    for (i = 0; i < len - 2; i += 3) {
  +        *p++ = basis_64[(string[i] >> 2) & 0x3F];
  +        *p++ = basis_64[((string[i] & 0x3) << 4) |
  +                        ((int) (string[i + 1] & 0xF0) >> 4)];
  +        *p++ = basis_64[((string[i + 1] & 0xF) << 2) |
  +                        ((int) (string[i + 2] & 0xC0) >> 6)];
  +        *p++ = basis_64[string[i + 2] & 0x3F];
  +        c += 4;
  +        if ( c >= 64 ) {
  +            *p++ = '\r';
  +            *p++ = '\n';
  +            c = 0;
  +		}
  +    }
  +    if (i < len) {
  +        *p++ = basis_64[(string[i] >> 2) & 0x3F];
  +        if (i == (len - 1)) {
  +            *p++ = basis_64[((string[i] & 0x3) << 4)];
  +            *p++ = '=';
  +        }
  +        else {
  +            *p++ = basis_64[((string[i] & 0x3) << 4) |
  +                            ((int) (string[i + 1] & 0xF0) >> 4)];
  +            *p++ = basis_64[((string[i + 1] & 0xF) << 2)];
  +        }
  +        *p++ = '=';
  +        c++;
  +    }
  +    if ( c != 0 ) {
  +        *p++ = '\r';
  +        *p++ = '\n';
  +    }
  +
  +	t = end_cert;
  +	while (*t != '\0')
  +		*p++ = *t++;
  +
  +    *p++ = '\0';
  +    return p - encoded;
  +}
  +
  +
  +static char x2c(const char *what)
  +{
  +    register char digit;
  +
  +    digit = ((what[0] >= 'A') ? ((what[0] & 0xdf) - 'A') + 10 : (what[0] - '0'));
  +    digit *= 16;
  +    digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A') + 10 : (what[1] - '0'));
  +    return (digit);
  +}
  +
  +static int unescape_url(char *url)
  +{
  +    register int x, y, badesc, badpath;
  +
  +    badesc = 0;
  +    badpath = 0;
  +    for (x = 0, y = 0; url[y]; ++x, ++y) {
  +        if (url[y] != '%')
  +            url[x] = url[y];
  +        else {
  +            if (!isxdigit(url[y + 1]) || !isxdigit(url[y + 2])) {
  +                badesc = 1;
  +                url[x] = '%';
  +            }
  +            else {
  +                url[x] = x2c(&url[y + 1]);
  +                y += 2;
  +                if (url[x] == '/' || url[x] == '\0')
  +                    badpath = 1;
  +            }
  +        }
  +    }
  +    url[x] = '\0';
  +    if (badesc)
  +            return BAD_REQUEST;
  +    else if (badpath)
  +            return BAD_PATH;
  +    else
  +            return 0;
  +}
  +
  +static void getparents(char *name)
  +{
  +    int l, w;
  +
  +    /* Four paseses, as per RFC 1808 */
  +    /* a) remove ./ path segments */
  +
  +    for (l = 0, w = 0; name[l] != '\0';) {
  +        if (name[l] == '.' && name[l + 1] == '/' && (l == 0 || name[l -
1] == '/'))
  +            l += 2;
  +        else
  +            name[w++] = name[l++];
  +    }
  +
  +    /* b) remove trailing . path, segment */
  +    if (w == 1 && name[0] == '.')
  +        w--;
  +    else if (w > 1 && name[w - 1] == '.' && name[w - 2] == '/')
  +        w--;
  +    name[w] = '\0';
  +
  +    /* c) remove all xx/../ segments. (including leading ../ and /../) */
  +    l = 0;
  +
  +    while (name[l] != '\0') {
  +        if (name[l] == '.' && name[l + 1] == '.' && name[l + 2] == '/'
&&
  +            (l == 0 || name[l - 1] == '/')) {
  +            register int m = l + 3, n;
  +
  +            l = l - 2;
  +            if (l >= 0) {
  +                while (l >= 0 && name[l] != '/')
  +                    l--;
  +                l++;
  +            }
  +            else
  +                l = 0;
  +            n = l;
  +            while ((name[n] = name[m]))
  +                (++n, ++m);
  +        }
  +        else
  +            ++l;
  +    }
  +
  +    /* d) remove trailing xx/.. segment. */
  +    if (l == 2 && name[0] == '.' && name[1] == '.')
  +        name[0] = '\0';
  +    else if (l > 2 && name[l - 1] == '.' && name[l - 2] == '.' &&
name[l - 3] == '/') {
  +        l = l - 4;
  +        if (l >= 0) {
  +            while (l >= 0 && name[l] != '/')
  +                l--;
  +            l++;
  +        }
  +        else
  +            l = 0;
  +        name[l] = '\0';
  +    }
  +}
  +
  +/* Apache code to escape a URL */
  +
  +#define T_OS_ESCAPE_PATH	(4)
  +
  +static const unsigned char test_char_table[256] = {
  +    0,14,14,14,14,14,14,14,14,14,15,14,14,14,14,14,14,14,14,14,
  +    14,14,14,14,14,14,14,14,14,14,14,14,14,0,7,6,1,6,1,1,
  +    9,9,1,0,8,0,0,10,0,0,0,0,0,0,0,0,0,0,8,15,
  +    15,8,15,15,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  +    0,0,0,0,0,0,0,0,0,0,0,15,15,15,7,0,7,0,0,0,
  +    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  +    0,0,0,15,7,15,1,14,6,6,6,6,6,6,6,6,6,6,6,6,
  +    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  +    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  +    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  +    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  +    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  +    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6 
  +};
  +
  +#define TEST_CHAR(c, f)	(test_char_table[(unsigned)(c)] & (f))
  +
  +static const char c2x_table[] = "0123456789abcdef";
  +
  +static unsigned char *c2x(unsigned what, unsigned char *where)
  +{
  +    *where++ = '%';
  +    *where++ = c2x_table[what >> 4];
  +    *where++ = c2x_table[what & 0xf];
  +    return where;
  +}
  +
  +static int escape_url(const char *path, char *dest, int destsize)
  +{
  +    const unsigned char *s = (const unsigned char *)path;
  +    unsigned char *d = (unsigned char *)dest;
  +    unsigned char *e = dest + destsize - 1;
  +    unsigned char *ee = dest + destsize - 3;
  +    unsigned c;
  +
  +    while ((c = *s)) {
  +	if (TEST_CHAR(c, T_OS_ESCAPE_PATH)) {
  +            if (d >= ee )
  +                return JK_FALSE;
  +	    d = c2x(c, d);
  +	}
  +	else {
  +            if (d >= e )
  +                return JK_FALSE;
  +	    *d++ = c;
  +	}
  +	++s;
  +    }
  +    *d = '\0';
  +    return JK_TRUE;
  +}
  +
   
   
   static void write_error_response(PHTTP_FILTER_CONTEXT pfc,char *status,char * msg)
  @@ -104,6 +339,7 @@
       pfc->WriteClient(pfc, msg, &len, 0);
   }
   
  +
   static int JK_METHOD jk2_service_iis_head(jk_env_t *env, jk_ws_service_t *s ){
       static char crlf[3] = { (char)13, (char)10, '\0' };
   	char *reason;
  @@ -112,7 +348,7 @@
   
       if (s->status< 100 || s->status > 1000) {
           env->l->jkLog(env,env->l, JK_LOG_ERROR, 
  -               "jk_ws_service_t::start_response, invalid status %d\n", s->status);
  +               "jk_ws_service_t::jk2_service_iis_head, invalid status %d\n", s->status);
           return JK_FALSE;
       }
   
  @@ -169,8 +405,8 @@
                                                   status_str,
                                                   (LPDWORD)&len_of_status,
                                                   (LPDWORD)headers_str)) {
  -                jk_log(logger, JK_LOG_ERROR, 
  -                       "jk_ws_service_t::start_response, ServerSupportFunction failed\n");
  +                env->l->jkLog(env,env->l, JK_LOG_ERROR, 
  +                       "jk_ws_service_t::jk2_service_iis_head, ServerSupportFunction failed\n");
                   return JK_FALSE;
               }       
   
  @@ -180,8 +416,8 @@
   
       }
   
  -    jk_log(logger, JK_LOG_ERROR, 
  -           "jk_ws_service_t::start_response, NULL parameters\n");
  +    env->l->jkLog(env,env->l, JK_LOG_ERROR, 
  +           "jk_ws_service_t::jk2_service_iis_head, NULL parameters\n");
   
       return JK_FALSE;
   }
  @@ -191,7 +427,7 @@
                             unsigned l,
                             unsigned *a)
   {
  -    jk_log(logger, JK_LOG_DEBUG, 
  +    env->l->jkLog(env,env->l, JK_LOG_DEBUG, 
              "Into jk_ws_service_t::read\n");
   
       if (s && s->ws_private && b && a) {
  @@ -225,7 +461,7 @@
                   if (p->lpEcb->ReadClient(p->lpEcb->ConnID, buf, &l)) {
                       *a += l;            
                   } else {
  -                    jk_log(logger, JK_LOG_ERROR, 
  +                    env->l->jkLog(env,env->l, JK_LOG_ERROR, 
                              "jk_ws_service_t::read, ReadClient failed\n");
                       return JK_FALSE;
                   }                   
  @@ -234,7 +470,7 @@
           return JK_TRUE;
       }
   
  -    jk_log(logger, JK_LOG_ERROR, 
  +    env->l->jkLog(env,env->l, JK_LOG_ERROR, 
              "jk_ws_service_t::read, NULL parameters\n");
       return JK_FALSE;
   }
  @@ -243,7 +479,7 @@
                              const void *b,
                              unsigned l)
   {
  -    jk_log(logger, JK_LOG_DEBUG, 
  +    env->l->jkLog(env,env->l, JK_LOG_DEBUG, 
              "Into jk_ws_service_t::write\n");
   
       if (s && s->ws_private && b) {
  @@ -254,7 +490,7 @@
               char *buf = (char *)b;
   
               if (!p->request_started) {
  -                start_response(env, s );
  +                jk2_service_iis_head(env, s );
               }
   
               while(written < l) {
  @@ -263,7 +499,7 @@
                                             buf + written, 
                                             &try_to_write, 
                                             0)) {
  -                    jk_log(logger, JK_LOG_ERROR, 
  +                    env->l->jkLog(env,env->l, JK_LOG_ERROR, 
                              "jk_ws_service_t::write, WriteClient failed\n");
                       return JK_FALSE;
                   }
  @@ -275,27 +511,64 @@
   
       }
   
  -    jk_log(logger, JK_LOG_ERROR, 
  +    env->l->jkLog(env,env->l, JK_LOG_ERROR, 
              "jk_ws_service_t::write, NULL parameters\n");
   
       return JK_FALSE;
   }
   
   
  -static int init_ws_service(isapi_private_data_t *private_data,
  -                           jk_ws_service_t *s,
  -                           char **worker_name) 
  +int JK_METHOD jk2_service_iis_init(jk_env_t *env, jk_ws_service_t *s)
   {
  -    char huge_buf[16 * 1024]; /* should be enough for all */
  +    if(s==NULL ) {
  +        return JK_FALSE;
  +    }
   
  -    DWORD huge_buf_sz;
  +    s->head   = jk2_service_iis_head;
  +    s->read   = jk2_service_iis_read;
  +    s->write  = jk2_service_iis_write;
  +    s->init   = jk2_service_iis_init_ws_service;
  +    
  +    return JK_TRUE;
  +}
   
  -    s->jvm_route = NULL;
   
  -    s->head = start_response;
  -    s->read = read;
  -    s->write = write;
  +static int get_server_value(LPEXTENSION_CONTROL_BLOCK lpEcb,
  +                            char *name,
  +                            char  *buf,
  +                            DWORD bufsz,
  +                            char  *def_val)
  +{
  +    if (!lpEcb->GetServerVariable(lpEcb->ConnID, 
  +                                 name,
  +                                 buf,
  +                                 (LPDWORD)&bufsz)) {
  +        strcpy(buf, def_val);
  +        return JK_FALSE;
  +    }
  +
  +    if (bufsz > 0) {
  +        buf[bufsz - 1] = '\0';
  +    }
  +
  +    return JK_TRUE;
  +}
   
  +
  +static int JK_METHOD jk2_service_iis_init_ws_service( struct jk_env *env, jk_ws_service_t
*s,
  +                 struct jk_worker *w, void *serverObj )
  +
  +/* */
  +
  +{
  +    isapi_private_data_t *private_data=serverObj;
  +    char huge_buf[16 * 1024]; /* should be enough for all */
  +	char **worker_name;
  +	
  +    DWORD huge_buf_sz;
  +
  +    s->jvm_route = NULL;
  +    
       GET_SERVER_VARIABLE_VALUE(HTTP_WORKER_HEADER_NAME, (*worker_name));           
       GET_SERVER_VARIABLE_VALUE(HTTP_URI_HEADER_NAME, s->req_uri);     
       GET_SERVER_VARIABLE_VALUE(HTTP_QUERY_HEADER_NAME, s->query_string);     
  @@ -328,7 +601,7 @@
       s->ssl_session  = NULL;
   	s->ssl_key_size = -1;
   
  -    s->headers_in  = NULL;
  +    jk2_map_default_create(env, &s->headers_in, s->pool );
   //    s->headers_values   = NULL;
   //  s->num_headers      = 0;
       
  @@ -370,20 +643,15 @@
           if (num_of_vars) {
               unsigned j;
   
  -            s->attributes=NULL;
  -				_names = 
  -                jk_pool_alloc(&private_data->p, num_of_vars * sizeof(char *));
  -            s->attributes_values = 
  -                jk_pool_alloc(&private_data->p, num_of_vars * sizeof(char *));
  +			jk2_map_default_create(env, &s->attributes, s->pool );
  +
               j = 0;
               for(i = 0 ; i < 9 ; i++) {                
                   if (ssl_env_values[i]) {
  -                    s->attributes_names[j] = ssl_env_names[i];
  -                    s->attributes_values[j] = ssl_env_values[i];
  +                    s->attributes->put(env,s->attributes,ssl_env_names[i],ssl_env_values[i],NULL);
                       j++;
                   }
               }
  -            s->num_attributes = num_of_vars;
    			if (ssl_env_values[4] && ssl_env_values[4][0] == '1') {
   				CERT_CONTEXT_EX cc;
   				DWORD cc_sz = sizeof(cc);
  @@ -395,11 +663,11 @@
   											 (DWORD)HSE_REQ_GET_CERT_INFO_EX,                               
   											 (LPVOID)&cc,NULL,NULL) != FALSE)
   				{
  -					jk_log(logger, JK_LOG_DEBUG,"Client Certificate encoding:%d sz:%d flags:%ld\n",
  +					env->l->jkLog(env,env->l, JK_LOG_DEBUG,"Client Certificate encoding:%d sz:%d
flags:%ld\n",
   								cc.CertContext.dwCertEncodingType & X509_ASN_ENCODING ,
   								cc.CertContext.cbCertEncoded,
   								cc.dwCertificateFlags);
  -                    s->ssl_cert=jk_pool_alloc(&private_data->p,
  +                    s->ssl_cert=private_data->p.alloc(env,&private_data->p,
                                   base64_encode_cert_len(cc.CertContext.cbCertEncoded));
   
                       s->ssl_cert_len = base64_encode_cert(s->ssl_cert,
  @@ -409,7 +677,6 @@
           }
       }
   
  -*/
   	huge_buf_sz = sizeof(huge_buf);         
       if (get_server_value(private_data->lpEcb,
                           "ALL_HTTP",             
  @@ -426,13 +693,14 @@
           }
   
           if (cnt) {
  -            char *headers_buf = jk_pool_strdup(&private_data->p, huge_buf);
  +            char *headers_buf = private_data->p.pstrdup(env,&private_data->p,
huge_buf);
               unsigned i;
               unsigned len_of_http_prefix = strlen("HTTP_");
               BOOL need_content_length_header = (s->content_length == 0);
               
               cnt -= 2; /* For our two special headers */
               /* allocate an extra header slot in case we need to add a content-length header
*/
  +/*
               s->headers_names  = jk_pool_alloc(&private_data->p, (cnt + 1) * sizeof(char
*));
               s->headers_values = jk_pool_alloc(&private_data->p, (cnt + 1) * sizeof(char
*));
   
  @@ -440,8 +708,10 @@
                   return JK_FALSE;
               }
   
  + */
               for(i = 0, tmp = headers_buf ; *tmp && i < cnt ; ) {
                   int real_header = JK_TRUE;
  +				char *name;
   
                   /* Skipp the HTTP_ prefix to the beginning of th header name */
                   tmp += len_of_http_prefix;
  @@ -452,13 +722,13 @@
                   } else if(need_content_length_header &&
                      !strnicmp(tmp, CONTENT_LENGTH, strlen(CONTENT_LENGTH))) {
                       need_content_length_header = FALSE;
  -                    s->headers_names[i]  = tmp;
  +                    name  = tmp;
                   } else if (!strnicmp(tmp, TOMCAT_TRANSLATE_HEADER_NAME,
                                             strlen(TOMCAT_TRANSLATE_HEADER_NAME))) {
                       tmp += 6; /* TOMCAT */
  -                    s->headers_names[i]  = tmp;
  +                    name  = tmp;
                   } else {
  -                    s->headers_names[i]  = tmp;
  +                    name  = tmp;
                   }
   
                   while(':' != *tmp && *tmp) {
  @@ -478,7 +748,7 @@
                   }
   
                   if (real_header) {
  -                    s->headers_values[i]  = tmp;
  +                    s->headers_in->put(env,s->headers_in,name,tmp,NULL);
                   }
                   
                   while(*tmp != '\n' && *tmp != '\r') {
  @@ -501,11 +771,9 @@
                * but non-zero length body.
                */
               if(need_content_length_header) {
  -                s->headers_names[cnt] = "content-length";
  -                s->headers_values[cnt] = "0";
  +                s->headers_in->put(env,s->headers_in,"content-length","0",NULL);
                   cnt++;
               }
  -            s->num_headers = cnt;
           } else {
               /* We must have our two headers */
               return JK_FALSE;
  @@ -517,111 +785,4 @@
       return JK_TRUE;
   }
   
  -static int get_server_value(LPEXTENSION_CONTROL_BLOCK lpEcb,
  -                            char *name,
  -                            char  *buf,
  -                            DWORD bufsz,
  -                            char  *def_val)
  -{
  -    if (!lpEcb->GetServerVariable(lpEcb->ConnID, 
  -                                 name,
  -                                 buf,
  -                                 (LPDWORD)&bufsz)) {
  -        strcpy(buf, def_val);
  -        return JK_FALSE;
  -    }
  -
  -    if (bufsz > 0) {
  -        buf[bufsz - 1] = '\0';
  -    }
  -
  -    return JK_TRUE;
  -}
  -
  -static const char begin_cert [] = 
  -	"-----BEGIN CERTIFICATE-----\r\n";
  -
  -static const char end_cert [] = 
  -	"-----END CERTIFICATE-----\r\n";
  -
  -static const char basis_64[] =
  -    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  -
  -static int base64_encode_cert_len(int len)
  -{
  -	int n = ((len + 2) / 3 * 4) + 1; // base64 encoded size
  -	n += (n + 63 / 64) * 2; // add CRLF's
  -	n += sizeof(begin_cert) + sizeof(end_cert) - 2;  // add enclosing strings.
  -    return n;
  -}
  -
  -static int base64_encode_cert(char *encoded,
  -                              const unsigned char *string, int len)
  -{
  -    int i,c;
  -    char *p;
  -	const char *t;
  -
  -    p = encoded;
  -
  -	t = begin_cert;
  -	while (*t != '\0')
  -		*p++ = *t++;
  -
  -    c = 0;
  -    for (i = 0; i < len - 2; i += 3) {
  -        *p++ = basis_64[(string[i] >> 2) & 0x3F];
  -        *p++ = basis_64[((string[i] & 0x3) << 4) |
  -                        ((int) (string[i + 1] & 0xF0) >> 4)];
  -        *p++ = basis_64[((string[i + 1] & 0xF) << 2) |
  -                        ((int) (string[i + 2] & 0xC0) >> 6)];
  -        *p++ = basis_64[string[i + 2] & 0x3F];
  -        c += 4;
  -        if ( c >= 64 ) {
  -            *p++ = '\r';
  -            *p++ = '\n';
  -            c = 0;
  -		}
  -    }
  -    if (i < len) {
  -        *p++ = basis_64[(string[i] >> 2) & 0x3F];
  -        if (i == (len - 1)) {
  -            *p++ = basis_64[((string[i] & 0x3) << 4)];
  -            *p++ = '=';
  -        }
  -        else {
  -            *p++ = basis_64[((string[i] & 0x3) << 4) |
  -                            ((int) (string[i + 1] & 0xF0) >> 4)];
  -            *p++ = basis_64[((string[i + 1] & 0xF) << 2)];
  -        }
  -        *p++ = '=';
  -        c++;
  -    }
  -    if ( c != 0 ) {
  -        *p++ = '\r';
  -        *p++ = '\n';
  -    }
  -
  -	t = end_cert;
  -	while (*t != '\0')
  -		*p++ = *t++;
  -
  -    *p++ = '\0';
  -    return p - encoded;
  -}
  -
  -int jk2_service_iis_init(jk_env_t *env, jk_ws_service_t *s)
  -{
  -    if(s==NULL ) {
  -        return JK_FALSE;
  -    }
  -
  -    s->head   = jk2_service_iis_head;
  -    s->read   = jk2_service_iis_read;
  -    s->write  = jk2_service_iis_write;
  -    s->init   = jk2_init_ws_service;
  -    s->afterRequest     = jk2_service_apache2_afterRequest;
  -    
  -    return JK_TRUE;
  -}
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message