summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Base/URL.cpp')
-rw-r--r--Swiften/Base/URL.cpp14
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,7 +1,7 @@
/*
- * 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>
@@ -9,11 +9,11 @@
#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;
@@ -60,22 +60,22 @@ URL URL::fromString(const std::string& urlString) {
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 {
@@ -85,11 +85,11 @@ URL URL::fromString(const std::string& urlString) {
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();
}
}
@@ -130,11 +130,11 @@ std::string URL::toString() const {
else {
result += host;
}
if (port) {
result += ":";
- result += boost::lexical_cast<std::string>(*port);
+ result += std::to_string(*port);
}
result += path;
return result;
}