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
|
|
|
*/
|
|
|
|
|
2005-08-09 13:17:47 +02:00
|
|
|
#include "config.h"
|
2008-11-17 19:29:32 +01:00
|
|
|
#include "wine/port.h"
|
2005-08-09 13:17:47 +02:00
|
|
|
|
2008-02-14 10:55:33 +01:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2005-08-02 13:29:04 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#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"
|
2010-08-29 23:31:49 +02:00
|
|
|
#include "msxml6.h"
|
2005-08-02 13:29:04 +02:00
|
|
|
|
2009-08-10 14:30:51 +02:00
|
|
|
#include "wine/unicode.h"
|
2005-08-02 13:29:04 +02:00
|
|
|
#include "wine/debug.h"
|
2008-11-17 19:29:32 +01:00
|
|
|
#include "wine/library.h"
|
2005-08-02 13:29:04 +02:00
|
|
|
|
2005-08-09 13:17:47 +02:00
|
|
|
#include "msxml_private.h"
|
|
|
|
|
2005-08-02 13:29:04 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msxml);
|
|
|
|
|
2010-11-10 04:40:34 +01:00
|
|
|
HINSTANCE MSXML_hInstance = NULL;
|
|
|
|
|
2009-08-10 14:30:51 +02:00
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
|
2010-10-27 16:35:56 +02:00
|
|
|
void wineXmlCallbackLog(char const* caller, xmlErrorLevel lvl, char const* msg, va_list ap)
|
|
|
|
{
|
|
|
|
char* buf = NULL;
|
|
|
|
int len = 32, needed;
|
|
|
|
enum __wine_debug_class dbcl = __WINE_DBCL_ERR;
|
|
|
|
switch (lvl)
|
|
|
|
{
|
|
|
|
case XML_ERR_NONE:
|
|
|
|
dbcl = __WINE_DBCL_TRACE;
|
|
|
|
break;
|
|
|
|
case XML_ERR_WARNING:
|
|
|
|
dbcl = __WINE_DBCL_WARN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-11-17 14:21:09 +01:00
|
|
|
do
|
2010-10-27 16:35:56 +02:00
|
|
|
{
|
|
|
|
heap_free(buf);
|
2010-11-17 14:21:09 +01:00
|
|
|
buf = heap_alloc(len);
|
|
|
|
needed = vsnprintf(buf, len, msg, ap);
|
|
|
|
if (needed == -1)
|
|
|
|
len *= 2;
|
|
|
|
else if (needed >= len)
|
|
|
|
len = needed + 1;
|
|
|
|
else
|
|
|
|
needed = 0;
|
2010-10-27 16:35:56 +02:00
|
|
|
}
|
2010-11-17 14:21:09 +01:00
|
|
|
while (needed);
|
|
|
|
|
|
|
|
wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "%s", buf);
|
|
|
|
heap_free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2010-11-17 14:21:09 +01:00
|
|
|
wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "%s", err->message);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllCanUnloadNow(void)
|
2005-08-02 13:29:04 +02:00
|
|
|
{
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-17 19:29:32 +01:00
|
|
|
|
|
|
|
void* libxslt_handle = NULL;
|
|
|
|
#ifdef SONAME_LIBXSLT
|
|
|
|
# define DECL_FUNCPTR(f) typeof(f) * p##f = NULL
|
|
|
|
DECL_FUNCPTR(xsltApplyStylesheet);
|
|
|
|
DECL_FUNCPTR(xsltCleanupGlobals);
|
|
|
|
DECL_FUNCPTR(xsltFreeStylesheet);
|
|
|
|
DECL_FUNCPTR(xsltParseStylesheetDoc);
|
2010-10-27 16:35:56 +02:00
|
|
|
# undef DECL_FUNCPTR
|
2008-11-17 19:29:32 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void init_libxslt(void)
|
|
|
|
{
|
|
|
|
#ifdef SONAME_LIBXSLT
|
2008-11-19 08:40:25 +01:00
|
|
|
void (*pxsltInit)(void); /* Missing in libxslt <= 1.1.14 */
|
|
|
|
|
2008-11-17 19:29:32 +01:00
|
|
|
libxslt_handle = wine_dlopen(SONAME_LIBXSLT, RTLD_NOW, NULL, 0);
|
|
|
|
if (!libxslt_handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#define LOAD_FUNCPTR(f, needed) if ((p##f = wine_dlsym(libxslt_handle, #f, NULL, 0)) == NULL && needed) { WARN("Can't find symbol %s\n", #f); goto sym_not_found; }
|
|
|
|
LOAD_FUNCPTR(xsltInit, 0);
|
|
|
|
LOAD_FUNCPTR(xsltApplyStylesheet, 1);
|
|
|
|
LOAD_FUNCPTR(xsltCleanupGlobals, 1);
|
|
|
|
LOAD_FUNCPTR(xsltFreeStylesheet, 1);
|
|
|
|
LOAD_FUNCPTR(xsltParseStylesheetDoc, 1);
|
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
|
|
|
|
if (pxsltInit)
|
|
|
|
pxsltInit();
|
|
|
|
return;
|
|
|
|
|
|
|
|
sym_not_found:
|
|
|
|
wine_dlclose(libxslt_handle, NULL, 0);
|
|
|
|
libxslt_handle = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-02 13:29:04 +02:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
|
|
|
|
{
|
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
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
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");
|
|
|
|
|
2010-11-12 15:33:17 +01:00
|
|
|
schemasInit();
|
2008-03-26 09:52:36 +01:00
|
|
|
#endif
|
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:
|
2008-11-17 19:29:32 +01:00
|
|
|
#ifdef SONAME_LIBXSLT
|
|
|
|
if (libxslt_handle)
|
|
|
|
{
|
|
|
|
pxsltCleanupGlobals();
|
|
|
|
wine_dlclose(libxslt_handle, NULL, 0);
|
|
|
|
libxslt_handle = NULL;
|
|
|
|
}
|
2008-03-26 09:52:36 +01:00
|
|
|
#endif
|
2005-08-09 13:17:47 +02:00
|
|
|
#ifdef HAVE_LIBXML2
|
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();
|
2005-08-09 13:17:47 +02:00
|
|
|
#endif
|
2008-08-21 23:37:48 +02:00
|
|
|
release_typelib();
|
2005-08-02 13:29:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-12-21 13:41:29 +01:00
|
|
|
|
2010-12-30 13:07:50 +01:00
|
|
|
const char *debugstr_variant(const VARIANT *v)
|
|
|
|
{
|
|
|
|
if(!v)
|
|
|
|
return "(null)";
|
|
|
|
|
|
|
|
switch(V_VT(v)) {
|
|
|
|
case VT_EMPTY:
|
|
|
|
return "{VT_EMPTY}";
|
|
|
|
case VT_NULL:
|
|
|
|
return "{VT_NULL}";
|
|
|
|
case VT_I4:
|
|
|
|
return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
|
|
|
|
case VT_R8:
|
|
|
|
return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
|
|
|
|
case VT_BSTR:
|
|
|
|
return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
|
|
|
|
case VT_DISPATCH:
|
|
|
|
return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
|
|
|
|
case VT_BOOL:
|
|
|
|
return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
|
|
|
|
case VT_UINT:
|
|
|
|
return wine_dbg_sprintf("{VT_UINT: %u}", V_UINT(v));
|
|
|
|
default:
|
|
|
|
return wine_dbg_sprintf("{vt %d}", V_VT(v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-21 13:41:29 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* DllRegisterServer (MSXML3.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllRegisterServer(void)
|
|
|
|
{
|
|
|
|
return __wine_register_resources( MSXML_hInstance, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllUnregisterServer (MSXML3.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllUnregisterServer(void)
|
|
|
|
{
|
|
|
|
return __wine_unregister_resources( MSXML_hInstance, NULL );
|
|
|
|
}
|