msxml3: Test insertBefore() behaviour with node relinking, simplify common test cases.
[wine] / dlls / msxml3 / domimpl.c
1 /*
2  *    DOM Document Implementation implementation
3  *
4  * Copyright 2007 Alistair Leslie-Hughes
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 #define COBJMACROS
22
23 #include "config.h"
24
25 #include <stdarg.h>
26 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 #endif
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "ole2.h"
35 #include "msxml6.h"
36
37 #include "msxml_private.h"
38
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
42
43 #ifdef HAVE_LIBXML2
44
45 typedef struct _domimpl
46 {
47     IXMLDOMImplementation IXMLDOMImplementation_iface;
48     LONG ref;
49 } domimpl;
50
51 static inline domimpl *impl_from_IXMLDOMImplementation( IXMLDOMImplementation *iface )
52 {
53     return CONTAINING_RECORD(iface, domimpl, IXMLDOMImplementation_iface);
54 }
55
56 static HRESULT WINAPI dimimpl_QueryInterface(
57     IXMLDOMImplementation *iface,
58     REFIID riid,
59     void** ppvObject )
60 {
61     domimpl *This = impl_from_IXMLDOMImplementation( iface );
62     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
63
64     if ( IsEqualGUID( riid, &IID_IXMLDOMImplementation ) ||
65          IsEqualGUID( riid, &IID_IDispatch ) ||
66          IsEqualGUID( riid, &IID_IUnknown ) )
67     {
68         *ppvObject = iface;
69     }
70     else
71     {
72         FIXME("Unsupported interface %s\n", debugstr_guid(riid));
73         *ppvObject = NULL;
74         return E_NOINTERFACE;
75     }
76
77     IXMLDOMImplementation_AddRef( iface );
78
79     return S_OK;
80 }
81
82 static ULONG WINAPI dimimpl_AddRef(
83     IXMLDOMImplementation *iface )
84 {
85     domimpl *This = impl_from_IXMLDOMImplementation( iface );
86     return InterlockedIncrement( &This->ref );
87 }
88
89 static ULONG WINAPI dimimpl_Release(
90     IXMLDOMImplementation *iface )
91 {
92     domimpl *This = impl_from_IXMLDOMImplementation( iface );
93     ULONG ref;
94
95     ref = InterlockedDecrement( &This->ref );
96     if ( ref == 0 )
97     {
98         heap_free( This );
99     }
100
101     return ref;
102 }
103
104 static HRESULT WINAPI dimimpl_GetTypeInfoCount(
105     IXMLDOMImplementation *iface,
106     UINT* pctinfo )
107 {
108     domimpl *This = impl_from_IXMLDOMImplementation( iface );
109
110     TRACE("(%p)->(%p)\n", This, pctinfo);
111
112     *pctinfo = 1;
113
114     return S_OK;
115 }
116
117 static HRESULT WINAPI dimimpl_GetTypeInfo(
118     IXMLDOMImplementation *iface,
119     UINT iTInfo, LCID lcid,
120     ITypeInfo** ppTInfo )
121 {
122     domimpl *This = impl_from_IXMLDOMImplementation( iface );
123     HRESULT hr;
124
125     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
126
127     hr = get_typeinfo(IXMLDOMImplementation_tid, ppTInfo);
128
129     return hr;
130 }
131
132 static HRESULT WINAPI dimimpl_GetIDsOfNames(
133     IXMLDOMImplementation *iface,
134     REFIID riid, LPOLESTR* rgszNames,
135     UINT cNames, LCID lcid, DISPID* rgDispId )
136 {
137     domimpl *This = impl_from_IXMLDOMImplementation( iface );
138     ITypeInfo *typeinfo;
139     HRESULT hr;
140
141     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
142           lcid, rgDispId);
143
144     if(!rgszNames || cNames == 0 || !rgDispId)
145         return E_INVALIDARG;
146
147     hr = get_typeinfo(IXMLDOMImplementation_tid, &typeinfo);
148     if(SUCCEEDED(hr))
149     {
150         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
151         ITypeInfo_Release(typeinfo);
152     }
153
154     return hr;
155 }
156
157 static HRESULT WINAPI dimimpl_Invoke(
158     IXMLDOMImplementation *iface,
159     DISPID dispIdMember, REFIID riid, LCID lcid,
160     WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
161     EXCEPINFO* pExcepInfo, UINT* puArgErr )
162 {
163     domimpl *This = impl_from_IXMLDOMImplementation( iface );
164     ITypeInfo *typeinfo;
165     HRESULT hr;
166
167     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
168           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
169
170     hr = get_typeinfo(IXMLDOMImplementation_tid, &typeinfo);
171     if(SUCCEEDED(hr))
172     {
173         hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMImplementation_iface, dispIdMember, wFlags,
174                 pDispParams, pVarResult, pExcepInfo, puArgErr);
175         ITypeInfo_Release(typeinfo);
176     }
177
178     return hr;
179 }
180
181 static HRESULT WINAPI dimimpl_hasFeature(IXMLDOMImplementation* This, BSTR feature, BSTR version, VARIANT_BOOL *hasFeature)
182 {
183     static const WCHAR bVersion[] = {'1','.','0',0};
184     static const WCHAR bXML[] = {'X','M','L',0};
185     static const WCHAR bDOM[] = {'D','O','M',0};
186     static const WCHAR bMSDOM[] = {'M','S','-','D','O','M',0};
187     BOOL bValidFeature = FALSE;
188     BOOL bValidVersion = FALSE;
189
190     TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(feature), debugstr_w(version), hasFeature);
191
192     if(!feature || !hasFeature)
193         return E_INVALIDARG;
194
195     *hasFeature = VARIANT_FALSE;
196
197     if(!version || lstrcmpiW(version, bVersion) == 0)
198         bValidVersion = TRUE;
199
200     if(lstrcmpiW(feature, bXML) == 0 || lstrcmpiW(feature, bDOM) == 0 || lstrcmpiW(feature, bMSDOM) == 0)
201         bValidFeature = TRUE;
202
203     if(bValidVersion && bValidFeature)
204         *hasFeature = VARIANT_TRUE;
205
206     return S_OK;
207 }
208
209 static const struct IXMLDOMImplementationVtbl dimimpl_vtbl =
210 {
211     dimimpl_QueryInterface,
212     dimimpl_AddRef,
213     dimimpl_Release,
214     dimimpl_GetTypeInfoCount,
215     dimimpl_GetTypeInfo,
216     dimimpl_GetIDsOfNames,
217     dimimpl_Invoke,
218     dimimpl_hasFeature
219 };
220
221 IUnknown* create_doc_Implementation(void)
222 {
223     domimpl *This;
224
225     This = heap_alloc( sizeof *This );
226     if ( !This )
227         return NULL;
228
229     This->IXMLDOMImplementation_iface.lpVtbl = &dimimpl_vtbl;
230     This->ref = 1;
231
232     return (IUnknown*)&This->IXMLDOMImplementation_iface;
233 }
234
235 #endif