home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 9 / IOPROG_9.ISO / contrib / iis4 / iis4_07.cab / DumpVars.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-05  |  2.7 KB  |  91 lines

  1. // DumpVars.c  -> ISAPI sample to dump server variables
  2. // Wade A. Hilmo, August 1997
  3.  
  4.  
  5. #define _WIN32_WINNT 0x0400
  6.  
  7.  
  8. #include <windows.h>
  9. #include <httpext.h>
  10.  
  11.  
  12. BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer)
  13. {
  14.     pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
  15.  
  16.     lstrcpyn(pVer->lpszExtensionDesc, "DumpVars ISAPI Sample", HSE_MAX_EXT_DLL_NAME_LEN);
  17.  
  18.     return TRUE;
  19. }
  20.  
  21.  
  22. DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *lpEcb)
  23. {
  24.     DWORD dwBuffSize, dwNumVars, dwError, x;
  25.     char szServerVariable[][32] =
  26.         {"APPL_MD_PATH", "APPL_PHYSICAL_PATH", "AUTH_PASSWORD",
  27.         "AUTH_TYPE", "AUTH_USER", "CERT_COOKIE", "CERT_FLAGS",
  28.         "CERT_ISSUER", "CERT_KEYSIZE", "CERT_SECRETKEYSIZE",
  29.         "CERT_SERIALNUMBER", "CERT_SERVER_ISSUER",
  30.         "CERT_SERVER_SUBJECT", "CERT_SUBJECT", "CONTENT_LENGTH",
  31.         "CONTENT_TYPE", "HTTP_ACCEPT", "HTTPS", "HTTPS_KEYSIZE",
  32.         "HTTPS_SECRETKEYSIZE", "HTTPS_SERVER_ISSUER",
  33.         "HTTPS_SERVER_SUBJECT", "INSTANCE_ID", "INSTANCE_META_PATH",
  34.         "PATH_INFO", "PATH_TRANSLATED", "QUERY_STRING",
  35.         "REMOTE_ADDR", "REMOTE_HOST", "REMOTE_USER",
  36.         "REQUEST_METHOD", "SCRIPT_NAME", "SERVER_NAME",
  37.         "SERVER_PORT", "SERVER_PORT_SECURE", "SERVER_PROTOCOL",
  38.         "SERVER_SOFTWARE", "URL"};
  39.     char szOutput[2048], szValue[1024];
  40.  
  41.     dwNumVars = 38;    // There are 38 documented server variables
  42.  
  43.     // Send back headers to the client
  44.     lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, NULL, NULL, (LPDWORD)"Content-type: text/html\r\n\r\n");
  45.  
  46.     // Begin sending back HTML to the client
  47.     wsprintf(szOutput, "<HTML>\r\n<h1>Server Variable Dump</h1>\r\n<hr>\r\n");
  48.     dwBuffSize = strlen(szOutput);
  49.     lpEcb->WriteClient(lpEcb->ConnID, szOutput, &dwBuffSize, 0);
  50.  
  51.     // Get the server variables and send them
  52.     for (x = 0; x < dwNumVars; x++)
  53.     {
  54.         dwBuffSize = 1024;
  55.         if (!lpEcb->GetServerVariable(lpEcb->ConnID, szServerVariable[x], szValue, &dwBuffSize))
  56.         {
  57.             switch (dwError = GetLastError())
  58.             {
  59.                 case ERROR_INVALID_PARAMETER:
  60.                     wsprintf(szValue, "ERROR_INVALID_PARAMETER");
  61.                     break;
  62.  
  63.                 case ERROR_INVALID_INDEX:
  64.                     wsprintf(szValue, "ERROR_INVALID_INDEX");
  65.                     break;
  66.  
  67.                 case ERROR_INSUFFICIENT_BUFFER:
  68.                     wsprintf(szValue, "ERROR_INSUFFICIENT_BUFFER - %d bytes required.", dwBuffSize);
  69.                     break;
  70.  
  71.                 case ERROR_MORE_DATA:
  72.                     wsprintf(szValue, "ERROR_MORE_DATA");
  73.                     break;
  74.  
  75.                 case ERROR_NO_DATA:
  76.                     wsprintf(szValue, "ERROR_NO_DATA");
  77.                     break;
  78.  
  79.                 default:
  80.                     wsprintf(szValue, "*** Error %d occured retrieving server variable ***");
  81.             }
  82.         }
  83.  
  84.         wsprintf(szOutput, "%s: %s<br>\r\n", szServerVariable[x], szValue);
  85.         dwBuffSize = strlen(szOutput);
  86.         lpEcb->WriteClient(lpEcb->ConnID, szOutput, &dwBuffSize, 0);
  87.     }
  88.  
  89.     return HSE_STATUS_SUCCESS;
  90. }
  91.