wined3d: Recognize the SM4 round_ni opcode.
[wine/multimedia.git] / dlls / msxml3 / mxnamespace.c
blob17fbab8eaa18ee6b02588ed62ac12b9faef0a76d
1 /*
2 * IMXNamespaceManager implementation
4 * Copyright 2011 Nikolay Sivov for CodeWeavers
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.
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.
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
21 #define COBJMACROS
22 #define NONAMELESSUNION
24 #include "config.h"
26 #include <stdarg.h>
27 #ifdef HAVE_LIBXML2
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
30 # include <libxml/encoding.h>
31 #endif
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winuser.h"
36 #include "ole2.h"
37 #include "msxml6.h"
39 #include "msxml_private.h"
41 #include "wine/debug.h"
42 #include "wine/list.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
46 struct ns
48 BSTR prefix;
49 BSTR uri;
52 struct nscontext
54 struct list entry;
56 struct ns *ns;
57 int count;
58 int max_alloc;
61 #define DEFAULT_PREFIX_ALLOC_COUNT 16
63 static const WCHAR xmlW[] = {'x','m','l',0};
64 static const WCHAR xmluriW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','3','.','o','r','g',
65 '/','X','M','L','/','1','9','9','8','/','n','a','m','e','s','p','a','c','e',0};
67 typedef struct
69 IMXNamespaceManager IMXNamespaceManager_iface;
70 IVBMXNamespaceManager IVBMXNamespaceManager_iface;
71 LONG ref;
73 struct list ctxts;
75 VARIANT_BOOL override;
76 } namespacemanager;
78 static inline namespacemanager *impl_from_IMXNamespaceManager( IMXNamespaceManager *iface )
80 return CONTAINING_RECORD(iface, namespacemanager, IMXNamespaceManager_iface);
83 static inline namespacemanager *impl_from_IVBMXNamespaceManager( IVBMXNamespaceManager *iface )
85 return CONTAINING_RECORD(iface, namespacemanager, IVBMXNamespaceManager_iface);
88 static HRESULT declare_prefix(namespacemanager *This, const WCHAR *prefix, const WCHAR *uri)
90 struct nscontext *ctxt = LIST_ENTRY(list_head(&This->ctxts), struct nscontext, entry);
91 static const WCHAR emptyW[] = {0};
92 struct ns *ns;
93 int i;
95 if (ctxt->count == ctxt->max_alloc)
97 ctxt->max_alloc *= 2;
98 ctxt->ns = heap_realloc(ctxt->ns, ctxt->max_alloc*sizeof(*ctxt->ns));
101 if (!prefix) prefix = emptyW;
103 ns = NULL;
104 for (i = 0; i < ctxt->count; i++)
105 if (!strcmpW(ctxt->ns[i].prefix, prefix))
107 ns = &ctxt->ns[i];
108 break;
111 if (ns)
113 if (This->override == VARIANT_TRUE)
115 SysFreeString(ns->uri);
116 ns->uri = SysAllocString(uri);
117 return S_FALSE;
119 else
120 return E_FAIL;
122 else
124 ctxt->ns[ctxt->count].prefix = SysAllocString(prefix);
125 ctxt->ns[ctxt->count].uri = SysAllocString(uri);
126 ctxt->count++;
129 return S_OK;
132 /* returned stored pointer, caller needs to copy it */
133 static HRESULT get_declared_prefix_idx(const struct nscontext *ctxt, LONG index, BSTR *prefix)
135 *prefix = NULL;
137 if (index >= ctxt->count || index < 0) return E_FAIL;
139 if (index > 0) index = ctxt->count - index;
140 *prefix = ctxt->ns[index].prefix;
142 return S_OK;
145 static HRESULT get_uri_from_prefix(const struct nscontext *ctxt, const WCHAR *prefix, BSTR *uri)
147 int i;
149 for (i = 0; i < ctxt->count; i++)
150 if (!strcmpW(ctxt->ns[i].prefix, prefix))
152 *uri = ctxt->ns[i].uri;
153 return S_OK;
156 *uri = NULL;
157 return S_FALSE;
160 static struct nscontext* alloc_ns_context(void)
162 struct nscontext *ctxt;
164 ctxt = heap_alloc(sizeof(*ctxt));
165 if (!ctxt) return NULL;
167 ctxt->count = 0;
168 ctxt->max_alloc = DEFAULT_PREFIX_ALLOC_COUNT;
169 ctxt->ns = heap_alloc(ctxt->max_alloc*sizeof(*ctxt->ns));
171 /* first allocated prefix is always 'xml' */
172 ctxt->ns[0].prefix = SysAllocString(xmlW);
173 ctxt->ns[0].uri = SysAllocString(xmluriW);
174 ctxt->count++;
176 return ctxt;
179 static void free_ns_context(struct nscontext *ctxt)
181 int i;
183 for (i = 0; i < ctxt->count; i++)
185 SysFreeString(ctxt->ns[i].prefix);
186 SysFreeString(ctxt->ns[i].uri);
189 heap_free(ctxt->ns);
190 heap_free(ctxt);
193 static HRESULT WINAPI namespacemanager_QueryInterface(IMXNamespaceManager *iface, REFIID riid, void **ppvObject)
195 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
196 return IVBMXNamespaceManager_QueryInterface(&This->IVBMXNamespaceManager_iface, riid, ppvObject);
199 static ULONG WINAPI namespacemanager_AddRef(IMXNamespaceManager *iface)
201 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
202 return IVBMXNamespaceManager_AddRef(&This->IVBMXNamespaceManager_iface);
205 static ULONG WINAPI namespacemanager_Release(IMXNamespaceManager *iface)
207 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
208 return IVBMXNamespaceManager_Release(&This->IVBMXNamespaceManager_iface);
211 static HRESULT WINAPI namespacemanager_putAllowOverride(IMXNamespaceManager *iface,
212 VARIANT_BOOL override)
214 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
215 return IVBMXNamespaceManager_put_allowOverride(&This->IVBMXNamespaceManager_iface, override);
218 static HRESULT WINAPI namespacemanager_getAllowOverride(IMXNamespaceManager *iface,
219 VARIANT_BOOL *override)
221 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
222 return IVBMXNamespaceManager_get_allowOverride(&This->IVBMXNamespaceManager_iface, override);
225 static HRESULT WINAPI namespacemanager_reset(IMXNamespaceManager *iface)
227 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
228 return IVBMXNamespaceManager_reset(&This->IVBMXNamespaceManager_iface);
231 static HRESULT WINAPI namespacemanager_pushContext(IMXNamespaceManager *iface)
233 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
234 return IVBMXNamespaceManager_pushContext(&This->IVBMXNamespaceManager_iface);
237 static HRESULT WINAPI namespacemanager_pushNodeContext(IMXNamespaceManager *iface,
238 IXMLDOMNode *node, VARIANT_BOOL deep)
240 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
241 return IVBMXNamespaceManager_pushNodeContext(&This->IVBMXNamespaceManager_iface, node, deep);
244 static HRESULT WINAPI namespacemanager_popContext(IMXNamespaceManager *iface)
246 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
247 return IVBMXNamespaceManager_popContext(&This->IVBMXNamespaceManager_iface);
250 static HRESULT WINAPI namespacemanager_declarePrefix(IMXNamespaceManager *iface,
251 const WCHAR *prefix, const WCHAR *namespaceURI)
253 static const WCHAR xmlnsW[] = {'x','m','l','n','s',0};
255 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
257 TRACE("(%p)->(%s %s)\n", This, debugstr_w(prefix), debugstr_w(namespaceURI));
259 if (prefix && (!strcmpW(prefix, xmlW) || !strcmpW(prefix, xmlnsW) || !namespaceURI))
260 return E_INVALIDARG;
262 return declare_prefix(This, prefix, namespaceURI);
265 static HRESULT WINAPI namespacemanager_getDeclaredPrefix(IMXNamespaceManager *iface,
266 LONG index, WCHAR *prefix, int *prefix_len)
268 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
269 struct nscontext *ctxt;
270 HRESULT hr;
271 BSTR prfx;
273 TRACE("(%p)->(%d %p %p)\n", This, index, prefix, prefix_len);
275 if (!prefix_len) return E_POINTER;
277 ctxt = LIST_ENTRY(list_head(&This->ctxts), struct nscontext, entry);
278 hr = get_declared_prefix_idx(ctxt, index, &prfx);
279 if (hr != S_OK) return hr;
281 if (prefix)
283 if (*prefix_len < (INT)SysStringLen(prfx)) return E_XML_BUFFERTOOSMALL;
284 strcpyW(prefix, prfx);
287 *prefix_len = SysStringLen(prfx);
289 return S_OK;
292 static HRESULT WINAPI namespacemanager_getPrefix(IMXNamespaceManager *iface,
293 const WCHAR *uri, LONG index, WCHAR *prefix, int *prefix_len)
295 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
296 FIXME("(%p)->(%s %d %p %p): stub\n", This, debugstr_w(uri), index, prefix, prefix_len);
297 return E_NOTIMPL;
300 static HRESULT WINAPI namespacemanager_getURI(IMXNamespaceManager *iface,
301 const WCHAR *prefix, IXMLDOMNode *node, WCHAR *uri, int *uri_len)
303 namespacemanager *This = impl_from_IMXNamespaceManager( iface );
304 struct nscontext *ctxt;
305 HRESULT hr;
306 BSTR urib;
308 TRACE("(%p)->(%s %p %p %p)\n", This, debugstr_w(prefix), node, uri, uri_len);
310 if (!prefix) return E_INVALIDARG;
311 if (!uri_len) return E_POINTER;
313 if (node)
315 FIXME("namespaces from DOM node not supported\n");
316 return E_NOTIMPL;
319 ctxt = LIST_ENTRY(list_head(&This->ctxts), struct nscontext, entry);
320 hr = get_uri_from_prefix(ctxt, prefix, &urib);
321 if (hr == S_OK)
323 if (uri)
325 if (*uri_len < (INT)SysStringLen(urib)) return E_XML_BUFFERTOOSMALL;
326 strcpyW(uri, urib);
329 else
330 if (uri) *uri = 0;
332 *uri_len = SysStringLen(urib);
334 return hr;
337 static const struct IMXNamespaceManagerVtbl MXNamespaceManagerVtbl =
339 namespacemanager_QueryInterface,
340 namespacemanager_AddRef,
341 namespacemanager_Release,
342 namespacemanager_putAllowOverride,
343 namespacemanager_getAllowOverride,
344 namespacemanager_reset,
345 namespacemanager_pushContext,
346 namespacemanager_pushNodeContext,
347 namespacemanager_popContext,
348 namespacemanager_declarePrefix,
349 namespacemanager_getDeclaredPrefix,
350 namespacemanager_getPrefix,
351 namespacemanager_getURI
354 static HRESULT WINAPI vbnamespacemanager_QueryInterface(IVBMXNamespaceManager *iface, REFIID riid, void **ppvObject)
356 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
357 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
359 if ( IsEqualGUID( riid, &IID_IMXNamespaceManager) ||
360 IsEqualGUID( riid, &IID_IUnknown) )
362 *ppvObject = &This->IMXNamespaceManager_iface;
364 else if ( IsEqualGUID( riid, &IID_IVBMXNamespaceManager) ||
365 IsEqualGUID( riid, &IID_IDispatch) )
367 *ppvObject = &This->IVBMXNamespaceManager_iface;
369 else
371 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
372 *ppvObject = NULL;
373 return E_NOINTERFACE;
376 IVBMXNamespaceManager_AddRef( iface );
378 return S_OK;
381 static ULONG WINAPI vbnamespacemanager_AddRef(IVBMXNamespaceManager *iface)
383 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
384 ULONG ref = InterlockedIncrement( &This->ref );
385 TRACE("(%p)->(%u)\n", This, ref );
386 return ref;
389 static ULONG WINAPI vbnamespacemanager_Release(IVBMXNamespaceManager *iface)
391 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
392 ULONG ref = InterlockedDecrement( &This->ref );
394 TRACE("(%p)->(%u)\n", This, ref );
396 if ( ref == 0 )
398 struct nscontext *ctxt, *ctxt2;
400 LIST_FOR_EACH_ENTRY_SAFE(ctxt, ctxt2, &This->ctxts, struct nscontext, entry)
402 list_remove(&ctxt->entry);
403 free_ns_context(ctxt);
406 heap_free( This );
409 return ref;
412 static HRESULT WINAPI vbnamespacemanager_GetTypeInfoCount(IVBMXNamespaceManager *iface, UINT *pctinfo)
414 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
416 TRACE("(%p)->(%p)\n", This, pctinfo);
417 *pctinfo = 1;
419 return S_OK;
422 static HRESULT WINAPI vbnamespacemanager_GetTypeInfo(IVBMXNamespaceManager *iface, UINT iTInfo,
423 LCID lcid, ITypeInfo **ppTInfo)
425 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
427 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
429 return get_typeinfo(IVBMXNamespaceManager_tid, ppTInfo);
432 static HRESULT WINAPI vbnamespacemanager_GetIDsOfNames(IVBMXNamespaceManager *iface, REFIID riid,
433 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
435 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
436 ITypeInfo *typeinfo;
437 HRESULT hr;
439 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
440 lcid, rgDispId);
442 if(!rgszNames || cNames == 0 || !rgDispId)
443 return E_INVALIDARG;
445 hr = get_typeinfo(IVBMXNamespaceManager_tid, &typeinfo);
446 if(SUCCEEDED(hr))
448 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
449 ITypeInfo_Release(typeinfo);
452 return hr;
455 static HRESULT WINAPI vbnamespacemanager_Invoke(IVBMXNamespaceManager *iface, DISPID dispIdMember, REFIID riid,
456 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
457 EXCEPINFO *pExcepInfo, UINT *puArgErr)
459 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
460 ITypeInfo *typeinfo;
461 HRESULT hr;
463 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
464 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
466 hr = get_typeinfo(IVBMXNamespaceManager_tid, &typeinfo);
467 if(SUCCEEDED(hr))
469 hr = ITypeInfo_Invoke(typeinfo, &This->IVBMXNamespaceManager_iface, dispIdMember, wFlags,
470 pDispParams, pVarResult, pExcepInfo, puArgErr);
471 ITypeInfo_Release(typeinfo);
474 return hr;
477 static HRESULT WINAPI vbnamespacemanager_put_allowOverride(IVBMXNamespaceManager *iface,
478 VARIANT_BOOL override)
480 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
482 TRACE("(%p)->(%d)\n", This, override);
483 This->override = override;
485 return S_OK;
488 static HRESULT WINAPI vbnamespacemanager_get_allowOverride(IVBMXNamespaceManager *iface,
489 VARIANT_BOOL *override)
491 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
493 TRACE("(%p)->(%p)\n", This, override);
495 if (!override) return E_POINTER;
496 *override = This->override;
498 return S_OK;
501 static HRESULT WINAPI vbnamespacemanager_reset(IVBMXNamespaceManager *iface)
503 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
504 FIXME("(%p): stub\n", This);
505 return E_NOTIMPL;
508 static HRESULT WINAPI vbnamespacemanager_pushContext(IVBMXNamespaceManager *iface)
510 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
511 FIXME("(%p): stub\n", This);
512 return E_NOTIMPL;
515 static HRESULT WINAPI vbnamespacemanager_pushNodeContext(IVBMXNamespaceManager *iface,
516 IXMLDOMNode *node, VARIANT_BOOL deep)
518 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
519 FIXME("(%p)->(%p %d): stub\n", This, node, deep);
520 return E_NOTIMPL;
523 static HRESULT WINAPI vbnamespacemanager_popContext(IVBMXNamespaceManager *iface)
525 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
526 FIXME("(%p): stub\n", This);
527 return E_NOTIMPL;
530 static HRESULT WINAPI vbnamespacemanager_declarePrefix(IVBMXNamespaceManager *iface,
531 BSTR prefix, BSTR namespaceURI)
533 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
534 return IMXNamespaceManager_declarePrefix(&This->IMXNamespaceManager_iface, prefix, namespaceURI);
537 static HRESULT WINAPI vbnamespacemanager_getDeclaredPrefixes(IVBMXNamespaceManager *iface,
538 IMXNamespacePrefixes** prefixes)
540 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
541 FIXME("(%p)->(%p): stub\n", This, prefixes);
542 return E_NOTIMPL;
545 static HRESULT WINAPI vbnamespacemanager_getPrefixes(IVBMXNamespaceManager *iface,
546 BSTR namespaceURI, IMXNamespacePrefixes** prefixes)
548 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
549 FIXME("(%p)->(%s %p): stub\n", This, debugstr_w(namespaceURI), prefixes);
550 return E_NOTIMPL;
553 static HRESULT WINAPI vbnamespacemanager_getURI(IVBMXNamespaceManager *iface,
554 BSTR prefix, VARIANT* uri)
556 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
557 FIXME("(%p)->(%s %p): stub\n", This, debugstr_w(prefix), uri);
558 return E_NOTIMPL;
561 static HRESULT WINAPI vbnamespacemanager_getURIFromNode(IVBMXNamespaceManager *iface,
562 BSTR prefix, IXMLDOMNode *node, VARIANT *uri)
564 namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
565 FIXME("(%p)->(%s %p %p): stub\n", This, debugstr_w(prefix), node, uri);
566 return E_NOTIMPL;
569 static const struct IVBMXNamespaceManagerVtbl VBMXNamespaceManagerVtbl =
571 vbnamespacemanager_QueryInterface,
572 vbnamespacemanager_AddRef,
573 vbnamespacemanager_Release,
574 vbnamespacemanager_GetTypeInfoCount,
575 vbnamespacemanager_GetTypeInfo,
576 vbnamespacemanager_GetIDsOfNames,
577 vbnamespacemanager_Invoke,
578 vbnamespacemanager_put_allowOverride,
579 vbnamespacemanager_get_allowOverride,
580 vbnamespacemanager_reset,
581 vbnamespacemanager_pushContext,
582 vbnamespacemanager_pushNodeContext,
583 vbnamespacemanager_popContext,
584 vbnamespacemanager_declarePrefix,
585 vbnamespacemanager_getDeclaredPrefixes,
586 vbnamespacemanager_getPrefixes,
587 vbnamespacemanager_getURI,
588 vbnamespacemanager_getURIFromNode
591 HRESULT MXNamespaceManager_create(IUnknown *outer, void **obj)
593 namespacemanager *ns;
594 struct nscontext *ctxt;
596 TRACE("(%p, %p)\n", outer, obj);
598 ns = heap_alloc( sizeof (*ns) );
599 if( !ns )
600 return E_OUTOFMEMORY;
602 ns->IMXNamespaceManager_iface.lpVtbl = &MXNamespaceManagerVtbl;
603 ns->IVBMXNamespaceManager_iface.lpVtbl = &VBMXNamespaceManagerVtbl;
604 ns->ref = 1;
606 list_init(&ns->ctxts);
607 ctxt = alloc_ns_context();
608 list_add_head(&ns->ctxts, &ctxt->entry);
610 ns->override = VARIANT_TRUE;
612 *obj = &ns->IMXNamespaceManager_iface;
614 TRACE("returning iface %p\n", *obj);
616 return S_OK;