WebSocket++ 0.8.4
C++ websocket client/server library
Loading...
Searching...
No Matches
uri.hpp
1/*
2 * Copyright (c) 2014, Peter Thorson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the WebSocket++ Project nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28#ifndef WEBSOCKETPP_URI_HPP
29#define WEBSOCKETPP_URI_HPP
30
31#include <websocketpp/error.hpp>
32
33#include <websocketpp/common/memory.hpp>
34#include <websocketpp/common/stdint.hpp>
35
36#include <algorithm>
37#include <locale>
38#include <sstream>
39#include <string>
40
41namespace websocketpp {
42
43// TODO: figure out why this fixes horrible linking errors.
44
45/// Default port for ws://
46static uint16_t const uri_default_port = 80;
47/// Default port for wss://
48static uint16_t const uri_default_secure_port = 443;
49
50
51
52/// A group of helper methods for parsing and validating URIs against RFC 3986
53namespace uri_helper {
54
55/// RFC3986 unreserved character test
56/**
57 * @since 0.8.3
58 *
59 * @param c the char to test
60 * @return True if the character is considered `unreserved`
61 */
62inline bool unreserved(char c) {
63 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
64 return true;
65 } else if (c >= '0' && c <= '9') {
66 return true;
67 } else if (c == '-' || c == '.' || c == '_' || c == '~') {
68 return true;
69 } else {
70 return false;
71 }
72}
73
74/// RFC3986 generic delimiter character test
75/**
76 * @param c the char to test
77 * @return True if the character is considered a generic delimiter
78 */
79inline bool gen_delim(char c) {
80 switch(c) {
81 case ':':
82 case '/':
83 case '?':
84 case '#':
85 case '[':
86 case ']':
87 case '@':
88 return true;
89 default:
90 return false;
91 }
92}
93
94/// RFC3986 subcomponent delimiter character test
95/**
96 * @since 0.8.3
97 *
98 * @param c the char to test
99 * @return True if the character is considered a subcomponent delimiter
100 */
101inline bool sub_delim(char c) {
102 switch(c) {
103 case '!':
104 case '$':
105 case '&':
106 case '\'':
107 case '(':
108 case ')':
109 case '*':
110 case '+':
111 case ',':
112 case ';':
113 case '=':
114 return true;
115 default:
116 return false;
117 }
118}
119
120/// RFC3986 hex digit character test
121/**
122 * Case insensitive
123 *
124 * @since 0.8.3
125 *
126 * @param c the char to test
127 * @return True if the character is considered a hexadecimal digit
128 */
129inline bool hexdigit(char c) {
130 switch(c) {
131 case '0':
132 case '1':
133 case '2':
134 case '3':
135 case '4':
136 case '5':
137 case '6':
138 case '7':
139 case '8':
140 case '9':
141 case 'A':
142 case 'B':
143 case 'C':
144 case 'D':
145 case 'E':
146 case 'F':
147 case 'a':
148 case 'b':
149 case 'c':
150 case 'd':
151 case 'e':
152 case 'f':
153 return true;
154 default:
155 return false;
156 }
157}
158
159/// RFC3986 scheme character test
160/**
161 * @since 0.8.3
162 *
163 * @param c the char to test
164 * @return True if the character is considered a valid character for a uri scheme
165 */
166inline bool scheme(char c) {
167 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
168 return true;
169 } else if (c >= '0' && c <= '9') {
170 return true;
171 } else if (c == '+' || c == '-' || c == '.') {
172 return true;
173 } else {
174 return false;
175 }
176}
177
178/// RFC3986 digit character test
179/**
180 * @since 0.8.3
181 *
182 * @param c the char to test
183 * @return True if the character is considered a digit (0-9)
184 */
185inline bool digit(char c) {
186 return c >= '0' && c <= '9';
187}
188
189/// RFC3986 digit character test (iterator version)
190/**
191 * @since 0.8.3
192 *
193 * @param c the char to test
194 * @return True if the character is considered a digit (0-9)
195 */
196inline bool digit(std::string::const_iterator it) {
197 return digit(*it);
198}
199
200
201/// RFC3986 per cent encoded character test
202/**
203 * caller must range check (only caller knows the actual range)
204 * caller must check for leading %
205 *
206 * @since 0.8.3
207 *
208 * @param it An iterator to the first character after the % sign
209 * @return True if both the character pointed at by the iterator and
210 * the next one represent a valid RFC3986 percent encoding
211 */
212inline bool pct_encoded(std::string::const_iterator it) {
213 return hexdigit(*it) && hexdigit(*(it + 1));
214}
215
216/// Tests a range for a valid IPv4 decimal octet
217/**
218 * @since 0.8.3
219 *
220 * @param start An iterator to the first character of the range to check (inclusive)
221 * @param start An iterator to the last character of the range to check (exclusive)
222 * @return True if the range represents a valid IPv4 decimal octet (0-255)
223 */
224inline bool dec_octet(std::string::const_iterator start, std::string::const_iterator end) {
225 if (end-start == 1) {
226 return digit(start);
227 } else if (end-start == 2) {
228 return ((*start >= '1' && *start <= '9') && digit(start+1));
229 } else if (end-start == 3) {
230 if (*start == '1') {
231 return digit(start+1) && digit(start+2);
232 } else if (*start == '2') {
233 if (*(start+1) >= '0' && *(start+1) <= '4') {
234 return digit(start+2);
235 } else if (*(start+1) == '5') {
236 return *(start+2) >= '0' && *(start+2) <= '5';
237 }
238 }
239 }
240 return false;
241}
242
243/// Tests a range for a valid IPv4 literal
244/**
245 * @since 0.8.3
246 *
247 * @param start An iterator to the first character of the range to check (inclusive)
248 * @param start An iterator to the last character of the range to check (exclusive)
249 * @return True if the range represents a valid IPv4 literal address
250 */
251inline bool ipv4_literal(std::string::const_iterator start, std::string::const_iterator end) {
252 std::string::const_iterator cursor = start;
253 size_t counter = 0;
254 for (std::string::const_iterator it = start; it != end; ++it) {
255 if (*it == '.') {
256 if (dec_octet(cursor,it)) {
257 cursor = it+1;
258 counter++;
259 if (counter > 3) {
260 return false;
261 }
262 } else {
263 return false;
264 }
265 }
266 }
267
268 // check final octet
269 return (counter == 3 && dec_octet(cursor,end));
270}
271
272/// Tests a range for a valid IPv6 hex quad
273/**
274 * @since 0.8.3
275 *
276 * @param start An iterator to the first character of the range to check (inclusive)
277 * @param start An iterator to the last character of the range to check (exclusive)
278 * @return True if the range represents a valid IPv6 hex quad
279 */
280inline bool hex4(std::string::const_iterator start, std::string::const_iterator end) {
281 if (end-start == 0 || end-start >4) {
282 return false;
283 }
284 for (std::string::const_iterator it = start; it != end; ++it) {
285 if (!hexdigit(*it)) {
286 return false;
287 }
288 }
289 return true;
290}
291
292/// Tests a range for a valid IPv6 literal
293/**
294 * @since 0.8.3
295 *
296 * @param start An iterator to the first character of the range to check (inclusive)
297 * @param start An iterator to the last character of the range to check (exclusive)
298 * @return True if the range represents a valid IPv6 literal
299 */
300inline bool ipv6_literal(std::string::const_iterator start, std::string::const_iterator end) {
301 // initial range check
302 if (end-start > 45 && end-start >= 2) {
303 return false;
304 }
305
306 // peal off and count hex4s until we run out of colons,
307 // note the abbreviation marker if we see one.
308 std::string::const_iterator cursor = start;
309 std::string::const_iterator it = start;
310 size_t count = 0;
311 size_t abbr = 0;
312 while (it != end) {
313 if (*it == ':') {
314 if (it == start) {
315 // if a : happens at the beginning, don't check for a hex quad, just advance
316 // the cursor. The abbreviation marker will be counted on the next pass
317 cursor++;
318 } else if (it-cursor == 0) {
319 // this is a double colon abbreviation marker
320 cursor++;
321 abbr++;
322 } else if (hex4(cursor,it)) {
323 cursor = it+1;
324 count++;
325 } else {
326 return false;
327 }
328 }
329 it++;
330 }
331
332 // final bit either needs to be a hex4 or an IPv4 literal
333 if (cursor == end) {
334 // fine
335 } else if (hex4(cursor,end)) {
336 count++;
337 } else if (ipv4_literal(cursor, end)) {
338 count += 2;
339 } else {
340 return false;
341 }
342
343 if ((abbr == 0 && count != 8) || (abbr == 1 && count > 7) || abbr > 1) {
344 return false;
345 }
346
347 return true;
348}
349
350/// Tests a character for validity for a registry name
351/**
352 * will fail on %, which is valid, but only when used as a part of a multiple
353 * character escape sequence. Since this test checks a single character it
354 * can't tell whether a % character is valid so it returns false. The caller
355 * needs to catch and handle %s in another way.
356 *
357 * @since 0.8.3
358 *
359 * @param c The character to test
360 * @return True if the range represents a valid IPv6 literal
361 */
362inline bool reg_name(char c) {
363 return unreserved(c) || sub_delim(c);
364}
365
366/// Tests a range for validity for a registry name
367/**
368 * @since 0.8.3
369 *
370 * @param start An iterator to the first character of the range to check (inclusive)
371 * @param start An iterator to the last character of the range to check (exclusive)
372 * @return True if the range represents a valid registry name
373 */
374inline bool reg_name(std::string::const_iterator start, std::string::const_iterator end) {
375 std::string::const_iterator it = start;
376 while (it != end) {
377 if (*it == '%') {
378 // check for valid % encoded char
379 if (it+2 < end && uri_helper::pct_encoded(it+1)) {
380 it += 3;
381 continue;
382 } else {
383 return false;
384 }
385 } else if (!uri_helper::reg_name(*it)) {
386 return false;
387 }
388 ++it;
389 }
390 return true;
391}
392
393} // end namespace uri_helper
394
395
396
397
398class uri {
399public:
400 explicit uri(std::string const & uri_string) : m_valid(false), m_ipv6_literal(false) {
401 std::string::const_iterator it;
402 std::string::const_iterator temp;
403
404 int state = 0;
405
406 it = uri_string.begin();
407 size_t uri_len = uri_string.length();
408
409 // extract scheme. We only consider Websocket and HTTP URI schemes as valid
410 if (uri_len >= 7 && std::equal(it,it+6,"wss://")) {
411 m_secure = true;
412 m_scheme = "wss";
413 it += 6;
414 } else if (uri_len >= 6 && std::equal(it,it+5,"ws://")) {
415 m_secure = false;
416 m_scheme = "ws";
417 it += 5;
418 } else if (uri_len >= 8 && std::equal(it,it+7,"http://")) {
419 m_secure = false;
420 m_scheme = "http";
421 it += 7;
422 } else if (uri_len >= 9 && std::equal(it,it+8,"https://")) {
423 m_secure = true;
424 m_scheme = "https";
425 it += 8;
426 } else {
427 return;
428 }
429
430 // extract host.
431 // either a host string
432 // an IPv4 address
433 // or an IPv6 address
434 if (*it == '[') {
435 ++it;
436 // IPv6 literal
437 // extract IPv6 digits until ]
438
439 // TODO: this doesn't work on g++... not sure why
440 //temp = std::find(it,it2,']');
441
442 temp = it;
443 while (temp != uri_string.end()) {
444 if (*temp == ']') {
445 break;
446 }
447 ++temp;
448 }
449
450 if (temp == uri_string.end()) {
451 return;
452 } else {
453 // validate IPv6 literal parts
454 if (!uri_helper::ipv6_literal(it,temp)) {
455 return;
456 } else {
457 m_ipv6_literal = true;
458 }
459 m_host.append(it,temp);
460 }
461 it = temp+1;
462 if (it == uri_string.end()) {
463 state = 2;
464 } else if (*it == '/' || *it == '?' || *it == '#') {
465 // todo: better path parsing
466 state = 2;
467
468 // we don't increment the iterator here because we want the
469 // delimiter to be read again as a part of the path
470 } else if (*it == ':') {
471 state = 1;
472
473 // start reading port after the delimiter
474 ++it;
475 } else {
476 // problem
477 return;
478 }
479 } else {
480 // IPv4 or hostname
481 // extract until : or first path component
482 while (state == 0) {
483 if (it == uri_string.end()) {
484 state = 2;
485 break;
486 } else if (*it == '%') {
487 // check for valid % encoded char
488 if (it+2 < uri_string.end() && uri_helper::pct_encoded(it+1)) {
489 m_host.append(it,it+2);
490 it += 3;
491 }
492 } else if (!uri_helper::reg_name(*it)) {
493 // we hit one of the general delimiters
494 if (*it == ':') {
495 // got host vs port delimiter
496 // end hostname start port
497 state = 1;
498
499 // start reading port after the delimiter
500 ++it;
501 } else if (*it == '/' || *it == '#' || *it == '?') {
502 // one of the normal authority vs path delimiters
503 // end hostname and start parsing path
504 state = 2;
505
506 // we don't increment the iterator here because we want the
507 // delimiter to be read again as a part of the path
508 } else {
509 // either @, [, or ]
510 // @ = userinfo fragment
511 // [ and ] = illegal, basically
512 return;
513 }
514 } else {
515 m_host += *it;
516 ++it;
517 }
518
519 }
520 }
521
522 // parse port
523 std::string port;
524 while (state == 1) {
525 if (it == uri_string.end()) {
526 // if we stop parsing the port and there wasn't actually a port
527 // we have an invalid URI
528 if (port.empty()) {
529 return;
530 }
531 state = 3;
532 } else if (uri_helper::digit(it)) {
533 port += *it;
534 ++it;
535 } else {
536 // if we stop parsing the port and there wasn't actually a port
537 // we have an invalid URI
538 if (port.empty()) {
539 return;
540 }
541 state = 3;
542
543 // we don't increment the iterator here because we want the
544 // delimiter to be read again as a part of the path
545 }
546
547 }
548
549 lib::error_code ec;
550 m_port = get_port_from_string(port, ec);
551
552 if (ec) {
553 return;
554 }
555
556 // step back one so the first char of the path delimiter doesn't get eaten
557 m_resource.append(it,uri_string.end());
558
559 if (m_resource.empty()) {
560 m_resource = "/";
561 }
562
563 // todo: validate path component
564
565
566 m_valid = true;
567 }
568
569 uri(bool secure, std::string const & host, uint16_t port,
570 std::string const & resource)
571 : m_scheme(secure ? "wss" : "ws")
572 , m_host(host)
573 , m_resource(resource.empty() ? "/" : resource)
574 , m_port(port)
575 , m_secure(secure)
576 {
577 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
578 m_valid = m_ipv6_literal || uri_helper::reg_name(host.begin(), host.end());
579 }
580
581 uri(bool secure, std::string const & host, std::string const & resource)
582 : m_scheme(secure ? "wss" : "ws")
583 , m_host(host)
584 , m_resource(resource.empty() ? "/" : resource)
585 , m_port(secure ? uri_default_secure_port : uri_default_port)
586 , m_secure(secure)
587 {
588 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
589 m_valid = m_ipv6_literal || uri_helper::reg_name(host.begin(), host.end());
590 }
591
592 uri(bool secure, std::string const & host, std::string const & port,
593 std::string const & resource)
594 : m_scheme(secure ? "wss" : "ws")
595 , m_host(host)
596 , m_resource(resource.empty() ? "/" : resource)
597 , m_secure(secure)
598 {
599 lib::error_code ec;
600 m_port = get_port_from_string(port,ec);
601 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
602
603 m_valid = !ec && (m_ipv6_literal || uri_helper::reg_name(host.begin(), host.end()));
604 }
605
606 uri(std::string const & scheme, std::string const & host, uint16_t port,
607 std::string const & resource)
608 : m_scheme(scheme)
609 , m_host(host)
610 , m_resource(resource.empty() ? "/" : resource)
611 , m_port(port)
612 , m_secure(scheme == "wss" || scheme == "https")
613 {
614 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
615 m_valid = m_ipv6_literal || uri_helper::reg_name(host.begin(), host.end());
616 }
617
618 uri(std::string scheme, std::string const & host, std::string const & resource)
619 : m_scheme(scheme)
620 , m_host(host)
621 , m_resource(resource.empty() ? "/" : resource)
622 , m_port((scheme == "wss" || scheme == "https") ? uri_default_secure_port : uri_default_port)
623 , m_secure(scheme == "wss" || scheme == "https")
624 {
625 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
626 m_valid = m_ipv6_literal || uri_helper::reg_name(host.begin(), host.end());
627 }
628
629 uri(std::string const & scheme, std::string const & host,
630 std::string const & port, std::string const & resource)
631 : m_scheme(scheme)
632 , m_host(host)
633 , m_resource(resource.empty() ? "/" : resource)
634 , m_secure(scheme == "wss" || scheme == "https")
635 {
636 lib::error_code ec;
637 m_port = get_port_from_string(port,ec);
638 m_ipv6_literal = uri_helper::ipv6_literal(host.begin(), host.end());
639
640 m_valid = !ec && (m_ipv6_literal || uri_helper::reg_name(host.begin(), host.end()));
641 }
642
643 bool get_valid() const {
644 return m_valid;
645 }
646
647 // Check whether the host of this URI is an IPv6 literal address
648 /**
649 * @since 0.8.3
650 * @return True if the host of this URI is an IPv6 literal address
651 */
652 bool is_ipv6_literal() const {
653 return m_ipv6_literal;
654 }
655
656 bool get_secure() const {
657 return m_secure;
658 }
659
660 std::string const & get_scheme() const {
661 return m_scheme;
662 }
663
664 std::string const & get_host() const {
665 return m_host;
666 }
667
668 std::string get_host_port() const {
669 if (m_port == (m_secure ? uri_default_secure_port : uri_default_port)) {
670 // todo: should this have brackets for v6?
671 return m_host;
672 } else {
673 std::stringstream p;
674 p.imbue(std::locale::classic());
675 if (m_ipv6_literal) {
676 p << "[" << m_host << "]:" << m_port;
677 } else {
678 p << m_host << ":" << m_port;
679 }
680
681 return p.str();
682 }
683 }
684
685 std::string get_authority() const {
686 std::stringstream p;
687 p.imbue(std::locale::classic());
688 if (m_ipv6_literal) {
689 p << "[" << m_host << "]:" << m_port;
690 } else {
691 p << m_host << ":" << m_port;
692 }
693 return p.str();
694 }
695
696 uint16_t get_port() const {
697 return m_port;
698 }
699
700 std::string get_port_str() const {
701 std::stringstream p;
702 p.imbue(std::locale::classic());
703 p << m_port;
704 return p.str();
705 }
706
707 std::string const & get_resource() const {
708 return m_resource;
709 }
710
711 std::string str() const {
712 std::stringstream s;
713 s.imbue(std::locale::classic());
714
715 s << m_scheme << "://";
716 if (m_ipv6_literal) {
717 s << "[" << m_host << "]";
718 } else {
719 s << m_host;
720 }
721
722 if (m_port != (m_secure ? uri_default_secure_port : uri_default_port)) {
723 s << ":" << m_port;
724 }
725
726 s << m_resource;
727 return s.str();
728 }
729
730 /// Return the query portion
731 /**
732 * Returns the query portion (after the ?) of the URI or an empty string if
733 * there is none.
734 *
735 * @return query portion of the URI.
736 */
737 std::string get_query() const {
738 std::size_t found = m_resource.find('?');
739 if (found != std::string::npos) {
740 return m_resource.substr(found + 1);
741 } else {
742 return "";
743 }
744 }
745
746 // get fragment
747
748 // hi <3
749
750 // get the string representation of this URI
751
752 //std::string base() const; // is this still needed?
753
754 // setter methods set some or all (in the case of parse) based on the input.
755 // These functions throw a uri_exception on failure.
756 /*void set_uri(const std::string& uri);
757
758 void set_secure(bool secure);
759 void set_host(const std::string& host);
760 void set_port(uint16_t port);
761 void set_port(const std::string& port);
762 void set_resource(const std::string& resource);*/
763private:
764 uint16_t get_port_from_string(std::string const & port, lib::error_code &
765 ec) const
766 {
767 ec = lib::error_code();
768
769 if (port.empty()) {
770 return (m_secure ? uri_default_secure_port : uri_default_port);
771 }
772
773 unsigned int t_port = static_cast<unsigned int>(atoi(port.c_str()));
774
775 if (t_port > 65535) {
776 ec = error::make_error_code(error::invalid_port);
777 }
778
779 if (t_port == 0) {
780 ec = error::make_error_code(error::invalid_port);
781 }
782
783 return static_cast<uint16_t>(t_port);
784 }
785
786 std::string m_scheme;
787 std::string m_host;
788 std::string m_resource;
789 uint16_t m_port;
790 bool m_secure;
791 bool m_valid;
792 bool m_ipv6_literal;
793};
794
795/// Pointer to a URI
796typedef lib::shared_ptr<uri> uri_ptr;
797
798} // namespace websocketpp
799
800#endif // WEBSOCKETPP_URI_HPP
#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.
Definition basic.hpp:37
Stub for user supplied base class.
Stub for user supplied base class.
Stub class for use when disabling permessage_deflate extension.
Definition disabled.hpp:53
Stores, parses, and manipulates HTTP requests.
Definition request.hpp:50
Stores, parses, and manipulates HTTP responses.
Definition response.hpp:57
Basic logger that outputs to an ostream.
Definition basic.hpp:59
Thread safe stub "random" integer generator.
Definition none.hpp:46
Server endpoint role based on the given config.
Basic ASIO endpoint socket component.
Definition none.hpp:323
Asio based endpoint transport component.
Definition endpoint.hpp:54
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 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
Definition endpoint.hpp:62
config::elog_type elog_type
Type of this endpoint's error logging policy.
Definition endpoint.hpp:56
void set_write_handler(write_handler h)
Sets the write handler.
Definition endpoint.hpp:134
void set_shutdown_handler(shutdown_handler h)
Sets the shutdown handler.
Definition endpoint.hpp:154
bool is_secure() const
Tests whether or not the underlying transport is secure.
Definition endpoint.hpp:116
lib::shared_ptr< type > ptr
Type of a pointer to this endpoint transport component.
Definition endpoint.hpp:51
transport_con_type::ptr transport_con_ptr
Definition endpoint.hpp:65
void async_connect(transport_con_ptr, uri_ptr, connect_handler cb)
Initiate a new connection.
Definition endpoint.hpp:183
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
Definition endpoint.hpp:197
void init_logging(lib::shared_ptr< alog_type > a, lib::shared_ptr< elog_type > e)
Initialize logging.
Definition endpoint.hpp:171
endpoint type
Type of this endpoint transport component.
Definition endpoint.hpp:49
void register_ostream(std::ostream *o)
Register a default output stream.
Definition endpoint.hpp:80
config::concurrency_type concurrency_type
Type of this endpoint's concurrency policy.
Definition endpoint.hpp:54
void set_secure(bool value)
Set whether or not endpoint can create secure connections.
Definition endpoint.hpp:102
config::alog_type alog_type
Type of this endpoint's access logging policy.
Definition endpoint.hpp:58
iostream transport error category
Definition base.hpp:85
std::string get_query() const
Return the query portion.
Definition uri.hpp:737
bool is_ipv6_literal() const
Definition uri.hpp:652
#define _WEBSOCKETPP_NOEXCEPT_TOKEN_
Definition cpp11.hpp:115
#define __has_extension
Definition cpp11.hpp:40
#define __has_feature(x)
Definition cpp11.hpp:37
Concurrency handling support.
Definition basic.hpp:34
Library level error codes.
Definition error.hpp:44
@ invalid_port
Invalid port in URI.
Definition error.hpp:120
Implementation of RFC 7692, the permessage-deflate WebSocket extension.
Definition disabled.hpp:44
HTTP handling support.
Definition request.hpp:37
Stub RNG policy that always returns 0.
Definition none.hpp:35
Random number generation policies.
Transport policy that uses asio.
Definition endpoint.hpp:46
Generic transport related errors.
@ pass_through
underlying transport pass through
@ operation_not_supported
Operation not supported.
@ operation_aborted
Operation aborted.
@ 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
Definition base.hpp:64
@ invalid_num_bytes
async_read_at_least call requested more bytes than buffer can store
Definition base.hpp:71
@ double_read
async_read called while another async_read was in progress
Definition base.hpp:74
lib::error_code make_error_code(error::value e)
Get an error code with the given value and the iostream transport category.
Definition base.hpp:118
lib::error_category const & get_category()
Get a reference to a static copy of the iostream transport error category.
Definition base.hpp:112
Transport policy that uses STL iostream for I/O and does not support timers.
Definition endpoint.hpp:43
lib::function< lib::error_code(connection_hdl, std::vector< transport::buffer > const &bufs)> vector_write_handler
Definition base.hpp:57
lib::function< lib::error_code(connection_hdl)> shutdown_handler
Definition base.hpp:61
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.
Definition base.hpp:48
Transport policies provide network connectivity and timers.
Definition endpoint.hpp:45
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.
Definition endpoint.hpp:80
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.
Definition endpoint.hpp:83
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.
Definition uri.hpp:53
bool digit(char c)
RFC3986 digit character test.
Definition uri.hpp:185
bool gen_delim(char c)
RFC3986 generic delimiter character test.
Definition uri.hpp:79
bool digit(std::string::const_iterator it)
RFC3986 digit character test (iterator version).
Definition uri.hpp:196
bool ipv4_literal(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv4 literal.
Definition uri.hpp:251
bool sub_delim(char c)
RFC3986 subcomponent delimiter character test.
Definition uri.hpp:101
bool reg_name(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for validity for a registry name.
Definition uri.hpp:374
bool pct_encoded(std::string::const_iterator it)
RFC3986 per cent encoded character test.
Definition uri.hpp:212
bool scheme(char c)
RFC3986 scheme character test.
Definition uri.hpp:166
bool unreserved(char c)
RFC3986 unreserved character test.
Definition uri.hpp:62
bool reg_name(char c)
Tests a character for validity for a registry name.
Definition uri.hpp:362
bool hex4(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv6 hex quad.
Definition uri.hpp:280
bool dec_octet(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv4 decimal octet.
Definition uri.hpp:224
bool ipv6_literal(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv6 literal.
Definition uri.hpp:300
bool hexdigit(char c)
RFC3986 hex digit character test.
Definition uri.hpp:129
Namespace for the WebSocket++ project.
static uint16_t const uri_default_secure_port
Default port for wss://.
Definition uri.hpp:48
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
static uint16_t const uri_default_port
Default port for ws://.
Definition uri.hpp:46
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Definition uri.hpp:796
Server config with asio transport and TLS disabled.
static const bool allow_disabling_context_takeover
Maximum size (in bytes) of a decompressed message.
Definition core.hpp:275
static const long timeout_socket_shutdown
Length of time to wait for socket shutdown.
Definition core.hpp:137
static const long timeout_connect
Length of time to wait for TCP connect.
Definition core.hpp:134
static const long timeout_dns_resolve
Length of time to wait for dns resolution.
Definition core.hpp:131
static const long timeout_proxy
Length of time to wait before a proxy handshake is aborted.
Definition core.hpp:121
static const long timeout_socket_pre_init
Default timer values (in ms).
Definition core.hpp:118
static const long timeout_socket_post_init
Length of time to wait for socket post-initialization.
Definition core.hpp:128
Server config with iostream transport.
Definition core.hpp:68
websocketpp::random::none::int_generator< uint32_t > rng_type
RNG policies.
Definition core.hpp:93
static const websocketpp::log::level elog_level
Default static error logging channels.
Definition core.hpp:176
websocketpp::transport::iostream::endpoint< transport_config > transport_type
Transport Endpoint Component.
Definition core.hpp:142
static const size_t max_http_body_size
Default maximum http body size.
Definition core.hpp:252
static const long timeout_open_handshake
Default timer values (in ms).
Definition core.hpp:152
static const size_t max_message_size
Default maximum message size.
Definition core.hpp:240
static const bool drop_on_protocol_error
Drop connections immediately on protocol error.
Definition core.hpp:213
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
Definition core.hpp:154
static const websocketpp::log::level alog_level
Default static access logging channels.
Definition core.hpp:189
websocketpp::log::basic< concurrency_type, websocketpp::log::elevel > elog_type
Logging policies.
Definition core.hpp:88
static const long timeout_pong
Length of time to wait for a pong after a ping.
Definition core.hpp:156
static const bool silent_close
Suppresses the return of detailed connection close information.
Definition core.hpp:228
static bool const enable_multithreading
Definition core.hpp:98
static const size_t connection_read_buffer_size
Size of the per-connection read buffer.
Definition core.hpp:204
static const bool enable_extensions
Global flag for enabling/disabling extensions.
Definition core.hpp:255
static const int client_version
WebSocket Protocol version to use as a client.
Definition core.hpp:164
Package of log levels for logging access events.
Definition levels.hpp:112
static level const devel
Development messages (warning: very chatty).
Definition levels.hpp:141
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:152
Package of log levels for logging errors.
Definition levels.hpp:59
static level const devel
Low level debugging information (warning: very chatty).
Definition levels.hpp:63
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:80
A simple utility buffer class.
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_