1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-08-07 06:43:02 +03:00

patch from Stefano Zacchiroli to fix some URI/file escaping problems

* nanoftp.c nanohttp.c xmlIO.c: patch from Stefano Zacchiroli
  to fix some URI/file escaping problems
Daniel
This commit is contained in:
Daniel Veillard
2003-01-10 16:09:51 +00:00
parent 3b87b6b398
commit cacbe5d110
4 changed files with 60 additions and 33 deletions

View File

@@ -1,3 +1,8 @@
Fri Jan 10 17:07:01 CET 2003 Daniel Veillard <daniel@veillard.com>
* nanoftp.c nanohttp.c xmlIO.c: patch from Stefano Zacchiroli
to fix some URI/file escaping problems
Fri Jan 10 16:20:34 CET 2003 Daniel Veillard <daniel@veillard.com> Fri Jan 10 16:20:34 CET 2003 Daniel Veillard <daniel@veillard.com>
* python/generator.py: fixed a bug raised by Raymond Wiker, * python/generator.py: fixed a bug raised by Raymond Wiker,

View File

@@ -59,6 +59,7 @@
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/xmlerror.h> #include <libxml/xmlerror.h>
#include <libxml/uri.h>
#include <libxml/nanoftp.h> #include <libxml/nanoftp.h>
#include <libxml/globals.h> #include <libxml/globals.h>
@@ -496,6 +497,7 @@ xmlNanoFTPScanProxy(const char *URL) {
void* void*
xmlNanoFTPNewCtxt(const char *URL) { xmlNanoFTPNewCtxt(const char *URL) {
xmlNanoFTPCtxtPtr ret; xmlNanoFTPCtxtPtr ret;
char *unescaped;
ret = (xmlNanoFTPCtxtPtr) xmlMalloc(sizeof(xmlNanoFTPCtxt)); ret = (xmlNanoFTPCtxtPtr) xmlMalloc(sizeof(xmlNanoFTPCtxt));
if (ret == NULL) return(NULL); if (ret == NULL) return(NULL);
@@ -508,8 +510,12 @@ xmlNanoFTPNewCtxt(const char *URL) {
ret->controlBufUsed = 0; ret->controlBufUsed = 0;
ret->controlFd = -1; ret->controlFd = -1;
if (URL != NULL) unescaped = xmlURIUnescapeString(URL, 0, NULL);
if (unescaped != NULL)
xmlNanoFTPScanURL(ret, unescaped);
else if (URL != NULL)
xmlNanoFTPScanURL(ret, URL); xmlNanoFTPScanURL(ret, URL);
xmlFree(unescaped);
return(ret); return(ret);
} }

View File

@@ -372,7 +372,6 @@ xmlNanoHTTPScanProxy(const char *URL) {
static xmlNanoHTTPCtxtPtr static xmlNanoHTTPCtxtPtr
xmlNanoHTTPNewCtxt(const char *URL) { xmlNanoHTTPNewCtxt(const char *URL) {
xmlNanoHTTPCtxtPtr ret; xmlNanoHTTPCtxtPtr ret;
xmlChar *escaped;
ret = (xmlNanoHTTPCtxtPtr) xmlMalloc(sizeof(xmlNanoHTTPCtxt)); ret = (xmlNanoHTTPCtxtPtr) xmlMalloc(sizeof(xmlNanoHTTPCtxt));
if (ret == NULL) return(NULL); if (ret == NULL) return(NULL);
@@ -383,13 +382,7 @@ xmlNanoHTTPNewCtxt(const char *URL) {
ret->fd = -1; ret->fd = -1;
ret->ContentLength = -1; ret->ContentLength = -1;
escaped = xmlURIEscapeStr(BAD_CAST URL, BAD_CAST"@/:=?;#%&");
if (escaped != NULL) {
xmlNanoHTTPScanURL(ret, (const char *) escaped);
xmlFree(escaped);
} else {
xmlNanoHTTPScanURL(ret, URL); xmlNanoHTTPScanURL(ret, URL);
}
return(ret); return(ret);
} }

71
xmlIO.c
View File

@@ -339,7 +339,7 @@ xmlFileMatch (const char *filename ATTRIBUTE_UNUSED) {
} }
/** /**
* xmlFileOpen: * xmlFileOpen_real:
* @filename: the URI for matching * @filename: the URI for matching
* *
* input from FILE *, supports compressed input * input from FILE *, supports compressed input
@@ -347,8 +347,8 @@ xmlFileMatch (const char *filename ATTRIBUTE_UNUSED) {
* *
* Returns an I/O context or NULL in case of error * Returns an I/O context or NULL in case of error
*/ */
void * static void *
xmlFileOpen (const char *filename) { xmlFileOpen_real (const char *filename) {
const char *path = NULL; const char *path = NULL;
FILE *fd; FILE *fd;
@@ -385,6 +385,27 @@ xmlFileOpen (const char *filename) {
return((void *) fd); return((void *) fd);
} }
/**
* xmlFileOpen:
* @filename: the URI for matching
*
* Wrapper around xmlFileOpen_real that try it with an unescaped
* version of @filename, if this fails fallback to @filename
*/
void *
xmlFileOpen (const char *filename) {
char *unescaped;
void *retval;
unescaped = xmlURIUnescapeString(filename, 0, NULL);
if (unescaped != NULL) {
retval = xmlFileOpen_real(unescaped);
} else {
retval = xmlFileOpen_real(filename);
}
xmlFree(unescaped);
return retval;
}
/** /**
* xmlFileOpenW: * xmlFileOpenW:
* @filename: the URI for matching * @filename: the URI for matching
@@ -513,7 +534,7 @@ xmlGzfileMatch (const char *filename ATTRIBUTE_UNUSED) {
} }
/** /**
* xmlGzfileOpen: * xmlGzfileOpen_real:
* @filename: the URI for matching * @filename: the URI for matching
* *
* input from compressed file open * input from compressed file open
@@ -522,7 +543,7 @@ xmlGzfileMatch (const char *filename ATTRIBUTE_UNUSED) {
* Returns an I/O context or NULL in case of error * Returns an I/O context or NULL in case of error
*/ */
static void * static void *
xmlGzfileOpen (const char *filename) { xmlGzfileOpen_real (const char *filename) {
const char *path = NULL; const char *path = NULL;
gzFile fd; gzFile fd;
@@ -555,6 +576,27 @@ xmlGzfileOpen (const char *filename) {
return((void *) fd); return((void *) fd);
} }
/**
* xmlGzfileOpen:
* @filename: the URI for matching
*
* Wrapper around xmlGzfileOpen that try it with an unescaped
* version of @filename, if this fails fallback to @filename
*/
static void *
xmlGzfileOpen (const char *filename) {
char *unescaped;
void *retval;
unescaped = xmlURIUnescapeString(filename, 0, NULL);
if (unescaped != NULL) {
retval = xmlGzfileOpen_real(unescaped);
} else {
retval = xmlGzfileOpen_real(filename);
}
xmlFree(unescaped);
return retval;
}
/** /**
* xmlGzfileOpenW: * xmlGzfileOpenW:
* @filename: the URI for matching * @filename: the URI for matching
@@ -1724,7 +1766,6 @@ xmlParserInputBufferCreateFilename
xmlParserInputBufferPtr ret; xmlParserInputBufferPtr ret;
int i = 0; int i = 0;
void *context = NULL; void *context = NULL;
char *unescaped;
char *normalized; char *normalized;
if (xmlInputCallbackInitialized == 0) if (xmlInputCallbackInitialized == 0)
@@ -1740,24 +1781,6 @@ xmlParserInputBufferCreateFilename
/* /*
* Try to find one of the input accept method accepting that scheme * Try to find one of the input accept method accepting that scheme
* Go in reverse to give precedence to user defined handlers. * Go in reverse to give precedence to user defined handlers.
* try with an unescaped version of the URI
*/
unescaped = xmlURIUnescapeString((char *) normalized, 0, NULL);
if (unescaped != NULL) {
for (i = xmlInputCallbackNr - 1;i >= 0;i--) {
if ((xmlInputCallbackTable[i].matchcallback != NULL) &&
(xmlInputCallbackTable[i].matchcallback(unescaped) != 0)) {
context = xmlInputCallbackTable[i].opencallback(unescaped);
if (context != NULL)
break;
}
}
xmlFree(unescaped);
}
/*
* If this failed try with a non-escaped URI this may be a strange
* filename
*/ */
if (context == NULL) { if (context == NULL) {
for (i = xmlInputCallbackNr - 1;i >= 0;i--) { for (i = xmlInputCallbackNr - 1;i >= 0;i--) {