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.

327 lines
12 KiB

  1. //=============================================================================
  2. // Contains definitions for reading in version 5.0 MSInfo extensions.
  3. //=============================================================================
  4. #pragma once
  5. //-----------------------------------------------------------------------------
  6. // Constants used in the data gathering files.
  7. //-----------------------------------------------------------------------------
  8. #define NODE_KEYWORD "node"
  9. #define COLUMN_KEYWORD "columns"
  10. #define LINE_KEYWORD "line"
  11. #define ENUMLINE_KEYWORD "enumlines"
  12. #define FIELD_KEYWORD "field"
  13. #define STATIC_SOURCE "static"
  14. #define TEMPLATE_FILE_TAG "MSINFO,0000"
  15. #define SORT_VALUE "VALUE"
  16. #define SORT_LEXICAL "LEXICAL"
  17. #define COMPLEXITY_ADVANCED "ADVANCED"
  18. #define COMPLEXITY_BASIC "BASIC"
  19. #define DEPENDENCY_JOIN "dependency"
  20. #define SQL_FILTER "WQL:"
  21. //-----------------------------------------------------------------------------
  22. // These structures are used by the INTERNAL_CATEGORY structure to store both
  23. // the specification for what information is shown as well as the actually
  24. // data to be shown (refreshed on command).
  25. //-----------------------------------------------------------------------------
  26. // GATH_VALUE is used to store a list of strings. A list of column names or a
  27. // list of arguments would use the GATH_VALUE struct. Note, a next pointer is
  28. // not needed because these structures will be allocated contiguously (in
  29. // an array).
  30. struct GATH_VALUE
  31. {
  32. GATH_VALUE();
  33. ~GATH_VALUE();
  34. CString m_strText;
  35. DWORD m_dwValue;
  36. GATH_VALUE * m_pNext;
  37. };
  38. // A GATH_FIELD is used to store the specification for a text string. It contains
  39. // a format string (a printf style string) and a GATH_VALUE pointer to a list of
  40. // arguments for the format string.
  41. struct GATH_FIELD
  42. {
  43. GATH_FIELD();
  44. ~GATH_FIELD();
  45. CString m_strSource; // WBEM class containing information
  46. CString m_strFormat; // printf-type format string
  47. unsigned short m_usWidth; // width (if this field is for a column)
  48. MSIColumnSortType m_sort; // how to sort this column
  49. DataComplexity m_datacomplexity; // is this column BASIC or ADVANCED
  50. GATH_VALUE * m_pArgs; // arguments for m_strFormat
  51. GATH_FIELD * m_pNext; // next field in the list
  52. };
  53. // A GATH_LINESPEC is used to specify what is shown on a line in the listview. It
  54. // contains a string for a class to enumerate. If this string is empty, then
  55. // the struct merely represents a single line in the display. The GATH_FIELD pointer
  56. // is to a list of the fields (one for each column), and the m_pNext pointer is
  57. // to the next line to be displayed. If m_strEnumerateClass is not empty, then
  58. // the class specified is enumerated, and the lines pointed to by m_pEnumeratedGroup
  59. // are repeated for each instance of the class. Note, if a class is to be enumerated,
  60. // the m_pFields pointer must be null (since this line won't display anything
  61. // itself, but enumerate a class for another group of lines).
  62. //
  63. // m_pConstraintFields is a pointer to a linked list of fields which serve as
  64. // constraints for the enumeration. These can be used to filter the enumerated
  65. // instances or to perform joins to related classes so they are enumerated as
  66. // well is the primary class. m_pConstraintFields should only be non-NULL when
  67. // m_pEnumeratedGroup is non-NULL.
  68. struct GATH_LINESPEC
  69. {
  70. GATH_LINESPEC();
  71. ~GATH_LINESPEC();
  72. CString m_strEnumerateClass;
  73. DataComplexity m_datacomplexity;
  74. GATH_FIELD * m_pFields;
  75. GATH_LINESPEC * m_pEnumeratedGroup;
  76. GATH_FIELD * m_pConstraintFields;
  77. GATH_LINESPEC * m_pNext;
  78. };
  79. // The GATH_LINE struct contains the actual data to be displayed on a line. The
  80. // refresh operation will take list of GATH_LINESPEC structs and create a list
  81. // of GATH_LINE structs. The m_aValue pointer is to a list of values to be
  82. // displayed (one per column).
  83. struct GATH_LINE
  84. {
  85. GATH_LINE();
  86. ~GATH_LINE();
  87. GATH_VALUE * m_aValue;
  88. DataComplexity m_datacomplexity;
  89. };
  90. //-----------------------------------------------------------------------------
  91. // The following structure is used within this object to store information
  92. // about the categories. Specifically, this structure will be allocated for
  93. // each category, and a pointer stored in m_mapCategories. This representation
  94. // will not be used outside this object, rather, a CDataCategory object will
  95. // be used.
  96. //-----------------------------------------------------------------------------
  97. struct INTERNAL_CATEGORY
  98. {
  99. INTERNAL_CATEGORY();
  100. ~INTERNAL_CATEGORY();
  101. GATH_VALUE m_categoryName; // realized name of category
  102. GATH_FIELD m_fieldName; // field used to get name
  103. CString m_strEnumerateClass; // if !(empty or "static"), this category repeated
  104. CString m_strIdentifier; // non-localized internal name
  105. CString m_strNoInstances; // message to use if there are no instances
  106. BOOL m_fListView; // is this cat a list view
  107. BOOL m_fDynamic; // was this cat enumerated
  108. BOOL m_fIncluded; // should this cat be included
  109. DWORD m_dwID; // the ID for this cat
  110. DWORD m_dwParentID; // my parent
  111. DWORD m_dwChildID; // my first child
  112. DWORD m_dwDynamicChildID; // my first dynamically created child
  113. DWORD m_dwNextID; // my next sibling
  114. DWORD m_dwPrevID; // my previous sibling
  115. DWORD m_dwColCount; // number of columns
  116. GATH_FIELD * m_pColSpec; // list of fields to make col names
  117. GATH_VALUE * m_aCols; // realized list of columns
  118. GATH_LINESPEC* m_pLineSpec; // list of line specifiers
  119. DWORD m_dwLineCount; // number of lines (NOT number of line specs)
  120. GATH_LINE * * m_apLines; // realized list of lines
  121. BOOL m_fRefreshed; // has the category ever been refreshed
  122. DWORD m_dwLastError; // last error specific to this category
  123. };
  124. //-----------------------------------------------------------------------------
  125. // A class to contain the template functions.
  126. //-----------------------------------------------------------------------------
  127. class CTemplateFileFunctions
  128. {
  129. public:
  130. static DWORD ParseTemplateIntoVersion5Categories(const CString & strExtension, CMapWordToPtr & mapVersion5Categories);
  131. static DWORD ReadTemplateFile(CFile * pFile, CMapWordToPtr & mapVersion5Categories);
  132. static BOOL ReadHeaderInfo(CFile * pFile);
  133. static BOOL VerifyUNICODEFile(CFile * pFile);
  134. static BOOL VerifyAndAdvanceFile(CFile * pFile, const CString & strVerify);
  135. static DWORD ReadNodeRecursive(CFile * pFile, CMapWordToPtr & mapCategories, DWORD dwParentID, DWORD dwPrevID);
  136. static INTERNAL_CATEGORY * GetInternalRep(CMapWordToPtr & mapCategories, DWORD dwID);
  137. static INTERNAL_CATEGORY * CreateCategory(CMapWordToPtr & mapCategories, DWORD dwNewID, DWORD dwParentID, DWORD dwPrevID);
  138. static BOOL ReadArgument(CFile * pFile, CString & strSource);
  139. static BOOL ReadField(CFile * pFile, GATH_FIELD & field);
  140. static GATH_LINESPEC * ReadLineEnumRecursive(CFile * pFile, CMapWordToPtr & mapCategories);
  141. static BOOL ReadColumnInfo(CFile * pFile, CMapWordToPtr & mapCategories, DWORD dwID);
  142. static GATH_LINESPEC * ReadLineInfo(CFile * pFile);
  143. static BOOL GetKeyword(CFile * pFile, CString & strKeyword);
  144. };
  145. //-----------------------------------------------------------------------------
  146. // A class to contain the refresh functions.
  147. //-----------------------------------------------------------------------------
  148. class CWMIHelper;
  149. class CRefreshFunctions
  150. {
  151. public:
  152. static BOOL RefreshLines(CWMIHelper * pWMI, GATH_LINESPEC * pLineSpec, DWORD dwColumns, CPtrList & listLinePtrs, volatile BOOL * pfCancel);
  153. static BOOL RefreshOneLine(CWMIHelper * pWMI, GATH_LINE * pLine, GATH_LINESPEC * pLineSpec, DWORD dwColCount);
  154. static BOOL RefreshValue(CWMIHelper * pWMI, GATH_VALUE * pVal, GATH_FIELD * pField);
  155. static BOOL GetValue(CWMIHelper * pWMI, TCHAR cFormat, TCHAR *szFormatFragment, CString &strResult, DWORD &dwResult, GATH_FIELD *pField, int iArgNumber);
  156. };
  157. //-----------------------------------------------------------------------------
  158. // The CMSIObject class is a thin wrapper for the IWbemClassObject interface.
  159. // We use this so we can return a custom label for a null object (if there
  160. // are no instances, we sometimes want to show some caption).
  161. //-----------------------------------------------------------------------------
  162. typedef enum { MOS_NO_INSTANCES, MOS_MSG_INSTANCE, MOS_INSTANCE } MSIObjectState;
  163. struct IWbemClassObject;
  164. class CMSIObject
  165. {
  166. public:
  167. CMSIObject(IWbemClassObject * pObject, const CString & strLabel, HRESULT hres, CWMIHelper * pWMI, MSIObjectState objState);
  168. ~CMSIObject();
  169. HRESULT Get(BSTR property, LONG lFlags, VARIANT *pVal, VARTYPE *pvtType, LONG *plFlavor);
  170. HRESULT GetErrorLabel(CString & strError);
  171. MSIObjectState IsValid();
  172. private:
  173. IWbemClassObject * m_pObject;
  174. CString m_strLabel;
  175. HRESULT m_hresCreation;
  176. CWMIHelper * m_pWMI;
  177. MSIObjectState m_objState;
  178. };
  179. //-----------------------------------------------------------------------------
  180. // The CMSIEnumerator class encapsulates the WBEM enumerator interface, or
  181. // implements our own form of enumerator (such as for the LNK command in the
  182. // template file).
  183. //-----------------------------------------------------------------------------
  184. struct IEnumWbemClassObject;
  185. class CMSIEnumerator
  186. {
  187. public:
  188. CMSIEnumerator();
  189. ~CMSIEnumerator();
  190. HRESULT Create(const CString & strClass, const GATH_FIELD * pConstraints, CWMIHelper * pWMI);
  191. HRESULT Next(CMSIObject ** ppObject);
  192. HRESULT Reset(const GATH_FIELD * pConstraints);
  193. private:
  194. typedef enum { CLASS, WQL, LNK, INTERNAL } EnumType;
  195. private:
  196. EnumType m_enumtype;
  197. BOOL m_fOnlyDups;
  198. BOOL m_fGotDuplicate;
  199. BOOL m_fMinOfOne;
  200. int m_iMinOfOneCount;
  201. CString m_strClass;
  202. CString m_strObjPath;
  203. CString m_strAssocClass;
  204. CString m_strResultClass;
  205. CString m_strLNKObject;
  206. CString m_strNoInstanceLabel;
  207. IEnumWbemClassObject * m_pEnum;
  208. CWMIHelper * m_pWMI;
  209. const GATH_FIELD * m_pConstraints;
  210. HRESULT m_hresCreation;
  211. IWbemClassObject * m_pSavedDup;
  212. CString m_strSavedDup;
  213. CStringList * m_pstrList;
  214. private:
  215. BOOL AssocObjectOK(IWbemClassObject * pObject, CString & strAssociatedObject);
  216. HRESULT ParseLNKCommand(const CString & strStatement, CString & strObjPath, CString & strAssocClass, CString & strResultClass);
  217. void ProcessEnumString(CString & strStatement, BOOL & fMinOfOne, BOOL & fOnlyDups, CWMIHelper * pWMI, CString & strNoInstanceLabel, BOOL fMakeDoubleBackslashes = FALSE);
  218. HRESULT CreateInternalEnum(const CString & strInternal, CWMIHelper * pWMI);
  219. HRESULT InternalNext(IWbemClassObject ** ppWBEMObject);
  220. };
  221. //-----------------------------------------------------------------------------
  222. // A class to map a DWORD to refresh data (used by the refresh function).
  223. //-----------------------------------------------------------------------------
  224. class CMapExtensionRefreshData
  225. {
  226. public:
  227. CMapExtensionRefreshData() : m_dwIndex(0) { };
  228. ~CMapExtensionRefreshData()
  229. {
  230. GATH_LINESPEC * pLineSpec;
  231. WORD key;
  232. for (POSITION pos = m_map.GetStartPosition(); pos != NULL;)
  233. {
  234. m_map.GetNextAssoc(pos, key, (void * &) pLineSpec);
  235. if (pLineSpec)
  236. delete pLineSpec;
  237. }
  238. m_map.RemoveAll();
  239. CString * pstr;
  240. for (pos = m_mapStrings.GetStartPosition(); pos != NULL;)
  241. {
  242. m_mapStrings.GetNextAssoc(pos, key, (void * &) pstr);
  243. if (pstr)
  244. delete pstr;
  245. }
  246. m_mapStrings.RemoveAll();
  247. }
  248. DWORD Insert(GATH_LINESPEC * pLineSpec)
  249. {
  250. if (pLineSpec == NULL)
  251. return 0;
  252. m_dwIndex += 1;
  253. m_map.SetAt((WORD) m_dwIndex, (void *) pLineSpec);
  254. return m_dwIndex;
  255. }
  256. void InsertString(DWORD dwID, const CString & strInsert)
  257. {
  258. CString * pstr = new CString(strInsert);
  259. m_mapStrings.SetAt((WORD) dwID, (void *) pstr);
  260. }
  261. GATH_LINESPEC * Lookup(DWORD dwIndex)
  262. {
  263. GATH_LINESPEC * pReturn;
  264. if (m_map.Lookup((WORD) dwIndex, (void * &) pReturn))
  265. return pReturn;
  266. return NULL;
  267. }
  268. CString * LookupString(DWORD dwIndex)
  269. {
  270. CString * pstrReturn;
  271. if (m_mapStrings.Lookup((WORD) dwIndex, (void * &) pstrReturn))
  272. return pstrReturn;
  273. return NULL;;
  274. }
  275. private:
  276. DWORD m_dwIndex;
  277. CMapWordToPtr m_map;
  278. CMapWordToPtr m_mapStrings;
  279. };
  280. extern CMapExtensionRefreshData gmapExtensionRefreshData;