]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHeaderRange.h
merge from trunk
[thirdparty/squid.git] / src / HttpHeaderRange.h
1 /*
2 *
3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
5 *
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
28 *
29 */
30
31 #ifndef SQUID_HTTPHEADERRANGE_H
32 #define SQUID_HTTPHEADERRANGE_H
33
34 #include "MemPool.h"
35 #include "Packer.h"
36 #include "Range.h"
37 #include "SquidString.h"
38
39 #include <vector>
40
41 class HttpReply;
42 /* http byte-range-spec */
43
44 class HttpHdrRangeSpec
45 {
46
47 public:
48 MEMPROXY_CLASS(HttpHdrRangeSpec);
49 typedef Range<int64_t, uint64_t> HttpRange;
50 static int64_t const UnknownPosition;
51
52 HttpHdrRangeSpec();
53 static HttpHdrRangeSpec *Create(const char *field, int fieldLen);
54
55 bool parseInit(const char *field, int flen);
56 int canonize(int64_t clen);
57 void outputInfo( char const *note) const;
58 void packInto(Packer * p) const;
59 bool mergeWith(const HttpHdrRangeSpec * donor);
60 int64_t offset;
61 int64_t length;
62 };
63
64 MEMPROXY_CLASS_INLINE(HttpHdrRangeSpec);
65
66 /**
67 * There may be more than one byte range specified in the request.
68 * This object holds all range specs in order of their appearence
69 * in the request because we SHOULD preserve that order.
70 */
71 class HttpHdrRange
72 {
73
74 public:
75 MEMPROXY_CLASS(HttpHdrRange);
76
77 static size_t ParsedCount;
78 /* Http Range Header Field */
79 static HttpHdrRange *ParseCreate(const String * range_spec);
80
81 HttpHdrRange();
82 HttpHdrRange(HttpHdrRange const &);
83 ~HttpHdrRange();
84 HttpHdrRange &operator= (HttpHdrRange const &);
85
86 typedef std::vector<HttpHdrRangeSpec *>::iterator iterator;
87 typedef std::vector<HttpHdrRangeSpec *>::const_iterator const_iterator;
88 iterator begin();
89 const_iterator begin () const;
90 iterator end();
91 const_iterator end() const;
92
93 /* adjust specs after the length is known */
94 int canonize(int64_t);
95 int canonize(HttpReply *rep);
96 /* returns true if ranges are valid; inits HttpHdrRange */
97 bool parseInit(const String * range_spec);
98 void packInto(Packer * p) const;
99 /* other */
100 bool isComplex() const;
101 bool willBeComplex() const;
102 int64_t firstOffset() const;
103 int64_t lowestOffset(int64_t) const;
104 bool offsetLimitExceeded(const int64_t limit) const;
105 bool contains(HttpHdrRangeSpec& r) const;
106 std::vector<HttpHdrRangeSpec *> specs;
107
108 private:
109 void getCanonizedSpecs (std::vector<HttpHdrRangeSpec *> &copy);
110 void merge (std::vector<HttpHdrRangeSpec *> &basis);
111 int64_t clen;
112 };
113
114 MEMPROXY_CLASS_INLINE(HttpHdrRange);
115
116 /**
117 * Data for iterating thru range specs
118 */
119 class HttpHdrRangeIter
120 {
121
122 public:
123 HttpHdrRange::iterator pos;
124 HttpHdrRange::iterator end;
125 const HttpHdrRangeSpec *currentSpec() const;
126 void updateSpec();
127 int64_t debt() const;
128 void debt(int64_t);
129 int64_t debt_size; /* bytes left to send from the current spec */
130 String boundary; /* boundary for multipart responses */
131 bool valid;
132 };
133
134 #endif /* SQUID_HTTPHEADERRANGE_H */