From 7b77f771719bf28fee434807a5d3437d1012e962 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sun, 4 Dec 2011 08:10:03 -0600 Subject: [PATCH] changes the type of the URI port consts --- src/uri.cpp | 90 ++--------------------------------------------------- src/uri.hpp | 8 +++-- 2 files changed, 8 insertions(+), 90 deletions(-) diff --git a/src/uri.cpp b/src/uri.cpp index 688997cea6..28070b969b 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -131,9 +131,9 @@ std::string uri::str() const { s << "ws" << (m_secure ? "s" : "") << "://" << m_host; - /*if (m_port != (m_secure ? DEFAULT_SECURE_PORT : DEFAULT_PORT)) { + if (m_port != (m_secure ? DEFAULT_SECURE_PORT : DEFAULT_PORT)) { s << ":" << m_port; - }*/ + } s << m_resource; return s.str(); @@ -155,88 +155,4 @@ uint16_t uri::get_port_from_string(const std::string& port) const { } return t_port; -} - -/*std::string uri::base() const { - std::stringstream s; - - s << "ws" << (secure ? "s" : "") << "://" << host; - - if (port != (secure ? DEFAULT_SECURE_PORT : DEFAULT_PORT)) { - s << ":" << port; - } - - s << "/"; - return s.str(); -} - -void uri::set_secure(bool secure) { - m_secure = secure; -} - -void uri::set_host(const std::string& host) { - // TODO: additional validation? - m_host = host; -} -void set_port(uint16_t port) { - if (port > 65535) { - throw uri_exception("Port must be less than 65535"); - } -} -void set_port(const std::string& port); -void set_resource(const std::string& resource);*/ - - - - - - - - - - - - - -/*bool uri::parse(const std::string& uri) { - boost::cmatch matches; - static const boost::regex expression("(ws|wss)://([^/:\\[]+|\\[[0-9:]+\\])(:\\d{1,5})?(/[^#]*)?"); - - // TODO: should this split resource into path/query? - - if (boost::regex_match(uri.c_str(), matches, expression)) { - secure = (matches[1] == "wss"); - host = matches[2]; - - std::string port(matches[3]); - - if (port != "") { - // strip off the : - // this could probably be done with a better regex. - port = port.substr(1); - } - - m_port = get_port_from_string(port); - - if (matches[3] == "") { - port = (secure ? DEFAULT_SECURE_PORT : DEFAULT_PORT); - } else { - unsigned int t_port = atoi(std::string(matches[3]).substr(1).c_str()); - - if (t_port > 65535) { - return false; - } - - port = atoi(std::string(matches[3]).substr(1).c_str()); - } - - resource = (matches[4] == "" ? "/" : matches[4]); - - return true; - } - - return false; -}*/ - - - +} \ No newline at end of file diff --git a/src/uri.hpp b/src/uri.hpp index a25fcc10c9..6061303abf 100644 --- a/src/uri.hpp +++ b/src/uri.hpp @@ -50,11 +50,13 @@ private: std::string m_msg; }; + + class uri { public: - static const int DEFAULT_PORT = 80; - static const int DEFAULT_SECURE_PORT = 443; - + static const uint16_t DEFAULT_PORT = 80; + static const uint16_t DEFAULT_SECURE_PORT = 443; + explicit uri(const std::string& uri); uri(bool secure, const std::string& host, uint16_t port, const std::string& resource); uri(bool secure, const std::string& host, const std::string& resource);