1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

Implemented detection of compressed files, setting doc->compressed

* xmlIO.c include/libxml/xmlIO.h parser.c: Implemented detection
  of compressed files, setting doc->compressed appropriately
  (bug #120503).
This commit is contained in:
William M. Brack 2003-09-08 01:57:30 +00:00
parent f2a941fc1e
commit c07329e2ab
4 changed files with 31 additions and 12 deletions

View File

@ -1,3 +1,9 @@
Sun Sep 7 19:58:33 PTD 2003 William Brack <wbrack@mmm.com.hk>
* xmlIO.c include/libxml/xmlIO.h parser.c: Implemented detection
of compressed files, setting doc->compressed appropriately
(bug #120503).
Sun Sep 7 22:53:06 CEST 2003 Daniel Veillard <daniel@veillard.com>
* parser.c: try to cope with the fact that apps may still

View File

@ -129,6 +129,7 @@ struct _xmlParserInputBuffer {
xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 */
xmlBufferPtr raw; /* if encoder != NULL buffer for raw input */
int compressed; /* -1=unknown, 0=not compressed, 1=compressed */
};

View File

@ -2923,7 +2923,7 @@ get_more:
SHRINK;
GROW;
in = ctxt->input->cur;
} while ((*in >= 0x20) && (*in <= 0x7F) || (*in == 0x09));
} while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09));
nbchar = 0;
}
ctxt->input->line = line;
@ -11345,7 +11345,13 @@ xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const char *filename,
xmlParseDocument(ctxt);
if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc;
if ((ctxt->wellFormed) || recovery) {
ret = ctxt->myDoc;
if (ctxt->input->buf->compressed > 0)
ret->compression = 9;
else
ret->compression = ctxt->input->buf->compressed;
}
else {
ret = NULL;
xmlFreeDoc(ctxt->myDoc);

26
xmlIO.c
View File

@ -1588,6 +1588,7 @@ xmlAllocParserInputBuffer(xmlCharEncoding enc) {
ret->readcallback = NULL;
ret->closecallback = NULL;
ret->context = NULL;
ret->compressed = -1;
return(ret);
}
@ -1698,13 +1699,6 @@ xmlOutputBufferClose(xmlOutputBufferPtr out) {
return( ( err_rc == 0 ) ? written : err_rc );
}
/**
* xmlParserInputBufferCreateFname:
* @URI: a C string containing the URI or filename
* @enc: the charset encoding if known
*
* Returns the new parser input or NULL
*/
/**
* xmlParserInputBufferCreateFilename:
* @URI: a C string containing the URI or filename
@ -1729,9 +1723,6 @@ xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {
if (URI == NULL) return(NULL);
#ifdef LIBXML_CATALOG_ENABLED
#endif
/*
* Try to find one of the input accept method accepting that scheme
* Go in reverse to give precedence to user defined handlers.
@ -1758,6 +1749,21 @@ xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {
ret->context = context;
ret->readcallback = xmlInputCallbackTable[i].readcallback;
ret->closecallback = xmlInputCallbackTable[i].closecallback;
#ifdef HAVE_ZLIB_H
if (xmlInputCallbackTable[i].opencallback == xmlGzfileOpen) {
if (((z_stream *)context)->avail_in > 4) {
char *cptr, buff4[4];
cptr = ((z_stream *)context)->next_in;
if (gzread(context, buff4, 4) == 4) {
if (strncmp(buff4, cptr, 4) == 0)
ret->compressed = 0;
else
ret->compressed = 1;
gzrewind(context);
}
}
}
#endif
}
return(ret);
}