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, LPBYTE lpbyBuf, DWORD dwLength);
-
- //
- // DllMain 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. DllMain is called for both loading
- // and unloading. See the Win32 SDK for more info on how
- // DLLs load and unload.
- //
- // An important part of building any DLL is deciding how the
- // entry point is going to function. You may not want an
- // entry point at all. Or, you might call your entry point
- // DllMain and add a link option
- //
- // -entry:DllMainCRTStartup$(DLLENTRY)
- //
- // The makefile symbol DLLENTRY is defined in ntwin32.mak,
- // which comes with Win32 SDK and Visual C++.
- //
- // You might choose to use Visual C++ 2.x or 4.x--go into the
- // project settings, link tab, output and specify a the entry
- // symbol DllMainCRTStartup$(DLLENTRY).
- //
- // By the way, $(DLLENTRY) currently resolves to @12, which is
- // the ordinal of _CRT_INIT, the C Runtime initializer.
- //
-
- BOOL WINAPI DllMain (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];
- DWORD dwWritten;
-
- // Get the keys sent by the client
- hKeyList = GetKeyList (pECB);
-
- // Send content type
- TCHAR str[] = TEXT("Content-type: text/html\r\n");
- dwWritten = sizeof (str);
- pECB->ServerSupportFunction (pECB->ConnID,
- HSE_REQ_SEND_RESPONSE_HEADER,
- NULL,
- &dwWritten,
- (LPDWORD) str);
-
-
- // Create a basic HTML page
- HtmlCreatePage (pECB, TEXT("FormDump.dll Reply"));
- HtmlHeading (pECB, 2, TEXT("Data Sent by Your Form"));
-
- // Report errors
- if (!hKeyList)
- {
- HtmlBold (pECB, TEXT("No keys sent or error decoding keys"));
- }
- else
- {
- HKEYLIST hKey;
-
- // Print a quick overview
- HtmlWriteTextLine (pECB, TEXT("The form you submitted data to just called"));
- HtmlWriteTextLine (pECB, TEXT("the Internet Information Server extension"));
- HtmlWriteTextLine (pECB, TEXT("FormDump.dll. Here is a listing of what was"));
- HtmlWriteTextLine (pECB, TEXT("received and what variables inside FormDump"));
- HtmlWriteTextLine (pECB, TEXT("have the data."));
- HtmlEndParagraph (pECB);
-
-
- // Loop through all of the keys
- hKey = hKeyList;
- while (hKey)
- {
- // Details about the key
- LPCTSTR lpszKeyName;
- DWORD dwLength;
- BOOL bHasCtrlChars;
- int nInstance;
- HKEYLIST hLastKey;
-
- // We get info, and hKey points to next key in list
- hLastKey = hKey; //keep this for later
- hKey = GetKeyInfo (hKey, &lpszKeyName, &dwLength,
- &bHasCtrlChars, &nInstance);
-
-
- // Build web page
- HtmlBold (pECB, TEXT("Form Key Name (lpszKeyName): "));
- HtmlWriteText (pECB, lpszKeyName);
- HtmlLineBreak (pECB);
-
- HtmlBold (pECB, TEXT("Length of Key Data (dwLength): "));
- wsprintf (szMsg, TEXT("%u"), dwLength);
- HtmlWriteText (pECB, szMsg);
- HtmlLineBreak (pECB);
-
- HtmlBold (pECB, TEXT("Data Has Control Characters (bHasCtrlChars): "));
- wsprintf (szMsg, TEXT("%u"), bHasCtrlChars);
- HtmlWriteText (pECB, szMsg);
- HtmlLineBreak (pECB);
-
- HtmlBold (pECB, TEXT("Instance of Form Key (nInstance): "));
- wsprintf (szMsg, TEXT("%u"), nInstance);
- HtmlWriteText (pECB, szMsg);
-
- if (dwLength)
- {
- HtmlLineBreak (pECB);
- HtmlBold (pECB, TEXT("Data Sent for Key:"));
- HtmlLineBreak (pECB);
-
- HexDumper (pECB, GetKeyBuffer (hLastKey), dwLength);
- }
-
- HtmlEndParagraph (pECB);
- }
-
- // Clean up
- FreeKeyList (hKeyList);
- }
-
- HtmlEndPage (pECB);
-
- return HSE_STATUS_SUCCESS;
- }
-
- //
- // Put the inbound data in a hex dump format
- //
-
- void HexDumper (EXTENSION_CONTROL_BLOCK *pECB, LPBYTE lpbyBuf, DWORD dwLength)
- {
- DWORD dwSize;
- TCHAR szLine[80];
- TCHAR szHex[3];
- DWORD i;
- DWORD dwPos = 0;
-
- HtmlBeginPreformattedText (pECB);
-
- while (dwLength)
- {
- // Take min of 16 or dwLength
- dwSize = min (16, dwLength);
-
- // Build text line
- wsprintf (szLine, TEXT(" %04X "), dwPos);
-
- for (i = 0 ; i < dwSize ; i++)
- {
- wsprintf (szHex, TEXT("%02X"), lpbyBuf[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 < dwSize ; i++)
- {
- if (isprint (lpbyBuf[i]))
- {
- wsprintf (szHex, TEXT("%c"), lpbyBuf[i]);
- lstrcat (szLine, szHex);
- }
- else
- {
- lstrcat (szLine, TEXT("."));
- }
- }
-
- // Write data to web page
- HtmlWriteTextLine (pECB, szLine);
-
- // Advance positions
- dwLength -= dwSize;
- dwPos += dwSize;
- lpbyBuf += dwSize;
- }
-
- HtmlEndPreformattedText (pECB);
- }