├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── CONTRIBUTING.md ├── DESCRIPTION ├── LICENSE.note ├── NAMESPACE ├── NEWS.md ├── R ├── cpp11.R └── websocket.R ├── README.md ├── cleanup ├── configure ├── cran-comments.md ├── man ├── WebSocket.Rd └── figures │ └── logo.svg ├── pkgdown ├── _pkgdown.yml └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── revdep ├── .gitignore ├── README.md ├── cran.md ├── failures.md └── problems.md ├── src ├── .gitignore ├── Makevars.in ├── Makevars.ucrt ├── Makevars.win ├── README.md ├── client.hpp ├── cpp11.cpp ├── debug.cpp ├── debug.h ├── lib │ ├── update.sh │ └── websocketpp │ │ ├── base64 │ │ └── base64.hpp │ │ ├── client.hpp │ │ ├── close.hpp │ │ ├── common │ │ ├── asio.hpp │ │ ├── asio_ssl.hpp │ │ ├── chrono.hpp │ │ ├── connection_hdl.hpp │ │ ├── cpp11.hpp │ │ ├── functional.hpp │ │ ├── md5.hpp │ │ ├── memory.hpp │ │ ├── network.hpp │ │ ├── platforms.hpp │ │ ├── random.hpp │ │ ├── regex.hpp │ │ ├── stdint.hpp │ │ ├── system_error.hpp │ │ ├── thread.hpp │ │ ├── time.hpp │ │ └── type_traits.hpp │ │ ├── concurrency │ │ ├── basic.hpp │ │ └── none.hpp │ │ ├── config │ │ ├── asio.hpp │ │ ├── asio_client.hpp │ │ ├── asio_no_tls.hpp │ │ ├── asio_no_tls_client.hpp │ │ ├── boost_config.hpp │ │ ├── core.hpp │ │ ├── core_client.hpp │ │ ├── debug.hpp │ │ ├── debug_asio.hpp │ │ ├── debug_asio_no_tls.hpp │ │ ├── minimal_client.hpp │ │ └── minimal_server.hpp │ │ ├── connection.hpp │ │ ├── connection_base.hpp │ │ ├── endpoint.hpp │ │ ├── endpoint_base.hpp │ │ ├── error.hpp │ │ ├── extensions │ │ ├── extension.hpp │ │ └── permessage_deflate │ │ │ ├── disabled.hpp │ │ │ └── enabled.hpp │ │ ├── frame.hpp │ │ ├── http │ │ ├── constants.hpp │ │ ├── impl │ │ │ ├── parser.hpp │ │ │ ├── request.hpp │ │ │ └── response.hpp │ │ ├── parser.hpp │ │ ├── request.hpp │ │ └── response.hpp │ │ ├── impl │ │ ├── connection_impl.hpp │ │ ├── endpoint_impl.hpp │ │ └── utilities_impl.hpp │ │ ├── logger │ │ ├── basic.hpp │ │ ├── levels.hpp │ │ ├── stub.hpp │ │ └── syslog.hpp │ │ ├── message_buffer │ │ ├── alloc.hpp │ │ ├── message.hpp │ │ └── pool.hpp │ │ ├── processors │ │ ├── base.hpp │ │ ├── hybi00.hpp │ │ ├── hybi07.hpp │ │ ├── hybi08.hpp │ │ ├── hybi13.hpp │ │ └── processor.hpp │ │ ├── random │ │ ├── none.hpp │ │ └── random_device.hpp │ │ ├── roles │ │ ├── client_endpoint.hpp │ │ └── server_endpoint.hpp │ │ ├── server.hpp │ │ ├── sha1 │ │ └── sha1.hpp │ │ ├── transport │ │ ├── asio │ │ │ ├── base.hpp │ │ │ ├── connection.hpp │ │ │ ├── endpoint.hpp │ │ │ └── security │ │ │ │ ├── base.hpp │ │ │ │ ├── none.hpp │ │ │ │ └── tls.hpp │ │ ├── base │ │ │ ├── connection.hpp │ │ │ └── endpoint.hpp │ │ ├── debug │ │ │ ├── base.hpp │ │ │ ├── connection.hpp │ │ │ └── endpoint.hpp │ │ ├── iostream │ │ │ ├── base.hpp │ │ │ ├── connection.hpp │ │ │ └── endpoint.hpp │ │ └── stub │ │ │ ├── base.hpp │ │ │ ├── connection.hpp │ │ │ └── endpoint.hpp │ │ ├── uri.hpp │ │ ├── utf8_validator.hpp │ │ ├── utilities.hpp │ │ └── version.hpp ├── tests │ ├── main.c │ └── soname.h ├── websocket.cpp ├── websocket_connection.cpp ├── websocket_connection.h ├── websocket_defs.h ├── websocket_task.cpp ├── websocket_task.h └── wrapped_print.h ├── tests ├── testthat.R └── testthat │ └── test-client.R ├── tools ├── version.c └── winlibs.R ├── vignettes ├── .gitignore └── overview.Rmd └── websocket.Rproj /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^CRAN-RELEASE$ 2 | ^cran-comments\.md$ 3 | ^docs$ 4 | ^_pkgdown\.yml$ 5 | ^windows$ 6 | ^websocket\.Rproj$ 7 | ^\.Rproj\.user$ 8 | ^/tmp$ 9 | ^tmp 10 | ^/windows$ 11 | ^.vscode$ 12 | ^CONTRIBUTING.md$ 13 | ^\.github$ 14 | ^configure.log$ 15 | ^revdep$ 16 | ^pkgdown$ 17 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/rstudio/shiny-workflows 2 | # 3 | # NOTE: This Shiny team GHA workflow is overkill for most R packages. 4 | # For most R packages it is better to use https://github.com/r-lib/actions 5 | on: 6 | push: 7 | branches: [main, rc-**] 8 | pull_request: 9 | branches: [main] 10 | schedule: 11 | - cron: '0 9 * * 1' # every monday 12 | 13 | name: Package checks 14 | 15 | jobs: 16 | website: 17 | uses: rstudio/shiny-workflows/.github/workflows/website.yaml@v1 18 | routine: 19 | uses: rstudio/shiny-workflows/.github/workflows/routine.yaml@v1 20 | with: 21 | extra-packages: | 22 | decor 23 | R-CMD-check: 24 | uses: rstudio/shiny-workflows/.github/workflows/R-CMD-check.yaml@v1 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | inst/doc 2 | .Rproj.user 3 | .Rhistory 4 | .RData 5 | .Ruserdata 6 | .DS_Store 7 | src/Makevars 8 | /windows 9 | configure.log 10 | docs 11 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | We welcome contributions to the **websocket** package. To submit a contribution: 2 | 3 | 1. [Fork](https://github.com/rstudio/websocket/fork) the repository and make your changes. 4 | 5 | 2. Ensure that you have signed the [individual](https://rstudioblog.files.wordpress.com/2017/05/rstudio_individual_contributor_agreement.pdf) or [corporate](https://rstudioblog.files.wordpress.com/2017/05/rstudio_corporate_contributor_agreement.pdf) contributor agreement as appropriate. You can send the signed copy to jj@rstudio.com. 6 | 7 | 3. Submit a [pull request](https://help.github.com/articles/using-pull-requests). 8 | 9 | We generally will not merge a pull request that updates `websocketpp` or included libraries because it is difficult for us to verify that the update is done correctly. We prefer to update included libraries ourselves. 10 | 11 | ## How to make changes 12 | 13 | Before you submit a pull request, please do the following: 14 | 15 | * Add an entry to NEWS.md concisely describing what you changed. 16 | 17 | * If appropriate, add unit tests in the tests/ directory. 18 | 19 | * Run Build->Check Package in the RStudio IDE, or `devtools::check()`, to make sure your change did not add any messages, warnings, or errors. 20 | 21 | Doing these things will make it easier to evaluate your pull request. Even so, we may still decide to modify your code or even not merge it at all. Factors that may prevent us from merging the pull request include: 22 | 23 | * breaking backward compatibility 24 | * adding a feature that we do not consider relevant 25 | * is hard to understand 26 | * is hard to maintain in the future 27 | * is computationally expensive 28 | * is not intuitive for people to use 29 | 30 | We will try to be responsive and provide feedback in case we decide not to merge your pull request. 31 | 32 | ## Filing issues 33 | 34 | If you find a bug in websocket, you can also [file an issue](https://github.com/rstudio/websocket/issues/new). Please provide as much relevant information as you can, and include a minimal reproducible example if possible. 35 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: websocket 2 | Version: 1.4.4.9000 3 | Title: 'WebSocket' Client Library 4 | Description: Provides a 'WebSocket' client interface for R. 5 | 'WebSocket' is a protocol for low-overhead real-time communication: 6 | . 7 | Authors@R: c( 8 | person("Winston", "Chang", role = c("aut", "cre"), email = "winston@posit.co"), 9 | person("Joe", "Cheng", role = "aut", email = "joe@posit.co"), 10 | person("Alan", "Dipert", role = "aut"), 11 | person("Barbara", "Borges", role = "aut"), 12 | person(family = "Posit, PBC", role = "cph"), 13 | person("Peter", "Thorson", role = c("ctb", "cph"), comment = "WebSocket++ library"), 14 | person("René", "Nyffenegger", role = c("ctb", "cph"), comment = "Base 64 library"), 15 | person("Micael", "Hildenborg", role = c("ctb", "cph"), comment = "SHA1 library"), 16 | person(family = "Aladdin Enterprises", role = "cph", comment = "MD5 library"), 17 | person("Bjoern", "Hoehrmann", role = c("ctb", "cph"), comment = "UTF8 Validation library")) 18 | License: GPL-2 19 | Encoding: UTF-8 20 | ByteCompile: true 21 | Imports: 22 | R6, 23 | later (>= 1.2.0) 24 | LinkingTo: cpp11, AsioHeaders, later 25 | BugReports: https://github.com/rstudio/websocket/issues 26 | SystemRequirements: GNU make, OpenSSL >= 1.0.2 27 | RoxygenNote: 7.3.2 28 | Suggests: 29 | httpuv, 30 | testthat, 31 | knitr, 32 | rmarkdown 33 | VignetteBuilder: knitr 34 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(WebSocket) 4 | import(later) 5 | importFrom(R6,R6Class) 6 | useDynLib(websocket, .registration = TRUE) 7 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # websocket (development version) 2 | 3 | # websocket 1.4.4 4 | 5 | * Silences inaccurate deprecation warnings from certain C++ compilers. (#116) 6 | 7 | * Fixes builds for Windows systems without openssl.pc. (@jeroen, #117) 8 | 9 | # websocket 1.4.3 10 | 11 | * When compiled with Rtools42 to 45, it now uses the copy of openssl that comes with Rtools. (@kalibera, #113) 12 | 13 | # websocket 1.4.2 14 | 15 | * Fixes for C++20, and removed use of non-API function `R_nchar`. (#109) 16 | 17 | # websocket 1.4.1 18 | 19 | * Add UCRT toolchain support (@jeroen, #82) 20 | 21 | * Add `BugReports` URL to DESCRIPTION (@jeroen, #83) 22 | 23 | # websocket 1.4.0 24 | 25 | * Switched away from Rcpp and BH, to cpp11. (#73) 26 | 27 | # websocket 1.3.2 28 | 29 | * Made a tweak to autobrew in `configure` script. (@jeroen, #75) 30 | 31 | * Added a proxy example to README. 32 | 33 | * Made tests more reliable by eliminating need for external connections. 34 | 35 | # websocket 1.3.1 36 | 37 | * Increased OpenSSL system requirement from 1.0.1 to 1.0.2. 38 | 39 | # websocket 1.3.0 40 | 41 | * Update to WebSocket++ 0.8.2, in order to work with AsioHeaders 1.16.1-1. (#68) 42 | 43 | * Windows and Mac: Update to OpenSSL 1.1.1g. (#69) 44 | 45 | * Building and installing the package no longer leaves files in the system temp directory. (#69) 46 | 47 | # websocket 1.2.0 48 | 49 | * Websocket I/O now runs on a separate thread, so Websocket no longer uses polling. This should also reduce latency for handling incoming messages. (#62) 50 | 51 | # websocket 1.1.0 52 | 53 | * Added `maxMessageSize` argument to `WebSocket$new()`. (#57) 54 | 55 | # websocket 1.0.0 56 | 57 | * Initial release 58 | -------------------------------------------------------------------------------- /R/cpp11.R: -------------------------------------------------------------------------------- 1 | # Generated by cpp11: do not edit by hand 2 | 3 | wsCreate <- function(uri, loop_id, robjPublic, robjPrivate, accessLogChannels, errorLogChannels, maxMessageSize) { 4 | .Call(`_websocket_wsCreate`, uri, loop_id, robjPublic, robjPrivate, accessLogChannels, errorLogChannels, maxMessageSize) 5 | } 6 | 7 | wsAppendHeader <- function(wsc_xptr, key, value) { 8 | invisible(.Call(`_websocket_wsAppendHeader`, wsc_xptr, key, value)) 9 | } 10 | 11 | wsAddProtocols <- function(wsc_xptr, protocols) { 12 | invisible(.Call(`_websocket_wsAddProtocols`, wsc_xptr, protocols)) 13 | } 14 | 15 | wsConnect <- function(wsc_xptr) { 16 | invisible(.Call(`_websocket_wsConnect`, wsc_xptr)) 17 | } 18 | 19 | wsSend <- function(wsc_xptr, msg) { 20 | invisible(.Call(`_websocket_wsSend`, wsc_xptr, msg)) 21 | } 22 | 23 | wsClose <- function(wsc_xptr, code, reason) { 24 | invisible(.Call(`_websocket_wsClose`, wsc_xptr, code, reason)) 25 | } 26 | 27 | wsProtocol <- function(wsc_xptr) { 28 | .Call(`_websocket_wsProtocol`, wsc_xptr) 29 | } 30 | 31 | wsState <- function(wsc_xptr) { 32 | .Call(`_websocket_wsState`, wsc_xptr) 33 | } 34 | 35 | wsUpdateLogChannels <- function(wsc_xptr, accessOrError, setOrClear, logChannels) { 36 | invisible(.Call(`_websocket_wsUpdateLogChannels`, wsc_xptr, accessOrError, setOrClear, logChannels)) 37 | } 38 | -------------------------------------------------------------------------------- /cleanup: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rm -f src/Makevars configure.log autobrew 4 | rm -Rf .deps 5 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | # Anticonf (tm) script by Jeroen Ooms (2020) 2 | # This script will query 'pkg-config' for the required cflags and ldflags. 3 | # If pkg-config is unavailable or does not find the library, try setting 4 | # INCLUDE_DIR and LIB_DIR manually via e.g: 5 | # R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib' 6 | 7 | # Library settings 8 | PKG_CONFIG_NAME="openssl" 9 | PKG_DEB_NAME="libssl-dev" 10 | PKG_RPM_NAME="openssl-devel" 11 | PKG_CSW_NAME="libssl_dev" 12 | PKG_BREW_NAME="openssl@1.1" 13 | PKG_TEST_FILE="tools/version.c" 14 | PKG_LIBS="-lssl -lcrypto" 15 | PKG_CFLAGS="" 16 | 17 | # Use pkg-config if available 18 | pkg-config ${PKG_CONFIG_NAME} --atleast-version=1.0 2>/dev/null 19 | if [ $? -eq 0 ]; then 20 | PKGCONFIG_CFLAGS=`pkg-config --cflags ${PKG_CONFIG_NAME}` 21 | PKGCONFIG_LIBS=`pkg-config --libs ${PKG_CONFIG_NAME}` 22 | fi 23 | 24 | # Note that cflags may be empty in case of success 25 | if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then 26 | echo "Found INCLUDE_DIR and/or LIB_DIR!" 27 | PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS" 28 | PKG_LIBS="-L$LIB_DIR $PKG_LIBS" 29 | elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then 30 | echo "Found pkg-config cflags and libs!" 31 | PKG_CFLAGS=${PKGCONFIG_CFLAGS} 32 | PKG_LIBS=${PKGCONFIG_LIBS} 33 | elif [ `uname` = "Darwin" ]; then 34 | brew --version 2>/dev/null 35 | if [ $? -eq 0 ]; then 36 | BREWDIR=`brew --prefix` 37 | PKG_CFLAGS="-I$BREWDIR/opt/openssl/include" 38 | PKG_LIBS="-L$BREWDIR/opt/openssl/lib $PKG_LIBS" 39 | else 40 | curl -sfL "https://autobrew.github.io/scripts/$PKG_BREW_NAME" > autobrew 41 | . ./autobrew 42 | fi 43 | fi 44 | 45 | # Find compiler 46 | CC=`${R_HOME}/bin/R CMD config CC` 47 | CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS` 48 | CPPFLAGS=`${R_HOME}/bin/R CMD config CPPFLAGS` 49 | 50 | # For debugging 51 | echo "Using PKG_CFLAGS=$PKG_CFLAGS" 52 | 53 | # Test configuration 54 | ${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E ${PKG_TEST_FILE} >/dev/null 2>configure.log 55 | 56 | # Customize the error 57 | if [ $? -ne 0 ]; then 58 | echo "--------------------------- [ANTICONF] --------------------------------" 59 | echo "Configuration failed because $PKG_CONFIG_NAME was not found. Try installing:" 60 | echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu, etc)" 61 | echo " * rpm: $PKG_RPM_NAME (Fedora, CentOS, RHEL)" 62 | echo " * csw: $PKG_CSW_NAME (Solaris)" 63 | echo " * brew: $PKG_BREW_NAME (Mac OSX)" 64 | echo "If $PKG_CONFIG_NAME is already installed, check that 'pkg-config' is in your" 65 | echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config" 66 | echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:" 67 | echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'" 68 | echo "-------------------------- [ERROR MESSAGE] ---------------------------" 69 | cat configure.log 70 | echo "--------------------------------------------------------------------" 71 | exit 1 72 | fi 73 | 74 | # Try to link against the correct OpenSSL version 75 | if [ -z "$AUTOBREW" ]; then 76 | SONAME=`${CC} -E ${PKG_CFLAGS} src/tests/soname.h | sh | xargs` 77 | if [ "$SONAME" ]; then 78 | if [ `uname` = "Darwin" ]; then 79 | PKG_LIBS_VERSIONED=`echo "${PKG_LIBS}" | sed "s/-lssl/-lssl.${SONAME}/" | sed "s/-lcrypto/-lcrypto.${SONAME}/"` 80 | else 81 | PKG_LIBS_VERSIONED=`echo "${PKG_LIBS}" | sed "s/-lssl/-l:libssl.so.${SONAME}/" | sed "s/-lcrypto/-l:libcrypto.so.${SONAME}/"` 82 | fi 83 | 84 | # Test if versioned linking works 85 | ${CC} ${PKG_CFLAGS} src/tests/main.c ${PKG_LIBS_VERSIONED} -o src/main.exe 2>/dev/null 86 | if [ $? -eq 0 ]; then rm -f src/main.exe; PKG_LIBS="${PKG_LIBS_VERSIONED}"; fi 87 | 88 | # Suppress opensslv3 warnings for now 89 | if [ "$SONAME" = "3" ]; then 90 | PKG_CFLAGS="$PKG_CFLAGS -DOPENSSL_SUPPRESS_DEPRECATED" 91 | fi 92 | 93 | fi #SONAME 94 | fi #AUTOBREW 95 | 96 | echo "Using PKG_LIBS=$PKG_LIBS" 97 | 98 | # Write to Makevars 99 | sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars 100 | 101 | # Success 102 | exit 0 103 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | There were no ERRORs or WARNINGs. 4 | 5 | There were 2 NOTEs: 6 | 7 | * checking installed package size ... NOTE 8 | installed size is 19.8Mb 9 | sub-directories of 1Mb or more: 10 | libs 19.6Mb 11 | 12 | The websocketpp C++ library is several megabytes in size, so this is unavoidable. 13 | 14 | * GNU make is a SystemRequirements. 15 | 16 | GNU syntax += is used in Makevars.in to append to the PKG_LIBS variable. 17 | 18 | ## revdepcheck results 19 | 20 | We checked 8 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 21 | 22 | * We saw 0 new problems 23 | * We failed to check 0 packages 24 | 25 | -------------------------------------------------------------------------------- /pkgdown/_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://rstudio.github.io/websocket/ 2 | 3 | development: 4 | mode: auto 5 | 6 | template: 7 | params: 8 | bootswatch: cosmo 9 | docsearch: 10 | api_key: '9e39a401e6bab5df9d3b823b69a4085b' 11 | index_name: 'websocket' 12 | 13 | navbar: 14 | type: inverse 15 | left: 16 | - text: Home 17 | icon: fa-home 18 | href: index.html 19 | - text: Learning 20 | menu: 21 | - text: "Overview" 22 | href: articles/overview.html 23 | - text: Reference 24 | href: reference/index.html 25 | 26 | authors: 27 | RStudio: 28 | href: https://www.rstudio.com 29 | html: 30 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/websocket/06819236bccfd3a6b387a27300a75a816b1c2fc7/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/websocket/06819236bccfd3a6b387a27300a75a816b1c2fc7/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/websocket/06819236bccfd3a6b387a27300a75a816b1c2fc7/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/websocket/06819236bccfd3a6b387a27300a75a816b1c2fc7/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/websocket/06819236bccfd3a6b387a27300a75a816b1c2fc7/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/websocket/06819236bccfd3a6b387a27300a75a816b1c2fc7/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/websocket/06819236bccfd3a6b387a27300a75a816b1c2fc7/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/websocket/06819236bccfd3a6b387a27300a75a816b1c2fc7/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/websocket/06819236bccfd3a6b387a27300a75a816b1c2fc7/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /revdep/.gitignore: -------------------------------------------------------------------------------- 1 | checks 2 | library 3 | checks.noindex 4 | library.noindex 5 | cloud.noindex 6 | data.sqlite 7 | *.html 8 | -------------------------------------------------------------------------------- /revdep/README.md: -------------------------------------------------------------------------------- 1 | # Platform 2 | 3 | |field |value | 4 | |:--------|:-------------------------------------| 5 | |version |R version 4.4.3 (2025-02-28) | 6 | |os |Ubuntu 24.04.2 LTS | 7 | |system |x86_64, linux-gnu | 8 | |ui |RStudio | 9 | |language |en_GB:en | 10 | |collate |en_GB.UTF-8 | 11 | |ctype |en_GB.UTF-8 | 12 | |tz |Europe/London | 13 | |date |2025-04-07 | 14 | |rstudio |2024.12.1+563 Kousa Dogwood (desktop) | 15 | |pandoc |3.1.3 @ /usr/bin/pandoc | 16 | |quarto |1.6.40 @ /usr/local/bin/quarto | 17 | 18 | # Dependencies 19 | 20 | |package |old |new |Δ | 21 | |:-----------|:--------|:----------|:--| 22 | |websocket |1.4.2 |1.4.3.9000 |* | 23 | |AsioHeaders |1.22.1-2 |1.22.1-2 | | 24 | |cpp11 |0.5.2 |0.5.2 | | 25 | |later |1.4.1 |1.4.1 | | 26 | |R6 |2.6.1 |2.6.1 | | 27 | |Rcpp |1.0.14 |1.0.14 | | 28 | |rlang |1.1.5 |1.1.5 | | 29 | 30 | # Revdeps 31 | 32 | -------------------------------------------------------------------------------- /revdep/cran.md: -------------------------------------------------------------------------------- 1 | ## revdepcheck results 2 | 3 | We checked 8 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 4 | 5 | * We saw 0 new problems 6 | * We failed to check 0 packages 7 | 8 | -------------------------------------------------------------------------------- /revdep/failures.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /revdep/problems.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | *.dll 4 | -------------------------------------------------------------------------------- /src/Makevars.in: -------------------------------------------------------------------------------- 1 | PKG_CPPFLAGS = -I./lib @cflags@ -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS 2 | PKG_LIBS += @libs@ 3 | 4 | #### Debugging flags #### 5 | # Uncomment to enable thread assertions 6 | # PKG_CPPFLAGS += -pthread -DDEBUG_THREAD -UNDEBUG 7 | # PKG_LIBS += -pthread 8 | -------------------------------------------------------------------------------- /src/Makevars.ucrt: -------------------------------------------------------------------------------- 1 | PKG_CPPFLAGS = -I./lib -D_WEBSOCKETPP_CPP11_THREAD_ 2 | PKG_LIBS = $(shell pkg-config --libs openssl) 3 | ifeq ($(PKG_LIBS),) 4 | PKG_LIBS = -lssl -lcrypto -lz -lws2_32 -lgdi32 -lcrypt32 5 | else 6 | PKG_CPPFLAGS += $(shell pkg-config --cflags openssl) 7 | endif 8 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | OPENSSL_VERSION=1.1.1g 2 | 3 | # Some settings from https://github.com/zaphoyd/websocketpp/issues/478 4 | PKG_CPPFLAGS=-I./lib -I../windows/openssl-$(OPENSSL_VERSION)/include -D_WEBSOCKETPP_CPP11_THREAD_ 5 | PKG_LIBS= -L../windows/openssl-$(OPENSSL_VERSION)/lib${R_ARCH}${CRT} -lssl -lcrypto -lz -lws2_32 -lgdi32 -lcrypt32 6 | 7 | #### Debugging flags #### 8 | # Uncomment to enable thread assertions 9 | # PKG_CPPFLAGS += -DDEBUG_THREAD -UNDEBUG 10 | 11 | .PHONY: all winlibs 12 | 13 | all: $(SHLIB) 14 | 15 | # Need to make sure that openssl is fully downloaded before trying to compile 16 | # websocket.cpp. See https://github.com/rstudio/websocket/issues/43 17 | $(OBJECTS): winlibs 18 | 19 | clean: 20 | rm -f $(SHLIB) $(OBJECTS) 21 | 22 | winlibs: 23 | "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" "../tools/winlibs.R" $(OPENSSL_VERSION) 24 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | Notes about compiled sources 2 | ============================ 3 | 4 | ## websocketpp 5 | 6 | This package makes use of the [websocketpp](https://github.com/zaphoyd/websocketpp) C++ library. It can conflict with another copy of websocketpp that is used in the RStudio IDE, leading to a crash ([#7](https://github.com/rstudio/websocket/issues/7) and [rstudio/rstudio#2838](https://github.com/rstudio/rstudio/issues/2838)). To avoid the crash, the `websocketpp` namespace has been renamed to `ws_websocketpp` in our copy of it. 7 | 8 | The stock version of websocketpp [does not compile in minGW](https://github.com/zaphoyd/websocketpp/issues/478) on Windows, because the version of libstdc++ does not define `std::errc::error_canceled`. This is apparently due to [a bug](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68307) in GNU libstdc++ which is fixed in later versions of minGW. To make it compile, we used a workaround borrowed from this [pull request](https://github.com/zaphoyd/websocketpp/pull/479) on websocketpp which has not been merged because the project seems to be no longer maintained. 9 | 10 | To update websocketpp: 11 | 12 | * Update the script at src/lib/update.sh to get the specified version, and then run the script. It will download the files and perform the namespace renaming. 13 | * Re-apply the `std::errc::error_canceled` patch by running `git cherry-pick 8167dac`. 14 | -------------------------------------------------------------------------------- /src/cpp11.cpp: -------------------------------------------------------------------------------- 1 | // Generated by cpp11: do not edit by hand 2 | // clang-format off 3 | 4 | 5 | #include "cpp11/declarations.hpp" 6 | #include 7 | 8 | // websocket.cpp 9 | SEXP wsCreate(std::string uri, int loop_id, cpp11::environment robjPublic, cpp11::environment robjPrivate, cpp11::strings accessLogChannels, cpp11::strings errorLogChannels, int maxMessageSize); 10 | extern "C" SEXP _websocket_wsCreate(SEXP uri, SEXP loop_id, SEXP robjPublic, SEXP robjPrivate, SEXP accessLogChannels, SEXP errorLogChannels, SEXP maxMessageSize) { 11 | BEGIN_CPP11 12 | return cpp11::as_sexp(wsCreate(cpp11::as_cpp>(uri), cpp11::as_cpp>(loop_id), cpp11::as_cpp>(robjPublic), cpp11::as_cpp>(robjPrivate), cpp11::as_cpp>(accessLogChannels), cpp11::as_cpp>(errorLogChannels), cpp11::as_cpp>(maxMessageSize))); 13 | END_CPP11 14 | } 15 | // websocket.cpp 16 | void wsAppendHeader(SEXP wsc_xptr, std::string key, std::string value); 17 | extern "C" SEXP _websocket_wsAppendHeader(SEXP wsc_xptr, SEXP key, SEXP value) { 18 | BEGIN_CPP11 19 | wsAppendHeader(cpp11::as_cpp>(wsc_xptr), cpp11::as_cpp>(key), cpp11::as_cpp>(value)); 20 | return R_NilValue; 21 | END_CPP11 22 | } 23 | // websocket.cpp 24 | void wsAddProtocols(SEXP wsc_xptr, cpp11::strings protocols); 25 | extern "C" SEXP _websocket_wsAddProtocols(SEXP wsc_xptr, SEXP protocols) { 26 | BEGIN_CPP11 27 | wsAddProtocols(cpp11::as_cpp>(wsc_xptr), cpp11::as_cpp>(protocols)); 28 | return R_NilValue; 29 | END_CPP11 30 | } 31 | // websocket.cpp 32 | void wsConnect(SEXP wsc_xptr); 33 | extern "C" SEXP _websocket_wsConnect(SEXP wsc_xptr) { 34 | BEGIN_CPP11 35 | wsConnect(cpp11::as_cpp>(wsc_xptr)); 36 | return R_NilValue; 37 | END_CPP11 38 | } 39 | // websocket.cpp 40 | void wsSend(SEXP wsc_xptr, SEXP msg); 41 | extern "C" SEXP _websocket_wsSend(SEXP wsc_xptr, SEXP msg) { 42 | BEGIN_CPP11 43 | wsSend(cpp11::as_cpp>(wsc_xptr), cpp11::as_cpp>(msg)); 44 | return R_NilValue; 45 | END_CPP11 46 | } 47 | // websocket.cpp 48 | void wsClose(SEXP wsc_xptr, uint16_t code, std::string reason); 49 | extern "C" SEXP _websocket_wsClose(SEXP wsc_xptr, SEXP code, SEXP reason) { 50 | BEGIN_CPP11 51 | wsClose(cpp11::as_cpp>(wsc_xptr), cpp11::as_cpp>(code), cpp11::as_cpp>(reason)); 52 | return R_NilValue; 53 | END_CPP11 54 | } 55 | // websocket.cpp 56 | std::string wsProtocol(SEXP wsc_xptr); 57 | extern "C" SEXP _websocket_wsProtocol(SEXP wsc_xptr) { 58 | BEGIN_CPP11 59 | return cpp11::as_sexp(wsProtocol(cpp11::as_cpp>(wsc_xptr))); 60 | END_CPP11 61 | } 62 | // websocket.cpp 63 | std::string wsState(SEXP wsc_xptr); 64 | extern "C" SEXP _websocket_wsState(SEXP wsc_xptr) { 65 | BEGIN_CPP11 66 | return cpp11::as_sexp(wsState(cpp11::as_cpp>(wsc_xptr))); 67 | END_CPP11 68 | } 69 | // websocket.cpp 70 | void wsUpdateLogChannels(SEXP wsc_xptr, std::string accessOrError, std::string setOrClear, cpp11::strings logChannels); 71 | extern "C" SEXP _websocket_wsUpdateLogChannels(SEXP wsc_xptr, SEXP accessOrError, SEXP setOrClear, SEXP logChannels) { 72 | BEGIN_CPP11 73 | wsUpdateLogChannels(cpp11::as_cpp>(wsc_xptr), cpp11::as_cpp>(accessOrError), cpp11::as_cpp>(setOrClear), cpp11::as_cpp>(logChannels)); 74 | return R_NilValue; 75 | END_CPP11 76 | } 77 | 78 | extern "C" { 79 | static const R_CallMethodDef CallEntries[] = { 80 | {"_websocket_wsAddProtocols", (DL_FUNC) &_websocket_wsAddProtocols, 2}, 81 | {"_websocket_wsAppendHeader", (DL_FUNC) &_websocket_wsAppendHeader, 3}, 82 | {"_websocket_wsClose", (DL_FUNC) &_websocket_wsClose, 3}, 83 | {"_websocket_wsConnect", (DL_FUNC) &_websocket_wsConnect, 1}, 84 | {"_websocket_wsCreate", (DL_FUNC) &_websocket_wsCreate, 7}, 85 | {"_websocket_wsProtocol", (DL_FUNC) &_websocket_wsProtocol, 1}, 86 | {"_websocket_wsSend", (DL_FUNC) &_websocket_wsSend, 2}, 87 | {"_websocket_wsState", (DL_FUNC) &_websocket_wsState, 1}, 88 | {"_websocket_wsUpdateLogChannels", (DL_FUNC) &_websocket_wsUpdateLogChannels, 4}, 89 | {NULL, NULL, 0} 90 | }; 91 | } 92 | 93 | extern "C" attribute_visible void R_init_websocket(DllInfo* dll){ 94 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 95 | R_useDynamicSymbols(dll, FALSE); 96 | R_forceSymbols(dll, TRUE); 97 | } 98 | -------------------------------------------------------------------------------- /src/debug.cpp: -------------------------------------------------------------------------------- 1 | #include "debug.h" 2 | 3 | #if defined(DEBUG_THREAD) 4 | 5 | wsdebug_thrd_t __main_thread__; 6 | wsdebug_thrd_t __background_thread__; 7 | 8 | wsdebug_thrd_t wsdebug_thrd_current(void) { 9 | #if defined(_TTHREAD_WIN32_) 10 | return GetCurrentThread(); 11 | #else 12 | return pthread_self(); 13 | #endif 14 | } 15 | 16 | #endif // defined(DEBUG_THREAD) 17 | -------------------------------------------------------------------------------- /src/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef DEBUG_H 2 | #define DEBUG_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | // See the Makevars file to see how to compile with various debugging settings. 9 | 10 | #ifdef DEBUG_THREAD 11 | 12 | #ifdef _WIN32 13 | #ifndef WIN32_LEAN_AND_MEAN 14 | #define WIN32_LEAN_AND_MEAN 15 | #define __UNDEF_LEAN_AND_MEAN 16 | #endif 17 | #include 18 | #ifdef __UNDEF_LEAN_AND_MEAN 19 | #undef WIN32_LEAN_AND_MEAN 20 | #undef __UNDEF_LEAN_AND_MEAN 21 | #endif 22 | #else 23 | #include 24 | #endif 25 | 26 | 27 | #ifdef _WIN32 28 | typedef HANDLE wsdebug_thrd_t; 29 | #else 30 | typedef pthread_t wsdebug_thrd_t; 31 | #endif 32 | 33 | wsdebug_thrd_t wsdebug_thrd_current(void); 34 | 35 | 36 | extern wsdebug_thrd_t __main_thread__; 37 | extern wsdebug_thrd_t __background_thread__; 38 | 39 | // This must be called from the main thread so that thread assertions can be 40 | // tested later. 41 | #define REGISTER_MAIN_THREAD() __main_thread__ = wsdebug_thrd_current(); 42 | #define REGISTER_BACKGROUND_THREAD() __background_thread__ = wsdebug_thrd_current(); 43 | #define ASSERT_MAIN_THREAD() assert(wsdebug_thrd_current() == __main_thread__); 44 | #define ASSERT_BACKGROUND_THREAD() assert(wsdebug_thrd_current() == __background_thread__); 45 | 46 | #else // ifdef DEBUG_THREAD 47 | 48 | #define REGISTER_MAIN_THREAD() 49 | #define REGISTER_BACKGROUND_THREAD() 50 | #define ASSERT_MAIN_THREAD() 51 | #define ASSERT_BACKGROUND_THREAD() 52 | 53 | #endif // ifdef DEBUG_THREAD 54 | 55 | 56 | #ifdef __cplusplus 57 | } // extern "C" 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/lib/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | COMMIT=0.8.2 4 | 5 | set -e 6 | 7 | rm -rf websocketpp websocketpp_repo 8 | git clone --depth=1 -b "$COMMIT" https://github.com/zaphoyd/websocketpp websocketpp_repo 9 | (cd websocketpp_repo && git checkout "$COMMIT") 10 | rm websocketpp_repo/websocketpp/CMakeLists.txt 11 | export LC_CTYPE=C 12 | export LANG=C 13 | cd websocketpp_repo/websocketpp 14 | find . -path ./.git -prune -o -type f -print0 | xargs -0 sed -i "" -e 's/websocketpp::/ws_websocketpp::/g' 15 | find . -path ./.git -prune -o -type f -print0 | xargs -0 sed -i "" -e 's/namespace websocketpp/namespace ws_websocketpp/g' 16 | find . -path ./.git -prune -o -type f -print0 | xargs -0 sed -i "" -e 's/&std::cout/(std::ostream*)\&WrappedOstream::cout/g' 17 | find . -path ./.git -prune -o -type f -print0 | xargs -0 sed -i "" -e 's/&std::cerr/(std::ostream*)\&WrappedOstream::cerr/g' 18 | cd ../.. 19 | mv websocketpp_repo/websocketpp . 20 | rm -rf websocketpp_repo 21 | 22 | echo "IMPORTANT NOTE: Apply this patch manually:" >&2 23 | echo "https://github.com/rstudio/websocket/commit/063ca452c7639b952dfd4981602436d43305457a" >&2 24 | -------------------------------------------------------------------------------- /src/lib/websocketpp/base64/base64.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | ****** 3 | base64.hpp is a repackaging of the base64.cpp and base64.h files into a 4 | single header suitable for use as a header only library. This conversion was 5 | done by Peter Thorson (webmaster@zaphoyd.com) in 2012. All modifications to 6 | the code are redistributed under the same license as the original, which is 7 | listed below. 8 | ****** 9 | 10 | base64.cpp and base64.h 11 | 12 | Copyright (C) 2004-2008 René Nyffenegger 13 | 14 | This source code is provided 'as-is', without any express or implied 15 | warranty. In no event will the author be held liable for any damages 16 | arising from the use of this software. 17 | 18 | Permission is granted to anyone to use this software for any purpose, 19 | including commercial applications, and to alter it and redistribute it 20 | freely, subject to the following restrictions: 21 | 22 | 1. The origin of this source code must not be misrepresented; you must not 23 | claim that you wrote the original source code. If you use this source code 24 | in a product, an acknowledgment in the product documentation would be 25 | appreciated but is not required. 26 | 27 | 2. Altered source versions must be plainly marked as such, and must not be 28 | misrepresented as being the original source code. 29 | 30 | 3. This notice may not be removed or altered from any source distribution. 31 | 32 | René Nyffenegger rene.nyffenegger@adp-gmbh.ch 33 | 34 | */ 35 | 36 | #ifndef _BASE64_HPP_ 37 | #define _BASE64_HPP_ 38 | 39 | #include 40 | 41 | namespace ws_websocketpp { 42 | 43 | static std::string const base64_chars = 44 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 45 | "abcdefghijklmnopqrstuvwxyz" 46 | "0123456789+/"; 47 | 48 | /// Test whether a character is a valid base64 character 49 | /** 50 | * @param c The character to test 51 | * @return true if c is a valid base64 character 52 | */ 53 | static inline bool is_base64(unsigned char c) { 54 | return (c == 43 || // + 55 | (c >= 47 && c <= 57) || // /-9 56 | (c >= 65 && c <= 90) || // A-Z 57 | (c >= 97 && c <= 122)); // a-z 58 | } 59 | 60 | /// Encode a char buffer into a base64 string 61 | /** 62 | * @param input The input data 63 | * @param len The length of input in bytes 64 | * @return A base64 encoded string representing input 65 | */ 66 | inline std::string base64_encode(unsigned char const * input, size_t len) { 67 | std::string ret; 68 | int i = 0; 69 | int j = 0; 70 | unsigned char char_array_3[3]; 71 | unsigned char char_array_4[4]; 72 | 73 | while (len--) { 74 | char_array_3[i++] = *(input++); 75 | if (i == 3) { 76 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 77 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + 78 | ((char_array_3[1] & 0xf0) >> 4); 79 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + 80 | ((char_array_3[2] & 0xc0) >> 6); 81 | char_array_4[3] = char_array_3[2] & 0x3f; 82 | 83 | for(i = 0; (i <4) ; i++) { 84 | ret += base64_chars[char_array_4[i]]; 85 | } 86 | i = 0; 87 | } 88 | } 89 | 90 | if (i) { 91 | for(j = i; j < 3; j++) { 92 | char_array_3[j] = '\0'; 93 | } 94 | 95 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 96 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + 97 | ((char_array_3[1] & 0xf0) >> 4); 98 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + 99 | ((char_array_3[2] & 0xc0) >> 6); 100 | char_array_4[3] = char_array_3[2] & 0x3f; 101 | 102 | for (j = 0; (j < i + 1); j++) { 103 | ret += base64_chars[char_array_4[j]]; 104 | } 105 | 106 | while((i++ < 3)) { 107 | ret += '='; 108 | } 109 | } 110 | 111 | return ret; 112 | } 113 | 114 | /// Encode a string into a base64 string 115 | /** 116 | * @param input The input data 117 | * @return A base64 encoded string representing input 118 | */ 119 | inline std::string base64_encode(std::string const & input) { 120 | return base64_encode( 121 | reinterpret_cast(input.data()), 122 | input.size() 123 | ); 124 | } 125 | 126 | /// Decode a base64 encoded string into a string of raw bytes 127 | /** 128 | * @param input The base64 encoded input data 129 | * @return A string representing the decoded raw bytes 130 | */ 131 | inline std::string base64_decode(std::string const & input) { 132 | size_t in_len = input.size(); 133 | int i = 0; 134 | int j = 0; 135 | int in_ = 0; 136 | unsigned char char_array_4[4], char_array_3[3]; 137 | std::string ret; 138 | 139 | while (in_len-- && ( input[in_] != '=') && is_base64(input[in_])) { 140 | char_array_4[i++] = input[in_]; in_++; 141 | if (i ==4) { 142 | for (i = 0; i <4; i++) { 143 | char_array_4[i] = static_cast(base64_chars.find(char_array_4[i])); 144 | } 145 | 146 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 147 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 148 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 149 | 150 | for (i = 0; (i < 3); i++) { 151 | ret += char_array_3[i]; 152 | } 153 | i = 0; 154 | } 155 | } 156 | 157 | if (i) { 158 | for (j = i; j <4; j++) 159 | char_array_4[j] = 0; 160 | 161 | for (j = 0; j <4; j++) 162 | char_array_4[j] = static_cast(base64_chars.find(char_array_4[j])); 163 | 164 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 165 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 166 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 167 | 168 | for (j = 0; (j < i - 1); j++) { 169 | ret += static_cast(char_array_3[j]); 170 | } 171 | } 172 | 173 | return ret; 174 | } 175 | 176 | } // namespace ws_websocketpp 177 | 178 | #endif // _BASE64_HPP_ 179 | -------------------------------------------------------------------------------- /src/lib/websocketpp/client.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_CLIENT_HPP 29 | #define WEBSOCKETPP_CLIENT_HPP 30 | 31 | #include 32 | 33 | #endif //WEBSOCKETPP_CLIENT_HPP 34 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/asio_ssl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, 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_COMMON_ASIO_SSL_HPP 29 | #define WEBSOCKETPP_COMMON_ASIO_SSL_HPP 30 | 31 | // NOTE: This file must be included before common/asio.hpp 32 | 33 | #ifdef ASIO_STANDALONE 34 | #include 35 | #else 36 | #include 37 | #endif 38 | 39 | #endif // WEBSOCKETPP_COMMON_ASIO_SSL_HPP 40 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/chrono.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, 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_COMMON_CHRONO_HPP 29 | #define WEBSOCKETPP_COMMON_CHRONO_HPP 30 | 31 | #include 32 | 33 | // If we've determined that we're in full C++11 mode and the user hasn't 34 | // explicitly disabled the use of C++11 functional header, then prefer it to 35 | // boost. 36 | #if defined _WEBSOCKETPP_CPP11_INTERNAL_ && !defined _WEBSOCKETPP_NO_CPP11_CHRONO_ 37 | #ifndef _WEBSOCKETPP_CPP11_CHRONO_ 38 | #define _WEBSOCKETPP_CPP11_CHRONO_ 39 | #endif 40 | #endif 41 | 42 | // If we're on Visual Studio 2012 or higher and haven't explicitly disabled 43 | // the use of C++11 chrono header then prefer it to boost. 44 | #if defined(_MSC_VER) && _MSC_VER >= 1700 && !defined _WEBSOCKETPP_NO_CPP11_CHRONO_ 45 | #ifndef _WEBSOCKETPP_CPP11_CHRONO_ 46 | #define _WEBSOCKETPP_CPP11_CHRONO_ 47 | #endif 48 | #endif 49 | 50 | #ifdef _WEBSOCKETPP_CPP11_CHRONO_ 51 | #include 52 | #else 53 | #include 54 | #endif 55 | 56 | namespace ws_websocketpp { 57 | namespace lib { 58 | 59 | #ifdef _WEBSOCKETPP_CPP11_CHRONO_ 60 | namespace chrono = std::chrono; 61 | #else 62 | namespace chrono = boost::chrono; 63 | #endif 64 | 65 | } // namespace lib 66 | } // namespace ws_websocketpp 67 | 68 | #endif // WEBSOCKETPP_COMMON_CHRONO_HPP 69 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/connection_hdl.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_COMMON_CONNECTION_HDL_HPP 29 | #define WEBSOCKETPP_COMMON_CONNECTION_HDL_HPP 30 | 31 | #include 32 | 33 | namespace ws_websocketpp { 34 | 35 | /// A handle to uniquely identify a connection. 36 | /** 37 | * This type uniquely identifies a connection. It is implemented as a weak 38 | * pointer to the connection in question. This provides uniqueness across 39 | * multiple endpoints and ensures that IDs never conflict or run out. 40 | * 41 | * It is safe to make copies of this handle, store those copies in containers, 42 | * and use them from other threads. 43 | * 44 | * This handle can be upgraded to a full shared_ptr using 45 | * `endpoint::get_con_from_hdl()` from within a handler fired by the connection 46 | * that owns the handler. 47 | */ 48 | typedef lib::weak_ptr connection_hdl; 49 | 50 | } // namespace ws_websocketpp 51 | 52 | #endif // WEBSOCKETPP_COMMON_CONNECTION_HDL_HPP 53 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/functional.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_COMMON_FUNCTIONAL_HPP 29 | #define WEBSOCKETPP_COMMON_FUNCTIONAL_HPP 30 | 31 | #include 32 | 33 | // If we've determined that we're in full C++11 mode and the user hasn't 34 | // explicitly disabled the use of C++11 functional header, then prefer it to 35 | // boost. 36 | #if defined _WEBSOCKETPP_CPP11_INTERNAL_ && !defined _WEBSOCKETPP_NO_CPP11_FUNCTIONAL_ 37 | #ifndef _WEBSOCKETPP_CPP11_FUNCTIONAL_ 38 | #define _WEBSOCKETPP_CPP11_FUNCTIONAL_ 39 | #endif 40 | #endif 41 | 42 | // If we're on Visual Studio 2010 or higher and haven't explicitly disabled 43 | // the use of C++11 functional header then prefer it to boost. 44 | #if defined(_MSC_VER) && _MSC_VER >= 1600 && !defined _WEBSOCKETPP_NO_CPP11_FUNCTIONAL_ 45 | #ifndef _WEBSOCKETPP_CPP11_FUNCTIONAL_ 46 | #define _WEBSOCKETPP_CPP11_FUNCTIONAL_ 47 | #endif 48 | #endif 49 | 50 | 51 | 52 | #ifdef _WEBSOCKETPP_CPP11_FUNCTIONAL_ 53 | #include 54 | #else 55 | #include 56 | #include 57 | #include 58 | #endif 59 | 60 | 61 | 62 | namespace ws_websocketpp { 63 | namespace lib { 64 | 65 | #ifdef _WEBSOCKETPP_CPP11_FUNCTIONAL_ 66 | using std::function; 67 | using std::bind; 68 | using std::ref; 69 | namespace placeholders = std::placeholders; 70 | 71 | // There are some cases where a C++11 compiler balks at using std::ref 72 | // but a C++03 compiler using boost function requires boost::ref. As such 73 | // lib::ref is not useful in these cases. Instead this macro allows the use 74 | // of boost::ref in the case of a boost compile or no reference wrapper at 75 | // all in the case of a C++11 compile 76 | #define _WEBSOCKETPP_REF(x) x 77 | 78 | template 79 | void clear_function(T & x) { 80 | x = nullptr; 81 | } 82 | #else 83 | using boost::function; 84 | using boost::bind; 85 | using boost::ref; 86 | namespace placeholders { 87 | /// \todo this feels hacky, is there a better way? 88 | using ::_1; 89 | using ::_2; 90 | using ::_3; 91 | } 92 | 93 | // See above definition for more details on what this is and why it exists 94 | #define _WEBSOCKETPP_REF(x) boost::ref(x) 95 | 96 | template 97 | void clear_function(T & x) { 98 | x.clear(); 99 | } 100 | #endif 101 | 102 | } // namespace lib 103 | } // namespace ws_websocketpp 104 | 105 | #endif // WEBSOCKETPP_COMMON_FUNCTIONAL_HPP 106 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/memory.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_COMMON_MEMORY_HPP 29 | #define WEBSOCKETPP_COMMON_MEMORY_HPP 30 | 31 | #include 32 | 33 | // If we've determined that we're in full C++11 mode and the user hasn't 34 | // explicitly disabled the use of C++11 memory header, then prefer it to 35 | // boost. 36 | #if defined _WEBSOCKETPP_CPP11_INTERNAL_ && !defined _WEBSOCKETPP_NO_CPP11_MEMORY_ 37 | #ifndef _WEBSOCKETPP_CPP11_MEMORY_ 38 | #define _WEBSOCKETPP_CPP11_MEMORY_ 39 | #endif 40 | #endif 41 | 42 | // If we're on Visual Studio 2010 or higher and haven't explicitly disabled 43 | // the use of C++11 functional header then prefer it to boost. 44 | #if defined(_MSC_VER) && _MSC_VER >= 1600 && !defined _WEBSOCKETPP_NO_CPP11_MEMORY_ 45 | #ifndef _WEBSOCKETPP_CPP11_MEMORY_ 46 | #define _WEBSOCKETPP_CPP11_MEMORY_ 47 | #endif 48 | #endif 49 | 50 | 51 | 52 | #ifdef _WEBSOCKETPP_CPP11_MEMORY_ 53 | #include 54 | #else 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #endif 61 | 62 | namespace ws_websocketpp { 63 | namespace lib { 64 | 65 | #ifdef _WEBSOCKETPP_CPP11_MEMORY_ 66 | using std::shared_ptr; 67 | using std::weak_ptr; 68 | using std::enable_shared_from_this; 69 | using std::static_pointer_cast; 70 | using std::make_shared; 71 | using std::unique_ptr; 72 | 73 | typedef std::unique_ptr unique_ptr_uchar_array; 74 | #else 75 | using boost::shared_ptr; 76 | using boost::weak_ptr; 77 | using std::auto_ptr; 78 | using boost::enable_shared_from_this; 79 | using boost::static_pointer_cast; 80 | using boost::make_shared; 81 | 82 | typedef boost::scoped_array unique_ptr_uchar_array; 83 | #endif 84 | 85 | } // namespace lib 86 | } // namespace ws_websocketpp 87 | 88 | #endif // WEBSOCKETPP_COMMON_MEMORY_HPP 89 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/network.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_COMMON_NETWORK_HPP 29 | #define WEBSOCKETPP_COMMON_NETWORK_HPP 30 | 31 | // For ntohs and htons 32 | #if defined(_WIN32) 33 | #include 34 | #else 35 | //#include 36 | #include 37 | #endif 38 | 39 | #include 40 | 41 | namespace ws_websocketpp { 42 | namespace lib { 43 | namespace net { 44 | 45 | inline bool is_little_endian() { 46 | short int val = 0x1; 47 | char *ptr = reinterpret_cast(&val); 48 | return (ptr[0] == 1); 49 | } 50 | 51 | #define TYP_INIT 0 52 | #define TYP_SMLE 1 53 | #define TYP_BIGE 2 54 | 55 | /// Convert 64 bit value to network byte order 56 | /** 57 | * This method is prefixed to avoid conflicts with operating system level 58 | * macros for this functionality. 59 | * 60 | * TODO: figure out if it would be beneficial to use operating system level 61 | * macros for this. 62 | * 63 | * @param src The integer in host byte order 64 | * @return src converted to network byte order 65 | */ 66 | inline uint64_t _htonll(uint64_t src) { 67 | static int typ = TYP_INIT; 68 | unsigned char c; 69 | union { 70 | uint64_t ull; 71 | unsigned char c[8]; 72 | } x; 73 | if (typ == TYP_INIT) { 74 | x.ull = 0x01; 75 | typ = (x.c[7] == 0x01ULL) ? TYP_BIGE : TYP_SMLE; 76 | } 77 | if (typ == TYP_BIGE) 78 | return src; 79 | x.ull = src; 80 | c = x.c[0]; x.c[0] = x.c[7]; x.c[7] = c; 81 | c = x.c[1]; x.c[1] = x.c[6]; x.c[6] = c; 82 | c = x.c[2]; x.c[2] = x.c[5]; x.c[5] = c; 83 | c = x.c[3]; x.c[3] = x.c[4]; x.c[4] = c; 84 | return x.ull; 85 | } 86 | 87 | /// Convert 64 bit value to host byte order 88 | /** 89 | * This method is prefixed to avoid conflicts with operating system level 90 | * macros for this functionality. 91 | * 92 | * TODO: figure out if it would be beneficial to use operating system level 93 | * macros for this. 94 | * 95 | * @param src The integer in network byte order 96 | * @return src converted to host byte order 97 | */ 98 | inline uint64_t _ntohll(uint64_t src) { 99 | return _htonll(src); 100 | } 101 | 102 | } // net 103 | } // lib 104 | } // websocketpp 105 | 106 | #endif // WEBSOCKETPP_COMMON_NETWORK_HPP 107 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/platforms.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_COMMON_PLATFORMS_HPP 29 | #define WEBSOCKETPP_COMMON_PLATFORMS_HPP 30 | 31 | /** 32 | * This header contains any platform specific preprocessor adjustments that 33 | * don't fit somewhere else better. 34 | */ 35 | 36 | #if defined(_WIN32) && !defined(NOMINMAX) 37 | // don't define min and max macros that conflict with std::min and std::max 38 | #define NOMINMAX 39 | #endif 40 | 41 | // Bump up the variadic parameter max for Visual Studio 2012 42 | #if defined(_MSC_VER) && _MSC_VER == 1700 43 | #define _VARIADIC_MAX 8 44 | #endif 45 | 46 | #endif // WEBSOCKETPP_COMMON_PLATFORMS_HPP 47 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/random.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_COMMON_RANDOM_DEVICE_HPP 29 | #define WEBSOCKETPP_COMMON_RANDOM_DEVICE_HPP 30 | 31 | #include 32 | 33 | // If we've determined that we're in full C++11 mode and the user hasn't 34 | // explicitly disabled the use of C++11 random header, then prefer it to 35 | // boost. 36 | #if defined _WEBSOCKETPP_CPP11_INTERNAL_ && !defined _WEBSOCKETPP_NO_CPP11_RANDOM_DEVICE_ 37 | #ifndef _WEBSOCKETPP_CPP11_RANDOM_DEVICE_ 38 | #define _WEBSOCKETPP_CPP11_RANDOM_DEVICE_ 39 | #endif 40 | #endif 41 | 42 | 43 | // If we're on Visual Studio 2010 or higher and haven't explicitly disabled 44 | // the use of C++11 random header then prefer it to boost. 45 | #if defined(_MSC_VER) && _MSC_VER >= 1600 && !defined _WEBSOCKETPP_NO_CPP11_MEMORY_ 46 | #ifndef _WEBSOCKETPP_CPP11_MEMORY_ 47 | #define _WEBSOCKETPP_CPP11_MEMORY_ 48 | #endif 49 | #endif 50 | 51 | 52 | 53 | #ifdef _WEBSOCKETPP_CPP11_RANDOM_DEVICE_ 54 | #include 55 | #else 56 | #include 57 | 58 | #if (BOOST_VERSION/100000) == 1 && ((BOOST_VERSION/100)%1000) > 46 59 | #include 60 | #include 61 | #elif (BOOST_VERSION/100000) == 1 && ((BOOST_VERSION/100)%1000) >= 43 62 | #include 63 | #else 64 | // TODO: static_assert(false, "Could not find a suitable random_device") 65 | #endif 66 | #endif 67 | 68 | namespace ws_websocketpp { 69 | namespace lib { 70 | 71 | #ifdef _WEBSOCKETPP_CPP11_RANDOM_DEVICE_ 72 | using std::random_device; 73 | using std::uniform_int_distribution; 74 | #else 75 | using boost::random::random_device; 76 | using boost::random::uniform_int_distribution; 77 | #endif 78 | 79 | } // namespace lib 80 | } // namespace ws_websocketpp 81 | 82 | #endif // WEBSOCKETPP_COMMON_RANDOM_DEVICE_HPP 83 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/regex.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_COMMON_REGEX_HPP 29 | #define WEBSOCKETPP_COMMON_REGEX_HPP 30 | 31 | #if defined _WEBSOCKETPP_CPP11_STL_ && !defined _WEBSOCKETPP_NO_CPP11_REGEX_ 32 | #ifndef _WEBSOCKETPP_CPP11_REGEX_ 33 | #define _WEBSOCKETPP_CPP11_REGEX_ 34 | #endif 35 | #endif 36 | 37 | #ifdef _WEBSOCKETPP_CPP11_REGEX_ 38 | #include 39 | #else 40 | #include 41 | #endif 42 | 43 | namespace ws_websocketpp { 44 | namespace lib { 45 | 46 | #ifdef _WEBSOCKETPP_CPP11_REGEX_ 47 | using std::cmatch; 48 | using std::regex; 49 | using std::regex_match; 50 | #else 51 | using boost::cmatch; 52 | using boost::regex; 53 | using boost::regex_match; 54 | #endif 55 | 56 | } // namespace lib 57 | } // namespace ws_websocketpp 58 | 59 | #endif // WEBSOCKETPP_COMMON_REGEX_HPP 60 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/stdint.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_COMMON_STDINT_HPP 29 | #define WEBSOCKETPP_COMMON_STDINT_HPP 30 | 31 | #ifndef __STDC_LIMIT_MACROS 32 | #define __STDC_LIMIT_MACROS 1 33 | #endif 34 | 35 | #if defined (_WIN32) && defined (_MSC_VER) && (_MSC_VER < 1600) 36 | #include 37 | 38 | using boost::int8_t; 39 | using boost::int_least8_t; 40 | using boost::int_fast8_t; 41 | using boost::uint8_t; 42 | using boost::uint_least8_t; 43 | using boost::uint_fast8_t; 44 | 45 | using boost::int16_t; 46 | using boost::int_least16_t; 47 | using boost::int_fast16_t; 48 | using boost::uint16_t; 49 | using boost::uint_least16_t; 50 | using boost::uint_fast16_t; 51 | 52 | using boost::int32_t; 53 | using boost::int_least32_t; 54 | using boost::int_fast32_t; 55 | using boost::uint32_t; 56 | using boost::uint_least32_t; 57 | using boost::uint_fast32_t; 58 | 59 | #ifndef BOOST_NO_INT64_T 60 | using boost::int64_t; 61 | using boost::int_least64_t; 62 | using boost::int_fast64_t; 63 | using boost::uint64_t; 64 | using boost::uint_least64_t; 65 | using boost::uint_fast64_t; 66 | #endif 67 | using boost::intmax_t; 68 | using boost::uintmax_t; 69 | #else 70 | #include 71 | #endif 72 | 73 | #endif // WEBSOCKETPP_COMMON_STDINT_HPP 74 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/system_error.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_COMMON_SYSTEM_ERROR_HPP 29 | #define WEBSOCKETPP_COMMON_SYSTEM_ERROR_HPP 30 | 31 | 32 | #include 33 | 34 | // If we've determined that we're in full C++11 mode and the user hasn't 35 | // explicitly disabled the use of C++11 system_error header, then prefer it to 36 | // boost. 37 | #if defined _WEBSOCKETPP_CPP11_INTERNAL_ && !defined _WEBSOCKETPP_NO_CPP11_SYSTEM_ERROR_ 38 | #ifndef _WEBSOCKETPP_CPP11_SYSTEM_ERROR_ 39 | #define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_ 40 | #endif 41 | #endif 42 | 43 | // If we're on Visual Studio 2010 or higher and haven't explicitly disabled 44 | // the use of C++11 system_error header then prefer it to boost. 45 | #if defined(_MSC_VER) && _MSC_VER >= 1600 && !defined _WEBSOCKETPP_NO_CPP11_SYSTEM_ERROR_ 46 | #ifndef _WEBSOCKETPP_CPP11_SYSTEM_ERROR_ 47 | #define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_ 48 | #endif 49 | #endif 50 | 51 | 52 | 53 | #ifdef _WEBSOCKETPP_CPP11_SYSTEM_ERROR_ 54 | #include 55 | #else 56 | #include 57 | #include 58 | #endif 59 | 60 | namespace ws_websocketpp { 61 | namespace lib { 62 | 63 | #ifdef _WEBSOCKETPP_CPP11_SYSTEM_ERROR_ 64 | using std::errc; 65 | using std::error_code; 66 | using std::error_category; 67 | using std::error_condition; 68 | using std::system_error; 69 | #define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_ namespace std { 70 | #define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_ } 71 | #else 72 | namespace errc = boost::system::errc; 73 | using boost::system::error_code; 74 | using boost::system::error_category; 75 | using boost::system::error_condition; 76 | using boost::system::system_error; 77 | #define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_ namespace boost { namespace system { 78 | #define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_ }} 79 | #endif 80 | 81 | } // namespace lib 82 | } // namespace ws_websocketpp 83 | 84 | #endif // WEBSOCKETPP_COMMON_SYSTEM_ERROR_HPP 85 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/thread.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, 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_COMMON_THREAD_HPP 29 | #define WEBSOCKETPP_COMMON_THREAD_HPP 30 | 31 | #include 32 | 33 | // If we autodetect C++11 and haven't been explicitly instructed to not use 34 | // C++11 threads, then set the defines that instructs the rest of this header 35 | // to use C++11 and 36 | #if defined _WEBSOCKETPP_CPP11_INTERNAL_ && !defined _WEBSOCKETPP_NO_CPP11_THREAD_ 37 | // MinGW by default does not support C++11 thread/mutex so even if the 38 | // internal check for C++11 passes, ignore it if we are on MinGW 39 | #if (!defined(__MINGW32__) && !defined(__MINGW64__)) 40 | #ifndef _WEBSOCKETPP_CPP11_THREAD_ 41 | #define _WEBSOCKETPP_CPP11_THREAD_ 42 | #endif 43 | #endif 44 | #endif 45 | 46 | // If we're on Visual Studio 2013 or higher and haven't explicitly disabled 47 | // the use of C++11 thread header then prefer it to boost. 48 | #if defined(_MSC_VER) && _MSC_VER >= 1800 && !defined _WEBSOCKETPP_NO_CPP11_THREAD_ 49 | #ifndef _WEBSOCKETPP_CPP11_THREAD_ 50 | #define _WEBSOCKETPP_CPP11_THREAD_ 51 | #endif 52 | #endif 53 | 54 | #if defined(_WEBSOCKETPP_MINGW_THREAD_) 55 | #include 56 | #include 57 | #include 58 | #elif defined(_WEBSOCKETPP_CPP11_THREAD_) 59 | #include 60 | #include 61 | #include 62 | #else 63 | #include 64 | #include 65 | #include 66 | #endif 67 | 68 | namespace ws_websocketpp { 69 | namespace lib { 70 | 71 | #if defined(_WEBSOCKETPP_CPP11_THREAD_) || defined(_WEBSOCKETPP_MINGW_THREAD_) 72 | using std::mutex; 73 | using std::lock_guard; 74 | using std::thread; 75 | using std::unique_lock; 76 | using std::condition_variable; 77 | #else 78 | using boost::mutex; 79 | using boost::lock_guard; 80 | using boost::thread; 81 | using boost::unique_lock; 82 | using boost::condition_variable; 83 | #endif 84 | 85 | } // namespace lib 86 | } // namespace ws_websocketpp 87 | 88 | #endif // WEBSOCKETPP_COMMON_THREAD_HPP 89 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/time.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_COMMON_TIME_HPP 29 | #define WEBSOCKETPP_COMMON_TIME_HPP 30 | 31 | #include 32 | 33 | namespace ws_websocketpp { 34 | namespace lib { 35 | 36 | // Code in this header was inspired by the following article and includes some 37 | // code from the related project g2log. The g2log code is public domain licensed 38 | // http://kjellkod.wordpress.com/2013/01/22/exploring-c11-part-2-localtime-and-time-again/ 39 | 40 | /// Thread safe cross platform localtime 41 | inline std::tm localtime(std::time_t const & time) { 42 | std::tm tm_snapshot; 43 | #if (defined(__MINGW32__) || defined(__MINGW64__)) 44 | memcpy(&tm_snapshot, ::localtime(&time), sizeof(std::tm)); 45 | #elif (defined(WIN32) || defined(_WIN32) || defined(__WIN32__)) 46 | localtime_s(&tm_snapshot, &time); 47 | #else 48 | localtime_r(&time, &tm_snapshot); // POSIX 49 | #endif 50 | return tm_snapshot; 51 | } 52 | 53 | } // lib 54 | } // websocketpp 55 | 56 | #endif // WEBSOCKETPP_COMMON_TIME_HPP 57 | -------------------------------------------------------------------------------- /src/lib/websocketpp/common/type_traits.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, 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_COMMON_TYPE_TRAITS_HPP 29 | #define WEBSOCKETPP_COMMON_TYPE_TRAITS_HPP 30 | 31 | #include 32 | 33 | // If we've determined that we're in full C++11 mode and the user hasn't 34 | // explicitly disabled the use of C++11 functional header, then prefer it to 35 | // boost. 36 | #if defined _WEBSOCKETPP_CPP11_INTERNAL_ && !defined _WEBSOCKETPP_NO_CPP11_TYPE_TRAITS_ 37 | #ifndef _WEBSOCKETPP_CPP11_TYPE_TRAITS_ 38 | #define _WEBSOCKETPP_CPP11_TYPE_TRAITS_ 39 | #endif 40 | #endif 41 | 42 | 43 | #ifdef _WEBSOCKETPP_CPP11_TYPE_TRAITS_ 44 | #include 45 | #else 46 | #include 47 | #endif 48 | 49 | 50 | 51 | namespace ws_websocketpp { 52 | namespace lib { 53 | 54 | #ifdef _WEBSOCKETPP_CPP11_TYPE_TRAITS_ 55 | using std::aligned_storage; 56 | using std::is_same; 57 | #else 58 | using boost::aligned_storage; 59 | using boost::is_same; 60 | #endif 61 | 62 | } // namespace lib 63 | } // namespace ws_websocketpp 64 | 65 | #endif // WEBSOCKETPP_COMMON_TYPE_TRAITS_HPP 66 | -------------------------------------------------------------------------------- /src/lib/websocketpp/concurrency/basic.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_CONCURRENCY_BASIC_HPP 29 | #define WEBSOCKETPP_CONCURRENCY_BASIC_HPP 30 | 31 | #include 32 | 33 | namespace ws_websocketpp { 34 | namespace concurrency { 35 | 36 | /// Concurrency policy that uses std::mutex / boost::mutex 37 | class basic { 38 | public: 39 | typedef lib::mutex mutex_type; 40 | typedef lib::lock_guard scoped_lock_type; 41 | }; 42 | 43 | } // namespace concurrency 44 | } // namespace ws_websocketpp 45 | 46 | #endif // WEBSOCKETPP_CONCURRENCY_BASIC_HPP 47 | -------------------------------------------------------------------------------- /src/lib/websocketpp/concurrency/none.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_CONCURRENCY_NONE_HPP 29 | #define WEBSOCKETPP_CONCURRENCY_NONE_HPP 30 | 31 | namespace ws_websocketpp { 32 | 33 | /// Concurrency handling support 34 | namespace concurrency { 35 | 36 | /// Implementation for no-op locking primitives 37 | namespace none_impl { 38 | /// A fake mutex implementation that does nothing 39 | class fake_mutex { 40 | public: 41 | fake_mutex() {} 42 | ~fake_mutex() {} 43 | }; 44 | 45 | /// A fake lock guard implementation that does nothing 46 | class fake_lock_guard { 47 | public: 48 | explicit fake_lock_guard(fake_mutex) {} 49 | ~fake_lock_guard() {} 50 | }; 51 | } // namespace none_impl 52 | 53 | /// Stub concurrency policy that implements the interface using no-ops. 54 | /** 55 | * This policy documents the concurrency policy interface using no-ops. It can 56 | * be used as a reference or base for building a new concurrency policy. It can 57 | * also be used as is to disable all locking for endpoints used in purely single 58 | * threaded programs. 59 | */ 60 | class none { 61 | public: 62 | /// The type of a mutex primitive 63 | /** 64 | * std::mutex is an example. 65 | */ 66 | typedef none_impl::fake_mutex mutex_type; 67 | 68 | /// The type of a scoped/RAII lock primitive. 69 | /** 70 | * The scoped lock constructor should take a mutex_type as a parameter, 71 | * acquire that lock, and release it in its destructor. std::lock_guard is 72 | * an example. 73 | */ 74 | typedef none_impl::fake_lock_guard scoped_lock_type; 75 | }; 76 | 77 | } // namespace concurrency 78 | } // namespace ws_websocketpp 79 | 80 | #endif // WEBSOCKETPP_CONCURRENCY_ASYNC_HPP 81 | -------------------------------------------------------------------------------- /src/lib/websocketpp/config/asio.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_CONFIG_ASIO_TLS_HPP 29 | #define WEBSOCKETPP_CONFIG_ASIO_TLS_HPP 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | // Pull in non-tls config 36 | #include 37 | 38 | // Define TLS config 39 | namespace ws_websocketpp { 40 | namespace config { 41 | 42 | /// Server config with asio transport and TLS enabled 43 | struct asio_tls : public core { 44 | typedef asio_tls type; 45 | typedef core base; 46 | 47 | typedef base::concurrency_type concurrency_type; 48 | 49 | typedef base::request_type request_type; 50 | typedef base::response_type response_type; 51 | 52 | typedef base::message_type message_type; 53 | typedef base::con_msg_manager_type con_msg_manager_type; 54 | typedef base::endpoint_msg_manager_type endpoint_msg_manager_type; 55 | 56 | typedef base::alog_type alog_type; 57 | typedef base::elog_type elog_type; 58 | 59 | typedef base::rng_type rng_type; 60 | 61 | struct transport_config : public base::transport_config { 62 | typedef type::concurrency_type concurrency_type; 63 | typedef type::alog_type alog_type; 64 | typedef type::elog_type elog_type; 65 | typedef type::request_type request_type; 66 | typedef type::response_type response_type; 67 | typedef ws_websocketpp::transport::asio::tls_socket::endpoint socket_type; 68 | }; 69 | 70 | typedef ws_websocketpp::transport::asio::endpoint 71 | transport_type; 72 | }; 73 | 74 | } // namespace config 75 | } // namespace ws_websocketpp 76 | 77 | #endif // WEBSOCKETPP_CONFIG_ASIO_TLS_HPP 78 | -------------------------------------------------------------------------------- /src/lib/websocketpp/config/asio_client.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_CONFIG_ASIO_TLS_CLIENT_HPP 29 | #define WEBSOCKETPP_CONFIG_ASIO_TLS_CLIENT_HPP 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | // Pull in non-tls config 36 | #include 37 | 38 | // Define TLS config 39 | namespace ws_websocketpp { 40 | namespace config { 41 | 42 | /// Client config with asio transport and TLS enabled 43 | struct asio_tls_client : public core_client { 44 | typedef asio_tls_client type; 45 | typedef core_client base; 46 | 47 | typedef base::concurrency_type concurrency_type; 48 | 49 | typedef base::request_type request_type; 50 | typedef base::response_type response_type; 51 | 52 | typedef base::message_type message_type; 53 | typedef base::con_msg_manager_type con_msg_manager_type; 54 | typedef base::endpoint_msg_manager_type endpoint_msg_manager_type; 55 | 56 | typedef base::alog_type alog_type; 57 | typedef base::elog_type elog_type; 58 | 59 | typedef base::rng_type rng_type; 60 | 61 | struct transport_config : public base::transport_config { 62 | typedef type::concurrency_type concurrency_type; 63 | typedef type::alog_type alog_type; 64 | typedef type::elog_type elog_type; 65 | typedef type::request_type request_type; 66 | typedef type::response_type response_type; 67 | typedef ws_websocketpp::transport::asio::tls_socket::endpoint socket_type; 68 | }; 69 | 70 | typedef ws_websocketpp::transport::asio::endpoint 71 | transport_type; 72 | }; 73 | 74 | } // namespace config 75 | } // namespace ws_websocketpp 76 | 77 | #endif // WEBSOCKETPP_CONFIG_ASIO_TLS_CLIENT_HPP 78 | -------------------------------------------------------------------------------- /src/lib/websocketpp/config/asio_no_tls.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_CONFIG_ASIO_HPP 29 | #define WEBSOCKETPP_CONFIG_ASIO_HPP 30 | 31 | #include 32 | #include 33 | 34 | namespace ws_websocketpp { 35 | namespace config { 36 | 37 | /// Server config with asio transport and TLS disabled 38 | struct asio : public core { 39 | typedef asio type; 40 | typedef core base; 41 | 42 | typedef base::concurrency_type concurrency_type; 43 | 44 | typedef base::request_type request_type; 45 | typedef base::response_type response_type; 46 | 47 | typedef base::message_type message_type; 48 | typedef base::con_msg_manager_type con_msg_manager_type; 49 | typedef base::endpoint_msg_manager_type endpoint_msg_manager_type; 50 | 51 | typedef base::alog_type alog_type; 52 | typedef base::elog_type elog_type; 53 | 54 | typedef base::rng_type rng_type; 55 | 56 | struct transport_config : public base::transport_config { 57 | typedef type::concurrency_type concurrency_type; 58 | typedef type::alog_type alog_type; 59 | typedef type::elog_type elog_type; 60 | typedef type::request_type request_type; 61 | typedef type::response_type response_type; 62 | typedef ws_websocketpp::transport::asio::basic_socket::endpoint 63 | socket_type; 64 | }; 65 | 66 | typedef ws_websocketpp::transport::asio::endpoint 67 | transport_type; 68 | }; 69 | 70 | } // namespace config 71 | } // namespace ws_websocketpp 72 | 73 | #endif // WEBSOCKETPP_CONFIG_ASIO_HPP 74 | -------------------------------------------------------------------------------- /src/lib/websocketpp/config/asio_no_tls_client.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_CONFIG_ASIO_CLIENT_HPP 29 | #define WEBSOCKETPP_CONFIG_ASIO_CLIENT_HPP 30 | 31 | #include 32 | #include 33 | 34 | namespace ws_websocketpp { 35 | namespace config { 36 | 37 | /// Client config with asio transport and TLS disabled 38 | struct asio_client : public core_client { 39 | typedef asio_client type; 40 | typedef core_client base; 41 | 42 | typedef base::concurrency_type concurrency_type; 43 | 44 | typedef base::request_type request_type; 45 | typedef base::response_type response_type; 46 | 47 | typedef base::message_type message_type; 48 | typedef base::con_msg_manager_type con_msg_manager_type; 49 | typedef base::endpoint_msg_manager_type endpoint_msg_manager_type; 50 | 51 | typedef base::alog_type alog_type; 52 | typedef base::elog_type elog_type; 53 | 54 | typedef base::rng_type rng_type; 55 | 56 | struct transport_config : public base::transport_config { 57 | typedef type::concurrency_type concurrency_type; 58 | typedef type::alog_type alog_type; 59 | typedef type::elog_type elog_type; 60 | typedef type::request_type request_type; 61 | typedef type::response_type response_type; 62 | typedef ws_websocketpp::transport::asio::basic_socket::endpoint 63 | socket_type; 64 | }; 65 | 66 | typedef ws_websocketpp::transport::asio::endpoint 67 | transport_type; 68 | }; 69 | 70 | } // namespace config 71 | } // namespace ws_websocketpp 72 | 73 | #endif // WEBSOCKETPP_CONFIG_ASIO_CLIENT_HPP 74 | -------------------------------------------------------------------------------- /src/lib/websocketpp/config/boost_config.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 | // This header defines WebSocket++ macros for C++11 compatibility based on the 29 | // Boost.Config library. This will correctly configure most target platforms 30 | // simply by including this header before any other WebSocket++ header. 31 | 32 | #ifndef WEBSOCKETPP_CONFIG_BOOST_CONFIG_HPP 33 | #define WEBSOCKETPP_CONFIG_BOOST_CONFIG_HPP 34 | 35 | #include 36 | 37 | // _WEBSOCKETPP_CPP11_MEMORY_ and _WEBSOCKETPP_CPP11_FUNCTIONAL_ presently 38 | // only work if either both or neither is defined. 39 | #if !defined BOOST_NO_CXX11_SMART_PTR && !defined BOOST_NO_CXX11_HDR_FUNCTIONAL 40 | #define _WEBSOCKETPP_CPP11_MEMORY_ 41 | #define _WEBSOCKETPP_CPP11_FUNCTIONAL_ 42 | #endif 43 | 44 | #ifdef BOOST_ASIO_HAS_STD_CHRONO 45 | #define _WEBSOCKETPP_CPP11_CHRONO_ 46 | #endif 47 | 48 | #ifndef BOOST_NO_CXX11_HDR_RANDOM 49 | #define _WEBSOCKETPP_CPP11_RANDOM_DEVICE_ 50 | #endif 51 | 52 | #ifndef BOOST_NO_CXX11_HDR_REGEX 53 | #define _WEBSOCKETPP_CPP11_REGEX_ 54 | #endif 55 | 56 | #ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR 57 | #define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_ 58 | #endif 59 | 60 | #ifndef BOOST_NO_CXX11_HDR_THREAD 61 | #define _WEBSOCKETPP_CPP11_THREAD_ 62 | #endif 63 | 64 | #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST 65 | #define _WEBSOCKETPP_INITIALIZER_LISTS_ 66 | #endif 67 | 68 | #define _WEBSOCKETPP_NOEXCEPT_TOKEN_ BOOST_NOEXCEPT 69 | #define _WEBSOCKETPP_CONSTEXPR_TOKEN_ BOOST_CONSTEXPR 70 | // TODO: nullptr support 71 | 72 | #endif // WEBSOCKETPP_CONFIG_BOOST_CONFIG_HPP 73 | -------------------------------------------------------------------------------- /src/lib/websocketpp/config/debug_asio.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_CONFIG_ASIO_TLS_DEBUG_HPP 29 | #define WEBSOCKETPP_CONFIG_ASIO_TLS_DEBUG_HPP 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | // Pull in non-tls config 36 | #include 37 | 38 | // Define TLS config 39 | namespace ws_websocketpp { 40 | namespace config { 41 | 42 | /// Client/Server debug config with asio transport and TLS enabled 43 | struct debug_asio_tls : public debug_core { 44 | typedef debug_asio_tls type; 45 | typedef debug_core base; 46 | 47 | typedef base::concurrency_type concurrency_type; 48 | 49 | typedef base::request_type request_type; 50 | typedef base::response_type response_type; 51 | 52 | typedef base::message_type message_type; 53 | typedef base::con_msg_manager_type con_msg_manager_type; 54 | typedef base::endpoint_msg_manager_type endpoint_msg_manager_type; 55 | 56 | typedef base::alog_type alog_type; 57 | typedef base::elog_type elog_type; 58 | 59 | typedef base::rng_type rng_type; 60 | 61 | struct transport_config : public base::transport_config { 62 | typedef type::concurrency_type concurrency_type; 63 | typedef type::alog_type alog_type; 64 | typedef type::elog_type elog_type; 65 | typedef type::request_type request_type; 66 | typedef type::response_type response_type; 67 | typedef ws_websocketpp::transport::asio::tls_socket::endpoint socket_type; 68 | }; 69 | 70 | typedef ws_websocketpp::transport::asio::endpoint 71 | transport_type; 72 | }; 73 | 74 | } // namespace config 75 | } // namespace ws_websocketpp 76 | 77 | #endif // WEBSOCKETPP_CONFIG_ASIO_TLS_DEBUG_HPP 78 | -------------------------------------------------------------------------------- /src/lib/websocketpp/config/debug_asio_no_tls.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_CONFIG_ASIO_DEBUG_HPP 29 | #define WEBSOCKETPP_CONFIG_ASIO_DEBUG_HPP 30 | 31 | #include 32 | #include 33 | 34 | namespace ws_websocketpp { 35 | namespace config { 36 | 37 | /// Client/Server debug config with asio transport and TLS disabled 38 | struct debug_asio : public debug_core { 39 | typedef debug_asio type; 40 | typedef debug_core base; 41 | 42 | typedef base::concurrency_type concurrency_type; 43 | 44 | typedef base::request_type request_type; 45 | typedef base::response_type response_type; 46 | 47 | typedef base::message_type message_type; 48 | typedef base::con_msg_manager_type con_msg_manager_type; 49 | typedef base::endpoint_msg_manager_type endpoint_msg_manager_type; 50 | 51 | typedef base::alog_type alog_type; 52 | typedef base::elog_type elog_type; 53 | 54 | typedef base::rng_type rng_type; 55 | 56 | struct transport_config : public base::transport_config { 57 | typedef type::concurrency_type concurrency_type; 58 | typedef type::alog_type alog_type; 59 | typedef type::elog_type elog_type; 60 | typedef type::request_type request_type; 61 | typedef type::response_type response_type; 62 | typedef ws_websocketpp::transport::asio::basic_socket::endpoint 63 | socket_type; 64 | }; 65 | 66 | typedef ws_websocketpp::transport::asio::endpoint 67 | transport_type; 68 | }; 69 | 70 | } // namespace config 71 | } // namespace ws_websocketpp 72 | 73 | #endif // WEBSOCKETPP_CONFIG_ASIO_DEBUG_HPP 74 | -------------------------------------------------------------------------------- /src/lib/websocketpp/config/minimal_client.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_CONFIG_MINIMAL_CLIENT_HPP 29 | #define WEBSOCKETPP_CONFIG_MINIMAL_CLIENT_HPP 30 | 31 | #include 32 | 33 | namespace ws_websocketpp { 34 | namespace config { 35 | 36 | /// Client config with minimal dependencies 37 | /** 38 | * This config strips out as many dependencies as possible. It is suitable for 39 | * use as a base class for custom configs that want to implement or choose their 40 | * own policies for components that even the core config includes. 41 | * 42 | * NOTE: this config stubs out enough that it cannot be used directly. You must 43 | * supply at least a transport policy and a cryptographically secure random 44 | * number generation policy for a config based on `minimal_client` to do 45 | * anything useful. 46 | * 47 | * Present dependency list for minimal_server config: 48 | * 49 | * C++98 STL: 50 | * 51 | * 52 | * 53 | * 54 | * 55 | * 56 | * C++11 STL or Boost 57 | * 58 | * 59 | * 60 | * 61 | * Operating System: 62 | * or 63 | * or (for ntohl.. could potentially bundle this) 64 | * 65 | * @since 0.4.0-dev 66 | */ 67 | typedef minimal_server minimal_client; 68 | 69 | } // namespace config 70 | } // namespace ws_websocketpp 71 | 72 | #endif // WEBSOCKETPP_CONFIG_MINIMAL_CLIENT_HPP 73 | -------------------------------------------------------------------------------- /src/lib/websocketpp/connection_base.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_CONNECTION_BASE_HPP 29 | #define WEBSOCKETPP_CONNECTION_BASE_HPP 30 | 31 | namespace ws_websocketpp { 32 | 33 | /// Stub for user supplied base class. 34 | class connection_base {}; 35 | 36 | } // namespace ws_websocketpp 37 | 38 | #endif // WEBSOCKETPP_CONNECTION_BASE_HPP 39 | -------------------------------------------------------------------------------- /src/lib/websocketpp/endpoint_base.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_ENDPOINT_BASE_HPP 29 | #define WEBSOCKETPP_ENDPOINT_BASE_HPP 30 | 31 | namespace ws_websocketpp { 32 | 33 | /// Stub for user supplied base class. 34 | class endpoint_base {}; 35 | 36 | } // namespace ws_websocketpp 37 | 38 | #endif // WEBSOCKETPP_ENDPOINT_BASE_HPP 39 | -------------------------------------------------------------------------------- /src/lib/websocketpp/extensions/extension.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_EXTENSION_HPP 29 | #define WEBSOCKETPP_EXTENSION_HPP 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | namespace ws_websocketpp { 38 | 39 | /** 40 | * Some generic information about extensions 41 | * 42 | * Each extension object has an implemented flag. It can be retrieved by calling 43 | * is_implemented(). This compile time flag indicates whether or not the object 44 | * in question actually implements the extension or if it is a placeholder stub 45 | * 46 | * Each extension object also has an enabled flag. It can be retrieved by 47 | * calling is_enabled(). This runtime flag indicates whether or not the 48 | * extension has been negotiated for this connection. 49 | */ 50 | namespace extensions { 51 | 52 | namespace error { 53 | enum value { 54 | /// Catch all 55 | general = 1, 56 | 57 | /// Extension disabled 58 | disabled 59 | }; 60 | 61 | class category : public lib::error_category { 62 | public: 63 | category() {} 64 | 65 | const char *name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_ { 66 | return "websocketpp.extension"; 67 | } 68 | 69 | std::string message(int value) const { 70 | switch(value) { 71 | case general: 72 | return "Generic extension error"; 73 | case disabled: 74 | return "Use of methods from disabled extension"; 75 | default: 76 | return "Unknown permessage-compress error"; 77 | } 78 | } 79 | }; 80 | 81 | inline lib::error_category const & get_category() { 82 | static category instance; 83 | return instance; 84 | } 85 | 86 | inline lib::error_code make_error_code(error::value e) { 87 | return lib::error_code(static_cast(e), get_category()); 88 | } 89 | 90 | } // namespace error 91 | } // namespace extensions 92 | } // namespace ws_websocketpp 93 | 94 | _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_ 95 | template<> struct is_error_code_enum 96 | 97 | { 98 | static const bool value = true; 99 | }; 100 | _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_ 101 | 102 | #endif // WEBSOCKETPP_EXTENSION_HPP 103 | -------------------------------------------------------------------------------- /src/lib/websocketpp/extensions/permessage_deflate/disabled.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_EXTENSION_PERMESSAGE_DEFLATE_DISABLED_HPP 29 | #define WEBSOCKETPP_EXTENSION_PERMESSAGE_DEFLATE_DISABLED_HPP 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace ws_websocketpp { 43 | namespace extensions { 44 | namespace permessage_deflate { 45 | 46 | /// Stub class for use when disabling permessage_deflate extension 47 | /** 48 | * This class is a stub that implements the permessage_deflate interface 49 | * with minimal dependencies. It is used to disable permessage_deflate 50 | * functionality at compile time without loading any unnecessary code. 51 | */ 52 | template 53 | class disabled { 54 | typedef std::pair err_str_pair; 55 | 56 | public: 57 | /// Negotiate extension 58 | /** 59 | * The disabled extension always fails the negotiation with a disabled 60 | * error. 61 | * 62 | * @param offer Attribute from client's offer 63 | * @return Status code and value to return to remote endpoint 64 | */ 65 | err_str_pair negotiate(http::attribute_list const &) { 66 | return make_pair(make_error_code(error::disabled),std::string()); 67 | } 68 | 69 | /// Initialize state 70 | /** 71 | * For the disabled extension state initialization is a no-op. 72 | * 73 | * @param is_server True to initialize as a server, false for a client. 74 | * @return A code representing the error that occurred, if any 75 | */ 76 | lib::error_code init(bool) { 77 | return lib::error_code(); 78 | } 79 | 80 | /// Returns true if the extension is capable of providing 81 | /// permessage_deflate functionality 82 | bool is_implemented() const { 83 | return false; 84 | } 85 | 86 | /// Returns true if permessage_deflate functionality is active for this 87 | /// connection 88 | bool is_enabled() const { 89 | return false; 90 | } 91 | 92 | /// Generate extension offer 93 | /** 94 | * Creates an offer string to include in the Sec-WebSocket-Extensions 95 | * header of outgoing client requests. 96 | * 97 | * @return A WebSocket extension offer string for this extension 98 | */ 99 | std::string generate_offer() const { 100 | return ""; 101 | } 102 | 103 | /// Compress bytes 104 | /** 105 | * @param [in] in String to compress 106 | * @param [out] out String to append compressed bytes to 107 | * @return Error or status code 108 | */ 109 | lib::error_code compress(std::string const &, std::string &) { 110 | return make_error_code(error::disabled); 111 | } 112 | 113 | /// Decompress bytes 114 | /** 115 | * @param buf Byte buffer to decompress 116 | * @param len Length of buf 117 | * @param out String to append decompressed bytes to 118 | * @return Error or status code 119 | */ 120 | lib::error_code decompress(uint8_t const *, size_t, std::string &) { 121 | return make_error_code(error::disabled); 122 | } 123 | }; 124 | 125 | } // namespace permessage_deflate 126 | } // namespace extensions 127 | } // namespace ws_websocketpp 128 | 129 | #endif // WEBSOCKETPP_EXTENSION_PERMESSAGE_DEFLATE_DISABLED_HPP 130 | -------------------------------------------------------------------------------- /src/lib/websocketpp/http/request.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 HTTP_PARSER_REQUEST_HPP 29 | #define HTTP_PARSER_REQUEST_HPP 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | namespace ws_websocketpp { 37 | namespace http { 38 | namespace parser { 39 | 40 | /// Stores, parses, and manipulates HTTP requests 41 | /** 42 | * http::request provides the following functionality for working with HTTP 43 | * requests. 44 | * 45 | * - Initialize request via manually setting each element 46 | * - Initialize request via reading raw bytes and parsing 47 | * - Once initialized, access individual parsed elements 48 | * - Once initialized, read entire request as raw bytes 49 | */ 50 | class request : public parser { 51 | public: 52 | typedef request type; 53 | typedef lib::shared_ptr ptr; 54 | 55 | request() 56 | : m_buf(lib::make_shared()) 57 | , m_ready(false) {} 58 | 59 | /// Process bytes in the input buffer 60 | /** 61 | * Process up to len bytes from input buffer buf. Returns the number of 62 | * bytes processed. Bytes left unprocessed means bytes left over after the 63 | * final header delimiters. 64 | * 65 | * Consume is a streaming processor. It may be called multiple times on one 66 | * request and the full headers need not be available before processing can 67 | * begin. If the end of the request was reached during this call to consume 68 | * the ready flag will be set. Further calls to consume once ready will be 69 | * ignored. 70 | * 71 | * Consume will throw an http::exception in the case of an error. Typical 72 | * error reasons include malformed requests, incomplete requests, and max 73 | * header size being reached. 74 | * 75 | * @param buf Pointer to byte buffer 76 | * @param len Size of byte buffer 77 | * @return Number of bytes processed. 78 | */ 79 | size_t consume(char const * buf, size_t len); 80 | 81 | /// Returns whether or not the request is ready for reading. 82 | bool ready() const { 83 | return m_ready; 84 | } 85 | 86 | /// Returns the full raw request (including the body) 87 | std::string raw() const; 88 | 89 | /// Returns the raw request headers only (similar to an HTTP HEAD request) 90 | std::string raw_head() const; 91 | 92 | /// Set the HTTP method. Must be a valid HTTP token 93 | void set_method(std::string const & method); 94 | 95 | /// Return the request method 96 | std::string const & get_method() const { 97 | return m_method; 98 | } 99 | 100 | /// Set the HTTP uri. Must be a valid HTTP uri 101 | void set_uri(std::string const & uri); 102 | 103 | /// Return the requested URI 104 | std::string const & get_uri() const { 105 | return m_uri; 106 | } 107 | 108 | private: 109 | /// Helper function for message::consume. Process request line 110 | void process(std::string::iterator begin, std::string::iterator end); 111 | 112 | lib::shared_ptr m_buf; 113 | std::string m_method; 114 | std::string m_uri; 115 | bool m_ready; 116 | }; 117 | 118 | } // namespace parser 119 | } // namespace http 120 | } // namespace ws_websocketpp 121 | 122 | #include 123 | 124 | #endif // HTTP_PARSER_REQUEST_HPP 125 | -------------------------------------------------------------------------------- /src/lib/websocketpp/impl/utilities_impl.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_UTILITIES_IMPL_HPP 29 | #define WEBSOCKETPP_UTILITIES_IMPL_HPP 30 | 31 | #include 32 | #include 33 | 34 | namespace ws_websocketpp { 35 | namespace utility { 36 | 37 | inline std::string to_lower(std::string const & in) { 38 | std::string out = in; 39 | std::transform(out.begin(),out.end(),out.begin(),::tolower); 40 | return out; 41 | } 42 | 43 | inline std::string to_hex(std::string const & input) { 44 | std::string output; 45 | std::string hex = "0123456789ABCDEF"; 46 | 47 | for (size_t i = 0; i < input.size(); i++) { 48 | output += hex[(input[i] & 0xF0) >> 4]; 49 | output += hex[input[i] & 0x0F]; 50 | output += " "; 51 | } 52 | 53 | return output; 54 | } 55 | 56 | inline std::string to_hex(uint8_t const * input, size_t length) { 57 | std::string output; 58 | std::string hex = "0123456789ABCDEF"; 59 | 60 | for (size_t i = 0; i < length; i++) { 61 | output += hex[(input[i] & 0xF0) >> 4]; 62 | output += hex[input[i] & 0x0F]; 63 | output += " "; 64 | } 65 | 66 | return output; 67 | } 68 | 69 | inline std::string to_hex(const char* input,size_t length) { 70 | return to_hex(reinterpret_cast(input),length); 71 | } 72 | 73 | inline std::string string_replace_all(std::string subject, std::string const & 74 | search, std::string const & replace) 75 | { 76 | size_t pos = 0; 77 | while((pos = subject.find(search, pos)) != std::string::npos) { 78 | subject.replace(pos, search.length(), replace); 79 | pos += replace.length(); 80 | } 81 | return subject; 82 | } 83 | 84 | } // namespace utility 85 | } // namespace ws_websocketpp 86 | 87 | #endif // WEBSOCKETPP_UTILITIES_IMPL_HPP 88 | -------------------------------------------------------------------------------- /src/lib/websocketpp/logger/stub.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_LOGGER_STUB_HPP 29 | #define WEBSOCKETPP_LOGGER_STUB_HPP 30 | 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | 37 | namespace ws_websocketpp { 38 | namespace log { 39 | 40 | /// Stub logger that ignores all input 41 | class stub { 42 | public: 43 | /// Construct the logger 44 | /** 45 | * @param hint A channel type specific hint for how to construct the logger 46 | */ 47 | explicit stub(channel_type_hint::value) {} 48 | 49 | /// Construct the logger 50 | /** 51 | * @param default_channels A set of channels to statically enable 52 | * @param hint A channel type specific hint for how to construct the logger 53 | */ 54 | stub(level, channel_type_hint::value) {} 55 | _WEBSOCKETPP_CONSTEXPR_TOKEN_ stub() {} 56 | 57 | /// Dynamically enable the given list of channels 58 | /** 59 | * All operations on the stub logger are no-ops and all arguments are 60 | * ignored 61 | * 62 | * @param channels The package of channels to enable 63 | */ 64 | void set_channels(level) {} 65 | 66 | /// Dynamically disable the given list of channels 67 | /** 68 | * All operations on the stub logger are no-ops and all arguments are 69 | * ignored 70 | * 71 | * @param channels The package of channels to disable 72 | */ 73 | void clear_channels(level) {} 74 | 75 | /// Write a string message to the given channel 76 | /** 77 | * Writing on the stub logger is a no-op and all arguments are ignored 78 | * 79 | * @param channel The channel to write to 80 | * @param msg The message to write 81 | */ 82 | void write(level, std::string const &) {} 83 | 84 | /// Write a cstring message to the given channel 85 | /** 86 | * Writing on the stub logger is a no-op and all arguments are ignored 87 | * 88 | * @param channel The channel to write to 89 | * @param msg The message to write 90 | */ 91 | void write(level, char const *) {} 92 | 93 | /// Test whether a channel is statically enabled 94 | /** 95 | * The stub logger has no channels so all arguments are ignored and 96 | * `static_test` always returns false. 97 | * 98 | * @param channel The package of channels to test 99 | */ 100 | _WEBSOCKETPP_CONSTEXPR_TOKEN_ bool static_test(level) const { 101 | return false; 102 | } 103 | 104 | /// Test whether a channel is dynamically enabled 105 | /** 106 | * The stub logger has no channels so all arguments are ignored and 107 | * `dynamic_test` always returns false. 108 | * 109 | * @param channel The package of channels to test 110 | */ 111 | bool dynamic_test(level) { 112 | return false; 113 | } 114 | }; 115 | 116 | } // log 117 | } // websocketpp 118 | 119 | #endif // WEBSOCKETPP_LOGGER_STUB_HPP 120 | -------------------------------------------------------------------------------- /src/lib/websocketpp/logger/syslog.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 | * The initial version of this logging policy was contributed to the WebSocket++ 28 | * project by Tom Hughes. 29 | */ 30 | 31 | #ifndef WEBSOCKETPP_LOGGER_SYSLOG_HPP 32 | #define WEBSOCKETPP_LOGGER_SYSLOG_HPP 33 | 34 | #include 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | namespace ws_websocketpp { 42 | namespace log { 43 | 44 | /// Basic logger that outputs to syslog 45 | template 46 | class syslog : public basic { 47 | public: 48 | typedef basic base; 49 | 50 | /// Construct the logger 51 | /** 52 | * @param hint A channel type specific hint for how to construct the logger 53 | */ 54 | syslog(channel_type_hint::value hint = 55 | channel_type_hint::access) 56 | : basic(hint), m_channel_type_hint(hint) {} 57 | 58 | /// Construct the logger 59 | /** 60 | * @param channels A set of channels to statically enable 61 | * @param hint A channel type specific hint for how to construct the logger 62 | */ 63 | syslog(level channels, channel_type_hint::value hint = 64 | channel_type_hint::access) 65 | : basic(channels, hint), m_channel_type_hint(hint) {} 66 | 67 | /// Write a string message to the given channel 68 | /** 69 | * @param channel The channel to write to 70 | * @param msg The message to write 71 | */ 72 | void write(level channel, std::string const & msg) { 73 | write(channel, msg.c_str()); 74 | } 75 | 76 | /// Write a cstring message to the given channel 77 | /** 78 | * @param channel The channel to write to 79 | * @param msg The message to write 80 | */ 81 | void write(level channel, char const * msg) { 82 | scoped_lock_type lock(base::m_lock); 83 | if (!this->dynamic_test(channel)) { return; } 84 | ::syslog(syslog_priority(channel), "[%s] %s", 85 | names::channel_name(channel), msg); 86 | } 87 | private: 88 | typedef typename base::scoped_lock_type scoped_lock_type; 89 | 90 | /// The default level is used for all access logs and any error logs that 91 | /// don't trivially map to one of the standard syslog levels. 92 | static int const default_level = LOG_INFO; 93 | 94 | /// retrieve the syslog priority code given a WebSocket++ channel 95 | /** 96 | * @param channel The level to look up 97 | * @return The syslog level associated with `channel` 98 | */ 99 | int syslog_priority(level channel) const { 100 | if (m_channel_type_hint == channel_type_hint::access) { 101 | return syslog_priority_access(channel); 102 | } else { 103 | return syslog_priority_error(channel); 104 | } 105 | } 106 | 107 | /// retrieve the syslog priority code given a WebSocket++ error channel 108 | /** 109 | * @param channel The level to look up 110 | * @return The syslog level associated with `channel` 111 | */ 112 | int syslog_priority_error(level channel) const { 113 | switch (channel) { 114 | case elevel::devel: 115 | return LOG_DEBUG; 116 | case elevel::library: 117 | return LOG_DEBUG; 118 | case elevel::info: 119 | return LOG_INFO; 120 | case elevel::warn: 121 | return LOG_WARNING; 122 | case elevel::rerror: 123 | return LOG_ERR; 124 | case elevel::fatal: 125 | return LOG_CRIT; 126 | default: 127 | return default_level; 128 | } 129 | } 130 | 131 | /// retrieve the syslog priority code given a WebSocket++ access channel 132 | /** 133 | * @param channel The level to look up 134 | * @return The syslog level associated with `channel` 135 | */ 136 | _WEBSOCKETPP_CONSTEXPR_TOKEN_ int syslog_priority_access(level) const { 137 | return default_level; 138 | } 139 | 140 | channel_type_hint::value m_channel_type_hint; 141 | }; 142 | 143 | } // log 144 | } // websocketpp 145 | 146 | #endif // WEBSOCKETPP_LOGGER_SYSLOG_HPP 147 | -------------------------------------------------------------------------------- /src/lib/websocketpp/message_buffer/alloc.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_MESSAGE_BUFFER_ALLOC_HPP 29 | #define WEBSOCKETPP_MESSAGE_BUFFER_ALLOC_HPP 30 | 31 | #include 32 | #include 33 | 34 | namespace ws_websocketpp { 35 | namespace message_buffer { 36 | namespace alloc { 37 | 38 | /// A connection message manager that allocates a new message for each 39 | /// request. 40 | template 41 | class con_msg_manager 42 | : public lib::enable_shared_from_this > 43 | { 44 | public: 45 | typedef con_msg_manager type; 46 | typedef lib::shared_ptr ptr; 47 | typedef lib::weak_ptr weak_ptr; 48 | 49 | typedef typename message::ptr message_ptr; 50 | 51 | /// Get an empty message buffer 52 | /** 53 | * @return A shared pointer to an empty new message 54 | */ 55 | message_ptr get_message() { 56 | return message_ptr(lib::make_shared(type::shared_from_this())); 57 | } 58 | 59 | /// Get a message buffer with specified size and opcode 60 | /** 61 | * @param op The opcode to use 62 | * @param size Minimum size in bytes to request for the message payload. 63 | * 64 | * @return A shared pointer to a new message with specified size. 65 | */ 66 | message_ptr get_message(frame::opcode::value op,size_t size) { 67 | return message_ptr(lib::make_shared(type::shared_from_this(),op,size)); 68 | } 69 | 70 | /// Recycle a message 71 | /** 72 | * This method shouldn't be called. If it is, return false to indicate an 73 | * error. The rest of the method recycle chain should notice this and free 74 | * the memory. 75 | * 76 | * @param msg The message to be recycled. 77 | * 78 | * @return true if the message was successfully recycled, false otherwse. 79 | */ 80 | bool recycle(message *) { 81 | return false; 82 | } 83 | }; 84 | 85 | /// An endpoint message manager that allocates a new manager for each 86 | /// connection. 87 | template 88 | class endpoint_msg_manager { 89 | public: 90 | typedef typename con_msg_manager::ptr con_msg_man_ptr; 91 | 92 | /// Get a pointer to a connection message manager 93 | /** 94 | * @return A pointer to the requested connection message manager. 95 | */ 96 | con_msg_man_ptr get_manager() const { 97 | return con_msg_man_ptr(lib::make_shared()); 98 | } 99 | }; 100 | 101 | } // namespace alloc 102 | } // namespace message_buffer 103 | } // namespace ws_websocketpp 104 | 105 | #endif // WEBSOCKETPP_MESSAGE_BUFFER_ALLOC_HPP 106 | -------------------------------------------------------------------------------- /src/lib/websocketpp/processors/hybi07.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_PROCESSOR_HYBI07_HPP 29 | #define WEBSOCKETPP_PROCESSOR_HYBI07_HPP 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | namespace ws_websocketpp { 37 | namespace processor { 38 | 39 | /// Processor for Hybi Draft version 07 40 | /** 41 | * The primary difference between 07 and 08 is a version number. 42 | */ 43 | template 44 | class hybi07 : public hybi08 { 45 | public: 46 | typedef typename config::request_type request_type; 47 | 48 | typedef typename config::con_msg_manager_type::ptr msg_manager_ptr; 49 | typedef typename config::rng_type rng_type; 50 | 51 | explicit hybi07(bool secure, bool p_is_server, msg_manager_ptr manager, rng_type& rng) 52 | : hybi08(secure, p_is_server, manager, rng) {} 53 | 54 | /// Fill in a set of request headers for a client connection request 55 | /** 56 | * The Hybi 07 processor only implements incoming connections so this will 57 | * always return an error. 58 | * 59 | * @param [out] req Set of headers to fill in 60 | * @param [in] uri The uri being connected to 61 | * @param [in] subprotocols The list of subprotocols to request 62 | */ 63 | lib::error_code client_handshake_request(request_type &, uri_ptr, 64 | std::vector const &) const 65 | { 66 | return error::make_error_code(error::no_protocol_support); 67 | } 68 | 69 | int get_version() const { 70 | return 7; 71 | } 72 | private: 73 | }; 74 | 75 | } // namespace processor 76 | } // namespace ws_websocketpp 77 | 78 | #endif //WEBSOCKETPP_PROCESSOR_HYBI07_HPP 79 | -------------------------------------------------------------------------------- /src/lib/websocketpp/processors/hybi08.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_PROCESSOR_HYBI08_HPP 29 | #define WEBSOCKETPP_PROCESSOR_HYBI08_HPP 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | namespace ws_websocketpp { 37 | namespace processor { 38 | 39 | /// Processor for Hybi Draft version 08 40 | /** 41 | * The primary difference between 08 and 13 is a different origin header name 42 | */ 43 | template 44 | class hybi08 : public hybi13 { 45 | public: 46 | typedef hybi08 type; 47 | typedef typename config::request_type request_type; 48 | 49 | typedef typename config::con_msg_manager_type::ptr msg_manager_ptr; 50 | typedef typename config::rng_type rng_type; 51 | 52 | explicit hybi08(bool secure, bool p_is_server, msg_manager_ptr manager, rng_type& rng) 53 | : hybi13(secure, p_is_server, manager, rng) {} 54 | 55 | /// Fill in a set of request headers for a client connection request 56 | /** 57 | * The Hybi 08 processor only implements incoming connections so this will 58 | * always return an error. 59 | * 60 | * @param [out] req Set of headers to fill in 61 | * @param [in] uri The uri being connected to 62 | * @param [in] subprotocols The list of subprotocols to request 63 | */ 64 | lib::error_code client_handshake_request(request_type &, uri_ptr, 65 | std::vector const &) const 66 | { 67 | return error::make_error_code(error::no_protocol_support); 68 | } 69 | 70 | int get_version() const { 71 | return 8; 72 | } 73 | 74 | std::string const & get_origin(request_type const & r) const { 75 | return r.get_header("Sec-WebSocket-Origin"); 76 | } 77 | private: 78 | }; 79 | 80 | } // namespace processor 81 | } // namespace ws_websocketpp 82 | 83 | #endif //WEBSOCKETPP_PROCESSOR_HYBI08_HPP 84 | -------------------------------------------------------------------------------- /src/lib/websocketpp/random/none.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_RANDOM_NONE_HPP 29 | #define WEBSOCKETPP_RANDOM_NONE_HPP 30 | 31 | namespace ws_websocketpp { 32 | /// Random number generation policies 33 | namespace random { 34 | /// Stub RNG policy that always returns 0 35 | namespace none { 36 | 37 | /// Thread safe stub "random" integer generator. 38 | /** 39 | * This template class provides a random integer stub. The interface mimics the 40 | * WebSocket++ RNG generator classes but the generater function always returns 41 | * zero. This can be used to stub out the RNG for unit and performance testing. 42 | * 43 | * Call operator() to generate the next number 44 | */ 45 | template 46 | class int_generator { 47 | public: 48 | int_generator() {} 49 | 50 | /// advances the engine's state and returns the generated value 51 | int_type operator()() { 52 | return 0; 53 | } 54 | }; 55 | 56 | } // namespace none 57 | } // namespace random 58 | } // namespace ws_websocketpp 59 | 60 | #endif //WEBSOCKETPP_RANDOM_NONE_HPP 61 | -------------------------------------------------------------------------------- /src/lib/websocketpp/random/random_device.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_RANDOM_RANDOM_DEVICE_HPP 29 | #define WEBSOCKETPP_RANDOM_RANDOM_DEVICE_HPP 30 | 31 | #include 32 | 33 | namespace ws_websocketpp { 34 | namespace random { 35 | /// RNG policy based on std::random_device or boost::random_device 36 | namespace random_device { 37 | 38 | /// Thread safe non-deterministic random integer generator. 39 | /** 40 | * This template class provides thread safe non-deterministic random integer 41 | * generation. Numbers are produced in a uniformly distributed range from the 42 | * smallest to largest value that int_type can store. 43 | * 44 | * Thread-safety is provided via locking based on the concurrency template 45 | * parameter. 46 | * 47 | * Non-deterministic RNG is provided via ws_websocketpp::lib which uses either 48 | * C++11 or Boost 1.47+'s random_device class. 49 | * 50 | * Call operator() to generate the next number 51 | */ 52 | template 53 | class int_generator { 54 | public: 55 | typedef typename concurrency::scoped_lock_type scoped_lock_type; 56 | typedef typename concurrency::mutex_type mutex_type; 57 | 58 | /// constructor 59 | //mac TODO: figure out if signed types present a range problem 60 | int_generator() {} 61 | 62 | /// advances the engine's state and returns the generated value 63 | int_type operator()() { 64 | scoped_lock_type guard(m_lock); 65 | return m_dis(m_rng); 66 | } 67 | private: 68 | 69 | 70 | lib::random_device m_rng; 71 | lib::uniform_int_distribution m_dis; 72 | 73 | mutex_type m_lock; 74 | }; 75 | 76 | } // namespace random_device 77 | } // namespace random 78 | } // namespace ws_websocketpp 79 | 80 | #endif //WEBSOCKETPP_RANDOM_RANDOM_DEVICE_HPP 81 | -------------------------------------------------------------------------------- /src/lib/websocketpp/server.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_SERVER_HPP 29 | #define WEBSOCKETPP_SERVER_HPP 30 | 31 | #include 32 | 33 | #endif //WEBSOCKETPP_SERVER_HPP 34 | -------------------------------------------------------------------------------- /src/lib/websocketpp/transport/asio/security/base.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, 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_TRANSPORT_ASIO_SOCKET_BASE_HPP 29 | #define WEBSOCKETPP_TRANSPORT_ASIO_SOCKET_BASE_HPP 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | // Interface that sockets/security policies must implement 41 | 42 | /* 43 | * Endpoint Interface 44 | * 45 | * bool is_secure() const; 46 | * @return Whether or not the endpoint creates secure connections 47 | * 48 | * lib::error_code init(socket_con_ptr scon); 49 | * Called by the transport after a new connection is created to initialize 50 | * the socket component of the connection. 51 | * @param scon Pointer to the socket component of the connection 52 | * @return Error code (empty on success) 53 | */ 54 | 55 | 56 | // Connection 57 | // TODO 58 | // set_hostname(std::string hostname) 59 | // pre_init(init_handler); 60 | // post_init(init_handler); 61 | 62 | namespace ws_websocketpp { 63 | namespace transport { 64 | namespace asio { 65 | namespace socket { 66 | 67 | typedef lib::function shutdown_handler; 68 | 69 | /** 70 | * The transport::asio::socket::* classes are a set of security/socket related 71 | * policies and support code for the ASIO transport types. 72 | */ 73 | 74 | /// Errors related to asio transport sockets 75 | namespace error { 76 | enum value { 77 | /// Catch-all error for security policy errors that don't fit in other 78 | /// categories 79 | security = 1, 80 | 81 | /// Catch-all error for socket component errors that don't fit in other 82 | /// categories 83 | socket, 84 | 85 | /// A function was called in a state that it was illegal to do so. 86 | invalid_state, 87 | 88 | /// The application was prompted to provide a TLS context and it was 89 | /// empty or otherwise invalid 90 | invalid_tls_context, 91 | 92 | /// TLS Handshake Timeout 93 | tls_handshake_timeout, 94 | 95 | /// pass_through from underlying library 96 | pass_through, 97 | 98 | /// Required tls_init handler not present 99 | missing_tls_init_handler, 100 | 101 | /// TLS Handshake Failed 102 | tls_handshake_failed, 103 | 104 | /// Failed to set TLS SNI hostname 105 | tls_failed_sni_hostname 106 | }; 107 | } // namespace error 108 | 109 | /// Error category related to asio transport socket policies 110 | class socket_category : public lib::error_category { 111 | public: 112 | char const * name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_ { 113 | return "websocketpp.transport.asio.socket"; 114 | } 115 | 116 | std::string message(int value) const { 117 | switch(value) { 118 | case error::security: 119 | return "Security policy error"; 120 | case error::socket: 121 | return "Socket component error"; 122 | case error::invalid_state: 123 | return "Invalid state"; 124 | case error::invalid_tls_context: 125 | return "Invalid or empty TLS context supplied"; 126 | case error::tls_handshake_timeout: 127 | return "TLS handshake timed out"; 128 | case error::pass_through: 129 | return "Pass through from socket policy"; 130 | case error::missing_tls_init_handler: 131 | return "Required tls_init handler not present."; 132 | case error::tls_handshake_failed: 133 | return "TLS handshake failed"; 134 | case error::tls_failed_sni_hostname: 135 | return "Failed to set TLS SNI hostname"; 136 | default: 137 | return "Unknown"; 138 | } 139 | } 140 | }; 141 | 142 | inline lib::error_category const & get_socket_category() { 143 | static socket_category instance; 144 | return instance; 145 | } 146 | 147 | inline lib::error_code make_error_code(error::value e) { 148 | return lib::error_code(static_cast(e), get_socket_category()); 149 | } 150 | 151 | /// Type of asio transport socket policy initialization handlers 152 | typedef lib::function init_handler; 153 | 154 | } // namespace socket 155 | } // namespace asio 156 | } // namespace transport 157 | } // namespace ws_websocketpp 158 | 159 | #endif // WEBSOCKETPP_TRANSPORT_ASIO_SOCKET_BASE_HPP 160 | -------------------------------------------------------------------------------- /src/lib/websocketpp/transport/base/endpoint.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_TRANSPORT_BASE_HPP 29 | #define WEBSOCKETPP_TRANSPORT_BASE_HPP 30 | 31 | #include 32 | #include 33 | 34 | namespace ws_websocketpp { 35 | /// Transport policies provide network connectivity and timers 36 | /** 37 | * ### Endpoint Interface 38 | * 39 | * Transport endpoint components needs to provide: 40 | * 41 | * **init**\n 42 | * `lib::error_code init(transport_con_ptr tcon)`\n 43 | * init is called by an endpoint once for each newly created connection. 44 | * It's purpose is to give the transport policy the chance to perform any 45 | * transport specific initialization that couldn't be done via the default 46 | * constructor. 47 | * 48 | * **is_secure**\n 49 | * `bool is_secure() const`\n 50 | * Test whether the transport component of this endpoint is capable of secure 51 | * connections. 52 | * 53 | * **async_connect**\n 54 | * `void async_connect(transport_con_ptr tcon, uri_ptr location, 55 | * connect_handler handler)`\n 56 | * Initiate a connection to `location` using the given connection `tcon`. `tcon` 57 | * is a pointer to the transport connection component of the connection. When 58 | * complete, `handler` should be called with the the connection's 59 | * `connection_hdl` and any error that occurred. 60 | * 61 | * **init_logging** 62 | * `void init_logging(const lib::shared_ptr& a, const lib::shared_ptr& e)`\n 63 | * Called once after construction to provide pointers to the endpoint's access 64 | * and error loggers. These may be stored and used to log messages or ignored. 65 | */ 66 | namespace transport { 67 | 68 | /// The type and signature of the callback passed to the accept method 69 | typedef lib::function accept_handler; 70 | 71 | /// The type and signature of the callback passed to the connect method 72 | typedef lib::function connect_handler; 73 | 74 | } // namespace transport 75 | } // namespace ws_websocketpp 76 | 77 | #endif // WEBSOCKETPP_TRANSPORT_BASE_HPP 78 | -------------------------------------------------------------------------------- /src/lib/websocketpp/transport/debug/base.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_TRANSPORT_DEBUG_BASE_HPP 29 | #define WEBSOCKETPP_TRANSPORT_DEBUG_BASE_HPP 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | namespace ws_websocketpp { 37 | namespace transport { 38 | /// Debug transport policy that is used for various mocking and stubbing duties 39 | /// in unit tests. 40 | namespace debug { 41 | 42 | /// debug transport errors 43 | namespace error { 44 | enum value { 45 | /// Catch-all error for transport policy errors that don't fit in other 46 | /// categories 47 | general = 1, 48 | 49 | /// not implemented 50 | not_implemented, 51 | 52 | invalid_num_bytes, 53 | 54 | double_read 55 | }; 56 | 57 | /// debug transport error category 58 | class category : public lib::error_category { 59 | public: 60 | category() {} 61 | 62 | char const * name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_ { 63 | return "websocketpp.transport.debug"; 64 | } 65 | 66 | std::string message(int value) const { 67 | switch(value) { 68 | case general: 69 | return "Generic stub transport policy error"; 70 | case not_implemented: 71 | return "feature not implemented"; 72 | case invalid_num_bytes: 73 | return "Invalid number of bytes"; 74 | case double_read: 75 | return "Read while another read was outstanding"; 76 | default: 77 | return "Unknown"; 78 | } 79 | } 80 | }; 81 | 82 | /// Get a reference to a static copy of the debug transport error category 83 | inline lib::error_category const & get_category() { 84 | static category instance; 85 | return instance; 86 | } 87 | 88 | /// Get an error code with the given value and the debug transport category 89 | inline lib::error_code make_error_code(error::value e) { 90 | return lib::error_code(static_cast(e), get_category()); 91 | } 92 | 93 | } // namespace error 94 | } // namespace debug 95 | } // namespace transport 96 | } // namespace ws_websocketpp 97 | _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_ 98 | template<> struct is_error_code_enum 99 | { 100 | static bool const value = true; 101 | }; 102 | _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_ 103 | 104 | #endif // WEBSOCKETPP_TRANSPORT_DEBUG_BASE_HPP 105 | -------------------------------------------------------------------------------- /src/lib/websocketpp/transport/debug/endpoint.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_TRANSPORT_DEBUG_HPP 29 | #define WEBSOCKETPP_TRANSPORT_DEBUG_HPP 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | namespace ws_websocketpp { 38 | namespace transport { 39 | namespace debug { 40 | 41 | template 42 | class endpoint { 43 | public: 44 | /// Type of this endpoint transport component 45 | typedef endpoint type; 46 | /// Type of a pointer to this endpoint transport component 47 | typedef lib::shared_ptr ptr; 48 | 49 | /// Type of this endpoint's concurrency policy 50 | typedef typename config::concurrency_type concurrency_type; 51 | /// Type of this endpoint's error logging policy 52 | typedef typename config::elog_type elog_type; 53 | /// Type of this endpoint's access logging policy 54 | typedef typename config::alog_type alog_type; 55 | 56 | /// Type of this endpoint transport component's associated connection 57 | /// transport component. 58 | typedef debug::connection transport_con_type; 59 | /// Type of a shared pointer to this endpoint transport component's 60 | /// associated connection transport component 61 | typedef typename transport_con_type::ptr transport_con_ptr; 62 | 63 | // generate and manage our own io_service 64 | explicit endpoint() 65 | { 66 | //std::cout << "transport::iostream::endpoint constructor" << std::endl; 67 | } 68 | 69 | /// Set whether or not endpoint can create secure connections 70 | /** 71 | * TODO: docs 72 | * 73 | * Setting this value only indicates whether or not the endpoint is capable 74 | * of producing and managing secure connections. Connections produced by 75 | * this endpoint must also be individually flagged as secure if they are. 76 | * 77 | * @since 0.3.0-alpha4 78 | * 79 | * @param value Whether or not the endpoint can create secure connections. 80 | */ 81 | void set_secure(bool) {} 82 | 83 | /// Tests whether or not the underlying transport is secure 84 | /** 85 | * TODO: docs 86 | * 87 | * @return Whether or not the underlying transport is secure 88 | */ 89 | bool is_secure() const { 90 | return false; 91 | } 92 | protected: 93 | /// Initialize logging 94 | /** 95 | * The loggers are located in the main endpoint class. As such, the 96 | * transport doesn't have direct access to them. This method is called 97 | * by the endpoint constructor to allow shared logging from the transport 98 | * component. These are raw pointers to member variables of the endpoint. 99 | * In particular, they cannot be used in the transport constructor as they 100 | * haven't been constructed yet, and cannot be used in the transport 101 | * destructor as they will have been destroyed by then. 102 | * 103 | * @param a A pointer to the access logger to use. 104 | * @param e A pointer to the error logger to use. 105 | */ 106 | void init_logging(lib::shared_ptr, lib::shared_ptr) {} 107 | 108 | /// Initiate a new connection 109 | /** 110 | * @param tcon A pointer to the transport connection component of the 111 | * connection to connect. 112 | * @param u A URI pointer to the URI to connect to. 113 | * @param cb The function to call back with the results when complete. 114 | */ 115 | void async_connect(transport_con_ptr, uri_ptr, connect_handler cb) { 116 | cb(lib::error_code()); 117 | } 118 | 119 | /// Initialize a connection 120 | /** 121 | * Init is called by an endpoint once for each newly created connection. 122 | * It's purpose is to give the transport policy the chance to perform any 123 | * transport specific initialization that couldn't be done via the default 124 | * constructor. 125 | * 126 | * @param tcon A pointer to the transport portion of the connection. 127 | * @return A status code indicating the success or failure of the operation 128 | */ 129 | lib::error_code init(transport_con_ptr) { 130 | return lib::error_code(); 131 | } 132 | private: 133 | 134 | }; 135 | 136 | } // namespace debug 137 | } // namespace transport 138 | } // namespace ws_websocketpp 139 | 140 | #endif // WEBSOCKETPP_TRANSPORT_DEBUG_HPP 141 | -------------------------------------------------------------------------------- /src/lib/websocketpp/transport/iostream/base.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_TRANSPORT_IOSTREAM_BASE_HPP 29 | #define WEBSOCKETPP_TRANSPORT_IOSTREAM_BASE_HPP 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | namespace ws_websocketpp { 42 | namespace transport { 43 | /// Transport policy that uses STL iostream for I/O and does not support timers 44 | namespace iostream { 45 | 46 | /// The type and signature of the callback used by iostream transport to write 47 | typedef lib::function 48 | write_handler; 49 | 50 | /// The type and signature of the callback used by iostream transport to perform 51 | /// vectored writes. 52 | /** 53 | * If a vectored write handler is not set the standard write handler will be 54 | * called multiple times. 55 | */ 56 | typedef lib::function const 57 | & bufs)> vector_write_handler; 58 | 59 | /// The type and signature of the callback used by iostream transport to signal 60 | /// a transport shutdown. 61 | typedef lib::function shutdown_handler; 62 | 63 | /// iostream transport errors 64 | namespace error { 65 | enum value { 66 | /// Catch-all error for transport policy errors that don't fit in other 67 | /// categories 68 | general = 1, 69 | 70 | /// async_read_at_least call requested more bytes than buffer can store 71 | invalid_num_bytes, 72 | 73 | /// async_read called while another async_read was in progress 74 | double_read, 75 | 76 | /// An operation that requires an output stream was attempted before 77 | /// setting one. 78 | output_stream_required, 79 | 80 | /// stream error 81 | bad_stream 82 | }; 83 | 84 | /// iostream transport error category 85 | class category : public lib::error_category { 86 | public: 87 | category() {} 88 | 89 | char const * name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_ { 90 | return "websocketpp.transport.iostream"; 91 | } 92 | 93 | std::string message(int value) const { 94 | switch(value) { 95 | case general: 96 | return "Generic iostream transport policy error"; 97 | case invalid_num_bytes: 98 | return "async_read_at_least call requested more bytes than buffer can store"; 99 | case double_read: 100 | return "Async read already in progress"; 101 | case output_stream_required: 102 | return "An output stream to be set before async_write can be used"; 103 | case bad_stream: 104 | return "A stream operation returned ios::bad"; 105 | default: 106 | return "Unknown"; 107 | } 108 | } 109 | }; 110 | 111 | /// Get a reference to a static copy of the iostream transport error category 112 | inline lib::error_category const & get_category() { 113 | static category instance; 114 | return instance; 115 | } 116 | 117 | /// Get an error code with the given value and the iostream transport category 118 | inline lib::error_code make_error_code(error::value e) { 119 | return lib::error_code(static_cast(e), get_category()); 120 | } 121 | 122 | } // namespace error 123 | } // namespace iostream 124 | } // namespace transport 125 | } // namespace ws_websocketpp 126 | _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_ 127 | template<> struct is_error_code_enum 128 | { 129 | static bool const value = true; 130 | }; 131 | _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_ 132 | 133 | #endif // WEBSOCKETPP_TRANSPORT_IOSTREAM_BASE_HPP 134 | -------------------------------------------------------------------------------- /src/lib/websocketpp/transport/stub/base.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_TRANSPORT_STUB_BASE_HPP 29 | #define WEBSOCKETPP_TRANSPORT_STUB_BASE_HPP 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | namespace ws_websocketpp { 37 | namespace transport { 38 | /// Stub transport policy that has no input or output. 39 | namespace stub { 40 | 41 | /// stub transport errors 42 | namespace error { 43 | enum value { 44 | /// Catch-all error for transport policy errors that don't fit in other 45 | /// categories 46 | general = 1, 47 | 48 | /// not implemented 49 | not_implemented 50 | }; 51 | 52 | /// stub transport error category 53 | class category : public lib::error_category { 54 | public: 55 | category() {} 56 | 57 | char const * name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_ { 58 | return "websocketpp.transport.stub"; 59 | } 60 | 61 | std::string message(int value) const { 62 | switch(value) { 63 | case general: 64 | return "Generic stub transport policy error"; 65 | case not_implemented: 66 | return "feature not implemented"; 67 | default: 68 | return "Unknown"; 69 | } 70 | } 71 | }; 72 | 73 | /// Get a reference to a static copy of the stub transport error category 74 | inline lib::error_category const & get_category() { 75 | static category instance; 76 | return instance; 77 | } 78 | 79 | /// Get an error code with the given value and the stub transport category 80 | inline lib::error_code make_error_code(error::value e) { 81 | return lib::error_code(static_cast(e), get_category()); 82 | } 83 | 84 | } // namespace error 85 | } // namespace stub 86 | } // namespace transport 87 | } // namespace ws_websocketpp 88 | _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_ 89 | template<> struct is_error_code_enum 90 | { 91 | static bool const value = true; 92 | }; 93 | _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_ 94 | 95 | #endif // WEBSOCKETPP_TRANSPORT_STUB_BASE_HPP 96 | -------------------------------------------------------------------------------- /src/lib/websocketpp/transport/stub/endpoint.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_TRANSPORT_STUB_HPP 29 | #define WEBSOCKETPP_TRANSPORT_STUB_HPP 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | namespace ws_websocketpp { 38 | namespace transport { 39 | namespace stub { 40 | 41 | template 42 | class endpoint { 43 | public: 44 | /// Type of this endpoint transport component 45 | typedef endpoint type; 46 | /// Type of a pointer to this endpoint transport component 47 | typedef lib::shared_ptr ptr; 48 | 49 | /// Type of this endpoint's concurrency policy 50 | typedef typename config::concurrency_type concurrency_type; 51 | /// Type of this endpoint's error logging policy 52 | typedef typename config::elog_type elog_type; 53 | /// Type of this endpoint's access logging policy 54 | typedef typename config::alog_type alog_type; 55 | 56 | /// Type of this endpoint transport component's associated connection 57 | /// transport component. 58 | typedef stub::connection transport_con_type; 59 | /// Type of a shared pointer to this endpoint transport component's 60 | /// associated connection transport component 61 | typedef typename transport_con_type::ptr transport_con_ptr; 62 | 63 | // generate and manage our own io_service 64 | explicit endpoint() 65 | { 66 | //std::cout << "transport::iostream::endpoint constructor" << std::endl; 67 | } 68 | 69 | /// Set whether or not endpoint can create secure connections 70 | /** 71 | * TODO: docs 72 | * 73 | * Setting this value only indicates whether or not the endpoint is capable 74 | * of producing and managing secure connections. Connections produced by 75 | * this endpoint must also be individually flagged as secure if they are. 76 | * 77 | * @since 0.3.0-alpha4 78 | * 79 | * @param value Whether or not the endpoint can create secure connections. 80 | */ 81 | void set_secure(bool value) {} 82 | 83 | /// Tests whether or not the underlying transport is secure 84 | /** 85 | * TODO: docs 86 | * 87 | * @return Whether or not the underlying transport is secure 88 | */ 89 | bool is_secure() const { 90 | return false; 91 | } 92 | protected: 93 | /// Initialize logging 94 | /** 95 | * The loggers are located in the main endpoint class. As such, the 96 | * transport doesn't have direct access to them. This method is called 97 | * by the endpoint constructor to allow shared logging from the transport 98 | * component. These are raw pointers to member variables of the endpoint. 99 | * In particular, they cannot be used in the transport constructor as they 100 | * haven't been constructed yet, and cannot be used in the transport 101 | * destructor as they will have been destroyed by then. 102 | * 103 | * @param a A pointer to the access logger to use. 104 | * @param e A pointer to the error logger to use. 105 | */ 106 | void init_logging(alog_type * a, elog_type * e) {} 107 | 108 | /// Initiate a new connection 109 | /** 110 | * @param tcon A pointer to the transport connection component of the 111 | * connection to connect. 112 | * @param u A URI pointer to the URI to connect to. 113 | * @param cb The function to call back with the results when complete. 114 | */ 115 | void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb) { 116 | cb(make_error_code(error::not_implemented)); 117 | } 118 | 119 | /// Initialize a connection 120 | /** 121 | * Init is called by an endpoint once for each newly created connection. 122 | * It's purpose is to give the transport policy the chance to perform any 123 | * transport specific initialization that couldn't be done via the default 124 | * constructor. 125 | * 126 | * @param tcon A pointer to the transport portion of the connection. 127 | * @return A status code indicating the success or failure of the operation 128 | */ 129 | lib::error_code init(transport_con_ptr tcon) { 130 | return make_error_code(error::not_implemented); 131 | } 132 | private: 133 | 134 | }; 135 | 136 | } // namespace stub 137 | } // namespace transport 138 | } // namespace ws_websocketpp 139 | 140 | #endif // WEBSOCKETPP_TRANSPORT_STUB_HPP 141 | -------------------------------------------------------------------------------- /src/lib/websocketpp/utf8_validator.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The following code is adapted from code originally written by Bjoern 3 | * Hoehrmann . See 4 | * http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details. 5 | * 6 | * The original license: 7 | * 8 | * Copyright (c) 2008-2009 Bjoern Hoehrmann 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | * SOFTWARE. 27 | */ 28 | 29 | #ifndef UTF8_VALIDATOR_HPP 30 | #define UTF8_VALIDATOR_HPP 31 | 32 | #include 33 | 34 | #include 35 | 36 | namespace ws_websocketpp { 37 | namespace utf8_validator { 38 | 39 | /// State that represents a valid utf8 input sequence 40 | static unsigned int const utf8_accept = 0; 41 | /// State that represents an invalid utf8 input sequence 42 | static unsigned int const utf8_reject = 1; 43 | 44 | /// Lookup table for the UTF8 decode state machine 45 | static uint8_t const utf8d[] = { 46 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00..1f 47 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 20..3f 48 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 40..5f 49 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 60..7f 50 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, // 80..9f 51 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, // a0..bf 52 | 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // c0..df 53 | 0xa,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x4,0x3,0x3, // e0..ef 54 | 0xb,0x6,0x6,0x6,0x5,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8, // f0..ff 55 | 0x0,0x1,0x2,0x3,0x5,0x8,0x7,0x1,0x1,0x1,0x4,0x6,0x1,0x1,0x1,0x1, // s0..s0 56 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1, // s1..s2 57 | 1,2,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1, // s3..s4 58 | 1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,1,1,1, // s5..s6 59 | 1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // s7..s8 60 | }; 61 | 62 | /// Decode the next byte of a UTF8 sequence 63 | /** 64 | * @param [out] state The decoder state to advance 65 | * @param [out] codep The codepoint to fill in 66 | * @param [in] byte The byte to input 67 | * @return The ending state of the decode operation 68 | */ 69 | inline uint32_t decode(uint32_t * state, uint32_t * codep, uint8_t byte) { 70 | uint32_t type = utf8d[byte]; 71 | 72 | *codep = (*state != utf8_accept) ? 73 | (byte & 0x3fu) | (*codep << 6) : 74 | (0xff >> type) & (byte); 75 | 76 | *state = utf8d[256 + *state*16 + type]; 77 | return *state; 78 | } 79 | 80 | /// Provides streaming UTF8 validation functionality 81 | class validator { 82 | public: 83 | /// Construct and initialize the validator 84 | validator() : m_state(utf8_accept),m_codepoint(0) {} 85 | 86 | /// Advance the state of the validator with the next input byte 87 | /** 88 | * @param byte The byte to advance the validation state with 89 | * @return Whether or not the byte resulted in a validation error. 90 | */ 91 | bool consume (uint8_t byte) { 92 | if (utf8_validator::decode(&m_state,&m_codepoint,byte) == utf8_reject) { 93 | return false; 94 | } 95 | return true; 96 | } 97 | 98 | /// Advance validator state with input from an iterator pair 99 | /** 100 | * @param begin Input iterator to the start of the input range 101 | * @param end Input iterator to the end of the input range 102 | * @return Whether or not decoding the bytes resulted in a validation error. 103 | */ 104 | template 105 | bool decode (iterator_type begin, iterator_type end) { 106 | for (iterator_type it = begin; it != end; ++it) { 107 | unsigned int result = utf8_validator::decode( 108 | &m_state, 109 | &m_codepoint, 110 | static_cast(*it) 111 | ); 112 | 113 | if (result == utf8_reject) { 114 | return false; 115 | } 116 | } 117 | return true; 118 | } 119 | 120 | /// Return whether the input sequence ended on a valid utf8 codepoint 121 | /** 122 | * @return Whether or not the input sequence ended on a valid codepoint. 123 | */ 124 | bool complete() { 125 | return m_state == utf8_accept; 126 | } 127 | 128 | /// Reset the validator to decode another message 129 | void reset() { 130 | m_state = utf8_accept; 131 | m_codepoint = 0; 132 | } 133 | private: 134 | uint32_t m_state; 135 | uint32_t m_codepoint; 136 | }; 137 | 138 | /// Validate a UTF8 string 139 | /** 140 | * convenience function that creates a validator, validates a complete string 141 | * and returns the result. 142 | */ 143 | inline bool validate(std::string const & s) { 144 | validator v; 145 | if (!v.decode(s.begin(),s.end())) { 146 | return false; 147 | } 148 | return v.complete(); 149 | } 150 | 151 | } // namespace utf8_validator 152 | } // namespace ws_websocketpp 153 | 154 | #endif // UTF8_VALIDATOR_HPP 155 | -------------------------------------------------------------------------------- /src/lib/websocketpp/version.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, 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_VERSION_HPP 29 | #define WEBSOCKETPP_VERSION_HPP 30 | 31 | /// Namespace for the WebSocket++ project 32 | namespace ws_websocketpp { 33 | 34 | /* 35 | other places where version information is kept 36 | - readme.md 37 | - changelog.md 38 | - Doxyfile 39 | - CMakeLists.txt 40 | */ 41 | 42 | /// Library major version number 43 | static int const major_version = 0; 44 | /// Library minor version number 45 | static int const minor_version = 8; 46 | /// Library patch version number 47 | static int const patch_version = 2; 48 | /// Library pre-release flag 49 | /** 50 | * This is a textual flag indicating the type and number for pre-release 51 | * versions (dev, alpha, beta, rc). This will be blank for release versions. 52 | */ 53 | 54 | static char const prerelease_flag[] = ""; 55 | 56 | /// Default user agent string 57 | static char const user_agent[] = "WebSocket++/0.8.2"; 58 | 59 | } // namespace ws_websocketpp 60 | 61 | #endif // WEBSOCKETPP_VERSION_HPP 62 | -------------------------------------------------------------------------------- /src/tests/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(){ 8 | OpenSSL_add_all_digests(); 9 | OpenSSL_add_all_algorithms(); 10 | OpenSSL_add_all_ciphers(); 11 | ERR_load_crypto_strings(); 12 | SSL_load_error_strings(); 13 | SSL_library_init(); 14 | } 15 | -------------------------------------------------------------------------------- /src/tests/soname.h: -------------------------------------------------------------------------------- 1 | #include "openssl/opensslv.h" 2 | 3 | #define XSTR(x) STR(x) 4 | #define STR(x) #x 5 | echo XSTR(SHLIB_VERSION_NUMBER) 6 | -------------------------------------------------------------------------------- /src/websocket.cpp: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | #include 3 | #include 4 | 5 | // These are defined by windows.h but we have to undefine them so that the 6 | // typedef enum Rboolean will be used later on. 7 | #undef TRUE 8 | #undef FALSE 9 | 10 | #endif // _WIN32 11 | 12 | 13 | #include 14 | #include "cpp11.hpp" 15 | #include "wrapped_print.h" 16 | #include 17 | #include "client.hpp" 18 | #include "websocket_defs.h" 19 | #include "websocket_task.h" 20 | #include "websocket_connection.h" 21 | #include "debug.h" 22 | 23 | 24 | shared_ptr xptrGetWsConn(SEXP wsc_xptr) { 25 | if (TYPEOF(wsc_xptr) != EXTPTRSXP) { 26 | cpp11::stop("Expected external pointer."); 27 | } 28 | return *reinterpret_cast*>(R_ExternalPtrAddr(wsc_xptr)); 29 | } 30 | 31 | void wsc_deleter(SEXP wsc_xptr) { 32 | ASSERT_MAIN_THREAD() 33 | shared_ptr wsc = xptrGetWsConn(wsc_xptr); 34 | if (!wsc->client->stopped()) { 35 | // I don't think we'll ever actually get here because as long as the 36 | // connection is open, the WebsocketConnection object will contain a 37 | // reference to the R6 object (robjPublic), which contains a reference 38 | // back to the WebsocketConnection object. This prevents the R6 object 39 | // from getting GC'd, and its external pointer in turn will not get GC'd. 40 | // But just in case we get here somehow, we'll stop the thread. 41 | wsc->client->stop(); 42 | } 43 | delete reinterpret_cast*>(R_ExternalPtrAddr(wsc_xptr)); 44 | R_ClearExternalPtr(wsc_xptr); 45 | } 46 | 47 | 48 | [[cpp11::register]] 49 | SEXP wsCreate( 50 | std::string uri, 51 | int loop_id, 52 | cpp11::environment robjPublic, 53 | cpp11::environment robjPrivate, 54 | cpp11::strings accessLogChannels, 55 | cpp11::strings errorLogChannels, 56 | int maxMessageSize 57 | ) { 58 | REGISTER_MAIN_THREAD() 59 | WebsocketConnection* wsc = new WebsocketConnection( 60 | uri, loop_id, robjPublic, robjPrivate, accessLogChannels, errorLogChannels, maxMessageSize 61 | ); 62 | 63 | shared_ptr *wsc_pp = new shared_ptr(wsc); 64 | SEXP wsc_xptr = PROTECT(R_MakeExternalPtr(wsc_pp, R_NilValue, R_NilValue)); 65 | R_RegisterCFinalizerEx(wsc_xptr, wsc_deleter, TRUE); 66 | UNPROTECT(1); 67 | return wsc_xptr; 68 | } 69 | 70 | [[cpp11::register]] 71 | void wsAppendHeader(SEXP wsc_xptr, std::string key, std::string value) { 72 | ASSERT_MAIN_THREAD() 73 | shared_ptr wsc = xptrGetWsConn(wsc_xptr); 74 | wsc->client->append_header(key, value); 75 | } 76 | 77 | [[cpp11::register]] 78 | void wsAddProtocols(SEXP wsc_xptr, cpp11::strings protocols) { 79 | ASSERT_MAIN_THREAD() 80 | shared_ptr wsc = xptrGetWsConn(wsc_xptr); 81 | for (auto it = protocols.begin(); it != protocols.end(); ++it) { 82 | std::string protocol = *it; 83 | wsc->client->add_subprotocol(protocol); 84 | } 85 | } 86 | 87 | [[cpp11::register]] 88 | void wsConnect(SEXP wsc_xptr) { 89 | ASSERT_MAIN_THREAD() 90 | shared_ptr wsc = xptrGetWsConn(wsc_xptr); 91 | 92 | wsc->client->connect(); 93 | 94 | // Starts a new thread in which WebsocketTask::execute is called. Object is 95 | // automatically deleted when thread stops. 96 | WebsocketTask* wst = new WebsocketTask(wsc); 97 | wst->begin(); 98 | } 99 | 100 | [[cpp11::register]] 101 | void wsSend(SEXP wsc_xptr, SEXP msg) { 102 | ASSERT_MAIN_THREAD() 103 | shared_ptr wsc = xptrGetWsConn(wsc_xptr); 104 | 105 | if (TYPEOF(msg) == STRSXP && 106 | Rf_length(msg) == 1 && 107 | STRING_ELT(msg, 0) != NA_STRING) 108 | { 109 | // TODO: Make sure that message lifetime is long enough 110 | const char* msg_ptr = CHAR(STRING_ELT(msg, 0)); 111 | int len = Rf_xlength(STRING_ELT(msg, 0)); 112 | // When send() is called, I believe that the message is immediately 113 | // appended to the message buffer, and then the actual sending of the 114 | // message is queued. Since a copy of the message is made, it should be 115 | // safe if the original msg is cleared before the actual send happens. 116 | wsc->client->send(msg_ptr, len, ws_websocketpp::frame::opcode::text); 117 | 118 | } else if (TYPEOF(msg) == RAWSXP) { 119 | wsc->client->send(RAW(msg), Rf_length(msg), ws_websocketpp::frame::opcode::binary); 120 | } else { 121 | cpp11::stop("msg must be a one-element character vector or a raw vector."); 122 | } 123 | } 124 | 125 | [[cpp11::register]] 126 | void wsClose(SEXP wsc_xptr, uint16_t code, std::string reason) { 127 | ASSERT_MAIN_THREAD() 128 | shared_ptr wsc = xptrGetWsConn(wsc_xptr); 129 | wsc->close(code, reason); 130 | } 131 | 132 | [[cpp11::register]] 133 | std::string wsProtocol(SEXP wsc_xptr) { 134 | ASSERT_MAIN_THREAD() 135 | shared_ptr wsc = xptrGetWsConn(wsc_xptr); 136 | return wsc->client->get_subprotocol(); 137 | } 138 | 139 | [[cpp11::register]] 140 | std::string wsState(SEXP wsc_xptr) { 141 | ASSERT_MAIN_THREAD() 142 | shared_ptr wsc = xptrGetWsConn(wsc_xptr); 143 | switch(wsc->state) { 144 | case WebsocketConnection::STATE::INIT: return "INIT"; 145 | case WebsocketConnection::STATE::OPEN: return "OPEN"; 146 | case WebsocketConnection::STATE::CLOSING: return "CLOSING"; 147 | case WebsocketConnection::STATE::CLOSED: return "CLOSED"; 148 | case WebsocketConnection::STATE::FAILED: return "FAILED"; 149 | } 150 | 151 | // Shouldn't be possible to get here, but some compilers still complain 152 | // about reaching end of a non-void function. 153 | return "UNKNOWN"; 154 | } 155 | 156 | [[cpp11::register]] 157 | void wsUpdateLogChannels( 158 | SEXP wsc_xptr, 159 | std::string accessOrError, 160 | std::string setOrClear, 161 | cpp11::strings logChannels 162 | ) { 163 | ASSERT_MAIN_THREAD() 164 | shared_ptr wsc = xptrGetWsConn(wsc_xptr); 165 | wsc->client->update_log_channels(accessOrError, setOrClear, logChannels); 166 | } 167 | -------------------------------------------------------------------------------- /src/websocket_connection.h: -------------------------------------------------------------------------------- 1 | #ifndef WEBSOCKET_CONNECTION_HPP 2 | #define WEBSOCKET_CONNECTION_HPP 3 | 4 | #include 5 | #include "cpp11.hpp" 6 | #include "websocket_defs.h" 7 | 8 | 9 | class WebsocketConnection : public enable_shared_from_this 10 | { 11 | public: 12 | WebsocketConnection( 13 | std::string uri, 14 | int loop_id, 15 | cpp11::environment robjPublic, 16 | cpp11::environment robjPrivate, 17 | cpp11::strings accessLogChannels, 18 | cpp11::strings errorLogChannels, 19 | int maxMessageSize 20 | ); 21 | 22 | // Make noncopyable (without boost) 23 | WebsocketConnection(const WebsocketConnection&) = delete; 24 | WebsocketConnection& operator=(const WebsocketConnection&) = delete; 25 | 26 | 27 | void rHandleMessage(message_ptr msg); 28 | void rHandleClose(ws_websocketpp::close::status::value code, std::string reason); 29 | void rHandleOpen(); 30 | void rHandleFail(); 31 | 32 | shared_ptr client; 33 | 34 | void close(uint16_t code, std::string reason); 35 | 36 | enum STATE { INIT, OPEN, CLOSING, CLOSED, FAILED }; 37 | // This value should be touched only from the main thread. 38 | STATE state = INIT; 39 | 40 | // ~WebsocketConnection() { 41 | // std::cerr << "WebsocketConnection::~WebsocketConnection\n"; 42 | // }; 43 | 44 | private: 45 | std::string uri; 46 | int loop_id; 47 | cpp11::environment robjPublic; 48 | cpp11::environment robjPrivate; 49 | 50 | // This value should be touched only from the main thread. 51 | bool closeOnOpen = false; 52 | 53 | // Callbacks for the Client object - these run on the background thread, and 54 | // schedule their counterparts prefixed with "r" (like rHandleMessage()) to 55 | // run on the main R thread. 56 | void handleMessage(ws_websocketpp::connection_hdl, message_ptr msg); 57 | void handleClose(ws_websocketpp::connection_hdl); 58 | void handleOpen(ws_websocketpp::connection_hdl); 59 | void handleFail(ws_websocketpp::connection_hdl); 60 | 61 | void removeHandlers(); 62 | 63 | cpp11::function getInvoker(std::string name); 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/websocket_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef WEBSOCKET_DEFS_HPP 2 | #define WEBSOCKET_DEFS_HPP 3 | 4 | #include "client.hpp" 5 | #include "wrapped_print.h" 6 | #include 7 | 8 | // The websocketpp/common/functional.hpp file detects if a C++11 compiler is 9 | // used. If so, ws_websocketpp::lib::shared_ptr is a std::shared_ptr. If not, 10 | // ws_websocketpp::lib::shared_ptr is a boost::shared_ptr. 11 | using ws_websocketpp::lib::shared_ptr; 12 | using ws_websocketpp::lib::weak_ptr; 13 | using ws_websocketpp::lib::make_shared; 14 | using ws_websocketpp::lib::enable_shared_from_this; 15 | 16 | using ws_websocketpp::lib::placeholders::_1; 17 | using ws_websocketpp::lib::placeholders::_2; 18 | using ws_websocketpp::lib::bind; 19 | 20 | typedef shared_ptr context_ptr; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/websocket_task.cpp: -------------------------------------------------------------------------------- 1 | #include "websocket_defs.h" 2 | #include "websocket_task.h" 3 | #include "debug.h" 4 | 5 | WebsocketTask::WebsocketTask(shared_ptr wsc) { 6 | this->wsc = wsc; 7 | } 8 | 9 | void WebsocketTask::execute() { 10 | REGISTER_BACKGROUND_THREAD() 11 | wsc->client->run(); 12 | } 13 | 14 | void WebsocketTask::complete() { 15 | ASSERT_MAIN_THREAD() 16 | } 17 | -------------------------------------------------------------------------------- /src/websocket_task.h: -------------------------------------------------------------------------------- 1 | #ifndef WEBSOCKET_TASK_HPP 2 | #define WEBSOCKET_TASK_HPP 3 | 4 | #include 5 | #include "websocket_defs.h" 6 | #include "websocket_connection.h" 7 | 8 | class WebsocketTask : public later::BackgroundTask 9 | { 10 | public: 11 | WebsocketTask(shared_ptr wsc); 12 | 13 | // Make noncopyable (without boost) 14 | WebsocketTask(const WebsocketTask&) = delete; 15 | WebsocketTask& operator=(const WebsocketTask&) = delete; 16 | 17 | // ~WebsocketTask() { 18 | // std::cerr << "WebsocketTask::~WebsocketTask\n"; 19 | // }; 20 | 21 | protected: 22 | void execute(); 23 | void complete(); 24 | 25 | private: 26 | shared_ptr wsc; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/wrapped_print.h: -------------------------------------------------------------------------------- 1 | #ifndef WRAPPED_PRINT_HPP 2 | #define WRAPPED_PRINT_HPP 3 | 4 | // This file provides substitutes for Rprintf, REprintf, Rcpp::Rcout, and 5 | // Rcpp::Rcerr. However, when code on a background thread calls one of these 6 | // R-prefixed functions, it is very unsafe and can lead to memory corruption. 7 | // 8 | // It isn't possible to switch to plain old printf, std::cerr, and std::cout, 9 | // because R CMD check will flag these and raise a WARNING. 10 | // 11 | // This file provides substitutes which will not cause memory corruption and 12 | // will not result in warnings from R CMD check. 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | // It's not safe to call REprintf from the background thread but we need some 22 | // way to output error messages. R CMD check does not it if the code uses the 23 | // symbols stdout, stderr, and printf, so this function is a way to avoid 24 | // those. It's to calling `fprintf(stderr, ...)`. 25 | inline void err_printf(const char *fmt, ...) { 26 | const size_t max_size = 4096; 27 | char buf[max_size]; 28 | 29 | va_list args; 30 | va_start(args, fmt); 31 | int n = vsnprintf(buf, max_size, fmt, args); 32 | va_end(args); 33 | 34 | if (n == -1) 35 | return; 36 | 37 | ssize_t res = write(STDERR_FILENO, buf, n); 38 | // This is here simply to avoid a warning about "ignoring return value" of 39 | // the write(), on some compilers. (Seen with gcc 4.4.7 on RHEL 6) 40 | res += 0; 41 | } 42 | 43 | // Same as above, but for printf (or Rprintf). 44 | inline void out_printf(const char *fmt, ...) { 45 | const size_t max_size = 4096; 46 | char buf[max_size]; 47 | 48 | va_list args; 49 | va_start(args, fmt); 50 | int n = vsnprintf(buf, max_size, fmt, args); 51 | va_end(args); 52 | 53 | if (n == -1) 54 | return; 55 | 56 | ssize_t res = write(STDOUT_FILENO, buf, n); 57 | // This is here simply to avoid a warning about "ignoring return value" of 58 | // the write(), on some compilers. (Seen with gcc 4.4.7 on RHEL 6) 59 | res += 0; 60 | } 61 | 62 | 63 | class WrappedStreambuf : public std::streambuf { 64 | public: 65 | // out_type: true means stdout; false means stderr. 66 | WrappedStreambuf(bool out_type) : out_type(out_type) {} 67 | 68 | protected: 69 | std::streamsize xsputn(const char *s, std::streamsize n) { 70 | if (out_type) { 71 | err_printf("%.*s", n, s); 72 | } else { 73 | out_printf("%.*s", n, s); 74 | } 75 | return n; 76 | }; 77 | 78 | private: 79 | bool out_type; 80 | }; 81 | 82 | 83 | namespace WrappedOstream { 84 | static WrappedStreambuf out_buf(true); 85 | static WrappedStreambuf err_buf(false); 86 | static std::ostream cout(&out_buf); 87 | static std::ostream cerr(&err_buf); 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(websocket) 3 | 4 | test_check("websocket") 5 | -------------------------------------------------------------------------------- /tools/version.c: -------------------------------------------------------------------------------- 1 | #include 2 | #if OPENSSL_VERSION_NUMBER < 0x10000000L 3 | #error OpenSSL version too old 4 | #endif 5 | -------------------------------------------------------------------------------- /tools/winlibs.R: -------------------------------------------------------------------------------- 1 | # Build against mingw-w64 build of openssl 2 | VERSION <- commandArgs(TRUE) 3 | if(!file.exists(sprintf("../windows/openssl-%s/include/openssl/ssl.h", VERSION))){ 4 | if(getRversion() < "3.3.0") setInternet2() 5 | download.file(sprintf("https://github.com/rwinlib/openssl/archive/v%s.zip", VERSION), 6 | "lib.zip", quiet = TRUE) 7 | dir.create("../windows", showWarnings = FALSE) 8 | unzip("lib.zip", exdir = "../windows") 9 | unlink("lib.zip") 10 | } 11 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /websocket.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | --------------------------------------------------------------------------------