From 4f47959470b1222a454e5b8ccea57c710f590cbb Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Thu, 3 Feb 2022 03:09:07 +0000 Subject: [PATCH] Use RegisteredRunners to initialize/clean the ESI module (#965) --- src/esi/ExpatParser.cc | 22 ++++++++++++++++++ src/esi/Libxml2Parser.cc | 22 ++++++++++++++++++ src/esi/Makefile.am | 2 -- src/esi/Module.cc | 48 ---------------------------------------- src/esi/Module.h | 21 ------------------ src/main.cc | 11 --------- 6 files changed, 44 insertions(+), 82 deletions(-) delete mode 100644 src/esi/Module.cc delete mode 100644 src/esi/Module.h diff --git a/src/esi/ExpatParser.cc b/src/esi/ExpatParser.cc index a57c7ee9da..9826d5c5b9 100644 --- a/src/esi/ExpatParser.cc +++ b/src/esi/ExpatParser.cc @@ -12,8 +12,30 @@ #if USE_SQUID_ESI && HAVE_LIBEXPAT +#include "base/RunnersRegistry.h" #include "esi/ExpatParser.h" +#include + +namespace Esi +{ + +class ExpatRr : public RegisteredRunner +{ +public: + void finalizeConfig() + { + registration.reset(new ESIParser::Register("expat", &ESIExpatParser::NewParser)); + } + +private: + std::unique_ptr registration; +}; + +RunnerRegistrationEntry(ExpatRr); + +} + EsiParserDefinition(ESIExpatParser); ESIExpatParser::ESIExpatParser(ESIParserClient *aClient) : theClient (aClient) diff --git a/src/esi/Libxml2Parser.cc b/src/esi/Libxml2Parser.cc index 6c14c8c3a0..9a42144f4d 100644 --- a/src/esi/Libxml2Parser.cc +++ b/src/esi/Libxml2Parser.cc @@ -16,8 +16,30 @@ #if USE_SQUID_ESI && HAVE_LIBXML2 +#include "base/RunnersRegistry.h" #include "esi/Libxml2Parser.h" +#include + +namespace Esi +{ + +class Libxml2Rr : public RegisteredRunner +{ +public: + void finalizeConfig() + { + registration.reset(new ESIParser::Register("libxml2", &ESILibxml2Parser::NewParser)); + } + +private: + std::unique_ptr registration; +}; + +RunnerRegistrationEntry(Libxml2Rr); + +} + // the global document that will store the resolved entity // definitions static htmlDocPtr entity_doc = NULL; diff --git a/src/esi/Makefile.am b/src/esi/Makefile.am index eba97714fd..eb6ecd1798 100644 --- a/src/esi/Makefile.am +++ b/src/esi/Makefile.am @@ -40,8 +40,6 @@ libesi_la_SOURCES = \ Include.cc \ Include.h \ Literal.h \ - Module.cc \ - Module.h \ Parser.cc \ Parser.h \ Segment.cc \ diff --git a/src/esi/Module.cc b/src/esi/Module.cc deleted file mode 100644 index f5eeb4f168..0000000000 --- a/src/esi/Module.cc +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 1996-2021 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -#include "squid.h" -#include "esi/Libxml2Parser.h" -#include "esi/Module.h" -/* include for esi/ExpatParser.h must follow esi/Libxml2Parser.h */ -/* do not remove this comment, as it acts as barrier for the autmatic sorting */ -#include "esi/ExpatParser.h" - -#if HAVE_LIBXML2 -static ESIParser::Register *prLibxml = 0; -#endif -#if HAVE_LIBEXPAT -static ESIParser::Register *prExpat = 0; -#endif - -void Esi::Init() -{ -#if HAVE_LIBEXPAT - assert(!prExpat); // we should be called once - prExpat = new ESIParser::Register("expat", &ESIExpatParser::NewParser); -#endif - -#if HAVE_LIBXML2 - assert(!prLibxml); // we should be called once - prLibxml = new ESIParser::Register("libxml2", &ESILibxml2Parser::NewParser); -#endif -} - -void Esi::Clean() -{ -#if HAVE_LIBEXPAT - delete prExpat; - prExpat = NULL; -#endif - -#if HAVE_LIBXML2 - delete prLibxml; - prLibxml = NULL; -#endif -} - diff --git a/src/esi/Module.h b/src/esi/Module.h deleted file mode 100644 index 4d61cc278d..0000000000 --- a/src/esi/Module.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 1996-2021 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -#ifndef SQUID_ESI_MODULE_H -#define SQUID_ESI_MODULE_H - -namespace Esi -{ - -void Init(); -void Clean(); - -} // namespace Esi - -#endif /* SQUID_ESI_MODULE_H */ - diff --git a/src/main.cc b/src/main.cc index cceb2b40d9..fd995d543e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -117,9 +117,6 @@ #if USE_ADAPTATION #include "adaptation/Config.h" #endif -#if USE_SQUID_ESI -#include "esi/Module.h" -#endif #if SQUID_SNMP #include "snmp_core.h" #endif @@ -1313,10 +1310,6 @@ mainInitialize(void) Adaptation::Config::Finalize(enableAdaptation); #endif -#if USE_SQUID_ESI - Esi::Init(); -#endif - #if USE_DELAY_POOLS Config.ClientDelay.finalize(); #endif @@ -2094,10 +2087,6 @@ SquidShutdown() releaseServerSockets(); commCloseAllSockets(); -#if USE_SQUID_ESI - Esi::Clean(); -#endif - #if USE_DELAY_POOLS DelayPools::FreePools(); #endif -- 2.47.2