diff --git a/ChangeLog b/ChangeLog index 3a23da9b..20c0dd13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Sep 7 19:58:33 PTD 2003 William Brack + + * 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 * parser.c: try to cope with the fact that apps may still diff --git a/include/libxml/xmlIO.h b/include/libxml/xmlIO.h index 419f812a..9d182a65 100644 --- a/include/libxml/xmlIO.h +++ b/include/libxml/xmlIO.h @@ -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 */ }; diff --git a/parser.c b/parser.c index b5ae4a8b..830a29a0 100644 --- a/parser.c +++ b/parser.c @@ -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); diff --git a/xmlIO.c b/xmlIO.c index d100948d..df7d975b 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -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); }