mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2026-01-26 21:41:34 +03:00
xmllint: Use zlib directly
This prepares xmllint for eventually removing decompression support from libxml2.
This commit is contained in:
committed by
Daniel Garcia Moreno
parent
0704f52ea4
commit
956dfd2ddd
@@ -455,6 +455,9 @@ if(LIBXML2_WITH_PROGRAMS)
|
||||
endif()
|
||||
install(TARGETS ${PROGRAM} EXPORT LibXml2 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT programs)
|
||||
endforeach()
|
||||
if(LIBXML2_WITH_ZLIB)
|
||||
target_link_libraries(xmllint ZLIB::ZLIB)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LIBXML2_WITH_TESTS)
|
||||
|
||||
@@ -137,9 +137,9 @@ runsuite_DEPENDENCIES = $(DEPS)
|
||||
runsuite_LDADD= $(LDADDS)
|
||||
|
||||
xmllint_SOURCES = xmllint.c shell.c lintmain.c
|
||||
xmllint_CFLAGS = $(AM_CFLAGS) $(RDL_CFLAGS)
|
||||
xmllint_CFLAGS = $(AM_CFLAGS) $(RDL_CFLAGS) $(Z_CFLAGS)
|
||||
xmllint_DEPENDENCIES = $(DEPS)
|
||||
xmllint_LDADD= $(RDL_LIBS) $(LDADDS)
|
||||
xmllint_LDADD = $(RDL_LIBS) $(Z_LIBS) $(LDADDS)
|
||||
|
||||
testModule_SOURCES=testModule.c
|
||||
testModule_DEPENDENCIES = $(DEPS)
|
||||
|
||||
@@ -838,6 +838,8 @@ if test "$with_zlib" != "no" && test "$with_zlib" != ""; then
|
||||
XML_PRIVATE_LIBS="${XML_PRIVATE_LIBS} ${Z_LIBS}"
|
||||
fi
|
||||
AC_SUBST(WITH_ZLIB)
|
||||
AC_SUBST(Z_CFLAGS)
|
||||
AC_SUBST(Z_LIBS)
|
||||
|
||||
dnl
|
||||
dnl Checks for iconv library.
|
||||
|
||||
@@ -356,6 +356,10 @@ if want_history
|
||||
xmllint_deps += history_dep
|
||||
endif
|
||||
|
||||
if want_zlib
|
||||
xmllint_deps += dependency('zlib')
|
||||
endif
|
||||
|
||||
### crypto
|
||||
if sys_windows == true
|
||||
bcrypt_dep = cc.find_library('bcrypt', required: true)
|
||||
|
||||
69
xmllint.c
69
xmllint.c
@@ -33,6 +33,10 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#include <libxml/xmlmemory.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/parserInternals.h>
|
||||
@@ -329,10 +333,28 @@ xmllintResourceLoader(void *ctxt, const char *URL,
|
||||
* *
|
||||
************************************************************************/
|
||||
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
static int
|
||||
xmllintGzRead(void *ctxt, char *buf, int len) {
|
||||
return gzread(ctxt, buf, len);
|
||||
}
|
||||
|
||||
static int
|
||||
xmllintGzClose(void *ctxt) {
|
||||
if (gzclose(ctxt) != Z_OK)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static xmlDocPtr
|
||||
parseXml(xmllintState *lint, const char *filename) {
|
||||
xmlParserCtxtPtr ctxt = lint->ctxt;
|
||||
xmlDocPtr doc;
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
gzFile gz;
|
||||
#endif
|
||||
|
||||
#ifdef LIBXML_PUSH_ENABLED
|
||||
if (lint->appOptions & XML_LINT_PUSH_ENABLED) {
|
||||
@@ -380,12 +402,26 @@ parseXml(xmllintState *lint, const char *filename) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
if (strcmp(filename, "-") == 0)
|
||||
doc = xmlCtxtReadFd(ctxt, STDIN_FILENO, "-", NULL,
|
||||
lint->parseOptions | XML_PARSE_UNZIP);
|
||||
gz = gzdopen(STDIN_FILENO, "rb");
|
||||
else
|
||||
doc = xmlCtxtReadFile(ctxt, filename, NULL,
|
||||
lint->parseOptions | XML_PARSE_UNZIP);
|
||||
gz = gzopen(filename, "rb");
|
||||
|
||||
if (gz == NULL) {
|
||||
fprintf(lint->errStream, "Can't open %s\n", filename);
|
||||
lint->progresult = XMLLINT_ERR_RDFILE;
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
doc = xmlCtxtReadIO(ctxt, xmllintGzRead, xmllintGzClose, gz,
|
||||
filename, NULL, lint->parseOptions);
|
||||
#else
|
||||
if (strcmp(filename, "-") == 0)
|
||||
doc = xmlCtxtReadFd(ctxt, STDIN_FILENO, "-", NULL, lint->parseOptions);
|
||||
else
|
||||
doc = xmlCtxtReadFile(ctxt, filename, NULL, lint->parseOptions);
|
||||
#endif
|
||||
|
||||
return(doc);
|
||||
}
|
||||
@@ -1351,16 +1387,35 @@ static void streamFile(xmllintState *lint, const char *filename) {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
gzFile gz;
|
||||
#endif
|
||||
|
||||
xmlResetLastError();
|
||||
|
||||
#ifdef LIBXML_ZLIB_ENABLED
|
||||
if (strcmp(filename, "-") == 0)
|
||||
gz = gzdopen(STDIN_FILENO, "rb");
|
||||
else
|
||||
gz = gzopen(filename, "rb");
|
||||
|
||||
if (gz == NULL) {
|
||||
fprintf(lint->errStream, "Can't open %s\n", filename);
|
||||
lint->progresult = XMLLINT_ERR_RDFILE;
|
||||
return;
|
||||
}
|
||||
|
||||
reader = xmlReaderForIO(xmllintGzRead, xmllintGzClose, gz,
|
||||
filename, NULL, lint->parseOptions);
|
||||
#else
|
||||
if (strcmp(filename, "-") == 0) {
|
||||
reader = xmlReaderForFd(STDIN_FILENO, "-", NULL,
|
||||
lint->parseOptions | XML_PARSE_UNZIP);
|
||||
lint->parseOptions);
|
||||
}
|
||||
else {
|
||||
reader = xmlReaderForFile(filename, NULL,
|
||||
lint->parseOptions | XML_PARSE_UNZIP);
|
||||
reader = xmlReaderForFile(filename, NULL, lint->parseOptions);
|
||||
}
|
||||
#endif
|
||||
if (reader == NULL) {
|
||||
const xmlError *error = xmlGetLastError();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user