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
[ARRAY_SIZE( error_props
)];
48 #define ERROR_MAGIC (('E' << 24) | ('R' << 16) | ('R' << 8) | 'O')
50 static struct error
*alloc_error(void)
52 static const ULONG count
= ARRAY_SIZE( error_props
);
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
;
152 TRACE( "%p\n", handle
);
154 if (!error
) return E_INVALIDARG
;
156 EnterCriticalSection( &error
->cs
);
158 if (error
->magic
!= ERROR_MAGIC
)
160 LeaveCriticalSection( &error
->cs
);
164 reset_error( error
);
166 LeaveCriticalSection( &error
->cs
);
167 TRACE( "returning %08x\n", hr
);
171 /**************************************************************************
172 * WsGetErrorProperty [webservices.@]
174 HRESULT WINAPI
WsGetErrorProperty( WS_ERROR
*handle
, WS_ERROR_PROPERTY_ID id
, void *buf
,
177 struct error
*error
= (struct error
*)handle
;
180 TRACE( "%p %u %p %u\n", handle
, id
, buf
, size
);
182 if (!error
) return E_INVALIDARG
;
184 EnterCriticalSection( &error
->cs
);
186 if (error
->magic
!= ERROR_MAGIC
)
188 LeaveCriticalSection( &error
->cs
);
192 hr
= prop_get( error
->prop
, error
->prop_count
, id
, buf
, size
);
194 LeaveCriticalSection( &error
->cs
);
195 TRACE( "returning %08x\n", hr
);
199 /**************************************************************************
200 * WsGetErrorString [webservices.@]
202 HRESULT WINAPI
WsGetErrorString( WS_ERROR
*handle
, ULONG index
, WS_STRING
*str
)
204 FIXME( "%p %u %p: stub\n", handle
, index
, str
);
208 /**************************************************************************
209 * WsSetErrorProperty [webservices.@]
211 HRESULT WINAPI
WsSetErrorProperty( WS_ERROR
*handle
, WS_ERROR_PROPERTY_ID id
, const void *value
,
214 struct error
*error
= (struct error
*)handle
;
217 TRACE( "%p %u %p %u\n", handle
, id
, value
, size
);
219 if (!error
) return E_INVALIDARG
;
221 EnterCriticalSection( &error
->cs
);
223 if (error
->magic
!= ERROR_MAGIC
)
225 LeaveCriticalSection( &error
->cs
);
229 if (id
== WS_ERROR_PROPERTY_LANGID
) hr
= WS_E_INVALID_OPERATION
;
230 else hr
= prop_set( error
->prop
, error
->prop_count
, id
, value
, size
);
232 LeaveCriticalSection( &error
->cs
);
233 TRACE( "returning %08x\n", hr
);