]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Crude implementation of ESIParser registry, making ESIParser.cc
authorhno <>
Tue, 29 Mar 2005 04:44:12 +0000 (04:44 +0000)
committerhno <>
Tue, 29 Mar 2005 04:44:12 +0000 (04:44 +0000)
independent of the available parsers, indirectly solving the
libxml2/expat conflict and preparing for easy buildtime selection of the
available parsers.

src/ESICustomParser.cc
src/ESICustomParser.h
src/ESIExpatParser.cc
src/ESIExpatParser.h
src/ESILibxml2Parser.cc
src/ESILibxml2Parser.h
src/ESIParser.cc
src/ESIParser.h

index 35d49051e51cf80759c80d819ae5a33adf6f6a16..3e98703759c2383a395c45053d5fd8df8498937a 100644 (file)
@@ -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()
 {
index 30af6c298d621359acb494433303715f279b26f5..d3de62157512177fa4c166811e53152b21fdc21f 100644 (file)
@@ -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 {
index b9cb7953d82fcb29dd253fe7741b138924fbe06a..71b46c7369b33fac3a0344d8ecc863903c4640b1 100644 (file)
@@ -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 */
index 67c091bc56c1d77de9c1bea4350c9ed3881d7ebe..5be5f8181532c0600deb998a674458a17048c2d8 100644 (file)
@@ -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);
index 293d41426dd6e7c834d14e15ff4e47046d2c8a09..f32c330371dd2c383befd7afa65e5e05c7a2c036 100644 (file)
@@ -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)
 {
index b1b7094953f49c2bc4e2a56b439e053eaaab240f..6a4bef56913b7d73ecfd4ecd4d5bc6c4dd4282b6 100644 (file)
@@ -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;
index 10e59567408b07ef9a3ad5a586b921b6f9e7c2b0..ed7c90bfce4e55db28b8371e9eeb209bf012a9f0 100644 (file)
@@ -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
 
 #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);
 }
index e965f0e86901f4567fc0ee932980ba69448f3d19..9ee17a95a5e56ccd88930dcbfe1d48dafd824ad2 100644 (file)
@@ -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<ESIParser> 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 */