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"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
37 #include "wine/library.h"
39 #include "msxml_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
45 /* Support for loading xml files from a Wine Windows drive */
46 static int wineXmlMatchCallback (char const * filename
)
50 TRACE("%s\n", filename
);
53 * We will deal with loading XML files from the file system
54 * We only care about files that linux cannot find.
57 if(isalpha(filename
[0]) && filename
[1] == ':')
63 static void *wineXmlOpenCallback (char const * filename
)
65 BSTR sFilename
= bstr_from_xmlChar( (xmlChar
*)filename
);
68 TRACE("%s\n", debugstr_w(sFilename
));
70 hFile
= CreateFileW(sFilename
, GENERIC_READ
,FILE_SHARE_READ
, NULL
,
71 OPEN_EXISTING
,FILE_ATTRIBUTE_NORMAL
, NULL
);
72 if(hFile
== INVALID_HANDLE_VALUE
) hFile
= 0;
73 SysFreeString(sFilename
);
77 static int wineXmlReadCallback(void * context
, char * buffer
, int len
)
81 TRACE("%p %s %d\n", context
, buffer
, len
);
83 if ((context
== NULL
) || (buffer
== NULL
))
86 if(!ReadFile( context
, buffer
,len
, &dwBytesRead
, NULL
))
88 ERR("Failed to read file\n");
92 TRACE("Read %d\n", dwBytesRead
);
97 static int wineXmlFileCloseCallback (void * context
)
99 return CloseHandle(context
) ? 0 : -1;
105 HRESULT WINAPI
DllCanUnloadNow(void)
112 void* libxslt_handle
= NULL
;
113 #ifdef SONAME_LIBXSLT
114 # define DECL_FUNCPTR(f) typeof(f) * p##f = NULL
115 DECL_FUNCPTR(xsltApplyStylesheet
);
116 DECL_FUNCPTR(xsltCleanupGlobals
);
117 DECL_FUNCPTR(xsltFreeStylesheet
);
118 DECL_FUNCPTR(xsltParseStylesheetDoc
);
122 static void init_libxslt(void)
124 #ifdef SONAME_LIBXSLT
125 void (*pxsltInit
)(void); /* Missing in libxslt <= 1.1.14 */
127 libxslt_handle
= wine_dlopen(SONAME_LIBXSLT
, RTLD_NOW
, NULL
, 0);
131 #define LOAD_FUNCPTR(f, needed) if ((p##f = wine_dlsym(libxslt_handle, #f, NULL, 0)) == NULL && needed) { WARN("Can't find symbol %s\n", #f); goto sym_not_found; }
132 LOAD_FUNCPTR(xsltInit
, 0);
133 LOAD_FUNCPTR(xsltApplyStylesheet
, 1);
134 LOAD_FUNCPTR(xsltCleanupGlobals
, 1);
135 LOAD_FUNCPTR(xsltFreeStylesheet
, 1);
136 LOAD_FUNCPTR(xsltParseStylesheetDoc
, 1);
144 wine_dlclose(libxslt_handle
, NULL
, 0);
145 libxslt_handle
= NULL
;
150 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
154 case DLL_PROCESS_ATTACH
:
158 /* Set the default indent character to a single tab,
159 for this thread and as default for new threads */
160 xmlTreeIndentString
= "\t";
161 xmlThrDefTreeIndentString("\t");
163 /* Register callbacks for loading XML files */
164 if(xmlRegisterInputCallbacks(wineXmlMatchCallback
, wineXmlOpenCallback
,
165 wineXmlReadCallback
, wineXmlFileCloseCallback
) == -1)
166 WARN("Failed to register callbacks\n");
170 DisableThreadLibraryCalls(hInstDLL
);
172 case DLL_PROCESS_DETACH
:
173 #ifdef SONAME_LIBXSLT
176 pxsltCleanupGlobals();
177 wine_dlclose(libxslt_handle
, NULL
, 0);
178 libxslt_handle
= NULL
;
182 /* Restore default Callbacks */
183 xmlCleanupInputCallbacks();
184 xmlRegisterDefaultInputCallbacks();