11#include <boost/lexical_cast.hpp> 
   20    : url_(url), valid_(false), error_message_(), scheme_(
Url::
HTTPS),
 
   21      hostname_(), port_(0), path_() {
 
 
   27    return (url_ < url.
rawUrl());
 
 
   37Url::getHostname()
 const {
 
   44    std::string hostname = getHostname();
 
   45    if ((hostname.length() >= 2) && (hostname.at(0) == 
'[')) {
 
   46        return (hostname.substr(1, hostname.length() - 2));
 
 
   68    s << 
"://" << getHostname();
 
 
   80Url::checkValid()
 const {
 
   89    error_message_.clear();
 
   95    std::ostringstream error;
 
   98    size_t offset = url_.find(
":");
 
   99    if ((offset == 0) || (offset == std::string::npos)) {
 
  100        error << 
"url " << url_ << 
" lacks http or https scheme";
 
  101        error_message_ = error.str();
 
  106    std::string scheme = url_.substr(0, offset);
 
  107    if (scheme == 
"http") {
 
  110    } 
else if (scheme == 
"https") {
 
  114        error << 
"invalid scheme " << scheme << 
" in " << url_;
 
  115        error_message_ = 
error.str();
 
  120    if (url_.substr(offset, 3) != 
"://") {
 
  121        error << 
"expected :// after scheme in " << url_;
 
  122        error_message_ = 
error.str();
 
  128    if (offset >= url_.length()) {
 
  129        error << 
"hostname missing in " << url_;
 
  130        error_message_ = 
error.str();
 
  137    if (url_.at(offset) == 
'[') {
 
  138        offset2 = url_.find(
']', offset);
 
  139        if (offset2 == std::string::npos) {
 
  140            error << 
"expected ] after IPv6 address in " << url_;
 
  141            error_message_ = 
error.str();
 
  144        } 
else if (offset2 == offset + 1) {
 
  145            error << 
"expected IPv6 address within [] in " << url_;
 
  146            error_message_ = 
error.str();
 
  157        offset2 = url_.find(
":", offset);
 
  158        if (offset2 == std::string::npos) {
 
  159            offset2 = url_.find(
"/", offset);
 
  160            if (offset2 == std::string::npos) {
 
  162                offset2 = url_.length();
 
  168    hostname_ = url_.substr(offset, offset2 - offset);
 
  172    if (offset2 == url_.length()) {
 
  179    if (url_.at(offset2) == 
':') {
 
  180        if (offset2 == url_.length() - 1) {
 
  181            error << 
"expected port number after : in " << url_;
 
  182            error_message_ = 
error.str();
 
  189        size_t slash_offset = url_.find(
'/', offset2);
 
  190        std::string port_str;
 
  191        if (slash_offset == std::string::npos) {
 
  192            port_str = url_.substr(offset2);
 
  194            port_str = url_.substr(offset2, slash_offset - offset2);
 
  199            port_ = boost::lexical_cast<unsigned>(port_str);
 
  202            error << 
"invalid port number " << port_str << 
" in " << url_;
 
  203            error_message_ = 
error.str();
 
  208        offset2 = slash_offset;
 
  212    if (offset2 != std::string::npos) {
 
  213        path_ = url_.substr(offset2);
 
A generic exception that is thrown if a function is called in a prohibited way.
std::string toText() const
Returns textual representation of the URL.
std::string getStrippedHostname() const
Returns hostname stripped from [ ] characters surrounding IPv6 address.
unsigned getPort() const
Returns port number.
Scheme getScheme() const
Returns parsed scheme.
bool operator<(const Url &url) const
compares URLs lexically.
Url(const std::string &url)
Constructor.
bool isValid() const
Checks if the URL is valid.
std::string getPath() const
Returns path.
const std::string & rawUrl() const
Returns the raw, unparsed URL string.
Scheme
Scheme: https or http.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.