costin 01/12/04 10:29:11 Added: jk/native2/include jk_requtil.h jk_mt.h jk_endpoint.h jk_md5.h Log: Moved from common. jk_requtil contains code from jk_lb_worker ( parsing of request, extracting cookie, etc ). It's general purpose, can be used in other workers and it simplifies lb worker. Revision Changes Path 1.1 jakarta-tomcat-connectors/jk/native2/include/jk_requtil.h Index: jk_requtil.h =================================================================== /* ========================================================================= * * * * 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 <[EMAIL PROTECTED]>. * * * * 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/>. * * * * ========================================================================= */ /** * Utils for processing various request components * * @author: Gal Shachor <[EMAIL PROTECTED]> * @author: Henri Gomez <[EMAIL PROTECTED]> * @author: Costin Manolache */ #ifndef JK_REQUTIL_H #define JK_REQUTIL_H #include "jk_global.h" #include "jk_ajp14.h" #include "jk_channel.h" #include "jk_env.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /* * Request methods, coded as numbers instead of strings. * The list of methods was taken from Section 5.1.1 of RFC 2616, * RFC 2518, the ACL IETF draft, and the DeltaV IESG Proposed Standard. */ #define SC_M_OPTIONS (unsigned char)1 #define SC_M_GET (unsigned char)2 #define SC_M_HEAD (unsigned char)3 #define SC_M_POST (unsigned char)4 #define SC_M_PUT (unsigned char)5 #define SC_M_DELETE (unsigned char)6 #define SC_M_TRACE (unsigned char)7 #define SC_M_PROPFIND (unsigned char)8 #define SC_M_PROPPATCH (unsigned char)9 #define SC_M_MKCOL (unsigned char)10 #define SC_M_COPY (unsigned char)11 #define SC_M_MOVE (unsigned char)12 #define SC_M_LOCK (unsigned char)13 #define SC_M_UNLOCK (unsigned char)14 #define SC_M_ACL (unsigned char)15 #define SC_M_REPORT (unsigned char)16 #define SC_M_VERSION_CONTROL (unsigned char)17 #define SC_M_CHECKIN (unsigned char)18 #define SC_M_CHECKOUT (unsigned char)19 #define SC_M_UNCHECKOUT (unsigned char)20 #define SC_M_SEARCH (unsigned char)21 /* * Frequent request headers, these headers are coded as numbers * instead of strings. */ #define SC_ACCEPT (unsigned short)0xA001 #define SC_ACCEPT_CHARSET (unsigned short)0xA002 #define SC_ACCEPT_ENCODING (unsigned short)0xA003 #define SC_ACCEPT_LANGUAGE (unsigned short)0xA004 #define SC_AUTHORIZATION (unsigned short)0xA005 #define SC_CONNECTION (unsigned short)0xA006 #define SC_CONTENT_TYPE (unsigned short)0xA007 #define SC_CONTENT_LENGTH (unsigned short)0xA008 #define SC_COOKIE (unsigned short)0xA009 #define SC_COOKIE2 (unsigned short)0xA00A #define SC_HOST (unsigned short)0xA00B #define SC_PRAGMA (unsigned short)0xA00C #define SC_REFERER (unsigned short)0xA00D #define SC_USER_AGENT (unsigned short)0xA00E /* * Frequent response headers, these headers are coded as numbers * instead of strings. * * Content-Type * Content-Language * Content-Length * Date * Last-Modified * Location * Set-Cookie * Servlet-Engine * Status * WWW-Authenticate * */ #define SC_RESP_CONTENT_TYPE (unsigned short)0xA001 #define SC_RESP_CONTENT_LANGUAGE (unsigned short)0xA002 #define SC_RESP_CONTENT_LENGTH (unsigned short)0xA003 #define SC_RESP_DATE (unsigned short)0xA004 #define SC_RESP_LAST_MODIFIED (unsigned short)0xA005 #define SC_RESP_LOCATION (unsigned short)0xA006 #define SC_RESP_SET_COOKIE (unsigned short)0xA007 #define SC_RESP_SET_COOKIE2 (unsigned short)0xA008 #define SC_RESP_SERVLET_ENGINE (unsigned short)0xA009 #define SC_RESP_STATUS (unsigned short)0xA00A #define SC_RESP_WWW_AUTHENTICATE (unsigned short)0xA00B #define SC_RES_HEADERS_NUM 11 /** Get header value using a lookup table. */ const char *jk_requtil_getHeaderById(int sc); /** * Get method id. */ int jk_requtil_getMethodId(const char *method, unsigned char *sc); /** * Get header id. */ int jk_requtil_getHeaderId(const char *header_name, unsigned short *sc); /** Retrieve session id from the cookie or the parameter * (parameter first) */ char *jk_requtil_getSessionId(jk_ws_service_t *s); /** Retrieve the cookie with the given name */ char *jk_requtil_getCookieByName(jk_ws_service_t *s, const char *name); /* Retrieve the parameter with the given name */ char *jk_requtil_getPathParam(jk_ws_service_t *s, const char *name); /** Extract the 'route' from the session id. The route is * the id of the worker that generated the session and where all * further requests in that session will be sent. */ char *jk_requtil_getSessionRoute(jk_ws_service_t *s); /** Initialize the request * * jk_init_ws_service */ void jk_requtil_initRequest(jk_ws_service_t *s); #ifdef __cplusplus } #endif /* __cplusplus */ #endif 1.1 jakarta-tomcat-connectors/jk/native2/include/jk_mt.h Index: jk_mt.h =================================================================== /* ========================================================================= * * * * 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 <[EMAIL PROTECTED]>. * * * * 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/>. * * * * ========================================================================= */ /*************************************************************************** * Description: Multi thread portability code for JK * * Author: Gal Shachor <[EMAIL PROTECTED]> * * Version: $Revision: 1.1 $ * ***************************************************************************/ #ifndef _JK_MT_H #define _JK_MT_H #include "jk_global.h" /* * All WIN32 code is MT, UNIX code that uses pthreads is marked by the POSIX * _REENTRANT define. */ #if defined (WIN32) || defined(_REENTRANT) /* * Marks execution under MT compilation */ #define _MT_CODE #ifdef WIN32 #include <windows.h> typedef CRITICAL_SECTION JK_CRIT_SEC; #define JK_INIT_CS(x, rc) InitializeCriticalSection(x); rc = JK_TRUE; #define JK_DELETE_CS(x, rc) DeleteCriticalSection(x); rc = JK_TRUE; #define JK_ENTER_CS(x, rc) EnterCriticalSection(x); rc = JK_TRUE; #define JK_LEAVE_CS(x, rc) LeaveCriticalSection(x); rc = JK_TRUE; #else /* Unix pthreads */ #include <pthread.h> typedef pthread_mutex_t JK_CRIT_SEC; #define JK_INIT_CS(x, rc)\ if(pthread_mutex_init(x, NULL)) rc = JK_FALSE; else rc = JK_TRUE; #define JK_DELETE_CS(x, rc)\ if(pthread_mutex_lock(x)) rc = JK_FALSE; else rc = JK_TRUE; #define JK_ENTER_CS(x, rc)\ if(pthread_mutex_unlock(x)) rc = JK_FALSE; else rc = JK_TRUE; #define JK_LEAVE_CS(x, rc)\ if(pthread_mutex_destroy(x)) rc = JK_FALSE; else rc = JK_TRUE; #endif /* Unix pthreads */ #else /* Not an MT code */ typedef void *JK_CRIT_SEC; #define JK_INIT_CS(x, rc) rc = JK_TRUE; #define JK_DELETE_CS(x, rc) rc = JK_TRUE; #define JK_ENTER_CS(x, rc) rc = JK_TRUE; #define JK_LEAVE_CS(x, rc) rc = JK_TRUE; #endif /* Not an MT code */ #endif /* _JK_MT_H */ 1.1 jakarta-tomcat-connectors/jk/native2/include/jk_endpoint.h Index: jk_endpoint.h =================================================================== /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil-*- */ /* ========================================================================= * * * * 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 <[EMAIL PROTECTED]>. * * * * 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/>. * * * * ========================================================================= */ /*************************************************************************** * Description: Definitions of the endpoint. * * Author: Gal Shachor <[EMAIL PROTECTED]> * Author: Dan Milstein <[EMAIL PROTECTED]> * Author: Henri Gomez <[EMAIL PROTECTED]> * Version: $Revision: 1.1 $ ***************************************************************************/ #ifndef JK_ENDPOINT_H #define JK_ENDPOINT_H #include "jk_map.h" #include "jk_service.h" #include "jk_logger.h" #include "jk_pool.h" #include "jk_uriMap.h" #include "jk_msg_buff.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ struct jk_endpoint; struct jk_ws_service; typedef struct jk_endpoint jk_endpoint_t; /* * The endpoint 'class', which represents one end of a connection to the * servlet engine. Basically, supports nothing other than forwarding the * request to the servlet engine. Endpoints can be persistent (as with * ajp13/ajp14, where a single connection is reused many times), or can last for a * single request (as with ajp12, where a new connection is created for * every request). * * An endpoint for a given protocol is obtained by the web server plugin * from a worker object for that protocol. See below for details. * * As with all the core jk classes, this is essentially an abstract base * class which is implemented/extended by classes which are specific to a * particular protocol. By using an abstract base class in this manner, * plugins can be written for different servers (e.g. IIS, Apache) without * the plugins having to worry about which protocol they are talking. * * This particular OO-in-C system uses a 'endpoint_private' pointer to * point to the protocol-specific data/functions. So in the subclasses, the * methods do most of their work by getting their hands on the * endpoint_private pointer and then using that to get at the functions for * their protocol. * * Try imagining this as a 'public abstract class', and the * endpoint_private pointer as a sort of extra 'this' reference. Or * imagine that you are seeing the internal vtables of your favorite OO * language. Whatever works for you. * * See jk_ajp13_worker.c/jk_ajp14_worker.c and jk_ajp12_worker.c for examples. */ struct jk_endpoint { /* * A 'this' pointer which is used by the subclasses of this class to * point to data/functions which are specific to a given protocol * (e.g. ajp12 or ajp13 or ajp14). */ void *endpoint_private; /** Data specific to a channel connection */ void *channelData; struct jk_worker *worker; jk_pool_t pool; jk_pool_atom_t buf[BIG_POOL_SIZE]; int proto; /* PROTOCOL USED AJP13/AJP14 */ int sd; int reuse; unsigned left_bytes_to_send; /* Buffers for req/res */ /* Used to be ajp_operation */ struct jk_msg_buf *request; /* original request storage */ struct jk_msg_buf *reply; /* reply storage (chuncked by ajp13 */ struct jk_msg_buf *post; /* small post data storage area */ int uploadfd; /* future persistant storage id */ int recoverable; /* if exchange could be conducted on another TC */ /* * Forward a request to the servlet engine. The request is described * by the jk_ws_service_t object. I'm not sure exactly how * is_recoverable_error is being used. */ int (JK_METHOD *service)(jk_endpoint_t *e, struct jk_ws_service *s, jk_logger_t *l, int *is_recoverable_error); /* * Called when this particular endpoint has finished processing a * request. For some protocols (e.g. ajp12), this frees the memory * associated with the endpoint. For others (e.g. ajp13/ajp14), this can * return the endpoint to a cache of already opened endpoints. * * Note that the first argument is *not* a 'this' pointer, but is * rather a pointer to a 'this' pointer. This is necessary, because * we may need to free this object. */ int (JK_METHOD *done)(jk_endpoint_t **p, jk_logger_t *l); }; int ajp_get_endpoint(struct jk_worker *pThis, jk_endpoint_t **pend, jk_logger_t *l, int proto); int ajp_connect_to_endpoint(jk_endpoint_t *ae, jk_logger_t *l); void ajp_close_endpoint(jk_endpoint_t *ae, jk_logger_t *l); int ajp_connection_tcp_send_message(jk_endpoint_t *ae, jk_msg_buf_t *msg, jk_logger_t *l); int ajp_connection_tcp_get_message(jk_endpoint_t *ae, jk_msg_buf_t *msg, jk_logger_t *l); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* JK_ENDPOINT_H */ 1.1 jakarta-tomcat-connectors/jk/native2/include/jk_md5.h Index: jk_md5.h =================================================================== /* * This is work is derived from material Copyright RSA Data Security, Inc. * * The RSA copyright statement and Licence for that original material is * included below. This is followed by the Apache copyright statement and * licence for the modifications made to that material. */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved. License to copy and use this software is granted provided that it is identified as the "RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing this software or this function. License is also granted to make and use derivative works provided that such works are identified as "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing the derived work. RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided "as is" without express or implied warranty of any kind. These notices must be retained in any copies of any part of this documentation and/or software. */ /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * 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 acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" 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 [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, 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 * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. */ #ifndef JK_APACHE_MD5_H #define JK_APACHE_MD5_H #ifdef __cplusplus extern "C" { #endif /* MD5.H - header file for MD5.C */ #define JK_MD5_DIGESTSIZE 16 /* JK_UINT4 defines a four byte word */ typedef unsigned int JK_UINT4; /* MD5 context. */ typedef struct { JK_UINT4 state[4]; /* state (ABCD) */ JK_UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ unsigned char buffer[64]; /* input buffer */ } JK_MD5_CTX; /* * Define the Magic String prefix that identifies a password as being * hashed using our algorithm. */ #define JK_MD5PW_ID "$apr1$" #define JK_MD5PW_IDLEN 6 char * JK_METHOD jk_hextocstr(unsigned char *org, char * dst, int n); char * JK_METHOD jk_md5(const unsigned char *org, const unsigned char *org2, char *dst); #ifdef __cplusplus } #endif #endif /* !JK_APACHE_MD5_H */
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>