1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-28 00:21:53 +03:00

obsoleted xmlNormalizeWindowsPath

This commit is contained in:
Igor Zlatkovic
2003-02-19 14:51:00 +00:00
parent f2238e6e55
commit 5f9fada355
5 changed files with 19 additions and 86 deletions

View File

@ -6031,7 +6031,7 @@ docbCreateFileParserCtxt(const char *filename,
memset(inputStream, 0, sizeof(docbParserInput)); memset(inputStream, 0, sizeof(docbParserInput));
inputStream->filename = (char *) inputStream->filename = (char *)
xmlNormalizeWindowsPath((const xmlChar *)filename); xmlCanonicPath((const xmlChar *)filename);
inputStream->line = 1; inputStream->line = 1;
inputStream->col = 1; inputStream->col = 1;
inputStream->buf = buf; inputStream->buf = buf;

View File

@ -42,6 +42,7 @@
#include <libxml/valid.h> #include <libxml/valid.h>
#include <libxml/xmlIO.h> #include <libxml/xmlIO.h>
#include <libxml/globals.h> #include <libxml/globals.h>
#include <libxml/uri.h>
#define HTML_MAX_NAMELEN 1000 #define HTML_MAX_NAMELEN 1000
#define HTML_PARSER_BIG_BUFFER_SIZE 1000 #define HTML_PARSER_BIG_BUFFER_SIZE 1000
@ -5346,7 +5347,7 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
memset(inputStream, 0, sizeof(htmlParserInput)); memset(inputStream, 0, sizeof(htmlParserInput));
inputStream->filename = (char *) inputStream->filename = (char *)
xmlNormalizeWindowsPath((xmlChar *)filename); xmlCanonicPath((xmlChar *)filename);
inputStream->line = 1; inputStream->line = 1;
inputStream->col = 1; inputStream->col = 1;
inputStream->buf = buf; inputStream->buf = buf;

View File

@ -239,7 +239,11 @@ xmlParserInputPtr xmlNoNetExternalEntityLoader(const char *URL,
const char *ID, const char *ID,
xmlParserCtxtPtr ctxt); xmlParserCtxtPtr ctxt);
xmlChar *xmlNormalizeWindowsPath (const xmlChar *path); /*
* xmlNormalizeWindowsPath is obsolete, don't use it.
* Check xmlCanonicPath in uri.h for a better alternative.
*/
xmlChar * xmlNormalizeWindowsPath (const xmlChar *path);
int xmlCheckFilename (const char *path); int xmlCheckFilename (const char *path);
/** /**

View File

@ -9154,7 +9154,7 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
inputStream->filename = NULL; inputStream->filename = NULL;
else else
inputStream->filename = (char *) inputStream->filename = (char *)
xmlNormalizeWindowsPath((const xmlChar *) filename); xmlCanonicPath((const xmlChar *) filename);
inputStream->buf = buf; inputStream->buf = buf;
inputStream->base = inputStream->buf->buffer->content; inputStream->base = inputStream->buf->buffer->content;
inputStream->cur = inputStream->buf->buffer->content; inputStream->cur = inputStream->buf->buffer->content;
@ -10330,7 +10330,6 @@ xmlCreateFileParserCtxt(const char *filename)
xmlParserCtxtPtr ctxt; xmlParserCtxtPtr ctxt;
xmlParserInputPtr inputStream; xmlParserInputPtr inputStream;
char *directory = NULL; char *directory = NULL;
xmlChar *normalized;
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
if (ctxt == NULL) { if (ctxt == NULL) {
@ -10340,26 +10339,18 @@ xmlCreateFileParserCtxt(const char *filename)
return(NULL); return(NULL);
} }
normalized = xmlNormalizeWindowsPath((const xmlChar *) filename); inputStream = xmlLoadExternalEntity(filename, NULL, ctxt);
if (normalized == NULL) {
xmlFreeParserCtxt(ctxt);
return(NULL);
}
inputStream = xmlLoadExternalEntity((char *) normalized, NULL, ctxt);
if (inputStream == NULL) { if (inputStream == NULL) {
xmlFreeParserCtxt(ctxt); xmlFreeParserCtxt(ctxt);
xmlFree(normalized);
return(NULL); return(NULL);
} }
inputPush(ctxt, inputStream); inputPush(ctxt, inputStream);
if ((ctxt->directory == NULL) && (directory == NULL)) if ((ctxt->directory == NULL) && (directory == NULL))
directory = xmlParserGetDirectory((char *) normalized); directory = xmlParserGetDirectory(filename);
if ((ctxt->directory == NULL) && (directory != NULL)) if ((ctxt->directory == NULL) && (directory != NULL))
ctxt->directory = directory; ctxt->directory = directory;
xmlFree(normalized);
return(ctxt); return(ctxt);
} }

79
xmlIO.c
View File

@ -121,70 +121,17 @@ static xmlOutputCallback xmlOutputCallbackTable[MAX_OUTPUT_CALLBACK];
static int xmlOutputCallbackNr = 0; static int xmlOutputCallbackNr = 0;
static int xmlOutputCallbackInitialized = 0; static int xmlOutputCallbackInitialized = 0;
/************************************************************************
* *
* Handling of Windows file paths *
* *
************************************************************************/
#define IS_WINDOWS_PATH(p) \
((p != NULL) && \
(((p[0] >= 'a') && (p[0] <= 'z')) || \
((p[0] >= 'A') && (p[0] <= 'Z'))) && \
(p[1] == ':') && ((p[2] == '/') || (p[2] == '\\')))
/** /**
* xmlNormalizeWindowsPath: * xmlNormalizeWindowsPath:
* @path: a windows path like "C:/foo/bar"
* *
* Normalize a Windows path to make an URL from it * This function is obsolete. Please see xmlURIFromPath in uri.c for
* * a better solution.
* Returns a new URI which must be freed by the caller or NULL
* in case of error
*/ */
xmlChar * xmlChar *
xmlNormalizeWindowsPath(const xmlChar *path) xmlNormalizeWindowsPath(const xmlChar *path)
{ {
int len, i = 0, j; return xmlCanonicPath(path);
xmlChar *ret;
if (path == NULL)
return(NULL);
len = xmlStrlen(path);
if (!IS_WINDOWS_PATH(path)) {
ret = xmlStrdup(path);
if (ret == NULL)
return(NULL);
j = 0;
} else {
ret = xmlMalloc(len + 10);
if (ret == NULL)
return(NULL);
ret[0] = 'f';
ret[1] = 'i';
ret[2] = 'l';
ret[3] = 'e';
ret[4] = ':';
ret[5] = '/';
ret[6] = '/';
ret[7] = '/';
j = 8;
}
while (i < len) {
/* TODO: UTF8 conversion + URI escaping ??? */
if (path[i] == '\\')
ret[j] = '/';
else
ret[j] = path[i];
i++;
j++;
}
ret[j] = 0;
return(ret);
} }
/** /**
@ -1768,14 +1715,11 @@ xmlParserInputBufferCreateFilename
xmlParserInputBufferPtr ret; xmlParserInputBufferPtr ret;
int i = 0; int i = 0;
void *context = NULL; void *context = NULL;
char *normalized;
if (xmlInputCallbackInitialized == 0) if (xmlInputCallbackInitialized == 0)
xmlRegisterDefaultInputCallbacks(); xmlRegisterDefaultInputCallbacks();
if (URI == NULL) return(NULL); if (URI == NULL) return(NULL);
normalized = (char *) xmlNormalizeWindowsPath((const xmlChar *)URI);
if (normalized == NULL) return(NULL);
#ifdef LIBXML_CATALOG_ENABLED #ifdef LIBXML_CATALOG_ENABLED
#endif #endif
@ -1788,13 +1732,12 @@ xmlParserInputBufferCreateFilename
for (i = xmlInputCallbackNr - 1;i >= 0;i--) { for (i = xmlInputCallbackNr - 1;i >= 0;i--) {
if ((xmlInputCallbackTable[i].matchcallback != NULL) && if ((xmlInputCallbackTable[i].matchcallback != NULL) &&
(xmlInputCallbackTable[i].matchcallback(URI) != 0)) { (xmlInputCallbackTable[i].matchcallback(URI) != 0)) {
context = xmlInputCallbackTable[i].opencallback(normalized); context = xmlInputCallbackTable[i].opencallback(URI);
if (context != NULL) if (context != NULL)
break; break;
} }
} }
} }
xmlFree(normalized);
if (context == NULL) { if (context == NULL) {
return(NULL); return(NULL);
} }
@ -1834,7 +1777,6 @@ xmlOutputBufferCreateFilename(const char *URI,
int i = 0; int i = 0;
void *context = NULL; void *context = NULL;
char *unescaped; char *unescaped;
char *normalized;
int is_http_uri = 0; /* Can't change if HTTP disabled */ int is_http_uri = 0; /* Can't change if HTTP disabled */
@ -1842,13 +1784,11 @@ xmlOutputBufferCreateFilename(const char *URI,
xmlRegisterDefaultOutputCallbacks(); xmlRegisterDefaultOutputCallbacks();
if (URI == NULL) return(NULL); if (URI == NULL) return(NULL);
normalized = (char *) xmlNormalizeWindowsPath((const xmlChar *)URI);
if (normalized == NULL) return(NULL);
#ifdef LIBXML_HTTP_ENABLED #ifdef LIBXML_HTTP_ENABLED
/* Need to prevent HTTP URI's from falling into zlib short circuit */ /* Need to prevent HTTP URI's from falling into zlib short circuit */
is_http_uri = xmlIOHTTPMatch( normalized ); is_http_uri = xmlIOHTTPMatch( URI );
#endif #endif
@ -1857,7 +1797,7 @@ xmlOutputBufferCreateFilename(const char *URI,
* 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 * try with an unescaped version of the URI
*/ */
unescaped = xmlURIUnescapeString(normalized, 0, NULL); unescaped = xmlURIUnescapeString(URI, 0, NULL);
if (unescaped != NULL) { if (unescaped != NULL) {
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
if ((compression > 0) && (compression <= 9) && (is_http_uri == 0)) { if ((compression > 0) && (compression <= 9) && (is_http_uri == 0)) {
@ -1870,7 +1810,6 @@ xmlOutputBufferCreateFilename(const char *URI,
ret->closecallback = xmlGzfileClose; ret->closecallback = xmlGzfileClose;
} }
xmlFree(unescaped); xmlFree(unescaped);
xmlFree(normalized);
return(ret); return(ret);
} }
} }
@ -1899,7 +1838,7 @@ xmlOutputBufferCreateFilename(const char *URI,
if (context == NULL) { if (context == NULL) {
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
if ((compression > 0) && (compression <= 9) && (is_http_uri == 0)) { if ((compression > 0) && (compression <= 9) && (is_http_uri == 0)) {
context = xmlGzfileOpenW(normalized, compression); context = xmlGzfileOpenW(URI, compression);
if (context != NULL) { if (context != NULL) {
ret = xmlAllocOutputBuffer(encoder); ret = xmlAllocOutputBuffer(encoder);
if (ret != NULL) { if (ret != NULL) {
@ -1907,14 +1846,13 @@ xmlOutputBufferCreateFilename(const char *URI,
ret->writecallback = xmlGzfileWrite; ret->writecallback = xmlGzfileWrite;
ret->closecallback = xmlGzfileClose; ret->closecallback = xmlGzfileClose;
} }
xmlFree(normalized);
return(ret); return(ret);
} }
} }
#endif #endif
for (i = xmlOutputCallbackNr - 1;i >= 0;i--) { for (i = xmlOutputCallbackNr - 1;i >= 0;i--) {
if ((xmlOutputCallbackTable[i].matchcallback != NULL) && if ((xmlOutputCallbackTable[i].matchcallback != NULL) &&
(xmlOutputCallbackTable[i].matchcallback(normalized) != 0)) { (xmlOutputCallbackTable[i].matchcallback(URI) != 0)) {
#if defined(LIBXML_HTTP_ENABLED) && defined(HAVE_ZLIB_H) #if defined(LIBXML_HTTP_ENABLED) && defined(HAVE_ZLIB_H)
/* Need to pass compression parameter into HTTP open calls */ /* Need to pass compression parameter into HTTP open calls */
if (xmlOutputCallbackTable[i].matchcallback == xmlIOHTTPMatch) if (xmlOutputCallbackTable[i].matchcallback == xmlIOHTTPMatch)
@ -1927,7 +1865,6 @@ xmlOutputBufferCreateFilename(const char *URI,
} }
} }
} }
xmlFree(normalized);
if (context == NULL) { if (context == NULL) {
return(NULL); return(NULL);