mod_jk.c

来自「Tomcat 4.1与WebServer集成组件的源代码包.」· C语言 代码 · 共 506 行 · 第 1/2 页

C
506
字号
/* -*- 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 <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/>.   * *                                                                           * * ========================================================================= *//*************************************************************************** * Description: Apache 2 plugin for Jakarta/Tomcat                         * * Author:      Gal Shachor <shachor@il.ibm.com>                           * *                 Henri Gomez <hgomez@slib.fr>                               * * Version:     $Revision: 1.65 $                                           * ***************************************************************************//* * mod_jk: keeps all servlet/jakarta related ramblings together. */#include "apu_compat.h"#include "ap_config.h"#include "apr_lib.h"#include "apr_date.h"#include "apr_file_info.h"#include "httpd.h"#include "http_config.h"#include "http_request.h"#include "http_core.h"#include "http_protocol.h"#include "http_main.h"#include "http_log.h"#include "util_script.h"#ifdef AS400#include "ap_charset.h"#include "util_charset.h"              /* ap_hdrs_from_ascii */#endif/* moved to apr since http-2.0.19-dev */#if (MODULE_MAGIC_NUMBER_MAJOR < 20010523)#include "util_date.h"#endif#include "apr_strings.h"/* * Jakarta (jk_) include files */#ifdef NETWARE#define __sys_types_h__#define __sys_socket_h__#define __netdb_h__#define __netinet_in_h__#define __arpa_inet_h__#define __sys_timeval_h__#endif#include "jk_global.h"#include "jk_util.h"#include "jk_map.h"#include "jk_pool.h"#include "jk_service.h"#include "jk_worker.h"#include "jk_uri_worker_map.h"#define JK_WORKER_ID        ("jakarta.worker")#define JK_HANDLER          ("jakarta-servlet")#define JK_DURATION         ("jakarta.worker.duration")#define JK_MAGIC_TYPE       ("application/x-jakarta-servlet")#define NULL_FOR_EMPTY(x)   ((x && !strlen(x)) ? NULL : x) /* * If you are not using SSL, comment out the following line. It will make * apache run faster.   * * Personally, I (DM), think this may be a lie. */#define ADD_SSL_INFO    /* module MODULE_VAR_EXPORT jk_module; */AP_MODULE_DECLARE_DATA module jk_module;typedef struct {    /*     * Log stuff     */    char *log_file;    int  log_level;    jk_logger_t *log;    /*     * Worker stuff     */    jk_map_t *worker_properties;    char     *worker_file;    jk_map_t *uri_to_context;    int      mountcopy;    char     *secret_key;    jk_map_t *automount;    jk_uri_worker_map_t *uw_map;    int was_initialized;    /*     * Automatic context path apache alias     */    char *alias_dir;    /*     * Request Logging     */    char *format_string;    apr_array_header_t *format;    /*     * SSL Support     */    int  ssl_enable;    char *https_indicator;    char *certs_indicator;    char *cipher_indicator;    char *session_indicator;  /* Servlet API 2.3 requirement */    char *key_size_indicator; /* Servlet API 2.3 requirement */    /*     * Jk Options     */    int options;    /*     * Environment variables support     */    int envvars_in_use;    apr_table_t * envvars;    server_rec *s;} jk_server_conf_t;struct apache_private_data {    jk_pool_t p;        int response_started;    int read_body_started;    request_rec *r;};typedef struct apache_private_data apache_private_data_t;static jk_logger_t *     main_log = NULL;static jk_worker_env_t   worker_env;static int JK_METHOD ws_start_response(jk_ws_service_t *s,                                       int status,                                       const char *reason,                                       const char * const *header_names,                                       const char * const *header_values,                                       unsigned num_of_headers);static int JK_METHOD ws_read(jk_ws_service_t *s,                             void *b,                             unsigned len,                             unsigned *actually_read);static void init_jk( apr_pool_t *pconf,jk_server_conf_t *conf, server_rec *s );static int JK_METHOD ws_write(jk_ws_service_t *s,                              const void *b,                              unsigned l);/* ========================================================================= *//* JK Service step callbacks                                                 *//* ========================================================================= */static int JK_METHOD ws_start_response(jk_ws_service_t *s,                                       int status,                                       const char *reason,                                       const char * const *header_names,                                       const char * const *header_values,                                       unsigned num_of_headers){    if(s && s->ws_private) {        unsigned h;        apache_private_data_t *p = s->ws_private;        request_rec *r = p->r;                if(!reason) {            reason = "";        }        r->status = status;        r->status_line = apr_psprintf(r->pool, "%d %s", status, reason);        for(h = 0 ; h < num_of_headers ; h++) {            if(!strcasecmp(header_names[h], "Content-type")) {                char *tmp = apr_pstrdup(r->pool, header_values[h]);                ap_content_type_tolower(tmp);                /* It should be done like this in Apache 2.0 */                /* This way, Apache 2.0 will be able to set the output filter */                /* and it make jk useable with deflate using AddOutputFilterByType DEFLATE text/html */                ap_set_content_type(r, tmp);            } else if(!strcasecmp(header_names[h], "Location")) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?