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

📄 mod_isapi.c

📁 Apache V2.0.15 Alpha For Linuxhttpd-2_0_15-alpha.tar.Z
💻 C
📖 第 1 页 / 共 4 页
字号:
/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 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 apache@apache.org. * * 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. *//* * mod_isapi.c - Internet Server Application (ISA) module for Apache * by Alexei Kosut <akosut@apache.org> * * This module implements Microsoft's ISAPI, allowing Apache (when running * under Windows) to load Internet Server Applications (ISAPI extensions). * It implements all of the ISAPI 2.0 specification, except for the  * "Microsoft-only" extensions dealing with asynchronous I/O. All ISAPI * extensions that use only synchronous I/O and are compatible with the * ISAPI 2.0 specification should work (most ISAPI 1.0 extensions should * function as well). * * To load, simply place the ISA in a location in the document tree. * Then add an "AddHandler isapi-isa dll" into your config file. * You should now be able to load ISAPI DLLs just be reffering to their * URLs. Make sure the ExecCGI option is active in the directory * the ISA is in. */#include "apr_strings.h"#include "apr_portable.h"#include "apr_buckets.h"#include "ap_config.h"#include "httpd.h"#include "http_config.h"#include "http_core.h"#include "http_protocol.h"#include "http_request.h"#include "http_log.h"#include "util_script.h"#include "mod_core.h"/* We use the exact same header file as the original */#include <HttpExt.h>#if !defined(HSE_REQ_MAP_URL_TO_PATH_EX) \ || !defined(HSE_REQ_SEND_RESPONSE_HEADER_EX)#pragma message("WARNING: This build of Apache is missing the recent changes")#pragma message("in the Microsoft Win32 Platform SDK; some mod_isapi features")#pragma message("will be disabled.  To obtain the latest Platform SDK files,")#pragma message("please refer to:")#pragma message("http://msdn.microsoft.com/downloads/sdks/platform/platform.asp")#endif/* TODO: Unknown errors that must be researched for correct codes */#define TODO_ERROR 1/* Seems IIS does not enforce the requirement for \r\n termination on HSE_REQ_SEND_RESPONSE_HEADER,   define this to conform */#define RELAX_HEADER_RULEmodule isapi_module;/* Declare the ISAPI functions */BOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName,                               LPVOID lpvBuffer, LPDWORD lpdwSizeofBuffer);BOOL WINAPI WriteClient (HCONN ConnID, LPVOID Buffer, LPDWORD lpwdwBytes,                         DWORD dwReserved);BOOL WINAPI ReadClient (HCONN ConnID, LPVOID lpvBuffer, LPDWORD lpdwSize);BOOL WINAPI ServerSupportFunction (HCONN hConn, DWORD dwHSERequest,                                   LPVOID lpvBuffer, LPDWORD lpdwSize,                                   LPDWORD lpdwDataType);/*    The optimiser blows it totally here. What happens is that autos are addressed relative to the    stack pointer, which, of course, moves around. The optimiser seems to lose track of it somewhere    between setting HttpExtensionProc's address and calling through it. We work around the problem by     forcing it to use frame pointers.    The revisions below may eliminate this artifact.*/#pragma optimize("y",off)/* Our isapi server config structure */typedef struct {    HANDLE lock;    apr_array_header_t *loaded;    DWORD ReadAheadBuffer;    int LogNotSupported;    int AppendLogToErrors;    int AppendLogToQuery;} isapi_server_conf;/* Our loaded isapi module description structure */typedef struct {    const char *filename;    apr_dso_handle_t *handle;    HSE_VERSION_INFO *pVer;    PFN_GETEXTENSIONVERSION GetExtensionVersion;    PFN_HTTPEXTENSIONPROC   HttpExtensionProc;    PFN_TERMINATEEXTENSION  TerminateExtension;    int   refcount;    DWORD timeout;    BOOL  fakeasync;    DWORD reportversion;} isapi_loaded;/* Our "Connection ID" structure */typedef struct {    LPEXTENSION_CONTROL_BLOCK ecb;    isapi_server_conf *sconf;    isapi_loaded *isa;    request_rec  *r;    PFN_HSE_IO_COMPLETION completion;    PVOID  completion_arg;    HANDLE complete;} isapi_cid;static BOOL isapi_unload(isapi_loaded* isa, int force);static apr_status_t cleanup_isapi_server_config(void *sconfv){    isapi_server_conf *sconf = sconfv;    size_t n;    isapi_loaded **isa;     n = sconf->loaded->nelts;    isa = (isapi_loaded **)sconf->loaded->elts;    while(n--) {        if ((*isa)->handle)            isapi_unload(*isa, TRUE);         ++isa;    }    CloseHandle(sconf->lock);    return APR_SUCCESS;}static void *create_isapi_server_config(apr_pool_t *p, server_rec *s){    isapi_server_conf *sconf = apr_palloc(p, sizeof(isapi_server_conf));    sconf->loaded = apr_array_make(p, 20, sizeof(isapi_loaded*));    sconf->lock = CreateMutex(NULL, FALSE, NULL);    sconf->ReadAheadBuffer = 49152;    sconf->LogNotSupported    = -1;    sconf->AppendLogToErrors   = 0;    sconf->AppendLogToQuery    = 0;    apr_pool_cleanup_register(p, sconf, cleanup_isapi_server_config,                                    apr_pool_cleanup_null);    return sconf;}static int compare_loaded(const void *av, const void *bv){    const isapi_loaded **a = av;    const isapi_loaded **b = bv;    return strcmp((*a)->filename, (*b)->filename);}static void isapi_post_config(apr_pool_t *p, apr_pool_t *plog,                              apr_pool_t *ptemp, server_rec *s){    isapi_server_conf *sconf = ap_get_module_config(s->module_config,                                                     &isapi_module);    isapi_loaded **elts = (isapi_loaded **)sconf->loaded->elts;    int nelts = sconf->loaded->nelts;    /* sort the elements of the main_server, by filename */    qsort(elts, nelts, sizeof(isapi_loaded*), compare_loaded);    /* and make the virtualhosts share the same thing */    for (s = s->next; s; s = s->next) {	ap_set_module_config(s->module_config, &isapi_module, sconf);    }}static apr_status_t isapi_load(apr_pool_t *p, isapi_server_conf *sconf,                                request_rec *r, const char *fpath,                                isapi_loaded** isa){    isapi_loaded **found = (isapi_loaded **)sconf->loaded->elts;    apr_status_t rv;    int n;    for (n = 0; n < sconf->loaded->nelts; ++n) {        if (strcasecmp(fpath, (*found)->filename) == 0) {            break;        }        ++found;    }        if (n < sconf->loaded->nelts)     {        *isa = *found;        if ((*isa)->handle)         {            ++(*isa)->refcount;            return APR_SUCCESS;        }        /* Otherwise we fall through and have to reload the resource         * into this existing mod_isapi cache bucket.         */    }    else    {        *isa = apr_pcalloc(p, sizeof(isapi_module));        (*isa)->filename = fpath;        (*isa)->pVer = apr_pcalloc(p, sizeof(HSE_VERSION_INFO));            /* TODO: These need to become overrideable, so that we         * assure a given isapi can be fooled into behaving well.         */        (*isa)->timeout = INFINITE; /* microsecs */        (*isa)->fakeasync = TRUE;        (*isa)->reportversion = MAKELONG(0, 5); /* Revision 5.0 */    }        rv = apr_dso_load(&(*isa)->handle, fpath, p);    if (rv)    {        ap_log_rerror(APLOG_MARK, APLOG_ALERT, rv, r,                      "ISAPI %s failed to load", fpath);        (*isa)->handle = NULL;        return rv;    }    rv = apr_dso_sym((void**)&(*isa)->GetExtensionVersion, (*isa)->handle,                     "GetExtensionVersion");    if (rv)    {        ap_log_rerror(APLOG_MARK, APLOG_ALERT, rv, r,                      "ISAPI %s is missing GetExtensionVersion()",                      fpath);        apr_dso_unload((*isa)->handle);        (*isa)->handle = NULL;        return rv;    }    rv = apr_dso_sym((void**)&(*isa)->HttpExtensionProc, (*isa)->handle,                     "HttpExtensionProc");    if (rv)    {        ap_log_rerror(APLOG_MARK, APLOG_ALERT, rv, r,                      "ISAPI %s is missing HttpExtensionProc()",                      fpath);        apr_dso_unload((*isa)->handle);        (*isa)->handle = NULL;        return rv;    }    /* TerminateExtension() is an optional interface */    rv = apr_dso_sym((void**)&(*isa)->TerminateExtension, (*isa)->handle,                     "TerminateExtension");    SetLastError(0);    /* Run GetExtensionVersion() */    if (!((*isa)->GetExtensionVersion)((*isa)->pVer)) {        apr_status_t rv = apr_get_os_error();        ap_log_rerror(APLOG_MARK, APLOG_ALERT, rv, r,                      "ISAPI %s call GetExtensionVersion() failed",                       fpath);        apr_dso_unload((*isa)->handle);        (*isa)->handle = NULL;        return rv;    }    ++(*isa)->refcount;

⌨️ 快捷键说明

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