[3/7] webservices: Move error support to a separate file.
Hans Leidekker
hans at codeweavers.com
Wed Mar 29 04:14:45 CDT 2017
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
dlls/webservices/Makefile.in | 1 +
dlls/webservices/error.c | 234 +++++++++++++++++++++++++++++++++++++++++++
dlls/webservices/reader.c | 204 -------------------------------------
3 files changed, 235 insertions(+), 204 deletions(-)
create mode 100644 dlls/webservices/error.c
diff --git a/dlls/webservices/Makefile.in b/dlls/webservices/Makefile.in
index 8de4f6b2b9..8caa8023cc 100644
--- a/dlls/webservices/Makefile.in
+++ b/dlls/webservices/Makefile.in
@@ -4,6 +4,7 @@ IMPORTS = winhttp rpcrt4 user32
C_SRCS = \
channel.c \
+ error.c \
main.c \
msg.c \
proxy.c \
diff --git a/dlls/webservices/error.c b/dlls/webservices/error.c
new file mode 100644
index 0000000000..3173735345
--- /dev/null
+++ b/dlls/webservices/error.c
@@ -0,0 +1,234 @@
+/*
+ * Copyright 2015, 2016 Hans Leidekker for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "winnls.h"
+#include "webservices.h"
+
+#include "wine/debug.h"
+#include "wine/list.h"
+#include "webservices_private.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(webservices);
+
+static const struct prop_desc error_props[] =
+{
+ { sizeof(ULONG), TRUE }, /* WS_ERROR_PROPERTY_STRING_COUNT */
+ { sizeof(ULONG), FALSE }, /* WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE */
+ { sizeof(LANGID), FALSE } /* WS_ERROR_PROPERTY_LANGID */
+};
+
+struct error
+{
+ ULONG magic;
+ CRITICAL_SECTION cs;
+ ULONG prop_count;
+ struct prop prop[sizeof(error_props)/sizeof(error_props[0])];
+};
+
+#define ERROR_MAGIC (('E' << 24) | ('R' << 16) | ('R' << 8) | 'O')
+
+static struct error *alloc_error(void)
+{
+ static const ULONG count = sizeof(error_props)/sizeof(error_props[0]);
+ struct error *ret;
+ ULONG size = sizeof(*ret) + prop_size( error_props, count );
+
+ if (!(ret = heap_alloc_zero( size ))) return NULL;
+
+ ret->magic = ERROR_MAGIC;
+ InitializeCriticalSection( &ret->cs );
+ ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": error.cs");
+
+ prop_init( error_props, count, ret->prop, &ret[1] );
+ ret->prop_count = count;
+ return ret;
+}
+
+static void free_error( struct error *error )
+{
+ error->cs.DebugInfo->Spare[0] = 0;
+ DeleteCriticalSection( &error->cs );
+ heap_free( error );
+}
+
+/**************************************************************************
+ * WsCreateError [webservices.@]
+ */
+HRESULT WINAPI WsCreateError( const WS_ERROR_PROPERTY *properties, ULONG count, WS_ERROR **handle )
+{
+ struct error *error;
+ LANGID langid = GetUserDefaultUILanguage();
+ HRESULT hr;
+ ULONG i;
+
+ TRACE( "%p %u %p\n", properties, count, handle );
+
+ if (!handle) return E_INVALIDARG;
+ if (!(error = alloc_error())) return E_OUTOFMEMORY;
+
+ prop_set( error->prop, error->prop_count, WS_ERROR_PROPERTY_LANGID, &langid, sizeof(langid) );
+ for (i = 0; i < count; i++)
+ {
+ if (properties[i].id == WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE)
+ {
+ free_error( error );
+ return E_INVALIDARG;
+ }
+ hr = prop_set( error->prop, error->prop_count, properties[i].id, properties[i].value,
+ properties[i].valueSize );
+ if (hr != S_OK)
+ {
+ free_error( error );
+ return hr;
+ }
+ }
+
+ *handle = (WS_ERROR *)error;
+ return S_OK;
+}
+
+static void reset_error( struct error *error )
+{
+ ULONG code = 0;
+ /* FIXME: release strings added with WsAddErrorString when it's implemented, reset string count */
+ prop_set( error->prop, error->prop_count, WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE, &code, sizeof(code) );
+}
+
+/**************************************************************************
+ * WsFreeError [webservices.@]
+ */
+void WINAPI WsFreeError( WS_ERROR *handle )
+{
+ struct error *error = (struct error *)handle;
+
+ TRACE( "%p\n", handle );
+
+ if (!error) return;
+
+ EnterCriticalSection( &error->cs );
+
+ if (error->magic != ERROR_MAGIC)
+ {
+ LeaveCriticalSection( &error->cs );
+ return;
+ }
+
+ reset_error( error );
+ error->magic = 0;
+
+ LeaveCriticalSection( &error->cs );
+ free_error( error );
+}
+
+/**************************************************************************
+ * WsResetError [webservices.@]
+ */
+HRESULT WINAPI WsResetError( WS_ERROR *handle )
+{
+ struct error *error = (struct error *)handle;
+
+ TRACE( "%p\n", handle );
+
+ if (!error) return E_INVALIDARG;
+
+ EnterCriticalSection( &error->cs );
+
+ if (error->magic != ERROR_MAGIC)
+ {
+ LeaveCriticalSection( &error->cs );
+ return E_INVALIDARG;
+ }
+
+ reset_error( error );
+
+ LeaveCriticalSection( &error->cs );
+ return S_OK;
+}
+
+/**************************************************************************
+ * WsGetErrorProperty [webservices.@]
+ */
+HRESULT WINAPI WsGetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, void *buf,
+ ULONG size )
+{
+ struct error *error = (struct error *)handle;
+ HRESULT hr;
+
+ TRACE( "%p %u %p %u\n", handle, id, buf, size );
+
+ if (!error) return E_INVALIDARG;
+
+ EnterCriticalSection( &error->cs );
+
+ if (error->magic != ERROR_MAGIC)
+ {
+ LeaveCriticalSection( &error->cs );
+ return E_INVALIDARG;
+ }
+
+ hr = prop_get( error->prop, error->prop_count, id, buf, size );
+
+ LeaveCriticalSection( &error->cs );
+ return hr;
+}
+
+/**************************************************************************
+ * WsGetErrorString [webservices.@]
+ */
+HRESULT WINAPI WsGetErrorString( WS_ERROR *handle, ULONG index, WS_STRING *str )
+{
+ FIXME( "%p %u %p: stub\n", handle, index, str );
+ return E_NOTIMPL;
+}
+
+/**************************************************************************
+ * WsSetErrorProperty [webservices.@]
+ */
+HRESULT WINAPI WsSetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, const void *value,
+ ULONG size )
+{
+ struct error *error = (struct error *)handle;
+ HRESULT hr;
+
+ TRACE( "%p %u %p %u\n", handle, id, value, size );
+
+ if (!error) return E_INVALIDARG;
+
+ EnterCriticalSection( &error->cs );
+
+ if (error->magic != ERROR_MAGIC)
+ {
+ LeaveCriticalSection( &error->cs );
+ return E_INVALIDARG;
+ }
+
+ if (id == WS_ERROR_PROPERTY_LANGID)
+ {
+ LeaveCriticalSection( &error->cs );
+ return WS_E_INVALID_OPERATION;
+ }
+
+ hr = prop_set( error->prop, error->prop_count, id, value, size );
+
+ LeaveCriticalSection( &error->cs );
+ return hr;
+}
diff --git a/dlls/webservices/reader.c b/dlls/webservices/reader.c
index 26a5fe912d..07c645a1e2 100644
--- a/dlls/webservices/reader.c
+++ b/dlls/webservices/reader.c
@@ -70,210 +70,6 @@ HRESULT prop_get( const struct prop *prop, ULONG count, ULONG id, void *buf, ULO
return S_OK;
}
-static const struct prop_desc error_props[] =
-{
- { sizeof(ULONG), TRUE }, /* WS_ERROR_PROPERTY_STRING_COUNT */
- { sizeof(ULONG), FALSE }, /* WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE */
- { sizeof(LANGID), FALSE } /* WS_ERROR_PROPERTY_LANGID */
-};
-
-struct error
-{
- ULONG magic;
- CRITICAL_SECTION cs;
- ULONG prop_count;
- struct prop prop[sizeof(error_props)/sizeof(error_props[0])];
-};
-
-#define ERROR_MAGIC (('E' << 24) | ('R' << 16) | ('R' << 8) | 'O')
-
-static struct error *alloc_error(void)
-{
- static const ULONG count = sizeof(error_props)/sizeof(error_props[0]);
- struct error *ret;
- ULONG size = sizeof(*ret) + prop_size( error_props, count );
-
- if (!(ret = heap_alloc_zero( size ))) return NULL;
-
- ret->magic = ERROR_MAGIC;
- InitializeCriticalSection( &ret->cs );
- ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": error.cs");
-
- prop_init( error_props, count, ret->prop, &ret[1] );
- ret->prop_count = count;
- return ret;
-}
-
-static void free_error( struct error *error )
-{
- error->cs.DebugInfo->Spare[0] = 0;
- DeleteCriticalSection( &error->cs );
- heap_free( error );
-}
-
-/**************************************************************************
- * WsCreateError [webservices.@]
- */
-HRESULT WINAPI WsCreateError( const WS_ERROR_PROPERTY *properties, ULONG count, WS_ERROR **handle )
-{
- struct error *error;
- LANGID langid = GetUserDefaultUILanguage();
- HRESULT hr;
- ULONG i;
-
- TRACE( "%p %u %p\n", properties, count, handle );
-
- if (!handle) return E_INVALIDARG;
- if (!(error = alloc_error())) return E_OUTOFMEMORY;
-
- prop_set( error->prop, error->prop_count, WS_ERROR_PROPERTY_LANGID, &langid, sizeof(langid) );
- for (i = 0; i < count; i++)
- {
- if (properties[i].id == WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE)
- {
- free_error( error );
- return E_INVALIDARG;
- }
- hr = prop_set( error->prop, error->prop_count, properties[i].id, properties[i].value,
- properties[i].valueSize );
- if (hr != S_OK)
- {
- free_error( error );
- return hr;
- }
- }
-
- *handle = (WS_ERROR *)error;
- return S_OK;
-}
-
-static void reset_error( struct error *error )
-{
- ULONG code = 0;
- /* FIXME: release strings added with WsAddErrorString when it's implemented, reset string count */
- prop_set( error->prop, error->prop_count, WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE, &code, sizeof(code) );
-}
-
-/**************************************************************************
- * WsFreeError [webservices.@]
- */
-void WINAPI WsFreeError( WS_ERROR *handle )
-{
- struct error *error = (struct error *)handle;
-
- TRACE( "%p\n", handle );
-
- if (!error) return;
-
- EnterCriticalSection( &error->cs );
-
- if (error->magic != ERROR_MAGIC)
- {
- LeaveCriticalSection( &error->cs );
- return;
- }
-
- reset_error( error );
- error->magic = 0;
-
- LeaveCriticalSection( &error->cs );
- free_error( error );
-}
-
-/**************************************************************************
- * WsResetError [webservices.@]
- */
-HRESULT WINAPI WsResetError( WS_ERROR *handle )
-{
- struct error *error = (struct error *)handle;
-
- TRACE( "%p\n", handle );
-
- if (!error) return E_INVALIDARG;
-
- EnterCriticalSection( &error->cs );
-
- if (error->magic != ERROR_MAGIC)
- {
- LeaveCriticalSection( &error->cs );
- return E_INVALIDARG;
- }
-
- reset_error( error );
-
- LeaveCriticalSection( &error->cs );
- return S_OK;
-}
-
-/**************************************************************************
- * WsGetErrorProperty [webservices.@]
- */
-HRESULT WINAPI WsGetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, void *buf,
- ULONG size )
-{
- struct error *error = (struct error *)handle;
- HRESULT hr;
-
- TRACE( "%p %u %p %u\n", handle, id, buf, size );
-
- if (!error) return E_INVALIDARG;
-
- EnterCriticalSection( &error->cs );
-
- if (error->magic != ERROR_MAGIC)
- {
- LeaveCriticalSection( &error->cs );
- return E_INVALIDARG;
- }
-
- hr = prop_get( error->prop, error->prop_count, id, buf, size );
-
- LeaveCriticalSection( &error->cs );
- return hr;
-}
-
-/**************************************************************************
- * WsGetErrorString [webservices.@]
- */
-HRESULT WINAPI WsGetErrorString( WS_ERROR *handle, ULONG index, WS_STRING *str )
-{
- FIXME( "%p %u %p: stub\n", handle, index, str );
- return E_NOTIMPL;
-}
-
-/**************************************************************************
- * WsSetErrorProperty [webservices.@]
- */
-HRESULT WINAPI WsSetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, const void *value,
- ULONG size )
-{
- struct error *error = (struct error *)handle;
- HRESULT hr;
-
- TRACE( "%p %u %p %u\n", handle, id, value, size );
-
- if (!error) return E_INVALIDARG;
-
- EnterCriticalSection( &error->cs );
-
- if (error->magic != ERROR_MAGIC)
- {
- LeaveCriticalSection( &error->cs );
- return E_INVALIDARG;
- }
-
- if (id == WS_ERROR_PROPERTY_LANGID)
- {
- LeaveCriticalSection( &error->cs );
- return WS_E_INVALID_OPERATION;
- }
-
- hr = prop_set( error->prop, error->prop_count, id, value, size );
-
- LeaveCriticalSection( &error->cs );
- return hr;
-}
-
static const struct prop_desc heap_props[] =
{
{ sizeof(SIZE_T), FALSE }, /* WS_HEAP_PROPERTY_MAX_SIZE */
--
2.11.0
More information about the wine-patches
mailing list