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
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 */
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]);
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
;
67 static void free_error( struct error
*error
)
69 error
->cs
.DebugInfo
->Spare
[0] = 0;
70 DeleteCriticalSection( &error
->cs
);
74 /**************************************************************************
75 * WsCreateError [webservices.@]
77 HRESULT WINAPI
WsCreateError( const WS_ERROR_PROPERTY
*properties
, ULONG count
, WS_ERROR
**handle
)
80 LANGID langid
= GetUserDefaultUILanguage();
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
)
97 hr
= prop_set( error
->prop
, error
->prop_count
, properties
[i
].id
, properties
[i
].value
,
98 properties
[i
].valueSize
);
106 TRACE( "created %p\n", error
);
107 *handle
= (WS_ERROR
*)error
;
111 static void reset_error( struct error
*error
)
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
);
129 EnterCriticalSection( &error
->cs
);
131 if (error
->magic
!= ERROR_MAGIC
)
133 LeaveCriticalSection( &error
->cs
);
137 reset_error( error
);
140 LeaveCriticalSection( &error
->cs
);
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
);
163 reset_error( error
);
165 LeaveCriticalSection( &error
->cs
);
169 /**************************************************************************
170 * WsGetErrorProperty [webservices.@]
172 HRESULT WINAPI
WsGetErrorProperty( WS_ERROR
*handle
, WS_ERROR_PROPERTY_ID id
, void *buf
,
175 struct error
*error
= (struct error
*)handle
;
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
);
190 hr
= prop_get( error
->prop
, error
->prop_count
, id
, buf
, size
);
192 LeaveCriticalSection( &error
->cs
);
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
);
205 /**************************************************************************
206 * WsSetErrorProperty [webservices.@]
208 HRESULT WINAPI
WsSetErrorProperty( WS_ERROR
*handle
, WS_ERROR_PROPERTY_ID id
, const void *value
,
211 struct error
*error
= (struct error
*)handle
;
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
);
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
);