]> git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/Parser.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / esi / Parser.cc
1 /*
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 86 ESI processing */
10
11 #include "squid.h"
12 #include "esi/Parser.h"
13 #include "fatal.h"
14
15 char *ESIParser::Type = NULL;
16 ESIParser::Register *ESIParser::Parser = NULL;
17
18 std::list<ESIParser::Register *> &
19 ESIParser::GetRegistry()
20 {
21 static std::list<ESIParser::Register *> parsers;
22 return parsers;
23 }
24
25 ESIParser::Pointer
26 ESIParser::NewParser(ESIParserClient *aClient)
27 {
28 if (Parser == NULL) {
29 Parser = GetRegistry().front();
30
31 // if type name matters, use it
32 if (strcasecmp(Type, "auto") != 0) {
33 for (auto *p : GetRegistry()) {
34 if (p && strcasecmp(p->name, Type) != 0)
35 Parser = p;
36 }
37 }
38
39 if (Parser == NULL)
40 fatal ("Unknown ESI Parser type");
41 }
42
43 return (Parser->newParser)(aClient);
44 }
45
46 ESIParser::Register::Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient)) : name(_name), newParser(_newParser)
47 {
48 ESIParser::GetRegistry().emplace_back(this);
49 }
50
51 ESIParser::Register::~Register()
52 {
53 ESIParser::GetRegistry().remove(this);
54 }
55