From: Amos Jeffries Date: Mon, 30 Mar 2009 11:44:37 +0000 (+1300) Subject: Author: Alex Rousskov X-Git-Tag: SQUID_3_1_0_7~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0c8eab419f87fd90f7bc0e7ed974bd4faa75bce2;p=thirdparty%2Fsquid.git Author: Alex Rousskov SourceLayout: esi/, take 1 Moved src/ESI* files into src/esi/. Renamed ESI source files from ESIFoo.{cc,cci,h} to Foo.{cc,cci,h}. Replaced implicit constructor-based Parser registration with an explicit call to Esi::Init() which knows of all ESI parsers. Added Esi::Clean counterpart. Made libTrie build conditional on ESI support being enabled. No true source code changes except for parser initialization. No functionality changes were intended. No runtime tests with ESI performed. TODO: I did not move the tests/ESIExpressions test into src/esi because we need to fix the entire testing layout before we should start moving individual tests: They currently depend on individual source and object files in src/ and in tests/ and that kind of dependency should not be multiplied but removed. TODO: Move ESI types into the Esi namespace. --- diff --git a/configure.in b/configure.in index 63e46597f4..1bd2ca9217 100644 --- a/configure.in +++ b/configure.in @@ -3791,6 +3791,7 @@ AC_CONFIG_FILES([\ src/adaptation/Makefile \ src/adaptation/icap/Makefile \ src/adaptation/ecap/Makefile \ + src/esi/Makefile \ src/icmp/Makefile \ src/ip/Makefile \ contrib/Makefile \ diff --git a/lib/Makefile.am b/lib/Makefile.am index 8cd9e72ced..ab4274d77e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -3,12 +3,16 @@ # $Id$ # -SUBDIRS = libTrie +SUBDIRS = if USE_LOADABLE_MODULES SUBDIRS += libLtdl endif +if USE_ESI +SUBDIRS += libTrie +endif + CLEANFILES = @@ -89,10 +93,8 @@ libmiscutil_a_SOURCES = \ xusleep.c \ $(XPROF_STATS_SOURCE) \ $(WIN32SRC) -libmiscutil_a_LIBADD = \ - libTrie/src/Trie.o \ - libTrie/src/TrieNode.o \ - @LIBOBJS@ +libmiscutil_a_LIBADD = @LIBOBJS@ + # $(top_srcdir)/include/version.h should be a dependency libntlmauth_a_SOURCES = \ ntlmauth.c diff --git a/src/Makefile.am b/src/Makefile.am index c13c848ea5..7bbd6539ec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,6 +40,15 @@ endif ADAPTATION_LIBS = @ADAPTATION_LIBS@ +if USE_ESI +SUBDIRS += esi +ESI_LIBS = \ + esi/libesi.la \ + $(top_builddir)/lib/libTrie/src/libTrie.a +else +ESI_LIBS = +endif + DELAY_POOL_ALL_SOURCE = \ CommonPool.h \ CompositePoolNode.h \ @@ -70,43 +79,6 @@ else DELAY_POOL_SOURCE = endif -ESI_ALL_SOURCE = \ - ElementList.h \ - ESI.cc \ - ESI.h \ - ESIAssign.cc \ - ESIAssign.h \ - ESIAttempt.h \ - ESIContext.cc \ - ESIContext.h \ - ESICustomParser.cc \ - ESICustomParser.h \ - ESIElement.h \ - ESIExcept.h \ - ESIExpatParser.cc \ - ESIExpatParser.h \ - ESIExpression.cc \ - ESIExpression.h \ - ESIInclude.cc \ - ESIInclude.h \ - ESILiteral.h \ - ESILibxml2Parser.cc \ - ESILibxml2Parser.h \ - ESIParser.cc \ - ESIParser.h \ - ESISegment.cc \ - ESISegment.h \ - ESISequence.cc \ - ESISequence.h \ - ESIVar.h \ - ESIVarState.cc \ - ESIVarState.h -if USE_ESI - ESI_SOURCE = $(ESI_ALL_SOURCE) -else - ESI_SOURCE = -endif - if ENABLE_XPROF_STATS XPROF_STATS_SOURCE = ProfStats.cc else @@ -203,7 +175,6 @@ INCLUDES = \ -I$(top_srcdir)/src \ -I$(top_builddir)/include \ -I$(top_srcdir)/include \ - -I$(top_srcdir)/lib/libTrie/include \ -I$(top_builddir)/lib \ -I$(top_srcdir)/lib \ @SQUID_CPPUNIT_INC@ @@ -280,7 +251,6 @@ EXTRA_squid_SOURCES = \ ipc.cc \ ipc_win32.cc \ $(IDENT_ALL_SOURCE) \ - $(ESI_ALL_SOURCE) \ ProfStats.cc \ LeakFinder.cc \ LeakFinder.h \ @@ -374,7 +344,6 @@ squid_SOURCES = \ enums.h \ errorpage.cc \ errorpage.h \ - $(ESI_SOURCE) \ ETag.cc \ event.cc \ event.h \ @@ -569,6 +538,7 @@ squid_LDADD = \ @REGEXLIB@ \ @SNMPLIB@ \ ${ADAPTATION_LIBS} \ + ${ESI_LIBS} \ @SSLLIB@ \ -lmiscutil \ @XTRA_LIBS@ \ @@ -1072,7 +1042,6 @@ tests_testCacheManager_SOURCES = \ dlink.cc \ $(DNSSOURCE) \ errorpage.cc \ - $(ESI_SOURCE) \ ETag.cc \ external_acl.cc \ ExternalACLEntry.cc \ @@ -1170,6 +1139,7 @@ tests_testCacheManager_LDADD = \ icmp/libicmp.la icmp/libicmp-core.la \ @REPL_OBJS@ \ ${ADAPTATION_LIBS} \ + ${ESI_LIBS} \ @REGEXLIB@ \ @SNMPLIB@ \ -L../lib -lmiscutil \ @@ -1241,7 +1211,6 @@ tests_testEvent_SOURCES = \ dlink.cc \ $(DNSSOURCE) \ errorpage.cc \ - $(ESI_SOURCE) \ ETag.cc \ external_acl.cc \ ExternalACLEntry.cc \ @@ -1338,6 +1307,7 @@ tests_testEvent_LDADD = \ icmp/libicmp.la icmp/libicmp-core.la \ @REPL_OBJS@ \ ${ADAPTATION_LIBS} \ + ${ESI_LIBS} \ @REGEXLIB@ \ @SNMPLIB@ \ -L../lib -lmiscutil \ @@ -1388,7 +1358,6 @@ tests_testEventLoop_SOURCES = \ dlink.cc \ $(DNSSOURCE) \ errorpage.cc \ - $(ESI_SOURCE) \ ETag.cc \ external_acl.cc \ ExternalACLEntry.cc \ @@ -1485,6 +1454,7 @@ tests_testEventLoop_LDADD = \ icmp/libicmp.la icmp/libicmp-core.la \ @REPL_OBJS@ \ ${ADAPTATION_LIBS} \ + ${ESI_LIBS} \ @REGEXLIB@ \ @SNMPLIB@ \ -L../lib -lmiscutil \ @@ -1524,7 +1494,6 @@ tests_test_http_range_SOURCES = \ dlink.cc \ $(DNSSOURCE) \ errorpage.cc \ - $(ESI_SOURCE) \ ETag.cc \ external_acl.cc \ ExternalACLEntry.cc \ @@ -1628,6 +1597,7 @@ tests_test_http_range_LDADD = \ @REPL_OBJS@ \ @STORE_LIBS_TO_ADD@ \ ${ADAPTATION_LIBS} \ + ${ESI_LIBS} \ @REGEXLIB@ \ @SNMPLIB@ \ -L../lib -lmiscutil \ @@ -1677,7 +1647,6 @@ tests_testHttpRequest_SOURCES = \ dlink.cc \ $(DNSSOURCE) \ errorpage.cc \ - $(ESI_SOURCE) \ ETag.cc \ external_acl.cc \ ExternalACLEntry.cc \ @@ -1775,6 +1744,7 @@ tests_testHttpRequest_LDADD = \ icmp/libicmp.la icmp/libicmp-core.la \ @REPL_OBJS@ \ ${ADAPTATION_LIBS} \ + ${ESI_LIBS} \ @REGEXLIB@ \ @SNMPLIB@ \ -L../lib -lmiscutil \ @@ -2026,7 +1996,6 @@ tests_testURL_SOURCES = \ dlink.cc \ $(DNSSOURCE) \ errorpage.cc \ - $(ESI_SOURCE) \ ETag.cc \ external_acl.cc \ ExternalACLEntry.cc \ @@ -2122,6 +2091,7 @@ tests_testURL_LDADD = \ @REGEXLIB@ \ @REPL_OBJS@ \ ${ADAPTATION_LIBS} \ + ${ESI_LIBS} \ @SNMPLIB@ \ -L../lib -lmiscutil \ @SQUID_CPPUNIT_LIBS@ \ diff --git a/src/Store.h b/src/Store.h index 8e60c2413a..1d6ebf3d46 100644 --- a/src/Store.h +++ b/src/Store.h @@ -50,7 +50,7 @@ #include "RemovalPolicy.h" #if USE_SQUID_ESI -#include "ESIElement.h" +#include "esi/Element.h" #endif class AsyncCall; diff --git a/src/cache_cf.cc b/src/cache_cf.cc index bec35bf316..0bed7904ea 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -57,7 +57,7 @@ #include "snmp.h" #endif #if USE_SQUID_ESI -#include "ESIParser.h" +#include "esi/Parser.h" #endif #if USE_ADAPTATION diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 1d62ea48f5..57a51e1a03 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -48,7 +48,7 @@ #include "clientStream.h" #include "auth/UserRequest.h" #if USE_SQUID_ESI -#include "ESI.h" +#include "esi/Esi.h" #endif #include "MemObject.h" #include "fde.h" diff --git a/src/ESIAssign.cc b/src/esi/Assign.cc similarity index 98% rename from src/ESIAssign.cc rename to src/esi/Assign.cc index 3efc390638..6b5aed741e 100644 --- a/src/ESIAssign.cc +++ b/src/esi/Assign.cc @@ -40,9 +40,9 @@ */ #if (USE_SQUID_ESI == 1) -#include "ESIAssign.h" -#include "ESIContext.h" -#include "ESISequence.h" +#include "esi/Assign.h" +#include "esi/Context.h" +#include "esi/Sequence.h" ESIAssign::~ESIAssign() { diff --git a/src/ESIAssign.h b/src/esi/Assign.h similarity index 98% rename from src/ESIAssign.h rename to src/esi/Assign.h index c107d50126..fd9fa12947 100644 --- a/src/ESIAssign.h +++ b/src/esi/Assign.h @@ -37,9 +37,9 @@ #define SQUID_ESIASSIGN_H #include "squid.h" -#include "ESIElement.h" +#include "esi/Element.h" #include "SquidString.h" -#include "ESIVarState.h" +#include "esi/VarState.h" /* ESIVariableExpression */ /* This is a variable that is itself and expression */ diff --git a/src/ESIAttempt.h b/src/esi/Attempt.h similarity index 97% rename from src/ESIAttempt.h rename to src/esi/Attempt.h index f09d67971c..e7b0f5d5e9 100644 --- a/src/ESIAttempt.h +++ b/src/esi/Attempt.h @@ -37,8 +37,8 @@ #define SQUID_ESIATTEMPT_H #include "squid.h" -#include "ESIElement.h" -#include "ESISequence.h" +#include "esi/Element.h" +#include "esi/Sequence.h" /* esiAttempt */ diff --git a/src/ESIContext.cc b/src/esi/Context.cc similarity index 99% rename from src/ESIContext.cc rename to src/esi/Context.cc index 841313a0bf..2db6adbcf5 100644 --- a/src/ESIContext.cc +++ b/src/esi/Context.cc @@ -40,7 +40,7 @@ */ #if (USE_SQUID_ESI == 1) -#include "ESIContext.h" +#include "esi/Context.h" #include "Store.h" #include "client_side_request.h" diff --git a/src/ESIContext.h b/src/esi/Context.h similarity index 99% rename from src/ESIContext.h rename to src/esi/Context.h index 5416a2cf41..bf958dc59e 100644 --- a/src/ESIContext.h +++ b/src/esi/Context.h @@ -34,14 +34,14 @@ #ifndef SQUID_ESICONTEXT_H #define SQUID_ESICONTEXT_H -#include "ESIElement.h" +#include "esi/Element.h" #include "clientStream.h" class ESIVarState; class ClientHttpRequest; -#include "ESIParser.h" +#include "esi/Parser.h" /* ESIContext */ diff --git a/src/ESICustomParser.cc b/src/esi/CustomParser.cc similarity index 99% rename from src/ESICustomParser.cc rename to src/esi/CustomParser.cc index b59880d009..d9bfba8f43 100644 --- a/src/ESICustomParser.cc +++ b/src/esi/CustomParser.cc @@ -34,14 +34,14 @@ */ #include "squid.h" -#include "ESICustomParser.h" +#include "esi/CustomParser.h" #include "Trie.h" #include "TrieCharTransform.h" #include "Array.h" Trie *ESICustomParser::SearchTrie=NULL; -RegisterESIParser("custom", ESICustomParser); +EsiParserDefinition(ESICustomParser); Trie * ESICustomParser::GetTrie() diff --git a/src/ESICustomParser.h b/src/esi/CustomParser.h similarity index 97% rename from src/ESICustomParser.h rename to src/esi/CustomParser.h index 146a4ac444..7bc2b9a3f7 100644 --- a/src/ESICustomParser.h +++ b/src/esi/CustomParser.h @@ -35,7 +35,7 @@ class Trie; /* inherits from */ -#include "ESIParser.h" +#include "esi/Parser.h" /* for String variables */ #include "SquidString.h" @@ -54,8 +54,9 @@ public: long int lineNumber() const; char const * errorString() const; + EsiParserDeclaration; + private: - ESI_PARSER_TYPE; static Trie *SearchTrie; static Trie *GetTrie(); enum ESITAG_t { diff --git a/src/ESIElement.h b/src/esi/Element.h similarity index 99% rename from src/ESIElement.h rename to src/esi/Element.h index ef773bd153..b2f6d0c393 100644 --- a/src/ESIElement.h +++ b/src/esi/Element.h @@ -34,7 +34,7 @@ #define SQUID_ESIELEMENT_H #include "RefCount.h" -#include "ESISegment.h" +#include "esi/Segment.h" typedef enum { ESI_PROCESS_COMPLETE = 0, diff --git a/src/ElementList.h b/src/esi/ElementList.h similarity index 98% rename from src/ElementList.h rename to src/esi/ElementList.h index aa7bef2bf3..15ff033b0a 100644 --- a/src/ElementList.h +++ b/src/esi/ElementList.h @@ -37,7 +37,7 @@ #define SQUID_ELEMENTLIST_H #include "squid.h" -#include "ESIElement.h" +#include "esi/Element.h" class ElementList { diff --git a/src/ESI.cc b/src/esi/Esi.cc similarity index 99% rename from src/ESI.cc rename to src/esi/Esi.cc index 875e8b25df..d41513ea9e 100644 --- a/src/ESI.cc +++ b/src/esi/Esi.cc @@ -38,22 +38,22 @@ */ #if (USE_SQUID_ESI == 1) -#include "ESI.h" +#include "esi/Esi.h" #include "clientStream.h" #include "client_side_request.h" #include "errorpage.h" -#include "ESISegment.h" -#include "ESIElement.h" -#include "ESIContext.h" +#include "esi/Segment.h" +#include "esi/Element.h" +#include "esi/Context.h" #include "HttpHdrSc.h" #include "HttpHdrScTarget.h" #include "HttpReply.h" -#include "ESIAttempt.h" -#include "ESIExcept.h" +#include "esi/Attempt.h" +#include "esi/Except.h" #include "client_side.h" -#include "ESIVarState.h" -#include "ESIAssign.h" -#include "ESIExpression.h" +#include "esi/VarState.h" +#include "esi/Assign.h" +#include "esi/Expression.h" #include "HttpRequest.h" #include "MemBuf.h" #include "ip/IpAddress.h" @@ -116,11 +116,11 @@ struct esiComment : public ESIElement { MEMPROXY_CLASS_INLINE(esiComment) /**DOCS_NOSEMI*/ -#include "ESILiteral.h" +#include "esi/Literal.h" -#include "ESISequence.h" +#include "esi/Sequence.h" -#include "ESIInclude.h" +#include "esi/Include.h" /* esiRemove */ @@ -181,7 +181,7 @@ private: MEMPROXY_CLASS_INLINE(esiTry) /**DOCS_NOSEMI*/ -#include "ESIVar.h" +#include "esi/Var.h" /* esiChoose */ diff --git a/src/ESI.h b/src/esi/Esi.h similarity index 100% rename from src/ESI.h rename to src/esi/Esi.h diff --git a/src/ESIExcept.h b/src/esi/Except.h similarity index 97% rename from src/ESIExcept.h rename to src/esi/Except.h index 9e432d385f..7c684b0cd4 100644 --- a/src/ESIExcept.h +++ b/src/esi/Except.h @@ -37,8 +37,8 @@ #define SQUID_ESIEXCEPT_H #include "squid.h" -#include "ESIElement.h" -#include "ESISequence.h" +#include "esi/Element.h" +#include "esi/Sequence.h" /* esiExcept */ diff --git a/src/ESIExpatParser.cc b/src/esi/ExpatParser.cc similarity index 97% rename from src/ESIExpatParser.cc rename to src/esi/ExpatParser.cc index d5c1affd7a..6bdb0fd9c1 100644 --- a/src/ESIExpatParser.cc +++ b/src/esi/ExpatParser.cc @@ -37,9 +37,9 @@ #if USE_SQUID_ESI -#include "ESIExpatParser.h" +#include "esi/ExpatParser.h" -RegisterESIParser("expat", ESIExpatParser); +EsiParserDefinition(ESIExpatParser); ESIExpatParser::ESIExpatParser(ESIParserClient *aClient) : theClient (aClient) { diff --git a/src/ESIExpatParser.h b/src/esi/ExpatParser.h similarity index 96% rename from src/ESIExpatParser.h rename to src/esi/ExpatParser.h index 32d48fb1ff..dfc5045a51 100644 --- a/src/ESIExpatParser.h +++ b/src/esi/ExpatParser.h @@ -35,8 +35,8 @@ #if USE_SQUID_ESI -#include "ESIParser.h" -#include "expat.h" +#include "esi/Parser.h" +#include class ESIExpatParser : public ESIParser { @@ -51,8 +51,9 @@ public: long int lineNumber() const; char const * errorString() const; + EsiParserDeclaration; + private: - ESI_PARSER_TYPE; /** our parser */ mutable XML_Parser p; static void Start(void *data, const XML_Char *el, const char **attr); diff --git a/src/ESIExpression.cc b/src/esi/Expression.cc similarity index 99% rename from src/ESIExpression.cc rename to src/esi/Expression.cc index a831052522..759171842d 100644 --- a/src/ESIExpression.cc +++ b/src/esi/Expression.cc @@ -34,7 +34,7 @@ */ #include "squid.h" -#include "ESIExpression.h" +#include "esi/Expression.h" /* stack precedence rules: * before pushing an operator onto the stack, the diff --git a/src/ESIExpression.h b/src/esi/Expression.h similarity index 100% rename from src/ESIExpression.h rename to src/esi/Expression.h diff --git a/src/ESIInclude.cc b/src/esi/Include.cc similarity index 99% rename from src/ESIInclude.cc rename to src/esi/Include.cc index 88d0dd675b..d869b82204 100644 --- a/src/ESIInclude.cc +++ b/src/esi/Include.cc @@ -41,8 +41,8 @@ */ #if (USE_SQUID_ESI == 1) -#include "ESIInclude.h" -#include "ESIVarState.h" +#include "esi/Include.h" +#include "esi/VarState.h" #include "client_side_request.h" #include "HttpReply.h" diff --git a/src/ESIInclude.h b/src/esi/Include.h similarity index 97% rename from src/ESIInclude.h rename to src/esi/Include.h index 6c3e701c88..944a6cfaf4 100644 --- a/src/ESIInclude.h +++ b/src/esi/Include.h @@ -37,9 +37,9 @@ #define SQUID_ESIINCLUDE_H #include "squid.h" -#include "ESISegment.h" -#include "ESIElement.h" -#include "ESIContext.h" +#include "esi/Segment.h" +#include "esi/Element.h" +#include "esi/Context.h" class ESIInclude; typedef RefCount ESIIncludePtr; diff --git a/src/ESILibxml2Parser.cc b/src/esi/Libxml2Parser.cc similarity index 98% rename from src/ESILibxml2Parser.cc rename to src/esi/Libxml2Parser.cc index 8875ba9c22..e0fc3562cc 100644 --- a/src/ESILibxml2Parser.cc +++ b/src/esi/Libxml2Parser.cc @@ -41,13 +41,13 @@ #if USE_SQUID_ESI -#include "ESILibxml2Parser.h" +#include "esi/Libxml2Parser.h" // the global document that will store the resolved entity // definitions static htmlDocPtr entity_doc = NULL; -RegisterESIParser("libxml2", ESILibxml2Parser); +EsiParserDefinition(ESILibxml2Parser); // the SAX callback functions void esi_startElementSAXFunc(void * ctx, const xmlChar * name, const xmlChar ** atts) diff --git a/src/ESILibxml2Parser.h b/src/esi/Libxml2Parser.h similarity index 97% rename from src/ESILibxml2Parser.h rename to src/esi/Libxml2Parser.h index 21ac43f68f..c360930bb9 100644 --- a/src/ESILibxml2Parser.h +++ b/src/esi/Libxml2Parser.h @@ -42,7 +42,7 @@ #if USE_SQUID_ESI -#include "ESIParser.h" +#include "esi/Parser.h" // workaround for definition of "free" that prevents include of // parser.h from libxml2 without errors #ifdef free @@ -70,8 +70,9 @@ public: ESIParserClient *getClient() { return theClient; } + EsiParserDeclaration; + private: - ESI_PARSER_TYPE; mutable xmlParserCtxtPtr parser; /* our parser */ ESIParserClient *theClient; diff --git a/src/ESILiteral.h b/src/esi/Literal.h similarity index 98% rename from src/ESILiteral.h rename to src/esi/Literal.h index a6e49571ec..19f53b5846 100644 --- a/src/ESILiteral.h +++ b/src/esi/Literal.h @@ -37,7 +37,7 @@ #define SQUID_ESILITERAL_H #include "squid.h" -#include "ESIElement.h" +#include "esi/Element.h" class ESIContext; /* esiLiteral */ diff --git a/src/esi/Makefile.am b/src/esi/Makefile.am new file mode 100644 index 0000000000..bbd58b7ed6 --- /dev/null +++ b/src/esi/Makefile.am @@ -0,0 +1,43 @@ +include $(top_srcdir)/src/Common.am +include $(top_srcdir)/src/TestHeaders.am + +noinst_LTLIBRARIES = libesi.la + +libesi_la_SOURCES = \ + Assign.cc \ + Assign.h \ + Attempt.h \ + Context.cc \ + Context.h \ + CustomParser.cc \ + CustomParser.h \ + 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 \ + Parser.h \ + Segment.cc \ + Segment.h \ + Sequence.cc \ + Sequence.h \ + Var.h \ + VarState.cc \ + VarState.h + +INCLUDES += \ + -I$(top_srcdir)/lib/libTrie/include \ + -I$(top_builddir)/lib/libTrie/include + diff --git a/src/esi/Module.cc b/src/esi/Module.cc new file mode 100644 index 0000000000..cbc91c74f3 --- /dev/null +++ b/src/esi/Module.cc @@ -0,0 +1,28 @@ +#include "squid.h" +#include "esi/Module.h" +#include "esi/CustomParser.h" +#include "esi/Libxml2Parser.h" +#include "esi/ExpatParser.h" /* must follow esi/Libxml2Parser.h */ + +static ESIParser::Register *prCustom = 0; +static ESIParser::Register *prLibxml = 0; +static ESIParser::Register *prExpat = 0; + +void Esi::Init() { + assert(!prCustom); // we should be called once + prCustom = new ESIParser::Register("custom", &ESICustomParser::NewParser); + prLibxml = new ESIParser::Register("libxml2", &ESILibxml2Parser::NewParser); + prExpat = new ESIParser::Register("expat", &ESIExpatParser::NewParser); +} + +void Esi::Clean() { + assert(prCustom); // we should be called once, and only after Init() + + delete prExpat; + delete prLibxml; + delete prCustom; + + prExpat = NULL; + prLibxml = NULL; + prCustom = NULL; +} diff --git a/src/esi/Module.h b/src/esi/Module.h new file mode 100644 index 0000000000..98483a9fb7 --- /dev/null +++ b/src/esi/Module.h @@ -0,0 +1,11 @@ +#ifndef SQUID_ESI_MODULE_H +#define SQUID_ESI_MODULE_H + +namespace Esi { + + extern void Init(); + extern void Clean(); + +}; // namespace Esi + +#endif /* SQUID_ESI_MODULE_H */ diff --git a/src/ESIParser.cc b/src/esi/Parser.cc similarity index 82% rename from src/ESIParser.cc rename to src/esi/Parser.cc index 778e9bf5f9..1b656071b1 100644 --- a/src/ESIParser.cc +++ b/src/esi/Parser.cc @@ -33,7 +33,7 @@ */ #include "squid.h" -#include "ESIParser.h" +#include "esi/Parser.h" char *ESIParser::Type = NULL; ESIParser::Register *ESIParser::Parsers = NULL; @@ -54,3 +54,14 @@ ESIParser::NewParser(ESIParserClient *aClient) return (Parser->newParser)(aClient); } + +ESIParser::Register::Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient)) : name(_name), newParser(_newParser) { + this->next = ESIParser::Parsers; + ESIParser::Parsers = this; +} + +ESIParser::Register::~Register() { + // TODO: support random-order deregistration + assert(ESIParser::Parsers == this); + ESIParser::Parsers = next; +} diff --git a/src/ESIParser.h b/src/esi/Parser.h similarity index 89% rename from src/ESIParser.h rename to src/esi/Parser.h index e6bbfb1962..13ac18d4f3 100644 --- a/src/ESIParser.h +++ b/src/esi/Parser.h @@ -52,6 +52,7 @@ public: class ESIParser : public RefCountable { public: + class Register; typedef RefCount Pointer; static void registerParser(const char *name, Pointer (*new_func)(ESIParserClient *aClient)); @@ -70,8 +71,6 @@ public: protected: ESIParser() {}; - class Register; - private: static Register *Parser; static Register *Parsers; @@ -83,26 +82,21 @@ class ESIParser::Register { public: - Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient)) : name(_name), newParser(_newParser) { - this->next = ESIParser::Parsers; - ESIParser::Parsers = this; - } + Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient)); + ~Register(); const char *name; ESIParser::Pointer (*newParser)(ESIParserClient *aClient); Register * next; }; -#define RegisterESIParser(name, ThisClass) \ - ESIParser::Register ThisClass::thisParser(name, &NewParser); \ +#define EsiParserDefinition(ThisClass) \ ESIParser::Pointer ThisClass::NewParser(ESIParserClient *aClient) \ { \ return new ThisClass (aClient); \ } -#define ESI_PARSER_TYPE \ - static ESIParser::Pointer NewParser(ESIParserClient *aClient); \ - static ESIParser::Register thisParser - +#define EsiParserDeclaration \ + static ESIParser::Pointer NewParser(ESIParserClient *aClient) #endif /* SQUID_ESIPARSER_H */ diff --git a/src/ESISegment.cc b/src/esi/Segment.cc similarity index 99% rename from src/ESISegment.cc rename to src/esi/Segment.cc index d82e5185e5..a6f9df604d 100644 --- a/src/ESISegment.cc +++ b/src/esi/Segment.cc @@ -34,7 +34,7 @@ */ #include "squid.h" -#include "ESISegment.h" +#include "esi/Segment.h" #include "SquidString.h" CBDATA_TYPE(ESISegment); diff --git a/src/ESISegment.h b/src/esi/Segment.h similarity index 100% rename from src/ESISegment.h rename to src/esi/Segment.h diff --git a/src/ESISequence.cc b/src/esi/Sequence.cc similarity index 99% rename from src/ESISequence.cc rename to src/esi/Sequence.cc index 06f4d4fca4..bb4035c7d0 100644 --- a/src/ESISequence.cc +++ b/src/esi/Sequence.cc @@ -40,10 +40,10 @@ */ #if (USE_SQUID_ESI == 1) -#include "ESISequence.h" -#include "ESILiteral.h" -#include "ESIAttempt.h" -#include "ESIExcept.h" +#include "esi/Sequence.h" +#include "esi/Literal.h" +#include "esi/Attempt.h" +#include "esi/Except.h" class esiExcept; diff --git a/src/ESISequence.h b/src/esi/Sequence.h similarity index 98% rename from src/ESISequence.h rename to src/esi/Sequence.h index f72d1e0f1a..9c5193cafb 100644 --- a/src/ESISequence.h +++ b/src/esi/Sequence.h @@ -37,8 +37,8 @@ #define SQUID_ESISEQUENCE_H #include "squid.h" -#include "ESIElement.h" -#include "ElementList.h" +#include "esi/Element.h" +#include "esi/ElementList.h" /* esiSequence */ diff --git a/src/ESIVar.h b/src/esi/Var.h similarity index 97% rename from src/ESIVar.h rename to src/esi/Var.h index bdff8c58f1..412414ced7 100644 --- a/src/ESIVar.h +++ b/src/esi/Var.h @@ -37,8 +37,8 @@ #define SQUID_ESIVAR_H #include "squid.h" -#include "ESIElement.h" -#include "ESISequence.h" +#include "esi/Element.h" +#include "esi/Sequence.h" /* esiVar */ diff --git a/src/ESIVarState.cc b/src/esi/VarState.cc similarity index 99% rename from src/ESIVarState.cc rename to src/esi/VarState.cc index be147a128d..8e7d5f9d91 100644 --- a/src/ESIVarState.cc +++ b/src/esi/VarState.cc @@ -35,7 +35,7 @@ */ #include "squid.h" -#include "ESIVarState.h" +#include "esi/VarState.h" #include "HttpReply.h" CBDATA_TYPE (ESIVarState); diff --git a/src/ESIVarState.h b/src/esi/VarState.h similarity index 99% rename from src/ESIVarState.h rename to src/esi/VarState.h index 66c34ecaac..ec66d45342 100644 --- a/src/ESIVarState.h +++ b/src/esi/VarState.h @@ -34,7 +34,7 @@ #ifndef SQUID_ESIVARSTATE_H #define SQUID_ESIVARSTATE_H -#include "ESISegment.h" +#include "esi/Segment.h" #include "Trie.h" #include "Array.h" #include "HttpHeader.h" diff --git a/src/main.cc b/src/main.cc index d02d90e0ab..09e17929d5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -86,6 +86,10 @@ #include "adaptation/Config.h" #endif +#if USE_SQUID_ESI +#include "esi/Module.h" +#endif + #if USE_WIN32_SERVICE #include "squid_windows.h" @@ -1061,6 +1065,9 @@ mainInitialize(void) Adaptation::Config::Finalize(enableAdaptation); #endif +#if USE_SQUID_ESI + Esi::Init(); +#endif debugs(1, 1, "Ready to serve requests."); @@ -1671,6 +1678,11 @@ SquidShutdown() releaseServerSockets(); commCloseAllSockets(); + +#if USE_SQUID_ESI + Esi::Clean(); +#endif + #if DELAY_POOLS DelayPools::FreePools(); diff --git a/test-suite/ESIExpressions.cc b/test-suite/ESIExpressions.cc index 182be9fc11..d7ccbf14eb 100644 --- a/test-suite/ESIExpressions.cc +++ b/test-suite/ESIExpressions.cc @@ -34,7 +34,7 @@ */ #include "squid.h" -#include "ESIExpression.h" +#include "esi/Expression.h" int main () diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index e9f5ddc854..2718487481 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -66,7 +66,7 @@ tcp_banger2_LDADD = -L$(top_builddir)/lib -lmiscutil DEBUG_SOURCE = test_tools.cc debug_SOURCES = debug.cc $(DEBUG_SOURCE) ESIExpressions_SOURCES = ESIExpressions.cc $(DEBUG_SOURCE) -ESIExpressions_LDADD = $(top_builddir)/src/ESIExpression.o \ +ESIExpressions_LDADD = $(top_builddir)/src/esi/Expression.o \ $(LDADD) mem_node_test_SOURCES = mem_node_test.cc mem_node_test_LDADD = $(top_builddir)/src/mem_node.o $(LDADD)