odbccp32: Add ordinals to spec file.
[wine.git] / dlls / msxml3 / main.c
blob5967ac057b4d5049d487a7b250147c3bf98c5dd1
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/xsltutils.h>
39 # include <libxslt/variables.h>
40 # include <libxslt/xsltInternals.h>
41 # endif
42 #endif
44 #include "windef.h"
45 #include "winbase.h"
46 #include "winuser.h"
47 #include "ole2.h"
48 #include "rpcproxy.h"
49 #include "msxml.h"
50 #include "msxml6.h"
52 #include "wine/unicode.h"
53 #include "wine/debug.h"
54 #include "wine/library.h"
56 #include "msxml_private.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
60 HINSTANCE MSXML_hInstance = NULL;
62 #ifdef HAVE_LIBXML2
64 void wineXmlCallbackLog(char const* caller, xmlErrorLevel lvl, char const* msg, va_list ap)
66 static const int max_size = 200;
67 enum __wine_debug_class dbcl;
68 char buff[max_size];
69 int len;
71 switch (lvl)
73 case XML_ERR_NONE:
74 dbcl = __WINE_DBCL_TRACE;
75 break;
76 case XML_ERR_WARNING:
77 dbcl = __WINE_DBCL_WARN;
78 break;
79 default:
80 dbcl = __WINE_DBCL_ERR;
81 break;
84 len = vsnprintf(buff, max_size, msg, ap);
85 if (len == -1 || len >= max_size) buff[max_size-1] = 0;
87 wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "%s", buff);
90 void wineXmlCallbackError(char const* caller, xmlErrorPtr err)
92 enum __wine_debug_class dbcl;
94 switch (err->level)
96 case XML_ERR_NONE: dbcl = __WINE_DBCL_TRACE; break;
97 case XML_ERR_WARNING: dbcl = __WINE_DBCL_WARN; break;
98 default: dbcl = __WINE_DBCL_ERR; break;
101 wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "error code %d", err->code);
102 if (err->message)
103 wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, ": %s", err->message);
104 else
105 wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "\n");
108 /* Support for loading xml files from a Wine Windows drive */
109 static int wineXmlMatchCallback (char const * filename)
111 int nRet = 0;
113 TRACE("%s\n", filename);
116 * We will deal with loading XML files from the file system
117 * We only care about files that linux cannot find.
118 * e.g. C:,D: etc
120 if(isalpha(filename[0]) && filename[1] == ':')
121 nRet = 1;
123 return nRet;
126 static void *wineXmlOpenCallback (char const * filename)
128 BSTR sFilename = bstr_from_xmlChar( (const xmlChar*)filename);
129 HANDLE hFile;
131 TRACE("%s\n", debugstr_w(sFilename));
133 hFile = CreateFileW(sFilename, GENERIC_READ,FILE_SHARE_READ, NULL,
134 OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
135 if(hFile == INVALID_HANDLE_VALUE) hFile = 0;
136 SysFreeString(sFilename);
137 return hFile;
140 static int wineXmlReadCallback(void * context, char * buffer, int len)
142 DWORD dwBytesRead;
144 TRACE("%p %s %d\n", context, buffer, len);
146 if ((context == NULL) || (buffer == NULL))
147 return(-1);
149 if(!ReadFile( context, buffer,len, &dwBytesRead, NULL))
151 ERR("Failed to read file\n");
152 return -1;
155 TRACE("Read %d\n", dwBytesRead);
157 return dwBytesRead;
160 static int wineXmlFileCloseCallback (void * context)
162 return CloseHandle(context) ? 0 : -1;
165 void* libxslt_handle = NULL;
166 #ifdef SONAME_LIBXSLT
167 # define DECL_FUNCPTR(f) typeof(f) * p##f = NULL
168 DECL_FUNCPTR(xsltApplyStylesheet);
169 DECL_FUNCPTR(xsltApplyStylesheetUser);
170 DECL_FUNCPTR(xsltCleanupGlobals);
171 DECL_FUNCPTR(xsltFreeStylesheet);
172 DECL_FUNCPTR(xsltFreeTransformContext);
173 DECL_FUNCPTR(xsltNewTransformContext);
174 DECL_FUNCPTR(xsltParseStylesheetDoc);
175 DECL_FUNCPTR(xsltQuoteUserParams);
176 DECL_FUNCPTR(xsltSaveResultTo);
177 # undef DECL_FUNCPTR
178 #endif
180 static void init_libxslt(void)
182 #ifdef SONAME_LIBXSLT
183 void (*pxsltInit)(void); /* Missing in libxslt <= 1.1.14 */
185 libxslt_handle = wine_dlopen(SONAME_LIBXSLT, RTLD_NOW, NULL, 0);
186 if (!libxslt_handle)
187 return;
189 #define LOAD_FUNCPTR(f, needed) \
190 if ((p##f = wine_dlsym(libxslt_handle, #f, NULL, 0)) == NULL) \
191 if (needed) { WARN("Can't find symbol %s\n", #f); goto sym_not_found; }
192 LOAD_FUNCPTR(xsltInit, 0);
193 LOAD_FUNCPTR(xsltApplyStylesheet, 1);
194 LOAD_FUNCPTR(xsltApplyStylesheetUser, 1);
195 LOAD_FUNCPTR(xsltCleanupGlobals, 1);
196 LOAD_FUNCPTR(xsltFreeStylesheet, 1);
197 LOAD_FUNCPTR(xsltFreeTransformContext, 1);
198 LOAD_FUNCPTR(xsltNewTransformContext, 1);
199 LOAD_FUNCPTR(xsltParseStylesheetDoc, 1);
200 LOAD_FUNCPTR(xsltQuoteUserParams, 1);
201 LOAD_FUNCPTR(xsltSaveResultTo, 1);
202 #undef LOAD_FUNCPTR
204 if (pxsltInit)
205 pxsltInit();
206 return;
208 sym_not_found:
209 wine_dlclose(libxslt_handle, NULL, 0);
210 libxslt_handle = NULL;
211 #endif
214 #endif /* HAVE_LIBXML2 */
217 HRESULT WINAPI DllCanUnloadNow(void)
219 return S_FALSE;
223 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID reserved)
225 MSXML_hInstance = hInstDLL;
227 switch(fdwReason)
229 case DLL_PROCESS_ATTACH:
230 #ifdef HAVE_LIBXML2
231 xmlInitParser();
233 /* Set the default indent character to a single tab,
234 for this thread and as default for new threads */
235 xmlTreeIndentString = "\t";
236 xmlThrDefTreeIndentString("\t");
238 /* Register callbacks for loading XML files */
239 if(xmlRegisterInputCallbacks(wineXmlMatchCallback, wineXmlOpenCallback,
240 wineXmlReadCallback, wineXmlFileCloseCallback) == -1)
241 WARN("Failed to register callbacks\n");
243 schemasInit();
244 init_libxslt();
245 #endif
246 DisableThreadLibraryCalls(hInstDLL);
247 break;
248 case DLL_PROCESS_DETACH:
249 if (reserved) break;
250 #ifdef HAVE_LIBXML2
251 #ifdef SONAME_LIBXSLT
252 if (libxslt_handle)
254 pxsltCleanupGlobals();
255 wine_dlclose(libxslt_handle, NULL, 0);
257 #endif
258 /* Restore default Callbacks */
259 xmlCleanupInputCallbacks();
260 xmlRegisterDefaultInputCallbacks();
262 xmlCleanupParser();
263 schemasCleanup();
264 #endif
265 release_typelib();
266 break;
268 return TRUE;
271 const char *debugstr_variant(const VARIANT *v)
273 if(!v)
274 return "(null)";
276 switch(V_VT(v)) {
277 case VT_EMPTY:
278 return "{VT_EMPTY}";
279 case VT_NULL:
280 return "{VT_NULL}";
281 case VT_I1:
282 return wine_dbg_sprintf("{VT_I1: %d}", V_I1(v));
283 case VT_I2:
284 return wine_dbg_sprintf("{VT_I2: %d}", V_I2(v));
285 case VT_I4:
286 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
287 case VT_INT:
288 return wine_dbg_sprintf("{VT_INT: %d}", V_INT(v));
289 case VT_R8:
290 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
291 case VT_BSTR:
292 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
293 case VT_DISPATCH:
294 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
295 case VT_BOOL:
296 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
297 case VT_UNKNOWN:
298 return wine_dbg_sprintf("{VT_UNKNOWN: %p}", V_UNKNOWN(v));
299 case VT_UINT:
300 return wine_dbg_sprintf("{VT_UINT: %u}", V_UINT(v));
301 case VT_BSTR|VT_BYREF:
302 return wine_dbg_sprintf("{VT_BSTR|VT_BYREF: ptr %p, data %s}",
303 V_BSTRREF(v), debugstr_w(V_BSTRREF(v) ? *V_BSTRREF(v) : NULL));
304 case VT_ERROR:
305 return wine_dbg_sprintf("{VT_ERROR: 0x%08x}", V_ERROR(v));
306 case VT_VARIANT|VT_BYREF:
307 return wine_dbg_sprintf("{VT_VARIANT|VT_BYREF: %s}", debugstr_variant(V_VARIANTREF(v)));
308 case VT_UI1|VT_ARRAY:
309 return "{VT_UI1|VT_ARRAY}";
310 default:
311 return wine_dbg_sprintf("{vt %d}", V_VT(v));
315 /***********************************************************************
316 * DllRegisterServer (MSXML3.@)
318 HRESULT WINAPI DllRegisterServer(void)
320 return __wine_register_resources( MSXML_hInstance );
323 /***********************************************************************
324 * DllUnregisterServer (MSXML3.@)
326 HRESULT WINAPI DllUnregisterServer(void)
328 return __wine_unregister_resources( MSXML_hInstance );