home *** CD-ROM | disk | FTP | other *** search
- <HTML><TITLE>TstISAPI.cpp</TITLE><BODY><PRE>/*____________________________________________________________________________*\
- *
-
- Copyright (c) 1997 John Roy. All rights reserved.
-
- These sources, libraries and applications are
- FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
- as long as the following conditions are adhered to.
-
- 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. Redistributions of any form whatsoever and all advertising materials
- mentioning features must contain the following
- acknowledgment:
- "This product includes software developed by John Roy
- (http://www.johnroy.com/pi3/)."
-
- 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 AUTHORS 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.
-
- *____________________________________________________________________________*|
- *
- * $Source: ISAPI20.cpp$
- * $Date: Sun Aug 10 06:36:50 1997$
- *
- Description:
- Test ISAPI
-
- \*____________________________________________________________________________*/
- //$SourceTop:$
-
- #include <stdio.h>
- #include <HTTPExt.h>
-
- /*____________________________________________________________________________*\
- *
- Function:
- Synopsis:
- Description:
- Internal function for sending a variable
- \*____________________________________________________________________________*/
- static void Internal_sendVar( LPEXTENSION_CONTROL_BLOCK lpEcb,
- const char *pVariable, int iNumeric=0 )
- {
- enum { BUF_SIZE = 1024 };
- char szBuf[BUF_SIZE];
- DWORD dwLen;
-
- dwLen = strlen( pVariable );
- (lpEcb->WriteClient)(
- lpEcb->ConnID,
- (void *)pVariable,
- &dwLen,
- 0 ); /* reserved */
-
- dwLen = 1;
- (lpEcb->WriteClient)(
- lpEcb->ConnID,
- "=",
- &dwLen,
- 0 ); /* reserved */
-
- dwLen = BUF_SIZE;
- (lpEcb->GetServerVariable)(
- lpEcb->ConnID,
- (char *)pVariable,
- (void *)szBuf,
- &dwLen );
-
- if ( iNumeric )
- {
- long lTmp = *( (long *)szBuf );
- sprintf( szBuf, "%ld", lTmp );
- dwLen = strlen( szBuf );
- };
-
- (lpEcb->WriteClient)(
- lpEcb->ConnID,
- (void *)szBuf,
- &dwLen,
- 0 ); /* reserved */
-
- dwLen = 1;
- (lpEcb->WriteClient)(
- lpEcb->ConnID,
- "\n",
- &dwLen,
- 0 ); /* reserved */
- }
-
- /*____________________________________________________________________________*\
- *
- Function:
- Synopsis:
- Description:
- \*____________________________________________________________________________*/
- BOOL WINAPI GetExtensionVersion( HSE_VERSION_INFO *pInfo )
- {
- pInfo->dwExtensionVersion = HSE_VERSION_MAJOR;
- pInfo->dwExtensionVersion = pInfo->dwExtensionVersion << 16;
- pInfo->dwExtensionVersion = pInfo->dwExtensionVersion | HSE_VERSION_MINOR;
- sprintf( pInfo->lpszExtensionDesc, "%s", "Hello! ISAPI" );
- return TRUE;
- }
-
- /*____________________________________________________________________________*\
- *
- Function:
- Synopsis:
- Description:
- \*____________________________________________________________________________*/
- DWORD WINAPI HttpExtensionProc( LPEXTENSION_CONTROL_BLOCK lpEcb )
- {
- DWORD dwLen;
-
- /*
- ** Send HTTP Headers
- */
- #define HEADER "Content-Type: text/html\r\n\r\n"
- dwLen = sizeof(HEADER) - 1;
- (lpEcb->ServerSupportFunction)(
- lpEcb->ConnID,
- HSE_REQ_SEND_RESPONSE_HEADER,
- 0, /* 200 OK */
- &dwLen,
- (LPDWORD)HEADER
- );
-
- /*
- ** Send body header
- */
- #define BODY_TOP "\
- <HTML><BODY BGCOLOR=\"#FFFFFF\" BACKGROUND=\"/icons/Pi3Tile.gif\">\
- <H1>Hello World!</H1>Welcome to the wonderful world of ISAPI programming!\
- <PRE>\
- "
- dwLen = sizeof( BODY_TOP ) - 1;
- (lpEcb->WriteClient)(
- lpEcb->ConnID,
- BODY_TOP,
- &dwLen,
- 0 /* reserved */
- );
-
- Internal_sendVar( lpEcb, "AUTH_TYPE" );
- Internal_sendVar( lpEcb, "CONTENT_LENGTH", 1 );
- Internal_sendVar( lpEcb, "CONTENT_TYPE" );
- Internal_sendVar( lpEcb, "GATEWAY_INTERFACE" );
- Internal_sendVar( lpEcb, "PATH_INFO" );
- Internal_sendVar( lpEcb, "PATH_TRANSLATED" );
- Internal_sendVar( lpEcb, "QUERY_STRING" );
- Internal_sendVar( lpEcb, "REMOTE_ADDR" );
- Internal_sendVar( lpEcb, "REMOTE_HOST" );
- Internal_sendVar( lpEcb, "REMOTE_USER" );
- Internal_sendVar( lpEcb, "REQUEST_METHOD" );
- Internal_sendVar( lpEcb, "SCRIPT_NAME" );
- Internal_sendVar( lpEcb, "SERVER_NAME" );
- Internal_sendVar( lpEcb, "SERVER_PORT" );
- Internal_sendVar( lpEcb, "SERVER_PROTOCOL" );
- Internal_sendVar( lpEcb, "SERVER_SOFTWARE" );
- Internal_sendVar( lpEcb, "AUTH_PASS" );
- #undef AT
-
- /*
- ** Send body footer
- */
- #define BODY_FOOTER "\
- </PRE></BODY></HTML>"
- dwLen = sizeof( BODY_FOOTER ) - 1;
- (lpEcb->WriteClient)(
- lpEcb->ConnID,
- BODY_FOOTER,
- &dwLen,
- 0 /* reserved */
- );
-
- /*
- ** Success, but we didn't send the content-length header
- */
- return HSE_STATUS_SUCCESS;
- }
-
- </PRE></BODY></HTML>