]> git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/Element.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / esi / Element.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_ESIELEMENT_H
10 #define SQUID_ESIELEMENT_H
11
12 #include "base/RefCount.h"
13 #include "Debug.h"
14 #include "esi/Segment.h"
15
16 typedef enum {
17 ESI_PROCESS_COMPLETE = 0,
18 ESI_PROCESS_PENDING_WONTFAIL = 1,
19 ESI_PROCESS_PENDING_MAYFAIL = 2,
20 ESI_PROCESS_FAILED = 3
21 } esiProcessResult_t;
22
23 class ESIElement;
24
25 struct esiTreeParent : public RefCountable {
26 virtual void provideData (ESISegment::Pointer data, ESIElement * source) {
27 /* make abstract when all functionality complete */
28 assert (0);
29 }
30
31 virtual void fail(ESIElement * source, char const *reason = NULL) {}
32
33 virtual ~esiTreeParent() {}
34 };
35
36 typedef RefCount<esiTreeParent> esiTreeParentPtr;
37
38 class ESIVarState;
39
40 class ESIElement : public esiTreeParent
41 {
42
43 public:
44 typedef RefCount<ESIElement> Pointer;
45
46 /* the types we have */
47 enum ESIElementType_t {
48 ESI_ELEMENT_NONE,
49 ESI_ELEMENT_INCLUDE,
50 ESI_ELEMENT_COMMENT,
51 ESI_ELEMENT_REMOVE,
52 ESI_ELEMENT_TRY,
53 ESI_ELEMENT_ATTEMPT,
54 ESI_ELEMENT_EXCEPT,
55 ESI_ELEMENT_VARS,
56 ESI_ELEMENT_CHOOSE,
57 ESI_ELEMENT_WHEN,
58 ESI_ELEMENT_OTHERWISE,
59 ESI_ELEMENT_ASSIGN
60 };
61 static ESIElementType_t IdentifyElement (const char *);
62 virtual bool addElement(ESIElement::Pointer) {
63 /* Don't accept children */
64 debugs(86,5, "ESIElement::addElement: Failed for " << this);
65 return false;
66 }
67
68 virtual void render (ESISegment::Pointer) = 0;
69 /* process this element */
70 virtual esiProcessResult_t process (int dovars) {
71 debugs(86,5, "esiProcessComplete: Processed " << this);
72 return ESI_PROCESS_COMPLETE;
73 }
74
75 virtual bool mayFail() const {
76 return true;
77 }
78
79 virtual Pointer makeCacheable() const = 0;
80 virtual Pointer makeUsable(esiTreeParentPtr, ESIVarState &) const = 0;
81
82 /* The top level no longer needs this element */
83 virtual void finish() = 0;
84 };
85
86 #endif /* SQUID_ESIELEMENT_H */
87