mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / webservices / error.c
blob34135851ecc2a5dd1c1d84388f02ab1ee57322c4
1 /*
2 * Copyright 2015, 2016 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winnls.h"
24 #include "webservices.h"
26 #include "wine/debug.h"
27 #include "wine/heap.h"
28 #include "wine/list.h"
29 #include "webservices_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(webservices);
33 static const struct prop_desc error_props[] =
35 { sizeof(ULONG), TRUE }, /* WS_ERROR_PROPERTY_STRING_COUNT */
36 { sizeof(ULONG), FALSE }, /* WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE */
37 { sizeof(LANGID), FALSE } /* WS_ERROR_PROPERTY_LANGID */
40 struct error
42 ULONG magic;
43 CRITICAL_SECTION cs;
44 ULONG prop_count;
45 struct prop prop[ARRAY_SIZE( error_props )];
48 #define ERROR_MAGIC (('E' << 24) | ('R' << 16) | ('R' << 8) | 'O')
50 static struct error *alloc_error(void)
52 static const ULONG count = ARRAY_SIZE( error_props );
53 struct error *ret;
54 ULONG size = sizeof(*ret) + prop_size( error_props, count );
56 if (!(ret = heap_alloc_zero( size ))) return NULL;
58 ret->magic = ERROR_MAGIC;
59 InitializeCriticalSection( &ret->cs );
60 ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": error.cs");
62 prop_init( error_props, count, ret->prop, &ret[1] );
63 ret->prop_count = count;
64 return ret;
67 static void free_error( struct error *error )
69 error->cs.DebugInfo->Spare[0] = 0;
70 DeleteCriticalSection( &error->cs );
71 heap_free( error );
74 /**************************************************************************
75 * WsCreateError [webservices.@]
77 HRESULT WINAPI WsCreateError( const WS_ERROR_PROPERTY *properties, ULONG count, WS_ERROR **handle )
79 struct error *error;
80 LANGID langid = GetUserDefaultUILanguage();
81 HRESULT hr;
82 ULONG i;
84 TRACE( "%p %u %p\n", properties, count, handle );
86 if (!handle) return E_INVALIDARG;
87 if (!(error = alloc_error())) return E_OUTOFMEMORY;
89 prop_set( error->prop, error->prop_count, WS_ERROR_PROPERTY_LANGID, &langid, sizeof(langid) );
90 for (i = 0; i < count; i++)
92 if (properties[i].id == WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE)
94 free_error( error );
95 return E_INVALIDARG;
97 hr = prop_set( error->prop, error->prop_count, properties[i].id, properties[i].value,
98 properties[i].valueSize );
99 if (hr != S_OK)
101 free_error( error );
102 return hr;
106 TRACE( "created %p\n", error );
107 *handle = (WS_ERROR *)error;
108 return S_OK;
111 static void reset_error( struct error *error )
113 ULONG code = 0;
114 /* FIXME: release strings added with WsAddErrorString when it's implemented, reset string count */
115 prop_set( error->prop, error->prop_count, WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE, &code, sizeof(code) );
118 /**************************************************************************
119 * WsFreeError [webservices.@]
121 void WINAPI WsFreeError( WS_ERROR *handle )
123 struct error *error = (struct error *)handle;
125 TRACE( "%p\n", handle );
127 if (!error) return;
129 EnterCriticalSection( &error->cs );
131 if (error->magic != ERROR_MAGIC)
133 LeaveCriticalSection( &error->cs );
134 return;
137 reset_error( error );
138 error->magic = 0;
140 LeaveCriticalSection( &error->cs );
141 free_error( error );
144 /**************************************************************************
145 * WsResetError [webservices.@]
147 HRESULT WINAPI WsResetError( WS_ERROR *handle )
149 struct error *error = (struct error *)handle;
150 HRESULT hr = S_OK;
152 TRACE( "%p\n", handle );
154 if (!error) return E_INVALIDARG;
156 EnterCriticalSection( &error->cs );
158 if (error->magic != ERROR_MAGIC)
160 LeaveCriticalSection( &error->cs );
161 return E_INVALIDARG;
164 reset_error( error );
166 LeaveCriticalSection( &error->cs );
167 TRACE( "returning %08x\n", hr );
168 return hr;
171 /**************************************************************************
172 * WsGetErrorProperty [webservices.@]
174 HRESULT WINAPI WsGetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, void *buf,
175 ULONG size )
177 struct error *error = (struct error *)handle;
178 HRESULT hr;
180 TRACE( "%p %u %p %u\n", handle, id, buf, size );
182 if (!error) return E_INVALIDARG;
184 EnterCriticalSection( &error->cs );
186 if (error->magic != ERROR_MAGIC)
188 LeaveCriticalSection( &error->cs );
189 return E_INVALIDARG;
192 hr = prop_get( error->prop, error->prop_count, id, buf, size );
194 LeaveCriticalSection( &error->cs );
195 TRACE( "returning %08x\n", hr );
196 return hr;
199 /**************************************************************************
200 * WsGetErrorString [webservices.@]
202 HRESULT WINAPI WsGetErrorString( WS_ERROR *handle, ULONG index, WS_STRING *str )
204 FIXME( "%p %u %p: stub\n", handle, index, str );
205 return E_NOTIMPL;
208 /**************************************************************************
209 * WsSetErrorProperty [webservices.@]
211 HRESULT WINAPI WsSetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, const void *value,
212 ULONG size )
214 struct error *error = (struct error *)handle;
215 HRESULT hr;
217 TRACE( "%p %u %p %u\n", handle, id, value, size );
219 if (!error) return E_INVALIDARG;
221 EnterCriticalSection( &error->cs );
223 if (error->magic != ERROR_MAGIC)
225 LeaveCriticalSection( &error->cs );
226 return E_INVALIDARG;
229 if (id == WS_ERROR_PROPERTY_LANGID) hr = WS_E_INVALID_OPERATION;
230 else hr = prop_set( error->prop, error->prop_count, id, value, size );
232 LeaveCriticalSection( &error->cs );
233 TRACE( "returning %08x\n", hr );
234 return hr;