]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 1996-2025 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_SRC_ANYP_PROTOCOLVERSION_H | |
10 | #define SQUID_SRC_ANYP_PROTOCOLVERSION_H | |
11 | ||
12 | #include "anyp/ProtocolType.h" | |
13 | ||
14 | #include <ostream> | |
15 | ||
16 | namespace AnyP | |
17 | { | |
18 | ||
19 | /** | |
20 | * Stores a protocol version label. | |
21 | * For example HTTP/1.1 or ICY/1.0 or FTP/2.0 | |
22 | */ | |
23 | class ProtocolVersion | |
24 | { | |
25 | ||
26 | public: | |
27 | // BUG: major() and minor() are macros. | |
28 | // we can't use a fast constructor syntax without renaming them globally | |
29 | ProtocolVersion() : protocol(PROTO_NONE) { | |
30 | major = 0; | |
31 | minor = 0; | |
32 | } | |
33 | ||
34 | ProtocolVersion(ProtocolType which, unsigned int aMajor, unsigned int aMinor) : protocol(which) { | |
35 | major = aMajor; | |
36 | minor = aMinor; | |
37 | } | |
38 | ||
39 | ProtocolType protocol; ///< which protocol this version is for | |
40 | unsigned int major; ///< major version number | |
41 | unsigned int minor; ///< minor version number | |
42 | ||
43 | /// whether the version is "known" (e.g., has been parsed or explicitly set) | |
44 | explicit operator bool() const { return protocol != PROTO_NONE; } | |
45 | ||
46 | bool operator==(const ProtocolVersion& that) const { | |
47 | if (this->protocol != that.protocol) | |
48 | return false; | |
49 | ||
50 | if (this->major != that.major) | |
51 | return false; | |
52 | ||
53 | if (this->minor != that.minor) | |
54 | return false; | |
55 | ||
56 | return true; | |
57 | } | |
58 | ||
59 | bool operator!=(const ProtocolVersion& that) const { | |
60 | return (((this->protocol != that.protocol) || this->major != that.major) || (this->minor != that.minor)); | |
61 | } | |
62 | ||
63 | bool operator <(const ProtocolVersion& that) const { | |
64 | if (this->protocol != that.protocol) | |
65 | return false; // throw? | |
66 | ||
67 | return (this->major < that.major || | |
68 | (this->major == that.major && this->minor < that.minor)); | |
69 | } | |
70 | ||
71 | bool operator >(const ProtocolVersion& that) const { | |
72 | if (this->protocol != that.protocol) | |
73 | return false; // throw? | |
74 | ||
75 | return (this->major > that.major || | |
76 | (this->major == that.major && this->minor > that.minor)); | |
77 | } | |
78 | ||
79 | bool operator <=(const ProtocolVersion& that) const { | |
80 | if (this->protocol != that.protocol) | |
81 | return false; // throw? | |
82 | ||
83 | return !(*this > that); | |
84 | } | |
85 | ||
86 | bool operator >=(const ProtocolVersion& that) const { | |
87 | if (this->protocol != that.protocol) | |
88 | return false; // throw? | |
89 | ||
90 | return !(*this < that); | |
91 | } | |
92 | }; | |
93 | ||
94 | inline std::ostream & | |
95 | operator << (std::ostream &os, const ProtocolVersion &v) | |
96 | { | |
97 | return (os << AnyP::ProtocolType_str[v.protocol] << '/' << v.major << '.' << v.minor); | |
98 | } | |
99 | ||
100 | } // namespace AnyP | |
101 | ||
102 | #endif /* SQUID_SRC_ANYP_PROTOCOLVERSION_H */ | |
103 |