Commit 2eab7118 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

webservices: Parse comment nodes.

parent 8d357fc1
......@@ -287,6 +287,11 @@ static void free_node( struct node *node )
heap_free( text->text );
break;
}
case WS_XML_NODE_TYPE_COMMENT:
{
WS_XML_COMMENT_NODE *comment = (WS_XML_COMMENT_NODE *)node;
heap_free( comment->value.bytes );
}
case WS_XML_NODE_TYPE_END_ELEMENT:
case WS_XML_NODE_TYPE_EOF:
case WS_XML_NODE_TYPE_BOF:
......@@ -342,6 +347,7 @@ enum reader_state
READER_STATE_STARTELEMENT,
READER_STATE_TEXT,
READER_STATE_ENDELEMENT,
READER_STATE_COMMENT,
READER_STATE_EOF
};
......@@ -954,6 +960,45 @@ static HRESULT read_endelement( struct reader *reader )
return S_OK;
}
static HRESULT read_comment( struct reader *reader )
{
unsigned int len = 0, ch, skip;
const char *start;
struct node *node;
WS_XML_COMMENT_NODE *comment;
if (read_cmp( reader, "<!--", 4 )) return WS_E_INVALID_FORMAT;
read_skip( reader, 4 );
start = read_current_ptr( reader );
for (;;)
{
if (!read_cmp( reader, "-->", 3 ))
{
read_skip( reader, 3 );
break;
}
if (!(ch = read_utf8_char( reader, &skip ))) return WS_E_INVALID_FORMAT;
read_skip( reader, skip );
len += skip;
}
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;
}
memcpy( comment->value.bytes, start, len );
comment->value.length = len;
list_add_after( &reader->current->entry, &node->entry );
reader->current = node;
reader->state = READER_STATE_COMMENT;
return S_OK;
}
static HRESULT read_node( struct reader *reader )
{
HRESULT hr;
......@@ -972,6 +1017,7 @@ static HRESULT read_node( struct reader *reader )
if (FAILED( hr )) return hr;
}
else if (!read_cmp( reader, "</", 2 )) return read_endelement( reader );
else if (!read_cmp( reader, "<!", 2 )) return read_comment( reader );
else if (!read_cmp( reader, "<", 1 )) return read_startelement( reader );
else return read_text( reader );
}
......
......@@ -52,6 +52,9 @@ static const char data6[] =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<text attr= \"value\" attr2='value2'>test</text>";
static const char data7[] =
"<!-- comment -->";
static const char data8[] =
"<node1><node2>test</node2></node1>";
......@@ -780,6 +783,9 @@ static void test_WsReadNode(void)
static const char str12[] = "<text>test</text>";
static const char str13[] = "<?xml version=\"1.0\"?><text>test</text>";
static const char str14[] = "";
static const char str15[] = "<!--";
static const char str16[] = "<!---->";
static const char str17[] = "<!--comment-->";
HRESULT hr;
WS_XML_READER *reader;
const WS_XML_NODE *node;
......@@ -808,6 +814,9 @@ static void test_WsReadNode(void)
{ str12, S_OK, WS_XML_NODE_TYPE_ELEMENT },
{ str13, S_OK, WS_XML_NODE_TYPE_ELEMENT },
{ str14, WS_E_INVALID_FORMAT, 0, 1 },
{ str15, WS_E_INVALID_FORMAT, 0 },
{ str16, S_OK, WS_XML_NODE_TYPE_COMMENT },
{ str17, S_OK, WS_XML_NODE_TYPE_COMMENT },
};
hr = WsCreateReader( NULL, 0, &reader, NULL ) ;
......@@ -915,6 +924,26 @@ static void test_WsReadNode(void)
ok( !memcmp( text->value.bytes, "value2", 6 ), "wrong data\n" );
}
hr = set_input( reader, data7, sizeof(data7) - 1 );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsFillReader( reader, sizeof(data7) - 1, NULL, NULL );
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 );
if (node)
{
WS_XML_COMMENT_NODE *comment = (WS_XML_COMMENT_NODE *)node;
ok( comment->node.nodeType == WS_XML_NODE_TYPE_COMMENT, "got %u\n", comment->node.nodeType );
ok( comment->value.length == 9, "got %u\n", comment->value.length );
ok( !memcmp( comment->value.bytes, " comment ", 9 ), "wrong data\n" );
}
WsFreeReader( reader );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment