]> git.ipfire.org Git - thirdparty/squid.git/blame - src/esi/Parser.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / esi / Parser.cc
CommitLineData
43ae1d95 1/*
77b1029d 2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
43ae1d95 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
43ae1d95 7 */
8
bbc27441
AJ
9/* DEBUG: section 86 ESI processing */
10
582c2af2 11#include "squid.h"
f99c2cfe 12#include "esi/Parser.h"
582c2af2 13#include "fatal.h"
43ae1d95 14
15char *ESIParser::Type = NULL;
dd2bdef3 16ESIParser::Register *ESIParser::Parser = NULL;
43ae1d95 17
57b6788e
AJ
18std::list<ESIParser::Register *> &
19ESIParser::GetRegistry()
20{
21 static std::list<ESIParser::Register *> parsers;
22 return parsers;
23}
24
43ae1d95 25ESIParser::Pointer
26ESIParser::NewParser(ESIParserClient *aClient)
27{
c2d4889f 28 if (Parser == NULL) {
57b6788e 29 Parser = GetRegistry().front();
964b44c3 30
799b66d1
AJ
31 // if type name matters, use it
32 if (strcasecmp(Type, "auto") != 0) {
57b6788e
AJ
33 for (auto *p : GetRegistry()) {
34 if (p && strcasecmp(p->name, Type) != 0)
35 Parser = p;
36 }
799b66d1 37 }
43ae1d95 38
c2d4889f 39 if (Parser == NULL)
40 fatal ("Unknown ESI Parser type");
41 }
43ae1d95 42
c2d4889f 43 return (Parser->newParser)(aClient);
43ae1d95 44}
7901db21 45
af6a12ee
AJ
46ESIParser::Register::Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient)) : name(_name), newParser(_newParser)
47{
57b6788e 48 ESIParser::GetRegistry().emplace_back(this);
7901db21
AR
49}
50
af6a12ee
AJ
51ESIParser::Register::~Register()
52{
57b6788e 53 ESIParser::GetRegistry().remove(this);
7901db21 54}
f53969cc 55