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.

356 lines
12 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // fusion\xmlparser\XMLParser.hxx
  4. //
  5. /////////////////////////////////////////////////////////////////////////////////
  6. #ifndef _FUSION_XMLPARSER__XMLPARSER_H_INCLUDE_
  7. #define _FUSION_XMLPARSER__XMLPARSER_H_INCLUDE_
  8. #pragma once
  9. #include <ole2.h>
  10. #include <xmlparser.h>
  11. #include "xmlhelper.hxx"
  12. class XMLStream;
  13. typedef _reference<IXMLParser> RXMLParser;
  14. typedef _reference<IXMLNodeFactory> RNodeFactory;
  15. typedef _reference<IUnknown> RUnknown;
  16. typedef _reference<IBindStatusCallback> RIBindStatusCallback;
  17. #include "encodingstream.hxx"
  18. #include "_rawstack.hxx"
  19. //#define XMLFLAG_RUNBUFFERONLY 0x1000
  20. //------------------------------------------------------------------------
  21. // An internal Parser IID so that DTDNodeFactory can call internal methods.
  22. const IID IID_Parser = {0xa79b04fe,0x8b3c,0x11d2,{0x9c, 0xd3,0x00,0x60,0xb0,0xec,0x3d,0x30}};
  23. class XMLParser : public _unknown<IXMLParser, &IID_IXMLParser>
  24. {
  25. public:
  26. XMLParser();
  27. ~XMLParser();
  28. // ======= IUnknown override ============================
  29. virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void ** ppvObject);
  30. virtual ULONG STDMETHODCALLTYPE AddRef(void);
  31. virtual ULONG STDMETHODCALLTYPE Release(void);
  32. // ====== IXMLNodeSource methods ========================
  33. virtual HRESULT STDMETHODCALLTYPE SetFactory(
  34. /* [in] */ IXMLNodeFactory __RPC_FAR *pNodeFactory);
  35. virtual HRESULT STDMETHODCALLTYPE GetFactory(
  36. /* [out] */ IXMLNodeFactory** ppNodeFactory);
  37. virtual HRESULT STDMETHODCALLTYPE Abort(
  38. /* [in] */ BSTR bstrErrorInfo);
  39. virtual ULONG STDMETHODCALLTYPE GetLineNumber(void);
  40. virtual ULONG STDMETHODCALLTYPE GetLinePosition(void);
  41. virtual ULONG STDMETHODCALLTYPE GetAbsolutePosition(void);
  42. virtual HRESULT STDMETHODCALLTYPE GetLineBuffer(
  43. /* [out] */ const WCHAR **ppwcBuf,
  44. /* [out] */ ULONG *pulLen,
  45. /* [out] */ ULONG *pulStartPos);
  46. virtual HRESULT STDMETHODCALLTYPE GetLastError(void);
  47. virtual HRESULT STDMETHODCALLTYPE GetErrorInfo(/* [out] */ BSTR *pbstrErrorInfo)
  48. {
  49. ASSERT_NTC(FALSE);
  50. UNUSED(pbstrErrorInfo);
  51. return E_NOTIMPL;
  52. }
  53. virtual ULONG STDMETHODCALLTYPE GetFlags() {
  54. return 0;
  55. }
  56. virtual HRESULT STDMETHODCALLTYPE GetURL(
  57. /* [out] */ const WCHAR **ppwcBuf) {
  58. UNUSED(ppwcBuf);
  59. return E_NOTIMPL;
  60. }
  61. // ====== IXMLParser methods ==============================
  62. virtual HRESULT STDMETHODCALLTYPE SetURL(
  63. /* [in] */ const WCHAR* pszBaseUrl,
  64. /* [in] */ const WCHAR* pszRelativeUrl,
  65. /* [in] */ BOOL async) {
  66. UNUSED(pszBaseUrl);
  67. UNUSED(pszRelativeUrl);
  68. UNUSED(async);
  69. return E_NOTIMPL;
  70. }
  71. virtual HRESULT STDMETHODCALLTYPE Load(
  72. /* [in] */ BOOL fFullyAvailable,
  73. /* [in] */ IMoniker *pimkName,
  74. /* [in] */ LPBC pibc,
  75. /* [in] */ DWORD grfMode) {
  76. UNUSED(fFullyAvailable);
  77. UNUSED(pimkName);
  78. UNUSED(pibc);
  79. UNUSED(grfMode);
  80. return E_NOTIMPL;
  81. }
  82. virtual HRESULT STDMETHODCALLTYPE SetInput(
  83. /* [in] */ IUnknown*pStm);
  84. virtual HRESULT STDMETHODCALLTYPE PushData(
  85. /* [in] */ const char *pData,
  86. /* [in] */ ULONG ulChars,
  87. /* [in] */ BOOL bLastBuffer);
  88. virtual HRESULT STDMETHODCALLTYPE LoadEntity(
  89. /* [in] */ const WCHAR* pszBaseUrl,
  90. /* [in] */ const WCHAR* pszRelativeUrl,
  91. /* [in] */ BOOL fpe) {
  92. UNUSED(pszBaseUrl);
  93. UNUSED(pszRelativeUrl);
  94. UNUSED(fpe);
  95. return E_NOTIMPL;
  96. }
  97. virtual HRESULT STDMETHODCALLTYPE ParseEntity(
  98. /* [in] */ const WCHAR* pwcText,
  99. /* [in] */ ULONG ulLen,
  100. /* [in] */ BOOL fpe){
  101. UNUSED(pwcText);
  102. UNUSED(ulLen);
  103. UNUSED(fpe);
  104. return E_NOTIMPL;
  105. }
  106. virtual HRESULT STDMETHODCALLTYPE ExpandEntity(
  107. /* [in] */ const WCHAR* pwcText,
  108. /* [in] */ ULONG ulLen) {
  109. UNUSED(pwcText);
  110. UNUSED(ulLen);
  111. return E_NOTIMPL;
  112. }
  113. virtual HRESULT STDMETHODCALLTYPE SetRoot(
  114. /* [in] */ PVOID pRoot) {
  115. UNUSED(pRoot);
  116. return E_NOTIMPL;
  117. }
  118. virtual HRESULT STDMETHODCALLTYPE GetRoot(
  119. /* [in] */ PVOID __RPC_FAR *ppRoot){
  120. UNUSED(ppRoot);
  121. return E_NOTIMPL;
  122. }
  123. virtual HRESULT STDMETHODCALLTYPE Run(
  124. /* [in] */ long lChars);
  125. virtual HRESULT STDMETHODCALLTYPE GetParserState(void) ;
  126. virtual HRESULT STDMETHODCALLTYPE Suspend(void) ;
  127. virtual HRESULT STDMETHODCALLTYPE Reset(void) ;
  128. virtual HRESULT STDMETHODCALLTYPE SetFlags(
  129. /* [in] */ ULONG iFlags) {
  130. UNUSED(iFlags);
  131. return E_NOTIMPL;
  132. }
  133. virtual HRESULT STDMETHODCALLTYPE LoadDTD(
  134. /* [in] */ const WCHAR * pszBaseUrl,
  135. /* [in] */ const WCHAR * pszRelativeUrl){
  136. UNUSED(pszBaseUrl);
  137. UNUSED(pszRelativeUrl);
  138. return E_NOTIMPL;
  139. }
  140. virtual HRESULT STDMETHODCALLTYPE SetSecureBaseURL(
  141. /* [in] */ const WCHAR* pszBaseUrl){
  142. UNUSED(pszBaseUrl);
  143. return E_NOTIMPL;
  144. }
  145. virtual HRESULT STDMETHODCALLTYPE GetSecureBaseURL(
  146. /* [out] */ const WCHAR ** ppwcBuf){
  147. UNUSED(ppwcBuf);
  148. return E_NOTIMPL;
  149. }
  150. // ======= internal only methods for Parser
  151. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  152. HRESULT SetCurrentURL(
  153. /* [in] */ const WCHAR* pszCurrentUrl); // SRC attribute on <SCRIPT island>
  154. // used by SetInput()
  155. HRESULT SetBaseURL(
  156. /* [in] */ const WCHAR* pszBaseUrl); // in case PushData is called.
  157. #endif
  158. HRESULT ErrorCallback(HRESULT hr);
  159. private:
  160. void ctorInit();
  161. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  162. HRESULT PushURL(
  163. /* [in] */ const WCHAR* pszBaseUrl,
  164. /* [in] */ const WCHAR* pszRelativeUrl,
  165. /* [in] */ bool async,
  166. /* [in] */ bool tokenizer,
  167. /* [in] */ bool dtd,
  168. /* [in] */ bool fentity,
  169. /* [in] */ bool fpe );
  170. // used in SetURL(). LoadDTDDate(), LoadEntity();
  171. #endif
  172. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  173. HRESULT PushTokenizer(URLStream* stream);
  174. #else
  175. HRESULT PushTokenizer();
  176. #endif
  177. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  178. HRESULT PushDownload(URLStream* stream, XMLStream* tokenizer);
  179. #else
  180. HRESULT PushDownload(XMLStream* tokenizer);
  181. #endif
  182. HRESULT PopDownload();
  183. XMLStream* _pTokenizer;
  184. PVOID _pRoot;
  185. HRESULT _fLastError;
  186. BSTR _bstrError;
  187. bool _fWaiting;
  188. bool _fSuspended;
  189. bool _fStopped;
  190. bool _fStarted;
  191. bool _fInXmlDecl;
  192. bool _fFoundEncoding;
  193. USHORT _usFlags;
  194. bool _fCaseInsensitive;
  195. //bool _fTokenizerChanged; // used in DTD, tokenizer may change in DTD file
  196. bool _fGotVersion; // used in XML_VERSION
  197. long _fRunEntryCount; // used in Run(), counting how many is running the Parsing-While
  198. //bool _fInLoading; // used in PushURL(), Load(), HandleData(),
  199. bool _fInsideRun; // used in Run()
  200. bool _fFoundRoot;
  201. //bool _fSeenDocType; // used in DTD
  202. bool _fRootLevel; // whether we are at the root level in document.
  203. bool _fFoundNonWS;
  204. bool _fPendingBeginChildren;
  205. bool _fPendingEndChildren;
  206. //BSTR _fAttemptedURL; // used in PushURL(), Load(), GetErrorInfo();
  207. struct Download
  208. {
  209. XMLStream* _pTokenizer;
  210. //RURLStream _pURLStream;
  211. REncodingStream _pEncodingStream;
  212. bool _fAsync;
  213. bool _fDTD;
  214. bool _fEntity;
  215. bool _fPEReference;
  216. bool _fFoundNonWS;
  217. bool _fFoundRoot; // saved values in case we're downloading a schema
  218. bool _fSeenDocType;
  219. bool _fRootLevel; // whether we are at the root level in document.
  220. int _fDepth; // current depth of stack.
  221. };
  222. _rawstack<Download> _pDownloads;
  223. Download* _pdc; // current download.
  224. // the Context struct contains members that map to the XML_NODE_INFO struct
  225. // defined in xmlparser.idl so that we can pass the contents of the Context
  226. // as a XML_NODE_INFO* pointer in BeginChildren, EndChildren and Error.
  227. typedef struct _MY_XML_NODE_INFO : public XML_NODE_INFO
  228. {
  229. // DWORD dwSize; // size of this struct
  230. // DWORD dwType; // node type (XML_NODE_TYPE)
  231. // DWORD dwSubType; // node sub type (XML_NODE_SUBTYPE)
  232. // BOOL fTerminal; // whether this node can have any children
  233. // WCHAR* pwcText; // element names, or text node contents.
  234. // ULONG ulLen; // length of pwcText
  235. // ULONG ulNsPrefixLen; // if element name, this is namespace prefix length.
  236. // PVOID pNode; // optionally created by & returned from node factory
  237. // PVOID pReserved; // reserved for factories to use between themselves.
  238. WCHAR* _pwcTagName; // saved tag name
  239. ULONG _ulBufLen;
  240. } MY_XML_NODE_INFO;
  241. typedef MY_XML_NODE_INFO* PMY_XML_NODE_INFO;
  242. _rawstack<MY_XML_NODE_INFO> _pStack;
  243. long _lCurrentElement;
  244. PMY_XML_NODE_INFO _pCurrent;
  245. USHORT _cAttributes; // count of attributes on stack.
  246. // And we need a contiguous array of pointers to the XML_NODE_INFO
  247. // structs for CreateNode.
  248. PMY_XML_NODE_INFO* _paNodeInfo;
  249. USHORT _cNodeInfoAllocated;
  250. USHORT _cNodeInfoCurrent;
  251. PVOID _pNode; // current node (== pCurrent->pNode OR _pRoot).
  252. // Push saves this factory in the context and pop restores it
  253. // from the context.
  254. RNodeFactory _pFactory; // current factory (!= pCurrent->pParentFactory).
  255. HRESULT push(XML_NODE_INFO& info);
  256. HRESULT pushAttribute(XML_NODE_INFO& info);
  257. HRESULT pushAttributeValue(XML_NODE_INFO& info);
  258. HRESULT pop(const WCHAR* tag, ULONG len);
  259. HRESULT pop();
  260. HRESULT popAttributes();
  261. void popAttribute();
  262. HRESULT popDTDAttribute() { return E_NOTIMPL; }
  263. HRESULT CopyContext();
  264. HRESULT CopyText(PMY_XML_NODE_INFO pNodeInfo);
  265. HRESULT ReportUnclosedTags(int index);
  266. HRESULT GrowBuffer(PMY_XML_NODE_INFO pNodeInfo, long newlen);
  267. HRESULT GrowNodeInfo();
  268. CRITICAL_SECTION _cs;
  269. HRESULT init();
  270. HRESULT PushStream(IStream* pStm, bool fpe);
  271. //Download* FindDownload(URLStream* pStream);
  272. WCHAR* getSecureBaseURL()
  273. {
  274. if (_pszSecureBaseURL)
  275. return _pszSecureBaseURL;
  276. else if (_dwSafetyOptions)
  277. return _pszBaseURL;
  278. return NULL;
  279. }
  280. WCHAR* _pszSecureBaseURL;
  281. WCHAR* _pszCurrentURL;
  282. WCHAR* _pszBaseURL;
  283. bool _fIgnoreEncodingAttr;
  284. DWORD _dwSafetyOptions;
  285. };
  286. #endif // _FUSION_XMLPARSER__XMLPARSER_H_INCLUDE_