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.

201 lines
4.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 2000.
  5. //
  6. // File: appcur.cxx
  7. //
  8. // Contents:
  9. //
  10. // History:
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <curstk.hxx>
  16. #include <isearch.hxx>
  17. #include "appcur.hxx"
  18. //
  19. // Note: Don't enforce cMaxNodes as this is a client-side operation over a
  20. // single file. The denial of service problem doesn't exist.
  21. //
  22. COccCursor * CAppQueriable::QueryCursor( const CKey * pKey, BOOL isRange, ULONG & cMaxNodes )
  23. {
  24. ciDebugOut(( DEB_CURSOR,
  25. "CAppQueriable::QueryCursor. Key %.*ws\n isRange=%s, cMaxNodes=%d\n",
  26. pKey->StrLen(), pKey->GetStr(),
  27. isRange ? "TRUE" : "FALSE",
  28. cMaxNodes ));
  29. int iPos = _recog.FindDet ( isRange? DetPrefix: DetSingleKey, pKey, 0 );
  30. Win4Assert ( 0 <= iPos );
  31. CRegionList& regList = _recog.GetRegionList (iPos);
  32. return new CAppCursor( regList, _hitSink );
  33. }
  34. COccCursor * CAppQueriable::QueryRangeCursor( const CKey * pKeyBegin,
  35. const CKey * pKeyEnd,
  36. ULONG & cMaxNodes )
  37. {
  38. ciDebugOut(( DEB_CURSOR,
  39. "CAppQueriable::QueryRangeCursor. KeyBegin:: %.*ws\n KeyEnd:: %.*ws\n cMaxNodes=%d\n",
  40. pKeyBegin->StrLen(), pKeyBegin->GetStr(),
  41. pKeyEnd->StrLen(), pKeyEnd->GetStr(),
  42. cMaxNodes ));
  43. int iPos = _recog.FindDet ( DetRange, pKeyBegin, pKeyEnd );
  44. Win4Assert ( 0 <= iPos );
  45. CRegionList& regList = _recog.GetRegionList (iPos);
  46. return new CAppCursor( regList, _hitSink );
  47. }
  48. COccCursor * CAppQueriable::QuerySynCursor( CKeyArray & keyArr,
  49. BOOL isRange,
  50. ULONG & cMaxNodes )
  51. {
  52. COccCurStack curStk;
  53. COccCursor *pCur;
  54. int keyCount = keyArr.Count();
  55. ciDebugOut(( DEB_CURSOR,
  56. "CAppQueriable::QuerySynCursor. isRange=%s keyCount=%d cMaxNodes=%d\n",
  57. isRange ? "TRUE" : "FALSE",
  58. keyCount,
  59. cMaxNodes ));
  60. for (int i = 0; i < keyCount; i++)
  61. {
  62. CKey& key = keyArr.Get(i);
  63. ciDebugOut(( DEB_CURSOR,
  64. "CAppQueriable::QuerySynCursor. Key %.*ws\n",
  65. key.StrLen(), key.GetStr() ));
  66. int iPos = _recog.FindDet ( isRange? DetPrefix: DetSingleKey, &key, 0 );
  67. Win4Assert ( 0 <= iPos );
  68. CRegionList& regList = _recog.GetRegionList (iPos);
  69. pCur = new CAppCursor ( regList, _hitSink );
  70. curStk.Push(pCur);
  71. }
  72. pCur = curStk.QuerySynCursor(10);
  73. return pCur;
  74. }
  75. // Initialize private data and start the search.
  76. CAppCursor::CAppCursor ( CRegionList& regList, CHitSink& hitSink )
  77. : _occ(1), _regList(regList), _regIter (regList), _hitSink(hitSink),
  78. _fWidInvalid(FALSE)
  79. {
  80. LoadPosition();
  81. }
  82. // pure virtual overrides for CCursor
  83. WORKID CAppCursor::WorkId()
  84. {
  85. ciDebugOut(( DEB_CURSOR, "CAppCursor::WorkId\n" ));
  86. if ( IsEmpty() || _fWidInvalid )
  87. return widInvalid;
  88. else
  89. return 1;
  90. }
  91. WORKID CAppCursor::NextWorkId()
  92. {
  93. _fWidInvalid = TRUE;
  94. return widInvalid;
  95. }
  96. ULONG CAppCursor::HitCount()
  97. {
  98. return _hitSink.Count();
  99. }
  100. ULONG CAppCursor::OccurrenceCount()
  101. {
  102. // Win4Assert(!"CAppCursor::OccurrenceCount");
  103. // return max(1,_hitSink.Count());
  104. return 1;
  105. }
  106. ULONG CAppCursor::WorkIdCount()
  107. {
  108. return 1;
  109. }
  110. LONG CAppCursor::Rank() { return MAX_QUERY_RANK; }
  111. OCCURRENCE CAppCursor::Occurrence()
  112. {
  113. return _occ;
  114. }
  115. OCCURRENCE CAppCursor::NextOccurrence()
  116. {
  117. if (OCC_INVALID != _occ)
  118. {
  119. Advance ();
  120. }
  121. return _occ;
  122. }
  123. // record the hit in TheHitSink
  124. LONG CAppCursor::Hit()
  125. {
  126. ciDebugOut(( DEB_CURSOR, "CAppCursor::Hit\n" ));
  127. if ( _occ != OCC_INVALID )
  128. {
  129. _hitSink.AddPosition ( _regIter.GetRegionHit()->Region() );
  130. return MAX_QUERY_RANK;
  131. }
  132. else
  133. {
  134. return rankInvalid;
  135. }
  136. }
  137. void CAppCursor::Advance ()
  138. {
  139. Win4Assert (!_regList.AtEnd(_regIter));
  140. _regList.Advance(_regIter);
  141. LoadPosition ();
  142. }
  143. void CAppCursor::LoadPosition ()
  144. {
  145. ciDebugOut(( DEB_CURSOR, "CAppCursor::LoadPosition\n" ));
  146. if (_regList.AtEnd(_regIter))
  147. {
  148. _occ = OCC_INVALID;
  149. }
  150. else
  151. {
  152. _occ = _regIter.GetRegionHit()->Occurrence();
  153. }
  154. }
  155. LONG CAppCursor::NextHit()
  156. {
  157. ciDebugOut(( DEB_CURSOR, "CAppCursor::NextHit\n" ));
  158. NextOccurrence ();
  159. return Hit();
  160. }