2010-01-18 22:05:53 +01:00
|
|
|
/*
|
|
|
|
* IXmlReader implementation
|
|
|
|
*
|
2017-03-06 10:35:55 +01:00
|
|
|
* Copyright 2010, 2012-2013, 2016-2017 Nikolay Sivov
|
2010-01-18 22:05:53 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
2013-06-18 13:53:11 +02:00
|
|
|
#include <stdio.h>
|
2010-01-18 22:05:53 +01:00
|
|
|
#include <stdarg.h>
|
2017-03-31 15:58:06 +02:00
|
|
|
#include <assert.h>
|
2010-01-18 22:05:53 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "initguid.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "xmllite.h"
|
2012-11-17 17:22:47 +01:00
|
|
|
#include "xmllite_private.h"
|
2010-01-18 22:05:53 +01:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2012-12-04 10:31:25 +01:00
|
|
|
#include "wine/list.h"
|
2010-01-18 22:05:53 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(xmllite);
|
|
|
|
|
2010-01-21 16:19:20 +01:00
|
|
|
/* not defined in public headers */
|
|
|
|
DEFINE_GUID(IID_IXmlReaderInput, 0x0b3ccc9b, 0x9214, 0x428b, 0xa2, 0xae, 0xef, 0x3a, 0xa8, 0x71, 0xaf, 0xda);
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
XmlReadInState_Initial,
|
|
|
|
XmlReadInState_XmlDecl,
|
|
|
|
XmlReadInState_Misc_DTD,
|
2013-01-12 22:09:32 +01:00
|
|
|
XmlReadInState_DTD,
|
|
|
|
XmlReadInState_DTD_Misc,
|
2013-01-18 07:04:27 +01:00
|
|
|
XmlReadInState_Element,
|
2013-01-20 22:03:23 +01:00
|
|
|
XmlReadInState_Content,
|
2013-06-15 18:45:21 +02:00
|
|
|
XmlReadInState_MiscEnd, /* optional Misc at the end of a document */
|
|
|
|
XmlReadInState_Eof
|
2012-12-19 06:30:44 +01:00
|
|
|
} XmlReaderInternalState;
|
|
|
|
|
2013-03-08 11:10:26 +01:00
|
|
|
/* This state denotes where parsing was interrupted by input problem.
|
|
|
|
Reader resumes parsing using this information. */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
XmlReadResumeState_Initial,
|
|
|
|
XmlReadResumeState_PITarget,
|
2013-03-10 10:28:38 +01:00
|
|
|
XmlReadResumeState_PIBody,
|
2013-03-10 15:29:43 +01:00
|
|
|
XmlReadResumeState_CDATA,
|
2013-03-10 12:45:38 +01:00
|
|
|
XmlReadResumeState_Comment,
|
2013-06-15 18:45:21 +02:00
|
|
|
XmlReadResumeState_STag,
|
2013-10-14 06:10:34 +02:00
|
|
|
XmlReadResumeState_CharData,
|
|
|
|
XmlReadResumeState_Whitespace
|
2013-03-08 11:10:26 +01:00
|
|
|
} XmlReaderResumeState;
|
|
|
|
|
|
|
|
/* saved pointer index to resume from particular input position */
|
|
|
|
typedef enum
|
|
|
|
{
|
2013-03-10 10:28:38 +01:00
|
|
|
XmlReadResume_Name, /* PITarget, name for NCName, prefix for QName */
|
|
|
|
XmlReadResume_Local, /* local for QName */
|
2013-06-15 18:45:21 +02:00
|
|
|
XmlReadResume_Body, /* PI body, comment text, CDATA text, CharData text */
|
2013-03-08 11:10:26 +01:00
|
|
|
XmlReadResume_Last
|
|
|
|
} XmlReaderResume;
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
StringValue_LocalName,
|
2013-06-14 22:54:44 +02:00
|
|
|
StringValue_Prefix,
|
2013-01-06 21:55:36 +01:00
|
|
|
StringValue_QualifiedName,
|
2013-01-08 11:32:21 +01:00
|
|
|
StringValue_Value,
|
2013-01-06 21:55:36 +01:00
|
|
|
StringValue_Last
|
|
|
|
} XmlReaderStringValue;
|
|
|
|
|
2018-11-02 08:56:57 +01:00
|
|
|
BOOL is_namestartchar(WCHAR ch);
|
2017-03-06 10:35:55 +01:00
|
|
|
|
2013-06-18 13:53:11 +02:00
|
|
|
static const char *debugstr_nodetype(XmlNodeType nodetype)
|
|
|
|
{
|
2013-12-30 10:17:08 +01:00
|
|
|
static const char * const type_names[] =
|
2013-06-18 13:53:11 +02:00
|
|
|
{
|
|
|
|
"None",
|
|
|
|
"Element",
|
|
|
|
"Attribute",
|
|
|
|
"Text",
|
|
|
|
"CDATA",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"ProcessingInstruction",
|
|
|
|
"Comment",
|
|
|
|
"",
|
|
|
|
"DocumentType",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"Whitespace",
|
|
|
|
"",
|
|
|
|
"EndElement",
|
|
|
|
"",
|
|
|
|
"XmlDeclaration"
|
|
|
|
};
|
|
|
|
|
|
|
|
if (nodetype > _XmlNodeType_Last)
|
2013-12-30 10:16:59 +01:00
|
|
|
return wine_dbg_sprintf("unknown type=%d", nodetype);
|
|
|
|
|
2013-06-18 13:53:11 +02:00
|
|
|
return type_names[nodetype];
|
|
|
|
}
|
|
|
|
|
2014-05-14 09:52:13 +02:00
|
|
|
static const char *debugstr_reader_prop(XmlReaderProperty prop)
|
2013-06-18 13:53:11 +02:00
|
|
|
{
|
2013-12-30 10:17:08 +01:00
|
|
|
static const char * const prop_names[] =
|
2013-06-18 13:53:11 +02:00
|
|
|
{
|
|
|
|
"MultiLanguage",
|
|
|
|
"ConformanceLevel",
|
|
|
|
"RandomAccess",
|
|
|
|
"XmlResolver",
|
|
|
|
"DtdProcessing",
|
|
|
|
"ReadState",
|
|
|
|
"MaxElementDepth",
|
|
|
|
"MaxEntityExpansion"
|
|
|
|
};
|
|
|
|
|
|
|
|
if (prop > _XmlReaderProperty_Last)
|
2013-12-30 10:16:59 +01:00
|
|
|
return wine_dbg_sprintf("unknown property=%d", prop);
|
|
|
|
|
2013-06-18 13:53:11 +02:00
|
|
|
return prop_names[prop];
|
|
|
|
}
|
|
|
|
|
2012-11-17 19:54:16 +01:00
|
|
|
struct xml_encoding_data
|
|
|
|
{
|
2012-11-26 03:59:49 +01:00
|
|
|
const WCHAR *name;
|
2012-11-17 19:54:16 +01:00
|
|
|
xml_encoding enc;
|
|
|
|
UINT cp;
|
|
|
|
};
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
static const struct xml_encoding_data xml_encoding_map[] =
|
|
|
|
{
|
|
|
|
{ L"US-ASCII", XmlEncoding_USASCII, 20127 },
|
|
|
|
{ L"UTF-16", XmlEncoding_UTF16, 1200 },
|
|
|
|
{ L"UTF-8", XmlEncoding_UTF8, CP_UTF8 },
|
2012-11-17 19:54:16 +01:00
|
|
|
};
|
|
|
|
|
2014-05-15 16:49:37 +02:00
|
|
|
const WCHAR *get_encoding_name(xml_encoding encoding)
|
|
|
|
{
|
|
|
|
return xml_encoding_map[encoding].name;
|
|
|
|
}
|
|
|
|
|
2015-08-05 17:13:57 +02:00
|
|
|
xml_encoding get_encoding_from_codepage(UINT codepage)
|
|
|
|
{
|
|
|
|
int i;
|
2018-02-22 07:01:43 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(xml_encoding_map); i++)
|
2015-08-05 17:13:57 +02:00
|
|
|
{
|
|
|
|
if (xml_encoding_map[i].cp == codepage) return xml_encoding_map[i].enc;
|
|
|
|
}
|
|
|
|
return XmlEncoding_Unknown;
|
|
|
|
}
|
|
|
|
|
2012-11-17 19:54:16 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *data;
|
2013-10-09 13:37:08 +02:00
|
|
|
UINT cur;
|
2012-11-17 19:54:16 +01:00
|
|
|
unsigned int allocated;
|
|
|
|
unsigned int written;
|
2017-03-21 16:19:32 +01:00
|
|
|
BOOL prev_cr;
|
2012-11-17 19:54:16 +01:00
|
|
|
} encoded_buffer;
|
|
|
|
|
|
|
|
typedef struct input_buffer input_buffer;
|
|
|
|
|
2013-01-05 23:08:27 +01:00
|
|
|
typedef struct
|
2010-01-21 16:19:20 +01:00
|
|
|
{
|
2011-03-24 13:53:43 +01:00
|
|
|
IXmlReaderInput IXmlReaderInput_iface;
|
2010-01-21 16:19:20 +01:00
|
|
|
LONG ref;
|
2012-11-17 20:12:53 +01:00
|
|
|
/* reference passed on IXmlReaderInput creation, is kept when input is created */
|
|
|
|
IUnknown *input;
|
2012-11-17 17:40:46 +01:00
|
|
|
IMalloc *imalloc;
|
2012-11-19 05:33:55 +01:00
|
|
|
xml_encoding encoding;
|
|
|
|
BOOL hint;
|
|
|
|
WCHAR *baseuri;
|
2012-11-17 20:12:53 +01:00
|
|
|
/* stream reference set after SetInput() call from reader,
|
|
|
|
stored as sequential stream, cause currently
|
|
|
|
optimizations possible with IStream aren't implemented */
|
|
|
|
ISequentialStream *stream;
|
2012-11-17 19:54:16 +01:00
|
|
|
input_buffer *buffer;
|
2013-01-27 08:17:27 +01:00
|
|
|
unsigned int pending : 1;
|
2010-01-21 16:19:20 +01:00
|
|
|
} xmlreaderinput;
|
|
|
|
|
2013-01-27 08:54:58 +01:00
|
|
|
static const struct IUnknownVtbl xmlreaderinputvtbl;
|
|
|
|
|
2013-03-14 12:08:29 +01:00
|
|
|
/* Structure to hold parsed string of specific length.
|
|
|
|
|
|
|
|
Reader stores node value as 'start' pointer, on request
|
|
|
|
a null-terminated version of it is allocated.
|
|
|
|
|
|
|
|
To init a strval variable use reader_init_strval(),
|
|
|
|
to set strval as a reader value use reader_set_strval().
|
|
|
|
*/
|
2012-12-04 10:31:25 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2013-03-14 12:08:29 +01:00
|
|
|
WCHAR *str; /* allocated null-terminated string */
|
2013-08-20 12:07:32 +02:00
|
|
|
UINT len; /* length in WCHARs, altered after ReadValueChunk */
|
2013-10-09 13:37:08 +02:00
|
|
|
UINT start; /* input position where value starts */
|
2012-12-04 10:31:25 +01:00
|
|
|
} strval;
|
|
|
|
|
2020-12-03 00:32:47 +01:00
|
|
|
static WCHAR emptyW[] = L"";
|
2020-11-18 07:44:41 +01:00
|
|
|
static WCHAR xmlW[] = L"xml";
|
|
|
|
static WCHAR xmlnsW[] = L"xmlns";
|
2020-12-03 00:32:48 +01:00
|
|
|
static const strval strval_empty = { emptyW, 0 };
|
|
|
|
static const strval strval_xml = { xmlW, 3 };
|
|
|
|
static const strval strval_xmlns = { xmlnsW, 5 };
|
2013-01-06 21:55:36 +01:00
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position
|
|
|
|
{
|
|
|
|
UINT line_number;
|
|
|
|
UINT line_position;
|
|
|
|
};
|
|
|
|
|
2017-03-17 14:46:13 +01:00
|
|
|
enum attribute_flags
|
|
|
|
{
|
|
|
|
ATTRIBUTE_NS_DEFINITION = 0x1,
|
|
|
|
ATTRIBUTE_DEFAULT_NS_DEFINITION = 0x2,
|
|
|
|
};
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
struct attribute
|
|
|
|
{
|
|
|
|
struct list entry;
|
2016-12-09 14:38:24 +01:00
|
|
|
strval prefix;
|
2012-12-04 10:31:25 +01:00
|
|
|
strval localname;
|
2017-03-07 04:50:58 +01:00
|
|
|
strval qname;
|
2012-12-04 10:31:25 +01:00
|
|
|
strval value;
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position position;
|
2017-03-17 14:46:13 +01:00
|
|
|
unsigned int flags;
|
2012-12-04 10:31:25 +01:00
|
|
|
};
|
|
|
|
|
2013-01-20 20:46:25 +01:00
|
|
|
struct element
|
|
|
|
{
|
|
|
|
struct list entry;
|
2016-12-09 14:38:23 +01:00
|
|
|
strval prefix;
|
2013-08-19 08:42:38 +02:00
|
|
|
strval localname;
|
2016-12-09 14:38:23 +01:00
|
|
|
strval qname;
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position position;
|
2013-01-20 20:46:25 +01:00
|
|
|
};
|
|
|
|
|
2016-12-09 14:38:24 +01:00
|
|
|
struct ns
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
strval prefix;
|
|
|
|
strval uri;
|
|
|
|
struct element *element;
|
|
|
|
};
|
|
|
|
|
2013-01-05 23:08:27 +01:00
|
|
|
typedef struct
|
2012-11-17 20:22:09 +01:00
|
|
|
{
|
|
|
|
IXmlReader IXmlReader_iface;
|
|
|
|
LONG ref;
|
|
|
|
xmlreaderinput *input;
|
|
|
|
IMalloc *imalloc;
|
|
|
|
XmlReadState state;
|
2017-03-13 10:27:54 +01:00
|
|
|
HRESULT error; /* error set on XmlReadState_Error */
|
2012-12-19 06:30:44 +01:00
|
|
|
XmlReaderInternalState instate;
|
2013-03-08 11:10:26 +01:00
|
|
|
XmlReaderResumeState resumestate;
|
2012-11-19 01:00:24 +01:00
|
|
|
XmlNodeType nodetype;
|
2012-11-17 20:22:09 +01:00
|
|
|
DtdProcessing dtdmode;
|
2016-03-14 07:37:46 +01:00
|
|
|
IXmlResolver *resolver;
|
2016-10-30 09:05:28 +01:00
|
|
|
IUnknown *mlang;
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position position;
|
2012-12-04 10:31:25 +01:00
|
|
|
struct list attrs; /* attributes list for current node */
|
2012-12-06 13:05:19 +01:00
|
|
|
struct attribute *attr; /* current attribute */
|
2012-12-04 10:31:25 +01:00
|
|
|
UINT attr_count;
|
2016-12-09 14:38:24 +01:00
|
|
|
struct list nsdef;
|
|
|
|
struct list ns;
|
2013-01-20 20:46:25 +01:00
|
|
|
struct list elements;
|
2017-03-31 15:58:06 +02:00
|
|
|
int chunk_read_off;
|
2013-01-06 21:55:36 +01:00
|
|
|
strval strvalues[StringValue_Last];
|
2013-01-20 22:03:23 +01:00
|
|
|
UINT depth;
|
2013-06-18 14:31:01 +02:00
|
|
|
UINT max_depth;
|
2016-12-09 14:38:22 +01:00
|
|
|
BOOL is_empty_element;
|
2017-03-09 05:14:10 +01:00
|
|
|
struct element empty_element; /* used for empty elements without end tag <a />,
|
|
|
|
and to keep <?xml reader position */
|
2013-10-09 13:37:08 +02:00
|
|
|
UINT resume[XmlReadResume_Last]; /* offsets used to resume reader */
|
2012-11-17 20:22:09 +01:00
|
|
|
} xmlreader;
|
|
|
|
|
2012-11-17 19:54:16 +01:00
|
|
|
struct input_buffer
|
|
|
|
{
|
|
|
|
encoded_buffer utf16;
|
|
|
|
encoded_buffer encoded;
|
|
|
|
UINT code_page;
|
|
|
|
xmlreaderinput *input;
|
|
|
|
};
|
|
|
|
|
2010-01-18 22:18:22 +01:00
|
|
|
static inline xmlreader *impl_from_IXmlReader(IXmlReader *iface)
|
|
|
|
{
|
2011-03-24 13:53:43 +01:00
|
|
|
return CONTAINING_RECORD(iface, xmlreader, IXmlReader_iface);
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2010-01-21 16:19:20 +01:00
|
|
|
static inline xmlreaderinput *impl_from_IXmlReaderInput(IXmlReaderInput *iface)
|
|
|
|
{
|
2011-03-24 13:53:43 +01:00
|
|
|
return CONTAINING_RECORD(iface, xmlreaderinput, IXmlReaderInput_iface);
|
2010-01-21 16:19:20 +01:00
|
|
|
}
|
|
|
|
|
2012-11-17 17:40:46 +01:00
|
|
|
/* reader memory allocation functions */
|
|
|
|
static inline void *reader_alloc(xmlreader *reader, size_t len)
|
|
|
|
{
|
|
|
|
return m_alloc(reader->imalloc, len);
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:23 +01:00
|
|
|
static inline void *reader_alloc_zero(xmlreader *reader, size_t len)
|
|
|
|
{
|
|
|
|
void *ret = reader_alloc(reader, len);
|
|
|
|
if (ret)
|
|
|
|
memset(ret, 0, len);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-17 17:40:46 +01:00
|
|
|
static inline void reader_free(xmlreader *reader, void *mem)
|
|
|
|
{
|
2012-11-24 22:09:32 +01:00
|
|
|
m_free(reader->imalloc, mem);
|
2012-11-17 17:40:46 +01:00
|
|
|
}
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
/* Just return pointer from offset, no attempt to read more. */
|
|
|
|
static inline WCHAR *reader_get_ptr2(const xmlreader *reader, UINT offset)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &reader->input->buffer->utf16;
|
|
|
|
return (WCHAR*)buffer->data + offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline WCHAR *reader_get_strptr(const xmlreader *reader, const strval *v)
|
|
|
|
{
|
|
|
|
return v->str ? v->str : reader_get_ptr2(reader, v->start);
|
|
|
|
}
|
|
|
|
|
2013-01-20 20:46:25 +01:00
|
|
|
static HRESULT reader_strvaldup(xmlreader *reader, const strval *src, strval *dest)
|
|
|
|
{
|
|
|
|
*dest = *src;
|
|
|
|
|
|
|
|
if (src->str != strval_empty.str)
|
|
|
|
{
|
|
|
|
dest->str = reader_alloc(reader, (dest->len+1)*sizeof(WCHAR));
|
|
|
|
if (!dest->str) return E_OUTOFMEMORY;
|
2013-10-09 13:37:08 +02:00
|
|
|
memcpy(dest->str, reader_get_strptr(reader, src), dest->len*sizeof(WCHAR));
|
2013-01-20 20:46:25 +01:00
|
|
|
dest->str[dest->len] = 0;
|
2013-10-09 13:37:08 +02:00
|
|
|
dest->start = 0;
|
2013-01-20 20:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-17 17:40:46 +01:00
|
|
|
/* reader input memory allocation functions */
|
|
|
|
static inline void *readerinput_alloc(xmlreaderinput *input, size_t len)
|
|
|
|
{
|
|
|
|
return m_alloc(input->imalloc, len);
|
|
|
|
}
|
|
|
|
|
2012-11-19 00:01:46 +01:00
|
|
|
static inline void *readerinput_realloc(xmlreaderinput *input, void *mem, size_t len)
|
|
|
|
{
|
|
|
|
return m_realloc(input->imalloc, mem, len);
|
|
|
|
}
|
|
|
|
|
2012-11-17 17:40:46 +01:00
|
|
|
static inline void readerinput_free(xmlreaderinput *input, void *mem)
|
|
|
|
{
|
2012-11-24 22:09:32 +01:00
|
|
|
m_free(input->imalloc, mem);
|
2012-11-17 17:40:46 +01:00
|
|
|
}
|
|
|
|
|
2012-11-19 05:33:55 +01:00
|
|
|
static inline WCHAR *readerinput_strdupW(xmlreaderinput *input, const WCHAR *str)
|
|
|
|
{
|
|
|
|
LPWSTR ret = NULL;
|
|
|
|
|
|
|
|
if(str) {
|
|
|
|
DWORD size;
|
|
|
|
|
2019-06-27 21:49:21 +02:00
|
|
|
size = (lstrlenW(str)+1)*sizeof(WCHAR);
|
2012-11-19 05:33:55 +01:00
|
|
|
ret = readerinput_alloc(input, size);
|
|
|
|
if (ret) memcpy(ret, str, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-31 15:57:51 +02:00
|
|
|
/* This one frees stored string value if needed */
|
|
|
|
static void reader_free_strvalued(xmlreader *reader, strval *v)
|
|
|
|
{
|
|
|
|
if (v->str != strval_empty.str)
|
|
|
|
{
|
|
|
|
reader_free(reader, v->str);
|
|
|
|
*v = strval_empty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
static void reader_clear_attrs(xmlreader *reader)
|
|
|
|
{
|
|
|
|
struct attribute *attr, *attr2;
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(attr, attr2, &reader->attrs, struct attribute, entry)
|
|
|
|
{
|
2017-03-31 15:57:51 +02:00
|
|
|
reader_free_strvalued(reader, &attr->localname);
|
2017-03-31 15:58:21 +02:00
|
|
|
reader_free_strvalued(reader, &attr->value);
|
2012-12-04 10:31:25 +01:00
|
|
|
reader_free(reader, attr);
|
|
|
|
}
|
|
|
|
list_init(&reader->attrs);
|
|
|
|
reader->attr_count = 0;
|
2014-02-21 03:35:05 +01:00
|
|
|
reader->attr = NULL;
|
2012-12-04 10:31:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute data holds pointers to buffer data, so buffer shrink is not possible
|
|
|
|
while we are on a node with attributes */
|
2017-03-07 04:50:58 +01:00
|
|
|
static HRESULT reader_add_attr(xmlreader *reader, strval *prefix, strval *localname, strval *qname,
|
2017-03-17 14:46:13 +01:00
|
|
|
strval *value, const struct reader_position *position, unsigned int flags)
|
2012-12-04 10:31:25 +01:00
|
|
|
{
|
|
|
|
struct attribute *attr;
|
2017-03-31 15:57:51 +02:00
|
|
|
HRESULT hr;
|
2012-12-04 10:31:25 +01:00
|
|
|
|
|
|
|
attr = reader_alloc(reader, sizeof(*attr));
|
|
|
|
if (!attr) return E_OUTOFMEMORY;
|
|
|
|
|
2017-03-31 15:57:51 +02:00
|
|
|
hr = reader_strvaldup(reader, localname, &attr->localname);
|
2017-03-31 15:58:21 +02:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = reader_strvaldup(reader, value, &attr->value);
|
|
|
|
if (hr != S_OK)
|
|
|
|
reader_free_strvalued(reader, &attr->value);
|
|
|
|
}
|
2017-03-31 15:57:51 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
reader_free(reader, attr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:24 +01:00
|
|
|
if (prefix)
|
|
|
|
attr->prefix = *prefix;
|
|
|
|
else
|
|
|
|
memset(&attr->prefix, 0, sizeof(attr->prefix));
|
2017-03-07 04:50:58 +01:00
|
|
|
attr->qname = qname ? *qname : *localname;
|
2017-03-09 05:14:09 +01:00
|
|
|
attr->position = *position;
|
2017-03-17 14:46:13 +01:00
|
|
|
attr->flags = flags;
|
2012-12-04 10:31:25 +01:00
|
|
|
list_add_tail(&reader->attrs, &attr->entry);
|
|
|
|
reader->attr_count++;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:11 +01:00
|
|
|
/* Returns current element, doesn't check if reader is actually positioned on it. */
|
|
|
|
static struct element *reader_get_element(xmlreader *reader)
|
|
|
|
{
|
|
|
|
if (reader->is_empty_element)
|
|
|
|
return &reader->empty_element;
|
|
|
|
|
|
|
|
return LIST_ENTRY(list_head(&reader->elements), struct element, entry);
|
|
|
|
}
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
static inline void reader_init_strvalue(UINT start, UINT len, strval *v)
|
2013-03-14 12:08:29 +01:00
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
v->start = start;
|
2013-03-14 12:08:29 +01:00
|
|
|
v->len = len;
|
2013-10-09 13:37:08 +02:00
|
|
|
v->str = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const char* debug_strval(const xmlreader *reader, const strval *v)
|
|
|
|
{
|
|
|
|
return debugstr_wn(reader_get_strptr(reader, v), v->len);
|
|
|
|
}
|
|
|
|
|
2013-11-01 10:19:40 +01:00
|
|
|
/* used to initialize from constant string */
|
2013-10-09 13:37:08 +02:00
|
|
|
static inline void reader_init_cstrvalue(WCHAR *str, UINT len, strval *v)
|
|
|
|
{
|
|
|
|
v->start = 0;
|
|
|
|
v->len = len;
|
|
|
|
v->str = str;
|
2013-03-14 12:08:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-20 20:46:25 +01:00
|
|
|
static void reader_free_strvalue(xmlreader *reader, XmlReaderStringValue type)
|
|
|
|
{
|
|
|
|
reader_free_strvalued(reader, &reader->strvalues[type]);
|
|
|
|
}
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
static void reader_free_strvalues(xmlreader *reader)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
for (type = 0; type < StringValue_Last; type++)
|
|
|
|
reader_free_strvalue(reader, type);
|
|
|
|
}
|
|
|
|
|
2013-01-22 10:11:51 +01:00
|
|
|
/* This helper should only be used to test if strings are the same,
|
|
|
|
it doesn't try to sort. */
|
2013-10-09 13:37:08 +02:00
|
|
|
static inline int strval_eq(const xmlreader *reader, const strval *str1, const strval *str2)
|
2013-01-22 10:11:51 +01:00
|
|
|
{
|
|
|
|
if (str1->len != str2->len) return 0;
|
2013-10-09 13:37:08 +02:00
|
|
|
return !memcmp(reader_get_strptr(reader, str1), reader_get_strptr(reader, str2), str1->len*sizeof(WCHAR));
|
2013-01-22 10:11:51 +01:00
|
|
|
}
|
|
|
|
|
2013-01-20 20:46:25 +01:00
|
|
|
static void reader_clear_elements(xmlreader *reader)
|
|
|
|
{
|
|
|
|
struct element *elem, *elem2;
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(elem, elem2, &reader->elements, struct element, entry)
|
|
|
|
{
|
2016-12-09 14:38:28 +01:00
|
|
|
reader_free_strvalued(reader, &elem->prefix);
|
|
|
|
reader_free_strvalued(reader, &elem->localname);
|
2013-01-20 20:46:25 +01:00
|
|
|
reader_free_strvalued(reader, &elem->qname);
|
|
|
|
reader_free(reader, elem);
|
|
|
|
}
|
|
|
|
list_init(&reader->elements);
|
2017-03-17 14:46:11 +01:00
|
|
|
reader_free_strvalued(reader, &reader->empty_element.localname);
|
2017-03-17 14:46:12 +01:00
|
|
|
reader_free_strvalued(reader, &reader->empty_element.qname);
|
2016-12-09 14:38:22 +01:00
|
|
|
reader->is_empty_element = FALSE;
|
2013-01-20 20:46:25 +01:00
|
|
|
}
|
|
|
|
|
2017-07-21 14:00:03 +02:00
|
|
|
static struct ns *reader_lookup_ns(xmlreader *reader, const strval *prefix)
|
|
|
|
{
|
|
|
|
struct list *nslist = prefix ? &reader->ns : &reader->nsdef;
|
|
|
|
struct ns *ns;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_REV(ns, nslist, struct ns, entry) {
|
|
|
|
if (strval_eq(reader, prefix, &ns->prefix))
|
|
|
|
return ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-20 22:03:23 +01:00
|
|
|
static HRESULT reader_inc_depth(xmlreader *reader)
|
|
|
|
{
|
2017-03-07 04:50:59 +01:00
|
|
|
return (++reader->depth >= reader->max_depth && reader->max_depth) ? SC_E_MAXELEMENTDEPTH : S_OK;
|
2013-01-20 22:03:23 +01:00
|
|
|
}
|
|
|
|
|
2013-06-18 14:31:01 +02:00
|
|
|
static void reader_dec_depth(xmlreader *reader)
|
|
|
|
{
|
2017-03-06 10:35:59 +01:00
|
|
|
if (reader->depth)
|
|
|
|
reader->depth--;
|
2013-06-18 14:31:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:24 +01:00
|
|
|
static HRESULT reader_push_ns(xmlreader *reader, const strval *prefix, const strval *uri, BOOL def)
|
|
|
|
{
|
|
|
|
struct ns *ns;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
ns = reader_alloc(reader, sizeof(*ns));
|
|
|
|
if (!ns) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if (def)
|
|
|
|
memset(&ns->prefix, 0, sizeof(ns->prefix));
|
|
|
|
else {
|
|
|
|
hr = reader_strvaldup(reader, prefix, &ns->prefix);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
reader_free(reader, ns);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = reader_strvaldup(reader, uri, &ns->uri);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
reader_free_strvalued(reader, &ns->prefix);
|
|
|
|
reader_free(reader, ns);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ns->element = NULL;
|
|
|
|
list_add_head(def ? &reader->nsdef : &reader->ns, &ns->entry);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:23 +01:00
|
|
|
static void reader_free_element(xmlreader *reader, struct element *element)
|
2013-01-20 20:46:25 +01:00
|
|
|
{
|
2016-12-09 14:38:23 +01:00
|
|
|
reader_free_strvalued(reader, &element->prefix);
|
|
|
|
reader_free_strvalued(reader, &element->localname);
|
|
|
|
reader_free_strvalued(reader, &element->qname);
|
|
|
|
reader_free(reader, element);
|
|
|
|
}
|
2013-01-20 20:46:25 +01:00
|
|
|
|
2016-12-09 14:38:25 +01:00
|
|
|
static void reader_mark_ns_nodes(xmlreader *reader, struct element *element)
|
|
|
|
{
|
|
|
|
struct ns *ns;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(ns, &reader->ns, struct ns, entry) {
|
|
|
|
if (ns->element)
|
|
|
|
break;
|
|
|
|
ns->element = element;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(ns, &reader->nsdef, struct ns, entry) {
|
|
|
|
if (ns->element)
|
|
|
|
break;
|
|
|
|
ns->element = element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:23 +01:00
|
|
|
static HRESULT reader_push_element(xmlreader *reader, strval *prefix, strval *localname,
|
2017-03-09 05:14:09 +01:00
|
|
|
strval *qname, const struct reader_position *position)
|
2016-12-09 14:38:23 +01:00
|
|
|
{
|
|
|
|
struct element *element;
|
|
|
|
HRESULT hr;
|
2013-08-19 08:42:38 +02:00
|
|
|
|
2016-12-09 14:38:23 +01:00
|
|
|
element = reader_alloc_zero(reader, sizeof(*element));
|
2017-03-06 10:35:59 +01:00
|
|
|
if (!element)
|
|
|
|
return E_OUTOFMEMORY;
|
2016-12-09 14:38:23 +01:00
|
|
|
|
2017-03-06 10:35:59 +01:00
|
|
|
if ((hr = reader_strvaldup(reader, prefix, &element->prefix)) == S_OK &&
|
|
|
|
(hr = reader_strvaldup(reader, localname, &element->localname)) == S_OK &&
|
|
|
|
(hr = reader_strvaldup(reader, qname, &element->qname)) == S_OK)
|
2016-12-09 14:38:23 +01:00
|
|
|
{
|
2017-03-06 10:35:59 +01:00
|
|
|
list_add_head(&reader->elements, &element->entry);
|
|
|
|
reader_mark_ns_nodes(reader, element);
|
|
|
|
reader->is_empty_element = FALSE;
|
2017-03-09 05:14:09 +01:00
|
|
|
element->position = *position;
|
2016-12-09 14:38:23 +01:00
|
|
|
}
|
2017-03-06 10:35:59 +01:00
|
|
|
else
|
|
|
|
reader_free_element(reader, element);
|
2016-12-09 14:38:23 +01:00
|
|
|
|
2013-01-20 20:46:25 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:25 +01:00
|
|
|
static void reader_pop_ns_nodes(xmlreader *reader, struct element *element)
|
2013-01-22 10:11:51 +01:00
|
|
|
{
|
2016-12-09 14:38:25 +01:00
|
|
|
struct ns *ns, *ns2;
|
2013-01-22 10:11:51 +01:00
|
|
|
|
2016-12-09 14:38:25 +01:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE_REV(ns, ns2, &reader->ns, struct ns, entry) {
|
|
|
|
if (ns->element != element)
|
|
|
|
break;
|
|
|
|
|
|
|
|
list_remove(&ns->entry);
|
|
|
|
reader_free_strvalued(reader, &ns->prefix);
|
|
|
|
reader_free_strvalued(reader, &ns->uri);
|
|
|
|
reader_free(reader, ns);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!list_empty(&reader->nsdef)) {
|
|
|
|
ns = LIST_ENTRY(list_head(&reader->nsdef), struct ns, entry);
|
|
|
|
if (ns->element == element) {
|
|
|
|
list_remove(&ns->entry);
|
|
|
|
reader_free_strvalued(reader, &ns->prefix);
|
|
|
|
reader_free_strvalued(reader, &ns->uri);
|
|
|
|
reader_free(reader, ns);
|
|
|
|
}
|
2013-01-22 10:11:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:25 +01:00
|
|
|
static void reader_pop_element(xmlreader *reader)
|
|
|
|
{
|
|
|
|
struct element *element;
|
|
|
|
|
|
|
|
if (list_empty(&reader->elements))
|
|
|
|
return;
|
|
|
|
|
|
|
|
element = LIST_ENTRY(list_head(&reader->elements), struct element, entry);
|
|
|
|
list_remove(&element->entry);
|
|
|
|
|
|
|
|
reader_pop_ns_nodes(reader, element);
|
|
|
|
reader_free_element(reader, element);
|
|
|
|
|
|
|
|
/* It was a root element, the rest is expected as Misc */
|
|
|
|
if (list_empty(&reader->elements))
|
|
|
|
reader->instate = XmlReadInState_MiscEnd;
|
|
|
|
}
|
|
|
|
|
2013-01-27 08:17:27 +01:00
|
|
|
/* Always make a copy, cause strings are supposed to be null terminated. Null pointer for 'value'
|
|
|
|
means node value is to be determined. */
|
2013-01-06 21:55:36 +01:00
|
|
|
static void reader_set_strvalue(xmlreader *reader, XmlReaderStringValue type, const strval *value)
|
|
|
|
{
|
|
|
|
strval *v = &reader->strvalues[type];
|
|
|
|
|
|
|
|
reader_free_strvalue(reader, type);
|
2013-01-27 08:17:27 +01:00
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
v->str = NULL;
|
2013-10-09 13:37:08 +02:00
|
|
|
v->start = 0;
|
2013-01-27 08:17:27 +01:00
|
|
|
v->len = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
if (value->str == strval_empty.str)
|
|
|
|
*v = *value;
|
|
|
|
else
|
|
|
|
{
|
2013-03-14 12:08:29 +01:00
|
|
|
if (type == StringValue_Value)
|
|
|
|
{
|
|
|
|
/* defer allocation for value string */
|
|
|
|
v->str = NULL;
|
|
|
|
v->start = value->start;
|
|
|
|
v->len = value->len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v->str = reader_alloc(reader, (value->len + 1)*sizeof(WCHAR));
|
2013-10-09 13:37:08 +02:00
|
|
|
memcpy(v->str, reader_get_strptr(reader, value), value->len*sizeof(WCHAR));
|
2013-03-14 12:08:29 +01:00
|
|
|
v->str[value->len] = 0;
|
|
|
|
v->len = value->len;
|
|
|
|
}
|
2013-01-06 21:55:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-27 08:17:27 +01:00
|
|
|
static inline int is_reader_pending(xmlreader *reader)
|
|
|
|
{
|
|
|
|
return reader->input->pending;
|
|
|
|
}
|
|
|
|
|
2012-11-17 19:54:16 +01:00
|
|
|
static HRESULT init_encoded_buffer(xmlreaderinput *input, encoded_buffer *buffer)
|
|
|
|
{
|
|
|
|
const int initial_len = 0x2000;
|
|
|
|
buffer->data = readerinput_alloc(input, initial_len);
|
|
|
|
if (!buffer->data) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
memset(buffer->data, 0, 4);
|
2013-10-09 13:37:08 +02:00
|
|
|
buffer->cur = 0;
|
2012-11-17 19:54:16 +01:00
|
|
|
buffer->allocated = initial_len;
|
|
|
|
buffer->written = 0;
|
2017-03-21 16:19:32 +01:00
|
|
|
buffer->prev_cr = FALSE;
|
2012-11-17 19:54:16 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_encoded_buffer(xmlreaderinput *input, encoded_buffer *buffer)
|
|
|
|
{
|
|
|
|
readerinput_free(input, buffer->data);
|
|
|
|
}
|
|
|
|
|
2014-05-15 16:47:26 +02:00
|
|
|
HRESULT get_code_page(xml_encoding encoding, UINT *cp)
|
2012-11-17 19:54:16 +01:00
|
|
|
{
|
|
|
|
if (encoding == XmlEncoding_Unknown)
|
|
|
|
{
|
|
|
|
FIXME("unsupported encoding %d\n", encoding);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-11-25 06:10:46 +01:00
|
|
|
*cp = xml_encoding_map[encoding].cp;
|
2012-11-17 19:54:16 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-21 06:56:23 +01:00
|
|
|
xml_encoding parse_encoding_name(const WCHAR *name, int len)
|
2012-11-19 05:33:55 +01:00
|
|
|
{
|
|
|
|
int min, max, n, c;
|
|
|
|
|
2012-11-26 03:59:49 +01:00
|
|
|
if (!name) return XmlEncoding_Unknown;
|
2012-11-19 05:33:55 +01:00
|
|
|
|
|
|
|
min = 0;
|
2018-02-22 07:01:43 +01:00
|
|
|
max = ARRAY_SIZE(xml_encoding_map) - 1;
|
2012-11-19 05:33:55 +01:00
|
|
|
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
n = (min+max)/2;
|
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
if (len != -1)
|
2019-06-27 21:49:21 +02:00
|
|
|
c = wcsnicmp(xml_encoding_map[n].name, name, len);
|
2012-11-27 14:46:42 +01:00
|
|
|
else
|
2019-06-27 21:49:21 +02:00
|
|
|
c = wcsicmp(xml_encoding_map[n].name, name);
|
2012-11-19 05:33:55 +01:00
|
|
|
if (!c)
|
|
|
|
return xml_encoding_map[n].enc;
|
|
|
|
|
|
|
|
if (c > 0)
|
|
|
|
max = n-1;
|
|
|
|
else
|
|
|
|
min = n+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return XmlEncoding_Unknown;
|
|
|
|
}
|
|
|
|
|
2012-11-19 00:01:46 +01:00
|
|
|
static HRESULT alloc_input_buffer(xmlreaderinput *input)
|
2012-11-17 19:54:16 +01:00
|
|
|
{
|
|
|
|
input_buffer *buffer;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
input->buffer = NULL;
|
|
|
|
|
|
|
|
buffer = readerinput_alloc(input, sizeof(*buffer));
|
|
|
|
if (!buffer) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
buffer->input = input;
|
2012-11-19 00:01:46 +01:00
|
|
|
buffer->code_page = ~0; /* code page is unknown at this point */
|
|
|
|
hr = init_encoded_buffer(input, &buffer->utf16);
|
2012-11-17 19:54:16 +01:00
|
|
|
if (hr != S_OK) {
|
|
|
|
readerinput_free(input, buffer);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-11-19 00:01:46 +01:00
|
|
|
hr = init_encoded_buffer(input, &buffer->encoded);
|
2012-11-17 19:54:16 +01:00
|
|
|
if (hr != S_OK) {
|
2012-11-19 00:01:46 +01:00
|
|
|
free_encoded_buffer(input, &buffer->utf16);
|
2012-11-17 19:54:16 +01:00
|
|
|
readerinput_free(input, buffer);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
input->buffer = buffer;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_input_buffer(input_buffer *buffer)
|
|
|
|
{
|
|
|
|
free_encoded_buffer(buffer->input, &buffer->encoded);
|
|
|
|
free_encoded_buffer(buffer->input, &buffer->utf16);
|
|
|
|
readerinput_free(buffer->input, buffer);
|
|
|
|
}
|
|
|
|
|
2012-11-19 00:01:46 +01:00
|
|
|
static void readerinput_release_stream(xmlreaderinput *readerinput)
|
2012-11-17 20:12:53 +01:00
|
|
|
{
|
2012-11-17 20:22:09 +01:00
|
|
|
if (readerinput->stream) {
|
|
|
|
ISequentialStream_Release(readerinput->stream);
|
|
|
|
readerinput->stream = NULL;
|
2012-11-17 20:12:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Queries already stored interface for IStream/ISequentialStream.
|
|
|
|
Interface supplied on creation will be overwritten */
|
2014-05-13 16:25:37 +02:00
|
|
|
static inline HRESULT readerinput_query_for_stream(xmlreaderinput *readerinput)
|
2012-11-17 20:12:53 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2012-11-19 00:01:46 +01:00
|
|
|
readerinput_release_stream(readerinput);
|
2012-11-17 20:22:09 +01:00
|
|
|
hr = IUnknown_QueryInterface(readerinput->input, &IID_IStream, (void**)&readerinput->stream);
|
2012-11-17 20:12:53 +01:00
|
|
|
if (hr != S_OK)
|
2012-11-17 20:22:09 +01:00
|
|
|
hr = IUnknown_QueryInterface(readerinput->input, &IID_ISequentialStream, (void**)&readerinput->stream);
|
2012-11-17 20:12:53 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-11-19 00:01:46 +01:00
|
|
|
/* reads a chunk to raw buffer */
|
|
|
|
static HRESULT readerinput_growraw(xmlreaderinput *readerinput)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &readerinput->buffer->encoded;
|
2012-12-28 09:17:06 +01:00
|
|
|
/* to make sure aligned length won't exceed allocated length */
|
|
|
|
ULONG len = buffer->allocated - buffer->written - 4;
|
|
|
|
ULONG read;
|
2012-11-19 00:01:46 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-01-05 16:17:18 +01:00
|
|
|
/* always try to get aligned to 4 bytes, so the only case we can get partially read characters is
|
2012-11-19 00:01:46 +01:00
|
|
|
variable width encodings like UTF-8 */
|
|
|
|
len = (len + 3) & ~3;
|
|
|
|
/* try to use allocated space or grow */
|
|
|
|
if (buffer->allocated - buffer->written < len)
|
|
|
|
{
|
|
|
|
buffer->allocated *= 2;
|
|
|
|
buffer->data = readerinput_realloc(readerinput, buffer->data, buffer->allocated);
|
|
|
|
len = buffer->allocated - buffer->written;
|
|
|
|
}
|
|
|
|
|
2013-01-27 08:17:27 +01:00
|
|
|
read = 0;
|
2012-11-19 00:01:46 +01:00
|
|
|
hr = ISequentialStream_Read(readerinput->stream, buffer->data + buffer->written, len, &read);
|
2013-10-09 13:38:02 +02:00
|
|
|
TRACE("written=%d, alloc=%d, requested=%d, read=%d, ret=0x%08x\n", buffer->written, buffer->allocated, len, read, hr);
|
2013-01-27 08:17:27 +01:00
|
|
|
readerinput->pending = hr == E_PENDING;
|
|
|
|
if (FAILED(hr)) return hr;
|
2012-11-19 00:01:46 +01:00
|
|
|
buffer->written += read;
|
2021-04-15 11:50:10 +02:00
|
|
|
if (!buffer->written)
|
|
|
|
return MX_E_INPUTEND;
|
2012-11-19 00:01:46 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-10-09 13:38:34 +02:00
|
|
|
/* grows UTF-16 buffer so it has at least 'length' WCHAR chars free on return */
|
2012-11-25 06:10:46 +01:00
|
|
|
static void readerinput_grow(xmlreaderinput *readerinput, int length)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &readerinput->buffer->utf16;
|
|
|
|
|
2013-10-09 13:38:34 +02:00
|
|
|
length *= sizeof(WCHAR);
|
2012-11-25 06:10:46 +01:00
|
|
|
/* grow if needed, plus 4 bytes to be sure null terminator will fit in */
|
|
|
|
if (buffer->allocated < buffer->written + length + 4)
|
|
|
|
{
|
|
|
|
int grown_size = max(2*buffer->allocated, buffer->allocated + length);
|
|
|
|
buffer->data = readerinput_realloc(readerinput, buffer->data, grown_size);
|
|
|
|
buffer->allocated = grown_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:36:46 +02:00
|
|
|
static inline BOOL readerinput_is_utf8(xmlreaderinput *readerinput)
|
2012-11-19 00:01:46 +01:00
|
|
|
{
|
2013-12-18 23:14:16 +01:00
|
|
|
static const char startA[] = {'<','?'};
|
|
|
|
static const char commentA[] = {'<','!'};
|
2013-01-18 07:04:27 +01:00
|
|
|
encoded_buffer *buffer = &readerinput->buffer->encoded;
|
|
|
|
unsigned char *ptr = (unsigned char*)buffer->data;
|
|
|
|
|
|
|
|
return !memcmp(buffer->data, startA, sizeof(startA)) ||
|
|
|
|
!memcmp(buffer->data, commentA, sizeof(commentA)) ||
|
|
|
|
/* test start byte */
|
|
|
|
(ptr[0] == '<' &&
|
|
|
|
(
|
|
|
|
(ptr[1] && (ptr[1] <= 0x7f)) ||
|
|
|
|
(buffer->data[1] >> 5) == 0x6 || /* 2 bytes */
|
|
|
|
(buffer->data[1] >> 4) == 0xe || /* 3 bytes */
|
|
|
|
(buffer->data[1] >> 3) == 0x1e) /* 4 bytes */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT readerinput_detectencoding(xmlreaderinput *readerinput, xml_encoding *enc)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &readerinput->buffer->encoded;
|
2013-12-18 23:14:16 +01:00
|
|
|
static const char utf8bom[] = {0xef,0xbb,0xbf};
|
|
|
|
static const char utf16lebom[] = {0xff,0xfe};
|
2017-03-06 10:35:55 +01:00
|
|
|
WCHAR *ptrW;
|
2012-11-25 06:10:46 +01:00
|
|
|
|
|
|
|
*enc = XmlEncoding_Unknown;
|
|
|
|
|
2013-03-11 05:45:53 +01:00
|
|
|
if (buffer->written <= 3)
|
|
|
|
{
|
|
|
|
HRESULT hr = readerinput_growraw(readerinput);
|
|
|
|
if (FAILED(hr)) return hr;
|
2017-03-28 17:27:17 +02:00
|
|
|
if (buffer->written < 3) return MX_E_INPUTEND;
|
2013-03-11 05:45:53 +01:00
|
|
|
}
|
2012-11-19 00:01:46 +01:00
|
|
|
|
2017-03-06 10:35:55 +01:00
|
|
|
ptrW = (WCHAR *)buffer->data;
|
2012-11-19 00:01:46 +01:00
|
|
|
/* try start symbols if we have enough data to do that, input buffer should contain
|
|
|
|
first chunk already */
|
2013-01-18 07:04:27 +01:00
|
|
|
if (readerinput_is_utf8(readerinput))
|
2012-11-25 06:10:46 +01:00
|
|
|
*enc = XmlEncoding_UTF8;
|
2017-03-06 10:35:55 +01:00
|
|
|
else if (*ptrW == '<')
|
|
|
|
{
|
|
|
|
ptrW++;
|
|
|
|
if (*ptrW == '?' || *ptrW == '!' || is_namestartchar(*ptrW))
|
|
|
|
*enc = XmlEncoding_UTF16;
|
|
|
|
}
|
2012-11-25 06:10:46 +01:00
|
|
|
/* try with BOM now */
|
|
|
|
else if (!memcmp(buffer->data, utf8bom, sizeof(utf8bom)))
|
2012-11-19 00:01:46 +01:00
|
|
|
{
|
2012-11-25 06:10:46 +01:00
|
|
|
buffer->cur += sizeof(utf8bom);
|
|
|
|
*enc = XmlEncoding_UTF8;
|
|
|
|
}
|
|
|
|
else if (!memcmp(buffer->data, utf16lebom, sizeof(utf16lebom)))
|
|
|
|
{
|
|
|
|
buffer->cur += sizeof(utf16lebom);
|
|
|
|
*enc = XmlEncoding_UTF16;
|
2012-11-19 00:01:46 +01:00
|
|
|
}
|
|
|
|
|
2012-11-25 06:10:46 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int readerinput_get_utf8_convlen(xmlreaderinput *readerinput)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &readerinput->buffer->encoded;
|
|
|
|
int len = buffer->written;
|
|
|
|
|
2021-04-15 11:50:10 +02:00
|
|
|
assert(len);
|
|
|
|
|
2012-11-25 06:10:46 +01:00
|
|
|
/* complete single byte char */
|
|
|
|
if (!(buffer->data[len-1] & 0x80)) return len;
|
|
|
|
|
|
|
|
/* find start byte of multibyte char */
|
|
|
|
while (--len && !(buffer->data[len] & 0xc0))
|
|
|
|
;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2012-12-28 09:17:06 +01:00
|
|
|
/* Returns byte length of complete char sequence for buffer code page,
|
|
|
|
it's relative to current buffer position which is currently used for BOM handling
|
|
|
|
only. */
|
|
|
|
static int readerinput_get_convlen(xmlreaderinput *readerinput)
|
2012-11-25 06:10:46 +01:00
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &readerinput->buffer->encoded;
|
2012-12-20 00:29:19 +01:00
|
|
|
int len;
|
2012-11-25 06:10:46 +01:00
|
|
|
|
2012-12-28 09:17:06 +01:00
|
|
|
if (readerinput->buffer->code_page == CP_UTF8)
|
2012-11-25 06:10:46 +01:00
|
|
|
len = readerinput_get_utf8_convlen(readerinput);
|
|
|
|
else
|
|
|
|
len = buffer->written;
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
TRACE("%d\n", len - buffer->cur);
|
|
|
|
return len - buffer->cur;
|
2012-11-25 06:10:46 +01:00
|
|
|
}
|
|
|
|
|
2013-01-13 19:36:30 +01:00
|
|
|
/* It's possible that raw buffer has some leftovers from last conversion - some char
|
2012-12-28 09:17:06 +01:00
|
|
|
sequence that doesn't represent a full code point. Length argument should be calculated with
|
2013-01-13 19:36:30 +01:00
|
|
|
readerinput_get_convlen(), if it's -1 it will be calculated here. */
|
2012-12-28 09:17:06 +01:00
|
|
|
static void readerinput_shrinkraw(xmlreaderinput *readerinput, int len)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &readerinput->buffer->encoded;
|
2013-01-13 19:36:30 +01:00
|
|
|
|
|
|
|
if (len == -1)
|
|
|
|
len = readerinput_get_convlen(readerinput);
|
|
|
|
|
2021-04-15 11:50:10 +02:00
|
|
|
assert(len >= 0);
|
2013-10-09 13:37:08 +02:00
|
|
|
memmove(buffer->data, buffer->data + buffer->cur + (buffer->written - len), len);
|
2013-01-13 19:36:30 +01:00
|
|
|
/* everything below cur is lost too */
|
2013-10-09 13:37:08 +02:00
|
|
|
buffer->written -= len + buffer->cur;
|
|
|
|
/* after this point we don't need cur offset really,
|
2012-12-28 09:17:06 +01:00
|
|
|
it's used only to mark where actual data begins when first chunk is read */
|
2013-10-09 13:37:08 +02:00
|
|
|
buffer->cur = 0;
|
2012-12-28 09:17:06 +01:00
|
|
|
}
|
|
|
|
|
2017-03-21 16:19:32 +01:00
|
|
|
static void fixup_buffer_cr(encoded_buffer *buffer, int off)
|
|
|
|
{
|
|
|
|
BOOL prev_cr = buffer->prev_cr;
|
|
|
|
const WCHAR *src;
|
|
|
|
WCHAR *dest;
|
|
|
|
|
|
|
|
src = dest = (WCHAR*)buffer->data + off;
|
|
|
|
while ((const char*)src < buffer->data + buffer->written)
|
|
|
|
{
|
|
|
|
if (*src == '\r')
|
|
|
|
{
|
|
|
|
*dest++ = '\n';
|
|
|
|
src++;
|
|
|
|
prev_cr = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(prev_cr && *src == '\n')
|
|
|
|
src++;
|
|
|
|
else
|
|
|
|
*dest++ = *src++;
|
|
|
|
prev_cr = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer->written = (char*)dest - buffer->data;
|
|
|
|
buffer->prev_cr = prev_cr;
|
|
|
|
*dest = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-25 06:10:46 +01:00
|
|
|
/* note that raw buffer content is kept */
|
|
|
|
static void readerinput_switchencoding(xmlreaderinput *readerinput, xml_encoding enc)
|
|
|
|
{
|
|
|
|
encoded_buffer *src = &readerinput->buffer->encoded;
|
|
|
|
encoded_buffer *dest = &readerinput->buffer->utf16;
|
|
|
|
int len, dest_len;
|
2018-09-05 17:42:38 +02:00
|
|
|
UINT cp = ~0u;
|
2012-11-25 06:10:46 +01:00
|
|
|
HRESULT hr;
|
2012-12-19 06:30:44 +01:00
|
|
|
WCHAR *ptr;
|
2012-11-25 06:10:46 +01:00
|
|
|
|
|
|
|
hr = get_code_page(enc, &cp);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
2012-12-28 09:17:06 +01:00
|
|
|
readerinput->buffer->code_page = cp;
|
|
|
|
len = readerinput_get_convlen(readerinput);
|
2012-11-25 06:10:46 +01:00
|
|
|
|
|
|
|
TRACE("switching to cp %d\n", cp);
|
|
|
|
|
|
|
|
/* just copy in this case */
|
|
|
|
if (enc == XmlEncoding_UTF16)
|
2012-11-19 00:01:46 +01:00
|
|
|
{
|
2012-11-25 06:10:46 +01:00
|
|
|
readerinput_grow(readerinput, len);
|
2013-10-09 13:37:08 +02:00
|
|
|
memcpy(dest->data, src->data + src->cur, len);
|
2012-12-21 06:35:30 +01:00
|
|
|
dest->written += len*sizeof(WCHAR);
|
2017-03-21 16:19:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dest_len = MultiByteToWideChar(cp, 0, src->data + src->cur, len, NULL, 0);
|
|
|
|
readerinput_grow(readerinput, dest_len);
|
|
|
|
ptr = (WCHAR*)dest->data;
|
|
|
|
MultiByteToWideChar(cp, 0, src->data + src->cur, len, ptr, dest_len);
|
|
|
|
ptr[dest_len] = 0;
|
|
|
|
dest->written += dest_len*sizeof(WCHAR);
|
2012-11-19 00:01:46 +01:00
|
|
|
}
|
|
|
|
|
2017-03-21 16:19:32 +01:00
|
|
|
fixup_buffer_cr(dest, 0);
|
2012-12-21 06:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* shrinks parsed data a buffer begins with */
|
|
|
|
static void reader_shrink(xmlreader *reader)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &reader->input->buffer->utf16;
|
|
|
|
|
|
|
|
/* avoid to move too often using threshold shrink length */
|
2013-10-09 13:37:08 +02:00
|
|
|
if (buffer->cur*sizeof(WCHAR) > buffer->written / 2)
|
2012-12-21 06:35:30 +01:00
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
buffer->written -= buffer->cur*sizeof(WCHAR);
|
|
|
|
memmove(buffer->data, (WCHAR*)buffer->data + buffer->cur, buffer->written);
|
|
|
|
buffer->cur = 0;
|
|
|
|
*(WCHAR*)&buffer->data[buffer->written] = 0;
|
2012-12-21 06:35:30 +01:00
|
|
|
}
|
2012-11-19 00:01:46 +01:00
|
|
|
}
|
|
|
|
|
2012-12-28 09:17:06 +01:00
|
|
|
/* This is a normal way for reader to get new data converted from raw buffer to utf16 buffer.
|
|
|
|
It won't attempt to shrink but will grow destination buffer if needed */
|
2013-01-27 08:17:27 +01:00
|
|
|
static HRESULT reader_more(xmlreader *reader)
|
2012-12-28 09:17:06 +01:00
|
|
|
{
|
|
|
|
xmlreaderinput *readerinput = reader->input;
|
|
|
|
encoded_buffer *src = &readerinput->buffer->encoded;
|
|
|
|
encoded_buffer *dest = &readerinput->buffer->utf16;
|
|
|
|
UINT cp = readerinput->buffer->code_page;
|
2017-03-21 16:19:32 +01:00
|
|
|
int len, dest_len, prev_len;
|
2013-01-27 08:17:27 +01:00
|
|
|
HRESULT hr;
|
2012-12-28 09:17:06 +01:00
|
|
|
WCHAR *ptr;
|
|
|
|
|
|
|
|
/* get some raw data from stream first */
|
2021-04-15 11:50:10 +02:00
|
|
|
if (FAILED(hr = readerinput_growraw(readerinput)))
|
|
|
|
return hr;
|
|
|
|
|
2012-12-28 09:17:06 +01:00
|
|
|
len = readerinput_get_convlen(readerinput);
|
2017-03-21 16:19:32 +01:00
|
|
|
prev_len = dest->written / sizeof(WCHAR);
|
2012-12-28 09:17:06 +01:00
|
|
|
|
|
|
|
/* just copy for UTF-16 case */
|
2017-08-03 10:00:31 +02:00
|
|
|
if (cp == 1200)
|
2012-12-28 09:17:06 +01:00
|
|
|
{
|
|
|
|
readerinput_grow(readerinput, len);
|
2013-10-09 13:38:02 +02:00
|
|
|
memcpy(dest->data + dest->written, src->data + src->cur, len);
|
2012-12-28 09:17:06 +01:00
|
|
|
dest->written += len*sizeof(WCHAR);
|
2017-03-21 16:19:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dest_len = MultiByteToWideChar(cp, 0, src->data + src->cur, len, NULL, 0);
|
|
|
|
readerinput_grow(readerinput, dest_len);
|
|
|
|
ptr = (WCHAR*)(dest->data + dest->written);
|
|
|
|
MultiByteToWideChar(cp, 0, src->data + src->cur, len, ptr, dest_len);
|
|
|
|
ptr[dest_len] = 0;
|
|
|
|
dest->written += dest_len*sizeof(WCHAR);
|
|
|
|
/* get rid of processed data */
|
|
|
|
readerinput_shrinkraw(readerinput, len);
|
2012-12-28 09:17:06 +01:00
|
|
|
}
|
|
|
|
|
2017-03-21 16:19:32 +01:00
|
|
|
fixup_buffer_cr(dest, prev_len);
|
2013-01-27 08:17:27 +01:00
|
|
|
return hr;
|
2012-12-28 09:17:06 +01:00
|
|
|
}
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
static inline UINT reader_get_cur(xmlreader *reader)
|
2012-11-26 03:59:49 +01:00
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
return reader->input->buffer->utf16.cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline WCHAR *reader_get_ptr(xmlreader *reader)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &reader->input->buffer->utf16;
|
|
|
|
WCHAR *ptr = (WCHAR*)buffer->data + buffer->cur;
|
2012-12-28 09:17:06 +01:00
|
|
|
if (!*ptr) reader_more(reader);
|
2013-10-09 13:38:02 +02:00
|
|
|
return (WCHAR*)buffer->data + buffer->cur;
|
2012-11-26 03:59:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int reader_cmp(xmlreader *reader, const WCHAR *str)
|
|
|
|
{
|
2015-02-20 19:54:32 +01:00
|
|
|
int i=0;
|
2013-10-09 13:37:08 +02:00
|
|
|
const WCHAR *ptr = reader_get_ptr(reader);
|
2015-02-20 19:54:32 +01:00
|
|
|
while (str[i])
|
|
|
|
{
|
|
|
|
if (!ptr[i])
|
|
|
|
{
|
|
|
|
reader_more(reader);
|
|
|
|
ptr = reader_get_ptr(reader);
|
|
|
|
}
|
|
|
|
if (str[i] != ptr[i])
|
|
|
|
return ptr[i] - str[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 0;
|
2012-11-26 03:59:49 +01:00
|
|
|
}
|
|
|
|
|
2017-03-10 09:06:43 +01:00
|
|
|
static void reader_update_position(xmlreader *reader, WCHAR ch)
|
|
|
|
{
|
|
|
|
if (ch == '\r')
|
|
|
|
reader->position.line_position = 1;
|
|
|
|
else if (ch == '\n')
|
|
|
|
{
|
|
|
|
reader->position.line_number++;
|
|
|
|
reader->position.line_position = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
reader->position.line_position++;
|
|
|
|
}
|
|
|
|
|
2012-11-26 03:59:49 +01:00
|
|
|
/* moves cursor n WCHARs forward */
|
|
|
|
static void reader_skipn(xmlreader *reader, int n)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &reader->input->buffer->utf16;
|
2017-03-10 09:06:43 +01:00
|
|
|
const WCHAR *ptr;
|
2012-11-26 03:59:49 +01:00
|
|
|
|
2017-03-10 09:06:43 +01:00
|
|
|
while (*(ptr = reader_get_ptr(reader)) && n--)
|
2012-11-26 03:59:49 +01:00
|
|
|
{
|
2017-03-10 09:06:43 +01:00
|
|
|
reader_update_position(reader, *ptr);
|
2013-10-09 13:37:08 +02:00
|
|
|
buffer->cur++;
|
2012-11-26 03:59:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:36:46 +02:00
|
|
|
static inline BOOL is_wchar_space(WCHAR ch)
|
2012-12-19 06:30:44 +01:00
|
|
|
{
|
|
|
|
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
|
|
|
|
}
|
|
|
|
|
2012-11-26 03:59:49 +01:00
|
|
|
/* [3] S ::= (#x20 | #x9 | #xD | #xA)+ */
|
|
|
|
static int reader_skipspaces(xmlreader *reader)
|
|
|
|
{
|
2013-10-14 06:10:34 +02:00
|
|
|
const WCHAR *ptr = reader_get_ptr(reader);
|
|
|
|
UINT start = reader_get_cur(reader);
|
2012-11-26 03:59:49 +01:00
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
while (is_wchar_space(*ptr))
|
2012-11-26 03:59:49 +01:00
|
|
|
{
|
2017-03-10 09:06:43 +01:00
|
|
|
reader_skipn(reader, 1);
|
2013-10-14 06:10:34 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2012-11-26 03:59:49 +01:00
|
|
|
}
|
|
|
|
|
2013-10-14 06:10:34 +02:00
|
|
|
return reader_get_cur(reader) - start;
|
2012-11-26 03:59:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* [26] VersionNum ::= '1.' [0-9]+ */
|
2012-12-04 10:31:25 +01:00
|
|
|
static HRESULT reader_parse_versionnum(xmlreader *reader, strval *val)
|
2012-11-26 03:59:49 +01:00
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *ptr, *ptr2;
|
|
|
|
UINT start;
|
2012-11-26 03:59:49 +01:00
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L"1.")) return WC_E_XMLDECL;
|
2013-10-09 13:37:08 +02:00
|
|
|
|
|
|
|
start = reader_get_cur(reader);
|
2012-11-26 03:59:49 +01:00
|
|
|
/* skip "1." */
|
|
|
|
reader_skipn(reader, 2);
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr2 = ptr = reader_get_ptr(reader);
|
2012-11-26 03:59:49 +01:00
|
|
|
while (*ptr >= '0' && *ptr <= '9')
|
2013-10-09 13:37:08 +02:00
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
ptr = reader_get_ptr(reader);
|
|
|
|
}
|
2012-11-26 03:59:49 +01:00
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
if (ptr2 == ptr) return WC_E_DIGIT;
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, val);
|
|
|
|
TRACE("version=%s\n", debug_strval(reader, val));
|
2012-11-26 03:59:49 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:44:06 +01:00
|
|
|
/* [25] Eq ::= S? '=' S? */
|
|
|
|
static HRESULT reader_parse_eq(xmlreader *reader)
|
|
|
|
{
|
|
|
|
reader_skipspaces(reader);
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L"=")) return WC_E_EQUAL;
|
2012-11-28 15:44:06 +01:00
|
|
|
/* skip '=' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
reader_skipspaces(reader);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
static BOOL reader_is_quote(xmlreader *reader)
|
|
|
|
{
|
|
|
|
return !reader_cmp(reader, L"\'") || !reader_cmp(reader, L"\"");
|
|
|
|
}
|
|
|
|
|
2012-11-26 03:59:49 +01:00
|
|
|
/* [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"') */
|
|
|
|
static HRESULT reader_parse_versioninfo(xmlreader *reader)
|
|
|
|
{
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position position;
|
2012-12-04 10:31:25 +01:00
|
|
|
strval val, name;
|
2012-11-26 03:59:49 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!reader_skipspaces(reader)) return WC_E_WHITESPACE;
|
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
position = reader->position;
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L"version")) return WC_E_XMLDECL;
|
2013-03-14 12:08:29 +01:00
|
|
|
reader_init_strvalue(reader_get_cur(reader), 7, &name);
|
2012-11-26 03:59:49 +01:00
|
|
|
/* skip 'version' */
|
|
|
|
reader_skipn(reader, 7);
|
|
|
|
|
2012-11-28 15:44:06 +01:00
|
|
|
hr = reader_parse_eq(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
2012-11-26 03:59:49 +01:00
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_is_quote(reader))
|
2012-11-26 03:59:49 +01:00
|
|
|
return WC_E_QUOTE;
|
|
|
|
/* skip "'"|'"' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
hr = reader_parse_versionnum(reader, &val);
|
2012-11-26 03:59:49 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_is_quote(reader))
|
2012-11-26 03:59:49 +01:00
|
|
|
return WC_E_QUOTE;
|
|
|
|
|
|
|
|
/* skip "'"|'"' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2017-03-17 14:46:13 +01:00
|
|
|
return reader_add_attr(reader, NULL, &name, NULL, &val, &position, 0);
|
2012-11-26 03:59:49 +01:00
|
|
|
}
|
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
/* ([A-Za-z0-9._] | '-') */
|
2013-10-09 22:36:46 +02:00
|
|
|
static inline BOOL is_wchar_encname(WCHAR ch)
|
2012-11-27 14:46:42 +01:00
|
|
|
{
|
|
|
|
return ((ch >= 'A' && ch <= 'Z') ||
|
|
|
|
(ch >= 'a' && ch <= 'z') ||
|
|
|
|
(ch >= '0' && ch <= '9') ||
|
|
|
|
(ch == '.') || (ch == '_') ||
|
|
|
|
(ch == '-'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* */
|
2012-12-04 10:31:25 +01:00
|
|
|
static HRESULT reader_parse_encname(xmlreader *reader, strval *val)
|
2012-11-27 14:46:42 +01:00
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *start = reader_get_ptr(reader), *ptr;
|
2012-11-27 14:46:42 +01:00
|
|
|
xml_encoding enc;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if ((*start < 'A' || *start > 'Z') && (*start < 'a' || *start > 'z'))
|
|
|
|
return WC_E_ENCNAME;
|
|
|
|
|
2014-02-12 08:58:06 +01:00
|
|
|
val->start = reader_get_cur(reader);
|
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
ptr = start;
|
|
|
|
while (is_wchar_encname(*++ptr))
|
|
|
|
;
|
|
|
|
|
|
|
|
len = ptr - start;
|
|
|
|
enc = parse_encoding_name(start, len);
|
|
|
|
TRACE("encoding name %s\n", debugstr_wn(start, len));
|
2012-12-04 10:31:25 +01:00
|
|
|
val->str = start;
|
|
|
|
val->len = len;
|
2012-11-27 14:46:42 +01:00
|
|
|
|
|
|
|
if (enc == XmlEncoding_Unknown)
|
|
|
|
return WC_E_ENCNAME;
|
|
|
|
|
|
|
|
/* skip encoding name */
|
|
|
|
reader_skipn(reader, len);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" ) */
|
|
|
|
static HRESULT reader_parse_encdecl(xmlreader *reader)
|
|
|
|
{
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position position;
|
2012-12-04 10:31:25 +01:00
|
|
|
strval name, val;
|
2012-11-27 14:46:42 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2014-02-11 08:50:30 +01:00
|
|
|
if (!reader_skipspaces(reader)) return S_FALSE;
|
2012-11-27 14:46:42 +01:00
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
position = reader->position;
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L"encoding")) return S_FALSE;
|
2013-10-09 13:37:08 +02:00
|
|
|
name.str = reader_get_ptr(reader);
|
2014-02-12 08:58:06 +01:00
|
|
|
name.start = reader_get_cur(reader);
|
2012-12-04 10:31:25 +01:00
|
|
|
name.len = 8;
|
2012-11-27 14:46:42 +01:00
|
|
|
/* skip 'encoding' */
|
|
|
|
reader_skipn(reader, 8);
|
|
|
|
|
2012-11-28 15:44:06 +01:00
|
|
|
hr = reader_parse_eq(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
2012-11-27 14:46:42 +01:00
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_is_quote(reader))
|
2012-11-27 14:46:42 +01:00
|
|
|
return WC_E_QUOTE;
|
|
|
|
/* skip "'"|'"' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
hr = reader_parse_encname(reader, &val);
|
2012-11-27 14:46:42 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_is_quote(reader))
|
2012-11-27 14:46:42 +01:00
|
|
|
return WC_E_QUOTE;
|
|
|
|
|
|
|
|
/* skip "'"|'"' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2017-03-17 14:46:13 +01:00
|
|
|
return reader_add_attr(reader, NULL, &name, NULL, &val, &position, 0);
|
2012-11-27 14:46:42 +01:00
|
|
|
}
|
|
|
|
|
2012-11-28 13:59:57 +01:00
|
|
|
/* [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"')) */
|
|
|
|
static HRESULT reader_parse_sddecl(xmlreader *reader)
|
|
|
|
{
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position position;
|
2012-12-04 10:31:25 +01:00
|
|
|
strval name, val;
|
2013-10-09 13:37:08 +02:00
|
|
|
UINT start;
|
2012-11-28 15:44:06 +01:00
|
|
|
HRESULT hr;
|
2012-11-28 13:59:57 +01:00
|
|
|
|
2014-02-11 08:51:21 +01:00
|
|
|
if (!reader_skipspaces(reader)) return S_FALSE;
|
2012-11-28 13:59:57 +01:00
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
position = reader->position;
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L"standalone")) return S_FALSE;
|
2013-03-14 12:08:29 +01:00
|
|
|
reader_init_strvalue(reader_get_cur(reader), 10, &name);
|
2012-11-28 13:59:57 +01:00
|
|
|
/* skip 'standalone' */
|
|
|
|
reader_skipn(reader, 10);
|
|
|
|
|
2012-11-28 15:44:06 +01:00
|
|
|
hr = reader_parse_eq(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
2012-11-28 13:59:57 +01:00
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_is_quote(reader))
|
2012-11-28 13:59:57 +01:00
|
|
|
return WC_E_QUOTE;
|
|
|
|
/* skip "'"|'"' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L"yes") && reader_cmp(reader, L"no"))
|
2012-11-28 13:59:57 +01:00
|
|
|
return WC_E_XMLDECL;
|
|
|
|
|
|
|
|
start = reader_get_cur(reader);
|
|
|
|
/* skip 'yes'|'no' */
|
2020-11-18 07:44:41 +01:00
|
|
|
reader_skipn(reader, reader_cmp(reader, L"yes") ? 2 : 3);
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, &val);
|
|
|
|
TRACE("standalone=%s\n", debug_strval(reader, &val));
|
2012-11-28 13:59:57 +01:00
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_is_quote(reader))
|
2012-11-28 13:59:57 +01:00
|
|
|
return WC_E_QUOTE;
|
|
|
|
/* skip "'"|'"' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2017-03-17 14:46:13 +01:00
|
|
|
return reader_add_attr(reader, NULL, &name, NULL, &val, &position, 0);
|
2012-11-28 13:59:57 +01:00
|
|
|
}
|
|
|
|
|
2012-11-26 03:59:49 +01:00
|
|
|
/* [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' */
|
|
|
|
static HRESULT reader_parse_xmldecl(xmlreader *reader)
|
|
|
|
{
|
2017-03-09 05:14:10 +01:00
|
|
|
struct reader_position position;
|
2012-11-26 03:59:49 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L"<?xml "))
|
2017-03-09 05:14:10 +01:00
|
|
|
return S_FALSE;
|
2012-11-26 03:59:49 +01:00
|
|
|
|
2017-03-09 05:14:10 +01:00
|
|
|
reader_skipn(reader, 2);
|
|
|
|
position = reader->position;
|
|
|
|
reader_skipn(reader, 3);
|
2012-11-26 03:59:49 +01:00
|
|
|
hr = reader_parse_versioninfo(reader);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
hr = reader_parse_encdecl(reader);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2012-11-28 13:59:57 +01:00
|
|
|
hr = reader_parse_sddecl(reader);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
reader_skipspaces(reader);
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L"?>"))
|
2017-03-09 05:14:10 +01:00
|
|
|
return WC_E_XMLDECL;
|
|
|
|
|
|
|
|
/* skip '?>' */
|
2012-11-28 13:59:57 +01:00
|
|
|
reader_skipn(reader, 2);
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
reader->nodetype = XmlNodeType_XmlDeclaration;
|
2017-03-09 05:14:10 +01:00
|
|
|
reader->empty_element.position = position;
|
2017-03-07 04:50:55 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_LocalName, &strval_xml);
|
|
|
|
reader_set_strvalue(reader, StringValue_QualifiedName, &strval_xml);
|
2012-12-19 06:30:44 +01:00
|
|
|
|
2012-11-28 13:59:57 +01:00
|
|
|
return S_OK;
|
2012-11-26 03:59:49 +01:00
|
|
|
}
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
/* [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' */
|
|
|
|
static HRESULT reader_parse_comment(xmlreader *reader)
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *ptr;
|
|
|
|
UINT start;
|
2012-12-19 06:32:37 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
if (reader->resumestate == XmlReadResumeState_Comment)
|
2013-01-27 08:17:27 +01:00
|
|
|
{
|
2013-03-08 11:10:26 +01:00
|
|
|
start = reader->resume[XmlReadResume_Body];
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-01-27 08:17:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* skip '<!--' */
|
|
|
|
reader_skipn(reader, 4);
|
|
|
|
reader_shrink(reader);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
|
|
|
start = reader_get_cur(reader);
|
2013-01-27 08:17:27 +01:00
|
|
|
reader->nodetype = XmlNodeType_Comment;
|
2013-03-08 11:10:26 +01:00
|
|
|
reader->resume[XmlReadResume_Body] = start;
|
2013-03-10 12:45:38 +01:00
|
|
|
reader->resumestate = XmlReadResumeState_Comment;
|
2013-01-27 08:17:27 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_Value, NULL);
|
|
|
|
}
|
2012-12-19 06:32:37 +01:00
|
|
|
|
2013-01-27 08:17:27 +01:00
|
|
|
/* will exit when there's no more data, it won't attempt to
|
|
|
|
read more from stream */
|
2012-12-19 06:32:37 +01:00
|
|
|
while (*ptr)
|
|
|
|
{
|
2012-12-28 09:17:06 +01:00
|
|
|
if (ptr[0] == '-')
|
2012-12-19 06:32:37 +01:00
|
|
|
{
|
2012-12-28 09:17:06 +01:00
|
|
|
if (ptr[1] == '-')
|
2012-12-19 06:32:37 +01:00
|
|
|
{
|
2012-12-28 09:17:06 +01:00
|
|
|
if (ptr[2] == '>')
|
|
|
|
{
|
2013-03-14 12:08:29 +01:00
|
|
|
strval value;
|
2013-01-08 11:32:21 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, &value);
|
|
|
|
TRACE("%s\n", debug_strval(reader, &value));
|
|
|
|
|
|
|
|
/* skip rest of markup '->' */
|
2012-12-28 09:17:06 +01:00
|
|
|
reader_skipn(reader, 3);
|
2013-10-09 13:37:08 +02:00
|
|
|
|
2013-01-08 11:32:21 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_Value, &value);
|
2013-10-09 13:37:08 +02:00
|
|
|
reader->resume[XmlReadResume_Body] = 0;
|
2013-03-10 12:45:38 +01:00
|
|
|
reader->resumestate = XmlReadResumeState_Initial;
|
2012-12-28 09:17:06 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return WC_E_COMMENT;
|
2012-12-19 06:32:37 +01:00
|
|
|
}
|
|
|
|
}
|
2013-10-09 13:37:08 +02:00
|
|
|
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
ptr++;
|
2012-12-19 06:32:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-27 08:17:27 +01:00
|
|
|
return S_OK;
|
2012-12-19 06:30:44 +01:00
|
|
|
}
|
|
|
|
|
2013-01-15 20:54:14 +01:00
|
|
|
/* [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] */
|
2013-10-09 22:36:46 +02:00
|
|
|
static inline BOOL is_char(WCHAR ch)
|
2013-01-15 20:54:14 +01:00
|
|
|
{
|
|
|
|
return (ch == '\t') || (ch == '\r') || (ch == '\n') ||
|
|
|
|
(ch >= 0x20 && ch <= 0xd7ff) ||
|
|
|
|
(ch >= 0xd800 && ch <= 0xdbff) || /* high surrogate */
|
|
|
|
(ch >= 0xdc00 && ch <= 0xdfff) || /* low surrogate */
|
|
|
|
(ch >= 0xe000 && ch <= 0xfffd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%] */
|
2018-11-02 08:56:57 +01:00
|
|
|
BOOL is_pubchar(WCHAR ch)
|
2013-01-15 20:54:14 +01:00
|
|
|
{
|
|
|
|
return (ch == ' ') ||
|
|
|
|
(ch >= 'a' && ch <= 'z') ||
|
|
|
|
(ch >= 'A' && ch <= 'Z') ||
|
|
|
|
(ch >= '0' && ch <= '9') ||
|
|
|
|
(ch >= '-' && ch <= ';') || /* '()*+,-./:; */
|
|
|
|
(ch == '=') || (ch == '?') ||
|
|
|
|
(ch == '@') || (ch == '!') ||
|
|
|
|
(ch >= '#' && ch <= '%') || /* #$% */
|
|
|
|
(ch == '_') || (ch == '\r') || (ch == '\n');
|
|
|
|
}
|
|
|
|
|
2018-11-02 08:56:57 +01:00
|
|
|
BOOL is_namestartchar(WCHAR ch)
|
2013-01-05 23:08:27 +01:00
|
|
|
{
|
|
|
|
return (ch == ':') || (ch >= 'A' && ch <= 'Z') ||
|
|
|
|
(ch == '_') || (ch >= 'a' && ch <= 'z') ||
|
|
|
|
(ch >= 0xc0 && ch <= 0xd6) ||
|
|
|
|
(ch >= 0xd8 && ch <= 0xf6) ||
|
|
|
|
(ch >= 0xf8 && ch <= 0x2ff) ||
|
|
|
|
(ch >= 0x370 && ch <= 0x37d) ||
|
|
|
|
(ch >= 0x37f && ch <= 0x1fff) ||
|
|
|
|
(ch >= 0x200c && ch <= 0x200d) ||
|
|
|
|
(ch >= 0x2070 && ch <= 0x218f) ||
|
|
|
|
(ch >= 0x2c00 && ch <= 0x2fef) ||
|
|
|
|
(ch >= 0x3001 && ch <= 0xd7ff) ||
|
|
|
|
(ch >= 0xd800 && ch <= 0xdbff) || /* high surrogate */
|
|
|
|
(ch >= 0xdc00 && ch <= 0xdfff) || /* low surrogate */
|
|
|
|
(ch >= 0xf900 && ch <= 0xfdcf) ||
|
|
|
|
(ch >= 0xfdf0 && ch <= 0xfffd);
|
|
|
|
}
|
|
|
|
|
2013-01-18 07:04:27 +01:00
|
|
|
/* [4 NS] NCName ::= Name - (Char* ':' Char*) */
|
2018-09-10 14:27:31 +02:00
|
|
|
BOOL is_ncnamechar(WCHAR ch)
|
2013-01-05 23:08:27 +01:00
|
|
|
{
|
2013-01-18 07:04:27 +01:00
|
|
|
return (ch >= 'A' && ch <= 'Z') ||
|
2013-01-05 23:08:27 +01:00
|
|
|
(ch == '_') || (ch >= 'a' && ch <= 'z') ||
|
|
|
|
(ch == '-') || (ch == '.') ||
|
|
|
|
(ch >= '0' && ch <= '9') ||
|
|
|
|
(ch == 0xb7) ||
|
|
|
|
(ch >= 0xc0 && ch <= 0xd6) ||
|
|
|
|
(ch >= 0xd8 && ch <= 0xf6) ||
|
|
|
|
(ch >= 0xf8 && ch <= 0x2ff) ||
|
|
|
|
(ch >= 0x300 && ch <= 0x36f) ||
|
|
|
|
(ch >= 0x370 && ch <= 0x37d) ||
|
|
|
|
(ch >= 0x37f && ch <= 0x1fff) ||
|
|
|
|
(ch >= 0x200c && ch <= 0x200d) ||
|
|
|
|
(ch >= 0x203f && ch <= 0x2040) ||
|
|
|
|
(ch >= 0x2070 && ch <= 0x218f) ||
|
|
|
|
(ch >= 0x2c00 && ch <= 0x2fef) ||
|
|
|
|
(ch >= 0x3001 && ch <= 0xd7ff) ||
|
|
|
|
(ch >= 0xd800 && ch <= 0xdbff) || /* high surrogate */
|
|
|
|
(ch >= 0xdc00 && ch <= 0xdfff) || /* low surrogate */
|
|
|
|
(ch >= 0xf900 && ch <= 0xfdcf) ||
|
|
|
|
(ch >= 0xfdf0 && ch <= 0xfffd);
|
|
|
|
}
|
|
|
|
|
2018-11-02 08:56:57 +01:00
|
|
|
BOOL is_namechar(WCHAR ch)
|
2013-01-18 07:04:27 +01:00
|
|
|
{
|
|
|
|
return (ch == ':') || is_ncnamechar(ch);
|
|
|
|
}
|
|
|
|
|
2013-06-15 19:53:33 +02:00
|
|
|
static XmlNodeType reader_get_nodetype(const xmlreader *reader)
|
|
|
|
{
|
|
|
|
/* When we're on attribute always return attribute type, container node type is kept.
|
|
|
|
Note that container is not necessarily an element, and attribute doesn't mean it's
|
|
|
|
an attribute in XML spec terms. */
|
|
|
|
return reader->attr ? XmlNodeType_Attribute : reader->nodetype;
|
|
|
|
}
|
|
|
|
|
2013-01-05 23:08:27 +01:00
|
|
|
/* [4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] |
|
|
|
|
[#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] |
|
|
|
|
[#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
|
|
[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
|
|
|
|
[5] Name ::= NameStartChar (NameChar)* */
|
|
|
|
static HRESULT reader_parse_name(xmlreader *reader, strval *name)
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *ptr;
|
|
|
|
UINT start;
|
2013-01-05 23:08:27 +01:00
|
|
|
|
2013-03-08 11:10:26 +01:00
|
|
|
if (reader->resume[XmlReadResume_Name])
|
|
|
|
{
|
|
|
|
start = reader->resume[XmlReadResume_Name];
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-03-08 11:10:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
|
|
|
start = reader_get_cur(reader);
|
2013-03-08 11:10:26 +01:00
|
|
|
if (!is_namestartchar(*ptr)) return WC_E_NAMECHARACTER;
|
|
|
|
}
|
2013-01-05 23:08:27 +01:00
|
|
|
|
|
|
|
while (is_namechar(*ptr))
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-01-05 23:08:27 +01:00
|
|
|
}
|
|
|
|
|
2013-03-08 11:10:26 +01:00
|
|
|
if (is_reader_pending(reader))
|
|
|
|
{
|
|
|
|
reader->resume[XmlReadResume_Name] = start;
|
|
|
|
return E_PENDING;
|
|
|
|
}
|
|
|
|
else
|
2013-10-09 13:37:08 +02:00
|
|
|
reader->resume[XmlReadResume_Name] = 0;
|
2013-03-08 11:10:26 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, name);
|
|
|
|
TRACE("name %s:%d\n", debug_strval(reader, name), name->len);
|
2013-01-05 23:08:27 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) */
|
|
|
|
static HRESULT reader_parse_pitarget(xmlreader *reader, strval *target)
|
|
|
|
{
|
2020-11-18 07:44:41 +01:00
|
|
|
static const strval xmlval = { (WCHAR *)L"xml", 3 };
|
2013-01-05 23:08:27 +01:00
|
|
|
strval name;
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *ptr;
|
2013-01-05 23:08:27 +01:00
|
|
|
HRESULT hr;
|
2013-03-07 23:22:42 +01:00
|
|
|
UINT i;
|
2013-01-05 23:08:27 +01:00
|
|
|
|
|
|
|
hr = reader_parse_name(reader, &name);
|
2013-03-08 11:10:26 +01:00
|
|
|
if (FAILED(hr)) return is_reader_pending(reader) ? E_PENDING : WC_E_PI;
|
2013-01-05 23:08:27 +01:00
|
|
|
|
|
|
|
/* now that we got name check for illegal content */
|
2013-10-09 13:37:08 +02:00
|
|
|
if (strval_eq(reader, &name, &xmlval))
|
2013-01-05 23:08:27 +01:00
|
|
|
return WC_E_LEADINGXML;
|
|
|
|
|
|
|
|
/* PITarget can't be a qualified name */
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_strptr(reader, &name);
|
2013-01-05 23:08:27 +01:00
|
|
|
for (i = 0; i < name.len; i++)
|
2013-10-09 13:37:08 +02:00
|
|
|
if (ptr[i] == ':')
|
2013-01-05 23:08:27 +01:00
|
|
|
return i ? NC_E_NAMECOLON : WC_E_PI;
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
TRACE("pitarget %s:%d\n", debug_strval(reader, &name), name.len);
|
2013-01-05 23:08:27 +01:00
|
|
|
*target = name;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
/* [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' */
|
|
|
|
static HRESULT reader_parse_pi(xmlreader *reader)
|
|
|
|
{
|
2013-01-05 23:08:27 +01:00
|
|
|
strval target;
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *ptr;
|
|
|
|
UINT start;
|
2013-01-05 23:08:27 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-03-08 11:10:26 +01:00
|
|
|
switch (reader->resumestate)
|
|
|
|
{
|
|
|
|
case XmlReadResumeState_Initial:
|
|
|
|
/* skip '<?' */
|
|
|
|
reader_skipn(reader, 2);
|
|
|
|
reader_shrink(reader);
|
|
|
|
reader->resumestate = XmlReadResumeState_PITarget;
|
|
|
|
case XmlReadResumeState_PITarget:
|
|
|
|
hr = reader_parse_pitarget(reader, &target);
|
|
|
|
if (FAILED(hr)) return hr;
|
2013-05-31 17:27:31 +02:00
|
|
|
reader_set_strvalue(reader, StringValue_LocalName, &target);
|
|
|
|
reader_set_strvalue(reader, StringValue_QualifiedName, &target);
|
|
|
|
reader_set_strvalue(reader, StringValue_Value, &strval_empty);
|
2013-03-08 11:10:26 +01:00
|
|
|
reader->resumestate = XmlReadResumeState_PIBody;
|
2013-10-09 13:37:08 +02:00
|
|
|
reader->resume[XmlReadResume_Body] = reader_get_cur(reader);
|
2013-03-08 11:10:26 +01:00
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
2013-01-05 23:08:27 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
start = reader->resume[XmlReadResume_Body];
|
|
|
|
ptr = reader_get_ptr(reader);
|
2013-01-05 23:08:27 +01:00
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
if (ptr[0] == '?')
|
|
|
|
{
|
|
|
|
if (ptr[1] == '>')
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
UINT cur = reader_get_cur(reader);
|
2013-03-14 12:08:29 +01:00
|
|
|
strval value;
|
2013-01-08 12:42:57 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
/* strip all leading whitespace chars */
|
|
|
|
while (start < cur)
|
|
|
|
{
|
|
|
|
ptr = reader_get_ptr2(reader, start);
|
|
|
|
if (!is_wchar_space(*ptr)) break;
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
|
|
|
|
reader_init_strvalue(start, cur-start, &value);
|
|
|
|
|
2013-01-05 23:08:27 +01:00
|
|
|
/* skip '?>' */
|
|
|
|
reader_skipn(reader, 2);
|
2013-10-09 13:37:08 +02:00
|
|
|
TRACE("%s\n", debug_strval(reader, &value));
|
2013-01-05 23:08:27 +01:00
|
|
|
reader->nodetype = XmlNodeType_ProcessingInstruction;
|
2013-03-08 11:10:26 +01:00
|
|
|
reader->resumestate = XmlReadResumeState_Initial;
|
2013-10-09 13:37:08 +02:00
|
|
|
reader->resume[XmlReadResume_Body] = 0;
|
2013-01-08 12:42:57 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_Value, &value);
|
2013-01-05 23:08:27 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
2013-10-09 13:37:08 +02:00
|
|
|
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
ptr = reader_get_ptr(reader);
|
2013-01-05 23:08:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2012-12-19 06:30:44 +01:00
|
|
|
}
|
|
|
|
|
2013-01-13 19:36:30 +01:00
|
|
|
/* This one is used to parse significant whitespace nodes, like in Misc production */
|
|
|
|
static HRESULT reader_parse_whitespace(xmlreader *reader)
|
|
|
|
{
|
2013-10-14 06:10:34 +02:00
|
|
|
switch (reader->resumestate)
|
|
|
|
{
|
|
|
|
case XmlReadResumeState_Initial:
|
|
|
|
reader_shrink(reader);
|
|
|
|
reader->resumestate = XmlReadResumeState_Whitespace;
|
|
|
|
reader->resume[XmlReadResume_Body] = reader_get_cur(reader);
|
|
|
|
reader->nodetype = XmlNodeType_Whitespace;
|
|
|
|
reader_set_strvalue(reader, StringValue_LocalName, &strval_empty);
|
|
|
|
reader_set_strvalue(reader, StringValue_QualifiedName, &strval_empty);
|
|
|
|
reader_set_strvalue(reader, StringValue_Value, &strval_empty);
|
2013-10-26 11:16:37 +02:00
|
|
|
/* fallthrough */
|
2013-10-14 06:10:34 +02:00
|
|
|
case XmlReadResumeState_Whitespace:
|
|
|
|
{
|
|
|
|
strval value;
|
|
|
|
UINT start;
|
2013-01-13 19:36:30 +01:00
|
|
|
|
2013-10-14 06:10:34 +02:00
|
|
|
reader_skipspaces(reader);
|
|
|
|
if (is_reader_pending(reader)) return S_OK;
|
2013-01-13 19:36:30 +01:00
|
|
|
|
2013-10-14 06:10:34 +02:00
|
|
|
start = reader->resume[XmlReadResume_Body];
|
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, &value);
|
|
|
|
reader_set_strvalue(reader, StringValue_Value, &value);
|
|
|
|
TRACE("%s\n", debug_strval(reader, &value));
|
|
|
|
reader->resumestate = XmlReadResumeState_Initial;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
2013-01-13 19:36:30 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
/* [27] Misc ::= Comment | PI | S */
|
|
|
|
static HRESULT reader_parse_misc(xmlreader *reader)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_FALSE;
|
|
|
|
|
2013-03-10 12:45:38 +01:00
|
|
|
if (reader->resumestate != XmlReadResumeState_Initial)
|
2013-01-27 08:17:27 +01:00
|
|
|
{
|
|
|
|
hr = reader_more(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
/* finish current node */
|
2013-03-10 12:45:38 +01:00
|
|
|
switch (reader->resumestate)
|
|
|
|
{
|
|
|
|
case XmlReadResumeState_PITarget:
|
|
|
|
case XmlReadResumeState_PIBody:
|
|
|
|
return reader_parse_pi(reader);
|
|
|
|
case XmlReadResumeState_Comment:
|
2013-01-27 08:17:27 +01:00
|
|
|
return reader_parse_comment(reader);
|
2013-10-14 06:10:34 +02:00
|
|
|
case XmlReadResumeState_Whitespace:
|
|
|
|
return reader_parse_whitespace(reader);
|
2013-03-10 12:45:38 +01:00
|
|
|
default:
|
|
|
|
ERR("unknown resume state %d\n", reader->resumestate);
|
|
|
|
}
|
2013-01-27 08:17:27 +01:00
|
|
|
}
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
while (1)
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
const WCHAR *cur = reader_get_ptr(reader);
|
2012-12-19 06:30:44 +01:00
|
|
|
|
|
|
|
if (is_wchar_space(*cur))
|
2013-01-13 19:36:30 +01:00
|
|
|
hr = reader_parse_whitespace(reader);
|
2020-11-18 07:44:41 +01:00
|
|
|
else if (!reader_cmp(reader, L"<!--"))
|
2012-12-19 06:30:44 +01:00
|
|
|
hr = reader_parse_comment(reader);
|
2020-11-18 07:44:41 +01:00
|
|
|
else if (!reader_cmp(reader, L"<?"))
|
2012-12-19 06:30:44 +01:00
|
|
|
hr = reader_parse_pi(reader);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
2013-01-12 22:09:32 +01:00
|
|
|
if (hr != S_FALSE) return hr;
|
2012-12-19 06:30:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-01-15 20:54:14 +01:00
|
|
|
/* [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") */
|
|
|
|
static HRESULT reader_parse_sys_literal(xmlreader *reader, strval *literal)
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *cur = reader_get_ptr(reader), quote;
|
|
|
|
UINT start;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
if (*cur != '"' && *cur != '\'') return WC_E_QUOTE;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
quote = *cur;
|
2013-01-15 20:54:14 +01:00
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
cur = reader_get_ptr(reader);
|
|
|
|
start = reader_get_cur(reader);
|
2013-01-15 20:54:14 +01:00
|
|
|
while (is_char(*cur) && *cur != quote)
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
cur = reader_get_ptr(reader);
|
2013-01-15 20:54:14 +01:00
|
|
|
}
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, literal);
|
2013-01-15 20:54:14 +01:00
|
|
|
if (*cur == quote) reader_skipn(reader, 1);
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
TRACE("%s\n", debug_strval(reader, literal));
|
2013-01-15 20:54:14 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
|
|
|
|
[13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%] */
|
|
|
|
static HRESULT reader_parse_pub_literal(xmlreader *reader, strval *literal)
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *cur = reader_get_ptr(reader), quote;
|
|
|
|
UINT start;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
if (*cur != '"' && *cur != '\'') return WC_E_QUOTE;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
quote = *cur;
|
2013-01-15 20:54:14 +01:00
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
start = reader_get_cur(reader);
|
|
|
|
cur = reader_get_ptr(reader);
|
2013-01-15 20:54:14 +01:00
|
|
|
while (is_pubchar(*cur) && *cur != quote)
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
cur = reader_get_ptr(reader);
|
2013-01-15 20:54:14 +01:00
|
|
|
}
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, literal);
|
2016-11-22 15:57:20 +01:00
|
|
|
if (*cur == quote) reader_skipn(reader, 1);
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
TRACE("%s\n", debug_strval(reader, literal));
|
2013-01-15 20:54:14 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral */
|
|
|
|
static HRESULT reader_parse_externalid(xmlreader *reader)
|
|
|
|
{
|
2020-11-18 07:44:41 +01:00
|
|
|
static WCHAR systemW[] = L"SYSTEM";
|
|
|
|
static WCHAR publicW[] = L"PUBLIC";
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position position = reader->position;
|
2016-11-22 15:57:20 +01:00
|
|
|
strval name, sys;
|
2013-01-15 20:54:14 +01:00
|
|
|
HRESULT hr;
|
|
|
|
int cnt;
|
|
|
|
|
2016-11-22 15:57:20 +01:00
|
|
|
if (!reader_cmp(reader, publicW)) {
|
|
|
|
strval pub;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
2016-11-22 15:57:20 +01:00
|
|
|
/* public id */
|
|
|
|
reader_skipn(reader, 6);
|
|
|
|
cnt = reader_skipspaces(reader);
|
|
|
|
if (!cnt) return WC_E_WHITESPACE;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
2016-11-22 15:57:20 +01:00
|
|
|
hr = reader_parse_pub_literal(reader, &pub);
|
|
|
|
if (FAILED(hr)) return hr;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
2019-06-27 21:49:21 +02:00
|
|
|
reader_init_cstrvalue(publicW, lstrlenW(publicW), &name);
|
2017-03-17 14:46:13 +01:00
|
|
|
hr = reader_add_attr(reader, NULL, &name, NULL, &pub, &position, 0);
|
2016-11-22 15:57:20 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
cnt = reader_skipspaces(reader);
|
|
|
|
if (!cnt) return S_OK;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
2016-11-22 15:57:20 +01:00
|
|
|
/* optional system id */
|
|
|
|
hr = reader_parse_sys_literal(reader, &sys);
|
|
|
|
if (FAILED(hr)) return S_OK;
|
|
|
|
|
2019-06-27 21:49:21 +02:00
|
|
|
reader_init_cstrvalue(systemW, lstrlenW(systemW), &name);
|
2017-03-17 14:46:13 +01:00
|
|
|
hr = reader_add_attr(reader, NULL, &name, NULL, &sys, &position, 0);
|
2016-11-22 15:57:20 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
} else if (!reader_cmp(reader, systemW)) {
|
2013-01-15 20:54:14 +01:00
|
|
|
/* system id */
|
|
|
|
reader_skipn(reader, 6);
|
|
|
|
cnt = reader_skipspaces(reader);
|
|
|
|
if (!cnt) return WC_E_WHITESPACE;
|
|
|
|
|
|
|
|
hr = reader_parse_sys_literal(reader, &sys);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2019-06-27 21:49:21 +02:00
|
|
|
reader_init_cstrvalue(systemW, lstrlenW(systemW), &name);
|
2017-03-17 14:46:13 +01:00
|
|
|
return reader_add_attr(reader, NULL, &name, NULL, &sys, &position, 0);
|
2013-01-15 20:54:14 +01:00
|
|
|
}
|
|
|
|
|
2016-11-22 15:57:20 +01:00
|
|
|
return S_FALSE;
|
2013-01-15 20:54:14 +01:00
|
|
|
}
|
|
|
|
|
2013-01-12 22:09:32 +01:00
|
|
|
/* [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>' */
|
|
|
|
static HRESULT reader_parse_dtd(xmlreader *reader)
|
|
|
|
{
|
2013-01-15 20:54:14 +01:00
|
|
|
strval name;
|
|
|
|
WCHAR *cur;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L"<!DOCTYPE")) return S_FALSE;
|
2013-01-15 20:54:14 +01:00
|
|
|
reader_shrink(reader);
|
|
|
|
|
|
|
|
/* DTD processing is not allowed by default */
|
|
|
|
if (reader->dtdmode == DtdProcessing_Prohibit) return WC_E_DTDPROHIBITED;
|
|
|
|
|
|
|
|
reader_skipn(reader, 9);
|
|
|
|
if (!reader_skipspaces(reader)) return WC_E_WHITESPACE;
|
|
|
|
|
|
|
|
/* name */
|
|
|
|
hr = reader_parse_name(reader, &name);
|
|
|
|
if (FAILED(hr)) return WC_E_DECLDOCTYPE;
|
|
|
|
|
|
|
|
reader_skipspaces(reader);
|
|
|
|
|
|
|
|
hr = reader_parse_externalid(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
reader_skipspaces(reader);
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
cur = reader_get_ptr(reader);
|
2013-01-15 20:54:14 +01:00
|
|
|
if (*cur != '>')
|
|
|
|
{
|
|
|
|
FIXME("internal subset parsing not implemented\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip '>' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
|
|
|
reader->nodetype = XmlNodeType_DocumentType;
|
|
|
|
reader_set_strvalue(reader, StringValue_LocalName, &name);
|
|
|
|
reader_set_strvalue(reader, StringValue_QualifiedName, &name);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-10 10:28:38 +01:00
|
|
|
/* [11 NS] LocalPart ::= NCName */
|
2017-03-10 09:06:41 +01:00
|
|
|
static HRESULT reader_parse_local(xmlreader *reader, strval *local, BOOL check_for_separator)
|
2013-01-18 07:04:27 +01:00
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *ptr;
|
|
|
|
UINT start;
|
2013-01-18 07:04:27 +01:00
|
|
|
|
2013-03-10 10:28:38 +01:00
|
|
|
if (reader->resume[XmlReadResume_Local])
|
|
|
|
{
|
|
|
|
start = reader->resume[XmlReadResume_Local];
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-03-10 10:28:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
|
|
|
start = reader_get_cur(reader);
|
2013-03-10 10:28:38 +01:00
|
|
|
}
|
2013-01-18 07:04:27 +01:00
|
|
|
|
|
|
|
while (is_ncnamechar(*ptr))
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-01-18 07:04:27 +01:00
|
|
|
}
|
|
|
|
|
2017-03-10 09:06:41 +01:00
|
|
|
if (check_for_separator && *ptr == ':')
|
|
|
|
return NC_E_QNAMECOLON;
|
|
|
|
|
2013-03-10 10:28:38 +01:00
|
|
|
if (is_reader_pending(reader))
|
2013-01-18 07:04:27 +01:00
|
|
|
{
|
2013-03-10 10:28:38 +01:00
|
|
|
reader->resume[XmlReadResume_Local] = start;
|
|
|
|
return E_PENDING;
|
|
|
|
}
|
|
|
|
else
|
2013-10-09 13:37:08 +02:00
|
|
|
reader->resume[XmlReadResume_Local] = 0;
|
2013-01-18 07:04:27 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, local);
|
2013-03-10 10:28:38 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [7 NS] QName ::= PrefixedName | UnprefixedName
|
|
|
|
[8 NS] PrefixedName ::= Prefix ':' LocalPart
|
|
|
|
[9 NS] UnprefixedName ::= LocalPart
|
|
|
|
[10 NS] Prefix ::= NCName */
|
|
|
|
static HRESULT reader_parse_qname(xmlreader *reader, strval *prefix, strval *local, strval *qname)
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *ptr;
|
|
|
|
UINT start;
|
2013-03-10 10:28:38 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (reader->resume[XmlReadResume_Name])
|
|
|
|
{
|
|
|
|
start = reader->resume[XmlReadResume_Name];
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-03-10 10:28:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
|
|
|
start = reader_get_cur(reader);
|
2013-03-10 10:28:38 +01:00
|
|
|
reader->resume[XmlReadResume_Name] = start;
|
|
|
|
if (!is_ncnamechar(*ptr)) return NC_E_QNAMECHARACTER;
|
|
|
|
}
|
2013-01-18 07:04:27 +01:00
|
|
|
|
2013-03-10 10:28:38 +01:00
|
|
|
if (reader->resume[XmlReadResume_Local])
|
|
|
|
{
|
2017-03-10 09:06:41 +01:00
|
|
|
hr = reader_parse_local(reader, local, FALSE);
|
2013-03-10 10:28:38 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2013-03-14 12:08:29 +01:00
|
|
|
reader_init_strvalue(reader->resume[XmlReadResume_Name],
|
|
|
|
local->start - reader->resume[XmlReadResume_Name] - 1,
|
|
|
|
prefix);
|
2013-03-10 10:28:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* skip prefix part */
|
2013-01-18 07:04:27 +01:00
|
|
|
while (is_ncnamechar(*ptr))
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-01-18 07:04:27 +01:00
|
|
|
}
|
2013-03-10 10:28:38 +01:00
|
|
|
|
|
|
|
if (is_reader_pending(reader)) return E_PENDING;
|
|
|
|
|
|
|
|
/* got a qualified name */
|
|
|
|
if (*ptr == ':')
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, prefix);
|
2013-03-10 10:28:38 +01:00
|
|
|
|
|
|
|
/* skip ':' */
|
|
|
|
reader_skipn(reader, 1);
|
2017-03-10 09:06:41 +01:00
|
|
|
hr = reader_parse_local(reader, local, TRUE);
|
2013-03-10 10:28:38 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(reader->resume[XmlReadResume_Name], reader_get_cur(reader)-reader->resume[XmlReadResume_Name], local);
|
|
|
|
reader_init_strvalue(0, 0, prefix);
|
2013-03-10 10:28:38 +01:00
|
|
|
}
|
2013-01-18 07:04:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prefix->len)
|
2013-10-09 13:37:08 +02:00
|
|
|
TRACE("qname %s:%s\n", debug_strval(reader, prefix), debug_strval(reader, local));
|
2013-01-18 07:04:27 +01:00
|
|
|
else
|
2013-10-09 13:37:08 +02:00
|
|
|
TRACE("ncname %s\n", debug_strval(reader, local));
|
2013-01-18 07:04:27 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(prefix->len ? prefix->start : local->start,
|
2013-03-14 12:08:29 +01:00
|
|
|
/* count ':' too */
|
|
|
|
(prefix->len ? prefix->len + 1 : 0) + local->len,
|
|
|
|
qname);
|
2013-01-18 07:04:27 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
reader->resume[XmlReadResume_Name] = 0;
|
|
|
|
reader->resume[XmlReadResume_Local] = 0;
|
2013-03-10 10:28:38 +01:00
|
|
|
|
2013-01-18 07:04:27 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
static WCHAR get_predefined_entity(const xmlreader *reader, const strval *name)
|
2013-08-20 12:07:32 +02:00
|
|
|
{
|
2020-11-18 07:44:41 +01:00
|
|
|
static const strval lt = { (WCHAR *)L"lt", 2 };
|
|
|
|
static const strval gt = { (WCHAR *)L"gt", 2 };
|
|
|
|
static const strval amp = { (WCHAR *)L"amp", 3 };
|
|
|
|
static const strval apos = { (WCHAR *)L"apos", 4 };
|
|
|
|
static const strval quot = { (WCHAR *)L"quot", 4 };
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *str = reader_get_strptr(reader, name);
|
2013-08-20 12:07:32 +02:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
switch (*str)
|
2013-08-20 12:07:32 +02:00
|
|
|
{
|
|
|
|
case 'l':
|
2013-10-09 13:37:08 +02:00
|
|
|
if (strval_eq(reader, name, <)) return '<';
|
2013-08-20 12:07:32 +02:00
|
|
|
break;
|
|
|
|
case 'g':
|
2013-10-09 13:37:08 +02:00
|
|
|
if (strval_eq(reader, name, >)) return '>';
|
2013-08-20 12:07:32 +02:00
|
|
|
break;
|
|
|
|
case 'a':
|
2013-10-09 13:37:08 +02:00
|
|
|
if (strval_eq(reader, name, &))
|
2013-08-20 12:07:32 +02:00
|
|
|
return '&';
|
2013-10-09 13:37:08 +02:00
|
|
|
else if (strval_eq(reader, name, &apos))
|
2013-08-20 12:07:32 +02:00
|
|
|
return '\'';
|
|
|
|
break;
|
|
|
|
case 'q':
|
2013-10-09 13:37:08 +02:00
|
|
|
if (strval_eq(reader, name, ")) return '\"';
|
2013-08-20 12:07:32 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-30 12:59:28 +02:00
|
|
|
/* [66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'
|
|
|
|
[67] Reference ::= EntityRef | CharRef
|
|
|
|
[68] EntityRef ::= '&' Name ';' */
|
|
|
|
static HRESULT reader_parse_reference(xmlreader *reader)
|
|
|
|
{
|
2013-08-20 12:07:32 +02:00
|
|
|
encoded_buffer *buffer = &reader->input->buffer->utf16;
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *start = reader_get_ptr(reader), *ptr;
|
|
|
|
UINT cur = reader_get_cur(reader);
|
2013-08-19 08:46:49 +02:00
|
|
|
WCHAR ch = 0;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* skip '&' */
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-08-19 08:46:49 +02:00
|
|
|
|
|
|
|
if (*ptr == '#')
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-08-19 08:46:49 +02:00
|
|
|
|
|
|
|
/* hex char or decimal */
|
|
|
|
if (*ptr == 'x')
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-08-19 08:46:49 +02:00
|
|
|
|
|
|
|
while (*ptr != ';')
|
|
|
|
{
|
|
|
|
if ((*ptr >= '0' && *ptr <= '9'))
|
|
|
|
ch = ch*16 + *ptr - '0';
|
|
|
|
else if ((*ptr >= 'a' && *ptr <= 'f'))
|
|
|
|
ch = ch*16 + *ptr - 'a' + 10;
|
|
|
|
else if ((*ptr >= 'A' && *ptr <= 'F'))
|
|
|
|
ch = ch*16 + *ptr - 'A' + 10;
|
|
|
|
else
|
|
|
|
return ch ? WC_E_SEMICOLON : WC_E_HEXDIGIT;
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-08-19 08:46:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (*ptr != ';')
|
|
|
|
{
|
|
|
|
if ((*ptr >= '0' && *ptr <= '9'))
|
|
|
|
{
|
|
|
|
ch = ch*10 + *ptr - '0';
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-08-19 08:46:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return ch ? WC_E_SEMICOLON : WC_E_DIGIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_char(ch)) return WC_E_XMLCHARACTER;
|
|
|
|
|
|
|
|
/* normalize */
|
|
|
|
if (is_wchar_space(ch)) ch = ' ';
|
|
|
|
|
2017-03-02 22:11:28 +01:00
|
|
|
ptr = reader_get_ptr(reader);
|
|
|
|
start = reader_get_ptr2(reader, cur);
|
|
|
|
len = buffer->written - ((char *)ptr - buffer->data);
|
|
|
|
memmove(start + 1, ptr + 1, len);
|
|
|
|
|
|
|
|
buffer->written -= (reader_get_cur(reader) - cur) * sizeof(WCHAR);
|
2021-08-06 14:01:16 +02:00
|
|
|
*(WCHAR*)(buffer->data + buffer->written) = 0;
|
2013-10-09 13:37:08 +02:00
|
|
|
buffer->cur = cur + 1;
|
2013-08-19 08:46:49 +02:00
|
|
|
|
|
|
|
*start = ch;
|
|
|
|
}
|
|
|
|
else
|
2013-08-20 12:07:32 +02:00
|
|
|
{
|
|
|
|
strval name;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = reader_parse_name(reader, &name);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-08-20 12:07:32 +02:00
|
|
|
if (*ptr != ';') return WC_E_SEMICOLON;
|
|
|
|
|
|
|
|
/* predefined entities resolve to a single character */
|
2013-10-09 13:37:08 +02:00
|
|
|
ch = get_predefined_entity(reader, &name);
|
2013-08-20 12:07:32 +02:00
|
|
|
if (ch)
|
|
|
|
{
|
|
|
|
len = buffer->written - ((char*)ptr - buffer->data) - sizeof(WCHAR);
|
|
|
|
memmove(start+1, ptr+1, len);
|
2013-10-09 13:37:08 +02:00
|
|
|
buffer->cur = cur + 1;
|
2017-03-20 14:01:11 +01:00
|
|
|
buffer->written -= (ptr - start) * sizeof(WCHAR);
|
2021-08-06 14:01:16 +02:00
|
|
|
*(WCHAR*)(buffer->data + buffer->written) = 0;
|
2013-08-19 08:46:49 +02:00
|
|
|
|
2013-08-20 12:07:32 +02:00
|
|
|
*start = ch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
FIXME("undeclared entity %s\n", debug_strval(reader, &name));
|
2013-08-20 12:07:32 +02:00
|
|
|
return WC_E_UNDECLAREDENTITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2013-07-30 12:59:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* [10 NS] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'" */
|
|
|
|
static HRESULT reader_parse_attvalue(xmlreader *reader, strval *value)
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *ptr, quote;
|
|
|
|
UINT start;
|
2013-07-30 12:59:28 +02:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-07-30 12:59:28 +02:00
|
|
|
|
|
|
|
/* skip opening quote */
|
|
|
|
quote = *ptr;
|
|
|
|
if (quote != '\"' && quote != '\'') return WC_E_QUOTE;
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
|
|
|
start = reader_get_cur(reader);
|
2013-07-30 12:59:28 +02:00
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
if (*ptr == '<') return WC_E_LESSTHAN;
|
|
|
|
|
|
|
|
if (*ptr == quote)
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, value);
|
2013-07-30 12:59:28 +02:00
|
|
|
/* skip closing quote */
|
|
|
|
reader_skipn(reader, 1);
|
2013-10-09 13:37:08 +02:00
|
|
|
return S_OK;
|
2013-07-30 12:59:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*ptr == '&')
|
|
|
|
{
|
|
|
|
HRESULT hr = reader_parse_reference(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
}
|
|
|
|
else
|
2013-08-19 08:46:49 +02:00
|
|
|
{
|
2017-03-21 16:19:32 +01:00
|
|
|
/* replace all whitespace chars with ' ' */
|
|
|
|
if (is_wchar_space(*ptr)) *ptr = ' ';
|
2013-07-30 12:59:28 +02:00
|
|
|
reader_skipn(reader, 1);
|
2013-08-19 08:46:49 +02:00
|
|
|
}
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-07-30 12:59:28 +02:00
|
|
|
}
|
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
return WC_E_QUOTE;
|
2013-07-30 12:59:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* [1 NS] NSAttName ::= PrefixedAttName | DefaultAttName
|
|
|
|
[2 NS] PrefixedAttName ::= 'xmlns:' NCName
|
|
|
|
[3 NS] DefaultAttName ::= 'xmlns'
|
|
|
|
[15 NS] Attribute ::= NSAttName Eq AttValue | QName Eq AttValue */
|
|
|
|
static HRESULT reader_parse_attribute(xmlreader *reader)
|
|
|
|
{
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position position = reader->position;
|
2016-12-09 14:38:24 +01:00
|
|
|
strval prefix, local, qname, value;
|
2017-03-17 14:46:13 +01:00
|
|
|
enum attribute_flags flags = 0;
|
2013-07-30 12:59:28 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = reader_parse_qname(reader, &prefix, &local, &qname);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2016-12-09 14:38:24 +01:00
|
|
|
if (strval_eq(reader, &prefix, &strval_xmlns))
|
2017-03-17 14:46:13 +01:00
|
|
|
flags |= ATTRIBUTE_NS_DEFINITION;
|
2013-07-30 12:59:28 +02:00
|
|
|
|
2016-12-09 14:38:24 +01:00
|
|
|
if (strval_eq(reader, &qname, &strval_xmlns))
|
2017-03-17 14:46:13 +01:00
|
|
|
flags |= ATTRIBUTE_DEFAULT_NS_DEFINITION;
|
2013-07-30 12:59:28 +02:00
|
|
|
|
|
|
|
hr = reader_parse_eq(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = reader_parse_attvalue(reader, &value);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2017-03-17 14:46:13 +01:00
|
|
|
if (flags & (ATTRIBUTE_NS_DEFINITION | ATTRIBUTE_DEFAULT_NS_DEFINITION))
|
|
|
|
reader_push_ns(reader, &local, &value, !!(flags & ATTRIBUTE_DEFAULT_NS_DEFINITION));
|
2016-12-09 14:38:24 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
TRACE("%s=%s\n", debug_strval(reader, &local), debug_strval(reader, &value));
|
2017-03-17 14:46:13 +01:00
|
|
|
return reader_add_attr(reader, &prefix, &local, &qname, &value, &position, flags);
|
2013-07-30 12:59:28 +02:00
|
|
|
}
|
|
|
|
|
2013-01-18 07:04:27 +01:00
|
|
|
/* [12 NS] STag ::= '<' QName (S Attribute)* S? '>'
|
|
|
|
[14 NS] EmptyElemTag ::= '<' QName (S Attribute)* S? '/>' */
|
2017-03-09 05:14:08 +01:00
|
|
|
static HRESULT reader_parse_stag(xmlreader *reader, strval *prefix, strval *local, strval *qname)
|
2013-01-18 07:04:27 +01:00
|
|
|
{
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position position = reader->position;
|
2013-01-18 07:04:27 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = reader_parse_qname(reader, prefix, local, qname);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
for (;;)
|
2013-01-22 10:11:51 +01:00
|
|
|
{
|
2013-07-30 12:59:28 +02:00
|
|
|
reader_skipspaces(reader);
|
|
|
|
|
|
|
|
/* empty element */
|
2020-11-18 07:44:41 +01:00
|
|
|
if ((reader->is_empty_element = !reader_cmp(reader, L"/>")))
|
2013-07-30 12:59:28 +02:00
|
|
|
{
|
2017-03-17 14:46:11 +01:00
|
|
|
struct element *element = &reader->empty_element;
|
|
|
|
|
2013-07-30 12:59:28 +02:00
|
|
|
/* skip '/>' */
|
|
|
|
reader_skipn(reader, 2);
|
2017-03-17 14:46:11 +01:00
|
|
|
|
2017-03-17 14:46:12 +01:00
|
|
|
reader_free_strvalued(reader, &element->qname);
|
2017-03-17 14:46:11 +01:00
|
|
|
reader_free_strvalued(reader, &element->localname);
|
|
|
|
|
|
|
|
element->prefix = *prefix;
|
2017-03-17 14:46:12 +01:00
|
|
|
reader_strvaldup(reader, qname, &element->qname);
|
2017-03-17 14:46:11 +01:00
|
|
|
reader_strvaldup(reader, local, &element->localname);
|
|
|
|
element->position = position;
|
|
|
|
reader_mark_ns_nodes(reader, element);
|
2013-07-30 12:59:28 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* got a start tag */
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_cmp(reader, L">"))
|
2013-07-30 12:59:28 +02:00
|
|
|
{
|
|
|
|
/* skip '>' */
|
|
|
|
reader_skipn(reader, 1);
|
2017-03-09 05:14:09 +01:00
|
|
|
return reader_push_element(reader, prefix, local, qname, &position);
|
2013-07-30 12:59:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hr = reader_parse_attribute(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
2013-01-20 22:03:23 +01:00
|
|
|
}
|
2013-01-20 20:46:25 +01:00
|
|
|
|
2013-07-30 12:59:28 +02:00
|
|
|
return S_OK;
|
2013-01-18 07:04:27 +01:00
|
|
|
}
|
|
|
|
|
2013-01-15 20:54:14 +01:00
|
|
|
/* [39] element ::= EmptyElemTag | STag content ETag */
|
|
|
|
static HRESULT reader_parse_element(xmlreader *reader)
|
|
|
|
{
|
2013-01-18 07:04:27 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-03-10 10:28:38 +01:00
|
|
|
switch (reader->resumestate)
|
|
|
|
{
|
|
|
|
case XmlReadResumeState_Initial:
|
|
|
|
/* check if we are really on element */
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L"<")) return S_FALSE;
|
2013-01-18 07:04:27 +01:00
|
|
|
|
2013-03-10 10:28:38 +01:00
|
|
|
/* skip '<' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
|
|
|
reader_shrink(reader);
|
|
|
|
reader->resumestate = XmlReadResumeState_STag;
|
|
|
|
case XmlReadResumeState_STag:
|
|
|
|
{
|
|
|
|
strval qname, prefix, local;
|
2013-01-18 07:04:27 +01:00
|
|
|
|
2013-03-10 10:28:38 +01:00
|
|
|
/* this handles empty elements too */
|
2017-03-09 05:14:08 +01:00
|
|
|
hr = reader_parse_stag(reader, &prefix, &local, &qname);
|
2013-03-10 10:28:38 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
2013-01-18 07:04:27 +01:00
|
|
|
|
2016-12-09 14:38:32 +01:00
|
|
|
/* FIXME: need to check for defined namespace to reject invalid prefix */
|
2013-03-10 10:28:38 +01:00
|
|
|
|
|
|
|
/* if we got empty element and stack is empty go straight to Misc */
|
2017-03-09 05:14:08 +01:00
|
|
|
if (reader->is_empty_element && list_empty(&reader->elements))
|
2013-03-10 10:28:38 +01:00
|
|
|
reader->instate = XmlReadInState_MiscEnd;
|
|
|
|
else
|
|
|
|
reader->instate = XmlReadInState_Content;
|
2013-01-20 22:03:23 +01:00
|
|
|
|
2013-03-10 10:28:38 +01:00
|
|
|
reader->nodetype = XmlNodeType_Element;
|
|
|
|
reader->resumestate = XmlReadResumeState_Initial;
|
2013-06-14 22:54:44 +02:00
|
|
|
reader_set_strvalue(reader, StringValue_Prefix, &prefix);
|
2013-03-10 10:28:38 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_QualifiedName, &qname);
|
2017-03-07 04:50:56 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_Value, &strval_empty);
|
2013-03-10 10:28:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
2013-01-18 07:04:27 +01:00
|
|
|
|
|
|
|
return hr;
|
2013-01-12 22:09:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-20 22:03:23 +01:00
|
|
|
/* [13 NS] ETag ::= '</' QName S? '>' */
|
|
|
|
static HRESULT reader_parse_endtag(xmlreader *reader)
|
|
|
|
{
|
2017-03-09 05:14:09 +01:00
|
|
|
struct reader_position position;
|
2013-01-22 10:11:51 +01:00
|
|
|
strval prefix, local, qname;
|
2017-03-08 05:07:10 +01:00
|
|
|
struct element *element;
|
2013-01-22 10:11:51 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* skip '</' */
|
|
|
|
reader_skipn(reader, 2);
|
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
position = reader->position;
|
2013-01-22 10:11:51 +01:00
|
|
|
hr = reader_parse_qname(reader, &prefix, &local, &qname);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
reader_skipspaces(reader);
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (reader_cmp(reader, L">")) return WC_E_GREATERTHAN;
|
2013-01-22 10:11:51 +01:00
|
|
|
|
|
|
|
/* skip '>' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
|
|
|
/* Element stack should never be empty at this point, cause we shouldn't get to
|
|
|
|
content parsing if it's empty. */
|
2017-03-08 05:07:10 +01:00
|
|
|
element = LIST_ENTRY(list_head(&reader->elements), struct element, entry);
|
|
|
|
if (!strval_eq(reader, &element->qname, &qname)) return WC_E_ELEMENTMATCH;
|
2013-01-22 10:11:51 +01:00
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
/* update position stored for start tag, we won't be using it */
|
|
|
|
element->position = position;
|
|
|
|
|
2013-01-22 10:11:51 +01:00
|
|
|
reader->nodetype = XmlNodeType_EndElement;
|
2017-03-08 05:07:10 +01:00
|
|
|
reader->is_empty_element = FALSE;
|
2016-12-09 14:38:23 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_Prefix, &prefix);
|
2013-01-22 10:11:51 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2013-01-20 22:03:23 +01:00
|
|
|
}
|
|
|
|
|
2013-01-23 09:12:55 +01:00
|
|
|
/* [18] CDSect ::= CDStart CData CDEnd
|
|
|
|
[19] CDStart ::= '<![CDATA['
|
|
|
|
[20] CData ::= (Char* - (Char* ']]>' Char*))
|
|
|
|
[21] CDEnd ::= ']]>' */
|
|
|
|
static HRESULT reader_parse_cdata(xmlreader *reader)
|
|
|
|
{
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *ptr;
|
|
|
|
UINT start;
|
2013-03-10 15:29:43 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
if (reader->resumestate == XmlReadResumeState_CDATA)
|
2013-03-10 15:29:43 +01:00
|
|
|
{
|
|
|
|
start = reader->resume[XmlReadResume_Body];
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-03-10 15:29:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* skip markup '<![CDATA[' */
|
|
|
|
reader_skipn(reader, 9);
|
|
|
|
reader_shrink(reader);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
|
|
|
start = reader_get_cur(reader);
|
2013-03-10 15:29:43 +01:00
|
|
|
reader->nodetype = XmlNodeType_CDATA;
|
|
|
|
reader->resume[XmlReadResume_Body] = start;
|
|
|
|
reader->resumestate = XmlReadResumeState_CDATA;
|
|
|
|
reader_set_strvalue(reader, StringValue_Value, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
if (*ptr == ']' && *(ptr+1) == ']' && *(ptr+2) == '>')
|
|
|
|
{
|
2013-03-14 12:08:29 +01:00
|
|
|
strval value;
|
2013-03-10 15:29:43 +01:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, &value);
|
|
|
|
|
2013-03-10 15:29:43 +01:00
|
|
|
/* skip ']]>' */
|
|
|
|
reader_skipn(reader, 3);
|
2013-10-09 13:37:08 +02:00
|
|
|
TRACE("%s\n", debug_strval(reader, &value));
|
|
|
|
|
2013-03-10 15:29:43 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_Value, &value);
|
2013-10-09 13:37:08 +02:00
|
|
|
reader->resume[XmlReadResume_Body] = 0;
|
2013-03-10 15:29:43 +01:00
|
|
|
reader->resumestate = XmlReadResumeState_Initial;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
2019-11-05 23:01:47 +01:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-03-10 15:29:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-23 09:12:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) */
|
|
|
|
static HRESULT reader_parse_chardata(xmlreader *reader)
|
|
|
|
{
|
2017-03-10 09:06:44 +01:00
|
|
|
struct reader_position position;
|
2013-10-09 13:37:08 +02:00
|
|
|
WCHAR *ptr;
|
|
|
|
UINT start;
|
2013-06-15 18:45:21 +02:00
|
|
|
|
2013-10-09 13:37:08 +02:00
|
|
|
if (reader->resumestate == XmlReadResumeState_CharData)
|
2013-06-15 18:45:21 +02:00
|
|
|
{
|
|
|
|
start = reader->resume[XmlReadResume_Body];
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
2013-06-15 18:45:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader_shrink(reader);
|
2013-10-09 13:37:08 +02:00
|
|
|
ptr = reader_get_ptr(reader);
|
|
|
|
start = reader_get_cur(reader);
|
2013-06-15 18:45:21 +02:00
|
|
|
/* There's no text */
|
|
|
|
if (!*ptr || *ptr == '<') return S_OK;
|
2013-09-29 16:55:20 +02:00
|
|
|
reader->nodetype = is_wchar_space(*ptr) ? XmlNodeType_Whitespace : XmlNodeType_Text;
|
2013-06-15 18:45:21 +02:00
|
|
|
reader->resume[XmlReadResume_Body] = start;
|
|
|
|
reader->resumestate = XmlReadResumeState_CharData;
|
|
|
|
reader_set_strvalue(reader, StringValue_Value, NULL);
|
|
|
|
}
|
|
|
|
|
2017-03-10 09:06:44 +01:00
|
|
|
position = reader->position;
|
2013-06-15 18:45:21 +02:00
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
/* CDATA closing sequence ']]>' is not allowed */
|
|
|
|
if (ptr[0] == ']' && ptr[1] == ']' && ptr[2] == '>')
|
|
|
|
return WC_E_CDSECTEND;
|
|
|
|
|
|
|
|
/* Found next markup part */
|
|
|
|
if (ptr[0] == '<')
|
|
|
|
{
|
|
|
|
strval value;
|
|
|
|
|
2017-03-10 09:06:44 +01:00
|
|
|
reader->empty_element.position = position;
|
2013-10-09 13:37:08 +02:00
|
|
|
reader_init_strvalue(start, reader_get_cur(reader)-start, &value);
|
2013-06-15 18:45:21 +02:00
|
|
|
reader_set_strvalue(reader, StringValue_Value, &value);
|
2013-10-09 13:37:08 +02:00
|
|
|
reader->resume[XmlReadResume_Body] = 0;
|
2013-09-29 16:52:47 +02:00
|
|
|
reader->resumestate = XmlReadResumeState_Initial;
|
2013-06-15 18:45:21 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-29 16:55:20 +02:00
|
|
|
/* this covers a case when text has leading whitespace chars */
|
|
|
|
if (!is_wchar_space(*ptr)) reader->nodetype = XmlNodeType_Text;
|
2017-02-05 23:19:30 +01:00
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_cmp(reader, L"&"))
|
2017-02-05 23:19:30 +01:00
|
|
|
reader_parse_reference(reader);
|
|
|
|
else
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
|
|
|
ptr = reader_get_ptr(reader);
|
2013-06-15 18:45:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-23 09:12:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-20 22:03:23 +01:00
|
|
|
/* [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* */
|
|
|
|
static HRESULT reader_parse_content(xmlreader *reader)
|
|
|
|
{
|
2013-03-10 15:29:43 +01:00
|
|
|
if (reader->resumestate != XmlReadResumeState_Initial)
|
|
|
|
{
|
|
|
|
switch (reader->resumestate)
|
|
|
|
{
|
|
|
|
case XmlReadResumeState_CDATA:
|
|
|
|
return reader_parse_cdata(reader);
|
2013-03-10 15:32:00 +01:00
|
|
|
case XmlReadResumeState_Comment:
|
|
|
|
return reader_parse_comment(reader);
|
|
|
|
case XmlReadResumeState_PIBody:
|
|
|
|
case XmlReadResumeState_PITarget:
|
|
|
|
return reader_parse_pi(reader);
|
2013-06-15 18:45:21 +02:00
|
|
|
case XmlReadResumeState_CharData:
|
|
|
|
return reader_parse_chardata(reader);
|
2013-03-10 15:29:43 +01:00
|
|
|
default:
|
|
|
|
ERR("unknown resume state %d\n", reader->resumestate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-20 22:03:23 +01:00
|
|
|
reader_shrink(reader);
|
|
|
|
|
2013-01-23 09:12:55 +01:00
|
|
|
/* handle end tag here, it indicates end of content as well */
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_cmp(reader, L"</"))
|
2013-01-20 22:03:23 +01:00
|
|
|
return reader_parse_endtag(reader);
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_cmp(reader, L"<!--"))
|
2013-01-23 09:12:55 +01:00
|
|
|
return reader_parse_comment(reader);
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_cmp(reader, L"<?"))
|
2013-01-23 09:12:55 +01:00
|
|
|
return reader_parse_pi(reader);
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_cmp(reader, L"<![CDATA["))
|
2013-01-23 09:12:55 +01:00
|
|
|
return reader_parse_cdata(reader);
|
|
|
|
|
2020-11-18 07:44:41 +01:00
|
|
|
if (!reader_cmp(reader, L"<"))
|
2013-01-23 09:12:55 +01:00
|
|
|
return reader_parse_element(reader);
|
|
|
|
|
|
|
|
/* what's left must be CharData */
|
|
|
|
return reader_parse_chardata(reader);
|
2013-01-20 22:03:23 +01:00
|
|
|
}
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
static HRESULT reader_parse_nextnode(xmlreader *reader)
|
|
|
|
{
|
2016-12-09 14:38:25 +01:00
|
|
|
XmlNodeType nodetype = reader_get_nodetype(reader);
|
2012-12-19 06:30:44 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-06-18 13:53:11 +02:00
|
|
|
if (!is_reader_pending(reader))
|
2017-03-31 15:58:06 +02:00
|
|
|
{
|
|
|
|
reader->chunk_read_off = 0;
|
2013-06-18 13:53:11 +02:00
|
|
|
reader_clear_attrs(reader);
|
2017-03-31 15:58:06 +02:00
|
|
|
}
|
2013-06-18 13:53:11 +02:00
|
|
|
|
2017-01-07 14:43:56 +01:00
|
|
|
/* When moving from EndElement or empty element, pop its own namespace definitions */
|
2017-03-06 10:35:59 +01:00
|
|
|
switch (nodetype)
|
|
|
|
{
|
2017-03-07 04:50:59 +01:00
|
|
|
case XmlNodeType_Attribute:
|
|
|
|
reader_dec_depth(reader);
|
|
|
|
/* fallthrough */
|
2017-03-06 10:35:59 +01:00
|
|
|
case XmlNodeType_Element:
|
|
|
|
if (reader->is_empty_element)
|
|
|
|
reader_pop_ns_nodes(reader, &reader->empty_element);
|
2017-03-07 04:50:59 +01:00
|
|
|
else if (FAILED(hr = reader_inc_depth(reader)))
|
|
|
|
return hr;
|
2017-03-06 10:35:59 +01:00
|
|
|
break;
|
|
|
|
case XmlNodeType_EndElement:
|
2016-12-09 14:38:25 +01:00
|
|
|
reader_pop_element(reader);
|
2017-03-06 10:35:59 +01:00
|
|
|
reader_dec_depth(reader);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
2016-12-09 14:38:25 +01:00
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
for (;;)
|
2012-12-19 06:30:44 +01:00
|
|
|
{
|
|
|
|
switch (reader->instate)
|
|
|
|
{
|
|
|
|
/* if it's a first call for a new input we need to detect stream encoding */
|
|
|
|
case XmlReadInState_Initial:
|
|
|
|
{
|
|
|
|
xml_encoding enc;
|
|
|
|
|
|
|
|
hr = readerinput_growraw(reader->input);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
reader->position.line_number = 1;
|
|
|
|
reader->position.line_position = 1;
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
/* try to detect encoding by BOM or data and set input code page */
|
|
|
|
hr = readerinput_detectencoding(reader->input, &enc);
|
2017-03-06 10:35:55 +01:00
|
|
|
TRACE("detected encoding %s, 0x%08x\n", enc == XmlEncoding_Unknown ? "(unknown)" :
|
|
|
|
debugstr_w(xml_encoding_map[enc].name), hr);
|
2012-12-19 06:30:44 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
/* always switch first time cause we have to put something in */
|
|
|
|
readerinput_switchencoding(reader->input, enc);
|
|
|
|
|
|
|
|
/* parse xml declaration */
|
|
|
|
hr = reader_parse_xmldecl(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2013-01-13 19:36:30 +01:00
|
|
|
readerinput_shrinkraw(reader->input, -1);
|
2012-12-19 06:30:44 +01:00
|
|
|
reader->instate = XmlReadInState_Misc_DTD;
|
|
|
|
if (hr == S_OK) return hr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XmlReadInState_Misc_DTD:
|
|
|
|
hr = reader_parse_misc(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
|
|
|
if (hr == S_FALSE)
|
2012-12-19 06:30:44 +01:00
|
|
|
reader->instate = XmlReadInState_DTD;
|
2013-01-15 20:54:14 +01:00
|
|
|
else
|
|
|
|
return hr;
|
2012-12-19 06:30:44 +01:00
|
|
|
break;
|
|
|
|
case XmlReadInState_DTD:
|
2013-01-12 22:09:32 +01:00
|
|
|
hr = reader_parse_dtd(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2013-01-12 22:09:32 +01:00
|
|
|
reader->instate = XmlReadInState_DTD_Misc;
|
2013-01-15 20:54:14 +01:00
|
|
|
return hr;
|
2013-01-12 22:09:32 +01:00
|
|
|
}
|
2013-01-15 20:54:14 +01:00
|
|
|
else
|
|
|
|
reader->instate = XmlReadInState_Element;
|
2013-01-12 22:09:32 +01:00
|
|
|
break;
|
|
|
|
case XmlReadInState_DTD_Misc:
|
|
|
|
hr = reader_parse_misc(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
2013-01-15 20:54:14 +01:00
|
|
|
|
|
|
|
if (hr == S_FALSE)
|
2013-01-12 22:09:32 +01:00
|
|
|
reader->instate = XmlReadInState_Element;
|
2013-01-15 20:54:14 +01:00
|
|
|
else
|
|
|
|
return hr;
|
|
|
|
break;
|
|
|
|
case XmlReadInState_Element:
|
2013-01-20 22:03:23 +01:00
|
|
|
return reader_parse_element(reader);
|
|
|
|
case XmlReadInState_Content:
|
|
|
|
return reader_parse_content(reader);
|
2013-06-15 18:45:21 +02:00
|
|
|
case XmlReadInState_MiscEnd:
|
|
|
|
hr = reader_parse_misc(reader);
|
2017-03-20 14:01:00 +01:00
|
|
|
if (hr != S_FALSE) return hr;
|
2013-06-15 18:45:21 +02:00
|
|
|
|
2017-03-20 14:01:00 +01:00
|
|
|
if (*reader_get_ptr(reader))
|
2017-03-06 10:35:57 +01:00
|
|
|
{
|
2017-03-20 14:01:00 +01:00
|
|
|
WARN("found garbage in the end of XML\n");
|
|
|
|
return WC_E_SYNTAX;
|
2017-03-06 10:35:57 +01:00
|
|
|
}
|
2017-03-20 14:01:00 +01:00
|
|
|
|
|
|
|
reader->instate = XmlReadInState_Eof;
|
|
|
|
reader->state = XmlReadState_EndOfFile;
|
|
|
|
reader->nodetype = XmlNodeType_None;
|
2013-06-15 18:45:21 +02:00
|
|
|
return hr;
|
|
|
|
case XmlReadInState_Eof:
|
|
|
|
return S_FALSE;
|
2012-12-19 06:30:44 +01:00
|
|
|
default:
|
|
|
|
FIXME("internal state %d not handled\n", reader->instate);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2010-01-18 22:18:22 +01:00
|
|
|
static HRESULT WINAPI xmlreader_QueryInterface(IXmlReader *iface, REFIID riid, void** ppvObject)
|
|
|
|
{
|
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
|
2013-01-27 08:54:58 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
|
2010-01-18 22:18:22 +01:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_IXmlReader))
|
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
2013-01-27 08:54:58 +01:00
|
|
|
*ppvObject = NULL;
|
2010-01-18 22:18:22 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IXmlReader_AddRef(iface);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlreader_AddRef(IXmlReader *iface)
|
|
|
|
{
|
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
2012-11-17 17:22:47 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:24 +01:00
|
|
|
static void reader_clear_ns(xmlreader *reader)
|
|
|
|
{
|
|
|
|
struct ns *ns, *ns2;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(ns, ns2, &reader->ns, struct ns, entry) {
|
2017-03-29 19:47:05 +02:00
|
|
|
list_remove(&ns->entry);
|
2016-12-09 14:38:24 +01:00
|
|
|
reader_free_strvalued(reader, &ns->prefix);
|
|
|
|
reader_free_strvalued(reader, &ns->uri);
|
|
|
|
reader_free(reader, ns);
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(ns, ns2, &reader->nsdef, struct ns, entry) {
|
2017-03-29 19:47:05 +02:00
|
|
|
list_remove(&ns->entry);
|
2016-12-09 14:38:24 +01:00
|
|
|
reader_free_strvalued(reader, &ns->uri);
|
|
|
|
reader_free(reader, ns);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 19:47:05 +02:00
|
|
|
static void reader_reset_parser(xmlreader *reader)
|
|
|
|
{
|
|
|
|
reader->position.line_number = 0;
|
|
|
|
reader->position.line_position = 0;
|
|
|
|
|
|
|
|
reader_clear_elements(reader);
|
|
|
|
reader_clear_attrs(reader);
|
|
|
|
reader_clear_ns(reader);
|
|
|
|
reader_free_strvalues(reader);
|
|
|
|
|
|
|
|
reader->depth = 0;
|
|
|
|
reader->nodetype = XmlNodeType_None;
|
|
|
|
reader->resumestate = XmlReadResumeState_Initial;
|
|
|
|
memset(reader->resume, 0, sizeof(reader->resume));
|
|
|
|
reader->is_empty_element = FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-18 22:18:22 +01:00
|
|
|
static ULONG WINAPI xmlreader_Release(IXmlReader *iface)
|
|
|
|
{
|
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
2012-11-17 17:22:47 +01:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
2010-01-18 22:18:22 +01:00
|
|
|
|
2012-11-17 17:22:47 +01:00
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
2010-01-18 22:18:22 +01:00
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2012-11-17 17:22:47 +01:00
|
|
|
IMalloc *imalloc = This->imalloc;
|
2017-03-29 19:47:05 +02:00
|
|
|
reader_reset_parser(This);
|
2012-11-17 20:22:09 +01:00
|
|
|
if (This->input) IUnknown_Release(&This->input->IXmlReaderInput_iface);
|
2016-03-14 07:37:46 +01:00
|
|
|
if (This->resolver) IXmlResolver_Release(This->resolver);
|
2016-10-30 09:05:28 +01:00
|
|
|
if (This->mlang) IUnknown_Release(This->mlang);
|
2012-11-17 17:22:47 +01:00
|
|
|
reader_free(This, This);
|
|
|
|
if (imalloc) IMalloc_Release(imalloc);
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_SetInput(IXmlReader* iface, IUnknown *input)
|
|
|
|
{
|
2010-01-21 19:05:25 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
2013-01-27 08:54:58 +01:00
|
|
|
IXmlReaderInput *readerinput;
|
2010-01-21 19:05:25 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, input);
|
2010-01-21 19:05:25 +01:00
|
|
|
|
|
|
|
if (This->input)
|
|
|
|
{
|
2012-11-19 00:01:46 +01:00
|
|
|
readerinput_release_stream(This->input);
|
2012-11-17 20:22:09 +01:00
|
|
|
IUnknown_Release(&This->input->IXmlReaderInput_iface);
|
2012-11-17 20:12:53 +01:00
|
|
|
This->input = NULL;
|
2010-01-21 19:05:25 +01:00
|
|
|
}
|
|
|
|
|
2017-03-29 19:47:05 +02:00
|
|
|
reader_reset_parser(This);
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2010-01-21 19:05:25 +01:00
|
|
|
/* just reset current input */
|
2010-01-23 21:03:14 +01:00
|
|
|
if (!input)
|
|
|
|
{
|
2010-01-25 21:52:09 +01:00
|
|
|
This->state = XmlReadState_Initial;
|
2010-01-23 21:03:14 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2010-01-21 19:05:25 +01:00
|
|
|
|
|
|
|
/* now try IXmlReaderInput, ISequentialStream, IStream */
|
2013-01-27 08:54:58 +01:00
|
|
|
hr = IUnknown_QueryInterface(input, &IID_IXmlReaderInput, (void**)&readerinput);
|
|
|
|
if (hr == S_OK)
|
2010-01-21 19:05:25 +01:00
|
|
|
{
|
2013-01-27 08:54:58 +01:00
|
|
|
if (readerinput->lpVtbl == &xmlreaderinputvtbl)
|
|
|
|
This->input = impl_from_IXmlReaderInput(readerinput);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("got external IXmlReaderInput implementation: %p, vtbl=%p\n",
|
|
|
|
readerinput, readerinput->lpVtbl);
|
|
|
|
IUnknown_Release(readerinput);
|
|
|
|
return E_FAIL;
|
2012-11-17 20:22:09 +01:00
|
|
|
|
2013-01-27 08:54:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hr != S_OK || !readerinput)
|
|
|
|
{
|
2010-01-21 19:05:25 +01:00
|
|
|
/* create IXmlReaderInput basing on supplied interface */
|
2010-01-23 17:05:50 +01:00
|
|
|
hr = CreateXmlReaderInputWithEncodingName(input,
|
2014-05-14 19:53:55 +02:00
|
|
|
This->imalloc, NULL, FALSE, NULL, &readerinput);
|
2010-01-23 17:05:50 +01:00
|
|
|
if (hr != S_OK) return hr;
|
2012-11-17 20:22:09 +01:00
|
|
|
This->input = impl_from_IXmlReaderInput(readerinput);
|
2010-01-21 19:05:25 +01:00
|
|
|
}
|
|
|
|
|
2010-01-23 17:05:50 +01:00
|
|
|
/* set stream for supplied IXmlReaderInput */
|
2012-11-19 00:01:46 +01:00
|
|
|
hr = readerinput_query_for_stream(This->input);
|
2010-01-25 20:37:59 +01:00
|
|
|
if (hr == S_OK)
|
2012-12-19 06:30:44 +01:00
|
|
|
{
|
2010-01-23 21:03:14 +01:00
|
|
|
This->state = XmlReadState_Initial;
|
2012-12-19 06:30:44 +01:00
|
|
|
This->instate = XmlReadInState_Initial;
|
|
|
|
}
|
2010-01-23 17:05:50 +01:00
|
|
|
return hr;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_GetProperty(IXmlReader* iface, UINT property, LONG_PTR *value)
|
|
|
|
{
|
2010-01-23 21:03:14 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
|
2014-05-14 09:52:13 +02:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_reader_prop(property), value);
|
2010-01-23 21:03:14 +01:00
|
|
|
|
|
|
|
if (!value) return E_INVALIDARG;
|
|
|
|
|
|
|
|
switch (property)
|
|
|
|
{
|
2016-10-30 09:05:28 +01:00
|
|
|
case XmlReaderProperty_MultiLanguage:
|
|
|
|
*value = (LONG_PTR)This->mlang;
|
|
|
|
if (This->mlang)
|
|
|
|
IUnknown_AddRef(This->mlang);
|
|
|
|
break;
|
2016-03-14 07:37:46 +01:00
|
|
|
case XmlReaderProperty_XmlResolver:
|
|
|
|
*value = (LONG_PTR)This->resolver;
|
|
|
|
if (This->resolver)
|
|
|
|
IXmlResolver_AddRef(This->resolver);
|
|
|
|
break;
|
2012-08-29 06:12:01 +02:00
|
|
|
case XmlReaderProperty_DtdProcessing:
|
|
|
|
*value = This->dtdmode;
|
|
|
|
break;
|
2010-01-23 21:03:14 +01:00
|
|
|
case XmlReaderProperty_ReadState:
|
|
|
|
*value = This->state;
|
|
|
|
break;
|
2017-03-07 04:50:59 +01:00
|
|
|
case XmlReaderProperty_MaxElementDepth:
|
|
|
|
*value = This->max_depth;
|
|
|
|
break;
|
2010-01-23 21:03:14 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unimplemented property (%u)\n", property);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_SetProperty(IXmlReader* iface, UINT property, LONG_PTR value)
|
|
|
|
{
|
2012-08-29 06:12:01 +02:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
|
2016-03-14 07:37:46 +01:00
|
|
|
TRACE("(%p)->(%s 0x%lx)\n", This, debugstr_reader_prop(property), value);
|
2012-08-29 06:12:01 +02:00
|
|
|
|
|
|
|
switch (property)
|
|
|
|
{
|
2016-10-27 17:34:53 +02:00
|
|
|
case XmlReaderProperty_MultiLanguage:
|
2016-10-30 09:05:28 +01:00
|
|
|
if (This->mlang)
|
|
|
|
IUnknown_Release(This->mlang);
|
|
|
|
This->mlang = (IUnknown*)value;
|
|
|
|
if (This->mlang)
|
|
|
|
IUnknown_AddRef(This->mlang);
|
|
|
|
if (This->mlang)
|
|
|
|
FIXME("Ignoring MultiLanguage %p\n", This->mlang);
|
2016-10-27 17:34:53 +02:00
|
|
|
break;
|
2016-03-14 07:37:46 +01:00
|
|
|
case XmlReaderProperty_XmlResolver:
|
|
|
|
if (This->resolver)
|
|
|
|
IXmlResolver_Release(This->resolver);
|
|
|
|
This->resolver = (IXmlResolver*)value;
|
|
|
|
if (This->resolver)
|
|
|
|
IXmlResolver_AddRef(This->resolver);
|
|
|
|
break;
|
2012-08-29 06:12:01 +02:00
|
|
|
case XmlReaderProperty_DtdProcessing:
|
|
|
|
if (value < 0 || value > _DtdProcessing_Last) return E_INVALIDARG;
|
|
|
|
This->dtdmode = value;
|
|
|
|
break;
|
2016-10-27 17:34:56 +02:00
|
|
|
case XmlReaderProperty_MaxElementDepth:
|
2017-03-07 04:50:59 +01:00
|
|
|
This->max_depth = value;
|
2016-10-27 17:34:56 +02:00
|
|
|
break;
|
2012-08-29 06:12:01 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unimplemented property (%u)\n", property);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
static HRESULT WINAPI xmlreader_Read(IXmlReader* iface, XmlNodeType *nodetype)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2012-11-19 00:01:46 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
2012-12-19 06:30:44 +01:00
|
|
|
XmlNodeType oldtype = This->nodetype;
|
2017-03-13 10:27:54 +01:00
|
|
|
XmlNodeType type;
|
2012-12-19 06:30:44 +01:00
|
|
|
HRESULT hr;
|
2012-11-19 00:01:46 +01:00
|
|
|
|
2012-12-19 06:32:37 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, nodetype);
|
2012-11-19 00:01:46 +01:00
|
|
|
|
2017-03-13 10:27:54 +01:00
|
|
|
if (!nodetype)
|
|
|
|
nodetype = &type;
|
2012-11-19 00:01:46 +01:00
|
|
|
|
2017-03-13 10:27:54 +01:00
|
|
|
switch (This->state)
|
|
|
|
{
|
|
|
|
case XmlReadState_Closed:
|
|
|
|
hr = S_FALSE;
|
|
|
|
break;
|
|
|
|
case XmlReadState_Error:
|
|
|
|
hr = This->error;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
hr = reader_parse_nextnode(This);
|
|
|
|
if (SUCCEEDED(hr) && oldtype == XmlNodeType_None && This->nodetype != oldtype)
|
|
|
|
This->state = XmlReadState_Interactive;
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
This->state = XmlReadState_Error;
|
|
|
|
This->nodetype = XmlNodeType_None;
|
2017-03-13 10:27:55 +01:00
|
|
|
This->depth = 0;
|
2017-03-13 10:27:54 +01:00
|
|
|
This->error = hr;
|
|
|
|
}
|
|
|
|
}
|
2017-03-06 10:35:56 +01:00
|
|
|
|
|
|
|
TRACE("node type %s\n", debugstr_nodetype(This->nodetype));
|
2017-03-13 10:27:54 +01:00
|
|
|
*nodetype = This->nodetype;
|
2012-11-26 03:59:49 +01:00
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
return hr;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_GetNodeType(IXmlReader* iface, XmlNodeType *node_type)
|
|
|
|
{
|
2012-11-19 01:00:24 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
2017-01-27 09:17:41 +01:00
|
|
|
|
2012-11-19 01:00:24 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, node_type);
|
2012-12-06 13:18:28 +01:00
|
|
|
|
2017-01-27 09:17:41 +01:00
|
|
|
if (!node_type)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2013-06-15 19:53:33 +02:00
|
|
|
*node_type = reader_get_nodetype(This);
|
2012-11-19 01:00:24 +01:00
|
|
|
return This->state == XmlReadState_Closed ? S_FALSE : S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2017-07-21 14:00:04 +02:00
|
|
|
static void reader_set_current_attribute(xmlreader *reader, struct attribute *attr)
|
|
|
|
{
|
|
|
|
reader->attr = attr;
|
|
|
|
reader->chunk_read_off = 0;
|
|
|
|
reader_set_strvalue(reader, StringValue_Prefix, &attr->prefix);
|
|
|
|
reader_set_strvalue(reader, StringValue_QualifiedName, &attr->qname);
|
|
|
|
reader_set_strvalue(reader, StringValue_Value, &attr->value);
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:26 +01:00
|
|
|
static HRESULT reader_move_to_first_attribute(xmlreader *reader)
|
|
|
|
{
|
|
|
|
if (!reader->attr_count)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2017-03-06 10:35:59 +01:00
|
|
|
if (!reader->attr)
|
2017-03-07 04:50:59 +01:00
|
|
|
reader_inc_depth(reader);
|
2017-03-06 10:35:59 +01:00
|
|
|
|
2017-07-21 14:00:04 +02:00
|
|
|
reader_set_current_attribute(reader, LIST_ENTRY(list_head(&reader->attrs), struct attribute, entry));
|
2016-12-09 14:38:26 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-18 22:18:22 +01:00
|
|
|
static HRESULT WINAPI xmlreader_MoveToFirstAttribute(IXmlReader* iface)
|
|
|
|
{
|
2012-12-06 13:05:19 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2016-12-09 14:38:26 +01:00
|
|
|
return reader_move_to_first_attribute(This);
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_MoveToNextAttribute(IXmlReader* iface)
|
|
|
|
{
|
2012-12-06 13:05:19 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
const struct list *next;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if (!This->attr_count) return S_FALSE;
|
|
|
|
|
|
|
|
if (!This->attr)
|
2016-12-09 14:38:26 +01:00
|
|
|
return reader_move_to_first_attribute(This);
|
2012-12-06 13:05:19 +01:00
|
|
|
|
|
|
|
next = list_next(&This->attrs, &This->attr->entry);
|
|
|
|
if (next)
|
2017-07-21 14:00:04 +02:00
|
|
|
reader_set_current_attribute(This, LIST_ENTRY(next, struct attribute, entry));
|
2012-12-06 13:05:19 +01:00
|
|
|
|
|
|
|
return next ? S_OK : S_FALSE;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2017-07-21 14:00:03 +02:00
|
|
|
static void reader_get_attribute_ns_uri(xmlreader *reader, struct attribute *attr, const WCHAR **uri, UINT *len)
|
|
|
|
{
|
2020-11-18 07:44:41 +01:00
|
|
|
static const WCHAR xmlns_uriW[] = L"http://www.w3.org/2000/xmlns/";
|
|
|
|
static const WCHAR xml_uriW[] = L"http://www.w3.org/XML/1998/namespace";
|
2017-07-21 14:00:03 +02:00
|
|
|
|
|
|
|
/* Check for reserved prefixes first */
|
|
|
|
if ((strval_eq(reader, &attr->prefix, &strval_empty) && strval_eq(reader, &attr->localname, &strval_xmlns)) ||
|
|
|
|
strval_eq(reader, &attr->prefix, &strval_xmlns))
|
|
|
|
{
|
|
|
|
*uri = xmlns_uriW;
|
2018-02-22 07:01:43 +01:00
|
|
|
*len = ARRAY_SIZE(xmlns_uriW) - 1;
|
2017-07-21 14:00:03 +02:00
|
|
|
}
|
|
|
|
else if (strval_eq(reader, &attr->prefix, &strval_xml))
|
|
|
|
{
|
|
|
|
*uri = xml_uriW;
|
2018-02-22 07:01:43 +01:00
|
|
|
*len = ARRAY_SIZE(xml_uriW) - 1;
|
2017-07-21 14:00:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*uri = NULL;
|
|
|
|
*len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*uri)
|
|
|
|
{
|
|
|
|
struct ns *ns;
|
|
|
|
|
|
|
|
if ((ns = reader_lookup_ns(reader, &attr->prefix)))
|
|
|
|
{
|
|
|
|
*uri = ns->uri.str;
|
|
|
|
*len = ns->uri.len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*uri = emptyW;
|
|
|
|
*len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reader_get_attribute_local_name(xmlreader *reader, struct attribute *attr, const WCHAR **name, UINT *len)
|
|
|
|
{
|
|
|
|
if (attr->flags & ATTRIBUTE_DEFAULT_NS_DEFINITION)
|
|
|
|
{
|
|
|
|
*name = xmlnsW;
|
|
|
|
*len = 5;
|
|
|
|
}
|
|
|
|
else if (attr->flags & ATTRIBUTE_NS_DEFINITION)
|
|
|
|
{
|
|
|
|
const struct ns *ns = reader_lookup_ns(reader, &attr->localname);
|
|
|
|
*name = ns->prefix.str;
|
|
|
|
*len = ns->prefix.len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*name = attr->localname.str;
|
|
|
|
*len = attr->localname.len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-18 22:18:22 +01:00
|
|
|
static HRESULT WINAPI xmlreader_MoveToAttributeByName(IXmlReader* iface,
|
2017-07-21 14:00:03 +02:00
|
|
|
const WCHAR *local_name, const WCHAR *namespace_uri)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2017-07-21 14:00:03 +02:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
UINT target_name_len, target_uri_len;
|
|
|
|
struct attribute *attr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %s)\n", This, debugstr_w(local_name), debugstr_w(namespace_uri));
|
|
|
|
|
|
|
|
if (!local_name)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!This->attr_count)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
if (!namespace_uri)
|
|
|
|
namespace_uri = emptyW;
|
|
|
|
|
2019-06-27 21:49:21 +02:00
|
|
|
target_name_len = lstrlenW(local_name);
|
|
|
|
target_uri_len = lstrlenW(namespace_uri);
|
2017-07-21 14:00:03 +02:00
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(attr, &This->attrs, struct attribute, entry)
|
|
|
|
{
|
|
|
|
UINT name_len, uri_len;
|
|
|
|
const WCHAR *name, *uri;
|
|
|
|
|
|
|
|
reader_get_attribute_local_name(This, attr, &name, &name_len);
|
|
|
|
reader_get_attribute_ns_uri(This, attr, &uri, &uri_len);
|
|
|
|
|
|
|
|
if (name_len == target_name_len && uri_len == target_uri_len &&
|
2019-06-27 21:49:21 +02:00
|
|
|
!wcscmp(name, local_name) && !wcscmp(uri, namespace_uri))
|
2017-07-21 14:00:03 +02:00
|
|
|
{
|
2017-07-21 14:00:04 +02:00
|
|
|
reader_set_current_attribute(This, attr);
|
2017-07-21 14:00:03 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_FALSE;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_MoveToElement(IXmlReader* iface)
|
|
|
|
{
|
2012-12-06 13:05:19 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if (!This->attr_count) return S_FALSE;
|
2017-03-06 10:35:59 +01:00
|
|
|
|
|
|
|
if (This->attr)
|
|
|
|
reader_dec_depth(This);
|
|
|
|
|
2012-12-06 13:05:19 +01:00
|
|
|
This->attr = NULL;
|
2013-08-19 08:42:38 +02:00
|
|
|
|
|
|
|
/* FIXME: support other node types with 'attributes' like DTD */
|
2016-12-09 14:38:22 +01:00
|
|
|
if (This->is_empty_element) {
|
2017-03-07 04:50:57 +01:00
|
|
|
reader_set_strvalue(This, StringValue_Prefix, &This->empty_element.prefix);
|
2016-12-09 14:38:22 +01:00
|
|
|
reader_set_strvalue(This, StringValue_QualifiedName, &This->empty_element.qname);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
struct element *element = LIST_ENTRY(list_head(&This->elements), struct element, entry);
|
|
|
|
if (element) {
|
2017-03-07 04:50:57 +01:00
|
|
|
reader_set_strvalue(This, StringValue_Prefix, &element->prefix);
|
2016-12-09 14:38:22 +01:00
|
|
|
reader_set_strvalue(This, StringValue_QualifiedName, &element->qname);
|
|
|
|
}
|
2013-08-19 08:42:38 +02:00
|
|
|
}
|
2017-03-31 15:58:06 +02:00
|
|
|
This->chunk_read_off = 0;
|
2017-03-07 04:50:56 +01:00
|
|
|
reader_set_strvalue(This, StringValue_Value, &strval_empty);
|
2013-08-19 08:42:38 +02:00
|
|
|
|
2012-12-06 13:05:19 +01:00
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
static HRESULT WINAPI xmlreader_GetQualifiedName(IXmlReader* iface, LPCWSTR *name, UINT *len)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2013-01-06 21:55:36 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
2017-03-17 14:46:13 +01:00
|
|
|
struct attribute *attribute = This->attr;
|
2017-03-17 14:46:12 +01:00
|
|
|
struct element *element;
|
2017-03-08 05:07:11 +01:00
|
|
|
UINT length;
|
2013-01-06 21:55:36 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, name, len);
|
2017-03-08 05:07:11 +01:00
|
|
|
|
|
|
|
if (!len)
|
|
|
|
len = &length;
|
|
|
|
|
2017-03-10 09:06:40 +01:00
|
|
|
switch (reader_get_nodetype(This))
|
2017-03-08 05:07:11 +01:00
|
|
|
{
|
2017-03-10 09:06:40 +01:00
|
|
|
case XmlNodeType_Text:
|
|
|
|
case XmlNodeType_CDATA:
|
|
|
|
case XmlNodeType_Comment:
|
|
|
|
case XmlNodeType_Whitespace:
|
|
|
|
*name = emptyW;
|
|
|
|
*len = 0;
|
|
|
|
break;
|
2017-03-08 05:07:11 +01:00
|
|
|
case XmlNodeType_Element:
|
|
|
|
case XmlNodeType_EndElement:
|
2017-03-17 14:46:12 +01:00
|
|
|
element = reader_get_element(This);
|
|
|
|
if (element->prefix.len)
|
2017-03-08 05:07:11 +01:00
|
|
|
{
|
|
|
|
*name = element->qname.str;
|
|
|
|
*len = element->qname.len;
|
|
|
|
}
|
2017-03-17 14:46:12 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*name = element->localname.str;
|
|
|
|
*len = element->localname.len;
|
|
|
|
}
|
|
|
|
break;
|
2017-03-17 14:46:13 +01:00
|
|
|
case XmlNodeType_Attribute:
|
|
|
|
if (attribute->flags & ATTRIBUTE_DEFAULT_NS_DEFINITION)
|
|
|
|
{
|
|
|
|
*name = xmlnsW;
|
|
|
|
*len = 5;
|
|
|
|
} else if (attribute->prefix.len)
|
|
|
|
{
|
|
|
|
*name = This->strvalues[StringValue_QualifiedName].str;
|
|
|
|
*len = This->strvalues[StringValue_QualifiedName].len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-31 15:57:51 +02:00
|
|
|
*name = attribute->localname.str;
|
|
|
|
*len = attribute->localname.len;
|
2017-03-17 14:46:13 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-03-08 05:07:11 +01:00
|
|
|
default:
|
|
|
|
*name = This->strvalues[StringValue_QualifiedName].str;
|
|
|
|
*len = This->strvalues[StringValue_QualifiedName].len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:29 +01:00
|
|
|
static struct ns *reader_lookup_nsdef(xmlreader *reader)
|
|
|
|
{
|
|
|
|
if (list_empty(&reader->nsdef))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return LIST_ENTRY(list_head(&reader->nsdef), struct ns, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_GetNamespaceUri(IXmlReader* iface, const WCHAR **uri, UINT *len)
|
|
|
|
{
|
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
const strval *prefix = &This->strvalues[StringValue_Prefix];
|
|
|
|
XmlNodeType nodetype;
|
|
|
|
struct ns *ns;
|
|
|
|
UINT length;
|
|
|
|
|
|
|
|
TRACE("(%p %p %p)\n", iface, uri, len);
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
len = &length;
|
|
|
|
|
|
|
|
switch ((nodetype = reader_get_nodetype(This)))
|
|
|
|
{
|
|
|
|
case XmlNodeType_Attribute:
|
2017-07-21 14:00:03 +02:00
|
|
|
reader_get_attribute_ns_uri(This, This->attr, uri, len);
|
2016-12-09 14:38:29 +01:00
|
|
|
break;
|
|
|
|
case XmlNodeType_Element:
|
|
|
|
case XmlNodeType_EndElement:
|
|
|
|
{
|
|
|
|
ns = reader_lookup_ns(This, prefix);
|
|
|
|
|
|
|
|
/* pick top default ns if any */
|
|
|
|
if (!ns)
|
|
|
|
ns = reader_lookup_nsdef(This);
|
|
|
|
|
|
|
|
if (ns) {
|
|
|
|
*uri = ns->uri.str;
|
|
|
|
*len = ns->uri.len;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*uri = emptyW;
|
|
|
|
*len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-03-08 05:07:09 +01:00
|
|
|
case XmlNodeType_Text:
|
|
|
|
case XmlNodeType_CDATA:
|
|
|
|
case XmlNodeType_ProcessingInstruction:
|
|
|
|
case XmlNodeType_Comment:
|
|
|
|
case XmlNodeType_Whitespace:
|
|
|
|
case XmlNodeType_XmlDeclaration:
|
|
|
|
*uri = emptyW;
|
|
|
|
*len = 0;
|
|
|
|
break;
|
2016-12-09 14:38:29 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled node type %d\n", nodetype);
|
2017-07-21 14:00:03 +02:00
|
|
|
*uri = NULL;
|
|
|
|
*len = 0;
|
2016-12-09 14:38:29 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2010-01-18 22:05:53 +01:00
|
|
|
}
|
2010-01-18 22:18:22 +01:00
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
static HRESULT WINAPI xmlreader_GetLocalName(IXmlReader* iface, LPCWSTR *name, UINT *len)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2013-01-06 21:55:36 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
2017-03-17 14:46:11 +01:00
|
|
|
struct element *element;
|
2017-03-08 05:07:10 +01:00
|
|
|
UINT length;
|
2013-01-06 21:55:36 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, name, len);
|
2017-03-08 05:07:10 +01:00
|
|
|
|
|
|
|
if (!len)
|
|
|
|
len = &length;
|
|
|
|
|
2017-03-10 09:06:39 +01:00
|
|
|
switch (reader_get_nodetype(This))
|
2017-03-08 05:07:10 +01:00
|
|
|
{
|
2017-03-10 09:06:39 +01:00
|
|
|
case XmlNodeType_Text:
|
|
|
|
case XmlNodeType_CDATA:
|
|
|
|
case XmlNodeType_Comment:
|
|
|
|
case XmlNodeType_Whitespace:
|
|
|
|
*name = emptyW;
|
|
|
|
*len = 0;
|
|
|
|
break;
|
2017-03-08 05:07:10 +01:00
|
|
|
case XmlNodeType_Element:
|
|
|
|
case XmlNodeType_EndElement:
|
2017-03-17 14:46:11 +01:00
|
|
|
element = reader_get_element(This);
|
|
|
|
*name = element->localname.str;
|
|
|
|
*len = element->localname.len;
|
|
|
|
break;
|
2017-03-17 14:46:13 +01:00
|
|
|
case XmlNodeType_Attribute:
|
2017-07-21 14:00:03 +02:00
|
|
|
reader_get_attribute_local_name(This, This->attr, name, len);
|
2017-03-17 14:46:13 +01:00
|
|
|
break;
|
2017-03-08 05:07:10 +01:00
|
|
|
default:
|
|
|
|
*name = This->strvalues[StringValue_LocalName].str;
|
|
|
|
*len = This->strvalues[StringValue_LocalName].len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2017-03-09 05:14:06 +01:00
|
|
|
static HRESULT WINAPI xmlreader_GetPrefix(IXmlReader* iface, const WCHAR **ret, UINT *len)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2013-06-14 22:54:44 +02:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
2017-03-09 05:14:06 +01:00
|
|
|
XmlNodeType nodetype;
|
|
|
|
UINT length;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, ret, len);
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
len = &length;
|
|
|
|
|
|
|
|
*ret = emptyW;
|
|
|
|
*len = 0;
|
|
|
|
|
|
|
|
switch ((nodetype = reader_get_nodetype(This)))
|
|
|
|
{
|
|
|
|
case XmlNodeType_Element:
|
|
|
|
case XmlNodeType_EndElement:
|
|
|
|
case XmlNodeType_Attribute:
|
|
|
|
{
|
|
|
|
const strval *prefix = &This->strvalues[StringValue_Prefix];
|
|
|
|
struct ns *ns;
|
|
|
|
|
|
|
|
if (strval_eq(This, prefix, &strval_xml))
|
|
|
|
{
|
|
|
|
*ret = xmlW;
|
|
|
|
*len = 3;
|
|
|
|
}
|
|
|
|
else if (strval_eq(This, prefix, &strval_xmlns))
|
|
|
|
{
|
|
|
|
*ret = xmlnsW;
|
|
|
|
*len = 5;
|
|
|
|
}
|
|
|
|
else if ((ns = reader_lookup_ns(This, prefix)))
|
|
|
|
{
|
|
|
|
*ret = ns->prefix.str;
|
|
|
|
*len = ns->prefix.len;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
2013-06-14 22:54:44 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 15:58:06 +02:00
|
|
|
static const strval *reader_get_value(xmlreader *reader, BOOL ensure_allocated)
|
|
|
|
{
|
|
|
|
strval *val;
|
|
|
|
|
|
|
|
switch (reader_get_nodetype(reader))
|
|
|
|
{
|
|
|
|
case XmlNodeType_XmlDeclaration:
|
|
|
|
case XmlNodeType_EndElement:
|
|
|
|
case XmlNodeType_None:
|
|
|
|
return &strval_empty;
|
|
|
|
case XmlNodeType_Attribute:
|
|
|
|
/* For namespace definition attributes return values from namespace list */
|
|
|
|
if (reader->attr->flags & (ATTRIBUTE_NS_DEFINITION | ATTRIBUTE_DEFAULT_NS_DEFINITION))
|
|
|
|
{
|
|
|
|
struct ns *ns;
|
|
|
|
|
|
|
|
if (!(ns = reader_lookup_ns(reader, &reader->attr->localname)))
|
|
|
|
ns = reader_lookup_nsdef(reader);
|
|
|
|
|
|
|
|
return &ns->uri;
|
|
|
|
}
|
2017-03-31 15:58:21 +02:00
|
|
|
return &reader->attr->value;
|
2017-03-31 15:58:06 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = &reader->strvalues[StringValue_Value];
|
|
|
|
if (!val->str && ensure_allocated)
|
|
|
|
{
|
|
|
|
WCHAR *ptr = reader_alloc(reader, (val->len+1)*sizeof(WCHAR));
|
|
|
|
if (!ptr) return NULL;
|
|
|
|
memcpy(ptr, reader_get_strptr(reader, val), val->len*sizeof(WCHAR));
|
|
|
|
ptr[val->len] = 0;
|
|
|
|
val->str = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-03-14 12:08:29 +01:00
|
|
|
static HRESULT WINAPI xmlreader_GetValue(IXmlReader* iface, const WCHAR **value, UINT *len)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2013-03-14 12:08:29 +01:00
|
|
|
xmlreader *reader = impl_from_IXmlReader(iface);
|
2017-03-31 15:58:06 +02:00
|
|
|
const strval *val = &reader->strvalues[StringValue_Value];
|
|
|
|
UINT off;
|
2013-01-08 11:32:21 +01:00
|
|
|
|
2013-03-14 12:08:29 +01:00
|
|
|
TRACE("(%p)->(%p %p)\n", reader, value, len);
|
2013-01-27 08:17:27 +01:00
|
|
|
|
2013-03-11 05:49:28 +01:00
|
|
|
*value = NULL;
|
|
|
|
|
2017-03-08 05:07:08 +01:00
|
|
|
if ((reader->nodetype == XmlNodeType_Comment && !val->str && !val->len) || is_reader_pending(reader))
|
2013-01-27 08:17:27 +01:00
|
|
|
{
|
|
|
|
XmlNodeType type;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IXmlReader_Read(iface, &type);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
/* return if still pending, partially read values are not reported */
|
2013-03-14 12:08:29 +01:00
|
|
|
if (is_reader_pending(reader)) return E_PENDING;
|
2013-01-27 08:17:27 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 15:58:06 +02:00
|
|
|
val = reader_get_value(reader, TRUE);
|
|
|
|
if (!val)
|
|
|
|
return E_OUTOFMEMORY;
|
2016-12-09 14:38:30 +01:00
|
|
|
|
2017-03-31 15:58:06 +02:00
|
|
|
off = abs(reader->chunk_read_off);
|
|
|
|
assert(off <= val->len);
|
|
|
|
*value = val->str + off;
|
|
|
|
if (len) *len = val->len - off;
|
|
|
|
reader->chunk_read_off = -off;
|
2013-01-08 11:32:21 +01:00
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2013-03-14 12:08:29 +01:00
|
|
|
static HRESULT WINAPI xmlreader_ReadValueChunk(IXmlReader* iface, WCHAR *buffer, UINT chunk_size, UINT *read)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2013-03-14 12:08:29 +01:00
|
|
|
xmlreader *reader = impl_from_IXmlReader(iface);
|
2017-03-31 15:58:06 +02:00
|
|
|
const strval *val;
|
|
|
|
UINT len = 0;
|
2013-03-14 12:08:29 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %u %p)\n", reader, buffer, chunk_size, read);
|
|
|
|
|
2017-03-31 15:58:06 +02:00
|
|
|
val = reader_get_value(reader, FALSE);
|
|
|
|
|
|
|
|
/* If value is already read by GetValue, chunk_read_off is negative and chunked reads are not possible. */
|
|
|
|
if (reader->chunk_read_off >= 0)
|
|
|
|
{
|
|
|
|
assert(reader->chunk_read_off <= val->len);
|
|
|
|
len = min(val->len - reader->chunk_read_off, chunk_size);
|
|
|
|
}
|
2017-03-21 16:19:24 +01:00
|
|
|
if (read) *read = len;
|
2013-03-14 12:08:29 +01:00
|
|
|
|
2017-03-21 16:19:24 +01:00
|
|
|
if (len)
|
2013-03-14 12:08:29 +01:00
|
|
|
{
|
2017-03-31 15:58:06 +02:00
|
|
|
memcpy(buffer, reader_get_strptr(reader, val) + reader->chunk_read_off, len*sizeof(WCHAR));
|
|
|
|
reader->chunk_read_off += len;
|
2013-03-14 12:08:29 +01:00
|
|
|
}
|
|
|
|
|
2017-03-21 16:19:24 +01:00
|
|
|
return len || !chunk_size ? S_OK : S_FALSE;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_GetBaseUri(IXmlReader* iface,
|
|
|
|
LPCWSTR *baseUri,
|
|
|
|
UINT *baseUri_length)
|
|
|
|
{
|
|
|
|
FIXME("(%p %p %p): stub\n", iface, baseUri, baseUri_length);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI xmlreader_IsDefault(IXmlReader* iface)
|
|
|
|
{
|
|
|
|
FIXME("(%p): stub\n", iface);
|
2013-06-15 20:04:24 +02:00
|
|
|
return FALSE;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI xmlreader_IsEmptyElement(IXmlReader* iface)
|
|
|
|
{
|
2013-06-15 19:53:33 +02:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
/* Empty elements are not placed in stack, it's stored as a global reader flag that makes sense
|
|
|
|
when current node is start tag of an element */
|
2016-12-09 14:38:22 +01:00
|
|
|
return (reader_get_nodetype(This) == XmlNodeType_Element) ? This->is_empty_element : FALSE;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
static HRESULT WINAPI xmlreader_GetLineNumber(IXmlReader* iface, UINT *line_number)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2010-01-25 19:55:02 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
2017-03-09 05:14:09 +01:00
|
|
|
const struct element *element;
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
TRACE("(%p %p)\n", This, line_number);
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
if (!line_number)
|
|
|
|
return E_INVALIDARG;
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
switch (reader_get_nodetype(This))
|
|
|
|
{
|
|
|
|
case XmlNodeType_Element:
|
|
|
|
case XmlNodeType_EndElement:
|
2017-03-17 14:46:11 +01:00
|
|
|
element = reader_get_element(This);
|
2017-03-09 05:14:09 +01:00
|
|
|
*line_number = element->position.line_number;
|
|
|
|
break;
|
|
|
|
case XmlNodeType_Attribute:
|
|
|
|
*line_number = This->attr->position.line_number;
|
|
|
|
break;
|
2017-03-10 09:06:44 +01:00
|
|
|
case XmlNodeType_Whitespace:
|
2017-03-09 05:14:10 +01:00
|
|
|
case XmlNodeType_XmlDeclaration:
|
|
|
|
*line_number = This->empty_element.position.line_number;
|
|
|
|
break;
|
2017-03-09 05:14:09 +01:00
|
|
|
default:
|
|
|
|
*line_number = This->position.line_number;
|
|
|
|
break;
|
|
|
|
}
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-10 09:06:42 +01:00
|
|
|
return This->state == XmlReadState_Closed ? S_FALSE : S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
static HRESULT WINAPI xmlreader_GetLinePosition(IXmlReader* iface, UINT *line_position)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2010-01-25 19:55:02 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
2017-03-09 05:14:09 +01:00
|
|
|
const struct element *element;
|
|
|
|
|
|
|
|
TRACE("(%p %p)\n", This, line_position);
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
if (!line_position)
|
|
|
|
return E_INVALIDARG;
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
switch (reader_get_nodetype(This))
|
|
|
|
{
|
|
|
|
case XmlNodeType_Element:
|
|
|
|
case XmlNodeType_EndElement:
|
2017-03-17 14:46:11 +01:00
|
|
|
element = reader_get_element(This);
|
2017-03-09 05:14:09 +01:00
|
|
|
*line_position = element->position.line_position;
|
|
|
|
break;
|
|
|
|
case XmlNodeType_Attribute:
|
|
|
|
*line_position = This->attr->position.line_position;
|
|
|
|
break;
|
2017-03-10 09:06:44 +01:00
|
|
|
case XmlNodeType_Whitespace:
|
2017-03-09 05:14:10 +01:00
|
|
|
case XmlNodeType_XmlDeclaration:
|
|
|
|
*line_position = This->empty_element.position.line_position;
|
|
|
|
break;
|
2017-03-09 05:14:09 +01:00
|
|
|
default:
|
|
|
|
*line_position = This->position.line_position;
|
|
|
|
break;
|
|
|
|
}
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-10 09:06:42 +01:00
|
|
|
return This->state == XmlReadState_Closed ? S_FALSE : S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
static HRESULT WINAPI xmlreader_GetAttributeCount(IXmlReader* iface, UINT *count)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2012-12-04 10:31:25 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, count);
|
|
|
|
|
|
|
|
if (!count) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*count = This->attr_count;
|
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_GetDepth(IXmlReader* iface, UINT *depth)
|
|
|
|
{
|
2013-01-20 22:03:23 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
TRACE("(%p)->(%p)\n", This, depth);
|
|
|
|
*depth = This->depth;
|
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI xmlreader_IsEOF(IXmlReader* iface)
|
|
|
|
{
|
2017-03-06 10:35:58 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
return This->state == XmlReadState_EndOfFile;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IXmlReaderVtbl xmlreader_vtbl =
|
|
|
|
{
|
|
|
|
xmlreader_QueryInterface,
|
|
|
|
xmlreader_AddRef,
|
|
|
|
xmlreader_Release,
|
|
|
|
xmlreader_SetInput,
|
|
|
|
xmlreader_GetProperty,
|
|
|
|
xmlreader_SetProperty,
|
|
|
|
xmlreader_Read,
|
|
|
|
xmlreader_GetNodeType,
|
|
|
|
xmlreader_MoveToFirstAttribute,
|
|
|
|
xmlreader_MoveToNextAttribute,
|
|
|
|
xmlreader_MoveToAttributeByName,
|
|
|
|
xmlreader_MoveToElement,
|
|
|
|
xmlreader_GetQualifiedName,
|
|
|
|
xmlreader_GetNamespaceUri,
|
|
|
|
xmlreader_GetLocalName,
|
|
|
|
xmlreader_GetPrefix,
|
|
|
|
xmlreader_GetValue,
|
|
|
|
xmlreader_ReadValueChunk,
|
|
|
|
xmlreader_GetBaseUri,
|
|
|
|
xmlreader_IsDefault,
|
|
|
|
xmlreader_IsEmptyElement,
|
|
|
|
xmlreader_GetLineNumber,
|
|
|
|
xmlreader_GetLinePosition,
|
|
|
|
xmlreader_GetAttributeCount,
|
|
|
|
xmlreader_GetDepth,
|
|
|
|
xmlreader_IsEOF
|
|
|
|
};
|
|
|
|
|
2010-01-23 17:05:50 +01:00
|
|
|
/** IXmlReaderInput **/
|
2010-01-21 16:19:20 +01:00
|
|
|
static HRESULT WINAPI xmlreaderinput_QueryInterface(IXmlReaderInput *iface, REFIID riid, void** ppvObject)
|
|
|
|
{
|
|
|
|
xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
|
|
|
|
|
2013-01-27 08:54:58 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
|
2010-01-21 16:19:20 +01:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IXmlReaderInput) ||
|
|
|
|
IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-17 20:12:53 +01:00
|
|
|
WARN("interface %s not implemented\n", debugstr_guid(riid));
|
2013-01-27 08:54:58 +01:00
|
|
|
*ppvObject = NULL;
|
2010-01-21 16:19:20 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlreaderinput_AddRef(IXmlReaderInput *iface)
|
|
|
|
{
|
|
|
|
xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
|
2012-11-17 17:40:46 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
2010-01-21 16:19:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlreaderinput_Release(IXmlReaderInput *iface)
|
|
|
|
{
|
|
|
|
xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
|
2012-11-17 17:40:46 +01:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
2010-01-21 16:19:20 +01:00
|
|
|
|
2012-11-17 17:40:46 +01:00
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
2010-01-21 16:19:20 +01:00
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2012-11-17 17:40:46 +01:00
|
|
|
IMalloc *imalloc = This->imalloc;
|
2010-01-23 17:05:50 +01:00
|
|
|
if (This->input) IUnknown_Release(This->input);
|
2012-11-17 20:12:53 +01:00
|
|
|
if (This->stream) ISequentialStream_Release(This->stream);
|
2012-11-17 19:54:16 +01:00
|
|
|
if (This->buffer) free_input_buffer(This->buffer);
|
2012-11-19 05:33:55 +01:00
|
|
|
readerinput_free(This, This->baseuri);
|
2012-11-17 17:40:46 +01:00
|
|
|
readerinput_free(This, This);
|
|
|
|
if (imalloc) IMalloc_Release(imalloc);
|
2010-01-21 16:19:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2013-01-27 08:54:58 +01:00
|
|
|
static const struct IUnknownVtbl xmlreaderinputvtbl =
|
2010-01-21 16:19:20 +01:00
|
|
|
{
|
|
|
|
xmlreaderinput_QueryInterface,
|
|
|
|
xmlreaderinput_AddRef,
|
|
|
|
xmlreaderinput_Release
|
|
|
|
};
|
|
|
|
|
2012-11-17 17:22:47 +01:00
|
|
|
HRESULT WINAPI CreateXmlReader(REFIID riid, void **obj, IMalloc *imalloc)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
|
|
|
xmlreader *reader;
|
2017-04-11 13:28:40 +02:00
|
|
|
HRESULT hr;
|
2013-01-08 11:32:21 +01:00
|
|
|
int i;
|
2010-01-18 22:18:22 +01:00
|
|
|
|
2012-11-17 17:22:47 +01:00
|
|
|
TRACE("(%s, %p, %p)\n", wine_dbgstr_guid(riid), obj, imalloc);
|
2010-01-18 22:18:22 +01:00
|
|
|
|
2012-11-17 17:22:47 +01:00
|
|
|
if (imalloc)
|
|
|
|
reader = IMalloc_Alloc(imalloc, sizeof(*reader));
|
|
|
|
else
|
|
|
|
reader = heap_alloc(sizeof(*reader));
|
2017-03-17 14:46:11 +01:00
|
|
|
if (!reader)
|
|
|
|
return E_OUTOFMEMORY;
|
2010-01-18 22:18:22 +01:00
|
|
|
|
2017-03-17 14:46:11 +01:00
|
|
|
memset(reader, 0, sizeof(*reader));
|
2011-03-24 13:53:43 +01:00
|
|
|
reader->IXmlReader_iface.lpVtbl = &xmlreader_vtbl;
|
2010-01-18 22:18:22 +01:00
|
|
|
reader->ref = 1;
|
2010-01-23 21:03:14 +01:00
|
|
|
reader->state = XmlReadState_Closed;
|
2012-12-19 06:30:44 +01:00
|
|
|
reader->instate = XmlReadInState_Initial;
|
2013-03-08 11:10:26 +01:00
|
|
|
reader->resumestate = XmlReadResumeState_Initial;
|
2012-08-29 06:12:01 +02:00
|
|
|
reader->dtdmode = DtdProcessing_Prohibit;
|
2012-11-17 17:22:47 +01:00
|
|
|
reader->imalloc = imalloc;
|
|
|
|
if (imalloc) IMalloc_AddRef(imalloc);
|
2012-11-19 01:00:24 +01:00
|
|
|
reader->nodetype = XmlNodeType_None;
|
2012-12-04 10:31:25 +01:00
|
|
|
list_init(&reader->attrs);
|
2016-12-09 14:38:24 +01:00
|
|
|
list_init(&reader->nsdef);
|
|
|
|
list_init(&reader->ns);
|
2013-01-20 20:46:25 +01:00
|
|
|
list_init(&reader->elements);
|
2013-06-18 14:31:01 +02:00
|
|
|
reader->max_depth = 256;
|
2013-01-08 11:32:21 +01:00
|
|
|
|
2017-03-31 15:58:06 +02:00
|
|
|
reader->chunk_read_off = 0;
|
2013-01-08 11:32:21 +01:00
|
|
|
for (i = 0; i < StringValue_Last; i++)
|
|
|
|
reader->strvalues[i] = strval_empty;
|
2010-01-18 22:18:22 +01:00
|
|
|
|
2017-04-11 13:28:40 +02:00
|
|
|
hr = IXmlReader_QueryInterface(&reader->IXmlReader_iface, riid, obj);
|
|
|
|
IXmlReader_Release(&reader->IXmlReader_iface);
|
2010-01-18 22:18:22 +01:00
|
|
|
|
2017-04-11 13:28:40 +02:00
|
|
|
TRACE("returning iface %p, hr %#x\n", *obj, hr);
|
2010-01-18 22:18:22 +01:00
|
|
|
|
2017-04-11 13:28:40 +02:00
|
|
|
return hr;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
2010-01-21 15:47:03 +01:00
|
|
|
|
|
|
|
HRESULT WINAPI CreateXmlReaderInputWithEncodingName(IUnknown *stream,
|
2012-11-17 17:40:46 +01:00
|
|
|
IMalloc *imalloc,
|
2010-01-21 15:47:03 +01:00
|
|
|
LPCWSTR encoding,
|
|
|
|
BOOL hint,
|
|
|
|
LPCWSTR base_uri,
|
|
|
|
IXmlReaderInput **ppInput)
|
|
|
|
{
|
2010-01-21 16:19:20 +01:00
|
|
|
xmlreaderinput *readerinput;
|
2012-11-17 19:54:16 +01:00
|
|
|
HRESULT hr;
|
2010-01-21 16:19:20 +01:00
|
|
|
|
2012-11-19 05:33:55 +01:00
|
|
|
TRACE("%p %p %s %d %s %p\n", stream, imalloc, wine_dbgstr_w(encoding),
|
2010-01-21 16:19:20 +01:00
|
|
|
hint, wine_dbgstr_w(base_uri), ppInput);
|
|
|
|
|
|
|
|
if (!stream || !ppInput) return E_INVALIDARG;
|
|
|
|
|
2012-11-17 17:40:46 +01:00
|
|
|
if (imalloc)
|
|
|
|
readerinput = IMalloc_Alloc(imalloc, sizeof(*readerinput));
|
|
|
|
else
|
|
|
|
readerinput = heap_alloc(sizeof(*readerinput));
|
2010-01-21 16:19:20 +01:00
|
|
|
if(!readerinput) return E_OUTOFMEMORY;
|
|
|
|
|
2013-01-27 08:54:58 +01:00
|
|
|
readerinput->IXmlReaderInput_iface.lpVtbl = &xmlreaderinputvtbl;
|
2010-01-21 16:19:20 +01:00
|
|
|
readerinput->ref = 1;
|
2012-11-17 17:40:46 +01:00
|
|
|
readerinput->imalloc = imalloc;
|
2012-11-17 20:12:53 +01:00
|
|
|
readerinput->stream = NULL;
|
2012-11-17 17:40:46 +01:00
|
|
|
if (imalloc) IMalloc_AddRef(imalloc);
|
2012-11-27 14:46:42 +01:00
|
|
|
readerinput->encoding = parse_encoding_name(encoding, -1);
|
2012-11-19 05:33:55 +01:00
|
|
|
readerinput->hint = hint;
|
|
|
|
readerinput->baseuri = readerinput_strdupW(readerinput, base_uri);
|
2013-01-27 08:17:27 +01:00
|
|
|
readerinput->pending = 0;
|
2012-11-17 19:54:16 +01:00
|
|
|
|
2012-11-19 00:01:46 +01:00
|
|
|
hr = alloc_input_buffer(readerinput);
|
2012-11-17 19:54:16 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
2013-01-27 08:17:27 +01:00
|
|
|
readerinput_free(readerinput, readerinput->baseuri);
|
2012-11-17 19:54:16 +01:00
|
|
|
readerinput_free(readerinput, readerinput);
|
2013-01-27 08:17:27 +01:00
|
|
|
if (imalloc) IMalloc_Release(imalloc);
|
2012-11-17 19:54:16 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2010-01-23 17:05:50 +01:00
|
|
|
IUnknown_QueryInterface(stream, &IID_IUnknown, (void**)&readerinput->input);
|
2010-01-21 16:19:20 +01:00
|
|
|
|
2011-03-24 13:53:43 +01:00
|
|
|
*ppInput = &readerinput->IXmlReaderInput_iface;
|
2010-01-21 16:19:20 +01:00
|
|
|
|
|
|
|
TRACE("returning iface %p\n", *ppInput);
|
|
|
|
|
|
|
|
return S_OK;
|
2010-01-21 15:47:03 +01:00
|
|
|
}
|