]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpHeaderRange.h
Summary: Merge cleanup code from comms branch.
[thirdparty/squid.git] / src / HttpHeaderRange.h
CommitLineData
528b2c61 1
2/*
62e76326 3 * $Id: HttpHeaderRange.h,v 1.2 2003/02/21 22:50:05 robertc Exp $
528b2c61 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 "Range.h"
38
39typedef struct _HttpReply HttpReply;
40/* http byte-range-spec */
62e76326 41
42class HttpHdrRangeSpec
43{
44
45public:
528b2c61 46 void *operator new(size_t);
47 void operator delete (void *);
48 void deleteSelf() const;
49 typedef Range<ssize_t> HttpRange;
50 static ssize_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);
56 int canonize(size_t clen);
57 void outputInfo( char const *note) const;
58 void packInto(Packer * p) const;
59 bool mergeWith(const HttpHdrRangeSpec * donor);
60 ssize_t offset;
61 ssize_t length;
62e76326 62
528b2c61 63private:
64 static MemPool *Pool;
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 */
62e76326 71
72class HttpHdrRange
73{
74
528b2c61 75public:
76 void *operator new(size_t);
77 void operator delete (void *);
78 void deleteSelf() const;
79
80 static size_t ParsedCount;
81 /* Http Range Header Field */
82 static HttpHdrRange *ParseCreate(const String * range_spec);
83
84 HttpHdrRange();
85 HttpHdrRange(HttpHdrRange const &);
86 ~HttpHdrRange();
87 HttpHdrRange &operator= (HttpHdrRange const &);
88
89 typedef Vector<HttpHdrRangeSpec *>::iterator iterator;
90 typedef Vector<HttpHdrRangeSpec *>::const_iterator const_iterator;
91 iterator begin();
92 const_iterator begin () const;
93 iterator end();
94 const_iterator end() const;
62e76326 95
528b2c61 96 /* adjust specs after the length is known */
97 int canonize(size_t);
98 int canonize(HttpReply *rep);
99 /* returns true if ranges are valid; inits HttpHdrRange */
100 bool parseInit(const String * range_spec);
101 void packInto(Packer * p) const;
102 /* other */
103 bool isComplex() const;
104 bool willBeComplex() const;
105 ssize_t firstOffset() const;
106 ssize_t lowestOffset(ssize_t) const;
107 bool offsetLimitExceeded() const;
108 Vector<HttpHdrRangeSpec *> specs;
62e76326 109
528b2c61 110private:
111 static MemPool *Pool;
112 void getCanonizedSpecs (Vector<HttpHdrRangeSpec *> &copy);
113 void merge (Vector<HttpHdrRangeSpec *> &basis);
114 ssize_t clen;
115};
116
117/* data for iterating thru range specs */
62e76326 118
119class HttpHdrRangeIter
120{
121
122public:
528b2c61 123 HttpHdrRange::iterator pos;
124 const HttpHdrRangeSpec *currentSpec() const;
125 void updateSpec();
126 ssize_t debt() const;
127 void debt(ssize_t);
128 ssize_t debt_size; /* bytes left to send from the current spec */
129 String boundary; /* boundary for multipart responses */
130 bool valid;
131};
62e76326 132
528b2c61 133#endif /* SQUID_HTTPHEADERRANGE_H */