2 * MXWriter implementation
4 * Copyright 2011-2012 Nikolay Sivov for CodeWeavers
5 * Copyright 2011 Thomas Mullaly
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 # include <libxml/parser.h>
36 #include "wine/debug.h"
38 #include "msxml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
42 static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
43 static const WCHAR emptyW[] = {0};
44 static const WCHAR spaceW[] = {' '};
45 static const WCHAR quotW[] = {'\"'};
56 OutputBuffer_Native = 0x001,
57 OutputBuffer_Encoded = 0x010,
58 OutputBuffer_Both = 0x100
64 MXWriter_DisableEscaping,
80 unsigned int allocated;
87 encoded_buffer encoded;
94 IMXWriter IMXWriter_iface;
95 ISAXContentHandler ISAXContentHandler_iface;
96 ISAXLexicalHandler ISAXLexicalHandler_iface;
97 ISAXDeclHandler ISAXDeclHandler_iface;
100 MSXML_VERSION class_version;
102 VARIANT_BOOL props[MXWriter_LastProp];
108 BSTR encoding; /* exact property value */
109 xml_encoding xml_enc;
111 /* contains a pending (or not closed yet) element name or NULL if
112 we don't have to close */
118 output_buffer *buffer;
133 IMXAttributes IMXAttributes_iface;
134 ISAXAttributes ISAXAttributes_iface;
137 MSXML_VERSION class_version;
144 static inline mxattributes *impl_from_IMXAttributes( IMXAttributes *iface )
146 return CONTAINING_RECORD(iface, mxattributes, IMXAttributes_iface);
149 static inline mxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface )
151 return CONTAINING_RECORD(iface, mxattributes, ISAXAttributes_iface);
154 static HRESULT mxattributes_grow(mxattributes *This)
156 if (This->length < This->allocated) return S_OK;
158 This->allocated *= 2;
159 This->attr = heap_realloc(This->attr, This->allocated*sizeof(mxattribute));
161 return This->attr ? S_OK : E_OUTOFMEMORY;
164 static xml_encoding parse_encoding_name(const WCHAR *encoding)
166 static const WCHAR utf8W[] = {'U','T','F','-','8',0};
167 if (!strcmpiW(encoding, utf8W)) return XmlEncoding_UTF8;
168 if (!strcmpiW(encoding, utf16W)) return XmlEncoding_UTF16;
169 return XmlEncoding_Unknown;
172 static HRESULT init_encoded_buffer(encoded_buffer *buffer)
174 const int initial_len = 0x2000;
175 buffer->data = heap_alloc(initial_len);
176 if (!buffer->data) return E_OUTOFMEMORY;
178 memset(buffer->data, 0, 4);
179 buffer->allocated = initial_len;
185 static void free_encoded_buffer(encoded_buffer *buffer)
187 heap_free(buffer->data);
190 static HRESULT get_code_page(xml_encoding encoding, UINT *cp)
194 case XmlEncoding_UTF8:
197 case XmlEncoding_UTF16:
201 FIXME("unsupported encoding %d\n", encoding);
208 static HRESULT alloc_output_buffer(xml_encoding encoding, output_buffer **buffer)
213 ret = heap_alloc(sizeof(*ret));
214 if (!ret) return E_OUTOFMEMORY;
216 hr = get_code_page(encoding, &ret->code_page);
222 hr = init_encoded_buffer(&ret->utf16);
228 if (ret->code_page == CP_UTF8) {
229 hr = init_encoded_buffer(&ret->encoded);
231 free_encoded_buffer(&ret->utf16);
237 memset(&ret->encoded, 0, sizeof(ret->encoded));
244 static void free_output_buffer(output_buffer *buffer)
246 free_encoded_buffer(&buffer->encoded);
247 free_encoded_buffer(&buffer->utf16);
251 static void grow_buffer(encoded_buffer *buffer, int length)
253 /* grow if needed, plus 4 bytes to be sure null terminator will fit in */
254 if (buffer->allocated < buffer->written + length + 4)
256 int grown_size = max(2*buffer->allocated, buffer->allocated + length);
257 buffer->data = heap_realloc(buffer->data, grown_size);
258 buffer->allocated = grown_size;
262 static HRESULT write_output_buffer_mode(output_buffer *buffer, output_mode mode, const WCHAR *data, int len)
267 if (mode & (OutputBuffer_Encoded | OutputBuffer_Both)) {
268 if (buffer->code_page == CP_UTF8)
270 length = WideCharToMultiByte(buffer->code_page, 0, data, len, NULL, 0, NULL, NULL);
271 grow_buffer(&buffer->encoded, length);
272 ptr = buffer->encoded.data + buffer->encoded.written;
273 length = WideCharToMultiByte(buffer->code_page, 0, data, len, ptr, length, NULL, NULL);
274 buffer->encoded.written += len == -1 ? length-1 : length;
278 if (mode & (OutputBuffer_Native | OutputBuffer_Both)) {
279 /* WCHAR data just copied */
280 length = len == -1 ? strlenW(data) : len;
283 length *= sizeof(WCHAR);
285 grow_buffer(&buffer->utf16, length);
286 ptr = buffer->utf16.data + buffer->utf16.written;
288 memcpy(ptr, data, length);
289 buffer->utf16.written += length;
291 /* null termination */
292 memset(ptr, 0, sizeof(WCHAR));
299 static HRESULT write_output_buffer(output_buffer *buffer, const WCHAR *data, int len)
301 return write_output_buffer_mode(buffer, OutputBuffer_Both, data, len);
304 static HRESULT write_output_buffer_quoted(output_buffer *buffer, const WCHAR *data, int len)
306 write_output_buffer(buffer, quotW, 1);
307 write_output_buffer(buffer, data, len);
308 write_output_buffer(buffer, quotW, 1);
313 /* frees buffer data, reallocates with a default lengths */
314 static void close_output_buffer(mxwriter *This)
316 heap_free(This->buffer->utf16.data);
317 heap_free(This->buffer->encoded.data);
318 init_encoded_buffer(&This->buffer->utf16);
319 init_encoded_buffer(&This->buffer->encoded);
320 get_code_page(This->xml_enc, &This->buffer->code_page);
323 /* escapes special characters like:
329 static WCHAR *get_escaped_string(const WCHAR *str, escape_mode mode, int *len)
331 static const WCHAR ltW[] = {'&','l','t',';'};
332 static const WCHAR ampW[] = {'&','a','m','p',';'};
333 static const WCHAR equotW[] = {'&','q','u','o','t',';'};
334 static const WCHAR gtW[] = {'&','g','t',';'};
336 const int default_alloc = 100;
337 const int grow_thresh = 10;
338 int p = *len, conv_len;
341 /* default buffer size to something if length is unknown */
342 conv_len = *len == -1 ? default_alloc : max(2**len, default_alloc);
343 ptr = ret = heap_alloc(conv_len*sizeof(WCHAR));
347 if (ptr - ret > conv_len - grow_thresh)
349 int written = ptr - ret;
351 ptr = ret = heap_realloc(ret, conv_len*sizeof(WCHAR));
358 memcpy(ptr, ltW, sizeof(ltW));
359 ptr += sizeof(ltW)/sizeof(WCHAR);
362 memcpy(ptr, ampW, sizeof(ampW));
363 ptr += sizeof(ampW)/sizeof(WCHAR);
366 memcpy(ptr, gtW, sizeof(gtW));
367 ptr += sizeof(gtW)/sizeof(WCHAR);
370 if (mode == EscapeValue)
372 memcpy(ptr, equotW, sizeof(equotW));
373 ptr += sizeof(equotW)/sizeof(WCHAR);
376 /* fallthrough for text mode */
386 if (*len != -1) *len = ptr-ret;
392 static void write_prolog_buffer(const mxwriter *This)
394 static const WCHAR versionW[] = {'<','?','x','m','l',' ','v','e','r','s','i','o','n','='};
395 static const WCHAR encodingW[] = {' ','e','n','c','o','d','i','n','g','=','\"'};
396 static const WCHAR standaloneW[] = {' ','s','t','a','n','d','a','l','o','n','e','=','\"'};
397 static const WCHAR yesW[] = {'y','e','s','\"','?','>'};
398 static const WCHAR noW[] = {'n','o','\"','?','>'};
399 static const WCHAR crlfW[] = {'\r','\n'};
402 write_output_buffer(This->buffer, versionW, sizeof(versionW)/sizeof(WCHAR));
403 write_output_buffer_quoted(This->buffer, This->version, -1);
406 write_output_buffer(This->buffer, encodingW, sizeof(encodingW)/sizeof(WCHAR));
408 /* always write UTF-16 to WCHAR buffer */
409 write_output_buffer_mode(This->buffer, OutputBuffer_Native, utf16W, sizeof(utf16W)/sizeof(WCHAR) - 1);
410 write_output_buffer_mode(This->buffer, OutputBuffer_Encoded, This->encoding, -1);
411 write_output_buffer(This->buffer, quotW, 1);
414 write_output_buffer(This->buffer, standaloneW, sizeof(standaloneW)/sizeof(WCHAR));
415 if (This->props[MXWriter_Standalone] == VARIANT_TRUE)
416 write_output_buffer(This->buffer, yesW, sizeof(yesW)/sizeof(WCHAR));
418 write_output_buffer(This->buffer, noW, sizeof(noW)/sizeof(WCHAR));
420 write_output_buffer(This->buffer, crlfW, sizeof(crlfW)/sizeof(WCHAR));
423 /* Attempts to the write data from the mxwriter's buffer to
424 * the destination stream (if there is one).
426 static HRESULT write_data_to_stream(mxwriter *This)
428 encoded_buffer *buffer;
435 if (This->xml_enc != XmlEncoding_UTF16)
436 buffer = &This->buffer->encoded;
438 buffer = &This->buffer->utf16;
440 if (This->dest_written > buffer->written) {
441 ERR("Failed sanity check! Not sure what to do... (%d > %d)\n", This->dest_written, buffer->written);
443 } else if (This->dest_written == buffer->written && This->xml_enc != XmlEncoding_UTF8)
444 /* Windows seems to make an empty write call when the encoding is UTF-8 and
445 * all the data has been written to the stream. It doesn't seem make this call
446 * for any other encodings.
450 /* Write the current content from the output buffer into 'dest'.
451 * TODO: Check what Windows does if the IStream doesn't write all of
452 * the data we give it at once.
454 hr = IStream_Write(This->dest, buffer->data+This->dest_written,
455 buffer->written-This->dest_written, &written);
457 WARN("Failed to write data to IStream (0x%08x)\n", hr);
461 This->dest_written += written;
465 /* Newly added element start tag left unclosed cause for empty elements
466 we have to close it differently. */
467 static void close_element_starttag(const mxwriter *This)
469 static const WCHAR gtW[] = {'>'};
470 if (!This->element) return;
471 write_output_buffer(This->buffer, gtW, 1);
474 static void set_element_name(mxwriter *This, const WCHAR *name, int len)
476 SysFreeString(This->element);
477 This->element = name ? SysAllocStringLen(name, len) : NULL;
480 static inline HRESULT flush_output_buffer(mxwriter *This)
482 close_element_starttag(This);
483 set_element_name(This, NULL, 0);
485 return write_data_to_stream(This);
488 /* Resets the mxwriter's output buffer by closing it, then creating a new
489 * output buffer using the given encoding.
491 static inline void reset_output_buffer(mxwriter *This)
493 close_output_buffer(This);
494 This->dest_written = 0;
497 static HRESULT writer_set_property(mxwriter *writer, mxwriter_prop property, VARIANT_BOOL value)
499 writer->props[property] = value;
500 writer->prop_changed = TRUE;
504 static HRESULT writer_get_property(const mxwriter *writer, mxwriter_prop property, VARIANT_BOOL *value)
506 if (!value) return E_POINTER;
507 *value = writer->props[property];
511 static inline mxwriter *impl_from_IMXWriter(IMXWriter *iface)
513 return CONTAINING_RECORD(iface, mxwriter, IMXWriter_iface);
516 static inline mxwriter *impl_from_ISAXContentHandler(ISAXContentHandler *iface)
518 return CONTAINING_RECORD(iface, mxwriter, ISAXContentHandler_iface);
521 static inline mxwriter *impl_from_ISAXLexicalHandler(ISAXLexicalHandler *iface)
523 return CONTAINING_RECORD(iface, mxwriter, ISAXLexicalHandler_iface);
526 static inline mxwriter *impl_from_ISAXDeclHandler(ISAXDeclHandler *iface)
528 return CONTAINING_RECORD(iface, mxwriter, ISAXDeclHandler_iface);
531 static HRESULT WINAPI mxwriter_QueryInterface(IMXWriter *iface, REFIID riid, void **obj)
533 mxwriter *This = impl_from_IMXWriter( iface );
535 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
539 if ( IsEqualGUID( riid, &IID_IMXWriter ) ||
540 IsEqualGUID( riid, &IID_IDispatch ) ||
541 IsEqualGUID( riid, &IID_IUnknown ) )
543 *obj = &This->IMXWriter_iface;
545 else if ( IsEqualGUID( riid, &IID_ISAXContentHandler ) )
547 *obj = &This->ISAXContentHandler_iface;
549 else if ( IsEqualGUID( riid, &IID_ISAXLexicalHandler ) )
551 *obj = &This->ISAXLexicalHandler_iface;
553 else if ( IsEqualGUID( riid, &IID_ISAXDeclHandler ) )
555 *obj = &This->ISAXDeclHandler_iface;
557 else if (dispex_query_interface(&This->dispex, riid, obj))
559 return *obj ? S_OK : E_NOINTERFACE;
563 ERR("interface %s not implemented\n", debugstr_guid(riid));
565 return E_NOINTERFACE;
568 IMXWriter_AddRef(iface);
572 static ULONG WINAPI mxwriter_AddRef(IMXWriter *iface)
574 mxwriter *This = impl_from_IMXWriter( iface );
575 LONG ref = InterlockedIncrement(&This->ref);
577 TRACE("(%p)->(%d)\n", This, ref);
582 static ULONG WINAPI mxwriter_Release(IMXWriter *iface)
584 mxwriter *This = impl_from_IMXWriter( iface );
585 ULONG ref = InterlockedDecrement(&This->ref);
587 TRACE("(%p)->(%d)\n", This, ref);
591 /* Windows flushes the buffer when the interface is destroyed. */
592 flush_output_buffer(This);
593 free_output_buffer(This->buffer);
595 if (This->dest) IStream_Release(This->dest);
596 SysFreeString(This->version);
597 SysFreeString(This->encoding);
599 SysFreeString(This->element);
600 release_dispex(&This->dispex);
607 static HRESULT WINAPI mxwriter_GetTypeInfoCount(IMXWriter *iface, UINT* pctinfo)
609 mxwriter *This = impl_from_IMXWriter( iface );
610 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
613 static HRESULT WINAPI mxwriter_GetTypeInfo(
615 UINT iTInfo, LCID lcid,
616 ITypeInfo** ppTInfo )
618 mxwriter *This = impl_from_IMXWriter( iface );
619 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
620 iTInfo, lcid, ppTInfo);
623 static HRESULT WINAPI mxwriter_GetIDsOfNames(
625 REFIID riid, LPOLESTR* rgszNames,
626 UINT cNames, LCID lcid, DISPID* rgDispId )
628 mxwriter *This = impl_from_IMXWriter( iface );
629 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
630 riid, rgszNames, cNames, lcid, rgDispId);
633 static HRESULT WINAPI mxwriter_Invoke(
635 DISPID dispIdMember, REFIID riid, LCID lcid,
636 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
637 EXCEPINFO* pExcepInfo, UINT* puArgErr )
639 mxwriter *This = impl_from_IMXWriter( iface );
640 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
641 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
644 static HRESULT WINAPI mxwriter_put_output(IMXWriter *iface, VARIANT dest)
646 mxwriter *This = impl_from_IMXWriter( iface );
649 TRACE("(%p)->(%s)\n", This, debugstr_variant(&dest));
651 hr = flush_output_buffer(This);
659 if (This->dest) IStream_Release(This->dest);
661 reset_output_buffer(This);
668 hr = IUnknown_QueryInterface(V_UNKNOWN(&dest), &IID_IStream, (void**)&stream);
671 /* Recreate the output buffer to make sure it's using the correct encoding. */
672 reset_output_buffer(This);
674 if (This->dest) IStream_Release(This->dest);
679 FIXME("unhandled interface type for VT_UNKNOWN destination\n");
683 FIXME("unhandled destination type %s\n", debugstr_variant(&dest));
690 static HRESULT WINAPI mxwriter_get_output(IMXWriter *iface, VARIANT *dest)
692 mxwriter *This = impl_from_IMXWriter( iface );
694 TRACE("(%p)->(%p)\n", This, dest);
698 HRESULT hr = flush_output_buffer(This);
702 V_VT(dest) = VT_BSTR;
703 V_BSTR(dest) = SysAllocString((WCHAR*)This->buffer->utf16.data);
708 FIXME("not implemented when stream is set up\n");
713 static HRESULT WINAPI mxwriter_put_encoding(IMXWriter *iface, BSTR encoding)
715 mxwriter *This = impl_from_IMXWriter( iface );
719 TRACE("(%p)->(%s)\n", This, debugstr_w(encoding));
721 enc = parse_encoding_name(encoding);
722 if (enc == XmlEncoding_Unknown)
724 FIXME("unsupported encoding %s\n", debugstr_w(encoding));
728 hr = flush_output_buffer(This);
732 SysReAllocString(&This->encoding, encoding);
735 TRACE("got encoding %d\n", This->xml_enc);
736 reset_output_buffer(This);
740 static HRESULT WINAPI mxwriter_get_encoding(IMXWriter *iface, BSTR *encoding)
742 mxwriter *This = impl_from_IMXWriter( iface );
744 TRACE("(%p)->(%p)\n", This, encoding);
746 if (!encoding) return E_POINTER;
748 *encoding = SysAllocString(This->encoding);
749 if (!*encoding) return E_OUTOFMEMORY;
754 static HRESULT WINAPI mxwriter_put_byteOrderMark(IMXWriter *iface, VARIANT_BOOL value)
756 mxwriter *This = impl_from_IMXWriter( iface );
758 TRACE("(%p)->(%d)\n", This, value);
759 return writer_set_property(This, MXWriter_BOM, value);
762 static HRESULT WINAPI mxwriter_get_byteOrderMark(IMXWriter *iface, VARIANT_BOOL *value)
764 mxwriter *This = impl_from_IMXWriter( iface );
766 TRACE("(%p)->(%p)\n", This, value);
767 return writer_get_property(This, MXWriter_BOM, value);
770 static HRESULT WINAPI mxwriter_put_indent(IMXWriter *iface, VARIANT_BOOL value)
772 mxwriter *This = impl_from_IMXWriter( iface );
774 TRACE("(%p)->(%d)\n", This, value);
775 return writer_set_property(This, MXWriter_Indent, value);
778 static HRESULT WINAPI mxwriter_get_indent(IMXWriter *iface, VARIANT_BOOL *value)
780 mxwriter *This = impl_from_IMXWriter( iface );
782 TRACE("(%p)->(%p)\n", This, value);
783 return writer_get_property(This, MXWriter_Indent, value);
786 static HRESULT WINAPI mxwriter_put_standalone(IMXWriter *iface, VARIANT_BOOL value)
788 mxwriter *This = impl_from_IMXWriter( iface );
790 TRACE("(%p)->(%d)\n", This, value);
791 return writer_set_property(This, MXWriter_Standalone, value);
794 static HRESULT WINAPI mxwriter_get_standalone(IMXWriter *iface, VARIANT_BOOL *value)
796 mxwriter *This = impl_from_IMXWriter( iface );
798 TRACE("(%p)->(%p)\n", This, value);
799 return writer_get_property(This, MXWriter_Standalone, value);
802 static HRESULT WINAPI mxwriter_put_omitXMLDeclaration(IMXWriter *iface, VARIANT_BOOL value)
804 mxwriter *This = impl_from_IMXWriter( iface );
806 TRACE("(%p)->(%d)\n", This, value);
807 return writer_set_property(This, MXWriter_OmitXmlDecl, value);
810 static HRESULT WINAPI mxwriter_get_omitXMLDeclaration(IMXWriter *iface, VARIANT_BOOL *value)
812 mxwriter *This = impl_from_IMXWriter( iface );
814 TRACE("(%p)->(%p)\n", This, value);
815 return writer_get_property(This, MXWriter_OmitXmlDecl, value);
818 static HRESULT WINAPI mxwriter_put_version(IMXWriter *iface, BSTR version)
820 mxwriter *This = impl_from_IMXWriter( iface );
822 TRACE("(%p)->(%s)\n", This, debugstr_w(version));
824 if (!version) return E_INVALIDARG;
826 SysFreeString(This->version);
827 This->version = SysAllocString(version);
832 static HRESULT WINAPI mxwriter_get_version(IMXWriter *iface, BSTR *version)
834 mxwriter *This = impl_from_IMXWriter( iface );
836 TRACE("(%p)->(%p)\n", This, version);
838 if (!version) return E_POINTER;
840 return return_bstr(This->version, version);
843 static HRESULT WINAPI mxwriter_put_disableOutputEscaping(IMXWriter *iface, VARIANT_BOOL value)
845 mxwriter *This = impl_from_IMXWriter( iface );
847 TRACE("(%p)->(%d)\n", This, value);
848 return writer_set_property(This, MXWriter_DisableEscaping, value);
851 static HRESULT WINAPI mxwriter_get_disableOutputEscaping(IMXWriter *iface, VARIANT_BOOL *value)
853 mxwriter *This = impl_from_IMXWriter( iface );
855 TRACE("(%p)->(%p)\n", This, value);
856 return writer_get_property(This, MXWriter_DisableEscaping, value);
859 static HRESULT WINAPI mxwriter_flush(IMXWriter *iface)
861 mxwriter *This = impl_from_IMXWriter( iface );
862 TRACE("(%p)\n", This);
863 return flush_output_buffer(This);
866 static const struct IMXWriterVtbl MXWriterVtbl =
868 mxwriter_QueryInterface,
871 mxwriter_GetTypeInfoCount,
872 mxwriter_GetTypeInfo,
873 mxwriter_GetIDsOfNames,
877 mxwriter_put_encoding,
878 mxwriter_get_encoding,
879 mxwriter_put_byteOrderMark,
880 mxwriter_get_byteOrderMark,
883 mxwriter_put_standalone,
884 mxwriter_get_standalone,
885 mxwriter_put_omitXMLDeclaration,
886 mxwriter_get_omitXMLDeclaration,
887 mxwriter_put_version,
888 mxwriter_get_version,
889 mxwriter_put_disableOutputEscaping,
890 mxwriter_get_disableOutputEscaping,
894 /*** ISAXContentHandler ***/
895 static HRESULT WINAPI SAXContentHandler_QueryInterface(
896 ISAXContentHandler *iface,
900 mxwriter *This = impl_from_ISAXContentHandler( iface );
901 return IMXWriter_QueryInterface(&This->IMXWriter_iface, riid, obj);
904 static ULONG WINAPI SAXContentHandler_AddRef(ISAXContentHandler *iface)
906 mxwriter *This = impl_from_ISAXContentHandler( iface );
907 return IMXWriter_AddRef(&This->IMXWriter_iface);
910 static ULONG WINAPI SAXContentHandler_Release(ISAXContentHandler *iface)
912 mxwriter *This = impl_from_ISAXContentHandler( iface );
913 return IMXWriter_Release(&This->IMXWriter_iface);
916 static HRESULT WINAPI SAXContentHandler_putDocumentLocator(
917 ISAXContentHandler *iface,
918 ISAXLocator *locator)
920 mxwriter *This = impl_from_ISAXContentHandler( iface );
921 FIXME("(%p)->(%p)\n", This, locator);
925 static HRESULT WINAPI SAXContentHandler_startDocument(ISAXContentHandler *iface)
927 mxwriter *This = impl_from_ISAXContentHandler( iface );
929 TRACE("(%p)\n", This);
931 /* If properties have been changed since the last "endDocument" call
932 * we need to reset the output buffer. If we don't the output buffer
933 * could end up with multiple XML documents in it, plus this seems to
934 * be how Windows works.
936 if (This->prop_changed) {
937 reset_output_buffer(This);
938 This->prop_changed = FALSE;
941 if (This->props[MXWriter_OmitXmlDecl] == VARIANT_TRUE) return S_OK;
943 write_prolog_buffer(This);
945 if (This->dest && This->xml_enc == XmlEncoding_UTF16) {
946 static const char utf16BOM[] = {0xff,0xfe};
948 if (This->props[MXWriter_BOM] == VARIANT_TRUE)
949 /* Windows passes a NULL pointer as the pcbWritten parameter and
950 * ignores any error codes returned from this Write call.
952 IStream_Write(This->dest, utf16BOM, sizeof(utf16BOM), NULL);
958 static HRESULT WINAPI SAXContentHandler_endDocument(ISAXContentHandler *iface)
960 mxwriter *This = impl_from_ISAXContentHandler( iface );
961 TRACE("(%p)\n", This);
962 This->prop_changed = FALSE;
963 return flush_output_buffer(This);
966 static HRESULT WINAPI SAXContentHandler_startPrefixMapping(
967 ISAXContentHandler *iface,
973 mxwriter *This = impl_from_ISAXContentHandler( iface );
974 FIXME("(%p)->(%s %s)\n", This, debugstr_wn(prefix, nprefix), debugstr_wn(uri, nuri));
978 static HRESULT WINAPI SAXContentHandler_endPrefixMapping(
979 ISAXContentHandler *iface,
983 mxwriter *This = impl_from_ISAXContentHandler( iface );
984 FIXME("(%p)->(%s)\n", This, debugstr_wn(prefix, nprefix));
988 static HRESULT WINAPI SAXContentHandler_startElement(
989 ISAXContentHandler *iface,
990 const WCHAR *namespaceUri,
992 const WCHAR *local_name,
996 ISAXAttributes *attr)
998 mxwriter *This = impl_from_ISAXContentHandler( iface );
999 static const WCHAR ltW[] = {'<'};
1001 TRACE("(%p)->(%s %s %s %p)\n", This, debugstr_wn(namespaceUri, nnamespaceUri),
1002 debugstr_wn(local_name, nlocal_name), debugstr_wn(QName, nQName), attr);
1004 if ((!namespaceUri || !local_name || !QName) && This->class_version != MSXML6)
1005 return E_INVALIDARG;
1007 close_element_starttag(This);
1008 set_element_name(This, QName ? QName : emptyW,
1009 QName ? nQName : 0);
1011 write_output_buffer(This->buffer, ltW, 1);
1012 write_output_buffer(This->buffer, QName, nQName);
1020 hr = ISAXAttributes_getLength(attr, &length);
1021 if (FAILED(hr)) return hr;
1023 for (i = 0; i < length; i++)
1025 static const WCHAR eqW[] = {'='};
1030 hr = ISAXAttributes_getQName(attr, i, &str, &len);
1031 if (FAILED(hr)) return hr;
1033 /* space separator in front of every attribute */
1034 write_output_buffer(This->buffer, spaceW, 1);
1035 write_output_buffer(This->buffer, str, len);
1037 write_output_buffer(This->buffer, eqW, 1);
1040 hr = ISAXAttributes_getValue(attr, i, &str, &len);
1041 if (FAILED(hr)) return hr;
1043 escaped = get_escaped_string(str, EscapeValue, &len);
1044 write_output_buffer_quoted(This->buffer, escaped, len);
1052 static HRESULT WINAPI SAXContentHandler_endElement(
1053 ISAXContentHandler *iface,
1054 const WCHAR *namespaceUri,
1056 const WCHAR * local_name,
1061 mxwriter *This = impl_from_ISAXContentHandler( iface );
1063 TRACE("(%p)->(%s:%d %s:%d %s:%d)\n", This, debugstr_wn(namespaceUri, nnamespaceUri), nnamespaceUri,
1064 debugstr_wn(local_name, nlocal_name), nlocal_name, debugstr_wn(QName, nQName), nQName);
1066 if ((!namespaceUri || !local_name || !QName) && This->class_version != MSXML6)
1067 return E_INVALIDARG;
1069 if (This->element && QName && !strncmpW(This->element, QName, nQName))
1071 static const WCHAR closeW[] = {'/','>'};
1073 write_output_buffer(This->buffer, closeW, 2);
1077 static const WCHAR closetagW[] = {'<','/'};
1078 static const WCHAR gtW[] = {'>'};
1080 write_output_buffer(This->buffer, closetagW, 2);
1081 write_output_buffer(This->buffer, QName, nQName);
1082 write_output_buffer(This->buffer, gtW, 1);
1085 set_element_name(This, NULL, 0);
1090 static HRESULT WINAPI SAXContentHandler_characters(
1091 ISAXContentHandler *iface,
1095 mxwriter *This = impl_from_ISAXContentHandler( iface );
1097 TRACE("(%p)->(%s:%d)\n", This, debugstr_wn(chars, nchars), nchars);
1099 if (!chars) return E_INVALIDARG;
1101 close_element_starttag(This);
1102 set_element_name(This, NULL, 0);
1107 write_output_buffer(This->buffer, chars, nchars);
1113 escaped = get_escaped_string(chars, EscapeText, &len);
1114 write_output_buffer(This->buffer, escaped, len);
1122 static HRESULT WINAPI SAXContentHandler_ignorableWhitespace(
1123 ISAXContentHandler *iface,
1127 mxwriter *This = impl_from_ISAXContentHandler( iface );
1128 FIXME("(%p)->(%s)\n", This, debugstr_wn(chars, nchars));
1132 static HRESULT WINAPI SAXContentHandler_processingInstruction(
1133 ISAXContentHandler *iface,
1134 const WCHAR *target,
1139 mxwriter *This = impl_from_ISAXContentHandler( iface );
1140 FIXME("(%p)->(%s %s)\n", This, debugstr_wn(target, ntarget), debugstr_wn(data, ndata));
1144 static HRESULT WINAPI SAXContentHandler_skippedEntity(
1145 ISAXContentHandler *iface,
1149 mxwriter *This = impl_from_ISAXContentHandler( iface );
1150 FIXME("(%p)->(%s)\n", This, debugstr_wn(name, nname));
1154 static const struct ISAXContentHandlerVtbl SAXContentHandlerVtbl =
1156 SAXContentHandler_QueryInterface,
1157 SAXContentHandler_AddRef,
1158 SAXContentHandler_Release,
1159 SAXContentHandler_putDocumentLocator,
1160 SAXContentHandler_startDocument,
1161 SAXContentHandler_endDocument,
1162 SAXContentHandler_startPrefixMapping,
1163 SAXContentHandler_endPrefixMapping,
1164 SAXContentHandler_startElement,
1165 SAXContentHandler_endElement,
1166 SAXContentHandler_characters,
1167 SAXContentHandler_ignorableWhitespace,
1168 SAXContentHandler_processingInstruction,
1169 SAXContentHandler_skippedEntity
1172 /*** ISAXLexicalHandler ***/
1173 static HRESULT WINAPI SAXLexicalHandler_QueryInterface(ISAXLexicalHandler *iface,
1174 REFIID riid, void **obj)
1176 mxwriter *This = impl_from_ISAXLexicalHandler( iface );
1177 return IMXWriter_QueryInterface(&This->IMXWriter_iface, riid, obj);
1180 static ULONG WINAPI SAXLexicalHandler_AddRef(ISAXLexicalHandler *iface)
1182 mxwriter *This = impl_from_ISAXLexicalHandler( iface );
1183 return IMXWriter_AddRef(&This->IMXWriter_iface);
1186 static ULONG WINAPI SAXLexicalHandler_Release(ISAXLexicalHandler *iface)
1188 mxwriter *This = impl_from_ISAXLexicalHandler( iface );
1189 return IMXWriter_Release(&This->IMXWriter_iface);
1192 static HRESULT WINAPI SAXLexicalHandler_startDTD(ISAXLexicalHandler *iface,
1193 const WCHAR *name, int name_len, const WCHAR *publicId, int publicId_len,
1194 const WCHAR *systemId, int systemId_len)
1196 static const WCHAR doctypeW[] = {'<','!','D','O','C','T','Y','P','E',' '};
1197 static const WCHAR openintW[] = {'[','\r','\n'};
1199 mxwriter *This = impl_from_ISAXLexicalHandler( iface );
1201 TRACE("(%p)->(%s %s %s)\n", This, debugstr_wn(name, name_len), debugstr_wn(publicId, publicId_len),
1202 debugstr_wn(systemId, systemId_len));
1204 if (!name) return E_INVALIDARG;
1206 write_output_buffer(This->buffer, doctypeW, sizeof(doctypeW)/sizeof(WCHAR));
1210 write_output_buffer(This->buffer, name, name_len);
1211 write_output_buffer(This->buffer, spaceW, 1);
1216 static const WCHAR publicW[] = {'P','U','B','L','I','C',' '};
1218 write_output_buffer(This->buffer, publicW, sizeof(publicW)/sizeof(WCHAR));
1219 write_output_buffer_quoted(This->buffer, publicId, publicId_len);
1221 if (!systemId) return E_INVALIDARG;
1224 write_output_buffer(This->buffer, spaceW, 1);
1226 write_output_buffer_quoted(This->buffer, systemId, systemId_len);
1229 write_output_buffer(This->buffer, spaceW, 1);
1233 static const WCHAR systemW[] = {'S','Y','S','T','E','M',' '};
1235 write_output_buffer(This->buffer, systemW, sizeof(systemW)/sizeof(WCHAR));
1236 write_output_buffer_quoted(This->buffer, systemId, systemId_len);
1238 write_output_buffer(This->buffer, spaceW, 1);
1241 write_output_buffer(This->buffer, openintW, sizeof(openintW)/sizeof(WCHAR));
1246 static HRESULT WINAPI SAXLexicalHandler_endDTD(ISAXLexicalHandler *iface)
1248 mxwriter *This = impl_from_ISAXLexicalHandler( iface );
1249 static const WCHAR closedtdW[] = {']','>','\r','\n'};
1251 TRACE("(%p)\n", This);
1253 write_output_buffer(This->buffer, closedtdW, sizeof(closedtdW)/sizeof(WCHAR));
1258 static HRESULT WINAPI SAXLexicalHandler_startEntity(ISAXLexicalHandler *iface, const WCHAR *name, int len)
1260 mxwriter *This = impl_from_ISAXLexicalHandler( iface );
1261 FIXME("(%p)->(%s): stub\n", This, debugstr_wn(name, len));
1265 static HRESULT WINAPI SAXLexicalHandler_endEntity(ISAXLexicalHandler *iface, const WCHAR *name, int len)
1267 mxwriter *This = impl_from_ISAXLexicalHandler( iface );
1268 FIXME("(%p)->(%s): stub\n", This, debugstr_wn(name, len));
1272 static HRESULT WINAPI SAXLexicalHandler_startCDATA(ISAXLexicalHandler *iface)
1274 static const WCHAR scdataW[] = {'<','!','[','C','D','A','T','A','['};
1275 mxwriter *This = impl_from_ISAXLexicalHandler( iface );
1277 TRACE("(%p)\n", This);
1279 write_output_buffer(This->buffer, scdataW, sizeof(scdataW)/sizeof(WCHAR));
1285 static HRESULT WINAPI SAXLexicalHandler_endCDATA(ISAXLexicalHandler *iface)
1287 mxwriter *This = impl_from_ISAXLexicalHandler( iface );
1288 static const WCHAR ecdataW[] = {']',']','>'};
1290 TRACE("(%p)\n", This);
1292 write_output_buffer(This->buffer, ecdataW, sizeof(ecdataW)/sizeof(WCHAR));
1293 This->cdata = FALSE;
1298 static HRESULT WINAPI SAXLexicalHandler_comment(ISAXLexicalHandler *iface, const WCHAR *chars, int nchars)
1300 mxwriter *This = impl_from_ISAXLexicalHandler( iface );
1301 static const WCHAR copenW[] = {'<','!','-','-'};
1302 static const WCHAR ccloseW[] = {'-','-','>','\r','\n'};
1304 TRACE("(%p)->(%s:%d)\n", This, debugstr_wn(chars, nchars), nchars);
1306 if (!chars) return E_INVALIDARG;
1308 close_element_starttag(This);
1310 write_output_buffer(This->buffer, copenW, sizeof(copenW)/sizeof(WCHAR));
1312 write_output_buffer(This->buffer, chars, nchars);
1313 write_output_buffer(This->buffer, ccloseW, sizeof(ccloseW)/sizeof(WCHAR));
1318 static const struct ISAXLexicalHandlerVtbl SAXLexicalHandlerVtbl =
1320 SAXLexicalHandler_QueryInterface,
1321 SAXLexicalHandler_AddRef,
1322 SAXLexicalHandler_Release,
1323 SAXLexicalHandler_startDTD,
1324 SAXLexicalHandler_endDTD,
1325 SAXLexicalHandler_startEntity,
1326 SAXLexicalHandler_endEntity,
1327 SAXLexicalHandler_startCDATA,
1328 SAXLexicalHandler_endCDATA,
1329 SAXLexicalHandler_comment
1332 /*** ISAXDeclHandler ***/
1333 static HRESULT WINAPI SAXDeclHandler_QueryInterface(ISAXDeclHandler *iface,
1334 REFIID riid, void **obj)
1336 mxwriter *This = impl_from_ISAXDeclHandler( iface );
1337 return IMXWriter_QueryInterface(&This->IMXWriter_iface, riid, obj);
1340 static ULONG WINAPI SAXDeclHandler_AddRef(ISAXDeclHandler *iface)
1342 mxwriter *This = impl_from_ISAXDeclHandler( iface );
1343 return IMXWriter_AddRef(&This->IMXWriter_iface);
1346 static ULONG WINAPI SAXDeclHandler_Release(ISAXDeclHandler *iface)
1348 mxwriter *This = impl_from_ISAXDeclHandler( iface );
1349 return IMXWriter_Release(&This->IMXWriter_iface);
1352 static HRESULT WINAPI SAXDeclHandler_elementDecl(ISAXDeclHandler *iface,
1353 const WCHAR *name, int n_name, const WCHAR *model, int n_model)
1355 static const WCHAR elementW[] = {'<','!','E','L','E','M','E','N','T',' '};
1356 static const WCHAR closeelementW[] = {'>','\r','\n'};
1357 mxwriter *This = impl_from_ISAXDeclHandler( iface );
1359 TRACE("(%p)->(%s:%d %s:%d)\n", This, debugstr_wn(name, n_name), n_name,
1360 debugstr_wn(model, n_model), n_model);
1362 if (!name || !model) return E_INVALIDARG;
1364 write_output_buffer(This->buffer, elementW, sizeof(elementW)/sizeof(WCHAR));
1366 write_output_buffer(This->buffer, name, n_name);
1367 write_output_buffer(This->buffer, spaceW, sizeof(spaceW)/sizeof(WCHAR));
1370 write_output_buffer(This->buffer, model, n_model);
1371 write_output_buffer(This->buffer, closeelementW, sizeof(closeelementW)/sizeof(WCHAR));
1376 static HRESULT WINAPI SAXDeclHandler_attributeDecl(ISAXDeclHandler *iface,
1377 const WCHAR *element, int n_element, const WCHAR *attr, int n_attr,
1378 const WCHAR *type, int n_type, const WCHAR *Default, int n_default,
1379 const WCHAR *value, int n_value)
1381 mxwriter *This = impl_from_ISAXDeclHandler( iface );
1382 FIXME("(%p)->(%s:%d %s:%d %s:%d %s:%d %s:%d): stub\n", This, debugstr_wn(element, n_element), n_element,
1383 debugstr_wn(attr, n_attr), n_attr, debugstr_wn(type, n_type), n_type, debugstr_wn(Default, n_default), n_default,
1384 debugstr_wn(value, n_value), n_value);
1388 static HRESULT WINAPI SAXDeclHandler_internalEntityDecl(ISAXDeclHandler *iface,
1389 const WCHAR *name, int n_name, const WCHAR *value, int n_value)
1391 mxwriter *This = impl_from_ISAXDeclHandler( iface );
1392 FIXME("(%p)->(%s:%d %s:%d): stub\n", This, debugstr_wn(name, n_name), n_name,
1393 debugstr_wn(value, n_value), n_value);
1397 static HRESULT WINAPI SAXDeclHandler_externalEntityDecl(ISAXDeclHandler *iface,
1398 const WCHAR *name, int n_name, const WCHAR *publicId, int n_publicId,
1399 const WCHAR *systemId, int n_systemId)
1401 mxwriter *This = impl_from_ISAXDeclHandler( iface );
1402 FIXME("(%p)->(%s:%d %s:%d %s:%d): stub\n", This, debugstr_wn(name, n_name), n_name,
1403 debugstr_wn(publicId, n_publicId), n_publicId, debugstr_wn(systemId, n_systemId), n_systemId);
1407 static const ISAXDeclHandlerVtbl SAXDeclHandlerVtbl = {
1408 SAXDeclHandler_QueryInterface,
1409 SAXDeclHandler_AddRef,
1410 SAXDeclHandler_Release,
1411 SAXDeclHandler_elementDecl,
1412 SAXDeclHandler_attributeDecl,
1413 SAXDeclHandler_internalEntityDecl,
1414 SAXDeclHandler_externalEntityDecl
1417 static const tid_t mxwriter_iface_tids[] = {
1422 static dispex_static_data_t mxwriter_dispex = {
1429 HRESULT MXWriter_create(MSXML_VERSION version, IUnknown *outer, void **ppObj)
1431 static const WCHAR version10W[] = {'1','.','0',0};
1435 TRACE("(%p, %p)\n", outer, ppObj);
1437 if (outer) FIXME("support aggregation, outer\n");
1439 This = heap_alloc( sizeof (*This) );
1441 return E_OUTOFMEMORY;
1443 This->IMXWriter_iface.lpVtbl = &MXWriterVtbl;
1444 This->ISAXContentHandler_iface.lpVtbl = &SAXContentHandlerVtbl;
1445 This->ISAXLexicalHandler_iface.lpVtbl = &SAXLexicalHandlerVtbl;
1446 This->ISAXDeclHandler_iface.lpVtbl = &SAXDeclHandlerVtbl;
1448 This->class_version = version;
1450 This->props[MXWriter_BOM] = VARIANT_TRUE;
1451 This->props[MXWriter_DisableEscaping] = VARIANT_FALSE;
1452 This->props[MXWriter_Indent] = VARIANT_FALSE;
1453 This->props[MXWriter_OmitXmlDecl] = VARIANT_FALSE;
1454 This->props[MXWriter_Standalone] = VARIANT_FALSE;
1455 This->prop_changed = FALSE;
1456 This->encoding = SysAllocString(utf16W);
1457 This->version = SysAllocString(version10W);
1458 This->xml_enc = XmlEncoding_UTF16;
1460 This->element = NULL;
1461 This->cdata = FALSE;
1464 This->dest_written = 0;
1466 hr = alloc_output_buffer(This->xml_enc, &This->buffer);
1468 SysFreeString(This->encoding);
1469 SysFreeString(This->version);
1474 init_dispex(&This->dispex, (IUnknown*)&This->IMXWriter_iface, &mxwriter_dispex);
1476 *ppObj = &This->IMXWriter_iface;
1478 TRACE("returning iface %p\n", *ppObj);
1483 static HRESULT WINAPI MXAttributes_QueryInterface(IMXAttributes *iface, REFIID riid, void **ppObj)
1485 mxattributes *This = impl_from_IMXAttributes( iface );
1487 TRACE("(%p)->(%s %p)\n", This, debugstr_guid( riid ), ppObj);
1491 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1492 IsEqualGUID( riid, &IID_IDispatch ) ||
1493 IsEqualGUID( riid, &IID_IMXAttributes ))
1497 else if ( IsEqualGUID( riid, &IID_ISAXAttributes ))
1499 *ppObj = &This->ISAXAttributes_iface;
1501 else if (dispex_query_interface(&This->dispex, riid, ppObj))
1503 return *ppObj ? S_OK : E_NOINTERFACE;
1507 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1508 return E_NOINTERFACE;
1511 IMXAttributes_AddRef( iface );
1516 static ULONG WINAPI MXAttributes_AddRef(IMXAttributes *iface)
1518 mxattributes *This = impl_from_IMXAttributes( iface );
1519 ULONG ref = InterlockedIncrement( &This->ref );
1520 TRACE("(%p)->(%d)\n", This, ref );
1524 static ULONG WINAPI MXAttributes_Release(IMXAttributes *iface)
1526 mxattributes *This = impl_from_IMXAttributes( iface );
1527 LONG ref = InterlockedDecrement( &This->ref );
1529 TRACE("(%p)->(%d)\n", This, ref);
1535 for (i = 0; i < This->length; i++)
1537 SysFreeString(This->attr[i].qname);
1538 SysFreeString(This->attr[i].local);
1539 SysFreeString(This->attr[i].uri);
1540 SysFreeString(This->attr[i].type);
1541 SysFreeString(This->attr[i].value);
1544 release_dispex(&This->dispex);
1545 heap_free(This->attr);
1552 static HRESULT WINAPI MXAttributes_GetTypeInfoCount(IMXAttributes *iface, UINT* pctinfo)
1554 mxattributes *This = impl_from_IMXAttributes( iface );
1555 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1558 static HRESULT WINAPI MXAttributes_GetTypeInfo(IMXAttributes *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
1560 mxattributes *This = impl_from_IMXAttributes( iface );
1561 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1564 static HRESULT WINAPI MXAttributes_GetIDsOfNames(
1565 IMXAttributes *iface,
1567 LPOLESTR* rgszNames,
1572 mxattributes *This = impl_from_IMXAttributes( iface );
1573 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
1574 riid, rgszNames, cNames, lcid, rgDispId);
1577 static HRESULT WINAPI MXAttributes_Invoke(
1578 IMXAttributes *iface,
1579 DISPID dispIdMember,
1583 DISPPARAMS* pDispParams,
1584 VARIANT* pVarResult,
1585 EXCEPINFO* pExcepInfo,
1588 mxattributes *This = impl_from_IMXAttributes( iface );
1589 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
1590 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1593 static HRESULT WINAPI MXAttributes_addAttribute(IMXAttributes *iface,
1594 BSTR uri, BSTR localName, BSTR QName, BSTR type, BSTR value)
1596 mxattributes *This = impl_from_IMXAttributes( iface );
1600 TRACE("(%p)->(%s %s %s %s %s)\n", This, debugstr_w(uri), debugstr_w(localName),
1601 debugstr_w(QName), debugstr_w(type), debugstr_w(value));
1603 if ((!uri || !localName || !QName || !type || !value) && This->class_version != MSXML6)
1604 return E_INVALIDARG;
1606 /* ensure array is large enough */
1607 hr = mxattributes_grow(This);
1608 if (hr != S_OK) return hr;
1610 attr = &This->attr[This->length];
1612 attr->qname = SysAllocString(QName);
1613 attr->local = SysAllocString(localName);
1614 attr->uri = SysAllocString(uri);
1615 attr->type = SysAllocString(type);
1616 attr->value = SysAllocString(value);
1622 static HRESULT WINAPI MXAttributes_addAttributeFromIndex(IMXAttributes *iface,
1623 VARIANT atts, int index)
1625 mxattributes *This = impl_from_IMXAttributes( iface );
1626 FIXME("(%p)->(%s %d): stub\n", This, debugstr_variant(&atts), index);
1630 static HRESULT WINAPI MXAttributes_clear(IMXAttributes *iface)
1632 mxattributes *This = impl_from_IMXAttributes( iface );
1633 FIXME("(%p): stub\n", This);
1637 static HRESULT WINAPI MXAttributes_removeAttribute(IMXAttributes *iface, int index)
1639 mxattributes *This = impl_from_IMXAttributes( iface );
1640 FIXME("(%p)->(%d): stub\n", This, index);
1644 static HRESULT WINAPI MXAttributes_setAttribute(IMXAttributes *iface, int index,
1645 BSTR uri, BSTR localName, BSTR QName, BSTR type, BSTR value)
1647 mxattributes *This = impl_from_IMXAttributes( iface );
1648 FIXME("(%p)->(%d %s %s %s %s %s): stub\n", This, index, debugstr_w(uri),
1649 debugstr_w(localName), debugstr_w(QName), debugstr_w(type), debugstr_w(value));
1653 static HRESULT WINAPI MXAttributes_setAttributes(IMXAttributes *iface, VARIANT atts)
1655 mxattributes *This = impl_from_IMXAttributes( iface );
1656 FIXME("(%p)->(%s): stub\n", This, debugstr_variant(&atts));
1660 static HRESULT WINAPI MXAttributes_setLocalName(IMXAttributes *iface, int index,
1663 mxattributes *This = impl_from_IMXAttributes( iface );
1664 FIXME("(%p)->(%d %s): stub\n", This, index, debugstr_w(localName));
1668 static HRESULT WINAPI MXAttributes_setQName(IMXAttributes *iface, int index, BSTR QName)
1670 mxattributes *This = impl_from_IMXAttributes( iface );
1671 FIXME("(%p)->(%d %s): stub\n", This, index, debugstr_w(QName));
1675 static HRESULT WINAPI MXAttributes_setURI(IMXAttributes *iface, int index, BSTR uri)
1677 mxattributes *This = impl_from_IMXAttributes( iface );
1678 FIXME("(%p)->(%d %s): stub\n", This, index, debugstr_w(uri));
1682 static HRESULT WINAPI MXAttributes_setValue(IMXAttributes *iface, int index, BSTR value)
1684 mxattributes *This = impl_from_IMXAttributes( iface );
1685 FIXME("(%p)->(%d %s): stub\n", This, index, debugstr_w(value));
1689 static const IMXAttributesVtbl MXAttributesVtbl = {
1690 MXAttributes_QueryInterface,
1691 MXAttributes_AddRef,
1692 MXAttributes_Release,
1693 MXAttributes_GetTypeInfoCount,
1694 MXAttributes_GetTypeInfo,
1695 MXAttributes_GetIDsOfNames,
1696 MXAttributes_Invoke,
1697 MXAttributes_addAttribute,
1698 MXAttributes_addAttributeFromIndex,
1700 MXAttributes_removeAttribute,
1701 MXAttributes_setAttribute,
1702 MXAttributes_setAttributes,
1703 MXAttributes_setLocalName,
1704 MXAttributes_setQName,
1705 MXAttributes_setURI,
1706 MXAttributes_setValue
1709 static HRESULT WINAPI SAXAttributes_QueryInterface(ISAXAttributes *iface, REFIID riid, void **ppObj)
1711 mxattributes *This = impl_from_ISAXAttributes( iface );
1712 return IMXAttributes_QueryInterface(&This->IMXAttributes_iface, riid, ppObj);
1715 static ULONG WINAPI SAXAttributes_AddRef(ISAXAttributes *iface)
1717 mxattributes *This = impl_from_ISAXAttributes( iface );
1718 return IMXAttributes_AddRef(&This->IMXAttributes_iface);
1721 static ULONG WINAPI SAXAttributes_Release(ISAXAttributes *iface)
1723 mxattributes *This = impl_from_ISAXAttributes( iface );
1724 return IMXAttributes_Release(&This->IMXAttributes_iface);
1727 static HRESULT WINAPI SAXAttributes_getLength(ISAXAttributes *iface, int *length)
1729 mxattributes *This = impl_from_ISAXAttributes( iface );
1730 TRACE("(%p)->(%p)\n", This, length);
1732 if (!length && (This->class_version == MSXML_DEFAULT || This->class_version == MSXML3))
1735 *length = This->length;
1740 static HRESULT WINAPI SAXAttributes_getURI(ISAXAttributes *iface, int nIndex, const WCHAR **pUrl,
1743 mxattributes *This = impl_from_ISAXAttributes( iface );
1744 FIXME("(%p)->(%d %p %p): stub\n", This, nIndex, pUrl, pUriSize);
1748 static HRESULT WINAPI SAXAttributes_getLocalName(ISAXAttributes *iface, int nIndex, const WCHAR **localName,
1751 mxattributes *This = impl_from_ISAXAttributes( iface );
1752 FIXME("(%p)->(%d %p %p): stub\n", This, nIndex, localName, length);
1756 static HRESULT WINAPI SAXAttributes_getQName(ISAXAttributes *iface, int index, const WCHAR **qname, int *length)
1758 mxattributes *This = impl_from_ISAXAttributes( iface );
1760 TRACE("(%p)->(%d %p %p)\n", This, index, qname, length);
1762 if (index >= This->length) return E_INVALIDARG;
1763 if (!qname || !length) return E_POINTER;
1765 *qname = This->attr[index].qname;
1766 *length = SysStringLen(This->attr[index].qname);
1771 static HRESULT WINAPI SAXAttributes_getName(ISAXAttributes *iface, int nIndex, const WCHAR **pUri, int *pUriLength,
1772 const WCHAR ** pLocalName, int * pLocalNameSize, const WCHAR ** pQName, int * pQNameLength)
1774 mxattributes *This = impl_from_ISAXAttributes( iface );
1775 FIXME("(%p)->(%d %p %p %p %p %p %p): stub\n", This, nIndex, pUri, pUriLength, pLocalName, pLocalNameSize,
1776 pQName, pQNameLength);
1780 static HRESULT WINAPI SAXAttributes_getIndexFromName(ISAXAttributes *iface, const WCHAR * pUri, int cUriLength,
1781 const WCHAR * pLocalName, int cocalNameLength, int * index)
1783 mxattributes *This = impl_from_ISAXAttributes( iface );
1784 FIXME("(%p)->(%s:%d %s:%d %p): stub\n", This, debugstr_wn(pUri, cUriLength), cUriLength,
1785 debugstr_wn(pLocalName, cocalNameLength), cocalNameLength, index);
1789 static HRESULT WINAPI SAXAttributes_getIndexFromQName(ISAXAttributes *iface, const WCHAR * pQName,
1790 int nQNameLength, int * index)
1792 mxattributes *This = impl_from_ISAXAttributes( iface );
1793 FIXME("(%p)->(%s:%d %p): stub\n", This, debugstr_wn(pQName, nQNameLength), nQNameLength, index);
1797 static HRESULT WINAPI SAXAttributes_getType(ISAXAttributes *iface, int nIndex, const WCHAR ** pType,
1800 mxattributes *This = impl_from_ISAXAttributes( iface );
1801 FIXME("(%p)->(%d %p %p): stub\n", This, nIndex, pType, pTypeLength);
1805 static HRESULT WINAPI SAXAttributes_getTypeFromName(ISAXAttributes *iface, const WCHAR * pUri, int nUri,
1806 const WCHAR * pLocalName, int nLocalName, const WCHAR ** pType, int * nType)
1808 mxattributes *This = impl_from_ISAXAttributes( iface );
1809 FIXME("(%p)->(%s:%d %s:%d %p %p): stub\n", This, debugstr_wn(pUri, nUri), nUri,
1810 debugstr_wn(pLocalName, nLocalName), nLocalName, pType, nType);
1814 static HRESULT WINAPI SAXAttributes_getTypeFromQName(ISAXAttributes *iface, const WCHAR * pQName,
1815 int nQName, const WCHAR ** pType, int * nType)
1817 mxattributes *This = impl_from_ISAXAttributes( iface );
1818 FIXME("(%p)->(%s:%d %p %p): stub\n", This, debugstr_wn(pQName, nQName), nQName, pType, nType);
1822 static HRESULT WINAPI SAXAttributes_getValue(ISAXAttributes *iface, int nIndex, const WCHAR ** pValue,
1825 mxattributes *This = impl_from_ISAXAttributes( iface );
1826 FIXME("(%p)->(%d %p %p): stub\n", This, nIndex, pValue, nValue);
1830 static HRESULT WINAPI SAXAttributes_getValueFromName(ISAXAttributes *iface, const WCHAR * pUri,
1831 int nUri, const WCHAR * pLocalName, int nLocalName, const WCHAR ** pValue, int * nValue)
1833 mxattributes *This = impl_from_ISAXAttributes( iface );
1834 FIXME("(%p)->(%s:%d %s:%d %p %p): stub\n", This, debugstr_wn(pUri, nUri), nUri,
1835 debugstr_wn(pLocalName, nLocalName), nLocalName, pValue, nValue);
1839 static HRESULT WINAPI SAXAttributes_getValueFromQName(ISAXAttributes *iface, const WCHAR * pQName,
1840 int nQName, const WCHAR ** pValue, int * nValue)
1842 mxattributes *This = impl_from_ISAXAttributes( iface );
1843 FIXME("(%p)->(%s:%d %p %p): stub\n", This, debugstr_wn(pQName, nQName), nQName, pValue, nValue);
1847 static const ISAXAttributesVtbl SAXAttributesVtbl = {
1848 SAXAttributes_QueryInterface,
1849 SAXAttributes_AddRef,
1850 SAXAttributes_Release,
1851 SAXAttributes_getLength,
1852 SAXAttributes_getURI,
1853 SAXAttributes_getLocalName,
1854 SAXAttributes_getQName,
1855 SAXAttributes_getName,
1856 SAXAttributes_getIndexFromName,
1857 SAXAttributes_getIndexFromQName,
1858 SAXAttributes_getType,
1859 SAXAttributes_getTypeFromName,
1860 SAXAttributes_getTypeFromQName,
1861 SAXAttributes_getValue,
1862 SAXAttributes_getValueFromName,
1863 SAXAttributes_getValueFromQName
1866 static const tid_t mxattrs_iface_tids[] = {
1871 static dispex_static_data_t mxattrs_dispex = {
1878 HRESULT SAXAttributes_create(MSXML_VERSION version, IUnknown *outer, void **ppObj)
1880 static const int default_count = 10;
1883 TRACE("(%p, %p)\n", outer, ppObj);
1885 This = heap_alloc( sizeof (*This) );
1887 return E_OUTOFMEMORY;
1889 This->IMXAttributes_iface.lpVtbl = &MXAttributesVtbl;
1890 This->ISAXAttributes_iface.lpVtbl = &SAXAttributesVtbl;
1893 This->class_version = version;
1895 This->attr = heap_alloc(default_count*sizeof(mxattribute));
1897 This->allocated = default_count;
1899 *ppObj = &This->IMXAttributes_iface;
1901 init_dispex(&This->dispex, (IUnknown*)&This->IMXAttributes_iface, &mxattrs_dispex);
1903 TRACE("returning iface %p\n", *ppObj);