Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
websocketpp::uri Class Reference

#include <uri.hpp>

Public Member Functions

 uri (std::string const &uri_string)
 
 uri (bool secure, std::string const &host, uint16_t port, std::string const &resource)
 
 uri (bool secure, std::string const &host, std::string const &resource)
 
 uri (bool secure, std::string const &host, std::string const &port, std::string const &resource)
 
 uri (std::string const &scheme, std::string const &host, uint16_t port, std::string const &resource)
 
 uri (std::string scheme, std::string const &host, std::string const &resource)
 
 uri (std::string const &scheme, std::string const &host, std::string const &port, std::string const &resource)
 
bool get_valid () const
 
bool get_secure () const
 
std::string const & get_scheme () const
 
std::string const & get_host () const
 
std::string get_host_port () const
 
std::string get_authority () const
 
uint16_t get_port () const
 
std::string get_port_str () const
 
std::string const & get_resource () const
 
std::string str () const
 
std::string get_query () const
 Return the query portion.
 

Detailed Description

Definition at line 48 of file uri.hpp.

Constructor & Destructor Documentation

◆ uri() [1/7]

websocketpp::uri::uri ( std::string const & uri_string)
inlineexplicit

Definition at line 50 of file uri.hpp.

50 : m_valid(false) {
51 std::string::const_iterator it;
52 std::string::const_iterator temp;
53
54 int state = 0;
55
56 it = uri_string.begin();
57 size_t uri_len = uri_string.length();
58
59 if (uri_len >= 7 && std::equal(it,it+6,"wss://")) {
60 m_secure = true;
61 m_scheme = "wss";
62 it += 6;
63 } else if (uri_len >= 6 && std::equal(it,it+5,"ws://")) {
64 m_secure = false;
65 m_scheme = "ws";
66 it += 5;
67 } else if (uri_len >= 8 && std::equal(it,it+7,"http://")) {
68 m_secure = false;
69 m_scheme = "http";
70 it += 7;
71 } else if (uri_len >= 9 && std::equal(it,it+8,"https://")) {
72 m_secure = true;
73 m_scheme = "https";
74 it += 8;
75 } else {
76 return;
77 }
78
79 // extract host.
80 // either a host string
81 // an IPv4 address
82 // or an IPv6 address
83 if (*it == '[') {
84 ++it;
85 // IPv6 literal
86 // extract IPv6 digits until ]
87
88 // TODO: this doesn't work on g++... not sure why
89 //temp = std::find(it,it2,']');
90
91 temp = it;
92 while (temp != uri_string.end()) {
93 if (*temp == ']') {
94 break;
95 }
96 ++temp;
97 }
98
99 if (temp == uri_string.end()) {
100 return;
101 } else {
102 // validate IPv6 literal parts
103 // can contain numbers, a-f and A-F
104 m_host.append(it,temp);
105 }
106 it = temp+1;
107 if (it == uri_string.end()) {
108 state = 2;
109 } else if (*it == '/') {
110 state = 2;
111 ++it;
112 } else if (*it == ':') {
113 state = 1;
114 ++it;
115 } else {
116 // problem
117 return;
118 }
119 } else {
120 // IPv4 or hostname
121 // extract until : or /
122 while (state == 0) {
123 if (it == uri_string.end()) {
124 state = 2;
125 break;
126 } else if (*it == '/') {
127 state = 2;
128 } else if (*it == ':') {
129 // end hostname start port
130 state = 1;
131 } else {
132 m_host += *it;
133 }
134 ++it;
135 }
136 }
137
138 // parse port
139 std::string port;
140 while (state == 1) {
141 if (it == uri_string.end()) {
142 // state is not used after this point presently.
143 // this should be re-enabled if it ever is needed in a future
144 // refactoring
145 //state = 3;
146 break;
147 } else if (*it == '/') {
148 state = 3;
149 } else {
150 port += *it;
151 }
152 ++it;
153 }
154
155 lib::error_code ec;
156 m_port = get_port_from_string(port, ec);
157
158 if (ec) {
159 return;
160 }
161
162 m_resource = "/";
163 m_resource.append(it,uri_string.end());
164
165
166 m_valid = true;
167 }

◆ uri() [2/7]

websocketpp::uri::uri ( bool secure,
std::string const & host,
uint16_t port,
std::string const & resource )
inline

Definition at line 169 of file uri.hpp.

171 : m_scheme(secure ? "wss" : "ws")
172 , m_host(host)
173 , m_resource(resource.empty() ? "/" : resource)
174 , m_port(port)
175 , m_secure(secure)
176 , m_valid(true) {}

◆ uri() [3/7]

websocketpp::uri::uri ( bool secure,
std::string const & host,
std::string const & resource )
inline

Definition at line 178 of file uri.hpp.

179 : m_scheme(secure ? "wss" : "ws")
180 , m_host(host)
181 , m_resource(resource.empty() ? "/" : resource)
182 , m_port(secure ? uri_default_secure_port : uri_default_port)
183 , m_secure(secure)
184 , m_valid(true) {}

◆ uri() [4/7]

websocketpp::uri::uri ( bool secure,
std::string const & host,
std::string const & port,
std::string const & resource )
inline

Definition at line 186 of file uri.hpp.

188 : m_scheme(secure ? "wss" : "ws")
189 , m_host(host)
190 , m_resource(resource.empty() ? "/" : resource)
191 , m_secure(secure)
192 {
193 lib::error_code ec;
194 m_port = get_port_from_string(port,ec);
195 m_valid = !ec;
196 }

◆ uri() [5/7]

websocketpp::uri::uri ( std::string const & scheme,
std::string const & host,
uint16_t port,
std::string const & resource )
inline

Definition at line 198 of file uri.hpp.

200 : m_scheme(scheme)
201 , m_host(host)
202 , m_resource(resource.empty() ? "/" : resource)
203 , m_port(port)
204 , m_secure(scheme == "wss" || scheme == "https")
205 , m_valid(true) {}

◆ uri() [6/7]

websocketpp::uri::uri ( std::string scheme,
std::string const & host,
std::string const & resource )
inline

Definition at line 207 of file uri.hpp.

208 : m_scheme(scheme)
209 , m_host(host)
210 , m_resource(resource.empty() ? "/" : resource)
211 , m_port((scheme == "wss" || scheme == "https") ? uri_default_secure_port : uri_default_port)
212 , m_secure(scheme == "wss" || scheme == "https")
213 , m_valid(true) {}

◆ uri() [7/7]

websocketpp::uri::uri ( std::string const & scheme,
std::string const & host,
std::string const & port,
std::string const & resource )
inline

Definition at line 215 of file uri.hpp.

217 : m_scheme(scheme)
218 , m_host(host)
219 , m_resource(resource.empty() ? "/" : resource)
220 , m_secure(scheme == "wss" || scheme == "https")
221 {
222 lib::error_code ec;
223 m_port = get_port_from_string(port,ec);
224 m_valid = !ec;
225 }

Member Function Documentation

◆ get_authority()

std::string websocketpp::uri::get_authority ( ) const
inline

Definition at line 253 of file uri.hpp.

253 {
254 std::stringstream p;
255 p << m_host << ":" << m_port;
256 return p.str();
257 }
const mie::Vuint & p
Definition bn.cpp:27

◆ get_host()

std::string const & websocketpp::uri::get_host ( ) const
inline

Definition at line 239 of file uri.hpp.

239 {
240 return m_host;
241 }
Here is the caller graph for this function:

◆ get_host_port()

std::string websocketpp::uri::get_host_port ( ) const
inline

Definition at line 243 of file uri.hpp.

243 {
244 if (m_port == (m_secure ? uri_default_secure_port : uri_default_port)) {
245 return m_host;
246 } else {
247 std::stringstream p;
248 p << m_host << ":" << m_port;
249 return p.str();
250 }
251 }
Here is the caller graph for this function:

◆ get_port()

uint16_t websocketpp::uri::get_port ( ) const
inline

Definition at line 259 of file uri.hpp.

259 {
260 return m_port;
261 }
Here is the caller graph for this function:

◆ get_port_str()

std::string websocketpp::uri::get_port_str ( ) const
inline

Definition at line 263 of file uri.hpp.

263 {
264 std::stringstream p;
265 p << m_port;
266 return p.str();
267 }

◆ get_query()

std::string websocketpp::uri::get_query ( ) const
inline

Returns the query portion (after the ?) of the URI or an empty string if there is none.

Returns
query portion of the URI.

Definition at line 293 of file uri.hpp.

293 {
294 std::size_t found = m_resource.find('?');
295 if (found != std::string::npos) {
296 return m_resource.substr(found + 1);
297 } else {
298 return "";
299 }
300 }
Here is the caller graph for this function:

◆ get_resource()

std::string const & websocketpp::uri::get_resource ( ) const
inline

Definition at line 269 of file uri.hpp.

269 {
270 return m_resource;
271 }
Here is the caller graph for this function:

◆ get_scheme()

std::string const & websocketpp::uri::get_scheme ( ) const
inline

Definition at line 235 of file uri.hpp.

235 {
236 return m_scheme;
237 }
Here is the caller graph for this function:

◆ get_secure()

bool websocketpp::uri::get_secure ( ) const
inline

Definition at line 231 of file uri.hpp.

231 {
232 return m_secure;
233 }
Here is the caller graph for this function:

◆ get_valid()

bool websocketpp::uri::get_valid ( ) const
inline

Definition at line 227 of file uri.hpp.

227 {
228 return m_valid;
229 }
Here is the caller graph for this function:

◆ str()

std::string websocketpp::uri::str ( ) const
inline

Definition at line 273 of file uri.hpp.

273 {
274 std::stringstream s;
275
276 s << m_scheme << "://" << m_host;
277
278 if (m_port != (m_secure ? uri_default_secure_port : uri_default_port)) {
279 s << ":" << m_port;
280 }
281
282 s << m_resource;
283 return s.str();
284 }
char * s
Here is the caller graph for this function:

The documentation for this class was generated from the following file: