/*
- * $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
Trie *ESICustomParser::SearchTrie=NULL;
+RegisterESIParser("custom", ESICustomParser);
+
Trie *
ESICustomParser::GetTrie()
{
/*
- * $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/
char const * errorString() const;
private:
+ ESI_PARSER_TYPE;
static Trie *SearchTrie;
static Trie *GetTrie();
enum ESITAG_t {
/*
- * $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
#include "squid.h"
#include "ESIExpatParser.h"
+RegisterESIParser("expat", ESIExpatParser);
+
ESIExpatParser::ESIExpatParser(ESIParserClient *aClient) : theClient (aClient)
{
/* TODO: grab the document encoding from the headers */
/*
- * $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/
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);
/*
- * $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)
*
// definitions
static htmlDocPtr entity_doc = NULL;
+RegisterESIParser("libxml2", ESILibxml2Parser);
+
// the SAX callback functions
void esi_startElementSAXFunc(void * ctx, const xmlChar * name, const xmlChar ** atts)
{
/*
- * $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)
*
ESIParserClient *getClient() { return theClient; }
private:
+ ESI_PARSER_TYPE;
mutable xmlParserCtxtPtr parser; /* our parser */
ESIParserClient *theClient;
/*
- * $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);
}
/*
- * $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/
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 */
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 */