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
)(void**);
51 typedef HRESULT (*DOMFactoryCreateInstanceFunc
)(MSXML_VERSION
, 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
, MSXML2
},
63 { &CLSID_DOMDocument26
, MSXML26
},
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
, MSXML26
},
71 { &CLSID_FreeThreadedDOMDocument30
, MSXML3
},
72 { &CLSID_FreeThreadedDOMDocument40
, MSXML4
},
73 { &CLSID_FreeThreadedDOMDocument60
, MSXML6
},
75 { &CLSID_XMLSchemaCache
, MSXML_DEFAULT
},
76 { &CLSID_XMLSchemaCache26
, MSXML26
},
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
},
86 { &CLSID_SAXXMLReader
, MSXML_DEFAULT
},
87 { &CLSID_SAXXMLReader30
, MSXML3
},
88 { &CLSID_SAXXMLReader40
, MSXML4
},
89 { &CLSID_SAXXMLReader60
, MSXML6
},
91 { &CLSID_SAXAttributes
, MSXML_DEFAULT
},
92 { &CLSID_SAXAttributes30
, MSXML3
},
93 { &CLSID_SAXAttributes40
, MSXML4
},
94 { &CLSID_SAXAttributes60
, MSXML6
},
96 { &CLSID_XMLView
, MSXML_DEFAULT
}
99 static MSXML_VERSION
get_msxml_version(const GUID
*clsid
)
103 for (i
= 0; i
< sizeof(clsid_versions_table
)/sizeof(struct clsid_version_t
); i
++)
104 if (IsEqualGUID(clsid
, clsid_versions_table
[i
].clsid
))
105 return clsid_versions_table
[i
].version
;
107 ERR("unknown clsid=%s\n", debugstr_guid(clsid
));
108 return MSXML_DEFAULT
;
111 /******************************************************************************
116 IClassFactory IClassFactory_iface
;
117 ClassFactoryCreateInstanceFunc pCreateInstance
;
122 IClassFactory IClassFactory_iface
;
124 DOMFactoryCreateInstanceFunc pCreateInstance
;
125 MSXML_VERSION version
;
128 static inline ClassFactory
*ClassFactory_from_IClassFactory(IClassFactory
*iface
)
130 return CONTAINING_RECORD(iface
, ClassFactory
, IClassFactory_iface
);
133 static HRESULT WINAPI
ClassFactory_QueryInterface(
134 IClassFactory
*iface
,
138 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
139 IsEqualGUID(riid
, &IID_IClassFactory
))
141 IClassFactory_AddRef( iface
);
146 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
148 return E_NOINTERFACE
;
151 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
156 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
161 static HRESULT WINAPI
ClassFactory_CreateInstance(
162 IClassFactory
*iface
,
167 ClassFactory
*This
= ClassFactory_from_IClassFactory(iface
);
171 TRACE("%p %s %p\n", pOuter
, debugstr_guid(riid
), ppobj
);
176 return CLASS_E_NOAGGREGATION
;
178 r
= This
->pCreateInstance( (void**) &punk
);
182 r
= IUnknown_QueryInterface( punk
, riid
, ppobj
);
183 IUnknown_Release( punk
);
187 static HRESULT WINAPI
ClassFactory_LockServer(
188 IClassFactory
*iface
,
191 FIXME("(%p)->(%d),stub!\n",iface
,dolock
);
195 static inline DOMFactory
*DOMFactory_from_IClassFactory(IClassFactory
*iface
)
197 return CONTAINING_RECORD(iface
, DOMFactory
, IClassFactory_iface
);
200 static ULONG WINAPI
DOMClassFactory_AddRef(IClassFactory
*iface
)
202 DOMFactory
*This
= DOMFactory_from_IClassFactory(iface
);
203 ULONG ref
= InterlockedIncrement(&This
->ref
);
204 TRACE("(%p) ref = %u\n", This
, ref
);
208 static ULONG WINAPI
DOMClassFactory_Release(IClassFactory
*iface
)
210 DOMFactory
*This
= DOMFactory_from_IClassFactory(iface
);
211 ULONG ref
= InterlockedDecrement(&This
->ref
);
212 TRACE("(%p) ref = %u\n", This
, ref
);
219 static HRESULT WINAPI
DOMClassFactory_CreateInstance(
220 IClassFactory
*iface
,
225 DOMFactory
*This
= DOMFactory_from_IClassFactory(iface
);
229 TRACE("%p %s %p\n", pOuter
, debugstr_guid(riid
), ppobj
);
234 return CLASS_E_NOAGGREGATION
;
236 r
= This
->pCreateInstance( This
->version
, (void**) &punk
);
240 r
= IUnknown_QueryInterface( punk
, riid
, ppobj
);
241 IUnknown_Release( punk
);
245 static const struct IClassFactoryVtbl ClassFactoryVtbl
=
247 ClassFactory_QueryInterface
,
249 ClassFactory_Release
,
250 ClassFactory_CreateInstance
,
251 ClassFactory_LockServer
254 static const struct IClassFactoryVtbl DOMClassFactoryVtbl
=
256 ClassFactory_QueryInterface
,
257 DOMClassFactory_AddRef
,
258 DOMClassFactory_Release
,
259 DOMClassFactory_CreateInstance
,
260 ClassFactory_LockServer
263 static HRESULT
DOMClassFactory_Create(const GUID
*clsid
, REFIID riid
, void **ppv
, DOMFactoryCreateInstanceFunc fnCreateInstance
)
265 DOMFactory
*ret
= heap_alloc(sizeof(DOMFactory
));
268 ret
->IClassFactory_iface
.lpVtbl
= &DOMClassFactoryVtbl
;
270 ret
->version
= get_msxml_version(clsid
);
271 ret
->pCreateInstance
= fnCreateInstance
;
273 hres
= IClassFactory_QueryInterface(&ret
->IClassFactory_iface
, riid
, ppv
);
281 static ClassFactory xmldoccf
= { { &ClassFactoryVtbl
}, XMLDocument_create
};
282 static ClassFactory httpreqcf
= { { &ClassFactoryVtbl
}, XMLHTTPRequest_create
};
283 static ClassFactory serverhttp
= { { &ClassFactoryVtbl
}, ServerXMLHTTP_create
};
284 static ClassFactory xsltemplatecf
= { { &ClassFactoryVtbl
}, XSLTemplate_create
};
285 static ClassFactory mxnsmanagercf
= { {&ClassFactoryVtbl
}, MXNamespaceManager_create
};
286 static ClassFactory xmlparsercf
= { { &ClassFactoryVtbl
}, XMLParser_create
};
287 static ClassFactory xmlviewcf
= { { &ClassFactoryVtbl
}, XMLView_create
};
289 /******************************************************************
290 * DllGetClassObject (MSXML3.@)
292 HRESULT WINAPI
DllGetClassObject( REFCLSID rclsid
, REFIID riid
, void **ppv
)
294 IClassFactory
*cf
= NULL
;
296 TRACE("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
298 if( IsEqualCLSID( rclsid
, &CLSID_DOMDocument
) || /* Version indep. v 2.x */
299 IsEqualCLSID( rclsid
, &CLSID_DOMDocument2
) || /* Version indep. v 3.0 */
300 IsEqualCLSID( rclsid
, &CLSID_DOMDocument26
)|| /* Version dep. v 2.6 */
301 IsEqualCLSID( rclsid
, &CLSID_DOMDocument30
)|| /* Version dep. v 3.0 */
302 IsEqualCLSID( rclsid
, &CLSID_DOMDocument40
)|| /* Version dep. v 4.0 */
303 IsEqualCLSID( rclsid
, &CLSID_DOMDocument60
)) /* Version dep. v 6.0 */
305 return DOMClassFactory_Create(rclsid
, riid
, ppv
, DOMDocument_create
);
307 else if( IsEqualCLSID( rclsid
, &CLSID_XMLSchemaCache
) ||
308 IsEqualCLSID( rclsid
, &CLSID_XMLSchemaCache26
) ||
309 IsEqualCLSID( rclsid
, &CLSID_XMLSchemaCache30
) ||
310 IsEqualCLSID( rclsid
, &CLSID_XMLSchemaCache40
) ||
311 IsEqualCLSID( rclsid
, &CLSID_XMLSchemaCache60
))
313 return DOMClassFactory_Create(rclsid
, riid
, ppv
, SchemaCache_create
);
315 else if( IsEqualCLSID( rclsid
, &CLSID_XMLDocument
) )
317 cf
= &xmldoccf
.IClassFactory_iface
;
319 else if( IsEqualCLSID( rclsid
, &CLSID_DOMFreeThreadedDocument
) || /* Version indep. v 2.x */
320 IsEqualCLSID( rclsid
, &CLSID_FreeThreadedDOMDocument
) ||
321 IsEqualCLSID( rclsid
, &CLSID_FreeThreadedDOMDocument26
) ||
322 IsEqualCLSID( rclsid
, &CLSID_FreeThreadedDOMDocument30
) ||
323 IsEqualCLSID( rclsid
, &CLSID_FreeThreadedDOMDocument40
) ||
324 IsEqualCLSID( rclsid
, &CLSID_FreeThreadedDOMDocument60
))
326 return DOMClassFactory_Create(rclsid
, riid
, ppv
, DOMDocument_create
);
328 else if( IsEqualCLSID( rclsid
, &CLSID_SAXXMLReader
) ||
329 IsEqualCLSID( rclsid
, &CLSID_SAXXMLReader30
) ||
330 IsEqualCLSID( rclsid
, &CLSID_SAXXMLReader40
) ||
331 IsEqualCLSID( rclsid
, &CLSID_SAXXMLReader60
))
333 return DOMClassFactory_Create(rclsid
, riid
, ppv
, SAXXMLReader_create
);
335 else if( IsEqualCLSID( rclsid
, &CLSID_XMLHTTPRequest
) ||
336 IsEqualCLSID( rclsid
, &CLSID_XMLHTTP
) ||
337 IsEqualCLSID( rclsid
, &CLSID_XMLHTTP26
) ||
338 IsEqualCLSID( rclsid
, &CLSID_XMLHTTP30
) ||
339 IsEqualCLSID( rclsid
, &CLSID_XMLHTTP40
) ||
340 IsEqualCLSID( rclsid
, &CLSID_XMLHTTP60
))
342 cf
= &httpreqcf
.IClassFactory_iface
;
344 else if( IsEqualCLSID( rclsid
, &CLSID_ServerXMLHTTP
) ||
345 IsEqualCLSID( rclsid
, &CLSID_ServerXMLHTTP30
) ||
346 IsEqualCLSID( rclsid
, &CLSID_ServerXMLHTTP40
) ||
347 IsEqualCLSID( rclsid
, &CLSID_ServerXMLHTTP60
))
349 cf
= &serverhttp
.IClassFactory_iface
;
351 else if( IsEqualCLSID( rclsid
, &CLSID_XSLTemplate
) ||
352 IsEqualCLSID( rclsid
, &CLSID_XSLTemplate26
) ||
353 IsEqualCLSID( rclsid
, &CLSID_XSLTemplate30
) ||
354 IsEqualCLSID( rclsid
, &CLSID_XSLTemplate40
) ||
355 IsEqualCLSID( rclsid
, &CLSID_XSLTemplate60
))
357 cf
= &xsltemplatecf
.IClassFactory_iface
;
359 else if( IsEqualCLSID( rclsid
, &CLSID_MXXMLWriter
) ||
360 IsEqualCLSID( rclsid
, &CLSID_MXXMLWriter30
) ||
361 IsEqualCLSID( rclsid
, &CLSID_MXXMLWriter40
) ||
362 IsEqualCLSID( rclsid
, &CLSID_MXXMLWriter60
) )
364 return DOMClassFactory_Create(rclsid
, riid
, ppv
, MXWriter_create
);
366 else if( IsEqualCLSID( rclsid
, &CLSID_SAXAttributes
) ||
367 IsEqualCLSID( rclsid
, &CLSID_SAXAttributes30
) ||
368 IsEqualCLSID( rclsid
, &CLSID_SAXAttributes40
) ||
369 IsEqualCLSID( rclsid
, &CLSID_SAXAttributes60
))
371 return DOMClassFactory_Create(rclsid
, riid
, ppv
, SAXAttributes_create
);
373 else if( IsEqualCLSID( rclsid
, &CLSID_MXNamespaceManager
) ||
374 IsEqualCLSID( rclsid
, &CLSID_MXNamespaceManager40
) ||
375 IsEqualCLSID( rclsid
, &CLSID_MXNamespaceManager60
) )
377 cf
= &mxnsmanagercf
.IClassFactory_iface
;
379 else if( IsEqualCLSID( rclsid
, &CLSID_XMLParser
) ||
380 IsEqualCLSID( rclsid
, &CLSID_XMLParser26
) ||
381 IsEqualCLSID( rclsid
, &CLSID_XMLParser30
) )
383 cf
= &xmlparsercf
.IClassFactory_iface
;
385 else if( IsEqualCLSID( rclsid
, &CLSID_XMLView
) )
387 cf
= &xmlviewcf
.IClassFactory_iface
;
391 return CLASS_E_CLASSNOTAVAILABLE
;
393 return IClassFactory_QueryInterface( cf
, riid
, ppv
);