home *** CD-ROM | disk | FTP | other *** search
- #define WIN32_LEAN_AND_MEAN // the bare essential Win32 API
- #include <windows.h>
- #include <ctype.h> // for isprint()
- #include <httpext.h>
-
- #include "keys.h"
- #include "html.h"
-
- // prototype
- void HexDumper (EXTENSION_CONTROL_BLOCK *pECB,
- HANDLE hContent, DWORD dwOffset, DWORD dwLength);
-
- //
- // DllEntryPoint allows us to initialize our state variables.
- // You might keep state information, as the DLL often remains
- // loaded for several client requests. The server may choose
- // to unload this DLL, and you should save your state to disk,
- // and reload it here. DllEntryPoint is called for both
- // loading and unloading. See the Win32 SDK for more info
- // on how DLLs load and unload.
- //
-
- BOOL WINAPI DllEntryPoint (HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpv)
- {
- // Nothing to do here
- return (TRUE);
- }
-
-
- //
- // BOOL WINAPI GetExtensionVersion (HSE_VERSION_INFO *pVersionInfo)
- //
- // Return the version this server is built for. See <httpext.h> for
- // a prototype. This function is required by the spec.
- //
-
- BOOL WINAPI GetExtensionVersion (HSE_VERSION_INFO *pVersionInfo)
- {
- // set version to httpext.h version constants
- pVersionInfo->dwExtensionVersion = MAKELONG (HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
-
- lstrcpyn ((LPTSTR) pVersionInfo->lpszExtensionDesc,
- TEXT("FORMDUMP - A Form Decoder and Dumper"),
- HSE_MAX_EXT_DLL_NAME_LEN);
-
- return TRUE;
- } // GetExtensionVersion()
-
-
- //
- // Our entry point:
- //
- // BOOL WINAPI HttpExtensionProc (EXTENSION_CONTROL_BLOCK *pECB)
- //
- // This function pulls in all inbound data. A reply page is built
- // so the user can see how forms appear in our key list.
- // This function is also required by the spec.
- //
-
- DWORD WINAPI HttpExtensionProc (EXTENSION_CONTROL_BLOCK *pECB)
- {
- HKEYLIST hKeyList;
- TCHAR szMsg[128];
- HANDLE hContent;
-
- // Get the keys sent by the client
- hKeyList = GetKeyList (pECB);
-
- // Create a basic HTML page
- HtmlCreatePage (pECB, TEXT("Internet Server API Debugging Tool"));
- HtmlHeading (pECB, 2, TEXT("Data Sent by Your Form"));
-
- // Open the content file
- if (hKeyList)
- {
- hContent = CreateFile (GetContentPath (hKeyList),
- GENERIC_READ,
- 0, // No sharing mode
- NULL, // Default security attribs
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, // In this sample, we sequentially access this too
- NULL // No template file
- );
-
- // Report errors as necessary
- if (hContent == INVALID_HANDLE_VALUE)
- {
- HtmlBold (pECB, TEXT("Can't open content file"));
- FreeKeyList (hKeyList);
- hKeyList = NULL;
- }
- }
-
- // Report errors
- if (!hKeyList)
- {
- HtmlBold (pECB, TEXT("No keys sent or error decoding keys"));
- CloseHandle (hContent);
- }
- else
- {
- HKEYLIST hKey;
-
- // Loop through all of the keys
- hKey = hKeyList;
- while (hKey)
- {
- // Details about the key
- LPCTSTR lpszKeyName;
- DWORD dwOffset;
- DWORD dwLength;
- BOOL bHasCtrlChars;
- int nInstance;
-
- // We get info, and hKey points to next key in list
- hKey = GetKeyInfo (hKey, &lpszKeyName, &dwOffset, &dwLength,
- &bHasCtrlChars, &nInstance);
-
-
- // Build web page
- HtmlBold (pECB, TEXT("lpszKeyName: "));
- HtmlWriteText (pECB, lpszKeyName);
- HtmlLineBreak (pECB);
-
- HtmlBold (pECB, TEXT("dwOffset: "));
- wsprintf (szMsg, TEXT("%u"), dwOffset);
- HtmlWriteText (pECB, szMsg);
- HtmlLineBreak (pECB);
-
- HtmlBold (pECB, TEXT("dwLength: "));
- wsprintf (szMsg, TEXT("%u"), dwLength);
- HtmlWriteText (pECB, szMsg);
- HtmlLineBreak (pECB);
-
- HtmlBold (pECB, TEXT("bHasCtrlChars: "));
- wsprintf (szMsg, TEXT("%u"), bHasCtrlChars);
- HtmlWriteText (pECB, szMsg);
- HtmlLineBreak (pECB);
-
- HtmlBold (pECB, TEXT("nInstance: "));
- wsprintf (szMsg, TEXT("%u"), nInstance);
- HtmlWriteText (pECB, szMsg);
-
- if (dwLength)
- {
- HtmlLineBreak (pECB);
- HtmlBold (pECB, TEXT("Data:"));
- HtmlLineBreak (pECB);
-
- HexDumper (pECB, hContent, dwOffset, dwLength);
- }
-
- HtmlEndParagraph (pECB);
- }
-
- // Finally, write the content path
- HtmlBold (pECB, TEXT("Content Path: "));
- HtmlWriteText (pECB, GetContentPath (hKeyList));
- HtmlEndParagraph (pECB);
-
- // Clean up
- CloseHandle (hContent);
- FreeKeyList (hKeyList);
- }
-
- HtmlEndPage (pECB);
-
- return HSE_STATUS_SUCCESS;
- }
-
- //
- // Put the inbound data in a hex dump format
- //
-
- void HexDumper (EXTENSION_CONTROL_BLOCK *pECB,
- HANDLE hContent, DWORD dwOffset, DWORD dwLength)
- {
- BYTE byLineBuf[16];
- DWORD dwRead;
- DWORD dwSize;
- TCHAR szLine[256];
- TCHAR szHex[3];
- DWORD i;
- DWORD dwPos = 0;
-
- HtmlBeginPreformattedText (pECB);
-
- //
- // We move to the offset, but this sample sequentially
- // accesses the keys anyway. Because the key data is
- // saved in the same order as the key list, we could
- // omit this as long as we only read dwLength bytes.
- // It is necessary for random-access though.
- //
- SetFilePointer (hContent, dwOffset, NULL, FILE_BEGIN);
-
- while (dwLength)
- {
- // Take min of 16 or dwLength
- dwSize = min (16, dwLength);
-
- // Get data from content file
- if (ReadFile (hContent, byLineBuf, dwSize, &dwRead, NULL))
- {
- // Build text line
- wsprintf (szLine, TEXT(" %04X "), dwPos);
-
- for (i = 0 ; i < dwRead ; i++)
- {
- wsprintf (szHex, TEXT("%02X"), byLineBuf[i]);
- lstrcat (szLine, szHex);
- lstrcat (szLine, TEXT(" "));
- }
-
- // Add spaces for short lines
- while (i < 16)
- {
- lstrcat (szLine, TEXT(" "));
- i++;
- }
-
- // Add ASCII chars
- for (i = 0 ; i < dwRead ; i++)
- {
- if (isprint (byLineBuf[i]))
- {
- wsprintf (szHex, TEXT("%c"), byLineBuf[i]);
- lstrcat (szLine, szHex);
- }
- else
- {
- lstrcat (szLine, TEXT("."));
- }
- }
-
- // Write data to web page
- HtmlWriteTextLine (pECB, szLine);
-
- dwLength -= dwRead;
- dwPos += dwRead;
- }
- else
- {
- // Write error to web
- HtmlWriteTextLine (pECB, TEXT("Error reading content file"));
- break;
- }
- }
-
- HtmlEndPreformattedText (pECB);
- }