Signed-off-by: Hans Leidekker hans@codeweavers.com --- dlls/mshtml/htmlstorage.c | 109 +++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-)
diff --git a/dlls/mshtml/htmlstorage.c b/dlls/mshtml/htmlstorage.c index 8f154291e36..107ae7ad720 100644 --- a/dlls/mshtml/htmlstorage.c +++ b/dlls/mshtml/htmlstorage.c @@ -372,11 +372,116 @@ static HRESULT WINAPI HTMLStorage_getItem(IHTMLStorage *iface, BSTR bstrKey, VAR return get_item(This->filename, bstrKey, value); }
+static HRESULT set_attribute(IXMLDOMElement *elem, const WCHAR *name, BSTR value) +{ + BSTR str; + VARIANT var; + HRESULT hres; + + str = SysAllocString(name); + if(!str) + return E_OUTOFMEMORY; + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = value; + + hres = IXMLDOMElement_setAttribute(elem, str, var); + + SysFreeString(str); + return hres; +} + +static HRESULT save_storage(struct storage *storage, const WCHAR *filename) +{ + VARIANT var; + HRESULT hres; + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(filename); + if(!V_BSTR(&var)) + return E_OUTOFMEMORY; + + hres = IXMLDOMDocument_save(storage->doc, var); + SysFreeString(V_BSTR(&var)); + return hres; +} + +static HRESULT set_item(const WCHAR *filename, BSTR key, BSTR value) +{ + struct storage *storage; + IXMLDOMNode *root = NULL, *node = NULL; + IXMLDOMElement *elem = NULL; + BSTR query = NULL; + HRESULT hres; + + hres = open_storage(filename, &storage); + if(hres != S_OK) + return hres; + + hres = get_root_node(storage->doc, &root); + if(hres != S_OK) + goto done; + + query = build_query(key); + if(!query) { + hres = E_OUTOFMEMORY; + goto done; + } + + hres = IXMLDOMNode_selectSingleNode(root, query, &node); + if(hres == S_OK) { + hres = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem); + if(hres != S_OK) + goto done; + + hres = set_attribute(elem, L"value", value); + if(hres != S_OK) + goto done; + }else { + BSTR str = SysAllocString(L"item"); + hres = IXMLDOMDocument_createElement(storage->doc, str, &elem); + SysFreeString(str); + if(hres != S_OK) + goto done; + + hres = set_attribute(elem, L"name", key); + if(hres != S_OK) + goto done; + + hres = set_attribute(elem, L"value", value); + if(hres != S_OK) + goto done; + + hres = IXMLDOMNode_appendChild(root, (IXMLDOMNode*)elem, NULL); + if(hres != S_OK) + goto done; + } + + hres = save_storage(storage, filename); + +done: + SysFreeString(query); + if(root) + IXMLDOMNode_Release(root); + if(node) + IXMLDOMNode_Release(node); + if(elem) + IXMLDOMElement_Release(elem); + close_storage(storage); + return hres; +} + static HRESULT WINAPI HTMLStorage_setItem(IHTMLStorage *iface, BSTR bstrKey, BSTR bstrValue) { HTMLStorage *This = impl_from_IHTMLStorage(iface); - FIXME("(%p)->(%s %s)\n", This, debugstr_w(bstrKey), debugstr_w(bstrValue)); - return E_NOTIMPL; + + TRACE("(%p)->(%s %s)\n", This, debugstr_w(bstrKey), debugstr_w(bstrValue)); + + if(!This->filename) { + FIXME("session storage not supported\n"); + return E_NOTIMPL; + } + + return set_item(This->filename, bstrKey, bstrValue); }
static HRESULT WINAPI HTMLStorage_removeItem(IHTMLStorage *iface, BSTR bstrKey)