⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jk_isapi_plugin.c

📁 Tomcat 4.1与WebServer集成组件的源代码包.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ========================================================================= * *                                                                           * *                 The Apache Software License,  Version 1.1                 * *                                                                           * *          Copyright (c) 1999-2002 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: ISAPI plugin for IIS/PWS                                   * * Author:      Gal Shachor <shachor@il.ibm.com>                           * * Author:      Larry Isaacs <larryi@apache.org>                           * * Author:      Ignacio J. Ortega <nacho@apache.org>                       * * Version:     $Revision: 1.51 $                                           * ***************************************************************************/// This define is needed to include wincrypt,h, needed to get client certificates#define _WIN32_WINNT 0x0400#include <httpext.h>#include <httpfilt.h>#include <wininet.h>#include "jk_global.h"#include "jk_requtil.h"#include "jk_map.h"#include "jk_pool.h"#include "jk_logger.h"#include "jk_env.h"#include "jk_service.h"#include "jk_worker.h"#include "apr_general.h"#include "jk_iis.h"//#include "jk_uri_worker_map.h"#define SERVER_ROOT_TAG         ("serverRoot")#define EXTENSION_URI_TAG       ("extensionUri")#define WORKERS_FILE_TAG        ("workersFile")#define USE_AUTH_COMP_TAG       ("authComplete")#define THREAD_POOL_TAG         ("threadPool")static char  file_name[_MAX_PATH];static char  ini_file_name[MAX_PATH];static int   using_ini_file = JK_FALSE;static int   is_inited = JK_FALSE;static int   is_mapread = JK_FALSE;static int   was_inited = JK_FALSE;static DWORD auth_notification_flags = 0;static int   use_auth_notification_flags = 0;static jk_workerEnv_t *workerEnv;apr_pool_t *jk_globalPool;static char extension_uri[INTERNET_MAX_URL_LENGTH] = "/jakarta/isapi_redirector2.dll";static char worker_file[MAX_PATH * 2] = "";static char server_root[MAX_PATH * 2] = "";static int init_jk(char *serverName);static int initialize_extension();static int read_registry_init_data(jk_env_t *env);extern int jk_jni_status_code;static int get_registry_config_parameter(HKEY hkey,                                         const char *tag,                                          char *b,                                         DWORD sz);static jk_env_t* jk2_create_config();static int get_auth_flags();/*  ThreadPool support * */int use_thread_pool = 0;static void write_error_response(PHTTP_FILTER_CONTEXT pfc,char *status,char * msg){    char crlf[3] = { (char)13, (char)10, '\0' };    char *ctype = "Content-Type:text/html\r\n\r\n";    DWORD len = strlen(msg);    /* reject !!! */    pfc->ServerSupportFunction(pfc,                                SF_REQ_SEND_RESPONSE_HEADER,                               status,                               (DWORD)crlf,                               (DWORD)ctype);    pfc->WriteClient(pfc, msg, &len, 0);}HANDLE jk2_starter_event;HANDLE jk2_inited_event;HANDLE jk2_starter_thread = NULL;VOID jk2_isapi_starter( LPVOID lpParam ) {    Sleep(1000);        apr_initialize();    apr_pool_create( &jk_globalPool, NULL );    initialize_extension();    if (is_inited) {        if (init_jk(NULL))            is_mapread = JK_TRUE;    }    SetEvent(jk2_inited_event);    WaitForSingleObject(jk2_starter_event, INFINITE);    if (is_inited) {        was_inited = JK_TRUE;        is_inited = JK_FALSE;        if (workerEnv) {            jk_env_t *env = workerEnv->globalEnv;            jk2_iis_close_pool(env);            workerEnv->close(env, workerEnv);        }        is_mapread = JK_FALSE;    }    apr_pool_destroy(jk_globalPool);    apr_terminate();    /* Clean up and die. */    ExitThread(0); } BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer){    DWORD dwThreadId;    ULONG http_filter_revision = HTTP_FILTER_REVISION;    jk2_inited_event = CreateEvent(NULL, FALSE, FALSE, NULL);    jk2_starter_event = CreateEvent(NULL, FALSE, FALSE, NULL);    jk2_starter_thread = CreateThread(NULL, 0,                                      (LPTHREAD_START_ROUTINE)jk2_isapi_starter,                                      NULL,                                      0,                                      &dwThreadId);                            WaitForSingleObject(jk2_inited_event, INFINITE);    if (!is_inited || !is_mapread) {        return FALSE;    }    pVer->dwFilterVersion = pVer->dwServerFilterVersion;    if (pVer->dwFilterVersion > http_filter_revision) {        pVer->dwFilterVersion = http_filter_revision;    }    auth_notification_flags = get_auth_flags();#ifdef SF_NOTIFY_AUTH_COMPLETE    if (auth_notification_flags == SF_NOTIFY_AUTH_COMPLETE) {        pVer->dwFlags = SF_NOTIFY_ORDER_HIGH        |                         SF_NOTIFY_SECURE_PORT       |                         SF_NOTIFY_NONSECURE_PORT    |                        SF_NOTIFY_PREPROC_HEADERS   |                        SF_NOTIFY_AUTH_COMPLETE;    }    else#endif    {        pVer->dwFlags = SF_NOTIFY_ORDER_HIGH        |                         SF_NOTIFY_SECURE_PORT       |                         SF_NOTIFY_NONSECURE_PORT    |                        SF_NOTIFY_PREPROC_HEADERS;       }    strcpy(pVer->lpszFilterDesc, VERSION_STRING);    return TRUE;}DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc,                            DWORD dwNotificationType,                             LPVOID pvNotification){    jk_env_t *env=NULL;     jk_uriEnv_t *uriEnv=NULL;    if (!is_inited) {        initialize_extension();    }    /* Initialise jk */    if (is_inited && !is_mapread) {        char serverName[MAX_SERVERNAME];        DWORD dwLen = sizeof(serverName);        if (pfc->GetServerVariable(pfc, SERVER_NAME, serverName, &dwLen)){            if (dwLen > 0) {                serverName[dwLen-1] = '\0';            }            if (init_jk(serverName)){                is_mapread = JK_TRUE;            }        }        /* If we can't read the map we become dormant */        if (!is_mapread)            is_inited = JK_FALSE;    }    if (is_inited && is_mapread) {        env = workerEnv->globalEnv->getEnv( workerEnv->globalEnv );        if (auth_notification_flags == dwNotificationType)        {             char uri[INTERNET_MAX_URL_LENGTH];             char snuri[INTERNET_MAX_URL_LENGTH]="/";            char Host[INTERNET_MAX_URL_LENGTH];            char Translate[INTERNET_MAX_URL_LENGTH];            char Port[INTERNET_MAX_URL_LENGTH];            BOOL (WINAPI * GetHeader)                 (struct _HTTP_FILTER_CONTEXT * pfc, LPSTR lpszName, LPVOID lpvBuffer, LPDWORD lpdwSize );            BOOL (WINAPI * SetHeader)                 (struct _HTTP_FILTER_CONTEXT * pfc, LPSTR lpszName, LPSTR lpszValue );            BOOL (WINAPI * AddHeader)                 (struct _HTTP_FILTER_CONTEXT * pfc, LPSTR lpszName,LPSTR lpszValue );            char *query;            DWORD sz = sizeof(uri);            DWORD szHost = sizeof(Host);            DWORD szTranslate = sizeof(Translate);            DWORD szPort = sizeof(Port);            int   nPort;#ifdef SF_NOTIFY_AUTH_COMPLETE            if (auth_notification_flags == SF_NOTIFY_AUTH_COMPLETE) {                GetHeader=((PHTTP_FILTER_AUTH_COMPLETE_INFO)pvNotification)->GetHeader;                SetHeader=((PHTTP_FILTER_AUTH_COMPLETE_INFO)pvNotification)->SetHeader;                AddHeader=((PHTTP_FILTER_AUTH_COMPLETE_INFO)pvNotification)->AddHeader;            }             else #endif            {                GetHeader=((PHTTP_FILTER_PREPROC_HEADERS)pvNotification)->GetHeader;                SetHeader=((PHTTP_FILTER_PREPROC_HEADERS)pvNotification)->SetHeader;                AddHeader=((PHTTP_FILTER_PREPROC_HEADERS)pvNotification)->AddHeader;            }            env->l->jkLog(env, env->l,  JK_LOG_DEBUG,                    "HttpFilterProc started\n");

⌨️ 快捷键说明

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