[PATCH] Added xml Input Callbacks to support loading files from a Wine windows drive

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Fri May 2 04:38:33 CDT 2008


---
 dlls/msxml3/main.c |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/dlls/msxml3/main.c b/dlls/msxml3/main.c
index 1bf3a98..49fce1e 100644
--- a/dlls/msxml3/main.c
+++ b/dlls/msxml3/main.c
@@ -24,6 +24,7 @@
 #define COBJMACROS
 
 #include <stdarg.h>
+#include <wctype.h>
 #include "windef.h"
 #include "winbase.h"
 #include "winuser.h"
@@ -162,6 +163,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 sColon = 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(iswalpha(sFilename[0]) && sFilename[1] == sColon[0])
+        nRet = 1;
+        
+    SysFreeString(sFilename);
+    SysFreeString(sColon);
+        
+    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 +253,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 +269,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


--------------080302040101070602060301--




More information about the wine-patches mailing list