4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2005 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
39 /* undef the #define in msxml2 so that we can access the v.2 version
40 independent CLSID as well as the v.3 one. */
41 #undef CLSID_DOMDocument
43 #include "wine/debug.h"
45 #include "msxml_private.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
49 typedef HRESULT (*ClassFactoryCreateInstanceFunc)(IUnknown *pUnkOuter, LPVOID *ppObj);
50 typedef HRESULT (*DOMFactoryCreateInstanceFunc)(const GUID *clsid, IUnknown *pUnkOuter, LPVOID *ppObj);
52 /******************************************************************************
57 IClassFactory IClassFactory_iface;
58 ClassFactoryCreateInstanceFunc pCreateInstance;
63 IClassFactory IClassFactory_iface;
65 DOMFactoryCreateInstanceFunc pCreateInstance;
69 static inline ClassFactory *ClassFactory_from_IClassFactory(IClassFactory *iface)
71 return CONTAINING_RECORD(iface, ClassFactory, IClassFactory_iface);
74 static HRESULT WINAPI ClassFactory_QueryInterface(
79 if (IsEqualGUID(riid, &IID_IUnknown) ||
80 IsEqualGUID(riid, &IID_IClassFactory))
82 IClassFactory_AddRef( iface );
87 FIXME("interface %s not implemented\n", debugstr_guid(riid));
92 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface )
97 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface )
102 static HRESULT WINAPI ClassFactory_CreateInstance(
103 IClassFactory *iface,
108 ClassFactory *This = ClassFactory_from_IClassFactory(iface);
112 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
117 return CLASS_E_NOAGGREGATION;
119 r = This->pCreateInstance( pOuter, (void**) &punk );
123 r = IUnknown_QueryInterface( punk, riid, ppobj );
124 IUnknown_Release( punk );
128 static HRESULT WINAPI ClassFactory_LockServer(
129 IClassFactory *iface,
132 FIXME("(%p)->(%d),stub!\n",iface,dolock);
136 static inline DOMFactory *DOMFactory_from_IClassFactory(IClassFactory *iface)
138 return CONTAINING_RECORD(iface, DOMFactory, IClassFactory_iface);
141 static ULONG WINAPI DOMClassFactory_AddRef(IClassFactory *iface )
143 DOMFactory *This = DOMFactory_from_IClassFactory(iface);
144 ULONG ref = InterlockedIncrement(&This->ref);
145 TRACE("(%p) ref = %u\n", This, ref);
149 static ULONG WINAPI DOMClassFactory_Release(IClassFactory *iface )
151 DOMFactory *This = DOMFactory_from_IClassFactory(iface);
152 ULONG ref = InterlockedDecrement(&This->ref);
153 TRACE("(%p) ref = %u\n", This, ref);
160 static HRESULT WINAPI DOMClassFactory_CreateInstance(
161 IClassFactory *iface,
166 DOMFactory *This = DOMFactory_from_IClassFactory(iface);
170 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
175 return CLASS_E_NOAGGREGATION;
177 r = This->pCreateInstance( &This->clsid, pOuter, (void**) &punk );
181 r = IUnknown_QueryInterface( punk, riid, ppobj );
182 IUnknown_Release( punk );
186 static const struct IClassFactoryVtbl ClassFactoryVtbl =
188 ClassFactory_QueryInterface,
190 ClassFactory_Release,
191 ClassFactory_CreateInstance,
192 ClassFactory_LockServer
195 static const struct IClassFactoryVtbl DOMClassFactoryVtbl =
197 ClassFactory_QueryInterface,
198 DOMClassFactory_AddRef,
199 DOMClassFactory_Release,
200 DOMClassFactory_CreateInstance,
201 ClassFactory_LockServer
204 static HRESULT DOMClassFactory_Create(const GUID *clsid, REFIID riid, void **ppv, DOMFactoryCreateInstanceFunc fnCreateInstance)
206 DOMFactory *ret = heap_alloc(sizeof(DOMFactory));
209 ret->IClassFactory_iface.lpVtbl = &DOMClassFactoryVtbl;
212 ret->pCreateInstance = fnCreateInstance;
214 hres = IClassFactory_QueryInterface(&ret->IClassFactory_iface, riid, ppv);
222 static ClassFactory xmldoccf = { { &ClassFactoryVtbl }, XMLDocument_create };
223 static ClassFactory saxreadcf = { { &ClassFactoryVtbl }, SAXXMLReader_create };
224 static ClassFactory httpreqcf = { { &ClassFactoryVtbl }, XMLHTTPRequest_create };
225 static ClassFactory xsltemplatecf = { { &ClassFactoryVtbl }, XSLTemplate_create };
226 static ClassFactory mxwritercf = { { &ClassFactoryVtbl }, MXWriter_create };
228 /******************************************************************
229 * DllGetClassObject (MSXML3.@)
231 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, void **ppv )
233 IClassFactory *cf = NULL;
235 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv );
237 if( IsEqualCLSID( rclsid, &CLSID_DOMDocument ) || /* Version indep. v 2.x */
238 IsEqualCLSID( rclsid, &CLSID_DOMDocument2 ) || /* Version indep. v 3.0 */
239 IsEqualCLSID( rclsid, &CLSID_DOMDocument26 )|| /* Version dep. v 2.6 */
240 IsEqualCLSID( rclsid, &CLSID_DOMDocument30 )|| /* Version dep. v 3.0 */
241 IsEqualCLSID( rclsid, &CLSID_DOMDocument40 )|| /* Version dep. v 4.0 */
242 IsEqualCLSID( rclsid, &CLSID_DOMDocument60 )) /* Version dep. v 6.0 */
244 return DOMClassFactory_Create(rclsid, riid, ppv, DOMDocument_create);
246 else if( IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache ) ||
247 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache26 ) ||
248 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache30 ) ||
249 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache40 ) ||
250 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache60 ))
252 return DOMClassFactory_Create(rclsid, riid, ppv, SchemaCache_create);
254 else if( IsEqualCLSID( rclsid, &CLSID_XMLDocument ) )
256 cf = &xmldoccf.IClassFactory_iface;
258 else if( IsEqualCLSID( rclsid, &CLSID_DOMFreeThreadedDocument ) || /* Version indep. v 2.x */
259 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument ) ||
260 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument26 ) ||
261 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument30 ) ||
262 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument40 ) ||
263 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument60 ))
265 return DOMClassFactory_Create(rclsid, riid, ppv, DOMDocument_create);
267 else if( IsEqualCLSID( rclsid, &CLSID_SAXXMLReader) ||
268 IsEqualCLSID( rclsid, &CLSID_SAXXMLReader30 ) ||
269 IsEqualCLSID( rclsid, &CLSID_SAXXMLReader40 ) ||
270 IsEqualCLSID( rclsid, &CLSID_SAXXMLReader60 ))
272 cf = &saxreadcf.IClassFactory_iface;
274 else if( IsEqualCLSID( rclsid, &CLSID_XMLHTTPRequest ) ||
275 IsEqualCLSID( rclsid, &CLSID_XMLHTTP) ||
276 IsEqualCLSID( rclsid, &CLSID_XMLHTTP26 ) ||
277 IsEqualCLSID( rclsid, &CLSID_XMLHTTP30 ) ||
278 IsEqualCLSID( rclsid, &CLSID_XMLHTTP40 ) ||
279 IsEqualCLSID( rclsid, &CLSID_XMLHTTP60 ))
281 cf = &httpreqcf.IClassFactory_iface;
283 else if( IsEqualCLSID( rclsid, &CLSID_XSLTemplate ) ||
284 IsEqualCLSID( rclsid, &CLSID_XSLTemplate26 ) ||
285 IsEqualCLSID( rclsid, &CLSID_XSLTemplate30 ) ||
286 IsEqualCLSID( rclsid, &CLSID_XSLTemplate40 ) ||
287 IsEqualCLSID( rclsid, &CLSID_XSLTemplate60 ))
289 cf = &xsltemplatecf.IClassFactory_iface;
291 else if( IsEqualCLSID( rclsid, &CLSID_MXXMLWriter ) ||
292 IsEqualCLSID( rclsid, &CLSID_MXXMLWriter30 ) ||
293 IsEqualCLSID( rclsid, &CLSID_MXXMLWriter40 ) ||
294 IsEqualCLSID( rclsid, &CLSID_MXXMLWriter60 ) )
296 cf = &mxwritercf.IClassFactory_iface;
300 return CLASS_E_CLASSNOTAVAILABLE;
302 return IClassFactory_QueryInterface( cf, riid, ppv );