home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / DumpVars.cpp < prev    next >
C/C++ Source or Header  |  1997-10-25  |  5KB  |  224 lines

  1. /*++
  2.  
  3. Copyright (c) 1997  Microsoft Corporation
  4.  
  5. Module Name:    DumpVars.cpp
  6.  
  7. Abstract:
  8.  
  9.     ISAPI Extension sample to dump server variables
  10.  
  11. --*/
  12.  
  13. #define WIN32_LEAN_AND_MEAN
  14. #include <windows.h>
  15. #include <httpext.h>
  16.  
  17.  
  18. DWORD WINAPI 
  19. HttpExtensionProc( 
  20.     IN EXTENSION_CONTROL_BLOCK * pECB
  21. )
  22. /*++
  23.  
  24. Purpose:
  25.  
  26.     Use WriteClient() function to dump the value of each 
  27.     server variable in the table.
  28.  
  29. Arguments:
  30.  
  31.     pECB - pointer to the extenstion control block 
  32.  
  33. Returns:
  34.  
  35.     HSE_STATUS_SUCCESS
  36.  
  37. --*/
  38. {
  39.     char * aszServerVariables[] =
  40.         {"APPL_MD_PATH", "APPL_PHYSICAL_PATH", "AUTH_PASSWORD",
  41.         "AUTH_TYPE", "AUTH_USER", "CERT_COOKIE", "CERT_FLAGS",
  42.         "CERT_ISSUER", "CERT_KEYSIZE", "CERT_SECRETKEYSIZE",
  43.         "CERT_SERIALNUMBER", "CERT_SERVER_ISSUER",
  44.         "CERT_SERVER_SUBJECT", "CERT_SUBJECT", "CONTENT_LENGTH",
  45.         "CONTENT_TYPE", "HTTP_ACCEPT", "HTTPS", "HTTPS_KEYSIZE",
  46.         "HTTPS_SECRETKEYSIZE", "HTTPS_SERVER_ISSUER",
  47.         "HTTPS_SERVER_SUBJECT", "INSTANCE_ID", "INSTANCE_META_PATH",
  48.         "PATH_INFO", "PATH_TRANSLATED", "QUERY_STRING",
  49.         "REMOTE_ADDR", "REMOTE_HOST", "REMOTE_USER",
  50.         "REQUEST_METHOD", "SCRIPT_NAME", "SERVER_NAME",
  51.         "SERVER_PORT", "SERVER_PORT_SECURE", "SERVER_PROTOCOL",
  52.         "SERVER_SOFTWARE", "URL"};
  53.     char szOutput[2048], szValue[1024];
  54.     DWORD dwBuffSize, dwNumVars, dwError, x;
  55.     HSE_SEND_HEADER_EX_INFO HeaderExInfo;
  56.  
  57.     //
  58.     // Send headers to the client
  59.     //
  60.     HeaderExInfo.pszStatus = "200 OK";
  61.     HeaderExInfo.pszHeader = "Content-type: text/html\r\n\r\n";
  62.     HeaderExInfo.cchStatus = strlen( HeaderExInfo.pszStatus );
  63.     HeaderExInfo.cchHeader = strlen( HeaderExInfo.pszHeader );
  64.     HeaderExInfo.fKeepConn = FALSE;
  65.     
  66.     pECB->ServerSupportFunction( 
  67.         pECB->ConnID,
  68.         HSE_REQ_SEND_RESPONSE_HEADER_EX,
  69.         &HeaderExInfo,
  70.         NULL,
  71.         NULL
  72.         );
  73.  
  74.  
  75.     //
  76.     // Begin sending back HTML to the client
  77.     //
  78.  
  79.     strcpy( 
  80.         szOutput, 
  81.         "<HTML>\r\n<BODY><h1>Server Variable Dump</h1>\r\n<hr>\r\n"
  82.         );
  83.     dwBuffSize = strlen( szOutput );
  84.     pECB->WriteClient( pECB->ConnID, szOutput, &dwBuffSize, 0 );
  85.  
  86.  
  87.     dwNumVars = ( sizeof aszServerVariables )/( sizeof aszServerVariables[0] );
  88.  
  89.     //
  90.     // Get the server variables and send them
  91.     //
  92.  
  93.     for ( x = 0; x < dwNumVars; x++ ) {
  94.  
  95.         dwBuffSize = 1024;
  96.         szValue[0] = '\0';
  97.         if ( !pECB->GetServerVariable( 
  98.                 pECB->ConnID, 
  99.                 aszServerVariables[x], 
  100.                 szValue, 
  101.                 &dwBuffSize
  102.                 ) ) {
  103.  
  104.             //
  105.             // Analyze the problem and report result to user
  106.             //
  107.  
  108.             switch (dwError = GetLastError( )) {
  109.             case ERROR_INVALID_PARAMETER:
  110.                 strcpy( szValue, "ERROR_INVALID_PARAMETER" );
  111.                 break;
  112.  
  113.             case ERROR_INVALID_INDEX:
  114.                 strcpy( szValue, "ERROR_INVALID_INDEX" );
  115.                 break;
  116.  
  117.             case ERROR_INSUFFICIENT_BUFFER:
  118.                 wsprintf( 
  119.                     szValue, 
  120.                     "ERROR_INSUFFICIENT_BUFFER - %d bytes required.", 
  121.                     dwBuffSize
  122.                     );
  123.                 break;
  124.  
  125.             case ERROR_MORE_DATA:
  126.                 strcpy( szValue, "ERROR_MORE_DATA" );
  127.                 break;
  128.  
  129.             case ERROR_NO_DATA:
  130.                 strcpy( szValue, "ERROR_NO_DATA" );
  131.                 break;
  132.  
  133.             default:
  134.                 wsprintf( 
  135.                     szValue, 
  136.                     "*** Error %d occured retrieving server variable ***",
  137.                     dwError
  138.                     );
  139.             }
  140.         }
  141.  
  142.         // 
  143.         // Dump server variable name and value
  144.         //
  145.  
  146.         wsprintf( szOutput, "%s: %s<br>\r\n", aszServerVariables[x], szValue );
  147.         dwBuffSize = strlen( szOutput );
  148.  
  149.         //
  150.         // Send the line to client
  151.         //
  152.  
  153.         pECB->WriteClient( pECB->ConnID, szOutput, &dwBuffSize, 0 );
  154.     }
  155.  
  156.     //
  157.     // End HTML page
  158.     //
  159.  
  160.     strcpy( szOutput, "</BODY>\r\n</HTML>\r\n\r\n" );
  161.     dwBuffSize = strlen( szOutput );
  162.     pECB->WriteClient( pECB->ConnID, szOutput, &dwBuffSize, 0 );
  163.  
  164.     return HSE_STATUS_SUCCESS;
  165. }
  166.  
  167.  
  168. BOOL WINAPI 
  169. GetExtensionVersion( 
  170.     OUT HSE_VERSION_INFO * pVer
  171.  )
  172. /*++
  173.  
  174. Purpose:
  175.  
  176.     This is required ISAPI Extension DLL entry point.
  177.  
  178. Arguments:
  179.  
  180.     pVer - poins to extension version info structure 
  181.  
  182. Returns:
  183.  
  184.     always returns TRUE
  185.  
  186. --*/
  187. {
  188.     pVer->dwExtensionVersion = 
  189.         MAKELONG( HSE_VERSION_MINOR, HSE_VERSION_MAJOR );
  190.  
  191.     lstrcpyn( 
  192.         pVer->lpszExtensionDesc, 
  193.         "DumpVars ISAPI Sample", 
  194.         HSE_MAX_EXT_DLL_NAME_LEN );
  195.  
  196.     return TRUE;
  197. }
  198.  
  199.  
  200. BOOL WINAPI
  201. TerminateExtension( 
  202.     IN DWORD dwFlags 
  203. )
  204. /*++
  205.  
  206. Routine Description:
  207.  
  208.     This function is called when the WWW service is shutdown
  209.  
  210. Arguments:
  211.  
  212.     dwFlags - HSE_TERM_ADVISORY_UNLOAD or HSE_TERM_MUST_UNLOAD
  213.  
  214. Return Value:
  215.  
  216.     TRUE if extension is ready to be unloaded,
  217.     FALSE otherwise
  218.  
  219. --*/
  220. {
  221.     return TRUE;
  222. }
  223.  
  224.