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

  1. // Redirect.c  -> ISAPI sample to demonstrate redirecting a request
  2. // Wade A. Hilmo, September 1996
  3.  
  4. #define _WIN32_WINNT 0x0400
  5.  
  6. #include <windows.h>
  7. #include <httpext.h>
  8.  
  9.  
  10. DWORD SendInstructionPage(EXTENSION_CONTROL_BLOCK *lpEcb);
  11.  
  12.  
  13. BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer)
  14. {
  15.     pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
  16.  
  17.     lstrcpyn(pVer->lpszExtensionDesc, "Redirect ISAPI Sample", HSE_MAX_EXT_DLL_NAME_LEN);
  18.  
  19.     return TRUE;
  20. }
  21.  
  22.  
  23. DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *lpEcb)
  24. {
  25.     DWORD dwBuffSize;
  26.  
  27.  
  28.     // If no query string is present, return the instruction page
  29.     
  30.     if (!strlen(lpEcb->lpszQueryString))
  31.         return SendInstructionPage(lpEcb);
  32.  
  33.  
  34.     // Check to see if the redirect URL is on another server. If it is, use
  35.     // HSE_REQ_SEND_URL_REDIRECT_RESP.  If it's on this local server, use
  36.     // HSE_REQ_SEND_URL to return the specified URL without using an HTTP 302
  37.     // status code.
  38.  
  39.     dwBuffSize = strlen(lpEcb->lpszQueryString);
  40.  
  41.  
  42.     if (!strnicmp(lpEcb->lpszQueryString, "http://", 7))
  43.         lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_URL_REDIRECT_RESP, lpEcb->lpszQueryString, &dwBuffSize, NULL);
  44.     else
  45.     {
  46.         // Check to make sure that query string begins with a '/'.
  47.     
  48.         if (*(lpEcb->lpszQueryString) != '/')
  49.             return SendInstructionPage(lpEcb);
  50.  
  51.         lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_URL, lpEcb->lpszQueryString, &dwBuffSize, NULL);
  52.     }
  53.  
  54.     return HSE_STATUS_SUCCESS;
  55. }
  56.  
  57. DWORD SendInstructionPage(EXTENSION_CONTROL_BLOCK *lpEcb)
  58. {
  59.     char szOutput[1024];
  60.     DWORD dwBuffSize;
  61.     
  62.  
  63.     // Send headers
  64.     
  65.     lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, NULL, NULL, (LPDWORD)"Content-type: text/html\r\n\r\n");
  66.  
  67.  
  68.     // Build the response page
  69.     
  70.     wsprintf(szOutput, "<h1>Redirect.dll</h1>\r\n<hr>\r\n");
  71.     strcat(szOutput, "Redirect.dll returns the resource specified on the query string.<br>\r\n<br>\r\n");
  72.     strcat(szOutput, "To specify a resource on the same server as Redirect.dll, use the following form:<br>\r\n<br>\r\n");
  73.     strcat(szOutput, "<code> http://server/scripts/Redirect.dll?/virtualdir/file.htm </code><br>\r\n<br>\r\n");
  74.     strcat(szOutput, "To specify a resource on another server, use the following form:<br>\r\n<br>\r\n");
  75.     strcat(szOutput, "<code> http://server/scripts/Redirect.dll?http://server/virtualdir/file.htm </code>");
  76.  
  77.  
  78.     // Return the page to the browser
  79.     
  80.     dwBuffSize = strlen(szOutput);
  81.     lpEcb->WriteClient(lpEcb->ConnID, szOutput, &dwBuffSize, 0);
  82.  
  83.  
  84.     return HSE_STATUS_SUCCESS;
  85. }
  86.