[1/8] webservices: Parse comment nodes.
Hans Leidekker
hans at codeweavers.com
Thu Oct 22 03:17:14 CDT 2015
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
dlls/webservices/reader.c | 46 +++++++++++++++++++++++++++++++++++++++++
dlls/webservices/tests/reader.c | 29 ++++++++++++++++++++++++++
2 files changed, 75 insertions(+)
diff --git a/dlls/webservices/reader.c b/dlls/webservices/reader.c
index ac61890..d888223 100644
--- a/dlls/webservices/reader.c
+++ b/dlls/webservices/reader.c
@@ -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 );
}
diff --git a/dlls/webservices/tests/reader.c b/dlls/webservices/tests/reader.c
index f4ac601..31587e1 100644
--- a/dlls/webservices/tests/reader.c
+++ b/dlls/webservices/tests/reader.c
@@ -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 );
}
--
2.6.1
More information about the wine-patches
mailing list