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.

366 lines
10 KiB

  1. /*++
  2. Copyright (c) 1996-1998 Microsoft Corporation
  3. Module Name :
  4. mb.hxx
  5. Abstract:
  6. This module defines the USER-level wrapper class for access to the
  7. metabase. It uses the UNICODE DCOM API for Metabase
  8. Author:
  9. Environment:
  10. Win32 - User Mode
  11. Project:
  12. Internet Server DLL
  13. Revision History:
  14. MuraliK 03-Nov-1998
  15. --*/
  16. #ifndef _MB_HXX_
  17. #define _MB_HXX_
  18. #include "irtlmisc.h"
  19. #include "buffer.hxx"
  20. #include "string.hxx"
  21. #include "multisz.hxx"
  22. /************************************************************
  23. * Type Definitions
  24. ************************************************************/
  25. class IRTL_DLLEXP MB {
  26. public:
  27. MB( IMSAdminBase * pAdminBase);
  28. ~MB(void);
  29. //
  30. // Metabase operations: Open, Close & Save ops
  31. //
  32. inline BOOL
  33. Open( LPCWSTR pwszPath,
  34. DWORD dwFlags = METADATA_PERMISSION_READ );
  35. BOOL Open( METADATA_HANDLE hOpenRoot OPTIONAL,
  36. LPCWSTR pwszPath,
  37. DWORD dwFlags = METADATA_PERMISSION_READ );
  38. BOOL Close(void);
  39. BOOL Save(void);
  40. // ------------------------------------------
  41. // Operations on the metadata objects: enum, add, delete
  42. // ------------------------------------------
  43. BOOL GetDataSetNumber( IN LPCWSTR pszPath,
  44. OUT DWORD * pdwDataSetNumber );
  45. BOOL EnumObjects( IN LPCWSTR pszPath,
  46. OUT LPWSTR pszName,
  47. IN DWORD dwIndex );
  48. BOOL AddObject( IN LPCWSTR pszPath);
  49. BOOL DeleteObject( IN LPCWSTR pszPath);
  50. BOOL GetSystemChangeNumber( DWORD *pdwChangeNumber );
  51. METADATA_HANDLE QueryHandle( VOID ) const { return m_hMBPath; }
  52. IMSAdminBase * QueryAdminBase( VOID ) const { return m_pAdminBase; }
  53. BOOL GetAll( IN LPCWSTR pszPath,
  54. IN DWORD dwFlags,
  55. IN DWORD dwUserType,
  56. OUT BUFFER * pBuff,
  57. OUT DWORD * pcRecords,
  58. OUT DWORD * pdwDataSetNumber );
  59. BOOL DeleteData(IN LPCWSTR pszPath,
  60. IN DWORD dwPropID,
  61. IN DWORD dwUserType,
  62. IN DWORD dwDataType
  63. );
  64. // ------------------------------------------
  65. // Set operations on the Metabase object
  66. // ------------------------------------------
  67. BOOL SetData( IN LPCWSTR pszPath,
  68. IN DWORD dwPropID,
  69. IN DWORD dwUserType,
  70. IN DWORD dwDataType,
  71. IN VOID * pvData,
  72. IN DWORD cbData,
  73. IN DWORD dwFlags = METADATA_INHERIT );
  74. inline
  75. BOOL SetDword( IN LPCWSTR pszPath,
  76. IN DWORD dwPropID,
  77. DWORD dwUserType,
  78. DWORD dwValue,
  79. DWORD dwFlags = METADATA_INHERIT );
  80. inline
  81. BOOL SetString( IN LPCWSTR pszPath,
  82. DWORD dwPropID,
  83. DWORD dwUserType,
  84. IN LPCWSTR pszValue,
  85. DWORD dwFlags = METADATA_INHERIT );
  86. #if NOT_IMPLEMENTED
  87. inline
  88. BOOL SetMultiSZ( IN LPCWSTR pszPath,
  89. DWORD dwPropID,
  90. DWORD dwUserType,
  91. IN LPCWSTR pszValue, // should be double-null terminated
  92. DWORD dwFlags = METADATA_INHERIT );
  93. #endif // NOT_IMPLEMENTED
  94. // ------------------------------------------
  95. // Get operations on the Metabase object
  96. // ------------------------------------------
  97. BOOL GetData( IN LPCWSTR pszPath,
  98. IN DWORD dwPropID,
  99. IN DWORD dwUserType,
  100. IN DWORD dwDataType,
  101. OUT VOID * pvData,
  102. IN OUT DWORD * pcbData,
  103. IN DWORD dwFlags = METADATA_INHERIT );
  104. BOOL GetDataPaths(IN LPCWSTR pszPath,
  105. IN DWORD dwPropID,
  106. IN DWORD dwDataType,
  107. OUT BUFFER * pBuff );
  108. BOOL GetChildPaths(IN LPCWSTR pszPath,
  109. OUT BUFFER * pBuff );
  110. inline
  111. BOOL GetDword( IN LPCWSTR pszPath,
  112. IN DWORD dwPropID,
  113. IN DWORD dwUserType,
  114. OUT DWORD * pdwValue,
  115. IN DWORD dwFlags = METADATA_INHERIT );
  116. // Get DWORD, substitue a default if available.
  117. inline
  118. VOID GetDword( IN LPCWSTR pszPath,
  119. IN DWORD dwPropID,
  120. IN DWORD dwUserType,
  121. IN DWORD dwDefaultValue,
  122. OUT DWORD * pdwValue,
  123. IN DWORD dwFlags = METADATA_INHERIT
  124. );
  125. inline BOOL
  126. GetString( IN LPCWSTR pszPath,
  127. IN DWORD dwPropID,
  128. IN DWORD dwUserType,
  129. OUT LPWSTR pszValue,
  130. OUT DWORD * pcbValue,
  131. IN DWORD dwFlags = METADATA_INHERIT );
  132. BOOL
  133. GetStr( IN LPCWSTR pszPath,
  134. IN DWORD dwPropID,
  135. IN DWORD dwUserType,
  136. OUT STRU * pstrValue,
  137. IN DWORD dwFlags = METADATA_INHERIT,
  138. IN LPCWSTR pszDefault = NULL );
  139. BOOL
  140. GetMultisz( LPCWSTR pszPath,
  141. DWORD dwPropID,
  142. DWORD dwUserType,
  143. MULTISZ * pMultiszValue,
  144. DWORD dwFlags = METADATA_INHERIT );
  145. BOOL GetBuffer( LPCWSTR pszPath,
  146. DWORD dwPropID,
  147. DWORD dwUserType,
  148. BUFFER* pbu,
  149. LPDWORD pdwL,
  150. DWORD dwFlags = METADATA_INHERIT )
  151. {
  152. *pdwL = pbu->QuerySize();
  153. TryAgain:
  154. if ( GetData( pszPath,
  155. dwPropID,
  156. dwUserType,
  157. BINARY_METADATA,
  158. pbu->QueryPtr(),
  159. pdwL,
  160. dwFlags ) )
  161. {
  162. return TRUE;
  163. }
  164. else if ( GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
  165. pbu->Resize( *pdwL ) )
  166. {
  167. goto TryAgain;
  168. }
  169. return FALSE;
  170. }
  171. private:
  172. IMSAdminBase * m_pAdminBase;
  173. METADATA_HANDLE m_hMBPath;
  174. };
  175. inline BOOL
  176. MB::GetDword( IN LPCWSTR pszPath,
  177. IN DWORD dwPropID,
  178. IN DWORD dwUserType,
  179. OUT DWORD * pdwValue,
  180. IN DWORD dwFlags )
  181. {
  182. DWORD cb = sizeof(DWORD);
  183. return GetData( pszPath,
  184. dwPropID,
  185. dwUserType,
  186. DWORD_METADATA,
  187. pdwValue,
  188. &cb,
  189. dwFlags );
  190. }
  191. inline VOID
  192. MB::GetDword( IN LPCWSTR pszPath,
  193. IN DWORD dwPropID,
  194. IN DWORD dwUserType,
  195. IN DWORD dwDefaultValue,
  196. OUT DWORD * pdwValue,
  197. IN DWORD dwFlags
  198. )
  199. {
  200. DWORD cb = sizeof(DWORD);
  201. if ( !GetData( pszPath,
  202. dwPropID,
  203. dwUserType,
  204. DWORD_METADATA,
  205. pdwValue,
  206. &cb,
  207. dwFlags )
  208. ) {
  209. *pdwValue = dwDefaultValue;
  210. }
  211. } // MB::GetDword()
  212. inline BOOL
  213. MB::GetString( IN LPCWSTR pszPath,
  214. IN DWORD dwPropID,
  215. IN DWORD dwUserType,
  216. OUT LPWSTR pszValue,
  217. OUT DWORD * pcbValue,
  218. IN DWORD dwFlags )
  219. {
  220. return GetData( pszPath,
  221. dwPropID,
  222. dwUserType,
  223. STRING_METADATA,
  224. pszValue,
  225. pcbValue,
  226. dwFlags );
  227. } // MB::GetString()
  228. inline BOOL
  229. MB::SetDword( IN LPCWSTR pszPath,
  230. IN DWORD dwPropID,
  231. IN DWORD dwUserType,
  232. IN DWORD dwValue,
  233. IN DWORD dwFlags )
  234. {
  235. return SetData( pszPath,
  236. dwPropID,
  237. dwUserType,
  238. DWORD_METADATA,
  239. (PVOID) &dwValue,
  240. sizeof( DWORD ),
  241. dwFlags );
  242. }
  243. inline BOOL
  244. MB::SetString( IN LPCWSTR pszPath,
  245. IN DWORD dwPropID,
  246. IN DWORD dwUserType,
  247. IN LPCWSTR pszValue,
  248. IN DWORD dwFlags )
  249. {
  250. return SetData( pszPath,
  251. dwPropID,
  252. dwUserType,
  253. STRING_METADATA,
  254. (PVOID ) pszValue,
  255. (DWORD) (wcslen(pszValue) + 1) * sizeof(WCHAR),
  256. dwFlags );
  257. }
  258. #if NOT_IMPLEMENTED
  259. inline BOOL
  260. MB::SetMultiSZ( IN LPCWSTR pszPath,
  261. IN DWORD dwPropID,
  262. IN DWORD dwUserType,
  263. IN LPCWSTR pszValue, // should be double-null terminated
  264. IN DWORD dwFlags )
  265. {
  266. return SetData( pszPath,
  267. dwPropID,
  268. dwUserType,
  269. MULTISZ_METADATA,
  270. (PVOID ) pszValue,
  271. 0, // string length ignored for inprocess clients
  272. dwFlags );
  273. }
  274. #endif // NOT_IMPLEMENTED
  275. # ifdef FULL_MB
  276. //
  277. // Simple wrapper class around the metabase APIs
  278. //
  279. // The Metabase Interface pointer is assumed to remain valid for the lifetime
  280. // of this object.
  281. //
  282. // The character counts for paths should include the terminating '\0'.
  283. //
  284. //
  285. class MB
  286. {
  287. public:
  288. private:
  289. IMDCOM * _pMBCom;
  290. METADATA_HANDLE _hMB;
  291. };
  292. # endif // FULL_MB
  293. inline BOOL
  294. MB::Open( LPCWSTR pwszPath,
  295. DWORD dwFlags )
  296. {
  297. return Open( METADATA_MASTER_ROOT_HANDLE,
  298. pwszPath,
  299. dwFlags );
  300. }
  301. #endif // _MB_HXX_