/src/botan/build/include/botan/tls_server_info.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * TLS Server Information |
3 | | * (C) 2012 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #ifndef BOTAN_TLS_SERVER_INFO_H_ |
9 | | #define BOTAN_TLS_SERVER_INFO_H_ |
10 | | |
11 | | #include <botan/types.h> |
12 | | #include <string> |
13 | | |
14 | | namespace Botan { |
15 | | |
16 | | namespace TLS { |
17 | | |
18 | | /** |
19 | | * Represents information known about a TLS server. |
20 | | */ |
21 | | class BOTAN_PUBLIC_API(2, 0) Server_Information final { |
22 | | public: |
23 | | /** |
24 | | * An empty server info - nothing known |
25 | | */ |
26 | 0 | Server_Information() : m_hostname(""), m_service(""), m_port(0) {} |
27 | | |
28 | | /** |
29 | | * @param hostname the host's DNS name, if known |
30 | | * @param port specifies the protocol port of the server (eg for |
31 | | * TCP/UDP). Zero represents unknown. |
32 | | */ |
33 | | Server_Information(std::string_view hostname, uint16_t port = 0) : |
34 | 8.52k | m_hostname(hostname), m_service(""), m_port(port) {} |
35 | | |
36 | | /** |
37 | | * @param hostname the host's DNS name, if known |
38 | | * @param service is a text string of the service type |
39 | | * (eg "https", "tor", or "git") |
40 | | * @param port specifies the protocol port of the server (eg for |
41 | | * TCP/UDP). Zero represents unknown. |
42 | | */ |
43 | | Server_Information(std::string_view hostname, std::string_view service, uint16_t port = 0) : |
44 | 0 | m_hostname(hostname), m_service(service), m_port(port) {} |
45 | | |
46 | | /** |
47 | | * @return the host's DNS name, if known |
48 | | */ |
49 | 2.50k | std::string hostname() const { return m_hostname; } |
50 | | |
51 | | /** |
52 | | * @return text string of the service type, e.g., |
53 | | * "https", "tor", or "git" |
54 | | */ |
55 | 0 | std::string service() const { return m_service; } |
56 | | |
57 | | /** |
58 | | * @return the protocol port of the server, or zero if unknown |
59 | | */ |
60 | 0 | uint16_t port() const { return m_port; } |
61 | | |
62 | | /** |
63 | | * @return whether the hostname is known |
64 | | */ |
65 | 2.50k | bool empty() const { return m_hostname.empty(); } |
66 | | |
67 | | private: |
68 | | std::string m_hostname, m_service; |
69 | | uint16_t m_port; |
70 | | }; |
71 | | |
72 | 0 | inline bool operator==(const Server_Information& a, const Server_Information& b) { |
73 | 0 | return (a.hostname() == b.hostname()) && (a.service() == b.service()) && (a.port() == b.port()); |
74 | 0 | } |
75 | | |
76 | 0 | inline bool operator!=(const Server_Information& a, const Server_Information& b) { return !(a == b); } |
77 | | |
78 | 0 | inline bool operator<(const Server_Information& a, const Server_Information& b) { |
79 | 0 | if(a.hostname() != b.hostname()) |
80 | 0 | return (a.hostname() < b.hostname()); |
81 | 0 | if(a.service() != b.service()) |
82 | 0 | return (a.service() < b.service()); |
83 | 0 | if(a.port() != b.port()) |
84 | 0 | return (a.port() < b.port()); |
85 | 0 | return false; // equal |
86 | 0 | } |
87 | | |
88 | | } // namespace TLS |
89 | | |
90 | | } // namespace Botan |
91 | | |
92 | | #endif |