Commit fb96151b authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

msxml3: Move string conversion helper to header.

parent 68cc66d8
......@@ -1984,9 +1984,9 @@ static HRESULT WINAPI domdoc_createNode(
break;
}
xml_name = xmlChar_from_wchar(name);
xml_name = xmlchar_from_wchar(name);
/* prevent empty href to be allocated */
href = namespaceURI ? xmlChar_from_wchar(namespaceURI) : NULL;
href = namespaceURI ? xmlchar_from_wchar(namespaceURI) : NULL;
switch(node_type)
{
......@@ -2853,8 +2853,7 @@ static HRESULT WINAPI domdoc_setProperty(
pNsList = &(This->properties->selectNsList);
clear_selectNsList(pNsList);
heap_free(nsStr);
nsStr = xmlChar_from_wchar(bstr);
nsStr = xmlchar_from_wchar(bstr);
TRACE("Setting SelectionNamespaces property to: %s\n", nsStr);
......
......@@ -1056,7 +1056,7 @@ static HRESULT WINAPI domelem_getAttribute(
V_BSTR(value) = NULL;
V_VT(value) = VT_NULL;
xml_name = xmlChar_from_wchar( name );
xml_name = xmlchar_from_wchar( name );
if(!xmlValidateNameValue(xml_name))
hr = E_FAIL;
......@@ -1099,8 +1099,8 @@ static HRESULT WINAPI domelem_setAttribute(
return hr;
}
xml_name = xmlChar_from_wchar( name );
xml_value = xmlChar_from_wchar( V_BSTR(&var) );
xml_name = xmlchar_from_wchar( name );
xml_value = xmlchar_from_wchar( V_BSTR(&var) );
if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
hr = E_FAIL;
......@@ -1153,7 +1153,7 @@ static HRESULT WINAPI domelem_getAttributeNode(
if ( !element )
return E_FAIL;
xml_name = xmlChar_from_wchar(p);
xml_name = xmlchar_from_wchar(p);
if(!xmlValidateNameValue(xml_name))
{
......@@ -1228,8 +1228,8 @@ static HRESULT WINAPI domelem_setAttributeNode(
SysFreeString(prefix);
}
name = xmlChar_from_wchar(nameW);
value = xmlChar_from_wchar(V_BSTR(&valueW));
name = xmlchar_from_wchar(nameW);
value = xmlchar_from_wchar(V_BSTR(&valueW));
if (!name || !value)
{
......
......@@ -157,6 +157,43 @@ extern HINSTANCE MSXML_hInstance;
void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*);
BOOL dispex_query_interface(DispatchEx*,REFIID,void**);
/* memory allocation functions */
static inline void *heap_alloc(size_t len)
{
return HeapAlloc(GetProcessHeap(), 0, len);
}
static inline void *heap_alloc_zero(size_t len)
{
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
}
static inline void *heap_realloc(void *mem, size_t len)
{
return HeapReAlloc(GetProcessHeap(), 0, mem, len);
}
static inline BOOL heap_free(void *mem)
{
return HeapFree(GetProcessHeap(), 0, mem);
}
static inline LPWSTR heap_strdupW(LPCWSTR str)
{
LPWSTR ret = NULL;
if(str) {
DWORD size;
size = (strlenW(str)+1)*sizeof(WCHAR);
ret = heap_alloc(size);
memcpy(ret, str, size);
}
return ret;
}
#ifdef HAVE_LIBXML2
extern void schemasInit(void);
......@@ -354,6 +391,17 @@ static inline HRESULT return_null_bstr(BSTR *p)
return S_FALSE;
}
static inline xmlChar *xmlchar_from_wchar( LPCWSTR str )
{
xmlChar *xmlstr;
DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
xmlstr = heap_alloc( len );
if ( xmlstr )
WideCharToMultiByte( CP_UTF8, 0, str, -1, (LPSTR) xmlstr, len, NULL, NULL );
return xmlstr;
}
#endif
extern IXMLDOMParseError *create_parseError( LONG code, BSTR url, BSTR reason, BSTR srcText,
......@@ -396,43 +444,6 @@ void detach_bsc(bsc_t*);
const char *debugstr_variant(const VARIANT*);
/* memory allocation functions */
static inline void *heap_alloc(size_t len)
{
return HeapAlloc(GetProcessHeap(), 0, len);
}
static inline void *heap_alloc_zero(size_t len)
{
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
}
static inline void *heap_realloc(void *mem, size_t len)
{
return HeapReAlloc(GetProcessHeap(), 0, mem, len);
}
static inline BOOL heap_free(void *mem)
{
return HeapFree(GetProcessHeap(), 0, mem);
}
static inline LPWSTR heap_strdupW(LPCWSTR str)
{
LPWSTR ret = NULL;
if(str) {
DWORD size;
size = (strlenW(str)+1)*sizeof(WCHAR);
ret = heap_alloc(size);
memcpy(ret, str, size);
}
return ret;
}
/* Error Codes - not defined anywhere in the public headers */
#define E_XML_ELEMENT_UNDECLARED 0xC00CE00D
#define E_XML_ELEMENT_ID_NOT_FOUND 0xC00CE00E
......
......@@ -162,7 +162,7 @@ HRESULT node_set_content(xmlnode *This, LPCWSTR value)
xmlChar *str;
TRACE("(%p)->(%s)\n", This, debugstr_w(value));
str = xmlChar_from_wchar(value);
str = xmlchar_from_wchar(value);
if(!str)
return E_OUTOFMEMORY;
......@@ -176,7 +176,7 @@ static HRESULT node_set_content_escaped(xmlnode *This, LPCWSTR value)
xmlChar *str, *escaped;
TRACE("(%p)->(%s)\n", This, debugstr_w(value));
str = xmlChar_from_wchar(value);
str = xmlchar_from_wchar(value);
if(!str)
return E_OUTOFMEMORY;
......@@ -641,7 +641,7 @@ HRESULT node_put_text(xmlnode *This, BSTR text)
TRACE("(%p)->(%s)\n", This, debugstr_w(text));
str = xmlChar_from_wchar(text);
str = xmlchar_from_wchar(text);
/* Escape the string. */
str2 = xmlEncodeEntitiesReentrant(This->node->doc, str);
......@@ -1029,7 +1029,7 @@ HRESULT node_select_nodes(const xmlnode *This, BSTR query, IXMLDOMNodeList **nod
if (!query || !nodes) return E_INVALIDARG;
str = xmlChar_from_wchar(query);
str = xmlchar_from_wchar(query);
hr = queryresult_create(This->node, str, nodes);
heap_free(str);
......
......@@ -189,18 +189,6 @@ static HRESULT WINAPI xmlnodemap_Invoke(
return hr;
}
xmlChar *xmlChar_from_wchar( LPCWSTR str )
{
DWORD len;
xmlChar *xmlstr;
len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
xmlstr = heap_alloc( len );
if ( xmlstr )
WideCharToMultiByte( CP_UTF8, 0, str, -1, (LPSTR) xmlstr, len, NULL, NULL );
return xmlstr;
}
static HRESULT WINAPI xmlnodemap_getNamedItem(
IXMLDOMNamedNodeMap *iface,
BSTR name,
......@@ -334,13 +322,13 @@ static HRESULT WINAPI xmlnodemap_getQualifiedItem(
if (namespaceURI && *namespaceURI)
{
href = xmlChar_from_wchar(namespaceURI);
href = xmlchar_from_wchar(namespaceURI);
if (!href) return E_OUTOFMEMORY;
}
else
href = NULL;
name = xmlChar_from_wchar(baseName);
name = xmlchar_from_wchar(baseName);
if (!name)
{
heap_free(href);
......@@ -380,13 +368,13 @@ static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
if (namespaceURI && *namespaceURI)
{
href = xmlChar_from_wchar(namespaceURI);
href = xmlchar_from_wchar(namespaceURI);
if (!href) return E_OUTOFMEMORY;
}
else
href = NULL;
name = xmlChar_from_wchar(baseName);
name = xmlchar_from_wchar(baseName);
if (!name)
{
heap_free(href);
......
......@@ -1061,7 +1061,7 @@ static HRESULT WINAPI schema_cache_Invoke(IXMLDOMSchemaCollection2* iface,
static HRESULT WINAPI schema_cache_add(IXMLDOMSchemaCollection2* iface, BSTR uri, VARIANT var)
{
schema_cache* This = impl_from_IXMLDOMSchemaCollection2(iface);
xmlChar* name = uri ? xmlChar_from_wchar(uri) : xmlChar_from_wchar(emptyW);
xmlChar* name = uri ? xmlchar_from_wchar(uri) : xmlchar_from_wchar(emptyW);
TRACE("(%p)->(%s %s)\n", This, debugstr_w(uri), debugstr_variant(&var));
switch (V_VT(&var))
......@@ -1162,7 +1162,7 @@ static HRESULT WINAPI schema_cache_get(IXMLDOMSchemaCollection2* iface, BSTR uri
if (!node)
return E_POINTER;
name = uri ? xmlChar_from_wchar(uri) : xmlChar_from_wchar(emptyW);
name = uri ? xmlchar_from_wchar(uri) : xmlchar_from_wchar(emptyW);
entry = (cache_entry*) xmlHashLookup(This->cache, name);
heap_free(name);
......@@ -1177,7 +1177,7 @@ static HRESULT WINAPI schema_cache_get(IXMLDOMSchemaCollection2* iface, BSTR uri
static HRESULT WINAPI schema_cache_remove(IXMLDOMSchemaCollection2* iface, BSTR uri)
{
schema_cache* This = impl_from_IXMLDOMSchemaCollection2(iface);
xmlChar* name = uri ? xmlChar_from_wchar(uri) : xmlChar_from_wchar(emptyW);
xmlChar* name = uri ? xmlchar_from_wchar(uri) : xmlchar_from_wchar(emptyW);
TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(uri));
xmlHashRemoveEntry(This->cache, name, cache_free);
......
......@@ -237,8 +237,8 @@ static HRESULT WINAPI xmlelem_setAttribute(IXMLElement *iface, BSTR strPropertyN
if (!strPropertyName || V_VT(&PropertyValue) != VT_BSTR)
return E_INVALIDARG;
name = xmlChar_from_wchar(strPropertyName);
value = xmlChar_from_wchar(V_BSTR(&PropertyValue));
name = xmlchar_from_wchar(strPropertyName);
value = xmlchar_from_wchar(V_BSTR(&PropertyValue));
attr = xmlSetProp(This->node, name, value);
heap_free(name);
......@@ -276,7 +276,7 @@ static HRESULT WINAPI xmlelem_getAttribute(IXMLElement *iface, BSTR name,
xmlAttrPtr attr;
xmlChar *xml_name;
xml_name = xmlChar_from_wchar(name);
xml_name = xmlchar_from_wchar(name);
attr = This->node->properties;
while (attr)
{
......@@ -321,7 +321,7 @@ static HRESULT WINAPI xmlelem_removeAttribute(IXMLElement *iface, BSTR strProper
if (!strPropertyName)
return E_INVALIDARG;
name = xmlChar_from_wchar(strPropertyName);
name = xmlchar_from_wchar(strPropertyName);
attr = xmlHasProp(This->node, name);
if (!attr)
goto done;
......@@ -414,7 +414,7 @@ static HRESULT WINAPI xmlelem_put_text(IXMLElement *iface, BSTR p)
if (This->node->type == XML_ELEMENT_NODE)
return E_NOTIMPL;
content = xmlChar_from_wchar(p);
content = xmlchar_from_wchar(p);
xmlNodeSetContent(This->node, content);
heap_free(content);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment