/*++ Copyright (c) 2002 Microsoft Corporation Module Name: wbisapi.cxx Abstract: Implements a fast WebBench ISAPI Author: Bilal Alam (balam) Sept 3, 2002 --*/ #include #include #include #include #include #include CHAR * g_pszStaticHeader; DWORD g_cbStaticHeader; DWORD WINAPI HttpExtensionProc( EXTENSION_CONTROL_BLOCK * pecb ) /*++ Routine Description: Main entry point for ISAPI Arguments: pecb - EXTENSION_CONTROL_BLOCK * Return Value: HSE_STATUS_* --*/ { CHAR achDynamic[ 4096 ]; STRA strDynamic( achDynamic, sizeof( achDynamic ) ); HRESULT hr; BOOL fRet; CHAR achBuffer[ 512 ]; DWORD cbBuffer; HSE_RESPONSE_VECTOR responseVector; HSE_VECTOR_ELEMENT vectorElement[ 2 ]; // // Generate dynamic portion // hr = strDynamic.Append( "SERVER_NAME = " ); if ( FAILED( hr ) ) { goto Failure; } cbBuffer = sizeof( achBuffer ); fRet = pecb->GetServerVariable( pecb->ConnID, "SERVER_NAME", achBuffer, &cbBuffer ); if ( !fRet ) { hr = HRESULT_FROM_WIN32( GetLastError() ); goto Failure; } hr = strDynamic.Append( achBuffer ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nGATEWAY_INTERFACE = CGI/1.1\nSERVER_PROTOCOL = " ); if ( FAILED( hr ) ) { goto Failure; } cbBuffer = sizeof( achBuffer ); fRet = pecb->GetServerVariable( pecb->ConnID, "SERVER_PROTOCOL", achBuffer, &cbBuffer ); if ( !fRet ) { hr = HRESULT_FROM_WIN32( GetLastError() ); goto Failure; } hr = strDynamic.Append( achBuffer ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nSERVER_PORT = 80\nREQUEST_METHOD = " ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( pecb->lpszMethod ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nHTTP_ACCEPT = " ); if ( FAILED( hr ) ) { goto Failure; } cbBuffer = sizeof( achBuffer ); fRet = pecb->GetServerVariable( pecb->ConnID, "HTTP_ACCEPT", achBuffer, &cbBuffer ); if ( !fRet ) { achBuffer[ 0 ] = '\0'; } hr = strDynamic.Append( achBuffer ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nHTTP_USER_AGENT = " ); if ( FAILED( hr ) ) { goto Failure; } cbBuffer = sizeof( achBuffer ); fRet = pecb->GetServerVariable( pecb->ConnID, "HTTP_USER_AGENT", achBuffer, &cbBuffer ); if ( !fRet ) { achBuffer[ 0 ] = '\0'; } hr = strDynamic.Append( achBuffer ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nHTTP_REFERER = " ); if ( FAILED( hr ) ) { goto Failure; } cbBuffer = sizeof( achBuffer ); fRet = pecb->GetServerVariable( pecb->ConnID, "HTTP_REFERER", achBuffer, &cbBuffer ); if ( !fRet ) { achBuffer[ 0 ] = '\0'; } hr = strDynamic.Append( achBuffer ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nPATH_INFO = " ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( pecb->lpszPathInfo ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nPATH_TRANSLATED = " ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( pecb->lpszPathTranslated ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nSCRIPT_NAME = " ); if ( FAILED( hr ) ) { goto Failure; } cbBuffer = sizeof( achBuffer ); fRet = pecb->GetServerVariable( pecb->ConnID, "SCRIPT_NAME", achBuffer, &cbBuffer ); if ( !fRet ) { hr = HRESULT_FROM_WIN32( GetLastError() ); goto Failure; } hr = strDynamic.Append( achBuffer ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nQUERY_STRING = " ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( pecb->lpszQueryString ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nREMOTE_HOST = " ); if ( FAILED( hr ) ) { goto Failure; } cbBuffer = sizeof( achBuffer ); fRet = pecb->GetServerVariable( pecb->ConnID, "REMOTE_HOST", achBuffer, &cbBuffer ); if ( !fRet ) { hr = HRESULT_FROM_WIN32( GetLastError() ); goto Failure; } hr = strDynamic.Append( achBuffer ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nREMOTE_ADDR = " ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( achBuffer ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nREMOTE_USER = \nAUTH_TYPE = \nCONTENT_TYPE = " ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( pecb->lpszContentType ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nCONTENT_LENGTH = " ); if ( FAILED( hr ) ) { goto Failure; } cbBuffer = sizeof( achBuffer ); fRet = pecb->GetServerVariable( pecb->ConnID, "CONTENT_LENGTH", achBuffer, &cbBuffer ); if ( !fRet ) { hr = HRESULT_FROM_WIN32( GetLastError() ); goto Failure; } hr = strDynamic.Append( achBuffer ); if ( FAILED( hr ) ) { goto Failure; } hr = strDynamic.Append( "\nANNOTATION_SERVER = \n\n" ); if ( FAILED( hr ) ) { goto Failure; } // // Phew. Now that dynamic portion is done, send out response // vectorElement[ 0 ].ElementType = HSE_VECTOR_ELEMENT_TYPE_MEMORY_BUFFER; vectorElement[ 0 ].pvContext = g_pszStaticHeader; vectorElement[ 0 ].cbSize = g_cbStaticHeader; vectorElement[ 1 ].ElementType = HSE_VECTOR_ELEMENT_TYPE_MEMORY_BUFFER; vectorElement[ 1 ].pvContext = strDynamic.QueryStr(); vectorElement[ 1 ].cbSize = strDynamic.QueryCB(); responseVector.lpElementArray = vectorElement; responseVector.nElementCount = 2; responseVector.dwFlags = HSE_IO_FINAL_SEND | HSE_IO_SYNC | HSE_IO_DISCONNECT_AFTER_SEND; responseVector.pszStatus = NULL; responseVector.pszHeaders = NULL; // // Let'r rip // fRet = pecb->ServerSupportFunction( pecb->ConnID, HSE_REQ_VECTOR_SEND, &responseVector, NULL, NULL ); if ( !fRet ) { return HSE_STATUS_ERROR; } else { return HSE_STATUS_SUCCESS; } Failure: SetLastError( hr ); return HSE_STATUS_ERROR; } BOOL WINAPI GetExtensionVersion( HSE_VERSION_INFO * pver ) /*++ Routine Description: Initialization routine for ISAPI Arguments: pver - Version information Return Value: TRUE if successful, else FALSE --*/ { // // Do ISAPI interface init crap // pver->dwExtensionVersion = MAKELONG( 0, 1 ); strcpy( pver->lpszExtensionDesc, "WebBench ISAPI" ); // // Setup static header // g_pszStaticHeader = "HTTP/1.1 200 OK\r\n" \ "Content-type: text/html\r\n\r\n" \ "WebBench 2.0 HTTP API Application\n" \ "
SERVER_SOFTWARE = Microsoft-IIS/6.0\n";
    g_cbStaticHeader = (DWORD) strlen( g_pszStaticHeader );

    return TRUE;
}

BOOL
WINAPI
TerminateExtension(
    DWORD             
)
/*++

Routine Description:

    Cleanup ISAPI extension

Arguments:

    None

Return Value:

    TRUE if successful, else FALSE

--*/
{
    return TRUE;
}