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>
53 #include "wine/unicode.h"
54 #include "wine/debug.h"
55 #include "wine/library.h"
57 #include "msxml_private.h"
59 HINSTANCE MSXML_hInstance
= NULL
;
63 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
65 void wineXmlCallbackLog(char const* caller
, xmlErrorLevel lvl
, char const* msg
, va_list ap
)
67 enum __wine_debug_class dbcl
;
69 const int max_size
= sizeof(buff
) / sizeof(buff
[0]);
75 dbcl
= __WINE_DBCL_TRACE
;
78 dbcl
= __WINE_DBCL_WARN
;
81 dbcl
= __WINE_DBCL_ERR
;
85 len
= vsnprintf(buff
, max_size
, msg
, ap
);
86 if (len
== -1 || len
>= max_size
) buff
[max_size
-1] = 0;
88 wine_dbg_log(dbcl
, &__wine_dbch_msxml
, caller
, "%s", buff
);
91 void wineXmlCallbackError(char const* caller
, xmlErrorPtr err
)
93 enum __wine_debug_class dbcl
;
97 case XML_ERR_NONE
: dbcl
= __WINE_DBCL_TRACE
; break;
98 case XML_ERR_WARNING
: dbcl
= __WINE_DBCL_WARN
; break;
99 default: dbcl
= __WINE_DBCL_ERR
; break;
102 wine_dbg_log(dbcl
, &__wine_dbch_msxml
, caller
, "error code %d", err
->code
);
104 wine_dbg_log(dbcl
, &__wine_dbch_msxml
, caller
, ": %s", err
->message
);
106 wine_dbg_log(dbcl
, &__wine_dbch_msxml
, caller
, "\n");
109 /* Support for loading xml files from a Wine Windows drive */
110 static int wineXmlMatchCallback (char const * filename
)
114 TRACE("%s\n", filename
);
117 * We will deal with loading XML files from the file system
118 * We only care about files that linux cannot find.
121 if(isalpha(filename
[0]) && filename
[1] == ':')
127 static void *wineXmlOpenCallback (char const * filename
)
129 BSTR sFilename
= bstr_from_xmlChar( (const xmlChar
*)filename
);
132 TRACE("%s\n", debugstr_w(sFilename
));
134 hFile
= CreateFileW(sFilename
, GENERIC_READ
,FILE_SHARE_READ
, NULL
,
135 OPEN_EXISTING
,FILE_ATTRIBUTE_NORMAL
, NULL
);
136 if(hFile
== INVALID_HANDLE_VALUE
) hFile
= 0;
137 SysFreeString(sFilename
);
141 static int wineXmlReadCallback(void * context
, char * buffer
, int len
)
145 TRACE("%p %s %d\n", context
, buffer
, len
);
147 if ((context
== NULL
) || (buffer
== NULL
))
150 if(!ReadFile( context
, buffer
,len
, &dwBytesRead
, NULL
))
152 ERR("Failed to read file\n");
156 TRACE("Read %d\n", dwBytesRead
);
161 static int wineXmlFileCloseCallback (void * context
)
163 return CloseHandle(context
) ? 0 : -1;
166 void* libxslt_handle
= NULL
;
167 #ifdef SONAME_LIBXSLT
168 # define DECL_FUNCPTR(f) typeof(f) * p##f = NULL
169 DECL_FUNCPTR(xsltApplyStylesheet
);
170 DECL_FUNCPTR(xsltApplyStylesheetUser
);
171 DECL_FUNCPTR(xsltCleanupGlobals
);
172 DECL_FUNCPTR(xsltFreeStylesheet
);
173 DECL_FUNCPTR(xsltFreeTransformContext
);
174 DECL_FUNCPTR(xsltNewTransformContext
);
175 DECL_FUNCPTR(xsltNextImport
);
176 DECL_FUNCPTR(xsltParseStylesheetDoc
);
177 DECL_FUNCPTR(xsltQuoteUserParams
);
178 DECL_FUNCPTR(xsltSaveResultTo
);
182 static void init_libxslt(void)
184 #ifdef SONAME_LIBXSLT
185 void (*pxsltInit
)(void); /* Missing in libxslt <= 1.1.14 */
187 libxslt_handle
= wine_dlopen(SONAME_LIBXSLT
, RTLD_NOW
, NULL
, 0);
191 #define LOAD_FUNCPTR(f, needed) \
192 if ((p##f = wine_dlsym(libxslt_handle, #f, NULL, 0)) == NULL) \
193 if (needed) { WARN("Can't find symbol %s\n", #f); goto sym_not_found; }
194 LOAD_FUNCPTR(xsltInit
, 0);
195 LOAD_FUNCPTR(xsltApplyStylesheet
, 1);
196 LOAD_FUNCPTR(xsltApplyStylesheetUser
, 1);
197 LOAD_FUNCPTR(xsltCleanupGlobals
, 1);
198 LOAD_FUNCPTR(xsltFreeStylesheet
, 1);
199 LOAD_FUNCPTR(xsltFreeTransformContext
, 1);
200 LOAD_FUNCPTR(xsltNewTransformContext
, 1);
201 LOAD_FUNCPTR(xsltNextImport
, 1);
202 LOAD_FUNCPTR(xsltParseStylesheetDoc
, 1);
203 LOAD_FUNCPTR(xsltQuoteUserParams
, 1);
204 LOAD_FUNCPTR(xsltSaveResultTo
, 1);
212 wine_dlclose(libxslt_handle
, NULL
, 0);
213 libxslt_handle
= NULL
;
217 #endif /* HAVE_LIBXML2 */
220 HRESULT WINAPI
DllCanUnloadNow(void)
226 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID reserved
)
228 MSXML_hInstance
= hInstDLL
;
232 case DLL_PROCESS_ATTACH
:
236 /* Set the default indent character to a single tab,
237 for this thread and as default for new threads */
238 xmlTreeIndentString
= "\t";
239 xmlThrDefTreeIndentString("\t");
241 /* Register callbacks for loading XML files */
242 if(xmlRegisterInputCallbacks(wineXmlMatchCallback
, wineXmlOpenCallback
,
243 wineXmlReadCallback
, wineXmlFileCloseCallback
) == -1)
244 WARN("Failed to register callbacks\n");
249 DisableThreadLibraryCalls(hInstDLL
);
251 case DLL_PROCESS_DETACH
:
254 #ifdef SONAME_LIBXSLT
257 pxsltCleanupGlobals();
258 wine_dlclose(libxslt_handle
, NULL
, 0);
261 /* Restore default Callbacks */
262 xmlCleanupInputCallbacks();
263 xmlRegisterDefaultInputCallbacks();
274 /***********************************************************************
275 * DllRegisterServer (MSXML3.@)
277 HRESULT WINAPI
DllRegisterServer(void)
279 return __wine_register_resources( MSXML_hInstance
);
282 /***********************************************************************
283 * DllUnregisterServer (MSXML3.@)
285 HRESULT WINAPI
DllUnregisterServer(void)
287 return __wine_unregister_resources( MSXML_hInstance
);