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.

386 lines
9.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: cpropmgr.hxx
  7. //
  8. // Contents: Header for property manager - object that implements/helps
  9. // implement IUMIPropList functions.
  10. // The property manager needs to be initialized in one of 2 modes
  11. // 1) PropertyCache mode in which case it uses the objects existing
  12. // property cache to provide IUMIPropList support and
  13. // 2) Interface property mode in which case a list of the properties,
  14. // this object should support is passed in (refer to constructor
  15. // for complete details).
  16. //
  17. // History: 02-07-00 AjayR Created.
  18. //
  19. //----------------------------------------------------------------------------
  20. #ifndef __CPROPMGR_H__
  21. #define __CPROPMGR_H__
  22. //
  23. // Global fucntions that are used to free the umi properties/values arrays
  24. //
  25. HRESULT FreeOneUmiProperty(UMI_PROPERTY *pUmiProperty);
  26. HRESULT FreeUmiPropertyValues(UMI_PROPERTY_VALUES *pUmiProps);
  27. HRESULT ConvertUmiPropCodeToLdapCode(ULONG uUmiFlags, DWORD &dwLdapOpCode);
  28. HRESULT ConvertLdapCodeToUmiPropCode(DWORD dwLdapCode, ULONG &uUmiFlags);
  29. HRESULT ConvertLdapSyntaxIdToUmiType(DWORD dwLdapSyntax, ULONG &uUmiType);
  30. //
  31. // Default number of properties in prop mgr mode.
  32. //
  33. #define MAX_PROPMGR_PROP_COUNT 15
  34. typedef ULONG UMIPROPS;
  35. typedef LONG UMIPROP;
  36. typedef struct _intfproperty{
  37. LPWSTR pszPropertyName; // Property name.
  38. DWORD dwNumElements;
  39. DWORD dwFlags; // Status of the value.
  40. DWORD dwSyntaxId; // Syntax Id of the stored value.
  41. PUMI_PROPERTY pUmiProperty; // Umi property with values.
  42. }INTF_PROPERTY, *PINTF_PROPERTY;
  43. const DWORD OPERATION_CODE_READABLE = 1;
  44. const DWORD OPERATION_CODE_WRITEABLE = 2;
  45. const DWORD OPERATION_CODE_READWRITE = 3;
  46. //
  47. // These are the codes used by the property cache.
  48. //
  49. #define PROPERTY_INIT 0
  50. #define PROPERTY_UPDATE 1
  51. #define PROPERTY_ADD 2
  52. #define PROPERTY_DELETE 3
  53. #define PROPERTY_DELETE_VALUE 4
  54. class CPropertyManager : INHERIT_TRACKING,
  55. public IUmiPropList
  56. {
  57. public:
  58. //
  59. // IUknown support.
  60. //
  61. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR* ppvObj) ;
  62. //
  63. // We cannot use standard refCounting cause the release method is
  64. // different. This should be similar to the DECLARE_STD_REFCOUNTING
  65. // except that in release we release a ref to the pIADs also.
  66. //
  67. STDMETHOD_(ULONG, AddRef)()
  68. {
  69. if (!_fPropCacheMode && _pUnk) {
  70. //
  71. // This is to make sure we are not left with a
  72. // dangling IADs ref.
  73. //
  74. _pUnk->AddRef();
  75. }
  76. # if DBG == 1
  77. return StdAddRef();
  78. #else
  79. //
  80. // We need to use the stuff directly from the definition as
  81. // the fn is not defined for fre builds.
  82. //
  83. InterlockedIncrement((long*)&_ulRefs);
  84. return _ulRefs;
  85. #endif
  86. };
  87. STDMETHOD_(ULONG, Release)()
  88. {
  89. #if DBG == 1
  90. //
  91. // Delete is handled by the owning IADs Object.
  92. //
  93. ULONG ul = StdRelease();
  94. //
  95. // Need to releas the ref only if we are in intf prop mode.
  96. // In the propCache mode, this object does not need to be ref
  97. // counted cause it's lifetime is similar to that of the
  98. // owning object (one implementing IADs).
  99. //
  100. if (!_fPropCacheMode && _pUnk) {
  101. _pUnk->Release();
  102. }
  103. return ul;
  104. #else
  105. InterlockedDecrement((long*)&_ulRefs);
  106. if (!_fPropCacheMode && _pUnk) {
  107. _pUnk->Release();
  108. }
  109. return _ulRefs;
  110. #endif
  111. };
  112. //
  113. // IUmiPropList methods.
  114. //
  115. STDMETHOD(Put)(
  116. IN LPCWSTR pszName,
  117. IN ULONG uFlags,
  118. OUT UMI_PROPERTY_VALUES *pProp
  119. );
  120. STDMETHOD(Get)(
  121. IN LPCWSTR pszName,
  122. IN ULONG uFlags,
  123. OUT UMI_PROPERTY_VALUES **pProp
  124. );
  125. STDMETHOD(GetAt)(
  126. IN LPCWSTR pszName,
  127. IN ULONG uFlags,
  128. IN ULONG uBufferLength,
  129. OUT LPVOID pExistingMem
  130. );
  131. STDMETHOD(GetAs)(
  132. IN LPCWSTR pszName,
  133. IN ULONG uFlags,
  134. IN ULONG uCoercionType,
  135. OUT UMI_PROPERTY_VALUES **pProp
  136. );
  137. STDMETHOD (Delete)(
  138. IN LPCWSTR pszUrl,
  139. IN OPTIONAL ULONG uFlags
  140. );
  141. STDMETHOD(FreeMemory)(
  142. ULONG uReserved,
  143. LPVOID pMem
  144. );
  145. STDMETHOD(GetProps)(
  146. IN LPCWSTR *pszNames,
  147. IN ULONG uNameCount,
  148. IN ULONG uFlags,
  149. OUT UMI_PROPERTY_VALUES **pProps
  150. );
  151. STDMETHOD(PutProps)(
  152. IN LPCWSTR *pszNames,
  153. IN ULONG uNameCount,
  154. IN ULONG uFlags,
  155. IN UMI_PROPERTY_VALUES *pProps
  156. );
  157. STDMETHOD(PutFrom)(
  158. IN LPCWSTR pszName,
  159. IN ULONG uFlags,
  160. IN ULONG uBufferLength,
  161. IN LPVOID pExistingMem
  162. );
  163. //
  164. // Other public methods.
  165. //
  166. CPropertyManager::
  167. CPropertyManager();
  168. CPropertyManager::
  169. ~CPropertyManager();
  170. //
  171. // Use this to initialize with property cache object.
  172. //
  173. static
  174. HRESULT
  175. CPropertyManager::
  176. CreatePropertyManager(
  177. IADs *pADsObj,
  178. IUnknown *pUnk,
  179. CPropertyCache *pPropCache,
  180. CCredentials *pCreds,
  181. LPWSTR pszServerName,
  182. CPropertyManager FAR * FAR * ppPropertyManager = NULL
  183. );
  184. static
  185. HRESULT
  186. CPropertyManager::
  187. CreatePropertyManager(
  188. IUnknown *pUnk,
  189. IUnknown *pADs,
  190. CCredentials *pCredentials,
  191. INTF_PROP_DATA intfPropTable[],
  192. CPropertyManager FAR * FAR * ppPropertyManager
  193. );
  194. //
  195. // Helper functions that are not part of the interfaces supported.
  196. //
  197. HRESULT
  198. CPropertyManager::GetStringProperty(
  199. LPCWSTR pszPropName,
  200. LPWSTR *pszRetStrVal
  201. );
  202. HRESULT
  203. CPropertyManager::GetLongProperty(
  204. LPCWSTR pszPropName,
  205. LONG *plVal
  206. );
  207. HRESULT
  208. CPropertyManager::GetBoolProperty(
  209. LPCWSTR pszPropName,
  210. BOOL *pfFlag
  211. );
  212. HRESULT
  213. CPropertyManager::GetLastStatus(
  214. ULONG uFlags,
  215. ULONG *puSpecificStatus,
  216. REFIID riid,
  217. LPVOID *pStatusObj
  218. );
  219. //
  220. // Helper to delete SD on commit calls if needed.
  221. //
  222. HRESULT
  223. CPropertyManager::DeleteSDIfPresent();
  224. protected:
  225. //
  226. // These are internal methods.
  227. //
  228. HRESULT
  229. CPropertyManager::
  230. AddProperty(
  231. LPCWSTR szPropertyName,
  232. UMI_PROPERTY umiProperty
  233. );
  234. HRESULT
  235. CPropertyManager::
  236. UpdateProperty(
  237. DWORD dwIndex,
  238. UMI_PROPERTY umiProperty
  239. );
  240. HRESULT
  241. CPropertyManager::
  242. FindProperty(
  243. LPCWSTR szPropertyName,
  244. PDWORD pdwIndex
  245. );
  246. HRESULT
  247. CPropertyManager::
  248. DeleteProperty(
  249. DWORD dwIndex
  250. );
  251. VOID
  252. CPropertyManager::
  253. flushpropertycache();
  254. HRESULT
  255. CPropertyManager::
  256. ClearAllPropertyFlags(VOID);
  257. //
  258. // Way to get a list of the names of the properties.
  259. //
  260. HRESULT
  261. CPropertyManager::
  262. GetPropertyNames(PUMI_PROPERTY_VALUES *pUmiProps);
  263. //
  264. // Way to get a list of the names and types for schema objects.
  265. //
  266. HRESULT
  267. CPropertyManager::
  268. GetPropertyNamesSchema(PUMI_PROPERTY_VALUES *pUmiProps);
  269. //
  270. // Add Property to table and return index of entry.
  271. //
  272. HRESULT
  273. CPropertyManager::
  274. AddToTable(
  275. LPCWSTR pszPropertyName,
  276. PDWORD pdwIndex
  277. );
  278. //
  279. // Check if this is a valid interfaceProperty.
  280. //
  281. BOOL
  282. CPropertyManager::
  283. VerifyIfValidProperty(
  284. LPCWSTR pszPropertyName,
  285. UMI_PROPERTY umiProperty
  286. );
  287. //
  288. // More helper routines.
  289. //
  290. HRESULT
  291. CPropertyManager::GetIndexInStaticTable(
  292. LPCWSTR pszName,
  293. DWORD &dwIndex
  294. );
  295. void
  296. CPropertyManager::SetLastStatus(ULONG ulStatus){
  297. _ulStatus = ulStatus;
  298. }
  299. //
  300. // Does all the hard work for interface properties.
  301. //
  302. HRESULT
  303. CPropertyManager::GetInterfaceProperty(
  304. LPCWSTR pszName,
  305. ULONG uFlags,
  306. UMI_PROPERTY_VALUES **ppProp,
  307. DWORD dwTableIndex
  308. );
  309. protected:
  310. //
  311. // Not all are used in all cases. If in propCache mode, a lot of
  312. // these are not used, the _pPropCache already has the info we
  313. // need.
  314. // Likewise if we are in intfProperties mode, the _pPropCache is
  315. // not valid, the other member variables have useful information
  316. // though.
  317. //
  318. DWORD _dwMaxProperties;
  319. CPropertyCache * _pPropCache;
  320. PINTF_PROPERTY _pIntfProperties;
  321. DWORD _dwMaxLimit;
  322. BOOL _fPropCacheMode;
  323. INTF_PROP_DATA * _pStaticPropData;
  324. ULONG _ulStatus;
  325. IADs* _pIADs;
  326. IUnknown* _pUnk;
  327. //
  328. // All these are part of the owning object, do not free.
  329. //
  330. CCredentials* _pCreds;
  331. LPWSTR _pszServerName;
  332. };
  333. #endif // __CPROPMGR_H__