Source code of Windows XP (NT5)
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.

159 lines
4.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1998.
  5. //
  6. // File: scpfixup.hxx
  7. //
  8. // Contents: Scope fixup classes to translate local paths to uncs that
  9. // remote machines can reference.
  10. //
  11. // History: 17-Oct-96 dlee created
  12. //
  13. //----------------------------------------------------------------------------
  14. #pragma once
  15. //+---------------------------------------------------------------------------
  16. //
  17. // Class: CScopeFixupElem
  18. //
  19. // Purpose: An element in the scope fixup table
  20. //
  21. // History: 17-Oct-96 dlee created
  22. //
  23. //----------------------------------------------------------------------------
  24. class CScopeFixupElem
  25. {
  26. public:
  27. CScopeFixupElem( WCHAR const * pwcScope,
  28. WCHAR const * pwcFixup ) :
  29. _scope( pwcScope ),
  30. _fixup( pwcFixup ),
  31. _fSeen( TRUE )
  32. {
  33. _scope.AppendBackSlash();
  34. _fixup.AppendBackSlash();
  35. }
  36. BOOL IsMatch( CLowcaseBuf const & orig ) const
  37. {
  38. return ( orig.Length() >= _scope.Length() ) &&
  39. ( RtlEqualMemory( orig.Get(),
  40. _scope.Get(),
  41. _scope.Length() * sizeof WCHAR ) );
  42. }
  43. BOOL IsExactMatch( CScopeFixupElem const & orig ) const
  44. {
  45. return ( orig._scope.Length() == _scope.Length() ) &&
  46. ( RtlEqualMemory( orig._scope.Get(),
  47. _scope.Get(),
  48. _scope.Length() * sizeof WCHAR ) ) &&
  49. ( orig._fixup.Length() == _fixup.Length() ) &&
  50. ( RtlEqualMemory( orig._fixup.Get(),
  51. _fixup.Get(),
  52. _fixup.Length() * sizeof WCHAR ) );
  53. }
  54. BOOL IsInverseMatch( CLowerFunnyPath & lcaseFunnyPath ) const
  55. {
  56. return ( ( lcaseFunnyPath.GetActualLength() >= _fixup.Length() ) &&
  57. ( RtlEqualMemory( lcaseFunnyPath.GetActualPath(),
  58. _fixup.Get(),
  59. _fixup.Length() * sizeof WCHAR ) ) ) ||
  60. ( ( lcaseFunnyPath.GetActualLength() == ( _fixup.Length() - 1 ) ) &&
  61. ( RtlEqualMemory( lcaseFunnyPath.GetActualPath(),
  62. _fixup.Get(),
  63. lcaseFunnyPath.GetActualLength() * sizeof WCHAR ) ) );
  64. }
  65. unsigned Fixup( CLowcaseBuf const & orig,
  66. WCHAR * pwcResult,
  67. unsigned cwcResult ) const
  68. {
  69. unsigned cwcPrefix = _fixup.Length();
  70. unsigned cwcTail = 1 + orig.Length() - _scope.Length();
  71. if ( cwcResult < ( cwcPrefix + cwcTail ) )
  72. return cwcPrefix + cwcTail;
  73. RtlCopyMemory( pwcResult,
  74. _fixup.Get(),
  75. cwcPrefix * sizeof WCHAR );
  76. RtlCopyMemory( pwcResult + _fixup.Length(),
  77. orig.Get() + _scope.Length(),
  78. cwcTail * sizeof WCHAR );
  79. return cwcPrefix + cwcTail - 1;
  80. } //Fixup
  81. void InverseFixup( CLowerFunnyPath & lcaseFunnyPath ) const
  82. {
  83. unsigned cwcPrefix = _scope.Length();
  84. unsigned cwcTail = lcaseFunnyPath.GetActualLength() - _fixup.Length();
  85. XGrowable<WCHAR> xTemp( cwcPrefix + cwcTail + 1 );
  86. RtlCopyMemory( xTemp.Get(),
  87. _scope.Get(),
  88. cwcPrefix * sizeof WCHAR );
  89. RtlCopyMemory( xTemp.Get() + _scope.Length(),
  90. lcaseFunnyPath.GetActualPath() + _fixup.Length(),
  91. ( 1 + cwcTail ) * sizeof WCHAR );
  92. lcaseFunnyPath.SetPath( xTemp.Get(), cwcPrefix + cwcTail, TRUE );
  93. } //InverseFixup
  94. CLowcaseBuf & GetScope() { return _scope; }
  95. BOOL IsSeen() const { return _fSeen; }
  96. void SetSeen() { _fSeen = TRUE; }
  97. void ClearSeen() { _fSeen = FALSE; }
  98. private:
  99. BOOL _fSeen;
  100. CLowcaseBuf _scope;
  101. CLowcaseBuf _fixup;
  102. };
  103. //+---------------------------------------------------------------------------
  104. //
  105. // Class: CScopeFixup
  106. //
  107. // Purpose: The scope fixup table.
  108. //
  109. // History: 17-Oct-96 dlee created
  110. //
  111. //----------------------------------------------------------------------------
  112. class CScopeFixup
  113. {
  114. public:
  115. CScopeFixup() { }
  116. void Add( WCHAR const * pwcScope, WCHAR const * pwcFixup );
  117. void Remove( WCHAR const * pwcScope, WCHAR const * pwcFixup );
  118. BOOL IsExactMatch( WCHAR const * pwcScope, WCHAR const * pwcFixup );
  119. unsigned Fixup( WCHAR const * pwcOriginal,
  120. WCHAR * pwcResult,
  121. unsigned cwcResult,
  122. unsigned cSkip );
  123. void InverseFixup( CLowerFunnyPath & lcaseFunnyPath );
  124. void BeginSeen();
  125. void EndSeen();
  126. private:
  127. CCountedDynArray<CScopeFixupElem> _aElems;
  128. CReadWriteAccess _rwLock;
  129. };