ucrtbase: Add __stdio_common_vfprintf_s.
[wine.git] / dlls / msxml3 / main.c
blob1905f57be4f12f9afcd9d1feaa3bdc9940439605
1 /*
2 * MSXML Class Factory
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
22 #include "config.h"
23 #include "wine/port.h"
25 #define COBJMACROS
27 #include <stdarg.h>
28 #ifdef HAVE_LIBXML2
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>
34 # endif
35 # ifdef HAVE_LIBXSLT_TRANSFORM_H
36 # include <libxslt/transform.h>
37 # endif
38 # include <libxslt/imports.h>
39 # include <libxslt/xsltutils.h>
40 # include <libxslt/variables.h>
41 # include <libxslt/xsltInternals.h>
42 # endif
43 #endif
45 #include "windef.h"
46 #include "winbase.h"
47 #include "winuser.h"
48 #include "ole2.h"
49 #include "rpcproxy.h"
50 #include "msxml.h"
51 #include "msxml6.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;
61 #ifdef HAVE_LIBXML2
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;
68 char buff[200];
69 const int max_size = sizeof(buff) / sizeof(buff[0]);
70 int len;
72 switch (lvl)
74 case XML_ERR_NONE:
75 dbcl = __WINE_DBCL_TRACE;
76 break;
77 case XML_ERR_WARNING:
78 dbcl = __WINE_DBCL_WARN;
79 break;
80 default:
81 dbcl = __WINE_DBCL_ERR;
82 break;
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;
95 switch (err->level)
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);
103 if (err->message)
104 wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, ": %s", err->message);
105 else
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)
112 int nRet = 0;
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.
119 * e.g. C:,D: etc
121 if(isalpha(filename[0]) && filename[1] == ':')
122 nRet = 1;
124 return nRet;
127 static void *wineXmlOpenCallback (char const * filename)
129 BSTR sFilename = bstr_from_xmlChar( (const xmlChar*)filename);
130 HANDLE hFile;
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);
138 return hFile;
141 static int wineXmlReadCallback(void * context, char * buffer, int len)
143 DWORD dwBytesRead;
145 TRACE("%p %s %d\n", context, buffer, len);
147 if ((context == NULL) || (buffer == NULL))
148 return(-1);
150 if(!ReadFile( context, buffer,len, &dwBytesRead, NULL))
152 ERR("Failed to read file\n");
153 return -1;
156 TRACE("Read %d\n", dwBytesRead);
158 return 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);
179 # undef DECL_FUNCPTR
180 #endif
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);
188 if (!libxslt_handle)
189 return;
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);
205 #undef LOAD_FUNCPTR
207 if (pxsltInit)
208 pxsltInit();
209 return;
211 sym_not_found:
212 wine_dlclose(libxslt_handle, NULL, 0);
213 libxslt_handle = NULL;
214 #endif
217 #endif /* HAVE_LIBXML2 */
220 HRESULT WINAPI DllCanUnloadNow(void)
222 return S_FALSE;
226 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID reserved)
228 MSXML_hInstance = hInstDLL;
230 switch(fdwReason)
232 case DLL_PROCESS_ATTACH:
233 #ifdef HAVE_LIBXML2
234 xmlInitParser();
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");
246 schemasInit();
247 init_libxslt();
248 #endif
249 DisableThreadLibraryCalls(hInstDLL);
250 break;
251 case DLL_PROCESS_DETACH:
252 if (reserved) break;
253 #ifdef HAVE_LIBXML2
254 #ifdef SONAME_LIBXSLT
255 if (libxslt_handle)
257 pxsltCleanupGlobals();
258 wine_dlclose(libxslt_handle, NULL, 0);
260 #endif
261 /* Restore default Callbacks */
262 xmlCleanupInputCallbacks();
263 xmlRegisterDefaultInputCallbacks();
265 xmlCleanupParser();
266 schemasCleanup();
267 #endif
268 release_typelib();
269 break;
271 return TRUE;
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 );