17 #ifndef ABSTRACTSERVERINFO_HPP_ 
   18 #define ABSTRACTSERVERINFO_HPP_ 
   24 #include <boost/cstdint.hpp> 
   25 #include <boost/lexical_cast.hpp> 
   27 #include <botan/botan.h> 
   28 #include <botan/base64.h> 
   36 template<ChannelType Type>
 
   40             , 
const std::string& encodedPublicKey);
 
   45             , 
const Botan::MemoryVector<boost::uint8_t>& publicKey);
 
   47     virtual const std::string& 
getHost()
 const {
 
   55     virtual const Botan::MemoryVector<boost::uint8_t>& 
getPublicKey()
 const {
 
   61         ss << host_ << 
":" << port_;
 
   76     template<
typename KeyRepresentation>
 
   77     void verify(
const std::string& host, 
const boost::int32_t& port
 
   78                                 , 
const KeyRepresentation& encodedPublicKey);
 
   80     void assign(
const std::string& host, 
const boost::int32_t& port
 
   81                                 , 
const std::string& encodedPublicKey);
 
   82     void assign(
const std::string& host, 
const boost::int32_t& port
 
   83                     , 
const Botan::MemoryVector<boost::uint8_t>& decodedPublicKey);
 
   86     const ChannelType channelType_;
 
   90     boost::uint16_t    port_;
 
   92     Botan::MemoryVector<boost::uint8_t>    publicKey_;
 
   95 template<ChannelType Type>
 
   97         , 
const std::string& encodedPublicKey) : channelType_(Type), serverType_(type)
 
   99     verify(host, port, encodedPublicKey);
 
  100     assign(host, port, encodedPublicKey);
 
  103 template<ChannelType Type>
 
  105     : channelType_(Type), serverType_(type)
 
  107     if (!hostPort.empty()) {
 
  108         std::size_t delimPos = hostPort.find(
':');
 
  110         boost::int32_t port = 0;
 
  112         if (delimPos != std::string::npos) {
 
  113             host = hostPort.substr(0, delimPos);
 
  115                 port = boost::lexical_cast<boost::int32_t>(hostPort.substr(delimPos + 1, std::string::npos));
 
  116             } 
catch (std::exception& e) {
 
  121         verify(host, port, encodedPublicKey);
 
  122         assign(host, port, encodedPublicKey);
 
  128 template<ChannelType Type>
 
  130         , 
const Botan::MemoryVector<boost::uint8_t>& publicKey) : channelType_(Type), serverType_(type)
 
  132     verify(host, port, publicKey);
 
  133     assign(host, port, publicKey);
 
  136 template<ChannelType Type>
 
  137 template<
typename KeyRepresentation>
 
  144     if (port < 1 || port > USHRT_MAX) {
 
  145         throw KaaException(
"Server port not in valid range");
 
  148     if (encodedPublicKey.empty()) {
 
  149         throw KaaException(
"Empty server public key");
 
  153 template<ChannelType Type>
 
  154 void AbstractServerInfo<Type>::assign(
const std::string& host, 
const boost::int32_t& port, 
const std::string& encodedPublicKey)
 
  158     publicKey_ = Botan::base64_decode(encodedPublicKey);
 
  161 template<ChannelType Type>
 
  162 void AbstractServerInfo<Type>::assign(
const std::string& host, 
const boost::int32_t& port, 
const Botan::MemoryVector<boost::uint8_t>& decodedPublicKey)
 
  166     publicKey_ = decodedPublicKey;
 
virtual const std::string & getHost() const 
 
virtual ~AbstractServerInfo()
 
virtual boost::uint16_t getPort() const 
 
virtual ServerType getServerType() const 
 
AbstractServerInfo(ServerType type, const std::string &host, const boost::int32_t &port, const std::string &encodedPublicKey)
 
virtual ChannelType getChannelType() const 
 
virtual HttpUrl getUrl() const 
 
virtual const Botan::MemoryVector< boost::uint8_t > & getPublicKey() const