2007-12-30 10:49:17 +00: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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2013-12-26 12:57:01 +00:00
|
|
|
#include "precomp.h"
|
2013-01-24 23:00:42 +00:00
|
|
|
|
|
|
|
#include <wine/port.h>
|
2007-12-30 10:49:17 +00:00
|
|
|
|
2012-09-09 19:47:25 +00:00
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
# ifdef SONAME_LIBXSLT
|
|
|
|
# ifdef HAVE_LIBXSLT_PATTERN_H
|
|
|
|
# include <libxslt/pattern.h>
|
|
|
|
# endif
|
|
|
|
# ifdef HAVE_LIBXSLT_TRANSFORM_H
|
|
|
|
# include <libxslt/transform.h>
|
|
|
|
# endif
|
2014-04-24 15:40:52 +00:00
|
|
|
# include <libxslt/imports.h>
|
2012-09-09 19:47:25 +00:00
|
|
|
# include <libxslt/xsltutils.h>
|
2014-04-24 15:40:52 +00:00
|
|
|
# include <libxslt/variables.h>
|
2012-09-09 19:47:25 +00:00
|
|
|
# include <libxslt/xsltInternals.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include <rpcproxy.h>
|
2007-12-30 10:49:17 +00:00
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include <wine/library.h>
|
2007-12-30 10:49:17 +00:00
|
|
|
|
2012-09-09 19:47:25 +00:00
|
|
|
HINSTANCE MSXML_hInstance = NULL;
|
|
|
|
|
2009-08-22 15:10:54 +00:00
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
|
2012-09-09 19:47:25 +00:00
|
|
|
void wineXmlCallbackLog(char const* caller, xmlErrorLevel lvl, char const* msg, va_list ap)
|
|
|
|
{
|
|
|
|
enum __wine_debug_class dbcl;
|
|
|
|
char buff[200];
|
2014-04-24 15:40:52 +00:00
|
|
|
const int max_size = sizeof(buff) / sizeof(buff[0]);
|
2012-09-09 19:47:25 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
switch (lvl)
|
|
|
|
{
|
|
|
|
case XML_ERR_NONE:
|
|
|
|
dbcl = __WINE_DBCL_TRACE;
|
|
|
|
break;
|
|
|
|
case XML_ERR_WARNING:
|
|
|
|
dbcl = __WINE_DBCL_WARN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dbcl = __WINE_DBCL_ERR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = vsnprintf(buff, max_size, msg, ap);
|
|
|
|
if (len == -1 || len >= max_size) buff[max_size-1] = 0;
|
|
|
|
|
|
|
|
wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "%s", buff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wineXmlCallbackError(char const* caller, xmlErrorPtr err)
|
|
|
|
{
|
|
|
|
enum __wine_debug_class dbcl;
|
|
|
|
|
|
|
|
switch (err->level)
|
|
|
|
{
|
|
|
|
case XML_ERR_NONE: dbcl = __WINE_DBCL_TRACE; break;
|
|
|
|
case XML_ERR_WARNING: dbcl = __WINE_DBCL_WARN; break;
|
|
|
|
default: dbcl = __WINE_DBCL_ERR; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2009-08-22 15:10:54 +00: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-04-20 17:24:00 +00:00
|
|
|
BSTR sFilename = bstr_from_xmlChar( (const xmlChar*)filename);
|
2009-08-22 15:10:54 +00: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;
|
|
|
|
}
|
|
|
|
|
2009-01-04 10:48:19 +00:00
|
|
|
void* libxslt_handle = NULL;
|
|
|
|
#ifdef SONAME_LIBXSLT
|
|
|
|
# define DECL_FUNCPTR(f) typeof(f) * p##f = NULL
|
|
|
|
DECL_FUNCPTR(xsltApplyStylesheet);
|
2014-04-24 15:40:52 +00:00
|
|
|
DECL_FUNCPTR(xsltApplyStylesheetUser);
|
2009-01-04 10:48:19 +00:00
|
|
|
DECL_FUNCPTR(xsltCleanupGlobals);
|
|
|
|
DECL_FUNCPTR(xsltFreeStylesheet);
|
2014-04-24 15:40:52 +00:00
|
|
|
DECL_FUNCPTR(xsltFreeTransformContext);
|
|
|
|
DECL_FUNCPTR(xsltNewTransformContext);
|
|
|
|
DECL_FUNCPTR(xsltNextImport);
|
2009-01-04 10:48:19 +00:00
|
|
|
DECL_FUNCPTR(xsltParseStylesheetDoc);
|
2014-04-24 15:40:52 +00:00
|
|
|
DECL_FUNCPTR(xsltQuoteUserParams);
|
|
|
|
DECL_FUNCPTR(xsltSaveResultTo);
|
2012-09-09 19:47:25 +00:00
|
|
|
# undef DECL_FUNCPTR
|
2009-01-04 10:48:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void init_libxslt(void)
|
|
|
|
{
|
|
|
|
#ifdef SONAME_LIBXSLT
|
|
|
|
void (*pxsltInit)(void); /* Missing in libxslt <= 1.1.14 */
|
|
|
|
|
|
|
|
libxslt_handle = wine_dlopen(SONAME_LIBXSLT, RTLD_NOW, NULL, 0);
|
|
|
|
if (!libxslt_handle)
|
|
|
|
return;
|
|
|
|
|
2012-09-09 19:47:25 +00:00
|
|
|
#define LOAD_FUNCPTR(f, needed) \
|
|
|
|
if ((p##f = wine_dlsym(libxslt_handle, #f, NULL, 0)) == NULL) \
|
|
|
|
if (needed) { WARN("Can't find symbol %s\n", #f); goto sym_not_found; }
|
2009-01-04 10:48:19 +00:00
|
|
|
LOAD_FUNCPTR(xsltInit, 0);
|
|
|
|
LOAD_FUNCPTR(xsltApplyStylesheet, 1);
|
2014-04-24 15:40:52 +00:00
|
|
|
LOAD_FUNCPTR(xsltApplyStylesheetUser, 1);
|
2009-01-04 10:48:19 +00:00
|
|
|
LOAD_FUNCPTR(xsltCleanupGlobals, 1);
|
|
|
|
LOAD_FUNCPTR(xsltFreeStylesheet, 1);
|
2014-04-24 15:40:52 +00:00
|
|
|
LOAD_FUNCPTR(xsltFreeTransformContext, 1);
|
|
|
|
LOAD_FUNCPTR(xsltNewTransformContext, 1);
|
|
|
|
LOAD_FUNCPTR(xsltNextImport, 1);
|
2009-01-04 10:48:19 +00:00
|
|
|
LOAD_FUNCPTR(xsltParseStylesheetDoc, 1);
|
2014-04-24 15:40:52 +00:00
|
|
|
LOAD_FUNCPTR(xsltQuoteUserParams, 1);
|
|
|
|
LOAD_FUNCPTR(xsltSaveResultTo, 1);
|
2009-01-04 10:48:19 +00:00
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
|
|
|
|
if (pxsltInit)
|
|
|
|
pxsltInit();
|
|
|
|
return;
|
|
|
|
|
|
|
|
sym_not_found:
|
|
|
|
wine_dlclose(libxslt_handle, NULL, 0);
|
|
|
|
libxslt_handle = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-04-24 15:40:52 +00:00
|
|
|
#endif /* HAVE_LIBXML2 */
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT WINAPI DllCanUnloadNow(void)
|
|
|
|
{
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-23 11:38:27 +00:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID reserved)
|
2007-12-30 10:49:17 +00:00
|
|
|
{
|
2012-09-09 19:47:25 +00:00
|
|
|
MSXML_hInstance = hInstDLL;
|
|
|
|
|
2007-12-30 10:49:17 +00:00
|
|
|
switch(fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
xmlInitParser();
|
2008-09-08 16:51:03 +00:00
|
|
|
|
2009-01-04 10:48:19 +00:00
|
|
|
/* Set the default indent character to a single tab,
|
|
|
|
for this thread and as default for new threads */
|
2008-09-08 16:51:03 +00:00
|
|
|
xmlTreeIndentString = "\t";
|
2009-01-04 10:48:19 +00:00
|
|
|
xmlThrDefTreeIndentString("\t");
|
2009-08-22 15:10:54 +00:00
|
|
|
|
|
|
|
/* Register callbacks for loading XML files */
|
|
|
|
if(xmlRegisterInputCallbacks(wineXmlMatchCallback, wineXmlOpenCallback,
|
|
|
|
wineXmlReadCallback, wineXmlFileCloseCallback) == -1)
|
|
|
|
WARN("Failed to register callbacks\n");
|
|
|
|
|
2012-09-09 19:47:25 +00:00
|
|
|
schemasInit();
|
2009-01-04 10:48:19 +00:00
|
|
|
init_libxslt();
|
2014-04-24 15:40:52 +00:00
|
|
|
#endif
|
2007-12-30 10:49:17 +00:00
|
|
|
DisableThreadLibraryCalls(hInstDLL);
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
2014-04-24 15:40:52 +00:00
|
|
|
if (reserved) break;
|
|
|
|
#ifdef HAVE_LIBXML2
|
2009-01-04 10:48:19 +00:00
|
|
|
#ifdef SONAME_LIBXSLT
|
|
|
|
if (libxslt_handle)
|
|
|
|
{
|
|
|
|
pxsltCleanupGlobals();
|
|
|
|
wine_dlclose(libxslt_handle, NULL, 0);
|
|
|
|
}
|
2008-09-08 16:51:03 +00:00
|
|
|
#endif
|
2009-08-22 15:10:54 +00:00
|
|
|
/* Restore default Callbacks */
|
|
|
|
xmlCleanupInputCallbacks();
|
|
|
|
xmlRegisterDefaultInputCallbacks();
|
|
|
|
|
2007-12-30 10:49:17 +00:00
|
|
|
xmlCleanupParser();
|
2012-09-09 19:47:25 +00:00
|
|
|
schemasCleanup();
|
2007-12-30 10:49:17 +00:00
|
|
|
#endif
|
2008-09-08 16:51:03 +00:00
|
|
|
release_typelib();
|
2007-12-30 10:49:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-09-09 19:47:25 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllRegisterServer (MSXML3.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllRegisterServer(void)
|
|
|
|
{
|
|
|
|
return __wine_register_resources( MSXML_hInstance );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllUnregisterServer (MSXML3.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllUnregisterServer(void)
|
|
|
|
{
|
|
|
|
return __wine_unregister_resources( MSXML_hInstance );
|
|
|
|
}
|