*/
#define IN_LIBXML
#include "libxml.h"
-#ifdef HAVE_LZMA_H
+#ifdef LIBXML_LZMA_ENABLED
#include <string.h>
#ifdef HAVE_ERRNO_H
#ifdef HAVE_ZLIB_H
#include <zlib.h>
#endif
+#ifdef HAVE_LZMA_H
#include <lzma.h>
+#endif
#include "xzlib.h"
#include <libxml/xmlmemory.h>
return (xzFile) state;
}
+static int
+xz_compressed(xzFile f) {
+ xz_statep state;
+
+ if (f == NULL)
+ return(-1);
+ state = (xz_statep) f;
+ if (state->init <= 0)
+ return(-1);
+
+ switch (state->how) {
+ case COPY:
+ return(0);
+ case GZIP:
+ case LZMA:
+ return(1);
+ }
+ return(-1);
+}
+
xzFile
__libxml2_xzopen(const char *path, const char *mode)
{
return xz_open(path, -1, mode);
}
+int
+__libxml2_xzcompressed(xzFile f) {
+ return xz_compressed(f);
+}
+
xzFile
__libxml2_xzdopen(int fd, const char *mode)
{
return 0;
}
+#ifdef HAVE_ZLIB_H
+static int
+xz_avail_zstrm(xz_statep state)
+{
+ int ret;
+ state->strm.avail_in = state->zstrm.avail_in;
+ state->strm.next_in = state->zstrm.next_in;
+ ret = xz_avail(state);
+ state->zstrm.avail_in = (uInt) state->strm.avail_in;
+ state->zstrm.next_in = (Bytef *) state->strm.next_in;
+ return ret;
+}
+#endif
+
static int
is_format_xz(xz_statep state)
{
#define NEXT() ((strm->avail_in == 0 && xz_avail(state) == -1) ? -1 : \
(strm->avail_in == 0 ? -1 : \
(strm->avail_in--, *(strm->next_in)++)))
+/* Same thing, but from zstrm */
+#define NEXTZ() ((strm->avail_in == 0 && xz_avail_zstrm(state) == -1) ? -1 : \
+ (strm->avail_in == 0 ? -1 : \
+ (strm->avail_in--, *(strm->next_in)++)))
/* Get a four-byte little-endian integer and return 0 on success and the value
in *ret. Otherwise -1 is returned and *ret is not modified. */
unsigned long val;
z_streamp strm = &(state->zstrm);
- val = NEXT();
- val += (unsigned) NEXT() << 8;
- val += (unsigned long) NEXT() << 16;
- ch = NEXT();
+ val = NEXTZ();
+ val += (unsigned) NEXTZ() << 8;
+ val += (unsigned long) NEXTZ() << 16;
+ ch = NEXTZ();
if (ch == -1)
return -1;
val += (unsigned long) ch << 24;
xz_error(state, LZMA_DATA_ERROR, "compressed data error");
return -1;
}
+ if (ret == LZMA_PROG_ERROR) {
+ xz_error(state, LZMA_PROG_ERROR, "compression error");
+ return -1;
+ }
} while (strm->avail_out && ret != LZMA_STREAM_END);
/* update available output and crc check value */
xmlFree(state);
return ret ? ret : LZMA_OK;
}
-#endif /* HAVE_LZMA_H */
+#endif /* LIBXML_LZMA_ENABLED */