2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
28#ifndef WEBSOCKETPP_URI_HPP
29#define WEBSOCKETPP_URI_HPP
31#include <websocketpp/error.hpp>
33#include <websocketpp/common/memory.hpp>
34#include <websocketpp/common/stdint.hpp>
56
57
58
59
60
62 if ((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z')) {
64 }
else if (c >=
'0' && c <=
'9') {
66 }
else if (c ==
'-' || c ==
'.' || c ==
'_' || c ==
'~') {
75
76
77
95
96
97
98
99
121
122
123
124
125
126
127
160
161
162
163
164
166 if ((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z')) {
168 }
else if (c >=
'0' && c <=
'9') {
170 }
else if (c ==
'+' || c ==
'-' || c ==
'.') {
179
180
181
182
183
185 return c >=
'0' && c <=
'9';
190
191
192
193
194
195inline bool digit(std::string::const_iterator it) {
202
203
204
205
206
207
208
209
210
212 return hexdigit(*it) && hexdigit(*(it + 1));
217
218
219
220
221
222
223inline bool dec_octet(std::string::const_iterator start, std::string::const_iterator end) {
224 if (end-start == 1) {
226 }
else if (end-start == 2) {
227 return ((*start >=
'1' && *start <=
'9') && digit(start+1));
228 }
else if (end-start == 3) {
230 return digit(start+1) && digit(start+2);
231 }
else if (*start ==
'2') {
232 if (*(start+1) >=
'0' && *(start+1) <=
'4') {
233 return digit(start+2);
234 }
else if (*(start+1) ==
'5') {
235 return *(start+2) >=
'0' && *(start+2) <=
'5';
244
245
246
247
248
249
250inline bool ipv4_literal(std::string::const_iterator start, std::string::const_iterator end) {
251 std::string::const_iterator cursor = start;
253 for (std::string::const_iterator it = start; it != end; ++it) {
255 if (dec_octet(cursor,it)) {
268 return (counter == 3 && dec_octet(cursor,end));
273
274
275
276
277
278
279inline bool hex4(std::string::const_iterator start, std::string::const_iterator end) {
280 if (end-start == 0 || end-start >4) {
283 for (std::string::const_iterator it = start; it != end; ++it) {
284 if (!hexdigit(*it)) {
293
294
295
296
297
298
299inline bool ipv6_literal(std::string::const_iterator start, std::string::const_iterator end) {
301 if (end-start > 45 && end-start >= 2) {
307 std::string::const_iterator cursor = start;
308 std::string::const_iterator it = start;
317 }
else if (it-cursor == 0) {
321 }
else if (hex4(cursor,it)) {
334 }
else if (hex4(cursor,end)) {
336 }
else if (ipv4_literal(cursor, end)) {
342 if ((abbr == 0 && count != 8) || (abbr == 1 && count > 7) || abbr > 1) {
351
352
353
354
355
356
357
358
359
360
367
368
369
370
371
372
373inline bool reg_name(std::string::const_iterator start, std::string::const_iterator end) {
374 std::string::const_iterator it = start;
378 if (it+2 < end && uri_helper::pct_encoded(it+1)) {
399 explicit uri(std::string
const & uri_string) : m_valid(
false), m_ipv6_literal(
false) {
400 std::string::const_iterator it;
401 std::string::const_iterator temp;
405 it = uri_string.begin();
406 size_t uri_len = uri_string.length();
409 if (uri_len >= 7 && std::equal(it,it+6,
"wss://")) {
413 }
else if (uri_len >= 6 && std::equal(it,it+5,
"ws://")) {
417 }
else if (uri_len >= 8 && std::equal(it,it+7,
"http://")) {
421 }
else if (uri_len >= 9 && std::equal(it,it+8,
"https://")) {
442 while (temp != uri_string.end()) {
449 if (temp == uri_string.end()) {
453 if (!uri_helper::ipv6_literal(it,temp)) {
456 m_ipv6_literal =
true;
458 m_host.append(it,temp);
461 if (it == uri_string.end()) {
463 }
else if (*it ==
'/' || *it ==
'?' || *it ==
'#') {
469 }
else if (*it ==
':') {
482 if (it == uri_string.end()) {
485 }
else if (*it ==
'%') {
487 if (it+2 < uri_string.end() && uri_helper::pct_encoded(it+1)) {
488 m_host.append(it,it+2);
500 }
else if (*it ==
'/' || *it ==
'#' || *it ==
'?') {
524 if (it == uri_string.end()) {
549 m_port = get_port_from_string(port, ec);
556 m_resource.append(it,uri_string.end());
558 if (m_resource.empty()) {
568 uri(
bool secure, std::string
const & host, uint16_t port,
569 std::string
const & resource)
570 : m_scheme(secure ?
"wss" :
"ws")
572 , m_resource(resource.empty() ?
"/" : resource)
576 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
580 uri(
bool secure, std::string
const & host, std::string
const & resource)
581 : m_scheme(secure ?
"wss" :
"ws")
583 , m_resource(resource.empty() ?
"/" : resource)
587 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
591 uri(
bool secure, std::string
const & host, std::string
const & port,
592 std::string
const & resource)
593 : m_scheme(secure ?
"wss" :
"ws")
595 , m_resource(resource.empty() ?
"/" : resource)
599 m_port = get_port_from_string(port,ec);
600 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
605 uri(std::string
const & scheme, std::string
const & host, uint16_t port,
606 std::string
const & resource)
609 , m_resource(resource.empty() ?
"/" : resource)
611 , m_secure(scheme ==
"wss" || scheme ==
"https")
613 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
617 uri(std::string scheme, std::string
const & host, std::string
const & resource)
620 , m_resource(resource.empty() ?
"/" : resource)
622 , m_secure(scheme ==
"wss" || scheme ==
"https")
624 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
628 uri(std::string
const & scheme, std::string
const & host,
629 std::string
const & port, std::string
const & resource)
632 , m_resource(resource.empty() ?
"/" : resource)
633 , m_secure(scheme ==
"wss" || scheme ==
"https")
636 m_port = get_port_from_string(port,ec);
637 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
642 bool get_valid()
const {
648
649
650
652 return m_ipv6_literal;
655 bool get_secure()
const {
659 std::string
const & get_scheme()
const {
663 std::string
const & get_host()
const {
667 std::string get_host_port()
const {
673 if (m_ipv6_literal) {
674 p <<
"[" << m_host <<
"]:" << m_port;
676 p << m_host <<
":" << m_port;
683 std::string get_authority()
const {
685 if (m_ipv6_literal) {
686 p <<
"[" << m_host <<
"]:" << m_port;
688 p << m_host <<
":" << m_port;
693 uint16_t get_port()
const {
697 std::string get_port_str()
const {
703 std::string
const & get_resource()
const {
707 std::string str()
const {
710 s << m_scheme <<
"://";
711 if (m_ipv6_literal) {
712 s <<
"[" << m_host <<
"]";
727
728
729
730
731
733 std::size_t found = m_resource.find(
'?');
734 if (found != std::string::npos) {
735 return m_resource.substr(found + 1);
752
753
754
755
756
757
759 uint16_t get_port_from_string(std::string
const & port, lib::error_code &
762 ec = lib::error_code();
768 unsigned int t_port =
static_cast<
unsigned int>(atoi(port.c_str()));
770 if (t_port > 65535) {
778 return static_cast<uint16_t>(t_port);
781 std::string m_scheme;
783 std::string m_resource;
#define _WEBSOCKETPP_CPP11_FUNCTIONAL_
#define _WEBSOCKETPP_CPP11_THREAD_
#define _WEBSOCKETPP_CPP11_MEMORY_
#define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_
Concurrency policy that uses std::mutex / boost::mutex.
Stub for user supplied base class.
Stub for user supplied base class.
Stub class for use when disabling permessage_deflate extension.
Stores, parses, and manipulates HTTP requests.
Stores, parses, and manipulates HTTP responses.
Basic logger that outputs to an ostream.
Thread safe stub "random" integer generator.
Server endpoint role based on the given config.
Basic ASIO endpoint socket component.
Asio based endpoint transport component.
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.
connection_hdl get_handle() const
Get the connection handle.
config::alog_type alog_type
Type of this transport's access logging policy.
lib::error_code dispatch(dispatch_handler handler)
Call given handler back within the transport's event system (if present).
void set_uri(uri_ptr)
Set uri hook.
void async_shutdown(transport::shutdown_handler handler)
Perform cleanup on socket shutdown_handler.
void set_write_handler(write_handler h)
Sets the write handler.
void set_secure(bool value)
Set whether or not this connection is secure.
void set_shutdown_handler(shutdown_handler h)
Sets the shutdown handler.
connection< config > type
Type of this connection transport component.
config::elog_type elog_type
Type of this transport's error logging policy.
void fatal_error()
Signal transport error.
size_t read_some(char const *buf, size_t len)
Manual input supply (read some).
size_t read_all(char const *buf, size_t len)
Manual input supply (read all).
void async_write(char const *buf, size_t len, transport::write_handler handler)
Asyncronous Transport Write.
size_t readsome(char const *buf, size_t len)
Manual input supply (DEPRECATED).
config::concurrency_type concurrency_type
transport concurrency policy
void init(init_handler handler)
Initialize the connection transport.
timer_ptr set_timer(long, timer_handler)
Call back a function after a period of time.
friend std::istream & operator>>(std::istream &in, type &t)
Overloaded stream input operator.
void set_vector_write_handler(vector_write_handler h)
Sets the vectored write handler.
bool is_secure() const
Tests whether or not the underlying transport is secure.
std::string get_remote_endpoint() const
Get human readable remote endpoint address.
void set_handle(connection_hdl hdl)
Set Connection Handle.
void register_ostream(std::ostream *o)
Register a std::ostream with the transport for writing output.
void async_read_at_least(size_t num_bytes, char *buf, size_t len, read_handler handler)
Initiate an async_read for at least num_bytes bytes into buf.
void async_write(std::vector< buffer > const &bufs, transport::write_handler handler)
Asyncronous Transport Write (scatter-gather).
ptr get_shared()
Get a shared pointer to this component.
iostream::connection< config > transport_con_type
config::elog_type elog_type
Type of this endpoint's error logging policy.
void set_write_handler(write_handler h)
Sets the write handler.
void set_shutdown_handler(shutdown_handler h)
Sets the shutdown handler.
bool is_secure() const
Tests whether or not the underlying transport is secure.
lib::shared_ptr< type > ptr
Type of a pointer to this endpoint transport component.
transport_con_type::ptr transport_con_ptr
void async_connect(transport_con_ptr, uri_ptr, connect_handler cb)
Initiate a new connection.
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
void init_logging(lib::shared_ptr< alog_type > a, lib::shared_ptr< elog_type > e)
Initialize logging.
endpoint type
Type of this endpoint transport component.
void register_ostream(std::ostream *o)
Register a default output stream.
config::concurrency_type concurrency_type
Type of this endpoint's concurrency policy.
void set_secure(bool value)
Set whether or not endpoint can create secure connections.
config::alog_type alog_type
Type of this endpoint's access logging policy.
iostream transport error category
std::string get_query() const
Return the query portion.
bool is_ipv6_literal() const
#define _WEBSOCKETPP_NOEXCEPT_TOKEN_
Concurrency handling support.
Library level error codes.
@ invalid_port
Invalid port in URI.
Implementation of RFC 7692, the permessage-deflate WebSocket extension.
Stub RNG policy that always returns 0.
Random number generation policies.
Transport policy that uses asio.
Generic transport related errors.
@ pass_through
underlying transport pass through
@ operation_not_supported
Operation not supported.
@ operation_aborted
Operation aborted.
@ tls_error
Other TLS error.
@ invalid_num_bytes
async_read_at_least call requested more bytes than buffer can store
@ action_after_shutdown
read or write after shutdown
@ tls_short_read
TLS short read.
@ double_read
async_read called while another async_read was in progress
iostream transport errors
@ invalid_num_bytes
async_read_at_least call requested more bytes than buffer can store
@ double_read
async_read called while another async_read was in progress
lib::error_code make_error_code(error::value e)
Get an error code with the given value and the iostream transport category.
lib::error_category const & get_category()
Get a reference to a static copy of the iostream transport error category.
Transport policy that uses STL iostream for I/O and does not support timers.
lib::function< lib::error_code(connection_hdl, std::vector< transport::buffer > const &bufs)> vector_write_handler
lib::function< lib::error_code(connection_hdl)> shutdown_handler
lib::function< lib::error_code(connection_hdl, char const *, size_t)> write_handler
The type and signature of the callback used by iostream transport to write.
Transport policies provide network connectivity and timers.
lib::function< void(lib::error_code const &, size_t)> read_handler
The type and signature of the callback passed to the read method.
lib::function< void()> dispatch_handler
The type and signature of the callback passed to the dispatch method.
lib::function< void()> interrupt_handler
The type and signature of the callback passed to the interrupt method.
lib::function< void(lib::error_code const &)> accept_handler
The type and signature of the callback passed to the accept method.
lib::function< void(lib::error_code const &)> timer_handler
The type and signature of the callback passed to the read method.
lib::function< void(lib::error_code const &)> connect_handler
The type and signature of the callback passed to the connect method.
lib::function< void(lib::error_code const &)> write_handler
The type and signature of the callback passed to the write method.
lib::function< void(lib::error_code const &)> init_handler
The type and signature of the callback passed to the init hook.
lib::function< void(lib::error_code const &)> shutdown_handler
The type and signature of the callback passed to the shutdown method.
A group of helper methods for parsing and validating URIs against RFC 3986.
bool digit(char c)
RFC3986 digit character test.
bool gen_delim(char c)
RFC3986 generic delimiter character test.
bool digit(std::string::const_iterator it)
RFC3986 digit character test (iterator version).
bool ipv4_literal(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv4 literal.
bool sub_delim(char c)
RFC3986 subcomponent delimiter character test.
bool reg_name(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for validity for a registry name.
bool pct_encoded(std::string::const_iterator it)
RFC3986 per cent encoded character test.
bool scheme(char c)
RFC3986 scheme character test.
bool unreserved(char c)
RFC3986 unreserved character test.
bool reg_name(char c)
Tests a character for validity for a registry name.
bool hex4(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv6 hex quad.
bool dec_octet(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv4 decimal octet.
bool ipv6_literal(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv6 literal.
bool hexdigit(char c)
RFC3986 hex digit character test.
Namespace for the WebSocket++ project.
static uint16_t const uri_default_secure_port
Default port for wss://.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
static uint16_t const uri_default_port
Default port for ws://.
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Server config with asio transport and TLS disabled.
Extension specific settings:
static const uint8_t minimum_outgoing_window_bits
static const bool allow_disabling_context_takeover
static const long timeout_socket_shutdown
Length of time to wait for socket shutdown.
static const long timeout_connect
Length of time to wait for TCP connect.
static const long timeout_dns_resolve
Length of time to wait for dns resolution.
static const long timeout_proxy
Length of time to wait before a proxy handshake is aborted.
static const long timeout_socket_pre_init
Default timer values (in ms).
static bool const enable_multithreading
static const long timeout_socket_post_init
Length of time to wait for socket post-initialization.
Server config with iostream transport.
websocketpp::random::none::int_generator< uint32_t > rng_type
RNG policies.
static const websocketpp::log::level elog_level
Default static error logging channels.
websocketpp::transport::iostream::endpoint< transport_config > transport_type
Transport Endpoint Component.
static const size_t max_http_body_size
Default maximum http body size.
static const long timeout_open_handshake
Default timer values (in ms).
static const size_t max_message_size
Default maximum message size.
static const bool drop_on_protocol_error
Drop connections immediately on protocol error.
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
static const websocketpp::log::level alog_level
Default static access logging channels.
websocketpp::log::basic< concurrency_type, websocketpp::log::elevel > elog_type
Logging policies.
static const long timeout_pong
Length of time to wait for a pong after a ping.
static const bool silent_close
Suppresses the return of detailed connection close information.
static bool const enable_multithreading
static const size_t connection_read_buffer_size
Size of the per-connection read buffer.
static const bool enable_extensions
Global flag for enabling/disabling extensions.
static const int client_version
WebSocket Protocol version to use as a client.
Package of log levels for logging access events.
static level const devel
Development messages (warning: very chatty).
static level const all
Special aggregate value representing "all levels".
Package of log levels for logging errors.
static level const devel
Low level debugging information (warning: very chatty).
static level const all
Special aggregate value representing "all levels".
A simple utility buffer class.
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_