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