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.

302 lines
9.8 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. HRESULT ErrorCallback(HRESULT hr);
  152. HRESULT HrInitialize();
  153. private:
  154. HRESULT PushTokenizer();
  155. HRESULT PushDownload(XMLStream* tokenizer);
  156. HRESULT PopDownload();
  157. XMLStream* _pTokenizer;
  158. PVOID _pRoot;
  159. HRESULT _fLastError;
  160. BSTR _bstrError;
  161. bool _fWaiting;
  162. bool _fSuspended;
  163. bool _fStopped;
  164. bool _fStarted;
  165. bool _fInXmlDecl;
  166. bool _fFoundEncoding;
  167. USHORT _usFlags;
  168. bool _fCaseInsensitive;
  169. //bool _fTokenizerChanged; // used in DTD, tokenizer may change in DTD file
  170. bool _fGotVersion; // used in XML_VERSION
  171. long _fRunEntryCount; // used in Run(), counting how many is running the Parsing-While
  172. //bool _fInLoading; // used in PushURL(), Load(), HandleData(),
  173. bool _fInsideRun; // used in Run()
  174. bool _fFoundRoot;
  175. //bool _fSeenDocType; // used in DTD
  176. bool _fRootLevel; // whether we are at the root level in document.
  177. bool _fFoundNonWS;
  178. bool _fPendingBeginChildren;
  179. bool _fPendingEndChildren;
  180. //BSTR _fAttemptedURL; // used in PushURL(), Load(), GetErrorInfo();
  181. struct Download
  182. {
  183. XMLStream* _pTokenizer;
  184. //RURLStream _pURLStream;
  185. REncodingStream _pEncodingStream;
  186. bool _fAsync;
  187. bool _fDTD;
  188. bool _fEntity;
  189. bool _fPEReference;
  190. bool _fFoundNonWS;
  191. bool _fFoundRoot; // saved values in case we're downloading a schema
  192. bool _fSeenDocType;
  193. bool _fRootLevel; // whether we are at the root level in document.
  194. int _fDepth; // current depth of stack.
  195. };
  196. _rawstack<Download> _pDownloads;
  197. Download* _pdc; // current download.
  198. // the Context struct contains members that map to the XML_NODE_INFO struct
  199. // defined in xmlparser.idl so that we can pass the contents of the Context
  200. // as a XML_NODE_INFO* pointer in BeginChildren, EndChildren and Error.
  201. typedef struct _MY_XML_NODE_INFO : public XML_NODE_INFO
  202. {
  203. WCHAR* _pwcTagName; // saved tag name
  204. ULONG _ulBufLen;
  205. } MY_XML_NODE_INFO;
  206. typedef MY_XML_NODE_INFO* PMY_XML_NODE_INFO;
  207. _rawstack<MY_XML_NODE_INFO> _pStack;
  208. long _lCurrentElement;
  209. PMY_XML_NODE_INFO _pCurrent;
  210. USHORT _cAttributes; // count of attributes on stack.
  211. // And we need a contiguous array of pointers to the XML_NODE_INFO
  212. // structs for CreateNode.
  213. PMY_XML_NODE_INFO* _paNodeInfo;
  214. USHORT _cNodeInfoAllocated;
  215. USHORT _cNodeInfoCurrent;
  216. PVOID _pNode; // current node (== pCurrent->pNode OR _pRoot).
  217. // Push saves this factory in the context and pop restores it
  218. // from the context.
  219. RNodeFactory _pFactory; // current factory (!= pCurrent->pParentFactory).
  220. HRESULT push(XML_NODE_INFO& info);
  221. HRESULT pushAttribute(XML_NODE_INFO& info);
  222. HRESULT pushAttributeValue(XML_NODE_INFO& info);
  223. HRESULT pop(const WCHAR* tag, ULONG len);
  224. HRESULT pop();
  225. HRESULT popAttributes();
  226. void popAttribute();
  227. HRESULT popDTDAttribute() { return E_NOTIMPL; }
  228. HRESULT CopyContext();
  229. HRESULT CopyText(PMY_XML_NODE_INFO pNodeInfo);
  230. HRESULT ReportUnclosedTags(int index);
  231. HRESULT GrowBuffer(PMY_XML_NODE_INFO pNodeInfo, long newlen);
  232. HRESULT GrowNodeInfo();
  233. HRESULT init();
  234. HRESULT PushStream(IStream* pStm, bool fpe);
  235. DWORD _dwSafetyOptions;
  236. };
  237. #endif // _FUSION_XMLPARSER__XMLPARSER_H_INCLUDE_