Botan  2.4.0
Crypto and TLS for C++11
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 */
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
Server_Information(const std::string &hostname, uint16_t port=0)
bool operator<(const Server_Information &a, const Server_Information &b)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
std::string hostname() const
bool operator==(const Server_Information &a, const Server_Information &b)
Server_Information(const std::string &hostname, const std::string &service, uint16_t port=0)
Definition: alg_id.cpp:13
bool operator!=(const Server_Information &a, const Server_Information &b)