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.

265 lines
7.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1998.
  5. //
  6. // File: scpfixup.cxx
  7. //
  8. // Contents: Scope fixup classes to translate local paths to uncs that
  9. // remote machines can reference.
  10. //
  11. // History: 09-Jun-1998 KyleP Moved out of header
  12. //
  13. //----------------------------------------------------------------------------
  14. #include <pch.cxx>
  15. #pragma hdrstop
  16. #include <scpfixup.hxx>
  17. //+-------------------------------------------------------------------------
  18. //
  19. // Member: CScopeFixup::Add, public
  20. //
  21. // Synopsis: Adds a new fixup to the list
  22. //
  23. // Arguments: [pwcScope] -- Source (local) scope (e.g. c:\)
  24. // [pwcFixup] -- Fixed up scope (e.g. \\server\share\rootc)
  25. //
  26. // History: 09-Jun-1998 KyleP Added header
  27. //
  28. //--------------------------------------------------------------------------
  29. void CScopeFixup::Add( WCHAR const * pwcScope, WCHAR const * pwcFixup )
  30. {
  31. XPtr<CScopeFixupElem> xElem = new CScopeFixupElem( pwcScope,
  32. pwcFixup );
  33. CWriteAccess lock( _rwLock );
  34. for ( unsigned i = 0; i < _aElems.Count(); i++ )
  35. {
  36. if ( _aElems[i]->IsMatch( xElem->GetScope() ) )
  37. {
  38. //
  39. // Replace exact matching old fixup with new fixup
  40. //
  41. if ( _aElems[i]->IsExactMatch( xElem.GetReference() ) )
  42. {
  43. _aElems[i]->SetSeen();
  44. return;
  45. }
  46. else
  47. {
  48. //
  49. // Move the original match down the list.
  50. //
  51. CScopeFixupElem * p = _aElems[i];
  52. _aElems[i] = xElem.Acquire();
  53. xElem.Set( p );
  54. }
  55. }
  56. }
  57. _aElems.Add( xElem.GetPointer(), _aElems.Count() );
  58. xElem.Acquire();
  59. } //Add
  60. //+-------------------------------------------------------------------------
  61. //
  62. // Member: CScopeFixup::Remove, public
  63. //
  64. // Synopsis: Removes a fixup from the list
  65. //
  66. // Arguments: [pwcScope] -- Source (local) scope (e.g. c:\)
  67. // [pwcFixup] -- Fixed up scope (e.g. \\server\share\rootc)
  68. //
  69. // History: 09-Jun-1998 KyleP Created
  70. //
  71. //--------------------------------------------------------------------------
  72. void CScopeFixup::Remove( WCHAR const * pwcScope, WCHAR const * pwcFixup )
  73. {
  74. CScopeFixupElem Elem( pwcScope, pwcFixup );
  75. CWriteAccess lock( _rwLock );
  76. for ( unsigned i = 0; i < _aElems.Count(); i++ )
  77. {
  78. if ( _aElems[i]->IsExactMatch( Elem ) )
  79. {
  80. //
  81. // Order-preserving delete
  82. //
  83. delete _aElems.AcquireAndShrinkAndPreserveOrder( i );
  84. break;
  85. }
  86. }
  87. } //Remove
  88. //+-------------------------------------------------------------------------
  89. //
  90. // Member: CScopeFixup::IsExactMatch, public
  91. //
  92. // Arguments: [pwcScope] -- Source (local) scope (e.g. c:\)
  93. // [pwcFixup] -- Fixed up scope (e.g. \\server\share\rootc)
  94. //
  95. // Returns: TRUE if both the path and alias exactly match a currently
  96. // registered pair.
  97. //
  98. // History: 09-Jun-1998 KyleP Added header
  99. //
  100. //--------------------------------------------------------------------------
  101. BOOL CScopeFixup::IsExactMatch( WCHAR const * pwcScope,
  102. WCHAR const * pwcFixup )
  103. {
  104. CScopeFixupElem Elem( pwcScope, pwcFixup );
  105. CReadAccess lock( _rwLock );
  106. for ( unsigned i = 0; i < _aElems.Count(); i++ )
  107. {
  108. if ( _aElems[i]->IsExactMatch( Elem ) )
  109. return TRUE;
  110. }
  111. return FALSE;
  112. } //IsExactMatch
  113. //+-------------------------------------------------------------------------
  114. //
  115. // Member: CScopeFixup::Fixup, public
  116. //
  117. // Synopsis: Converts a local path to an aliased (fixed up) path
  118. //
  119. // Arguments: [pwcOriginal] -- Fixed up path (e.g. c:\foo.txt)
  120. // [pwcResult] -- Fixed up path (e.g. \\server\share\foo.txt)
  121. // [cwcResult] -- Size of [pwcResult]
  122. // [cSkip] -- Skip this many matches
  123. //
  124. // Returns: Count of characters written to [pwcResult]
  125. //
  126. // History: 09-Jun-1998 KyleP Added header
  127. //
  128. //--------------------------------------------------------------------------
  129. unsigned CScopeFixup::Fixup( WCHAR const * pwcOriginal,
  130. WCHAR * pwcResult,
  131. unsigned cwcResult,
  132. unsigned cSkip )
  133. {
  134. // the path is already lowercase -- don't copy or lowercase it.
  135. CLowcaseBuf orig( pwcOriginal, TRUE );
  136. {
  137. // =========================================================
  138. CReadAccess lock( _rwLock );
  139. for ( unsigned i = 0; i < _aElems.Count(); i++ )
  140. {
  141. if ( _aElems[i]->IsMatch( orig ) )
  142. {
  143. if ( 0 == cSkip )
  144. return _aElems[i]->Fixup( orig, pwcResult, cwcResult );
  145. else
  146. cSkip--;
  147. }
  148. }
  149. // =========================================================
  150. }
  151. // no fixup available -- just copy the original
  152. if ( cwcResult > orig.Length() )
  153. {
  154. RtlCopyMemory( pwcResult,
  155. pwcOriginal,
  156. ( orig.Length() + 1 ) * sizeof WCHAR );
  157. return orig.Length();
  158. }
  159. if ( 0 == cSkip )
  160. return orig.Length() + 1;
  161. else
  162. return 0;
  163. } //Fixup
  164. //+-------------------------------------------------------------------------
  165. //
  166. // Member: CScopeFixup::InverseFixup, public
  167. //
  168. // Synopsis: Converts a fixup to a source path.
  169. //
  170. // Arguments: [lcaseFunnyPath] -- Fixed up path (e.g. \\Server\Share\foo.txt)
  171. // Local path (e.g. c:\foo.txt) is also returned here
  172. //
  173. // History: 09-Jun-1998 KyleP Added header
  174. //
  175. //--------------------------------------------------------------------------
  176. void CScopeFixup::InverseFixup( CLowerFunnyPath & lcaseFunnyPath )
  177. {
  178. CReadAccess lock( _rwLock );
  179. for ( unsigned i = 0; i < _aElems.Count(); i++ )
  180. {
  181. if ( _aElems[i]->IsInverseMatch( lcaseFunnyPath ) )
  182. {
  183. _aElems[i]->InverseFixup( lcaseFunnyPath );
  184. break;
  185. }
  186. }
  187. } //InverseFixup
  188. //+-------------------------------------------------------------------------
  189. //
  190. // Member: CScopeFixup::BeginSeen, public
  191. //
  192. // Synopsis: Initiates 'seen processing' for fixups.
  193. //
  194. // History: 09-Jun-1998 KyleP Created
  195. //
  196. //--------------------------------------------------------------------------
  197. void CScopeFixup::BeginSeen()
  198. {
  199. CWriteAccess lock( _rwLock );
  200. for ( unsigned i = 0; i < _aElems.Count(); i++ )
  201. {
  202. _aElems[i]->ClearSeen();
  203. }
  204. } //BeginSeen
  205. //+-------------------------------------------------------------------------
  206. //
  207. // Member: CScopeFixup::EndSeen, public
  208. //
  209. // Synopsis: Removes any unreferenced fixups
  210. //
  211. // History: 09-Jun-1998 KyleP Created
  212. //
  213. //--------------------------------------------------------------------------
  214. void CScopeFixup::EndSeen()
  215. {
  216. CWriteAccess lock( _rwLock );
  217. for ( unsigned i = 0; i < _aElems.Count(); i++ )
  218. {
  219. if ( !_aElems[i]->IsSeen() )
  220. {
  221. ciDebugOut(( DEB_ITRACE, "Removing fixup for: %ws\n", _aElems[i]->GetScope().Get() ));
  222. delete _aElems.AcquireAndShrinkAndPreserveOrder(i);
  223. }
  224. }
  225. } //EndSeen