2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_ANYP_URISCHEME_H
10 #define SQUID_ANYP_URISCHEME_H
12 #include "anyp/ProtocolType.h"
13 #include "sbuf/SBuf.h"
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.
27 typedef std::vector
<SBuf
> LowercaseSchemeNames
;
29 UriScheme() : theScheme_(AnyP::PROTO_NONE
) {}
30 /// \param img Explicit scheme representation for unknown/none schemes.
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;
36 AnyP::UriScheme
& operator=(const AnyP::UriScheme
&o
) {
37 theScheme_
= o
.theScheme_
;
41 AnyP::UriScheme
& operator=(AnyP::UriScheme
&&) = default;
43 operator AnyP::ProtocolType() const { return theScheme_
; }
44 // XXX: does not account for comparison of unknown schemes (by image)
45 bool operator != (AnyP::ProtocolType
const & aProtocol
) const { return theScheme_
!= aProtocol
; }
47 /** Get a char string representation of the scheme.
48 * Does not include the ':' or "://" terminators.
50 SBuf
image() const {return image_
;}
52 unsigned short defaultPort() const;
54 /// initializes down-cased protocol scheme names array
57 /// \returns ProtocolType for the given scheme name or PROTO_UNKNOWN
58 static const AnyP::ProtocolType
FindProtocolType(const SBuf
&);
61 /// optimization: stores down-cased protocol scheme names, copied from
62 /// AnyP::ProtocolType_str
63 static LowercaseSchemeNames LowercaseSchemeNames_
;
65 /// This is a typecode pointer into the enum/registry of protocols handled.
66 AnyP::ProtocolType theScheme_
;
68 /// the string representation
75 operator << (std::ostream
&os
, AnyP::UriScheme
const &scheme
)
81 #endif /* SQUID_ANYP_URISCHEME_H */