webservices: Add support for reading comments in binary mode.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2017-05-25 12:54:43 +02:00 committed by Alexandre Julliard
parent b9953cef4e
commit 6f65dbc04c
2 changed files with 55 additions and 2 deletions

View File

@ -1942,7 +1942,7 @@ static HRESULT read_endelement( struct reader *reader )
}
}
static HRESULT read_comment( struct reader *reader )
static HRESULT read_comment_text( struct reader *reader )
{
unsigned int len = 0, ch, skip;
const unsigned char *start;
@ -1982,6 +1982,39 @@ static HRESULT read_comment( struct reader *reader )
return S_OK;
}
static HRESULT read_comment_bin( struct reader *reader )
{
struct node *node, *parent;
WS_XML_COMMENT_NODE *comment;
unsigned char type;
ULONG len;
HRESULT hr;
if ((hr = read_byte( reader, &type )) != S_OK) return hr;
if (type != RECORD_COMMENT) return WS_E_INVALID_FORMAT;
if ((hr = read_int31( reader, &len )) != S_OK) return hr;
if (!(parent = find_parent( reader ))) return WS_E_INVALID_FORMAT;
if (!(node = alloc_node( WS_XML_NODE_TYPE_COMMENT ))) return E_OUTOFMEMORY;
comment = (WS_XML_COMMENT_NODE *)node;
if (!(comment->value.bytes = heap_alloc( len )))
{
heap_free( node );
return E_OUTOFMEMORY;
}
if ((hr = read_bytes( reader, comment->value.bytes, len )) != S_OK)
{
free_node( node );
return E_OUTOFMEMORY;
}
comment->value.length = len;
read_insert_node( reader, parent, node );
reader->state = READER_STATE_COMMENT;
return S_OK;
}
static HRESULT read_startcdata( struct reader *reader )
{
struct node *node, *endnode, *parent;
@ -2074,7 +2107,7 @@ static HRESULT read_node_text( struct reader *reader )
}
else if (!read_cmp( reader, "</", 2 )) return read_endelement_text( reader );
else if (!read_cmp( reader, "<![CDATA[", 9 )) return read_startcdata( reader );
else if (!read_cmp( reader, "<!--", 4 )) return read_comment( reader );
else if (!read_cmp( reader, "<!--", 4 )) return read_comment_text( reader );
else if (!read_cmp( reader, "<", 1 )) return read_element_text( reader );
else if (!read_cmp( reader, "/>", 2 ) || !read_cmp( reader, ">", 1 )) return read_startelement_text( reader );
else return read_text_text( reader );
@ -2106,6 +2139,10 @@ static HRESULT read_node_bin( struct reader *reader )
{
return read_endelement_bin( reader );
}
else if (type == RECORD_COMMENT)
{
return read_comment_bin( reader );
}
else if (type >= RECORD_SHORT_ELEMENT && type <= RECORD_PREFIX_ELEMENT_Z)
{
return read_element_bin( reader );

View File

@ -4516,11 +4516,14 @@ static void test_binary_encoding(void)
{0x41,0x02,'p','2',0x01,'t',0x09,0x02,'p','2',0x02,'n','s',0x01};
static const char res4[] =
{0x41,0x02,'p','2',0x01,'t',0x09,0x02,'p','2',0x02,'n','s',0x99,0x04,'t','e','s','t'};
static const char res200[] =
{0x02,0x07,'c','o','m','m','e','n','t'};
const WS_XML_NODE *node;
const WS_XML_ELEMENT_NODE *elem;
const WS_XML_ATTRIBUTE *attr;
const WS_XML_TEXT_NODE *text;
const WS_XML_UTF8_TEXT *utf8;
const WS_XML_COMMENT_NODE *comment;
WS_XML_READER *reader;
HRESULT hr;
@ -4659,6 +4662,19 @@ static void test_binary_encoding(void)
ok( hr == S_OK, "got %08x\n", hr );
ok( node->nodeType == WS_XML_NODE_TYPE_END_ELEMENT, "got %u\n", node->nodeType );
/* comment */
hr = set_input_bin( reader, res200, sizeof(res200) );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsReadNode( reader, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsGetReaderNode( reader, &node, NULL );
ok( hr == S_OK, "got %08x\n", hr );
ok( node->nodeType == WS_XML_NODE_TYPE_COMMENT, "got %u\n", node->nodeType );
comment = (const WS_XML_COMMENT_NODE *)node;
ok( comment->value.length == 7, "got %u\n", comment->value.length );
ok( !memcmp( comment->value.bytes, "comment", 7 ), "wrong data\n" );
WsFreeReader( reader );
}