|
|
|
@ -1158,65 +1158,36 @@ xmlIODefaultMatch(const char *filename ATTRIBUTE_UNUSED) {
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* xmlInputDefaultOpen:
|
|
|
|
|
* @buf: input buffer to be filled
|
|
|
|
|
* @filename: filename or URI
|
|
|
|
|
*
|
|
|
|
|
* Returns an xmlParserErrors code.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
|
|
|
|
|
int ret;
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
#ifdef LIBXML_FTP_ENABLED
|
|
|
|
|
if (xmlIOFTPMatch(filename)) {
|
|
|
|
|
buf->context = xmlIOFTPOpen(filename);
|
|
|
|
|
|
|
|
|
|
if (buf->context != NULL) {
|
|
|
|
|
buf->readcallback = xmlIOFTPRead;
|
|
|
|
|
buf->closecallback = xmlIOFTPClose;
|
|
|
|
|
return(XML_ERR_OK);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* LIBXML_FTP_ENABLED */
|
|
|
|
|
|
|
|
|
|
#ifdef LIBXML_HTTP_ENABLED
|
|
|
|
|
if (xmlIOHTTPMatch(filename)) {
|
|
|
|
|
buf->context = xmlIOHTTPOpen(filename);
|
|
|
|
|
|
|
|
|
|
if (buf->context != NULL) {
|
|
|
|
|
buf->readcallback = xmlIOHTTPRead;
|
|
|
|
|
buf->closecallback = xmlIOHTTPClose;
|
|
|
|
|
return(XML_ERR_OK);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* LIBXML_HTTP_ENABLED */
|
|
|
|
|
int
|
|
|
|
|
xmlInputFromFd(xmlParserInputBufferPtr buf, int fd, int unzip) {
|
|
|
|
|
int copy;
|
|
|
|
|
|
|
|
|
|
if (!xmlFileMatch(filename))
|
|
|
|
|
return(XML_IO_ENOENT);
|
|
|
|
|
(void) unzip;
|
|
|
|
|
|
|
|
|
|
#ifdef LIBXML_LZMA_ENABLED
|
|
|
|
|
{
|
|
|
|
|
if (unzip) {
|
|
|
|
|
xzFile xzStream;
|
|
|
|
|
off_t pos;
|
|
|
|
|
|
|
|
|
|
ret = xmlFdOpen(filename, 0, &fd);
|
|
|
|
|
if (ret != XML_ERR_OK)
|
|
|
|
|
return(ret);
|
|
|
|
|
pos = lseek(fd, 0, SEEK_CUR);
|
|
|
|
|
|
|
|
|
|
xzStream = __libxml2_xzdopen(filename, fd, "rb");
|
|
|
|
|
copy = dup(fd);
|
|
|
|
|
if (copy == -1)
|
|
|
|
|
return(xmlIOErr(0, "dup()"));
|
|
|
|
|
|
|
|
|
|
xzStream = __libxml2_xzdopen("?", copy, "rb");
|
|
|
|
|
|
|
|
|
|
if (xzStream == NULL) {
|
|
|
|
|
close(fd);
|
|
|
|
|
close(copy);
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* Non-regular files like pipes can't be reopened.
|
|
|
|
|
* If a file isn't seekable, we pipe uncompressed
|
|
|
|
|
* input through xzlib.
|
|
|
|
|
*/
|
|
|
|
|
if ((lseek(fd, 0, SEEK_CUR) < 0) ||
|
|
|
|
|
(__libxml2_xzcompressed(xzStream) > 0)) {
|
|
|
|
|
if ((__libxml2_xzcompressed(xzStream) > 0) ||
|
|
|
|
|
/* Try to rewind if not gzip compressed */
|
|
|
|
|
(pos < 0) ||
|
|
|
|
|
(lseek(fd, pos, SEEK_SET) < 0)) {
|
|
|
|
|
/*
|
|
|
|
|
* If a file isn't seekable, we pipe uncompressed
|
|
|
|
|
* input through xzlib.
|
|
|
|
|
*/
|
|
|
|
|
buf->context = xzStream;
|
|
|
|
|
buf->readcallback = xmlXzfileRead;
|
|
|
|
|
buf->closecallback = xmlXzfileClose;
|
|
|
|
@ -1231,25 +1202,29 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
|
|
|
|
|
#endif /* LIBXML_LZMA_ENABLED */
|
|
|
|
|
|
|
|
|
|
#ifdef LIBXML_ZLIB_ENABLED
|
|
|
|
|
{
|
|
|
|
|
if (unzip) {
|
|
|
|
|
gzFile gzStream;
|
|
|
|
|
off_t pos;
|
|
|
|
|
|
|
|
|
|
ret = xmlFdOpen(filename, 0, &fd);
|
|
|
|
|
if (ret != XML_ERR_OK)
|
|
|
|
|
return(ret);
|
|
|
|
|
pos = lseek(fd, 0, SEEK_CUR);
|
|
|
|
|
|
|
|
|
|
copy = dup(fd);
|
|
|
|
|
if (copy == -1)
|
|
|
|
|
return(xmlIOErr(0, "dup()"));
|
|
|
|
|
|
|
|
|
|
gzStream = gzdopen(fd, "rb");
|
|
|
|
|
gzStream = gzdopen(copy, "rb");
|
|
|
|
|
|
|
|
|
|
if (gzStream == NULL) {
|
|
|
|
|
close(fd);
|
|
|
|
|
close(copy);
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* Non-regular files like pipes can't be reopened.
|
|
|
|
|
* If a file isn't seekable, we pipe uncompressed
|
|
|
|
|
* input through zlib.
|
|
|
|
|
*/
|
|
|
|
|
if ((lseek(fd, 0, SEEK_CUR) < 0) ||
|
|
|
|
|
(gzdirect(gzStream) == 0)) {
|
|
|
|
|
if ((gzdirect(gzStream) == 0) ||
|
|
|
|
|
/* Try to rewind if not gzip compressed */
|
|
|
|
|
(pos < 0) ||
|
|
|
|
|
(lseek(fd, pos, SEEK_SET) < 0)) {
|
|
|
|
|
/*
|
|
|
|
|
* If a file isn't seekable, we pipe uncompressed
|
|
|
|
|
* input through zlib.
|
|
|
|
|
*/
|
|
|
|
|
buf->context = gzStream;
|
|
|
|
|
buf->readcallback = xmlGzfileRead;
|
|
|
|
|
buf->closecallback = xmlGzfileClose;
|
|
|
|
@ -1263,16 +1238,67 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
|
|
|
|
|
}
|
|
|
|
|
#endif /* LIBXML_ZLIB_ENABLED */
|
|
|
|
|
|
|
|
|
|
ret = xmlFdOpen(filename, 0, &fd);
|
|
|
|
|
if (ret != XML_ERR_OK)
|
|
|
|
|
return(ret);
|
|
|
|
|
copy = dup(fd);
|
|
|
|
|
if (copy == -1)
|
|
|
|
|
return(xmlIOErr(0, "dup()"));
|
|
|
|
|
|
|
|
|
|
buf->context = (void *) (ptrdiff_t) fd;
|
|
|
|
|
buf->context = (void *) (ptrdiff_t) copy;
|
|
|
|
|
buf->readcallback = xmlFdRead;
|
|
|
|
|
buf->closecallback = xmlFdClose;
|
|
|
|
|
|
|
|
|
|
return(XML_ERR_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* xmlInputDefaultOpen:
|
|
|
|
|
* @buf: input buffer to be filled
|
|
|
|
|
* @filename: filename or URI
|
|
|
|
|
*
|
|
|
|
|
* Returns an xmlParserErrors code.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
|
|
|
|
|
int ret;
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
#ifdef LIBXML_FTP_ENABLED
|
|
|
|
|
if (xmlIOFTPMatch(filename)) {
|
|
|
|
|
buf->context = xmlIOFTPOpen(filename);
|
|
|
|
|
|
|
|
|
|
if (buf->context != NULL) {
|
|
|
|
|
buf->readcallback = xmlIOFTPRead;
|
|
|
|
|
buf->closecallback = xmlIOFTPClose;
|
|
|
|
|
return(XML_ERR_OK);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* LIBXML_FTP_ENABLED */
|
|
|
|
|
|
|
|
|
|
#ifdef LIBXML_HTTP_ENABLED
|
|
|
|
|
if (xmlIOHTTPMatch(filename)) {
|
|
|
|
|
buf->context = xmlIOHTTPOpen(filename);
|
|
|
|
|
|
|
|
|
|
if (buf->context != NULL) {
|
|
|
|
|
buf->readcallback = xmlIOHTTPRead;
|
|
|
|
|
buf->closecallback = xmlIOHTTPClose;
|
|
|
|
|
return(XML_ERR_OK);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* LIBXML_HTTP_ENABLED */
|
|
|
|
|
|
|
|
|
|
if (!xmlFileMatch(filename))
|
|
|
|
|
return(XML_IO_ENOENT);
|
|
|
|
|
|
|
|
|
|
ret = xmlFdOpen(filename, 0, &fd);
|
|
|
|
|
if (ret != XML_ERR_OK)
|
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
|
|
ret = xmlInputFromFd(buf, fd, /* unzip */ 1);
|
|
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
return(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef LIBXML_OUTPUT_ENABLED
|
|
|
|
|
/**
|
|
|
|
|
* xmlOutputDefaultOpen:
|
|
|
|
|