]> git.ipfire.org Git - thirdparty/squid.git/blame - src/anyp/UriScheme.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / anyp / UriScheme.h
CommitLineData
bbc27441 1/*
f70aedc4 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
bbc27441
AJ
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
1ca54a54
AJ
9#ifndef SQUID_ANYP_URISCHEME_H
10#define SQUID_ANYP_URISCHEME_H
11
12#include "anyp/ProtocolType.h"
d31d59d8 13#include "sbuf/SBuf.h"
074d6a40 14
1ca54a54 15#include <iosfwd>
45c1d1e6 16#include <vector>
1ca54a54
AJ
17
18namespace AnyP
19{
20
21/** This class represents a URI Scheme such as http:// https://, wais://, urn: etc.
22 * It does not represent the PROTOCOL that such schemes refer to.
23 */
24class UriScheme
25{
26public:
50a43a49
AR
27 typedef std::vector<SBuf> LowercaseSchemeNames;
28
1ca54a54 29 UriScheme() : theScheme_(AnyP::PROTO_NONE) {}
50a43a49 30 /// \param img Explicit scheme representation for unknown/none schemes.
d31d59d8
AJ
31 UriScheme(AnyP::ProtocolType const aScheme, const char *img = nullptr);
32 UriScheme(const AnyP::UriScheme &o) : theScheme_(o.theScheme_), image_(o.image_) {}
33 UriScheme(AnyP::UriScheme &&) = default;
1ca54a54
AJ
34 ~UriScheme() {}
35
d31d59d8
AJ
36 AnyP::UriScheme& operator=(const AnyP::UriScheme &o) {
37 theScheme_ = o.theScheme_;
38 image_ = o.image_;
39 return *this;
40 }
41 AnyP::UriScheme& operator=(AnyP::UriScheme &&) = default;
1ca54a54 42
d31d59d8
AJ
43 operator AnyP::ProtocolType() const { return theScheme_; }
44 // XXX: does not account for comparison of unknown schemes (by image)
1ca54a54
AJ
45 bool operator != (AnyP::ProtocolType const & aProtocol) const { return theScheme_ != aProtocol; }
46
47 /** Get a char string representation of the scheme.
d31d59d8 48 * Does not include the ':' or "://" terminators.
1ca54a54 49 */
d31d59d8 50 SBuf image() const {return image_;}
1ca54a54 51
5c51bffb
AJ
52 unsigned short defaultPort() const;
53
50a43a49
AR
54 /// initializes down-cased protocol scheme names array
55 static void Init();
56
6c880a16
AJ
57 /// \returns ProtocolType for the given scheme name or PROTO_UNKNOWN
58 static const AnyP::ProtocolType FindProtocolType(const SBuf &);
59
1ca54a54 60private:
50a43a49
AR
61 /// optimization: stores down-cased protocol scheme names, copied from
62 /// AnyP::ProtocolType_str
63 static LowercaseSchemeNames LowercaseSchemeNames_;
64
1ca54a54
AJ
65 /// This is a typecode pointer into the enum/registry of protocols handled.
66 AnyP::ProtocolType theScheme_;
d31d59d8
AJ
67
68 /// the string representation
69 SBuf image_;
1ca54a54
AJ
70};
71
72} // namespace AnyP
73
74inline std::ostream &
75operator << (std::ostream &os, AnyP::UriScheme const &scheme)
76{
d31d59d8 77 os << scheme.image();
1ca54a54
AJ
78 return os;
79}
80
81#endif /* SQUID_ANYP_URISCHEME_H */
f53969cc 82