]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHdrScTarget.cc
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / HttpHdrScTarget.cc
1
2 /*
3 * $Id$
4 *
5 * DEBUG: section 90 HTTP Cache Control Header
6 * AUTHOR: Alex Rousskov
7 * Robert Collins (Surrogate-Control is derived from
8 * Cache-Control).
9 *
10 * SQUID Web Proxy Cache http://www.squid-cache.org/
11 * ----------------------------------------------------------
12 *
13 * Squid is the result of efforts by numerous individuals from
14 * the Internet community; see the CONTRIBUTORS file for full
15 * details. Many organizations have provided support for Squid's
16 * development; see the SPONSORS file for full details. Squid is
17 * Copyrighted (C) 2001 by the Regents of the University of
18 * California; see the COPYRIGHT file for full details. Squid
19 * incorporates software developed and/or copyrighted by other
20 * sources; see the CREDITS file for full details.
21 *
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
35 *
36 */
37
38 #include "squid.h"
39 #include "HttpHdrSc.h"
40
41 /* local prototypes */
42
43 /* module initialization */
44
45 /* implementation */
46
47 HttpHdrScTarget *
48 httpHdrScTargetCreate(char const *target)
49 {
50 HttpHdrScTarget *sc = new HttpHdrScTarget();
51 sc->max_age = -1;
52 /* max_stale is specified as 0 if not specified in the header */
53 sc->target = target;
54 return sc;
55 }
56
57 void
58 httpHdrScTargetDestroy(HttpHdrScTarget * sc)
59 {
60 assert(sc);
61 sc->target.clean();
62 sc->content.clean();
63 delete sc;
64 }
65
66 HttpHdrScTarget *
67 httpHdrScTargetDup(const HttpHdrScTarget * sc)
68 {
69 HttpHdrScTarget *dup;
70 assert(sc);
71 dup = httpHdrScTargetCreate(sc->target.buf());
72 dup->mask = sc->mask;
73 dup->max_age = sc->max_age;
74 dup->content = sc->content;
75 return dup;
76 }
77
78 /* union of two targets */
79 void
80 httpHdrScTargetJoinWith(HttpHdrScTarget * sc, const HttpHdrScTarget * new_sc)
81 {
82 assert(sc && new_sc);
83 /* TODO: check both targets are the same */
84
85 if (sc->max_age < 0)
86 sc->max_age = new_sc->max_age;
87
88 if (sc->max_stale < new_sc->max_stale)
89 sc->max_stale = new_sc->max_stale;
90
91 /* RC TODO: copy unique missing content stringlist entries */
92 sc->mask |= new_sc->mask;
93 }
94
95 extern http_hdr_sc_type &operator++ (http_hdr_sc_type &aHeader);
96 extern int operator - (http_hdr_sc_type const &anSc, http_hdr_sc_type const &anSc2);
97 /* copies non-extant fields from new_sc to this sc */
98 void
99 httpHdrScTargetMergeWith(HttpHdrScTarget * sc, const HttpHdrScTarget * new_sc)
100 {
101 http_hdr_sc_type c;
102 assert(sc && new_sc);
103 /* Don't touch the target - this is used to get the operations for a
104 * single surrogate
105 */
106
107 for (c = SC_NO_STORE; c < SC_ENUM_END; ++c)
108 if (!EBIT_TEST(sc->mask, c) && EBIT_TEST(new_sc->mask,c)) {
109 EBIT_SET(sc->mask, c);
110
111 switch (c) {
112
113 case SC_MAX_AGE:
114 sc->max_age = new_sc->max_age;
115 sc->max_stale = new_sc->max_stale;
116 break;
117
118 case SC_CONTENT:
119 assert (sc->content.size() == 0);
120 sc->content = new_sc->content;
121 break;
122
123 default:
124 break;
125 }
126 }
127 }
128
129 /* negative max_age will clean old max_Age setting */
130 void
131 httpHdrScTargetSetMaxAge(HttpHdrScTarget * sc, int max_age)
132 {
133 assert(sc);
134 sc->max_age = max_age;
135
136 if (max_age >= 0)
137 EBIT_SET(sc->mask, SC_MAX_AGE);
138 else
139 EBIT_CLR(sc->mask, SC_MAX_AGE);
140 }
141
142 void
143 httpHdrScTargetUpdateStats(const HttpHdrScTarget * sc, StatHist * hist)
144 {
145 http_hdr_sc_type c;
146 assert(sc);
147
148 for (c = SC_NO_STORE; c < SC_ENUM_END; ++c)
149 if (EBIT_TEST(sc->mask, c))
150 statHistCount(hist, c);
151 }