]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHeaderRange.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / HttpHeaderRange.h
1 /*
2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_HTTPHEADERRANGE_H
10 #define SQUID_HTTPHEADERRANGE_H
11
12 #include "base/Range.h"
13 #include "mem/forward.h"
14 #include "SquidString.h"
15
16 #include <vector>
17
18 class HttpReply;
19 class Packable;
20
21 /* http byte-range-spec */
22
23 class HttpHdrRangeSpec
24 {
25 MEMPROXY_CLASS(HttpHdrRangeSpec);
26
27 public:
28 typedef Range<int64_t, uint64_t> HttpRange;
29 static int64_t const UnknownPosition;
30
31 HttpHdrRangeSpec();
32 static HttpHdrRangeSpec *Create(const char *field, int fieldLen);
33
34 bool parseInit(const char *field, int flen);
35 int canonize(int64_t clen);
36 void outputInfo( char const *note) const;
37 void packInto(Packable * p) const;
38 bool mergeWith(const HttpHdrRangeSpec * donor);
39 int64_t offset;
40 int64_t length;
41 };
42
43 /**
44 * There may be more than one byte range specified in the request.
45 * This object holds all range specs in order of their appearence
46 * in the request because we SHOULD preserve that order.
47 */
48 class HttpHdrRange
49 {
50 MEMPROXY_CLASS(HttpHdrRange);
51
52 public:
53 static size_t ParsedCount;
54 /* Http Range Header Field */
55 static HttpHdrRange *ParseCreate(const String * range_spec);
56
57 HttpHdrRange();
58 HttpHdrRange(HttpHdrRange const &);
59 ~HttpHdrRange();
60 HttpHdrRange &operator= (HttpHdrRange const &);
61
62 typedef std::vector<HttpHdrRangeSpec *>::iterator iterator;
63 typedef std::vector<HttpHdrRangeSpec *>::const_iterator const_iterator;
64 iterator begin();
65 const_iterator begin () const;
66 iterator end();
67 const_iterator end() const;
68
69 /* adjust specs after the length is known */
70 int canonize(int64_t);
71 int canonize(HttpReply *rep);
72 /* returns true if ranges are valid; inits HttpHdrRange */
73 bool parseInit(const String * range_spec);
74 void packInto(Packable * p) const;
75 /* other */
76 bool isComplex() const;
77 bool willBeComplex() const;
78 int64_t firstOffset() const;
79 int64_t lowestOffset(int64_t) const;
80 bool offsetLimitExceeded(const int64_t limit) const;
81 bool contains(const HttpHdrRangeSpec& r) const;
82 std::vector<HttpHdrRangeSpec *> specs;
83
84 private:
85 void getCanonizedSpecs (std::vector<HttpHdrRangeSpec *> &copy);
86 void merge (std::vector<HttpHdrRangeSpec *> &basis);
87 int64_t clen;
88 };
89
90 /**
91 * Data for iterating thru range specs
92 */
93 class HttpHdrRangeIter
94 {
95
96 public:
97 HttpHdrRange::iterator pos;
98 HttpHdrRange::iterator end;
99 const HttpHdrRangeSpec *currentSpec() const;
100 void updateSpec();
101 int64_t debt() const;
102 void debt(int64_t);
103 int64_t debt_size; /* bytes left to send from the current spec */
104 String boundary; /* boundary for multipart responses */
105 bool valid;
106 };
107
108 #endif /* SQUID_HTTPHEADERRANGE_H */
109