Botan  1.11.15
src/lib/tls/tls_server_info.h
Go to the documentation of this file.
00001 /*
00002 * TLS Server Information
00003 * (C) 2012 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_TLS_SERVER_INFO_H__
00009 #define BOTAN_TLS_SERVER_INFO_H__
00010 
00011 #include <botan/types.h>
00012 #include <string>
00013 
00014 namespace Botan {
00015 
00016 namespace TLS {
00017 
00018 /**
00019 * Represents information known about a TLS server.
00020 */
00021 class BOTAN_DLL Server_Information
00022    {
00023    public:
00024       /**
00025       * An empty server info - nothing known
00026       */
00027       Server_Information() : m_hostname(""), m_service(""), m_port(0) {}
00028 
00029       /**
00030       * @param hostname the host's DNS name, if known
00031       * @param port specifies the protocol port of the server (eg for
00032       *        TCP/UDP). Zero represents unknown.
00033       */
00034       Server_Information(const std::string& hostname,
00035                         u16bit port = 0) :
00036          m_hostname(hostname), m_service(""), m_port(port) {}
00037 
00038       /**
00039       * @param hostname the host's DNS name, if known
00040       * @param service is a text string of the service type
00041       *        (eg "https", "tor", or "git")
00042       * @param port specifies the protocol port of the server (eg for
00043       *        TCP/UDP). Zero represents unknown.
00044       */
00045       Server_Information(const std::string& hostname,
00046                         const std::string& service,
00047                         u16bit port = 0) :
00048          m_hostname(hostname), m_service(service), m_port(port) {}
00049 
00050       std::string hostname() const { return m_hostname; }
00051 
00052       std::string service() const { return m_service; }
00053 
00054       u16bit port() const { return m_port; }
00055 
00056       bool empty() const { return m_hostname.empty(); }
00057 
00058    private:
00059       std::string m_hostname, m_service;
00060       u16bit m_port;
00061    };
00062 
00063 inline bool operator==(const Server_Information& a, const Server_Information& b)
00064    {
00065    return (a.hostname() == b.hostname()) &&
00066           (a.service() == b.service()) &&
00067           (a.port() == b.port());
00068 
00069    }
00070 
00071 inline bool operator!=(const Server_Information& a, const Server_Information& b)
00072    {
00073    return !(a == b);
00074    }
00075 
00076 inline bool operator<(const Server_Information& a, const Server_Information& b)
00077    {
00078    if(a.hostname() != b.hostname())
00079       return (a.hostname() < b.hostname());
00080    if(a.service() != b.service())
00081       return (a.service() < b.service());
00082    if(a.port() != b.port())
00083       return (a.port() < b.port());
00084    return false; // equal
00085    }
00086 
00087 }
00088 
00089 }
00090 
00091 #endif