dinput: Clear DIA_APPNOMAP BuildActionMap flag with specific device semantic.
[wine.git] / dlls / msxml3 / main.c
blob66e23114bfaf65531ca16af58aa26e5e625895ce
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 #define COBJMACROS
24 #include <stdarg.h>
25 #include <libxml/parser.h>
26 #include <libxml/xmlerror.h>
27 #include <libxslt/pattern.h>
28 #include <libxslt/transform.h>
29 #include <libxslt/imports.h>
30 #include <libxslt/xsltutils.h>
31 #include <libxslt/variables.h>
32 #include <libxslt/xsltInternals.h>
33 #include <libxslt/documents.h>
34 #include <libxslt/extensions.h>
35 #include <libxslt/extra.h>
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winuser.h"
40 #include "ole2.h"
41 #include "rpcproxy.h"
42 #include "msxml.h"
43 #include "msxml2.h"
44 #include "msxml6.h"
46 #include "wine/debug.h"
48 #include "msxml_private.h"
50 HINSTANCE MSXML_hInstance = NULL;
52 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
54 void wineXmlCallbackLog(char const* caller, xmlErrorLevel lvl, char const* msg, va_list ap)
56 enum __wine_debug_class dbcl;
57 char buff[200];
58 const int max_size = ARRAY_SIZE(buff);
59 int len;
61 switch (lvl)
63 case XML_ERR_NONE:
64 dbcl = __WINE_DBCL_TRACE;
65 break;
66 case XML_ERR_WARNING:
67 dbcl = __WINE_DBCL_WARN;
68 break;
69 default:
70 dbcl = __WINE_DBCL_ERR;
71 break;
74 len = vsnprintf(buff, max_size, msg, ap);
75 if (len == -1 || len >= max_size) buff[max_size-1] = 0;
77 wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "%s", buff);
80 void wineXmlCallbackError(char const* caller, xmlErrorPtr err)
82 enum __wine_debug_class dbcl;
84 switch (err->level)
86 case XML_ERR_NONE: dbcl = __WINE_DBCL_TRACE; break;
87 case XML_ERR_WARNING: dbcl = __WINE_DBCL_WARN; break;
88 default: dbcl = __WINE_DBCL_ERR; break;
91 wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "error code %d", err->code);
92 if (err->message)
93 wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, ": %s", err->message);
94 else
95 wine_dbg_log(dbcl, &__wine_dbch_msxml, caller, "\n");
98 /* Support for loading xml files from a Wine Windows drive */
99 static int wineXmlMatchCallback (char const * filename)
101 int nRet = 0;
103 TRACE("%s\n", filename);
106 * We will deal with loading XML files from the file system
107 * We only care about files that linux cannot find.
108 * e.g. C:,D: etc
110 if(isalpha(filename[0]) && filename[1] == ':')
111 nRet = 1;
113 return nRet;
116 static void *wineXmlOpenCallback (char const * filename)
118 BSTR sFilename = bstr_from_xmlChar( (const xmlChar*)filename);
119 HANDLE hFile;
121 TRACE("%s\n", debugstr_w(sFilename));
123 hFile = CreateFileW(sFilename, GENERIC_READ,FILE_SHARE_READ, NULL,
124 OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
125 if(hFile == INVALID_HANDLE_VALUE) hFile = 0;
126 SysFreeString(sFilename);
127 return hFile;
130 static int wineXmlReadCallback(void * context, char * buffer, int len)
132 DWORD dwBytesRead;
134 TRACE("%p %s %d\n", context, buffer, len);
136 if ((context == NULL) || (buffer == NULL))
137 return(-1);
139 if(!ReadFile( context, buffer,len, &dwBytesRead, NULL))
141 ERR("Failed to read file\n");
142 return -1;
145 TRACE("Read %ld bytes.\n", dwBytesRead);
147 return dwBytesRead;
150 static int wineXmlFileCloseCallback (void * context)
152 return CloseHandle(context) ? 0 : -1;
155 static void init_libxslt(void)
157 xsltInit();
158 xsltSetLoaderFunc(xslt_doc_default_loader);
159 xsltRegisterExtModuleFunction(
160 (const xmlChar *)"node-set",
161 (const xmlChar *)"urn:schemas-microsoft-com:xslt",
162 xsltFunctionNodeSet);
165 static int to_utf8(int cp, unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
167 WCHAR *tmp;
168 int len = 0;
170 if (!in || !inlen) goto done;
172 len = MultiByteToWideChar(cp, 0, (const char *)in, *inlen, NULL, 0);
173 tmp = heap_alloc(len * sizeof(WCHAR));
174 if (!tmp) return -1;
175 MultiByteToWideChar(cp, 0, (const char *)in, *inlen, tmp, len);
177 len = WideCharToMultiByte(CP_UTF8, 0, tmp, len, (char *)out, *outlen, NULL, NULL);
178 heap_free(tmp);
179 if (!len) return -1;
180 done:
181 *outlen = len;
182 return len;
185 static int from_utf8(int cp, unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
187 WCHAR *tmp;
188 int len = 0;
190 if (!in || !inlen) goto done;
192 len = MultiByteToWideChar(CP_UTF8, 0, (const char *)in, *inlen, NULL, 0);
193 tmp = heap_alloc(len * sizeof(WCHAR));
194 if (!tmp) return -1;
195 MultiByteToWideChar(CP_UTF8, 0, (const char *)in, *inlen, tmp, len);
197 len = WideCharToMultiByte(cp, 0, tmp, len, (char *)out, *outlen, NULL, NULL);
198 heap_free(tmp);
199 if (!len) return -1;
200 done:
201 *outlen = len;
202 return len;
205 static int gbk_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
207 return to_utf8(936, out, outlen, in, inlen);
210 static int utf8_to_gbk(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
212 return from_utf8(936, out, outlen, in, inlen);
215 static int win1250_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
217 return to_utf8(1250, out, outlen, in, inlen);
220 static int utf8_to_win1250(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
222 return from_utf8(1250, out, outlen, in, inlen);
225 static int win1251_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
227 return to_utf8(1251, out, outlen, in, inlen);
230 static int utf8_to_win1251(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
232 return from_utf8(1251, out, outlen, in, inlen);
235 static int win1252_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
237 return to_utf8(1252, out, outlen, in, inlen);
240 static int utf8_to_win1252(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
242 return from_utf8(1252, out, outlen, in, inlen);
245 static int win1253_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
247 return to_utf8(1253, out, outlen, in, inlen);
250 static int utf8_to_win1253(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
252 return from_utf8(1253, out, outlen, in, inlen);
254 static int win1254_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
256 return to_utf8(1254, out, outlen, in, inlen);
259 static int utf8_to_win1254(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
261 return from_utf8(1254, out, outlen, in, inlen);
264 static int win1255_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
266 return to_utf8(1255, out, outlen, in, inlen);
269 static int utf8_to_win1255(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
271 return from_utf8(1255, out, outlen, in, inlen);
274 static int win1256_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
276 return to_utf8(1256, out, outlen, in, inlen);
279 static int utf8_to_win1256(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
281 return from_utf8(1256, out, outlen, in, inlen);
284 static int win1257_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
286 return to_utf8(1257, out, outlen, in, inlen);
289 static int utf8_to_win1257(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
291 return from_utf8(1257, out, outlen, in, inlen);
294 static int win1258_to_utf8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
296 return to_utf8(1258, out, outlen, in, inlen);
299 static int utf8_to_win1258(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
301 return from_utf8(1258, out, outlen, in, inlen);
304 static void init_char_encoders(void)
306 static const struct
308 const char *encoding;
309 xmlCharEncodingInputFunc input;
310 xmlCharEncodingOutputFunc output;
311 } encoder[] =
313 { "gbk", gbk_to_utf8, utf8_to_gbk },
314 { "windows-1250", win1250_to_utf8, utf8_to_win1250 },
315 { "windows-1251", win1251_to_utf8, utf8_to_win1251 },
316 { "windows-1252", win1252_to_utf8, utf8_to_win1252 },
317 { "windows-1253", win1253_to_utf8, utf8_to_win1253 },
318 { "windows-1254", win1254_to_utf8, utf8_to_win1254 },
319 { "windows-1255", win1255_to_utf8, utf8_to_win1255 },
320 { "windows-1256", win1256_to_utf8, utf8_to_win1256 },
321 { "windows-1257", win1257_to_utf8, utf8_to_win1257 },
322 { "windows-1258", win1258_to_utf8, utf8_to_win1258 }
324 int i;
326 for (i = 0; i < ARRAY_SIZE(encoder); i++)
328 if (!xmlFindCharEncodingHandler(encoder[i].encoding))
330 TRACE("Adding %s encoding handler\n", encoder[i].encoding);
331 xmlNewCharEncodingHandler(encoder[i].encoding, encoder[i].input, encoder[i].output);
336 const CLSID* DOMDocument_version(MSXML_VERSION v)
338 switch (v)
340 default:
341 case MSXML_DEFAULT: return &CLSID_DOMDocument;
342 case MSXML3: return &CLSID_DOMDocument30;
343 case MSXML4: return &CLSID_DOMDocument40;
344 case MSXML6: return &CLSID_DOMDocument60;
348 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID reserved)
350 MSXML_hInstance = hInstDLL;
352 switch(fdwReason)
354 case DLL_PROCESS_ATTACH:
355 xmlInitParser();
357 /* Set the default indent character to a single tab,
358 for this thread and as default for new threads */
359 xmlTreeIndentString = "\t";
360 xmlThrDefTreeIndentString("\t");
362 /* Register callbacks for loading XML files */
363 if(xmlRegisterInputCallbacks(wineXmlMatchCallback, wineXmlOpenCallback,
364 wineXmlReadCallback, wineXmlFileCloseCallback) == -1)
365 WARN("Failed to register callbacks\n");
367 init_char_encoders();
369 schemasInit();
370 init_libxslt();
371 DisableThreadLibraryCalls(hInstDLL);
372 break;
373 case DLL_PROCESS_DETACH:
374 if (reserved) break;
375 xsltCleanupGlobals();
376 /* Restore default Callbacks */
377 xmlCleanupInputCallbacks();
378 xmlRegisterDefaultInputCallbacks();
380 xmlCleanupParser();
381 schemasCleanup();
382 release_typelib();
383 break;
385 return TRUE;