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