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.

410 lines
12 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. PathParse.H
  5. Abstract:
  6. Implements the default object path parser.
  7. History:
  8. a-davj 5-feb-00 Created.
  9. --*/
  10. #ifndef _PATHPARSE_H_
  11. #define _PATHPARSE_H_
  12. #include "genlex.h"
  13. #include <wmiutils.h>
  14. #include <umi.h>
  15. #include "wbemcli.h"
  16. #include "flexarry.h"
  17. typedef LPVOID * PPVOID;
  18. class CSafeInCritSec : public CInCritSec
  19. {
  20. public:
  21. CSafeInCritSec(CRITICAL_SECTION * pcs):CInCritSec(pcs){};
  22. ~CSafeInCritSec(){};
  23. BOOL IsOK(){return true;};
  24. };
  25. class CRefCntCS
  26. {
  27. private:
  28. long m_lRef;
  29. CRITICAL_SECTION m_cs;
  30. HRESULT m_Status;
  31. public:
  32. CRefCntCS();
  33. ~CRefCntCS()
  34. {
  35. if(m_Status == S_OK)
  36. DeleteCriticalSection(&m_cs);
  37. }
  38. HRESULT GetStatus(){return m_Status;};
  39. long AddRef(void){long lRef = InterlockedIncrement(&m_lRef);return lRef;};
  40. long Release(void);
  41. CRITICAL_SECTION * GetCS(){return &m_cs;};
  42. };
  43. //***************************************************************************
  44. //
  45. // STRUCT NAME:
  46. //
  47. // CKeyRef
  48. //
  49. // DESCRIPTION:
  50. //
  51. // Holds information for a single key. Includes name, data, and data type.
  52. //
  53. //***************************************************************************
  54. struct CKeyRef
  55. {
  56. LPWSTR m_pName;
  57. DWORD m_dwType;
  58. DWORD m_dwSize;
  59. void * m_pData;
  60. CKeyRef();
  61. CKeyRef(LPCWSTR wszKeyName, DWORD dwType, DWORD dwSize, void * pData);
  62. HRESULT SetData(DWORD dwType, DWORD dwSize, void * pData);
  63. ~CKeyRef();
  64. // note that the caller is to free the returned string.
  65. LPWSTR GetValue(BOOL bQuotes=TRUE);
  66. DWORD GetValueSize();
  67. DWORD GetTotalSize();
  68. };
  69. //***************************************************************************
  70. //
  71. // CLASS NAME:
  72. //
  73. // CParsedComponent
  74. //
  75. // DESCRIPTION:
  76. //
  77. // Each namespace, scope and the class is represented by an instance of this. It holds
  78. // an array of CKeyRef objects and supports the IWbemPathKeyList interface.
  79. //
  80. //***************************************************************************
  81. class CParsedComponent : public IWbemPathKeyList
  82. {
  83. public:
  84. CParsedComponent(CRefCntCS *);
  85. ~CParsedComponent();
  86. friend class CDefPathParser;
  87. friend class CUmiPathParser;
  88. void ClearKeys ();
  89. HRESULT GetName(BSTR *pName);
  90. HRESULT Unparse(BSTR *pKey, bool bGetQuotes, bool bUseClassName);
  91. HRESULT GetComponentType(DWORD &dwType);
  92. BOOL AddKeyRef(CKeyRef* pAcquireRef);
  93. bool IsPossibleNamespace();
  94. bool IsInstance();
  95. HRESULT SetNS(LPCWSTR pName);
  96. //IUnknown members
  97. STDMETHODIMP QueryInterface(REFIID riid, PPVOID ppv)
  98. {
  99. *ppv=NULL;
  100. if (IID_IUnknown==riid || IID_IWbemPathKeyList==riid)
  101. *ppv=this;
  102. else if (riid == IID_IMarshal && m_pFTM)
  103. return m_pFTM->QueryInterface(riid, ppv);
  104. //postponed till Blackcomb if (IID_IUmiURLKeyList==riid)
  105. //postponed till Blackcomb *ppv = &m_UmiWrapper;
  106. if (NULL!=*ppv)
  107. {
  108. AddRef();
  109. return NOERROR;
  110. }
  111. return E_NOINTERFACE;
  112. };
  113. STDMETHODIMP_(ULONG) AddRef(void)
  114. {
  115. return InterlockedIncrement(&m_cRef);
  116. };
  117. STDMETHODIMP_(ULONG) Release(void)
  118. {
  119. long lRef = InterlockedDecrement(&m_cRef);
  120. if (0L == lRef)
  121. delete this;
  122. return lRef;
  123. };
  124. HRESULT STDMETHODCALLTYPE GetCount(
  125. /* [out] */ ULONG __RPC_FAR *puKeyCount);
  126. HRESULT STDMETHODCALLTYPE SetKey(
  127. /* [string][in] */ LPCWSTR wszName,
  128. /* [in] */ ULONG uFlags,
  129. /* [in] */ ULONG uCimType,
  130. /* [in] */ LPVOID pKeyVal);
  131. HRESULT STDMETHODCALLTYPE SetKey2(
  132. /* [string][in] */ LPCWSTR wszName,
  133. /* [in] */ ULONG uFlags,
  134. /* [in] */ ULONG uCimType,
  135. /* [in] */ VARIANT __RPC_FAR *pKeyVal);
  136. HRESULT STDMETHODCALLTYPE GetKey(
  137. /* [in] */ ULONG uKeyIx,
  138. /* [in] */ ULONG uFlags,
  139. /* [out][in] */ ULONG __RPC_FAR *puNameBufSize,
  140. /* [out][in] */ LPWSTR pszKeyName,
  141. /* [out][in] */ ULONG __RPC_FAR *puKeyValBufSize,
  142. /* [out][in] */ LPVOID pKeyVal,
  143. /* [out] */ ULONG __RPC_FAR *puApparentCimType);
  144. HRESULT STDMETHODCALLTYPE GetKey2(
  145. /* [in] */ ULONG uKeyIx,
  146. /* [in] */ ULONG uFlags,
  147. /* [out][in] */ ULONG __RPC_FAR *puNameBufSize,
  148. /* [out][in] */ LPWSTR pszKeyName,
  149. /* [out][in] */ VARIANT __RPC_FAR *pKeyValue,
  150. /* [out] */ ULONG __RPC_FAR *puApparentCimType);
  151. HRESULT STDMETHODCALLTYPE RemoveKey(
  152. /* [string][in] */ LPCWSTR wszName,
  153. /* [in] */ ULONG uFlags);
  154. HRESULT STDMETHODCALLTYPE RemoveAllKeys(
  155. /* [in] */ ULONG uFlags);
  156. HRESULT STDMETHODCALLTYPE MakeSingleton( boolean bSet);
  157. HRESULT STDMETHODCALLTYPE GetInfo(
  158. /* [in] */ ULONG uRequestedInfo,
  159. /* [out] */ ULONGLONG __RPC_FAR *puResponse);
  160. HRESULT STDMETHODCALLTYPE GetText(
  161. /* [in] */ long lFlags,
  162. /* [out][in] */ ULONG __RPC_FAR *puBuffLength,
  163. /* [string][out] */ LPWSTR pszText);
  164. private:
  165. BSTR m_sClassName;
  166. CFlexArray m_Keys;
  167. bool m_bSingleton;
  168. long m_cRef;
  169. CRefCntCS * m_pCS;
  170. IUnknown * m_pFTM;
  171. };
  172. //***************************************************************************
  173. //
  174. // CLASS NAME:
  175. //
  176. // CDefPathParser
  177. //
  178. // DESCRIPTION:
  179. //
  180. // Provides the default wmi path parser.
  181. //
  182. //***************************************************************************
  183. class CDefPathParser : public IWbemPath
  184. {
  185. public:
  186. CDefPathParser(void);
  187. ~CDefPathParser(void);
  188. DWORD GetNumComponents();
  189. bool IsEmpty(void);
  190. long GetNumNamespaces();
  191. void Empty(void);
  192. enum Status {UNINITIALIZED, BAD_STRING, EXECEPTION_THROWN, OK, FAILED_TO_INIT};
  193. BOOL ActualRelativeTest(LPWSTR wszMachine,
  194. LPWSTR wszNamespace,
  195. BOOL bChildrenOK);
  196. void InitEmpty(){};
  197. //IUnknown members
  198. STDMETHODIMP QueryInterface(REFIID riid, PPVOID ppv)
  199. {
  200. *ppv=NULL;
  201. if(m_dwStatus == FAILED_TO_INIT)
  202. return WBEM_E_OUT_OF_MEMORY;
  203. if(m_pCS == NULL)
  204. return E_NOINTERFACE;
  205. if (IID_IUnknown==riid || IID_IWbemPath==riid)
  206. *ppv=(IWbemPath *)this;
  207. else if (riid == IID_IMarshal && m_pFTM)
  208. return m_pFTM->QueryInterface(riid, ppv);
  209. if (NULL!=*ppv)
  210. {
  211. AddRef();
  212. return NOERROR;
  213. }
  214. return E_NOINTERFACE;
  215. };
  216. STDMETHODIMP_(ULONG) AddRef(void)
  217. {
  218. return InterlockedIncrement(&m_cRef);
  219. };
  220. STDMETHODIMP_(ULONG) Release(void)
  221. {
  222. long lRef = InterlockedDecrement(&m_cRef);
  223. if (0L == lRef)
  224. delete this;
  225. return lRef;
  226. };
  227. virtual HRESULT STDMETHODCALLTYPE SetText(
  228. /* [in] */ ULONG uMode,
  229. /* [in] */ LPCWSTR pszPath);
  230. virtual HRESULT STDMETHODCALLTYPE GetText(
  231. /* [in] */ long lFlags,
  232. /* [out][in] */ ULONG __RPC_FAR *puBuffLength,
  233. /* [string][out] */ LPWSTR pszText);
  234. virtual HRESULT STDMETHODCALLTYPE GetInfo(
  235. /* [in] */ ULONG uRequestedInfo,
  236. /* [out] */ ULONGLONG __RPC_FAR *puResponse);
  237. virtual HRESULT STDMETHODCALLTYPE SetServer(
  238. /* [string][in] */ LPCWSTR Name);
  239. virtual HRESULT STDMETHODCALLTYPE GetServer(
  240. /* [out][in] */ ULONG __RPC_FAR *puNameBufLength,
  241. /* [string][out] */ LPWSTR pName);
  242. virtual HRESULT STDMETHODCALLTYPE GetNamespaceCount(
  243. /* [out] */ ULONG __RPC_FAR *puCount);
  244. virtual HRESULT STDMETHODCALLTYPE SetNamespaceAt(
  245. /* [in] */ ULONG uIndex,
  246. /* [string][in] */ LPCWSTR pszName);
  247. virtual HRESULT STDMETHODCALLTYPE GetNamespaceAt(
  248. /* [in] */ ULONG uIndex,
  249. /* [out][in] */ ULONG __RPC_FAR *puNameBufLength,
  250. /* [string][out] */ LPWSTR pName);
  251. virtual HRESULT STDMETHODCALLTYPE RemoveNamespaceAt(
  252. /* [in] */ ULONG uIndex);
  253. virtual HRESULT STDMETHODCALLTYPE RemoveAllNamespaces( void);
  254. virtual HRESULT STDMETHODCALLTYPE GetScopeCount(
  255. /* [out] */ ULONG __RPC_FAR *puCount);
  256. virtual HRESULT STDMETHODCALLTYPE SetScope(
  257. unsigned long,unsigned short *);
  258. virtual HRESULT STDMETHODCALLTYPE SetScopeFromText(
  259. /* [in] */ ULONG uIndex,
  260. /* [in] */ LPWSTR pszText);
  261. virtual HRESULT STDMETHODCALLTYPE GetScope(
  262. /* [in] */ ULONG uIndex,
  263. /* [out][in] */ ULONG __RPC_FAR *puClassNameBufSize,
  264. /* [in] */ LPWSTR pszClass,
  265. /* [out] */ IWbemPathKeyList __RPC_FAR *__RPC_FAR *pKeyList);
  266. virtual HRESULT STDMETHODCALLTYPE GetScopeAsText(
  267. /* [in] */ ULONG uIndex,
  268. /* [out][in] */ ULONG __RPC_FAR *puTextBufSize,
  269. /* [out][in] */ LPWSTR pszText);
  270. virtual HRESULT STDMETHODCALLTYPE RemoveScope(
  271. /* [in] */ ULONG uIndex);
  272. virtual HRESULT STDMETHODCALLTYPE RemoveAllScopes( void);
  273. virtual HRESULT STDMETHODCALLTYPE SetClassName(
  274. /* [string][in] */ LPCWSTR Name);
  275. virtual HRESULT STDMETHODCALLTYPE GetClassName(
  276. /* [out][in] */ ULONG __RPC_FAR *puBuffLength,
  277. /* [string][out] */ LPWSTR pszName);
  278. virtual HRESULT STDMETHODCALLTYPE GetKeyList(
  279. /* [out] */ IWbemPathKeyList __RPC_FAR *__RPC_FAR *pOut);
  280. virtual HRESULT STDMETHODCALLTYPE CreateClassPart(
  281. /* [in] */ long lFlags,
  282. /* [string][in] */ LPCWSTR Name);
  283. virtual HRESULT STDMETHODCALLTYPE DeleteClassPart(
  284. /* [in] */ long lFlags);
  285. virtual BOOL STDMETHODCALLTYPE IsRelative(
  286. /* [string][in] */ LPWSTR wszMachine,
  287. /* [string][in] */ LPWSTR wszNamespace);
  288. virtual BOOL STDMETHODCALLTYPE IsRelativeOrChild(
  289. /* [string][in] */ LPWSTR wszMachine,
  290. /* [string][in] */ LPWSTR wszNamespace,
  291. /* [in] */ long lFlags);
  292. virtual BOOL STDMETHODCALLTYPE IsLocal(
  293. /* [string][in] */ LPCWSTR wszMachine);
  294. virtual BOOL STDMETHODCALLTYPE IsSameClassName(
  295. /* [string][in] */ LPCWSTR wszClass);
  296. HRESULT SetServer(LPCWSTR Name, bool m_bServerNameSetByDefault, bool bAcquire);
  297. BOOL HasServer(){return m_pServer != NULL;};
  298. LPWSTR GetPath(DWORD nStartAt, DWORD nStopAt,bool bGetServer = false);
  299. BOOL AddNamespace(LPCWSTR wszNamespace);
  300. BOOL AddClass(LPCWSTR lpClassName);
  301. BOOL AddKeyRef(CKeyRef* pAcquireRef);
  302. BOOL SetSingletonObj();
  303. LPWSTR GetNamespacePart();
  304. LPWSTR GetParentNamespacePart();
  305. BOOL SortKeys();
  306. CParsedComponent * GetLastComponent();
  307. HRESULT GetComponentString(ULONG Index, BSTR * pUnparsed, WCHAR & wDelim);
  308. HRESULT AddComponent(CParsedComponent * pComp);
  309. CParsedComponent * GetClass();
  310. CRefCntCS * GetRefCntCS(){return m_pCS;};
  311. void * m_pGenLex; // for test purposes only
  312. protected:
  313. bool m_bSetViaUMIPath;
  314. long m_cRef;
  315. LPWSTR m_pServer; // NULL if no server
  316. CFlexArray m_Components; // list of namespaces and scopes
  317. // CParsedComponent * m_pClass; // the class
  318. DWORD m_dwStatus;
  319. bool m_bParent; // true if text is ".."
  320. LPWSTR m_pRawPath; // temporary fix for Raja
  321. CRefCntCS * m_pCS;
  322. LPWSTR m_wszOriginalPath;
  323. bool m_bServerNameSetByDefault;
  324. IUnknown * m_pFTM;
  325. DWORD m_dwException;
  326. };
  327. #endif