home *** CD-ROM | disk | FTP | other *** search
- // Redirect.c -> ISAPI sample to demonstrate redirecting a request
- // Wade A. Hilmo, September 1996
-
- #define _WIN32_WINNT 0x0400
-
- #include <windows.h>
- #include <httpext.h>
-
-
- DWORD SendInstructionPage(EXTENSION_CONTROL_BLOCK *lpEcb);
-
-
- BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer)
- {
- pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
-
- lstrcpyn(pVer->lpszExtensionDesc, "Redirect ISAPI Sample", HSE_MAX_EXT_DLL_NAME_LEN);
-
- return TRUE;
- }
-
-
- DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *lpEcb)
- {
- DWORD dwBuffSize;
-
-
- // If no query string is present, return the instruction page
-
- if (!strlen(lpEcb->lpszQueryString))
- return SendInstructionPage(lpEcb);
-
-
- // Check to see if the redirect URL is on another server. If it is, use
- // HSE_REQ_SEND_URL_REDIRECT_RESP. If it's on this local server, use
- // HSE_REQ_SEND_URL to return the specified URL without using an HTTP 302
- // status code.
-
- dwBuffSize = strlen(lpEcb->lpszQueryString);
-
-
- if (!strnicmp(lpEcb->lpszQueryString, "http://", 7))
- lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_URL_REDIRECT_RESP, lpEcb->lpszQueryString, &dwBuffSize, NULL);
- else
- {
- // Check to make sure that query string begins with a '/'.
-
- if (*(lpEcb->lpszQueryString) != '/')
- return SendInstructionPage(lpEcb);
-
- lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_URL, lpEcb->lpszQueryString, &dwBuffSize, NULL);
- }
-
- return HSE_STATUS_SUCCESS;
- }
-
- DWORD SendInstructionPage(EXTENSION_CONTROL_BLOCK *lpEcb)
- {
- char szOutput[1024];
- DWORD dwBuffSize;
-
-
- // Send headers
-
- lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, NULL, NULL, (LPDWORD)"Content-type: text/html\r\n\r\n");
-
-
- // Build the response page
-
- wsprintf(szOutput, "<h1>Redirect.dll</h1>\r\n<hr>\r\n");
- strcat(szOutput, "Redirect.dll returns the resource specified on the query string.<br>\r\n<br>\r\n");
- strcat(szOutput, "To specify a resource on the same server as Redirect.dll, use the following form:<br>\r\n<br>\r\n");
- strcat(szOutput, "<code> http://server/scripts/Redirect.dll?/virtualdir/file.htm </code><br>\r\n<br>\r\n");
- strcat(szOutput, "To specify a resource on another server, use the following form:<br>\r\n<br>\r\n");
- strcat(szOutput, "<code> http://server/scripts/Redirect.dll?http://server/virtualdir/file.htm </code>");
-
-
- // Return the page to the browser
-
- dwBuffSize = strlen(szOutput);
- lpEcb->WriteClient(lpEcb->ConnID, szOutput, &dwBuffSize, 0);
-
-
- return HSE_STATUS_SUCCESS;
- }
-