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.

191 lines
5.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998-1999.
  5. //
  6. // File: signore.cxx
  7. //
  8. // Contents: CScopeIgnore methods
  9. //
  10. // Classes: CScopeIgnore
  11. //
  12. // History: 3-1-98 mohamedn created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include "cicat.hxx"
  18. //+-------------------------------------------------------------------------
  19. //
  20. // Member: CScopesIgnored::Enumerate(), public
  21. //
  22. // Synopsis: enumerates ignoredScopes table
  23. //
  24. // Arguments: [pwcRoot] -- contains table entries upon return
  25. // [cwc] -- buffer lenght of pwcRoot
  26. // [iBmk] -- enumeration index
  27. //
  28. // returns: TRUE if pwcRoot contains valid table entry. FALSE otherwise.
  29. //
  30. // History: 3-1-98 mohamedn created
  31. //
  32. //--------------------------------------------------------------------------
  33. BOOL CScopesIgnored::Enumerate(WCHAR * pwcRoot, unsigned cwc, unsigned & iBmk )
  34. {
  35. CReadAccess lock( _rwLock );
  36. while( iBmk < _aElems.Count() )
  37. {
  38. if ( cwc < ( wcslen( _aElems[iBmk]->Get() ) + 1 ) )
  39. THROW( CException(STATUS_INVALID_PARAMETER ) );
  40. wcscpy( pwcRoot, _aElems[iBmk]->Get() );
  41. iBmk++;
  42. return TRUE;
  43. }
  44. return FALSE;
  45. } //Enumerate
  46. //+-------------------------------------------------------------------------
  47. //
  48. // Member: CScopesIgnored::RemoveElement(), public
  49. //
  50. // Synopsis: removes an element from ignoredScopes table
  51. //
  52. // Arguments: [pwcScope] -- scope to remove.
  53. //
  54. // returns: none.
  55. //
  56. // History: 3-1-98 mohamedn created
  57. //
  58. //--------------------------------------------------------------------------
  59. void CScopesIgnored::RemoveElement(WCHAR const * pwcScope)
  60. {
  61. CLowcaseBuf lowcaseBuf(pwcScope);
  62. CWriteAccess lock( _rwLock );
  63. for ( unsigned i = 0; i < _aElems.Count(); i++ )
  64. {
  65. if ( lowcaseBuf.AreEqual(*_aElems[i]) )
  66. {
  67. delete _aElems.AcquireAndShrink(i);
  68. ConstructDFAObject();
  69. break;
  70. }
  71. }
  72. } //RemoveElement
  73. //+-------------------------------------------------------------------------
  74. //
  75. // Member: CScopesIgnored::RegExFind(), public
  76. //
  77. // Synopsis: finds a regular expression match for the passed in string.
  78. //
  79. // Arguments: [bufToFind] -- contains path to search for.
  80. //
  81. // returns: TRUE if path was found, FALSE otherwise.
  82. //
  83. // History: 3-1-98 mohamedn created
  84. //
  85. //--------------------------------------------------------------------------
  86. BOOL CScopesIgnored::RegExFind( CLowcaseBuf const & bufToFind )
  87. {
  88. //
  89. // The DFA may be NULL if we failed to create it while adding or
  90. // removing a scope.
  91. //
  92. // This logic is complicated by the fact that we can't promote from a
  93. // read lock to a write lock.
  94. //
  95. do
  96. {
  97. if ( _xDFA.IsNull() )
  98. {
  99. CWriteAccess lock( _rwLock );
  100. if ( _xDFA.IsNull() )
  101. ConstructDFAObject();
  102. }
  103. CReadAccess lock( _rwLock );
  104. if ( 0 == _aElems.Count() )
  105. return FALSE; // no excluded scopes to search
  106. if ( !_xDFA.IsNull() )
  107. {
  108. BOOL fFound = _xDFA->Recognize( bufToFind.Get() );
  109. ciDebugOut(( DEB_ITRACE, "%ws is %s Found\n", bufToFind.Get(),
  110. fFound ? "" : "not" ));
  111. return fFound;
  112. }
  113. } while ( TRUE );
  114. // Keep the compiler happy...
  115. return FALSE;
  116. } //RegExFind
  117. //+-------------------------------------------------------------------------
  118. //
  119. // Member: BOOL CScopesIgnored::ConstructDFAObject(), private
  120. //
  121. // Synopsis: Creates a new CDFA object
  122. //
  123. // History: 3-1-98 mohamedn created
  124. //
  125. //--------------------------------------------------------------------------
  126. void CScopesIgnored::ConstructDFAObject(void)
  127. {
  128. DWORD bufLen = 0;
  129. //
  130. // Generate a single buffer containing all excluded scopes.
  131. //
  132. for ( unsigned i = 0; i < _aElems.Count(); i++ )
  133. bufLen += _aElems[i]->Length() + 2; // to account for "|," reg-x chars.
  134. bufLen++; // null terminator.
  135. XGrowable<WCHAR> xExcludeString(4*80); // 4 lines by 80 wchars each.
  136. xExcludeString.SetSize(bufLen);
  137. for ( i = 0, xExcludeString[0] = L'\0' ; i < _aElems.Count(); i++ )
  138. {
  139. if ( i > 0 )
  140. wcscat( xExcludeString.Get(), L"|," ); // add a regX OR separator.
  141. wcscat( xExcludeString.Get(), _aElems[i]->Get() );
  142. }
  143. //
  144. // Create a new CDFA object, case insensitive with infinite timeout.
  145. //
  146. XPtr<CDFA> xDFA(new CDFA( xExcludeString.Get(), _tl, FALSE ) );
  147. _xDFA.Free();
  148. _xDFA.Set(xDFA.Acquire());
  149. ciDebugOut(( DEB_ITRACE, "New RegularExpression: %ws\n", xExcludeString.Get() ));
  150. } //ConstructDFAObject