2010-01-18 22:05:53 +01:00
|
|
|
/*
|
|
|
|
* IXmlReader implementation
|
|
|
|
*
|
2013-01-05 23:08:27 +01:00
|
|
|
* Copyright 2010, 2012-2013 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
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#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"
|
2012-11-19 05:33:55 +01:00
|
|
|
#include "wine/unicode.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-11-17 19:54:16 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
XmlEncoding_UTF16,
|
|
|
|
XmlEncoding_UTF8,
|
|
|
|
XmlEncoding_Unknown
|
|
|
|
} xml_encoding;
|
|
|
|
|
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,
|
|
|
|
XmlReadInState_Element
|
2012-12-19 06:30:44 +01:00
|
|
|
} XmlReaderInternalState;
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
StringValue_LocalName,
|
|
|
|
StringValue_QualifiedName,
|
2013-01-08 11:32:21 +01:00
|
|
|
StringValue_Value,
|
2013-01-06 21:55:36 +01:00
|
|
|
StringValue_Last
|
|
|
|
} XmlReaderStringValue;
|
|
|
|
|
2012-11-17 19:54:16 +01:00
|
|
|
static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
|
|
|
|
static const WCHAR utf8W[] = {'U','T','F','-','8',0};
|
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
static const WCHAR dblquoteW[] = {'\"',0};
|
|
|
|
static const WCHAR quoteW[] = {'\'',0};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct xml_encoding_data xml_encoding_map[] = {
|
|
|
|
{ utf16W, XmlEncoding_UTF16, ~0 },
|
|
|
|
{ utf8W, XmlEncoding_UTF8, CP_UTF8 }
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *data;
|
2012-11-25 06:10:46 +01:00
|
|
|
char *cur;
|
2012-11-17 19:54:16 +01:00
|
|
|
unsigned int allocated;
|
|
|
|
unsigned int written;
|
|
|
|
} 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;
|
2010-01-21 16:19:20 +01:00
|
|
|
} xmlreaderinput;
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2013-01-06 21:55:36 +01:00
|
|
|
WCHAR *str;
|
2012-12-04 10:31:25 +01:00
|
|
|
UINT len;
|
|
|
|
} strval;
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
static WCHAR emptyW[] = {0};
|
|
|
|
static const strval strval_empty = {emptyW, 0};
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
struct attribute
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
strval localname;
|
|
|
|
strval value;
|
|
|
|
};
|
|
|
|
|
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;
|
2012-12-19 06:30:44 +01:00
|
|
|
XmlReaderInternalState instate;
|
2012-11-19 01:00:24 +01:00
|
|
|
XmlNodeType nodetype;
|
2012-11-17 20:22:09 +01:00
|
|
|
DtdProcessing dtdmode;
|
|
|
|
UINT line, pos; /* reader position in XML stream */
|
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;
|
2013-01-06 21:55:36 +01:00
|
|
|
strval strvalues[StringValue_Last];
|
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
|
|
|
static inline void *m_alloc(IMalloc *imalloc, size_t len)
|
2012-11-17 17:22:47 +01:00
|
|
|
{
|
2012-11-17 17:40:46 +01:00
|
|
|
if (imalloc)
|
|
|
|
return IMalloc_Alloc(imalloc, len);
|
2012-11-17 17:22:47 +01:00
|
|
|
else
|
|
|
|
return heap_alloc(len);
|
|
|
|
}
|
|
|
|
|
2012-11-19 00:01:46 +01:00
|
|
|
static inline void *m_realloc(IMalloc *imalloc, void *mem, size_t len)
|
|
|
|
{
|
|
|
|
if (imalloc)
|
|
|
|
return IMalloc_Realloc(imalloc, mem, len);
|
|
|
|
else
|
|
|
|
return heap_realloc(mem, len);
|
|
|
|
}
|
|
|
|
|
2012-11-17 17:40:46 +01:00
|
|
|
static inline void m_free(IMalloc *imalloc, void *mem)
|
2012-11-17 17:22:47 +01:00
|
|
|
{
|
2012-11-17 17:40:46 +01:00
|
|
|
if (imalloc)
|
|
|
|
IMalloc_Free(imalloc, mem);
|
2012-11-17 17:22:47 +01:00
|
|
|
else
|
|
|
|
heap_free(mem);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
size = (strlenW(str)+1)*sizeof(WCHAR);
|
|
|
|
ret = readerinput_alloc(input, size);
|
|
|
|
if (ret) memcpy(ret, str, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
reader_free(reader, attr);
|
|
|
|
}
|
|
|
|
list_init(&reader->attrs);
|
|
|
|
reader->attr_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute data holds pointers to buffer data, so buffer shrink is not possible
|
|
|
|
while we are on a node with attributes */
|
|
|
|
static HRESULT reader_add_attr(xmlreader *reader, strval *localname, strval *value)
|
|
|
|
{
|
|
|
|
struct attribute *attr;
|
|
|
|
|
|
|
|
attr = reader_alloc(reader, sizeof(*attr));
|
|
|
|
if (!attr) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
attr->localname = *localname;
|
|
|
|
attr->value = *value;
|
|
|
|
list_add_tail(&reader->attrs, &attr->entry);
|
|
|
|
reader->attr_count++;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
static void reader_free_strvalue(xmlreader *reader, XmlReaderStringValue type)
|
|
|
|
{
|
|
|
|
strval *v = &reader->strvalues[type];
|
|
|
|
|
|
|
|
if (v->str != strval_empty.str)
|
|
|
|
{
|
|
|
|
reader_free(reader, v->str);
|
|
|
|
*v = strval_empty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reader_free_strvalues(xmlreader *reader)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
for (type = 0; type < StringValue_Last; type++)
|
|
|
|
reader_free_strvalue(reader, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* always make a copy, cause strings are supposed to be null terminated */
|
|
|
|
static void reader_set_strvalue(xmlreader *reader, XmlReaderStringValue type, const strval *value)
|
|
|
|
{
|
|
|
|
strval *v = &reader->strvalues[type];
|
|
|
|
|
|
|
|
reader_free_strvalue(reader, type);
|
|
|
|
if (value->str == strval_empty.str)
|
|
|
|
*v = *value;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v->str = reader_alloc(reader, (value->len + 1)*sizeof(WCHAR));
|
|
|
|
memcpy(v->str, value->str, value->len*sizeof(WCHAR));
|
|
|
|
v->str[value->len] = 0;
|
|
|
|
v->len = value->len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2012-11-25 06:10:46 +01:00
|
|
|
buffer->cur = buffer->data;
|
2012-11-17 19:54:16 +01:00
|
|
|
buffer->allocated = initial_len;
|
|
|
|
buffer->written = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_encoded_buffer(xmlreaderinput *input, encoded_buffer *buffer)
|
|
|
|
{
|
|
|
|
readerinput_free(input, buffer->data);
|
|
|
|
}
|
|
|
|
|
2012-11-25 06:10:46 +01:00
|
|
|
static 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;
|
|
|
|
}
|
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
static 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;
|
|
|
|
max = sizeof(xml_encoding_map)/sizeof(struct xml_encoding_data) - 1;
|
|
|
|
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
n = (min+max)/2;
|
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
if (len != -1)
|
|
|
|
c = strncmpiW(xml_encoding_map[n].name, name, len);
|
|
|
|
else
|
|
|
|
c = strcmpiW(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 */
|
2012-11-19 00:01:46 +01:00
|
|
|
static 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = ISequentialStream_Read(readerinput->stream, buffer->data + buffer->written, len, &read);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
TRACE("requested %d, read %d, ret 0x%08x\n", len, read, hr);
|
|
|
|
buffer->written += read;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-11-25 06:10:46 +01:00
|
|
|
/* grows UTF-16 buffer so it has at least 'length' bytes free on return */
|
|
|
|
static void readerinput_grow(xmlreaderinput *readerinput, int length)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &readerinput->buffer->utf16;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT readerinput_detectencoding(xmlreaderinput *readerinput, xml_encoding *enc)
|
2012-11-19 00:01:46 +01:00
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &readerinput->buffer->encoded;
|
2013-01-05 23:08:27 +01:00
|
|
|
static char startA[] = {'<','?'};
|
2013-01-05 23:42:02 +01:00
|
|
|
static char commentA[] = {'<','!'};
|
2012-11-25 06:10:46 +01:00
|
|
|
static WCHAR startW[] = {'<','?'};
|
2013-01-05 23:42:02 +01:00
|
|
|
static WCHAR commentW[] = {'<','!'};
|
2012-11-25 06:10:46 +01:00
|
|
|
static char utf8bom[] = {0xef,0xbb,0xbf};
|
|
|
|
static char utf16lebom[] = {0xff,0xfe};
|
|
|
|
|
|
|
|
*enc = XmlEncoding_Unknown;
|
|
|
|
|
|
|
|
if (buffer->written <= 3) return MX_E_INPUTEND;
|
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-05 23:42:02 +01:00
|
|
|
if (!memcmp(buffer->data, startA, sizeof(startA)) ||
|
|
|
|
!memcmp(buffer->data, commentA, sizeof(commentA)))
|
2012-11-25 06:10:46 +01:00
|
|
|
*enc = XmlEncoding_UTF8;
|
2013-01-05 23:42:02 +01:00
|
|
|
else if (!memcmp(buffer->data, startW, sizeof(startW)) ||
|
|
|
|
!memcmp(buffer->data, commentW, sizeof(commentW)))
|
2012-11-25 06:10:46 +01:00
|
|
|
*enc = XmlEncoding_UTF16;
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2012-12-28 09:17:06 +01:00
|
|
|
TRACE("%d\n", len - (int)(buffer->cur - buffer->data));
|
2012-11-25 06:10:46 +01:00
|
|
|
return len - (buffer->cur - buffer->data);
|
|
|
|
}
|
|
|
|
|
2012-12-28 09:17:06 +01:00
|
|
|
/* It's possbile that raw buffer has some leftovers from last conversion - some char
|
|
|
|
sequence that doesn't represent a full code point. Length argument should be calculated with
|
|
|
|
readerinput_get_convlen(). */
|
|
|
|
static void readerinput_shrinkraw(xmlreaderinput *readerinput, int len)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &readerinput->buffer->encoded;
|
|
|
|
memmove(buffer->data, buffer->cur + (buffer->written - len), len);
|
|
|
|
/* everything lower cur is lost too */
|
|
|
|
buffer->written -= len + (buffer->cur - buffer->data);
|
|
|
|
/* after this point we don't need cur pointer really,
|
|
|
|
it's used only to mark where actual data begins when first chunk is read */
|
|
|
|
buffer->cur = buffer->data;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
HRESULT hr;
|
2012-12-19 06:30:44 +01:00
|
|
|
WCHAR *ptr;
|
2012-11-25 06:10:46 +01:00
|
|
|
UINT cp;
|
|
|
|
|
|
|
|
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);
|
|
|
|
memcpy(dest->data, src->cur, len);
|
2012-12-21 06:35:30 +01:00
|
|
|
dest->written += len*sizeof(WCHAR);
|
2012-11-25 06:10:46 +01:00
|
|
|
return;
|
2012-11-19 00:01:46 +01:00
|
|
|
}
|
|
|
|
|
2012-11-25 06:10:46 +01:00
|
|
|
dest_len = MultiByteToWideChar(cp, 0, src->cur, len, NULL, 0);
|
|
|
|
readerinput_grow(readerinput, dest_len);
|
2012-12-19 06:30:44 +01:00
|
|
|
ptr = (WCHAR*)dest->data;
|
|
|
|
MultiByteToWideChar(cp, 0, src->cur, len, ptr, dest_len);
|
|
|
|
ptr[dest_len] = 0;
|
2012-12-21 06:35:30 +01:00
|
|
|
dest->written += dest_len*sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
if (buffer->cur - buffer->data > buffer->written / 2)
|
|
|
|
{
|
|
|
|
buffer->written -= buffer->cur - buffer->data;
|
|
|
|
memmove(buffer->data, buffer->cur, buffer->written);
|
|
|
|
buffer->cur = buffer->data;
|
|
|
|
*(WCHAR*)&buffer->cur[buffer->written] = 0;
|
|
|
|
}
|
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 */
|
|
|
|
static void reader_more(xmlreader *reader)
|
|
|
|
{
|
|
|
|
xmlreaderinput *readerinput = reader->input;
|
|
|
|
encoded_buffer *src = &readerinput->buffer->encoded;
|
|
|
|
encoded_buffer *dest = &readerinput->buffer->utf16;
|
|
|
|
UINT cp = readerinput->buffer->code_page;
|
|
|
|
int len, dest_len;
|
|
|
|
WCHAR *ptr;
|
|
|
|
|
|
|
|
/* get some raw data from stream first */
|
|
|
|
readerinput_growraw(readerinput);
|
|
|
|
len = readerinput_get_convlen(readerinput);
|
|
|
|
|
|
|
|
/* just copy for UTF-16 case */
|
|
|
|
if (cp == ~0)
|
|
|
|
{
|
|
|
|
readerinput_grow(readerinput, len);
|
|
|
|
memcpy(dest->data, src->cur, len);
|
|
|
|
dest->written += len*sizeof(WCHAR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dest_len = MultiByteToWideChar(cp, 0, src->cur, len, NULL, 0);
|
|
|
|
readerinput_grow(readerinput, dest_len);
|
|
|
|
ptr = (WCHAR*)dest->data;
|
|
|
|
MultiByteToWideChar(cp, 0, 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);
|
|
|
|
}
|
|
|
|
|
2013-01-06 21:55:36 +01:00
|
|
|
static inline WCHAR *reader_get_cur(xmlreader *reader)
|
2012-11-26 03:59:49 +01:00
|
|
|
{
|
2012-12-28 09:17:06 +01:00
|
|
|
WCHAR *ptr = (WCHAR*)reader->input->buffer->utf16.cur;
|
|
|
|
if (!*ptr) reader_more(reader);
|
|
|
|
return ptr;
|
2012-11-26 03:59:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int reader_cmp(xmlreader *reader, const WCHAR *str)
|
|
|
|
{
|
|
|
|
const WCHAR *ptr = reader_get_cur(reader);
|
|
|
|
return strncmpW(str, ptr, strlenW(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* moves cursor n WCHARs forward */
|
|
|
|
static void reader_skipn(xmlreader *reader, int n)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &reader->input->buffer->utf16;
|
|
|
|
const WCHAR *ptr = reader_get_cur(reader);
|
|
|
|
|
|
|
|
while (*ptr++ && n--)
|
|
|
|
{
|
|
|
|
buffer->cur += sizeof(WCHAR);
|
|
|
|
reader->pos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
static inline int is_wchar_space(WCHAR ch)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
encoded_buffer *buffer = &reader->input->buffer->utf16;
|
|
|
|
const WCHAR *ptr = reader_get_cur(reader), *start = ptr;
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
while (is_wchar_space(*ptr))
|
2012-11-26 03:59:49 +01:00
|
|
|
{
|
|
|
|
buffer->cur += sizeof(WCHAR);
|
|
|
|
if (*ptr == '\r')
|
|
|
|
reader->pos = 0;
|
|
|
|
else if (*ptr == '\n')
|
|
|
|
{
|
|
|
|
reader->line++;
|
|
|
|
reader->pos = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
reader->pos++;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ptr - start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [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-01-06 21:55:36 +01:00
|
|
|
WCHAR *ptr, *ptr2, *start = reader_get_cur(reader);
|
2012-11-26 03:59:49 +01:00
|
|
|
static const WCHAR onedotW[] = {'1','.',0};
|
|
|
|
|
|
|
|
if (reader_cmp(reader, onedotW)) return WC_E_XMLDECL;
|
|
|
|
/* skip "1." */
|
|
|
|
reader_skipn(reader, 2);
|
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
ptr2 = ptr = reader_get_cur(reader);
|
2012-11-26 03:59:49 +01:00
|
|
|
while (*ptr >= '0' && *ptr <= '9')
|
|
|
|
ptr++;
|
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
if (ptr2 == ptr) return WC_E_DIGIT;
|
2012-11-28 13:59:57 +01:00
|
|
|
TRACE("version=%s\n", debugstr_wn(start, ptr-start));
|
2012-12-04 10:31:25 +01:00
|
|
|
val->str = start;
|
|
|
|
val->len = ptr-start;
|
2012-11-27 14:46:42 +01:00
|
|
|
reader_skipn(reader, ptr-ptr2);
|
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)
|
|
|
|
{
|
|
|
|
static const WCHAR eqW[] = {'=',0};
|
|
|
|
reader_skipspaces(reader);
|
|
|
|
if (reader_cmp(reader, eqW)) return WC_E_EQUAL;
|
|
|
|
/* skip '=' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
reader_skipspaces(reader);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-26 03:59:49 +01:00
|
|
|
/* [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"') */
|
|
|
|
static HRESULT reader_parse_versioninfo(xmlreader *reader)
|
|
|
|
{
|
|
|
|
static const WCHAR versionW[] = {'v','e','r','s','i','o','n',0};
|
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;
|
|
|
|
|
|
|
|
if (reader_cmp(reader, versionW)) return WC_E_XMLDECL;
|
2012-12-04 10:31:25 +01:00
|
|
|
name.str = reader_get_cur(reader);
|
|
|
|
name.len = 7;
|
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
|
|
|
|
|
|
|
if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW))
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW))
|
|
|
|
return WC_E_QUOTE;
|
|
|
|
|
|
|
|
/* skip "'"|'"' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
return reader_add_attr(reader, &name, &val);
|
2012-11-26 03:59:49 +01:00
|
|
|
}
|
|
|
|
|
2012-11-27 14:46:42 +01:00
|
|
|
/* ([A-Za-z0-9._] | '-') */
|
|
|
|
static inline int is_wchar_encname(WCHAR ch)
|
|
|
|
{
|
|
|
|
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-01-06 21:55:36 +01:00
|
|
|
WCHAR *start = reader_get_cur(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;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
static const WCHAR encodingW[] = {'e','n','c','o','d','i','n','g',0};
|
2012-12-04 10:31:25 +01:00
|
|
|
strval name, val;
|
2012-11-27 14:46:42 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!reader_skipspaces(reader)) return WC_E_WHITESPACE;
|
|
|
|
|
2012-11-28 13:59:57 +01:00
|
|
|
if (reader_cmp(reader, encodingW)) return S_FALSE;
|
2012-12-04 10:31:25 +01:00
|
|
|
name.str = reader_get_cur(reader);
|
|
|
|
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
|
|
|
|
|
|
|
if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW))
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW))
|
|
|
|
return WC_E_QUOTE;
|
|
|
|
|
|
|
|
/* skip "'"|'"' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
return reader_add_attr(reader, &name, &val);
|
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)
|
|
|
|
{
|
|
|
|
static const WCHAR standaloneW[] = {'s','t','a','n','d','a','l','o','n','e',0};
|
|
|
|
static const WCHAR yesW[] = {'y','e','s',0};
|
|
|
|
static const WCHAR noW[] = {'n','o',0};
|
2013-01-06 21:55:36 +01:00
|
|
|
WCHAR *start, *ptr;
|
2012-12-04 10:31:25 +01:00
|
|
|
strval name, val;
|
2012-11-28 15:44:06 +01:00
|
|
|
HRESULT hr;
|
2012-11-28 13:59:57 +01:00
|
|
|
|
|
|
|
if (!reader_skipspaces(reader)) return WC_E_WHITESPACE;
|
|
|
|
|
|
|
|
if (reader_cmp(reader, standaloneW)) return S_FALSE;
|
2012-12-04 10:31:25 +01:00
|
|
|
name.str = reader_get_cur(reader);
|
|
|
|
name.len = 10;
|
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
|
|
|
|
|
|
|
if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW))
|
|
|
|
return WC_E_QUOTE;
|
|
|
|
/* skip "'"|'"' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
|
|
|
if (reader_cmp(reader, yesW) && reader_cmp(reader, noW))
|
|
|
|
return WC_E_XMLDECL;
|
|
|
|
|
|
|
|
start = reader_get_cur(reader);
|
|
|
|
/* skip 'yes'|'no' */
|
|
|
|
reader_skipn(reader, reader_cmp(reader, yesW) ? 2 : 3);
|
|
|
|
ptr = reader_get_cur(reader);
|
|
|
|
TRACE("standalone=%s\n", debugstr_wn(start, ptr-start));
|
2012-12-04 10:31:25 +01:00
|
|
|
val.str = start;
|
|
|
|
val.len = ptr-start;
|
2012-11-28 13:59:57 +01:00
|
|
|
|
|
|
|
if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW))
|
|
|
|
return WC_E_QUOTE;
|
|
|
|
/* skip "'"|'"' */
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
return reader_add_attr(reader, &name, &val);
|
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)
|
|
|
|
{
|
2013-01-05 23:08:27 +01:00
|
|
|
static const WCHAR xmldeclW[] = {'<','?','x','m','l',' ',0};
|
2012-11-28 13:59:57 +01:00
|
|
|
static const WCHAR declcloseW[] = {'?','>',0};
|
2012-11-26 03:59:49 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-01-05 23:08:27 +01:00
|
|
|
/* check if we have "<?xml " */
|
2012-11-28 13:59:57 +01:00
|
|
|
if (reader_cmp(reader, xmldeclW)) return S_FALSE;
|
2012-11-26 03:59:49 +01:00
|
|
|
|
|
|
|
reader_skipn(reader, 5);
|
|
|
|
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);
|
|
|
|
if (reader_cmp(reader, declcloseW)) return WC_E_XMLDECL;
|
|
|
|
reader_skipn(reader, 2);
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
reader->nodetype = XmlNodeType_XmlDeclaration;
|
2013-01-08 12:44:27 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_LocalName, &strval_empty);
|
|
|
|
reader_set_strvalue(reader, StringValue_QualifiedName, &strval_empty);
|
|
|
|
reader_set_strvalue(reader, StringValue_Value, &strval_empty);
|
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-01-08 11:32:21 +01:00
|
|
|
WCHAR *start, *ptr;
|
2012-12-19 06:32:37 +01:00
|
|
|
|
|
|
|
/* skip '<!--' */
|
|
|
|
reader_skipn(reader, 4);
|
2012-12-21 06:35:30 +01:00
|
|
|
reader_shrink(reader);
|
2012-12-19 06:32:37 +01:00
|
|
|
ptr = start = reader_get_cur(reader);
|
|
|
|
|
|
|
|
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-01-08 11:32:21 +01:00
|
|
|
strval value = { start, ptr-start };
|
|
|
|
|
2012-12-28 09:17:06 +01:00
|
|
|
TRACE("%s\n", debugstr_wn(start, ptr-start));
|
|
|
|
/* skip '-->' */
|
|
|
|
reader_skipn(reader, 3);
|
2013-01-06 21:55:36 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_LocalName, &strval_empty);
|
|
|
|
reader_set_strvalue(reader, StringValue_QualifiedName, &strval_empty);
|
2013-01-08 11:32:21 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_Value, &value);
|
2012-12-28 09:17:06 +01:00
|
|
|
reader->nodetype = XmlNodeType_Comment;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return WC_E_COMMENT;
|
2012-12-19 06:32:37 +01:00
|
|
|
}
|
|
|
|
else
|
2012-12-28 09:17:06 +01:00
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
reader_more(reader);
|
|
|
|
}
|
2012-12-19 06:32:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
ptr = reader_get_cur(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return MX_E_INPUTEND;
|
2012-12-19 06:30:44 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 23:08:27 +01:00
|
|
|
static inline int is_namestartchar(WCHAR ch)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_namechar(WCHAR ch)
|
|
|
|
{
|
|
|
|
return (ch == ':') || (ch >= 'A' && ch <= 'Z') ||
|
|
|
|
(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [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-01-06 21:55:36 +01:00
|
|
|
WCHAR *ptr, *start = reader_get_cur(reader);
|
2013-01-05 23:08:27 +01:00
|
|
|
|
|
|
|
ptr = start;
|
|
|
|
if (!is_namestartchar(*ptr)) return WC_E_NAMECHARACTER;
|
|
|
|
|
|
|
|
while (is_namechar(*ptr))
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
ptr = reader_get_cur(reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("name %s:%d\n", debugstr_wn(start, ptr-start), (int)(ptr-start));
|
|
|
|
name->str = start;
|
|
|
|
name->len = ptr-start;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) */
|
|
|
|
static HRESULT reader_parse_pitarget(xmlreader *reader, strval *target)
|
|
|
|
{
|
|
|
|
static const WCHAR xmlW[] = {'x','m','l'};
|
|
|
|
strval name;
|
|
|
|
HRESULT hr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
hr = reader_parse_name(reader, &name);
|
|
|
|
if (FAILED(hr)) return WC_E_PI;
|
|
|
|
|
|
|
|
/* now that we got name check for illegal content */
|
|
|
|
if (name.len == 3 && !strncmpiW(name.str, xmlW, 3))
|
|
|
|
return WC_E_LEADINGXML;
|
|
|
|
|
|
|
|
/* PITarget can't be a qualified name */
|
|
|
|
for (i = 0; i < name.len; i++)
|
|
|
|
if (name.str[i] == ':')
|
|
|
|
return i ? NC_E_NAMECOLON : WC_E_PI;
|
|
|
|
|
|
|
|
TRACE("pitarget %s:%d\n", debugstr_wn(name.str, name.len), name.len);
|
|
|
|
*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-08 12:42:57 +01:00
|
|
|
WCHAR *ptr, *start;
|
2013-01-05 23:08:27 +01:00
|
|
|
strval target;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* skip '<?' */
|
|
|
|
reader_skipn(reader, 2);
|
|
|
|
reader_shrink(reader);
|
|
|
|
|
|
|
|
hr = reader_parse_pitarget(reader, &target);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
ptr = reader_get_cur(reader);
|
|
|
|
/* exit earlier if there's no content */
|
|
|
|
if (ptr[0] == '?' && ptr[1] == '>')
|
|
|
|
{
|
|
|
|
/* skip '?>' */
|
|
|
|
reader_skipn(reader, 2);
|
|
|
|
reader->nodetype = XmlNodeType_ProcessingInstruction;
|
2013-01-06 21:55:36 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_LocalName, &target);
|
|
|
|
reader_set_strvalue(reader, StringValue_QualifiedName, &target);
|
2013-01-08 12:42:57 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_Value, &strval_empty);
|
2013-01-05 23:08:27 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now at least a single space char should be there */
|
|
|
|
if (!is_wchar_space(*ptr)) return WC_E_WHITESPACE;
|
|
|
|
reader_skipspaces(reader);
|
|
|
|
|
|
|
|
ptr = start = reader_get_cur(reader);
|
|
|
|
|
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
if (ptr[0] == '?')
|
|
|
|
{
|
|
|
|
if (ptr[1] == '>')
|
|
|
|
{
|
2013-01-08 12:42:57 +01:00
|
|
|
strval value = { start, ptr-start };
|
|
|
|
|
2013-01-05 23:08:27 +01:00
|
|
|
TRACE("%s\n", debugstr_wn(start, ptr-start));
|
|
|
|
/* skip '?>' */
|
|
|
|
reader_skipn(reader, 2);
|
|
|
|
reader->nodetype = XmlNodeType_ProcessingInstruction;
|
2013-01-06 21:55:36 +01:00
|
|
|
reader_set_strvalue(reader, StringValue_LocalName, &target);
|
|
|
|
reader_set_strvalue(reader, StringValue_QualifiedName, &target);
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
reader_more(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader_skipn(reader, 1);
|
|
|
|
ptr = reader_get_cur(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
static const WCHAR commentW[] = {'<','!','-','-',0};
|
|
|
|
static const WCHAR piW[] = {'<','?',0};
|
|
|
|
const WCHAR *cur = reader_get_cur(reader);
|
|
|
|
|
|
|
|
if (is_wchar_space(*cur))
|
|
|
|
reader_skipspaces(reader);
|
|
|
|
else if (!reader_cmp(reader, commentW))
|
|
|
|
hr = reader_parse_comment(reader);
|
|
|
|
else if (!reader_cmp(reader, piW))
|
|
|
|
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-12 22:09:32 +01:00
|
|
|
/* [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>' */
|
|
|
|
static HRESULT reader_parse_dtd(xmlreader *reader)
|
|
|
|
{
|
|
|
|
static const WCHAR doctypeW[] = {'D','O','C','T','Y','P','E',0};
|
|
|
|
/* check if we have "<!DOCTYPE" */
|
|
|
|
if (reader_cmp(reader, doctypeW)) return S_FALSE;
|
|
|
|
FIXME("DTD parsing not implemented\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
static HRESULT reader_parse_nextnode(xmlreader *reader)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* try to detect encoding by BOM or data and set input code page */
|
|
|
|
hr = readerinput_detectencoding(reader->input, &enc);
|
|
|
|
TRACE("detected encoding %s, 0x%08x\n", debugstr_w(xml_encoding_map[enc].name), hr);
|
|
|
|
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;
|
|
|
|
|
|
|
|
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-12 22:09:32 +01:00
|
|
|
if (hr == S_FALSE) {
|
2012-12-19 06:30:44 +01:00
|
|
|
reader->instate = XmlReadInState_DTD;
|
2013-01-12 22:09:32 +01:00
|
|
|
continue;
|
2012-12-19 06:30:44 +01:00
|
|
|
}
|
2013-01-12 22:09:32 +01:00
|
|
|
else if (hr == S_OK) 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;
|
|
|
|
if (hr == S_FALSE) {
|
|
|
|
reader->instate = XmlReadInState_DTD_Misc;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (hr == S_OK) return hr;
|
|
|
|
break;
|
|
|
|
case XmlReadInState_DTD_Misc:
|
|
|
|
hr = reader_parse_misc(reader);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (hr == S_FALSE) {
|
|
|
|
reader->instate = XmlReadInState_Element;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (hr == S_OK) return hr;
|
|
|
|
break;
|
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);
|
|
|
|
|
|
|
|
TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_IXmlReader))
|
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2012-11-17 20:22:09 +01:00
|
|
|
if (This->input) IUnknown_Release(&This->input->IXmlReaderInput_iface);
|
2012-12-04 10:31:25 +01:00
|
|
|
reader_clear_attrs(This);
|
2013-01-06 21:55:36 +01:00
|
|
|
reader_free_strvalues(This);
|
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);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-01-25 19:55:02 +01:00
|
|
|
This->line = This->pos = 0;
|
|
|
|
|
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 */
|
|
|
|
hr = IUnknown_QueryInterface(input, &IID_IXmlReaderInput, (void**)&This->input);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
2012-11-17 20:22:09 +01:00
|
|
|
IXmlReaderInput *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,
|
2012-11-17 20:22:09 +01:00
|
|
|
NULL, 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);
|
|
|
|
|
|
|
|
TRACE("(%p %u %p)\n", This, property, value);
|
|
|
|
|
|
|
|
if (!value) return E_INVALIDARG;
|
|
|
|
|
|
|
|
switch (property)
|
|
|
|
{
|
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;
|
|
|
|
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);
|
|
|
|
|
|
|
|
TRACE("(%p %u %lu)\n", iface, property, value);
|
|
|
|
|
|
|
|
switch (property)
|
|
|
|
{
|
|
|
|
case XmlReaderProperty_DtdProcessing:
|
|
|
|
if (value < 0 || value > _DtdProcessing_Last) return E_INVALIDARG;
|
|
|
|
This->dtdmode = value;
|
|
|
|
break;
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
|
|
|
if (This->state == XmlReadState_Closed) return S_FALSE;
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
hr = reader_parse_nextnode(This);
|
|
|
|
if (oldtype == XmlNodeType_None && This->nodetype != oldtype)
|
|
|
|
This->state = XmlReadState_Interactive;
|
|
|
|
if (hr == S_OK) *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);
|
|
|
|
TRACE("(%p)->(%p)\n", This, node_type);
|
2012-12-06 13:18:28 +01:00
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
*node_type = This->attr ? XmlNodeType_Attribute : This->nodetype;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!This->attr_count) return S_FALSE;
|
|
|
|
This->attr = LIST_ENTRY(list_head(&This->attrs), struct attribute, entry);
|
|
|
|
return S_OK;
|
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)
|
|
|
|
return IXmlReader_MoveToFirstAttribute(iface);
|
|
|
|
|
|
|
|
next = list_next(&This->attrs, &This->attr->entry);
|
|
|
|
if (next)
|
|
|
|
This->attr = LIST_ENTRY(next, struct attribute, entry);
|
|
|
|
|
|
|
|
return next ? S_OK : S_FALSE;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_MoveToAttributeByName(IXmlReader* iface,
|
|
|
|
LPCWSTR local_name,
|
|
|
|
LPCWSTR namespaceUri)
|
|
|
|
{
|
|
|
|
FIXME("(%p %p %p): stub\n", iface, local_name, namespaceUri);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
This->attr = NULL;
|
|
|
|
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);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, name, len);
|
|
|
|
*name = This->strvalues[StringValue_QualifiedName].str;
|
|
|
|
*len = This->strvalues[StringValue_QualifiedName].len;
|
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_GetNamespaceUri(IXmlReader* iface,
|
|
|
|
LPCWSTR *namespaceUri,
|
|
|
|
UINT *namespaceUri_length)
|
2010-01-18 22:05:53 +01:00
|
|
|
{
|
2010-01-18 22:18:22 +01:00
|
|
|
FIXME("(%p %p %p): stub\n", iface, namespaceUri, namespaceUri_length);
|
2010-01-18 22:05:53 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, name, len);
|
|
|
|
*name = This->strvalues[StringValue_LocalName].str;
|
|
|
|
*len = This->strvalues[StringValue_LocalName].len;
|
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_GetPrefix(IXmlReader* iface,
|
|
|
|
LPCWSTR *prefix,
|
|
|
|
UINT *prefix_length)
|
|
|
|
{
|
|
|
|
FIXME("(%p %p %p): stub\n", iface, prefix, prefix_length);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-01-08 11:32:21 +01:00
|
|
|
static HRESULT WINAPI xmlreader_GetValue(IXmlReader* iface, LPCWSTR *value, UINT *len)
|
2010-01-18 22:18:22 +01:00
|
|
|
{
|
2013-01-08 11:32:21 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, value, len);
|
|
|
|
*value = This->strvalues[StringValue_Value].str;
|
|
|
|
if (len) *len = This->strvalues[StringValue_Value].len;
|
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_ReadValueChunk(IXmlReader* iface,
|
|
|
|
WCHAR *buffer,
|
|
|
|
UINT chunk_size,
|
|
|
|
UINT *read)
|
|
|
|
{
|
|
|
|
FIXME("(%p %p %u %p): stub\n", iface, buffer, chunk_size, read);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI xmlreader_IsEmptyElement(IXmlReader* iface)
|
|
|
|
{
|
|
|
|
FIXME("(%p): stub\n", iface);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_GetLineNumber(IXmlReader* iface, UINT *lineNumber)
|
|
|
|
{
|
2010-01-25 19:55:02 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
|
|
|
|
TRACE("(%p %p)\n", This, lineNumber);
|
|
|
|
|
|
|
|
if (!lineNumber) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*lineNumber = This->line;
|
|
|
|
|
|
|
|
return S_OK;
|
2010-01-18 22:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlreader_GetLinePosition(IXmlReader* iface, UINT *linePosition)
|
|
|
|
{
|
2010-01-25 19:55:02 +01:00
|
|
|
xmlreader *This = impl_from_IXmlReader(iface);
|
|
|
|
|
|
|
|
TRACE("(%p %p)\n", This, linePosition);
|
|
|
|
|
|
|
|
if (!linePosition) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*linePosition = This->pos;
|
|
|
|
|
|
|
|
return 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)
|
|
|
|
{
|
|
|
|
FIXME("(%p %p): stub\n", iface, depth);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI xmlreader_IsEOF(IXmlReader* iface)
|
|
|
|
{
|
|
|
|
FIXME("(%p): stub\n", iface);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
|
|
|
|
|
|
|
|
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));
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IUnknownVtbl xmlreaderinput_vtbl =
|
|
|
|
{
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
if (!IsEqualGUID(riid, &IID_IXmlReader))
|
|
|
|
{
|
|
|
|
ERR("Unexpected IID requested -> (%s)\n", wine_dbgstr_guid(riid));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-11-17 17:22:47 +01:00
|
|
|
if (imalloc)
|
|
|
|
reader = IMalloc_Alloc(imalloc, sizeof(*reader));
|
|
|
|
else
|
|
|
|
reader = heap_alloc(sizeof(*reader));
|
2010-01-18 22:18:22 +01:00
|
|
|
if(!reader) return E_OUTOFMEMORY;
|
|
|
|
|
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-21 19:05:25 +01:00
|
|
|
reader->input = NULL;
|
2010-01-23 21:03:14 +01:00
|
|
|
reader->state = XmlReadState_Closed;
|
2012-12-19 06:30:44 +01:00
|
|
|
reader->instate = XmlReadInState_Initial;
|
2012-08-29 06:12:01 +02:00
|
|
|
reader->dtdmode = DtdProcessing_Prohibit;
|
2010-01-25 19:55:02 +01:00
|
|
|
reader->line = reader->pos = 0;
|
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);
|
|
|
|
reader->attr_count = 0;
|
2012-12-06 13:05:19 +01:00
|
|
|
reader->attr = NULL;
|
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
|
|
|
|
2012-11-17 17:22:47 +01:00
|
|
|
*obj = &reader->IXmlReader_iface;
|
2010-01-18 22:18:22 +01:00
|
|
|
|
2012-11-17 17:22:47 +01:00
|
|
|
TRACE("returning iface %p\n", *obj);
|
2010-01-18 22:18:22 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
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;
|
|
|
|
|
2011-03-24 13:53:43 +01:00
|
|
|
readerinput->IXmlReaderInput_iface.lpVtbl = &xmlreaderinput_vtbl;
|
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);
|
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)
|
|
|
|
{
|
|
|
|
readerinput_free(readerinput, readerinput);
|
|
|
|
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
|
|
|
}
|