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.

218 lines
9.6 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // WMI2XML.H
  6. //
  7. // rajesh 3/25/2000 Created.
  8. //
  9. // Contains the class definition of the component that implements the IWbemXMLConvertor
  10. // interface
  11. //
  12. //***************************************************************************
  13. #ifndef _WBEM2XML_H_
  14. #define _WBEM2XML_H_
  15. // Use this to protect features that rely on MSXML fixes
  16. #define WAITING_FOR_MSXML_FIX 0
  17. // These macros are used to write BSTRs, special characters etc. to the IStream
  18. #define WRITEBSTR(X) pOutputStream->Write ((void const *)X, wcslen (X) * sizeof (OLECHAR), NULL);
  19. #define WRITEWSTR(X) pOutputStream->Write ((void const *)X, wcslen (X) * sizeof (OLECHAR), NULL);
  20. #define WRITEWSTRL(X,L) pOutputStream->Write ((void const *)X, L * sizeof (OLECHAR), NULL);
  21. #define WRITECDATASTART WRITEBSTR(CDATASTART)
  22. #define WRITECDATAEND WRITEBSTR(CDATAEND)
  23. #define WRITEAMP WRITEBSTR(AMPERSAND)
  24. #define WRITELT WRITEBSTR(LEFTCHEVRON)
  25. #define WRITEGT WRITEBSTR(RIGHTCHEVRON)
  26. // TODO : Make sure this is disabled before release
  27. #ifdef WMIXML_DONL
  28. #define WRITENEWLINE pOutputStream->Write (XMLNEWLINE, 4, NULL);
  29. #else
  30. #define WRITENEWLINE
  31. #endif
  32. // Filter for deciding the level of naming information in the output XML
  33. typedef enum PathLevel
  34. {
  35. // No name - corresponds to CLASS|INSTANCE
  36. pathLevelAnonymous,
  37. // namespace-relative name - Corresponds to CLASS|(INSTANCENAME, INSTANCE)
  38. pathLevelNamed,
  39. // host-relative name - Corresponds to (LOCALCLASSPATH,CLASS)|(LOCALINSTANCEPATH,INSTANCE)
  40. pathLevelLocal,
  41. // Full name with host, namespace, classname and keyvalue bindings for an instance - Corresponds to (CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE)
  42. pathLevelFull
  43. } PathLevel;
  44. // Filter for Qualifiers
  45. typedef enum WmiXMLQualifierFilterEnum
  46. {
  47. wmiXMLQualifierFilterNone = 0x0,
  48. wmiXMLQualifierFilterLocal = 0x1,
  49. wmiXMLQualifierFilterPropagated = 0x2,
  50. wmiXMLQualifierFilterAll = 0x3
  51. } WmiXMLQualifierFilterEnum;
  52. // Controls the amount of class origin information in the output
  53. typedef enum WmiXMLClassOriginFilterEnum
  54. {
  55. wmiXMLClassOriginFilterNone = 0x0,
  56. wmiXMLClassOriginFilterClass = 0x1,
  57. wmiXMLClassOriginFilterInstance = 0x2,
  58. wmiXMLClassOriginFilterAll = 0x3
  59. } WmiXMLClassOriginFilterEnum;
  60. //***************************************************************************
  61. //
  62. // CLASS NAME:
  63. //
  64. // CWmiToXml
  65. //
  66. // DESCRIPTION:
  67. //
  68. // Performs conversion from WMI to XML.
  69. //
  70. //***************************************************************************
  71. class CWmiToXml : public IWbemXMLConvertor
  72. {
  73. private:
  74. // This is the enumeration of the names of properties that the control
  75. // looks for in an IWbemContext object for modifying its output
  76. enum
  77. {
  78. WMI_EXTENSIONS_ARG,
  79. PATH_LEVEL_ARG,
  80. QUALIFIER_FILTER_ARG,
  81. CLASS_ORIGIN_FILTER_ARG,
  82. LOCAL_ONLY_ARG,
  83. EXCLUDE_SYSTEM_PROPERTIES_ARG
  84. };
  85. static const LPCWSTR s_wmiToXmlArgs[];
  86. long m_cRef; // COM Ref count
  87. // Flags that modify the output
  88. // These are filled up from the IWbemContext object
  89. // that is passed for most function calls
  90. PathLevel m_iPathLevel;
  91. VARIANT_BOOL m_bAllowWMIExtensions;
  92. WmiXMLQualifierFilterEnum m_iQualifierFilter;
  93. WmiXMLClassOriginFilterEnum m_iClassOriginFilter;
  94. VARIANT_BOOL m_bLocalOnly;
  95. VARIANT_BOOL m_bExcludeSystemProperties;
  96. BOOL PropertyDefinedForClass (IWbemClassObject *pObject, BSTR bsPropertyName, BSTR strClassBasis);
  97. STDMETHODIMP MapClass (IStream *pOutputStream, IWbemClassObject *pObject, IWbemQualifierSet *pQualSet, BSTR *ppPropertyList, DWORD dwNumProperties, BSTR strClassBasis);
  98. STDMETHODIMP MapClassName (IStream *pOutputStream, BSTR bsClassName);
  99. STDMETHODIMP MapClassPath (IStream *pOutputStream, ParsedObjectPath *pParsedPath);
  100. STDMETHODIMP MapLocalClassPath (IStream *pOutputStream, ParsedObjectPath *pParsedPath);
  101. STDMETHODIMP MapInstance (IStream *pOutputStream, IWbemClassObject *pObject, IWbemQualifierSet *pQualSet, BSTR *ppPropertyList, DWORD dwNumProperties, BSTR strClassBasis);
  102. STDMETHODIMP MapInstancePath (IStream *pOutputStream, ParsedObjectPath *pParsedPath);
  103. STDMETHODIMP MapLocalInstancePath (IStream *pOutputStream, ParsedObjectPath *pParsedPath);
  104. STDMETHODIMP MapInstanceName (IStream *pOutputStream, ParsedObjectPath *pParsedPath);
  105. STDMETHODIMP MapNamespacePath (IStream *pOutputStream, BSTR bsNamespacePath);
  106. STDMETHODIMP MapNamespacePath (IStream *pOutputStream, ParsedObjectPath *pObjectPath);
  107. STDMETHODIMP MapLocalNamespacePath (IStream *pOutputStream, BSTR bsNamespacePath);
  108. STDMETHODIMP MapLocalNamespacePath (IStream *pOutputStream, ParsedObjectPath *pObjectPath);
  109. STDMETHODIMP MapQualifiers (IStream *pOutputStream, IWbemQualifierSet *pQualSet, IWbemQualifierSet *pQualSet2 = NULL);
  110. STDMETHODIMP MapQualifier (IStream *pOutputStream, BSTR name, long flavor, VARIANT &var);
  111. STDMETHODIMP MapProperties (IStream *pOutputStream, IWbemClassObject *pObject, BSTR *ppPropertyList, DWORD dwNumProperties, BSTR strClassBasis, bool bIsClass);
  112. STDMETHODIMP MapProperty (IStream *pOutputStream, IWbemClassObject *pObject, BSTR name, VARIANT &var, CIMTYPE cimtype,
  113. BOOL isArray, long flavor, bool bIsClass);
  114. STDMETHODIMP MapObjectProperty (IStream *pOutputStream, IWbemClassObject *pObject, BSTR name, VARIANT &var, BOOL isArray, long flavor, bool bIsClass);
  115. STDMETHODIMP MapReferenceProperty (IStream *pOutputStream, IWbemClassObject *pObject, BSTR name, VARIANT &var, bool isArray, long flavor, bool bIsClass);
  116. void MapArraySize (IStream *pOutputStream, IWbemQualifierSet *pQualSet);
  117. STDMETHODIMP MapMethods (IStream *pOutputStream, IWbemClassObject *pObject);
  118. void MapMethod (IStream *pOutputStream, IWbemClassObject *pObject, BSTR name, IWbemClassObject *pInParams, IWbemClassObject *pOutParams);
  119. void MapParameter (IStream *pOutputStream, BSTR paramName, IWbemQualifierSet *pQualSet,
  120. CIMTYPE cimtype, IWbemQualifierSet *pQualSet2 = NULL);
  121. void MapReturnParameter(IStream *pOutputStream, BSTR strParameterName, VARIANT &variant);
  122. STDMETHODIMP MapType (IStream *pOutputStream, CIMTYPE cimtype);
  123. STDMETHODIMP MapValue (IStream *pOutputStream, VARIANT &var);
  124. STDMETHODIMP MapValue (IStream *pOutputStream, CIMTYPE cimtype, BOOL isArray, VARIANT &var);
  125. STDMETHODIMP MapEmbeddedObjectValue (IStream *pOutputStream, BOOL isArray, VARIANT &var);
  126. STDMETHODIMP MapKeyValue (IStream *pOutputStream, VARIANT &var);
  127. void MapStrongType (IStream *pOutputStream, IWbemQualifierSet *pQualSet);
  128. void MapLocal (IStream *pOutputStream, long flavor);
  129. void MapClassOrigin (IStream *pOutputStream, BSTR &classOrigin, bool bIsClass);
  130. STDMETHODIMP MapMethodReturnType(IStream *pOutputStream, VARIANT *pValue, CIMTYPE returnCimType, IWbemClassObject *pOutputParams);
  131. // Primitive functions to map individual values
  132. void MapLongValue (IStream *pOutputStream, long val);
  133. void MapShortValue (IStream *pOutputStream, short val);
  134. void MapDoubleValue (IStream *pOutputStream, double val);
  135. void MapFloatValue (IStream *pOutputStream, float val);
  136. void MapBoolValue (IStream *pOutputStream, BOOL val);
  137. void MapByteValue (IStream *pOutputStream, unsigned char val);
  138. void MapCharValue (IStream *pOutputStream, long val);
  139. void MapStringValue (IStream *pOutputStream, BSTR &val);
  140. STDMETHODIMP MapReferenceValue (IStream *pOutputStream, bool isArray, VARIANT &var);
  141. void MapReferenceValue (IStream *pOutputStream, ParsedObjectPath *pObjectPath, BSTR strPath);
  142. bool IsReference (VARIANT &var, ParsedObjectPath **ppObjectPath);
  143. void GetFlagsFromContext(IWbemContext *pInputFlags);
  144. public:
  145. CWmiToXml();
  146. virtual ~CWmiToXml();
  147. //Non-delegating object IUnknown
  148. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  149. STDMETHODIMP_(ULONG) AddRef(void);
  150. STDMETHODIMP_(ULONG) Release(void);
  151. // Functions of the IWbemXMLConvertor interface
  152. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE MapObjectToXML(
  153. /* [in] */ IWbemClassObject *pObject,
  154. /* [in] */ BSTR *ppPropertyList, DWORD dwNumProperties,
  155. /* [in] */ IWbemContext *pInputFlags,
  156. /* [in] */ IStream *pOutputStream,
  157. /* [in[ */ BSTR strClassBasis);
  158. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE MapPropertyToXML(
  159. /* [in] */ IWbemClassObject *pObject,
  160. /* [in] */ BSTR strPropertyName,
  161. /* [in] */ IWbemContext *pInputFlags,
  162. /* [in] */ IStream *pOutputStream);
  163. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE MapInstanceNameToXML(
  164. /* [in] */ BSTR strInstanceName,
  165. /* [in] */ IWbemContext *pInputFlags,
  166. /* [in] */ IStream *pOutputStream);
  167. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE MapClassNameToXML(
  168. /* [in] */ BSTR strClassName,
  169. /* [in] */ IWbemContext *pInputFlags,
  170. /* [in] */ IStream *pOutputStream);
  171. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE MapInstancePathToXML(
  172. /* [in] */ BSTR strInstancePath,
  173. /* [in] */ IWbemContext *pInputFlags,
  174. /* [in] */ IStream *pOutputStream);
  175. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE MapClassPathToXML(
  176. /* [in] */ BSTR strClassPath,
  177. /* [in] */ IWbemContext *pInputFlags,
  178. /* [in] */ IStream *pOutputStream);
  179. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE MapMethodResultToXML(
  180. /* [in] */ IWbemClassObject *pMethodResult,
  181. /* [in] */ IWbemContext *pInputFlags,
  182. /* [in] */ IStream *pOutputStream);
  183. };
  184. #endif