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>
38 #include "xmlparser.h"
40 /* undef the #define in msxml2 so that we can access the v.2 version
41 independent CLSID as well as the v.3 one. */
42 #undef CLSID_DOMDocument
44 #include "wine/debug.h"
46 #include "msxml_private.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
50 typedef HRESULT (*ClassFactoryCreateInstanceFunc
)(IUnknown
*, void**);
51 typedef HRESULT (*DOMFactoryCreateInstanceFunc
)(MSXML_VERSION
, IUnknown
*, void**);
53 struct clsid_version_t
56 MSXML_VERSION version
;
59 static const struct clsid_version_t clsid_versions_table
[] =
61 { &CLSID_DOMDocument
, MSXML_DEFAULT
},
62 { &CLSID_DOMDocument2
, MSXML_DEFAULT
},
63 { &CLSID_DOMDocument26
, MSXML_DEFAULT
},
64 { &CLSID_DOMDocument30
, MSXML3
},
65 { &CLSID_DOMDocument40
, MSXML4
},
66 { &CLSID_DOMDocument60
, MSXML6
},
68 { &CLSID_DOMFreeThreadedDocument
, MSXML_DEFAULT
},
69 { &CLSID_FreeThreadedDOMDocument
, MSXML_DEFAULT
},
70 { &CLSID_FreeThreadedDOMDocument26
, MSXML_DEFAULT
},
71 { &CLSID_FreeThreadedDOMDocument30
, MSXML3
},
72 { &CLSID_FreeThreadedDOMDocument40
, MSXML4
},
73 { &CLSID_FreeThreadedDOMDocument60
, MSXML6
},
75 { &CLSID_XMLSchemaCache
, MSXML_DEFAULT
},
76 { &CLSID_XMLSchemaCache26
, MSXML_DEFAULT
},
77 { &CLSID_XMLSchemaCache30
, MSXML3
},
78 { &CLSID_XMLSchemaCache40
, MSXML4
},
79 { &CLSID_XMLSchemaCache60
, MSXML6
},
81 { &CLSID_MXXMLWriter
, MSXML_DEFAULT
},
82 { &CLSID_MXXMLWriter30
, MSXML3
},
83 { &CLSID_MXXMLWriter40
, MSXML4
},
84 { &CLSID_MXXMLWriter60
, MSXML6
}
87 static MSXML_VERSION
get_msxml_version(const GUID
*clsid
)
91 for (i
= 0; i
< sizeof(clsid_versions_table
)/sizeof(struct clsid_version_t
); i
++)
92 if (IsEqualGUID(clsid
, clsid_versions_table
[i
].clsid
))
93 return clsid_versions_table
[i
].version
;
95 ERR("unknown clsid=%s\n", debugstr_guid(clsid
));
99 /******************************************************************************
104 IClassFactory IClassFactory_iface
;
105 ClassFactoryCreateInstanceFunc pCreateInstance
;
110 IClassFactory IClassFactory_iface
;
112 DOMFactoryCreateInstanceFunc pCreateInstance
;
113 MSXML_VERSION version
;
116 static inline ClassFactory
*ClassFactory_from_IClassFactory(IClassFactory
*iface
)
118 return CONTAINING_RECORD(iface
, ClassFactory
, IClassFactory_iface
);
121 static HRESULT WINAPI
ClassFactory_QueryInterface(
122 IClassFactory
*iface
,
126 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
127 IsEqualGUID(riid
, &IID_IClassFactory
))
129 IClassFactory_AddRef( iface
);
134 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
136 return E_NOINTERFACE
;
139 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
144 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
149 static HRESULT WINAPI
ClassFactory_CreateInstance(
150 IClassFactory
*iface
,
155 ClassFactory
*This
= ClassFactory_from_IClassFactory(iface
);
159 TRACE("%p %s %p\n", pOuter
, debugstr_guid(riid
), ppobj
);
164 return CLASS_E_NOAGGREGATION
;
166 r
= This
->pCreateInstance( pOuter
, (void**) &punk
);
170 r
= IUnknown_QueryInterface( punk
, riid
, ppobj
);
171 IUnknown_Release( punk
);
175 static HRESULT WINAPI
ClassFactory_LockServer(
176 IClassFactory
*iface
,
179 FIXME("(%p)->(%d),stub!\n",iface
,dolock
);
183 static inline DOMFactory
*DOMFactory_from_IClassFactory(IClassFactory
*iface
)
185 return CONTAINING_RECORD(iface
, DOMFactory
, IClassFactory_iface
);
188 static ULONG WINAPI
DOMClassFactory_AddRef(IClassFactory
*iface
)
190 DOMFactory
*This
= DOMFactory_from_IClassFactory(iface
);
191 ULONG ref
= InterlockedIncrement(&This
->ref
);
192 TRACE("(%p) ref = %u\n", This
, ref
);
196 static ULONG WINAPI
DOMClassFactory_Release(IClassFactory
*iface
)
198 DOMFactory
*This
= DOMFactory_from_IClassFactory(iface
);
199 ULONG ref
= InterlockedDecrement(&This
->ref
);
200 TRACE("(%p) ref = %u\n", This
, ref
);
207 static HRESULT WINAPI
DOMClassFactory_CreateInstance(
208 IClassFactory
*iface
,
213 DOMFactory
*This
= DOMFactory_from_IClassFactory(iface
);
217 TRACE("%p %s %p\n", pOuter
, debugstr_guid(riid
), ppobj
);
222 return CLASS_E_NOAGGREGATION
;
224 r
= This
->pCreateInstance( This
->version
, pOuter
, (void**) &punk
);
228 r
= IUnknown_QueryInterface( punk
, riid
, ppobj
);
229 IUnknown_Release( punk
);
233 static const struct IClassFactoryVtbl ClassFactoryVtbl
=
235 ClassFactory_QueryInterface
,
237 ClassFactory_Release
,
238 ClassFactory_CreateInstance
,
239 ClassFactory_LockServer
242 static const struct IClassFactoryVtbl DOMClassFactoryVtbl
=
244 ClassFactory_QueryInterface
,
245 DOMClassFactory_AddRef
,
246 DOMClassFactory_Release
,
247 DOMClassFactory_CreateInstance
,
248 ClassFactory_LockServer
251 static HRESULT
DOMClassFactory_Create(const GUID
*clsid
, REFIID riid
, void **ppv
, DOMFactoryCreateInstanceFunc fnCreateInstance
)
253 DOMFactory
*ret
= heap_alloc(sizeof(DOMFactory
));
256 ret
->IClassFactory_iface
.lpVtbl
= &DOMClassFactoryVtbl
;
258 ret
->version
= get_msxml_version(clsid
);
259 ret
->pCreateInstance
= fnCreateInstance
;
261 hres
= IClassFactory_QueryInterface(&ret
->IClassFactory_iface
, riid
, ppv
);
269 static ClassFactory xmldoccf
= { { &ClassFactoryVtbl
}, XMLDocument_create
};
270 static ClassFactory saxreadcf
= { { &ClassFactoryVtbl
}, SAXXMLReader_create
};
271 static ClassFactory httpreqcf
= { { &ClassFactoryVtbl
}, XMLHTTPRequest_create
};
272 static ClassFactory xsltemplatecf
= { { &ClassFactoryVtbl
}, XSLTemplate_create
};
273 static ClassFactory mxnsmanagercf
= { {&ClassFactoryVtbl
}, MXNamespaceManager_create
};
274 static ClassFactory xmlparsercf
= { { &ClassFactoryVtbl
}, XMLParser_create
};
276 /******************************************************************
277 * DllGetClassObject (MSXML3.@)
279 HRESULT WINAPI
DllGetClassObject( REFCLSID rclsid
, REFIID riid
, void **ppv
)
281 IClassFactory
*cf
= NULL
;
283 TRACE("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
285 if( IsEqualCLSID( rclsid
, &CLSID_DOMDocument
) || /* Version indep. v 2.x */
286 IsEqualCLSID( rclsid
, &CLSID_DOMDocument2
) || /* Version indep. v 3.0 */
287 IsEqualCLSID( rclsid
, &CLSID_DOMDocument26
)|| /* Version dep. v 2.6 */
288 IsEqualCLSID( rclsid
, &CLSID_DOMDocument30
)|| /* Version dep. v 3.0 */
289 IsEqualCLSID( rclsid
, &CLSID_DOMDocument40
)|| /* Version dep. v 4.0 */
290 IsEqualCLSID( rclsid
, &CLSID_DOMDocument60
)) /* Version dep. v 6.0 */
292 return DOMClassFactory_Create(rclsid
, riid
, ppv
, DOMDocument_create
);
294 else if( IsEqualCLSID( rclsid
, &CLSID_XMLSchemaCache
) ||
295 IsEqualCLSID( rclsid
, &CLSID_XMLSchemaCache26
) ||
296 IsEqualCLSID( rclsid
, &CLSID_XMLSchemaCache30
) ||
297 IsEqualCLSID( rclsid
, &CLSID_XMLSchemaCache40
) ||
298 IsEqualCLSID( rclsid
, &CLSID_XMLSchemaCache60
))
300 return DOMClassFactory_Create(rclsid
, riid
, ppv
, SchemaCache_create
);
302 else if( IsEqualCLSID( rclsid
, &CLSID_XMLDocument
) )
304 cf
= &xmldoccf
.IClassFactory_iface
;
306 else if( IsEqualCLSID( rclsid
, &CLSID_DOMFreeThreadedDocument
) || /* Version indep. v 2.x */
307 IsEqualCLSID( rclsid
, &CLSID_FreeThreadedDOMDocument
) ||
308 IsEqualCLSID( rclsid
, &CLSID_FreeThreadedDOMDocument26
) ||
309 IsEqualCLSID( rclsid
, &CLSID_FreeThreadedDOMDocument30
) ||
310 IsEqualCLSID( rclsid
, &CLSID_FreeThreadedDOMDocument40
) ||
311 IsEqualCLSID( rclsid
, &CLSID_FreeThreadedDOMDocument60
))
313 return DOMClassFactory_Create(rclsid
, riid
, ppv
, DOMDocument_create
);
315 else if( IsEqualCLSID( rclsid
, &CLSID_SAXXMLReader
) ||
316 IsEqualCLSID( rclsid
, &CLSID_SAXXMLReader30
) ||
317 IsEqualCLSID( rclsid
, &CLSID_SAXXMLReader40
) ||
318 IsEqualCLSID( rclsid
, &CLSID_SAXXMLReader60
))
320 cf
= &saxreadcf
.IClassFactory_iface
;
322 else if( IsEqualCLSID( rclsid
, &CLSID_XMLHTTPRequest
) ||
323 IsEqualCLSID( rclsid
, &CLSID_XMLHTTP
) ||
324 IsEqualCLSID( rclsid
, &CLSID_XMLHTTP26
) ||
325 IsEqualCLSID( rclsid
, &CLSID_XMLHTTP30
) ||
326 IsEqualCLSID( rclsid
, &CLSID_XMLHTTP40
) ||
327 IsEqualCLSID( rclsid
, &CLSID_XMLHTTP60
))
329 cf
= &httpreqcf
.IClassFactory_iface
;
331 else if( IsEqualCLSID( rclsid
, &CLSID_XSLTemplate
) ||
332 IsEqualCLSID( rclsid
, &CLSID_XSLTemplate26
) ||
333 IsEqualCLSID( rclsid
, &CLSID_XSLTemplate30
) ||
334 IsEqualCLSID( rclsid
, &CLSID_XSLTemplate40
) ||
335 IsEqualCLSID( rclsid
, &CLSID_XSLTemplate60
))
337 cf
= &xsltemplatecf
.IClassFactory_iface
;
339 else if( IsEqualCLSID( rclsid
, &CLSID_MXXMLWriter
) ||
340 IsEqualCLSID( rclsid
, &CLSID_MXXMLWriter30
) ||
341 IsEqualCLSID( rclsid
, &CLSID_MXXMLWriter40
) ||
342 IsEqualCLSID( rclsid
, &CLSID_MXXMLWriter60
) )
344 return DOMClassFactory_Create(rclsid
, riid
, ppv
, MXWriter_create
);
346 else if( IsEqualCLSID( rclsid
, &CLSID_MXNamespaceManager
) ||
347 IsEqualCLSID( rclsid
, &CLSID_MXNamespaceManager40
) ||
348 IsEqualCLSID( rclsid
, &CLSID_MXNamespaceManager60
) )
350 cf
= &mxnsmanagercf
.IClassFactory_iface
;
352 else if( IsEqualCLSID( rclsid
, &CLSID_XMLParser
) ||
353 IsEqualCLSID( rclsid
, &CLSID_XMLParser26
) ||
354 IsEqualCLSID( rclsid
, &CLSID_XMLParser30
) )
356 cf
= &xmlparsercf
.IClassFactory_iface
;
360 return CLASS_E_CLASSNOTAVAILABLE
;
362 return IClassFactory_QueryInterface( cf
, riid
, ppv
);