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

📄 mod_isapi.c

📁 apache简化版
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ==================================================================== * Copyright (c) 1995-1998 The Apache Group.  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. All advertising materials mentioning features or use of this *    software must display the following acknowledgment: *    "This product includes software developed by the Apache Group *    for use in the Apache HTTP server project (http://www.apache.org/)." * * 4. The names "Apache Server" and "Apache Group" 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 Group. * * 6. Redistributions of any form whatsoever must retain the following *    acknowledgment: *    "This product includes software developed by the Apache Group *    for use in the Apache HTTP server project (http://www.apache.org/)." * * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``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 GROUP 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 Group and was originally based * on public domain software written at the National Center for * Supercomputing Applications, University of Illinois, Urbana-Champaign. * For more information on the Apache Group and the Apache HTTP server * project, please see <http://www.apache.org/>. * *//* * 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 "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"/* We use the exact same header file as the original */#include <HttpExt.h>/* 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;/* Our "Connection ID" structure */typedef struct {    LPEXTENSION_CONTROL_BLOCK ecb;    request_rec *r;    int status;} isapi_cid;/* 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 isapi_entry and calling through it. We work around the problem by forcing it to    use frame pointers.*/#pragma optimize("y",off)int isapi_handler (request_rec *r) {    LPEXTENSION_CONTROL_BLOCK ecb =	ap_pcalloc(r->pool, sizeof(struct _EXTENSION_CONTROL_BLOCK));    HSE_VERSION_INFO *pVer = ap_pcalloc(r->pool, sizeof(HSE_VERSION_INFO));    HINSTANCE isapi_handle;    BOOL (*isapi_version)(HSE_VERSION_INFO *); /* entry point 1 */    DWORD (*isapi_entry)(LPEXTENSION_CONTROL_BLOCK); /* entry point 2 */    BOOL (*isapi_term)(DWORD); /* optional entry point 3 */    isapi_cid *cid = ap_pcalloc(r->pool, sizeof(isapi_cid));    table *e = r->subprocess_env;    int retval;    /* Use similar restrictions as CGIs */    if (!(ap_allow_options(r) & OPT_EXECCGI))	return FORBIDDEN;    if (r->finfo.st_mode == 0)	return NOT_FOUND;    if (S_ISDIR(r->finfo.st_mode))	return FORBIDDEN;    /* Load the module */    if (!(isapi_handle = LoadLibraryEx(r->filename, NULL,				       LOAD_WITH_ALTERED_SEARCH_PATH))) {	ap_log_rerror(APLOG_MARK, APLOG_ALERT, r,		    "Could not load DLL: %s", r->filename);	return SERVER_ERROR;    }    if (!(isapi_version =	  (void *)(GetProcAddress(isapi_handle, "GetExtensionVersion")))) {	ap_log_rerror(APLOG_MARK, APLOG_ALERT, r,		    "DLL could not load GetExtensionVersion(): %s", r->filename);	FreeLibrary(isapi_handle);	return SERVER_ERROR;    }    if (!(isapi_entry =	  (void *)(GetProcAddress(isapi_handle, "HttpExtensionProc")))) {	ap_log_rerror(APLOG_MARK, APLOG_ALERT, r,		    "DLL could not load HttpExtensionProc(): %s", r->filename);	FreeLibrary(isapi_handle);	return SERVER_ERROR;    }    isapi_term = (void *)(GetProcAddress(isapi_handle, "TerminateExtension"));    /* Run GetExtensionVersion() */    if ((*isapi_version)(pVer) != TRUE) {	ap_log_rerror(APLOG_MARK, APLOG_ALERT, r,		    "ISAPI GetExtensionVersion() failed: %s", r->filename);	FreeLibrary(isapi_handle);	return SERVER_ERROR;    }    /* Set up variables */    ap_add_common_vars(r);    ap_add_cgi_vars(r);    /* Set up connection ID */    ecb->ConnID = (HCONN)cid;    cid->ecb = ecb;    cid->r = r;    cid->status = 0;    ecb->cbSize = sizeof(struct _EXTENSION_CONTROL_BLOCK);    ecb->dwVersion = MAKELONG(0, 2);    ecb->dwHttpStatusCode = 0;    strcpy(ecb->lpszLogData, "");    ecb->lpszMethod = r->method;    ecb->lpszQueryString = ap_table_get(e, "QUERY_STRING");    ecb->lpszPathInfo = ap_table_get(e, "PATH_INFO");    ecb->lpszPathTranslated = ap_table_get(e, "PATH_TRANSLATED");    ecb->lpszContentType = ap_table_get(e, "CONTENT_TYPE");    /* Set up client input */    if ((retval = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))) {	if (isapi_term) (*isapi_term)(HSE_TERM_MUST_UNLOAD);	FreeLibrary(isapi_handle);	return retval;    }    if (ap_should_client_block(r)) {	/* Unlike IIS, which limits this to 48k, we read the whole	 * sucker in. I suppose this could be bad for memory if someone	 * uploaded the complete works of Shakespeare. Well, WebSite	 * does the same thing.	 */	long to_read = atol(ap_table_get(e, "CONTENT_LENGTH"));	long read;	/* Actually, let's cap it at 48k, until we figure out what	 * to do with this... we don't want a Content-Length: 1000000000	 * taking out the machine.	 */	if (to_read > 49152) {	    if (isapi_term) (*isapi_term)(HSE_TERM_MUST_UNLOAD);	    FreeLibrary(isapi_handle);	    return HTTP_REQUEST_ENTITY_TOO_LARGE;	}	ecb->lpbData = ap_pcalloc(r->pool, 1 + to_read);	if ((read = ap_get_client_block(r, ecb->lpbData, to_read)) < 0) {	    if (isapi_term) (*isapi_term)(HSE_TERM_MUST_UNLOAD);	    FreeLibrary(isapi_handle);	    return SERVER_ERROR;	}	/* Although its not to spec, IIS seems to null-terminate	 * its lpdData string. So we will too. To make sure	 * cbAvailable matches cbTotalBytes, we'll up the latter	 * and equalize them.	 */	ecb->cbAvailable = ecb->cbTotalBytes = read + 1;	ecb->lpbData[read] = '\0';	}    else {	ecb->cbTotalBytes = 0;	ecb->cbAvailable = 0;	ecb->lpbData = NULL;    }    /* Set up the callbacks */    ecb->GetServerVariable = &GetServerVariable;    ecb->WriteClient = &WriteClient;    ecb->ReadClient = &ReadClient;    ecb->ServerSupportFunction = &ServerSupportFunction;    /* All right... try and load the sucker */    retval = (*isapi_entry)(ecb);    /* Set the status (for logging) */    if (ecb->dwHttpStatusCode)	r->status = ecb->dwHttpStatusCode;    /* Check for a log message - and log it */    if (ecb->lpszLogData && strcmp(ecb->lpszLogData, ""))	ap_log_rerror(APLOG_MARK, APLOG_ERR, r,		    "%s: %s", ecb->lpszLogData, r->filename);    /* All done with the DLL... get rid of it */    if (isapi_term) (*isapi_term)(HSE_TERM_MUST_UNLOAD);    FreeLibrary(isapi_handle);    switch(retval) {    case HSE_STATUS_SUCCESS:    case HSE_STATUS_SUCCESS_AND_KEEP_CONN:	/* Ignore the keepalive stuff; Apache handles it just fine without	 * the ISA's "advice".	 */	if (cid->status) /* We have a special status to return */	    return cid->status;	return OK;    case HSE_STATUS_PENDING:	/* We don't support this */

⌨️ 快捷键说明

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