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.

569 lines
12 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. path.hxx
  5. Abstract:
  6. The PATH class provides an interface to the complete
  7. Win32 name space. Complete means that it will correctly
  8. handle long, drive or UNC based, blank embedded, mixed case
  9. names. It should eliminate the need for everyone to code
  10. statements such as "is the second char a ':'" or "search for
  11. the first '\' from the end of the name". That is, access to and
  12. manipulation of path and file names should be performed soley
  13. through the PATH member functions. This will eliminate
  14. the recoding of standard name manipulation code and ensure
  15. complete support of Win32 functionality, such as codepage and
  16. DBCS support.
  17. Author:
  18. Steve Rowe 13-Dec-90
  19. Environment:
  20. ULIB, user
  21. Notes:
  22. To clarify terminology used here, the following describes a
  23. canonicalized path (in butchered BNF/reg exp):
  24. {Canon} ::= {Prefix}"\"{Name}
  25. {Prefix} ::= {Device}{Dirs}
  26. {Dirs} ::= {"\"{Component}}*
  27. {Device} ::= {Drive}|{Machine}
  28. {Drive} ::= {Letter}":"
  29. {Machine} ::= "\\"{Char}+
  30. {Letter} ::= valid drive letter [a-zA-Z]
  31. {Char} ::= valid filename/directory char [~:\]
  32. {Component} ::= {Char}+
  33. {Name} ::= {Base - excluding "."} | { {Base}"."{Ext} }
  34. {Base} ::= {Char}+
  35. {Ext} ::= {Char - excluding "."}+
  36. Legend:
  37. -------
  38. {x}* - 0 or more x
  39. {x}+ - 1 or more x
  40. "x" - just x (not the quotes)
  41. {x}|{y} - x or y (not both or none)
  42. Examples:
  43. ---------
  44. # Canon
  45. --- -----
  46. (1) x:\abc\def.ghi\jkl.mnop
  47. (2) \\x\abc\def.ghi\jkl.mnop
  48. (3) c:\config.sys
  49. (1) (2) (3)
  50. Prefix x:\abc\def.ghi \\x\abc\def.ghi c:
  51. Device x: \\x c:
  52. Dirs \abc \abc\def.ghi
  53. Name jkl.mnop jkl.mnop config.sys
  54. Base jkl jkl config
  55. Ext mnop mnop sys
  56. Component numbers are 0-based.
  57. --*/
  58. #if !defined( _PATH_)
  59. #define _PATH_
  60. #include "wstring.hxx"
  61. #include "array.hxx"
  62. //
  63. // Forward references & declarations
  64. //
  65. DECLARE_CLASS( PATH );
  66. //
  67. // PATHSTATE maintains the number of characters within each component that
  68. // makes up a PATH
  69. //
  70. struct _PATHSTATE {
  71. //
  72. // Prefix
  73. //
  74. CHNUM PrefixLen;
  75. CHNUM DeviceLen;
  76. CHNUM DirsLen;
  77. CHNUM SeparatorLen;
  78. //
  79. // Name
  80. //
  81. CHNUM NameLen;
  82. CHNUM BaseLen;
  83. CHNUM ExtLen;
  84. };
  85. DEFINE_TYPE( struct _PATHSTATE, PATHSTATE );
  86. typedef enum PATH_ANALYZE_CODE {
  87. PATH_OK,
  88. PATH_COULD_BE_FLOPPY,
  89. PATH_OUT_OF_MEMORY,
  90. PATH_INVALID_DRIVE_SPEC,
  91. PATH_NO_MOUNT_POINT_FOR_VOLUME_NAME_PATH
  92. };
  93. class PATH : public OBJECT {
  94. public:
  95. ULIB_EXPORT
  96. DECLARE_CONSTRUCTOR( PATH );
  97. DECLARE_CAST_MEMBER_FUNCTION( PATH );
  98. NONVIRTUAL
  99. ULIB_EXPORT
  100. BOOLEAN
  101. Initialize (
  102. IN PCWSTR InitialPath,
  103. IN BOOLEAN Canonicalize DEFAULT FALSE
  104. );
  105. NONVIRTUAL
  106. ULIB_EXPORT
  107. BOOLEAN
  108. Initialize (
  109. IN PCWSTRING InitialPath,
  110. IN BOOLEAN Canonicalize DEFAULT FALSE
  111. );
  112. NONVIRTUAL
  113. ULIB_EXPORT
  114. BOOLEAN
  115. Initialize (
  116. IN PCPATH InitialPath,
  117. IN BOOLEAN Canonicalize DEFAULT FALSE
  118. );
  119. VIRTUAL
  120. ULIB_EXPORT
  121. ~PATH (
  122. );
  123. NONVIRTUAL
  124. ULIB_EXPORT
  125. BOOLEAN
  126. AppendBase (
  127. IN PCWSTRING Base,
  128. IN BOOLEAN Absolute DEFAULT FALSE
  129. );
  130. NONVIRTUAL
  131. ULIB_EXPORT
  132. BOOLEAN
  133. EndsWithDelimiter (
  134. ) CONST;
  135. NONVIRTUAL
  136. PCWSTRING
  137. GetPathString (
  138. ) CONST;
  139. NONVIRTUAL
  140. ULIB_EXPORT
  141. BOOLEAN
  142. HasWildCard (
  143. ) CONST;
  144. NONVIRTUAL
  145. ULIB_EXPORT
  146. BOOLEAN
  147. IsDrive (
  148. ) CONST;
  149. NONVIRTUAL
  150. BOOLEAN
  151. IsRoot (
  152. ) CONST;
  153. NONVIRTUAL
  154. ULIB_EXPORT
  155. BOOLEAN
  156. ModifyName (
  157. IN PCWSTRING Pattern
  158. );
  159. NONVIRTUAL
  160. PWSTRING
  161. QueryBase (
  162. );
  163. NONVIRTUAL
  164. ULIB_EXPORT
  165. PARRAY
  166. QueryComponentArray (
  167. OUT PARRAY Array DEFAULT NULL
  168. ) CONST;
  169. NONVIRTUAL
  170. PWSTRING
  171. QueryDevice (
  172. );
  173. NONVIRTUAL
  174. PWSTRING
  175. QueryDirs (
  176. );
  177. NONVIRTUAL
  178. PWSTRING
  179. QueryDirsAndName (
  180. );
  181. NONVIRTUAL
  182. PWSTRING
  183. QueryExt (
  184. );
  185. NONVIRTUAL
  186. ULIB_EXPORT
  187. PPATH
  188. QueryFullPath (
  189. ) CONST;
  190. NONVIRTUAL
  191. ULIB_EXPORT
  192. PWSTRING
  193. QueryFullPathString (
  194. ) CONST;
  195. NONVIRTUAL
  196. PWSTRING
  197. QueryName (
  198. ) CONST;
  199. NONVIRTUAL
  200. ULIB_EXPORT
  201. PPATH
  202. QueryPath (
  203. ) CONST;
  204. NONVIRTUAL
  205. PWSTRING
  206. QueryPrefix (
  207. );
  208. NONVIRTUAL
  209. ULIB_EXPORT
  210. PWSTRING
  211. QueryRoot (
  212. );
  213. NONVIRTUAL
  214. ULIB_EXPORT
  215. PPATH
  216. QueryWCExpansion(
  217. IN PPATH BasePath
  218. );
  219. NONVIRTUAL
  220. BOOLEAN
  221. SetBase (
  222. IN PCWSTRING NewBase
  223. );
  224. ULIB_EXPORT
  225. BOOLEAN
  226. SetDevice (
  227. IN PCWSTRING NewDevice
  228. );
  229. NONVIRTUAL
  230. BOOLEAN
  231. SetExt (
  232. IN PCWSTRING NewExt
  233. );
  234. NONVIRTUAL
  235. ULIB_EXPORT
  236. BOOLEAN
  237. SetName (
  238. IN PCWSTRING NewName
  239. );
  240. NONVIRTUAL
  241. BOOLEAN
  242. SetPrefix (
  243. IN PCWSTRING NewPrefix
  244. );
  245. NONVIRTUAL
  246. ULIB_EXPORT
  247. BOOLEAN
  248. TruncateBase (
  249. );
  250. NONVIRTUAL
  251. ULIB_EXPORT
  252. VOID
  253. TruncateNameAtColon (
  254. );
  255. NONVIRTUAL
  256. ULIB_EXPORT
  257. VOID
  258. TruncateDelimiter (
  259. );
  260. ULIB_EXPORT
  261. BOOLEAN
  262. AppendDelimiter (
  263. );
  264. ULIB_EXPORT
  265. BOOLEAN
  266. AppendString (
  267. IN PCWSTRING String
  268. );
  269. NONVIRTUAL
  270. ULIB_EXPORT
  271. BOOLEAN
  272. IsGuidVolName(
  273. );
  274. NONVIRTUAL
  275. ULIB_EXPORT
  276. PPATH
  277. QueryMountPointPath(
  278. );
  279. NONVIRTUAL
  280. ULIB_EXPORT
  281. PWSTRING
  282. QueryGuidString(
  283. OUT PWSTRING LongestMountPointPath,
  284. OUT PBOOLEAN IsLongestMountPointADriveLetter,
  285. OUT PWSTRING DrivePath
  286. );
  287. NONVIRTUAL
  288. ULIB_EXPORT
  289. PATH_ANALYZE_CODE
  290. AnalyzePath(
  291. OUT PWSTRING VolumeName,
  292. OUT PPATH VolumePath,
  293. OUT PWSTRING RemainingPath
  294. );
  295. private:
  296. NONVIRTUAL
  297. VOID
  298. Construct (
  299. );
  300. NONVIRTUAL
  301. BOOLEAN
  302. ExpandWildCards(
  303. IN OUT PWSTRING pStr1,
  304. IN OUT PWSTRING pStr2
  305. );
  306. BOOLEAN
  307. Initialize (
  308. );
  309. NONVIRTUAL
  310. CHNUM
  311. QueryBaseStart (
  312. ) CONST;
  313. CHNUM
  314. QueryDeviceLen(
  315. IN PWSTRING pString
  316. ) CONST;
  317. NONVIRTUAL
  318. CHNUM
  319. QueryDeviceStart (
  320. ) CONST;
  321. NONVIRTUAL
  322. CHNUM
  323. QueryExtStart (
  324. ) CONST;
  325. NONVIRTUAL
  326. CHNUM
  327. QueryNameStart (
  328. ) CONST;
  329. NONVIRTUAL
  330. CHNUM
  331. QueryPrefixStart (
  332. ) CONST;
  333. NONVIRTUAL
  334. VOID
  335. SetPathState (
  336. );
  337. STATIC
  338. BOOLEAN
  339. BuildMountPoint(
  340. IN PWSTR Name,
  341. IN PCWSTR GuidNameToMatch,
  342. OUT PWSTR MountPointPath
  343. );
  344. #if DBG==1
  345. ULONG _Signature;
  346. BOOLEAN _Initialized;
  347. #endif
  348. //
  349. // path data
  350. //
  351. WCHAR _PathBuffer[MAX_PATH];
  352. FSTRING _PathString;
  353. PATHSTATE _PathState;
  354. };
  355. INLINE
  356. CHNUM
  357. PATH::QueryPrefixStart (
  358. ) CONST
  359. {
  360. return( 0 );
  361. }
  362. INLINE
  363. CHNUM
  364. PATH::QueryNameStart (
  365. ) CONST
  366. {
  367. //
  368. // Increment past the '\'
  369. //
  370. return( QueryPrefixStart() + _PathState.PrefixLen + _PathState.SeparatorLen );
  371. }
  372. INLINE
  373. CHNUM
  374. PATH::QueryBaseStart (
  375. ) CONST
  376. {
  377. return( QueryNameStart() );
  378. }
  379. INLINE
  380. CHNUM
  381. PATH::QueryDeviceStart (
  382. ) CONST
  383. {
  384. return( 0 );
  385. }
  386. INLINE
  387. CHNUM
  388. PATH::QueryExtStart (
  389. ) CONST
  390. {
  391. return( QueryNameStart() + _PathState.BaseLen + 1 );
  392. }
  393. INLINE
  394. PCWSTRING
  395. PATH::GetPathString (
  396. ) CONST
  397. {
  398. return( &_PathString );
  399. }
  400. INLINE
  401. PWSTRING
  402. PATH::QueryBase (
  403. )
  404. {
  405. return( _PathState.BaseLen ? _PathString.QueryString( QueryBaseStart(), _PathState.BaseLen ) : NULL );
  406. }
  407. INLINE
  408. PWSTRING
  409. PATH::QueryDirs (
  410. )
  411. {
  412. return( _PathState.DirsLen ? _PathString.QueryString( QueryDeviceStart() + _PathState.DeviceLen, _PathState.DirsLen ) : NULL );
  413. }
  414. INLINE
  415. PWSTRING
  416. PATH::QueryDirsAndName (
  417. )
  418. {
  419. return( ( _PathState.DirsLen || _PathState.NameLen ) ? _PathString.QueryString( QueryDeviceStart() + _PathState.DeviceLen ) : NULL );
  420. }
  421. INLINE
  422. PWSTRING
  423. PATH::QueryDevice (
  424. )
  425. {
  426. return( _PathState.DeviceLen ? _PathString.QueryString( QueryDeviceStart(), _PathState.DeviceLen ) : NULL );
  427. }
  428. INLINE
  429. PWSTRING
  430. PATH::QueryExt (
  431. )
  432. {
  433. return( _PathState.ExtLen ? _PathString.QueryString( QueryExtStart(), _PathState.ExtLen ) : NULL );
  434. }
  435. INLINE
  436. PWSTRING
  437. PATH::QueryName (
  438. ) CONST
  439. {
  440. return( _PathState.NameLen ? _PathString.QueryString( QueryNameStart(), _PathState.NameLen ) : NULL );
  441. }
  442. INLINE
  443. PWSTRING
  444. PATH::QueryPrefix (
  445. )
  446. {
  447. return( _PathState.PrefixLen ? _PathString.QueryString( QueryPrefixStart(), _PathState.PrefixLen ) : NULL );
  448. }
  449. #endif // _PATH_