mmsystem.dll16: Pass through MCI_LIST, MCI_SETAUDIO, and MCI_SETVIDEO.
[wine.git] / dlls / webservices / error.c
blob747af2a3f97ce0da692833f6c8c19191dbed6082
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 TRACE( "created %p\n", error );
106 *handle = (WS_ERROR *)error;
107 return S_OK;
110 static void reset_error( struct error *error )
112 ULONG code = 0;
113 /* FIXME: release strings added with WsAddErrorString when it's implemented, reset string count */
114 prop_set( error->prop, error->prop_count, WS_ERROR_PROPERTY_ORIGINAL_ERROR_CODE, &code, sizeof(code) );
117 /**************************************************************************
118 * WsFreeError [webservices.@]
120 void WINAPI WsFreeError( WS_ERROR *handle )
122 struct error *error = (struct error *)handle;
124 TRACE( "%p\n", handle );
126 if (!error) return;
128 EnterCriticalSection( &error->cs );
130 if (error->magic != ERROR_MAGIC)
132 LeaveCriticalSection( &error->cs );
133 return;
136 reset_error( error );
137 error->magic = 0;
139 LeaveCriticalSection( &error->cs );
140 free_error( error );
143 /**************************************************************************
144 * WsResetError [webservices.@]
146 HRESULT WINAPI WsResetError( WS_ERROR *handle )
148 struct error *error = (struct error *)handle;
150 TRACE( "%p\n", handle );
152 if (!error) return E_INVALIDARG;
154 EnterCriticalSection( &error->cs );
156 if (error->magic != ERROR_MAGIC)
158 LeaveCriticalSection( &error->cs );
159 return E_INVALIDARG;
162 reset_error( error );
164 LeaveCriticalSection( &error->cs );
165 return S_OK;
168 /**************************************************************************
169 * WsGetErrorProperty [webservices.@]
171 HRESULT WINAPI WsGetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, void *buf,
172 ULONG size )
174 struct error *error = (struct error *)handle;
175 HRESULT hr;
177 TRACE( "%p %u %p %u\n", handle, id, buf, size );
179 if (!error) return E_INVALIDARG;
181 EnterCriticalSection( &error->cs );
183 if (error->magic != ERROR_MAGIC)
185 LeaveCriticalSection( &error->cs );
186 return E_INVALIDARG;
189 hr = prop_get( error->prop, error->prop_count, id, buf, size );
191 LeaveCriticalSection( &error->cs );
192 return hr;
195 /**************************************************************************
196 * WsGetErrorString [webservices.@]
198 HRESULT WINAPI WsGetErrorString( WS_ERROR *handle, ULONG index, WS_STRING *str )
200 FIXME( "%p %u %p: stub\n", handle, index, str );
201 return E_NOTIMPL;
204 /**************************************************************************
205 * WsSetErrorProperty [webservices.@]
207 HRESULT WINAPI WsSetErrorProperty( WS_ERROR *handle, WS_ERROR_PROPERTY_ID id, const void *value,
208 ULONG size )
210 struct error *error = (struct error *)handle;
211 HRESULT hr;
213 TRACE( "%p %u %p %u\n", handle, id, value, size );
215 if (!error) return E_INVALIDARG;
217 EnterCriticalSection( &error->cs );
219 if (error->magic != ERROR_MAGIC)
221 LeaveCriticalSection( &error->cs );
222 return E_INVALIDARG;
225 if (id == WS_ERROR_PROPERTY_LANGID)
227 LeaveCriticalSection( &error->cs );
228 return WS_E_INVALID_OPERATION;
231 hr = prop_set( error->prop, error->prop_count, id, value, size );
233 LeaveCriticalSection( &error->cs );
234 return hr;