]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHeaderRange.h
SourceLayout: rename Array.h to base/Vector.h
[thirdparty/squid.git] / src / HttpHeaderRange.h
1
2 /*
3 *
4 * SQUID Web Proxy Cache http://www.squid-cache.org/
5 * ----------------------------------------------------------
6 *
7 * Squid is the result of efforts by numerous individuals from
8 * the Internet community; see the CONTRIBUTORS file for full
9 * details. Many organizations have provided support for Squid's
10 * development; see the SPONSORS file for full details. Squid is
11 * Copyrighted (C) 2001 by the Regents of the University of
12 * California; see the COPYRIGHT file for full details. Squid
13 * incorporates software developed and/or copyrighted by other
14 * sources; see the CREDITS file for full details.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
29 *
30 */
31
32 #ifndef SQUID_HTTPHEADERRANGE_H
33 #define SQUID_HTTPHEADERRANGE_H
34
35 #include "base/Vector.h"
36 #include "MemPool.h"
37 #include "Packer.h"
38 #include "Range.h"
39 #include "SquidString.h"
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 Vector<HttpHdrRangeSpec *>::iterator iterator;
87 typedef 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 Vector<HttpHdrRangeSpec *> specs;
107
108 private:
109 void getCanonizedSpecs (Vector<HttpHdrRangeSpec *> &copy);
110 void merge (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 const HttpHdrRangeSpec *currentSpec() const;
125 void updateSpec();
126 int64_t debt() const;
127 void debt(int64_t);
128 int64_t debt_size; /* bytes left to send from the current spec */
129 String boundary; /* boundary for multipart responses */
130 bool valid;
131 };
132
133 #endif /* SQUID_HTTPHEADERRANGE_H */