]> git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/Context.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / esi / Context.cc
1 /*
2 * Copyright (C) 1996-2020 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
13 /* MS Visual Studio Projects are monolithic, so we need the following
14 * #if to exclude the ESI code from compile process when not needed.
15 */
16 #if (USE_SQUID_ESI == 1)
17
18 #include "client_side_request.h"
19 #include "esi/Context.h"
20 #include "http/Stream.h"
21 #include "Store.h"
22
23 void
24 ESIContext::updateCachedAST()
25 {
26 assert (http);
27 assert (http->storeEntry());
28
29 if (hasCachedAST()) {
30 debugs(86, 5, "ESIContext::updateCachedAST: not updating AST cache for entry " <<
31 http->storeEntry() << " from ESI Context " << this <<
32 " as there is already a cached AST.");
33
34 return;
35 }
36
37 ESIElement::Pointer treeToCache = tree->makeCacheable();
38 debugs(86, 5, "ESIContext::updateCachedAST: Updating AST cache for entry " <<
39 http->storeEntry() << " with current value " <<
40 http->storeEntry()->cachedESITree.getRaw() << " to new value " <<
41 treeToCache.getRaw());
42
43 if (http->storeEntry()->cachedESITree.getRaw())
44 http->storeEntry()->cachedESITree->finish();
45
46 http->storeEntry()->cachedESITree = treeToCache;
47
48 treeToCache = NULL;
49 }
50
51 bool
52 ESIContext::hasCachedAST() const
53 {
54 assert (http);
55 assert (http->storeEntry());
56
57 if (http->storeEntry()->cachedESITree.getRaw()) {
58 debugs(86, 5, "ESIContext::hasCachedAST: " << this <<
59 " - Cached AST present in store entry " << http->storeEntry() << ".");
60 return true;
61 } else {
62 debugs(86, 5, "ESIContext::hasCachedAST: " << this <<
63 " - Cached AST not present in store entry " << http->storeEntry() << ".");
64 return false;
65 }
66 }
67
68 void
69 ESIContext::getCachedAST()
70 {
71 if (cachedASTInUse)
72 return;
73
74 assert (hasCachedAST());
75
76 assert (varState);
77
78 parserState.popAll();
79
80 tree = http->storeEntry()->cachedESITree->makeUsable (this, *varState);
81
82 cachedASTInUse = true;
83 }
84
85 void
86 ESIContext::setErrorMessage(char const *anError)
87 {
88 if (!errormessage)
89 errormessage = xstrdup(anError);
90 }
91
92 #endif /* USE_SQUID_ESI == 1 */
93