mod_isapi.c revision 8b02d65f24f85548965ccaef1d8fcd299f5db408
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* ====================================================================
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * The Apache Software License, Version 1.1
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Copyright (c) 2000 The Apache Software Foundation. All rights
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Redistribution and use in source and binary forms, with or without
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * modification, are permitted provided that the following conditions
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 1. Redistributions of source code must retain the above copyright
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * notice, this list of conditions and the following disclaimer.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 2. Redistributions in binary form must reproduce the above copyright
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * notice, this list of conditions and the following disclaimer in
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * the documentation and/or other materials provided with the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * distribution.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 3. The end-user documentation included with the redistribution,
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * if any, must include the following acknowledgment:
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * "This product includes software developed by the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Apache Software Foundation (http://www.apache.org/)."
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Alternately, this acknowledgment may appear in the software itself,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * if and wherever such third-party acknowledgments normally appear.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 4. The names "Apache" and "Apache Software Foundation" must
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * not be used to endorse or promote products derived from this
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * software without prior written permission. For written
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * permission, please contact apache@apache.org.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 5. Products derived from this software may not be called "Apache",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * nor may "Apache" appear in their name, without prior written
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * permission of the Apache Software Foundation.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * SUCH DAMAGE.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * ====================================================================
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * This software consists of voluntary contributions made by many
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * individuals on behalf of the Apache Software Foundation. For more
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * information on the Apache Software Foundation, please see
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Portions of this software are based upon public domain software
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * originally written at the National Center for Supercomputing Applications,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * University of Illinois, Urbana-Champaign.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * mod_isapi.c - Internet Server Application (ISA) module for Apache
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * by Alexei Kosut <akosut@apache.org>
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * This module implements Microsoft's ISAPI, allowing Apache (when running
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * under Windows) to load Internet Server Applications (ISAPI extensions).
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * It implements all of the ISAPI 2.0 specification, except for the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * "Microsoft-only" extensions dealing with asynchronous I/O. All ISAPI
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * extensions that use only synchronous I/O and are compatible with the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * ISAPI 2.0 specification should work (most ISAPI 1.0 extensions should
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * function as well).
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * To load, simply place the ISA in a location in the document tree.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Then add an "AddHandler isapi-isa dll" into your config file.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * You should now be able to load ISAPI DLLs just be reffering to their
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * URLs. Make sure the ExecCGI option is active in the directory
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * the ISA is in.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* We use the exact same header file as the original */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* TODO: Unknown errors that must be researched for correct codes */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* Seems IIS does not enforce the requirement for \r\n termination on HSE_REQ_SEND_RESPONSE_HEADER,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz define this to conform */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* Declare the ISAPI functions */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzBOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzBOOL WINAPI WriteClient (HCONN ConnID, LPVOID Buffer, LPDWORD lpwdwBytes,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzBOOL WINAPI ReadClient (HCONN ConnID, LPVOID lpvBuffer, LPDWORD lpdwSize);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzBOOL WINAPI ServerSupportFunction (HCONN hConn, DWORD dwHSERequest,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz The optimiser blows it totally here. What happens is that autos are addressed relative to the
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd stack pointer, which, of course, moves around. The optimiser seems to lose track of it somewhere
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd between setting HttpExtensionProc's address and calling through it. We work around the problem by
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd forcing it to use frame pointers.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd The revisions below may eliminate this artifact.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/* Our loaded isapi module description structure */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndtypedef struct {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/* Our "Connection ID" structure */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndtypedef struct {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Use similar restrictions as CGIs
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * If this fails, it's pointless to load the isapi dll.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Load the module
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * TODO: Critical section
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Warning: cid should not be allocated from pool if we
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * cache the isapi process in-memory.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * This code could use cacheing... everything that follows
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * should only be performed on the first isapi dll invocation,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * not with every HttpExtensionProc()
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz isa = apr_pcalloc(r->pool, sizeof(isapi_module));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz isa->pVer = apr_pcalloc(r->pool, sizeof(HSE_VERSION_INFO));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* TODO: These may need to become overrideable, so that we
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * assure a given isapi can be fooled into behaving well.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz isa->reportversion = MAKELONG(0, 5); /* Revision 5.0 */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (!(isa->handle = LoadLibraryEx(r->filename, NULL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ALERT, GetLastError(), r,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz (void *)(GetProcAddress(isa->handle, "GetExtensionVersion")))) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ALERT, GetLastError(), r,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "ISAPI %s is missing GetExtensionVersion()",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz (void *)(GetProcAddress(isa->handle, "HttpExtensionProc")))) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ALERT, GetLastError(), r,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "ISAPI %s is missing HttpExtensionProc()",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* TerminateExtension() is an optional interface */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz isa->TerminateExtension = (void *)(GetProcAddress(isa->handle, "TerminateExtension"));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Run GetExtensionVersion() */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* ### euh... we're passing the wrong type of error code here */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ALERT, HTTP_INTERNAL_SERVER_ERROR, r,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "ISAPI %s call GetExtensionVersion() failed",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Load of this module completed, this is the point at which *isa
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * could be cached for later invocation.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * on to invoking this request...
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Set up variables */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Set up connection structure and ecb */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz cid->ecb = apr_pcalloc(r->pool, sizeof(struct _EXTENSION_CONTROL_BLOCK));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* TODO: Critical section */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz // TODO: are copies really needed here?
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz cid->ecb->lpszMethod = apr_pstrdup(r->pool, (char*) r->method);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz cid->ecb->lpszQueryString = apr_pstrdup(r->pool,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz cid->ecb->lpszContentType = apr_pstrdup(r->pool,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Set up the callbacks */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd cid->ecb->ServerSupportFunction = &ServerSupportFunction;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Set up client input */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd cid->retval = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Unlike IIS, which limits this to 48k, we read the whole
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * sucker in. I suppose this could be bad for memory if someone
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * uploaded the complete works of Shakespeare. Well, WebSite
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * does the same thing.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * But we can be smarter and read up to our 48k and then allow
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * the ISAPI app to read further blocks as desired.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Actually, let's cap it at 48k, until we figure out what
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * to do with this... we don't want a Content-Length: 1000000000
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * taking out the machine.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if ((read = ap_get_client_block(r, cid->ecb->lpbData, to_read)) < 0) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Although its not to spec, IIS seems to null-terminate
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * its lpdData string. So we will too. To make sure
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * cbAvailable matches cbTotalBytes, we'll up the latter
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * and equalize them.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd cid->ecb->cbAvailable = cid->ecb->cbTotalBytes = read + 1;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* All right... try and run the sucker */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Set the status (for logging) */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Check for a log message - and log it */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Ignore the keepalive stuff; Apache handles it just fine without
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * the ISA's "advice".
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Per Microsoft: "In IIS versions 4.0 and later, the return
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * values HSE_STATUS_SUCCESS and HSE_STATUS_SUCCESS_AND_KEEP_CONN
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * are functionally identical: Keep-Alive connections are
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * maintained, if supported by the client."
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * ... so we were pat all this time
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* emulating async behavior...
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Create a cid->completed event and wait on it for some timeout
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * so that the app thinks is it running async.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * All async ServerSupportFunction calls will be handled through
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * the registered IO_COMPLETION hook.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_WARNING, APR_ENOTIMPL, r,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "ISAPI %s asynch I/O request refused",
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* TODO: Now what... if this hung, then do we kill our own
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * thread to force it's death? For now leave timeout = -1
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* end response if we have yet to do so.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* TODO: log unrecognized retval for debugging
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* All done with the DLL... get rid of it...
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * If optionally cached, pass HSE_TERM_ADVISORY_UNLOAD,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * and if it returns TRUE, unload, otherwise, cache it.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* TODO: Crit section */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndBOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd const char *result;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Mostly, we just grab it from the environment, but there are
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * a couple of special cases
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (!strcasecmp(lpszVariableName, "UNMAPPED_REMOTE_USER")) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* We don't support NT users, so this is always the same as
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * REMOTE_USER
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd else if (!strcasecmp(lpszVariableName, "SERVER_PORT_SECURE")) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Apache doesn't support secure requests inherently, so
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * we have no way of knowing. We'll be conservative, and say
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * all requests are insecure.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Didn't find it */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndBOOL WINAPI WriteClient (HCONN ConnID, LPVOID Buffer, LPDWORD lpwdwBytes,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd int writ; /* written, actually, but why shouldn't I make up words? */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* We only support synchronous writing */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_WARNING, ERROR_INVALID_PARAMETER, r,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if ((writ = ap_rwrite(Buffer, *lpwdwBytes, r)) == EOF) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz SetLastError(WSAEDISCON); /* TODO: Find the right error code */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzBOOL WINAPI ReadClient (HCONN ConnID, LPVOID lpvBuffer, LPDWORD lpdwSize)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* TODO: If the request was a huge transmit or chunked, continue piping the
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * request here, but if it's of a sane size, continue to ...
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic char* ComposeHeaders(request_rec *r, char* data)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* We *should* break before this while loop ends */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Get rid of \n and \r */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (p > 0 && data[p-1] == '\r') data[p-1] = '\0';
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* End of headers */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* ### euh... we're passing the wrong type of error
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ### code here */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ERR, HTTP_INTERNAL_SERVER_ERROR, r,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Check all the special-case headers. Similar to what
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * ap_scan_script_header_err() does (see that function for
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * more detail)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Nuke trailing whitespace */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else if (!strcasecmp(data, "Transfer-Encoding")) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_table_merge(r->err_headers_out, data, value);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Reset data */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* XXX: There is an O(n^2) attack possible here. */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzBOOL WINAPI ServerSupportFunction (HCONN hConn, DWORD dwHSERequest,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Set the status to be returned when the HttpExtensionProc()
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_table_set (r->headers_out, "Location", lpvBuffer);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Read any additional input */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (r->remaining > 0) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz while (ap_get_client_block(r, argsbuffer, HUGE_STRING_LEN));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Reset the method to GET */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Don't let anyone think there's still data */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_table_unset(r->headers_in, "Content-Length");
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz r->status_line = lpvBuffer ? lpvBuffer : apr_pstrdup(r->pool, "200 OK");
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Now fill in the HTTP headers, and the rest of it. Ick.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * lpdwDataType contains a string that has headers (in MIME
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * format), a blank like, then (possibly) data. We need
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * to parse it.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Easy case first:
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Make a copy - don't disturb the original */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz data = apr_pstrdup(r->pool, (char *)lpdwDataType);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Parse them out, or die trying */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* All the headers should be set now */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Any data left should now be sent directly */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Signal to resume the thread completing this request
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Map a URL to a filename */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz subreq = ap_sub_req_lookup_uri(apr_pstrndup(r->pool, (char *)lpvBuffer,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd GetFullPathName(subreq->filename, *lpdwSize - 1, (char *)lpvBuffer, NULL);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* IIS puts a trailing slash on directories, Apache doesn't */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Log lpvBuffer, of lpdwSize bytes, in the URI Query (cs-uri-query) field
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * This code will do for now...
2d728410bcf9e6e53698bb035f516e18efd76d8bnd /* TODO: Emulate a completion port, if we can...
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * Record the callback address and user defined argument...
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * we will call this after any async request (e.g. transmitfile)
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * as if the request had completed async execution.
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * Per MS docs... HSE_REQ_IO_COMPLETION replaces any prior call
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * to HSE_REQ_IO_COMPLETION, and lpvBuffer may be set to NULL.
2d728410bcf9e6e53698bb035f516e18efd76d8bnd /* Use TransmitFile... nothing wrong with that :)
2d728410bcf9e6e53698bb035f516e18efd76d8bnd /* ### euh... we're passing the wrong type of error code here */
2d728410bcf9e6e53698bb035f516e18efd76d8bnd "ISAPI asynchronous I/O not supported: %s",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz case HSE_REQ_GET_IMPERSONATION_TOKEN: /* Added in ISAPI 4.0 */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* TODO: Not quite ready for prime time yet */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Map a URL to a filename */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd subreq = ap_sub_req_lookup_uri(apr_pstrndup(r->pool, (char *)lpvBuffer,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz GetFullPathName(subreq->filename, *lpdwSize - 1, (char *)lpvBuffer, NULL);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* IIS puts a trailing slash on directories, Apache doesn't */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz lpdwDataType = (LPDWORD) apr_palloc(r->pool, sizeof(HSE_URL_MAPEX_INFO));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz strncpy(((LPHSE_URL_MAPEX_INFO)lpdwDataType)->lpszPath,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ((LPHSE_URL_MAPEX_INFO)lpdwDataType)->dwFlags = 0;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* is a combination of:
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * HSE_URL_FLAGS_READ Allow for read.
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * HSE_URL_FLAGS_WRITE Allow for write.
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * HSE_URL_FLAGS_EXECUTE Allow for execute.
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * HSE_URL_FLAGS_SSL Require SSL.
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * HSE_URL_FLAGS_DONT_CACHE Don't cache (virtual root only).
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * HSE_URL_FLAGS_NEGO_CERT Allow client SSL certifications.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * HSE_URL_FLAGS_REQUIRE_CERT Require client SSL certifications.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * HSE_URL_FLAGS_MAP_CERT Map SSL certification to a Windows account.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * HSE_URL_FLAGS_SSL128 Requires a 128-bit SSL.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * HSE_URL_FLAGS_SCRIPT Allows for script execution.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* (LPHSE_URL_MAPEX_INFO)lpdwDataType)->cchMatchingPath
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * (LPHSE_URL_MAPEX_INFO)lpdwDataType)->cchMatchingURL
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz case HSE_REQ_SEND_RESPONSE_HEADER_EX: /* Added in ISAPI 4.0 */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* TODO: Not quite ready for prime time */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz && ((LPHSE_SEND_HEADER_EX_INFO)lpvBuffer)->cchStatus) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ((LPHSE_SEND_HEADER_EX_INFO)lpvBuffer)->pszStatus,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (((LPHSE_SEND_HEADER_EX_INFO)lpvBuffer)->pszHeader
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Make a copy - don't disturb the original */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ((LPHSE_SEND_HEADER_EX_INFO)lpvBuffer)->pszHeader,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Parse them out, or die trying */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* ((LPHSE_SEND_HEADER_EX_INFO)lpvBuffer)->fKeepConn;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Now how are we about to start listening to an ISAPI's
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * idea of keeping or closing a connection? Seriously :)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* All the headers should be set now */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Any data left should now be sent directly */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* HSE_REQ_CLOSE_CONNACTION and HSE_REQ_IS_CONNECTED are not defined on
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * my system. wgs */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd case HSE_REQ_CLOSE_CONNECTION: /* Added after ISAPI 4.0 */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Returns True if client is connected c.f. Q188346*/
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* case HSE_REQ_EXTENSION_TRIGGER:
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Added after ISAPI 4.0?
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Undocumented - from the Microsoft Jan '00 Platform SDK
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* TODO: log unrecognized ServerSupportCommand for debugging