Update the address of the Free Software Foundation.
[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 <stdarg.h>
25 #include <assert.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winerror.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "msxml2.h"
32
33 #include "msxml_private.h"
34
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
38
39 typedef struct
40 {
41     const struct IXMLDOMParseErrorVtbl *lpVtbl;
42     LONG ref;
43     LONG code, line, linepos, filepos;
44     BSTR url, reason, srcText;
45 } parse_error_t;
46
47 static inline parse_error_t *impl_from_IXMLDOMParseError( IXMLDOMParseError *iface )
48 {
49     return (parse_error_t *)((char*)iface - FIELD_OFFSET(parse_error_t, lpVtbl));
50 }
51
52 static HRESULT WINAPI parseError_QueryInterface(
53     IXMLDOMParseError *iface,
54     REFIID riid,
55     void** ppvObject )
56 {
57     TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
58
59     if ( IsEqualGUID( riid, &IID_IUnknown ) ||
60          IsEqualGUID( riid, &IID_IDispatch ) ||
61          IsEqualGUID( riid, &IID_IXMLDOMParseError ) )
62     {
63         *ppvObject = iface;
64     }
65     else
66     {
67         FIXME("interface %s not implemented\n", debugstr_guid(riid));
68         return E_NOINTERFACE;
69     }
70
71     IXMLDOMParseError_AddRef( iface );
72
73     return S_OK;
74 }
75
76 static ULONG WINAPI parseError_AddRef(
77     IXMLDOMParseError *iface )
78 {
79     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
80     ULONG ref = InterlockedIncrement( &This->ref );
81     TRACE("(%p) ref now %ld\n", This, ref);
82     return ref;
83 }
84
85 static ULONG WINAPI parseError_Release(
86     IXMLDOMParseError *iface )
87 {
88     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
89     ULONG ref;
90
91     ref = InterlockedDecrement( &This->ref );
92     TRACE("(%p) ref now %ld\n", This, ref);
93     if ( ref == 0 )
94     {
95         SysFreeString(This->url);
96         SysFreeString(This->reason);
97         SysFreeString(This->srcText);
98         HeapFree( GetProcessHeap(), 0, This );
99     }
100
101     return ref;
102 }
103
104 static HRESULT WINAPI parseError_GetTypeInfoCount(
105     IXMLDOMParseError *iface,
106     UINT* pctinfo )
107 {
108     FIXME("\n");
109     return E_NOTIMPL;
110 }
111
112 static HRESULT WINAPI parseError_GetTypeInfo(
113     IXMLDOMParseError *iface,
114     UINT iTInfo,
115     LCID lcid,
116     ITypeInfo** ppTInfo )
117 {
118     FIXME("\n");
119     return E_NOTIMPL;
120 }
121
122 static HRESULT WINAPI parseError_GetIDsOfNames(
123     IXMLDOMParseError *iface,
124     REFIID riid,
125     LPOLESTR* rgszNames,
126     UINT cNames,
127     LCID lcid,
128     DISPID* rgDispId )
129 {
130     FIXME("\n");
131     return E_NOTIMPL;
132 }
133
134 static HRESULT WINAPI parseError_Invoke(
135     IXMLDOMParseError *iface,
136     DISPID dispIdMember,
137     REFIID riid,
138     LCID lcid,
139     WORD wFlags,
140     DISPPARAMS* pDispParams,
141     VARIANT* pVarResult,
142     EXCEPINFO* pExcepInfo,
143     UINT* puArgErr )
144 {
145     FIXME("\n");
146     return E_NOTIMPL;
147 }
148
149 static HRESULT WINAPI parseError_get_errorCode(
150     IXMLDOMParseError *iface,
151     LONG *code )
152 {
153     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
154     TRACE("(%p)->(%p)\n", This, code);
155
156     *code = This->code;
157
158     if(This->code == 0)
159         return S_FALSE;
160
161     return S_OK;
162 }
163
164 static HRESULT WINAPI parseError_get_url(
165     IXMLDOMParseError *iface,
166     BSTR *url )
167 {
168     FIXME("\n");
169     return E_NOTIMPL;
170 }
171
172 static HRESULT WINAPI parseError_get_reason(
173     IXMLDOMParseError *iface,
174     BSTR *reason )
175 {
176     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
177     TRACE("(%p)->(%p)\n", This, reason);
178     
179     if(!This->reason)
180     {
181         *reason = NULL;
182         return S_FALSE;
183     }
184     *reason = SysAllocString(This->reason);
185     return S_OK;
186 }
187
188 static HRESULT WINAPI parseError_get_srcText(
189     IXMLDOMParseError *iface,
190     BSTR *srcText )
191 {
192     FIXME("\n");
193     return E_NOTIMPL;
194 }
195
196 static HRESULT WINAPI parseError_get_line(
197     IXMLDOMParseError *iface,
198     LONG *line )
199 {
200     FIXME("\n");
201     return E_NOTIMPL;
202 }
203
204 static HRESULT WINAPI parseError_get_linepos(
205     IXMLDOMParseError *iface,
206     LONG *linepos )
207 {
208     FIXME("\n");
209     return E_NOTIMPL;
210 }
211
212 static HRESULT WINAPI parseError_get_filepos(
213     IXMLDOMParseError *iface,
214     LONG *filepos )
215 {
216     FIXME("\n");
217     return E_NOTIMPL;
218 }
219
220 static const struct IXMLDOMParseErrorVtbl parseError_vtbl =
221 {
222     parseError_QueryInterface,
223     parseError_AddRef,
224     parseError_Release,
225     parseError_GetTypeInfoCount,
226     parseError_GetTypeInfo,
227     parseError_GetIDsOfNames,
228     parseError_Invoke,
229     parseError_get_errorCode,
230     parseError_get_url,
231     parseError_get_reason,
232     parseError_get_srcText,
233     parseError_get_line,
234     parseError_get_linepos,
235     parseError_get_filepos
236 };
237
238 IXMLDOMParseError *create_parseError( LONG code, BSTR url, BSTR reason, BSTR srcText,
239                                       LONG line, LONG linepos, LONG filepos )
240 {
241     parse_error_t *This;
242
243     This = HeapAlloc( GetProcessHeap(), 0, sizeof(*This) );
244     if ( !This )
245         return NULL;
246
247     This->lpVtbl = &parseError_vtbl;
248     This->ref = 1;
249
250     This->code = code;
251     This->url = url;
252     This->reason = reason;
253     This->srcText = srcText;
254     This->line = line;
255     This->linepos = linepos;
256     This->filepos = filepos;
257
258     return (IXMLDOMParseError*) &This->lpVtbl;
259 }