mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Added utility class for parsing WS urls
This commit is contained in:
@@ -132,4 +132,42 @@ std::string lookup_ws_close_status_string(uint16_t code) {
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool websocketpp::ws_uri::parse(const std::string& uri) {
|
||||
boost::cmatch what;
|
||||
static const boost::regex expression("(ws|wss)://([^/:\\[]+|\\[[0-9:]+\\])(:\\d{1,5})?(/.*)?");
|
||||
|
||||
if (boost::regex_match(uri.c_str(), what, expression)) {
|
||||
if (what[1] == "wss") {
|
||||
secure = true;
|
||||
} else {
|
||||
secure = false;
|
||||
}
|
||||
|
||||
host = what[2];
|
||||
|
||||
if (what[3] == "") {
|
||||
port = (secure ? 443 : 80);
|
||||
} else {
|
||||
unsigned int t_port = atoi(std::string(what[3]).substr(1).c_str());
|
||||
|
||||
if (t_port > 65535) {
|
||||
return false;
|
||||
}
|
||||
|
||||
port = atoi(std::string(what[3]).substr(1).c_str());
|
||||
}
|
||||
|
||||
if (what[4] == "") {
|
||||
resource = "/";
|
||||
} else {
|
||||
resource = what[4];
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
// http://www.viva64.com/en/k/0018/
|
||||
// TODO: impliment stuff from here:
|
||||
@@ -45,4 +46,16 @@ uint64_t ntohll(uint64_t src);
|
||||
std::string lookup_http_error_string(int code);
|
||||
std::string lookup_ws_close_status_string(uint16_t code);
|
||||
|
||||
namespace websocketpp {
|
||||
struct ws_uri {
|
||||
bool parse(const std::string& uri);
|
||||
|
||||
bool secure;
|
||||
std::string host;
|
||||
uint16_t port;
|
||||
std::string resource;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // NETWORK_UTILITIES_HPP
|
||||
|
||||
Reference in New Issue
Block a user