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.

278 lines
12 KiB

  1. #if !defined(_FUSION_SXS_NODEFACTORY_H_INCLUDED_)
  2. #define _FUSION_SXS_NODEFACTORY_H_INCLUDED_
  3. #pragma once
  4. #include "FusionEventLog.h"
  5. #include <windows.h>
  6. #include <sxsp.h>
  7. #include <ole2.h>
  8. #include <xmlparser.h>
  9. #include "fusionbuffer.h"
  10. #include "partialassemblyversion.h"
  11. #include "xmlns.h"
  12. #include "stringpool.h"
  13. #include "policystatement.h"
  14. #define ELEMENT_LEGAL_ATTRIBUTE_FLAG_IGNORE (0x00000001)
  15. #define ELEMENT_LEGAL_ATTRIBUTE_FLAG_REQUIRED (0x00000002)
  16. typedef struct _ELEMENT_LEGAL_ATTRIBUTE
  17. {
  18. DWORD m_dwFlags;
  19. PCATTRIBUTE_NAME_DESCRIPTOR m_pName;
  20. SXSP_GET_ATTRIBUTE_VALUE_VALIDATION_ROUTINE m_pfnValidator;
  21. DWORD m_dwValidatorFlags;
  22. } ELEMENT_LEGAL_ATTRIBUTE, PELEMENT_LEGAL_ATTRIBUTE;
  23. typedef const struct _ELEMENT_LEGAL_ATTRIBUTE *PCELEMENT_LEGAL_ATTRIBUTE;
  24. class __declspec(uuid("832ff3cf-05bd-4eda-962f-d0a5307d55ae"))
  25. CNodeFactory : public IXMLNodeFactory
  26. {
  27. public:
  28. CNodeFactory();
  29. ~CNodeFactory();
  30. BOOL Initialize(
  31. PACTCTXGENCTX ActCtxGenCtx,
  32. PASSEMBLY Assembly,
  33. PACTCTXCTB_ASSEMBLY_CONTEXT AssemblyContext
  34. );
  35. BOOL SetParseType(ULONG ParseType, ULONG PathType, const CBaseStringBuffer &buffFileName, const FILETIME &rftLastWriteTime);
  36. VOID ResetParseState();
  37. // IUnknown methods:
  38. STDMETHODIMP_(ULONG) AddRef() { return 1; }
  39. STDMETHODIMP_(ULONG) Release() { return 1; }
  40. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
  41. // IXMLNodeFactory methods:
  42. STDMETHODIMP NotifyEvent(IXMLNodeSource *pSource, XML_NODEFACTORY_EVENT iEvt);
  43. STDMETHODIMP BeginChildren(IXMLNodeSource *pSource, XML_NODE_INFO *pNodeInfo);
  44. STDMETHODIMP EndChildren(IXMLNodeSource *pSource, BOOL fEmpty, XML_NODE_INFO *pNodeInfo);
  45. STDMETHODIMP Error(IXMLNodeSource *pSource, HRESULT hrErrorCode, USHORT cNumRecs, XML_NODE_INFO **apNodeInfo);
  46. STDMETHODIMP CreateNode(IXMLNodeSource *pSource, PVOID pNodeParent, USHORT cNumRecs, XML_NODE_INFO **apNodeInfo);
  47. HRESULT FirstCreateNodeCall(IXMLNodeSource *pSource, PVOID pNodeParent, USHORT NodeCount, const SXS_NODE_INFO *prgNodeInfo);
  48. enum
  49. {
  50. eValidateIdentity_VersionRequired = 0x00000001,
  51. eValidateIdentity_PoliciesNotAllowed = 0x00000002,
  52. eValidateIdentity_VersionNotAllowed = 0x00000008,
  53. };
  54. enum
  55. {
  56. eActualParseType_Undetermined,
  57. eActualParseType_Manifest,
  58. eActualParseType_PolicyManifest
  59. } m_IntuitedParseType;
  60. BOOL ValidateIdentity(DWORD Flags, ULONG Type, PCASSEMBLY_IDENTITY AssemblyIdentity);
  61. BOOL ValidateElementAttributes(PCSXS_NODE_INFO prgNodes, SIZE_T cNodes, PCELEMENT_LEGAL_ATTRIBUTE prgAttributes, UCHAR cAttributes);
  62. PCACTCTXCTB_PARSE_CONTEXT GetParseContext() const { return &m_ParseContext; }
  63. #if FUSION_XML_TREE
  64. HRESULT CreateXmlNode(PSXS_XML_NODE pParent, ULONG cNodes, XML_NODE_INFO **prgpNodes, PSXS_XML_NODE &rpNewNode);
  65. #endif // FUSION_XML_TREE
  66. // protected:
  67. PACTCTXGENCTX m_ActCtxGenCtx;
  68. PASSEMBLY m_Assembly;
  69. CXMLNamespaceManager m_XMLNamespaceManager;
  70. ULONG m_ParseType;
  71. bool m_fFirstCreateNodeCall;
  72. // We only track the state of the parse with respect to the tags that
  73. // we're interested in for metadata purposes. This amounts to just the
  74. // <ASSEMBLY> tag, and the dependencies. We ignore the rest.
  75. enum XMLParseState
  76. {
  77. eNotParsing,
  78. eParsing_doc,
  79. eParsing_doc_assembly,
  80. eParsing_doc_assembly_assemblyIdentity,
  81. eParsing_doc_assembly_comInterfaceExternalProxyStub,
  82. eParsing_doc_assembly_description,
  83. eParsing_doc_assembly_dependency,
  84. eParsing_doc_assembly_dependency_dependentAssembly,
  85. eParsing_doc_assembly_dependency_dependentAssembly_assemblyIdentity,
  86. eParsing_doc_assembly_dependency_dependentAssembly_bindingRedirect,
  87. eParsing_doc_assembly_file,
  88. eParsing_doc_assembly_file_comClass,
  89. eParsing_doc_assembly_file_comClass_progid,
  90. eParsing_doc_assembly_file_comInterfaceProxyStub,
  91. eParsing_doc_assembly_file_typelib,
  92. eParsing_doc_assembly_file_windowClass,
  93. eParsing_doc_assembly_clrSurrogate,
  94. eParsing_doc_assembly_clrClass,
  95. eParsing_doc_assembly_clrClass_progid,
  96. eParsing_doc_assembly_noInherit,
  97. eParsing_doc_assembly_noInheritable,
  98. eParsing_doc_configuration,
  99. eParsing_doc_configuration_windows,
  100. eParsing_doc_configuration_windows_assemblyBinding,
  101. eParsing_doc_configuration_windows_assemblyBinding_assemblyIdentity,
  102. eParsing_doc_configuration_windows_assemblyBinding_dependentAssembly,
  103. eParsing_doc_configuration_windows_assemblyBinding_dependentAssembly_assemblyIdentity,
  104. eParsing_doc_configuration_windows_assemblyBinding_dependentAssembly_bindingRedirect,
  105. eFatalParseError,
  106. } m_xpsParseState;
  107. ULONG m_cUnknownChildDepth;
  108. PACTCTXCTB_ASSEMBLY_CONTEXT m_AssemblyContext;
  109. ACTCTXCTB_PARSE_CONTEXT m_ParseContext;
  110. CSmallStringBuffer m_buffElementPath;
  111. CStringBuffer m_buffCurrentFileName;
  112. PASSEMBLY_IDENTITY m_CurrentPolicyDependentAssemblyIdentity;
  113. CPolicyStatement *m_CurrentPolicyStatement;
  114. CCaseInsensitiveUnicodeStringPtrTable<CPolicyStatement> *m_pApplicationPolicyTable;
  115. CStringBuffer m_buffCurrentApplicationPolicyIdentityKey;
  116. bool m_fAssemblyFound;
  117. bool m_fIdentityFound;
  118. bool m_fIsDependencyOptional;
  119. bool m_fDependencyChildHit;
  120. bool m_fAssemblyIdentityChildOfDependenctAssemblyHit;
  121. bool m_fIsMetadataSatellite;
  122. bool m_fMetadataSatelliteAlreadyFound;
  123. bool m_fNoInheritableFound;
  124. HRESULT ConvertXMLNodeInfoToSXSNodeInfo(const XML_NODE_INFO *pNodeInfo, SXS_NODE_INFO & sxsNodeInfo);
  125. #if FUSION_XML_TREE
  126. CStringPool m_ParseTreeStringPool;
  127. SXS_XML_DOCUMENT m_XmlDocument;
  128. SXS_XML_NODE *m_CurrentNode;
  129. SXS_XML_NODE *m_CurrentParent;
  130. SXS_XML_STRING m_InlineStringArray[64];
  131. SXS_XML_STRING *m_ActualStringArray;
  132. #endif
  133. //
  134. // XML Parsing worker functions:
  135. //
  136. typedef BOOL (CNodeFactory::*XMLParserWorkerFunctionPtr)(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  137. BOOL XMLParser_Element_doc_assembly(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  138. BOOL XMLParser_Element_doc_assembly_noInherit(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  139. BOOL XMLParser_Element_doc_assembly_noInheritable(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  140. BOOL XMLParser_Element_doc_assembly_assemblyIdentity(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  141. BOOL XMLParser_Element_doc_assembly_dependency(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  142. BOOL XMLParser_Element_doc_assembly_dependency_dependentAssembly(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  143. BOOL XMLParser_Element_doc_assembly_dependency_dependentAssembly_assemblyIdentity(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  144. BOOL XMLParser_Element_doc_assembly_dependency_dependentAssembly_bindingRedirect(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  145. BOOL XMLParser_Element_doc_configuration(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  146. BOOL XMLParser_Element_doc_configuration_windows(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  147. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  148. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding_assemblyIdentity(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  149. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  150. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly_assemblyIdentity(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  151. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly_bindingRedirect(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  152. //
  153. // Parsing helper functions:
  154. //
  155. enum XMLAttributeType
  156. {
  157. eAttributeTypeString, // represented by a CStringBuffer
  158. eAttributeTypeVersion, // represented by a ASSEMBLY_VERSION
  159. };
  160. //
  161. // Parser datatype specific worker functions. The first two parameters
  162. // are combined to refer the member to actually modify. The third is the
  163. // character string to be used as the value of the attribute.
  164. //
  165. // As an optimization, the datatype worker function may modify/destroy
  166. // the value in the third parameter. For example, the worker function
  167. // which just copies a CStringBuffer to another CStringBuffer actually
  168. // uses the CStringBuffer::TakeValue() member which avoids performing
  169. // a dynamic allocation if the attribute value exceeded the non-dynamically
  170. // allocated portion of the CStringBuffer.
  171. //
  172. typedef BOOL (CNodeFactory::*XMLParserValueParserFunctionPtr)(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  173. BOOL XMLParser_Parse_String(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  174. BOOL XMLParser_Parse_Version(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  175. BOOL XMLParser_Parse_ULARGE_INTEGER(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  176. BOOL XMLParser_Parse_FILETIME(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  177. BOOL XMLParser_Parse_GUID(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  178. BOOL XMLParser_Parse_BLOB(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  179. BOOL XMLParser_Parse_InstallAction(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  180. BOOL XMLParser_Parse_Boolean(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  181. BOOL XMLParser_Parse_PartialAssemblyVersion(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  182. struct AttributeMapEntry
  183. {
  184. LPCWSTR m_pszAttributeName;
  185. SIZE_T m_cchAttributeName;
  186. SIZE_T m_offsetData;
  187. SIZE_T m_offsetIndicator;
  188. XMLParserValueParserFunctionPtr m_pfn;
  189. };
  190. BOOL ParseElementAttributes(
  191. USHORT cNumRecs,
  192. XML_NODE_INFO **prgpNodeInfo,
  193. SIZE_T cAttributeMapEntries,
  194. const AttributeMapEntry *prgEntries);
  195. HRESULT LogParseError(
  196. DWORD dwLastParseError,
  197. const UNICODE_STRING *p1 = NULL,
  198. const UNICODE_STRING *p2 = NULL,
  199. const UNICODE_STRING *p3 = NULL,
  200. const UNICODE_STRING *p4 = NULL,
  201. const UNICODE_STRING *p5 = NULL,
  202. const UNICODE_STRING *p6 = NULL,
  203. const UNICODE_STRING *p7 = NULL,
  204. const UNICODE_STRING *p8 = NULL,
  205. const UNICODE_STRING *p9 = NULL,
  206. const UNICODE_STRING *p10 = NULL,
  207. const UNICODE_STRING *p11 = NULL,
  208. const UNICODE_STRING *p12 = NULL,
  209. const UNICODE_STRING *p13 = NULL,
  210. const UNICODE_STRING *p14 = NULL,
  211. const UNICODE_STRING *p15 = NULL,
  212. const UNICODE_STRING *p16 = NULL,
  213. const UNICODE_STRING *p17 = NULL,
  214. const UNICODE_STRING *p18 = NULL,
  215. const UNICODE_STRING *p19 = NULL,
  216. const UNICODE_STRING *p20 = NULL
  217. );
  218. static VOID WINAPI ParseErrorCallback_MissingRequiredAttribute(
  219. PCACTCTXCTB_PARSE_CONTEXT ParseContext,
  220. IN PCATTRIBUTE_NAME_DESCRIPTOR AttributeName
  221. );
  222. static VOID WINAPI ParseErrorCallback_AttributeNotAllowed(
  223. IN PCACTCTXCTB_PARSE_CONTEXT ParseContext,
  224. IN PCATTRIBUTE_NAME_DESCRIPTOR AttributeName
  225. );
  226. static VOID WINAPI ParseErrorCallback_InvalidAttributeValue(
  227. IN PCACTCTXCTB_PARSE_CONTEXT ParseContext,
  228. IN PCATTRIBUTE_NAME_DESCRIPTOR AttributeName
  229. );
  230. private:
  231. CNodeFactory(const CNodeFactory &);
  232. void operator =(const CNodeFactory &);
  233. };
  234. #endif