msxml3/tests: Avoid a crash that happens on some native systems.
[wine] / dlls / msxml3 / parseerror.c
1 /*
2  *    ParseError implementation
3  *
4  * Copyright 2005 Huw Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21
22 #define COBJMACROS
23
24 #include "config.h"
25
26 #include <stdarg.h>
27 #include <assert.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winerror.h"
31 #include "winuser.h"
32 #include "ole2.h"
33 #include "msxml2.h"
34
35 #include "msxml_private.h"
36
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
40
41 typedef struct
42 {
43     const struct IXMLDOMParseErrorVtbl *lpVtbl;
44     LONG ref;
45     LONG code, line, linepos, filepos;
46     BSTR url, reason, srcText;
47 } parse_error_t;
48
49 static inline parse_error_t *impl_from_IXMLDOMParseError( IXMLDOMParseError *iface )
50 {
51     return (parse_error_t *)((char*)iface - FIELD_OFFSET(parse_error_t, lpVtbl));
52 }
53
54 static HRESULT WINAPI parseError_QueryInterface(
55     IXMLDOMParseError *iface,
56     REFIID riid,
57     void** ppvObject )
58 {
59     TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
60
61     if ( IsEqualGUID( riid, &IID_IUnknown ) ||
62          IsEqualGUID( riid, &IID_IDispatch ) ||
63          IsEqualGUID( riid, &IID_IXMLDOMParseError ) )
64     {
65         *ppvObject = iface;
66     }
67     else
68     {
69         FIXME("interface %s not implemented\n", debugstr_guid(riid));
70         return E_NOINTERFACE;
71     }
72
73     IXMLDOMParseError_AddRef( iface );
74
75     return S_OK;
76 }
77
78 static ULONG WINAPI parseError_AddRef(
79     IXMLDOMParseError *iface )
80 {
81     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
82     ULONG ref = InterlockedIncrement( &This->ref );
83     TRACE("(%p) ref now %d\n", This, ref);
84     return ref;
85 }
86
87 static ULONG WINAPI parseError_Release(
88     IXMLDOMParseError *iface )
89 {
90     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
91     ULONG ref;
92
93     ref = InterlockedDecrement( &This->ref );
94     TRACE("(%p) ref now %d\n", This, ref);
95     if ( ref == 0 )
96     {
97         SysFreeString(This->url);
98         SysFreeString(This->reason);
99         SysFreeString(This->srcText);
100         HeapFree( GetProcessHeap(), 0, This );
101     }
102
103     return ref;
104 }
105
106 static HRESULT WINAPI parseError_GetTypeInfoCount(
107     IXMLDOMParseError *iface,
108     UINT* pctinfo )
109 {
110     FIXME("\n");
111     return E_NOTIMPL;
112 }
113
114 static HRESULT WINAPI parseError_GetTypeInfo(
115     IXMLDOMParseError *iface,
116     UINT iTInfo,
117     LCID lcid,
118     ITypeInfo** ppTInfo )
119 {
120     FIXME("\n");
121     return E_NOTIMPL;
122 }
123
124 static HRESULT WINAPI parseError_GetIDsOfNames(
125     IXMLDOMParseError *iface,
126     REFIID riid,
127     LPOLESTR* rgszNames,
128     UINT cNames,
129     LCID lcid,
130     DISPID* rgDispId )
131 {
132     FIXME("\n");
133     return E_NOTIMPL;
134 }
135
136 static HRESULT WINAPI parseError_Invoke(
137     IXMLDOMParseError *iface,
138     DISPID dispIdMember,
139     REFIID riid,
140     LCID lcid,
141     WORD wFlags,
142     DISPPARAMS* pDispParams,
143     VARIANT* pVarResult,
144     EXCEPINFO* pExcepInfo,
145     UINT* puArgErr )
146 {
147     FIXME("\n");
148     return E_NOTIMPL;
149 }
150
151 static HRESULT WINAPI parseError_get_errorCode(
152     IXMLDOMParseError *iface,
153     long *code )
154 {
155     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
156     TRACE("(%p)->(%p)\n", This, code);
157
158     *code = This->code;
159
160     if(This->code == 0)
161         return S_FALSE;
162
163     return S_OK;
164 }
165
166 static HRESULT WINAPI parseError_get_url(
167     IXMLDOMParseError *iface,
168     BSTR *url )
169 {
170     FIXME("\n");
171     return E_NOTIMPL;
172 }
173
174 static HRESULT WINAPI parseError_get_reason(
175     IXMLDOMParseError *iface,
176     BSTR *reason )
177 {
178     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
179     TRACE("(%p)->(%p)\n", This, reason);
180     
181     if(!This->reason)
182     {
183         *reason = NULL;
184         return S_FALSE;
185     }
186     *reason = SysAllocString(This->reason);
187     return S_OK;
188 }
189
190 static HRESULT WINAPI parseError_get_srcText(
191     IXMLDOMParseError *iface,
192     BSTR *srcText )
193 {
194     FIXME("\n");
195     return E_NOTIMPL;
196 }
197
198 static HRESULT WINAPI parseError_get_line(
199     IXMLDOMParseError *iface,
200     long *line )
201 {
202     FIXME("\n");
203     return E_NOTIMPL;
204 }
205
206 static HRESULT WINAPI parseError_get_linepos(
207     IXMLDOMParseError *iface,
208     long *linepos )
209 {
210     FIXME("\n");
211     return E_NOTIMPL;
212 }
213
214 static HRESULT WINAPI parseError_get_filepos(
215     IXMLDOMParseError *iface,
216     long *filepos )
217 {
218     FIXME("\n");
219     return E_NOTIMPL;
220 }
221
222 static const struct IXMLDOMParseErrorVtbl parseError_vtbl =
223 {
224     parseError_QueryInterface,
225     parseError_AddRef,
226     parseError_Release,
227     parseError_GetTypeInfoCount,
228     parseError_GetTypeInfo,
229     parseError_GetIDsOfNames,
230     parseError_Invoke,
231     parseError_get_errorCode,
232     parseError_get_url,
233     parseError_get_reason,
234     parseError_get_srcText,
235     parseError_get_line,
236     parseError_get_linepos,
237     parseError_get_filepos
238 };
239
240 IXMLDOMParseError *create_parseError( LONG code, BSTR url, BSTR reason, BSTR srcText,
241                                       LONG line, LONG linepos, LONG filepos )
242 {
243     parse_error_t *This;
244
245     This = HeapAlloc( GetProcessHeap(), 0, sizeof(*This) );
246     if ( !This )
247         return NULL;
248
249     This->lpVtbl = &parseError_vtbl;
250     This->ref = 1;
251
252     This->code = code;
253     This->url = url;
254     This->reason = reason;
255     This->srcText = srcText;
256     This->line = line;
257     This->linepos = linepos;
258     This->filepos = filepos;
259
260     return (IXMLDOMParseError*) &This->lpVtbl;
261 }