msxml3: Move string conversion helper to header.

This commit is contained in:
Nikolay Sivov 2011-03-10 22:15:09 +03:00 committed by Alexandre Julliard
parent 68cc66d800
commit fb96151b0e
7 changed files with 73 additions and 75 deletions

View File

@ -1984,9 +1984,9 @@ static HRESULT WINAPI domdoc_createNode(
break; break;
} }
xml_name = xmlChar_from_wchar(name); xml_name = xmlchar_from_wchar(name);
/* prevent empty href to be allocated */ /* prevent empty href to be allocated */
href = namespaceURI ? xmlChar_from_wchar(namespaceURI) : NULL; href = namespaceURI ? xmlchar_from_wchar(namespaceURI) : NULL;
switch(node_type) switch(node_type)
{ {
@ -2853,8 +2853,7 @@ static HRESULT WINAPI domdoc_setProperty(
pNsList = &(This->properties->selectNsList); pNsList = &(This->properties->selectNsList);
clear_selectNsList(pNsList); clear_selectNsList(pNsList);
heap_free(nsStr); heap_free(nsStr);
nsStr = xmlChar_from_wchar(bstr); nsStr = xmlchar_from_wchar(bstr);
TRACE("Setting SelectionNamespaces property to: %s\n", nsStr); TRACE("Setting SelectionNamespaces property to: %s\n", nsStr);

View File

@ -1056,7 +1056,7 @@ static HRESULT WINAPI domelem_getAttribute(
V_BSTR(value) = NULL; V_BSTR(value) = NULL;
V_VT(value) = VT_NULL; V_VT(value) = VT_NULL;
xml_name = xmlChar_from_wchar( name ); xml_name = xmlchar_from_wchar( name );
if(!xmlValidateNameValue(xml_name)) if(!xmlValidateNameValue(xml_name))
hr = E_FAIL; hr = E_FAIL;
@ -1099,8 +1099,8 @@ static HRESULT WINAPI domelem_setAttribute(
return hr; return hr;
} }
xml_name = xmlChar_from_wchar( name ); xml_name = xmlchar_from_wchar( name );
xml_value = xmlChar_from_wchar( V_BSTR(&var) ); xml_value = xmlchar_from_wchar( V_BSTR(&var) );
if(!xmlSetNsProp(element, NULL, xml_name, xml_value)) if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
hr = E_FAIL; hr = E_FAIL;
@ -1153,7 +1153,7 @@ static HRESULT WINAPI domelem_getAttributeNode(
if ( !element ) if ( !element )
return E_FAIL; return E_FAIL;
xml_name = xmlChar_from_wchar(p); xml_name = xmlchar_from_wchar(p);
if(!xmlValidateNameValue(xml_name)) if(!xmlValidateNameValue(xml_name))
{ {
@ -1228,8 +1228,8 @@ static HRESULT WINAPI domelem_setAttributeNode(
SysFreeString(prefix); SysFreeString(prefix);
} }
name = xmlChar_from_wchar(nameW); name = xmlchar_from_wchar(nameW);
value = xmlChar_from_wchar(V_BSTR(&valueW)); value = xmlchar_from_wchar(V_BSTR(&valueW));
if (!name || !value) if (!name || !value)
{ {

View File

@ -157,6 +157,43 @@ extern HINSTANCE MSXML_hInstance;
void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*); void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*);
BOOL dispex_query_interface(DispatchEx*,REFIID,void**); 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 #ifdef HAVE_LIBXML2
extern void schemasInit(void); extern void schemasInit(void);
@ -354,6 +391,17 @@ static inline HRESULT return_null_bstr(BSTR *p)
return S_FALSE; 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 #endif
extern IXMLDOMParseError *create_parseError( LONG code, BSTR url, BSTR reason, BSTR srcText, 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*); 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 */ /* Error Codes - not defined anywhere in the public headers */
#define E_XML_ELEMENT_UNDECLARED 0xC00CE00D #define E_XML_ELEMENT_UNDECLARED 0xC00CE00D
#define E_XML_ELEMENT_ID_NOT_FOUND 0xC00CE00E #define E_XML_ELEMENT_ID_NOT_FOUND 0xC00CE00E

View File

@ -162,7 +162,7 @@ HRESULT node_set_content(xmlnode *This, LPCWSTR value)
xmlChar *str; xmlChar *str;
TRACE("(%p)->(%s)\n", This, debugstr_w(value)); TRACE("(%p)->(%s)\n", This, debugstr_w(value));
str = xmlChar_from_wchar(value); str = xmlchar_from_wchar(value);
if(!str) if(!str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -176,7 +176,7 @@ static HRESULT node_set_content_escaped(xmlnode *This, LPCWSTR value)
xmlChar *str, *escaped; xmlChar *str, *escaped;
TRACE("(%p)->(%s)\n", This, debugstr_w(value)); TRACE("(%p)->(%s)\n", This, debugstr_w(value));
str = xmlChar_from_wchar(value); str = xmlchar_from_wchar(value);
if(!str) if(!str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -641,7 +641,7 @@ HRESULT node_put_text(xmlnode *This, BSTR text)
TRACE("(%p)->(%s)\n", This, debugstr_w(text)); TRACE("(%p)->(%s)\n", This, debugstr_w(text));
str = xmlChar_from_wchar(text); str = xmlchar_from_wchar(text);
/* Escape the string. */ /* Escape the string. */
str2 = xmlEncodeEntitiesReentrant(This->node->doc, str); 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; if (!query || !nodes) return E_INVALIDARG;
str = xmlChar_from_wchar(query); str = xmlchar_from_wchar(query);
hr = queryresult_create(This->node, str, nodes); hr = queryresult_create(This->node, str, nodes);
heap_free(str); heap_free(str);

View File

@ -189,18 +189,6 @@ static HRESULT WINAPI xmlnodemap_Invoke(
return hr; 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( static HRESULT WINAPI xmlnodemap_getNamedItem(
IXMLDOMNamedNodeMap *iface, IXMLDOMNamedNodeMap *iface,
BSTR name, BSTR name,
@ -334,13 +322,13 @@ static HRESULT WINAPI xmlnodemap_getQualifiedItem(
if (namespaceURI && *namespaceURI) if (namespaceURI && *namespaceURI)
{ {
href = xmlChar_from_wchar(namespaceURI); href = xmlchar_from_wchar(namespaceURI);
if (!href) return E_OUTOFMEMORY; if (!href) return E_OUTOFMEMORY;
} }
else else
href = NULL; href = NULL;
name = xmlChar_from_wchar(baseName); name = xmlchar_from_wchar(baseName);
if (!name) if (!name)
{ {
heap_free(href); heap_free(href);
@ -380,13 +368,13 @@ static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
if (namespaceURI && *namespaceURI) if (namespaceURI && *namespaceURI)
{ {
href = xmlChar_from_wchar(namespaceURI); href = xmlchar_from_wchar(namespaceURI);
if (!href) return E_OUTOFMEMORY; if (!href) return E_OUTOFMEMORY;
} }
else else
href = NULL; href = NULL;
name = xmlChar_from_wchar(baseName); name = xmlchar_from_wchar(baseName);
if (!name) if (!name)
{ {
heap_free(href); heap_free(href);

View File

@ -1061,7 +1061,7 @@ static HRESULT WINAPI schema_cache_Invoke(IXMLDOMSchemaCollection2* iface,
static HRESULT WINAPI schema_cache_add(IXMLDOMSchemaCollection2* iface, BSTR uri, VARIANT var) static HRESULT WINAPI schema_cache_add(IXMLDOMSchemaCollection2* iface, BSTR uri, VARIANT var)
{ {
schema_cache* This = impl_from_IXMLDOMSchemaCollection2(iface); 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)); TRACE("(%p)->(%s %s)\n", This, debugstr_w(uri), debugstr_variant(&var));
switch (V_VT(&var)) switch (V_VT(&var))
@ -1162,7 +1162,7 @@ static HRESULT WINAPI schema_cache_get(IXMLDOMSchemaCollection2* iface, BSTR uri
if (!node) if (!node)
return E_POINTER; 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); entry = (cache_entry*) xmlHashLookup(This->cache, name);
heap_free(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) static HRESULT WINAPI schema_cache_remove(IXMLDOMSchemaCollection2* iface, BSTR uri)
{ {
schema_cache* This = impl_from_IXMLDOMSchemaCollection2(iface); 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)); TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(uri));
xmlHashRemoveEntry(This->cache, name, cache_free); xmlHashRemoveEntry(This->cache, name, cache_free);

View File

@ -237,8 +237,8 @@ static HRESULT WINAPI xmlelem_setAttribute(IXMLElement *iface, BSTR strPropertyN
if (!strPropertyName || V_VT(&PropertyValue) != VT_BSTR) if (!strPropertyName || V_VT(&PropertyValue) != VT_BSTR)
return E_INVALIDARG; return E_INVALIDARG;
name = xmlChar_from_wchar(strPropertyName); name = xmlchar_from_wchar(strPropertyName);
value = xmlChar_from_wchar(V_BSTR(&PropertyValue)); value = xmlchar_from_wchar(V_BSTR(&PropertyValue));
attr = xmlSetProp(This->node, name, value); attr = xmlSetProp(This->node, name, value);
heap_free(name); heap_free(name);
@ -276,7 +276,7 @@ static HRESULT WINAPI xmlelem_getAttribute(IXMLElement *iface, BSTR name,
xmlAttrPtr attr; xmlAttrPtr attr;
xmlChar *xml_name; xmlChar *xml_name;
xml_name = xmlChar_from_wchar(name); xml_name = xmlchar_from_wchar(name);
attr = This->node->properties; attr = This->node->properties;
while (attr) while (attr)
{ {
@ -321,7 +321,7 @@ static HRESULT WINAPI xmlelem_removeAttribute(IXMLElement *iface, BSTR strProper
if (!strPropertyName) if (!strPropertyName)
return E_INVALIDARG; return E_INVALIDARG;
name = xmlChar_from_wchar(strPropertyName); name = xmlchar_from_wchar(strPropertyName);
attr = xmlHasProp(This->node, name); attr = xmlHasProp(This->node, name);
if (!attr) if (!attr)
goto done; goto done;
@ -414,7 +414,7 @@ static HRESULT WINAPI xmlelem_put_text(IXMLElement *iface, BSTR p)
if (This->node->type == XML_ELEMENT_NODE) if (This->node->type == XML_ELEMENT_NODE)
return E_NOTIMPL; return E_NOTIMPL;
content = xmlChar_from_wchar(p); content = xmlchar_from_wchar(p);
xmlNodeSetContent(This->node, content); xmlNodeSetContent(This->node, content);
heap_free(content); heap_free(content);