2005-08-02 13:29:04 +02:00
|
|
|
/*
|
|
|
|
* MSXML Class Factory
|
|
|
|
*
|
|
|
|
* Copyright 2002 Lionel Ulmer
|
|
|
|
* Copyright 2005 Mike McCormack
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-08-02 13:29:04 +02:00
|
|
|
*/
|
|
|
|
|
2008-02-14 10:55:33 +01:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2005-08-02 13:29:04 +02:00
|
|
|
#include <stdarg.h>
|
2021-10-20 11:39:06 +02:00
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/xmlerror.h>
|
|
|
|
#include <libxslt/pattern.h>
|
|
|
|
#include <libxslt/transform.h>
|
|
|
|
#include <libxslt/imports.h>
|
|
|
|
#include <libxslt/xsltutils.h>
|
|
|
|
#include <libxslt/variables.h>
|
|
|
|
#include <libxslt/xsltInternals.h>
|
|
|
|
#include <libxslt/documents.h>
|
|
|
|
#include <libxslt/extensions.h>
|
|
|
|
#include <libxslt/extra.h>
|
2011-02-24 13:11:53 +01:00
|
|
|
|
2005-08-02 13:29:04 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2010-12-21 13:41:29 +01:00
|
|
|
#include "rpcproxy.h"
|
2008-02-14 10:55:33 +01:00
|
|
|
#include "msxml.h"
|
2020-09-14 14:39:52 +02:00
|
|
|
#include "msxml2.h"
|
2010-08-29 23:31:49 +02:00
|
|
|
#include "msxml6.h"
|
2005-08-02 13:29:04 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2005-08-09 13:17:47 +02:00
|
|
|
#include "msxml_private.h"
|
|
|
|
|
2010-11-10 04:40:34 +01:00
|
|
|
HINSTANCE MSXML_hInstance = NULL;
|
|
|
|
|
2015-02-21 14:58:41 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msxml);
|
|
|
|
|
2010-10-27 16:35:56 +02:00
|
|
|
void wineXmlCallbackLog(char const* caller, xmlErrorLevel lvl, char const* msg, va_list ap)
|
|
|
|
{
|
2012-02-16 18:01:07 +01:00
|
|
|
enum __wine_debug_class dbcl;
|
2014-03-25 09:20:22 +01:00
|
|
|
char buff[200];
|
2018-02-26 23:16:41 +01:00
|
|
|
const int max_size = ARRAY_SIZE(buff);
|
2012-02-16 18:01:07 +01:00
|
|
|
int len;
|
|
|
|
|
2010-10-27 16:35:56 +02:00
|
|
|
switch (lvl)
|
|
|
|
{
|
|
|
|
case XML_ERR_NONE:
|
|
|
|
dbcl = __WINE_DBCL_TRACE;
|
|
|
|
break;
|
|
|
|
case XML_ERR_WARNING:
|
|
|
|
dbcl = __WINE_DBCL_WARN;
|
|
|
|
break;
|
|
|
|
default:
|
2012-02-16 18:01:07 +01:00
|
|
|
dbcl = __WINE_DBCL_ERR;
|
2010-10-27 16:35:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-16 18:01:07 +01:00
|
|
|
len = vsnprintf(buff, max_size, msg, ap);
|
|
|
|
if (len == -1 || len >= max_size) buff[max_size-1] = 0;
|
2010-11-17 14:21:09 +01:00
|
|
|
|
2012-02-16 18:01:07 +01:00
|
|
|
wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "%s", buff);
|
2010-11-17 14:21:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void wineXmlCallbackError(char const* caller, xmlErrorPtr err)
|
|
|
|
{
|
|
|
|
enum __wine_debug_class dbcl;
|
|
|
|
|
|
|
|
switch (err->level)
|
2010-10-27 16:35:56 +02:00
|
|
|
{
|
2010-11-17 14:21:09 +01:00
|
|
|
case XML_ERR_NONE: dbcl = __WINE_DBCL_TRACE; break;
|
|
|
|
case XML_ERR_WARNING: dbcl = __WINE_DBCL_WARN; break;
|
|
|
|
default: dbcl = __WINE_DBCL_ERR; break;
|
2010-10-27 16:35:56 +02:00
|
|
|
}
|
2012-02-16 18:02:45 +01:00
|
|
|
|
|
|
|
wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "error code %d", err->code);
|
|
|
|
if (err->message)
|
|
|
|
wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, ": %s", err->message);
|
|
|
|
else
|
|
|
|
wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "\n");
|
2010-10-27 16:35:56 +02:00
|
|
|
}
|
|
|
|
|
2009-08-10 14:30:51 +02:00
|
|
|
/* Support for loading xml files from a Wine Windows drive */
|
|
|
|
static int wineXmlMatchCallback (char const * filename)
|
|
|
|
{
|
|
|
|
int nRet = 0;
|
|
|
|
|
|
|
|
TRACE("%s\n", filename);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We will deal with loading XML files from the file system
|
|
|
|
* We only care about files that linux cannot find.
|
|
|
|
* e.g. C:,D: etc
|
|
|
|
*/
|
|
|
|
if(isalpha(filename[0]) && filename[1] == ':')
|
|
|
|
nRet = 1;
|
|
|
|
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *wineXmlOpenCallback (char const * filename)
|
|
|
|
{
|
2010-03-27 16:19:45 +01:00
|
|
|
BSTR sFilename = bstr_from_xmlChar( (const xmlChar*)filename);
|
2009-08-10 14:30:51 +02:00
|
|
|
HANDLE hFile;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(sFilename));
|
|
|
|
|
|
|
|
hFile = CreateFileW(sFilename, GENERIC_READ,FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if(hFile == INVALID_HANDLE_VALUE) hFile = 0;
|
|
|
|
SysFreeString(sFilename);
|
|
|
|
return hFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wineXmlReadCallback(void * context, char * buffer, int len)
|
|
|
|
{
|
|
|
|
DWORD dwBytesRead;
|
|
|
|
|
|
|
|
TRACE("%p %s %d\n", context, buffer, len);
|
|
|
|
|
|
|
|
if ((context == NULL) || (buffer == NULL))
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
if(!ReadFile( context, buffer,len, &dwBytesRead, NULL))
|
|
|
|
{
|
|
|
|
ERR("Failed to read file\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Read %d\n", dwBytesRead);
|
|
|
|
|
|
|
|
return dwBytesRead;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wineXmlFileCloseCallback (void * context)
|
|
|
|
{
|
|
|
|
return CloseHandle(context) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2008-11-17 19:29:32 +01:00
|
|
|
static void init_libxslt(void)
|
|
|
|
{
|
2021-10-20 11:39:06 +02:00
|
|
|
xsltInit();
|
|
|
|
xsltSetLoaderFunc(xslt_doc_default_loader);
|
|
|
|
xsltRegisterExtModuleFunction(
|
2018-01-23 09:27:56 +01:00
|
|
|
(const xmlChar *)"node-set",
|
|
|
|
(const xmlChar *)"urn:schemas-microsoft-com:xslt",
|
2021-10-20 11:39:06 +02:00
|
|
|
xsltFunctionNodeSet);
|
2008-11-17 19:29:32 +01:00
|
|
|
}
|
|
|
|
|
2019-08-09 12:16:07 +02:00
|
|
|
static int to_utf8(int cp, unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
WCHAR *tmp;
|
2021-10-20 11:31:58 +02:00
|
|
|
int len = 0;
|
2019-08-09 12:16:07 +02:00
|
|
|
|
2021-10-20 11:31:58 +02:00
|
|
|
if (!in || !inlen) goto done;
|
2019-08-09 12:16:07 +02:00
|
|
|
|
|
|
|
len = MultiByteToWideChar(cp, 0, (const char *)in, *inlen, NULL, 0);
|
|
|
|
tmp = heap_alloc(len * sizeof(WCHAR));
|
|
|
|
if (!tmp) return -1;
|
|
|
|
MultiByteToWideChar(cp, 0, (const char *)in, *inlen, tmp, len);
|
|
|
|
|
|
|
|
len = WideCharToMultiByte(CP_UTF8, 0, tmp, len, (char *)out, *outlen, NULL, NULL);
|
|
|
|
heap_free(tmp);
|
|
|
|
if (!len) return -1;
|
2021-10-20 11:31:58 +02:00
|
|
|
done:
|
2019-08-09 12:16:07 +02:00
|
|
|
*outlen = len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int from_utf8(int cp, unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
WCHAR *tmp;
|
2021-10-20 11:31:58 +02:00
|
|
|
int len = 0;
|
2019-08-09 12:16:07 +02:00
|
|
|
|
2021-10-20 11:31:58 +02:00
|
|
|
if (!in || !inlen) goto done;
|
2019-08-09 12:16:07 +02:00
|
|
|
|
|
|
|
len = MultiByteToWideChar(CP_UTF8, 0, (const char *)in, *inlen, NULL, 0);
|
|
|
|
tmp = heap_alloc(len * sizeof(WCHAR));
|
|
|
|
if (!tmp) return -1;
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, (const char *)in, *inlen, tmp, len);
|
|
|
|
|
|
|
|
len = WideCharToMultiByte(cp, 0, tmp, len, (char *)out, *outlen, NULL, NULL);
|
|
|
|
heap_free(tmp);
|
|
|
|
if (!len) return -1;
|
2021-10-20 11:31:58 +02:00
|
|
|
done:
|
2019-08-09 12:16:07 +02:00
|
|
|
*outlen = len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int win1250_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return to_utf8(1250, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int utf8_to_win1250(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return from_utf8(1250, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int win1251_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return to_utf8(1251, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int utf8_to_win1251(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return from_utf8(1251, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int win1252_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return to_utf8(1252, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int utf8_to_win1252(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return from_utf8(1252, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int win1253_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return to_utf8(1253, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int utf8_to_win1253(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return from_utf8(1253, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
static int win1254_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return to_utf8(1254, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int utf8_to_win1254(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return from_utf8(1254, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int win1255_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return to_utf8(1255, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int utf8_to_win1255(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return from_utf8(1255, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int win1256_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return to_utf8(1256, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int utf8_to_win1256(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return from_utf8(1256, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int win1257_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return to_utf8(1257, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int utf8_to_win1257(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return from_utf8(1257, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int win1258_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return to_utf8(1258, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int utf8_to_win1258(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
|
|
|
|
{
|
|
|
|
return from_utf8(1258, out, outlen, in, inlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_char_encoders(void)
|
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *encoding;
|
|
|
|
xmlCharEncodingInputFunc input;
|
|
|
|
xmlCharEncodingOutputFunc output;
|
|
|
|
} encoder[] =
|
|
|
|
{
|
|
|
|
{ "windows-1250", win1250_to_utf8, utf8_to_win1250 },
|
|
|
|
{ "windows-1251", win1251_to_utf8, utf8_to_win1251 },
|
|
|
|
{ "windows-1252", win1252_to_utf8, utf8_to_win1252 },
|
|
|
|
{ "windows-1253", win1253_to_utf8, utf8_to_win1253 },
|
|
|
|
{ "windows-1254", win1254_to_utf8, utf8_to_win1254 },
|
|
|
|
{ "windows-1255", win1255_to_utf8, utf8_to_win1255 },
|
|
|
|
{ "windows-1256", win1256_to_utf8, utf8_to_win1256 },
|
|
|
|
{ "windows-1257", win1257_to_utf8, utf8_to_win1257 },
|
|
|
|
{ "windows-1258", win1258_to_utf8, utf8_to_win1258 }
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
xmlInitCharEncodingHandlers();
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(encoder); i++)
|
|
|
|
{
|
|
|
|
if (!xmlFindCharEncodingHandler(encoder[i].encoding))
|
|
|
|
{
|
|
|
|
TRACE("Adding %s encoding handler\n", encoder[i].encoding);
|
|
|
|
xmlNewCharEncodingHandler(encoder[i].encoding, encoder[i].input, encoder[i].output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 14:39:52 +02:00
|
|
|
const CLSID* DOMDocument_version(MSXML_VERSION v)
|
|
|
|
{
|
|
|
|
switch (v)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case MSXML_DEFAULT: return &CLSID_DOMDocument;
|
|
|
|
case MSXML3: return &CLSID_DOMDocument30;
|
|
|
|
case MSXML4: return &CLSID_DOMDocument40;
|
|
|
|
case MSXML6: return &CLSID_DOMDocument60;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-30 17:25:29 +02:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID reserved)
|
2005-08-02 13:29:04 +02:00
|
|
|
{
|
2010-11-10 04:40:34 +01:00
|
|
|
MSXML_hInstance = hInstDLL;
|
|
|
|
|
2005-08-02 13:29:04 +02:00
|
|
|
switch(fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2005-08-09 13:17:47 +02:00
|
|
|
xmlInitParser();
|
2008-07-26 13:06:41 +02:00
|
|
|
|
2008-11-02 12:46:41 +01:00
|
|
|
/* Set the default indent character to a single tab,
|
|
|
|
for this thread and as default for new threads */
|
|
|
|
xmlTreeIndentString = "\t";
|
2008-07-26 13:06:41 +02:00
|
|
|
xmlThrDefTreeIndentString("\t");
|
2009-08-10 14:30:51 +02:00
|
|
|
|
|
|
|
/* Register callbacks for loading XML files */
|
|
|
|
if(xmlRegisterInputCallbacks(wineXmlMatchCallback, wineXmlOpenCallback,
|
|
|
|
wineXmlReadCallback, wineXmlFileCloseCallback) == -1)
|
|
|
|
WARN("Failed to register callbacks\n");
|
|
|
|
|
2019-08-09 12:16:07 +02:00
|
|
|
init_char_encoders();
|
|
|
|
|
2010-11-12 15:33:17 +01:00
|
|
|
schemasInit();
|
2008-11-17 19:29:32 +01:00
|
|
|
init_libxslt();
|
2005-08-02 13:29:04 +02:00
|
|
|
DisableThreadLibraryCalls(hInstDLL);
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
2013-04-30 17:25:29 +02:00
|
|
|
if (reserved) break;
|
2021-10-20 11:39:06 +02:00
|
|
|
xsltCleanupGlobals();
|
2009-08-10 14:30:51 +02:00
|
|
|
/* Restore default Callbacks */
|
|
|
|
xmlCleanupInputCallbacks();
|
|
|
|
xmlRegisterDefaultInputCallbacks();
|
|
|
|
|
2005-08-09 13:17:47 +02:00
|
|
|
xmlCleanupParser();
|
2010-11-12 15:33:17 +01:00
|
|
|
schemasCleanup();
|
2008-08-21 23:37:48 +02:00
|
|
|
release_typelib();
|
2005-08-02 13:29:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|