ReactOS 0.4.15-dev-7788-g1ad9096
propbag.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include "mshtml_private.h"
20
21typedef struct {
24
26
27 struct list props;
29
30typedef struct {
31 struct list entry;
35
36static void free_prop(param_prop_t *prop)
37{
38 list_remove(&prop->entry);
39
40 heap_free(prop->name);
41 heap_free(prop->value);
42 heap_free(prop);
43}
44
45static param_prop_t *find_prop(PropertyBag *prop_bag, const WCHAR *name)
46{
47 param_prop_t *iter;
48
49 LIST_FOR_EACH_ENTRY(iter, &prop_bag->props, param_prop_t, entry) {
50 if(!strcmpiW(iter->name, name))
51 return iter;
52 }
53
54 return NULL;
55}
56
57static HRESULT add_prop(PropertyBag *prop_bag, const WCHAR *name, const WCHAR *value)
58{
59 param_prop_t *prop;
60
61 if(!name || !value)
62 return S_OK;
63
64 TRACE("%p %s %s\n", prop_bag, debugstr_w(name), debugstr_w(value));
65
66 prop = heap_alloc(sizeof(*prop));
67 if(!prop)
68 return E_OUTOFMEMORY;
69
70 prop->name = heap_strdupW(name);
71 prop->value = heap_strdupW(value);
72 if(!prop->name || !prop->value) {
73 list_init(&prop->entry);
74 free_prop(prop);
75 return E_OUTOFMEMORY;
76 }
77
78 list_add_tail(&prop_bag->props, &prop->entry);
79 return S_OK;
80}
81
83{
84 return CONTAINING_RECORD(iface, PropertyBag, IPropertyBag_iface);
85}
86
88{
90
92 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
93 *ppv = &This->IPropertyBag_iface;
94 }else if(IsEqualGUID(&IID_IPropertyBag, riid)) {
95 TRACE("(%p)->(IID_IPropertyBag %p)\n", This, ppv);
96 *ppv = &This->IPropertyBag_iface;
97 }else if(IsEqualGUID(&IID_IPropertyBag2, riid)) {
98 TRACE("(%p)->(IID_IPropertyBag2 %p)\n", This, ppv);
99 *ppv = &This->IPropertyBag2_iface;
100 }else {
101 WARN("Unsopported interface %s\n", debugstr_guid(riid));
102 *ppv = NULL;
103 return E_NOINTERFACE;
104 }
105
106 IUnknown_AddRef((IUnknown*)*ppv);
107 return S_OK;
108}
109
111{
114
115 TRACE("(%p) ref=%d\n", This, ref);
116
117 return ref;
118}
119
121{
124
125 TRACE("(%p) ref=%d\n", This, ref);
126
127 if(!ref) {
128 while(!list_empty(&This->props))
131 }
132
133 return ref;
134}
135
136static HRESULT WINAPI PropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName, VARIANT *pVar, IErrorLog *pErrorLog)
137{
139 param_prop_t *prop;
140 VARIANT v;
141
142 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(pszPropName), pVar, pErrorLog);
143
144 prop = find_prop(This, pszPropName);
145 if(!prop) {
146 TRACE("Not found\n");
147 return E_INVALIDARG;
148 }
149
150 V_BSTR(&v) = SysAllocString(prop->value);
151 if(!V_BSTR(&v))
152 return E_OUTOFMEMORY;
153
154 if(V_VT(pVar) != VT_BSTR) {
156
157 V_VT(&v) = VT_BSTR;
158 hres = VariantChangeType(pVar, &v, 0, V_VT(pVar));
160 return hres;
161 }
162
163 V_BSTR(pVar) = V_BSTR(&v);
164 return S_OK;
165}
166
167static HRESULT WINAPI PropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName, VARIANT *pVar)
168{
170 FIXME("(%p)->(%s %s)\n", This, debugstr_w(pszPropName), debugstr_variant(pVar));
171 return E_NOTIMPL;
172}
173
174static const IPropertyBagVtbl PropertyBagVtbl = {
180};
181
183{
184 return CONTAINING_RECORD(iface, PropertyBag, IPropertyBag2_iface);
185}
186
188{
190 return IPropertyBag_QueryInterface(&This->IPropertyBag_iface, riid, ppv);
191}
192
194{
196 return IPropertyBag_AddRef(&This->IPropertyBag_iface);
197}
198
200{
202 return IPropertyBag_Release(&This->IPropertyBag_iface);
203}
204
205static HRESULT WINAPI PropertyBag2_Read(IPropertyBag2 *iface, ULONG cProperties, PROPBAG2 *pPropBag,
206 IErrorLog *pErrLog, VARIANT *pvarValue, HRESULT *phrError)
207{
209 FIXME("(%p)->(%d %p %p %p %p)\n", This, cProperties, pPropBag, pErrLog, pvarValue, phrError);
210 return E_NOTIMPL;
211}
212
213static HRESULT WINAPI PropertyBag2_Write(IPropertyBag2 *iface, ULONG cProperties, PROPBAG2 *pPropBag, VARIANT *pvarValue)
214{
216 FIXME("(%p)->(%d %p %s)\n", This, cProperties, pPropBag, debugstr_variant(pvarValue));
217 return E_NOTIMPL;
218}
219
221{
223 FIXME("(%p)->(%p)\n", This, pcProperties);
224 return E_NOTIMPL;
225}
226
228 PROPBAG2 *pPropBag, ULONG *pcProperties)
229{
231 FIXME("(%p)->(%u %u %p %p)\n", This, iProperty, cProperties, pPropBag, pcProperties);
232 return E_NOTIMPL;
233}
234
235static HRESULT WINAPI PropertyBag2_LoadObject(IPropertyBag2 *iface, LPCOLESTR pstrName, DWORD dwHint,
236 IUnknown *pUnkObject, IErrorLog *pErrLog)
237{
239 FIXME("(%p)->(%s %x %p %p)\n", This, debugstr_w(pstrName), dwHint, pUnkObject, pErrLog);
240 return E_NOTIMPL;
241}
242
243static const IPropertyBag2Vtbl PropertyBag2Vtbl = {
252};
253
255{
256 const PRUnichar *name, *value;
257 nsAString name_str, value_str;
259 nsIDOMHTMLElement *param_elem;
260 UINT32 length, i;
261 nsIDOMNode *nsnode;
262 nsresult nsres;
263 HRESULT hres = S_OK;
264
265 static const PRUnichar nameW[] = {'n','a','m','e',0};
266 static const PRUnichar paramW[] = {'p','a','r','a','m',0};
267 static const PRUnichar valueW[] = {'v','a','l','u','e',0};
268
269 nsAString_InitDepend(&name_str, paramW);
270 nsres = nsIDOMHTMLElement_GetElementsByTagName(nselem, &name_str, &params);
271 nsAString_Finish(&name_str);
272 if(NS_FAILED(nsres))
273 return E_FAIL;
274
275 nsres = nsIDOMHTMLCollection_GetLength(params, &length);
276 if(NS_FAILED(nsres))
277 length = 0;
278
279 for(i=0; i < length; i++) {
280 nsres = nsIDOMHTMLCollection_Item(params, i, &nsnode);
281 if(NS_FAILED(nsres)) {
282 hres = E_FAIL;
283 break;
284 }
285
286 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&param_elem);
287 nsIDOMNode_Release(nsnode);
288 if(NS_FAILED(nsres)) {
289 hres = E_FAIL;
290 break;
291 }
292
293 nsres = get_elem_attr_value(param_elem, nameW, &name_str, &name);
294 if(NS_SUCCEEDED(nsres)) {
295 nsres = get_elem_attr_value(param_elem, valueW, &value_str, &value);
296 if(NS_SUCCEEDED(nsres)) {
297 hres = add_prop(prop_bag, name, value);
299 }
300
301 nsAString_Finish(&name_str);
302 }
303
304 nsIDOMHTMLElement_Release(param_elem);
305 if(FAILED(hres))
306 break;
307 if(NS_FAILED(nsres)) {
308 hres = E_FAIL;
309 break;
310 }
311 }
312
313 nsIDOMHTMLCollection_Release(params);
314 return hres;
315}
316
318{
319 PropertyBag *prop_bag;
321
322 prop_bag = heap_alloc(sizeof(*prop_bag));
323 if(!prop_bag)
324 return E_OUTOFMEMORY;
325
326 prop_bag->IPropertyBag_iface.lpVtbl = &PropertyBagVtbl;
327 prop_bag->IPropertyBag2_iface.lpVtbl = &PropertyBag2Vtbl;
328 prop_bag->ref = 1;
329
330 list_init(&prop_bag->props);
331 hres = fill_props(nselem, prop_bag);
332 if(FAILED(hres) || list_empty(&prop_bag->props)) {
333 IPropertyBag_Release(&prop_bag->IPropertyBag_iface);
334 *ret = NULL;
335 return hres;
336 }
337
338 *ret = &prop_bag->IPropertyBag_iface;
339 return S_OK;
340}
unsigned int UINT32
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
static const WCHAR nameW[]
Definition: main.c:46
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static int list_empty(struct list_entry *head)
Definition: list.h:58
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
static void list_init(struct list_entry *head)
Definition: list.h:51
const GUID IID_IUnknown
#define FIXME(fmt,...)
Definition: debug.h:111
#define WARN(fmt,...)
Definition: debug.h:112
Definition: list.h:37
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
@ VT_BSTR
Definition: compat.h:2303
static const WCHAR valueW[]
Definition: object.c:48
unsigned long DWORD
Definition: ntddk_ex.h:95
const GLdouble * v
Definition: gl.h:2040
GLenum const GLfloat * params
Definition: glext.h:5645
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
nsresult get_elem_attr_value(nsIDOMHTMLElement *nselem, const WCHAR *name, nsAString *val_str, const PRUnichar **val)
Definition: htmlelem.c:143
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
uint32_t entry
Definition: isohybrid.c:63
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_w
Definition: kernel32.h:32
static const char * debugstr_variant(const VARIANT *var)
Definition: container.c:46
HRESULT hres
Definition: protocol.c:465
static UNICODE_STRING value_str
Definition: reg.c:1328
void nsAString_Finish(nsAString *) DECLSPEC_HIDDEN
Definition: nsembed.c:836
void nsAString_InitDepend(nsAString *, const PRUnichar *) DECLSPEC_HIDDEN
Definition: nsembed.c:826
#define NS_SUCCEEDED(res)
#define NS_FAILED(res)
WCHAR PRUnichar
Definition: nsiface.idl:48
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
#define V_VT(A)
Definition: oleauto.h:211
#define V_BSTR(A)
Definition: oleauto.h:226
const GUID IID_IPropertyBag
long LONG
Definition: pedump.c:60
static const IPropertyBagVtbl PropertyBagVtbl
Definition: propbag.c:174
static HRESULT WINAPI PropertyBag2_CountProperties(IPropertyBag2 *iface, ULONG *pcProperties)
Definition: propbag.c:220
static HRESULT WINAPI PropertyBag2_Write(IPropertyBag2 *iface, ULONG cProperties, PROPBAG2 *pPropBag, VARIANT *pvarValue)
Definition: propbag.c:213
static const IPropertyBag2Vtbl PropertyBag2Vtbl
Definition: propbag.c:243
static HRESULT WINAPI PropertyBag2_QueryInterface(IPropertyBag2 *iface, REFIID riid, void **ppv)
Definition: propbag.c:187
static HRESULT WINAPI PropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName, VARIANT *pVar)
Definition: propbag.c:167
static ULONG WINAPI PropertyBag_Release(IPropertyBag *iface)
Definition: propbag.c:120
static PropertyBag * impl_from_IPropertyBag2(IPropertyBag2 *iface)
Definition: propbag.c:182
static HRESULT add_prop(PropertyBag *prop_bag, const WCHAR *name, const WCHAR *value)
Definition: propbag.c:57
static HRESULT fill_props(nsIDOMHTMLElement *nselem, PropertyBag *prop_bag)
Definition: propbag.c:254
static HRESULT WINAPI PropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid, void **ppv)
Definition: propbag.c:87
static ULONG WINAPI PropertyBag2_AddRef(IPropertyBag2 *iface)
Definition: propbag.c:193
static PropertyBag * impl_from_IPropertyBag(IPropertyBag *iface)
Definition: propbag.c:82
static ULONG WINAPI PropertyBag_AddRef(IPropertyBag *iface)
Definition: propbag.c:110
static ULONG WINAPI PropertyBag2_Release(IPropertyBag2 *iface)
Definition: propbag.c:199
static HRESULT WINAPI PropertyBag2_Read(IPropertyBag2 *iface, ULONG cProperties, PROPBAG2 *pPropBag, IErrorLog *pErrLog, VARIANT *pvarValue, HRESULT *phrError)
Definition: propbag.c:205
static HRESULT WINAPI PropertyBag2_GetPropertyInfo(IPropertyBag2 *iface, ULONG iProperty, ULONG cProperties, PROPBAG2 *pPropBag, ULONG *pcProperties)
Definition: propbag.c:227
static HRESULT WINAPI PropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName, VARIANT *pVar, IErrorLog *pErrorLog)
Definition: propbag.c:136
HRESULT create_param_prop_bag(nsIDOMHTMLElement *nselem, IPropertyBag **ret)
Definition: propbag.c:317
static HRESULT WINAPI PropertyBag2_LoadObject(IPropertyBag2 *iface, LPCOLESTR pstrName, DWORD dwHint, IUnknown *pUnkObject, IErrorLog *pErrLog)
Definition: propbag.c:235
static void free_prop(param_prop_t *prop)
Definition: propbag.c:36
static param_prop_t * find_prop(PropertyBag *prop_bag, const WCHAR *name)
Definition: propbag.c:45
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define strcmpiW(s1, s2)
Definition: unicode.h:39
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define TRACE(s)
Definition: solgame.cpp:4
struct list props
Definition: propbag.c:27
LONG ref
Definition: propbag.c:25
IPropertyBag2 IPropertyBag2_iface
Definition: propbag.c:23
IPropertyBag IPropertyBag_iface
Definition: propbag.c:22
Definition: name.c:39
struct list entry
Definition: propbag.c:31
WCHAR * value
Definition: propbag.c:33
WCHAR * name
Definition: propbag.c:32
Definition: send.c:48
#define LIST_ENTRY(type)
Definition: queue.h:175
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
Definition: pdh_main.c:94
HRESULT WINAPI DECLSPEC_HOTPATCH VariantChangeType(VARIANTARG *pvargDest, VARIANTARG *pvargSrc, USHORT wFlags, VARTYPE vt)
Definition: variant.c:962
static const WCHAR props[]
Definition: wbemdisp.c:288
int ret
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364
__wchar_t WCHAR
Definition: xmlstorage.h:180