void Esi::Init()
{
- // register in reverse order of preference.
- // The latest registered parser will be used as default.
#if HAVE_LIBEXPAT
assert(!prExpat); // we should be called once
prExpat = new ESIParser::Register("expat", &ESIExpatParser::NewParser);
/* DEBUG: section 86 ESI processing */
#include "squid.h"
+#include "Debug.h"
#include "esi/Parser.h"
#include "fatal.h"
ESIParser::Pointer
ESIParser::NewParser(ESIParserClient *aClient)
{
- if (Parser == NULL) {
- Parser = GetRegistry().front();
-
- // if type name matters, use it
- if (strcasecmp(Type, "auto") != 0) {
- for (auto *p : GetRegistry()) {
- if (p && strcasecmp(p->name, Type) != 0)
- Parser = p;
- }
+ if (!Parser) {
+ // if esi_parser is configured, use that
+ const char *selectParserName = Type;
+ if (!selectParserName || strcasecmp(selectParserName, "auto") == 0) {
+#if HAVE_LIBXML2
+ // libxml2 is the more secure. prefer when possible
+ selectParserName = "libxml2";
+#else
+ // expat is more widely available
+ selectParserName = "expat";
+#endif
}
- if (Parser == NULL)
- fatal ("Unknown ESI Parser type");
+ for (auto *p : GetRegistry()) {
+ if (p && strcasecmp(p->name, selectParserName) == 0)
+ Parser = p;
+ }
+
+ if (!Parser)
+ fatalf("Unknown ESI Parser type '%s'", selectParserName);
+ debugs(86, 2, "selected ESI parser: " << Parser->name);
}
return (Parser->newParser)(aClient);