diff options
Diffstat (limited to 'Swiften/Base/URL.cpp')
| -rw-r--r-- | Swiften/Base/URL.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Swiften/Base/URL.cpp b/Swiften/Base/URL.cpp index 4a47a11..5c0f0d7 100644 --- a/Swiften/Base/URL.cpp +++ b/Swiften/Base/URL.cpp @@ -1,23 +1,23 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Base/URL.h> #include <algorithm> #include <iostream> namespace Swift { -int URL::getPortOrDefaultPort(const URL& url) { +unsigned short URL::getPortOrDefaultPort(const URL& url) { if (url.getPort()) { return *url.getPort(); } else if (url.getScheme() == "http") { return 80; } else if (url.getScheme() == "https") { return 443; } @@ -56,44 +56,44 @@ URL URL::fromString(const std::string& urlString) { userInfo = authority.substr(0, atIndex); hostAndPort = authority.substr(atIndex + 1); } else { userInfo = ""; hostAndPort = authority; } std::string host; - boost::optional<int> port; + boost::optional<unsigned short> port; if (hostAndPort[0] == '[') { // handle IPv6 address literals size_t addressEndIndex = hostAndPort.find(']'); if (addressEndIndex != std::string::npos) { host = hostAndPort.substr(1, addressEndIndex - 1); colonIndex = hostAndPort.find(':', addressEndIndex); if (colonIndex != std::string::npos) { try { - port = boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1)); + port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1))); } - catch (const boost::bad_lexical_cast&) { + catch (...) { return URL(); } } } else { return URL(); } } else { colonIndex = hostAndPort.find(':'); if (colonIndex != std::string::npos) { host = unescape(hostAndPort.substr(0, colonIndex)); try { - port = boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1)); + port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1))); } catch (const boost::bad_lexical_cast&) { return URL(); } } else { host = unescape(hostAndPort); } } @@ -126,19 +126,19 @@ std::string URL::toString() const { } if (host.find(':') != std::string::npos) { result += "[" + host + "]"; } else { result += host; } if (port) { result += ":"; - result += boost::lexical_cast<std::string>(*port); + result += std::to_string(*port); } result += path; return result; } // Disabling this code for now, since GCC4.5+boost1.42 (on ubuntu) seems to // result in a bug. Replacing it with naive code. #if 0 // Should be in anonymous namespace, but older GCCs complain if we do that |
Swift