Commit 5f51b603 authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

webservices: Fix handling of duplicate headers in WsAddCustomHeader.

parent b79891a2
......@@ -1022,9 +1022,7 @@ HRESULT WINAPI WsAddCustomHeader( WS_MESSAGE *handle, const WS_ELEMENT_DESCRIPTI
{
struct msg *msg = (struct msg *)handle;
struct header *header;
BOOL found = FALSE;
HRESULT hr;
ULONG i;
TRACE( "%p %p %08x %p %u %08x %p\n", handle, desc, option, value, size, attrs, error );
if (error) FIXME( "ignoring error parameter\n" );
......@@ -1032,30 +1030,11 @@ HRESULT WINAPI WsAddCustomHeader( WS_MESSAGE *handle, const WS_ELEMENT_DESCRIPTI
if (!handle || !desc) return E_INVALIDARG;
if (msg->state < WS_MESSAGE_STATE_INITIALIZED) return WS_E_INVALID_OPERATION;
for (i = 0; i < msg->header_count; i++)
{
if (msg->header[i]->type || msg->header[i]->mapped) continue;
if (WsXmlStringEquals( desc->elementLocalName, &msg->header[i]->name, NULL ) &&
WsXmlStringEquals( desc->elementNs, &msg->header[i]->ns, NULL ) == S_OK)
{
found = TRUE;
break;
}
}
if (!found)
{
if ((hr = grow_header_array( msg, msg->header_count + 1 )) != S_OK) return hr;
i = msg->header_count;
}
if ((hr = grow_header_array( msg, msg->header_count + 1 )) != S_OK) return hr;
if ((hr = build_custom_header( msg->heap, desc->elementLocalName, desc->elementNs, desc->type,
desc->typeDescription, option, value, size, &header )) != S_OK) return hr;
if (!found) msg->header_count++;
else free_header( msg->header[i] );
msg->header[i] = header;
msg->header[msg->header_count++] = header;
return write_envelope( msg );
}
......
......@@ -749,8 +749,22 @@ static void test_WsAddCustomHeader(void)
"xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
"<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
"</s:Header><s:Body/></s:Envelope>";
static const char expected3[] =
"<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
"xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
"<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
"<header xmlns=\"ns\">value</header><header xmlns=\"ns\">value2</header>"
"</s:Header><s:Body/></s:Envelope>";
static const char expected4[] =
"<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
"xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
"<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
"<header xmlns=\"ns\">value</header><header xmlns=\"ns\">value2</header>"
"<header2 xmlns=\"ns\">value2</header2></s:Header><s:Body/></s:Envelope>";
static WS_XML_STRING header = {6, (BYTE *)"header"}, ns = {2, (BYTE *)"ns"};
static WS_XML_STRING header2 = {7, (BYTE *)"header2"};
static WCHAR valueW[] = {'v','a','l','u','e',0};
static WCHAR value2W[] = {'v','a','l','u','e','2',0};
HRESULT hr;
WS_MESSAGE *msg;
WS_ELEMENT_DESCRIPTION desc;
......@@ -797,6 +811,16 @@ static void test_WsAddCustomHeader(void)
ok( hr == S_OK, "got %08x\n", hr );
check_output_header( msg, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
test.value = value2W;
hr = WsAddCustomHeader( msg, &desc, WS_WRITE_REQUIRED_VALUE, &test, sizeof(test), 0, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output_header( msg, expected3, -1, strstr(expected3, "urn:uuid:") - expected3, 46, __LINE__ );
desc.elementLocalName = &header2;
hr = WsAddCustomHeader( msg, &desc, WS_WRITE_REQUIRED_VALUE, &test, sizeof(test), 0, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output_header( msg, expected4, -1, strstr(expected4, "urn:uuid:") - expected4, 46, __LINE__ );
hr = WsAddCustomHeader( msg, &desc, WS_WRITE_REQUIRED_VALUE, NULL, 0, 0, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
......
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