📄 tstisapi.cpp
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. 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. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
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: /cvsroot/pi3web/Pi3Web_200/Source/ISAPI/TstISAPI.cpp,v $
* $Date: 2003/05/13 18:42:05 $
*
Description:
Test ISAPI
\*____________________________________________________________________________*/
//$SourceTop:$
#include <stdio.h>
#if WIN32
#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;
if ( !lpEcb->GetServerVariable(
lpEcb->ConnID,
(char *)pVariable,
(void *)szBuf,
&dwLen ))
{
sprintf(szBuf, "[ErrorCode: %d]", GetLastError());
dwLen = strlen(szBuf);
iNumeric = 0;
};
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, "ALL_HTTP" );
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;
}
#endif //WIN32
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -