4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2005 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
29 # include <libxml/parser.h>
30 # include <libxml/xmlerror.h>
31 # ifdef SONAME_LIBXSLT
32 # ifdef HAVE_LIBXSLT_PATTERN_H
33 # include <libxslt/pattern.h>
35 # ifdef HAVE_LIBXSLT_TRANSFORM_H
36 # include <libxslt/transform.h>
38 # include <libxslt/xsltutils.h>
39 # include <libxslt/xsltInternals.h>
51 #include "wine/unicode.h"
52 #include "wine/debug.h"
53 #include "wine/library.h"
55 #include "msxml_private.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
59 HINSTANCE MSXML_hInstance
= NULL
;
63 void wineXmlCallbackLog(char const* caller
, xmlErrorLevel lvl
, char const* msg
, va_list ap
)
67 enum __wine_debug_class dbcl
= __WINE_DBCL_ERR
;
71 dbcl
= __WINE_DBCL_TRACE
;
74 dbcl
= __WINE_DBCL_WARN
;
83 buf
= heap_alloc(len
);
84 needed
= vsnprintf(buf
, len
, msg
, ap
);
87 else if (needed
>= len
)
94 wine_dbg_log(dbcl
, &__wine_dbch_msxml
, caller
, "%s", buf
);
98 void wineXmlCallbackError(char const* caller
, xmlErrorPtr err
)
100 enum __wine_debug_class dbcl
;
104 case XML_ERR_NONE
: dbcl
= __WINE_DBCL_TRACE
; break;
105 case XML_ERR_WARNING
: dbcl
= __WINE_DBCL_WARN
; break;
106 default: dbcl
= __WINE_DBCL_ERR
; break;
108 wine_dbg_log(dbcl
, &__wine_dbch_msxml
, caller
, "%s", debugstr_a(err
->message
));
111 /* Support for loading xml files from a Wine Windows drive */
112 static int wineXmlMatchCallback (char const * filename
)
116 TRACE("%s\n", filename
);
119 * We will deal with loading XML files from the file system
120 * We only care about files that linux cannot find.
123 if(isalpha(filename
[0]) && filename
[1] == ':')
129 static void *wineXmlOpenCallback (char const * filename
)
131 BSTR sFilename
= bstr_from_xmlChar( (const xmlChar
*)filename
);
134 TRACE("%s\n", debugstr_w(sFilename
));
136 hFile
= CreateFileW(sFilename
, GENERIC_READ
,FILE_SHARE_READ
, NULL
,
137 OPEN_EXISTING
,FILE_ATTRIBUTE_NORMAL
, NULL
);
138 if(hFile
== INVALID_HANDLE_VALUE
) hFile
= 0;
139 SysFreeString(sFilename
);
143 static int wineXmlReadCallback(void * context
, char * buffer
, int len
)
147 TRACE("%p %s %d\n", context
, buffer
, len
);
149 if ((context
== NULL
) || (buffer
== NULL
))
152 if(!ReadFile( context
, buffer
,len
, &dwBytesRead
, NULL
))
154 ERR("Failed to read file\n");
158 TRACE("Read %d\n", dwBytesRead
);
163 static int wineXmlFileCloseCallback (void * context
)
165 return CloseHandle(context
) ? 0 : -1;
171 HRESULT WINAPI
DllCanUnloadNow(void)
177 void* libxslt_handle
= NULL
;
178 #ifdef SONAME_LIBXSLT
179 # define DECL_FUNCPTR(f) typeof(f) * p##f = NULL
180 DECL_FUNCPTR(xsltApplyStylesheet
);
181 DECL_FUNCPTR(xsltCleanupGlobals
);
182 DECL_FUNCPTR(xsltFreeStylesheet
);
183 DECL_FUNCPTR(xsltParseStylesheetDoc
);
187 static void init_libxslt(void)
189 #ifdef SONAME_LIBXSLT
190 void (*pxsltInit
)(void); /* Missing in libxslt <= 1.1.14 */
192 libxslt_handle
= wine_dlopen(SONAME_LIBXSLT
, RTLD_NOW
, NULL
, 0);
196 #define LOAD_FUNCPTR(f, needed) \
197 if ((p##f = wine_dlsym(libxslt_handle, #f, NULL, 0)) == NULL) \
198 if (needed) { WARN("Can't find symbol %s\n", #f); goto sym_not_found; }
199 LOAD_FUNCPTR(xsltInit
, 0);
200 LOAD_FUNCPTR(xsltApplyStylesheet
, 1);
201 LOAD_FUNCPTR(xsltCleanupGlobals
, 1);
202 LOAD_FUNCPTR(xsltFreeStylesheet
, 1);
203 LOAD_FUNCPTR(xsltParseStylesheetDoc
, 1);
211 wine_dlclose(libxslt_handle
, NULL
, 0);
212 libxslt_handle
= NULL
;
217 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
219 MSXML_hInstance
= hInstDLL
;
223 case DLL_PROCESS_ATTACH
:
227 /* Set the default indent character to a single tab,
228 for this thread and as default for new threads */
229 xmlTreeIndentString
= "\t";
230 xmlThrDefTreeIndentString("\t");
232 /* Register callbacks for loading XML files */
233 if(xmlRegisterInputCallbacks(wineXmlMatchCallback
, wineXmlOpenCallback
,
234 wineXmlReadCallback
, wineXmlFileCloseCallback
) == -1)
235 WARN("Failed to register callbacks\n");
240 DisableThreadLibraryCalls(hInstDLL
);
242 case DLL_PROCESS_DETACH
:
243 #ifdef SONAME_LIBXSLT
246 pxsltCleanupGlobals();
247 wine_dlclose(libxslt_handle
, NULL
, 0);
248 libxslt_handle
= NULL
;
252 /* Restore default Callbacks */
253 xmlCleanupInputCallbacks();
254 xmlRegisterDefaultInputCallbacks();
265 const char *debugstr_variant(const VARIANT
*v
)
276 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v
));
278 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v
));
280 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v
)));
282 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v
));
284 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v
));
286 return wine_dbg_sprintf("{VT_UNKNOWN: %p}", V_UNKNOWN(v
));
288 return wine_dbg_sprintf("{VT_UINT: %u}", V_UINT(v
));
289 case VT_BSTR
|VT_BYREF
:
290 return wine_dbg_sprintf("{VT_BSTR|VT_BYREF: ptr %p, data %s}",
291 V_BSTRREF(v
), debugstr_w(V_BSTRREF(v
) ? *V_BSTRREF(v
) : NULL
));
293 return wine_dbg_sprintf("{vt %d}", V_VT(v
));
297 /***********************************************************************
298 * DllRegisterServer (MSXML3.@)
300 HRESULT WINAPI
DllRegisterServer(void)
302 return __wine_register_resources( MSXML_hInstance
);
305 /***********************************************************************
306 * DllUnregisterServer (MSXML3.@)
308 HRESULT WINAPI
DllUnregisterServer(void)
310 return __wine_unregister_resources( MSXML_hInstance
);