Example #1
0
 uri(std::string const & scheme, std::string const & host,
         std::string const & port, std::string const & resource) :
                 m_scheme(scheme), m_host(host),
                 m_resource(resource == "" ? "/" : resource),
                 m_secure(scheme == "wss" || scheme == "https")
 {
     lib::error_code ec;
     m_port = get_port_from_string(port, ec);
     m_valid = !ec;
 }
Example #2
0
 uri(bool secure, std::string const & host, std::string const & port,
         std::string const & resource) :
                 m_scheme(secure ? "wss" : "ws"), m_host(host),
                 m_resource(resource == "" ? "/" : resource),
                 m_secure(secure)
 {
     lib::error_code ec;
     m_port = get_port_from_string(port, ec);
     m_valid = !ec;
 }
Example #3
0
 explicit uri(const std::string& uri) {
     // TODO: should this split resource into path/query?
     lib::cmatch matches;
     const lib::regex expression("(http|https|ws|wss)://([^/:\\[]+|\\[[0-9a-fA-F:.]+\\])(:\\d{1,5})?(/[^#]*)?");
     
     if (lib::regex_match(uri.c_str(), matches, expression)) {
         m_scheme = matches[1];
         m_secure = (m_scheme == "wss" || m_scheme == "https");
         m_host = matches[2];
         
         // strip brackets from IPv6 literal URIs
         if (m_host[0] == '[') {
             m_host = m_host.substr(1,m_host.size()-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);
         
         m_resource = matches[4];
         
         if (m_resource == "") {
             m_resource = "/";
         }
         
         return;
     }
     
     throw websocketpp::uri_exception("Error parsing WebSocket URI");
 }
Example #4
0
    explicit uri(std::string const & uri) :
                    m_valid(false)
    {
        std::string::const_iterator it;
        std::string::const_iterator temp;

        int state = 0;

        it = uri.begin();

        if (std::equal(it, it + 6, "wss://"))
        {
            m_secure = true;
            m_scheme = "wss";
            it += 6;
        }
        else if (std::equal(it, it + 5, "ws://"))
        {
            m_secure = false;
            m_scheme = "ws";
            it += 5;
        }
        else if (std::equal(it, it + 7, "http://"))
        {
            m_secure = false;
            m_scheme = "http";
            it += 7;
        }
        else if (std::equal(it, it + 8, "https://"))
        {
            m_secure = true;
            m_scheme = "https";
            it += 8;
        }
        else
        {
            return;
        }

        // extract host.
        // either a host string
        // an IPv4 address
        // or an IPv6 address
        if (*it == '[')
        {
            ++it;
            // IPv6 literal
            // extract IPv6 digits until ]

            // TODO: this doesn't work on g++... not sure why
            //temp = std::find(it,it2,']');

            temp = it;
            while (temp != uri.end())
            {
                if (*temp == ']')
                {
                    break;
                }
                ++temp;
            }

            if (temp == uri.end())
            {
                return;
            }
            else
            {
                // validate IPv6 literal parts
                // can contain numbers, a-f and A-F
                m_host.append(it, temp);
            }
            it = temp + 1;
            if (it == uri.end())
            {
                state = 2;
            }
            else if (*it == '/')
            {
                state = 2;
                ++it;
            }
            else if (*it == ':')
            {
                state = 1;
                ++it;
            }
            else
            {
                // problem
                return;
            }
        }
        else
        {
            // IPv4 or hostname
            // extract until : or /
            while (state == 0)
            {
                if (it == uri.end())
                {
                    state = 2;
                    break;
                }
                else if (*it == '/')
                {
                    state = 2;
                }
                else if (*it == ':')
                {
                    // end hostname start port
                    state = 1;
                }
                else
                {
                    m_host += *it;
                }
                ++it;
            }
        }

        // parse port
        std::string port = "";
        while (state == 1)
        {
            if (it == uri.end())
            {
                state = 3;
                break;
            }
            else if (*it == '/')
            {
                state = 3;
            }
            else
            {
                port += *it;
            }
            ++it;
        }

        lib::error_code ec;
        m_port = get_port_from_string(port, ec);

        if (ec)
        {
            return;
        }

        m_resource = "/";
        m_resource.append(it, uri.end());

        m_valid = true;
    }
Example #5
0
 uri(std::string scheme, const std::string& host, const std::string& port, const std::string& resource)
   : m_scheme(scheme)
   , m_host(host)
   , m_resource(resource == "" ? "/" : resource)
   , m_port(get_port_from_string(port))
   , m_secure(scheme == "wss" || scheme == "https") {}
Example #6
0
 uri(bool secure, const std::string& host, const std::string& port, const std::string& resource)
   : m_scheme(secure ? "wss" : "ws")
   , m_host(host)
   , m_resource(resource == "" ? "/" : resource)
   , m_port(get_port_from_string(port))
   , m_secure(secure) {}