]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
528b2c61 | 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. | |
26ac0430 | 19 | * |
528b2c61 | 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. | |
26ac0430 | 24 | * |
528b2c61 | 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 | ||
71b673d4 | 34 | #include "MemPool.h" |
25b6a907 | 35 | #include "Packer.h" |
71b673d4 | 36 | #include "Range.h" |
25b6a907 | 37 | #include "SquidString.h" |
528b2c61 | 38 | |
b7347197 FC |
39 | #include <vector> |
40 | ||
0353e724 | 41 | class HttpReply; |
528b2c61 | 42 | /* http byte-range-spec */ |
62e76326 | 43 | |
44 | class HttpHdrRangeSpec | |
45 | { | |
46 | ||
47 | public: | |
b001e822 | 48 | MEMPROXY_CLASS(HttpHdrRangeSpec); |
c16f948b | 49 | typedef Range<int64_t, uint64_t> HttpRange; |
47f6e231 | 50 | static int64_t const UnknownPosition; |
62e76326 | 51 | |
528b2c61 | 52 | HttpHdrRangeSpec(); |
53 | static HttpHdrRangeSpec *Create(const char *field, int fieldLen); | |
54 | ||
55 | bool parseInit(const char *field, int flen); | |
47f6e231 | 56 | int canonize(int64_t clen); |
528b2c61 | 57 | void outputInfo( char const *note) const; |
58 | void packInto(Packer * p) const; | |
59 | bool mergeWith(const HttpHdrRangeSpec * donor); | |
47f6e231 | 60 | int64_t offset; |
61 | int64_t length; | |
528b2c61 | 62 | }; |
63 | ||
d85b8894 | 64 | MEMPROXY_CLASS_INLINE(HttpHdrRangeSpec); |
b001e822 | 65 | |
63be0a78 | 66 | /** |
67 | * There may be more than one byte range specified in the request. | |
528b2c61 | 68 | * This object holds all range specs in order of their appearence |
69 | * in the request because we SHOULD preserve that order. | |
70 | */ | |
62e76326 | 71 | class HttpHdrRange |
72 | { | |
73 | ||
528b2c61 | 74 | public: |
b001e822 | 75 | MEMPROXY_CLASS(HttpHdrRange); |
528b2c61 | 76 | |
77 | static size_t ParsedCount; | |
78 | /* Http Range Header Field */ | |
30abd221 | 79 | static HttpHdrRange *ParseCreate(const String * range_spec); |
528b2c61 | 80 | |
81 | HttpHdrRange(); | |
82 | HttpHdrRange(HttpHdrRange const &); | |
83 | ~HttpHdrRange(); | |
84 | HttpHdrRange &operator= (HttpHdrRange const &); | |
85 | ||
24a8eaae FC |
86 | typedef std::vector<HttpHdrRangeSpec *>::iterator iterator; |
87 | typedef std::vector<HttpHdrRangeSpec *>::const_iterator const_iterator; | |
528b2c61 | 88 | iterator begin(); |
89 | const_iterator begin () const; | |
90 | iterator end(); | |
91 | const_iterator end() const; | |
62e76326 | 92 | |
528b2c61 | 93 | /* adjust specs after the length is known */ |
47f6e231 | 94 | int canonize(int64_t); |
528b2c61 | 95 | int canonize(HttpReply *rep); |
96 | /* returns true if ranges are valid; inits HttpHdrRange */ | |
30abd221 | 97 | bool parseInit(const String * range_spec); |
528b2c61 | 98 | void packInto(Packer * p) const; |
99 | /* other */ | |
100 | bool isComplex() const; | |
101 | bool willBeComplex() const; | |
47f6e231 | 102 | int64_t firstOffset() const; |
103 | int64_t lowestOffset(int64_t) const; | |
11e3fa1c | 104 | bool offsetLimitExceeded(const int64_t limit) const; |
fedd1531 | 105 | bool contains(HttpHdrRangeSpec& r) const; |
24a8eaae | 106 | std::vector<HttpHdrRangeSpec *> specs; |
62e76326 | 107 | |
528b2c61 | 108 | private: |
24a8eaae FC |
109 | void getCanonizedSpecs (std::vector<HttpHdrRangeSpec *> ©); |
110 | void merge (std::vector<HttpHdrRangeSpec *> &basis); | |
47f6e231 | 111 | int64_t clen; |
528b2c61 | 112 | }; |
113 | ||
d85b8894 | 114 | MEMPROXY_CLASS_INLINE(HttpHdrRange); |
62e76326 | 115 | |
63be0a78 | 116 | /** |
117 | * Data for iterating thru range specs | |
118 | */ | |
62e76326 | 119 | class HttpHdrRangeIter |
120 | { | |
121 | ||
122 | public: | |
528b2c61 | 123 | HttpHdrRange::iterator pos; |
24a8eaae | 124 | HttpHdrRange::iterator end; |
528b2c61 | 125 | const HttpHdrRangeSpec *currentSpec() const; |
126 | void updateSpec(); | |
47f6e231 | 127 | int64_t debt() const; |
128 | void debt(int64_t); | |
129 | int64_t debt_size; /* bytes left to send from the current spec */ | |
30abd221 | 130 | String boundary; /* boundary for multipart responses */ |
528b2c61 | 131 | bool valid; |
132 | }; | |
62e76326 | 133 | |
528b2c61 | 134 | #endif /* SQUID_HTTPHEADERRANGE_H */ |