[PATCH] Added xml Input Callbacks to support loading files from a Wine windows drive
Alistair Leslie-Hughes
leslie_alistair at hotmail.com
Sun Jun 22 05:47:14 CDT 2008
---
dlls/msxml3/main.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 85 insertions(+), 0 deletions(-)
diff --git a/dlls/msxml3/main.c b/dlls/msxml3/main.c
index 1bf3a98..18fc68b 100644
--- a/dlls/msxml3/main.c
+++ b/dlls/msxml3/main.c
@@ -162,6 +162,83 @@ static void process_detach(void)
}
}
+/* Support for loading xml files from a Wine Windows drive */
+static int wineXmlMatchCallback (char const * filename)
+{
+ BSTR sFilename = bstr_from_xmlChar( (xmlChar*)filename);
+ BSTR sSlash = bstr_from_xmlChar( (xmlChar*)"/");
+ int nRet = 0;
+
+ TRACE("%s\n", debugstr_w(sFilename));
+
+ /*
+ * We will deal with loading XML files from the file system
+ * We only care about files that linux cannot find.
+ * e.g. C:,D: etc
+ */
+ if(sFilename[1] != sSlash[0])
+ nRet = 1;
+
+ SysFreeString(sFilename);
+ SysFreeString(sSlash);
+
+ return nRet;
+}
+
+static void *wineXmlOpenCallback (char const * filename)
+{
+ BSTR sFilename = bstr_from_xmlChar( (xmlChar*)filename);
+ HANDLE hFile;
+
+ TRACE("%s\n", debugstr_w(sFilename));
+
+ hFile = CreateFileW(sFilename, GENERIC_READ,FILE_SHARE_READ, NULL,
+ OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
+ if(hFile == INVALID_HANDLE_VALUE)
+ {
+ ERR("failed to open file %s\n", debugstr_w(sFilename));
+ return NULL;
+ }
+
+ return ((void *) hFile);
+}
+
+static int wineXmlReadCallback(void * context, char * buffer, int len)
+{
+ DWORD dwBytesRead;
+
+ TRACE("%p %s %d\n", context, buffer, len);
+
+ if ((context == NULL) || (buffer == NULL))
+ return(-1);
+
+ if(!ReadFile( (HANDLE )context, buffer,len, &dwBytesRead, NULL))
+ {
+ ERR("Failed to read file\n");
+ return -1;
+ }
+
+ TRACE("Read %d\n", dwBytesRead);
+
+ return dwBytesRead;
+}
+
+static int wineXmlFileClose (void * context)
+{
+ int ret;
+
+ TRACE("%p\n", context);
+
+ if (context == NULL)
+ return -1;
+
+ ret = CloseHandle((HANDLE)context) ? 0 : -1;
+
+ return ret;
+}
+
+
+
HRESULT WINAPI DllCanUnloadNow(void)
{
FIXME("\n");
@@ -175,6 +252,10 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
case DLL_PROCESS_ATTACH:
#ifdef HAVE_LIBXML2
xmlInitParser();
+
+ /* Register callbacks for loading XML files */
+ if(!xmlRegisterInputCallbacks(wineXmlMatchCallback, wineXmlOpenCallback, wineXmlReadCallback, wineXmlFileClose))
+ WARN("Failed to register callbacks\n");
#endif
#ifdef HAVE_XSLTINIT
xsltInit();
@@ -187,6 +268,10 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
xsltCleanupGlobals();
#endif
#ifdef HAVE_LIBXML2
+ /* Restore default Callbacks */
+ xmlCleanupInputCallbacks();
+ xmlRegisterDefaultInputCallbacks();
+
xmlCleanupParser();
process_detach();
#endif
--
1.5.4.1
--------------020804030403050508000909--
More information about the wine-patches
mailing list