usp10: Fall back to 'dflt' language if shaping language tag isn't found.
[wine.git] / dlls / webservices / error.c
blob3173735345f1dcbfd77470e14e5b163ef4cb85fa
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/list.h"
28 #include "webservices_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(webservices);
32 static const struct prop_desc error_props[] =
34 { sizeof(ULONG), TRUE }, /* WS_ERROR_PROPERTY_STRING_COUNT */
35 { sizeof(ULONG), FALSE }, /* WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE */
36 { sizeof(LANGID), FALSE } /* WS_ERROR_PROPERTY_LANGID */
39 struct error
41 ULONG magic;
42 CRITICAL_SECTION cs;
43 ULONG prop_count;
44 struct prop prop[sizeof(error_props)/sizeof(error_props[0])];
47 #define ERROR_MAGIC (('E' << 24) | ('R' << 16) | ('R' << 8) | 'O')
49 static struct error *alloc_error(void)
51 static const ULONG count = sizeof(error_props)/sizeof(error_props[0]);
52 struct error *ret;
53 ULONG size = sizeof(*ret) + prop_size( error_props, count );
55 if (!(ret = heap_alloc_zero( size ))) return NULL;
57 ret->magic = ERROR_MAGIC;
58 InitializeCriticalSection( &ret->cs );
59 ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": error.cs");
61 prop_init( error_props, count, ret->prop, &ret[1] );
62 ret->prop_count = count;
63 return ret;
66 static void free_error( struct error *error )
68 error->cs.DebugInfo->Spare[0] = 0;
69 DeleteCriticalSection( &error->cs );
70 heap_free( error );
73 /**************************************************************************
74 * WsCreateError [webservices.@]
76 HRESULT WINAPI WsCreateError( const WS_ERROR_PROPERTY *properties, ULONG count, WS_ERROR **handle )
78 struct error *error;
79 LANGID langid = GetUserDefaultUILanguage();
80 HRESULT hr;
81 ULONG i;
83 TRACE( "%p %u %p\n", properties, count, handle );
85 if (!handle) return E_INVALIDARG;
86 if (!(error = alloc_error())) return E_OUTOFMEMORY;
88 prop_set( error->prop, error->prop_count, WS_ERROR_PROPERTY_LANGID, &langid, sizeof(langid) );
89 for (i = 0; i < count; i++)
91 if (properties[i].id == WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE)
93 free_error( error );
94 return E_INVALIDARG;
96 hr = prop_set( error->prop, error->prop_count, properties[i].id, properties[i].value,
97 properties[i].valueSize );
98 if (hr != S_OK)
100 free_error( error );
101 return hr;
105 *handle = (WS_ERROR *)error;
106 return S_OK;
109 static void reset_error( struct error *error )
111 ULONG code = 0;
112 /* FIXME: release strings added with WsAddErrorString when it's implemented, reset string count */
113 prop_set( error->prop, error->prop_count, WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE, &code, sizeof(code) );
116 /**************************************************************************
117 * WsFreeError [webservices.@]
119 void WINAPI WsFreeError( WS_ERROR *handle )
121 struct error *error = (struct error *)handle;
123 TRACE( "%p\n", handle );
125 if (!error) return;
127 EnterCriticalSection( &error->cs );
129 if (error->magic != ERROR_MAGIC)
131 LeaveCriticalSection( &error->cs );
132 return;
135 reset_error( error );
136 error->magic = 0;
138 LeaveCriticalSection( &error->cs );
139 free_error( error );
142 /**************************************************************************
143 * WsResetError [webservices.@]
145 HRESULT WINAPI WsResetError( WS_ERROR *handle )
147 struct error *error = (struct error *)handle;
149 TRACE( "%p\n", handle );
151 if (!error) return E_INVALIDARG;
153 EnterCriticalSection( &error->cs );
155 if (error->magic != ERROR_MAGIC)
157 LeaveCriticalSection( &error->cs );
158 return E_INVALIDARG;
161 reset_error( error );
163 LeaveCriticalSection( &error->cs );
164 return S_OK;
167 /**************************************************************************
168 * WsGetErrorProperty [webservices.@]
170 HRESULT WINAPI WsGetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, void *buf,
171 ULONG size )
173 struct error *error = (struct error *)handle;
174 HRESULT hr;
176 TRACE( "%p %u %p %u\n", handle, id, buf, size );
178 if (!error) return E_INVALIDARG;
180 EnterCriticalSection( &error->cs );
182 if (error->magic != ERROR_MAGIC)
184 LeaveCriticalSection( &error->cs );
185 return E_INVALIDARG;
188 hr = prop_get( error->prop, error->prop_count, id, buf, size );
190 LeaveCriticalSection( &error->cs );
191 return hr;
194 /**************************************************************************
195 * WsGetErrorString [webservices.@]
197 HRESULT WINAPI WsGetErrorString( WS_ERROR *handle, ULONG index, WS_STRING *str )
199 FIXME( "%p %u %p: stub\n", handle, index, str );
200 return E_NOTIMPL;
203 /**************************************************************************
204 * WsSetErrorProperty [webservices.@]
206 HRESULT WINAPI WsSetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, const void *value,
207 ULONG size )
209 struct error *error = (struct error *)handle;
210 HRESULT hr;
212 TRACE( "%p %u %p %u\n", handle, id, value, size );
214 if (!error) return E_INVALIDARG;
216 EnterCriticalSection( &error->cs );
218 if (error->magic != ERROR_MAGIC)
220 LeaveCriticalSection( &error->cs );
221 return E_INVALIDARG;
224 if (id == WS_ERROR_PROPERTY_LANGID)
226 LeaveCriticalSection( &error->cs );
227 return WS_E_INVALID_OPERATION;
230 hr = prop_set( error->prop, error->prop_count, id, value, size );
232 LeaveCriticalSection( &error->cs );
233 return hr;