Signed-off-by: Hans Leidekker hans@codeweavers.com --- dlls/mshtml/htmlstorage.c | 117 +++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-)
diff --git a/dlls/mshtml/htmlstorage.c b/dlls/mshtml/htmlstorage.c index fe1d6a21b88..b01247db56b 100644 --- a/dlls/mshtml/htmlstorage.c +++ b/dlls/mshtml/htmlstorage.c @@ -386,11 +386,124 @@ static HRESULT WINAPI HTMLStorage_getItem(IHTMLStorage *iface, BSTR bstrKey, VAR return hres; }
+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) +{ + VARIANT var; + HRESULT hres; + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(storage->filename); + if(!V_BSTR(&var)) + return E_OUTOFMEMORY; + + hres = IXMLDOMDocument_save(storage->doc, var); + SysFreeString(V_BSTR(&var)); + return hres; +} + +static HRESULT set_item(BSTR hostname, BSTR key, BSTR value) +{ + struct storage *storage; + IXMLDOMNode *root = NULL, *node = NULL; + IXMLDOMElement *elem = NULL; + BSTR query = NULL; + HRESULT hres; + + hres = open_storage(hostname, &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); + +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; + BSTR hostname; + HRESULT hres; + + TRACE("(%p)->(%s %s)\n", This, debugstr_w(bstrKey), debugstr_w(bstrValue)); + + if(!This->window) { + FIXME("session storage not supported\n"); + return E_NOTIMPL; + } + + hres = IUri_GetHost(This->window->base.outer_window->uri, &hostname); + if(hres != S_OK) + return hres; + + hres = set_item(hostname, bstrKey, bstrValue); + SysFreeString(hostname); + return hres; }
static HRESULT WINAPI HTMLStorage_removeItem(IHTMLStorage *iface, BSTR bstrKey)