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.

195 lines
5.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. * netname.hxx
  7. * NET_NAME class
  8. *
  9. * FILE HISTORY:
  10. * Yi-HsinS 12/8/91 Created, separated from sharebas.hxx
  11. * Yi-HsinS 12/15/91 Clean up for general use
  12. *
  13. *
  14. */
  15. #ifndef _NETNAME_HXX_
  16. #define _NETNAME_HXX_
  17. enum NETNAME_TYPE
  18. {
  19. TYPE_UNKNOWN,
  20. TYPE_PATH_UNC, // the form \\server\share\path
  21. TYPE_PATH_ABS, // the form x:\path
  22. };
  23. enum UNINITIALIZED_BOOL
  24. {
  25. BOOL_UNINITIALIZED = -1,
  26. BOOL_FALSE,
  27. BOOL_TRUE
  28. };
  29. /*************************************************************************
  30. NAME: NET_NAME
  31. SYNOPSIS: The class for manipulating net names
  32. For now, it only accepts fully qualified path names.
  33. (1) UNC path -- \\server\share[\relativepath]
  34. e.g. \\myserver\myshare or \\myserver\myshare\mydir
  35. (2) ABS path -- x:[\relativepath]
  36. where x: is either local or redirected
  37. e.g. x:\bar\boo or x:\ or x:
  38. Assumptions :
  39. (a) constructed with \\computer\share\bar\boo
  40. (b) constructed with x:\bar\boo where x: is redirected to
  41. \\computer\share ( corresponds to c:\foo on \\computer )
  42. (c) constructed with c:\bar\boo where c: is a local drive
  43. and the local computer name is \\computer
  44. Notes:
  45. The results in (a) will be in ( ) , the results
  46. in (b) will be in [ ] and the results in (c) will be
  47. the same as (b) unless otherwise stated in { }.
  48. INTERFACE: NET_NAME - constructor, takes an optional parameter
  49. indicating what type of path it should be.
  50. If not given, will try to see if the
  51. path is TYPE_PATH_UNC or TYPE_PATH_ABS.
  52. If it's neither one, then
  53. the constructor will fail with
  54. ERROR_INVALID_NAME.
  55. ~NET_NAME - destructor
  56. QueryComputerName - returns the name of the computer where
  57. the path physically resides.
  58. ( \\computer ) [ \\computer ]
  59. QueryShare - returns the share point
  60. ( share ) [ share ] { error: NERR_RemoteOnly }
  61. QueryDrive - returns the drive letter
  62. Empty string if constructed with UNC path
  63. ( "" ) [ x: ] { c: }
  64. QueryRelativePath - returns the relative path minus
  65. the drive letter or \\computer\share.
  66. ( Might be empty )
  67. ( bar\boo ) [ bar\boo ]
  68. QueryLastComponent - returns the last component
  69. ( boo ) [ boo ]
  70. QueryServerShare - returns \\computer\share if not constructed
  71. with local absolute path.
  72. ( \\computer\share )
  73. [ \\computer\myshare ]
  74. { error: NERR_RemoteOnly }
  75. QueryUNCPath - returns UNC path if not constructed with local
  76. absolute path.
  77. ( \\computer\share\bar\boo )
  78. [ \\computer\share\bar\boo ]
  79. { error: NERR_RemoteOnly }
  80. QueryLocalPath - returns the local path of the resource
  81. on the \\computer
  82. ( c:\foo\bar\boo )
  83. [ c:\foo\bar\boo ]
  84. { c:\bar\boo }
  85. QueryLocalDrive - returns the device of the resource
  86. on the \\computer
  87. ( c: ) [ c: ] { c: }
  88. QueryType - returns the type of the path, UNC path or
  89. absolute path
  90. ( TYPE_PATH_UNC ) [ TYPE_PATH_ABS ]
  91. IsLocal - returns TRUE if path is local, FALSE otherwise
  92. IsSharable - returns TRUE if the path is on a server,
  93. FALSE otherwise
  94. PARENT: BASE
  95. USES: NLS_STR
  96. CAVEATS:
  97. NOTES: All methods are optimized so that there is no overhead of
  98. hitting the redirector unless necessary .
  99. HISTORY:
  100. Yi-HsinS 12/5/91 ChuckC's proposed NET_NAME class
  101. Combined FULL_SHARE_NAME, UNC_NAME
  102. and RELATIVE_PATH_NAME to form
  103. NET_NAME
  104. Yi-HsinS 12/15/91 Clean up for general use and
  105. hit the redirector only when necessary.
  106. **************************************************************************/
  107. DLL_CLASS NET_NAME : public BASE
  108. {
  109. private:
  110. NETNAME_TYPE _netNameType;
  111. NLS_STR _nlsComputer;
  112. NLS_STR _nlsShare;
  113. NLS_STR _nlsRelativePath;
  114. NLS_STR _nlsDrive;
  115. NLS_STR _nlsLocalPath;
  116. // Use UNINITIALIZED_BOOL instead of BOOL because we need a value
  117. // indicating it's not initialized yet.
  118. UNINITIALIZED_BOOL _fLocal;
  119. // Use UNINITIALIZED_BOOL instead of BOOL because we need a value
  120. // indicating it's not initialized yet.
  121. UNINITIALIZED_BOOL _fSharable;
  122. // Set the members of a UNC path
  123. APIERR SetUNCPath( const TCHAR *pszNetName );
  124. // Set the members of an absolute path
  125. APIERR SetABSPath( const TCHAR *pszNetName );
  126. // Get the device x: information if constructed with x:\..\..
  127. APIERR GetDeviceInfo( void );
  128. public:
  129. NET_NAME( const TCHAR *pszNetName, NETNAME_TYPE netNameType = TYPE_UNKNOWN );
  130. ~NET_NAME();
  131. APIERR QueryComputerName( NLS_STR *pnlsComp );
  132. APIERR QueryShare( NLS_STR *pnlsShare );
  133. APIERR QueryDrive( NLS_STR *pnlsDrive );
  134. APIERR QueryRelativePath( NLS_STR *pnlsRelPath );
  135. APIERR QueryLastComponent( NLS_STR *pnlsLastComp );
  136. APIERR QueryServerShare( NLS_STR *pnlsServerShare );
  137. APIERR QueryUNCPath( NLS_STR *pnlsUNCPath );
  138. APIERR QueryLocalPath( NLS_STR *pnlsLocalPath );
  139. APIERR QueryLocalDrive( NLS_STR *pnlsLocalDrive );
  140. NETNAME_TYPE QueryType( void )
  141. { return _netNameType; }
  142. BOOL IsLocal( APIERR *perr );
  143. BOOL IsSharable( APIERR *perr );
  144. };
  145. #endif