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).
diff --git a/xmlIO.c b/xmlIO.c
index d100948..df7d975 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -1588,6 +1588,7 @@
     ret->readcallback = NULL;
     ret->closecallback = NULL;
     ret->context = NULL;
+    ret->compressed = -1;
 
     return(ret);
 }
@@ -1699,13 +1700,6 @@
 }
 
 /**
- * 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
  * @enc:  the charset encoding if known
@@ -1729,9 +1723,6 @@
 
     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 @@
 	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);
 }