wined3d: Use wined3d_texture_get_sub_resource_target() in wined3d_surface_upload_data().
[wine.git] / dlls / webservices / error.c
blobe4292db5bfa502db3cf91390a8461f20db8ec7b1
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[sizeof(error_props)/sizeof(error_props[0])];
48 #define ERROR_MAGIC (('E' << 24) | ('R' << 16) | ('R' << 8) | 'O')
50 static struct error *alloc_error(void)
52 static const ULONG count = sizeof(error_props)/sizeof(error_props[0]);
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;
151 TRACE( "%p\n", handle );
153 if (!error) return E_INVALIDARG;
155 EnterCriticalSection( &error->cs );
157 if (error->magic != ERROR_MAGIC)
159 LeaveCriticalSection( &error->cs );
160 return E_INVALIDARG;
163 reset_error( error );
165 LeaveCriticalSection( &error->cs );
166 return S_OK;
169 /**************************************************************************
170 * WsGetErrorProperty [webservices.@]
172 HRESULT WINAPI WsGetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, void *buf,
173 ULONG size )
175 struct error *error = (struct error *)handle;
176 HRESULT hr;
178 TRACE( "%p %u %p %u\n", handle, id, buf, size );
180 if (!error) return E_INVALIDARG;
182 EnterCriticalSection( &error->cs );
184 if (error->magic != ERROR_MAGIC)
186 LeaveCriticalSection( &error->cs );
187 return E_INVALIDARG;
190 hr = prop_get( error->prop, error->prop_count, id, buf, size );
192 LeaveCriticalSection( &error->cs );
193 return hr;
196 /**************************************************************************
197 * WsGetErrorString [webservices.@]
199 HRESULT WINAPI WsGetErrorString( WS_ERROR *handle, ULONG index, WS_STRING *str )
201 FIXME( "%p %u %p: stub\n", handle, index, str );
202 return E_NOTIMPL;
205 /**************************************************************************
206 * WsSetErrorProperty [webservices.@]
208 HRESULT WINAPI WsSetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, const void *value,
209 ULONG size )
211 struct error *error = (struct error *)handle;
212 HRESULT hr;
214 TRACE( "%p %u %p %u\n", handle, id, value, size );
216 if (!error) return E_INVALIDARG;
218 EnterCriticalSection( &error->cs );
220 if (error->magic != ERROR_MAGIC)
222 LeaveCriticalSection( &error->cs );
223 return E_INVALIDARG;
226 if (id == WS_ERROR_PROPERTY_LANGID)
228 LeaveCriticalSection( &error->cs );
229 return WS_E_INVALID_OPERATION;
232 hr = prop_set( error->prop, error->prop_count, id, value, size );
234 LeaveCriticalSection( &error->cs );
235 return hr;