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.

297 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 1996-1998 Microsoft Corporation
  3. Module Name :
  4. simplemb.hxx
  5. Abstract:
  6. based in mb.hxx from iisrearc
  7. This module defines the USER-level wrapper class for access to the
  8. metabase. It uses the UNICODE DCOM API for Metabase
  9. Author:
  10. Environment:
  11. Win32 - User Mode
  12. Project:
  13. Internet Server DLL
  14. Revision History:
  15. MuraliK 03-Nov-1998
  16. --*/
  17. #ifndef _SIMPLE_MB_HXX_
  18. #define _SIMPPLE_MB_HXX_
  19. #include "buffer.hxx"
  20. #if !defined( dllexp)
  21. #define dllexp __declspec( dllexport)
  22. #endif // !defined( dllexp)
  23. /************************************************************
  24. * Type Definitions
  25. ************************************************************/
  26. class SimpleMB {
  27. public:
  28. SimpleMB( IMSAdminBase * pAdminBase);
  29. ~SimpleMB(void);
  30. //
  31. // Metabase operations: Open, Close & Save ops
  32. //
  33. inline BOOL
  34. Open( LPCWSTR pwszPath,
  35. DWORD dwFlags = METADATA_PERMISSION_READ );
  36. BOOL Open( METADATA_HANDLE hOpenRoot OPTIONAL,
  37. LPCWSTR pwszPath,
  38. DWORD dwFlags = METADATA_PERMISSION_READ );
  39. BOOL Close(void);
  40. BOOL Save(void);
  41. // ------------------------------------------
  42. // Operations on the metadata objects: enum, add, delete
  43. // ------------------------------------------
  44. BOOL GetDataSetNumber( IN LPCWSTR pszPath,
  45. OUT DWORD * pdwDataSetNumber );
  46. BOOL EnumObjects( IN LPCWSTR pszPath,
  47. OUT LPWSTR pszName,
  48. IN DWORD dwIndex );
  49. BOOL AddObject( IN LPCWSTR pszPath);
  50. BOOL DeleteObject( IN LPCWSTR pszPath);
  51. BOOL GetSystemChangeNumber( DWORD *pdwChangeNumber );
  52. METADATA_HANDLE QueryHandle( VOID ) const { return m_hMBPath; }
  53. IMSAdminBase * QueryAdminBase( VOID ) const { return m_pAdminBase; }
  54. BOOL GetAll( IN LPCWSTR pszPath,
  55. IN DWORD dwFlags,
  56. IN DWORD dwUserType,
  57. OUT BUFFER * pBuff,
  58. OUT DWORD * pcRecords,
  59. OUT DWORD * pdwDataSetNumber );
  60. BOOL DeleteData(IN LPCWSTR pszPath,
  61. IN DWORD dwPropID,
  62. IN DWORD dwUserType,
  63. IN DWORD dwDataType
  64. );
  65. // ------------------------------------------
  66. // Set operations on the Metabase object
  67. // ------------------------------------------
  68. BOOL SetData( IN LPCWSTR pszPath,
  69. IN DWORD dwPropID,
  70. IN DWORD dwUserType,
  71. IN DWORD dwDataType,
  72. IN VOID * pvData,
  73. IN DWORD cbData,
  74. IN DWORD dwFlags = METADATA_INHERIT );
  75. inline
  76. BOOL SetDword( IN LPCWSTR pszPath,
  77. IN DWORD dwPropID,
  78. DWORD dwUserType,
  79. DWORD dwValue,
  80. DWORD dwFlags = METADATA_INHERIT );
  81. inline
  82. BOOL SetString( IN LPCWSTR pszPath,
  83. DWORD dwPropID,
  84. DWORD dwUserType,
  85. IN LPCWSTR pszValue,
  86. DWORD dwFlags = METADATA_INHERIT );
  87. // ------------------------------------------
  88. // Get operations on the Metabase object
  89. // ------------------------------------------
  90. BOOL GetData( IN LPCWSTR pszPath,
  91. IN DWORD dwPropID,
  92. IN DWORD dwUserType,
  93. IN DWORD dwDataType,
  94. OUT VOID * pvData,
  95. IN OUT DWORD * pcbData,
  96. IN DWORD dwFlags = METADATA_INHERIT );
  97. BOOL GetDataPaths(IN LPCWSTR pszPath,
  98. IN DWORD dwPropID,
  99. IN DWORD dwDataType,
  100. OUT BUFFER * pBuff );
  101. inline
  102. BOOL GetDword( IN LPCWSTR pszPath,
  103. IN DWORD dwPropID,
  104. IN DWORD dwUserType,
  105. OUT DWORD * pdwValue,
  106. IN DWORD dwFlags = METADATA_INHERIT );
  107. // Get DWORD, substitue a default if available.
  108. inline
  109. VOID GetDword( IN LPCWSTR pszPath,
  110. IN DWORD dwPropID,
  111. IN DWORD dwUserType,
  112. IN DWORD dwDefaultValue,
  113. OUT DWORD * pdwValue,
  114. IN DWORD dwFlags = METADATA_INHERIT
  115. );
  116. inline BOOL
  117. GetString( IN LPCWSTR pszPath,
  118. IN DWORD dwPropID,
  119. IN DWORD dwUserType,
  120. OUT LPWSTR pszValue,
  121. OUT DWORD * pcbValue,
  122. IN DWORD dwFlags = METADATA_INHERIT );
  123. BOOL GetBuffer( LPCWSTR pszPath,
  124. DWORD dwPropID,
  125. DWORD dwUserType,
  126. BUFFER* pbu,
  127. LPDWORD pdwL,
  128. DWORD dwFlags = METADATA_INHERIT )
  129. {
  130. *pdwL = pbu->QuerySize();
  131. TryAgain:
  132. if ( GetData( pszPath,
  133. dwPropID,
  134. dwUserType,
  135. BINARY_METADATA,
  136. pbu->QueryPtr(),
  137. pdwL,
  138. dwFlags ) )
  139. {
  140. return TRUE;
  141. }
  142. else if ( GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
  143. pbu->Resize( *pdwL ) )
  144. {
  145. goto TryAgain;
  146. }
  147. return FALSE;
  148. }
  149. private:
  150. IMSAdminBase * m_pAdminBase;
  151. METADATA_HANDLE m_hMBPath;
  152. };
  153. inline BOOL
  154. SimpleMB::GetDword( IN LPCWSTR pszPath,
  155. IN DWORD dwPropID,
  156. IN DWORD dwUserType,
  157. OUT DWORD * pdwValue,
  158. IN DWORD dwFlags )
  159. {
  160. DWORD cb = sizeof(DWORD);
  161. return GetData( pszPath,
  162. dwPropID,
  163. dwUserType,
  164. DWORD_METADATA,
  165. pdwValue,
  166. &cb,
  167. dwFlags );
  168. }
  169. inline VOID
  170. SimpleMB::GetDword( IN LPCWSTR pszPath,
  171. IN DWORD dwPropID,
  172. IN DWORD dwUserType,
  173. IN DWORD dwDefaultValue,
  174. OUT DWORD * pdwValue,
  175. IN DWORD dwFlags
  176. )
  177. {
  178. DWORD cb = sizeof(DWORD);
  179. if ( !GetData( pszPath,
  180. dwPropID,
  181. dwUserType,
  182. DWORD_METADATA,
  183. pdwValue,
  184. &cb,
  185. dwFlags )
  186. ) {
  187. *pdwValue = dwDefaultValue;
  188. }
  189. } // SimpleMB::GetDword()
  190. inline BOOL
  191. SimpleMB::GetString( IN LPCWSTR pszPath,
  192. IN DWORD dwPropID,
  193. IN DWORD dwUserType,
  194. OUT LPWSTR pszValue,
  195. OUT DWORD * pcbValue,
  196. IN DWORD dwFlags )
  197. {
  198. return GetData( pszPath,
  199. dwPropID,
  200. dwUserType,
  201. STRING_METADATA,
  202. pszValue,
  203. pcbValue,
  204. dwFlags );
  205. } // SimpleMB::GetString()
  206. inline BOOL
  207. SimpleMB::SetDword( IN LPCWSTR pszPath,
  208. IN DWORD dwPropID,
  209. IN DWORD dwUserType,
  210. IN DWORD dwValue,
  211. IN DWORD dwFlags )
  212. {
  213. return SetData( pszPath,
  214. dwPropID,
  215. dwUserType,
  216. DWORD_METADATA,
  217. (PVOID) &dwValue,
  218. sizeof( DWORD ),
  219. dwFlags );
  220. }
  221. inline BOOL
  222. SimpleMB::SetString( IN LPCWSTR pszPath,
  223. IN DWORD dwPropID,
  224. IN DWORD dwUserType,
  225. IN LPCWSTR pszValue,
  226. IN DWORD dwFlags )
  227. {
  228. return SetData( pszPath,
  229. dwPropID,
  230. dwUserType,
  231. STRING_METADATA,
  232. (PVOID ) pszValue,
  233. (DWORD) (wcslen(pszValue) + 1) * sizeof(WCHAR),
  234. dwFlags );
  235. }
  236. inline BOOL
  237. SimpleMB::Open( LPCWSTR pwszPath,
  238. DWORD dwFlags )
  239. {
  240. return Open( METADATA_MASTER_ROOT_HANDLE,
  241. pwszPath,
  242. dwFlags );
  243. }
  244. #endif // _MB_HXX_