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/imports.h>
39 # include <libxslt/xsltutils.h>
40 # include <libxslt/variables.h>
41 # include <libxslt/xsltInternals.h>
42 # include <libxslt/documents.h>
43 # include <libxslt/extensions.h>
44 # include <libxslt/extra.h>
56 #include "wine/unicode.h"
57 #include "wine/debug.h"
58 #include "wine/library.h"
60 #include "msxml_private.h"
62 HINSTANCE MSXML_hInstance
= NULL
;
66 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
68 void wineXmlCallbackLog(char const* caller
, xmlErrorLevel lvl
, char const* msg
, va_list ap
)
70 enum __wine_debug_class dbcl
;
72 const int max_size
= sizeof(buff
) / sizeof(buff
[0]);
78 dbcl
= __WINE_DBCL_TRACE
;
81 dbcl
= __WINE_DBCL_WARN
;
84 dbcl
= __WINE_DBCL_ERR
;
88 len
= vsnprintf(buff
, max_size
, msg
, ap
);
89 if (len
== -1 || len
>= max_size
) buff
[max_size
-1] = 0;
91 wine_dbg_log(dbcl
, &__wine_dbch_msxml
, caller
, "%s", buff
);
94 void wineXmlCallbackError(char const* caller
, xmlErrorPtr err
)
96 enum __wine_debug_class dbcl
;
100 case XML_ERR_NONE
: dbcl
= __WINE_DBCL_TRACE
; break;
101 case XML_ERR_WARNING
: dbcl
= __WINE_DBCL_WARN
; break;
102 default: dbcl
= __WINE_DBCL_ERR
; break;
105 wine_dbg_log(dbcl
, &__wine_dbch_msxml
, caller
, "error code %d", err
->code
);
107 wine_dbg_log(dbcl
, &__wine_dbch_msxml
, caller
, ": %s", err
->message
);
109 wine_dbg_log(dbcl
, &__wine_dbch_msxml
, caller
, "\n");
112 /* Support for loading xml files from a Wine Windows drive */
113 static int wineXmlMatchCallback (char const * filename
)
117 TRACE("%s\n", filename
);
120 * We will deal with loading XML files from the file system
121 * We only care about files that linux cannot find.
124 if(isalpha(filename
[0]) && filename
[1] == ':')
130 static void *wineXmlOpenCallback (char const * filename
)
132 BSTR sFilename
= bstr_from_xmlChar( (const xmlChar
*)filename
);
135 TRACE("%s\n", debugstr_w(sFilename
));
137 hFile
= CreateFileW(sFilename
, GENERIC_READ
,FILE_SHARE_READ
, NULL
,
138 OPEN_EXISTING
,FILE_ATTRIBUTE_NORMAL
, NULL
);
139 if(hFile
== INVALID_HANDLE_VALUE
) hFile
= 0;
140 SysFreeString(sFilename
);
144 static int wineXmlReadCallback(void * context
, char * buffer
, int len
)
148 TRACE("%p %s %d\n", context
, buffer
, len
);
150 if ((context
== NULL
) || (buffer
== NULL
))
153 if(!ReadFile( context
, buffer
,len
, &dwBytesRead
, NULL
))
155 ERR("Failed to read file\n");
159 TRACE("Read %d\n", dwBytesRead
);
164 static int wineXmlFileCloseCallback (void * context
)
166 return CloseHandle(context
) ? 0 : -1;
169 void* libxslt_handle
= NULL
;
170 #ifdef SONAME_LIBXSLT
171 # define DECL_FUNCPTR(f) typeof(f) * p##f = NULL
172 DECL_FUNCPTR(xsltApplyStylesheet
);
173 DECL_FUNCPTR(xsltApplyStylesheetUser
);
174 DECL_FUNCPTR(xsltCleanupGlobals
);
175 DECL_FUNCPTR(xsltFreeStylesheet
);
176 DECL_FUNCPTR(xsltFreeTransformContext
);
177 DECL_FUNCPTR(xsltFunctionNodeSet
);
178 DECL_FUNCPTR(xsltNewTransformContext
);
179 DECL_FUNCPTR(xsltNextImport
);
180 DECL_FUNCPTR(xsltParseStylesheetDoc
);
181 DECL_FUNCPTR(xsltQuoteUserParams
);
182 DECL_FUNCPTR(xsltRegisterExtModuleFunction
);
183 DECL_FUNCPTR(xsltSaveResultTo
);
184 DECL_FUNCPTR(xsltSetLoaderFunc
);
188 static void init_libxslt(void)
190 #ifdef SONAME_LIBXSLT
191 void (*pxsltInit
)(void); /* Missing in libxslt <= 1.1.14 */
193 libxslt_handle
= wine_dlopen(SONAME_LIBXSLT
, RTLD_NOW
, NULL
, 0);
197 #define LOAD_FUNCPTR(f, needed) \
198 if ((p##f = wine_dlsym(libxslt_handle, #f, NULL, 0)) == NULL) \
199 if (needed) { WARN("Can't find symbol %s\n", #f); goto sym_not_found; }
200 LOAD_FUNCPTR(xsltInit
, 0);
201 LOAD_FUNCPTR(xsltApplyStylesheet
, 1);
202 LOAD_FUNCPTR(xsltApplyStylesheetUser
, 1);
203 LOAD_FUNCPTR(xsltCleanupGlobals
, 1);
204 LOAD_FUNCPTR(xsltFreeStylesheet
, 1);
205 LOAD_FUNCPTR(xsltFreeTransformContext
, 1);
206 LOAD_FUNCPTR(xsltFunctionNodeSet
, 1);
207 LOAD_FUNCPTR(xsltNewTransformContext
, 1);
208 LOAD_FUNCPTR(xsltNextImport
, 1);
209 LOAD_FUNCPTR(xsltParseStylesheetDoc
, 1);
210 LOAD_FUNCPTR(xsltQuoteUserParams
, 1);
211 LOAD_FUNCPTR(xsltRegisterExtModuleFunction
, 1);
212 LOAD_FUNCPTR(xsltSaveResultTo
, 1);
213 LOAD_FUNCPTR(xsltSetLoaderFunc
, 1);
219 pxsltSetLoaderFunc(xslt_doc_default_loader
);
220 pxsltRegisterExtModuleFunction(
221 (const xmlChar
*)"node-set",
222 (const xmlChar
*)"urn:schemas-microsoft-com:xslt",
223 pxsltFunctionNodeSet
);
228 wine_dlclose(libxslt_handle
, NULL
, 0);
229 libxslt_handle
= NULL
;
233 #endif /* HAVE_LIBXML2 */
236 HRESULT WINAPI
DllCanUnloadNow(void)
242 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID reserved
)
244 MSXML_hInstance
= hInstDLL
;
248 case DLL_PROCESS_ATTACH
:
252 /* Set the default indent character to a single tab,
253 for this thread and as default for new threads */
254 xmlTreeIndentString
= "\t";
255 xmlThrDefTreeIndentString("\t");
257 /* Register callbacks for loading XML files */
258 if(xmlRegisterInputCallbacks(wineXmlMatchCallback
, wineXmlOpenCallback
,
259 wineXmlReadCallback
, wineXmlFileCloseCallback
) == -1)
260 WARN("Failed to register callbacks\n");
265 DisableThreadLibraryCalls(hInstDLL
);
267 case DLL_PROCESS_DETACH
:
270 #ifdef SONAME_LIBXSLT
273 pxsltCleanupGlobals();
274 wine_dlclose(libxslt_handle
, NULL
, 0);
277 /* Restore default Callbacks */
278 xmlCleanupInputCallbacks();
279 xmlRegisterDefaultInputCallbacks();
290 /***********************************************************************
291 * DllRegisterServer (MSXML3.@)
293 HRESULT WINAPI
DllRegisterServer(void)
295 return __wine_register_resources( MSXML_hInstance
);
298 /***********************************************************************
299 * DllUnregisterServer (MSXML3.@)
301 HRESULT WINAPI
DllUnregisterServer(void)
303 return __wine_unregister_resources( MSXML_hInstance
);