Commit 19fecc4f authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

webservices: Add generic property handlers.

parent f52accf8
......@@ -29,12 +29,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(webservices);
static const struct
{
ULONG size;
BOOL readonly;
}
channel_props[] =
static const struct prop_desc channel_props[] =
{
{ sizeof(ULONG), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE */
{ sizeof(UINT64), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_STREAMED_MESSAGE_SIZE */
......@@ -51,42 +46,14 @@ static struct channel *alloc_channel(void)
{
static const ULONG count = sizeof(channel_props)/sizeof(channel_props[0]);
struct channel *ret;
ULONG i, size = sizeof(*ret) + count * sizeof(WS_CHANNEL_PROPERTY);
char *ptr;
ULONG size = sizeof(*ret) + prop_size( channel_props, count );
for (i = 0; i < count; i++) size += channel_props[i].size;
if (!(ret = heap_alloc_zero( size ))) return NULL;
ptr = (char *)&ret->prop[count];
for (i = 0; i < count; i++)
{
ret->prop[i].value = ptr;
ret->prop[i].valueSize = channel_props[i].size;
ptr += ret->prop[i].valueSize;
}
prop_init( channel_props, count, ret->prop, &ret[1] );
ret->prop_count = count;
return ret;
}
static HRESULT set_channel_prop( struct channel *channel, WS_CHANNEL_PROPERTY_ID id, const void *value,
ULONG size )
{
if (id >= channel->prop_count || size != channel_props[id].size || channel_props[id].readonly)
return E_INVALIDARG;
memcpy( channel->prop[id].value, value, size );
return S_OK;
}
static HRESULT get_channel_prop( struct channel *channel, WS_CHANNEL_PROPERTY_ID id, void *buf, ULONG size )
{
if (id >= channel->prop_count || size != channel_props[id].size)
return E_INVALIDARG;
memcpy( buf, channel->prop[id].value, channel->prop[id].valueSize );
return S_OK;
}
void free_channel( struct channel *channel )
{
heap_free( channel );
......@@ -101,11 +68,13 @@ HRESULT create_channel( WS_CHANNEL_TYPE type, WS_CHANNEL_BINDING binding,
if (!(channel = alloc_channel())) return E_OUTOFMEMORY;
set_channel_prop( channel, WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE, &msg_size, sizeof(msg_size) );
prop_set( channel->prop, channel->prop_count, WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE,
&msg_size, sizeof(msg_size) );
for (i = 0; i < count; i++)
{
hr = set_channel_prop( channel, properties[i].id, properties[i].value, properties[i].valueSize );
hr = prop_set( channel->prop, channel->prop_count, properties[i].id, properties[i].value,
properties[i].valueSize );
if (hr != S_OK)
{
free_channel( channel );
......@@ -177,7 +146,7 @@ HRESULT WINAPI WsGetChannelProperty( WS_CHANNEL *handle, WS_CHANNEL_PROPERTY_ID
TRACE( "%p %u %p %u %p\n", handle, id, buf, size, error );
if (error) FIXME( "ignoring error parameter\n" );
return get_channel_prop( channel, id, buf, size );
return prop_get( channel->prop, channel->prop_count, id, buf, size );
}
/**************************************************************************
......@@ -191,5 +160,5 @@ HRESULT WINAPI WsSetChannelProperty( WS_CHANNEL *handle, WS_CHANNEL_PROPERTY_ID
TRACE( "%p %u %p %u\n", handle, id, value, size );
if (error) FIXME( "ignoring error parameter\n" );
return set_channel_prop( channel, id, value, size );
return prop_set( channel->prop, channel->prop_count, id, value, size );
}
......@@ -50,12 +50,32 @@ static inline WS_XML_NODE_TYPE node_type( const struct node *node )
return node->hdr.node.nodeType;
}
struct prop_desc
{
ULONG size;
BOOL readonly;
BOOL writeonly;
};
struct prop
{
void *value;
ULONG size;
BOOL readonly;
BOOL writeonly;
};
ULONG prop_size( const struct prop_desc *, ULONG ) DECLSPEC_HIDDEN;
void prop_init( const struct prop_desc *, ULONG, struct prop *, void * ) DECLSPEC_HIDDEN;
HRESULT prop_set( const struct prop *, ULONG, ULONG, const void *, ULONG ) DECLSPEC_HIDDEN;
HRESULT prop_get( const struct prop *, ULONG, ULONG, void *, ULONG ) DECLSPEC_HIDDEN;
struct channel
{
WS_CHANNEL_TYPE type;
WS_CHANNEL_BINDING binding;
ULONG prop_count;
WS_CHANNEL_PROPERTY prop[9];
struct prop prop[9];
};
HRESULT create_channel( WS_CHANNEL_TYPE, WS_CHANNEL_BINDING, const WS_CHANNEL_PROPERTY *,
......
......@@ -30,12 +30,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(webservices);
static const struct
{
ULONG size;
BOOL readonly;
}
writer_props[] =
static const struct prop_desc writer_props[] =
{
{ sizeof(ULONG), FALSE }, /* WS_XML_WRITER_PROPERTY_MAX_DEPTH */
{ sizeof(BOOL), FALSE }, /* WS_XML_WRITER_PROPERTY_ALLOW_FRAGMENT */
......@@ -83,49 +78,21 @@ struct writer
struct xmlbuf *output_buf;
WS_HEAP *output_heap;
ULONG prop_count;
WS_XML_WRITER_PROPERTY prop[sizeof(writer_props)/sizeof(writer_props[0])];
struct prop prop[sizeof(writer_props)/sizeof(writer_props[0])];
};
static struct writer *alloc_writer(void)
{
static const ULONG count = sizeof(writer_props)/sizeof(writer_props[0]);
struct writer *ret;
ULONG i, size = sizeof(*ret) + count * sizeof(WS_XML_WRITER_PROPERTY);
char *ptr;
ULONG size = sizeof(*ret) + prop_size( writer_props, count );
for (i = 0; i < count; i++) size += writer_props[i].size;
if (!(ret = heap_alloc_zero( size ))) return NULL;
ptr = (char *)&ret->prop[count];
for (i = 0; i < count; i++)
{
ret->prop[i].value = ptr;
ret->prop[i].valueSize = writer_props[i].size;
ptr += ret->prop[i].valueSize;
}
prop_init( writer_props, count, ret->prop, &ret[1] );
ret->prop_count = count;
return ret;
}
static HRESULT set_writer_prop( struct writer *writer, WS_XML_WRITER_PROPERTY_ID id, const void *value,
ULONG size )
{
if (id >= writer->prop_count || size != writer_props[id].size || writer_props[id].readonly)
return E_INVALIDARG;
memcpy( writer->prop[id].value, value, size );
return S_OK;
}
static HRESULT get_writer_prop( struct writer *writer, WS_XML_WRITER_PROPERTY_ID id, void *buf, ULONG size )
{
if (id >= writer->prop_count || size != writer_props[id].size)
return E_INVALIDARG;
memcpy( buf, writer->prop[id].value, writer->prop[id].valueSize );
return S_OK;
}
static void free_writer( struct writer *writer )
{
destroy_nodes( writer->root );
......@@ -196,17 +163,18 @@ HRESULT WINAPI WsCreateWriter( const WS_XML_WRITER_PROPERTY *properties, ULONG c
if (!handle) return E_INVALIDARG;
if (!(writer = alloc_writer())) return E_OUTOFMEMORY;
set_writer_prop( writer, WS_XML_WRITER_PROPERTY_MAX_DEPTH, &max_depth, sizeof(max_depth) );
set_writer_prop( writer, WS_XML_WRITER_PROPERTY_MAX_ATTRIBUTES, &max_attrs, sizeof(max_attrs) );
set_writer_prop( writer, WS_XML_WRITER_PROPERTY_BUFFER_TRIM_SIZE, &trim_size, sizeof(trim_size) );
set_writer_prop( writer, WS_XML_WRITER_PROPERTY_CHARSET, &charset, sizeof(charset) );
set_writer_prop( writer, WS_XML_WRITER_PROPERTY_BUFFER_MAX_SIZE, &max_size, sizeof(max_size) );
set_writer_prop( writer, WS_XML_WRITER_PROPERTY_MAX_MIME_PARTS_BUFFER_SIZE, &max_size, sizeof(max_size) );
set_writer_prop( writer, WS_XML_WRITER_PROPERTY_MAX_NAMESPACES, &max_ns, sizeof(max_ns) );
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) );
for (i = 0; i < count; i++)
{
hr = set_writer_prop( writer, properties[i].id, properties[i].value, properties[i].valueSize );
hr = prop_set( writer->prop, writer->prop_count, properties[i].id, properties[i].value,
properties[i].valueSize );
if (hr != S_OK)
{
free_writer( writer );
......@@ -214,7 +182,8 @@ HRESULT WINAPI WsCreateWriter( const WS_XML_WRITER_PROPERTY *properties, ULONG c
}
}
hr = get_writer_prop( writer, WS_XML_WRITER_PROPERTY_BUFFER_MAX_SIZE, &max_size, sizeof(max_size) );
hr = prop_get( writer->prop, writer->prop_count, WS_XML_WRITER_PROPERTY_BUFFER_MAX_SIZE,
&max_size, sizeof(max_size) );
if (hr != S_OK)
{
free_writer( writer );
......@@ -315,7 +284,7 @@ HRESULT WINAPI WsGetWriterProperty( WS_XML_WRITER *handle, WS_XML_WRITER_PROPERT
return S_OK;
}
default:
return get_writer_prop( writer, id, buf, size );
return prop_get( writer->prop, writer->prop_count, id, buf, size );
}
}
......@@ -351,7 +320,8 @@ HRESULT WINAPI WsSetOutput( WS_XML_WRITER *handle, const WS_XML_WRITER_ENCODING
for (i = 0; i < count; i++)
{
hr = set_writer_prop( writer, properties[i].id, properties[i].value, properties[i].valueSize );
hr = prop_set( writer->prop, writer->prop_count, properties[i].id, properties[i].value,
properties[i].valueSize );
if (hr != S_OK) return hr;
}
......@@ -413,7 +383,8 @@ HRESULT WINAPI WsSetOutputToBuffer( WS_XML_WRITER *handle, WS_XML_BUFFER *buffer
for (i = 0; i < count; i++)
{
hr = set_writer_prop( writer, properties[i].id, properties[i].value, properties[i].valueSize );
hr = prop_set( writer->prop, writer->prop_count, properties[i].id, properties[i].value,
properties[i].valueSize );
if (hr != S_OK) return hr;
}
......@@ -1686,7 +1657,8 @@ HRESULT WINAPI WsWriteXmlBufferToBytes( WS_XML_WRITER *handle, WS_XML_BUFFER *bu
for (i = 0; i < count; i++)
{
hr = set_writer_prop( writer, properties[i].id, properties[i].value, properties[i].valueSize );
hr = prop_set( writer->prop, writer->prop_count, properties[i].id, properties[i].value,
properties[i].valueSize );
if (hr != S_OK) return 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