2015-10-14 13:01:05 +02:00
|
|
|
/*
|
2016-02-03 15:43:47 +01:00
|
|
|
* Copyright 2015, 2016 Hans Leidekker for CodeWeavers
|
2015-10-14 13:01:05 +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
|
|
|
|
*/
|
|
|
|
|
2017-07-12 15:34:33 +02:00
|
|
|
#include <assert.h>
|
2015-10-14 13:01:05 +02:00
|
|
|
#include <stdarg.h>
|
2022-02-01 14:57:00 +01:00
|
|
|
#include <stdlib.h>
|
2016-07-04 11:35:45 +02:00
|
|
|
#include <stdio.h>
|
2019-10-31 22:18:32 +01:00
|
|
|
#include <float.h>
|
2016-07-08 10:20:30 +02:00
|
|
|
#include <math.h>
|
2015-10-14 13:01:05 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2019-06-26 09:36:53 +02:00
|
|
|
#include "winnls.h"
|
2016-01-21 15:27:59 +01:00
|
|
|
#include "winuser.h"
|
2015-10-14 13:01:05 +02:00
|
|
|
#include "webservices.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2015-11-10 10:46:40 +01:00
|
|
|
#include "wine/list.h"
|
2015-10-14 13:01:05 +02:00
|
|
|
#include "webservices_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(webservices);
|
|
|
|
|
2016-04-22 09:42:38 +02:00
|
|
|
static const struct prop_desc writer_props[] =
|
2015-10-14 13:01:05 +02:00
|
|
|
{
|
|
|
|
{ sizeof(ULONG), FALSE }, /* WS_XML_WRITER_PROPERTY_MAX_DEPTH */
|
|
|
|
{ sizeof(BOOL), FALSE }, /* WS_XML_WRITER_PROPERTY_ALLOW_FRAGMENT */
|
2018-06-20 15:04:45 +02:00
|
|
|
{ sizeof(ULONG), FALSE }, /* WS_XML_WRITER_PROPERTY_MAX_ATTRIBUTES */
|
2015-10-14 13:01:05 +02:00
|
|
|
{ sizeof(BOOL), FALSE }, /* WS_XML_WRITER_PROPERTY_WRITE_DECLARATION */
|
|
|
|
{ sizeof(ULONG), FALSE }, /* WS_XML_WRITER_PROPERTY_INDENT */
|
|
|
|
{ sizeof(ULONG), FALSE }, /* WS_XML_WRITER_PROPERTY_BUFFER_TRIM_SIZE */
|
|
|
|
{ sizeof(WS_CHARSET), FALSE }, /* WS_XML_WRITER_PROPERTY_CHARSET */
|
|
|
|
{ sizeof(WS_BUFFERS), FALSE }, /* WS_XML_WRITER_PROPERTY_BUFFERS */
|
|
|
|
{ sizeof(ULONG), FALSE }, /* WS_XML_WRITER_PROPERTY_BUFFER_MAX_SIZE */
|
|
|
|
{ sizeof(WS_BYTES), FALSE }, /* WS_XML_WRITER_PROPERTY_BYTES */
|
|
|
|
{ sizeof(BOOL), TRUE }, /* WS_XML_WRITER_PROPERTY_IN_ATTRIBUTE */
|
|
|
|
{ sizeof(ULONG), FALSE }, /* WS_XML_WRITER_PROPERTY_MAX_MIME_PARTS_BUFFER_SIZE */
|
|
|
|
{ sizeof(WS_BYTES), FALSE }, /* WS_XML_WRITER_PROPERTY_INITIAL_BUFFER */
|
|
|
|
{ sizeof(BOOL), FALSE }, /* WS_XML_WRITER_PROPERTY_ALLOW_INVALID_CHARACTER_REFERENCES */
|
|
|
|
{ sizeof(ULONG), FALSE }, /* WS_XML_WRITER_PROPERTY_MAX_NAMESPACES */
|
|
|
|
{ sizeof(ULONG), TRUE }, /* WS_XML_WRITER_PROPERTY_BYTES_WRITTEN */
|
|
|
|
{ sizeof(ULONG), TRUE }, /* WS_XML_WRITER_PROPERTY_BYTES_TO_CLOSE */
|
|
|
|
{ sizeof(BOOL), FALSE }, /* WS_XML_WRITER_PROPERTY_COMPRESS_EMPTY_ELEMENTS */
|
|
|
|
{ sizeof(BOOL), FALSE } /* WS_XML_WRITER_PROPERTY_EMIT_UNCOMPRESSED_EMPTY_ELEMENTS */
|
|
|
|
};
|
|
|
|
|
2015-11-10 10:46:40 +01:00
|
|
|
enum writer_state
|
|
|
|
{
|
|
|
|
WRITER_STATE_INITIAL,
|
|
|
|
WRITER_STATE_STARTELEMENT,
|
|
|
|
WRITER_STATE_STARTATTRIBUTE,
|
2016-02-03 15:43:47 +01:00
|
|
|
WRITER_STATE_STARTCDATA,
|
2015-11-10 10:46:40 +01:00
|
|
|
WRITER_STATE_ENDSTARTELEMENT,
|
2016-01-21 15:27:59 +01:00
|
|
|
WRITER_STATE_TEXT,
|
2016-07-04 11:35:41 +02:00
|
|
|
WRITER_STATE_COMMENT,
|
2016-02-03 15:43:47 +01:00
|
|
|
WRITER_STATE_ENDELEMENT,
|
|
|
|
WRITER_STATE_ENDCDATA
|
2015-11-10 10:46:40 +01:00
|
|
|
};
|
|
|
|
|
2015-10-14 13:01:05 +02:00
|
|
|
struct writer
|
|
|
|
{
|
2017-05-23 12:03:51 +02:00
|
|
|
ULONG magic;
|
|
|
|
CRITICAL_SECTION cs;
|
|
|
|
ULONG write_pos;
|
|
|
|
unsigned char *write_bufptr;
|
|
|
|
enum writer_state state;
|
|
|
|
struct node *root;
|
|
|
|
struct node *current;
|
|
|
|
WS_XML_STRING *current_ns;
|
|
|
|
WS_XML_WRITER_ENCODING_TYPE output_enc;
|
2017-06-14 11:07:31 +02:00
|
|
|
WS_CHARSET output_charset;
|
2017-05-23 12:03:51 +02:00
|
|
|
WS_XML_WRITER_OUTPUT_TYPE output_type;
|
2018-12-04 13:57:28 +01:00
|
|
|
WS_WRITE_CALLBACK output_cb;
|
|
|
|
void *output_cb_state;
|
2017-05-23 12:03:51 +02:00
|
|
|
struct xmlbuf *output_buf;
|
2018-06-20 15:04:45 +02:00
|
|
|
BOOL output_buf_user;
|
2017-05-23 12:03:51 +02:00
|
|
|
WS_HEAP *output_heap;
|
2018-12-04 13:57:28 +01:00
|
|
|
unsigned char *stream_buf;
|
2017-09-06 15:56:05 +02:00
|
|
|
const WS_XML_DICTIONARY *dict;
|
2017-09-06 15:56:09 +02:00
|
|
|
BOOL dict_do_lookup;
|
2017-06-22 10:43:11 +02:00
|
|
|
WS_DYNAMIC_STRING_CALLBACK dict_cb;
|
|
|
|
void *dict_cb_state;
|
2017-05-23 12:03:51 +02:00
|
|
|
ULONG prop_count;
|
2018-09-11 22:08:08 +02:00
|
|
|
struct prop prop[ARRAY_SIZE( writer_props )];
|
2015-10-14 13:01:05 +02:00
|
|
|
};
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
#define WRITER_MAGIC (('W' << 24) | ('R' << 16) | ('I' << 8) | 'T')
|
|
|
|
|
2015-10-14 13:01:05 +02:00
|
|
|
static struct writer *alloc_writer(void)
|
|
|
|
{
|
2018-09-11 22:08:08 +02:00
|
|
|
static const ULONG count = ARRAY_SIZE( writer_props );
|
2015-10-14 13:01:05 +02:00
|
|
|
struct writer *ret;
|
2016-04-22 09:42:38 +02:00
|
|
|
ULONG size = sizeof(*ret) + prop_size( writer_props, count );
|
2015-10-14 13:01:05 +02:00
|
|
|
|
2022-02-01 14:57:00 +01:00
|
|
|
if (!(ret = calloc( 1, size ))) return NULL;
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
ret->magic = WRITER_MAGIC;
|
|
|
|
InitializeCriticalSection( &ret->cs );
|
|
|
|
ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": writer.cs");
|
|
|
|
|
2016-04-22 09:42:38 +02:00
|
|
|
prop_init( writer_props, count, ret->prop, &ret[1] );
|
2015-10-14 13:01:05 +02:00
|
|
|
ret->prop_count = count;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-22 11:30:11 +02:00
|
|
|
static void free_writer( struct writer *writer )
|
|
|
|
{
|
2015-11-10 10:46:40 +01:00
|
|
|
destroy_nodes( writer->root );
|
2017-05-30 10:09:07 +02:00
|
|
|
free_xml_string( writer->current_ns );
|
2015-10-22 11:30:11 +02:00
|
|
|
WsFreeHeap( writer->output_heap );
|
2022-02-01 14:57:00 +01:00
|
|
|
free( writer->stream_buf );
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
writer->cs.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection( &writer->cs );
|
2022-02-01 14:57:00 +01:00
|
|
|
free( writer );
|
2015-10-22 11:30:11 +02:00
|
|
|
}
|
|
|
|
|
2015-11-10 10:46:40 +01:00
|
|
|
static void write_insert_eof( struct writer *writer, struct node *eof )
|
|
|
|
{
|
|
|
|
if (!writer->root) writer->root = eof;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eof->parent = writer->root;
|
|
|
|
list_add_tail( &writer->root->children, &eof->entry );
|
|
|
|
}
|
|
|
|
writer->current = eof;
|
|
|
|
}
|
|
|
|
|
2015-11-10 10:46:41 +01:00
|
|
|
static void write_insert_bof( struct writer *writer, struct node *bof )
|
|
|
|
{
|
|
|
|
writer->root->parent = bof;
|
|
|
|
list_add_tail( &bof->children, &writer->root->entry );
|
|
|
|
writer->current = writer->root = bof;
|
|
|
|
}
|
|
|
|
|
2016-06-21 14:04:41 +02:00
|
|
|
static void write_insert_node( struct writer *writer, struct node *parent, struct node *node )
|
2015-11-10 10:46:40 +01:00
|
|
|
{
|
2016-06-21 14:04:41 +02:00
|
|
|
node->parent = parent;
|
2016-07-04 11:35:41 +02:00
|
|
|
list_add_before( list_tail( &parent->children ), &node->entry );
|
2015-11-10 10:46:40 +01:00
|
|
|
writer->current = node;
|
|
|
|
}
|
|
|
|
|
2016-10-12 15:30:24 +02:00
|
|
|
static struct node *find_parent( struct writer *writer )
|
|
|
|
{
|
|
|
|
if (is_valid_parent( writer->current )) return writer->current;
|
|
|
|
if (is_valid_parent( writer->current->parent )) return writer->current->parent;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
static HRESULT init_writer( struct writer *writer )
|
2015-11-10 10:46:40 +01:00
|
|
|
{
|
|
|
|
struct node *node;
|
|
|
|
|
2017-06-14 11:07:31 +02:00
|
|
|
writer->write_pos = 0;
|
|
|
|
writer->write_bufptr = NULL;
|
2015-11-10 10:46:40 +01:00
|
|
|
destroy_nodes( writer->root );
|
2017-06-14 11:07:31 +02:00
|
|
|
writer->root = writer->current = NULL;
|
2017-05-30 10:09:07 +02:00
|
|
|
free_xml_string( writer->current_ns );
|
2017-06-14 11:07:31 +02:00
|
|
|
writer->current_ns = NULL;
|
2015-11-11 11:02:03 +01:00
|
|
|
|
2015-11-10 10:46:40 +01:00
|
|
|
if (!(node = alloc_node( WS_XML_NODE_TYPE_EOF ))) return E_OUTOFMEMORY;
|
|
|
|
write_insert_eof( writer, node );
|
2017-06-14 11:07:31 +02:00
|
|
|
writer->state = WRITER_STATE_INITIAL;
|
|
|
|
writer->output_enc = WS_XML_WRITER_ENCODING_TYPE_TEXT;
|
|
|
|
writer->output_charset = WS_CHARSET_UTF8;
|
|
|
|
writer->dict = NULL;
|
2017-09-06 15:56:09 +02:00
|
|
|
writer->dict_do_lookup = FALSE;
|
2017-06-22 10:43:11 +02:00
|
|
|
writer->dict_cb = NULL;
|
|
|
|
writer->dict_cb_state = NULL;
|
2015-11-10 10:46:40 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-14 13:01:05 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* WsCreateWriter [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsCreateWriter( const WS_XML_WRITER_PROPERTY *properties, ULONG count,
|
|
|
|
WS_XML_WRITER **handle, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer;
|
|
|
|
ULONG i, max_depth = 32, max_attrs = 128, trim_size = 4096, max_size = 65536, max_ns = 32;
|
|
|
|
WS_CHARSET charset = WS_CHARSET_UTF8;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %lu %p %p\n", properties, count, handle, error );
|
2015-10-14 13:01:05 +02:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!handle) return E_INVALIDARG;
|
|
|
|
if (!(writer = alloc_writer())) return E_OUTOFMEMORY;
|
|
|
|
|
2016-04-22 09:42:38 +02:00
|
|
|
prop_set( writer->prop, writer->prop_count, WS_XML_WRITER_PROPERTY_MAX_DEPTH, &max_depth, sizeof(max_depth) );
|
|
|
|
prop_set( writer->prop, writer->prop_count, WS_XML_WRITER_PROPERTY_MAX_ATTRIBUTES, &max_attrs, sizeof(max_attrs) );
|
|
|
|
prop_set( writer->prop, writer->prop_count, WS_XML_WRITER_PROPERTY_BUFFER_TRIM_SIZE, &trim_size, sizeof(trim_size) );
|
|
|
|
prop_set( writer->prop, writer->prop_count, WS_XML_WRITER_PROPERTY_CHARSET, &charset, sizeof(charset) );
|
|
|
|
prop_set( writer->prop, writer->prop_count, WS_XML_WRITER_PROPERTY_BUFFER_MAX_SIZE, &max_size, sizeof(max_size) );
|
|
|
|
prop_set( writer->prop, writer->prop_count, WS_XML_WRITER_PROPERTY_MAX_MIME_PARTS_BUFFER_SIZE, &max_size, sizeof(max_size) );
|
|
|
|
prop_set( writer->prop, writer->prop_count, WS_XML_WRITER_PROPERTY_MAX_NAMESPACES, &max_ns, sizeof(max_ns) );
|
2015-10-14 13:01:05 +02:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2016-04-22 09:42:38 +02:00
|
|
|
hr = prop_set( writer->prop, writer->prop_count, properties[i].id, properties[i].value,
|
|
|
|
properties[i].valueSize );
|
2015-10-14 13:01:05 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
2015-10-22 11:30:11 +02:00
|
|
|
free_writer( writer );
|
2015-10-14 13:01:05 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-31 13:45:54 +02:00
|
|
|
hr = WsCreateHeap( 1 << 20, 0, NULL, 0, &writer->output_heap, NULL );
|
2015-10-22 11:30:11 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
free_writer( writer );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
hr = init_writer( writer );
|
2015-11-10 10:46:40 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
free_writer( writer );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-09-21 11:26:11 +02:00
|
|
|
TRACE( "created %p\n", writer );
|
2015-10-14 13:01:05 +02:00
|
|
|
*handle = (WS_XML_WRITER *)writer;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsFreeWriter [webservices.@]
|
|
|
|
*/
|
|
|
|
void WINAPI WsFreeWriter( WS_XML_WRITER *handle )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
|
|
|
|
TRACE( "%p\n", handle );
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
if (!writer) return;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
writer->magic = 0;
|
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2015-10-22 11:30:11 +02:00
|
|
|
free_writer( writer );
|
2015-10-14 13:01:05 +02:00
|
|
|
}
|
2015-10-14 13:01:06 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsGetWriterProperty [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsGetWriterProperty( WS_XML_WRITER *handle, WS_XML_WRITER_PROPERTY_ID id,
|
|
|
|
void *buf, ULONG size, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2017-03-08 11:25:57 +01:00
|
|
|
HRESULT hr = S_OK;
|
2015-10-14 13:01:06 +02:00
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %u %p %lu %p\n", handle, id, buf, size, error );
|
2015-10-14 13:01:06 +02:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-12-04 13:57:28 +01:00
|
|
|
if (writer->output_type != WS_XML_WRITER_OUTPUT_TYPE_BUFFER) hr = WS_E_INVALID_OPERATION;
|
2018-10-17 13:42:36 +02:00
|
|
|
else
|
2015-11-11 11:02:01 +01:00
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
switch (id)
|
2017-03-08 11:25:57 +01:00
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
case WS_XML_WRITER_PROPERTY_BYTES:
|
2017-05-15 09:59:24 +02:00
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
WS_BYTES *bytes = buf;
|
|
|
|
if (size != sizeof(*bytes)) hr = E_INVALIDARG;
|
2017-05-15 09:59:24 +02:00
|
|
|
else
|
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
bytes->bytes = writer->output_buf->bytes.bytes;
|
|
|
|
bytes->length = writer->output_buf->bytes.length;
|
2017-05-15 09:59:24 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-10-17 13:42:36 +02:00
|
|
|
case WS_XML_WRITER_PROPERTY_BUFFERS:
|
|
|
|
if (writer->output_buf->bytes.length)
|
|
|
|
{
|
|
|
|
WS_BUFFERS *buffers = buf;
|
|
|
|
if (size != sizeof(*buffers)) hr = E_INVALIDARG;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffers->bufferCount = 1;
|
|
|
|
buffers->buffers = &writer->output_buf->bytes;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
hr = prop_get( writer->prop, writer->prop_count, id, buf, size );
|
|
|
|
}
|
2015-11-11 11:02:01 +01:00
|
|
|
}
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2015-10-14 13:01:06 +02:00
|
|
|
}
|
2015-10-14 13:01:07 +02:00
|
|
|
|
2015-10-22 11:30:11 +02:00
|
|
|
static void set_output_buffer( struct writer *writer, struct xmlbuf *xmlbuf )
|
|
|
|
{
|
|
|
|
/* free current buffer if it's ours */
|
2018-06-20 15:04:45 +02:00
|
|
|
if (writer->output_buf && !writer->output_buf_user)
|
2015-10-22 11:30:11 +02:00
|
|
|
{
|
|
|
|
free_xmlbuf( writer->output_buf );
|
|
|
|
}
|
|
|
|
writer->output_buf = xmlbuf;
|
|
|
|
writer->output_type = WS_XML_WRITER_OUTPUT_TYPE_BUFFER;
|
2017-05-15 09:59:23 +02:00
|
|
|
writer->write_bufptr = xmlbuf->bytes.bytes;
|
2015-10-22 11:30:11 +02:00
|
|
|
writer->write_pos = 0;
|
|
|
|
}
|
|
|
|
|
2018-12-04 13:57:28 +01:00
|
|
|
static void set_output_stream( struct writer *writer, WS_WRITE_CALLBACK callback, void *state )
|
|
|
|
{
|
|
|
|
writer->output_type = WS_XML_WRITER_OUTPUT_TYPE_STREAM;
|
|
|
|
writer->output_cb = callback;
|
|
|
|
writer->output_cb_state = state;
|
|
|
|
writer->write_bufptr = writer->stream_buf;
|
|
|
|
writer->write_pos = 0;
|
|
|
|
}
|
|
|
|
|
2015-10-14 13:01:07 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* WsSetOutput [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsSetOutput( WS_XML_WRITER *handle, const WS_XML_WRITER_ENCODING *encoding,
|
|
|
|
const WS_XML_WRITER_OUTPUT *output, const WS_XML_WRITER_PROPERTY *properties,
|
|
|
|
ULONG count, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2015-11-10 10:46:41 +01:00
|
|
|
struct node *node;
|
2015-10-14 13:01:07 +02:00
|
|
|
HRESULT hr;
|
|
|
|
ULONG i;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %p %p %p %lu %p\n", handle, encoding, output, properties, count, error );
|
2015-10-14 13:01:07 +02:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2015-10-22 11:30:11 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2016-04-22 09:42:38 +02:00
|
|
|
hr = prop_set( writer->prop, writer->prop_count, properties[i].id, properties[i].value,
|
|
|
|
properties[i].valueSize );
|
2017-03-08 11:25:57 +01:00
|
|
|
if (hr != S_OK) goto done;
|
2015-10-22 11:30:11 +02:00
|
|
|
}
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
if ((hr = init_writer( writer )) != S_OK) goto done;
|
2015-11-10 10:46:41 +01:00
|
|
|
|
2015-10-14 13:01:07 +02:00
|
|
|
switch (encoding->encodingType)
|
|
|
|
{
|
2015-11-10 10:46:41 +01:00
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT:
|
|
|
|
{
|
2018-12-04 13:57:28 +01:00
|
|
|
const WS_XML_WRITER_TEXT_ENCODING *text = (const WS_XML_WRITER_TEXT_ENCODING *)encoding;
|
2015-11-10 10:46:41 +01:00
|
|
|
if (text->charSet != WS_CHARSET_UTF8)
|
2015-10-14 13:01:07 +02:00
|
|
|
{
|
2015-11-10 10:46:41 +01:00
|
|
|
FIXME( "charset %u not supported\n", text->charSet );
|
2017-03-08 11:25:57 +01:00
|
|
|
hr = E_NOTIMPL;
|
|
|
|
goto done;
|
2015-11-10 10:46:41 +01:00
|
|
|
}
|
2017-06-14 11:07:31 +02:00
|
|
|
writer->output_enc = WS_XML_WRITER_ENCODING_TYPE_TEXT;
|
|
|
|
writer->output_charset = WS_CHARSET_UTF8;
|
2017-05-23 12:03:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY:
|
|
|
|
{
|
2018-12-04 13:57:28 +01:00
|
|
|
const WS_XML_WRITER_BINARY_ENCODING *bin = (const WS_XML_WRITER_BINARY_ENCODING *)encoding;
|
2017-06-14 11:07:31 +02:00
|
|
|
writer->output_enc = WS_XML_WRITER_ENCODING_TYPE_BINARY;
|
|
|
|
writer->output_charset = 0;
|
|
|
|
writer->dict = bin->staticDictionary;
|
2017-06-22 10:43:11 +02:00
|
|
|
writer->dict_cb = bin->dynamicStringCallback;
|
|
|
|
writer->dict_cb_state = bin->dynamicStringCallbackState;
|
2015-11-10 10:46:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME( "encoding type %u not supported\n", encoding->encodingType );
|
2017-03-08 11:25:57 +01:00
|
|
|
hr = E_NOTIMPL;
|
|
|
|
goto done;
|
2015-10-14 13:01:07 +02:00
|
|
|
}
|
2017-03-08 11:25:57 +01:00
|
|
|
|
2015-10-14 13:01:07 +02:00
|
|
|
switch (output->outputType)
|
|
|
|
{
|
2015-11-10 10:46:41 +01:00
|
|
|
case WS_XML_WRITER_OUTPUT_TYPE_BUFFER:
|
|
|
|
{
|
|
|
|
struct xmlbuf *xmlbuf;
|
2017-09-06 15:56:05 +02:00
|
|
|
if (!(xmlbuf = alloc_xmlbuf( writer->output_heap, 0, writer->output_enc, writer->output_charset,
|
|
|
|
writer->dict, NULL )))
|
2017-06-14 11:07:31 +02:00
|
|
|
{
|
|
|
|
hr = WS_E_QUOTA_EXCEEDED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
set_output_buffer( writer, xmlbuf );
|
2018-06-20 15:04:45 +02:00
|
|
|
writer->output_buf_user = FALSE;
|
2015-11-10 10:46:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-12-04 13:57:28 +01:00
|
|
|
case WS_XML_WRITER_OUTPUT_TYPE_STREAM:
|
|
|
|
{
|
|
|
|
const WS_XML_WRITER_STREAM_OUTPUT *stream = (const WS_XML_WRITER_STREAM_OUTPUT *)output;
|
2022-02-01 14:57:00 +01:00
|
|
|
if (!writer->stream_buf && !(writer->stream_buf = malloc( STREAM_BUFSIZE )))
|
2018-12-04 13:57:28 +01:00
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
set_output_stream( writer, stream->writeCallback, stream->writeCallbackState );
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2015-11-10 10:46:41 +01:00
|
|
|
default:
|
|
|
|
FIXME( "output type %u not supported\n", output->outputType );
|
2017-03-08 11:25:57 +01:00
|
|
|
hr = E_NOTIMPL;
|
|
|
|
goto done;
|
2015-10-14 13:01:07 +02:00
|
|
|
}
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
if (!(node = alloc_node( WS_XML_NODE_TYPE_BOF ))) hr = E_OUTOFMEMORY;
|
|
|
|
else write_insert_bof( writer, node );
|
|
|
|
|
|
|
|
done:
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2015-10-22 11:30:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsSetOutputToBuffer [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsSetOutputToBuffer( WS_XML_WRITER *handle, WS_XML_BUFFER *buffer,
|
|
|
|
const WS_XML_WRITER_PROPERTY *properties, ULONG count,
|
|
|
|
WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
struct xmlbuf *xmlbuf = (struct xmlbuf *)buffer;
|
2015-11-10 10:46:41 +01:00
|
|
|
struct node *node;
|
2015-10-22 11:30:11 +02:00
|
|
|
HRESULT hr;
|
|
|
|
ULONG i;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %p %p %lu %p\n", handle, buffer, properties, count, error );
|
2015-10-22 11:30:11 +02:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !xmlbuf) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2015-10-14 13:01:07 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2016-04-22 09:42:38 +02:00
|
|
|
hr = prop_set( writer->prop, writer->prop_count, properties[i].id, properties[i].value,
|
|
|
|
properties[i].valueSize );
|
2017-03-08 11:25:57 +01:00
|
|
|
if (hr != S_OK) goto done;
|
2015-10-14 13:01:07 +02:00
|
|
|
}
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
if ((hr = init_writer( writer )) != S_OK) goto done;
|
2017-06-14 11:07:31 +02:00
|
|
|
writer->output_enc = xmlbuf->encoding;
|
|
|
|
writer->output_charset = xmlbuf->charset;
|
2015-10-22 11:30:11 +02:00
|
|
|
set_output_buffer( writer, xmlbuf );
|
2018-06-20 15:04:45 +02:00
|
|
|
writer->output_buf_user = TRUE;
|
2015-11-10 10:46:41 +01:00
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
if (!(node = alloc_node( WS_XML_NODE_TYPE_BOF ))) hr = E_OUTOFMEMORY;
|
|
|
|
else write_insert_bof( writer, node );
|
|
|
|
|
|
|
|
done:
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2015-10-14 13:01:07 +02:00
|
|
|
}
|
2015-11-10 10:46:40 +01:00
|
|
|
|
2018-12-04 13:57:28 +01:00
|
|
|
static HRESULT flush_writer( struct writer *writer, ULONG min_size, const WS_ASYNC_CONTEXT *ctx,
|
|
|
|
WS_ERROR *error )
|
|
|
|
{
|
|
|
|
WS_BYTES buf;
|
|
|
|
|
|
|
|
if (writer->write_pos < min_size) return S_OK;
|
|
|
|
|
|
|
|
buf.bytes = writer->write_bufptr;
|
|
|
|
buf.length = writer->write_pos;
|
|
|
|
writer->output_cb( writer->output_cb_state, &buf, 1, ctx, error );
|
|
|
|
writer->write_pos = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsFlushWriter [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsFlushWriter( WS_XML_WRITER *handle, ULONG min_size, const WS_ASYNC_CONTEXT *ctx,
|
|
|
|
WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %lu %p %p\n", handle, min_size, ctx, error );
|
2018-12-04 13:57:28 +01:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
if (ctx) FIXME( "ignoring ctx parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (writer->output_type != WS_XML_WRITER_OUTPUT_TYPE_STREAM) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else hr = flush_writer( writer, min_size, ctx, error );
|
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2018-12-04 13:57:28 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-11-10 10:46:40 +01:00
|
|
|
static HRESULT write_grow_buffer( struct writer *writer, ULONG size )
|
|
|
|
{
|
|
|
|
struct xmlbuf *buf = writer->output_buf;
|
|
|
|
SIZE_T new_size;
|
|
|
|
void *tmp;
|
|
|
|
|
2018-12-04 13:57:28 +01:00
|
|
|
if (writer->output_type == WS_XML_WRITER_OUTPUT_TYPE_STREAM)
|
|
|
|
{
|
|
|
|
if (size > STREAM_BUFSIZE) return WS_E_QUOTA_EXCEEDED;
|
|
|
|
return flush_writer( writer, STREAM_BUFSIZE - size, NULL, NULL );
|
|
|
|
}
|
|
|
|
|
2017-05-15 09:59:23 +02:00
|
|
|
if (buf->size >= writer->write_pos + size)
|
2015-11-10 10:46:40 +01:00
|
|
|
{
|
2017-05-15 09:59:23 +02:00
|
|
|
buf->bytes.length = writer->write_pos + size;
|
2015-11-10 10:46:40 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2017-05-15 09:59:23 +02:00
|
|
|
new_size = max( buf->size * 2, writer->write_pos + size );
|
|
|
|
if (!(tmp = ws_realloc( buf->heap, buf->bytes.bytes, buf->size, new_size ))) return WS_E_QUOTA_EXCEEDED;
|
|
|
|
writer->write_bufptr = buf->bytes.bytes = tmp;
|
|
|
|
buf->size = new_size;
|
|
|
|
buf->bytes.length = writer->write_pos + size;
|
2015-11-10 10:46:40 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-20 14:53:39 +01:00
|
|
|
static inline void write_char( struct writer *writer, unsigned char ch )
|
2015-11-10 10:46:40 +01:00
|
|
|
{
|
|
|
|
writer->write_bufptr[writer->write_pos++] = ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void write_bytes( struct writer *writer, const BYTE *bytes, ULONG len )
|
|
|
|
{
|
|
|
|
memcpy( writer->write_bufptr + writer->write_pos, bytes, len );
|
|
|
|
writer->write_pos += len;
|
|
|
|
}
|
|
|
|
|
2016-09-28 12:37:59 +02:00
|
|
|
struct escape
|
|
|
|
{
|
|
|
|
char ch;
|
|
|
|
const char *entity;
|
|
|
|
ULONG len;
|
|
|
|
};
|
|
|
|
static const struct escape escape_lt = { '<', "<", 4 };
|
|
|
|
static const struct escape escape_gt = { '>', ">", 4 };
|
|
|
|
static const struct escape escape_amp = { '&', "&", 5 };
|
|
|
|
static const struct escape escape_apos = { '\'', "'", 6 };
|
|
|
|
static const struct escape escape_quot = { '"', """, 6 };
|
|
|
|
|
|
|
|
static HRESULT write_bytes_escape( struct writer *writer, const BYTE *bytes, ULONG len,
|
|
|
|
const struct escape **escapes, ULONG nb_escapes )
|
|
|
|
{
|
|
|
|
ULONG i, j, size;
|
|
|
|
const BYTE *ptr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
ptr = &bytes[i];
|
|
|
|
size = 1;
|
|
|
|
for (j = 0; j < nb_escapes; j++)
|
|
|
|
{
|
|
|
|
if (bytes[i] == escapes[j]->ch)
|
|
|
|
{
|
|
|
|
ptr = (const BYTE *)escapes[j]->entity;
|
|
|
|
size = escapes[j]->len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((hr = write_grow_buffer( writer, size )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, ptr, size );
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:54 +02:00
|
|
|
static HRESULT write_attribute_value_text( struct writer *writer, const WS_XML_TEXT *text, BOOL single )
|
|
|
|
{
|
|
|
|
WS_XML_UTF8_TEXT *utf8 = (WS_XML_UTF8_TEXT *)text;
|
|
|
|
const struct escape *escapes[3];
|
|
|
|
|
|
|
|
escapes[0] = single ? &escape_apos : &escape_quot;
|
|
|
|
escapes[1] = &escape_lt;
|
|
|
|
escapes[2] = &escape_amp;
|
|
|
|
return write_bytes_escape( writer, utf8->value.bytes, utf8->value.length, escapes, 3 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_attribute_text( struct writer *writer, const WS_XML_ATTRIBUTE *attr )
|
2015-11-10 10:46:40 +01:00
|
|
|
{
|
2016-01-21 15:27:54 +01:00
|
|
|
unsigned char quote = attr->singleQuote ? '\'' : '"';
|
2017-05-18 23:41:50 +02:00
|
|
|
const WS_XML_STRING *prefix = NULL;
|
2015-11-10 10:46:40 +01:00
|
|
|
ULONG size;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-01-21 15:27:55 +01:00
|
|
|
if (attr->prefix) prefix = attr->prefix;
|
|
|
|
|
2015-11-10 10:46:40 +01:00
|
|
|
/* ' prefix:attr="value"' */
|
|
|
|
|
|
|
|
size = attr->localName->length + 4 /* ' =""' */;
|
2017-05-15 09:59:21 +02:00
|
|
|
if (prefix && prefix->length) size += prefix->length + 1 /* ':' */;
|
2015-11-10 10:46:40 +01:00
|
|
|
if ((hr = write_grow_buffer( writer, size )) != S_OK) return hr;
|
|
|
|
|
|
|
|
write_char( writer, ' ' );
|
2017-05-15 09:59:21 +02:00
|
|
|
if (prefix && prefix->length)
|
2015-11-10 10:46:40 +01:00
|
|
|
{
|
2016-01-21 15:27:55 +01:00
|
|
|
write_bytes( writer, prefix->bytes, prefix->length );
|
2015-11-10 10:46:40 +01:00
|
|
|
write_char( writer, ':' );
|
|
|
|
}
|
|
|
|
write_bytes( writer, attr->localName->bytes, attr->localName->length );
|
|
|
|
write_char( writer, '=' );
|
2016-01-21 15:27:54 +01:00
|
|
|
write_char( writer, quote );
|
2017-05-23 12:03:54 +02:00
|
|
|
if (attr->value) hr = write_attribute_value_text( writer, attr->value, attr->singleQuote );
|
2016-01-21 15:27:54 +01:00
|
|
|
write_char( writer, quote );
|
2015-11-10 10:46:40 +01:00
|
|
|
|
2016-09-28 12:37:59 +02:00
|
|
|
return hr;
|
2015-11-10 10:46:40 +01:00
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:54 +02:00
|
|
|
static HRESULT write_int31( struct writer *writer, ULONG len )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2017-05-30 10:09:05 +02:00
|
|
|
if (len > 0x7fffffff) return E_INVALIDARG;
|
|
|
|
|
2017-05-23 12:03:54 +02:00
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
if (len < 0x80)
|
|
|
|
{
|
|
|
|
write_char( writer, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
write_char( writer, (len & 0x7f) | 0x80 );
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
if ((len >>= 7) < 0x80)
|
|
|
|
{
|
|
|
|
write_char( writer, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
write_char( writer, (len & 0x7f) | 0x80 );
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
if ((len >>= 7) < 0x80)
|
|
|
|
{
|
|
|
|
write_char( writer, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
write_char( writer, (len & 0x7f) | 0x80 );
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
if ((len >>= 7) < 0x80)
|
|
|
|
{
|
|
|
|
write_char( writer, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
write_char( writer, (len & 0x7f) | 0x80 );
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
if ((len >>= 7) < 0x08)
|
|
|
|
{
|
|
|
|
write_char( writer, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return WS_E_INVALID_FORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_string( struct writer *writer, const BYTE *bytes, ULONG len )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
if ((hr = write_int31( writer, len )) != S_OK) return hr;
|
|
|
|
if ((hr = write_grow_buffer( writer, len )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, bytes, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-30 10:09:05 +02:00
|
|
|
static HRESULT write_dict_string( struct writer *writer, ULONG id )
|
|
|
|
{
|
2017-06-22 10:43:11 +02:00
|
|
|
if (id > 0x7fffffff) return E_INVALIDARG;
|
2018-01-24 14:30:00 +01:00
|
|
|
return write_int31( writer, id );
|
2017-05-30 10:09:05 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 15:56:10 +02:00
|
|
|
static enum record_type get_attr_text_record_type( const WS_XML_TEXT *text, BOOL use_dict )
|
2017-05-23 12:03:54 +02:00
|
|
|
{
|
2017-07-12 15:34:30 +02:00
|
|
|
if (!text) return RECORD_CHARS8_TEXT;
|
|
|
|
switch (text->textType)
|
|
|
|
{
|
|
|
|
case WS_XML_TEXT_TYPE_UTF8:
|
|
|
|
{
|
|
|
|
const WS_XML_UTF8_TEXT *text_utf8 = (const WS_XML_UTF8_TEXT *)text;
|
2017-09-06 15:56:10 +02:00
|
|
|
if (use_dict) return RECORD_DICTIONARY_TEXT;
|
2017-07-12 15:34:30 +02:00
|
|
|
if (text_utf8->value.length <= MAX_UINT8) return RECORD_CHARS8_TEXT;
|
|
|
|
if (text_utf8->value.length <= MAX_UINT16) return RECORD_CHARS16_TEXT;
|
|
|
|
return RECORD_CHARS32_TEXT;
|
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
case WS_XML_TEXT_TYPE_UTF16:
|
|
|
|
{
|
|
|
|
const WS_XML_UTF16_TEXT *text_utf16 = (const WS_XML_UTF16_TEXT *)text;
|
|
|
|
int len = text_utf16->byteCount / sizeof(WCHAR);
|
|
|
|
int len_utf8 = WideCharToMultiByte( CP_UTF8, 0, (const WCHAR *)text_utf16->bytes, len, NULL, 0, NULL, NULL );
|
|
|
|
if (len_utf8 <= MAX_UINT8) return RECORD_CHARS8_TEXT;
|
|
|
|
if (len_utf8 <= MAX_UINT16) return RECORD_CHARS16_TEXT;
|
|
|
|
return RECORD_CHARS32_TEXT;
|
|
|
|
}
|
2017-07-12 15:34:31 +02:00
|
|
|
case WS_XML_TEXT_TYPE_BASE64:
|
|
|
|
{
|
|
|
|
const WS_XML_BASE64_TEXT *text_base64 = (const WS_XML_BASE64_TEXT *)text;
|
|
|
|
if (text_base64->length <= MAX_UINT8) return RECORD_BYTES8_TEXT;
|
|
|
|
if (text_base64->length <= MAX_UINT16) return RECORD_BYTES16_TEXT;
|
|
|
|
return RECORD_BYTES32_TEXT;
|
|
|
|
}
|
2017-07-12 15:34:32 +02:00
|
|
|
case WS_XML_TEXT_TYPE_BOOL:
|
|
|
|
{
|
|
|
|
const WS_XML_BOOL_TEXT *text_bool = (const WS_XML_BOOL_TEXT *)text;
|
|
|
|
return text_bool->value ? RECORD_TRUE_TEXT : RECORD_FALSE_TEXT;
|
|
|
|
}
|
2017-07-12 15:34:33 +02:00
|
|
|
case WS_XML_TEXT_TYPE_INT32:
|
|
|
|
{
|
|
|
|
const WS_XML_INT32_TEXT *text_int32 = (const WS_XML_INT32_TEXT *)text;
|
|
|
|
if (!text_int32->value) return RECORD_ZERO_TEXT;
|
|
|
|
if (text_int32->value == 1) return RECORD_ONE_TEXT;
|
|
|
|
if (text_int32->value >= MIN_INT8 && text_int32->value <= MAX_INT8) return RECORD_INT8_TEXT;
|
|
|
|
if (text_int32->value >= MIN_INT16 && text_int32->value <= MAX_INT16) return RECORD_INT16_TEXT;
|
|
|
|
return RECORD_INT32_TEXT;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_INT64:
|
|
|
|
{
|
|
|
|
const WS_XML_INT64_TEXT *text_int64 = (const WS_XML_INT64_TEXT *)text;
|
|
|
|
if (!text_int64->value) return RECORD_ZERO_TEXT;
|
|
|
|
if (text_int64->value == 1) return RECORD_ONE_TEXT;
|
|
|
|
if (text_int64->value >= MIN_INT8 && text_int64->value <= MAX_INT8) return RECORD_INT8_TEXT;
|
|
|
|
if (text_int64->value >= MIN_INT16 && text_int64->value <= MAX_INT16) return RECORD_INT16_TEXT;
|
|
|
|
if (text_int64->value >= MIN_INT32 && text_int64->value <= MAX_INT32) return RECORD_INT32_TEXT;
|
|
|
|
return RECORD_INT64_TEXT;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_UINT64:
|
|
|
|
{
|
|
|
|
const WS_XML_UINT64_TEXT *text_uint64 = (const WS_XML_UINT64_TEXT *)text;
|
|
|
|
if (!text_uint64->value) return RECORD_ZERO_TEXT;
|
|
|
|
if (text_uint64->value == 1) return RECORD_ONE_TEXT;
|
|
|
|
if (text_uint64->value <= MAX_INT8) return RECORD_INT8_TEXT;
|
|
|
|
if (text_uint64->value <= MAX_INT16) return RECORD_INT16_TEXT;
|
|
|
|
if (text_uint64->value <= MAX_INT32) return RECORD_INT32_TEXT;
|
|
|
|
if (text_uint64->value <= MAX_INT64) return RECORD_INT64_TEXT;
|
|
|
|
return RECORD_UINT64_TEXT;
|
|
|
|
}
|
2017-07-12 15:34:34 +02:00
|
|
|
case WS_XML_TEXT_TYPE_DOUBLE:
|
|
|
|
{
|
|
|
|
const WS_XML_DOUBLE_TEXT *text_double = (const WS_XML_DOUBLE_TEXT *)text;
|
|
|
|
if (!text_double->value) return RECORD_ZERO_TEXT;
|
|
|
|
if (text_double->value == 1) return RECORD_ONE_TEXT;
|
|
|
|
if (isinf( text_double->value ) || (INT64)text_double->value != text_double->value)
|
|
|
|
return RECORD_DOUBLE_TEXT;
|
|
|
|
if (text_double->value <= MAX_INT8) return RECORD_INT8_TEXT;
|
|
|
|
if (text_double->value <= MAX_INT16) return RECORD_INT16_TEXT;
|
|
|
|
if (text_double->value <= MAX_INT32) return RECORD_INT32_TEXT;
|
|
|
|
return RECORD_INT64_TEXT;
|
|
|
|
}
|
2017-07-12 15:34:35 +02:00
|
|
|
case WS_XML_TEXT_TYPE_GUID:
|
|
|
|
return RECORD_GUID_TEXT;
|
|
|
|
|
2017-07-12 15:34:36 +02:00
|
|
|
case WS_XML_TEXT_TYPE_UNIQUE_ID:
|
|
|
|
return RECORD_UNIQUE_ID_TEXT;
|
|
|
|
|
2017-07-12 15:34:37 +02:00
|
|
|
case WS_XML_TEXT_TYPE_DATETIME:
|
|
|
|
return RECORD_DATETIME_TEXT;
|
|
|
|
|
2017-07-12 15:34:30 +02:00
|
|
|
default:
|
|
|
|
FIXME( "unhandled text type %u\n", text->textType );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2017-05-23 12:03:54 +02:00
|
|
|
|
2017-07-12 15:34:33 +02:00
|
|
|
static INT64 get_text_value_int( const WS_XML_TEXT *text )
|
|
|
|
{
|
|
|
|
switch (text->textType)
|
|
|
|
{
|
|
|
|
case WS_XML_TEXT_TYPE_INT32:
|
|
|
|
{
|
|
|
|
const WS_XML_INT32_TEXT *text_int32 = (const WS_XML_INT32_TEXT *)text;
|
|
|
|
return text_int32->value;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_INT64:
|
|
|
|
{
|
|
|
|
const WS_XML_INT64_TEXT *text_int64 = (const WS_XML_INT64_TEXT *)text;
|
|
|
|
return text_int64->value;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_UINT64:
|
|
|
|
{
|
|
|
|
const WS_XML_UINT64_TEXT *text_uint64 = (const WS_XML_UINT64_TEXT *)text;
|
|
|
|
return text_uint64->value;
|
|
|
|
}
|
2017-07-12 15:34:34 +02:00
|
|
|
case WS_XML_TEXT_TYPE_DOUBLE:
|
|
|
|
{
|
|
|
|
const WS_XML_DOUBLE_TEXT *text_double = (const WS_XML_DOUBLE_TEXT *)text;
|
|
|
|
return text_double->value;
|
|
|
|
}
|
2017-07-12 15:34:33 +02:00
|
|
|
default:
|
|
|
|
ERR( "unhandled text type %u\n", text->textType );
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-06 15:56:10 +02:00
|
|
|
static BOOL get_string_id( struct writer *writer, const WS_XML_STRING *str, ULONG *id )
|
|
|
|
{
|
|
|
|
if (writer->dict && str->dictionary == writer->dict)
|
|
|
|
{
|
|
|
|
*id = str->id << 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (writer->dict_cb)
|
|
|
|
{
|
|
|
|
BOOL found = FALSE;
|
|
|
|
writer->dict_cb( writer->dict_cb_state, str, &found, id, NULL );
|
|
|
|
if (found) *id = (*id << 1) | 1;
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static ULONG format_bool( const BOOL *ptr, unsigned char *buf )
|
2017-05-23 12:03:54 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
static const unsigned char bool_true[] = {'t','r','u','e'}, bool_false[] = {'f','a','l','s','e'};
|
|
|
|
if (*ptr)
|
2017-09-06 15:56:10 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
memcpy( buf, bool_true, sizeof(bool_true) );
|
|
|
|
return sizeof(bool_true);
|
2017-09-06 15:56:10 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
memcpy( buf, bool_false, sizeof(bool_false) );
|
|
|
|
return sizeof(bool_false);
|
|
|
|
}
|
2017-05-23 12:03:54 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static ULONG format_int32( const INT32 *ptr, unsigned char *buf )
|
|
|
|
{
|
|
|
|
return wsprintfA( (char *)buf, "%d", *ptr );
|
|
|
|
}
|
2017-05-23 12:03:54 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static ULONG format_int64( const INT64 *ptr, unsigned char *buf )
|
|
|
|
{
|
|
|
|
return wsprintfA( (char *)buf, "%I64d", *ptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG format_uint64( const UINT64 *ptr, unsigned char *buf )
|
|
|
|
{
|
|
|
|
return wsprintfA( (char *)buf, "%I64u", *ptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG format_double( const double *ptr, unsigned char *buf )
|
|
|
|
{
|
2019-06-26 09:36:53 +02:00
|
|
|
static const double precision = 0.0000000000000001;
|
2017-12-08 15:49:41 +01:00
|
|
|
unsigned char *p = buf;
|
2019-06-26 09:36:53 +02:00
|
|
|
double val = *ptr;
|
2017-12-08 15:49:41 +01:00
|
|
|
int neg, mag, mag2, use_exp;
|
|
|
|
|
|
|
|
if (isnan( val ))
|
2017-05-23 12:03:54 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
memcpy( buf, "NaN", 3 );
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
if (isinf( val ))
|
2017-07-12 15:34:30 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
if (val < 0)
|
2017-05-23 12:03:54 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
memcpy( buf, "-INF", 4 );
|
|
|
|
return 4;
|
2017-05-23 12:03:54 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
memcpy( buf, "INF", 3 );
|
|
|
|
return 3;
|
2017-07-12 15:34:30 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
if (val == 0.0)
|
2017-07-12 15:34:30 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
*p = '0';
|
|
|
|
return 1;
|
2017-07-12 15:34:30 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
|
|
|
|
if ((neg = val < 0))
|
2017-07-12 15:34:31 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
*p++ = '-';
|
|
|
|
val = -val;
|
2017-07-12 15:34:31 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
|
2019-06-26 09:36:53 +02:00
|
|
|
mag = log10( val );
|
2017-12-08 15:49:41 +01:00
|
|
|
use_exp = (mag >= 15 || (neg && mag >= 1) || mag <= -1);
|
|
|
|
if (use_exp)
|
2017-07-12 15:34:31 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
if (mag < 0) mag -= 1;
|
2019-06-26 09:36:53 +02:00
|
|
|
val = val / pow( 10.0, mag );
|
2017-12-08 15:49:41 +01:00
|
|
|
mag2 = mag;
|
|
|
|
mag = 0;
|
2017-07-12 15:34:31 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
else if (mag < 1) mag = 0;
|
2017-07-12 15:34:32 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
while (val > precision || mag >= 0)
|
2017-07-12 15:34:33 +02:00
|
|
|
{
|
2019-06-26 09:36:53 +02:00
|
|
|
double weight = pow( 10.0, mag );
|
2017-12-08 15:49:41 +01:00
|
|
|
if (weight > 0 && !isinf( weight ))
|
|
|
|
{
|
2019-06-26 09:36:53 +02:00
|
|
|
int digit = floor( val / weight );
|
2017-12-08 15:49:41 +01:00
|
|
|
val -= digit * weight;
|
|
|
|
*(p++) = '0' + digit;
|
|
|
|
}
|
|
|
|
if (!mag && val > precision) *(p++) = '.';
|
|
|
|
mag--;
|
2017-07-12 15:34:33 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
|
|
|
|
if (use_exp)
|
2017-07-12 15:34:33 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
int i, j;
|
|
|
|
*(p++) = 'E';
|
|
|
|
if (mag2 > 0) *(p++) = '+';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*(p++) = '-';
|
|
|
|
mag2 = -mag2;
|
|
|
|
}
|
|
|
|
mag = 0;
|
|
|
|
while (mag2 > 0)
|
|
|
|
{
|
|
|
|
*(p++) = '0' + mag2 % 10;
|
|
|
|
mag2 /= 10;
|
|
|
|
mag++;
|
|
|
|
}
|
|
|
|
for (i = -mag, j = -1; i < j; i++, j--)
|
|
|
|
{
|
|
|
|
p[i] ^= p[j];
|
|
|
|
p[j] ^= p[i];
|
|
|
|
p[i] ^= p[j];
|
|
|
|
}
|
2017-07-12 15:34:33 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
|
|
|
|
return p - buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int year_size( int year )
|
|
|
|
{
|
|
|
|
return leap_year( year ) ? 366 : 365;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TZ_OFFSET 8
|
|
|
|
static ULONG format_datetime( const WS_DATETIME *ptr, unsigned char *buf )
|
|
|
|
{
|
|
|
|
static const char fmt[] = "%04u-%02u-%02uT%02u:%02u:%02u";
|
|
|
|
int day, hour, min, sec, sec_frac, month = 0, year = 1, tz_hour;
|
|
|
|
unsigned __int64 ticks, day_ticks;
|
|
|
|
ULONG len;
|
|
|
|
|
|
|
|
if (ptr->format == WS_DATETIME_FORMAT_LOCAL &&
|
|
|
|
ptr->ticks >= TICKS_1601_01_01 + TZ_OFFSET * TICKS_PER_HOUR)
|
2017-07-12 15:34:33 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
ticks = ptr->ticks - TZ_OFFSET * TICKS_PER_HOUR;
|
|
|
|
tz_hour = TZ_OFFSET;
|
2017-07-12 15:34:33 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
else
|
2017-07-12 15:34:33 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
ticks = ptr->ticks;
|
|
|
|
tz_hour = 0;
|
2017-07-12 15:34:33 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
day = ticks / TICKS_PER_DAY;
|
|
|
|
day_ticks = ticks % TICKS_PER_DAY;
|
|
|
|
hour = day_ticks / TICKS_PER_HOUR;
|
|
|
|
min = (day_ticks % TICKS_PER_HOUR) / TICKS_PER_MIN;
|
|
|
|
sec = (day_ticks % TICKS_PER_MIN) / TICKS_PER_SEC;
|
|
|
|
sec_frac = day_ticks % TICKS_PER_SEC;
|
|
|
|
|
|
|
|
while (day >= year_size( year ))
|
2017-07-12 15:34:33 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
day -= year_size( year );
|
|
|
|
year++;
|
2017-07-12 15:34:33 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
while (day >= month_days[leap_year( year )][month])
|
2017-07-12 15:34:34 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
day -= month_days[leap_year( year )][month];
|
|
|
|
month++;
|
2017-07-12 15:34:34 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
|
|
|
|
len = sprintf( (char *)buf, fmt, year, month + 1, day + 1, hour, min, sec );
|
|
|
|
if (sec_frac)
|
2017-07-12 15:34:35 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
static const char fmt_frac[] = ".%07u";
|
|
|
|
len += sprintf( (char *)buf + len, fmt_frac, sec_frac );
|
|
|
|
while (buf[len - 1] == '0') len--;
|
2017-07-12 15:34:35 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
if (ptr->format == WS_DATETIME_FORMAT_UTC)
|
2017-07-12 15:34:36 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
buf[len++] = 'Z';
|
2017-07-12 15:34:36 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
else if (ptr->format == WS_DATETIME_FORMAT_LOCAL)
|
2017-07-12 15:34:37 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
static const char fmt_tz[] = "%c%02u:00";
|
|
|
|
len += sprintf( (char *)buf + len, fmt_tz, tz_hour ? '-' : '+', tz_hour );
|
|
|
|
}
|
2017-07-12 15:34:37 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
return len;
|
|
|
|
}
|
2017-07-12 15:34:37 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static ULONG format_guid( const GUID *ptr, unsigned char *buf )
|
|
|
|
{
|
2022-01-31 14:13:15 +01:00
|
|
|
static const char fmt[] = "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
|
2017-12-08 15:49:41 +01:00
|
|
|
return sprintf( (char *)buf, fmt, ptr->Data1, ptr->Data2, ptr->Data3,
|
|
|
|
ptr->Data4[0], ptr->Data4[1], ptr->Data4[2], ptr->Data4[3],
|
|
|
|
ptr->Data4[4], ptr->Data4[5], ptr->Data4[6], ptr->Data4[7] );
|
2017-05-23 12:03:54 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static ULONG format_urn( const GUID *ptr, unsigned char *buf )
|
2017-05-30 10:09:05 +02:00
|
|
|
{
|
2022-01-31 14:13:15 +01:00
|
|
|
static const char fmt[] = "urn:uuid:%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
|
2017-12-08 15:49:41 +01:00
|
|
|
return sprintf( (char *)buf, fmt, ptr->Data1, ptr->Data2, ptr->Data3,
|
|
|
|
ptr->Data4[0], ptr->Data4[1], ptr->Data4[2], ptr->Data4[3],
|
|
|
|
ptr->Data4[4], ptr->Data4[5], ptr->Data4[6], ptr->Data4[7] );
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG format_qname( const WS_XML_STRING *prefix, const WS_XML_STRING *localname, unsigned char *buf )
|
|
|
|
{
|
|
|
|
ULONG len = 0;
|
|
|
|
if (prefix && prefix->length)
|
|
|
|
{
|
|
|
|
memcpy( buf, prefix->bytes, prefix->length );
|
|
|
|
len += prefix->length;
|
|
|
|
buf[len++] = ':';
|
|
|
|
}
|
|
|
|
memcpy( buf + len, localname->bytes, localname->length );
|
|
|
|
return len + localname->length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG encode_base64( const unsigned char *bin, ULONG len, unsigned char *buf )
|
|
|
|
{
|
|
|
|
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
ULONG i = 0, x;
|
|
|
|
|
|
|
|
while (len > 0)
|
|
|
|
{
|
|
|
|
buf[i++] = base64[(bin[0] & 0xfc) >> 2];
|
|
|
|
x = (bin[0] & 3) << 4;
|
|
|
|
if (len == 1)
|
|
|
|
{
|
|
|
|
buf[i++] = base64[x];
|
|
|
|
buf[i++] = '=';
|
|
|
|
buf[i++] = '=';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[i++] = base64[x | ((bin[1] & 0xf0) >> 4)];
|
|
|
|
x = (bin[1] & 0x0f) << 2;
|
|
|
|
if (len == 2)
|
|
|
|
{
|
|
|
|
buf[i++] = base64[x];
|
|
|
|
buf[i++] = '=';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[i++] = base64[x | ((bin[2] & 0xc0) >> 6)];
|
|
|
|
buf[i++] = base64[bin[2] & 0x3f];
|
|
|
|
bin += 3;
|
|
|
|
len -= 3;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2018-01-24 14:29:58 +01:00
|
|
|
HRESULT text_to_utf8text( const WS_XML_TEXT *text, const WS_XML_UTF8_TEXT *old, ULONG *offset,
|
|
|
|
WS_XML_UTF8_TEXT **ret )
|
2017-12-08 15:49:41 +01:00
|
|
|
{
|
|
|
|
ULONG len_old = old ? old->value.length : 0;
|
|
|
|
if (offset) *offset = len_old;
|
|
|
|
|
|
|
|
switch (text->textType)
|
|
|
|
{
|
|
|
|
case WS_XML_TEXT_TYPE_UTF8:
|
|
|
|
{
|
|
|
|
const WS_XML_UTF8_TEXT *src = (const WS_XML_UTF8_TEXT *)text;
|
|
|
|
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + src->value.length ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
memcpy( (*ret)->value.bytes + len_old, src->value.bytes, src->value.length );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_UTF16:
|
|
|
|
{
|
|
|
|
const WS_XML_UTF16_TEXT *src = (const WS_XML_UTF16_TEXT *)text;
|
|
|
|
const WCHAR *str = (const WCHAR *)src->bytes;
|
|
|
|
ULONG len = src->byteCount / sizeof(WCHAR), len_utf8;
|
|
|
|
|
|
|
|
if (src->byteCount % sizeof(WCHAR)) return E_INVALIDARG;
|
|
|
|
len_utf8 = WideCharToMultiByte( CP_UTF8, 0, str, len, NULL, 0, NULL, NULL );
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + len_utf8 ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
WideCharToMultiByte( CP_UTF8, 0, str, len, (char *)(*ret)->value.bytes + len_old, len_utf8, NULL, NULL );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_BASE64:
|
|
|
|
{
|
|
|
|
const WS_XML_BASE64_TEXT *base64 = (const WS_XML_BASE64_TEXT *)text;
|
|
|
|
ULONG len = ((4 * base64->length / 3) + 3) & ~3;
|
|
|
|
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + len ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
(*ret)->value.length = encode_base64( base64->bytes, base64->length, (*ret)->value.bytes + len_old ) + len_old;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_BOOL:
|
|
|
|
{
|
|
|
|
const WS_XML_BOOL_TEXT *bool_text = (const WS_XML_BOOL_TEXT *)text;
|
|
|
|
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + 5 ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
(*ret)->value.length = format_bool( &bool_text->value, (*ret)->value.bytes + len_old ) + len_old;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_INT32:
|
|
|
|
{
|
|
|
|
const WS_XML_INT32_TEXT *int32_text = (const WS_XML_INT32_TEXT *)text;
|
|
|
|
unsigned char buf[12]; /* "-2147483648" */
|
|
|
|
ULONG len = format_int32( &int32_text->value, buf );
|
|
|
|
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + len ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
memcpy( (*ret)->value.bytes + len_old, buf, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_INT64:
|
|
|
|
{
|
|
|
|
const WS_XML_INT64_TEXT *int64_text = (const WS_XML_INT64_TEXT *)text;
|
|
|
|
unsigned char buf[21]; /* "-9223372036854775808" */
|
|
|
|
ULONG len = format_int64( &int64_text->value, buf );
|
|
|
|
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + len ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
memcpy( (*ret)->value.bytes + len_old, buf, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_UINT64:
|
|
|
|
{
|
|
|
|
const WS_XML_UINT64_TEXT *uint64_text = (const WS_XML_UINT64_TEXT *)text;
|
|
|
|
unsigned char buf[21]; /* "18446744073709551615" */
|
|
|
|
ULONG len = format_uint64( &uint64_text->value, buf );
|
|
|
|
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + len ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
memcpy( (*ret)->value.bytes + len_old, buf, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_DOUBLE:
|
|
|
|
{
|
|
|
|
const WS_XML_DOUBLE_TEXT *double_text = (const WS_XML_DOUBLE_TEXT *)text;
|
|
|
|
unsigned char buf[32]; /* "-1.1111111111111111E-308", oversized to address Valgrind limitations */
|
2019-10-31 22:18:32 +01:00
|
|
|
unsigned int fpword = _control87( 0, 0 );
|
2017-12-08 15:49:41 +01:00
|
|
|
ULONG len;
|
|
|
|
|
2019-10-31 22:18:32 +01:00
|
|
|
_control87( _MCW_EM | _RC_NEAR | _PC_64, _MCW_EM | _MCW_RC | _MCW_PC );
|
2017-12-08 15:49:41 +01:00
|
|
|
len = format_double( &double_text->value, buf );
|
2019-10-31 22:18:32 +01:00
|
|
|
_control87( fpword, _MCW_EM | _MCW_RC | _MCW_PC );
|
2017-12-08 15:49:41 +01:00
|
|
|
if (!len) return E_NOTIMPL;
|
|
|
|
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + len ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
memcpy( (*ret)->value.bytes + len_old, buf, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_GUID:
|
|
|
|
{
|
|
|
|
const WS_XML_GUID_TEXT *id = (const WS_XML_GUID_TEXT *)text;
|
|
|
|
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + 37 ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
(*ret)->value.length = format_guid( &id->value, (*ret)->value.bytes + len_old ) + len_old;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_UNIQUE_ID:
|
|
|
|
{
|
|
|
|
const WS_XML_UNIQUE_ID_TEXT *id = (const WS_XML_UNIQUE_ID_TEXT *)text;
|
|
|
|
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + 46 ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
(*ret)->value.length = format_urn( &id->value, (*ret)->value.bytes + len_old ) + len_old;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_DATETIME:
|
|
|
|
{
|
|
|
|
const WS_XML_DATETIME_TEXT *dt = (const WS_XML_DATETIME_TEXT *)text;
|
|
|
|
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + 34 ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
(*ret)->value.length = format_datetime( &dt->value, (*ret)->value.bytes + len_old ) + len_old;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_QNAME:
|
|
|
|
{
|
|
|
|
const WS_XML_QNAME_TEXT *qn = (const WS_XML_QNAME_TEXT *)text;
|
|
|
|
ULONG len = qn->localName->length;
|
|
|
|
|
|
|
|
if (qn->prefix && qn->prefix->length) len += qn->prefix->length + 1;
|
|
|
|
if (!(*ret = alloc_utf8_text( NULL, len_old + len ))) return E_OUTOFMEMORY;
|
|
|
|
if (old) memcpy( (*ret)->value.bytes, old->value.bytes, len_old );
|
|
|
|
(*ret)->value.length = format_qname( qn->prefix, qn->localName, (*ret)->value.bytes + len_old ) + len_old;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled text type %u\n", text->textType );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_attribute_value_bin( struct writer *writer, const WS_XML_TEXT *text )
|
|
|
|
{
|
|
|
|
enum record_type type;
|
|
|
|
BOOL use_dict = FALSE;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG id;
|
|
|
|
|
|
|
|
if (text && text->textType == WS_XML_TEXT_TYPE_UTF8)
|
|
|
|
{
|
|
|
|
const WS_XML_UTF8_TEXT *utf8 = (const WS_XML_UTF8_TEXT *)text;
|
|
|
|
use_dict = get_string_id( writer, &utf8->value, &id );
|
|
|
|
}
|
|
|
|
type = get_attr_text_record_type( text, use_dict );
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RECORD_CHARS8_TEXT:
|
|
|
|
{
|
|
|
|
const WS_XML_UTF8_TEXT *text_utf8;
|
|
|
|
WS_XML_UTF8_TEXT *new = NULL;
|
|
|
|
UINT8 len;
|
|
|
|
|
|
|
|
if (!text)
|
|
|
|
{
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
write_char( writer, 0 );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if (text->textType == WS_XML_TEXT_TYPE_UTF8) text_utf8 = (const WS_XML_UTF8_TEXT *)text;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((hr = text_to_utf8text( text, NULL, NULL, &new )) != S_OK) return hr;
|
|
|
|
text_utf8 = new;
|
|
|
|
}
|
|
|
|
len = text_utf8->value.length;
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(len) + len )) != S_OK)
|
|
|
|
{
|
2022-02-01 14:57:00 +01:00
|
|
|
free( new );
|
2017-12-08 15:49:41 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
write_char( writer, len );
|
|
|
|
write_bytes( writer, text_utf8->value.bytes, len );
|
2022-02-01 14:57:00 +01:00
|
|
|
free( new );
|
2017-12-08 15:49:41 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_CHARS16_TEXT:
|
|
|
|
{
|
|
|
|
const WS_XML_UTF8_TEXT *text_utf8;
|
|
|
|
WS_XML_UTF8_TEXT *new = NULL;
|
|
|
|
UINT16 len;
|
|
|
|
|
|
|
|
if (text->textType == WS_XML_TEXT_TYPE_UTF8) text_utf8 = (const WS_XML_UTF8_TEXT *)text;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((hr = text_to_utf8text( text, NULL, NULL, &new )) != S_OK) return hr;
|
|
|
|
text_utf8 = new;
|
|
|
|
}
|
|
|
|
len = text_utf8->value.length;
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(len) + len )) != S_OK)
|
|
|
|
{
|
2022-02-01 14:57:00 +01:00
|
|
|
free( new );
|
2017-12-08 15:49:41 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
write_bytes( writer, (const BYTE *)&len, sizeof(len) );
|
|
|
|
write_bytes( writer, text_utf8->value.bytes, len );
|
2022-02-01 14:57:00 +01:00
|
|
|
free( new );
|
2017-12-08 15:49:41 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_BYTES8_TEXT:
|
|
|
|
{
|
|
|
|
WS_XML_BASE64_TEXT *text_base64 = (WS_XML_BASE64_TEXT *)text;
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + text_base64->length )) != S_OK) return hr;
|
|
|
|
write_char( writer, text_base64->length );
|
|
|
|
write_bytes( writer, text_base64->bytes, text_base64->length );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_BYTES16_TEXT:
|
|
|
|
{
|
|
|
|
WS_XML_BASE64_TEXT *text_base64 = (WS_XML_BASE64_TEXT *)text;
|
|
|
|
UINT16 len = text_base64->length;
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(len) + len )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)&len, sizeof(len) );
|
|
|
|
write_bytes( writer, text_base64->bytes, len );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_ZERO_TEXT:
|
|
|
|
case RECORD_ONE_TEXT:
|
|
|
|
case RECORD_FALSE_TEXT:
|
|
|
|
case RECORD_TRUE_TEXT:
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
case RECORD_INT8_TEXT:
|
|
|
|
{
|
|
|
|
INT8 val = get_text_value_int( text );
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(val) )) != S_OK) return hr;
|
|
|
|
write_char( writer, val );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_INT16_TEXT:
|
|
|
|
{
|
|
|
|
INT16 val = get_text_value_int( text );
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(val) )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)&val, sizeof(val) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_INT32_TEXT:
|
|
|
|
{
|
|
|
|
INT32 val = get_text_value_int( text );
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(val) )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)&val, sizeof(val) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_INT64_TEXT:
|
|
|
|
{
|
|
|
|
INT64 val = get_text_value_int( text );
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(val) )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)&val, sizeof(val) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_UINT64_TEXT:
|
|
|
|
{
|
|
|
|
WS_XML_UINT64_TEXT *text_uint64 = (WS_XML_UINT64_TEXT *)text;
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(text_uint64->value) )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)&text_uint64->value, sizeof(text_uint64->value) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_DOUBLE_TEXT:
|
|
|
|
{
|
|
|
|
WS_XML_DOUBLE_TEXT *text_double = (WS_XML_DOUBLE_TEXT *)text;
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(text_double->value) )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)&text_double->value, sizeof(text_double->value) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_GUID_TEXT:
|
|
|
|
{
|
|
|
|
WS_XML_GUID_TEXT *text_guid = (WS_XML_GUID_TEXT *)text;
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(text_guid->value) )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)&text_guid->value, sizeof(text_guid->value) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_UNIQUE_ID_TEXT:
|
|
|
|
{
|
|
|
|
WS_XML_UNIQUE_ID_TEXT *text_unique_id = (WS_XML_UNIQUE_ID_TEXT *)text;
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(text_unique_id->value) )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)&text_unique_id->value, sizeof(text_unique_id->value) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_DATETIME_TEXT:
|
|
|
|
{
|
|
|
|
WS_XML_DATETIME_TEXT *text_datetime = (WS_XML_DATETIME_TEXT *)text;
|
|
|
|
UINT64 val = text_datetime->value.ticks;
|
|
|
|
|
|
|
|
assert( val <= TICKS_MAX );
|
|
|
|
if (text_datetime->value.format == WS_DATETIME_FORMAT_UTC) val |= (UINT64)1 << 62;
|
|
|
|
else if (text_datetime->value.format == WS_DATETIME_FORMAT_LOCAL) val |= (UINT64)1 << 63;
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, sizeof(val) )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)&val, sizeof(val) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled record type %02x\n", type );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum record_type get_attr_record_type( const WS_XML_ATTRIBUTE *attr, BOOL use_dict )
|
|
|
|
{
|
|
|
|
if (!attr->prefix || !attr->prefix->length)
|
|
|
|
{
|
|
|
|
if (use_dict) return RECORD_SHORT_DICTIONARY_ATTRIBUTE;
|
|
|
|
return RECORD_SHORT_ATTRIBUTE;
|
|
|
|
}
|
2017-05-30 10:09:05 +02:00
|
|
|
if (attr->prefix->length == 1 && attr->prefix->bytes[0] >= 'a' && attr->prefix->bytes[0] <= 'z')
|
|
|
|
{
|
2017-05-30 10:09:07 +02:00
|
|
|
if (use_dict) return RECORD_PREFIX_DICTIONARY_ATTRIBUTE_A + attr->prefix->bytes[0] - 'a';
|
2017-05-30 10:09:05 +02:00
|
|
|
return RECORD_PREFIX_ATTRIBUTE_A + attr->prefix->bytes[0] - 'a';
|
|
|
|
}
|
2017-05-30 10:09:07 +02:00
|
|
|
if (use_dict) return RECORD_DICTIONARY_ATTRIBUTE;
|
2017-05-30 10:09:05 +02:00
|
|
|
return RECORD_ATTRIBUTE;
|
|
|
|
};
|
|
|
|
|
2017-05-23 12:03:54 +02:00
|
|
|
static HRESULT write_attribute_bin( struct writer *writer, const WS_XML_ATTRIBUTE *attr )
|
|
|
|
{
|
2017-06-22 10:43:11 +02:00
|
|
|
ULONG id;
|
2017-09-06 15:56:10 +02:00
|
|
|
enum record_type type = get_attr_record_type( attr, get_string_id(writer, attr->localName, &id) );
|
2017-05-23 12:03:54 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
|
|
|
|
if (type >= RECORD_PREFIX_ATTRIBUTE_A && type <= RECORD_PREFIX_ATTRIBUTE_Z)
|
|
|
|
{
|
|
|
|
if ((hr = write_string( writer, attr->localName->bytes, attr->localName->length )) != S_OK) return hr;
|
|
|
|
return write_attribute_value_bin( writer, attr->value );
|
|
|
|
}
|
2017-05-30 10:09:05 +02:00
|
|
|
if (type >= RECORD_PREFIX_DICTIONARY_ATTRIBUTE_A && type <= RECORD_PREFIX_DICTIONARY_ATTRIBUTE_Z)
|
|
|
|
{
|
2017-06-22 10:43:11 +02:00
|
|
|
if ((hr = write_dict_string( writer, id )) != S_OK) return hr;
|
2017-05-30 10:09:05 +02:00
|
|
|
return write_attribute_value_bin( writer, attr->value );
|
|
|
|
}
|
2017-05-23 12:03:54 +02:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RECORD_SHORT_ATTRIBUTE:
|
|
|
|
if ((hr = write_string( writer, attr->localName->bytes, attr->localName->length )) != S_OK) return hr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECORD_ATTRIBUTE:
|
|
|
|
if ((hr = write_string( writer, attr->prefix->bytes, attr->prefix->length )) != S_OK) return hr;
|
|
|
|
if ((hr = write_string( writer, attr->localName->bytes, attr->localName->length )) != S_OK) return hr;
|
|
|
|
break;
|
|
|
|
|
2017-05-30 10:09:05 +02:00
|
|
|
case RECORD_SHORT_DICTIONARY_ATTRIBUTE:
|
2017-06-22 10:43:11 +02:00
|
|
|
if ((hr = write_dict_string( writer, id )) != S_OK) return hr;
|
2017-05-30 10:09:05 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RECORD_DICTIONARY_ATTRIBUTE:
|
|
|
|
if ((hr = write_string( writer, attr->prefix->bytes, attr->prefix->length )) != S_OK) return hr;
|
2017-06-22 10:43:11 +02:00
|
|
|
if ((hr = write_dict_string( writer, id )) != S_OK) return hr;
|
2017-05-30 10:09:05 +02:00
|
|
|
break;
|
|
|
|
|
2017-05-23 12:03:54 +02:00
|
|
|
default:
|
2017-05-30 10:09:05 +02:00
|
|
|
ERR( "unhandled record type %02x\n", type );
|
2017-05-23 12:03:54 +02:00
|
|
|
return WS_E_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return write_attribute_value_bin( writer, attr->value );
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_attribute( struct writer *writer, const WS_XML_ATTRIBUTE *attr )
|
|
|
|
{
|
|
|
|
switch (writer->output_enc)
|
|
|
|
{
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT: return write_attribute_text( writer, attr );
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY: return write_attribute_bin( writer, attr );
|
|
|
|
default:
|
|
|
|
ERR( "unhandled encoding %u\n", writer->output_enc );
|
|
|
|
return WS_E_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 11:02:03 +01:00
|
|
|
static inline BOOL is_current_namespace( struct writer *writer, const WS_XML_STRING *ns )
|
|
|
|
{
|
|
|
|
return (WsXmlStringEquals( writer->current_ns, ns, NULL ) == S_OK);
|
|
|
|
}
|
|
|
|
|
2016-02-23 13:11:52 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsGetPrefixFromNamespace [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsGetPrefixFromNamespace( WS_XML_WRITER *handle, const WS_XML_STRING *ns,
|
|
|
|
BOOL required, const WS_XML_STRING **prefix,
|
|
|
|
WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
WS_XML_ELEMENT_NODE *elem;
|
|
|
|
BOOL found = FALSE;
|
2017-03-08 11:25:57 +01:00
|
|
|
HRESULT hr = S_OK;
|
2016-02-23 13:11:52 +01:00
|
|
|
|
|
|
|
TRACE( "%p %s %d %p %p\n", handle, debugstr_xmlstr(ns), required, prefix, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !ns || !prefix) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2016-02-23 13:11:52 +01:00
|
|
|
elem = &writer->current->hdr;
|
|
|
|
if (elem->prefix && is_current_namespace( writer, ns ))
|
|
|
|
{
|
|
|
|
*prefix = elem->prefix;
|
|
|
|
found = TRUE;
|
|
|
|
}
|
2017-03-08 11:25:57 +01:00
|
|
|
|
2016-02-23 13:11:52 +01:00
|
|
|
if (!found)
|
|
|
|
{
|
2017-03-08 11:25:57 +01:00
|
|
|
if (required) hr = WS_E_INVALID_FORMAT;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*prefix = NULL;
|
|
|
|
hr = S_FALSE;
|
|
|
|
}
|
2016-02-23 13:11:52 +01:00
|
|
|
}
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-02-23 13:11:52 +01:00
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:52 +02:00
|
|
|
static HRESULT write_namespace_attribute_text( struct writer *writer, const WS_XML_ATTRIBUTE *attr )
|
2016-02-23 13:11:50 +01:00
|
|
|
{
|
|
|
|
unsigned char quote = attr->singleQuote ? '\'' : '"';
|
|
|
|
ULONG size;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* ' xmlns:prefix="namespace"' */
|
|
|
|
|
|
|
|
size = attr->ns->length + 9 /* ' xmlns=""' */;
|
2018-01-24 14:29:59 +01:00
|
|
|
if (attr->prefix && attr->prefix->length) size += attr->prefix->length + 1 /* ':' */;
|
2016-02-23 13:11:50 +01:00
|
|
|
if ((hr = write_grow_buffer( writer, size )) != S_OK) return hr;
|
|
|
|
|
|
|
|
write_bytes( writer, (const BYTE *)" xmlns", 6 );
|
2018-01-24 14:29:59 +01:00
|
|
|
if (attr->prefix && attr->prefix->length)
|
2016-02-23 13:11:50 +01:00
|
|
|
{
|
|
|
|
write_char( writer, ':' );
|
|
|
|
write_bytes( writer, attr->prefix->bytes, attr->prefix->length );
|
|
|
|
}
|
|
|
|
write_char( writer, '=' );
|
|
|
|
write_char( writer, quote );
|
|
|
|
write_bytes( writer, attr->ns->bytes, attr->ns->length );
|
|
|
|
write_char( writer, quote );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-30 10:09:07 +02:00
|
|
|
static enum record_type get_xmlns_record_type( const WS_XML_ATTRIBUTE *attr, BOOL use_dict )
|
2017-05-23 12:03:52 +02:00
|
|
|
{
|
2017-05-30 10:09:05 +02:00
|
|
|
if (!attr->prefix || !attr->prefix->length)
|
|
|
|
{
|
2017-05-30 10:09:07 +02:00
|
|
|
if (use_dict) return RECORD_SHORT_DICTIONARY_XMLNS_ATTRIBUTE;
|
2017-05-30 10:09:05 +02:00
|
|
|
return RECORD_SHORT_XMLNS_ATTRIBUTE;
|
|
|
|
}
|
2017-05-30 10:09:07 +02:00
|
|
|
if (use_dict) return RECORD_DICTIONARY_XMLNS_ATTRIBUTE;
|
2017-05-23 12:03:52 +02:00
|
|
|
return RECORD_XMLNS_ATTRIBUTE;
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT write_namespace_attribute_bin( struct writer *writer, const WS_XML_ATTRIBUTE *attr )
|
|
|
|
{
|
2017-06-22 10:43:11 +02:00
|
|
|
ULONG id;
|
2017-09-06 15:56:10 +02:00
|
|
|
enum record_type type = get_xmlns_record_type( attr, get_string_id(writer, attr->ns, &id) );
|
2017-05-23 12:03:52 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RECORD_SHORT_XMLNS_ATTRIBUTE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECORD_XMLNS_ATTRIBUTE:
|
|
|
|
if ((hr = write_string( writer, attr->prefix->bytes, attr->prefix->length )) != S_OK) return hr;
|
|
|
|
break;
|
|
|
|
|
2017-05-30 10:09:05 +02:00
|
|
|
case RECORD_SHORT_DICTIONARY_XMLNS_ATTRIBUTE:
|
2017-06-22 10:43:11 +02:00
|
|
|
return write_dict_string( writer, id );
|
2017-05-30 10:09:05 +02:00
|
|
|
|
|
|
|
case RECORD_DICTIONARY_XMLNS_ATTRIBUTE:
|
|
|
|
if ((hr = write_string( writer, attr->prefix->bytes, attr->prefix->length )) != S_OK) return hr;
|
2017-06-22 10:43:11 +02:00
|
|
|
return write_dict_string( writer, id );
|
2017-05-30 10:09:05 +02:00
|
|
|
|
2017-05-23 12:03:52 +02:00
|
|
|
default:
|
2017-05-30 10:09:05 +02:00
|
|
|
ERR( "unhandled record type %02x\n", type );
|
2017-05-23 12:03:52 +02:00
|
|
|
return WS_E_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return write_string( writer, attr->ns->bytes, attr->ns->length );
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_namespace_attribute( struct writer *writer, const WS_XML_ATTRIBUTE *attr )
|
|
|
|
{
|
|
|
|
switch (writer->output_enc)
|
|
|
|
{
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT: return write_namespace_attribute_text( writer, attr );
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY: return write_namespace_attribute_bin( writer, attr );
|
|
|
|
default:
|
|
|
|
ERR( "unhandled encoding %u\n", writer->output_enc );
|
|
|
|
return WS_E_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:53 +02:00
|
|
|
static HRESULT add_namespace_attribute( struct writer *writer, const WS_XML_STRING *prefix,
|
|
|
|
const WS_XML_STRING *ns, BOOL single )
|
2016-02-23 13:11:50 +01:00
|
|
|
{
|
|
|
|
WS_XML_ATTRIBUTE *attr;
|
|
|
|
WS_XML_ELEMENT_NODE *elem = &writer->current->hdr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-01 14:57:00 +01:00
|
|
|
if (!(attr = calloc( 1, sizeof(*attr) ))) return E_OUTOFMEMORY;
|
2016-02-23 13:11:50 +01:00
|
|
|
|
|
|
|
attr->singleQuote = !!single;
|
|
|
|
attr->isXmlNs = 1;
|
2017-09-06 15:56:09 +02:00
|
|
|
if (prefix && !(attr->prefix = dup_xml_string( prefix, writer->dict_do_lookup )))
|
2016-02-23 13:11:50 +01:00
|
|
|
{
|
|
|
|
free_attribute( attr );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2017-09-06 15:56:09 +02:00
|
|
|
if (!(attr->ns = dup_xml_string( ns, writer->dict_do_lookup )))
|
2016-02-23 13:11:50 +01:00
|
|
|
{
|
|
|
|
free_attribute( attr );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
if ((hr = append_attribute( elem, attr )) != S_OK)
|
|
|
|
{
|
|
|
|
free_attribute( attr );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-25 20:02:45 +02:00
|
|
|
static inline BOOL str_equal( const WS_XML_STRING *str1, const WS_XML_STRING *str2 )
|
|
|
|
{
|
|
|
|
if (!str1 && !str2) return TRUE;
|
|
|
|
return WsXmlStringEquals( str1, str2, NULL ) == S_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-15 09:21:20 +02:00
|
|
|
static BOOL namespace_in_scope( const WS_XML_ELEMENT_NODE *elem, const WS_XML_STRING *prefix,
|
|
|
|
const WS_XML_STRING *ns )
|
2016-02-23 13:11:50 +01:00
|
|
|
{
|
|
|
|
ULONG i;
|
2016-06-15 09:21:20 +02:00
|
|
|
const struct node *node;
|
|
|
|
|
|
|
|
for (node = (const struct node *)elem; node; node = node->parent)
|
2016-02-23 13:11:50 +01:00
|
|
|
{
|
2016-06-15 09:21:20 +02:00
|
|
|
if (node_type( node ) != WS_XML_NODE_TYPE_ELEMENT) break;
|
|
|
|
|
|
|
|
elem = &node->hdr;
|
|
|
|
for (i = 0; i < elem->attributeCount; i++)
|
2016-02-23 13:11:50 +01:00
|
|
|
{
|
2016-06-15 09:21:20 +02:00
|
|
|
if (!elem->attributes[i]->isXmlNs) continue;
|
2016-08-25 20:02:45 +02:00
|
|
|
if (str_equal( elem->attributes[i]->prefix, prefix ) &&
|
|
|
|
str_equal( elem->attributes[i]->ns, ns )) return TRUE;
|
2016-02-23 13:11:50 +01:00
|
|
|
}
|
|
|
|
}
|
2016-06-15 09:21:20 +02:00
|
|
|
return FALSE;
|
2016-02-23 13:11:50 +01:00
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:53 +02:00
|
|
|
static HRESULT set_current_namespace( struct writer *writer, const WS_XML_STRING *ns )
|
|
|
|
{
|
|
|
|
WS_XML_STRING *str;
|
2017-09-06 15:56:09 +02:00
|
|
|
if (!(str = dup_xml_string( ns, writer->dict_do_lookup ))) return E_OUTOFMEMORY;
|
2017-05-30 10:09:07 +02:00
|
|
|
free_xml_string( writer->current_ns );
|
2017-05-23 12:03:53 +02:00
|
|
|
writer->current_ns = str;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT set_namespaces( struct writer *writer )
|
2016-02-23 13:11:50 +01:00
|
|
|
{
|
|
|
|
WS_XML_ELEMENT_NODE *elem = &writer->current->hdr;
|
|
|
|
HRESULT hr;
|
2017-05-23 12:03:53 +02:00
|
|
|
ULONG i;
|
2016-02-23 13:11:50 +01:00
|
|
|
|
2017-05-23 12:03:53 +02:00
|
|
|
if (elem->ns->length && !namespace_in_scope( elem, elem->prefix, elem->ns ))
|
|
|
|
{
|
|
|
|
if ((hr = add_namespace_attribute( writer, elem->prefix, elem->ns, FALSE )) != S_OK) return hr;
|
|
|
|
if ((hr = set_current_namespace( writer, elem->ns )) != S_OK) return hr;
|
|
|
|
}
|
2016-02-23 13:11:50 +01:00
|
|
|
|
2017-05-23 12:03:53 +02:00
|
|
|
for (i = 0; i < elem->attributeCount; i++)
|
|
|
|
{
|
|
|
|
const WS_XML_ATTRIBUTE *attr = elem->attributes[i];
|
|
|
|
if (!attr->ns->length || namespace_in_scope( elem, attr->prefix, attr->ns )) continue;
|
|
|
|
if ((hr = add_namespace_attribute( writer, attr->prefix, attr->ns, FALSE )) != S_OK) return hr;
|
|
|
|
}
|
2016-02-23 13:11:50 +01:00
|
|
|
|
2017-05-23 12:03:53 +02:00
|
|
|
return S_OK;
|
2016-02-23 13:11:50 +01:00
|
|
|
}
|
|
|
|
|
2015-11-11 11:02:07 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteEndAttribute [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteEndAttribute( WS_XML_WRITER *handle, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2018-10-17 13:42:36 +02:00
|
|
|
HRESULT hr = S_OK;
|
2015-11-11 11:02:07 +01:00
|
|
|
|
|
|
|
TRACE( "%p %p\n", handle, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2015-11-11 11:02:07 +01:00
|
|
|
writer->state = WRITER_STATE_STARTELEMENT;
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2018-10-17 13:42:36 +02:00
|
|
|
return hr;
|
2015-11-11 11:02:07 +01:00
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:52 +02:00
|
|
|
static HRESULT write_attributes( struct writer *writer, const WS_XML_ELEMENT_NODE *elem )
|
2016-06-21 14:04:41 +02:00
|
|
|
{
|
2017-05-23 12:03:52 +02:00
|
|
|
ULONG i;
|
2016-07-04 11:35:41 +02:00
|
|
|
HRESULT hr;
|
|
|
|
for (i = 0; i < elem->attributeCount; i++)
|
|
|
|
{
|
|
|
|
if (elem->attributes[i]->isXmlNs) continue;
|
|
|
|
if ((hr = write_attribute( writer, elem->attributes[i] )) != S_OK) return hr;
|
|
|
|
}
|
|
|
|
for (i = 0; i < elem->attributeCount; i++)
|
2016-06-21 14:04:41 +02:00
|
|
|
{
|
2016-07-04 11:35:41 +02:00
|
|
|
if (!elem->attributes[i]->isXmlNs || !elem->attributes[i]->prefix) continue;
|
|
|
|
if ((hr = write_namespace_attribute( writer, elem->attributes[i] )) != S_OK) return hr;
|
|
|
|
}
|
|
|
|
for (i = 0; i < elem->attributeCount; i++)
|
|
|
|
{
|
|
|
|
if (!elem->attributes[i]->isXmlNs || elem->attributes[i]->prefix) continue;
|
|
|
|
if ((hr = write_namespace_attribute( writer, elem->attributes[i] )) != S_OK) return hr;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
2016-06-21 14:04:41 +02:00
|
|
|
|
2017-05-23 12:03:52 +02:00
|
|
|
static HRESULT write_startelement_text( struct writer *writer )
|
2017-05-23 12:03:51 +02:00
|
|
|
{
|
2017-05-23 12:03:52 +02:00
|
|
|
const WS_XML_ELEMENT_NODE *elem = &writer->current->hdr;
|
|
|
|
ULONG size;
|
2017-05-23 12:03:51 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2017-05-23 12:03:52 +02:00
|
|
|
/* '<prefix:localname prefix:attr="value"... xmlns:prefix="ns"'... */
|
2017-05-23 12:03:51 +02:00
|
|
|
|
2017-05-23 12:03:52 +02:00
|
|
|
size = elem->localName->length + 1 /* '<' */;
|
|
|
|
if (elem->prefix && elem->prefix->length) size += elem->prefix->length + 1 /* ':' */;
|
|
|
|
if ((hr = write_grow_buffer( writer, size )) != S_OK) return hr;
|
2017-05-23 12:03:51 +02:00
|
|
|
|
2017-05-23 12:03:52 +02:00
|
|
|
write_char( writer, '<' );
|
|
|
|
if (elem->prefix && elem->prefix->length)
|
2017-05-23 12:03:51 +02:00
|
|
|
{
|
2017-05-23 12:03:52 +02:00
|
|
|
write_bytes( writer, elem->prefix->bytes, elem->prefix->length );
|
|
|
|
write_char( writer, ':' );
|
2017-05-23 12:03:51 +02:00
|
|
|
}
|
2017-05-23 12:03:52 +02:00
|
|
|
write_bytes( writer, elem->localName->bytes, elem->localName->length );
|
|
|
|
return write_attributes( writer, elem );
|
2017-05-23 12:03:51 +02:00
|
|
|
}
|
|
|
|
|
2017-05-30 10:09:07 +02:00
|
|
|
static enum record_type get_elem_record_type( const WS_XML_ELEMENT_NODE *elem, BOOL use_dict )
|
2017-05-23 12:03:51 +02:00
|
|
|
{
|
2017-05-30 10:09:05 +02:00
|
|
|
if (!elem->prefix || !elem->prefix->length)
|
|
|
|
{
|
2017-05-30 10:09:07 +02:00
|
|
|
if (use_dict) return RECORD_SHORT_DICTIONARY_ELEMENT;
|
2017-05-30 10:09:05 +02:00
|
|
|
return RECORD_SHORT_ELEMENT;
|
|
|
|
}
|
2017-05-23 12:03:52 +02:00
|
|
|
if (elem->prefix->length == 1 && elem->prefix->bytes[0] >= 'a' && elem->prefix->bytes[0] <= 'z')
|
|
|
|
{
|
2017-05-30 10:09:07 +02:00
|
|
|
if (use_dict) return RECORD_PREFIX_DICTIONARY_ELEMENT_A + elem->prefix->bytes[0] - 'a';
|
2017-05-23 12:03:52 +02:00
|
|
|
return RECORD_PREFIX_ELEMENT_A + elem->prefix->bytes[0] - 'a';
|
|
|
|
}
|
2017-05-30 10:09:07 +02:00
|
|
|
if (use_dict) return RECORD_DICTIONARY_ELEMENT;
|
2017-05-23 12:03:52 +02:00
|
|
|
return RECORD_ELEMENT;
|
|
|
|
};
|
2017-05-23 12:03:51 +02:00
|
|
|
|
|
|
|
static HRESULT write_startelement_bin( struct writer *writer )
|
|
|
|
{
|
|
|
|
const WS_XML_ELEMENT_NODE *elem = &writer->current->hdr;
|
2017-06-22 10:43:11 +02:00
|
|
|
ULONG id;
|
2017-09-06 15:56:10 +02:00
|
|
|
enum record_type type = get_elem_record_type( elem, get_string_id(writer, elem->localName, &id) );
|
2017-05-23 12:03:51 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2017-05-23 12:03:52 +02:00
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
|
2017-05-23 12:03:51 +02:00
|
|
|
if (type >= RECORD_PREFIX_ELEMENT_A && type <= RECORD_PREFIX_ELEMENT_Z)
|
|
|
|
{
|
2017-05-23 12:03:52 +02:00
|
|
|
if ((hr = write_string( writer, elem->localName->bytes, elem->localName->length )) != S_OK) return hr;
|
|
|
|
return write_attributes( writer, elem );
|
2017-05-23 12:03:51 +02:00
|
|
|
}
|
2017-05-30 10:09:05 +02:00
|
|
|
if (type >= RECORD_PREFIX_DICTIONARY_ELEMENT_A && type <= RECORD_PREFIX_DICTIONARY_ELEMENT_Z)
|
|
|
|
{
|
2017-06-22 10:43:11 +02:00
|
|
|
if ((hr = write_dict_string( writer, id )) != S_OK) return hr;
|
2017-05-30 10:09:05 +02:00
|
|
|
return write_attributes( writer, elem );
|
|
|
|
}
|
2017-05-23 12:03:51 +02:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RECORD_SHORT_ELEMENT:
|
2017-05-23 12:03:52 +02:00
|
|
|
if ((hr = write_string( writer, elem->localName->bytes, elem->localName->length )) != S_OK) return hr;
|
|
|
|
break;
|
2017-05-23 12:03:51 +02:00
|
|
|
|
|
|
|
case RECORD_ELEMENT:
|
|
|
|
if ((hr = write_string( writer, elem->prefix->bytes, elem->prefix->length )) != S_OK) return hr;
|
2017-05-23 12:03:52 +02:00
|
|
|
if ((hr = write_string( writer, elem->localName->bytes, elem->localName->length )) != S_OK) return hr;
|
|
|
|
break;
|
2017-05-23 12:03:51 +02:00
|
|
|
|
2017-05-30 10:09:05 +02:00
|
|
|
case RECORD_SHORT_DICTIONARY_ELEMENT:
|
2017-06-22 10:43:11 +02:00
|
|
|
if ((hr = write_dict_string( writer, id )) != S_OK) return hr;
|
2017-05-30 10:09:05 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RECORD_DICTIONARY_ELEMENT:
|
|
|
|
if ((hr = write_string( writer, elem->prefix->bytes, elem->prefix->length )) != S_OK) return hr;
|
2017-06-22 10:43:11 +02:00
|
|
|
if ((hr = write_dict_string( writer, id )) != S_OK) return hr;
|
2017-05-30 10:09:05 +02:00
|
|
|
break;
|
|
|
|
|
2017-05-23 12:03:51 +02:00
|
|
|
default:
|
2017-05-30 10:09:05 +02:00
|
|
|
ERR( "unhandled record type %02x\n", type );
|
2017-05-23 12:03:51 +02:00
|
|
|
return WS_E_NOT_SUPPORTED;
|
|
|
|
}
|
2017-05-23 12:03:52 +02:00
|
|
|
|
|
|
|
return write_attributes( writer, elem );
|
2017-05-23 12:03:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_startelement( struct writer *writer )
|
|
|
|
{
|
|
|
|
switch (writer->output_enc)
|
|
|
|
{
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT: return write_startelement_text( writer );
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY: return write_startelement_bin( writer );
|
|
|
|
default:
|
|
|
|
ERR( "unhandled encoding %u\n", writer->output_enc );
|
|
|
|
return WS_E_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 11:35:41 +02:00
|
|
|
static struct node *write_find_startelement( struct writer *writer )
|
|
|
|
{
|
|
|
|
struct node *node;
|
|
|
|
for (node = writer->current; node; node = node->parent)
|
|
|
|
{
|
|
|
|
if (node_type( node ) == WS_XML_NODE_TYPE_ELEMENT) return node;
|
2016-06-21 14:04:41 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-04 11:35:41 +02:00
|
|
|
static inline BOOL is_empty_element( const struct node *node )
|
2015-11-11 11:02:02 +01:00
|
|
|
{
|
2016-07-04 11:35:41 +02:00
|
|
|
const struct node *head = LIST_ENTRY( list_head( &node->children ), struct node, entry );
|
|
|
|
return node_type( head ) == WS_XML_NODE_TYPE_END_ELEMENT;
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:51 +02:00
|
|
|
static HRESULT write_endelement_text( struct writer *writer, const WS_XML_ELEMENT_NODE *elem )
|
2016-07-04 11:35:41 +02:00
|
|
|
{
|
|
|
|
ULONG size;
|
2015-11-11 11:02:02 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2016-07-04 11:35:41 +02:00
|
|
|
/* '/>' */
|
2016-06-21 14:04:41 +02:00
|
|
|
|
2016-07-04 11:35:41 +02:00
|
|
|
if (elem->isEmpty && writer->state != WRITER_STATE_ENDSTARTELEMENT)
|
2015-11-11 11:02:02 +01:00
|
|
|
{
|
2016-07-04 11:35:41 +02:00
|
|
|
if ((hr = write_grow_buffer( writer, 2 )) != S_OK) return hr;
|
2015-11-11 11:02:02 +01:00
|
|
|
write_char( writer, '/' );
|
|
|
|
write_char( writer, '>' );
|
2016-07-04 11:35:41 +02:00
|
|
|
return S_OK;
|
2015-11-11 11:02:02 +01:00
|
|
|
}
|
2016-07-04 11:35:41 +02:00
|
|
|
|
|
|
|
/* '</prefix:localname>' */
|
|
|
|
|
|
|
|
size = elem->localName->length + 3 /* '</>' */;
|
2017-05-15 09:59:21 +02:00
|
|
|
if (elem->prefix && elem->prefix->length) size += elem->prefix->length + 1 /* ':' */;
|
2016-07-04 11:35:41 +02:00
|
|
|
if ((hr = write_grow_buffer( writer, size )) != S_OK) return hr;
|
|
|
|
|
|
|
|
write_char( writer, '<' );
|
|
|
|
write_char( writer, '/' );
|
2017-05-15 09:59:21 +02:00
|
|
|
if (elem->prefix && elem->prefix->length)
|
2015-11-11 11:02:02 +01:00
|
|
|
{
|
2016-07-04 11:35:41 +02:00
|
|
|
write_bytes( writer, elem->prefix->bytes, elem->prefix->length );
|
|
|
|
write_char( writer, ':' );
|
2015-11-11 11:02:02 +01:00
|
|
|
}
|
2016-07-04 11:35:41 +02:00
|
|
|
write_bytes( writer, elem->localName->bytes, elem->localName->length );
|
|
|
|
write_char( writer, '>' );
|
2016-06-21 14:04:41 +02:00
|
|
|
return S_OK;
|
2016-07-04 11:35:41 +02:00
|
|
|
}
|
2016-06-21 14:04:41 +02:00
|
|
|
|
2017-05-23 12:03:51 +02:00
|
|
|
static HRESULT write_endelement_bin( struct writer *writer )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2017-05-23 12:03:54 +02:00
|
|
|
if (node_type( writer->current ) == WS_XML_NODE_TYPE_TEXT) return S_OK;
|
2017-05-23 12:03:51 +02:00
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
write_char( writer, RECORD_ENDELEMENT );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_endelement( struct writer *writer, const WS_XML_ELEMENT_NODE *elem )
|
|
|
|
{
|
|
|
|
switch (writer->output_enc)
|
|
|
|
{
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT: return write_endelement_text( writer, elem );
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY: return write_endelement_bin( writer );
|
|
|
|
default:
|
|
|
|
ERR( "unhandled encoding %u\n", writer->output_enc );
|
|
|
|
return WS_E_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 11:35:41 +02:00
|
|
|
static HRESULT write_close_element( struct writer *writer, struct node *node )
|
|
|
|
{
|
|
|
|
WS_XML_ELEMENT_NODE *elem = &node->hdr;
|
|
|
|
elem->isEmpty = is_empty_element( node );
|
|
|
|
return write_endelement( writer, elem );
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_endelement_node( struct writer *writer )
|
|
|
|
{
|
|
|
|
struct node *node;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!(node = write_find_startelement( writer ))) return WS_E_INVALID_FORMAT;
|
|
|
|
if (writer->state == WRITER_STATE_STARTELEMENT)
|
|
|
|
{
|
2017-05-23 12:03:53 +02:00
|
|
|
if ((hr = set_namespaces( writer )) != S_OK) return hr;
|
2016-07-04 11:35:41 +02:00
|
|
|
if ((hr = write_startelement( writer )) != S_OK) return hr;
|
|
|
|
}
|
|
|
|
if ((hr = write_close_element( writer, node )) != S_OK) return hr;
|
|
|
|
writer->current = node->parent;
|
|
|
|
writer->state = WRITER_STATE_ENDELEMENT;
|
|
|
|
return S_OK;
|
2015-11-11 11:02:02 +01:00
|
|
|
}
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteEndElement [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteEndElement( WS_XML_WRITER *handle, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2017-03-08 11:25:57 +01:00
|
|
|
HRESULT hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
TRACE( "%p %p\n", handle, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = write_endelement_node( writer );
|
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-07-04 11:35:41 +02:00
|
|
|
}
|
2016-01-21 15:27:59 +01:00
|
|
|
|
2017-05-23 12:03:51 +02:00
|
|
|
static HRESULT write_endstartelement_text( struct writer *writer )
|
2016-07-04 11:35:41 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
write_char( writer, '>' );
|
|
|
|
return S_OK;
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:51 +02:00
|
|
|
static HRESULT write_endstartelement( struct writer *writer )
|
|
|
|
{
|
|
|
|
switch (writer->output_enc)
|
|
|
|
{
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT: return write_endstartelement_text( writer );
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY: return S_OK;
|
|
|
|
default:
|
|
|
|
ERR( "unhandled encoding %u\n", writer->output_enc );
|
|
|
|
return WS_E_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 11:02:04 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteEndStartElement [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteEndStartElement( WS_XML_WRITER *handle, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "%p %p\n", handle, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2016-07-04 11:35:41 +02:00
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (writer->state != WRITER_STATE_STARTELEMENT) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else
|
2017-03-08 11:25:57 +01:00
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
if ((hr = set_namespaces( writer )) != S_OK) goto done;
|
|
|
|
if ((hr = write_startelement( writer )) != S_OK) goto done;
|
|
|
|
if ((hr = write_endstartelement( writer )) != S_OK) goto done;
|
|
|
|
writer->state = WRITER_STATE_ENDSTARTELEMENT;
|
2017-03-08 11:25:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-09 01:07:00 +01:00
|
|
|
return hr;
|
2015-11-11 11:02:04 +01:00
|
|
|
}
|
|
|
|
|
2016-01-29 13:27:26 +01:00
|
|
|
static HRESULT write_add_attribute( struct writer *writer, const WS_XML_STRING *prefix,
|
|
|
|
const WS_XML_STRING *localname, const WS_XML_STRING *ns,
|
|
|
|
BOOL single )
|
|
|
|
{
|
|
|
|
WS_XML_ATTRIBUTE *attr;
|
|
|
|
WS_XML_ELEMENT_NODE *elem = &writer->current->hdr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-01 14:57:00 +01:00
|
|
|
if (!(attr = calloc( 1, sizeof(*attr) ))) return E_OUTOFMEMORY;
|
2016-01-29 13:27:26 +01:00
|
|
|
|
2017-05-23 12:03:54 +02:00
|
|
|
if (!prefix && ns->length) prefix = elem->prefix;
|
2016-01-29 13:27:26 +01:00
|
|
|
|
|
|
|
attr->singleQuote = !!single;
|
2017-09-06 15:56:09 +02:00
|
|
|
if (prefix && !(attr->prefix = dup_xml_string( prefix, writer->dict_do_lookup )))
|
2016-01-29 13:27:26 +01:00
|
|
|
{
|
|
|
|
free_attribute( attr );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2017-09-06 15:56:09 +02:00
|
|
|
if (!(attr->localName = dup_xml_string( localname, writer->dict_do_lookup )))
|
2016-01-29 13:27:26 +01:00
|
|
|
{
|
|
|
|
free_attribute( attr );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2017-09-06 15:56:09 +02:00
|
|
|
if (!(attr->ns = dup_xml_string( ns, writer->dict_do_lookup )))
|
2016-01-29 13:27:26 +01:00
|
|
|
{
|
|
|
|
free_attribute( attr );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
if ((hr = append_attribute( elem, attr )) != S_OK)
|
|
|
|
{
|
|
|
|
free_attribute( attr );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-11-11 11:02:06 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteStartAttribute [webservices.@]
|
|
|
|
*/
|
2017-12-08 15:49:41 +01:00
|
|
|
HRESULT WINAPI WsWriteStartAttribute( WS_XML_WRITER *handle, const WS_XML_STRING *prefix,
|
|
|
|
const WS_XML_STRING *localname, const WS_XML_STRING *ns,
|
|
|
|
BOOL single, WS_ERROR *error )
|
2015-11-10 10:46:40 +01:00
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2017-03-08 11:25:57 +01:00
|
|
|
HRESULT hr;
|
2015-11-10 10:46:40 +01:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
TRACE( "%p %s %s %s %d %p\n", handle, debugstr_xmlstr(prefix), debugstr_xmlstr(localname),
|
|
|
|
debugstr_xmlstr(ns), single, error );
|
2015-11-10 10:46:40 +01:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !localname || !ns) return E_INVALIDARG;
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (writer->state != WRITER_STATE_STARTELEMENT) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else if ((hr = write_add_attribute( writer, prefix, localname, ns, single )) == S_OK)
|
2017-12-08 15:49:41 +01:00
|
|
|
writer->state = WRITER_STATE_STARTATTRIBUTE;
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2015-11-10 10:46:40 +01:00
|
|
|
}
|
2015-11-11 11:02:08 +01:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
/* flush current start element if necessary */
|
2018-12-04 13:57:28 +01:00
|
|
|
static HRESULT write_commit( struct writer *writer )
|
2016-07-04 11:35:45 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
if (writer->state == WRITER_STATE_STARTELEMENT)
|
2016-07-04 11:35:45 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
HRESULT hr;
|
|
|
|
if ((hr = set_namespaces( writer )) != S_OK) return hr;
|
|
|
|
if ((hr = write_startelement( writer )) != S_OK) return hr;
|
|
|
|
if ((hr = write_endstartelement( writer )) != S_OK) return hr;
|
|
|
|
writer->state = WRITER_STATE_ENDSTARTELEMENT;
|
2016-07-04 11:35:45 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
return S_OK;
|
2016-07-04 11:35:45 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static HRESULT write_add_cdata_node( struct writer *writer )
|
2016-07-04 11:35:45 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
struct node *node, *parent;
|
|
|
|
if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT;
|
|
|
|
if (!(node = alloc_node( WS_XML_NODE_TYPE_CDATA ))) return E_OUTOFMEMORY;
|
|
|
|
write_insert_node( writer, parent, node );
|
|
|
|
return S_OK;
|
2016-07-04 11:35:45 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static HRESULT write_add_endcdata_node( struct writer *writer )
|
2016-07-04 11:35:45 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
struct node *node;
|
|
|
|
if (!(node = alloc_node( WS_XML_NODE_TYPE_END_CDATA ))) return E_OUTOFMEMORY;
|
|
|
|
node->parent = writer->current;
|
|
|
|
list_add_tail( &node->parent->children, &node->entry );
|
|
|
|
return S_OK;
|
2016-07-04 11:35:45 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static HRESULT write_cdata( struct writer *writer )
|
2016-07-04 11:35:45 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
HRESULT hr;
|
|
|
|
if ((hr = write_grow_buffer( writer, 9 )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)"<![CDATA[", 9 );
|
|
|
|
return S_OK;
|
2016-07-04 11:35:45 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static HRESULT write_cdata_node( struct writer *writer )
|
2016-07-08 10:20:30 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
HRESULT hr;
|
2018-12-04 13:57:28 +01:00
|
|
|
if ((hr = write_commit( writer )) != S_OK) return hr;
|
2017-12-08 15:49:41 +01:00
|
|
|
if ((hr = write_add_cdata_node( writer )) != S_OK) return hr;
|
|
|
|
if ((hr = write_add_endcdata_node( writer )) != S_OK) return hr;
|
|
|
|
if ((hr = write_cdata( writer )) != S_OK) return hr;
|
|
|
|
writer->state = WRITER_STATE_STARTCDATA;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2016-07-08 10:20:30 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteStartCData [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteStartCData( WS_XML_WRITER *handle, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
HRESULT hr;
|
2016-07-08 10:20:30 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
TRACE( "%p %p\n", handle, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
2016-07-08 10:20:30 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
if (!writer) return E_INVALIDARG;
|
2016-07-08 10:20:30 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
2016-07-08 10:20:30 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
if (writer->magic != WRITER_MAGIC)
|
2016-07-08 10:20:30 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
2016-07-08 10:20:30 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
hr = write_cdata_node( writer );
|
2016-07-08 10:20:30 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-12-08 15:49:41 +01:00
|
|
|
return hr;
|
2016-10-04 13:28:34 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static HRESULT write_endcdata( struct writer *writer )
|
2016-10-04 13:28:34 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
HRESULT hr;
|
|
|
|
if ((hr = write_grow_buffer( writer, 3 )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)"]]>", 3 );
|
|
|
|
return S_OK;
|
2016-10-04 13:28:34 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static HRESULT write_endcdata_node( struct writer *writer )
|
2016-07-04 11:35:45 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
HRESULT hr;
|
|
|
|
if ((hr = write_endcdata( writer )) != S_OK) return hr;
|
|
|
|
writer->current = writer->current->parent;
|
|
|
|
writer->state = WRITER_STATE_ENDCDATA;
|
|
|
|
return S_OK;
|
2016-07-04 11:35:45 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteEndCData [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteEndCData( WS_XML_WRITER *handle, WS_ERROR *error )
|
2016-07-04 11:35:45 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "%p %p\n", handle, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
2016-07-04 11:35:45 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
if (writer->magic != WRITER_MAGIC)
|
2017-06-21 09:37:38 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
2017-06-21 09:37:38 +02:00
|
|
|
}
|
2016-10-04 13:28:36 +02:00
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (writer->state != WRITER_STATE_TEXT) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else hr = write_endcdata_node( writer );
|
2017-12-08 15:49:41 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-12-08 15:49:41 +01:00
|
|
|
return hr;
|
2016-10-04 13:28:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static HRESULT write_add_element_node( struct writer *writer, const WS_XML_STRING *prefix,
|
|
|
|
const WS_XML_STRING *localname, const WS_XML_STRING *ns )
|
2016-07-04 11:35:42 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
struct node *node, *parent;
|
|
|
|
WS_XML_ELEMENT_NODE *elem;
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT;
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
if (!prefix && node_type( parent ) == WS_XML_NODE_TYPE_ELEMENT)
|
2016-07-04 11:35:42 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
elem = &parent->hdr;
|
|
|
|
if (WsXmlStringEquals( ns, elem->ns, NULL ) == S_OK) prefix = elem->prefix;
|
2016-07-04 11:35:42 +02:00
|
|
|
}
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
if (!(node = alloc_node( WS_XML_NODE_TYPE_ELEMENT ))) return E_OUTOFMEMORY;
|
|
|
|
elem = &node->hdr;
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
if (prefix && !(elem->prefix = dup_xml_string( prefix, writer->dict_do_lookup )))
|
2016-07-04 11:35:45 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
free_node( node );
|
|
|
|
return E_OUTOFMEMORY;
|
2016-07-04 11:35:45 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
if (!(elem->localName = dup_xml_string( localname, writer->dict_do_lookup )))
|
2016-07-04 11:35:45 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
free_node( node );
|
|
|
|
return E_OUTOFMEMORY;
|
2016-07-04 11:35:45 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
if (!(elem->ns = dup_xml_string( ns, writer->dict_do_lookup )))
|
2016-07-04 11:35:45 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
free_node( node );
|
|
|
|
return E_OUTOFMEMORY;
|
2016-07-08 10:20:30 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
write_insert_node( writer, parent, node );
|
|
|
|
return S_OK;
|
|
|
|
}
|
2016-07-08 10:20:30 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static HRESULT write_add_endelement_node( struct writer *writer, struct node *parent )
|
|
|
|
{
|
|
|
|
struct node *node;
|
|
|
|
if (!(node = alloc_node( WS_XML_NODE_TYPE_END_ELEMENT ))) return E_OUTOFMEMORY;
|
|
|
|
node->parent = parent;
|
|
|
|
list_add_tail( &parent->children, &node->entry );
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
static HRESULT write_element_node( struct writer *writer, const WS_XML_STRING *prefix,
|
|
|
|
const WS_XML_STRING *localname, const WS_XML_STRING *ns )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2018-12-04 13:57:28 +01:00
|
|
|
if ((hr = write_commit( writer )) != S_OK) return hr;
|
2017-12-08 15:49:41 +01:00
|
|
|
if ((hr = write_add_element_node( writer, prefix, localname, ns )) != S_OK) return hr;
|
|
|
|
if ((hr = write_add_endelement_node( writer, writer->current )) != S_OK) return hr;
|
|
|
|
writer->state = WRITER_STATE_STARTELEMENT;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteStartElement [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteStartElement( WS_XML_WRITER *handle, const WS_XML_STRING *prefix,
|
|
|
|
const WS_XML_STRING *localname, const WS_XML_STRING *ns,
|
|
|
|
WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
HRESULT hr;
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
TRACE( "%p %s %s %s %p\n", handle, debugstr_xmlstr(prefix), debugstr_xmlstr(localname),
|
|
|
|
debugstr_xmlstr(ns), error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
if (!writer || !localname || !ns) return E_INVALIDARG;
|
2017-06-21 09:37:38 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
2016-07-04 11:35:42 +02:00
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
|
|
|
|
hr = write_element_node( writer, prefix, localname, ns );
|
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-12-08 15:49:41 +01:00
|
|
|
return hr;
|
2016-07-04 11:35:42 +02:00
|
|
|
}
|
|
|
|
|
2018-01-24 14:29:58 +01:00
|
|
|
HRESULT text_to_text( const WS_XML_TEXT *text, const WS_XML_TEXT *old, ULONG *offset, WS_XML_TEXT **ret )
|
2017-07-10 11:02:33 +02:00
|
|
|
{
|
|
|
|
if (offset) *offset = 0;
|
|
|
|
switch (text->textType)
|
|
|
|
{
|
|
|
|
case WS_XML_TEXT_TYPE_UTF8:
|
|
|
|
{
|
|
|
|
const WS_XML_UTF8_TEXT *utf8 = (const WS_XML_UTF8_TEXT *)text;
|
|
|
|
const WS_XML_UTF8_TEXT *utf8_old = (const WS_XML_UTF8_TEXT *)old;
|
|
|
|
WS_XML_UTF8_TEXT *new;
|
|
|
|
ULONG len = utf8->value.length, len_old = utf8_old ? utf8_old->value.length : 0;
|
|
|
|
|
|
|
|
if (!(new = alloc_utf8_text( NULL, len_old + len ))) return E_OUTOFMEMORY;
|
|
|
|
if (utf8_old) memcpy( new->value.bytes, utf8_old->value.bytes, len_old );
|
|
|
|
memcpy( new->value.bytes + len_old, utf8->value.bytes, len );
|
|
|
|
if (offset) *offset = len_old;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_UTF16:
|
|
|
|
{
|
|
|
|
const WS_XML_UTF16_TEXT *utf16 = (const WS_XML_UTF16_TEXT *)text;
|
2017-12-08 15:49:41 +01:00
|
|
|
const WS_XML_UTF16_TEXT *utf16_old = (const WS_XML_UTF16_TEXT *)old;
|
|
|
|
WS_XML_UTF16_TEXT *new;
|
|
|
|
ULONG len = utf16->byteCount, len_old = utf16_old ? utf16_old->byteCount : 0;
|
2017-07-12 15:34:30 +02:00
|
|
|
|
|
|
|
if (utf16->byteCount % sizeof(WCHAR)) return E_INVALIDARG;
|
2017-12-08 15:49:41 +01:00
|
|
|
if (!(new = alloc_utf16_text( NULL, len_old + len ))) return E_OUTOFMEMORY;
|
|
|
|
if (utf16_old) memcpy( new->bytes, utf16_old->bytes, len_old );
|
|
|
|
memcpy( new->bytes + len_old, utf16->bytes, len );
|
2017-07-10 11:02:33 +02:00
|
|
|
if (offset) *offset = len_old;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_BASE64:
|
|
|
|
{
|
|
|
|
const WS_XML_BASE64_TEXT *base64 = (const WS_XML_BASE64_TEXT *)text;
|
|
|
|
const WS_XML_BASE64_TEXT *base64_old = (const WS_XML_BASE64_TEXT *)old;
|
|
|
|
WS_XML_BASE64_TEXT *new;
|
|
|
|
ULONG len = base64->length, len_old = base64_old ? base64_old->length : 0;
|
|
|
|
|
|
|
|
if (!(new = alloc_base64_text( NULL, len_old + len ))) return E_OUTOFMEMORY;
|
|
|
|
if (base64_old) memcpy( new->bytes, base64_old->bytes, len_old );
|
|
|
|
memcpy( new->bytes + len_old, base64->bytes, len );
|
|
|
|
if (offset) *offset = len_old;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_BOOL:
|
|
|
|
{
|
|
|
|
const WS_XML_BOOL_TEXT *bool_text = (const WS_XML_BOOL_TEXT *)text;
|
|
|
|
WS_XML_BOOL_TEXT *new;
|
|
|
|
|
|
|
|
if (!(new = alloc_bool_text( bool_text->value ))) return E_OUTOFMEMORY;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_INT32:
|
|
|
|
{
|
|
|
|
const WS_XML_INT32_TEXT *int32_text = (const WS_XML_INT32_TEXT *)text;
|
|
|
|
WS_XML_INT32_TEXT *new;
|
|
|
|
|
|
|
|
if (!(new = alloc_int32_text( int32_text->value ))) return E_OUTOFMEMORY;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_INT64:
|
|
|
|
{
|
|
|
|
const WS_XML_INT64_TEXT *int64_text = (const WS_XML_INT64_TEXT *)text;
|
|
|
|
WS_XML_INT64_TEXT *new;
|
|
|
|
|
|
|
|
if (!(new = alloc_int64_text( int64_text->value ))) return E_OUTOFMEMORY;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_UINT64:
|
|
|
|
{
|
|
|
|
const WS_XML_UINT64_TEXT *uint64_text = (const WS_XML_UINT64_TEXT *)text;
|
|
|
|
WS_XML_UINT64_TEXT *new;
|
|
|
|
|
|
|
|
if (!(new = alloc_uint64_text( uint64_text->value ))) return E_OUTOFMEMORY;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_DOUBLE:
|
|
|
|
{
|
|
|
|
const WS_XML_DOUBLE_TEXT *double_text = (const WS_XML_DOUBLE_TEXT *)text;
|
|
|
|
WS_XML_DOUBLE_TEXT *new;
|
|
|
|
|
|
|
|
if (!(new = alloc_double_text( double_text->value ))) return E_OUTOFMEMORY;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_GUID:
|
|
|
|
{
|
|
|
|
const WS_XML_GUID_TEXT *id = (const WS_XML_GUID_TEXT *)text;
|
|
|
|
WS_XML_GUID_TEXT *new;
|
|
|
|
|
|
|
|
if (!(new = alloc_guid_text( &id->value ))) return E_OUTOFMEMORY;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_UNIQUE_ID:
|
|
|
|
{
|
|
|
|
const WS_XML_UNIQUE_ID_TEXT *id = (const WS_XML_UNIQUE_ID_TEXT *)text;
|
|
|
|
WS_XML_UNIQUE_ID_TEXT *new;
|
|
|
|
|
|
|
|
if (!(new = alloc_unique_id_text( &id->value ))) return E_OUTOFMEMORY;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_DATETIME:
|
|
|
|
{
|
|
|
|
const WS_XML_DATETIME_TEXT *dt = (const WS_XML_DATETIME_TEXT *)text;
|
|
|
|
WS_XML_DATETIME_TEXT *new;
|
|
|
|
|
|
|
|
if (!(new = alloc_datetime_text( &dt->value ))) return E_OUTOFMEMORY;
|
|
|
|
*ret = &new->text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled text type %u\n", text->textType );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 11:35:42 +02:00
|
|
|
static HRESULT write_set_attribute_value( struct writer *writer, const WS_XML_TEXT *value )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
|
|
|
WS_XML_ELEMENT_NODE *elem = &writer->current->hdr;
|
2016-07-04 11:35:42 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2017-04-28 12:12:46 +02:00
|
|
|
switch (value->textType)
|
|
|
|
{
|
|
|
|
case WS_XML_TEXT_TYPE_UTF8:
|
|
|
|
case WS_XML_TEXT_TYPE_UTF16:
|
|
|
|
case WS_XML_TEXT_TYPE_BASE64:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_XML_TEXT_TYPE_BOOL:
|
|
|
|
case WS_XML_TEXT_TYPE_INT32:
|
|
|
|
case WS_XML_TEXT_TYPE_INT64:
|
|
|
|
case WS_XML_TEXT_TYPE_UINT64:
|
|
|
|
case WS_XML_TEXT_TYPE_DOUBLE:
|
|
|
|
case WS_XML_TEXT_TYPE_GUID:
|
|
|
|
case WS_XML_TEXT_TYPE_UNIQUE_ID:
|
|
|
|
case WS_XML_TEXT_TYPE_DATETIME:
|
2017-07-10 11:02:33 +02:00
|
|
|
if (elem->attributes[elem->attributeCount - 1]->value) return WS_E_INVALID_OPERATION;
|
2017-04-28 12:12:46 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled text type %u\n", value->textType );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2017-07-10 11:02:33 +02:00
|
|
|
switch (writer->output_enc)
|
|
|
|
{
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT:
|
|
|
|
{
|
|
|
|
WS_XML_UTF8_TEXT *new, *old = (WS_XML_UTF8_TEXT *)elem->attributes[elem->attributeCount - 1]->value;
|
|
|
|
if ((hr = text_to_utf8text( value, old, NULL, &new )) != S_OK) return hr;
|
2022-02-01 14:57:00 +01:00
|
|
|
free( old );
|
2017-07-10 11:02:33 +02:00
|
|
|
elem->attributes[elem->attributeCount - 1]->value = &new->text;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY:
|
|
|
|
{
|
|
|
|
WS_XML_TEXT *new, *old = elem->attributes[elem->attributeCount - 1]->value;
|
|
|
|
if ((hr = text_to_text( value, old, NULL, &new )) != S_OK) return hr;
|
2022-02-01 14:57:00 +01:00
|
|
|
free( old );
|
2017-07-10 11:02:33 +02:00
|
|
|
elem->attributes[elem->attributeCount - 1]->value = new;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled output encoding %u\n", writer->output_enc );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2016-07-04 11:35:42 +02:00
|
|
|
return S_OK;
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
2016-07-04 11:35:42 +02:00
|
|
|
static HRESULT write_add_text_node( struct writer *writer, const WS_XML_TEXT *value )
|
2016-06-21 14:04:42 +02:00
|
|
|
{
|
2016-07-04 11:35:41 +02:00
|
|
|
struct node *node;
|
2016-06-21 14:04:42 +02:00
|
|
|
WS_XML_TEXT_NODE *text;
|
2016-07-04 11:35:42 +02:00
|
|
|
HRESULT hr;
|
2016-06-21 14:04:42 +02:00
|
|
|
|
2016-07-04 11:35:41 +02:00
|
|
|
if (node_type( writer->current ) != WS_XML_NODE_TYPE_ELEMENT &&
|
|
|
|
node_type( writer->current ) != WS_XML_NODE_TYPE_BOF &&
|
|
|
|
node_type( writer->current ) != WS_XML_NODE_TYPE_CDATA) return WS_E_INVALID_FORMAT;
|
2016-06-21 14:04:44 +02:00
|
|
|
|
2016-06-21 14:04:42 +02:00
|
|
|
if (!(node = alloc_node( WS_XML_NODE_TYPE_TEXT ))) return E_OUTOFMEMORY;
|
2017-07-10 11:02:33 +02:00
|
|
|
text = (WS_XML_TEXT_NODE *)node;
|
|
|
|
|
|
|
|
switch (writer->output_enc)
|
|
|
|
{
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT:
|
2016-07-04 11:35:42 +02:00
|
|
|
{
|
2017-07-10 11:02:33 +02:00
|
|
|
WS_XML_UTF8_TEXT *new;
|
|
|
|
if ((hr = text_to_utf8text( value, NULL, NULL, &new )) != S_OK)
|
|
|
|
{
|
2022-02-01 14:57:00 +01:00
|
|
|
free( node );
|
2017-07-10 11:02:33 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
text->text = &new->text;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY:
|
|
|
|
{
|
|
|
|
WS_XML_TEXT *new;
|
|
|
|
if ((hr = text_to_text( value, NULL, NULL, &new )) != S_OK)
|
|
|
|
{
|
2022-02-01 14:57:00 +01:00
|
|
|
free( node );
|
2017-07-10 11:02:33 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
text->text = new;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled output encoding %u\n", writer->output_enc );
|
2022-02-01 14:57:00 +01:00
|
|
|
free( node );
|
2017-07-10 11:02:33 +02:00
|
|
|
return E_NOTIMPL;
|
2016-07-04 11:35:42 +02:00
|
|
|
}
|
2016-06-21 14:04:42 +02:00
|
|
|
|
2016-07-04 11:35:41 +02:00
|
|
|
write_insert_node( writer, writer->current, node );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:54 +02:00
|
|
|
static HRESULT write_text_text( struct writer *writer, const WS_XML_TEXT *text, ULONG offset )
|
2016-07-04 11:35:41 +02:00
|
|
|
{
|
2017-05-23 12:03:54 +02:00
|
|
|
const WS_XML_UTF8_TEXT *utf8 = (const WS_XML_UTF8_TEXT *)text;
|
2016-07-04 11:35:41 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2016-09-28 12:37:59 +02:00
|
|
|
if (node_type( writer->current->parent ) == WS_XML_NODE_TYPE_ELEMENT)
|
|
|
|
{
|
|
|
|
const struct escape *escapes[3] = { &escape_lt, &escape_gt, &escape_amp };
|
2017-04-28 12:12:46 +02:00
|
|
|
return write_bytes_escape( writer, utf8->value.bytes + offset, utf8->value.length - offset, escapes, 3 );
|
2016-09-28 12:37:59 +02:00
|
|
|
}
|
|
|
|
else if (node_type( writer->current->parent ) == WS_XML_NODE_TYPE_CDATA)
|
|
|
|
{
|
2017-04-28 12:12:46 +02:00
|
|
|
if ((hr = write_grow_buffer( writer, utf8->value.length - offset )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, utf8->value.bytes + offset, utf8->value.length - offset );
|
2016-09-28 12:37:59 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WS_E_INVALID_FORMAT;
|
2016-07-04 11:35:41 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 15:56:10 +02:00
|
|
|
static enum record_type get_text_record_type( const WS_XML_TEXT *text, BOOL use_dict )
|
2017-07-12 15:34:30 +02:00
|
|
|
{
|
|
|
|
switch (text->textType)
|
|
|
|
{
|
|
|
|
case WS_XML_TEXT_TYPE_UTF8:
|
|
|
|
{
|
|
|
|
const WS_XML_UTF8_TEXT *text_utf8 = (const WS_XML_UTF8_TEXT *)text;
|
2017-09-06 15:56:10 +02:00
|
|
|
if (use_dict) return RECORD_DICTIONARY_TEXT_WITH_ENDELEMENT;
|
2017-07-12 15:34:30 +02:00
|
|
|
if (text_utf8->value.length <= MAX_UINT8) return RECORD_CHARS8_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_utf8->value.length <= MAX_UINT16) return RECORD_CHARS16_TEXT_WITH_ENDELEMENT;
|
|
|
|
return RECORD_CHARS32_TEXT_WITH_ENDELEMENT;
|
|
|
|
}
|
2017-12-08 15:49:41 +01:00
|
|
|
case WS_XML_TEXT_TYPE_UTF16:
|
|
|
|
{
|
|
|
|
const WS_XML_UTF16_TEXT *text_utf16 = (const WS_XML_UTF16_TEXT *)text;
|
|
|
|
int len = text_utf16->byteCount / sizeof(WCHAR);
|
|
|
|
int len_utf8 = WideCharToMultiByte( CP_UTF8, 0, (const WCHAR *)text_utf16->bytes, len, NULL, 0, NULL, NULL );
|
|
|
|
if (len_utf8 <= MAX_UINT8) return RECORD_CHARS8_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (len_utf8 <= MAX_UINT16) return RECORD_CHARS16_TEXT_WITH_ENDELEMENT;
|
|
|
|
return RECORD_CHARS32_TEXT_WITH_ENDELEMENT;
|
|
|
|
}
|
2017-07-12 15:34:31 +02:00
|
|
|
case WS_XML_TEXT_TYPE_BASE64:
|
|
|
|
{
|
|
|
|
const WS_XML_BASE64_TEXT *text_base64 = (const WS_XML_BASE64_TEXT *)text;
|
|
|
|
ULONG rem = text_base64->length % 3, len = text_base64->length - rem;
|
|
|
|
if (len <= MAX_UINT8) return RECORD_BYTES8_TEXT;
|
|
|
|
if (len <= MAX_UINT16) return RECORD_BYTES16_TEXT;
|
|
|
|
return RECORD_BYTES32_TEXT;
|
|
|
|
}
|
2017-07-12 15:34:32 +02:00
|
|
|
case WS_XML_TEXT_TYPE_BOOL:
|
|
|
|
{
|
|
|
|
const WS_XML_BOOL_TEXT *text_bool = (const WS_XML_BOOL_TEXT *)text;
|
|
|
|
return text_bool->value ? RECORD_TRUE_TEXT_WITH_ENDELEMENT : RECORD_FALSE_TEXT_WITH_ENDELEMENT;
|
|
|
|
}
|
2017-07-12 15:34:33 +02:00
|
|
|
case WS_XML_TEXT_TYPE_INT32:
|
|
|
|
{
|
|
|
|
const WS_XML_INT32_TEXT *text_int32 = (const WS_XML_INT32_TEXT *)text;
|
|
|
|
if (!text_int32->value) return RECORD_ZERO_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_int32->value == 1) return RECORD_ONE_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_int32->value >= MIN_INT8 && text_int32->value <= MAX_INT8) return RECORD_INT8_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_int32->value >= MIN_INT16 && text_int32->value <= MAX_INT16) return RECORD_INT16_TEXT_WITH_ENDELEMENT;
|
|
|
|
return RECORD_INT32_TEXT_WITH_ENDELEMENT;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_INT64:
|
|
|
|
{
|
|
|
|
const WS_XML_INT64_TEXT *text_int64 = (const WS_XML_INT64_TEXT *)text;
|
|
|
|
if (!text_int64->value) return RECORD_ZERO_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_int64->value == 1) return RECORD_ONE_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_int64->value >= MIN_INT8 && text_int64->value <= MAX_INT8) return RECORD_INT8_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_int64->value >= MIN_INT16 && text_int64->value <= MAX_INT16) return RECORD_INT16_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_int64->value >= MIN_INT32 && text_int64->value <= MAX_INT32) return RECORD_INT32_TEXT_WITH_ENDELEMENT;
|
|
|
|
return RECORD_INT64_TEXT_WITH_ENDELEMENT;
|
|
|
|
}
|
|
|
|
case WS_XML_TEXT_TYPE_UINT64:
|
|
|
|
{
|
|
|
|
const WS_XML_UINT64_TEXT *text_uint64 = (const WS_XML_UINT64_TEXT *)text;
|
|
|
|
if (!text_uint64->value) return RECORD_ZERO_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_uint64->value == 1) return RECORD_ONE_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_uint64->value <= MAX_INT8) return RECORD_INT8_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_uint64->value <= MAX_INT16) return RECORD_INT16_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_uint64->value <= MAX_INT32) return RECORD_INT32_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_uint64->value <= MAX_INT64) return RECORD_INT64_TEXT_WITH_ENDELEMENT;
|
|
|
|
return RECORD_UINT64_TEXT_WITH_ENDELEMENT;
|
|
|
|
}
|
2017-07-12 15:34:34 +02:00
|
|
|
case WS_XML_TEXT_TYPE_DOUBLE:
|
|
|
|
{
|
|
|
|
const WS_XML_DOUBLE_TEXT *text_double = (const WS_XML_DOUBLE_TEXT *)text;
|
|
|
|
if (!text_double->value) return RECORD_ZERO_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_double->value == 1) return RECORD_ONE_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (isinf( text_double->value ) || (INT64)text_double->value != text_double->value)
|
|
|
|
return RECORD_DOUBLE_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_double->value <= MAX_INT8) return RECORD_INT8_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_double->value <= MAX_INT16) return RECORD_INT16_TEXT_WITH_ENDELEMENT;
|
|
|
|
if (text_double->value <= MAX_INT32) return RECORD_INT32_TEXT_WITH_ENDELEMENT;
|
|
|
|
return RECORD_INT64_TEXT_WITH_ENDELEMENT;
|
|
|
|
}
|
2017-07-12 15:34:35 +02:00
|
|
|
case WS_XML_TEXT_TYPE_GUID:
|
|
|
|
return RECORD_GUID_TEXT_WITH_ENDELEMENT;
|
|
|
|
|
2017-07-12 15:34:36 +02:00
|
|
|
case WS_XML_TEXT_TYPE_UNIQUE_ID:
|
|
|
|
return RECORD_UNIQUE_ID_TEXT_WITH_ENDELEMENT;
|
|
|
|
|
2017-07-12 15:34:37 +02:00
|
|
|
case WS_XML_TEXT_TYPE_DATETIME:
|
|
|
|
return RECORD_DATETIME_TEXT_WITH_ENDELEMENT;
|
|
|
|
|
2017-07-12 15:34:30 +02:00
|
|
|
default:
|
|
|
|
FIXME( "unhandled text type %u\n", text->textType );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:54 +02:00
|
|
|
static HRESULT write_text_bin( struct writer *writer, const WS_XML_TEXT *text, ULONG offset )
|
|
|
|
{
|
2017-09-06 15:56:10 +02:00
|
|
|
enum record_type type;
|
|
|
|
BOOL use_dict = FALSE;
|
2017-05-23 12:03:54 +02:00
|
|
|
HRESULT hr;
|
2017-09-06 15:56:10 +02:00
|
|
|
ULONG id;
|
2017-05-23 12:03:54 +02:00
|
|
|
|
|
|
|
if (offset)
|
|
|
|
{
|
|
|
|
FIXME( "no support for appending text in binary mode\n" );
|
2017-07-12 15:34:30 +02:00
|
|
|
return E_NOTIMPL;
|
2017-05-23 12:03:54 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 15:56:10 +02:00
|
|
|
if (text->textType == WS_XML_TEXT_TYPE_UTF8)
|
|
|
|
{
|
|
|
|
const WS_XML_UTF8_TEXT *utf8 = (const WS_XML_UTF8_TEXT *)text;
|
|
|
|
use_dict = get_string_id( writer, &utf8->value, &id );
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((type = get_text_record_type( text, use_dict )))
|
2017-05-23 12:03:54 +02:00
|
|
|
{
|
|
|
|
case RECORD_CHARS8_TEXT_WITH_ENDELEMENT:
|
2017-07-12 15:34:30 +02:00
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
const WS_XML_UTF8_TEXT *text_utf8;
|
|
|
|
WS_XML_UTF8_TEXT *new = NULL;
|
|
|
|
UINT8 len;
|
2017-07-12 15:34:30 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
if (text->textType == WS_XML_TEXT_TYPE_UTF8) text_utf8 = (const WS_XML_UTF8_TEXT *)text;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((hr = text_to_utf8text( text, NULL, NULL, &new )) != S_OK) return hr;
|
|
|
|
text_utf8 = new;
|
|
|
|
}
|
|
|
|
len = text_utf8->value.length;
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(len) + len )) != S_OK)
|
|
|
|
{
|
2022-02-01 14:57:00 +01:00
|
|
|
free( new );
|
2017-12-08 15:49:41 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2017-05-23 12:03:54 +02:00
|
|
|
write_char( writer, type );
|
2017-07-12 15:34:30 +02:00
|
|
|
write_char( writer, len );
|
|
|
|
write_bytes( writer, text_utf8->value.bytes, len );
|
2022-02-01 14:57:00 +01:00
|
|
|
free( new );
|
2017-05-23 12:03:54 +02:00
|
|
|
return S_OK;
|
2017-07-12 15:34:30 +02:00
|
|
|
}
|
|
|
|
case RECORD_CHARS16_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
2017-12-08 15:49:41 +01:00
|
|
|
const WS_XML_UTF8_TEXT *text_utf8;
|
|
|
|
WS_XML_UTF8_TEXT *new = NULL;
|
|
|
|
UINT16 len;
|
2017-05-23 12:03:54 +02:00
|
|
|
|
2017-12-08 15:49:41 +01:00
|
|
|
if (text->textType == WS_XML_TEXT_TYPE_UTF8) text_utf8 = (const WS_XML_UTF8_TEXT *)text;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((hr = text_to_utf8text( text, NULL, NULL, &new )) != S_OK) return hr;
|
|
|
|
text_utf8 = new;
|
|
|
|
}
|
|
|
|
len = text_utf8->value.length;
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(len) + len )) != S_OK)
|
|
|
|
{
|
2022-02-01 14:57:00 +01:00
|
|
|
free( new );
|
2017-12-08 15:49:41 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2017-07-12 15:34:30 +02:00
|
|
|
write_char( writer, type );
|
|
|
|
write_bytes( writer, (const BYTE *)&len, sizeof(len) );
|
|
|
|
write_bytes( writer, text_utf8->value.bytes, len );
|
2022-02-01 14:57:00 +01:00
|
|
|
free( new );
|
2017-07-12 15:34:30 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2017-07-12 15:34:31 +02:00
|
|
|
case RECORD_BYTES8_TEXT:
|
|
|
|
{
|
|
|
|
const WS_XML_BASE64_TEXT *text_base64 = (const WS_XML_BASE64_TEXT *)text;
|
|
|
|
UINT8 rem = text_base64->length % 3, len = text_base64->length - rem;
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(len) + len )) != S_OK) return hr;
|
|
|
|
write_char( writer, rem ? RECORD_BYTES8_TEXT : RECORD_BYTES8_TEXT_WITH_ENDELEMENT );
|
|
|
|
write_char( writer, len );
|
|
|
|
write_bytes( writer, text_base64->bytes, len );
|
|
|
|
}
|
|
|
|
if (rem)
|
|
|
|
{
|
|
|
|
if ((hr = write_grow_buffer( writer, 3 )) != S_OK) return hr;
|
|
|
|
write_char( writer, RECORD_BYTES8_TEXT_WITH_ENDELEMENT );
|
|
|
|
write_char( writer, rem );
|
|
|
|
write_bytes( writer, (const BYTE *)text_base64->bytes + len, rem );
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_BYTES16_TEXT:
|
|
|
|
{
|
|
|
|
const WS_XML_BASE64_TEXT *text_base64 = (const WS_XML_BASE64_TEXT *)text;
|
|
|
|
UINT16 rem = text_base64->length % 3, len = text_base64->length - rem;
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(len) + len )) != S_OK) return hr;
|
|
|
|
write_char( writer, rem ? RECORD_BYTES16_TEXT : RECORD_BYTES16_TEXT_WITH_ENDELEMENT );
|
|
|
|
write_bytes( writer, (const BYTE *)&len, sizeof(len) );
|
|
|
|
write_bytes( writer, text_base64->bytes, len );
|
|
|
|
}
|
|
|
|
if (rem)
|
|
|
|
{
|
|
|
|
if ((hr = write_grow_buffer( writer, 3 )) != S_OK) return hr;
|
|
|
|
write_char( writer, RECORD_BYTES8_TEXT_WITH_ENDELEMENT );
|
|
|
|
write_char( writer, rem );
|
|
|
|
write_bytes( writer, (const BYTE *)text_base64->bytes + len, rem );
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
2021-08-31 13:45:55 +02:00
|
|
|
case RECORD_BYTES32_TEXT:
|
|
|
|
{
|
|
|
|
const WS_XML_BASE64_TEXT *text_base64 = (const WS_XML_BASE64_TEXT *)text;
|
|
|
|
UINT32 rem = text_base64->length % 3, len = text_base64->length - rem;
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(len) + len )) != S_OK) return hr;
|
|
|
|
write_char( writer, rem ? RECORD_BYTES32_TEXT : RECORD_BYTES32_TEXT_WITH_ENDELEMENT );
|
|
|
|
write_bytes( writer, (const BYTE *)&len, sizeof(len) );
|
|
|
|
write_bytes( writer, text_base64->bytes, len );
|
|
|
|
}
|
|
|
|
if (rem)
|
|
|
|
{
|
|
|
|
if ((hr = write_grow_buffer( writer, 3 )) != S_OK) return hr;
|
|
|
|
write_char( writer, RECORD_BYTES8_TEXT_WITH_ENDELEMENT );
|
|
|
|
write_char( writer, rem );
|
|
|
|
write_bytes( writer, (const BYTE *)text_base64->bytes + len, rem );
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-07-12 15:34:33 +02:00
|
|
|
case RECORD_ZERO_TEXT_WITH_ENDELEMENT:
|
|
|
|
case RECORD_ONE_TEXT_WITH_ENDELEMENT:
|
2017-07-12 15:34:32 +02:00
|
|
|
case RECORD_FALSE_TEXT_WITH_ENDELEMENT:
|
|
|
|
case RECORD_TRUE_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-07-12 15:34:33 +02:00
|
|
|
case RECORD_INT8_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
INT8 val = get_text_value_int( text );
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(val) )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
write_char( writer, val );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_INT16_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
INT16 val = get_text_value_int( text );
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(val) )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
write_bytes( writer, (const BYTE *)&val, sizeof(val) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_INT32_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
INT32 val = get_text_value_int( text );
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(val) )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
write_bytes( writer, (const BYTE *)&val, sizeof(val) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_INT64_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
INT64 val = get_text_value_int( text );
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(val) )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
write_bytes( writer, (const BYTE *)&val, sizeof(val) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case RECORD_UINT64_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
WS_XML_UINT64_TEXT *text_uint64 = (WS_XML_UINT64_TEXT *)text;
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(text_uint64->value) )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
write_bytes( writer, (const BYTE *)&text_uint64->value, sizeof(text_uint64->value) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-07-12 15:34:34 +02:00
|
|
|
case RECORD_DOUBLE_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
WS_XML_DOUBLE_TEXT *text_double = (WS_XML_DOUBLE_TEXT *)text;
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(text_double->value) )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
write_bytes( writer, (const BYTE *)&text_double->value, sizeof(text_double->value) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-07-12 15:34:35 +02:00
|
|
|
case RECORD_GUID_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
WS_XML_GUID_TEXT *text_guid = (WS_XML_GUID_TEXT *)text;
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(text_guid->value) )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
write_bytes( writer, (const BYTE *)&text_guid->value, sizeof(text_guid->value) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-07-12 15:34:36 +02:00
|
|
|
case RECORD_UNIQUE_ID_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
WS_XML_UNIQUE_ID_TEXT *text_unique_id = (WS_XML_UNIQUE_ID_TEXT *)text;
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(text_unique_id->value) )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
write_bytes( writer, (const BYTE *)&text_unique_id->value, sizeof(text_unique_id->value) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-07-12 15:34:37 +02:00
|
|
|
case RECORD_DATETIME_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
WS_XML_DATETIME_TEXT *text_datetime = (WS_XML_DATETIME_TEXT *)text;
|
|
|
|
UINT64 val = text_datetime->value.ticks;
|
|
|
|
|
|
|
|
assert( val <= TICKS_MAX );
|
|
|
|
if (text_datetime->value.format == WS_DATETIME_FORMAT_UTC) val |= (UINT64)1 << 62;
|
|
|
|
else if (text_datetime->value.format == WS_DATETIME_FORMAT_LOCAL) val |= (UINT64)1 << 63;
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 + sizeof(val) )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
write_bytes( writer, (const BYTE *)&val, sizeof(val) );
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-09-06 15:56:10 +02:00
|
|
|
case RECORD_DICTIONARY_TEXT_WITH_ENDELEMENT:
|
|
|
|
{
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
write_char( writer, type );
|
|
|
|
return write_dict_string( writer, id );
|
|
|
|
}
|
2017-05-23 12:03:54 +02:00
|
|
|
default:
|
2017-05-30 10:09:05 +02:00
|
|
|
FIXME( "unhandled record type %02x\n", type );
|
2017-07-12 15:34:30 +02:00
|
|
|
return E_NOTIMPL;
|
2017-05-23 12:03:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_text( struct writer *writer, const WS_XML_TEXT *text, ULONG offset )
|
|
|
|
{
|
|
|
|
if (!writer->current->parent) return WS_E_INVALID_FORMAT;
|
|
|
|
|
|
|
|
switch (writer->output_enc)
|
|
|
|
{
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT: return write_text_text( writer, text, offset );
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY: return write_text_bin( writer, text, offset );
|
|
|
|
default:
|
|
|
|
ERR( "unhandled encoding %u\n", writer->output_enc );
|
|
|
|
return WS_E_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 11:35:42 +02:00
|
|
|
static HRESULT write_text_node( struct writer *writer, const WS_XML_TEXT *text )
|
2016-07-04 11:35:41 +02:00
|
|
|
{
|
2017-05-23 12:03:54 +02:00
|
|
|
WS_XML_TEXT_NODE *node = (WS_XML_TEXT_NODE *)writer->current;
|
2017-07-10 11:02:33 +02:00
|
|
|
ULONG offset = 0;
|
2016-07-04 11:35:41 +02:00
|
|
|
HRESULT hr;
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2018-12-04 13:57:28 +01:00
|
|
|
if ((hr = write_commit( writer )) != S_OK) return hr;
|
2017-04-28 12:12:46 +02:00
|
|
|
if (node_type( writer->current ) != WS_XML_NODE_TYPE_TEXT)
|
|
|
|
{
|
|
|
|
if ((hr = write_add_text_node( writer, text )) != S_OK) return hr;
|
2017-05-23 12:03:54 +02:00
|
|
|
node = (WS_XML_TEXT_NODE *)writer->current;
|
2017-04-28 12:12:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-10 11:02:33 +02:00
|
|
|
switch (writer->output_enc)
|
|
|
|
{
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT:
|
|
|
|
{
|
|
|
|
WS_XML_UTF8_TEXT *new, *old = (WS_XML_UTF8_TEXT *)node->text;
|
|
|
|
offset = old->value.length;
|
|
|
|
if ((hr = text_to_utf8text( text, old, &offset, &new )) != S_OK) return hr;
|
2022-02-01 14:57:00 +01:00
|
|
|
free( old );
|
2017-07-10 11:02:33 +02:00
|
|
|
node->text = &new->text;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY:
|
|
|
|
{
|
|
|
|
WS_XML_TEXT *new, *old = node->text;
|
|
|
|
if ((hr = text_to_text( text, old, &offset, &new )) != S_OK) return hr;
|
2022-02-01 14:57:00 +01:00
|
|
|
free( old );
|
2017-07-10 11:02:33 +02:00
|
|
|
node->text = new;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled output encoding %u\n", writer->output_enc );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2017-04-28 12:12:46 +02:00
|
|
|
}
|
|
|
|
|
2017-05-23 12:03:54 +02:00
|
|
|
if ((hr = write_text( writer, node->text, offset )) != S_OK) return hr;
|
2017-04-28 12:12:46 +02:00
|
|
|
|
2016-06-21 14:04:42 +02:00
|
|
|
writer->state = WRITER_STATE_TEXT;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-11-11 11:02:08 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteText [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteText( WS_XML_WRITER *handle, const WS_XML_TEXT *text, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2017-03-08 11:25:57 +01:00
|
|
|
HRESULT hr;
|
2015-11-11 11:02:08 +01:00
|
|
|
|
|
|
|
TRACE( "%p %p %p\n", handle, text, error );
|
2017-04-28 12:12:49 +02:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
2015-11-11 11:02:08 +01:00
|
|
|
|
|
|
|
if (!writer || !text) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (writer->state == WRITER_STATE_STARTATTRIBUTE) hr = write_set_attribute_value( writer, text );
|
|
|
|
else hr = write_text_node( writer, text );
|
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
2017-04-28 12:12:49 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteBytes [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteBytes( WS_XML_WRITER *handle, const void *bytes, ULONG count, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
WS_XML_BASE64_TEXT base64;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %p %lu %p\n", handle, bytes, count, error );
|
2017-04-28 12:12:49 +02:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (!writer->output_type) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else
|
2017-04-28 12:12:49 +02:00
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
base64.text.textType = WS_XML_TEXT_TYPE_BASE64;
|
|
|
|
base64.bytes = (BYTE *)bytes;
|
|
|
|
base64.length = count;
|
2017-04-28 12:12:49 +02:00
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (writer->state == WRITER_STATE_STARTATTRIBUTE) hr = write_set_attribute_value( writer, &base64.text );
|
|
|
|
else hr = write_text_node( writer, &base64.text );
|
|
|
|
}
|
2017-04-28 12:12:49 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-04-28 12:12:49 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-04-28 12:12:50 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteChars [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteChars( WS_XML_WRITER *handle, const WCHAR *chars, ULONG count, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
WS_XML_UTF16_TEXT utf16;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %s %lu %p\n", handle, debugstr_wn(chars, count), count, error );
|
2017-04-28 12:12:50 +02:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (!writer->output_type) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else
|
2017-04-28 12:12:50 +02:00
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
utf16.text.textType = WS_XML_TEXT_TYPE_UTF16;
|
|
|
|
utf16.bytes = (BYTE *)chars;
|
|
|
|
utf16.byteCount = count * sizeof(WCHAR);
|
2017-04-28 12:12:50 +02:00
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (writer->state == WRITER_STATE_STARTATTRIBUTE) hr = write_set_attribute_value( writer, &utf16.text );
|
|
|
|
else hr = write_text_node( writer, &utf16.text );
|
|
|
|
}
|
2017-04-28 12:12:50 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-04-28 12:12:50 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-04-28 12:12:51 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteCharsUtf8 [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteCharsUtf8( WS_XML_WRITER *handle, const BYTE *bytes, ULONG count, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
WS_XML_UTF8_TEXT utf8;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %s %lu %p\n", handle, debugstr_an((const char *)bytes, count), count, error );
|
2017-04-28 12:12:51 +02:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (!writer->output_type) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else
|
2017-04-28 12:12:51 +02:00
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
utf8.text.textType = WS_XML_TEXT_TYPE_UTF8;
|
|
|
|
utf8.value.bytes = (BYTE *)bytes;
|
|
|
|
utf8.value.length = count;
|
2017-04-28 12:12:51 +02:00
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (writer->state == WRITER_STATE_STARTATTRIBUTE) hr = write_set_attribute_value( writer, &utf8.text );
|
|
|
|
else hr = write_text_node( writer, &utf8.text );
|
|
|
|
}
|
2017-04-28 12:12:51 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-04-28 12:12:51 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2016-07-04 11:35:42 +02:00
|
|
|
static HRESULT write_type_text( struct writer *writer, WS_TYPE_MAPPING mapping, const WS_XML_TEXT *text )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
|
|
|
switch (mapping)
|
|
|
|
{
|
|
|
|
case WS_ELEMENT_TYPE_MAPPING:
|
|
|
|
case WS_ELEMENT_CONTENT_TYPE_MAPPING:
|
2016-07-04 11:35:41 +02:00
|
|
|
return write_text_node( writer, text );
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
case WS_ATTRIBUTE_TYPE_MAPPING:
|
2016-07-04 11:35:42 +02:00
|
|
|
return write_set_attribute_value( writer, text );
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
case WS_ANY_ELEMENT_TYPE_MAPPING:
|
|
|
|
switch (writer->state)
|
|
|
|
{
|
|
|
|
case WRITER_STATE_STARTATTRIBUTE:
|
2016-07-04 11:35:42 +02:00
|
|
|
return write_set_attribute_value( writer, text );
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
case WRITER_STATE_STARTELEMENT:
|
2016-07-04 11:35:41 +02:00
|
|
|
return write_text_node( writer, text );
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME( "writer state %u not handled\n", writer->state );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME( "mapping %u not implemented\n", mapping );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-28 12:38:00 +02:00
|
|
|
static HRESULT write_add_nil_attribute( struct writer *writer )
|
|
|
|
{
|
|
|
|
static const WS_XML_STRING prefix = {1, (BYTE *)"a"};
|
|
|
|
static const WS_XML_STRING localname = {3, (BYTE *)"nil"};
|
|
|
|
static const WS_XML_STRING ns = {41, (BYTE *)"http://www.w3.org/2001/XMLSchema-instance"};
|
|
|
|
static const WS_XML_UTF8_TEXT value = {{WS_XML_TEXT_TYPE_UTF8}, {4, (BYTE *)"true"}};
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if ((hr = write_add_attribute( writer, &prefix, &localname, &ns, FALSE )) != S_OK) return hr;
|
|
|
|
if ((hr = write_set_attribute_value( writer, &value.text )) != S_OK) return hr;
|
2017-05-23 12:03:53 +02:00
|
|
|
return add_namespace_attribute( writer, &prefix, &ns, FALSE );
|
2016-09-28 12:38:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT get_value_ptr( WS_WRITE_OPTION option, const void *value, ULONG size, ULONG expected_size,
|
|
|
|
const void **ptr )
|
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case WS_WRITE_REQUIRED_VALUE:
|
|
|
|
case WS_WRITE_NILLABLE_VALUE:
|
|
|
|
if (!value || size != expected_size) return E_INVALIDARG;
|
|
|
|
*ptr = value;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
case WS_WRITE_REQUIRED_POINTER:
|
|
|
|
if (size != sizeof(const void *) || !(*ptr = *(const void **)value)) return E_INVALIDARG;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
case WS_WRITE_NILLABLE_POINTER:
|
|
|
|
if (size != sizeof(const void *)) return E_INVALIDARG;
|
|
|
|
*ptr = *(const void **)value;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
static HRESULT write_type_bool( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_BOOL_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const BOOL *value, ULONG size )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
2017-07-12 15:34:32 +02:00
|
|
|
WS_XML_BOOL_TEXT text_bool;
|
2016-09-28 12:38:00 +02:00
|
|
|
const BOOL *ptr;
|
|
|
|
HRESULT hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(BOOL), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
2017-07-12 15:34:32 +02:00
|
|
|
text_bool.text.textType = WS_XML_TEXT_TYPE_BOOL;
|
|
|
|
text_bool.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_bool.text );
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_int8( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_INT8_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const BOOL *value, ULONG size )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
2017-07-12 15:34:33 +02:00
|
|
|
WS_XML_INT32_TEXT text_int32;
|
2016-09-28 12:38:00 +02:00
|
|
|
const INT8 *ptr;
|
|
|
|
HRESULT hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(INT8), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
2017-07-12 15:34:33 +02:00
|
|
|
text_int32.text.textType = WS_XML_TEXT_TYPE_INT32;
|
|
|
|
text_int32.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_int32.text );
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_int16( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_INT16_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const BOOL *value, ULONG size )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
2017-07-12 15:34:33 +02:00
|
|
|
WS_XML_INT32_TEXT text_int32;
|
2016-09-28 12:38:00 +02:00
|
|
|
const INT16 *ptr;
|
|
|
|
HRESULT hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(INT16), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
2017-07-12 15:34:33 +02:00
|
|
|
text_int32.text.textType = WS_XML_TEXT_TYPE_INT32;
|
|
|
|
text_int32.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_int32.text );
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_int32( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_INT32_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
2017-07-12 15:34:33 +02:00
|
|
|
WS_XML_INT32_TEXT text_int32;
|
2016-09-28 12:38:00 +02:00
|
|
|
const INT32 *ptr;
|
|
|
|
HRESULT hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(INT32), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
2017-07-12 15:34:33 +02:00
|
|
|
text_int32.text.textType = WS_XML_TEXT_TYPE_INT32;
|
|
|
|
text_int32.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_int32.text );
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_int64( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_INT64_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
2017-07-12 15:34:33 +02:00
|
|
|
WS_XML_INT64_TEXT text_int64;
|
2016-09-28 12:38:00 +02:00
|
|
|
const INT64 *ptr;
|
|
|
|
HRESULT hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(INT64), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
2017-07-12 15:34:33 +02:00
|
|
|
text_int64.text.textType = WS_XML_TEXT_TYPE_INT64;
|
|
|
|
text_int64.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_int64.text );
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_uint8( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_UINT8_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
2017-07-12 15:34:33 +02:00
|
|
|
WS_XML_UINT64_TEXT text_uint64;
|
2016-09-28 12:38:00 +02:00
|
|
|
const UINT8 *ptr;
|
|
|
|
HRESULT hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(UINT8), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
2017-07-12 15:34:33 +02:00
|
|
|
text_uint64.text.textType = WS_XML_TEXT_TYPE_UINT64;
|
|
|
|
text_uint64.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_uint64.text );
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_uint16( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_UINT16_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
2017-07-12 15:34:33 +02:00
|
|
|
WS_XML_UINT64_TEXT text_uint64;
|
2016-09-28 12:38:00 +02:00
|
|
|
const UINT16 *ptr;
|
|
|
|
HRESULT hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(UINT16), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
2017-07-12 15:34:33 +02:00
|
|
|
text_uint64.text.textType = WS_XML_TEXT_TYPE_UINT64;
|
|
|
|
text_uint64.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_uint64.text );
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_uint32( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_UINT32_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
2017-07-12 15:34:33 +02:00
|
|
|
WS_XML_UINT64_TEXT text_uint64;
|
2016-09-28 12:38:00 +02:00
|
|
|
const UINT32 *ptr;
|
|
|
|
HRESULT hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(UINT32), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
2017-07-12 15:34:33 +02:00
|
|
|
text_uint64.text.textType = WS_XML_TEXT_TYPE_UINT64;
|
|
|
|
text_uint64.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_uint64.text );
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_uint64( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_UINT64_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
2017-07-12 15:34:33 +02:00
|
|
|
WS_XML_UINT64_TEXT text_uint64;
|
2016-09-28 12:38:00 +02:00
|
|
|
const UINT64 *ptr;
|
|
|
|
HRESULT hr;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(UINT64), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
2017-07-12 15:34:33 +02:00
|
|
|
text_uint64.text.textType = WS_XML_TEXT_TYPE_UINT64;
|
|
|
|
text_uint64.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_uint64.text );
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
2017-07-12 15:34:34 +02:00
|
|
|
static HRESULT write_type_double( struct writer *writer, WS_TYPE_MAPPING mapping,
|
|
|
|
const WS_DOUBLE_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
|
|
|
{
|
|
|
|
WS_XML_DOUBLE_TEXT text_double;
|
|
|
|
const double *ptr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(double), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
|
|
|
text_double.text.textType = WS_XML_TEXT_TYPE_DOUBLE;
|
|
|
|
text_double.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_double.text );
|
|
|
|
}
|
|
|
|
|
2016-10-04 13:28:34 +02:00
|
|
|
static HRESULT write_type_datetime( struct writer *writer, WS_TYPE_MAPPING mapping,
|
|
|
|
const WS_DATETIME_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
|
|
|
{
|
2017-07-12 15:34:37 +02:00
|
|
|
WS_XML_DATETIME_TEXT text_datetime;
|
2016-10-04 13:28:34 +02:00
|
|
|
const WS_DATETIME *ptr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(WS_DATETIME), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
if (ptr->ticks > TICKS_MAX || ptr->format > WS_DATETIME_FORMAT_NONE) return WS_E_INVALID_FORMAT;
|
|
|
|
|
2017-07-12 15:34:37 +02:00
|
|
|
text_datetime.text.textType = WS_XML_TEXT_TYPE_DATETIME;
|
|
|
|
text_datetime.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_datetime.text );
|
2016-10-04 13:28:34 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 14:23:59 +02:00
|
|
|
static HRESULT write_type_guid( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_GUID_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-08-17 14:23:59 +02:00
|
|
|
{
|
2017-07-12 15:34:35 +02:00
|
|
|
WS_XML_GUID_TEXT text_guid;
|
2016-09-28 12:38:00 +02:00
|
|
|
const GUID *ptr;
|
|
|
|
HRESULT hr;
|
2016-08-17 14:23:59 +02:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(GUID), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
2017-07-12 15:34:35 +02:00
|
|
|
text_guid.text.textType = WS_XML_TEXT_TYPE_GUID;
|
|
|
|
text_guid.value = *ptr;
|
|
|
|
return write_type_text( writer, mapping, &text_guid.text );
|
2016-08-17 14:23:59 +02:00
|
|
|
}
|
|
|
|
|
2017-06-21 09:37:37 +02:00
|
|
|
static HRESULT write_type_unique_id( struct writer *writer, WS_TYPE_MAPPING mapping,
|
|
|
|
const WS_UNIQUE_ID_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
|
|
|
{
|
2017-07-12 15:34:36 +02:00
|
|
|
WS_XML_UNIQUE_ID_TEXT text_unique_id;
|
|
|
|
WS_XML_UTF16_TEXT text_utf16;
|
2017-06-21 09:37:37 +02:00
|
|
|
const WS_UNIQUE_ID *ptr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(*ptr), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
|
|
|
|
if (ptr->uri.length)
|
|
|
|
{
|
2017-07-12 15:34:36 +02:00
|
|
|
text_utf16.text.textType = WS_XML_TEXT_TYPE_UTF16;
|
|
|
|
text_utf16.bytes = (BYTE *)ptr->uri.chars;
|
|
|
|
text_utf16.byteCount = ptr->uri.length * sizeof(WCHAR);
|
|
|
|
return write_type_text( writer, mapping, &text_utf16.text );
|
2017-06-21 09:37:37 +02:00
|
|
|
}
|
|
|
|
|
2017-07-12 15:34:36 +02:00
|
|
|
text_unique_id.text.textType = WS_XML_TEXT_TYPE_UNIQUE_ID;
|
|
|
|
text_unique_id.value = ptr->guid;
|
|
|
|
return write_type_text( writer, mapping, &text_unique_id.text );
|
2017-06-21 09:37:37 +02:00
|
|
|
}
|
|
|
|
|
2016-08-25 20:02:46 +02:00
|
|
|
static HRESULT write_type_string( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_STRING_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-08-25 20:02:46 +02:00
|
|
|
{
|
|
|
|
WS_XML_UTF16_TEXT utf16;
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_STRING *ptr;
|
|
|
|
HRESULT hr;
|
2016-08-25 20:02:46 +02:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(WS_STRING), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
if (!ptr->length) return S_OK;
|
|
|
|
|
2016-08-25 20:02:46 +02:00
|
|
|
utf16.text.textType = WS_XML_TEXT_TYPE_UTF16;
|
2016-09-28 12:38:00 +02:00
|
|
|
utf16.bytes = (BYTE *)ptr->chars;
|
|
|
|
utf16.byteCount = ptr->length * sizeof(WCHAR);
|
2016-08-25 20:02:46 +02:00
|
|
|
return write_type_text( writer, mapping, &utf16.text );
|
|
|
|
}
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
static HRESULT write_type_wsz( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_WSZ_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-01-21 15:27:59 +01:00
|
|
|
{
|
2016-07-04 11:35:42 +02:00
|
|
|
WS_XML_UTF16_TEXT utf16;
|
2016-09-28 12:38:00 +02:00
|
|
|
const WCHAR *ptr;
|
|
|
|
HRESULT hr;
|
|
|
|
int len;
|
2016-01-21 15:27:59 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-09-28 12:38:00 +02:00
|
|
|
|
|
|
|
if (!option || option == WS_WRITE_REQUIRED_VALUE || option == WS_WRITE_NILLABLE_VALUE) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, 0, (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
2019-06-26 09:36:53 +02:00
|
|
|
if (!(len = lstrlenW( ptr ))) return S_OK;
|
2016-09-28 12:38:00 +02:00
|
|
|
|
2016-07-04 11:35:42 +02:00
|
|
|
utf16.text.textType = WS_XML_TEXT_TYPE_UTF16;
|
2016-09-28 12:38:00 +02:00
|
|
|
utf16.bytes = (BYTE *)ptr;
|
|
|
|
utf16.byteCount = len * sizeof(WCHAR);
|
2016-07-04 11:35:42 +02:00
|
|
|
return write_type_text( writer, mapping, &utf16.text );
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
2016-10-04 13:28:36 +02:00
|
|
|
static HRESULT write_type_bytes( struct writer *writer, WS_TYPE_MAPPING mapping,
|
|
|
|
const WS_BYTES_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
|
|
|
{
|
|
|
|
WS_XML_BASE64_TEXT base64;
|
|
|
|
const WS_BYTES *ptr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!option) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(WS_BYTES), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if ((option == WS_WRITE_NILLABLE_VALUE && is_nil_value( value, size )) ||
|
|
|
|
(option == WS_WRITE_NILLABLE_POINTER && !ptr)) return write_add_nil_attribute( writer );
|
|
|
|
if (!ptr->length) return S_OK;
|
|
|
|
|
|
|
|
base64.text.textType = WS_XML_TEXT_TYPE_BASE64;
|
|
|
|
base64.bytes = ptr->bytes;
|
|
|
|
base64.length = ptr->length;
|
|
|
|
return write_type_text( writer, mapping, &base64.text );
|
|
|
|
}
|
|
|
|
|
2016-08-25 20:02:46 +02:00
|
|
|
static HRESULT write_type_xml_string( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_XML_STRING_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-08-25 20:02:46 +02:00
|
|
|
{
|
|
|
|
WS_XML_UTF8_TEXT utf8;
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_XML_STRING *ptr;
|
|
|
|
HRESULT hr;
|
2016-08-25 20:02:46 +02:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2016-09-28 12:38:00 +02:00
|
|
|
if (!option) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(WS_XML_STRING), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
if (option == WS_WRITE_NILLABLE_VALUE && is_nil_value( value, size )) return write_add_nil_attribute( writer );
|
|
|
|
if (!ptr->length) return S_OK;
|
2016-08-25 20:02:49 +02:00
|
|
|
|
2016-09-28 12:38:00 +02:00
|
|
|
utf8.text.textType = WS_XML_TEXT_TYPE_UTF8;
|
|
|
|
utf8.value.bytes = ptr->bytes;
|
|
|
|
utf8.value.length = ptr->length;
|
|
|
|
return write_type_text( writer, mapping, &utf8.text );
|
2016-08-25 20:02:49 +02:00
|
|
|
}
|
|
|
|
|
2017-06-21 09:37:38 +02:00
|
|
|
static HRESULT find_prefix( struct writer *writer, const WS_XML_STRING *ns, const WS_XML_STRING **prefix )
|
|
|
|
{
|
|
|
|
const struct node *node;
|
|
|
|
for (node = writer->current; node_type( node ) == WS_XML_NODE_TYPE_ELEMENT; node = node->parent)
|
|
|
|
{
|
|
|
|
const WS_XML_ELEMENT_NODE *elem = &node->hdr;
|
|
|
|
ULONG i;
|
|
|
|
for (i = 0; i < elem->attributeCount; i++)
|
|
|
|
{
|
|
|
|
if (!elem->attributes[i]->isXmlNs) continue;
|
|
|
|
if (WsXmlStringEquals( elem->attributes[i]->ns, ns, NULL ) != S_OK) continue;
|
|
|
|
*prefix = elem->attributes[i]->prefix;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return WS_E_INVALID_FORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_qname( struct writer *writer, WS_TYPE_MAPPING mapping,
|
|
|
|
const WS_XML_QNAME_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
|
|
|
{
|
|
|
|
WS_XML_QNAME_TEXT qname;
|
|
|
|
const WS_XML_QNAME *ptr;
|
|
|
|
const WS_XML_STRING *prefix;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
|
|
|
FIXME( "description not supported\n" );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!option) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(*ptr), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
|
|
|
if (option == WS_WRITE_NILLABLE_VALUE && is_nil_value( value, size )) return write_add_nil_attribute( writer );
|
|
|
|
|
|
|
|
if (((hr = find_prefix( writer, &ptr->ns, &prefix )) != S_OK)) return hr;
|
|
|
|
|
|
|
|
qname.text.textType = WS_XML_TEXT_TYPE_QNAME;
|
|
|
|
qname.prefix = (WS_XML_STRING *)prefix;
|
|
|
|
qname.localName = (WS_XML_STRING *)&ptr->localName;
|
|
|
|
qname.ns = (WS_XML_STRING *)&ptr->ns;
|
|
|
|
return write_type_text( writer, mapping, &qname.text );
|
|
|
|
}
|
|
|
|
|
2016-11-17 17:11:03 +01:00
|
|
|
static WS_WRITE_OPTION get_field_write_option( WS_TYPE type, ULONG options )
|
|
|
|
{
|
|
|
|
if (options & WS_FIELD_POINTER)
|
|
|
|
{
|
2020-03-17 15:35:45 +01:00
|
|
|
if (options & (WS_FIELD_OPTIONAL|WS_FIELD_NILLABLE|WS_FIELD_NILLABLE_ITEM)) return WS_WRITE_NILLABLE_POINTER;
|
2016-11-17 17:11:03 +01:00
|
|
|
return WS_WRITE_REQUIRED_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case WS_BOOL_TYPE:
|
|
|
|
case WS_INT8_TYPE:
|
|
|
|
case WS_INT16_TYPE:
|
|
|
|
case WS_INT32_TYPE:
|
|
|
|
case WS_INT64_TYPE:
|
|
|
|
case WS_UINT8_TYPE:
|
|
|
|
case WS_UINT16_TYPE:
|
|
|
|
case WS_UINT32_TYPE:
|
|
|
|
case WS_UINT64_TYPE:
|
|
|
|
case WS_DOUBLE_TYPE:
|
|
|
|
case WS_DATETIME_TYPE:
|
|
|
|
case WS_GUID_TYPE:
|
2017-06-21 09:37:37 +02:00
|
|
|
case WS_UNIQUE_ID_TYPE:
|
2016-11-17 17:11:03 +01:00
|
|
|
case WS_STRING_TYPE:
|
|
|
|
case WS_BYTES_TYPE:
|
|
|
|
case WS_XML_STRING_TYPE:
|
2017-06-21 09:37:38 +02:00
|
|
|
case WS_XML_QNAME_TYPE:
|
2016-11-17 17:11:03 +01:00
|
|
|
case WS_STRUCT_TYPE:
|
|
|
|
case WS_ENUM_TYPE:
|
2017-12-08 15:49:39 +01:00
|
|
|
case WS_UNION_TYPE:
|
2016-11-17 17:11:03 +01:00
|
|
|
if (options & (WS_FIELD_OPTIONAL|WS_FIELD_NILLABLE)) return WS_WRITE_NILLABLE_VALUE;
|
|
|
|
return WS_WRITE_REQUIRED_VALUE;
|
|
|
|
|
|
|
|
case WS_WSZ_TYPE:
|
|
|
|
case WS_DESCRIPTION_TYPE:
|
|
|
|
if (options & (WS_FIELD_OPTIONAL|WS_FIELD_NILLABLE)) return WS_WRITE_NILLABLE_POINTER;
|
|
|
|
return WS_WRITE_REQUIRED_POINTER;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled type %u\n", type );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 09:54:21 +01:00
|
|
|
static HRESULT find_index( const WS_UNION_DESCRIPTION *desc, int value, ULONG *idx )
|
|
|
|
{
|
|
|
|
ULONG i;
|
2017-12-08 15:49:39 +01:00
|
|
|
|
2018-11-08 09:54:21 +01:00
|
|
|
if (desc->valueIndices)
|
|
|
|
{
|
|
|
|
int c, min = 0, max = desc->fieldCount - 1;
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
i = (min + max) / 2;
|
|
|
|
c = value - desc->fields[desc->valueIndices[i]]->value;
|
|
|
|
if (c < 0)
|
|
|
|
max = i - 1;
|
|
|
|
else if (c > 0)
|
|
|
|
min = i + 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*idx = desc->valueIndices[i];
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return WS_E_INVALID_FORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fall back to linear search */
|
|
|
|
for (i = 0; i < desc->fieldCount; i++)
|
|
|
|
{
|
|
|
|
if (desc->fields[i]->value == value)
|
|
|
|
{
|
|
|
|
*idx = i;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return WS_E_INVALID_FORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_field( struct writer *, const WS_FIELD_DESCRIPTION *, const char *, ULONG );
|
2016-01-29 13:27:25 +01:00
|
|
|
|
2017-07-10 11:02:29 +02:00
|
|
|
static HRESULT write_type_union( struct writer *writer, const WS_UNION_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
|
|
|
{
|
2018-11-08 09:54:21 +01:00
|
|
|
ULONG i;
|
2017-07-10 11:02:29 +02:00
|
|
|
const void *ptr;
|
|
|
|
int enum_value;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (size < sizeof(enum_value)) return E_INVALIDARG;
|
2018-11-08 09:54:22 +01:00
|
|
|
if ((hr = get_value_ptr( option, value, size, desc->size, &ptr )) != S_OK) return hr;
|
2017-07-10 11:02:29 +02:00
|
|
|
|
2018-11-08 09:54:22 +01:00
|
|
|
enum_value = *(int *)(char *)ptr + desc->enumOffset;
|
|
|
|
if (enum_value == desc->noneEnumValue && option == WS_WRITE_NILLABLE_VALUE) return S_OK;
|
2017-07-10 11:02:29 +02:00
|
|
|
|
2018-11-08 09:54:21 +01:00
|
|
|
if ((hr = find_index( desc, enum_value, &i )) != S_OK) return hr;
|
|
|
|
return write_type_field( writer, &desc->fields[i]->field, ptr, desc->fields[i]->field.offset );
|
2017-07-10 11:02:29 +02:00
|
|
|
}
|
|
|
|
|
2018-11-08 09:54:21 +01:00
|
|
|
static HRESULT write_type( struct writer *, WS_TYPE_MAPPING, WS_TYPE, const void *, WS_WRITE_OPTION,
|
|
|
|
const void *, ULONG );
|
|
|
|
|
2017-12-08 15:49:39 +01:00
|
|
|
static HRESULT write_type_array( struct writer *writer, const WS_FIELD_DESCRIPTION *desc, const char *buf,
|
|
|
|
ULONG count )
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
ULONG i, size, offset = 0;
|
|
|
|
WS_WRITE_OPTION option;
|
|
|
|
|
|
|
|
if (!(option = get_field_write_option( desc->type, desc->options ))) return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* wrapper element */
|
|
|
|
if (desc->localName && ((hr = write_element_node( writer, NULL, desc->localName, desc->ns )) != S_OK))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (option == WS_WRITE_REQUIRED_VALUE || option == WS_WRITE_NILLABLE_VALUE)
|
|
|
|
size = get_type_size( desc->type, desc->typeDescription );
|
|
|
|
else
|
|
|
|
size = sizeof(const void *);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (desc->type == WS_UNION_TYPE)
|
|
|
|
{
|
|
|
|
if ((hr = write_type_union( writer, desc->typeDescription, option, buf + offset, size )) != S_OK)
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((hr = write_element_node( writer, NULL, desc->itemLocalName, desc->itemNs )) != S_OK) return hr;
|
|
|
|
if ((hr = write_type( writer, WS_ELEMENT_TYPE_MAPPING, desc->type, desc->typeDescription, option,
|
|
|
|
buf + offset, size )) != S_OK) return hr;
|
|
|
|
if ((hr = write_endelement_node( writer )) != S_OK) return hr;
|
|
|
|
}
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc->localName) hr = write_endelement_node( writer );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-07-10 11:02:29 +02:00
|
|
|
static HRESULT write_type_field( struct writer *writer, const WS_FIELD_DESCRIPTION *desc, const char *buf,
|
|
|
|
ULONG offset )
|
2016-01-29 13:27:25 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2016-03-02 14:06:29 +01:00
|
|
|
WS_TYPE_MAPPING mapping;
|
|
|
|
WS_WRITE_OPTION option;
|
2016-11-17 17:11:03 +01:00
|
|
|
ULONG count, size, field_options = desc->options;
|
|
|
|
const char *ptr = buf + offset;
|
2016-01-29 13:27:25 +01:00
|
|
|
|
2020-03-17 15:35:45 +01:00
|
|
|
if (field_options & ~(WS_FIELD_POINTER|WS_FIELD_OPTIONAL|WS_FIELD_NILLABLE|WS_FIELD_NILLABLE_ITEM))
|
2016-01-29 13:27:25 +01:00
|
|
|
{
|
2022-02-15 10:32:49 +01:00
|
|
|
FIXME( "options %#lx not supported\n", desc->options );
|
2016-01-29 13:27:25 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2020-03-20 16:03:53 +01:00
|
|
|
/* zero-terminated strings and descriptions are always pointers */
|
|
|
|
if (desc->type == WS_WSZ_TYPE || desc->type == WS_DESCRIPTION_TYPE) field_options |= WS_FIELD_POINTER;
|
2016-09-28 12:38:00 +02:00
|
|
|
|
2016-11-17 17:11:03 +01:00
|
|
|
if (field_options & WS_FIELD_POINTER)
|
|
|
|
size = sizeof(const void *);
|
|
|
|
else
|
|
|
|
size = get_type_size( desc->type, desc->typeDescription );
|
|
|
|
|
|
|
|
if (is_nil_value( ptr, size ))
|
2016-08-25 20:02:49 +02:00
|
|
|
{
|
2016-10-12 15:30:22 +02:00
|
|
|
if (field_options & WS_FIELD_OPTIONAL) return S_OK;
|
2020-03-17 15:35:45 +01:00
|
|
|
if (field_options & (WS_FIELD_NILLABLE|WS_FIELD_NILLABLE_ITEM))
|
2016-08-25 20:02:49 +02:00
|
|
|
{
|
2016-09-28 12:38:00 +02:00
|
|
|
if (field_options & WS_FIELD_POINTER) option = WS_WRITE_NILLABLE_POINTER;
|
|
|
|
else option = WS_WRITE_NILLABLE_VALUE;
|
2016-08-25 20:02:49 +02:00
|
|
|
}
|
2017-06-29 09:21:59 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (field_options & WS_FIELD_POINTER) option = WS_WRITE_REQUIRED_POINTER;
|
|
|
|
else option = WS_WRITE_REQUIRED_VALUE;
|
|
|
|
}
|
2016-08-25 20:02:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-28 12:38:00 +02:00
|
|
|
if (field_options & WS_FIELD_POINTER) option = WS_WRITE_REQUIRED_POINTER;
|
|
|
|
else option = WS_WRITE_REQUIRED_VALUE;
|
2016-08-25 20:02:49 +02:00
|
|
|
}
|
|
|
|
|
2016-01-29 13:27:26 +01:00
|
|
|
switch (desc->mapping)
|
|
|
|
{
|
2020-03-20 16:03:53 +01:00
|
|
|
case WS_TYPE_ATTRIBUTE_FIELD_MAPPING:
|
|
|
|
mapping = WS_ATTRIBUTE_TYPE_MAPPING;
|
|
|
|
break;
|
|
|
|
|
2016-01-29 13:27:26 +01:00
|
|
|
case WS_ATTRIBUTE_FIELD_MAPPING:
|
2016-03-02 14:06:28 +01:00
|
|
|
if (!desc->localName || !desc->ns) return E_INVALIDARG;
|
2016-01-29 13:27:26 +01:00
|
|
|
if ((hr = write_add_attribute( writer, NULL, desc->localName, desc->ns, FALSE )) != S_OK)
|
|
|
|
return hr;
|
2016-07-04 11:35:41 +02:00
|
|
|
writer->state = WRITER_STATE_STARTATTRIBUTE;
|
2016-03-02 14:06:29 +01:00
|
|
|
|
|
|
|
mapping = WS_ATTRIBUTE_TYPE_MAPPING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_ELEMENT_FIELD_MAPPING:
|
2016-07-04 11:35:41 +02:00
|
|
|
if ((hr = write_element_node( writer, NULL, desc->localName, desc->ns )) != S_OK) return hr;
|
2016-03-02 14:06:29 +01:00
|
|
|
mapping = WS_ELEMENT_TYPE_MAPPING;
|
2016-01-29 13:27:26 +01:00
|
|
|
break;
|
|
|
|
|
2017-07-10 11:02:29 +02:00
|
|
|
case WS_ELEMENT_CHOICE_FIELD_MAPPING:
|
|
|
|
if (desc->type != WS_UNION_TYPE || !desc->typeDescription) return E_INVALIDARG;
|
|
|
|
option = (field_options & WS_FIELD_OPTIONAL) ? WS_WRITE_NILLABLE_VALUE : WS_WRITE_REQUIRED_VALUE;
|
|
|
|
return write_type_union( writer, desc->typeDescription, option, ptr, size );
|
|
|
|
|
2016-11-17 17:11:03 +01:00
|
|
|
case WS_REPEATING_ELEMENT_FIELD_MAPPING:
|
2017-12-08 15:49:39 +01:00
|
|
|
case WS_REPEATING_ELEMENT_CHOICE_FIELD_MAPPING:
|
2016-11-17 17:11:03 +01:00
|
|
|
count = *(const ULONG *)(buf + desc->countOffset);
|
2017-12-08 15:49:39 +01:00
|
|
|
return write_type_array( writer, desc, *(const char **)ptr, count );
|
2016-11-17 17:11:03 +01:00
|
|
|
|
2016-01-29 13:27:26 +01:00
|
|
|
case WS_TEXT_FIELD_MAPPING:
|
2016-03-02 14:06:29 +01:00
|
|
|
switch (writer->state)
|
|
|
|
{
|
|
|
|
case WRITER_STATE_STARTELEMENT:
|
|
|
|
mapping = WS_ELEMENT_CONTENT_TYPE_MAPPING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WRITER_STATE_STARTATTRIBUTE:
|
|
|
|
mapping = WS_ATTRIBUTE_TYPE_MAPPING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled writer state %u\n", writer->state );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2016-01-29 13:27:26 +01:00
|
|
|
break;
|
|
|
|
|
2020-03-20 16:03:52 +01:00
|
|
|
case WS_ANY_ATTRIBUTES_FIELD_MAPPING:
|
|
|
|
return S_OK;
|
|
|
|
|
2016-01-29 13:27:26 +01:00
|
|
|
default:
|
|
|
|
FIXME( "field mapping %u not supported\n", desc->mapping );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2016-11-17 17:11:03 +01:00
|
|
|
if ((hr = write_type( writer, mapping, desc->type, desc->typeDescription, option, ptr, size )) != S_OK)
|
2016-09-28 12:38:00 +02:00
|
|
|
return hr;
|
2016-03-02 14:06:29 +01:00
|
|
|
|
|
|
|
switch (mapping)
|
2016-01-29 13:27:25 +01:00
|
|
|
{
|
2016-03-02 14:06:29 +01:00
|
|
|
case WS_ATTRIBUTE_TYPE_MAPPING:
|
|
|
|
writer->state = WRITER_STATE_STARTELEMENT;
|
2016-01-29 13:27:25 +01:00
|
|
|
break;
|
2016-03-02 14:06:29 +01:00
|
|
|
|
|
|
|
case WS_ELEMENT_TYPE_MAPPING:
|
2016-07-04 11:35:41 +02:00
|
|
|
if ((hr = write_endelement_node( writer )) != S_OK) return hr;
|
2016-01-29 13:27:25 +01:00
|
|
|
break;
|
2016-03-02 14:06:29 +01:00
|
|
|
|
|
|
|
default: break;
|
2016-01-29 13:27:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_struct( struct writer *writer, WS_TYPE_MAPPING mapping,
|
2016-09-28 12:38:00 +02:00
|
|
|
const WS_STRUCT_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
2016-01-29 13:27:25 +01:00
|
|
|
{
|
2016-11-17 17:11:03 +01:00
|
|
|
ULONG i, offset;
|
|
|
|
const void *ptr;
|
2016-01-29 13:27:25 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2016-09-28 12:38:00 +02:00
|
|
|
if (!desc) return E_INVALIDARG;
|
2022-02-15 10:32:49 +01:00
|
|
|
if (desc->structOptions) FIXME( "struct options %#lx not supported\n", desc->structOptions );
|
2016-01-29 13:27:25 +01:00
|
|
|
|
2016-10-25 13:03:23 +02:00
|
|
|
if ((hr = get_value_ptr( option, value, size, desc->size, &ptr )) != S_OK) return hr;
|
2020-03-17 15:35:45 +01:00
|
|
|
if (option == WS_WRITE_NILLABLE_POINTER && !ptr) return write_add_nil_attribute( writer );
|
2016-09-28 12:38:00 +02:00
|
|
|
|
2016-01-29 13:27:25 +01:00
|
|
|
for (i = 0; i < desc->fieldCount; i++)
|
|
|
|
{
|
2016-11-17 17:11:03 +01:00
|
|
|
offset = desc->fields[i]->offset;
|
2017-07-10 11:02:29 +02:00
|
|
|
if ((hr = write_type_field( writer, desc->fields[i], ptr, offset )) != S_OK) return hr;
|
2016-01-29 13:27:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-25 14:29:57 +02:00
|
|
|
static const WS_XML_STRING *get_enum_value_name( const WS_ENUM_DESCRIPTION *desc, int value )
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
for (i = 0; i < desc->valueCount; i++)
|
|
|
|
{
|
|
|
|
if (desc->values[i].value == value) return desc->values[i].name;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_type_enum( struct writer *writer, WS_TYPE_MAPPING mapping,
|
|
|
|
const WS_ENUM_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
|
|
|
const void *value, ULONG size )
|
|
|
|
{
|
|
|
|
const WS_XML_STRING *name;
|
|
|
|
WS_XML_UTF8_TEXT utf8;
|
|
|
|
const int *ptr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!desc) return E_INVALIDARG;
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(*ptr), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (!(name = get_enum_value_name( desc, *ptr ))) return E_INVALIDARG;
|
|
|
|
|
|
|
|
utf8.text.textType = WS_XML_TEXT_TYPE_UTF8;
|
|
|
|
utf8.value.bytes = name->bytes;
|
|
|
|
utf8.value.length = name->length;
|
|
|
|
return write_type_text( writer, mapping, &utf8.text );
|
|
|
|
}
|
|
|
|
|
2020-03-20 16:03:53 +01:00
|
|
|
static HRESULT write_type_description( struct writer *writer, WS_TYPE_MAPPING mapping,
|
|
|
|
WS_WRITE_OPTION option, const void *value, ULONG size )
|
|
|
|
{
|
|
|
|
const WS_STRUCT_DESCRIPTION *ptr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if ((hr = get_value_ptr( option, value, size, sizeof(*ptr), (const void **)&ptr )) != S_OK) return hr;
|
|
|
|
if (ptr) FIXME( "ignoring type description %p\n", ptr );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
static HRESULT write_type( struct writer *writer, WS_TYPE_MAPPING mapping, WS_TYPE type,
|
|
|
|
const void *desc, WS_WRITE_OPTION option, const void *value,
|
|
|
|
ULONG size )
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case WS_BOOL_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_bool( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
case WS_INT8_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_int8( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
case WS_INT16_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_int16( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
case WS_INT32_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_int32( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
case WS_INT64_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_int64( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
case WS_UINT8_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_uint8( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
case WS_UINT16_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_uint16( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
case WS_UINT32_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_uint32( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
case WS_UINT64_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_uint64( writer, mapping, desc, option, value, size );
|
2016-10-04 13:28:34 +02:00
|
|
|
|
2017-07-12 15:34:34 +02:00
|
|
|
case WS_DOUBLE_TYPE:
|
|
|
|
return write_type_double( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-10-04 13:28:34 +02:00
|
|
|
case WS_DATETIME_TYPE:
|
|
|
|
return write_type_datetime( writer, mapping, desc, option, value, size );
|
2016-09-28 12:38:00 +02:00
|
|
|
|
2016-08-17 14:23:59 +02:00
|
|
|
case WS_GUID_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_guid( writer, mapping, desc, option, value, size );
|
|
|
|
|
2017-06-21 09:37:37 +02:00
|
|
|
case WS_UNIQUE_ID_TYPE:
|
|
|
|
return write_type_unique_id( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-08-25 20:02:46 +02:00
|
|
|
case WS_STRING_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_string( writer, mapping, desc, option, value, size );
|
2016-07-08 10:20:32 +02:00
|
|
|
|
2016-09-28 12:38:00 +02:00
|
|
|
case WS_WSZ_TYPE:
|
|
|
|
return write_type_wsz( writer, mapping, desc, option, value, size );
|
2016-07-08 10:20:32 +02:00
|
|
|
|
2016-10-04 13:28:36 +02:00
|
|
|
case WS_BYTES_TYPE:
|
|
|
|
return write_type_bytes( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-08-25 20:02:46 +02:00
|
|
|
case WS_XML_STRING_TYPE:
|
2016-09-28 12:38:00 +02:00
|
|
|
return write_type_xml_string( writer, mapping, desc, option, value, size );
|
|
|
|
|
2017-06-21 09:37:38 +02:00
|
|
|
case WS_XML_QNAME_TYPE:
|
|
|
|
return write_type_qname( writer, mapping, desc, option, value, size );
|
|
|
|
|
2020-03-20 16:03:53 +01:00
|
|
|
case WS_DESCRIPTION_TYPE:
|
|
|
|
return write_type_description( writer, mapping, option, value, size );
|
|
|
|
|
2016-10-04 13:28:36 +02:00
|
|
|
case WS_STRUCT_TYPE:
|
|
|
|
return write_type_struct( writer, mapping, desc, option, value, size );
|
|
|
|
|
2019-09-25 14:29:57 +02:00
|
|
|
case WS_ENUM_TYPE:
|
|
|
|
return write_type_enum( writer, mapping, desc, option, value, size );
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
default:
|
|
|
|
FIXME( "type %u not supported\n", type );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-29 13:27:28 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteAttribute [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteAttribute( WS_XML_WRITER *handle, const WS_ATTRIBUTE_DESCRIPTION *desc,
|
|
|
|
WS_WRITE_OPTION option, const void *value, ULONG size,
|
|
|
|
WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %p %u %p %lu %p\n", handle, desc, option, value, size, error );
|
2016-01-29 13:27:28 +01:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !desc || !desc->attributeLocalName || !desc->attributeNs || !value)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (writer->state != WRITER_STATE_STARTELEMENT) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else if ((hr = write_add_attribute( writer, NULL, desc->attributeLocalName, desc->attributeNs, FALSE )) == S_OK)
|
2017-03-08 11:25:57 +01:00
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
writer->state = WRITER_STATE_STARTATTRIBUTE;
|
|
|
|
hr = write_type( writer, WS_ATTRIBUTE_TYPE_MAPPING, desc->type, desc->typeDescription, option, value, size );
|
2017-03-08 11:25:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-01-29 13:27:28 +01:00
|
|
|
}
|
|
|
|
|
2016-01-29 13:27:26 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteElement [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteElement( WS_XML_WRITER *handle, const WS_ELEMENT_DESCRIPTION *desc,
|
|
|
|
WS_WRITE_OPTION option, const void *value, ULONG size,
|
|
|
|
WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %p %u %p %lu %p\n", handle, desc, option, value, size, error );
|
2016-01-29 13:27:26 +01:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !desc || !desc->elementLocalName || !desc->elementNs || !value)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hr = write_element_node( writer, NULL, desc->elementLocalName, desc->elementNs )) != S_OK) goto done;
|
2016-01-29 13:27:26 +01:00
|
|
|
|
|
|
|
if ((hr = write_type( writer, WS_ANY_ELEMENT_TYPE_MAPPING, desc->type, desc->typeDescription,
|
2017-03-08 11:25:57 +01:00
|
|
|
option, value, size )) != S_OK) goto done;
|
|
|
|
|
|
|
|
hr = write_endelement_node( writer );
|
2016-01-29 13:27:26 +01:00
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
done:
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-01-29 13:27:26 +01:00
|
|
|
}
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteType [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteType( WS_XML_WRITER *handle, WS_TYPE_MAPPING mapping, WS_TYPE type,
|
|
|
|
const void *desc, WS_WRITE_OPTION option, const void *value,
|
|
|
|
ULONG size, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %u %u %p %u %p %lu %p\n", handle, mapping, type, desc, option, value,
|
2016-01-21 15:27:59 +01:00
|
|
|
size, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !value) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2016-01-21 15:27:59 +01:00
|
|
|
switch (mapping)
|
|
|
|
{
|
|
|
|
case WS_ATTRIBUTE_TYPE_MAPPING:
|
2017-03-08 11:25:57 +01:00
|
|
|
if (writer->state != WRITER_STATE_STARTATTRIBUTE) hr = WS_E_INVALID_FORMAT;
|
|
|
|
else hr = write_type( writer, mapping, type, desc, option, value, size );
|
2016-01-21 15:27:59 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_ELEMENT_TYPE_MAPPING:
|
|
|
|
case WS_ELEMENT_CONTENT_TYPE_MAPPING:
|
|
|
|
case WS_ANY_ELEMENT_TYPE_MAPPING:
|
|
|
|
hr = write_type( writer, mapping, type, desc, option, value, size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME( "mapping %u not implemented\n", mapping );
|
2017-03-08 11:25:57 +01:00
|
|
|
hr = E_NOTIMPL;
|
2016-01-21 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2016-01-21 15:27:59 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2016-05-18 13:51:22 +02:00
|
|
|
WS_TYPE map_value_type( WS_VALUE_TYPE type )
|
2016-01-29 13:27:27 +01:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case WS_BOOL_VALUE_TYPE: return WS_BOOL_TYPE;
|
|
|
|
case WS_INT8_VALUE_TYPE: return WS_INT8_TYPE;
|
|
|
|
case WS_INT16_VALUE_TYPE: return WS_INT16_TYPE;
|
|
|
|
case WS_INT32_VALUE_TYPE: return WS_INT32_TYPE;
|
|
|
|
case WS_INT64_VALUE_TYPE: return WS_INT64_TYPE;
|
|
|
|
case WS_UINT8_VALUE_TYPE: return WS_UINT8_TYPE;
|
|
|
|
case WS_UINT16_VALUE_TYPE: return WS_UINT16_TYPE;
|
|
|
|
case WS_UINT32_VALUE_TYPE: return WS_UINT32_TYPE;
|
|
|
|
case WS_UINT64_VALUE_TYPE: return WS_UINT64_TYPE;
|
|
|
|
case WS_FLOAT_VALUE_TYPE: return WS_FLOAT_TYPE;
|
|
|
|
case WS_DOUBLE_VALUE_TYPE: return WS_DOUBLE_TYPE;
|
|
|
|
case WS_DECIMAL_VALUE_TYPE: return WS_DECIMAL_TYPE;
|
|
|
|
case WS_DATETIME_VALUE_TYPE: return WS_DATETIME_TYPE;
|
|
|
|
case WS_TIMESPAN_VALUE_TYPE: return WS_TIMESPAN_TYPE;
|
|
|
|
case WS_GUID_VALUE_TYPE: return WS_GUID_TYPE;
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled type %u\n", type );
|
|
|
|
return ~0u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteValue [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteValue( WS_XML_WRITER *handle, WS_VALUE_TYPE value_type, const void *value,
|
|
|
|
ULONG size, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
WS_TYPE_MAPPING mapping;
|
2017-03-08 11:25:57 +01:00
|
|
|
HRESULT hr = S_OK;
|
2016-01-29 13:27:27 +01:00
|
|
|
WS_TYPE type;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %u %p %lu %p\n", handle, value_type, value, size, error );
|
2016-01-29 13:27:27 +01:00
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !value || (type = map_value_type( value_type )) == ~0u) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2016-01-29 13:27:27 +01:00
|
|
|
switch (writer->state)
|
|
|
|
{
|
|
|
|
case WRITER_STATE_STARTATTRIBUTE:
|
|
|
|
mapping = WS_ATTRIBUTE_TYPE_MAPPING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WRITER_STATE_STARTELEMENT:
|
|
|
|
mapping = WS_ELEMENT_TYPE_MAPPING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-03-08 11:25:57 +01:00
|
|
|
hr = WS_E_INVALID_FORMAT;
|
2016-01-29 13:27:27 +01:00
|
|
|
}
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
if (hr == S_OK) hr = write_type( writer, mapping, type, NULL, WS_WRITE_REQUIRED_VALUE, value, size );
|
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-01-29 13:27:27 +01:00
|
|
|
}
|
|
|
|
|
2016-09-13 14:31:34 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteArray [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteArray( WS_XML_WRITER *handle, const WS_XML_STRING *localname, const WS_XML_STRING *ns,
|
|
|
|
WS_VALUE_TYPE value_type, const void *array, ULONG size, ULONG offset,
|
|
|
|
ULONG count, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
WS_TYPE type;
|
|
|
|
ULONG type_size, i;
|
2017-03-09 01:07:11 +01:00
|
|
|
HRESULT hr = S_OK;
|
2016-09-13 14:31:34 +02:00
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %s %s %u %p %lu %lu %lu %p\n", handle, debugstr_xmlstr(localname), debugstr_xmlstr(ns),
|
2016-09-13 14:31:34 +02:00
|
|
|
value_type, array, size, offset, count, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!writer->output_type)
|
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
hr = WS_E_INVALID_OPERATION;
|
|
|
|
goto done;
|
2017-03-08 11:25:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!localname || !ns || (type = map_value_type( value_type )) == ~0u)
|
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
hr = E_INVALIDARG;
|
|
|
|
goto done;
|
2017-03-08 11:25:57 +01:00
|
|
|
}
|
2016-09-13 14:31:34 +02:00
|
|
|
|
|
|
|
type_size = get_type_size( type, NULL );
|
2017-03-08 11:25:57 +01:00
|
|
|
if (size % type_size || (offset + count) * type_size > size || (count && !array))
|
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
hr = E_INVALIDARG;
|
|
|
|
goto done;
|
2017-03-08 11:25:57 +01:00
|
|
|
}
|
2016-09-13 14:31:34 +02:00
|
|
|
|
|
|
|
for (i = offset; i < count; i++)
|
|
|
|
{
|
|
|
|
const char *ptr = (const char *)array + (offset + i) * type_size;
|
2017-03-08 11:25:57 +01:00
|
|
|
if ((hr = write_element_node( writer, NULL, localname, ns )) != S_OK) goto done;
|
2016-09-13 14:31:34 +02:00
|
|
|
if ((hr = write_type( writer, WS_ELEMENT_TYPE_MAPPING, type, NULL, WS_WRITE_REQUIRED_POINTER,
|
2017-03-08 11:25:57 +01:00
|
|
|
&ptr, sizeof(ptr) )) != S_OK) goto done;
|
|
|
|
if ((hr = write_endelement_node( writer )) != S_OK) goto done;
|
2016-09-13 14:31:34 +02:00
|
|
|
}
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
done:
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-09-13 14:31:34 +02:00
|
|
|
}
|
|
|
|
|
2016-01-21 15:27:56 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteXmlBuffer [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteXmlBuffer( WS_XML_WRITER *handle, WS_XML_BUFFER *buffer, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
struct xmlbuf *xmlbuf = (struct xmlbuf *)buffer;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "%p %p %p\n", handle, buffer, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !xmlbuf) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2017-06-14 11:07:31 +02:00
|
|
|
if (xmlbuf->encoding != writer->output_enc || xmlbuf->charset != writer->output_charset)
|
|
|
|
{
|
|
|
|
FIXME( "no support for different encoding and/or charset\n" );
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2018-12-04 13:57:28 +01:00
|
|
|
if ((hr = write_commit( writer )) != S_OK) goto done;
|
2017-05-15 09:59:23 +02:00
|
|
|
if ((hr = write_grow_buffer( writer, xmlbuf->bytes.length )) != S_OK) goto done;
|
|
|
|
write_bytes( writer, xmlbuf->bytes.bytes, xmlbuf->bytes.length );
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
done:
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-09 01:07:00 +01:00
|
|
|
return hr;
|
2016-01-21 15:27:56 +01:00
|
|
|
}
|
2016-01-21 15:27:57 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteXmlBufferToBytes [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteXmlBufferToBytes( WS_XML_WRITER *handle, WS_XML_BUFFER *buffer,
|
|
|
|
const WS_XML_WRITER_ENCODING *encoding,
|
|
|
|
const WS_XML_WRITER_PROPERTY *properties, ULONG count,
|
|
|
|
WS_HEAP *heap, void **bytes, ULONG *size, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
struct xmlbuf *xmlbuf = (struct xmlbuf *)buffer;
|
2017-03-08 11:25:57 +01:00
|
|
|
HRESULT hr = S_OK;
|
2016-01-21 15:27:57 +01:00
|
|
|
char *buf;
|
|
|
|
ULONG i;
|
|
|
|
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "%p %p %p %p %lu %p %p %p %p\n", handle, buffer, encoding, properties, count, heap,
|
2016-01-21 15:27:57 +01:00
|
|
|
bytes, size, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !xmlbuf || !heap || !bytes) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (encoding && encoding->encodingType != WS_XML_WRITER_ENCODING_TYPE_TEXT)
|
|
|
|
{
|
|
|
|
FIXME( "encoding type %u not supported\n", encoding->encodingType );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2016-01-21 15:27:57 +01:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2016-04-22 09:42:38 +02:00
|
|
|
hr = prop_set( writer->prop, writer->prop_count, properties[i].id, properties[i].value,
|
|
|
|
properties[i].valueSize );
|
2017-03-08 11:25:57 +01:00
|
|
|
if (hr != S_OK) goto done;
|
2016-01-21 15:27:57 +01:00
|
|
|
}
|
|
|
|
|
2017-05-15 09:59:23 +02:00
|
|
|
if (!(buf = ws_alloc( heap, xmlbuf->bytes.length ))) hr = WS_E_QUOTA_EXCEEDED;
|
2017-03-08 11:25:57 +01:00
|
|
|
else
|
|
|
|
{
|
2017-05-15 09:59:23 +02:00
|
|
|
memcpy( buf, xmlbuf->bytes.bytes, xmlbuf->bytes.length );
|
2017-03-08 11:25:57 +01:00
|
|
|
*bytes = buf;
|
2017-05-15 09:59:23 +02:00
|
|
|
*size = xmlbuf->bytes.length;
|
2017-03-08 11:25:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-01-21 15:27:57 +01:00
|
|
|
}
|
2016-02-23 13:11:51 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteXmlnsAttribute [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteXmlnsAttribute( WS_XML_WRITER *handle, const WS_XML_STRING *prefix,
|
|
|
|
const WS_XML_STRING *ns, BOOL single, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2017-03-08 11:25:57 +01:00
|
|
|
HRESULT hr = S_OK;
|
2016-02-23 13:11:51 +01:00
|
|
|
|
|
|
|
TRACE( "%p %s %s %d %p\n", handle, debugstr_xmlstr(prefix), debugstr_xmlstr(ns),
|
|
|
|
single, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !ns) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (writer->state != WRITER_STATE_STARTELEMENT) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else if (!namespace_in_scope( &writer->current->hdr, prefix, ns ))
|
2017-05-23 12:03:53 +02:00
|
|
|
hr = add_namespace_attribute( writer, prefix, ns, single );
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-02-23 13:11:51 +01:00
|
|
|
}
|
2016-06-21 14:04:46 +02:00
|
|
|
|
2017-04-28 12:12:47 +02:00
|
|
|
static HRESULT write_qualified_name( struct writer *writer, const WS_XML_STRING *prefix,
|
2017-06-21 09:37:38 +02:00
|
|
|
const WS_XML_STRING *localname, const WS_XML_STRING *ns )
|
2017-04-28 12:12:47 +02:00
|
|
|
{
|
2017-06-21 09:37:38 +02:00
|
|
|
WS_XML_QNAME_TEXT qname = {{WS_XML_TEXT_TYPE_QNAME}};
|
2017-04-28 12:12:47 +02:00
|
|
|
HRESULT hr;
|
2017-06-21 09:37:38 +02:00
|
|
|
|
2018-12-04 13:57:28 +01:00
|
|
|
if ((hr = write_commit( writer )) != S_OK) return hr;
|
2017-06-21 09:37:38 +02:00
|
|
|
if (!prefix && ((hr = find_prefix( writer, ns, &prefix )) != S_OK)) return hr;
|
|
|
|
|
|
|
|
qname.prefix = (WS_XML_STRING *)prefix;
|
|
|
|
qname.localName = (WS_XML_STRING *)localname;
|
|
|
|
qname.ns = (WS_XML_STRING *)ns;
|
|
|
|
|
|
|
|
if ((hr = write_add_text_node( writer, &qname.text )) != S_OK) return hr;
|
|
|
|
return write_text( writer, ((const WS_XML_TEXT_NODE *)writer->current)->text, 0 );
|
2017-04-28 12:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteQualifiedName [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteQualifiedName( WS_XML_WRITER *handle, const WS_XML_STRING *prefix,
|
|
|
|
const WS_XML_STRING *localname, const WS_XML_STRING *ns,
|
|
|
|
WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "%p %s %s %s %p\n", handle, debugstr_xmlstr(prefix), debugstr_xmlstr(localname),
|
|
|
|
debugstr_xmlstr(ns), error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (!writer->output_type) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else if (writer->state != WRITER_STATE_STARTELEMENT) hr = WS_E_INVALID_FORMAT;
|
|
|
|
else if (!localname || (!prefix && !ns)) hr = E_INVALIDARG;
|
|
|
|
else hr = write_qualified_name( writer, prefix, localname, ns );
|
2017-04-28 12:12:47 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-04-28 12:12:47 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2016-06-21 14:04:46 +02:00
|
|
|
static HRESULT write_move_to( struct writer *writer, WS_MOVE_TO move, BOOL *found )
|
|
|
|
{
|
|
|
|
BOOL success = FALSE;
|
|
|
|
struct node *node = writer->current;
|
|
|
|
|
|
|
|
switch (move)
|
|
|
|
{
|
|
|
|
case WS_MOVE_TO_ROOT_ELEMENT:
|
|
|
|
success = move_to_root_element( writer->root, &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_NEXT_ELEMENT:
|
|
|
|
success = move_to_next_element( &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_PREVIOUS_ELEMENT:
|
|
|
|
success = move_to_prev_element( &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_CHILD_ELEMENT:
|
|
|
|
success = move_to_child_element( &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_END_ELEMENT:
|
|
|
|
success = move_to_end_element( &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_PARENT_ELEMENT:
|
|
|
|
success = move_to_parent_element( &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_FIRST_NODE:
|
|
|
|
success = move_to_first_node( &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_NEXT_NODE:
|
|
|
|
success = move_to_next_node( &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_PREVIOUS_NODE:
|
|
|
|
success = move_to_prev_node( &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_CHILD_NODE:
|
|
|
|
success = move_to_child_node( &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_BOF:
|
|
|
|
success = move_to_bof( writer->root, &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_MOVE_TO_EOF:
|
|
|
|
success = move_to_eof( writer->root, &node );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled move %u\n", move );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success && node == writer->root) return E_INVALIDARG;
|
|
|
|
writer->current = node;
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
*found = success;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return success ? S_OK : WS_E_INVALID_FORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsMoveWriter [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsMoveWriter( WS_XML_WRITER *handle, WS_MOVE_TO move, BOOL *found, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2017-03-08 11:25:57 +01:00
|
|
|
HRESULT hr;
|
2016-06-21 14:04:46 +02:00
|
|
|
|
|
|
|
TRACE( "%p %u %p %p\n", handle, move, found, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-12-04 13:57:28 +01:00
|
|
|
if (writer->output_type != WS_XML_WRITER_OUTPUT_TYPE_BUFFER) hr = WS_E_INVALID_OPERATION;
|
2018-10-17 13:42:36 +02:00
|
|
|
else hr = write_move_to( writer, move, found );
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-06-21 14:04:46 +02:00
|
|
|
}
|
2016-06-21 14:04:47 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsGetWriterPosition [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsGetWriterPosition( WS_XML_WRITER *handle, WS_XML_NODE_POSITION *pos, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2018-10-17 13:42:36 +02:00
|
|
|
HRESULT hr = S_OK;
|
2016-06-21 14:04:47 +02:00
|
|
|
|
|
|
|
TRACE( "%p %p %p\n", handle, pos, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !pos) return E_INVALIDARG;
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (!writer->output_type) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else
|
2017-03-08 11:25:57 +01:00
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
pos->buffer = (WS_XML_BUFFER *)writer->output_buf;
|
|
|
|
pos->node = writer->current;
|
2017-03-08 11:25:57 +01:00
|
|
|
}
|
2016-06-21 14:04:47 +02:00
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2018-10-17 13:42:36 +02:00
|
|
|
return hr;
|
2016-06-21 14:04:47 +02:00
|
|
|
}
|
2016-06-21 14:04:48 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsSetWriterPosition [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsSetWriterPosition( WS_XML_WRITER *handle, const WS_XML_NODE_POSITION *pos, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2018-10-17 13:42:36 +02:00
|
|
|
HRESULT hr = S_OK;
|
2016-06-21 14:04:48 +02:00
|
|
|
|
|
|
|
TRACE( "%p %p %p\n", handle, pos, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
if (!writer || !pos) return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC || (struct xmlbuf *)pos->buffer != writer->output_buf)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (!writer->output_type) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else writer->current = pos->node;
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2018-10-17 13:42:36 +02:00
|
|
|
return hr;
|
2016-06-21 14:04:48 +02:00
|
|
|
}
|
2016-07-04 11:35:41 +02:00
|
|
|
|
|
|
|
static HRESULT write_add_comment_node( struct writer *writer, const WS_XML_STRING *value )
|
|
|
|
{
|
|
|
|
struct node *node, *parent;
|
|
|
|
WS_XML_COMMENT_NODE *comment;
|
|
|
|
|
2016-10-12 15:30:24 +02:00
|
|
|
if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT;
|
2016-07-04 11:35:41 +02:00
|
|
|
if (!(node = alloc_node( WS_XML_NODE_TYPE_COMMENT ))) return E_OUTOFMEMORY;
|
|
|
|
comment = (WS_XML_COMMENT_NODE *)node;
|
|
|
|
|
2022-02-01 14:57:00 +01:00
|
|
|
if (value->length && !(comment->value.bytes = malloc( value->length )))
|
2016-07-04 11:35:41 +02:00
|
|
|
{
|
|
|
|
free_node( node );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
memcpy( comment->value.bytes, value->bytes, value->length );
|
|
|
|
comment->value.length = value->length;
|
|
|
|
|
|
|
|
write_insert_node( writer, parent, node );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 12:54:38 +02:00
|
|
|
static HRESULT write_comment_text( struct writer *writer )
|
2016-07-04 11:35:41 +02:00
|
|
|
{
|
|
|
|
const WS_XML_COMMENT_NODE *comment = (const WS_XML_COMMENT_NODE *)writer->current;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, comment->value.length + 7 )) != S_OK) return hr;
|
|
|
|
write_bytes( writer, (const BYTE *)"<!--", 4 );
|
|
|
|
write_bytes( writer, comment->value.bytes, comment->value.length );
|
|
|
|
write_bytes( writer, (const BYTE *)"-->", 3 );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 12:54:38 +02:00
|
|
|
static HRESULT write_comment_bin( struct writer *writer )
|
|
|
|
{
|
|
|
|
const WS_XML_COMMENT_NODE *comment = (const WS_XML_COMMENT_NODE *)writer->current;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if ((hr = write_grow_buffer( writer, 1 )) != S_OK) return hr;
|
|
|
|
write_char( writer, RECORD_COMMENT );
|
|
|
|
return write_string( writer, comment->value.bytes, comment->value.length );
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_comment( struct writer *writer )
|
|
|
|
{
|
|
|
|
switch (writer->output_enc)
|
|
|
|
{
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_TEXT: return write_comment_text( writer );
|
|
|
|
case WS_XML_WRITER_ENCODING_TYPE_BINARY: return write_comment_bin( writer );
|
|
|
|
default:
|
|
|
|
ERR( "unhandled encoding %u\n", writer->output_enc );
|
|
|
|
return WS_E_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 11:35:41 +02:00
|
|
|
static HRESULT write_comment_node( struct writer *writer, const WS_XML_STRING *value )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2018-12-04 13:57:28 +01:00
|
|
|
if ((hr = write_commit( writer )) != S_OK) return hr;
|
2016-07-04 11:35:41 +02:00
|
|
|
if ((hr = write_add_comment_node( writer, value )) != S_OK) return hr;
|
|
|
|
if ((hr = write_comment( writer )) != S_OK) return hr;
|
|
|
|
writer->state = WRITER_STATE_COMMENT;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_set_attributes( struct writer *writer, WS_XML_ATTRIBUTE **attrs, ULONG count )
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2017-10-17 11:37:27 +02:00
|
|
|
const WS_XML_STRING *prefix = attrs[i]->prefix;
|
|
|
|
const WS_XML_STRING *localname = attrs[i]->localName;
|
|
|
|
const WS_XML_STRING *ns = attrs[i]->ns;
|
|
|
|
BOOL single = attrs[i]->singleQuote;
|
|
|
|
|
|
|
|
if (attrs[i]->isXmlNs)
|
|
|
|
{
|
|
|
|
if ((hr = add_namespace_attribute( writer, prefix, ns, single )) != S_OK) return hr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((hr = write_add_attribute( writer, prefix, localname, ns, single )) != S_OK) return hr;
|
|
|
|
if ((hr = write_set_attribute_value( writer, attrs[i]->value )) != S_OK) return hr;
|
|
|
|
}
|
2016-07-04 11:35:41 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_node( struct writer *writer, const WS_XML_NODE *node )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
switch (node->nodeType)
|
|
|
|
{
|
|
|
|
case WS_XML_NODE_TYPE_ELEMENT:
|
|
|
|
{
|
|
|
|
const WS_XML_ELEMENT_NODE *elem = (const WS_XML_ELEMENT_NODE *)node;
|
|
|
|
if ((hr = write_element_node( writer, elem->prefix, elem->localName, elem->ns )) != S_OK) return hr;
|
|
|
|
return write_set_attributes( writer, elem->attributes, elem->attributeCount );
|
|
|
|
}
|
|
|
|
case WS_XML_NODE_TYPE_TEXT:
|
|
|
|
{
|
|
|
|
const WS_XML_TEXT_NODE *text = (const WS_XML_TEXT_NODE *)node;
|
2016-07-04 11:35:42 +02:00
|
|
|
return write_text_node( writer, text->text );
|
2016-07-04 11:35:41 +02:00
|
|
|
}
|
|
|
|
case WS_XML_NODE_TYPE_END_ELEMENT:
|
|
|
|
return write_endelement_node( writer );
|
|
|
|
|
|
|
|
case WS_XML_NODE_TYPE_COMMENT:
|
|
|
|
{
|
|
|
|
const WS_XML_COMMENT_NODE *comment = (const WS_XML_COMMENT_NODE *)node;
|
|
|
|
return write_comment_node( writer, &comment->value );
|
|
|
|
}
|
|
|
|
case WS_XML_NODE_TYPE_CDATA:
|
|
|
|
return write_cdata_node( writer );
|
|
|
|
|
|
|
|
case WS_XML_NODE_TYPE_END_CDATA:
|
|
|
|
return write_endcdata_node( writer );
|
|
|
|
|
|
|
|
case WS_XML_NODE_TYPE_EOF:
|
|
|
|
case WS_XML_NODE_TYPE_BOF:
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WARN( "unknown node type %u\n", node->nodeType );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsWriteNode [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsWriteNode( WS_XML_WRITER *handle, const WS_XML_NODE *node, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2017-03-08 11:25:57 +01:00
|
|
|
HRESULT hr;
|
2016-07-04 11:35:41 +02:00
|
|
|
|
|
|
|
TRACE( "%p %p %p\n", handle, node, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer || !node) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (!writer->output_type) hr = WS_E_INVALID_OPERATION;
|
|
|
|
else hr = write_node( writer, node );
|
2017-03-08 11:25:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-07-04 11:35:41 +02:00
|
|
|
}
|
2016-07-04 11:35:44 +02:00
|
|
|
|
|
|
|
static HRESULT write_tree_node( struct writer *writer )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
switch (node_type( writer->current ))
|
|
|
|
{
|
|
|
|
case WS_XML_NODE_TYPE_ELEMENT:
|
|
|
|
if (writer->state == WRITER_STATE_STARTELEMENT && (hr = write_endstartelement( writer )) != S_OK)
|
|
|
|
return hr;
|
|
|
|
if ((hr = write_startelement( writer )) != S_OK) return hr;
|
|
|
|
writer->state = WRITER_STATE_STARTELEMENT;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
case WS_XML_NODE_TYPE_TEXT:
|
|
|
|
if (writer->state == WRITER_STATE_STARTELEMENT && (hr = write_endstartelement( writer )) != S_OK)
|
|
|
|
return hr;
|
2017-05-23 12:03:54 +02:00
|
|
|
if ((hr = write_text( writer, ((const WS_XML_TEXT_NODE *)writer->current)->text, 0 )) != S_OK) return hr;
|
2016-07-04 11:35:44 +02:00
|
|
|
writer->state = WRITER_STATE_TEXT;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
case WS_XML_NODE_TYPE_END_ELEMENT:
|
|
|
|
if ((hr = write_close_element( writer, writer->current->parent )) != S_OK) return hr;
|
|
|
|
writer->state = WRITER_STATE_ENDELEMENT;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
case WS_XML_NODE_TYPE_COMMENT:
|
|
|
|
if (writer->state == WRITER_STATE_STARTELEMENT && (hr = write_endstartelement( writer )) != S_OK)
|
|
|
|
return hr;
|
|
|
|
if ((hr = write_comment( writer )) != S_OK) return hr;
|
|
|
|
writer->state = WRITER_STATE_COMMENT;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
case WS_XML_NODE_TYPE_CDATA:
|
|
|
|
if (writer->state == WRITER_STATE_STARTELEMENT && (hr = write_endstartelement( writer )) != S_OK)
|
|
|
|
return hr;
|
|
|
|
if ((hr = write_cdata( writer )) != S_OK) return hr;
|
|
|
|
writer->state = WRITER_STATE_STARTCDATA;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
case WS_XML_NODE_TYPE_END_CDATA:
|
|
|
|
if ((hr = write_endcdata( writer )) != S_OK) return hr;
|
|
|
|
writer->state = WRITER_STATE_ENDCDATA;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
case WS_XML_NODE_TYPE_EOF:
|
|
|
|
case WS_XML_NODE_TYPE_BOF:
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR( "unknown node type %u\n", node_type(writer->current) );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_tree( struct writer *writer )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if ((hr = write_tree_node( writer )) != S_OK) return hr;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (node_type( writer->current ) == WS_XML_NODE_TYPE_EOF) break;
|
|
|
|
if (move_to_child_node( &writer->current ))
|
|
|
|
{
|
|
|
|
if ((hr = write_tree_node( writer )) != S_OK) return hr;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (move_to_next_node( &writer->current ))
|
|
|
|
{
|
|
|
|
if ((hr = write_tree_node( writer )) != S_OK) return hr;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!move_to_parent_node( &writer->current ) || !move_to_next_node( &writer->current ))
|
|
|
|
{
|
|
|
|
ERR( "invalid tree\n" );
|
|
|
|
return WS_E_INVALID_FORMAT;
|
|
|
|
}
|
|
|
|
if ((hr = write_tree_node( writer )) != S_OK) return hr;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_rewind( struct writer *writer )
|
|
|
|
{
|
|
|
|
writer->write_pos = 0;
|
|
|
|
writer->current = writer->root;
|
|
|
|
writer->state = WRITER_STATE_INITIAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* WsCopyNode [webservices.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WsCopyNode( WS_XML_WRITER *handle, WS_XML_READER *reader, WS_ERROR *error )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
2017-03-08 11:25:57 +01:00
|
|
|
struct node *parent, *current, *node = NULL;
|
2016-07-04 11:35:44 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "%p %p %p\n", handle, reader, error );
|
|
|
|
if (error) FIXME( "ignoring error parameter\n" );
|
|
|
|
|
|
|
|
if (!writer) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
if (!(parent = find_parent( writer ))) hr = WS_E_INVALID_FORMAT;
|
|
|
|
else
|
2017-03-08 11:25:57 +01:00
|
|
|
{
|
2018-10-17 13:42:36 +02:00
|
|
|
if ((hr = copy_node( reader, writer->output_enc, &node )) != S_OK) goto done;
|
|
|
|
current = writer->current;
|
|
|
|
write_insert_node( writer, parent, node );
|
2017-03-08 11:25:57 +01:00
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
write_rewind( writer );
|
|
|
|
if ((hr = write_tree( writer )) != S_OK) goto done;
|
|
|
|
writer->current = current;
|
2017-03-08 11:25:57 +01:00
|
|
|
|
2018-10-17 13:42:36 +02:00
|
|
|
WsMoveReader( reader, WS_MOVE_TO_NEXT_NODE, NULL, NULL );
|
|
|
|
}
|
2017-05-15 09:59:19 +02:00
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
done:
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
2022-02-15 10:32:49 +01:00
|
|
|
TRACE( "returning %#lx\n", hr );
|
2017-03-08 11:25:57 +01:00
|
|
|
return hr;
|
2016-07-04 11:35:44 +02:00
|
|
|
}
|
2016-10-25 13:03:23 +02:00
|
|
|
|
|
|
|
static HRESULT write_param( struct writer *writer, const WS_FIELD_DESCRIPTION *desc, const void *value )
|
|
|
|
{
|
2017-07-10 11:02:29 +02:00
|
|
|
return write_type_field( writer, desc, value, 0 );
|
2016-10-25 13:03:23 +02:00
|
|
|
}
|
|
|
|
|
2016-11-17 17:11:08 +01:00
|
|
|
static ULONG get_array_len( const WS_PARAMETER_DESCRIPTION *params, ULONG count, ULONG index, const void **args )
|
|
|
|
{
|
|
|
|
ULONG i, ret = 0;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (params[i].inputMessageIndex != index || params[i].parameterType != WS_PARAMETER_TYPE_ARRAY_COUNT)
|
|
|
|
continue;
|
|
|
|
if (args[i]) ret = *(const ULONG *)args[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_param_array( struct writer *writer, const WS_FIELD_DESCRIPTION *desc, const void *value,
|
|
|
|
ULONG len )
|
|
|
|
{
|
2017-12-08 15:49:39 +01:00
|
|
|
return write_type_array( writer, desc, value, len );
|
2016-11-17 17:11:08 +01:00
|
|
|
}
|
|
|
|
|
2016-10-25 13:03:23 +02:00
|
|
|
HRESULT write_input_params( WS_XML_WRITER *handle, const WS_ELEMENT_DESCRIPTION *desc,
|
|
|
|
const WS_PARAMETER_DESCRIPTION *params, ULONG count, const void **args )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
const WS_STRUCT_DESCRIPTION *desc_struct;
|
|
|
|
const WS_FIELD_DESCRIPTION *desc_field;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
if (desc->type != WS_STRUCT_TYPE || !(desc_struct = desc->typeDescription)) return E_INVALIDARG;
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hr = write_element_node( writer, NULL, desc->elementLocalName, desc->elementNs )) != S_OK) goto done;
|
2016-10-25 13:03:23 +02:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (params[i].inputMessageIndex == INVALID_PARAMETER_INDEX) continue;
|
|
|
|
if (params[i].parameterType == WS_PARAMETER_TYPE_MESSAGES)
|
|
|
|
{
|
|
|
|
FIXME( "messages type not supported\n" );
|
2017-03-08 11:25:57 +01:00
|
|
|
hr = E_NOTIMPL;
|
|
|
|
goto done;
|
2016-10-25 13:03:23 +02:00
|
|
|
}
|
2017-03-08 11:25:57 +01:00
|
|
|
if ((hr = get_param_desc( desc_struct, params[i].inputMessageIndex, &desc_field )) != S_OK) goto done;
|
2016-10-25 13:03:23 +02:00
|
|
|
if (params[i].parameterType == WS_PARAMETER_TYPE_NORMAL)
|
|
|
|
{
|
2017-03-08 11:25:57 +01:00
|
|
|
if ((hr = write_param( writer, desc_field, args[i] )) != S_OK) goto done;
|
2016-10-25 13:03:23 +02:00
|
|
|
}
|
|
|
|
else if (params[i].parameterType == WS_PARAMETER_TYPE_ARRAY)
|
|
|
|
{
|
2016-11-17 17:11:08 +01:00
|
|
|
const void *ptr = *(const void **)args[i];
|
|
|
|
ULONG len = get_array_len( params, count, params[i].inputMessageIndex, args );
|
2017-03-08 11:25:57 +01:00
|
|
|
if ((hr = write_param_array( writer, desc_field, ptr, len )) != S_OK) goto done;
|
2016-10-25 13:03:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 11:25:57 +01:00
|
|
|
hr = write_endelement_node( writer );
|
|
|
|
|
|
|
|
done:
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return hr;
|
2016-10-25 13:03:23 +02:00
|
|
|
}
|
2017-09-06 15:56:09 +02:00
|
|
|
|
2018-06-20 15:04:47 +02:00
|
|
|
HRESULT writer_set_lookup( WS_XML_WRITER *handle, BOOL enable )
|
2017-09-06 15:56:09 +02:00
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:04:47 +02:00
|
|
|
writer->dict_do_lookup = enable;
|
2017-09-06 15:56:09 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return S_OK;
|
|
|
|
}
|
2018-06-20 15:04:48 +02:00
|
|
|
|
|
|
|
HRESULT writer_set_dict_callback( WS_XML_WRITER *handle, WS_DYNAMIC_STRING_CALLBACK cb, void *state )
|
|
|
|
{
|
|
|
|
struct writer *writer = (struct writer *)handle;
|
|
|
|
|
|
|
|
EnterCriticalSection( &writer->cs );
|
|
|
|
|
|
|
|
if (writer->magic != WRITER_MAGIC)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
writer->dict_cb = cb;
|
|
|
|
writer->dict_cb_state = state;
|
|
|
|
|
|
|
|
LeaveCriticalSection( &writer->cs );
|
|
|
|
return S_OK;
|
|
|
|
}
|