]> git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/Parser.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / esi / Parser.h
1 /*
2 * Copyright (C) 1996-2017 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 #ifndef SQUID_ESIPARSER_H
10 #define SQUID_ESIPARSER_H
11
12 class ESIParserClient
13 {
14 public:
15 virtual void start(const char *el, const char **attr, size_t attrCount) = 0;
16 virtual void end(const char *el) = 0;
17 virtual void parserDefault (const char *s, int len) =0;
18 virtual void parserComment (const char *s) = 0;
19 virtual ~ESIParserClient() {};
20 };
21
22 #include "base/RefCount.h"
23
24 class ESIParser : public RefCountable
25 {
26 public:
27 class Register;
28 typedef RefCount<ESIParser> Pointer;
29
30 static void registerParser(const char *name, Pointer (*new_func)(ESIParserClient *aClient));
31 static Pointer NewParser(ESIParserClient *aClient);
32 static char *Type;
33
34 /**
35 \retval true on success
36 \retval false on what?
37 */
38 virtual bool parse(char const *dataToParse, size_t const lengthOfData, bool const endOfStream) = 0;
39
40 virtual long int lineNumber() const =0;
41 virtual char const * errorString() const =0;
42
43 protected:
44 ESIParser() {};
45
46 private:
47 static Register *Parser;
48 static Register *Parsers;
49
50 public:
51 };
52
53 class ESIParser::Register
54 {
55
56 public:
57 Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient));
58 ~Register();
59
60 const char *name;
61 ESIParser::Pointer (*newParser)(ESIParserClient *aClient);
62 Register * next;
63 };
64
65 #define EsiParserDefinition(ThisClass) \
66 ESIParser::Pointer ThisClass::NewParser(ESIParserClient *aClient) \
67 { \
68 return new ThisClass (aClient); \
69 }
70
71 #define EsiParserDeclaration \
72 static ESIParser::Pointer NewParser(ESIParserClient *aClient)
73
74 #endif /* SQUID_ESIPARSER_H */
75