From 941e75163b9fc827641afa35a8b24b1803204a8f Mon Sep 17 00:00:00 2001
From: Amos Jeffries
Date: Tue, 27 Oct 2009 18:24:36 +1300
Subject: [PATCH] Author: Henrik Nordstrom
Polished ESI support
* make libxml2 and libexpat parser modules pluggable (Henrik)
* make libexpat and libxml2 tunable at configure time (Amos + Henrik)
* Fix Bug 2794: ESI parsing fails on FreeBSD (Francesco Chemolli)
* Enable ESI by default and auto-test
---
configure.in | 78 +++++++++++++--------
doc/release-notes/release-3.1.html | 14 +++-
doc/release-notes/release-3.1.sgml | 12 ++++
lib/libTrie/test/Makefile.am | 2 +-
src/Makefile.am | 21 +++---
src/esi/ExpatParser.cc | 2 +-
src/esi/ExpatParser.h | 7 +-
src/esi/Expression.cc | 2 +
src/esi/Libxml2Parser.cc | 2 +-
src/esi/Libxml2Parser.h | 10 ++-
src/esi/Makefile.am | 23 ++++--
src/esi/Module.cc | 22 +++++-
test-suite/buildtests/layer-02-maximus.opts | 2 +-
13 files changed, 141 insertions(+), 56 deletions(-)
diff --git a/configure.in b/configure.in
index fc5a0b0130..b0576a7ec4 100644
--- a/configure.in
+++ b/configure.in
@@ -831,34 +831,61 @@ AC_ARG_ENABLE(delay-pools,
dnl disable generic/common adaptation support by default
use_adaptation=no
-AM_CONDITIONAL(USE_ESI, false)
+use_esi=yes
AC_ARG_ENABLE(esi,
- AS_HELP_STRING([--enable-esi],[Enable ESI for accelerators. Requires libexpat.
- Enabling ESI will cause squid to follow the
- Edge Acceleration Specification (www.esi.org).
- This causes squid to IGNORE client Cache-Control headers.
- DO NOT use this in a squid configured as a web proxy,
- ONLY use it in a squid configured for webserver acceleration.]),
+ AS_HELP_STRING([--enable-esi],[Enable ESI for accelerators. Benefits from libexpat or libxml2.
+ Enabling ESI will cause squid reverse proxies to be capable of the
+ Edge Acceleration Specification (www.esi.org).]),
use_esi=$enableval, use_esi=no)
+HAVE_LIBEXPAT=0
+EXPATLIB=
+HAVE_LIBXML2=0
+XMLLIB=
if test "$use_esi" = "yes" ; then
+ AC_MSG_NOTICE([Enabling ESI processor and Surrogate header support.])
AC_DEFINE(USE_SQUID_ESI,1,[Compile the ESI processor and Surrogate header support])
- AM_CONDITIONAL(USE_ESI, true)
- dnl Perform configuration consistency checks for ESI
- dnl ESI support requires libexpat
- AC_CHECK_LIB([expat], [main],
- [ESI_LIBS="-lexpat"],
- [AC_MSG_FAILURE([ESI support requires libexpat library, but no usable library was found])]
- )
- AC_CHECK_LIB([xml2], [main],
- [ESI_LIBS="-lxml2"],
- [AC_MSG_FAILURE([ESI support requires libxml2 library, but no usable library was found])]
- )
- XTRA_LIBS="$XTRA_LIBS -lexpat -lxml2"
+ AC_ARG_WITH(expat, AS_HELP_STRING([--without-libexpat],[Do not use libexpat for ESI. Default: auto-detect]))
+ if test "$with_expat" != "no" ; then
+ AC_CHECK_LIB([expat], [main], [EXPATLIB="-lexpat"; HAVE_LIBEXPAT=1])
+ AC_CHECK_HEADERS([expat.h])
+ AC_DEFINE_UNQUOTED(HAVE_LIBEXPAT, $HAVE_LIBEXPAT, [Define to 1 if you have the expat library])
+ if test "$with_expat" = "yes" && test "$HAVE_LIBEXPAT" != "1" ; then
+ AC_MSG_ERROR([Required library libexpat is not able to be found.])
+ fi
+ fi
+
+ AC_ARG_WITH(xml2, AS_HELP_STRING([--without-libxml2],[Do not use libxml2 for ESI. Default: auto-detect]))
+ if test "$with_xml2" != "no" ; then
+ AC_CHECK_LIB([xml2], [main], [XMLLIB="-lxml2"; HAVE_LIBXML2=1])
+ dnl Find the main header and include path...
+ AC_CHECK_HEADERS([libxml/parser.h], [], [
+ SAVED_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="-I/usr/include/libxml2 $CPPFLAGS"
+ unset ac_cv_header_libxml_parser_h
+ AC_CHECK_HEADERS([libxml/parser.h], [ac_cv_libxml2_include=yes], [])
+ CPPFLAGS="$SAVED_CPPFLAGS"
+ ])
+ if test "x$ac_cv_libxml2_include" = "xyes"; then
+ SQUID_CXXFLAGS="-I/usr/include/libxml2 $SQUID_CXXFLAGS"
+ CPPFLAGS="-I/usr/include/libxml2 $CPPFLAGS"
+ fi
+ dnl Now that we know where to look find the other headers...
+ AC_CHECK_HEADERS(libxml/HTMLparser.h libxml/HTMLtree.h)
+ AC_DEFINE_UNQUOTED(HAVE_LIBXML2, $HAVE_LIBXML2, [Define to 1 if you have the libxml2 library])
+ if test "$with_xml2" = "yes" && test "$HAVE_LIBXML2" != "1" ; then
+ AC_MSG_ERROR([Required library libxml2 is not able to be found.])
+ fi
+ fi
else
- AC_DEFINE(USE_SQUID_ESI,0,[Compile the ESI processor and Surrogate header support])
+ AC_MSG_NOTICE([Disabling ESI processor and Surrogate header support.])
fi
+AM_CONDITIONAL(USE_ESI, test "$use_esi" = "yes")
+AM_CONDITIONAL(HAVE_LIBEXPAT, test $HAVE_LIBEXPAT = 1)
+AC_SUBST(EXPATLIB)
+AM_CONDITIONAL(HAVE_LIBXML2, test $HAVE_LIBXML2 = 1)
+AC_SUBST(XMLLIB)
AM_CONDITIONAL(USE_ICAP_CLIENT, false)
AC_ARG_ENABLE(icap-client,
@@ -2244,17 +2271,6 @@ AC_CHECK_HEADERS( \
,,,
SQUID_BSDNET_INCLUDES)
-AC_CHECK_HEADERS([libxml/parser.h], [], [
- SAVED_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="-I/usr/include/libxml2 $CPPFLAGS"
- unset ac_cv_header_libxml_parser_h
- AC_CHECK_HEADERS([libxml/parser.h], [ac_cv_libxml2_include=yes], [])
- CPPFLAGS="$SAVED_CPPFLAGS"
- ])
-if test "x$ac_cv_libxml2_include" = "xyes"; then
- SQUID_CXXFLAGS="-I/usr/include/libxml2 $SQUID_CXXFLAGS"
-fi
-
AC_C_CONST
AC_C_BIGENDIAN
diff --git a/doc/release-notes/release-3.1.html b/doc/release-notes/release-3.1.html
index e1812a1737..65f20f2a3e 100644
--- a/doc/release-notes/release-3.1.html
+++ b/doc/release-notes/release-3.1.html
@@ -1,7 +1,7 @@
-
+
Squid 3.1.0.13 release notes
@@ -1740,6 +1740,18 @@ check the CNAME-Only Requests statistics squid maintains.
If it produces ongoing serious problems the external helper may be needed
but please report the bugs anyway.
+--with-libexpat / --without-libexpat
+Require libexpat XML parser to be built into Squid for ESI parsing.
+Build will fail if this option is used and the library is not present.
+Default is to auto-detect it when using ESI and ignore if not present.
+Use --without-libexpat to prevent it being auto-detected.
+
+--with-libxml2 / --without-libxml2
+Require libxml2 XML parser to be built into Squid for ESI parsing.
+Build will fail if this option is used and the library is not present.
+Default is to auto-detect it when building with ESI.
+Use --without-libxml2 to prevent it being auto-detected.
+
--with-logdir=PATH
Allow build-time configuration of Default location for squid logs.
diff --git a/doc/release-notes/release-3.1.sgml b/doc/release-notes/release-3.1.sgml
index 0d480f8bb1..295a759fe7 100644
--- a/doc/release-notes/release-3.1.sgml
+++ b/doc/release-notes/release-3.1.sgml
@@ -1491,6 +1491,18 @@ This section gives an account of those changes in three categories:
If it produces ongoing serious problems the external helper may be needed
but please report the bugs anyway.
+ --with-libexpat / --without-libexpat
+
Require libexpat XML parser to be built into Squid for ESI parsing.
+ Build will fail if this option is used and the library is not present.
+ Default is to auto-detect it when using ESI and ignore if not present.
+ Use --without-libexpat to prevent it being auto-detected.
+
+ --with-libxml2 / --without-libxml2
+
Require libxml2 XML parser to be built into Squid for ESI parsing.
+ Build will fail if this option is used and the library is not present.
+ Default is to auto-detect it when building with ESI.
+ Use --without-libxml2 to prevent it being auto-detected.
+
--with-logdir=PATH
Allow build-time configuration of Default location for squid logs.
diff --git a/lib/libTrie/test/Makefile.am b/lib/libTrie/test/Makefile.am
index abb8cad137..45f88fea58 100644
--- a/lib/libTrie/test/Makefile.am
+++ b/lib/libTrie/test/Makefile.am
@@ -11,4 +11,4 @@ trie_SOURCES = trie.cc
trie_LDADD = $(top_builddir)/src/libTrie.a
trie_c_SOURCES = trie-c.c
-trie_c_LDADD = $(top_builddir)/src/libTrie.a -lstdc++
+trie_c_LDADD = $(top_builddir)/src/libTrie.a -lstdc++ -lm
diff --git a/src/Makefile.am b/src/Makefile.am
index 39d8006f3e..6b2ba23f14 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,9 +44,12 @@ ADAPTATION_LIBS = @ADAPTATION_LIBS@
if USE_ESI
SUBDIRS += esi
-ESI_LIBS = \
+ESI_LOCAL_LIBS = \
esi/libesi.la \
$(top_builddir)/lib/libTrie/src/libTrie.a
+ESI_LIBS = $(ESI_LOCAL_LIBS) \
+ @XMLLIB@ \
+ @EXPATLIB@
else
ESI_LIBS =
endif
@@ -527,7 +530,7 @@ squid_LDADD = \
@REGEXLIB@ \
@SNMPLIB@ \
${ADAPTATION_LIBS} \
- ${ESI_LIBS} \
+ $(ESI_LIBS) \
@SSLLIB@ \
-lmiscutil \
@XTRA_LIBS@ \
@@ -539,7 +542,7 @@ squid_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \
@REPL_OBJS@ \
@SNMPLIB@ \
${ADAPTATION_LIBS} \
- ${ESI_LIBS} \
+ $(ESI_LOCAL_LIBS) \
$(COMMON_LIBS)
if USE_LOADABLE_MODULES
@@ -1174,7 +1177,7 @@ tests_testCacheManager_LDADD = \
icmp/libicmp.la icmp/libicmp-core.la \
@REPL_OBJS@ \
${ADAPTATION_LIBS} \
- ${ESI_LIBS} \
+ $(ESI_LIBS) \
@REGEXLIB@ \
@SNMPLIB@ \
-L../lib -lmiscutil \
@@ -1345,7 +1348,7 @@ tests_testEvent_LDADD = \
icmp/libicmp.la icmp/libicmp-core.la \
@REPL_OBJS@ \
${ADAPTATION_LIBS} \
- ${ESI_LIBS} \
+ $(ESI_LIBS) \
@REGEXLIB@ \
@SNMPLIB@ \
-L../lib -lmiscutil \
@@ -1493,7 +1496,7 @@ tests_testEventLoop_LDADD = \
icmp/libicmp.la icmp/libicmp-core.la \
@REPL_OBJS@ \
${ADAPTATION_LIBS} \
- ${ESI_LIBS} \
+ $(ESI_LIBS) \
@REGEXLIB@ \
@SNMPLIB@ \
-L../lib -lmiscutil \
@@ -1636,7 +1639,7 @@ tests_test_http_range_LDADD = \
icmp/libicmp.la icmp/libicmp-core.la \
@REPL_OBJS@ \
${ADAPTATION_LIBS} \
- ${ESI_LIBS} \
+ $(ESI_LIBS) \
@REGEXLIB@ \
@SNMPLIB@ \
-L../lib -lmiscutil \
@@ -1784,7 +1787,7 @@ tests_testHttpRequest_LDADD = \
icmp/libicmp.la icmp/libicmp-core.la \
@REPL_OBJS@ \
${ADAPTATION_LIBS} \
- ${ESI_LIBS} \
+ $(ESI_LIBS) \
@REGEXLIB@ \
@SNMPLIB@ \
-L../lib -lmiscutil \
@@ -2136,7 +2139,7 @@ tests_testURL_LDADD = \
@REGEXLIB@ \
@REPL_OBJS@ \
${ADAPTATION_LIBS} \
- ${ESI_LIBS} \
+ $(ESI_LIBS) \
@SNMPLIB@ \
-L../lib -lmiscutil \
@SQUID_CPPUNIT_LIBS@ \
diff --git a/src/esi/ExpatParser.cc b/src/esi/ExpatParser.cc
index 6bdb0fd9c1..3019af08ec 100644
--- a/src/esi/ExpatParser.cc
+++ b/src/esi/ExpatParser.cc
@@ -35,7 +35,7 @@
#include "squid.h"
-#if USE_SQUID_ESI
+#if USE_SQUID_ESI && HAVE_LIBEXPAT
#include "esi/ExpatParser.h"
diff --git a/src/esi/ExpatParser.h b/src/esi/ExpatParser.h
index dfc5045a51..76246d75fb 100644
--- a/src/esi/ExpatParser.h
+++ b/src/esi/ExpatParser.h
@@ -33,10 +33,15 @@
#ifndef SQUID_ESIEXPATPARSER_H
#define SQUID_ESIEXPATPARSER_H
-#if USE_SQUID_ESI
+#include "config.h"
+
+#if USE_SQUID_ESI && HAVE_LIBEXPAT
#include "esi/Parser.h"
+
+#if HAVE_EXPAT_H
#include
+#endif
class ESIExpatParser : public ESIParser
{
diff --git a/src/esi/Expression.cc b/src/esi/Expression.cc
index 759171842d..012790391b 100644
--- a/src/esi/Expression.cc
+++ b/src/esi/Expression.cc
@@ -714,6 +714,7 @@ getsymbol (const char *s, char const **endptr)
if ((point = strchr (s, '.')) && point - s < (ssize_t)length) {
/* floating point */
+ errno=0; /* reset errno */
rv.value.floating = strtod (s, &end);
if (s == end || errno) {
@@ -730,6 +731,7 @@ getsymbol (const char *s, char const **endptr)
}
} else {
/* INT */
+ errno=0; /* reset errno */
rv.value.integral = strtol (s, &end, 0);
if (s == end || errno) {
diff --git a/src/esi/Libxml2Parser.cc b/src/esi/Libxml2Parser.cc
index e0fc3562cc..8f1a7faa6a 100644
--- a/src/esi/Libxml2Parser.cc
+++ b/src/esi/Libxml2Parser.cc
@@ -39,7 +39,7 @@
#include "squid.h"
-#if USE_SQUID_ESI
+#if USE_SQUID_ESI && HAVE_LIBXML2
#include "esi/Libxml2Parser.h"
diff --git a/src/esi/Libxml2Parser.h b/src/esi/Libxml2Parser.h
index c360930bb9..1dd093983e 100644
--- a/src/esi/Libxml2Parser.h
+++ b/src/esi/Libxml2Parser.h
@@ -40,7 +40,9 @@
#ifndef SQUID_ESILIBXML2PARSER_H
#define SQUID_ESILIBXML2PARSER_H
-#if USE_SQUID_ESI
+#include "config.h"
+
+#if USE_SQUID_ESI && HAVE_LIBXML2
#include "esi/Parser.h"
// workaround for definition of "free" that prevents include of
@@ -49,9 +51,15 @@
#define OLD_FREE free
#undef free
#endif
+#if HAVE_LIBXML_PARSER_H
#include
+#endif
+#if HAVE_LIBXML_HTMLPARSER_H
#include
+#endif
+#if HAVE_LIBXML_HTMLTREE_H
#include
+#endif
#ifdef OLD_FREE
#define free OLD_FREE
diff --git a/src/esi/Makefile.am b/src/esi/Makefile.am
index bbd58b7ed6..8158a45b8d 100644
--- a/src/esi/Makefile.am
+++ b/src/esi/Makefile.am
@@ -3,28 +3,39 @@ include $(top_srcdir)/src/TestHeaders.am
noinst_LTLIBRARIES = libesi.la
+ESI_PARSER_SOURCES = \
+ CustomParser.cc \
+ CustomParser.h
+
+if HAVE_LIBEXPAT
+ESI_PARSER_SOURCES += \
+ ExpatParser.cc \
+ ExpatParser.h
+endif
+
+if HAVE_LIBXML2
+ESI_PARSER_SOURCES += \
+ Libxml2Parser.cc \
+ Libxml2Parser.h
+endif
+
libesi_la_SOURCES = \
Assign.cc \
Assign.h \
Attempt.h \
Context.cc \
Context.h \
- CustomParser.cc \
- CustomParser.h \
+ $(ESI_PARSER_SOURCES) \
Element.h \
ElementList.h \
Esi.cc \
Esi.h \
Except.h \
- ExpatParser.cc \
- ExpatParser.h \
Expression.cc \
Expression.h \
Include.cc \
Include.h \
Literal.h \
- Libxml2Parser.cc \
- Libxml2Parser.h \
Module.cc \
Module.h \
Parser.cc \
diff --git a/src/esi/Module.cc b/src/esi/Module.cc
index 5d7b71875e..71b9be035e 100644
--- a/src/esi/Module.cc
+++ b/src/esi/Module.cc
@@ -5,26 +5,42 @@
#include "esi/ExpatParser.h" /* must follow esi/Libxml2Parser.h */
static ESIParser::Register *prCustom = 0;
+#if HAVE_LIBXML2
static ESIParser::Register *prLibxml = 0;
+#endif
+#if HAVE_LIBEXPAT
static ESIParser::Register *prExpat = 0;
+#endif
void Esi::Init()
{
assert(!prCustom); // we should be called once
+
prCustom = new ESIParser::Register("custom", &ESICustomParser::NewParser);
+
+#if HAVE_LIBXML2
prLibxml = new ESIParser::Register("libxml2", &ESILibxml2Parser::NewParser);
+#endif
+
+#if HAVE_LIBEXPAT
prExpat = new ESIParser::Register("expat", &ESIExpatParser::NewParser);
+#endif
}
void Esi::Clean()
{
assert(prCustom); // we should be called once, and only after Init()
+#if HAVE_LIBEXPAT
delete prExpat;
- delete prLibxml;
- delete prCustom;
-
prExpat = NULL;
+#endif
+
+#if HAVE_LIBXML2
+ delete prLibxml;
prLibxml = NULL;
+#endif
+
+ delete prCustom;
prCustom = NULL;
}
diff --git a/test-suite/buildtests/layer-02-maximus.opts b/test-suite/buildtests/layer-02-maximus.opts
index ca311846b7..fb68aaea9b 100644
--- a/test-suite/buildtests/layer-02-maximus.opts
+++ b/test-suite/buildtests/layer-02-maximus.opts
@@ -36,7 +36,6 @@ MAKETEST="distcheck"
# --enable-ecap \
# --enable-epoll \
# --enable-kqueue \
-# --enable-esi \
# --enable-win32-service \
#
#
@@ -96,6 +95,7 @@ OPTS=" \
--enable-auto-locale \
--enable-translation \
--enable-zph-qos \
+ --enable-esi \
\
--with-aio \
--with-build-environment=default \
--
2.47.3