From: hno <> Date: Tue, 29 Mar 2005 04:44:12 +0000 (+0000) Subject: Crude implementation of ESIParser registry, making ESIParser.cc X-Git-Tag: SQUID_3_0_PRE4~821 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2d4889f56b87a1205ffe09cb1c6146d5cc56bdf;p=thirdparty%2Fsquid.git Crude implementation of ESIParser registry, making ESIParser.cc independent of the available parsers, indirectly solving the libxml2/expat conflict and preparing for easy buildtime selection of the available parsers. --- diff --git a/src/ESICustomParser.cc b/src/ESICustomParser.cc index 35d49051e5..3e98703759 100644 --- a/src/ESICustomParser.cc +++ b/src/ESICustomParser.cc @@ -1,6 +1,6 @@ /* - * $Id: ESICustomParser.cc,v 1.5 2005/01/06 13:16:38 serassio Exp $ + * $Id: ESICustomParser.cc,v 1.6 2005/03/28 21:44:12 hno Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -41,6 +41,8 @@ Trie *ESICustomParser::SearchTrie=NULL; +RegisterESIParser("custom", ESICustomParser); + Trie * ESICustomParser::GetTrie() { diff --git a/src/ESICustomParser.h b/src/ESICustomParser.h index 30af6c298d..d3de621575 100644 --- a/src/ESICustomParser.h +++ b/src/ESICustomParser.h @@ -1,5 +1,5 @@ /* - * $Id: ESICustomParser.h,v 1.4 2003/08/04 22:14:40 robertc Exp $ + * $Id: ESICustomParser.h,v 1.5 2005/03/28 21:44:12 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -49,6 +49,7 @@ public: char const * errorString() const; private: + ESI_PARSER_TYPE; static Trie *SearchTrie; static Trie *GetTrie(); enum ESITAG_t { diff --git a/src/ESIExpatParser.cc b/src/ESIExpatParser.cc index b9cb7953d8..71b46c7369 100644 --- a/src/ESIExpatParser.cc +++ b/src/ESIExpatParser.cc @@ -1,6 +1,6 @@ /* - * $Id: ESIExpatParser.cc,v 1.2 2003/08/04 22:14:40 robertc Exp $ + * $Id: ESIExpatParser.cc,v 1.3 2005/03/28 21:44:12 hno Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -36,6 +36,8 @@ #include "squid.h" #include "ESIExpatParser.h" +RegisterESIParser("expat", ESIExpatParser); + ESIExpatParser::ESIExpatParser(ESIParserClient *aClient) : theClient (aClient) { /* TODO: grab the document encoding from the headers */ diff --git a/src/ESIExpatParser.h b/src/ESIExpatParser.h index 67c091bc56..5be5f81815 100644 --- a/src/ESIExpatParser.h +++ b/src/ESIExpatParser.h @@ -1,5 +1,5 @@ /* - * $Id: ESIExpatParser.h,v 1.2 2003/08/04 22:14:40 robertc Exp $ + * $Id: ESIExpatParser.h,v 1.3 2005/03/28 21:44:12 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -48,6 +48,7 @@ public: char const * errorString() const; private: + ESI_PARSER_TYPE; mutable XML_Parser p; /* our parser */ static void Start(void *data, const char *el, const char **attr); static void End(void *data, const char *el); diff --git a/src/ESILibxml2Parser.cc b/src/ESILibxml2Parser.cc index 293d41426d..f32c330371 100644 --- a/src/ESILibxml2Parser.cc +++ b/src/ESILibxml2Parser.cc @@ -1,5 +1,5 @@ /* - * $Id: ESILibxml2Parser.cc,v 1.1 2004/12/10 00:49:53 hno Exp $ + * $Id: ESILibxml2Parser.cc,v 1.2 2005/03/28 21:44:12 hno Exp $ * * AUTHOR: Joachim Bauch (mail@joachim-bauch.de) * @@ -51,6 +51,8 @@ // definitions static htmlDocPtr entity_doc = NULL; +RegisterESIParser("libxml2", ESILibxml2Parser); + // the SAX callback functions void esi_startElementSAXFunc(void * ctx, const xmlChar * name, const xmlChar ** atts) { diff --git a/src/ESILibxml2Parser.h b/src/ESILibxml2Parser.h index b1b7094953..6a4bef5691 100644 --- a/src/ESILibxml2Parser.h +++ b/src/ESILibxml2Parser.h @@ -1,5 +1,5 @@ /* - * $Id: ESILibxml2Parser.h,v 1.1 2004/12/10 00:49:53 hno Exp $ + * $Id: ESILibxml2Parser.h,v 1.2 2005/03/28 21:44:12 hno Exp $ * * AUTHOR: Joachim Bauch (mail@joachim-bauch.de) * @@ -69,6 +69,7 @@ public: ESIParserClient *getClient() { return theClient; } private: + ESI_PARSER_TYPE; mutable xmlParserCtxtPtr parser; /* our parser */ ESIParserClient *theClient; diff --git a/src/ESIParser.cc b/src/ESIParser.cc index 10e5956740..ed7c90bfce 100644 --- a/src/ESIParser.cc +++ b/src/ESIParser.cc @@ -1,6 +1,6 @@ /* - * $Id: ESIParser.cc,v 1.5 2005/03/19 19:56:15 serassio Exp $ + * $Id: ESIParser.cc,v 1.6 2005/03/28 21:44:12 hno Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -35,25 +35,22 @@ #include "squid.h" #include "ESIParser.h" -#include "ESILibxml2Parser.h" -#include "ESIExpatParser.h" -#include "ESICustomParser.h" char *ESIParser::Type = NULL; +ESIParser::Register *ESIParser::Parsers = NULL; ESIParser::Pointer ESIParser::NewParser(ESIParserClient *aClient) { - if (!strcasecmp("libxml2", Type)) - return new ESILibxml2Parser (aClient); + if (Parser == NULL) { + Parser = Parsers; - if (!strcasecmp("expat", Type)) - return new ESIExpatParser (aClient); + while (Parser != NULL && strcasecmp(Parser->name, Type) != 0) + Parser = Parser->next; - if (!strcasecmp("custom", Type)) - return new ESICustomParser (aClient); + if (Parser == NULL) + fatal ("Unknown ESI Parser type"); + } - fatal ("Unknown ESI Parser type"); - - return NULL; + return (Parser->newParser)(aClient); } diff --git a/src/ESIParser.h b/src/ESIParser.h index e965f0e869..9ee17a95a5 100644 --- a/src/ESIParser.h +++ b/src/ESIParser.h @@ -1,5 +1,5 @@ /* - * $Id: ESIParser.h,v 1.2 2003/08/04 22:14:40 robertc Exp $ + * $Id: ESIParser.h,v 1.3 2005/03/28 21:44:12 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -48,6 +48,7 @@ class ESIParser : public RefCountable public: typedef RefCount Pointer; + static void registerParser(const char *name, Pointer (*new_func)(ESIParserClient *aClient)); static Pointer NewParser(ESIParserClient *aClient); static char *Type; /* true on success */ @@ -58,7 +59,38 @@ public: protected: ESIParser(){}; + class Register; + private: + static Register *Parser; + static Register *Parsers; + +public: +}; + +class ESIParser::Register +{ + +public: + Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient)) : name(_name), newParser(_newParser) + { + this->next = ESIParser::Parsers; + ESIParser::Parsers = this; + } + + const char *name; + ESIParser::Pointer (*newParser)(ESIParserClient *aClient); + Register * next; }; +#define RegisterESIParser(name, ThisClass) \ + ESIParser::Register ThisClass::thisParser(name, &NewParser); \ + ESIParser::Pointer ThisClass::NewParser(ESIParserClient *aClient) \ + { \ + return new ThisClass (aClient); \ + } + +#define ESI_PARSER_TYPE \ + static ESIParser::Pointer NewParser(ESIParserClient *aClient); \ + static ESIParser::Register thisParser #endif /* SQUID_ESIPARSER_H */