Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1004 lines
29 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1998.
  5. //
  6. // File: linkhits.hxx
  7. //
  8. // Classes: CInternalQuery - class used to convert a textual query to
  9. // a CDbRestriction
  10. // CGetEnvVars - class used to obtain and store CGI environment
  11. // variables
  12. // CQueryStringParser - class used to parse the QUERY_STRING
  13. // CGI variable
  14. // CURLUnescaper - class to unescape URL fragments
  15. // CSortQueryHits - class used to sort the positions making up
  16. // the hits returned by a query into the order
  17. // in which these positions appear in the document
  18. // CLinkQueryHits - class used to generate an HTML page allowing
  19. // the user to navigate among the words making up
  20. // the hits using "<<" (prev) and ">>" (next)
  21. // tags.
  22. //
  23. // Contents: class declarations for the hit-highliting feature in TRIPOLI
  24. //
  25. //
  26. // History: 05-15-96 t-matts Created
  27. //
  28. //--------------------------------------------------------------------------
  29. #pragma once
  30. #include <dbcmdtre.hxx>
  31. #include <restrict.hxx>
  32. #include <vquery.hxx>
  33. #include <plist.hxx>
  34. #include <strrest.hxx>
  35. #include <string.hxx>
  36. #include <cgiesc.hxx>
  37. #include <scanner.hxx>
  38. #include "cdoc.hxx"
  39. #include "whtmplat.hxx"
  40. const int MAX_VARIABLE_SIZE = 4096;
  41. const int MAX_HILITE_TYPE = 32;
  42. const int _MAX_BUFFER = 4096;
  43. class CLinkQueryHits;
  44. class CCollectVar;
  45. class CGetEnvVars;
  46. class PHttpOutput;
  47. class CURLUnescaper;
  48. class CSmartByteArray;
  49. LCID GetLCID( CWebServer & webServer );
  50. //
  51. // names of CGI variables and QUERY_STRING parameters globally defined to avoid
  52. // hard-coded checks when parsing
  53. //
  54. extern const WCHAR CommandLineVarName[];
  55. extern const WCHAR RestrictionVarName[];
  56. extern const WCHAR IDQFilenameVarName[];
  57. extern const WCHAR HiliteTypeVarName[];
  58. extern const WCHAR ColorVarName[];
  59. extern const WCHAR BoldVarName[];
  60. extern const WCHAR ItalicVarName[];
  61. extern const WCHAR ParaTag[];
  62. extern const WCHAR HRule[];
  63. extern const WCHAR Red24BitMask[];
  64. extern const WCHAR Blue24BitMask[];
  65. extern const WCHAR Green24BitMask[];
  66. extern const WCHAR Black24BitMask[];
  67. extern const WCHAR Yellow24BitMask[];
  68. //+---------------------------------------------------------------------------
  69. //
  70. // Class: CLanguageInfo
  71. //
  72. // Purpose: Class to track client and output code page.
  73. //
  74. // History: 9-12-96 srikants Created
  75. //
  76. // Notes: For converting the URL, we use locales in the following order
  77. // of precedence:
  78. //
  79. // 1. HTTP_ACCEPT_LANGUAGE
  80. // 2. Server/System Default
  81. //
  82. // For output of webhits results and for interpreting the
  83. // CiRestriction, we use the following precedence.
  84. //
  85. // 1. CiLocale
  86. // 2. HTTP_ACCEPT_LANGUAGE
  87. // 3. Server/System Default
  88. //
  89. //----------------------------------------------------------------------------
  90. class CLanguageInfo
  91. {
  92. public:
  93. enum { eAnsiCodePage = 1252 };
  94. CLanguageInfo() : _urlCodePage(eAnsiCodePage),
  95. _outputCodePage(0)
  96. {
  97. _urlLCID = GetSystemDefaultLCID();
  98. _queryLCID = _urlLCID;
  99. }
  100. void SetUrlLangInfo( UINT codePage, LCID lcid )
  101. {
  102. _urlCodePage = codePage;
  103. _urlLCID = lcid;
  104. }
  105. LCID GetUrlLCID() const { return _urlLCID; }
  106. ULONG GetUrlCodePage() const { return _urlCodePage; }
  107. void SetRestrictionLangInfo( UINT codePage, LCID lcid )
  108. {
  109. if ( codePage != _outputCodePage )
  110. {
  111. _outputCodePage = SetCodePageForCRunTimes( codePage );
  112. }
  113. _queryLCID = lcid;
  114. }
  115. void SetRestrictionLocale(LCID lcid)
  116. {
  117. _queryLCID = lcid;
  118. }
  119. void SetRestrictionCodepage(UINT codepage)
  120. {
  121. _urlCodePage = codepage;
  122. }
  123. ULONG GetOutputCodePage() const { return _outputCodePage; }
  124. LCID GetQueryLCID() const { return _queryLCID; }
  125. private:
  126. UINT SetCodePageForCRunTimes( UINT codePage );
  127. //
  128. // These variables are set depending upon the HTTP_ACCEPT_LANGUAGE.
  129. // If there is no HTTP_ACCEPT_LANGUAGE, System default is used.
  130. //
  131. UINT _urlCodePage; // code page of the browser (HTTP_ACCEPT_LANGUAGE)
  132. LCID _urlLCID; // LCID of the browser (HTTP_ACCEPT_LANGUAGE)
  133. //
  134. // These are set depending upon CiLocale, HTTP_ACCEPT_LANGUAGE,
  135. // System Default, in that order.
  136. //
  137. LCID _queryLCID; // LCID in which the query must be interpreted
  138. UINT _outputCodePage; // code page of the document and output
  139. };
  140. //+-------------------------------------------------------------------------
  141. //
  142. // Class: CInternalQueryx
  143. //
  144. // Purpose: Convert a textual query to a DbRestriction
  145. //
  146. // History: 05-14-1996 t-matts Created
  147. //
  148. //--------------------------------------------------------------------------
  149. class CInternalQuery
  150. {
  151. public:
  152. CInternalQuery(CGetEnvVars& rGetEnvVars, CEmptyPropertyList& rPList,
  153. LCID lcid );
  154. ~CInternalQuery();
  155. CDbRestriction& GetDbRestrictionRef()
  156. {
  157. Win4Assert(0 != _pDbRestriction);
  158. return *_pDbRestriction;
  159. }
  160. void CreateISearch( WCHAR const * pwszPath );
  161. ISearchQueryHits & GetISearchRef()
  162. {
  163. Win4Assert( 0 != _pISearch );
  164. return *_pISearch;
  165. }
  166. private:
  167. CDbRestriction* _pDbRestriction;
  168. ISearchQueryHits * _pISearch;
  169. };
  170. inline CInternalQuery::~CInternalQuery()
  171. {
  172. delete _pDbRestriction;
  173. if ( 0 != _pISearch )
  174. _pISearch->Release();
  175. }
  176. //+-------------------------------------------------------------------------
  177. //
  178. // Class: CSmartByteArray
  179. //
  180. // Purpose: Dynamically re-sizing text container, with a CopyTo operator
  181. // that allows fast copies and automatically appends a '\0'.
  182. // Used to extract chunks of text from memory
  183. //
  184. // History: 07-11-1996 t-matts Created
  185. //
  186. //--------------------------------------------------------------------------
  187. class CSmartByteArray
  188. {
  189. public:
  190. //
  191. // default size of buffer until something larger is placed in it through
  192. // CopyTo
  193. //
  194. enum DefSize{ DEFAULT_BUFFER_SIZE = 1024 };
  195. CSmartByteArray();
  196. void CopyTo(char* pszText, ULONG cbToCopy);
  197. XArray<CHAR>& GetXPtr() { return _xszBuffer; }
  198. char * GetPointer() { return _xszBuffer.GetPointer(); }
  199. private:
  200. XArray<CHAR> _xszBuffer;
  201. };
  202. //+-------------------------------------------------------------------------
  203. //
  204. // Class: CCollectVar
  205. //
  206. // Purpose: Used to retrieve environment variables as well
  207. // temporarily store them.
  208. //
  209. // History: 07-02-1996 t-matts Created
  210. //
  211. //--------------------------------------------------------------------------
  212. class CCollectVar
  213. {
  214. public:
  215. enum DefSize{ DEFAULT_BUFF_SIZE = 1024 };
  216. CCollectVar( CURLUnescaper& rUnescaper, CWebServer & webServer );
  217. //
  218. // returns ref. to smart pointer to variable value
  219. //
  220. const WCHAR* GetVarValue() { return _xwcsBuffer.GetPointer(); }
  221. int GetVarSize() { return _cwcVarSize; }
  222. BOOL GetEnvVar(CHAR const * pszVariableName);
  223. const char * GetMultiByteStr() const { return _xszBuffer.GetPointer(); }
  224. int GetMultiByteStrLen() const { return _cbVarSize; }
  225. void UnescapeAndConvertToUnicode();
  226. private:
  227. CURLUnescaper& _rUnescaper;
  228. CWebServer & _webServer;
  229. XArray<WCHAR> _xwcsBuffer; // Buffer to store the unicode str
  230. int _cwcVarSize; // Length of the un-escaped unicode
  231. // string in WCHARS excluding
  232. // terminating NULL.
  233. XArray<CHAR> _xszBuffer; // Buffer to store the ansi string
  234. int _cbVarSize; // Length of string excluding the
  235. };
  236. //+-------------------------------------------------------------------------
  237. //
  238. // Class: CQueryStringParser
  239. //
  240. // Purpose: Used to parse the QUERY_STRING CGI variable
  241. //
  242. // History: 07-08-1996 t-matts Created
  243. //
  244. //--------------------------------------------------------------------------
  245. class CQueryStringParser
  246. {
  247. public:
  248. CQueryStringParser( char * pszQUERY_STRING,
  249. CURLUnescaper& rUnescaper);
  250. void GetVarName(XPtrST<WCHAR>& rDestVarName)
  251. { rDestVarName.Set(_xwszVarName.Acquire()); }
  252. void GetVarValue(XPtrST<WCHAR>& rDestVarValue)
  253. { rDestVarValue.Set(_xwszVarValue.Acquire()); }
  254. BOOL NextVar();
  255. BOOL IsNull() { return _isNull; }
  256. private:
  257. char * EatChar(char *psz);
  258. char * ValidateArgument(char * psz);
  259. char * EatVariableName(char * psz);
  260. char * FindVarEnd(char * psz);
  261. char * _pszQS;
  262. char * _pszQSEnd;
  263. char * _pBeg;
  264. char * _pEnd;
  265. BOOL _isNull;
  266. XArray<WCHAR> _xwszVarName;
  267. XArray<WCHAR> _xwszVarValue;
  268. CURLUnescaper& _rUnescaper;
  269. CSmartByteArray _smartBuffer;
  270. };
  271. //+-------------------------------------------------------------------------
  272. //
  273. // Class: CURLUnescaper
  274. //
  275. // Purpose: Unescape an URL fragment
  276. //
  277. // History: 07-09-1996 t-matts Created
  278. //
  279. //--------------------------------------------------------------------------
  280. class CURLUnescaper
  281. {
  282. public:
  283. CURLUnescaper( UINT codePage );
  284. ULONG UnescapeAndConvertToUnicode( char const * pszMbStr,
  285. ULONG cc,
  286. XArray<WCHAR> & xwcsBuffer );
  287. private:
  288. UINT _codePage;
  289. };
  290. //+-------------------------------------------------------------------------
  291. //
  292. // Class: CGetEnvVars
  293. //
  294. // Purpose: Get CGI environment variables necessary to perform hit
  295. // highliting
  296. //
  297. // History: 05-20-1996 t-matts Created
  298. //
  299. //--------------------------------------------------------------------------
  300. class CGetEnvVars
  301. {
  302. public:
  303. enum { eMaxUserReplParams = 10 };
  304. enum REQUEST_METHOD { GET, POST };
  305. enum HiliteType { SUMMARY=0, FULL, PRETTY };
  306. CGetEnvVars( CWebServer & webServer,
  307. CLanguageInfo & langInfo,
  308. CCollectVar& rCollectVar,
  309. CURLUnescaper& rUnescaper );
  310. const WCHAR* GetRestriction() const
  311. { return _xwcsRestriction.GetPointer(); }
  312. const char * GetQueryString() const
  313. { return _xszQueryString.GetPointer(); }
  314. const WCHAR* GetQueryFileVPath() const
  315. { return _xwcsQueryFileVPath.GetPointer(); }
  316. const WCHAR* GetQueryFilePPath() const
  317. { return _xwcsQueryFilePPath.GetPointer(); }
  318. void AcceptQueryFilePPath( WCHAR * pwcsPPath, DWORD dwFlags )
  319. {
  320. _xwcsQueryFilePPath.Set( pwcsPPath );
  321. _dwQueryFileFlags = dwFlags;
  322. }
  323. void AcceptWebHitsFilePPath( WCHAR * pwcsPPath, DWORD dwFlags )
  324. {
  325. _xwcsWebHitsFilePPath.Set( pwcsPPath );
  326. _dwWebHitsFileFlags = dwFlags;
  327. }
  328. ULONG GetDialect() const { return _dialect; }
  329. const WCHAR* GetWebHitsFileVPath() const
  330. { return _xwcsWebHitsFileVPath.GetPointer(); }
  331. const WCHAR* GetWebHitsFilePPath() const
  332. { return _xwcsWebHitsFilePPath.GetPointer(); }
  333. const WCHAR* GetTemplateFileVPath() const
  334. { return _xwcsTemplateFileVPath.GetPointer(); }
  335. const WCHAR* GetTemplateFilePPath() const
  336. { return _xwcsTemplateFilePPath.GetPointer(); }
  337. const WCHAR* GetBeginHiliteTag() const
  338. { return _xwcsBeginHiliteTag.GetPointer(); }
  339. const WCHAR* GetEndHiliteTag() const
  340. { return _xwcsEndHiliteTag.GetPointer(); }
  341. const WCHAR * GetUserParam( ULONG n ) const
  342. {
  343. Win4Assert( n > 0 && n <= eMaxUserReplParams );
  344. return _aUserParams[n-1];
  345. }
  346. void AcceptTemplateFilePPath( WCHAR * pwcsPPath, DWORD dwFlags )
  347. {
  348. _xwcsTemplateFilePPath.Set( pwcsPPath );
  349. _dwTemplateFileFlags = dwFlags;
  350. }
  351. DWORD GetTemplateFileFlags() const { return _dwTemplateFileFlags; }
  352. DWORD GetQueryFileFlags() const { return _dwQueryFileFlags; }
  353. DWORD GetWebHitsFileFlags() const { return _dwWebHitsFileFlags; }
  354. const WCHAR* GetLocale() const { return _locale.GetPointer(); }
  355. const WCHAR* GetCodepage() const { return _codepage.GetPointer(); }
  356. HiliteType GetHiliteType() { return _hiliteType; }
  357. LCID GetLCID() { return _lcid; }
  358. XPtrST<WCHAR>& GetColour() { return _xwc24BitColourMask; }
  359. BOOL GetBold() { return _isBold; }
  360. BOOL GetItalic() { return _isItalic; }
  361. BOOL IsFixedFont() const { return _isFixedFont; }
  362. UINT GetFixedFontLineLen() const
  363. {
  364. return _ccFixedFontLine;
  365. }
  366. private:
  367. void RetrieveFilename();
  368. void RetrieveVPath();
  369. void RetrieveQueryString();
  370. int RetrieveCONTENT_LENGTH();
  371. void RetrieveREQUEST_METHOD();
  372. void RetrieveTextStream(ULONG cbContentLength);
  373. //
  374. // method used to parse parameters in QUERY_STRING
  375. //
  376. void ParseQUERY_STRING();
  377. void DetermineCodePage();
  378. void VerifyQSVariablesComplete();
  379. void SetVar(XPtrST<WCHAR>& xwszVarName,
  380. XPtrST<WCHAR>& xwszVarValue);
  381. ULONG IsUserParam( WCHAR const * pwcsParam );
  382. //
  383. // method through which the hit-highlighter was invoked
  384. //
  385. REQUEST_METHOD _method;
  386. CLanguageInfo & _langInfo;
  387. CWebServer & _webServer;
  388. XArray<WCHAR> _locale;
  389. XArray<WCHAR> _codepage;
  390. ULONG _dialect;
  391. XPtrST<WCHAR> _xwcsRestriction;
  392. XPtrST<WCHAR> _xwcsWebHitsFileVPath;
  393. XPtrST<WCHAR> _xwcsWebHitsFilePPath;
  394. DWORD _dwWebHitsFileFlags;
  395. XPtrST<WCHAR> _xwcsQueryFileVPath;
  396. XPtrST<WCHAR> _xwcsQueryFilePPath;
  397. DWORD _dwQueryFileFlags;
  398. XPtrST<WCHAR> _xwcsTemplateFileVPath;
  399. XPtrST<WCHAR> _xwcsTemplateFilePPath;
  400. DWORD _dwTemplateFileFlags;
  401. XPtrST<WCHAR> _xwcsBeginHiliteTag;
  402. XPtrST<WCHAR> _xwcsEndHiliteTag;
  403. XPtrST<WCHAR> _xwc24BitColourMask;
  404. XArray<char> _xszQueryString;
  405. CDynArray<WCHAR> _aUserParams;
  406. HiliteType _hiliteType;
  407. LCID _lcid;
  408. BOOL _isBold;
  409. BOOL _isItalic;
  410. BOOL _isFixedFont;
  411. UINT _ccFixedFontLine;
  412. //
  413. // ref to variable-retrieving object used to actually get the vars
  414. //
  415. CCollectVar& _rCollectVar;
  416. CURLUnescaper& _rUnescaper;
  417. };
  418. class CWebhitsTemplate;
  419. //+-------------------------------------------------------------------------
  420. //
  421. // Class: PHttpOutput
  422. //
  423. // Purpose: An abstracted interface for outputting text
  424. //
  425. // History: 06-17-1996 t-matts Created
  426. //
  427. //--------------------------------------------------------------------------
  428. class PHttpOutput
  429. {
  430. public:
  431. PHttpOutput( CWebServer & webServer,
  432. CLanguageInfo & langInfo );
  433. ~PHttpOutput() { Flush(); }
  434. void Flush();
  435. void Init( CGetEnvVars* rGetEnvVars,
  436. CWebhitsTemplate * pTemplate = 0 );
  437. virtual void OutputHttp( const WCHAR* pwcsBuffer, ULONG cLength,
  438. BOOL fRawText = FALSE );
  439. void OutputHttpText( WCHAR * pwcsBuffer, ULONG cLength );
  440. virtual void OutputHTMLHeader();
  441. virtual void OutputHilite(const WCHAR* pwszString, ULONG cwcBuffLength);
  442. void OutputHTMLFooter();
  443. void OutputLeftTag(int tagParam);
  444. void OutputRightTag(int tagParam);
  445. void OutputParaTag() { OutputHttp(ParaTag,wcslen(ParaTag)); }
  446. void OutputHRULE() { OutputHttp(HRule,wcslen(HRule)); }
  447. void OutputEllipsis();
  448. void OutputErrorHeader();
  449. void OutputErrorMessage( WCHAR * pwcsBuffer, ULONG ccBuffer );
  450. void TagPosition(int tagParam);
  451. BOOL HasPrintedHeader() { return _hasPrintedHeader; }
  452. void OutputPreformattedTag();
  453. BOOL IsTemplateFilePresent() const { return 0 != _pTemplate; }
  454. protected:
  455. void WriteToStdout( WCHAR const * pwszBuffer, ULONG cwc );
  456. void WriteNewline();
  457. void WriteBreakTag();
  458. void OutputPreFormatRawText( WCHAR const * pwszBuffer, ULONG cwc );
  459. enum { MAX_OUTPUT_BUF = 1024 };
  460. static BOOL IsNewLine( WCHAR wc )
  461. {
  462. return wc == L'\n'|| wc == L'\r' ||
  463. wc == UNICODE_PARAGRAPH_SEPARATOR;
  464. }
  465. //
  466. // flag to remember whether the header has been printed
  467. //
  468. CWebServer & _webServer;
  469. CLanguageInfo & _langInfo;
  470. BOOL _hasPrintedHeader;
  471. // temporary output buffer and a count of the number of characters in it
  472. WCHAR _wcOutputBuffer[MAX_OUTPUT_BUF];
  473. int _cwcOutputBuffer;
  474. // stores the 24 bit colour mask used to tag the hilighting font
  475. XPtrST<WCHAR> _xwc24BitColourMask;
  476. BOOL _isItalic;
  477. BOOL _isBold;
  478. BOOL _newLine;
  479. BOOL _isInPreformat; // tells if in the pre-formatted mode
  480. unsigned _ccCurrLine; // Number of chars in the current line
  481. unsigned _ccMaxLine; // Maximum # of chars per line
  482. //
  483. // the output object requires knowledge of certain environment variables
  484. //
  485. CGetEnvVars* _pGetEnvVars;
  486. CVirtualString _escapedStr;
  487. XArray<BYTE> _mbStr; // Place to store multi-byte string
  488. CVirtualString _vsResult;
  489. CWebhitsTemplate * _pTemplate; // Template file
  490. BOOL _fUseHiliteTags;
  491. ULONG _cwcBeginHiliteTag;
  492. ULONG _cwcEndHiliteTag;
  493. };
  494. //+-------------------------------------------------------------------------
  495. //
  496. // Class: PHttpFullOutput
  497. //
  498. // Purpose: PHttpOutput with an additional method to output header info
  499. // specific to the full hit-highliting
  500. //
  501. // History: 06-17-1996 t-matts Created
  502. //
  503. //--------------------------------------------------------------------------
  504. class PHttpFullOutput:public PHttpOutput
  505. {
  506. public:
  507. void OutputFullHeader();
  508. PHttpFullOutput( CWebServer & webServer,
  509. CLanguageInfo & langInfo ) :
  510. PHttpOutput( webServer, langInfo ) {}
  511. };
  512. //+-------------------------------------------------------------------------
  513. //
  514. // Class: CExtractedHit
  515. //
  516. // Purpose: Do a summary-like highliting of a single hit. I.e. extract a
  517. // single hit.
  518. //
  519. // History: 06-16-1996 t-matts Created
  520. //
  521. //--------------------------------------------------------------------------
  522. class CExtractedHit
  523. {
  524. public:
  525. CExtractedHit(CDocument& rDocument, Hit& rHit, PHttpOutput& rOutput,
  526. int cwcMargin, int cwcSeparation, int cwcDelim);
  527. void ExtractHit();
  528. void PrintPreamble(const Position& rStartPosition, int cwcDist);
  529. void PrintPostamble(const Position& rEndPosition, int cwcDist);
  530. void PrintBtwPositions( const Position& rStartPosition,
  531. const Position& rEndPosition );
  532. void DisplayPosition(const Position& rPos);
  533. private:
  534. int EatNullPositions();
  535. ULONG ComputeDistance (const Position& rStartPos,
  536. const Position& rEndPos);
  537. void SortHit();
  538. CDocument& _rDocument;
  539. Hit& _rHit;
  540. PHttpOutput& _rOutput;
  541. //
  542. // buffer used for output and a count of the number of characters in it
  543. //
  544. int _cwcOutputBuffer;
  545. // formatting parameters
  546. //
  547. // _cwcMargin - the maximum number of characters that will be printed
  548. // before and after each hit
  549. //
  550. int _cwcMargin;
  551. //
  552. // _cwcDelim - the max number of characters that will follow/precede
  553. // a position if the space between two consecutive positions in the
  554. // same hit is truncated
  555. //
  556. int _cwcDelim;
  557. //
  558. // _cwcSeparation - the max number of characters that may separate
  559. // two consecutive positions in the same hit before truncattion takes
  560. // place
  561. //
  562. int _cwcSeparation;
  563. };
  564. //+-------------------------------------------------------------------------
  565. //
  566. // Member: CExtractedHit::EatNullPositions, private inline
  567. //
  568. // Synopsis: Assuming that the positions in _rHit are sorted, returns the
  569. // index of the first non-null position. If all of the positions
  570. // are null positions, or the hit contains 0 positions, returns -1.
  571. //
  572. //--------------------------------------------------------------------------
  573. inline int CExtractedHit::EatNullPositions()
  574. {
  575. int cPos = _rHit.GetPositionCount();
  576. for (int i=0;i<cPos;i++)
  577. {
  578. if (!_rHit.GetPos(i).IsNullPosition())
  579. return i;
  580. }
  581. return -1;
  582. }
  583. //+-------------------------------------------------------------------------
  584. //
  585. // Class: CExtractHits
  586. //
  587. // Purpose: Functor to iterate over the hits in a document and output a
  588. // summary for each one
  589. //
  590. // History: 06-16-1996 t-matts Created
  591. //
  592. //--------------------------------------------------------------------------
  593. class CExtractHits
  594. {
  595. public:
  596. CExtractHits ( CDocument& rDocument,
  597. HitIter& rHitIter,
  598. PHttpOutput&,
  599. int cwcMargin = 150,
  600. int cwcSeparation = 80,
  601. int cwcDelim = 40 );
  602. };
  603. //+-------------------------------------------------------------------------
  604. //
  605. // Class: CSortQueryHits
  606. //
  607. // Purpose: Sort the positions returned as part of the hits in a document
  608. // object in the order in which they will appear in the document
  609. //
  610. // History: 05-20-1996 t-matts Created
  611. //
  612. //--------------------------------------------------------------------------
  613. class CSortQueryHits
  614. {
  615. public:
  616. CSortQueryHits(HitIter& rHitIter)
  617. :_rHitIter(rHitIter),_aPosition(0),_positionCount(0)
  618. {
  619. }
  620. ~CSortQueryHits() { delete[] _aPosition;}
  621. void Init();
  622. Position& GetPosition(int i) {return _aPosition[i];}
  623. int GetPositionCount() {return _positionCount;}
  624. private:
  625. HitIter& _rHitIter;
  626. Position* _aPosition;
  627. int _positionCount; //total # of distinct positions
  628. int CountPositions();
  629. };
  630. //+-------------------------------------------------------------------------
  631. //
  632. // Class: CLinkQueryHits
  633. //
  634. // Purpose: Insert the HTML tags necessary to enable next/prev navigation
  635. // through hits
  636. //
  637. // History: 05-16-1996 t-matts Created
  638. //
  639. //--------------------------------------------------------------------------
  640. class CLinkQueryHits
  641. {
  642. public:
  643. enum{BUFFER_SIZE = 4096,BOGUS_RANK = 1000};
  644. CLinkQueryHits( CInternalQuery& rCInternalQuery,
  645. CGetEnvVars& rGetEnvVars,
  646. PHttpFullOutput& rHttpOutput,
  647. DWORD cmsReadTimeout,
  648. CReleasableLock & lockSingleThreadedFilter,
  649. CEmptyPropertyList & propertyList,
  650. ULONG ulDisplayScript );
  651. void InsertLinks();
  652. private:
  653. BOOL MoveToNextDifferentPosition();
  654. BOOL AtBeginningOfPosition();
  655. BOOL LastTag();
  656. BOOL IsSeparatedBySpaces(int startOffset,
  657. int endOffset);
  658. void OutputBuffer()
  659. {
  660. _rHttpOutput.OutputHttp(_wcOutputBuffer,
  661. _ccOutputBuffer );
  662. }
  663. CGetEnvVars& _rGetEnvVars;
  664. CInternalQuery& _rInternalQuery;
  665. PHttpFullOutput& _rHttpOutput;
  666. CDocument _document;
  667. HitIter _HitIter;
  668. CSortQueryHits _sortedHits;
  669. //
  670. // buffer used to store document pieces retrieved from CDocument
  671. //
  672. WCHAR _Buffer[BUFFER_SIZE];
  673. //
  674. // buffer used for output & a count of characters in it
  675. //
  676. WCHAR _wcOutputBuffer[BUFFER_SIZE];
  677. int _ccOutputBuffer;
  678. //
  679. // information regarding the current position in the document
  680. //
  681. int _currentOffset; // current offset in buffer
  682. int _posIndex; // index of current position
  683. int _tagCount; // # of tag
  684. //
  685. // the total number of positions (not necessarily distinct)
  686. //
  687. int _posCount;
  688. //
  689. // data members to store the offset of the next position
  690. //
  691. int _nextBegOffset;
  692. int _nextEndOffset;
  693. };
  694. //+-------------------------------------------------------------------------
  695. //
  696. // Member: CLinkQueryHits::AtBeginningOfPosition
  697. //
  698. // Synopsis: returns true if we are positioned at the beginning of a
  699. // position
  700. //
  701. //--------------------------------------------------------------------------
  702. inline BOOL CLinkQueryHits::AtBeginningOfPosition()
  703. {
  704. return (_currentOffset == _nextBegOffset);
  705. }
  706. //+-------------------------------------------------------------------------
  707. //
  708. // Member: CLinkQueryHits::LastTag()
  709. //
  710. // Synopsis: returns true if the tag to be output is the last one in the
  711. // document and FALSE if not
  712. //
  713. //--------------------------------------------------------------------------
  714. inline BOOL CLinkQueryHits::LastTag()
  715. {
  716. return ((_tagCount == _posCount-1) || (_posIndex == _posCount-1));
  717. }
  718. //+-------------------------------------------------------------------------
  719. //
  720. // Member: CLinkQueryHits::MoveToNextDifferentPosition()
  721. //
  722. // Synopsis: goes through the array of sorted positions until it finds the
  723. // the next one
  724. //
  725. //--------------------------------------------------------------------------
  726. inline BOOL CLinkQueryHits::MoveToNextDifferentPosition()
  727. {
  728. for(;_posIndex <_posCount;_posIndex++)
  729. {
  730. Position nextPos = _sortedHits.GetPosition(_posIndex);
  731. _nextBegOffset = nextPos.GetBegOffset();
  732. _nextEndOffset = nextPos.GetEndOffset();
  733. if (_nextEndOffset > _currentOffset)
  734. break;
  735. }
  736. if (_posIndex == _posCount)
  737. return FALSE;
  738. return TRUE;
  739. }
  740. //+---------------------------------------------------------------------------
  741. //
  742. // Class: CWebhitsTemplate
  743. //
  744. // Purpose: A class that encapsulates a template file for webhits.
  745. //
  746. // History: 9-07-96 srikants Created
  747. //
  748. //----------------------------------------------------------------------------
  749. class CWebhitsTemplate
  750. {
  751. public:
  752. CWebhitsTemplate( CGetEnvVars const & envVars, ULONG codePage );
  753. CWTXFile & GetWTXFile() { return _wtxFile; }
  754. CWHVarSet & GetVariableSet() { return _variableSet; }
  755. BOOL DoesHeaderExist() const { return _wtxFile.DoesHeaderExist(); }
  756. BOOL DoesFooterExist() const { return _wtxFile.DoesFooterExist(); }
  757. private:
  758. CWHVarSet _variableSet;
  759. CWTXFile _wtxFile;
  760. };