mirror of
https://github.com/GNOME/libxml2.git
synced 2025-10-14 02:58:39 +08:00
Remove LZMA support
This commit is contained in:
@@ -23,7 +23,7 @@ install:
|
||||
.test:
|
||||
image: registry.gitlab.gnome.org/gnome/libxml2
|
||||
variables:
|
||||
BASE_CONFIG: "--with-http --with-schematron --with-lzma --with-zlib --with-python"
|
||||
BASE_CONFIG: "--with-http --with-schematron --with-zlib --with-python"
|
||||
before_script:
|
||||
- rm -rf libxml2-build
|
||||
- mkdir libxml2-build
|
||||
@@ -85,7 +85,7 @@ clang:msan:
|
||||
# only:
|
||||
# - schedules
|
||||
variables:
|
||||
CONFIG: "--without-python --without-zlib --without-lzma"
|
||||
CONFIG: "--without-python --without-zlib"
|
||||
CC: clang
|
||||
CFLAGS: "-O2 -g -fno-omit-frame-pointer -fsanitize=memory"
|
||||
MSAN_SYMBOLIZER_PATH: "$CI_PROJECT_DIR/.gitlab-ci/llvm-symbolizer"
|
||||
@@ -94,7 +94,7 @@ clang:msan:
|
||||
tags:
|
||||
- win32-ps
|
||||
variables:
|
||||
BASE_CONFIG: "--with-http --with-schematron --with-lzma --with-zlib --with-python"
|
||||
BASE_CONFIG: "--with-http --with-schematron --with-zlib --with-python"
|
||||
# Python is disabled for now, see #658
|
||||
CONFIG: "--with-docs --without-python"
|
||||
CHERE_INVOKING: "yes"
|
||||
|
@@ -19,7 +19,7 @@ RUN apt-get update && \
|
||||
curl git ca-certificates \
|
||||
autoconf automake libtool pkg-config \
|
||||
make gcc clang llvm libclang-rt-dev \
|
||||
zlib1g-dev liblzma-dev libgcrypt-dev \
|
||||
zlib1g-dev libgcrypt-dev \
|
||||
python3-dev \
|
||||
cmake meson \
|
||||
xz-utils \
|
||||
|
@@ -21,7 +21,6 @@ cmake `
|
||||
-DCMAKE_INSTALL_PREFIX=libxml2-install `
|
||||
-DLIBXML2_WITH_SCHEMATRON=ON `
|
||||
-DLIBXML2_WITH_ICONV=OFF `
|
||||
-DLIBXML2_WITH_LZMA=OFF `
|
||||
-DLIBXML2_WITH_PYTHON=OFF `
|
||||
-DLIBXML2_WITH_ZLIB=OFF `
|
||||
-S . -B libxml2-build
|
||||
|
@@ -9,7 +9,6 @@ cmake "$@" \
|
||||
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||
-DLIBXML2_WITH_HTTP=ON \
|
||||
-DLIBXML2_WITH_SCHEMATRON=ON \
|
||||
-DLIBXML2_WITH_LZMA=ON \
|
||||
-DLIBXML2_WITH_ZLIB=ON \
|
||||
-DLIBXML2_WITH_PYTHON=ON \
|
||||
$CONFIG \
|
||||
|
@@ -14,7 +14,6 @@ meson setup \
|
||||
-Ddocs=enabled \
|
||||
-Dhttp=enabled \
|
||||
-Dschematron=enabled \
|
||||
-Dlzma=enabled \
|
||||
-Dzlib=enabled \
|
||||
-Dpython=enabled \
|
||||
builddir
|
||||
|
@@ -34,7 +34,6 @@ option(LIBXML2_WITH_ICONV "Add ICONV support" ON)
|
||||
option(LIBXML2_WITH_ICU "Add ICU support" OFF)
|
||||
option(LIBXML2_WITH_ISO8859X "Add ISO8859X support if no iconv" ON)
|
||||
option(LIBXML2_WITH_LEGACY "Add deprecated APIs for compatibility" OFF)
|
||||
option(LIBXML2_WITH_LZMA "Use liblzma" OFF)
|
||||
option(LIBXML2_WITH_MODULES "Add the dynamic modules support" ON)
|
||||
option(LIBXML2_WITH_OUTPUT "Add the serialization support" ON)
|
||||
option(LIBXML2_WITH_PATTERN "Add the xmlPattern selection interface" ON)
|
||||
@@ -91,7 +90,7 @@ if(LIBXML2_WITH_PYTHON)
|
||||
CACHE PATH "Python bindings install directory")
|
||||
endif()
|
||||
|
||||
foreach(VARIABLE IN ITEMS WITH_C14N WITH_CATALOG WITH_DEBUG WITH_HTML WITH_HTTP WITH_ICONV WITH_ICU WITH_ISO8859X WITH_LZMA WITH_MODULES WITH_OUTPUT WITH_PATTERN WITH_PUSH WITH_READER WITH_REGEXPS WITH_RELAXNG WITH_SAX1 WITH_SCHEMAS WITH_SCHEMATRON WITH_THREADS WITH_THREAD_ALLOC WITH_VALID WITH_WRITER WITH_XINCLUDE WITH_XPATH WITH_XPTR WITH_ZLIB)
|
||||
foreach(VARIABLE IN ITEMS WITH_C14N WITH_CATALOG WITH_DEBUG WITH_HTML WITH_HTTP WITH_ICONV WITH_ICU WITH_ISO8859X WITH_MODULES WITH_OUTPUT WITH_PATTERN WITH_PUSH WITH_READER WITH_REGEXPS WITH_RELAXNG WITH_SAX1 WITH_SCHEMAS WITH_SCHEMATRON WITH_THREADS WITH_THREAD_ALLOC WITH_VALID WITH_WRITER WITH_XINCLUDE WITH_XPATH WITH_XPTR WITH_ZLIB)
|
||||
if(LIBXML2_${VARIABLE})
|
||||
set(${VARIABLE} 1)
|
||||
else()
|
||||
@@ -117,10 +116,6 @@ if(LIBXML2_WITH_ICU)
|
||||
find_package(ICU REQUIRED COMPONENTS uc)
|
||||
endif()
|
||||
|
||||
if(LIBXML2_WITH_LZMA)
|
||||
find_package(LibLZMA REQUIRED)
|
||||
endif()
|
||||
|
||||
if(LIBXML2_WITH_THREADS)
|
||||
find_package(Threads REQUIRED)
|
||||
set(THREAD_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
@@ -260,9 +255,6 @@ endif()
|
||||
if(LIBXML2_WITH_HTTP)
|
||||
list(APPEND LIBXML2_SRCS nanohttp.c)
|
||||
endif()
|
||||
if(LIBXML2_WITH_LZMA)
|
||||
list(APPEND LIBXML2_SRCS xzlib.c)
|
||||
endif()
|
||||
if(LIBXML2_WITH_MODULES)
|
||||
list(APPEND LIBXML2_SRCS xmlmodule.c)
|
||||
endif()
|
||||
@@ -369,18 +361,6 @@ if(LIBXML2_WITH_ICU)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LIBXML2_WITH_LZMA)
|
||||
target_link_libraries(LibXml2 PRIVATE LibLZMA::LibLZMA)
|
||||
set(LibLZMA_LDFLAGS "-llzma")
|
||||
list(APPEND XML_PRIVATE_LIBS "${LibLZMA_LDFLAGS}")
|
||||
pkg_check_modules(LibLZMA_PC IMPORTED_TARGET liblzma)
|
||||
if(LibLZMA_PC_FOUND)
|
||||
list(APPEND XML_PC_REQUIRES liblzma)
|
||||
else()
|
||||
list(APPEND XML_PC_LIBS "${LibLZMA_LDFLAGS}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LIBXML2_WITH_THREADS)
|
||||
target_link_libraries(LibXml2 PRIVATE Threads::Threads)
|
||||
endif()
|
||||
|
@@ -68,9 +68,6 @@ endif
|
||||
if WITH_HTTP_SOURCES
|
||||
libxml2_la_SOURCES += nanohttp.c
|
||||
endif
|
||||
if WITH_LZMA_SOURCES
|
||||
libxml2_la_SOURCES += xzlib.c
|
||||
endif
|
||||
if WITH_MODULES_SOURCES
|
||||
libxml2_la_SOURCES += xmlmodule.c
|
||||
endif
|
||||
|
2
NEWS
2
NEWS
@@ -15,7 +15,7 @@ Support for Schematron is now disabled by default.
|
||||
|
||||
### Removals
|
||||
|
||||
The built-in HTTP client was removed.
|
||||
The built-in HTTP client and support for LZMA compression were removed.
|
||||
|
||||
### Planned removals
|
||||
|
||||
|
@@ -61,7 +61,6 @@ The following options disable or enable code modules and relevant symbols:
|
||||
--with-iconv[=DIR] iconv support (on)
|
||||
--with-icu ICU support (off)
|
||||
--with-iso8859x ISO-8859-X support if no iconv (on)
|
||||
--with-lzma[=DIR] use liblzma in DIR (off)
|
||||
--with-modules dynamic modules support (on)
|
||||
--with-output serialization support (on)
|
||||
--with-pattern xmlPattern selection interface (on)
|
||||
@@ -154,10 +153,6 @@ iconv, you need an external libiconv library, for example
|
||||
[GNU libiconv](https://www.gnu.org/software/libiconv/). Using
|
||||
[ICU](https://icu.unicode.org/) is also supported but discouraged.
|
||||
|
||||
If enabled, libxml uses [libz](https://zlib.net/) or
|
||||
[liblzma](https://tukaani.org/xz/) to support reading compressed files.
|
||||
Use of this feature is discouraged.
|
||||
|
||||
The xmllint executable uses libreadline and libhistory if enabled.
|
||||
|
||||
### Build requirements
|
||||
|
58
configure.ac
58
configure.ac
@@ -86,8 +86,6 @@ AC_ARG_WITH(icu,
|
||||
[ --with-icu ICU support (off)])
|
||||
AC_ARG_WITH(iso8859x,
|
||||
[ --with-iso8859x ISO-8859-X support if no iconv (on)])
|
||||
AC_ARG_WITH(lzma,
|
||||
[ --with-lzma[[=DIR]] use liblzma in DIR (off)])
|
||||
AC_ARG_WITH(modules,
|
||||
[ --with-modules dynamic modules support (on)])
|
||||
AC_ARG_WITH(output,
|
||||
@@ -235,7 +233,6 @@ if test "$with_minimum" = "yes"; then
|
||||
test "$with_http" = "" && with_http=no
|
||||
test "$with_iconv" = "" && with_iconv=no
|
||||
test "$with_iso8859x" = "" && with_iso8859x=no
|
||||
test "$with_lzma" = "" && with_lzma=no
|
||||
test "$with_output" = "" && with_output=no
|
||||
test "$with_pattern" = "" && with_pattern=no
|
||||
test "$with_push" = "" && with_push=no
|
||||
@@ -842,61 +839,6 @@ if test "$with_zlib" != "no" && test "$with_zlib" != ""; then
|
||||
fi
|
||||
AC_SUBST(WITH_ZLIB)
|
||||
|
||||
dnl
|
||||
dnl Checks for lzma library.
|
||||
dnl
|
||||
WITH_LZMA=0
|
||||
|
||||
if test "$with_lzma" != "no" && test "$with_lzma" != ""; then
|
||||
echo "Enabling lzma compression support"
|
||||
|
||||
if test "$with_lzma" != "yes"; then
|
||||
LZMA_DIR=$with_lzma
|
||||
fi
|
||||
|
||||
# Don't run pkg-config if with_lzma contains a path.
|
||||
if test "x$LZMA_DIR" = "x"; then
|
||||
# Try pkg-config first so that static linking works.
|
||||
PKG_CHECK_MODULES([LZMA],[liblzma],
|
||||
[WITH_LZMA=1; XML_PC_REQUIRES="${XML_PC_REQUIRES} liblzma"],
|
||||
[:])
|
||||
fi
|
||||
|
||||
# If pkg-config failed, fall back to AC_CHECK_LIB. This
|
||||
# will not pick up the necessary LIBS flags for liblzma's
|
||||
# private dependencies, though, so static linking may fail.
|
||||
if test "$WITH_LZMA" = "0"; then
|
||||
_cppflags=$CPPFLAGS
|
||||
_libs=$LIBS
|
||||
if test "x$LZMA_DIR" != "x"; then
|
||||
CPPFLAGS="${CPPFLAGS} -I$LZMA_DIR/include"
|
||||
LIBS="${LIBS} -L$LZMA_DIR/lib"
|
||||
fi
|
||||
AC_CHECK_HEADERS(lzma.h,
|
||||
AC_CHECK_LIB(lzma, lzma_code,[
|
||||
WITH_LZMA=1
|
||||
if test "x${LZMA_DIR}" != "x"; then
|
||||
LZMA_CFLAGS="-I${LZMA_DIR}/include"
|
||||
LZMA_LIBS="-L${LZMA_DIR}/lib -llzma"
|
||||
else
|
||||
LZMA_LIBS="-llzma"
|
||||
fi])
|
||||
XML_PC_LIBS="${XML_PC_LIBS} ${LZMA_LIBS}"
|
||||
)
|
||||
CPPFLAGS=$_cppflags
|
||||
LIBS=$_libs
|
||||
fi
|
||||
|
||||
if test "$WITH_LZMA" = "0"; then
|
||||
AC_MSG_ERROR([liblzma not found])
|
||||
fi
|
||||
|
||||
XML_PRIVATE_CFLAGS="${XML_PRIVATE_CFLAGS} ${LZMA_CFLAGS}"
|
||||
XML_PRIVATE_LIBS="${XML_PRIVATE_LIBS} ${LZMA_LIBS}"
|
||||
fi
|
||||
AC_SUBST(WITH_LZMA)
|
||||
AM_CONDITIONAL(WITH_LZMA_SOURCES, test "$WITH_LZMA" = "1")
|
||||
|
||||
dnl
|
||||
dnl Checks for iconv library.
|
||||
dnl
|
||||
|
@@ -11,11 +11,11 @@ if [ "$SANITIZER" = undefined ]; then
|
||||
export CXXFLAGS="$CXXFLAGS $extra_cflags"
|
||||
fi
|
||||
|
||||
# Don't enable zlib and liblzma with MSan
|
||||
# Don't enable zlib with MSan
|
||||
if [ "$SANITIZER" = memory ]; then
|
||||
CONFIG=''
|
||||
else
|
||||
CONFIG='--with-zlib --with-lzma'
|
||||
CONFIG='--with-zlib'
|
||||
fi
|
||||
|
||||
# Workaround for a LeakSanitizer crashes,
|
||||
@@ -51,7 +51,7 @@ do
|
||||
$OBJS fuzz.o \
|
||||
-o $OUT/$fuzzer \
|
||||
$LIB_FUZZING_ENGINE \
|
||||
../.libs/libxml2.a -Wl,-Bstatic -lz -llzma -Wl,-Bdynamic
|
||||
../.libs/libxml2.a -Wl,-Bstatic -lz -Wl,-Bdynamic
|
||||
|
||||
if [ $fuzzer != api ]; then
|
||||
[ -e seed/$fuzzer ] || make seed/$fuzzer.stamp
|
||||
|
@@ -13,7 +13,6 @@ xmlversion_h.set10('WITH_ICONV', want_iconv)
|
||||
xmlversion_h.set10('WITH_ICU', want_icu)
|
||||
xmlversion_h.set10('WITH_ISO8859X', want_iso8859x)
|
||||
xmlversion_h.set10('WITH_LEGACY', want_legacy)
|
||||
xmlversion_h.set10('WITH_LZMA', want_lzma)
|
||||
xmlversion_h.set10('WITH_MODULES', want_modules)
|
||||
xmlversion_h.set('MODULE_EXTENSION', module_extension)
|
||||
xmlversion_h.set10('WITH_OUTPUT', want_output)
|
||||
|
@@ -2145,7 +2145,7 @@ typedef enum {
|
||||
XML_WITH_ZLIB = 31,
|
||||
/** ICU */
|
||||
XML_WITH_ICU = 32,
|
||||
/** LZMA compression */
|
||||
/** @deprecated LZMA support was removed */
|
||||
XML_WITH_LZMA = 33,
|
||||
/** RELAXNG, since 2.14 */
|
||||
XML_WITH_RELAXNG = 34,
|
||||
|
@@ -248,13 +248,6 @@
|
||||
#define LIBXML_ZLIB_ENABLED
|
||||
#endif
|
||||
|
||||
#if @WITH_LZMA@
|
||||
/**
|
||||
* Whether the Lzma support is compiled in
|
||||
*/
|
||||
#define LIBXML_LZMA_ENABLED
|
||||
#endif
|
||||
|
||||
#include <libxml/xmlexports.h>
|
||||
|
||||
#endif
|
||||
|
@@ -17,5 +17,4 @@ EXTRA_DIST = \
|
||||
threads.h \
|
||||
tree.h \
|
||||
xinclude.h \
|
||||
xpath.h \
|
||||
xzlib.h
|
||||
xpath.h
|
||||
|
@@ -1,32 +0,0 @@
|
||||
/**
|
||||
* xzlib.h: header for the front end for the transparent support of lzma
|
||||
* compression at the I/O layer
|
||||
*
|
||||
* See Copyright for the status of this software.
|
||||
*
|
||||
* Author: Anders F Bjorklund
|
||||
*/
|
||||
|
||||
#ifndef LIBXML2_XZLIB_H
|
||||
#define LIBXML2_XZLIB_H
|
||||
|
||||
#include <libxml/xmlversion.h>
|
||||
|
||||
#ifdef LIBXML_LZMA_ENABLED
|
||||
|
||||
typedef void *xzFile; /* opaque lzma file descriptor */
|
||||
|
||||
XML_HIDDEN xzFile
|
||||
__libxml2_xzopen(const char *path, const char *mode);
|
||||
XML_HIDDEN xzFile
|
||||
__libxml2_xzdopen(const char *path, int fd, const char *mode);
|
||||
XML_HIDDEN int
|
||||
__libxml2_xzread(xzFile file, void *buf, unsigned len);
|
||||
XML_HIDDEN int
|
||||
__libxml2_xzclose(xzFile file);
|
||||
XML_HIDDEN int
|
||||
__libxml2_xzcompressed(xzFile f);
|
||||
|
||||
#endif /* LIBXML_LZMA_ENABLED */
|
||||
|
||||
#endif /* LIBXML2_XZLIB_H */
|
@@ -95,7 +95,6 @@ set(LIBXML2_SHARED @BUILD_SHARED_LIBS@)
|
||||
set(LIBXML2_WITH_ICONV @LIBXML2_WITH_ICONV@)
|
||||
set(LIBXML2_WITH_THREADS @LIBXML2_WITH_THREADS@)
|
||||
set(LIBXML2_WITH_ICU @LIBXML2_WITH_ICU@)
|
||||
set(LIBXML2_WITH_LZMA @LIBXML2_WITH_LZMA@)
|
||||
set(LIBXML2_WITH_ZLIB @LIBXML2_WITH_ZLIB@)
|
||||
|
||||
if(NOT LIBXML2_SHARED)
|
||||
@@ -131,16 +130,6 @@ if(NOT LIBXML2_SHARED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LIBXML2_WITH_LZMA)
|
||||
find_dependency(LibLZMA)
|
||||
list(APPEND LIBXML2_LIBRARIES ${LIBLZMA_LIBRARIES})
|
||||
if(NOT LibLZMA_FOUND)
|
||||
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
|
||||
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "LibLZMA dependency was not found")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LIBXML2_WITH_ZLIB)
|
||||
find_dependency(ZLIB)
|
||||
list(APPEND LIBXML2_LIBRARIES ${ZLIB_LIBRARIES})
|
||||
|
@@ -46,7 +46,6 @@ set(LIBXML2_SHARED @BUILD_SHARED_LIBS@)
|
||||
set(LIBXML2_WITH_ICONV @WITH_ICONV@)
|
||||
set(LIBXML2_WITH_THREADS @WITH_THREADS@)
|
||||
set(LIBXML2_WITH_ICU @WITH_ICU@)
|
||||
set(LIBXML2_WITH_LZMA @WITH_LZMA@)
|
||||
set(LIBXML2_WITH_ZLIB @WITH_ZLIB@)
|
||||
|
||||
if(NOT LIBXML2_SHARED)
|
||||
@@ -85,17 +84,6 @@ if(NOT LIBXML2_SHARED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LIBXML2_WITH_LZMA)
|
||||
find_dependency(LibLZMA)
|
||||
list(APPEND LIBXML2_LIBRARIES ${LIBLZMA_LIBRARIES})
|
||||
list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$<LINK_ONLY:LibLZMA::LibLZMA>")
|
||||
if(NOT LibLZMA_FOUND)
|
||||
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
|
||||
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "LibLZMA dependency was not found")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LIBXML2_WITH_ZLIB)
|
||||
find_dependency(ZLIB)
|
||||
list(APPEND LIBXML2_LIBRARIES ${ZLIB_LIBRARIES})
|
||||
|
@@ -86,7 +86,6 @@ want_docs = get_option('docs').enabled()
|
||||
want_http = get_option('http').enabled()
|
||||
want_icu = get_option('icu').enabled()
|
||||
want_legacy = get_option('legacy').enabled()
|
||||
want_lzma = get_option('lzma').enabled()
|
||||
want_python = get_option('python').enabled()
|
||||
want_thread_alloc = get_option('thread-alloc').enabled()
|
||||
want_tls = get_option('tls').enabled()
|
||||
@@ -368,11 +367,6 @@ if want_zlib
|
||||
xml_deps += dependency('zlib')
|
||||
endif
|
||||
|
||||
### lzma
|
||||
if want_lzma
|
||||
xml_deps += dependency('liblzma')
|
||||
endif
|
||||
|
||||
# icu
|
||||
if want_icu
|
||||
icu_dep = dependency('icu-uc')
|
||||
@@ -424,7 +418,6 @@ xml_opt_src = [
|
||||
[want_debug, ['debugXML.c']],
|
||||
[want_html, ['HTMLparser.c', 'HTMLtree.c']],
|
||||
[want_http, ['nanohttp.c']],
|
||||
[want_lzma, ['xzlib.c']],
|
||||
[want_modules, ['xmlmodule.c']],
|
||||
[want_output, ['xmlsave.c']],
|
||||
[want_pattern, ['pattern.c']],
|
||||
@@ -592,7 +585,6 @@ config_cmake.set10('BUILD_SHARED_LIBS',
|
||||
get_option('default_library') != 'static')
|
||||
config_cmake.set10('WITH_ICONV', want_iconv)
|
||||
config_cmake.set10('WITH_ICU', want_icu)
|
||||
config_cmake.set10('WITH_LZMA', want_lzma)
|
||||
config_cmake.set10('WITH_MODULES', want_modules)
|
||||
config_cmake.set10('WITH_THREADS', want_threads)
|
||||
config_cmake.set10('WITH_ZLIB', want_zlib)
|
||||
@@ -629,7 +621,6 @@ summary(
|
||||
'icu': want_icu,
|
||||
'iso8859x': want_iso8859x,
|
||||
'legacy': want_legacy,
|
||||
'lzma': want_lzma,
|
||||
'modules': want_modules,
|
||||
'output': want_output,
|
||||
'pattern': want_pattern,
|
||||
|
@@ -56,11 +56,6 @@ option('legacy',
|
||||
description: 'Maximum ABI compatibility'
|
||||
)
|
||||
|
||||
option('lzma',
|
||||
type: 'feature',
|
||||
description: 'LZMA support'
|
||||
)
|
||||
|
||||
option('modules',
|
||||
type: 'feature',
|
||||
description: 'Dynamic modules support'
|
||||
|
4
parser.c
4
parser.c
@@ -651,11 +651,7 @@ xmlHasFeature(xmlFeature feature)
|
||||
return(0);
|
||||
#endif
|
||||
case XML_WITH_LZMA:
|
||||
#ifdef LIBXML_LZMA_ENABLED
|
||||
return(1);
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
case XML_WITH_ICU:
|
||||
#ifdef LIBXML_ICU_ENABLED
|
||||
return(1);
|
||||
|
@@ -46,7 +46,6 @@ if py.found() == true
|
||||
setup_py.set('LIBXML_VERSION', meson.project_version())
|
||||
setup_py.set('WITH_ICONV', want_iconv.to_int())
|
||||
setup_py.set('WITH_ICU', want_icu.to_int())
|
||||
setup_py.set('WITH_LZMA', want_lzma.to_int())
|
||||
setup_py.set('WITH_ZLIB', want_zlib.to_int())
|
||||
setup_py.set('WITH_THREADS', want_threads.to_int())
|
||||
configure_file(
|
||||
|
@@ -26,7 +26,6 @@ with_threads = @WITH_THREADS@
|
||||
# Features of libxml2 requiring external DLLs
|
||||
with_iconv = @WITH_ICONV@
|
||||
with_zlib = @WITH_ZLIB@
|
||||
with_lzma = @WITH_LZMA@
|
||||
with_icu = @WITH_ICU@
|
||||
|
||||
icu_series = 69
|
||||
@@ -40,7 +39,6 @@ else:
|
||||
# (Check the value of `icu_series` above as well)
|
||||
iconv_dll = 'iconv.dll'
|
||||
zlib_dll = 'zlib1.dll'
|
||||
lzma_dll = 'liblzma.dll'
|
||||
icu_dlls = ['icuuc%s.dll' % icu_series_s, 'icudt%s.dll' % icu_series_s]
|
||||
|
||||
# If this flag is set (windows only),
|
||||
@@ -160,8 +158,6 @@ if WITHDLLS:
|
||||
|
||||
if with_zlib == 1:
|
||||
dlls.append(zlib_dll)
|
||||
if with_lzma == 1:
|
||||
dlls.append(lzma_dll)
|
||||
if with_iconv == 1:
|
||||
dlls.append(iconv_dll)
|
||||
if with_icu == 1:
|
||||
|
@@ -81,9 +81,6 @@ LIBS = $(LIBS) iconvomf.lib
|
||||
!if "$(WITH_ZLIB)" == "1"
|
||||
LIBS = $(LIBS) zlibomf.lib
|
||||
!endif
|
||||
!if "$(WITH_LZMA)" == "1"
|
||||
LIBS = $(LIBS) liblzma.lib
|
||||
!endif
|
||||
!if "$(WITH_THREADS)" == "posix"
|
||||
LIBS = $(LIBS) pthreadVC.lib
|
||||
!endif
|
||||
|
@@ -57,9 +57,6 @@ ifeq ($(WITH_ZLIB),1)
|
||||
# LIBS += -lzdll
|
||||
LIBS += -lz
|
||||
endif
|
||||
ifeq ($(WITH_LZMA),1)
|
||||
LIBS += -llzma
|
||||
endif
|
||||
ifeq ($(WITH_THREADS),posix)
|
||||
LIBS += -lpthreadGC
|
||||
endif
|
||||
|
@@ -67,9 +67,6 @@ LIBS = $(LIBS) icuuc.lib icuin.lib icudt.lib
|
||||
# LIBS = $(LIBS) zdll.lib
|
||||
LIBS = $(LIBS) zlib.lib
|
||||
!endif
|
||||
!if "$(WITH_LZMA)" == "1"
|
||||
LIBS = $(LIBS) liblzma.lib
|
||||
!endif
|
||||
!if "$(WITH_THREADS)" == "posix"
|
||||
LIBS = $(LIBS) pthreadVC.lib
|
||||
!endif
|
||||
@@ -224,12 +221,6 @@ XML_OBJS_A_DLL = $(XML_INTDIR_A_DLL)\buf.obj\
|
||||
$(XML_INTDIR_A_DLL)\xpointer.obj\
|
||||
$(XML_INTDIR_A_DLL)\xmlstring.obj
|
||||
|
||||
!if "$(WITH_LZMA)" == "1"
|
||||
XML_OBJS = $(XML_OBJS) $(XML_INTDIR)\xzlib.obj
|
||||
XML_OBJS_A = $(XML_OBJS_A) $(XML_INTDIR_A)\xzlib.obj
|
||||
XML_OBJS_A_DLL = $(XML_OBJS_A_DLL) $(XML_INTDIR_A_DLL)\xzlib.obj
|
||||
!endif
|
||||
|
||||
# Xmllint and friends executables.
|
||||
UTILS = $(BINDIR)\xmllint.exe\
|
||||
$(BINDIR)\xmlcatalog.exe\
|
||||
|
@@ -40,7 +40,6 @@ var withIconv = true;
|
||||
var withIcu = false;
|
||||
var withIso8859x = false;
|
||||
var withZlib = false;
|
||||
var withLzma = false;
|
||||
var withDebug = true;
|
||||
var withSchemas = true;
|
||||
var withSchematron = true;
|
||||
@@ -122,7 +121,6 @@ function usage()
|
||||
txt += " icu: Enable icu support (" + (withIcu? "yes" : "no") + ")\n";
|
||||
txt += " iso8859x: Enable ISO8859X support (" + (withIso8859x? "yes" : "no") + ")\n";
|
||||
txt += " zlib: Enable zlib support (" + (withZlib? "yes" : "no") + ")\n";
|
||||
txt += " lzma: Enable lzma support (" + (withLzma? "yes" : "no") + ")\n";
|
||||
txt += " xml_debug: Enable XML debbugging module (" + (withDebug? "yes" : "no") + ")\n";
|
||||
txt += " regexps: Enable regular expressions (" + (withRegExps? "yes" : "no") + ")\n";
|
||||
txt += " relaxng: Enable RELAX NG support (" + (withRelaxNg ? "yes" : "no") + ")\n";
|
||||
@@ -209,7 +207,6 @@ function discoverVersion()
|
||||
vf.WriteLine("WITH_ICU=" + (withIcu? "1" : "0"));
|
||||
vf.WriteLine("WITH_ISO8859X=" + (withIso8859x? "1" : "0"));
|
||||
vf.WriteLine("WITH_ZLIB=" + (withZlib? "1" : "0"));
|
||||
vf.WriteLine("WITH_LZMA=" + (withLzma? "1" : "0"));
|
||||
vf.WriteLine("WITH_DEBUG=" + (withDebug? "1" : "0"));
|
||||
vf.WriteLine("WITH_SCHEMAS=" + (withSchemas? "1" : "0"));
|
||||
vf.WriteLine("WITH_SCHEMATRON=" + (withSchematron? "1" : "0"));
|
||||
@@ -307,8 +304,6 @@ function configureLibxml()
|
||||
of.WriteLine(s.replace(/\@WITH_ISO8859X\@/, withIso8859x? "1" : "0"));
|
||||
} else if (s.search(/\@WITH_ZLIB\@/) != -1) {
|
||||
of.WriteLine(s.replace(/\@WITH_ZLIB\@/, withZlib? "1" : "0"));
|
||||
} else if (s.search(/\@WITH_LZMA\@/) != -1) {
|
||||
of.WriteLine(s.replace(/\@WITH_LZMA\@/, withLzma? "1" : "0"));
|
||||
} else if (s.search(/\@WITH_DEBUG\@/) != -1) {
|
||||
of.WriteLine(s.replace(/\@WITH_DEBUG\@/, withDebug? "1" : "0"));
|
||||
} else if (s.search(/\@WITH_SCHEMAS\@/) != -1) {
|
||||
@@ -370,8 +365,6 @@ function configureLibxmlPy()
|
||||
of.WriteLine(s.replace(/\@WITH_THREADS\@/, withThreads == "no"? "0" : "1"));
|
||||
} else if (s.search(/\@WITH_ZLIB\@/) != -1) {
|
||||
of.WriteLine(s.replace(/\@WITH_ZLIB\@/, withZlib? "1" : "0"));
|
||||
} else if (s.search(/\@WITH_LZMA\@/) != -1) {
|
||||
of.WriteLine(s.replace(/\@WITH_LZMA\@/, withLzma? "1" : "0"));
|
||||
} else if (s.search(/\@WITH_ICONV\@/) != -1) {
|
||||
of.WriteLine(s.replace(/\@WITH_ICONV\@/, withIconv? "1" : "0"));
|
||||
} else if (s.search(/\@WITH_ICU\@/) != -1) {
|
||||
@@ -454,8 +447,6 @@ for (i = 0; (i < WScript.Arguments.length) && (error == 0); i++) {
|
||||
withIso8859x = strToBool(arg.substring(opt.length + 1, arg.length));
|
||||
else if (opt == "zlib")
|
||||
withZlib = strToBool(arg.substring(opt.length + 1, arg.length));
|
||||
else if (opt == "lzma")
|
||||
withLzma = strToBool(arg.substring(opt.length + 1, arg.length));
|
||||
else if (opt == "xml_debug")
|
||||
withDebug = strToBool(arg.substring(opt.length + 1, arg.length));
|
||||
else if (opt == "schemas")
|
||||
@@ -632,7 +623,6 @@ txtOut += " iconv support: " + boolToStr(withIconv) + "\n";
|
||||
txtOut += " icu support: " + boolToStr(withIcu) + "\n";
|
||||
txtOut += " iso8859x support: " + boolToStr(withIso8859x) + "\n";
|
||||
txtOut += " zlib support: " + boolToStr(withZlib) + "\n";
|
||||
txtOut += " lzma support: " + boolToStr(withLzma) + "\n";
|
||||
txtOut += " Debugging module: " + boolToStr(withDebug) + "\n";
|
||||
txtOut += " Regexp support: " + boolToStr(withRegExps) + "\n";
|
||||
txtOut += " Relax NG support: " + boolToStr(withRelaxNg) + "\n";
|
||||
|
87
xmlIO.c
87
xmlIO.c
@@ -28,9 +28,6 @@
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
#ifdef LIBXML_LZMA_ENABLED
|
||||
#include <lzma.h>
|
||||
#endif
|
||||
|
||||
#include <libxml/xmlIO.h>
|
||||
#include <libxml/xmlmemory.h>
|
||||
@@ -1136,47 +1133,6 @@ xmlGzfileClose (void * context) {
|
||||
}
|
||||
#endif /* LIBXML_ZLIB_ENABLED */
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
* I/O for compressed file accesses *
|
||||
* *
|
||||
************************************************************************/
|
||||
|
||||
#ifdef LIBXML_LZMA_ENABLED
|
||||
|
||||
#include "private/xzlib.h"
|
||||
|
||||
/**
|
||||
* Read `len` bytes to `buffer` from the compressed I/O channel.
|
||||
*
|
||||
* @param context the I/O context
|
||||
* @param buffer where to drop data
|
||||
* @param len number of bytes to write
|
||||
* @returns the number of bytes written
|
||||
*/
|
||||
static int
|
||||
xmlXzfileRead (void * context, char * buffer, int len) {
|
||||
int ret;
|
||||
|
||||
ret = __libxml2_xzread((xzFile) context, &buffer[0], len);
|
||||
if (ret < 0)
|
||||
return(-XML_IO_UNKNOWN);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a compressed I/O channel
|
||||
*
|
||||
* @param context the I/O context
|
||||
*/
|
||||
static int
|
||||
xmlXzfileClose (void * context) {
|
||||
if (__libxml2_xzclose((xzFile) context) != LZMA_OK)
|
||||
return(XML_IO_UNKNOWN);
|
||||
return(0);
|
||||
}
|
||||
#endif /* LIBXML_LZMA_ENABLED */
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
* Input/output buffers *
|
||||
@@ -1188,7 +1144,7 @@ xmlIODefaultMatch(const char *filename ATTRIBUTE_UNUSED) {
|
||||
return(1);
|
||||
}
|
||||
|
||||
#if defined(LIBXML_LZMA_ENABLED) || defined(LIBXML_ZLIB_ENABLED)
|
||||
#if defined(LIBXML_ZLIB_ENABLED)
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef __int64 xmlFileOffset;
|
||||
@@ -1212,7 +1168,7 @@ xmlSeek(int fd, xmlFileOffset offset, int whence) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* defined(LIBXML_LZMA_ENABLED) || defined(LIBXML_ZLIB_ENABLED) */
|
||||
#endif /* defined(LIBXML_ZLIB_ENABLED) */
|
||||
|
||||
/**
|
||||
* Update the buffer to read from `fd`. Supports the XML_INPUT_UNZIP
|
||||
@@ -1231,45 +1187,6 @@ xmlInputFromFd(xmlParserInputBuffer *buf, int fd,
|
||||
|
||||
(void) flags;
|
||||
|
||||
#ifdef LIBXML_LZMA_ENABLED
|
||||
if (flags & XML_INPUT_UNZIP) {
|
||||
xzFile xzStream;
|
||||
xmlFileOffset pos;
|
||||
|
||||
pos = xmlSeek(fd, 0, SEEK_CUR);
|
||||
|
||||
copy = dup(fd);
|
||||
if (copy == -1)
|
||||
return(xmlIOErr(errno));
|
||||
|
||||
xzStream = __libxml2_xzdopen("?", copy, "rb");
|
||||
|
||||
if (xzStream == NULL) {
|
||||
close(copy);
|
||||
} else {
|
||||
int compressed = (__libxml2_xzcompressed(xzStream) > 0);
|
||||
|
||||
if ((compressed) ||
|
||||
/* Try to rewind if not gzip compressed */
|
||||
(pos < 0) ||
|
||||
(xmlSeek(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;
|
||||
buf->compressed = compressed;
|
||||
|
||||
return(XML_ERR_OK);
|
||||
}
|
||||
|
||||
xmlXzfileClose(xzStream);
|
||||
}
|
||||
}
|
||||
#endif /* LIBXML_LZMA_ENABLED */
|
||||
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
if (flags & XML_INPUT_UNZIP) {
|
||||
gzFile gzStream;
|
||||
|
@@ -2300,7 +2300,6 @@ static void showVersion(FILE *errStream, const char *name) {
|
||||
if (xmlHasFeature(XML_WITH_MODULES)) fprintf(errStream, "Modules ");
|
||||
if (xmlHasFeature(XML_WITH_DEBUG)) fprintf(errStream, "Debug ");
|
||||
if (xmlHasFeature(XML_WITH_ZLIB)) fprintf(errStream, "Zlib ");
|
||||
if (xmlHasFeature(XML_WITH_LZMA)) fprintf(errStream, "Lzma ");
|
||||
fprintf(errStream, "\n");
|
||||
}
|
||||
|
||||
|
821
xzlib.c
821
xzlib.c
@@ -1,821 +0,0 @@
|
||||
/**
|
||||
* xzlib.c: front end for the transparent support of lzma compression
|
||||
* at the I/O layer, based on an example file from lzma project
|
||||
*
|
||||
* See Copyright for the status of this software.
|
||||
*
|
||||
* Author: Anders F Bjorklund
|
||||
*/
|
||||
#define IN_LIBXML
|
||||
#include "libxml.h"
|
||||
#ifdef LIBXML_LZMA_ENABLED
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
#ifdef LIBXML_LZMA_ENABLED
|
||||
#include <lzma.h>
|
||||
#endif
|
||||
|
||||
#include "private/xzlib.h"
|
||||
#include <libxml/xmlmemory.h>
|
||||
|
||||
/* values for xz_state how */
|
||||
#define LOOK 0 /* look for a gzip/lzma header */
|
||||
#define COPY 1 /* copy input directly */
|
||||
#define GZIP 2 /* decompress a gzip stream */
|
||||
#define LZMA 3 /* decompress a lzma stream */
|
||||
|
||||
/* internal lzma file state data structure */
|
||||
typedef struct {
|
||||
int mode; /* see lzma modes above */
|
||||
int fd; /* file descriptor */
|
||||
char *path; /* path or fd for error messages */
|
||||
uint64_t pos; /* current position in uncompressed data */
|
||||
unsigned int size; /* buffer size, zero if not allocated yet */
|
||||
unsigned int want; /* requested buffer size, default is BUFSIZ */
|
||||
unsigned char *in; /* input buffer */
|
||||
unsigned char *out; /* output buffer (double-sized when reading) */
|
||||
unsigned char *next; /* next output data to deliver or write */
|
||||
unsigned int have; /* amount of output data unused at next */
|
||||
int eof; /* true if end of input file reached */
|
||||
uint64_t start; /* where the lzma data started, for rewinding */
|
||||
uint64_t raw; /* where the raw data started, for seeking */
|
||||
int how; /* 0: get header, 1: copy, 2: decompress */
|
||||
int direct; /* true if last read direct, false if lzma */
|
||||
/* seek request */
|
||||
uint64_t skip; /* amount to skip (already rewound if backwards) */
|
||||
int seek; /* true if seek request pending */
|
||||
/* error information */
|
||||
int err; /* error code */
|
||||
char *msg; /* error message */
|
||||
/* lzma stream */
|
||||
int init; /* is the inflate stream initialized */
|
||||
lzma_stream strm; /* stream structure in-place (not a pointer) */
|
||||
char padding1[32]; /* padding allowing to cope with possible
|
||||
extensions of above structure without
|
||||
too much side effect */
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
/* zlib inflate or deflate stream */
|
||||
z_stream zstrm; /* stream structure in-place (not a pointer) */
|
||||
#endif
|
||||
char padding2[32]; /* padding allowing to cope with possible
|
||||
extensions of above structure without
|
||||
too much side effect */
|
||||
} xz_state, *xz_statep;
|
||||
|
||||
static void
|
||||
xz_error(xz_statep state, int err, const char *msg)
|
||||
{
|
||||
/* free previously allocated message and clear */
|
||||
if (state->msg != NULL) {
|
||||
if (state->err != LZMA_MEM_ERROR)
|
||||
xmlFree(state->msg);
|
||||
state->msg = NULL;
|
||||
}
|
||||
|
||||
/* set error code, and if no message, then done */
|
||||
state->err = err;
|
||||
if (msg == NULL)
|
||||
return;
|
||||
|
||||
/* for an out of memory error, save as static string */
|
||||
if (err == LZMA_MEM_ERROR) {
|
||||
state->msg = (char *) msg;
|
||||
return;
|
||||
}
|
||||
|
||||
/* construct error message with path */
|
||||
state->msg = xmlMalloc(strlen(state->path) + strlen(msg) + 3);
|
||||
if (state->msg == NULL) {
|
||||
state->err = LZMA_MEM_ERROR;
|
||||
state->msg = (char *) "out of memory";
|
||||
return;
|
||||
}
|
||||
strcpy(state->msg, state->path);
|
||||
strcat(state->msg, ": ");
|
||||
strcat(state->msg, msg);
|
||||
}
|
||||
|
||||
static void
|
||||
xz_reset(xz_statep state)
|
||||
{
|
||||
state->have = 0; /* no output data available */
|
||||
state->eof = 0; /* not at end of file */
|
||||
state->how = LOOK; /* look for gzip header */
|
||||
state->direct = 1; /* default for empty file */
|
||||
state->seek = 0; /* no seek request pending */
|
||||
xz_error(state, LZMA_OK, NULL); /* clear error */
|
||||
state->pos = 0; /* no uncompressed data yet */
|
||||
state->strm.avail_in = 0; /* no input data yet */
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
state->zstrm.avail_in = 0; /* no input data yet */
|
||||
#endif
|
||||
}
|
||||
|
||||
static xzFile
|
||||
xz_open(const char *path, int fd, const char *mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
xz_statep state;
|
||||
off_t offset;
|
||||
|
||||
/* allocate xzFile structure to return */
|
||||
state = xmlMalloc(sizeof(xz_state));
|
||||
if (state == NULL)
|
||||
return NULL;
|
||||
state->size = 0; /* no buffers allocated yet */
|
||||
state->want = BUFSIZ; /* requested buffer size */
|
||||
state->msg = NULL; /* no error message yet */
|
||||
state->init = 0; /* initialization of zlib data */
|
||||
|
||||
/* save the path name for error messages */
|
||||
state->path = xmlMalloc(strlen(path) + 1);
|
||||
if (state->path == NULL) {
|
||||
xmlFree(state);
|
||||
return NULL;
|
||||
}
|
||||
strcpy(state->path, path);
|
||||
|
||||
/* open the file with the appropriate mode (or just use fd) */
|
||||
state->fd = fd != -1 ? fd : open(path,
|
||||
#ifdef O_LARGEFILE
|
||||
O_LARGEFILE |
|
||||
#endif
|
||||
#ifdef O_BINARY
|
||||
O_BINARY |
|
||||
#endif
|
||||
O_RDONLY, 0666);
|
||||
if (state->fd == -1) {
|
||||
xmlFree(state->path);
|
||||
xmlFree(state);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* save the current position for rewinding (only if reading) */
|
||||
offset = lseek(state->fd, 0, SEEK_CUR);
|
||||
if (offset == -1)
|
||||
state->start = 0;
|
||||
else
|
||||
state->start = offset;
|
||||
|
||||
/* initialize stream */
|
||||
xz_reset(state);
|
||||
|
||||
/* return stream */
|
||||
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:
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
/* Don't use lzma for gzip */
|
||||
return(0);
|
||||
#else
|
||||
return(1);
|
||||
#endif
|
||||
case LZMA:
|
||||
return(1);
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
|
||||
xzFile
|
||||
__libxml2_xzopen(const char *path, const char *mode)
|
||||
{
|
||||
return xz_open(path, -1, mode);
|
||||
}
|
||||
|
||||
xzFile
|
||||
__libxml2_xzdopen(const char *path, int fd, const char *mode)
|
||||
{
|
||||
return xz_open(path, fd, mode);
|
||||
}
|
||||
|
||||
static int
|
||||
xz_load(xz_statep state, unsigned char *buf, unsigned int len,
|
||||
unsigned int *have)
|
||||
{
|
||||
int ret;
|
||||
|
||||
*have = 0;
|
||||
do {
|
||||
ret = read(state->fd, buf + *have, len - *have);
|
||||
if (ret <= 0)
|
||||
break;
|
||||
*have += ret;
|
||||
} while (*have < len);
|
||||
if (ret < 0) {
|
||||
xz_error(state, -1, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (ret == 0)
|
||||
state->eof = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
xz_avail(xz_statep state)
|
||||
{
|
||||
lzma_stream *strm = &(state->strm);
|
||||
|
||||
if (state->err != LZMA_OK)
|
||||
return -1;
|
||||
if (state->eof == 0) {
|
||||
/* avail_in is size_t, which is not necessary sizeof(unsigned) */
|
||||
unsigned tmp = strm->avail_in;
|
||||
|
||||
if (xz_load(state, state->in, state->size, &tmp) == -1) {
|
||||
strm->avail_in = tmp;
|
||||
return -1;
|
||||
}
|
||||
strm->avail_in = tmp;
|
||||
strm->next_in = state->in;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
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)
|
||||
{
|
||||
lzma_stream *strm = &(state->strm);
|
||||
|
||||
return strm->avail_in >= 6 && memcmp(state->in, "\3757zXZ", 6) == 0;
|
||||
}
|
||||
|
||||
static int
|
||||
is_format_lzma(xz_statep state)
|
||||
{
|
||||
lzma_stream *strm = &(state->strm);
|
||||
|
||||
lzma_filter filter;
|
||||
lzma_options_lzma *opt;
|
||||
uint32_t dict_size;
|
||||
uint64_t uncompressed_size;
|
||||
size_t i;
|
||||
|
||||
if (strm->avail_in < 13)
|
||||
return 0;
|
||||
|
||||
filter.id = LZMA_FILTER_LZMA1;
|
||||
if (lzma_properties_decode(&filter, NULL, state->in, 5) != LZMA_OK)
|
||||
return 0;
|
||||
|
||||
opt = filter.options;
|
||||
dict_size = opt->dict_size;
|
||||
free(opt); /* we can't use xmlFree on a string returned by zlib */
|
||||
|
||||
/* A hack to ditch tons of false positives: We allow only dictionary
|
||||
* sizes that are 2^n or 2^n + 2^(n-1) or UINT32_MAX. LZMA_Alone
|
||||
* created only files with 2^n, but accepts any dictionary size.
|
||||
* If someone complains, this will be reconsidered.
|
||||
*/
|
||||
if (dict_size != UINT32_MAX) {
|
||||
uint32_t d;
|
||||
|
||||
if (dict_size == 0)
|
||||
return 0;
|
||||
|
||||
d = dict_size - 1;
|
||||
d |= d >> 2;
|
||||
d |= d >> 3;
|
||||
d |= d >> 4;
|
||||
d |= d >> 8;
|
||||
d |= d >> 16;
|
||||
++d;
|
||||
if (d != dict_size || dict_size == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Another hack to ditch false positives: Assume that if the
|
||||
* uncompressed size is known, it must be less than 256 GiB.
|
||||
* Again, if someone complains, this will be reconsidered.
|
||||
*/
|
||||
uncompressed_size = 0;
|
||||
for (i = 0; i < 8; ++i)
|
||||
uncompressed_size |= (uint64_t) (state->in[5 + i]) << (i * 8);
|
||||
|
||||
if (uncompressed_size != UINT64_MAX
|
||||
&& uncompressed_size > (UINT64_C(1) << 38))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
|
||||
/* Get next byte from input, or -1 if end or error. */
|
||||
#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. */
|
||||
static int
|
||||
gz_next4(xz_statep state, unsigned long *ret)
|
||||
{
|
||||
int ch;
|
||||
unsigned long val;
|
||||
z_streamp strm = &(state->zstrm);
|
||||
|
||||
val = NEXTZ();
|
||||
val += (unsigned) NEXTZ() << 8;
|
||||
val += (unsigned long) NEXTZ() << 16;
|
||||
ch = NEXTZ();
|
||||
if (ch == -1)
|
||||
return -1;
|
||||
val += (unsigned long) ch << 24;
|
||||
*ret = val;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
xz_head(xz_statep state)
|
||||
{
|
||||
lzma_stream *strm = &(state->strm);
|
||||
lzma_stream init = LZMA_STREAM_INIT;
|
||||
int flags;
|
||||
unsigned len;
|
||||
|
||||
/* Avoid unused variable warning if features are disabled. */
|
||||
(void) flags;
|
||||
(void) len;
|
||||
|
||||
/* allocate read buffers and inflate memory */
|
||||
if (state->size == 0) {
|
||||
/* allocate buffers */
|
||||
state->in = xmlMalloc(state->want);
|
||||
state->out = xmlMalloc(state->want << 1);
|
||||
if (state->in == NULL || state->out == NULL) {
|
||||
if (state->out != NULL)
|
||||
xmlFree(state->out);
|
||||
if (state->in != NULL)
|
||||
xmlFree(state->in);
|
||||
xz_error(state, LZMA_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
state->size = state->want;
|
||||
|
||||
/* allocate decoder memory */
|
||||
state->strm = init;
|
||||
state->strm.avail_in = 0;
|
||||
state->strm.next_in = NULL;
|
||||
if (lzma_auto_decoder(&state->strm, 100000000, 0) != LZMA_OK) {
|
||||
xmlFree(state->out);
|
||||
xmlFree(state->in);
|
||||
state->size = 0;
|
||||
xz_error(state, LZMA_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
/* allocate inflate memory */
|
||||
state->zstrm.zalloc = Z_NULL;
|
||||
state->zstrm.zfree = Z_NULL;
|
||||
state->zstrm.opaque = Z_NULL;
|
||||
state->zstrm.avail_in = 0;
|
||||
state->zstrm.next_in = Z_NULL;
|
||||
if (state->init == 0) {
|
||||
if (inflateInit2(&(state->zstrm), -15) != Z_OK) {/* raw inflate */
|
||||
xmlFree(state->out);
|
||||
xmlFree(state->in);
|
||||
state->size = 0;
|
||||
xz_error(state, LZMA_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
state->init = 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* get some data in the input buffer */
|
||||
if (strm->avail_in == 0) {
|
||||
if (xz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* look for the xz magic header bytes */
|
||||
if (is_format_xz(state) || is_format_lzma(state)) {
|
||||
state->how = LZMA;
|
||||
state->direct = 0;
|
||||
return 0;
|
||||
}
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
/* look for the gzip magic header bytes 31 and 139 */
|
||||
if (strm->next_in[0] == 31) {
|
||||
strm->avail_in--;
|
||||
strm->next_in++;
|
||||
if (strm->avail_in == 0 && xz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in && strm->next_in[0] == 139) {
|
||||
/* we have a gzip header, woo hoo! */
|
||||
strm->avail_in--;
|
||||
strm->next_in++;
|
||||
|
||||
/* skip rest of header */
|
||||
if (NEXT() != 8) { /* compression method */
|
||||
xz_error(state, LZMA_DATA_ERROR,
|
||||
"unknown compression method");
|
||||
return -1;
|
||||
}
|
||||
flags = NEXT();
|
||||
if (flags & 0xe0) { /* reserved flag bits */
|
||||
xz_error(state, LZMA_DATA_ERROR,
|
||||
"unknown header flags set");
|
||||
return -1;
|
||||
}
|
||||
NEXT(); /* modification time */
|
||||
NEXT();
|
||||
NEXT();
|
||||
NEXT();
|
||||
NEXT(); /* extra flags */
|
||||
NEXT(); /* operating system */
|
||||
if (flags & 4) { /* extra field */
|
||||
len = (unsigned) NEXT();
|
||||
len += (unsigned) NEXT() << 8;
|
||||
while (len--)
|
||||
if (NEXT() < 0)
|
||||
break;
|
||||
}
|
||||
if (flags & 8) /* file name */
|
||||
while (NEXT() > 0) ;
|
||||
if (flags & 16) /* comment */
|
||||
while (NEXT() > 0) ;
|
||||
if (flags & 2) { /* header crc */
|
||||
NEXT();
|
||||
NEXT();
|
||||
}
|
||||
/* an unexpected end of file is not checked for here -- it will be
|
||||
* noticed on the first request for uncompressed data */
|
||||
|
||||
/* set up for decompression */
|
||||
inflateReset(&state->zstrm);
|
||||
state->zstrm.adler = crc32(0L, Z_NULL, 0);
|
||||
state->how = GZIP;
|
||||
state->direct = 0;
|
||||
return 0;
|
||||
} else {
|
||||
/* not a gzip file -- save first byte (31) and fall to raw i/o */
|
||||
state->out[0] = 31;
|
||||
state->have = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* doing raw i/o, save start of raw data for seeking, copy any leftover
|
||||
* input to output -- this assumes that the output buffer is larger than
|
||||
* the input buffer, which also assures space for gzungetc() */
|
||||
state->raw = state->pos;
|
||||
state->next = state->out;
|
||||
if (strm->avail_in) {
|
||||
memcpy(state->next + state->have, strm->next_in, strm->avail_in);
|
||||
state->have += strm->avail_in;
|
||||
strm->avail_in = 0;
|
||||
}
|
||||
state->how = COPY;
|
||||
state->direct = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
xz_decomp(xz_statep state)
|
||||
{
|
||||
int ret;
|
||||
unsigned had;
|
||||
unsigned long crc, len;
|
||||
lzma_stream *strm = &(state->strm);
|
||||
|
||||
lzma_action action = LZMA_RUN;
|
||||
|
||||
/* Avoid unused variable warning if features are disabled. */
|
||||
(void) crc;
|
||||
(void) len;
|
||||
|
||||
/* fill output buffer up to end of deflate stream */
|
||||
had = strm->avail_out;
|
||||
do {
|
||||
/* get more input for inflate() */
|
||||
if (strm->avail_in == 0 && xz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in == 0) {
|
||||
xz_error(state, LZMA_DATA_ERROR, "unexpected end of file");
|
||||
return -1;
|
||||
}
|
||||
if (state->eof)
|
||||
action = LZMA_FINISH;
|
||||
|
||||
/* decompress and handle errors */
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
if (state->how == GZIP) {
|
||||
state->zstrm.avail_in = (uInt) state->strm.avail_in;
|
||||
state->zstrm.next_in = (Bytef *) state->strm.next_in;
|
||||
state->zstrm.avail_out = (uInt) state->strm.avail_out;
|
||||
state->zstrm.next_out = (Bytef *) state->strm.next_out;
|
||||
ret = inflate(&state->zstrm, Z_NO_FLUSH);
|
||||
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
|
||||
xz_error(state, Z_STREAM_ERROR,
|
||||
"internal error: inflate stream corrupt");
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* FIXME: Remapping a couple of error codes and falling through
|
||||
* to the LZMA error handling looks fragile.
|
||||
*/
|
||||
if (ret == Z_MEM_ERROR)
|
||||
ret = LZMA_MEM_ERROR;
|
||||
if (ret == Z_DATA_ERROR)
|
||||
ret = LZMA_DATA_ERROR;
|
||||
if (ret == Z_STREAM_END)
|
||||
ret = LZMA_STREAM_END;
|
||||
state->strm.avail_in = state->zstrm.avail_in;
|
||||
state->strm.next_in = state->zstrm.next_in;
|
||||
state->strm.avail_out = state->zstrm.avail_out;
|
||||
state->strm.next_out = state->zstrm.next_out;
|
||||
} else /* state->how == LZMA */
|
||||
#endif
|
||||
ret = lzma_code(strm, action);
|
||||
if (ret == LZMA_MEM_ERROR) {
|
||||
xz_error(state, LZMA_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
if (ret == LZMA_DATA_ERROR) {
|
||||
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;
|
||||
}
|
||||
if ((state->how != GZIP) &&
|
||||
(ret != LZMA_OK) && (ret != LZMA_STREAM_END)) {
|
||||
xz_error(state, ret, "lzma error");
|
||||
return -1;
|
||||
}
|
||||
} while (strm->avail_out && ret != LZMA_STREAM_END);
|
||||
|
||||
/* update available output and crc check value */
|
||||
state->have = had - strm->avail_out;
|
||||
state->next = strm->next_out - state->have;
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
state->zstrm.adler =
|
||||
crc32(state->zstrm.adler, state->next, state->have);
|
||||
#endif
|
||||
|
||||
if (ret == LZMA_STREAM_END) {
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
if (state->how == GZIP) {
|
||||
if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) {
|
||||
xz_error(state, LZMA_DATA_ERROR, "unexpected end of file");
|
||||
return -1;
|
||||
}
|
||||
if (crc != state->zstrm.adler) {
|
||||
xz_error(state, LZMA_DATA_ERROR, "incorrect data check");
|
||||
return -1;
|
||||
}
|
||||
if (len != (state->zstrm.total_out & 0xffffffffL)) {
|
||||
xz_error(state, LZMA_DATA_ERROR, "incorrect length check");
|
||||
return -1;
|
||||
}
|
||||
state->strm.avail_in = 0;
|
||||
state->strm.next_in = NULL;
|
||||
state->strm.avail_out = 0;
|
||||
state->strm.next_out = NULL;
|
||||
} else
|
||||
#endif
|
||||
if (strm->avail_in != 0 || !state->eof) {
|
||||
xz_error(state, LZMA_DATA_ERROR, "trailing garbage");
|
||||
return -1;
|
||||
}
|
||||
state->how = LOOK; /* ready for next stream, once have is 0 (leave
|
||||
* state->direct unchanged to remember how) */
|
||||
}
|
||||
|
||||
/* good decompression */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
xz_make(xz_statep state)
|
||||
{
|
||||
lzma_stream *strm = &(state->strm);
|
||||
|
||||
if (state->how == LOOK) { /* look for lzma / gzip header */
|
||||
if (xz_head(state) == -1)
|
||||
return -1;
|
||||
if (state->have) /* got some data from xz_head() */
|
||||
return 0;
|
||||
}
|
||||
if (state->how == COPY) { /* straight copy */
|
||||
if (xz_load(state, state->out, state->size << 1, &(state->have)) ==
|
||||
-1)
|
||||
return -1;
|
||||
state->next = state->out;
|
||||
} else if (state->how == LZMA || state->how == GZIP) { /* decompress */
|
||||
strm->avail_out = state->size << 1;
|
||||
strm->next_out = state->out;
|
||||
if (xz_decomp(state) == -1)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
xz_skip(xz_statep state, uint64_t len)
|
||||
{
|
||||
unsigned n;
|
||||
|
||||
/* skip over len bytes or reach end-of-file, whichever comes first */
|
||||
while (len)
|
||||
/* skip over whatever is in output buffer */
|
||||
if (state->have) {
|
||||
n = (uint64_t) state->have > len ?
|
||||
(unsigned) len : state->have;
|
||||
state->have -= n;
|
||||
state->next += n;
|
||||
state->pos += n;
|
||||
len -= n;
|
||||
}
|
||||
|
||||
/* output buffer empty -- return if we're at the end of the input */
|
||||
else if (state->eof && state->strm.avail_in == 0)
|
||||
break;
|
||||
|
||||
/* need more data to skip -- load up output buffer */
|
||||
else {
|
||||
/* get more output, looking for header if required */
|
||||
if (xz_make(state) == -1)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
__libxml2_xzcompressed(xzFile f) {
|
||||
xz_head(f);
|
||||
|
||||
return xz_compressed(f);
|
||||
}
|
||||
|
||||
int
|
||||
__libxml2_xzread(xzFile file, void *buf, unsigned len)
|
||||
{
|
||||
unsigned got, n;
|
||||
xz_statep state;
|
||||
lzma_stream *strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (xz_statep) file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->err != LZMA_OK)
|
||||
return -1;
|
||||
|
||||
/* since an int is returned, make sure len fits in one, otherwise return
|
||||
* with an error (this avoids the flaw in the interface) */
|
||||
if ((int) len < 0) {
|
||||
xz_error(state, LZMA_BUF_ERROR,
|
||||
"requested length does not fit in int");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* if len is zero, avoid unnecessary operations */
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
/* process a skip request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (xz_skip(state, state->skip) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get len bytes to buf, or less than len if at the end */
|
||||
got = 0;
|
||||
do {
|
||||
/* first just try copying data from the output buffer */
|
||||
if (state->have) {
|
||||
n = state->have > len ? len : state->have;
|
||||
memcpy(buf, state->next, n);
|
||||
state->next += n;
|
||||
state->have -= n;
|
||||
}
|
||||
|
||||
/* output buffer empty -- return if we're at the end of the input */
|
||||
else if (state->eof && strm->avail_in == 0)
|
||||
break;
|
||||
|
||||
/* need output data -- for small len or new stream load up our output
|
||||
* buffer */
|
||||
else if (state->how == LOOK || len < (state->size << 1)) {
|
||||
/* get more output, looking for header if required */
|
||||
if (xz_make(state) == -1)
|
||||
return -1;
|
||||
continue; /* no progress yet -- go back to memcpy() above */
|
||||
/* the copy above assures that we will leave with space in the
|
||||
* output buffer, allowing at least one gzungetc() to succeed */
|
||||
}
|
||||
|
||||
/* large len -- read directly into user buffer */
|
||||
else if (state->how == COPY) { /* read directly */
|
||||
if (xz_load(state, buf, len, &n) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* large len -- decompress directly into user buffer */
|
||||
else { /* state->how == LZMA */
|
||||
strm->avail_out = len;
|
||||
strm->next_out = buf;
|
||||
if (xz_decomp(state) == -1)
|
||||
return -1;
|
||||
n = state->have;
|
||||
state->have = 0;
|
||||
}
|
||||
|
||||
/* update progress */
|
||||
len -= n;
|
||||
buf = (char *) buf + n;
|
||||
got += n;
|
||||
state->pos += n;
|
||||
} while (len);
|
||||
|
||||
/* return number of bytes read into user buffer (will fit in int) */
|
||||
return (int) got;
|
||||
}
|
||||
|
||||
int
|
||||
__libxml2_xzclose(xzFile file)
|
||||
{
|
||||
int ret;
|
||||
xz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return LZMA_DATA_ERROR;
|
||||
state = (xz_statep) file;
|
||||
|
||||
/* free memory and close file */
|
||||
if (state->size) {
|
||||
lzma_end(&(state->strm));
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
if (state->init == 1)
|
||||
inflateEnd(&(state->zstrm));
|
||||
state->init = 0;
|
||||
#endif
|
||||
xmlFree(state->out);
|
||||
xmlFree(state->in);
|
||||
}
|
||||
xmlFree(state->path);
|
||||
if ((state->msg != NULL) && (state->err != LZMA_MEM_ERROR))
|
||||
xmlFree(state->msg);
|
||||
ret = close(state->fd);
|
||||
xmlFree(state);
|
||||
return ret ? ret : LZMA_OK;
|
||||
}
|
||||
#endif /* LIBXML_LZMA_ENABLED */
|
Reference in New Issue
Block a user