/*
 * Copyright (C) 2011 Alistair Leslie-Hughes
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#pragma makedep register

import "unknwn.idl";
import "objidl.idl";
import "oaidl.idl";

interface IXMLNodeSource;
interface IXMLParser;
interface IXMLNodeFactory;
interface IMoniker;

typedef enum
{
    XML_ELEMENT = 1,
    XML_ATTRIBUTE,
    XML_PI,
    XML_XMLDECL,
    XML_DOCTYPE,
    XML_DTDATTRIBUTE,
    XML_ENTITYDECL,
    XML_ELEMENTDECL,
    XML_ATTLISTDECL,
    XML_NOTATION,
    XML_GROUP,
    XML_INCLUDESECT,
    XML_PCDATA,
    XML_CDATA,
    XML_IGNORESECT,
    XML_COMMENT,
    XML_ENTITYREF,
    XML_WHITESPACE,
    XML_NAME,
    XML_NMTOKEN,
    XML_STRING,
    XML_PEREF,
    XML_MODEL,
    XML_ATTDEF,
    XML_ATTTYPE,
    XML_ATTPRESENCE,
    XML_DTDSUBSET,
    XML_LASTNODETYPE
} XML_NODE_TYPE;

typedef enum
{
    XML_VERSION = XML_LASTNODETYPE,
    XML_ENCODING,
    XML_STANDALONE,
    XML_NS,
    XML_XMLSPACE,
    XML_XMLLANG,
    XML_SYSTEM,
    XML_PUBLIC,
    XML_NDATA,
    XML_AT_CDATA,
    XML_AT_ID,
    XML_AT_IDREF,
    XML_AT_IDREFS,
    XML_AT_ENTITY,
    XML_AT_ENTITIES,
    XML_AT_NMTOKEN,
    XML_AT_NMTOKENS,
    XML_AT_NOTATION,
    XML_AT_REQUIRED,
    XML_AT_IMPLIED,
    XML_AT_FIXED,
    XML_PENTITYDECL,
    XML_EMPTY,
    XML_ANY,
    XML_MIXED,
    XML_SEQUENCE,
    XML_CHOICE,
    XML_STAR,
    XML_PLUS,
    XML_QUESTIONMARK,
    XML_LASTSUBNODETYPE
}
XML_NODE_SUBTYPE;

typedef enum
{
    XML_E_PARSEERRORBASE = 0xC00CE500L,

    XML_E_ENDOFINPUT            = XML_E_PARSEERRORBASE,
    XML_E_MISSINGEQUALS         = 0xC00CE501,
    XML_E_MISSINGQUOTE          = 0xC00CE502,
    XML_E_COMMENTSYNTAX         = 0xC00CE503,
    XML_E_BADSTARTNAMECHAR      = 0xC00CE504,
    XML_E_BADNAMECHAR           = 0xC00CE505,
    XML_E_BADCHARINSTRING       = 0xC00CE506,
    XML_E_XMLDECLSYNTAX         = 0xC00CE507,
    XML_E_BADCHARDATA           = 0xC00CE508,
    XML_E_MISSINGWHITESPACE     = 0xC00CE509,
    XML_E_EXPECTINGTAGEND       = 0xC00CE50A,
    XML_E_BADCHARINDTD          = 0xC00CE50B,
    XML_E_BADCHARINDECL         = 0xC00CE50C,
    XML_E_MISSINGSEMICOLON      = 0xC00CE50D,
    XML_E_BADCHARINENTREF       = 0xC00CE50E,
    XML_E_UNBALANCEDPAREN       = 0xC00CE50F,
    XML_E_EXPECTINGOPENBRACKET  = 0xC00CE510,
    XML_E_BADENDCONDSECT        = 0xC00CE511,
    XML_E_INTERNALERROR         = 0xC00CE512,
    XML_E_UNEXPECTED_WHITESPACE = 0xC00CE513,
    XML_E_INCOMPLETE_ENCODING   = 0xC00CE514,
    XML_E_BADCHARINMIXEDMODEL   = 0xC00CE515,
    XML_E_MISSING_STAR          = 0xC00CE516,
    XML_E_BADCHARINMODEL        = 0xC00CE517,
    XML_E_MISSING_PAREN         = 0xC00CE518,
    XML_E_BADCHARINENUMERATION  = 0xC00CE519,
    XML_E_PIDECLSYNTAX          = 0xC00CE51A,
    XML_E_EXPECTINGCLOSEQUOTE   = 0xC00CE51B,
    XML_E_MULTIPLE_COLONS       = 0xC00CE51C,
    XML_E_INVALID_DECIMAL       = 0xC00CE51D,
    XML_E_INVALID_HEXIDECIMAL   = 0xC00CE51E,
    XML_E_INVALID_UNICODE       = 0xC00CE51F,
    XML_E_WHITESPACEORQUESTIONMARK  = 0xC00CE520,
    XML_E_ENDOFPE               = 0xC00CE521,

    XML_E_TOKEN_ERROR = XML_E_PARSEERRORBASE + 0x50,
    XML_E_SUSPENDED                     =  0xC00CE550,
    XML_E_STOPPED                       = 0xC00CE551,
    XML_E_UNEXPECTEDENDTAG              = 0xC00CE552,
    XML_E_UNCLOSEDTAG                   = 0xC00CE553,
    XML_E_DUPLICATEATTRIBUTE            = 0xC00CE554,
    XML_E_MULTIPLEROOTS                 = 0xC00CE555,
    XML_E_INVALIDATROOTLEVEL            = 0xC00CE556,
    XML_E_BADXMLDECL                    = 0xC00CE557,
    XML_E_MISSINGROOT                   = 0xC00CE558,
    XML_E_UNEXPECTEDEOF                 = 0xC00CE559,
    XML_E_BADPEREFINSUBSET              = 0xC00CE55A,
    XML_E_PE_NESTING                    = 0xC00CE55B,
    XML_E_INVALID_CDATACLOSINGTAG       = 0xC00CE55C,
    XML_E_UNCLOSEDPI                    = 0xC00CE55D,
    XML_E_UNCLOSEDSTARTTAG              = 0xC00CE55E,
    XML_E_UNCLOSEDENDTAG                = 0xC00CE55F,
    XML_E_UNCLOSEDSTRING                = 0xC00CE560,
    XML_E_UNCLOSEDCOMMENT               = 0xC00CE561,
    XML_E_UNCLOSEDDECL                  = 0xC00CE562,
    XML_E_UNCLOSEDMARKUPDECL            = 0xC00CE563,
    XML_E_UNCLOSEDCDATA                 = 0xC00CE564,
    XML_E_BADDECLNAME                   = 0xC00CE565,
    XML_E_BADEXTERNALID                 = 0xC00CE566,
    XML_E_BADELEMENTINDTD               = 0xC00CE567,
    XML_E_RESERVEDNAMESPACE             = 0xC00CE568,
    XML_E_EXPECTING_VERSION             = 0xC00CE569,
    XML_E_EXPECTING_ENCODING            = 0xC00CE56A,
    XML_E_EXPECTING_NAME                = 0xC00CE56B,
    XML_E_UNEXPECTED_ATTRIBUTE          = 0xC00CE56C,
    XML_E_ENDTAGMISMATCH                = 0xC00CE56D,
    XML_E_INVALIDENCODING               = 0xC00CE56E,
    XML_E_INVALIDSWITCH                 = 0xC00CE56F,
    XML_E_EXPECTING_NDATA               = 0xC00CE570,
    XML_E_INVALID_MODEL                 = 0xC00CE571,
    XML_E_INVALID_TYPE                  = 0xC00CE572,
    XML_E_INVALIDXMLSPACE               = 0xC00CE573,
    XML_E_MULTI_ATTR_VALUE              = 0xC00CE574,
    XML_E_INVALID_PRESENCE              = 0xC00CE575,
    XML_E_BADXMLCASE                    = 0xC00CE576,
    XML_E_CONDSECTINSUBSET              = 0xC00CE577,
    XML_E_CDATAINVALID                  = 0xC00CE578,
    XML_E_INVALID_STANDALONE            = 0xC00CE579,
    XML_E_UNEXPECTED_STANDALONE         = 0xC00CE57A,
    XML_E_DOCTYPE_IN_DTD                = 0xC00CE57B,
    XML_E_MISSING_ENTITY                = 0xC00CE57C,
    XML_E_ENTITYREF_INNAME              = 0xC00CE57D,
    XML_E_DOCTYPE_OUTSIDE_PROLOG        = 0xC00CE57E,
    XML_E_INVALID_VERSION               = 0xC00CE57F,
    XML_E_DTDELEMENT_OUTSIDE_DTD        = 0xC00CE580,
    XML_E_DUPLICATEDOCTYPE              = 0xC00CE581,
    XML_E_RESOURCE                      = 0xC00CE582,
    XML_E_MISSINGNAME                   = 0xC00CE583,
    XML_E_LASTERROR                     = 0xC00CE584
} XML_ERROR_CODE;

typedef enum
{
    XMLPARSER_IDLE,
    XMLPARSER_WAITING,
    XMLPARSER_BUSY,
    XMLPARSER_ERROR,
    XMLPARSER_STOPPED,
    XMLPARSER_SUSPENDED
} XML_PARSER_STATE;

typedef enum
{
    XMLFLAG_FLOATINGAMP       = 0x00000001,
    XMLFLAG_SHORTENDTAGS      = 0x00000002,
    XMLFLAG_CASEINSENSITIVE   = 0x00000004,
    XMLFLAG_NONAMESPACES      = 0x00000008,
    XMLFLAG_NOWHITESPACE      = 0x00000010,
    XMLFLAG_IE4QUIRKS         = 0x00000020,
    XMLFLAG_NODTDNODES        = 0x00000040,
    XMLFLAG_IE4COMPATIBILITY  = 0x000000FF,
    XMLFLAG_IE5COMPATIBILITY  = 0x00000100,
    XMLFLAG_SAX               = 0x00000200,
    XMLFLAG_NORMALIZELB       = 0x00000400,
    XMLFLAG_IGNOREENCODING    = 0x00000800,
    XMLFLAG_USEWINHTTP        = 0x00001000,
    XMLFLAG_RUNBUFFERONLY     = 0x00002000,
    XMLFLAG_PROHIBIT_DTD      = 0x00008000
} XML_PARSER_FLAGS;


typedef enum
{
    XMLNF_STARTDOCUMENT,
    XMLNF_STARTDTD,
    XMLNF_ENDDTD,
    XMLNF_STARTDTDSUBSET,
    XMLNF_ENDDTDSUBSET,
    XMLNF_ENDPROLOG,
    XMLNF_STARTENTITY,
    XMLNF_ENDENTITY,
    XMLNF_ENDDOCUMENT,
    XMLNF_DATAAVAILABLE,
    XMLNF_LASTEVENT = XMLNF_DATAAVAILABLE
} XML_NODEFACTORY_EVENT;

typedef struct _XML_NODE_INFO
{
    DWORD           dwSize;
    DWORD           dwType;
    DWORD           dwSubType;
    BOOL            fTerminal;
    const WCHAR*    pwcText;
    ULONG           ulLen;
    ULONG           ulNsPrefixLen;
    PVOID           pNode;
    PVOID           pReserved;
} XML_NODE_INFO;

[
    uuid(d242361c-51a0-11d2-9caf-0060b0ec3d39),
    helpstring("Microsoft XML Parser 1.0"),
    lcid(0x0000),
    version(1.0)
]
library XMLPSR
{
/* importlib("stdole32.tlb"); */
importlib("stdole2.tlb");

[
    local,
    object,
    pointer_default(unique),
    helpstring("IXMLNodeFactory Interface"),
    uuid(d242361f-51a0-11d2-9caf-0060b0ec3d39)
]
interface IXMLNodeFactory : IUnknown
{
    HRESULT NotifyEvent([in] IXMLNodeSource* pSource,[in] XML_NODEFACTORY_EVENT iEvt);
    HRESULT BeginChildren([in] IXMLNodeSource* pSource, [in] XML_NODE_INFO* pNodeInfo);
    HRESULT EndChildren([in] IXMLNodeSource* pSource, [in] BOOL fEmpty, [in] XML_NODE_INFO* pNodeInfo);
    HRESULT Error([in] IXMLNodeSource* pSource,[in] HRESULT hrErrorCode,
                [in] USHORT cNumRecs, [in] XML_NODE_INFO** ppNodeInfo);
    HRESULT CreateNode([in] IXMLNodeSource* pSource, [in] PVOID pNodeParent, [in] USHORT cNumRecs,
                [in] XML_NODE_INFO** ppNodeInfo);
};

[
    local,
    object,
    pointer_default(unique),
    uuid(d242361d-51a0-11d2-9caf-0060b0ec3d39)
]
interface IXMLNodeSource : IUnknown
{
    HRESULT SetFactory([in] IXMLNodeFactory* pNodeFactory);
    HRESULT GetFactory([out] IXMLNodeFactory** ppNodeFactory);
    HRESULT Abort([in] BSTR bstrErrorInfo);
    ULONG GetLineNumber();
    ULONG GetLinePosition();
    ULONG GetAbsolutePosition();
    HRESULT GetLineBuffer([out] const WCHAR** ppBuf,[out] ULONG* Len, [out] ULONG* StartPos);
    HRESULT GetLastError();
    HRESULT GetErrorInfo([out] BSTR* pErrorInfo);
    ULONG GetFlags();
    HRESULT GetURL([out] const WCHAR** ppBuf);
};

[
    local,
    object,
    pointer_default(unique),
    helpstring("IXMLParser Interface"),
    uuid(d242361e-51a0-11d2-9caf-0060b0ec3d39)
]
interface IXMLParser : IXMLNodeSource
{
    HRESULT SetURL([in] const WCHAR* pszBaseUrl,[in] const WCHAR* pszRelativeUrl,[in] BOOL fAsync);
    HRESULT Load([in] BOOL fFullyAvailable, [in] IMoniker *pimkName, [in] LPBC pibc, [in] DWORD grfMode);
    HRESULT SetInput([in] IUnknown *pStm);
    HRESULT PushData([in] const char* pData, [in] ULONG ulChars, [in] BOOL fLastBuffer);
    HRESULT LoadDTD([in] const WCHAR* pszBaseUrl, [in] const WCHAR* pszRelativeUrl);
    HRESULT LoadEntity([in] const WCHAR* pszBaseUrl, [in] const WCHAR* pszRelativeUrl, [in] BOOL fpe);
    HRESULT ParseEntity([in] const WCHAR* pwcText, [in] ULONG ulLen, [in] BOOL fpe);
    HRESULT ExpandEntity([in] const WCHAR* pwcText, [in] ULONG ulLen);
    HRESULT SetRoot([in] PVOID pRoot);
    HRESULT GetRoot([in] PVOID* ppRoot);
    HRESULT Run([in] long lChars);
    HRESULT GetParserState();
    HRESULT Suspend();
    HRESULT Reset();
    HRESULT SetFlags([in] ULONG iFlags);
    HRESULT SetSecureBaseURL([in] const WCHAR* pszBaseUrl);
    HRESULT GetSecureBaseURL([out] const WCHAR** ppwcBuf);
};

}

[
    helpstring("XML Parser"),
    uuid(f5078f19-c551-11d3-89b9-0000f81fe221),
    threading(both),
    progid("Msxml2.XMLParser"),
    vi_progid("Msxml2.XMLParser"),
    version(3.0)
]
coclass XMLParser
{
    [default] interface IXMLParser;
};

[
    helpstring("XML Parser 2.6"),
    uuid(f5078f20-c551-11d3-89b9-0000f81fe221),
    threading(both),
    progid("Msxml2.XMLParser.2.6"),
    vi_progid("Msxml2.XMLParser"),
    version(2.6)
]
coclass XMLParser26
{
    [default] interface IXMLParser;
};

[
    helpstring("XML Parser 3.0"),
    uuid(f5078f31-c551-11d3-89b9-0000f81fe221),
    threading(both),
    progid("Msxml2.XMLParser.3.0"),
    vi_progid("Msxml2.XMLParser"),
    version(3.0)
]
coclass XMLParser30
{
    [default] interface IXMLParser;
};

[
    helpstring("XML Document"),
    threading(apartment),
    uuid(48123bc4-99d9-11d1-a6b3-00c04fd91555),
    progid("xmlfile"),
    version(1.0)
]
coclass XMLView
{
    interface IPersistMoniker;
    interface IPersistHistory;
    interface IOleCommandTarget;
    interface IOleObject;
}