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