Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

tls_server_info.h
Go to the documentation of this file.
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_DLL Server_Information
22 {
23 public:
24 /**
25 * An empty server info - nothing known
26 */
27 Server_Information() : m_hostname(""), m_service(""), m_port(0) {}
28
29 /**
30 * @param hostname the host's DNS name, if known
31 * @param port specifies the protocol port of the server (eg for
32 * TCP/UDP). Zero represents unknown.
33 */
34 Server_Information(const std::string& hostname,
35 uint16_t port = 0) :
36 m_hostname(hostname), m_service(""), m_port(port) {}
37
38 /**
39 * @param hostname the host's DNS name, if known
40 * @param service is a text string of the service type
41 * (eg "https", "tor", or "git")
42 * @param port specifies the protocol port of the server (eg for
43 * TCP/UDP). Zero represents unknown.
44 */
45 Server_Information(const std::string& hostname,
46 const std::string& service,
47 uint16_t port = 0) :
48 m_hostname(hostname), m_service(service), m_port(port) {}
49
50 /**
51 * @return the host's DNS name, if known
52 */
53 std::string hostname() const { return m_hostname; }
54
55 /**
56 * @return text string of the service type, e.g.,
57 * "https", "tor", or "git"
58 */
59 std::string service() const { return m_service; }
60
61 /**
62 * @return the protocol port of the server, or zero if unknown
63 */
64 uint16_t port() const { return m_port; }
65
66 /**
67 * @return whether the hostname is known
68 */
69 bool empty() const { return m_hostname.empty(); }
70
71 private:
72 std::string m_hostname, m_service;
73 uint16_t m_port;
74 };
75
76 inline bool operator==(const Server_Information& a, const Server_Information& b)
77 {
78 return (a.hostname() == b.hostname()) &&
79 (a.service() == b.service()) &&
80 (a.port() == b.port());
81
82 }
83
84 inline bool operator!=(const Server_Information& a, const Server_Information& b)
85 {
86 return !(a == b);
87 }
88
89 inline bool operator<(const Server_Information& a, const Server_Information& b)
90 {
91 if(a.hostname() != b.hostname())
92 return (a.hostname() < b.hostname());
93 if(a.service() != b.service())
94 return (a.service() < b.service());
95 if(a.port() != b.port())
96 return (a.port() < b.port());
97 return false; // equal
98 }
99
100 }
101
102 }
103
104 #endif
Botan::TLS::Server_Information::empty
bool empty() const
Definition: tls_server_info.h:69
Botan::TLS::Server_Information::Server_Information
Server_Information(const std::string &hostname, uint16_t port=0)
Definition: tls_server_info.h:34
Botan::TLS::operator<
bool operator<(const Server_Information &a, const Server_Information &b)
Definition: tls_server_info.h:89
Botan::TLS::Server_Information::service
std::string service() const
Definition: tls_server_info.h:59
Botan::TLS::Server_Information::port
uint16_t port() const
Definition: tls_server_info.h:64
Botan::TLS::operator==
bool operator==(const Server_Information &a, const Server_Information &b)
Definition: tls_server_info.h:76
Botan::TLS::Server_Information::hostname
std::string hostname() const
Definition: tls_server_info.h:53
Botan::TLS::Server_Information::Server_Information
Server_Information(const std::string &hostname, const std::string &service, uint16_t port=0)
Definition: tls_server_info.h:45
Botan::TLS::Server_Information
Definition: tls_server_info.h:21
Botan
Definition: alg_id.cpp:13
Botan::TLS::operator!=
bool operator!=(const Server_Information &a, const Server_Information &b)
Definition: tls_server_info.h:84
Botan::TLS::Server_Information::Server_Information
Server_Information()
Definition: tls_server_info.h:27