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.

330 lines
9.9 KiB

  1. // sceparser.h: path and query parser provided by sce provider
  2. // Copyright (c)1997-2001 Microsoft Corporation
  3. //
  4. //////////////////////////////////////////////////////////////////////
  5. #if _MSC_VER >= 1000
  6. #pragma once
  7. #endif // _MSC_VER >= 1000
  8. #include "sceprov.h"
  9. /*
  10. Class description
  11. Naming:
  12. CScePathParser stands for SCE Path Parser.
  13. Base class:
  14. CComObjectRootEx for threading model and IUnknown.
  15. CComCoClass for class factory support.
  16. IScePathParser and ISceKeyChain for custom interfaces.
  17. Purpose of class:
  18. (1) We wish to simplify path parsing. This is our effort of creation Sce path parser
  19. that can be externally CoCreateInstance'd.
  20. (2) To support a more friendly and uniform interface, both SCE path parser and SCE query
  21. let client use the service via ISceKeyChain.
  22. Design:
  23. (1) See IScePathParser and ISceKeyChain. Almost everything is captured by these two interfaces.
  24. (2) This is not a directly instantiatable class. See Use section for creation steps.
  25. (3) Since paths only contains class name and key properties, we opt to use a less fancier data
  26. structure - vector to store the properties' (name,value) pair. The nature of key properties
  27. being normally limited in number should offer you comfort in using this data structure.
  28. (4) Class name and namespace are cached in separate string members.
  29. Use:
  30. (1) For external users:
  31. (a) CoCreateInstance of our class (CLSID_ScePathParser) and request for IID_IScePathParser.
  32. (b) Call ParsePath to parse the path string.
  33. (c) QI ISceKeyChain and use the key chain to access the results.
  34. (2) For internal users:
  35. (a) CComObject<CScePathParser>::CreateInstance(&pPathParser);
  36. (b) QI for IScePathParser.
  37. (c) ParsePath
  38. (d) QI ISceKeyChain and use the key chain to access the results.
  39. See CRequestObject's use for sample.
  40. Notes:
  41. (1) This class is not intended to be further derived. It is a final class. It's
  42. destructor is thus not virtual!
  43. (2) Refer to MSDN and ATL COM programming for the use of ATL.
  44. (3) The caller can't cache the interface pointer (ISceKeyChain) and do another parsing (which
  45. is allowed) and expect the previous ISceKeyChain interface to work for the previous parsing.
  46. */
  47. class ATL_NO_VTABLE CScePathParser
  48. : public CComObjectRootEx<CComMultiThreadModel>,
  49. public CComCoClass<CScePathParser, &CLSID_ScePathParser>,
  50. public IScePathParser,
  51. public ISceKeyChain
  52. {
  53. public:
  54. BEGIN_COM_MAP(CScePathParser)
  55. COM_INTERFACE_ENTRY(IScePathParser)
  56. COM_INTERFACE_ENTRY(ISceKeyChain)
  57. END_COM_MAP()
  58. DECLARE_NOT_AGGREGATABLE( CScePathParser )
  59. DECLARE_REGISTRY_RESOURCEID(IDR_SceProv)
  60. protected:
  61. CScePathParser();
  62. ~CScePathParser();
  63. public:
  64. //
  65. // IScePathParser
  66. //
  67. STDMETHOD(ParsePath) (
  68. IN LPCWSTR strObjectPath
  69. );
  70. //
  71. // ISceKeyChain
  72. //
  73. STDMETHOD(GetKeyPropertyCount) (
  74. OUT DWORD *pCount
  75. );
  76. STDMETHOD(GetNamespace) (
  77. OUT BSTR *pbstrNamespace
  78. );
  79. STDMETHOD(GetClassName) (
  80. OUT BSTR *pbstrClassName
  81. );
  82. STDMETHOD(GetKeyPropertyValue) (
  83. IN LPCWSTR pszKeyPropName,
  84. OUT VARIANT *pvarValue
  85. );
  86. STDMETHOD(GetKeyPropertyValueByIndex) (
  87. IN DWORD dwIndex,
  88. OUT BSTR* pbstrKeyPropName,
  89. OUT VARIANT *pvarValue
  90. );
  91. private:
  92. void Cleanup();
  93. std::vector<CPropValuePair*> m_vecKeyValueList;
  94. LPWSTR m_pszClassName;
  95. LPWSTR m_pszNamespace;
  96. };
  97. /*
  98. Class description
  99. Naming:
  100. CSceQueryParser stands for SCE Query Parser.
  101. Base class:
  102. (1) CComObjectRootEx for threading model and IUnknown.
  103. (2) CComCoClass for class factory support.
  104. (3) ISceQueryParser and ISceKeyChain for custom interfaces.
  105. Purpose of class:
  106. (1) We wish to simplify query parsing. This is our effort of creation Sce query parser
  107. that can be externally CoCreateInstance'd.
  108. (2) To support a more friendly and uniform interface, both SCE path parser and SCE query
  109. let client use the service via ISceKeyChain.
  110. Design:
  111. (1) See ISceQueryParser and ISceKeyChain. Almost everything is captured by these two interfaces.
  112. (2) This is not a directly instantiatable class. See Use section for creation steps.
  113. (3) Parsing a query is a very complicated matter. WMI support of complicated queries are limited
  114. too. We are very pragmatic about it: we only cares about the class names (actually, WMI limits
  115. its queries to unary - one class name only) and one important property - let's call it the querying
  116. property (m_bstrQueryingPropName). For SCE use, that querying property is almost always
  117. the store path.
  118. (4) Class names are cached in string list member m_vecClassList.
  119. (5) The query property values (in string) will be cached in a string list member - m_vecQueryingPropValueList.
  120. Use:
  121. (1) For external users:
  122. (a) CoCreateInstance of our class (CLSID_SceQueryParser) and request for IID_ISceQueryParser.
  123. (b) Call ParseQuery to parse the query.
  124. (c) QI ISceKeyChain and use the key chain to access the results.
  125. (2) For internal users:
  126. (a) CComObject<CScePathParser>::CreateInstance(&pPathParser);
  127. (b) QI for ISceQueryParser.
  128. (c) Call ParseQuery to parse the query.
  129. (d) QI ISceKeyChain and use the key chain to access the results.
  130. See CRequestObject's use for sample.
  131. Notes:
  132. (1) This class is not intended to be further derived. It is a final class. It's
  133. destructor is thus not virtual!
  134. (2) Refer to MSDN and ATL COM programming for the use of ATL.
  135. */
  136. class ATL_NO_VTABLE CSceQueryParser
  137. : public CComObjectRootEx<CComMultiThreadModel>,
  138. public CComCoClass<CSceQueryParser, &CLSID_SceQueryParser>,
  139. public ISceQueryParser,
  140. public ISceKeyChain
  141. {
  142. public:
  143. BEGIN_COM_MAP(CSceQueryParser)
  144. COM_INTERFACE_ENTRY(ISceQueryParser)
  145. COM_INTERFACE_ENTRY(ISceKeyChain)
  146. END_COM_MAP()
  147. DECLARE_NOT_AGGREGATABLE( CSceQueryParser )
  148. DECLARE_REGISTRY_RESOURCEID(IDR_SceProv)
  149. protected:
  150. CSceQueryParser();
  151. ~CSceQueryParser();
  152. public:
  153. //
  154. // ISceQueryParser
  155. //
  156. STDMETHOD(ParseQuery) (
  157. IN LPCWSTR strQuery,
  158. IN LPCWSTR strQueryPropName
  159. );
  160. STDMETHOD(GetClassCount) (
  161. OUT DWORD* pdwCount
  162. )
  163. {
  164. if (pdwCount == NULL)
  165. {
  166. return E_INVALIDARG;
  167. }
  168. *pdwCount = m_vecClassList.size();
  169. return S_OK;
  170. }
  171. STDMETHOD(GetClassName) (
  172. IN int iIndex,
  173. OUT BSTR * pbstrClassName
  174. );
  175. STDMETHOD(GetQueryingPropertyValueCount) (
  176. OUT DWORD* pdwCount
  177. )
  178. {
  179. if (pdwCount == NULL)
  180. {
  181. return E_INVALIDARG;
  182. }
  183. *pdwCount = m_vecQueryingPropValueList.size();
  184. return S_OK;
  185. }
  186. STDMETHOD(GetQueryingPropertyValue) (
  187. IN int iIndex,
  188. OUT BSTR * pbstrQPValue
  189. );
  190. //
  191. // ISceKeyChain
  192. //
  193. STDMETHOD(GetKeyPropertyCount) (
  194. OUT DWORD *pCount
  195. )
  196. {
  197. if (pCount == NULL)
  198. {
  199. return E_INVALIDARG;
  200. }
  201. *pCount = m_vecQueryingPropValueList.size() > 0 ? 1 : 0;
  202. return S_OK;
  203. }
  204. STDMETHOD(GetNamespace) (
  205. OUT BSTR *pbstrNamespace
  206. )
  207. {
  208. *pbstrNamespace = NULL;
  209. return WBEM_E_NOT_SUPPORTED;
  210. }
  211. STDMETHOD(GetClassName) (
  212. OUT BSTR *pbstrClassName
  213. )
  214. {
  215. //
  216. // since we only support single class query, this must be it
  217. //
  218. return GetClassName(0, pbstrClassName);
  219. }
  220. STDMETHOD(GetKeyPropertyValue) (
  221. IN LPCWSTR pszKeyPropName,
  222. OUT VARIANT * pvarValue
  223. );
  224. STDMETHOD(GetKeyPropertyValueByIndex) (
  225. IN DWORD dwIndex,
  226. OUT BSTR * pbstrKeyPropName,
  227. OUT VARIANT * pvarValue
  228. )
  229. {
  230. if (pbstrKeyPropName == NULL || pvarValue == NULL)
  231. {
  232. return E_INVALIDARG;
  233. }
  234. *pbstrKeyPropName = NULL;
  235. ::VariantInit(pvarValue);
  236. return WBEM_E_NOT_SUPPORTED;
  237. }
  238. private:
  239. void Cleanup();
  240. HRESULT ExtractClassNames (
  241. SWbemRpnEncodedQuery *pRpn
  242. );
  243. HRESULT ExtractQueryingProperties (
  244. SWbemRpnEncodedQuery *pRpn,
  245. LPCWSTR strQueryPropName
  246. );
  247. HRESULT GetQueryPropFromToken (
  248. SWbemRpnQueryToken *pRpnQueryToken,
  249. LPCWSTR strQueryPropName
  250. );
  251. std::vector<LPWSTR> m_vecClassList;
  252. std::vector<LPWSTR> m_vecQueryingPropValueList;
  253. CComBSTR m_bstrQueryingPropName;
  254. };