2011-04-30 09:42:29 +02:00
|
|
|
/*
|
|
|
|
* MXWriter implementation
|
|
|
|
*
|
2012-03-08 09:57:48 +01:00
|
|
|
* Copyright 2011-2012 Nikolay Sivov for CodeWeavers
|
2011-08-13 01:11:08 +02:00
|
|
|
* Copyright 2011 Thomas Mullaly
|
2011-04-30 09:42:29 +02: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 "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
# include <libxml/parser.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
|
|
|
|
#include "msxml6.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "msxml_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msxml);
|
|
|
|
|
2011-08-13 01:11:08 +02:00
|
|
|
static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
|
2011-08-27 12:19:22 +02:00
|
|
|
static const WCHAR emptyW[] = {0};
|
2012-01-27 14:09:42 +01:00
|
|
|
static const WCHAR spaceW[] = {' '};
|
|
|
|
static const WCHAR quotW[] = {'\"'};
|
2011-05-01 18:05:31 +02:00
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
XmlEncoding_UTF8,
|
|
|
|
XmlEncoding_UTF16,
|
|
|
|
XmlEncoding_Unknown
|
|
|
|
} xml_encoding;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
OutputBuffer_Native = 0x001,
|
|
|
|
OutputBuffer_Encoded = 0x010,
|
|
|
|
OutputBuffer_Both = 0x100
|
|
|
|
} output_mode;
|
|
|
|
|
2011-05-04 08:59:32 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
2011-05-07 19:57:45 +02:00
|
|
|
MXWriter_BOM = 0,
|
2011-05-07 20:15:33 +02:00
|
|
|
MXWriter_DisableEscaping,
|
2011-05-07 19:57:45 +02:00
|
|
|
MXWriter_Indent,
|
2011-05-07 18:53:33 +02:00
|
|
|
MXWriter_OmitXmlDecl,
|
2011-05-04 09:10:34 +02:00
|
|
|
MXWriter_Standalone,
|
2011-05-04 08:59:32 +02:00
|
|
|
MXWriter_LastProp
|
2011-12-16 00:36:53 +01:00
|
|
|
} mxwriter_prop;
|
2011-05-04 08:59:32 +02:00
|
|
|
|
2012-02-24 21:20:48 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
EscapeValue,
|
|
|
|
EscapeText
|
|
|
|
} escape_mode;
|
|
|
|
|
2011-12-15 14:03:21 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *data;
|
|
|
|
unsigned int allocated;
|
|
|
|
unsigned int written;
|
|
|
|
} encoded_buffer;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
encoded_buffer utf16;
|
|
|
|
encoded_buffer encoded;
|
|
|
|
UINT code_page;
|
|
|
|
} output_buffer;
|
|
|
|
|
2011-12-11 00:32:51 +01:00
|
|
|
typedef struct
|
2011-04-30 09:42:29 +02:00
|
|
|
{
|
2011-12-05 09:07:26 +01:00
|
|
|
DispatchEx dispex;
|
2011-04-30 09:42:29 +02:00
|
|
|
IMXWriter IMXWriter_iface;
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler ISAXContentHandler_iface;
|
2012-01-27 12:45:21 +01:00
|
|
|
ISAXLexicalHandler ISAXLexicalHandler_iface;
|
2012-03-08 09:57:48 +01:00
|
|
|
ISAXDeclHandler ISAXDeclHandler_iface;
|
2011-04-30 13:18:03 +02:00
|
|
|
|
2011-04-30 09:42:29 +02:00
|
|
|
LONG ref;
|
2011-08-24 14:06:58 +02:00
|
|
|
MSXML_VERSION class_version;
|
2011-04-30 13:36:37 +02:00
|
|
|
|
2011-05-04 08:59:32 +02:00
|
|
|
VARIANT_BOOL props[MXWriter_LastProp];
|
2011-08-13 01:11:08 +02:00
|
|
|
BOOL prop_changed;
|
2012-02-24 21:20:48 +01:00
|
|
|
BOOL cdata;
|
2011-12-16 00:36:53 +01:00
|
|
|
|
2011-05-01 18:05:31 +02:00
|
|
|
BSTR version;
|
2011-05-01 10:04:59 +02:00
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
BSTR encoding; /* exact property value */
|
|
|
|
xml_encoding xml_enc;
|
|
|
|
|
2011-08-27 12:19:22 +02:00
|
|
|
/* contains a pending (or not closed yet) element name or NULL if
|
|
|
|
we don't have to close */
|
|
|
|
BSTR element;
|
|
|
|
|
2011-05-01 10:04:59 +02:00
|
|
|
IStream *dest;
|
2011-12-15 14:03:21 +01:00
|
|
|
ULONG dest_written;
|
2011-12-09 16:24:46 +01:00
|
|
|
|
2011-12-15 14:03:21 +01:00
|
|
|
output_buffer *buffer;
|
2011-04-30 09:42:29 +02:00
|
|
|
} mxwriter;
|
|
|
|
|
2012-03-13 08:59:53 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BSTR qname;
|
|
|
|
BSTR local;
|
|
|
|
BSTR uri;
|
|
|
|
BSTR type;
|
|
|
|
BSTR value;
|
|
|
|
} mxattribute;
|
|
|
|
|
2012-03-08 21:11:45 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
DispatchEx dispex;
|
|
|
|
IMXAttributes IMXAttributes_iface;
|
2012-03-09 09:55:03 +01:00
|
|
|
ISAXAttributes ISAXAttributes_iface;
|
2012-03-08 21:11:45 +01:00
|
|
|
LONG ref;
|
2012-03-13 08:59:53 +01:00
|
|
|
|
|
|
|
MSXML_VERSION class_version;
|
|
|
|
|
|
|
|
mxattribute *attr;
|
|
|
|
int length;
|
|
|
|
int allocated;
|
2012-03-08 21:11:45 +01:00
|
|
|
} mxattributes;
|
|
|
|
|
|
|
|
static inline mxattributes *impl_from_IMXAttributes( IMXAttributes *iface )
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, mxattributes, IMXAttributes_iface);
|
|
|
|
}
|
|
|
|
|
2012-03-09 09:55:03 +01:00
|
|
|
static inline mxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface )
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, mxattributes, ISAXAttributes_iface);
|
|
|
|
}
|
|
|
|
|
2012-03-13 08:59:53 +01:00
|
|
|
static HRESULT mxattributes_grow(mxattributes *This)
|
|
|
|
{
|
|
|
|
if (This->length < This->allocated) return S_OK;
|
|
|
|
|
|
|
|
This->allocated *= 2;
|
|
|
|
This->attr = heap_realloc(This->attr, This->allocated*sizeof(mxattribute));
|
|
|
|
|
|
|
|
return This->attr ? S_OK : E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
static xml_encoding parse_encoding_name(const WCHAR *encoding)
|
2011-12-15 14:03:21 +01:00
|
|
|
{
|
2011-12-16 00:36:53 +01:00
|
|
|
static const WCHAR utf8W[] = {'U','T','F','-','8',0};
|
|
|
|
if (!strcmpiW(encoding, utf8W)) return XmlEncoding_UTF8;
|
|
|
|
if (!strcmpiW(encoding, utf16W)) return XmlEncoding_UTF16;
|
|
|
|
return XmlEncoding_Unknown;
|
2011-12-15 14:03:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT init_encoded_buffer(encoded_buffer *buffer)
|
|
|
|
{
|
|
|
|
const int initial_len = 0x2000;
|
|
|
|
buffer->data = heap_alloc(initial_len);
|
|
|
|
if (!buffer->data) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
memset(buffer->data, 0, 4);
|
|
|
|
buffer->allocated = initial_len;
|
|
|
|
buffer->written = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_encoded_buffer(encoded_buffer *buffer)
|
|
|
|
{
|
|
|
|
heap_free(buffer->data);
|
|
|
|
}
|
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
static HRESULT get_code_page(xml_encoding encoding, UINT *cp)
|
2011-12-15 14:03:21 +01:00
|
|
|
{
|
|
|
|
switch (encoding)
|
|
|
|
{
|
2011-12-16 00:36:53 +01:00
|
|
|
case XmlEncoding_UTF8:
|
2011-12-15 14:03:21 +01:00
|
|
|
*cp = CP_UTF8;
|
|
|
|
break;
|
2011-12-16 00:36:53 +01:00
|
|
|
case XmlEncoding_UTF16:
|
2011-12-15 14:03:21 +01:00
|
|
|
*cp = ~0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unsupported encoding %d\n", encoding);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
static HRESULT alloc_output_buffer(xml_encoding encoding, output_buffer **buffer)
|
2011-12-15 14:03:21 +01:00
|
|
|
{
|
|
|
|
output_buffer *ret;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
ret = heap_alloc(sizeof(*ret));
|
|
|
|
if (!ret) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = get_code_page(encoding, &ret->code_page);
|
|
|
|
if (hr != S_OK) {
|
|
|
|
heap_free(ret);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = init_encoded_buffer(&ret->utf16);
|
|
|
|
if (hr != S_OK) {
|
|
|
|
heap_free(ret);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret->code_page == CP_UTF8) {
|
|
|
|
hr = init_encoded_buffer(&ret->encoded);
|
|
|
|
if (hr != S_OK) {
|
|
|
|
free_encoded_buffer(&ret->utf16);
|
|
|
|
heap_free(ret);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
memset(&ret->encoded, 0, sizeof(ret->encoded));
|
|
|
|
|
|
|
|
*buffer = ret;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_output_buffer(output_buffer *buffer)
|
|
|
|
{
|
|
|
|
free_encoded_buffer(&buffer->encoded);
|
|
|
|
free_encoded_buffer(&buffer->utf16);
|
|
|
|
heap_free(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void grow_buffer(encoded_buffer *buffer, int length)
|
|
|
|
{
|
|
|
|
/* 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 = heap_realloc(buffer->data, grown_size);
|
|
|
|
buffer->allocated = grown_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_output_buffer_mode(output_buffer *buffer, output_mode mode, const WCHAR *data, int len)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
if (mode & (OutputBuffer_Encoded | OutputBuffer_Both)) {
|
|
|
|
if (buffer->code_page == CP_UTF8)
|
|
|
|
{
|
|
|
|
length = WideCharToMultiByte(buffer->code_page, 0, data, len, NULL, 0, NULL, NULL);
|
|
|
|
grow_buffer(&buffer->encoded, length);
|
|
|
|
ptr = buffer->encoded.data + buffer->encoded.written;
|
|
|
|
length = WideCharToMultiByte(buffer->code_page, 0, data, len, ptr, length, NULL, NULL);
|
|
|
|
buffer->encoded.written += len == -1 ? length-1 : length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode & (OutputBuffer_Native | OutputBuffer_Both)) {
|
|
|
|
/* WCHAR data just copied */
|
|
|
|
length = len == -1 ? strlenW(data) : len;
|
|
|
|
if (length)
|
|
|
|
{
|
|
|
|
length *= sizeof(WCHAR);
|
|
|
|
|
|
|
|
grow_buffer(&buffer->utf16, length);
|
|
|
|
ptr = buffer->utf16.data + buffer->utf16.written;
|
|
|
|
|
|
|
|
memcpy(ptr, data, length);
|
|
|
|
buffer->utf16.written += length;
|
|
|
|
ptr += length;
|
|
|
|
/* null termination */
|
|
|
|
memset(ptr, 0, sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_output_buffer(output_buffer *buffer, const WCHAR *data, int len)
|
|
|
|
{
|
|
|
|
return write_output_buffer_mode(buffer, OutputBuffer_Both, data, len);
|
|
|
|
}
|
|
|
|
|
2012-01-27 14:23:56 +01:00
|
|
|
static HRESULT write_output_buffer_quoted(output_buffer *buffer, const WCHAR *data, int len)
|
|
|
|
{
|
|
|
|
write_output_buffer(buffer, quotW, 1);
|
|
|
|
write_output_buffer(buffer, data, len);
|
|
|
|
write_output_buffer(buffer, quotW, 1);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-15 14:03:21 +01:00
|
|
|
/* frees buffer data, reallocates with a default lengths */
|
|
|
|
static void close_output_buffer(mxwriter *This)
|
|
|
|
{
|
|
|
|
heap_free(This->buffer->utf16.data);
|
|
|
|
heap_free(This->buffer->encoded.data);
|
|
|
|
init_encoded_buffer(&This->buffer->utf16);
|
|
|
|
init_encoded_buffer(&This->buffer->encoded);
|
2011-12-16 00:36:53 +01:00
|
|
|
get_code_page(This->xml_enc, &This->buffer->code_page);
|
2011-08-13 01:11:08 +02:00
|
|
|
}
|
|
|
|
|
2011-12-11 00:32:51 +01:00
|
|
|
/* escapes special characters like:
|
|
|
|
'<' -> "<"
|
|
|
|
'&' -> "&"
|
|
|
|
'"' -> """
|
|
|
|
'>' -> ">"
|
|
|
|
*/
|
2012-02-24 21:20:48 +01:00
|
|
|
static WCHAR *get_escaped_string(const WCHAR *str, escape_mode mode, int *len)
|
2011-12-11 00:32:51 +01:00
|
|
|
{
|
2012-01-27 14:09:42 +01:00
|
|
|
static const WCHAR ltW[] = {'&','l','t',';'};
|
|
|
|
static const WCHAR ampW[] = {'&','a','m','p',';'};
|
|
|
|
static const WCHAR equotW[] = {'&','q','u','o','t',';'};
|
|
|
|
static const WCHAR gtW[] = {'&','g','t',';'};
|
2011-12-11 00:32:51 +01:00
|
|
|
|
|
|
|
const int default_alloc = 100;
|
|
|
|
const int grow_thresh = 10;
|
|
|
|
int p = *len, conv_len;
|
|
|
|
WCHAR *ptr, *ret;
|
|
|
|
|
|
|
|
/* default buffer size to something if length is unknown */
|
|
|
|
conv_len = *len == -1 ? default_alloc : max(2**len, default_alloc);
|
|
|
|
ptr = ret = heap_alloc(conv_len*sizeof(WCHAR));
|
|
|
|
|
|
|
|
while (*str && p)
|
|
|
|
{
|
|
|
|
if (ptr - ret > conv_len - grow_thresh)
|
|
|
|
{
|
|
|
|
int written = ptr - ret;
|
|
|
|
conv_len *= 2;
|
|
|
|
ptr = ret = heap_realloc(ret, conv_len*sizeof(WCHAR));
|
|
|
|
ptr += written;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (*str)
|
|
|
|
{
|
|
|
|
case '<':
|
|
|
|
memcpy(ptr, ltW, sizeof(ltW));
|
|
|
|
ptr += sizeof(ltW)/sizeof(WCHAR);
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
memcpy(ptr, ampW, sizeof(ampW));
|
|
|
|
ptr += sizeof(ampW)/sizeof(WCHAR);
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
memcpy(ptr, gtW, sizeof(gtW));
|
|
|
|
ptr += sizeof(gtW)/sizeof(WCHAR);
|
|
|
|
break;
|
2012-02-24 21:20:48 +01:00
|
|
|
case '"':
|
|
|
|
if (mode == EscapeValue)
|
|
|
|
{
|
|
|
|
memcpy(ptr, equotW, sizeof(equotW));
|
|
|
|
ptr += sizeof(equotW)/sizeof(WCHAR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fallthrough for text mode */
|
2011-12-11 00:32:51 +01:00
|
|
|
default:
|
|
|
|
*ptr++ = *str;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
str++;
|
|
|
|
if (*len != -1) p--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*len != -1) *len = ptr-ret;
|
|
|
|
*++ptr = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-15 14:03:21 +01:00
|
|
|
static void write_prolog_buffer(const mxwriter *This)
|
2011-12-09 16:24:46 +01:00
|
|
|
{
|
2012-01-27 14:23:56 +01:00
|
|
|
static const WCHAR versionW[] = {'<','?','x','m','l',' ','v','e','r','s','i','o','n','='};
|
2011-12-15 14:03:21 +01:00
|
|
|
static const WCHAR encodingW[] = {' ','e','n','c','o','d','i','n','g','=','\"'};
|
|
|
|
static const WCHAR standaloneW[] = {' ','s','t','a','n','d','a','l','o','n','e','=','\"'};
|
|
|
|
static const WCHAR yesW[] = {'y','e','s','\"','?','>'};
|
|
|
|
static const WCHAR noW[] = {'n','o','\"','?','>'};
|
|
|
|
static const WCHAR crlfW[] = {'\r','\n'};
|
2011-12-09 16:24:46 +01:00
|
|
|
|
|
|
|
/* version */
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, versionW, sizeof(versionW)/sizeof(WCHAR));
|
2012-01-27 14:23:56 +01:00
|
|
|
write_output_buffer_quoted(This->buffer, This->version, -1);
|
2011-12-09 16:24:46 +01:00
|
|
|
|
|
|
|
/* encoding */
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, encodingW, sizeof(encodingW)/sizeof(WCHAR));
|
|
|
|
|
|
|
|
/* always write UTF-16 to WCHAR buffer */
|
|
|
|
write_output_buffer_mode(This->buffer, OutputBuffer_Native, utf16W, sizeof(utf16W)/sizeof(WCHAR) - 1);
|
2011-12-16 00:36:53 +01:00
|
|
|
write_output_buffer_mode(This->buffer, OutputBuffer_Encoded, This->encoding, -1);
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, quotW, 1);
|
2011-12-09 16:24:46 +01:00
|
|
|
|
|
|
|
/* standalone */
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, standaloneW, sizeof(standaloneW)/sizeof(WCHAR));
|
2011-12-09 16:24:46 +01:00
|
|
|
if (This->props[MXWriter_Standalone] == VARIANT_TRUE)
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, yesW, sizeof(yesW)/sizeof(WCHAR));
|
2011-12-09 16:24:46 +01:00
|
|
|
else
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, noW, sizeof(noW)/sizeof(WCHAR));
|
2011-12-09 16:24:46 +01:00
|
|
|
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, crlfW, sizeof(crlfW)/sizeof(WCHAR));
|
2011-12-09 16:24:46 +01:00
|
|
|
}
|
|
|
|
|
2011-08-13 01:11:08 +02:00
|
|
|
/* Attempts to the write data from the mxwriter's buffer to
|
|
|
|
* the destination stream (if there is one).
|
|
|
|
*/
|
|
|
|
static HRESULT write_data_to_stream(mxwriter *This)
|
|
|
|
{
|
2011-12-15 14:03:21 +01:00
|
|
|
encoded_buffer *buffer;
|
2011-08-13 01:11:08 +02:00
|
|
|
ULONG written = 0;
|
2011-12-09 16:24:46 +01:00
|
|
|
HRESULT hr;
|
2011-08-13 01:11:08 +02:00
|
|
|
|
|
|
|
if (!This->dest)
|
|
|
|
return S_OK;
|
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
if (This->xml_enc != XmlEncoding_UTF16)
|
2011-12-15 14:03:21 +01:00
|
|
|
buffer = &This->buffer->encoded;
|
2011-08-13 01:11:08 +02:00
|
|
|
else
|
2011-12-15 14:03:21 +01:00
|
|
|
buffer = &This->buffer->utf16;
|
2011-08-13 01:11:08 +02:00
|
|
|
|
2011-12-15 14:03:21 +01:00
|
|
|
if (This->dest_written > buffer->written) {
|
|
|
|
ERR("Failed sanity check! Not sure what to do... (%d > %d)\n", This->dest_written, buffer->written);
|
2011-08-13 01:11:08 +02:00
|
|
|
return E_FAIL;
|
2011-12-16 00:36:53 +01:00
|
|
|
} else if (This->dest_written == buffer->written && This->xml_enc != XmlEncoding_UTF8)
|
2011-08-13 01:11:08 +02:00
|
|
|
/* Windows seems to make an empty write call when the encoding is UTF-8 and
|
|
|
|
* all the data has been written to the stream. It doesn't seem make this call
|
|
|
|
* for any other encodings.
|
|
|
|
*/
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
/* Write the current content from the output buffer into 'dest'.
|
|
|
|
* TODO: Check what Windows does if the IStream doesn't write all of
|
|
|
|
* the data we give it at once.
|
|
|
|
*/
|
2011-12-15 14:03:21 +01:00
|
|
|
hr = IStream_Write(This->dest, buffer->data+This->dest_written,
|
|
|
|
buffer->written-This->dest_written, &written);
|
2011-12-09 16:24:46 +01:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
WARN("Failed to write data to IStream (0x%08x)\n", hr);
|
|
|
|
return hr;
|
2011-08-13 01:11:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
This->dest_written += written;
|
2011-12-09 16:24:46 +01:00
|
|
|
return hr;
|
2011-08-13 01:11:08 +02:00
|
|
|
}
|
|
|
|
|
2011-08-27 12:19:22 +02:00
|
|
|
/* Newly added element start tag left unclosed cause for empty elements
|
|
|
|
we have to close it differently. */
|
|
|
|
static void close_element_starttag(const mxwriter *This)
|
|
|
|
{
|
2011-12-15 14:03:21 +01:00
|
|
|
static const WCHAR gtW[] = {'>'};
|
2011-08-27 12:19:22 +02:00
|
|
|
if (!This->element) return;
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, gtW, 1);
|
2011-08-27 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2011-08-27 15:35:13 +02:00
|
|
|
static void set_element_name(mxwriter *This, const WCHAR *name, int len)
|
2011-08-27 12:19:22 +02:00
|
|
|
{
|
|
|
|
SysFreeString(This->element);
|
2011-08-27 15:35:13 +02:00
|
|
|
This->element = name ? SysAllocStringLen(name, len) : NULL;
|
2011-08-27 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2011-08-13 01:11:08 +02:00
|
|
|
static inline HRESULT flush_output_buffer(mxwriter *This)
|
|
|
|
{
|
2011-08-27 12:19:22 +02:00
|
|
|
close_element_starttag(This);
|
2011-08-27 15:35:13 +02:00
|
|
|
set_element_name(This, NULL, 0);
|
2012-02-24 21:20:48 +01:00
|
|
|
This->cdata = FALSE;
|
2011-08-13 01:11:08 +02:00
|
|
|
return write_data_to_stream(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resets the mxwriter's output buffer by closing it, then creating a new
|
|
|
|
* output buffer using the given encoding.
|
|
|
|
*/
|
|
|
|
static inline void reset_output_buffer(mxwriter *This)
|
|
|
|
{
|
2011-12-15 14:03:21 +01:00
|
|
|
close_output_buffer(This);
|
2011-08-13 01:11:08 +02:00
|
|
|
This->dest_written = 0;
|
|
|
|
}
|
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
static HRESULT writer_set_property(mxwriter *writer, mxwriter_prop property, VARIANT_BOOL value)
|
2011-10-06 17:22:00 +02:00
|
|
|
{
|
|
|
|
writer->props[property] = value;
|
|
|
|
writer->prop_changed = TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
static HRESULT writer_get_property(const mxwriter *writer, mxwriter_prop property, VARIANT_BOOL *value)
|
2011-10-06 17:35:07 +02:00
|
|
|
{
|
|
|
|
if (!value) return E_POINTER;
|
|
|
|
*value = writer->props[property];
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-30 09:42:29 +02:00
|
|
|
static inline mxwriter *impl_from_IMXWriter(IMXWriter *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, mxwriter, IMXWriter_iface);
|
|
|
|
}
|
|
|
|
|
2011-04-30 13:18:03 +02:00
|
|
|
static inline mxwriter *impl_from_ISAXContentHandler(ISAXContentHandler *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, mxwriter, ISAXContentHandler_iface);
|
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static inline mxwriter *impl_from_ISAXLexicalHandler(ISAXLexicalHandler *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, mxwriter, ISAXLexicalHandler_iface);
|
|
|
|
}
|
|
|
|
|
2012-03-08 09:57:48 +01:00
|
|
|
static inline mxwriter *impl_from_ISAXDeclHandler(ISAXDeclHandler *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, mxwriter, ISAXDeclHandler_iface);
|
|
|
|
}
|
|
|
|
|
2011-04-30 09:42:29 +02:00
|
|
|
static HRESULT WINAPI mxwriter_QueryInterface(IMXWriter *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
2011-12-05 09:07:26 +01:00
|
|
|
*obj = NULL;
|
|
|
|
|
2011-04-30 09:42:29 +02:00
|
|
|
if ( IsEqualGUID( riid, &IID_IMXWriter ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IDispatch ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IUnknown ) )
|
|
|
|
{
|
|
|
|
*obj = &This->IMXWriter_iface;
|
|
|
|
}
|
2011-04-30 13:18:03 +02:00
|
|
|
else if ( IsEqualGUID( riid, &IID_ISAXContentHandler ) )
|
|
|
|
{
|
|
|
|
*obj = &This->ISAXContentHandler_iface;
|
|
|
|
}
|
2012-01-27 12:45:21 +01:00
|
|
|
else if ( IsEqualGUID( riid, &IID_ISAXLexicalHandler ) )
|
|
|
|
{
|
|
|
|
*obj = &This->ISAXLexicalHandler_iface;
|
|
|
|
}
|
2012-03-08 09:57:48 +01:00
|
|
|
else if ( IsEqualGUID( riid, &IID_ISAXDeclHandler ) )
|
|
|
|
{
|
|
|
|
*obj = &This->ISAXDeclHandler_iface;
|
|
|
|
}
|
2011-12-05 09:07:26 +01:00
|
|
|
else if (dispex_query_interface(&This->dispex, riid, obj))
|
|
|
|
{
|
|
|
|
return *obj ? S_OK : E_NOINTERFACE;
|
|
|
|
}
|
2011-04-30 09:42:29 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("interface %s not implemented\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMXWriter_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI mxwriter_AddRef(IMXWriter *iface)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI mxwriter_Release(IMXWriter *iface)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
|
|
|
if(!ref)
|
2011-05-01 10:04:59 +02:00
|
|
|
{
|
2011-08-13 01:11:08 +02:00
|
|
|
/* Windows flushes the buffer when the interface is destroyed. */
|
|
|
|
flush_output_buffer(This);
|
2011-12-15 14:03:21 +01:00
|
|
|
free_output_buffer(This->buffer);
|
2011-08-13 01:11:08 +02:00
|
|
|
|
2011-05-01 10:04:59 +02:00
|
|
|
if (This->dest) IStream_Release(This->dest);
|
2011-05-01 18:05:31 +02:00
|
|
|
SysFreeString(This->version);
|
2011-12-16 00:36:53 +01:00
|
|
|
SysFreeString(This->encoding);
|
2011-05-01 18:05:31 +02:00
|
|
|
|
2011-08-27 12:19:22 +02:00
|
|
|
SysFreeString(This->element);
|
2011-12-05 09:07:26 +01:00
|
|
|
release_dispex(&This->dispex);
|
2011-04-30 09:42:29 +02:00
|
|
|
heap_free(This);
|
2011-05-01 10:04:59 +02:00
|
|
|
}
|
2011-04-30 09:42:29 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_GetTypeInfoCount(IMXWriter *iface, UINT* pctinfo)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-12-05 09:07:26 +01:00
|
|
|
return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_GetTypeInfo(
|
|
|
|
IMXWriter *iface,
|
|
|
|
UINT iTInfo, LCID lcid,
|
|
|
|
ITypeInfo** ppTInfo )
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-12-05 09:07:26 +01:00
|
|
|
return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
|
|
|
|
iTInfo, lcid, ppTInfo);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_GetIDsOfNames(
|
|
|
|
IMXWriter *iface,
|
|
|
|
REFIID riid, LPOLESTR* rgszNames,
|
|
|
|
UINT cNames, LCID lcid, DISPID* rgDispId )
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-12-05 09:07:26 +01:00
|
|
|
return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
|
|
|
|
riid, rgszNames, cNames, lcid, rgDispId);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_Invoke(
|
|
|
|
IMXWriter *iface,
|
|
|
|
DISPID dispIdMember, REFIID riid, LCID lcid,
|
|
|
|
WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
|
|
|
|
EXCEPINFO* pExcepInfo, UINT* puArgErr )
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-12-05 09:07:26 +01:00
|
|
|
return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
|
|
|
|
dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_put_output(IMXWriter *iface, VARIANT dest)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-08-13 01:11:08 +02:00
|
|
|
HRESULT hr;
|
2011-05-01 10:04:59 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_variant(&dest));
|
|
|
|
|
2011-08-13 01:11:08 +02:00
|
|
|
hr = flush_output_buffer(This);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2011-05-01 10:04:59 +02:00
|
|
|
switch (V_VT(&dest))
|
|
|
|
{
|
|
|
|
case VT_EMPTY:
|
|
|
|
{
|
|
|
|
if (This->dest) IStream_Release(This->dest);
|
|
|
|
This->dest = NULL;
|
2011-08-13 01:11:08 +02:00
|
|
|
reset_output_buffer(This);
|
2011-05-01 10:04:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VT_UNKNOWN:
|
|
|
|
{
|
|
|
|
IStream *stream;
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(V_UNKNOWN(&dest), &IID_IStream, (void**)&stream);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2011-08-13 01:11:08 +02:00
|
|
|
/* Recreate the output buffer to make sure it's using the correct encoding. */
|
|
|
|
reset_output_buffer(This);
|
|
|
|
|
2011-05-01 10:04:59 +02:00
|
|
|
if (This->dest) IStream_Release(This->dest);
|
|
|
|
This->dest = stream;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("unhandled interface type for VT_UNKNOWN destination\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("unhandled destination type %s\n", debugstr_variant(&dest));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_get_output(IMXWriter *iface, VARIANT *dest)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-01 18:05:31 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, dest);
|
|
|
|
|
|
|
|
if (!This->dest)
|
|
|
|
{
|
2011-12-15 14:03:21 +01:00
|
|
|
HRESULT hr = flush_output_buffer(This);
|
2011-08-13 01:11:08 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2011-05-01 18:05:31 +02:00
|
|
|
V_VT(dest) = VT_BSTR;
|
2011-12-15 14:03:21 +01:00
|
|
|
V_BSTR(dest) = SysAllocString((WCHAR*)This->buffer->utf16.data);
|
2011-05-01 18:05:31 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FIXME("not implemented when stream is set up\n");
|
|
|
|
|
2011-04-30 09:42:29 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_put_encoding(IMXWriter *iface, BSTR encoding)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-12-16 00:36:53 +01:00
|
|
|
xml_encoding enc;
|
|
|
|
HRESULT hr;
|
2011-05-01 10:54:09 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(encoding));
|
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
enc = parse_encoding_name(encoding);
|
|
|
|
if (enc == XmlEncoding_Unknown)
|
2011-05-01 10:54:09 +02:00
|
|
|
{
|
|
|
|
FIXME("unsupported encoding %s\n", debugstr_w(encoding));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2011-12-16 00:36:53 +01:00
|
|
|
|
|
|
|
hr = flush_output_buffer(This);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
SysReAllocString(&This->encoding, encoding);
|
|
|
|
This->xml_enc = enc;
|
|
|
|
|
|
|
|
TRACE("got encoding %d\n", This->xml_enc);
|
|
|
|
reset_output_buffer(This);
|
|
|
|
return S_OK;
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_get_encoding(IMXWriter *iface, BSTR *encoding)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-01 10:54:09 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, encoding);
|
|
|
|
|
|
|
|
if (!encoding) return E_POINTER;
|
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
*encoding = SysAllocString(This->encoding);
|
|
|
|
if (!*encoding) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return S_OK;
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
2011-05-07 19:57:45 +02:00
|
|
|
static HRESULT WINAPI mxwriter_put_byteOrderMark(IMXWriter *iface, VARIANT_BOOL value)
|
2011-04-30 09:42:29 +02:00
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-07 19:57:45 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, value);
|
2011-10-06 17:22:00 +02:00
|
|
|
return writer_set_property(This, MXWriter_BOM, value);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
2011-05-07 19:57:45 +02:00
|
|
|
static HRESULT WINAPI mxwriter_get_byteOrderMark(IMXWriter *iface, VARIANT_BOOL *value)
|
2011-04-30 09:42:29 +02:00
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-07 19:57:45 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, value);
|
2011-10-06 17:35:07 +02:00
|
|
|
return writer_get_property(This, MXWriter_BOM, value);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
2011-05-07 18:53:33 +02:00
|
|
|
static HRESULT WINAPI mxwriter_put_indent(IMXWriter *iface, VARIANT_BOOL value)
|
2011-04-30 09:42:29 +02:00
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-07 18:53:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, value);
|
2011-10-06 17:22:00 +02:00
|
|
|
return writer_set_property(This, MXWriter_Indent, value);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
2011-05-07 18:53:33 +02:00
|
|
|
static HRESULT WINAPI mxwriter_get_indent(IMXWriter *iface, VARIANT_BOOL *value)
|
2011-04-30 09:42:29 +02:00
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-07 18:53:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, value);
|
2011-10-06 17:35:07 +02:00
|
|
|
return writer_get_property(This, MXWriter_Indent, value);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_put_standalone(IMXWriter *iface, VARIANT_BOOL value)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-04-30 13:36:37 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, value);
|
2011-10-06 17:22:00 +02:00
|
|
|
return writer_set_property(This, MXWriter_Standalone, value);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_get_standalone(IMXWriter *iface, VARIANT_BOOL *value)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-04-30 13:36:37 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, value);
|
2011-10-06 17:35:07 +02:00
|
|
|
return writer_get_property(This, MXWriter_Standalone, value);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_put_omitXMLDeclaration(IMXWriter *iface, VARIANT_BOOL value)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-04 09:10:34 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, value);
|
2011-10-06 17:22:00 +02:00
|
|
|
return writer_set_property(This, MXWriter_OmitXmlDecl, value);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_get_omitXMLDeclaration(IMXWriter *iface, VARIANT_BOOL *value)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-04 09:10:34 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, value);
|
2011-10-06 17:35:07 +02:00
|
|
|
return writer_get_property(This, MXWriter_OmitXmlDecl, value);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_put_version(IMXWriter *iface, BSTR version)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-08-24 11:25:29 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(version));
|
|
|
|
|
|
|
|
if (!version) return E_INVALIDARG;
|
|
|
|
|
|
|
|
SysFreeString(This->version);
|
|
|
|
This->version = SysAllocString(version);
|
|
|
|
|
|
|
|
return S_OK;
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_get_version(IMXWriter *iface, BSTR *version)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-01 18:05:31 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, version);
|
|
|
|
|
|
|
|
if (!version) return E_POINTER;
|
|
|
|
|
|
|
|
return return_bstr(This->version, version);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_put_disableOutputEscaping(IMXWriter *iface, VARIANT_BOOL value)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-07 20:15:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, value);
|
2011-10-06 17:22:00 +02:00
|
|
|
return writer_set_property(This, MXWriter_DisableEscaping, value);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_get_disableOutputEscaping(IMXWriter *iface, VARIANT_BOOL *value)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-05-07 20:15:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, value);
|
2011-10-06 17:35:07 +02:00
|
|
|
return writer_get_property(This, MXWriter_DisableEscaping, value);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mxwriter_flush(IMXWriter *iface)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_IMXWriter( iface );
|
2011-08-13 01:11:08 +02:00
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
return flush_output_buffer(This);
|
2011-04-30 09:42:29 +02:00
|
|
|
}
|
|
|
|
|
2011-12-05 09:07:26 +01:00
|
|
|
static const struct IMXWriterVtbl MXWriterVtbl =
|
2011-04-30 09:42:29 +02:00
|
|
|
{
|
|
|
|
mxwriter_QueryInterface,
|
|
|
|
mxwriter_AddRef,
|
|
|
|
mxwriter_Release,
|
|
|
|
mxwriter_GetTypeInfoCount,
|
|
|
|
mxwriter_GetTypeInfo,
|
|
|
|
mxwriter_GetIDsOfNames,
|
|
|
|
mxwriter_Invoke,
|
|
|
|
mxwriter_put_output,
|
|
|
|
mxwriter_get_output,
|
|
|
|
mxwriter_put_encoding,
|
|
|
|
mxwriter_get_encoding,
|
|
|
|
mxwriter_put_byteOrderMark,
|
|
|
|
mxwriter_get_byteOrderMark,
|
|
|
|
mxwriter_put_indent,
|
|
|
|
mxwriter_get_indent,
|
|
|
|
mxwriter_put_standalone,
|
|
|
|
mxwriter_get_standalone,
|
|
|
|
mxwriter_put_omitXMLDeclaration,
|
|
|
|
mxwriter_get_omitXMLDeclaration,
|
|
|
|
mxwriter_put_version,
|
|
|
|
mxwriter_get_version,
|
|
|
|
mxwriter_put_disableOutputEscaping,
|
|
|
|
mxwriter_get_disableOutputEscaping,
|
|
|
|
mxwriter_flush
|
|
|
|
};
|
|
|
|
|
2011-04-30 13:18:03 +02:00
|
|
|
/*** ISAXContentHandler ***/
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_QueryInterface(
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler *iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **obj)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
|
|
|
return IMXWriter_QueryInterface(&This->IMXWriter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static ULONG WINAPI SAXContentHandler_AddRef(ISAXContentHandler *iface)
|
2011-04-30 13:18:03 +02:00
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
|
|
|
return IMXWriter_AddRef(&This->IMXWriter_iface);
|
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static ULONG WINAPI SAXContentHandler_Release(ISAXContentHandler *iface)
|
2011-04-30 13:18:03 +02:00
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
|
|
|
return IMXWriter_Release(&This->IMXWriter_iface);
|
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_putDocumentLocator(
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler *iface,
|
|
|
|
ISAXLocator *locator)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
|
|
|
FIXME("(%p)->(%p)\n", This, locator);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_startDocument(ISAXContentHandler *iface)
|
2011-04-30 13:18:03 +02:00
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
2011-05-01 18:05:31 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2011-08-13 01:11:08 +02:00
|
|
|
/* If properties have been changed since the last "endDocument" call
|
|
|
|
* we need to reset the output buffer. If we don't the output buffer
|
|
|
|
* could end up with multiple XML documents in it, plus this seems to
|
|
|
|
* be how Windows works.
|
|
|
|
*/
|
|
|
|
if (This->prop_changed) {
|
|
|
|
reset_output_buffer(This);
|
|
|
|
This->prop_changed = FALSE;
|
|
|
|
}
|
|
|
|
|
2011-05-04 09:10:34 +02:00
|
|
|
if (This->props[MXWriter_OmitXmlDecl] == VARIANT_TRUE) return S_OK;
|
|
|
|
|
2011-12-15 14:03:21 +01:00
|
|
|
write_prolog_buffer(This);
|
2011-05-01 18:05:31 +02:00
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
if (This->dest && This->xml_enc == XmlEncoding_UTF16) {
|
|
|
|
static const char utf16BOM[] = {0xff,0xfe};
|
2011-08-13 01:11:08 +02:00
|
|
|
|
|
|
|
if (This->props[MXWriter_BOM] == VARIANT_TRUE)
|
|
|
|
/* Windows passes a NULL pointer as the pcbWritten parameter and
|
|
|
|
* ignores any error codes returned from this Write call.
|
|
|
|
*/
|
|
|
|
IStream_Write(This->dest, utf16BOM, sizeof(utf16BOM), NULL);
|
|
|
|
}
|
|
|
|
|
2011-05-01 18:05:31 +02:00
|
|
|
return S_OK;
|
2011-04-30 13:18:03 +02:00
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_endDocument(ISAXContentHandler *iface)
|
2011-04-30 13:18:03 +02:00
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
2011-08-13 01:11:08 +02:00
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
This->prop_changed = FALSE;
|
|
|
|
return flush_output_buffer(This);
|
2011-04-30 13:18:03 +02:00
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_startPrefixMapping(
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler *iface,
|
|
|
|
const WCHAR *prefix,
|
|
|
|
int nprefix,
|
|
|
|
const WCHAR *uri,
|
|
|
|
int nuri)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
|
|
|
FIXME("(%p)->(%s %s)\n", This, debugstr_wn(prefix, nprefix), debugstr_wn(uri, nuri));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_endPrefixMapping(
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler *iface,
|
|
|
|
const WCHAR *prefix,
|
|
|
|
int nprefix)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
|
|
|
FIXME("(%p)->(%s)\n", This, debugstr_wn(prefix, nprefix));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_startElement(
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler *iface,
|
|
|
|
const WCHAR *namespaceUri,
|
|
|
|
int nnamespaceUri,
|
|
|
|
const WCHAR *local_name,
|
|
|
|
int nlocal_name,
|
|
|
|
const WCHAR *QName,
|
|
|
|
int nQName,
|
|
|
|
ISAXAttributes *attr)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
2011-12-15 14:03:21 +01:00
|
|
|
static const WCHAR ltW[] = {'<'};
|
2011-05-07 16:34:37 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %s %s %p)\n", This, debugstr_wn(namespaceUri, nnamespaceUri),
|
2011-04-30 13:18:03 +02:00
|
|
|
debugstr_wn(local_name, nlocal_name), debugstr_wn(QName, nQName), attr);
|
2011-05-07 16:34:37 +02:00
|
|
|
|
2011-08-25 13:31:02 +02:00
|
|
|
if ((!namespaceUri || !local_name || !QName) && This->class_version != MSXML6)
|
|
|
|
return E_INVALIDARG;
|
2011-05-07 16:34:37 +02:00
|
|
|
|
2011-08-27 12:19:22 +02:00
|
|
|
close_element_starttag(This);
|
2011-08-27 15:35:13 +02:00
|
|
|
set_element_name(This, QName ? QName : emptyW,
|
|
|
|
QName ? nQName : 0);
|
2011-08-27 12:19:22 +02:00
|
|
|
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, ltW, 1);
|
|
|
|
write_output_buffer(This->buffer, QName, nQName);
|
2011-05-07 17:37:59 +02:00
|
|
|
|
|
|
|
if (attr)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
INT length;
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
hr = ISAXAttributes_getLength(attr, &length);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
2012-01-27 14:23:56 +01:00
|
|
|
static const WCHAR eqW[] = {'='};
|
2011-05-07 17:37:59 +02:00
|
|
|
const WCHAR *str;
|
2011-12-11 00:32:51 +01:00
|
|
|
WCHAR *escaped;
|
2011-08-27 13:01:57 +02:00
|
|
|
INT len = 0;
|
2011-05-07 17:37:59 +02:00
|
|
|
|
|
|
|
hr = ISAXAttributes_getQName(attr, i, &str, &len);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2011-08-25 22:28:23 +02:00
|
|
|
/* space separator in front of every attribute */
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, spaceW, 1);
|
|
|
|
write_output_buffer(This->buffer, str, len);
|
2011-05-07 17:37:59 +02:00
|
|
|
|
2012-01-27 14:23:56 +01:00
|
|
|
write_output_buffer(This->buffer, eqW, 1);
|
2011-05-07 17:37:59 +02:00
|
|
|
|
2011-08-27 13:01:57 +02:00
|
|
|
len = 0;
|
2011-05-07 17:37:59 +02:00
|
|
|
hr = ISAXAttributes_getValue(attr, i, &str, &len);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2012-02-24 21:20:48 +01:00
|
|
|
escaped = get_escaped_string(str, EscapeValue, &len);
|
2012-01-27 14:23:56 +01:00
|
|
|
write_output_buffer_quoted(This->buffer, escaped, len);
|
2011-12-11 00:32:51 +01:00
|
|
|
heap_free(escaped);
|
2011-05-07 17:37:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-07 16:34:37 +02:00
|
|
|
return S_OK;
|
2011-04-30 13:18:03 +02:00
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_endElement(
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler *iface,
|
|
|
|
const WCHAR *namespaceUri,
|
|
|
|
int nnamespaceUri,
|
|
|
|
const WCHAR * local_name,
|
|
|
|
int nlocal_name,
|
|
|
|
const WCHAR *QName,
|
|
|
|
int nQName)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
2011-05-07 16:34:37 +02:00
|
|
|
|
2011-10-05 23:04:04 +02:00
|
|
|
TRACE("(%p)->(%s:%d %s:%d %s:%d)\n", This, debugstr_wn(namespaceUri, nnamespaceUri), nnamespaceUri,
|
|
|
|
debugstr_wn(local_name, nlocal_name), nlocal_name, debugstr_wn(QName, nQName), nQName);
|
2011-05-07 16:34:37 +02:00
|
|
|
|
2011-08-25 13:32:27 +02:00
|
|
|
if ((!namespaceUri || !local_name || !QName) && This->class_version != MSXML6)
|
|
|
|
return E_INVALIDARG;
|
2011-05-07 16:34:37 +02:00
|
|
|
|
2011-10-05 23:04:04 +02:00
|
|
|
if (This->element && QName && !strncmpW(This->element, QName, nQName))
|
2011-08-27 12:19:22 +02:00
|
|
|
{
|
2011-12-15 14:03:21 +01:00
|
|
|
static const WCHAR closeW[] = {'/','>'};
|
|
|
|
|
|
|
|
write_output_buffer(This->buffer, closeW, 2);
|
2011-08-27 12:19:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-15 14:03:21 +01:00
|
|
|
static const WCHAR closetagW[] = {'<','/'};
|
|
|
|
static const WCHAR gtW[] = {'>'};
|
2011-10-05 23:04:04 +02:00
|
|
|
|
2011-12-15 14:03:21 +01:00
|
|
|
write_output_buffer(This->buffer, closetagW, 2);
|
|
|
|
write_output_buffer(This->buffer, QName, nQName);
|
|
|
|
write_output_buffer(This->buffer, gtW, 1);
|
2011-08-27 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2011-08-27 15:35:13 +02:00
|
|
|
set_element_name(This, NULL, 0);
|
2011-05-07 16:34:37 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2011-04-30 13:18:03 +02:00
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_characters(
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler *iface,
|
|
|
|
const WCHAR *chars,
|
|
|
|
int nchars)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
2011-05-07 19:51:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s:%d)\n", This, debugstr_wn(chars, nchars), nchars);
|
|
|
|
|
|
|
|
if (!chars) return E_INVALIDARG;
|
|
|
|
|
2011-08-27 12:19:22 +02:00
|
|
|
close_element_starttag(This);
|
2011-08-27 15:35:13 +02:00
|
|
|
set_element_name(This, NULL, 0);
|
2011-08-27 12:19:22 +02:00
|
|
|
|
2011-05-07 19:51:33 +02:00
|
|
|
if (nchars)
|
2012-02-24 21:20:48 +01:00
|
|
|
{
|
|
|
|
if (This->cdata)
|
|
|
|
write_output_buffer(This->buffer, chars, nchars);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int len = nchars;
|
|
|
|
WCHAR *escaped;
|
|
|
|
|
|
|
|
escaped = get_escaped_string(chars, EscapeText, &len);
|
|
|
|
write_output_buffer(This->buffer, escaped, len);
|
|
|
|
heap_free(escaped);
|
|
|
|
}
|
|
|
|
}
|
2011-05-07 19:51:33 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2011-04-30 13:18:03 +02:00
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_ignorableWhitespace(
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler *iface,
|
|
|
|
const WCHAR *chars,
|
|
|
|
int nchars)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
|
|
|
FIXME("(%p)->(%s)\n", This, debugstr_wn(chars, nchars));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_processingInstruction(
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler *iface,
|
|
|
|
const WCHAR *target,
|
|
|
|
int ntarget,
|
|
|
|
const WCHAR *data,
|
|
|
|
int ndata)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
|
|
|
FIXME("(%p)->(%s %s)\n", This, debugstr_wn(target, ntarget), debugstr_wn(data, ndata));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static HRESULT WINAPI SAXContentHandler_skippedEntity(
|
2011-04-30 13:18:03 +02:00
|
|
|
ISAXContentHandler *iface,
|
|
|
|
const WCHAR *name,
|
|
|
|
int nname)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXContentHandler( iface );
|
|
|
|
FIXME("(%p)->(%s)\n", This, debugstr_wn(name, nname));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
static const struct ISAXContentHandlerVtbl SAXContentHandlerVtbl =
|
|
|
|
{
|
|
|
|
SAXContentHandler_QueryInterface,
|
|
|
|
SAXContentHandler_AddRef,
|
|
|
|
SAXContentHandler_Release,
|
|
|
|
SAXContentHandler_putDocumentLocator,
|
|
|
|
SAXContentHandler_startDocument,
|
|
|
|
SAXContentHandler_endDocument,
|
|
|
|
SAXContentHandler_startPrefixMapping,
|
|
|
|
SAXContentHandler_endPrefixMapping,
|
|
|
|
SAXContentHandler_startElement,
|
|
|
|
SAXContentHandler_endElement,
|
|
|
|
SAXContentHandler_characters,
|
|
|
|
SAXContentHandler_ignorableWhitespace,
|
|
|
|
SAXContentHandler_processingInstruction,
|
|
|
|
SAXContentHandler_skippedEntity
|
|
|
|
};
|
|
|
|
|
|
|
|
/*** ISAXLexicalHandler ***/
|
|
|
|
static HRESULT WINAPI SAXLexicalHandler_QueryInterface(ISAXLexicalHandler *iface,
|
|
|
|
REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXLexicalHandler( iface );
|
|
|
|
return IMXWriter_QueryInterface(&This->IMXWriter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI SAXLexicalHandler_AddRef(ISAXLexicalHandler *iface)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXLexicalHandler( iface );
|
|
|
|
return IMXWriter_AddRef(&This->IMXWriter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI SAXLexicalHandler_Release(ISAXLexicalHandler *iface)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXLexicalHandler( iface );
|
|
|
|
return IMXWriter_Release(&This->IMXWriter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXLexicalHandler_startDTD(ISAXLexicalHandler *iface,
|
|
|
|
const WCHAR *name, int name_len, const WCHAR *publicId, int publicId_len,
|
|
|
|
const WCHAR *systemId, int systemId_len)
|
|
|
|
{
|
2012-01-27 14:09:42 +01:00
|
|
|
static const WCHAR doctypeW[] = {'<','!','D','O','C','T','Y','P','E',' '};
|
|
|
|
static const WCHAR openintW[] = {'[','\r','\n'};
|
|
|
|
|
2012-01-27 12:45:21 +01:00
|
|
|
mxwriter *This = impl_from_ISAXLexicalHandler( iface );
|
2012-01-27 14:09:42 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %s %s)\n", This, debugstr_wn(name, name_len), debugstr_wn(publicId, publicId_len),
|
2012-01-27 12:45:21 +01:00
|
|
|
debugstr_wn(systemId, systemId_len));
|
2012-01-27 14:09:42 +01:00
|
|
|
|
|
|
|
if (!name) return E_INVALIDARG;
|
|
|
|
|
|
|
|
write_output_buffer(This->buffer, doctypeW, sizeof(doctypeW)/sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (*name)
|
|
|
|
{
|
|
|
|
write_output_buffer(This->buffer, name, name_len);
|
|
|
|
write_output_buffer(This->buffer, spaceW, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (publicId)
|
|
|
|
{
|
|
|
|
static const WCHAR publicW[] = {'P','U','B','L','I','C',' '};
|
|
|
|
|
|
|
|
write_output_buffer(This->buffer, publicW, sizeof(publicW)/sizeof(WCHAR));
|
2012-01-27 14:23:56 +01:00
|
|
|
write_output_buffer_quoted(This->buffer, publicId, publicId_len);
|
2012-01-27 14:09:42 +01:00
|
|
|
|
|
|
|
if (!systemId) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (*publicId)
|
|
|
|
write_output_buffer(This->buffer, spaceW, 1);
|
|
|
|
|
2012-01-27 14:23:56 +01:00
|
|
|
write_output_buffer_quoted(This->buffer, systemId, systemId_len);
|
2012-01-27 14:09:42 +01:00
|
|
|
|
|
|
|
if (*systemId)
|
|
|
|
write_output_buffer(This->buffer, spaceW, 1);
|
|
|
|
}
|
|
|
|
else if (systemId)
|
|
|
|
{
|
|
|
|
static const WCHAR systemW[] = {'S','Y','S','T','E','M',' '};
|
|
|
|
|
|
|
|
write_output_buffer(This->buffer, systemW, sizeof(systemW)/sizeof(WCHAR));
|
2012-01-27 14:23:56 +01:00
|
|
|
write_output_buffer_quoted(This->buffer, systemId, systemId_len);
|
2012-01-27 14:09:42 +01:00
|
|
|
if (*systemId)
|
|
|
|
write_output_buffer(This->buffer, spaceW, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
write_output_buffer(This->buffer, openintW, sizeof(openintW)/sizeof(WCHAR));
|
|
|
|
|
|
|
|
return S_OK;
|
2012-01-27 12:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXLexicalHandler_endDTD(ISAXLexicalHandler *iface)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXLexicalHandler( iface );
|
2012-01-27 14:09:42 +01:00
|
|
|
static const WCHAR closedtdW[] = {']','>','\r','\n'};
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
write_output_buffer(This->buffer, closedtdW, sizeof(closedtdW)/sizeof(WCHAR));
|
|
|
|
|
|
|
|
return S_OK;
|
2012-01-27 12:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXLexicalHandler_startEntity(ISAXLexicalHandler *iface, const WCHAR *name, int len)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXLexicalHandler( iface );
|
|
|
|
FIXME("(%p)->(%s): stub\n", This, debugstr_wn(name, len));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXLexicalHandler_endEntity(ISAXLexicalHandler *iface, const WCHAR *name, int len)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXLexicalHandler( iface );
|
|
|
|
FIXME("(%p)->(%s): stub\n", This, debugstr_wn(name, len));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXLexicalHandler_startCDATA(ISAXLexicalHandler *iface)
|
|
|
|
{
|
2012-01-27 13:30:03 +01:00
|
|
|
static const WCHAR scdataW[] = {'<','!','[','C','D','A','T','A','['};
|
2012-01-27 12:45:21 +01:00
|
|
|
mxwriter *This = impl_from_ISAXLexicalHandler( iface );
|
2012-01-27 13:30:03 +01:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
write_output_buffer(This->buffer, scdataW, sizeof(scdataW)/sizeof(WCHAR));
|
2012-02-24 21:20:48 +01:00
|
|
|
This->cdata = TRUE;
|
2012-01-27 13:30:03 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2012-01-27 12:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXLexicalHandler_endCDATA(ISAXLexicalHandler *iface)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXLexicalHandler( iface );
|
2012-01-27 13:30:03 +01:00
|
|
|
static const WCHAR ecdataW[] = {']',']','>'};
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
write_output_buffer(This->buffer, ecdataW, sizeof(ecdataW)/sizeof(WCHAR));
|
2012-02-24 21:20:48 +01:00
|
|
|
This->cdata = FALSE;
|
2012-01-27 13:30:03 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2012-01-27 12:45:21 +01:00
|
|
|
}
|
|
|
|
|
2012-01-27 13:13:54 +01:00
|
|
|
static HRESULT WINAPI SAXLexicalHandler_comment(ISAXLexicalHandler *iface, const WCHAR *chars, int nchars)
|
2012-01-27 12:45:21 +01:00
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXLexicalHandler( iface );
|
2012-01-27 13:13:54 +01:00
|
|
|
static const WCHAR copenW[] = {'<','!','-','-'};
|
|
|
|
static const WCHAR ccloseW[] = {'-','-','>','\r','\n'};
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s:%d)\n", This, debugstr_wn(chars, nchars), nchars);
|
|
|
|
|
|
|
|
if (!chars) return E_INVALIDARG;
|
|
|
|
|
|
|
|
close_element_starttag(This);
|
|
|
|
|
|
|
|
write_output_buffer(This->buffer, copenW, sizeof(copenW)/sizeof(WCHAR));
|
|
|
|
if (nchars)
|
|
|
|
write_output_buffer(This->buffer, chars, nchars);
|
|
|
|
write_output_buffer(This->buffer, ccloseW, sizeof(ccloseW)/sizeof(WCHAR));
|
|
|
|
|
|
|
|
return S_OK;
|
2012-01-27 12:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ISAXLexicalHandlerVtbl SAXLexicalHandlerVtbl =
|
|
|
|
{
|
|
|
|
SAXLexicalHandler_QueryInterface,
|
|
|
|
SAXLexicalHandler_AddRef,
|
|
|
|
SAXLexicalHandler_Release,
|
|
|
|
SAXLexicalHandler_startDTD,
|
|
|
|
SAXLexicalHandler_endDTD,
|
|
|
|
SAXLexicalHandler_startEntity,
|
|
|
|
SAXLexicalHandler_endEntity,
|
|
|
|
SAXLexicalHandler_startCDATA,
|
|
|
|
SAXLexicalHandler_endCDATA,
|
|
|
|
SAXLexicalHandler_comment
|
2011-04-30 13:18:03 +02:00
|
|
|
};
|
|
|
|
|
2012-03-08 09:57:48 +01:00
|
|
|
/*** ISAXDeclHandler ***/
|
|
|
|
static HRESULT WINAPI SAXDeclHandler_QueryInterface(ISAXDeclHandler *iface,
|
|
|
|
REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXDeclHandler( iface );
|
|
|
|
return IMXWriter_QueryInterface(&This->IMXWriter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI SAXDeclHandler_AddRef(ISAXDeclHandler *iface)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXDeclHandler( iface );
|
|
|
|
return IMXWriter_AddRef(&This->IMXWriter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI SAXDeclHandler_Release(ISAXDeclHandler *iface)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXDeclHandler( iface );
|
|
|
|
return IMXWriter_Release(&This->IMXWriter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXDeclHandler_elementDecl(ISAXDeclHandler *iface,
|
|
|
|
const WCHAR *name, int n_name, const WCHAR *model, int n_model)
|
|
|
|
{
|
2012-03-08 10:03:27 +01:00
|
|
|
static const WCHAR elementW[] = {'<','!','E','L','E','M','E','N','T',' '};
|
|
|
|
static const WCHAR closeelementW[] = {'>','\r','\n'};
|
2012-03-08 09:57:48 +01:00
|
|
|
mxwriter *This = impl_from_ISAXDeclHandler( iface );
|
2012-03-08 10:03:27 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s:%d %s:%d)\n", This, debugstr_wn(name, n_name), n_name,
|
2012-03-08 09:57:48 +01:00
|
|
|
debugstr_wn(model, n_model), n_model);
|
2012-03-08 10:03:27 +01:00
|
|
|
|
|
|
|
if (!name || !model) return E_INVALIDARG;
|
|
|
|
|
|
|
|
write_output_buffer(This->buffer, elementW, sizeof(elementW)/sizeof(WCHAR));
|
|
|
|
if (n_name) {
|
|
|
|
write_output_buffer(This->buffer, name, n_name);
|
|
|
|
write_output_buffer(This->buffer, spaceW, sizeof(spaceW)/sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
if (n_model)
|
|
|
|
write_output_buffer(This->buffer, model, n_model);
|
|
|
|
write_output_buffer(This->buffer, closeelementW, sizeof(closeelementW)/sizeof(WCHAR));
|
|
|
|
|
|
|
|
return S_OK;
|
2012-03-08 09:57:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXDeclHandler_attributeDecl(ISAXDeclHandler *iface,
|
|
|
|
const WCHAR *element, int n_element, const WCHAR *attr, int n_attr,
|
|
|
|
const WCHAR *type, int n_type, const WCHAR *Default, int n_default,
|
|
|
|
const WCHAR *value, int n_value)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXDeclHandler( iface );
|
|
|
|
FIXME("(%p)->(%s:%d %s:%d %s:%d %s:%d %s:%d): stub\n", This, debugstr_wn(element, n_element), n_element,
|
|
|
|
debugstr_wn(attr, n_attr), n_attr, debugstr_wn(type, n_type), n_type, debugstr_wn(Default, n_default), n_default,
|
|
|
|
debugstr_wn(value, n_value), n_value);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXDeclHandler_internalEntityDecl(ISAXDeclHandler *iface,
|
|
|
|
const WCHAR *name, int n_name, const WCHAR *value, int n_value)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXDeclHandler( iface );
|
|
|
|
FIXME("(%p)->(%s:%d %s:%d): stub\n", This, debugstr_wn(name, n_name), n_name,
|
|
|
|
debugstr_wn(value, n_value), n_value);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXDeclHandler_externalEntityDecl(ISAXDeclHandler *iface,
|
|
|
|
const WCHAR *name, int n_name, const WCHAR *publicId, int n_publicId,
|
|
|
|
const WCHAR *systemId, int n_systemId)
|
|
|
|
{
|
|
|
|
mxwriter *This = impl_from_ISAXDeclHandler( iface );
|
|
|
|
FIXME("(%p)->(%s:%d %s:%d %s:%d): stub\n", This, debugstr_wn(name, n_name), n_name,
|
|
|
|
debugstr_wn(publicId, n_publicId), n_publicId, debugstr_wn(systemId, n_systemId), n_systemId);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ISAXDeclHandlerVtbl SAXDeclHandlerVtbl = {
|
|
|
|
SAXDeclHandler_QueryInterface,
|
|
|
|
SAXDeclHandler_AddRef,
|
|
|
|
SAXDeclHandler_Release,
|
|
|
|
SAXDeclHandler_elementDecl,
|
|
|
|
SAXDeclHandler_attributeDecl,
|
|
|
|
SAXDeclHandler_internalEntityDecl,
|
|
|
|
SAXDeclHandler_externalEntityDecl
|
|
|
|
};
|
|
|
|
|
2011-12-05 09:07:26 +01:00
|
|
|
static const tid_t mxwriter_iface_tids[] = {
|
|
|
|
IMXWriter_tid,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static dispex_static_data_t mxwriter_dispex = {
|
|
|
|
NULL,
|
|
|
|
IMXWriter_tid,
|
|
|
|
NULL,
|
|
|
|
mxwriter_iface_tids
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT MXWriter_create(MSXML_VERSION version, IUnknown *outer, void **ppObj)
|
2011-04-30 09:42:29 +02:00
|
|
|
{
|
2011-05-01 18:05:31 +02:00
|
|
|
static const WCHAR version10W[] = {'1','.','0',0};
|
2011-04-30 09:42:29 +02:00
|
|
|
mxwriter *This;
|
2011-12-15 14:03:21 +01:00
|
|
|
HRESULT hr;
|
2011-04-30 09:42:29 +02:00
|
|
|
|
2011-12-05 09:07:26 +01:00
|
|
|
TRACE("(%p, %p)\n", outer, ppObj);
|
2011-04-30 09:42:29 +02:00
|
|
|
|
2011-12-05 09:07:26 +01:00
|
|
|
if (outer) FIXME("support aggregation, outer\n");
|
2011-04-30 09:42:29 +02:00
|
|
|
|
|
|
|
This = heap_alloc( sizeof (*This) );
|
|
|
|
if(!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2011-12-05 09:07:26 +01:00
|
|
|
This->IMXWriter_iface.lpVtbl = &MXWriterVtbl;
|
2012-01-27 12:45:21 +01:00
|
|
|
This->ISAXContentHandler_iface.lpVtbl = &SAXContentHandlerVtbl;
|
|
|
|
This->ISAXLexicalHandler_iface.lpVtbl = &SAXLexicalHandlerVtbl;
|
2012-03-08 09:57:48 +01:00
|
|
|
This->ISAXDeclHandler_iface.lpVtbl = &SAXDeclHandlerVtbl;
|
2011-04-30 09:42:29 +02:00
|
|
|
This->ref = 1;
|
2011-08-24 14:06:58 +02:00
|
|
|
This->class_version = version;
|
2011-04-30 09:42:29 +02:00
|
|
|
|
2011-05-07 19:57:45 +02:00
|
|
|
This->props[MXWriter_BOM] = VARIANT_TRUE;
|
2011-05-07 20:15:33 +02:00
|
|
|
This->props[MXWriter_DisableEscaping] = VARIANT_FALSE;
|
2011-05-07 18:53:33 +02:00
|
|
|
This->props[MXWriter_Indent] = VARIANT_FALSE;
|
2011-05-04 09:10:34 +02:00
|
|
|
This->props[MXWriter_OmitXmlDecl] = VARIANT_FALSE;
|
2011-05-04 08:59:32 +02:00
|
|
|
This->props[MXWriter_Standalone] = VARIANT_FALSE;
|
2011-08-13 01:11:08 +02:00
|
|
|
This->prop_changed = FALSE;
|
2011-12-16 00:36:53 +01:00
|
|
|
This->encoding = SysAllocString(utf16W);
|
2011-12-09 16:24:46 +01:00
|
|
|
This->version = SysAllocString(version10W);
|
2011-12-16 00:36:53 +01:00
|
|
|
This->xml_enc = XmlEncoding_UTF16;
|
2011-05-01 10:54:09 +02:00
|
|
|
|
2011-08-27 12:19:22 +02:00
|
|
|
This->element = NULL;
|
2012-02-24 21:20:48 +01:00
|
|
|
This->cdata = FALSE;
|
2011-08-27 12:19:22 +02:00
|
|
|
|
2011-05-01 10:04:59 +02:00
|
|
|
This->dest = NULL;
|
2011-08-13 01:11:08 +02:00
|
|
|
This->dest_written = 0;
|
2011-04-30 13:36:37 +02:00
|
|
|
|
2011-12-16 00:36:53 +01:00
|
|
|
hr = alloc_output_buffer(This->xml_enc, &This->buffer);
|
2011-12-15 14:03:21 +01:00
|
|
|
if (hr != S_OK) {
|
2011-12-16 00:36:53 +01:00
|
|
|
SysFreeString(This->encoding);
|
2011-12-15 14:03:21 +01:00
|
|
|
SysFreeString(This->version);
|
|
|
|
heap_free(This);
|
|
|
|
return hr;
|
|
|
|
}
|
2011-05-01 18:05:31 +02:00
|
|
|
|
2011-12-05 09:07:26 +01:00
|
|
|
init_dispex(&This->dispex, (IUnknown*)&This->IMXWriter_iface, &mxwriter_dispex);
|
|
|
|
|
2011-04-30 09:42:29 +02:00
|
|
|
*ppObj = &This->IMXWriter_iface;
|
|
|
|
|
|
|
|
TRACE("returning iface %p\n", *ppObj);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-03-08 21:11:45 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_QueryInterface(IMXAttributes *iface, REFIID riid, void **ppObj)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid( riid ), ppObj);
|
|
|
|
|
|
|
|
*ppObj = NULL;
|
|
|
|
|
|
|
|
if ( IsEqualGUID( riid, &IID_IUnknown ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IDispatch ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IMXAttributes ))
|
|
|
|
{
|
|
|
|
*ppObj = iface;
|
|
|
|
}
|
2012-03-09 09:55:03 +01:00
|
|
|
else if ( IsEqualGUID( riid, &IID_ISAXAttributes ))
|
|
|
|
{
|
|
|
|
*ppObj = &This->ISAXAttributes_iface;
|
|
|
|
}
|
2012-03-08 21:11:45 +01:00
|
|
|
else if (dispex_query_interface(&This->dispex, riid, ppObj))
|
|
|
|
{
|
|
|
|
return *ppObj ? S_OK : E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMXAttributes_AddRef( iface );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MXAttributes_AddRef(IMXAttributes *iface)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
ULONG ref = InterlockedIncrement( &This->ref );
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref );
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MXAttributes_Release(IMXAttributes *iface)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
LONG ref = InterlockedDecrement( &This->ref );
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2012-03-13 08:59:53 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < This->length; i++)
|
|
|
|
{
|
|
|
|
SysFreeString(This->attr[i].qname);
|
|
|
|
SysFreeString(This->attr[i].local);
|
|
|
|
SysFreeString(This->attr[i].uri);
|
|
|
|
SysFreeString(This->attr[i].type);
|
|
|
|
SysFreeString(This->attr[i].value);
|
|
|
|
}
|
|
|
|
|
2012-03-08 21:11:45 +01:00
|
|
|
release_dispex(&This->dispex);
|
2012-03-13 08:59:53 +01:00
|
|
|
heap_free(This->attr);
|
2012-03-08 21:11:45 +01:00
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_GetTypeInfoCount(IMXAttributes *iface, UINT* pctinfo)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_GetTypeInfo(IMXAttributes *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_GetIDsOfNames(
|
|
|
|
IMXAttributes *iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPOLESTR* rgszNames,
|
|
|
|
UINT cNames,
|
|
|
|
LCID lcid,
|
|
|
|
DISPID* rgDispId)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
|
|
|
|
riid, rgszNames, cNames, lcid, rgDispId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_Invoke(
|
|
|
|
IMXAttributes *iface,
|
|
|
|
DISPID dispIdMember,
|
|
|
|
REFIID riid,
|
|
|
|
LCID lcid,
|
|
|
|
WORD wFlags,
|
|
|
|
DISPPARAMS* pDispParams,
|
|
|
|
VARIANT* pVarResult,
|
|
|
|
EXCEPINFO* pExcepInfo,
|
|
|
|
UINT* puArgErr)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
|
|
|
|
dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_addAttribute(IMXAttributes *iface,
|
|
|
|
BSTR uri, BSTR localName, BSTR QName, BSTR type, BSTR value)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
2012-03-13 08:59:53 +01:00
|
|
|
mxattribute *attr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %s %s %s %s)\n", This, debugstr_w(uri), debugstr_w(localName),
|
2012-03-08 21:11:45 +01:00
|
|
|
debugstr_w(QName), debugstr_w(type), debugstr_w(value));
|
2012-03-13 08:59:53 +01:00
|
|
|
|
|
|
|
if ((!uri || !localName || !QName || !type || !value) && This->class_version != MSXML6)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* ensure array is large enough */
|
|
|
|
hr = mxattributes_grow(This);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
attr = &This->attr[This->length];
|
|
|
|
|
|
|
|
attr->qname = SysAllocString(QName);
|
|
|
|
attr->local = SysAllocString(localName);
|
|
|
|
attr->uri = SysAllocString(uri);
|
2012-03-14 09:44:34 +01:00
|
|
|
attr->type = SysAllocString(type ? type : emptyW);
|
2012-03-13 08:59:53 +01:00
|
|
|
attr->value = SysAllocString(value);
|
|
|
|
This->length++;
|
|
|
|
|
|
|
|
return S_OK;
|
2012-03-08 21:11:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_addAttributeFromIndex(IMXAttributes *iface,
|
|
|
|
VARIANT atts, int index)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%s %d): stub\n", This, debugstr_variant(&atts), index);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_clear(IMXAttributes *iface)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_removeAttribute(IMXAttributes *iface, int index)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%d): stub\n", This, index);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_setAttribute(IMXAttributes *iface, int index,
|
|
|
|
BSTR uri, BSTR localName, BSTR QName, BSTR type, BSTR value)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%d %s %s %s %s %s): stub\n", This, index, debugstr_w(uri),
|
|
|
|
debugstr_w(localName), debugstr_w(QName), debugstr_w(type), debugstr_w(value));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_setAttributes(IMXAttributes *iface, VARIANT atts)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%s): stub\n", This, debugstr_variant(&atts));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_setLocalName(IMXAttributes *iface, int index,
|
|
|
|
BSTR localName)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%d %s): stub\n", This, index, debugstr_w(localName));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_setQName(IMXAttributes *iface, int index, BSTR QName)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%d %s): stub\n", This, index, debugstr_w(QName));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_setURI(IMXAttributes *iface, int index, BSTR uri)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%d %s): stub\n", This, index, debugstr_w(uri));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MXAttributes_setValue(IMXAttributes *iface, int index, BSTR value)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_IMXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%d %s): stub\n", This, index, debugstr_w(value));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMXAttributesVtbl MXAttributesVtbl = {
|
|
|
|
MXAttributes_QueryInterface,
|
|
|
|
MXAttributes_AddRef,
|
|
|
|
MXAttributes_Release,
|
|
|
|
MXAttributes_GetTypeInfoCount,
|
|
|
|
MXAttributes_GetTypeInfo,
|
|
|
|
MXAttributes_GetIDsOfNames,
|
|
|
|
MXAttributes_Invoke,
|
|
|
|
MXAttributes_addAttribute,
|
|
|
|
MXAttributes_addAttributeFromIndex,
|
|
|
|
MXAttributes_clear,
|
|
|
|
MXAttributes_removeAttribute,
|
|
|
|
MXAttributes_setAttribute,
|
|
|
|
MXAttributes_setAttributes,
|
|
|
|
MXAttributes_setLocalName,
|
|
|
|
MXAttributes_setQName,
|
|
|
|
MXAttributes_setURI,
|
|
|
|
MXAttributes_setValue
|
|
|
|
};
|
|
|
|
|
2012-03-09 09:55:03 +01:00
|
|
|
static HRESULT WINAPI SAXAttributes_QueryInterface(ISAXAttributes *iface, REFIID riid, void **ppObj)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
return IMXAttributes_QueryInterface(&This->IMXAttributes_iface, riid, ppObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI SAXAttributes_AddRef(ISAXAttributes *iface)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
return IMXAttributes_AddRef(&This->IMXAttributes_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI SAXAttributes_Release(ISAXAttributes *iface)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
return IMXAttributes_Release(&This->IMXAttributes_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXAttributes_getLength(ISAXAttributes *iface, int *length)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
2012-03-13 09:05:45 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, length);
|
|
|
|
|
|
|
|
if (!length && (This->class_version == MSXML_DEFAULT || This->class_version == MSXML3))
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*length = This->length;
|
|
|
|
|
|
|
|
return S_OK;
|
2012-03-09 09:55:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXAttributes_getURI(ISAXAttributes *iface, int nIndex, const WCHAR **pUrl,
|
|
|
|
int *pUriSize)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%d %p %p): stub\n", This, nIndex, pUrl, pUriSize);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXAttributes_getLocalName(ISAXAttributes *iface, int nIndex, const WCHAR **localName,
|
|
|
|
int *length)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%d %p %p): stub\n", This, nIndex, localName, length);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXAttributes_getQName(ISAXAttributes *iface, int index, const WCHAR **qname, int *length)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
2012-03-13 09:12:16 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d %p %p)\n", This, index, qname, length);
|
|
|
|
|
|
|
|
if (index >= This->length) return E_INVALIDARG;
|
|
|
|
if (!qname || !length) return E_POINTER;
|
|
|
|
|
|
|
|
*qname = This->attr[index].qname;
|
|
|
|
*length = SysStringLen(This->attr[index].qname);
|
|
|
|
|
|
|
|
return S_OK;
|
2012-03-09 09:55:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXAttributes_getName(ISAXAttributes *iface, int nIndex, const WCHAR **pUri, int *pUriLength,
|
|
|
|
const WCHAR ** pLocalName, int * pLocalNameSize, const WCHAR ** pQName, int * pQNameLength)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%d %p %p %p %p %p %p): stub\n", This, nIndex, pUri, pUriLength, pLocalName, pLocalNameSize,
|
|
|
|
pQName, pQNameLength);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXAttributes_getIndexFromName(ISAXAttributes *iface, const WCHAR * pUri, int cUriLength,
|
|
|
|
const WCHAR * pLocalName, int cocalNameLength, int * index)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%s:%d %s:%d %p): stub\n", This, debugstr_wn(pUri, cUriLength), cUriLength,
|
|
|
|
debugstr_wn(pLocalName, cocalNameLength), cocalNameLength, index);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-03-14 10:18:55 +01:00
|
|
|
static HRESULT WINAPI SAXAttributes_getIndexFromQName(ISAXAttributes *iface, const WCHAR *qname,
|
|
|
|
int len, int *index)
|
2012-03-09 09:55:03 +01:00
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
2012-03-14 10:18:55 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s:%d %p)\n", This, debugstr_wn(qname, len), len, index);
|
|
|
|
|
|
|
|
if (!index && (This->class_version == MSXML_DEFAULT || This->class_version == MSXML3))
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (!qname || !index || !len) return E_INVALIDARG;
|
|
|
|
|
|
|
|
for (i = 0; i < This->length; i++)
|
|
|
|
{
|
|
|
|
if (len != SysStringLen(This->attr[i].qname)) continue;
|
|
|
|
if (strncmpW(qname, This->attr[i].qname, len)) continue;
|
|
|
|
|
|
|
|
*index = i;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_INVALIDARG;
|
2012-03-09 09:55:03 +01:00
|
|
|
}
|
|
|
|
|
2012-03-14 09:44:34 +01:00
|
|
|
static HRESULT WINAPI SAXAttributes_getType(ISAXAttributes *iface, int index, const WCHAR **type,
|
|
|
|
int *len)
|
2012-03-09 09:55:03 +01:00
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
2012-03-14 09:44:34 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d %p %p)\n", This, index, type, len);
|
|
|
|
|
|
|
|
if (index >= This->length) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if ((!type || !len) && (This->class_version == MSXML_DEFAULT || This->class_version == MSXML3))
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*type = This->attr[index].type;
|
|
|
|
*len = SysStringLen(This->attr[index].type);
|
|
|
|
|
|
|
|
return S_OK;
|
2012-03-09 09:55:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXAttributes_getTypeFromName(ISAXAttributes *iface, const WCHAR * pUri, int nUri,
|
|
|
|
const WCHAR * pLocalName, int nLocalName, const WCHAR ** pType, int * nType)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%s:%d %s:%d %p %p): stub\n", This, debugstr_wn(pUri, nUri), nUri,
|
|
|
|
debugstr_wn(pLocalName, nLocalName), nLocalName, pType, nType);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXAttributes_getTypeFromQName(ISAXAttributes *iface, const WCHAR * pQName,
|
|
|
|
int nQName, const WCHAR ** pType, int * nType)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%s:%d %p %p): stub\n", This, debugstr_wn(pQName, nQName), nQName, pType, nType);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-03-14 07:21:05 +01:00
|
|
|
static HRESULT WINAPI SAXAttributes_getValue(ISAXAttributes *iface, int index, const WCHAR **value,
|
|
|
|
int *len)
|
2012-03-09 09:55:03 +01:00
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
2012-03-14 07:21:05 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d %p %p)\n", This, index, value, len);
|
|
|
|
|
|
|
|
if (index >= This->length) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if ((!value || !len) && (This->class_version == MSXML_DEFAULT || This->class_version == MSXML3))
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*value = This->attr[index].value;
|
|
|
|
*len = SysStringLen(This->attr[index].value);
|
|
|
|
|
|
|
|
return S_OK;
|
2012-03-09 09:55:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXAttributes_getValueFromName(ISAXAttributes *iface, const WCHAR * pUri,
|
|
|
|
int nUri, const WCHAR * pLocalName, int nLocalName, const WCHAR ** pValue, int * nValue)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%s:%d %s:%d %p %p): stub\n", This, debugstr_wn(pUri, nUri), nUri,
|
|
|
|
debugstr_wn(pLocalName, nLocalName), nLocalName, pValue, nValue);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SAXAttributes_getValueFromQName(ISAXAttributes *iface, const WCHAR * pQName,
|
|
|
|
int nQName, const WCHAR ** pValue, int * nValue)
|
|
|
|
{
|
|
|
|
mxattributes *This = impl_from_ISAXAttributes( iface );
|
|
|
|
FIXME("(%p)->(%s:%d %p %p): stub\n", This, debugstr_wn(pQName, nQName), nQName, pValue, nValue);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ISAXAttributesVtbl SAXAttributesVtbl = {
|
|
|
|
SAXAttributes_QueryInterface,
|
|
|
|
SAXAttributes_AddRef,
|
|
|
|
SAXAttributes_Release,
|
|
|
|
SAXAttributes_getLength,
|
|
|
|
SAXAttributes_getURI,
|
|
|
|
SAXAttributes_getLocalName,
|
|
|
|
SAXAttributes_getQName,
|
|
|
|
SAXAttributes_getName,
|
|
|
|
SAXAttributes_getIndexFromName,
|
|
|
|
SAXAttributes_getIndexFromQName,
|
|
|
|
SAXAttributes_getType,
|
|
|
|
SAXAttributes_getTypeFromName,
|
|
|
|
SAXAttributes_getTypeFromQName,
|
|
|
|
SAXAttributes_getValue,
|
|
|
|
SAXAttributes_getValueFromName,
|
|
|
|
SAXAttributes_getValueFromQName
|
|
|
|
};
|
|
|
|
|
2012-03-08 21:11:45 +01:00
|
|
|
static const tid_t mxattrs_iface_tids[] = {
|
|
|
|
IMXAttributes_tid,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static dispex_static_data_t mxattrs_dispex = {
|
|
|
|
NULL,
|
|
|
|
IMXAttributes_tid,
|
|
|
|
NULL,
|
|
|
|
mxattrs_iface_tids
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT SAXAttributes_create(MSXML_VERSION version, IUnknown *outer, void **ppObj)
|
|
|
|
{
|
2012-03-13 08:59:53 +01:00
|
|
|
static const int default_count = 10;
|
2012-03-08 21:11:45 +01:00
|
|
|
mxattributes *This;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", outer, ppObj);
|
|
|
|
|
|
|
|
This = heap_alloc( sizeof (*This) );
|
|
|
|
if( !This )
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IMXAttributes_iface.lpVtbl = &MXAttributesVtbl;
|
2012-03-09 09:55:03 +01:00
|
|
|
This->ISAXAttributes_iface.lpVtbl = &SAXAttributesVtbl;
|
2012-03-08 21:11:45 +01:00
|
|
|
This->ref = 1;
|
|
|
|
|
2012-03-13 08:59:53 +01:00
|
|
|
This->class_version = version;
|
|
|
|
|
|
|
|
This->attr = heap_alloc(default_count*sizeof(mxattribute));
|
|
|
|
This->length = 0;
|
|
|
|
This->allocated = default_count;
|
|
|
|
|
2012-03-08 21:11:45 +01:00
|
|
|
*ppObj = &This->IMXAttributes_iface;
|
|
|
|
|
|
|
|
init_dispex(&This->dispex, (IUnknown*)&This->IMXAttributes_iface, &mxattrs_dispex);
|
|
|
|
|
|
|
|
TRACE("returning iface %p\n", *ppObj);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|