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/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 */
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]);
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
;
66 static void free_error( struct error
*error
)
68 error
->cs
.DebugInfo
->Spare
[0] = 0;
69 DeleteCriticalSection( &error
->cs
);
73 /**************************************************************************
74 * WsCreateError [webservices.@]
76 HRESULT WINAPI
WsCreateError( const WS_ERROR_PROPERTY
*properties
, ULONG count
, WS_ERROR
**handle
)
79 LANGID langid
= GetUserDefaultUILanguage();
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
)
96 hr
= prop_set( error
->prop
, error
->prop_count
, properties
[i
].id
, properties
[i
].value
,
97 properties
[i
].valueSize
);
105 *handle
= (WS_ERROR
*)error
;
109 static void reset_error( struct error
*error
)
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
);
127 EnterCriticalSection( &error
->cs
);
129 if (error
->magic
!= ERROR_MAGIC
)
131 LeaveCriticalSection( &error
->cs
);
135 reset_error( error
);
138 LeaveCriticalSection( &error
->cs
);
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
);
161 reset_error( error
);
163 LeaveCriticalSection( &error
->cs
);
167 /**************************************************************************
168 * WsGetErrorProperty [webservices.@]
170 HRESULT WINAPI
WsGetErrorProperty( WS_ERROR
*handle
, WS_ERROR_PROPERTY_ID id
, void *buf
,
173 struct error
*error
= (struct error
*)handle
;
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
);
188 hr
= prop_get( error
->prop
, error
->prop_count
, id
, buf
, size
);
190 LeaveCriticalSection( &error
->cs
);
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
);
203 /**************************************************************************
204 * WsSetErrorProperty [webservices.@]
206 HRESULT WINAPI
WsSetErrorProperty( WS_ERROR
*handle
, WS_ERROR_PROPERTY_ID id
, const void *value
,
209 struct error
*error
= (struct error
*)handle
;
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
);
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
);