home *** CD-ROM | disk | FTP | other *** search
- #include <windows.h>
- #include <stdio.h>
- #include <string.h>
-
- #include "httpext.h"
- #include "srch.h"
-
- // constructor
- CSrch::CSrch(char* cData, EXTENSION_CONTROL_BLOCK* pEcb)
- {
- bUseCase = TRUE;
- bOverflow = FALSE;
-
- bHitSomething = FALSE;
- sCounter = 0;
- sHitCount = -1;
-
- strcpy(pszAlias, "");
-
- // swap '+' to ' ' (put the space char back in)
- // this gets substituted by WWW server
- char* pData = cData;
- while (*pData)
- {
- if ((*pData == 0x0D) || (*pData == 0x0A)) *pData = '\0';
- pData++;
- }
-
- pData = cData;
- while (*pData)
- {
- if (*pData == '+') *pData = ' ';
- pData++;
- }
-
- pExtContext = pEcb;
- DecodeHex(cData);
- strcpy(cBuffer, cData);
-
- wsprintf(cPrintBuffer,"Content-Type: text/html\r\n" "\r\n"
- "<head>"
- "<title>Search Results</title></head>\n\n\r"
- "<body><H1><p align=center>Full Text Search</H1><p>"
- "<p align=center>Search string - %s<p>"
- "<p><hr>"
- ,
- cData);
- {
- DWORD dwLen=lstrlen(cPrintBuffer);
-
- pEcb->ServerSupportFunction(pEcb->ConnID,
- HSE_REQ_SEND_RESPONSE_HEADER,
- "200 OK",
- &dwLen,
- (LPDWORD) cPrintBuffer );
- }
-
- cParsedData = _strupr(cData);
-
- }
-
- // destructor
- CSrch::~CSrch()
- {
- unsigned long ulCount;
- if (bOverflow)
- {
- char pTemp[] = "<p><b>The search criteria returned > 255 hits. Please narrow your search value down and retry.</b><p>";
-
- ulCount = sizeof(pTemp);
- pExtContext->WriteClient( pExtContext->ConnID,
- pTemp,
- &ulCount,
- 0 );
-
-
- // clean up the allocated memory
- short sCount;
- for (sCount = 0; sCount <= sHitCount; sCount++)
- VirtualFree((LPVOID)sHitStruct[sCount].cHREF,
- 0, MEM_DECOMMIT | MEM_RELEASE);
-
- return;
- }
-
- if (!bHitSomething)
- {
- char pTemp[] = "<p><b>No hits found.</b><p></body>";
- ulCount = sizeof(pTemp);
- pExtContext->WriteClient( pExtContext->ConnID,
- pTemp,
- &ulCount,
- 0 );
- }
- else
- {
- Sort();
- short sCount;
- for (sCount = 0; sCount <= sHitCount; sCount++)
- {
- ulCount = wsprintf(cPrintBuffer,
- "<a href=%s>%s</a> - %d hit(s)<p>\n\r",
- sHitStruct[sCount].cHREF,
- sHitStruct[sCount].cHREF,
- sHitStruct[sCount].sHits);
-
- VirtualFree((LPVOID)sHitStruct[sCount].cHREF,
- 0, MEM_DECOMMIT | MEM_RELEASE);
-
- pExtContext->WriteClient( pExtContext->ConnID,
- cPrintBuffer,
- &ulCount,
- 0 );
-
- }
- ulCount = wsprintf(cPrintBuffer,"<p><p>"
- "<p><b>%d hit(s) found.</b><p>"
- ,
- sCounter);
-
- ulCount++;
- pExtContext->WriteClient( pExtContext->ConnID,
- cPrintBuffer,
- &ulCount,
- 0 );
-
- }
- {
- DWORD dwLen=0;
-
- pExtContext->ServerSupportFunction( pExtContext,
- HSE_REQ_DONE_WITH_SESSION,
- NULL,
- &dwLen,
- 0 );
- }
-
- }
-
- // selection sort
- void CSrch::Sort()
- {
- short sCurrent,sCompare,sMax;
-
- for (sCurrent = 0; sCurrent <= sHitCount; sCurrent++)
- {
- sMax = sCurrent;
- for (sCompare = (sCurrent + 1); sCompare <= sHitCount; sCompare++)
- if (sHitStruct[sCompare].sHits > sHitStruct[sMax].sHits) sMax = sCompare;
-
- Swap(sCurrent, sMax);
- }
- }
-
- // swap locations of minimum value and current
- void CSrch::Swap(short sCurrent,short sMax)
- {
- sSwap.sHits = sHitStruct[sMax].sHits;
- sHitStruct[sMax].sHits = sHitStruct[sCurrent].sHits;
- sHitStruct[sCurrent].sHits = sSwap.sHits;
-
- sSwap.cHREF = sHitStruct[sMax].cHREF;
- sHitStruct[sMax].cHREF = sHitStruct[sCurrent].cHREF;
- sHitStruct[sCurrent].cHREF = sSwap.cHREF;
-
- }
-
- // version information
- extern "C" BOOL WINAPI GetExtensionVersion( HSE_VERSION_INFO *version)
- {
- version->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
-
- strcpy(version->lpszExtensionDesc, "Srchd.dll v1.0");
-
- return TRUE;
- }
-
- // DLL Entry point
- extern "C" DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK* pEcb)
- {
- // first parse out the search string
- char* cData;
- // char* cBuffer = (char*)VirtualAlloc(0, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
- char* cBuffer = (char*)malloc(pEcb->cbAvailable);
-
- wsprintf(cBuffer,"%s", pEcb->lpbData);
- cData = strstr(cBuffer,"=");
- cData++;
-
- CSrch* cHTTPIn = new CSrch(cData, pEcb);
-
- // get the web tree location dir from the DLL load location
- char pszCurDir[256];
- char pszSetDir[256];
-
- GetModuleFileName(GetModuleHandle("srchd.dll"), pszCurDir, 256);
-
- strncpy(pszSetDir, pszCurDir, strlen(pszCurDir) - strlen("srchd.dll"));
- *(pszSetDir + ((strlen(pszCurDir) - strlen("srchd.dll")) - 1)) = 0;
- SetCurrentDirectory(pszSetDir);
-
- cHTTPIn->cStartDir = pszSetDir;
-
- DWORD dwSize = 100;
-
- pEcb->GetServerVariable(pEcb->ConnID, "QUERY_STRING", cHTTPIn->pszAlias, &dwSize);
-
- cHTTPIn->ListDirectoryContents(pszSetDir, "*.htm", cHTTPIn->cParsedData);
-
- // clean up before we get run again.
- // VirtualFree((LPVOID)cBuffer, 0, MEM_DECOMMIT | MEM_RELEASE);
- free(cBuffer);
- delete cHTTPIn;
-
- return HSE_STATUS_SUCCESS;
- }
-
-
-
-