ReactOS  0.4.13-dev-651-g5dbc677
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 
21 typedef struct {
24 
26 
27  struct list props;
28 } PropertyBag;
29 
30 typedef struct {
31  struct list entry;
34 } param_prop_t;
35 
36 static 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 
45 static 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 
57 static 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))
129  free_prop(LIST_ENTRY(This->props.next, param_prop_t, entry));
130  heap_free(This);
131  }
132 
133  return ref;
134 }
135 
136 static 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) {
155  HRESULT hres;
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 
167 static 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 
174 static 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 
205 static 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 
213 static 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 
227 static HRESULT WINAPI PropertyBag2_GetPropertyInfo(IPropertyBag2 *iface, ULONG iProperty, ULONG cProperties,
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 
235 static 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 
243 static 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;
320  HRESULT hres;
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 }
static void free_prop(param_prop_t *prop)
Definition: propbag.c:36
IPropertyBag2 IPropertyBag2_iface
Definition: propbag.c:23
struct list props
Definition: propbag.c:27
HRESULT WINAPI DECLSPEC_HOTPATCH VariantChangeType(VARIANTARG *pvargDest, VARIANTARG *pvargSrc, USHORT wFlags, VARTYPE vt)
Definition: variant.c:965
#define REFIID
Definition: guiddef.h:113
#define E_NOINTERFACE
Definition: winerror.h:2364
static HRESULT fill_props(nsIDOMHTMLElement *nselem, PropertyBag *prop_bag)
Definition: propbag.c:254
static const IPropertyBag2Vtbl PropertyBag2Vtbl
Definition: propbag.c:243
REFIID riid
Definition: precomp.h:44
#define WARN(fmt,...)
Definition: debug.h:111
HRESULT create_param_prop_bag(nsIDOMHTMLElement *nselem, IPropertyBag **ret)
Definition: propbag.c:317
REFIID LPVOID * ppv
Definition: atlbase.h:39
static ULONG WINAPI PropertyBag2_Release(IPropertyBag2 *iface)
Definition: propbag.c:199
nsresult get_elem_attr_value(nsIDOMHTMLElement *nselem, const WCHAR *name, nsAString *val_str, const PRUnichar **val)
Definition: htmlelem.c:143
static ULONG WINAPI PropertyBag_AddRef(IPropertyBag *iface)
Definition: propbag.c:110
static HRESULT add_prop(PropertyBag *prop_bag, const WCHAR *name, const WCHAR *value)
Definition: propbag.c:57
#define E_FAIL
Definition: ddrawi.h:102
Definition: send.c:47
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static ULONG WINAPI PropertyBag_Release(IPropertyBag *iface)
Definition: propbag.c:120
__WINE_SERVER_LIST_INLINE void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:102
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
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
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
GLenum const GLfloat * params
Definition: glext.h:5645
unsigned int UINT32
static HRESULT WINAPI PropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName, VARIANT *pVar)
Definition: propbag.c:167
long LONG
Definition: pedump.c:60
static ULONG WINAPI PropertyBag2_AddRef(IPropertyBag2 *iface)
Definition: propbag.c:193
static param_prop_t * find_prop(PropertyBag *prop_bag, const WCHAR *name)
Definition: propbag.c:45
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
#define debugstr_w
Definition: kernel32.h:32
WCHAR * value
Definition: propbag.c:33
static const IPropertyBagVtbl PropertyBagVtbl
Definition: propbag.c:174
GLenum GLint ref
Definition: glext.h:6028
#define FIXME(fmt,...)
Definition: debug.h:110
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
const GUID IID_IPropertyBag
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:241
static const WCHAR valueW[]
Definition: object.c:45
#define debugstr_guid
Definition: kernel32.h:35
struct PropertyBag PropertyBag
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define NS_FAILED(res)
static const WCHAR nameW[]
Definition: main.c:46
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
#define TRACE(s)
Definition: solgame.cpp:4
static HRESULT WINAPI PropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName, VARIANT *pVar, IErrorLog *pErrorLog)
Definition: propbag.c:136
LONG ref
Definition: propbag.c:25
HRESULT hres
Definition: protocol.c:465
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
const GUID IID_IUnknown
static HRESULT WINAPI PropertyBag2_Read(IPropertyBag2 *iface, ULONG cProperties, PROPBAG2 *pPropBag, IErrorLog *pErrLog, VARIANT *pvarValue, HRESULT *phrError)
Definition: propbag.c:205
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
static HRESULT WINAPI PropertyBag2_LoadObject(IPropertyBag2 *iface, LPCOLESTR pstrName, DWORD dwHint, IUnknown *pUnkObject, IErrorLog *pErrLog)
Definition: propbag.c:235
#define NS_SUCCEEDED(res)
IPropertyBag IPropertyBag_iface
Definition: propbag.c:22
struct list entry
Definition: propbag.c:31
int ret
#define InterlockedDecrement
Definition: armddk.h:52
#define V_VT(A)
Definition: oleauto.h:211
uint32_t entry
Definition: isohybrid.c:63
Definition: _list.h:228
GLsizei const GLfloat * value
Definition: glext.h:6069
#define V_BSTR(A)
Definition: oleauto.h:226
static HRESULT WINAPI PropertyBag2_CountProperties(IPropertyBag2 *iface, ULONG *pcProperties)
Definition: propbag.c:220
#define strcmpiW(s1, s2)
Definition: unicode.h:39
__WINE_SERVER_LIST_INLINE int list_empty(const struct list *list)
Definition: list.h:143
static const char * debugstr_variant(const VARIANT *var)
Definition: container.c:46
#define S_OK
Definition: intsafe.h:59
static UNICODE_STRING value_str
Definition: reg.c:1328
#define InterlockedIncrement
Definition: armddk.h:53
const GLdouble * v
Definition: gl.h:2040
#define E_NOTIMPL
Definition: ddrawi.h:99
void nsAString_InitDepend(nsAString *, const PRUnichar *) DECLSPEC_HIDDEN
Definition: nsembed.c:826
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
static PropertyBag * impl_from_IPropertyBag2(IPropertyBag2 *iface)
Definition: propbag.c:182
static HRESULT WINAPI PropertyBag2_Write(IPropertyBag2 *iface, ULONG cProperties, PROPBAG2 *pPropBag, VARIANT *pvarValue)
Definition: propbag.c:213
WCHAR * name
Definition: propbag.c:32
static HRESULT WINAPI PropertyBag2_QueryInterface(IPropertyBag2 *iface, REFIID riid, void **ppv)
Definition: propbag.c:187
void nsAString_Finish(nsAString *) DECLSPEC_HIDDEN
Definition: nsembed.c:836
Definition: name.c:36
static const WCHAR props[]
Definition: wbemdisp.c:288
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
HRESULT nsresult
Definition: nsiface.idl:39
WCHAR PRUnichar
Definition: nsiface.idl:48
unsigned int ULONG
Definition: retypes.h:1
static HRESULT WINAPI PropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid, void **ppv)
Definition: propbag.c:87
static PropertyBag * impl_from_IPropertyBag(IPropertyBag *iface)
Definition: propbag.c:82
#define LIST_ENTRY(type)
Definition: queue.h:175
static HRESULT WINAPI PropertyBag2_GetPropertyInfo(IPropertyBag2 *iface, ULONG iProperty, ULONG cProperties, PROPBAG2 *pPropBag, ULONG *pcProperties)
Definition: propbag.c:227
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
GLuint const GLchar * name
Definition: glext.h:6031