1 /**
2 * TLS Server Information
3 * 
4 * Copyright:
5 * (C) 2012 Jack Lloyd
6 * (C) 2014-2015 Etienne Cimon
7 *
8 * License:
9 * Botan is released under the Simplified BSD License (see LICENSE.md)
10 */
11 module botan.tls.server_info;
12 
13 import botan.constants;
14 static if (BOTAN_HAS_TLS):
15 
16 import botan.utils.types;
17 
18 /**
19 * Represents information known about a TLS server.
20 */
21 struct TLSServerInformation
22 {
23 public:
24     /**
25     * Params:
26     *  hostname = the host's DNS name, if known
27     *  port = specifies the protocol port of the server (eg for
28     *          TCP/UDP). Zero represents unknown.
29     */
30     this(in string hostname, ushort port = 0)
31     {
32 		//logDebug("Server info with hostname: ", hostname);
33         m_hostname = hostname; 
34         m_port = port; 
35     }
36 
37     /**
38     * Params:
39     *  hostname = the host's DNS name, if known
40     *  service = is a text string of the service type
41     *          (eg "https", "tor", or "git")
42     *  port = specifies the protocol port of the server (eg for
43     *          TCP/UDP). Zero represents unknown.
44     */
45     this(in string hostname,
46          in string service,
47          ushort port = 0)
48     {
49         m_hostname = hostname;
50         m_service = service;
51         m_port = port;
52     }
53 
54     string hostname() const { return m_hostname; }
55 
56     string service() const { return m_service; }
57 
58     ushort port() const { return m_port; }
59 
60     @property bool empty() const { return m_hostname == string.init; }
61 
62     bool opEquals(in TLSServerInformation b) const
63     {
64         return (hostname() == b.hostname()) &&
65                 (service() == b.service()) &&
66                 (port() == b.port());
67         
68     }
69 
70     int opCmp(in TLSServerInformation b) const
71     {
72         if (this == b) return 0;
73         else if (isLessThan(b)) return -1;
74         else return 1;
75     }
76 
77     bool isLessThan(in TLSServerInformation b) const
78     {
79         if (hostname() != b.hostname())
80             return (hostname() < b.hostname());
81         if (service() != b.service())
82             return (service() < b.service());
83         if (port() != b.port())
84             return (port() < b.port());
85         return false; // equal
86     }
87 
88 private:
89     string m_hostname, m_service;
90     ushort m_port;
91 }