ReactOS 0.4.16-dev-2208-g6350669
nodelist.c
Go to the documentation of this file.
1/*
2 * Node list implementation
3 *
4 * Copyright 2005 Mike McCormack
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#define COBJMACROS
22
23#include <stdarg.h>
24#include <libxml/parser.h>
25#include <libxml/xmlerror.h>
26
27#include "windef.h"
28#include "winbase.h"
29#include "winuser.h"
30#include "ole2.h"
31#include "msxml6.h"
32#include "msxml2did.h"
33
34#include "msxml_private.h"
35
36#include "wine/debug.h"
37
38/* This file implements the object returned by childNodes property. Note that this is
39 * not the IXMLDOMNodeList returned by XPath queries - it's implemented in selection.c.
40 * They are different because the list returned by childNodes:
41 * - is "live" - changes to the XML tree are automatically reflected in the list
42 * - doesn't supports IXMLDOMSelection
43 * - note that an attribute node have a text child in DOM but not in the XPath data model
44 * thus the child is inaccessible by an XPath query
45 */
46
48
49typedef struct
50{
54 xmlNodePtr parent;
55 xmlNodePtr current;
58
60{
62 return IXMLDOMNodeList_get_item((IXMLDOMNodeList*)iface, index, (IXMLDOMNode**)&V_DISPATCH(item));
63}
64
67 NULL
68};
69
71{
72 return CONTAINING_RECORD(iface, xmlnodelist, IXMLDOMNodeList_iface);
73}
74
76 IXMLDOMNodeList *iface,
78 void** ppvObject )
79{
81
82 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
83
84#ifdef __REACTOS__
85 if (!ppvObject)
86 {
87 /* NOTE: Interface documentation for IUnknown explicitly states
88 * this case should return E_POINTER. Empirical data proves
89 * MS violates this contract and instead return E_INVALIDARG.
90 */
91 return E_INVALIDARG;
92 }
93#endif
94
95 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
97 IsEqualGUID( riid, &IID_IXMLDOMNodeList ) )
98 {
99 *ppvObject = iface;
100 }
101 else if (IsEqualGUID( riid, &IID_IEnumVARIANT ))
102 {
103 if (!This->enumvariant)
104 {
106 if (FAILED(hr)) return hr;
107 }
108
109 return IEnumVARIANT_QueryInterface(This->enumvariant, &IID_IEnumVARIANT, ppvObject);
110 }
111 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
112 {
113 return *ppvObject ? S_OK : E_NOINTERFACE;
114 }
115 else
116 {
117 TRACE("interface %s not implemented\n", debugstr_guid(riid));
118 *ppvObject = NULL;
119 return E_NOINTERFACE;
120 }
121
122 IXMLDOMNodeList_AddRef( iface );
123
124 return S_OK;
125}
126
128 IXMLDOMNodeList *iface )
129{
132 TRACE("%p, refcount %lu.\n", iface, ref);
133 return ref;
134}
135
137 IXMLDOMNodeList *iface )
138{
141
142 TRACE("%p, refcount %lu.\n", iface, ref);
143
144 if (!ref)
145 {
146 xmldoc_release( This->parent->doc );
147 if (This->enumvariant) IEnumVARIANT_Release(This->enumvariant);
148 free( This );
149 }
150
151 return ref;
152}
153
155 IXMLDOMNodeList *iface,
156 UINT* pctinfo )
157{
159 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
160}
161
163 IXMLDOMNodeList *iface,
164 UINT iTInfo,
165 LCID lcid,
166 ITypeInfo** ppTInfo )
167{
169 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
170 iTInfo, lcid, ppTInfo);
171}
172
174 IXMLDOMNodeList *iface,
175 REFIID riid,
176 LPOLESTR* rgszNames,
177 UINT cNames,
178 LCID lcid,
179 DISPID* rgDispId )
180{
182 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
183 riid, rgszNames, cNames, lcid, rgDispId);
184}
185
187 IXMLDOMNodeList *iface,
188 DISPID dispIdMember,
189 REFIID riid,
190 LCID lcid,
191 WORD wFlags,
192 DISPPARAMS* pDispParams,
193 VARIANT* pVarResult,
194 EXCEPINFO* pExcepInfo,
195 UINT* puArgErr )
196{
198 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
199 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
200}
201
203 IXMLDOMNodeList* iface,
204 LONG index,
205 IXMLDOMNode** listItem)
206{
208 xmlNodePtr curr;
209 LONG nodeIndex = 0;
210
211 TRACE("%p, %ld, %p.\n", iface, index, listItem);
212
213 if(!listItem)
214 return E_INVALIDARG;
215
216 *listItem = NULL;
217
218 if (index < 0)
219 return S_FALSE;
220
221 curr = This->parent->children;
222 while(curr)
223 {
224 if(nodeIndex++ == index) break;
225 curr = curr->next;
226 }
227 if(!curr) return S_FALSE;
228
229 *listItem = create_node( curr );
230
231 return S_OK;
232}
233
235 IXMLDOMNodeList* iface,
236 LONG* listLength)
237{
238
239 xmlNodePtr curr;
240 LONG nodeCount = 0;
241
243
244 TRACE("(%p)->(%p)\n", This, listLength);
245
246 if(!listLength)
247 return E_INVALIDARG;
248
249 curr = This->parent->children;
250 while (curr)
251 {
252 nodeCount++;
253 curr = curr->next;
254 }
255
256 *listLength = nodeCount;
257 return S_OK;
258}
259
261 IXMLDOMNodeList* iface,
262 IXMLDOMNode** nextItem)
263{
265
266 TRACE("(%p)->(%p)\n", This, nextItem );
267
268 if(!nextItem)
269 return E_INVALIDARG;
270
271 *nextItem = NULL;
272
273 if (!This->current)
274 return S_FALSE;
275
276 *nextItem = create_node( This->current );
277 This->current = This->current->next;
278 return S_OK;
279}
280
282 IXMLDOMNodeList* iface)
283{
285
286 TRACE("%p\n", This);
287 This->current = This->parent->children;
288 return S_OK;
289}
290
292 IXMLDOMNodeList* iface,
293 IUnknown** enumv)
294{
296 TRACE("(%p)->(%p)\n", This, enumv);
298}
299
300static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl =
301{
314};
315
317{
318 WCHAR *ptr;
319 int idx = 0;
320
321 for(ptr = name; *ptr >= '0' && *ptr <= '9'; ptr++)
322 idx = idx*10 + (*ptr-'0');
323 if(*ptr)
324 return DISP_E_UNKNOWNNAME;
325
327 TRACE("ret %lx\n", *dispid);
328 return S_OK;
329}
330
332 VARIANT *res, EXCEPINFO *ei)
333{
335
336 TRACE("%p, %ld, %lx, %x, %p, %p, %p.\n", iface, id, lcid, flags, params, res, ei);
337
339 {
340 switch(flags)
341 {
343 {
344 IXMLDOMNode *disp = NULL;
345
347 IXMLDOMNodeList_get_item(&This->IXMLDOMNodeList_iface, id - DISPID_DOM_COLLECTION_BASE, &disp);
348 V_DISPATCH(res) = (IDispatch*)disp;
349 break;
350 }
351 default:
352 {
353 FIXME("unimplemented flags %x\n", flags);
354 break;
355 }
356 }
357 }
358 else if (id == DISPID_VALUE)
359 {
360 switch(flags)
361 {
364 case DISPATCH_METHOD:
365 {
368 HRESULT hr;
369
370 if (params->cArgs - params->cNamedArgs != 1) return DISP_E_BADPARAMCOUNT;
371
373 hr = VariantChangeType(&index, params->rgvarg, 0, VT_I4);
374 if(FAILED(hr))
375 {
376 FIXME("failed to convert arg, %s\n", debugstr_variant(params->rgvarg));
377 return hr;
378 }
379
380 IXMLDOMNodeList_get_item(&This->IXMLDOMNodeList_iface, V_I4(&index), &item);
383 break;
384 }
385 default:
386 {
387 FIXME("DISPID_VALUE: unimplemented flags %x\n", flags);
388 break;
389 }
390 }
391 }
392 else
393 return DISP_E_UNKNOWNNAME;
394
395 TRACE("ret %p\n", V_DISPATCH(res));
396
397 return S_OK;
398}
399
403};
404
407 0
408};
412 NULL,
414};
415
417{
419
420 This = malloc(sizeof(*This));
421 if ( !This )
422 return NULL;
423
424 This->IXMLDOMNodeList_iface.lpVtbl = &xmlnodelist_vtbl;
425 This->ref = 1;
426 This->parent = node;
427 This->current = node->children;
428 This->enumvariant = NULL;
429 xmldoc_add_ref( node->doc );
430
431 init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMNodeList_iface, &xmlnodelist_dispex);
432
433 return &This->IXMLDOMNodeList_iface;
434}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define index(s, c)
Definition: various.h:29
#define FIXME(fmt,...)
Definition: precomp.h:53
const GUID IID_IUnknown
#define E_INVALIDARG
Definition: ddrawi.h:101
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:41
OLECHAR * BSTR
Definition: compat.h:2293
@ VT_I4
Definition: compat.h:2298
@ VT_DISPATCH
Definition: compat.h:2304
LCID lcid
Definition: locale.c:5656
LONG xmldoc_release(xmlDocPtr doc)
Definition: domdoc.c:653
LONG xmldoc_add_ref(xmlDocPtr doc)
Definition: domdoc.c:619
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint res
Definition: glext.h:9613
GLuint index
Definition: glext.h:6031
GLenum const GLfloat * params
Definition: glext.h:5645
GLbitfield flags
Definition: glext.h:7161
static HRESULT create_node(HTMLDocumentNode *, nsIDOMNode *, HTMLDOMNode **)
Definition: htmlnode.c:1216
tid_t
Definition: ieframe.h:311
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:919
#define debugstr_guid
Definition: kernel32.h:35
static PVOID ptr
Definition: dispmode.c:27
static const char * debugstr_variant(const VARIANT *var)
Definition: container.c:46
static LPOLESTR
Definition: stg_prop.c:27
static VARIANTARG static DISPID
Definition: ordinal.c:49
BOOL dispex_query_interface(DispatchEx *This, REFIID riid, void **ppv)
Definition: dispex.c:1656
#define DISPID_DOM_COLLECTION_MAX
Definition: msxml2did.h:71
#define DISPID_DOM_COLLECTION_BASE
Definition: msxml2did.h:70
@ IXMLDOMNodeList_tid
Definition: msxml_dispex.h:52
HRESULT create_enumvariant(IUnknown *, BOOL, const struct enumvariant_funcs *, IEnumVARIANT **)
Definition: selection.c:565
unsigned int UINT
Definition: ndis.h:50
static HRESULT WINAPI xmlnodelist_GetTypeInfoCount(IXMLDOMNodeList *iface, UINT *pctinfo)
Definition: nodelist.c:154
static HRESULT WINAPI xmlnodelist_get_item(IXMLDOMNodeList *iface, LONG index, IXMLDOMNode **listItem)
Definition: nodelist.c:202
static HRESULT WINAPI xmlnodelist_nextNode(IXMLDOMNodeList *iface, IXMLDOMNode **nextItem)
Definition: nodelist.c:260
static const tid_t xmlnodelist_iface_tids[]
Definition: nodelist.c:405
static ULONG WINAPI xmlnodelist_AddRef(IXMLDOMNodeList *iface)
Definition: nodelist.c:127
static HRESULT WINAPI xmlnodelist_QueryInterface(IXMLDOMNodeList *iface, REFIID riid, void **ppvObject)
Definition: nodelist.c:75
static const struct enumvariant_funcs nodelist_enumvariant
Definition: nodelist.c:65
static dispex_static_data_t xmlnodelist_dispex
Definition: nodelist.c:409
static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl
Definition: nodelist.c:300
static HRESULT xmlnodelist_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
Definition: nodelist.c:316
static HRESULT WINAPI xmlnodelist_GetTypeInfo(IXMLDOMNodeList *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: nodelist.c:162
static HRESULT WINAPI xmlnodelist_Invoke(IXMLDOMNodeList *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
Definition: nodelist.c:186
static HRESULT xmlnodelist_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei)
Definition: nodelist.c:331
static HRESULT WINAPI xmlnodelist_reset(IXMLDOMNodeList *iface)
Definition: nodelist.c:281
static ULONG WINAPI xmlnodelist_Release(IXMLDOMNodeList *iface)
Definition: nodelist.c:136
static HRESULT WINAPI xmlnodelist_get_length(IXMLDOMNodeList *iface, LONG *listLength)
Definition: nodelist.c:234
static HRESULT WINAPI xmlnodelist_GetIDsOfNames(IXMLDOMNodeList *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: nodelist.c:173
IXMLDOMNodeList * create_children_nodelist(xmlNodePtr node)
Definition: nodelist.c:416
static HRESULT nodelist_get_item(IUnknown *iface, LONG index, VARIANT *item)
Definition: nodelist.c:59
static xmlnodelist * impl_from_IXMLDOMNodeList(IXMLDOMNodeList *iface)
Definition: nodelist.c:70
static HRESULT WINAPI xmlnodelist__newEnum(IXMLDOMNodeList *iface, IUnknown **enumv)
Definition: nodelist.c:291
static const dispex_static_data_vtbl_t xmlnodelist_dispex_vtbl
Definition: nodelist.c:400
#define DISPATCH_METHOD
Definition: oleauto.h:1006
#define V_VT(A)
Definition: oleauto.h:211
#define V_I4(A)
Definition: oleauto.h:247
#define V_DISPATCH(A)
Definition: oleauto.h:239
#define DISPATCH_PROPERTYGET
Definition: oleauto.h:1007
const GUID IID_IDispatch
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
DWORD LCID
Definition: nls.h:13
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
Definition: name.c:39
Definition: send.c:48
DispatchEx dispex
Definition: nodelist.c:51
IEnumVARIANT * enumvariant
Definition: nodelist.c:56
xmlNodePtr parent
Definition: nodelist.c:54
IXMLDOMNodeList IXMLDOMNodeList_iface
Definition: nodelist.c:52
xmlNodePtr current
Definition: nodelist.c:55
LONG ref
Definition: nodelist.c:53
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
Definition: dlist.c:348
HRESULT WINAPI DECLSPEC_HOTPATCH VariantChangeType(VARIANTARG *pvargDest, VARIANTARG *pvargSrc, USHORT wFlags, VARTYPE vt)
Definition: variant.c:962
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:568
WINBASEAPI _In_ DWORD _Out_ _In_ WORD wFlags
Definition: wincon_undoc.h:337
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:3451
#define E_NOINTERFACE
Definition: winerror.h:3479
#define DISP_E_BADPARAMCOUNT
Definition: winerror.h:3626
#define DISP_E_UNKNOWNNAME
Definition: winerror.h:3618
__wchar_t WCHAR
Definition: xmlstorage.h:180