mshtml: Wine Gecko 1.4 release.
[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 #ifdef HAVE_LIBXML2
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
30 #endif
31
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winerror.h"
35 #include "winuser.h"
36 #include "ole2.h"
37 #include "msxml6.h"
38
39 #include "msxml_private.h"
40
41 #include "wine/debug.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
44
45 typedef struct
46 {
47     DispatchEx dispex;
48     IXMLDOMParseError IXMLDOMParseError_iface;
49     LONG ref;
50     LONG code, line, linepos, filepos;
51     BSTR url, reason, srcText;
52 } parse_error_t;
53
54 static inline parse_error_t *impl_from_IXMLDOMParseError( IXMLDOMParseError *iface )
55 {
56     return CONTAINING_RECORD(iface, parse_error_t, IXMLDOMParseError_iface);
57 }
58
59 static HRESULT WINAPI parseError_QueryInterface(
60     IXMLDOMParseError *iface,
61     REFIID riid,
62     void** ppvObject )
63 {
64     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
65
66     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
67
68     if ( IsEqualGUID( riid, &IID_IUnknown ) ||
69          IsEqualGUID( riid, &IID_IDispatch ) ||
70          IsEqualGUID( riid, &IID_IXMLDOMParseError ) )
71     {
72         *ppvObject = iface;
73     }
74     else if (dispex_query_interface(&This->dispex, riid, ppvObject))
75     {
76         return *ppvObject ? S_OK : E_NOINTERFACE;
77     }
78     else
79     {
80         FIXME("interface %s not implemented\n", debugstr_guid(riid));
81         *ppvObject = NULL;
82         return E_NOINTERFACE;
83     }
84
85     IXMLDOMParseError_AddRef( iface );
86
87     return S_OK;
88 }
89
90 static ULONG WINAPI parseError_AddRef(
91     IXMLDOMParseError *iface )
92 {
93     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
94     ULONG ref = InterlockedIncrement( &This->ref );
95     TRACE("(%p)->(%d)\n", This, ref);
96     return ref;
97 }
98
99 static ULONG WINAPI parseError_Release(
100     IXMLDOMParseError *iface )
101 {
102     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
103     ULONG ref = InterlockedDecrement( &This->ref );
104
105     TRACE("(%p)->(%d)\n", This, ref);
106     if ( ref == 0 )
107     {
108         SysFreeString(This->url);
109         SysFreeString(This->reason);
110         SysFreeString(This->srcText);
111         release_dispex(&This->dispex);
112         heap_free( This );
113     }
114
115     return ref;
116 }
117
118 static HRESULT WINAPI parseError_GetTypeInfoCount(
119     IXMLDOMParseError *iface,
120     UINT* pctinfo )
121 {
122     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
123
124     TRACE("(%p)->(%p)\n", This, pctinfo);
125
126     *pctinfo = 1;
127
128     return S_OK;
129 }
130
131 static HRESULT WINAPI parseError_GetTypeInfo(
132     IXMLDOMParseError *iface,
133     UINT iTInfo,
134     LCID lcid,
135     ITypeInfo** ppTInfo )
136 {
137     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
138
139     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
140
141     return get_typeinfo(IXMLDOMParseError_tid, ppTInfo);
142 }
143
144 static HRESULT WINAPI parseError_GetIDsOfNames(
145     IXMLDOMParseError *iface,
146     REFIID riid,
147     LPOLESTR* rgszNames,
148     UINT cNames,
149     LCID lcid,
150     DISPID* rgDispId )
151 {
152     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
153     ITypeInfo *typeinfo;
154     HRESULT hr;
155
156     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
157           lcid, rgDispId);
158
159     if(!rgszNames || cNames == 0 || !rgDispId)
160         return E_INVALIDARG;
161
162     hr = get_typeinfo(IXMLDOMParseError_tid, &typeinfo);
163     if(SUCCEEDED(hr))
164     {
165         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
166         ITypeInfo_Release(typeinfo);
167     }
168
169     return hr;
170 }
171
172 static HRESULT WINAPI parseError_Invoke(
173     IXMLDOMParseError *iface,
174     DISPID dispIdMember,
175     REFIID riid,
176     LCID lcid,
177     WORD wFlags,
178     DISPPARAMS* pDispParams,
179     VARIANT* pVarResult,
180     EXCEPINFO* pExcepInfo,
181     UINT* puArgErr )
182 {
183     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
184     ITypeInfo *typeinfo;
185     HRESULT hr;
186
187     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
188           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
189
190     hr = get_typeinfo(IXMLDOMParseError_tid, &typeinfo);
191     if(SUCCEEDED(hr))
192     {
193         hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMParseError_iface, dispIdMember, wFlags,
194                 pDispParams, pVarResult, pExcepInfo, puArgErr);
195         ITypeInfo_Release(typeinfo);
196     }
197
198     return hr;
199 }
200
201 static HRESULT WINAPI parseError_get_errorCode(
202     IXMLDOMParseError *iface,
203     LONG *code )
204 {
205     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
206     TRACE("(%p)->(%p)\n", This, code);
207
208     *code = This->code;
209
210     if(This->code == 0)
211         return S_FALSE;
212
213     return S_OK;
214 }
215
216 static HRESULT WINAPI parseError_get_url(
217     IXMLDOMParseError *iface,
218     BSTR *url )
219 {
220     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
221     FIXME("(%p)->(%p)\n", This, url);
222     return E_NOTIMPL;
223 }
224
225 static HRESULT WINAPI parseError_get_reason(
226     IXMLDOMParseError *iface,
227     BSTR *reason )
228 {
229     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
230     TRACE("(%p)->(%p)\n", This, reason);
231     
232     if(!This->reason)
233     {
234         *reason = NULL;
235         return S_FALSE;
236     }
237     *reason = SysAllocString(This->reason);
238     return S_OK;
239 }
240
241 static HRESULT WINAPI parseError_get_srcText(
242     IXMLDOMParseError *iface,
243     BSTR *srcText )
244 {
245     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
246
247     TRACE("(%p)->(%p)\n", This, srcText);
248
249     if (!srcText) return E_INVALIDARG;
250
251     *srcText = SysAllocString(This->srcText);
252
253     return S_OK;
254 }
255
256 static HRESULT WINAPI parseError_get_line(
257     IXMLDOMParseError *iface,
258     LONG *line )
259 {
260     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
261
262     TRACE("(%p)->(%p): stub\n", This, line);
263
264     if (!line) return E_INVALIDARG;
265
266     *line = This->line;
267     return S_OK;
268 }
269
270 static HRESULT WINAPI parseError_get_linepos(
271     IXMLDOMParseError *iface,
272     LONG *linepos )
273 {
274     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
275
276     TRACE("(%p)->(%p)\n", This, linepos);
277
278     if (!linepos) return E_INVALIDARG;
279
280     *linepos = This->linepos;
281     return S_OK;
282 }
283
284 static HRESULT WINAPI parseError_get_filepos(
285     IXMLDOMParseError *iface,
286     LONG *filepos )
287 {
288     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
289     FIXME("(%p)->(%p)\n", This, filepos);
290     return E_NOTIMPL;
291 }
292
293 static const struct IXMLDOMParseErrorVtbl parseError_vtbl =
294 {
295     parseError_QueryInterface,
296     parseError_AddRef,
297     parseError_Release,
298     parseError_GetTypeInfoCount,
299     parseError_GetTypeInfo,
300     parseError_GetIDsOfNames,
301     parseError_Invoke,
302     parseError_get_errorCode,
303     parseError_get_url,
304     parseError_get_reason,
305     parseError_get_srcText,
306     parseError_get_line,
307     parseError_get_linepos,
308     parseError_get_filepos
309 };
310
311 static const tid_t parseError_iface_tids[] = {
312     IXMLDOMParseError_tid,
313     0
314 };
315
316 static dispex_static_data_t parseError_dispex = {
317     NULL,
318     IXMLDOMParseError_tid,
319     NULL,
320     parseError_iface_tids
321 };
322
323 IXMLDOMParseError *create_parseError( LONG code, BSTR url, BSTR reason, BSTR srcText,
324                                       LONG line, LONG linepos, LONG filepos )
325 {
326     parse_error_t *This;
327
328     This = heap_alloc( sizeof(*This) );
329     if ( !This )
330         return NULL;
331
332     This->IXMLDOMParseError_iface.lpVtbl = &parseError_vtbl;
333     This->ref = 1;
334
335     This->code = code;
336     This->url = url;
337     This->reason = reason;
338     This->srcText = srcText;
339     This->line = line;
340     This->linepos = linepos;
341     This->filepos = filepos;
342
343     init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMParseError_iface, &parseError_dispex);
344
345     return &This->IXMLDOMParseError_iface;
346 }