diff --git a/CMakeLists.txt b/CMakeLists.txt index edbdd5a92..78a8beef1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,7 +203,7 @@ if (BUILD_TESTS OR BUILD_EXAMPLES) else () message (FATAL_ERROR "Failed to find required dependency: boost") endif () - + find_package(OpenSSL) endif() diff --git a/COPYING b/COPYING index 2c37a4778..0ea3913ed 100644 --- a/COPYING +++ b/COPYING @@ -11,13 +11,13 @@ modification, are permitted provided that the following conditions are met: names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/SConstruct b/SConstruct index 3a82ab9b7..e7f69bc3e 100644 --- a/SConstruct +++ b/SConstruct @@ -157,7 +157,7 @@ else: print "C++11 build environment disabled" # if the build system is known to allow the isystem modifier for library include -# values then use it for the boost libraries. Otherwise just add them to the +# values then use it for the boost libraries. Otherwise just add them to the # regular CPPPATH values. if env['CXX'].startswith('g++') or env['CXX'].startswith('clang'): env.Append(CPPFLAGS = '-isystem ' + env['BOOST_INCLUDES']) @@ -166,7 +166,7 @@ else: env.Append(LIBPATH = [env['BOOST_LIBS']]) # if the build system is known to allow the isystem modifier for library include -# values then use it for the boost libraries. Otherwise just add them to the +# values then use it for the boost libraries. Otherwise just add them to the # regular CPPPATH values. if env_cpp11['CXX'].startswith('g++') or env_cpp11['CXX'].startswith('clang'): env_cpp11.Append(CPPFLAGS = '-isystem ' + env_cpp11['BOOST_INCLUDES']) diff --git a/changelog.md b/changelog.md index 0c45786a2..3e8e36a9b 100644 --- a/changelog.md +++ b/changelog.md @@ -11,7 +11,7 @@ HEAD binary sizes. - Updates handling of Server and User-Agent headers to better handle custom settings and allow suppression of these headers for security purposes. -- Fix issue where pong timeout handler always fired. Thank you Steven Klassen +- Fix issue where pong timeout handler always fired. Thank you Steven Klassen for reporting this bug. - Add ping and pong endpoint wrapper methods - Add `get_request()` pass through method to connection to allow calling methods @@ -25,7 +25,7 @@ HEAD 0.3.0-alpha2 - 2013-06-09 - Fix a regression that caused servers being sent two close frames in a row to end a connection uncleanly. #259 -- Fix a regression that caused spurious frames following a legitimate close +- Fix a regression that caused spurious frames following a legitimate close frames to erroneously trigger handlers. #258 - Change default HTTP response error code when no http_handler is defined from 500/Internal Server Error to 426/Upgrade Required diff --git a/examples/associative_storage/associative_storage.cpp b/examples/associative_storage/associative_storage.cpp index a5dd3e32f..e2245e4e4 100644 --- a/examples/associative_storage/associative_storage.cpp +++ b/examples/associative_storage/associative_storage.cpp @@ -20,55 +20,55 @@ class print_server { public: print_server() : m_next_sessionid(1) { m_server.init_asio(); - + m_server.set_open_handler(bind(&print_server::on_open,this,::_1)); m_server.set_close_handler(bind(&print_server::on_close,this,::_1)); m_server.set_message_handler(bind(&print_server::on_message,this,::_1,::_2)); } - + void on_open(connection_hdl hdl) { connection_data data; - + data.sessionid = m_next_sessionid++; data.name = ""; - + m_connections[hdl] = data; } - + void on_close(connection_hdl hdl) { connection_data& data = get_data_from_hdl(hdl); - - std::cout << "Closing connection " << data.name + + std::cout << "Closing connection " << data.name << " with sessionid " << data.sessionid << std::endl; - + m_connections.erase(hdl); } - + void on_message(connection_hdl hdl, server::message_ptr msg) { connection_data& data = get_data_from_hdl(hdl); - + if (data.name == "") { data.name = msg->get_payload(); - std::cout << "Setting name of connection with sessionid " + std::cout << "Setting name of connection with sessionid " << data.sessionid << " to " << data.name << std::endl; } else { - std::cout << "Got a message from connection " << data.name + std::cout << "Got a message from connection " << data.name << " with sessionid " << data.sessionid << std::endl; } } - + connection_data& get_data_from_hdl(connection_hdl hdl) { auto it = m_connections.find(hdl); - + if (it == m_connections.end()) { // this connection is not in the list. This really shouldn't happen // and probably means something else is wrong. throw std::invalid_argument("No data available for session"); } - + return it->second; } - + void run(uint16_t port) { m_server.listen(port); m_server.start_accept(); @@ -85,4 +85,4 @@ class print_server { int main() { print_server server; server.run(9002); -} \ No newline at end of file +} diff --git a/examples/broadcast_server/broadcast_server.cpp b/examples/broadcast_server/broadcast_server.cpp index 70e48b955..4066e07e5 100644 --- a/examples/broadcast_server/broadcast_server.cpp +++ b/examples/broadcast_server/broadcast_server.cpp @@ -35,31 +35,31 @@ enum action_type { struct action { action(action_type t, connection_hdl h) : type(t), hdl(h) {} action(action_type t, server::message_ptr m) : type(t), msg(m) {} - + action_type type; websocketpp::connection_hdl hdl; server::message_ptr msg; }; - + class broadcast_server { public: broadcast_server() { // Initialize Asio Transport m_server.init_asio(); - + // Register handler callbacks m_server.set_open_handler(bind(&broadcast_server::on_open,this,::_1)); m_server.set_close_handler(bind(&broadcast_server::on_close,this,::_1)); m_server.set_message_handler(bind(&broadcast_server::on_message,this,::_1,::_2)); } - + void run(uint16_t port) { // listen on specified port m_server.listen(port); - + // Start the server accept loop m_server.start_accept(); - + // Start the ASIO io_service run loop try { m_server.run(); @@ -71,7 +71,7 @@ class broadcast_server { std::cout << "other exception" << std::endl; } } - + void on_open(connection_hdl hdl) { unique_lock lock(m_action_lock); //std::cout << "on_open" << std::endl; @@ -79,7 +79,7 @@ class broadcast_server { lock.unlock(); m_action_cond.notify_one(); } - + void on_close(connection_hdl hdl) { unique_lock lock(m_action_lock); //std::cout << "on_close" << std::endl; @@ -87,7 +87,7 @@ class broadcast_server { lock.unlock(); m_action_cond.notify_one(); } - + void on_message(connection_hdl hdl, server::message_ptr msg) { // queue message up for sending by processing thread unique_lock lock(m_action_lock); @@ -96,20 +96,20 @@ class broadcast_server { lock.unlock(); m_action_cond.notify_one(); } - + void process_messages() { while(1) { unique_lock lock(m_action_lock); - + while(m_actions.empty()) { m_action_cond.wait(lock); } - + action a = m_actions.front(); m_actions.pop(); - + lock.unlock(); - + if (a.type == SUBSCRIBE) { unique_lock lock(m_connection_lock); m_connections.insert(a.hdl); @@ -118,7 +118,7 @@ class broadcast_server { m_connections.erase(a.hdl); } else if (a.type == MESSAGE) { unique_lock lock(m_connection_lock); - + con_list::iterator it; for (it = m_connections.begin(); it != m_connections.end(); ++it) { m_server.send(*it,a.msg); @@ -130,11 +130,11 @@ class broadcast_server { } private: typedef std::set> con_list; - + server m_server; con_list m_connections; std::queue m_actions; - + mutex m_action_lock; mutex m_connection_lock; condition_variable m_action_cond; @@ -143,15 +143,15 @@ class broadcast_server { int main() { try { broadcast_server server; - + // Start a thread to run the processing loop thread t(bind(&broadcast_server::process_messages,&server)); - + // Run the asio loop with the main thread server.run(9002); - + t.join(); - + } catch (std::exception & e) { std::cout << e.what() << std::endl; } diff --git a/examples/dev/main.cpp b/examples/dev/main.cpp index 241f0f780..9e93f6842 100644 --- a/examples/dev/main.cpp +++ b/examples/dev/main.cpp @@ -32,169 +32,169 @@ typedef websocketpp::server server; } return true; } - + void http(connection_ptr con) { std::cout << "handler http" << std::endl; } - + void on_load(connection_ptr con, ptr old_handler) { std::cout << "handler on_load" << std::endl; } void on_unload(connection_ptr con, ptr new_handler) { std::cout << "handler on_unload" << std::endl; } - + void on_open(connection_ptr con) { std::cout << "handler on_open" << std::endl; } void on_fail(connection_ptr con) { std::cout << "handler on_fail" << std::endl; } - + void on_message(connection_ptr con, message_ptr msg) { std::cout << "handler on_message" << std::endl; - - + + } - + void on_close(connection_ptr con) { std::cout << "handler on_close" << std::endl; } };*/ int main() { - typedef websocketpp::message_buffer::message + typedef websocketpp::message_buffer::message message_type; - typedef websocketpp::message_buffer::alloc::con_msg_manager + typedef websocketpp::message_buffer::alloc::con_msg_manager con_msg_man_type; con_msg_man_type::ptr manager(new con_msg_man_type()); - + size_t foo = 1024; - + message_type::ptr input = manager->get_message(websocketpp::frame::opcode::TEXT,foo); message_type::ptr output = manager->get_message(websocketpp::frame::opcode::TEXT,foo); websocketpp::frame::masking_key_type key; - + std::random_device dev; - - - + + + key.i = 0x12345678; - + double m = 18094238402394.0824923; - + /*std::cout << "Some Math" << std::endl; { boost::timer::auto_cpu_timer t; - + for (int i = 0; i < foo; i++) { m /= 1.001; } - + }*/ - + std::cout << m << std::endl; - + std::cout << "Random Gen" << std::endl; { boost::timer::auto_cpu_timer t; - + input->get_raw_payload().replace(0,foo,foo,'\0'); output->get_raw_payload().replace(0,foo,foo,'\0'); } - + std::cout << "Out of place accelerated" << std::endl; { boost::timer::auto_cpu_timer t; - + websocketpp::frame::word_mask_exact(reinterpret_cast(const_cast(input->get_raw_payload().data())), reinterpret_cast(const_cast(output->get_raw_payload().data())), foo, key); } - + std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; - + input->get_raw_payload().replace(0,foo,foo,'\0'); output->get_raw_payload().replace(0,foo,foo,'\0'); - + std::cout << "In place accelerated" << std::endl; { boost::timer::auto_cpu_timer t; - + websocketpp::frame::word_mask_exact(reinterpret_cast(const_cast(input->get_raw_payload().data())), reinterpret_cast(const_cast(input->get_raw_payload().data())), foo, key); } - + std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; - + input->get_raw_payload().replace(0,foo,foo,'\0'); output->get_raw_payload().replace(0,foo,foo,'\0'); std::cout << "Out of place byte by byte" << std::endl; { boost::timer::auto_cpu_timer t; - + websocketpp::frame::byte_mask(input->get_raw_payload().begin(), input->get_raw_payload().end(), output->get_raw_payload().begin(), key); } - + std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; - + input->get_raw_payload().replace(0,foo,foo,'\0'); output->get_raw_payload().replace(0,foo,foo,'\0'); std::cout << "In place byte by byte" << std::endl; { boost::timer::auto_cpu_timer t; - + websocketpp::frame::byte_mask(input->get_raw_payload().begin(), input->get_raw_payload().end(), input->get_raw_payload().begin(), key); } - + std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; - + input->get_raw_payload().replace(0,foo,foo,'a'); output->get_raw_payload().replace(0,foo,foo,'b'); std::cout << "Copy" << std::endl; { boost::timer::auto_cpu_timer t; - + std::copy(input->get_raw_payload().begin(), input->get_raw_payload().end(), output->get_raw_payload().begin()); } - + std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl; std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl; - + /*server::handler::ptr h(new handler()); - + server test_server(h); server::connection_ptr con; - + std::stringstream output; - + test_server.register_ostream(&output); - + con = test_server.get_connection(); - + con->start(); - + //foo.handle_accept(con,true); - + std::stringstream input; input << "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n"; //input << "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; input >> *con; - + std::stringstream input2; input2 << "messageabc2"; input2 >> *con; - + std::stringstream input3; input3 << "messageabc3"; input3 >> *con; - + std::stringstream input4; input4 << "close"; input4 >> *con; - + std::cout << "connection output:" << std::endl; std::cout << output.str() << std::endl;*/ } diff --git a/examples/echo_server/CMakeLists.txt b/examples/echo_server/CMakeLists.txt index adacc6aa7..a82dfa792 100644 --- a/examples/echo_server/CMakeLists.txt +++ b/examples/echo_server/CMakeLists.txt @@ -1,4 +1,4 @@ - + file (GLOB SOURCE_FILES *.cpp) file (GLOB HEADER_FILES *.hpp) diff --git a/examples/echo_server/echo_handler.hpp b/examples/echo_server/echo_handler.hpp index 96f15fe53..f90634212 100644 --- a/examples/echo_server/echo_handler.hpp +++ b/examples/echo_server/echo_handler.hpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ #ifndef WEBSOCKETPP_ECHO_SERVER_HANDLER_HPP diff --git a/examples/echo_server/echo_server.cpp b/examples/echo_server/echo_server.cpp index db8623421..f1f60e2d2 100644 --- a/examples/echo_server/echo_server.cpp +++ b/examples/echo_server/echo_server.cpp @@ -15,14 +15,14 @@ typedef server::message_ptr message_ptr; // Define a callback to handle incoming messages void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { - std::cout << "on_message called with hdl: " << hdl.lock().get() + std::cout << "on_message called with hdl: " << hdl.lock().get() << " and message: " << msg->get_payload() << std::endl; try { s->send(hdl, msg->get_payload(), msg->get_opcode()); } catch (const websocketpp::lib::error_code& e) { - std::cout << "Echo failed because: " << e + std::cout << "Echo failed because: " << e << "(" << e.message() << ")" << std::endl; } } @@ -30,24 +30,24 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { int main() { // Create a server endpoint server echo_server; - + try { // Set logging settings echo_server.set_access_channels(websocketpp::log::alevel::all); echo_server.clear_access_channels(websocketpp::log::alevel::frame_payload); - + // Initialize ASIO echo_server.init_asio(); - + // Register our message handler echo_server.set_message_handler(bind(&on_message,&echo_server,::_1,::_2)); - + // Listen on port 9002 echo_server.listen(9002); - + // Start the server accept loop echo_server.start_accept(); - + // Start the ASIO io_service run loop echo_server.run(); } catch (const std::exception & e) { diff --git a/examples/echo_server_tls/CMakeLists.txt b/examples/echo_server_tls/CMakeLists.txt index 619ac41ff..b87cbb1f0 100644 --- a/examples/echo_server_tls/CMakeLists.txt +++ b/examples/echo_server_tls/CMakeLists.txt @@ -1,10 +1,10 @@ - + file (GLOB SOURCE_FILES *.cpp) file (GLOB HEADER_FILES *.hpp) if (OPENSSL_FOUND) - + init_target (echo_server_tls) build_executable (${TARGET_NAME} ${SOURCE_FILES} ${HEADER_FILES}) @@ -12,4 +12,4 @@ build_executable (${TARGET_NAME} ${SOURCE_FILES} ${HEADER_FILES}) link_boost () link_openssl() final_target () -endif() \ No newline at end of file +endif() diff --git a/examples/echo_server_tls/echo_handler_tls.hpp b/examples/echo_server_tls/echo_handler_tls.hpp index 96f15fe53..f90634212 100644 --- a/examples/echo_server_tls/echo_handler_tls.hpp +++ b/examples/echo_server_tls/echo_handler_tls.hpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ #ifndef WEBSOCKETPP_ECHO_SERVER_HANDLER_HPP diff --git a/examples/echo_server_tls/echo_server_tls.cpp b/examples/echo_server_tls/echo_server_tls.cpp index 43ac0fc28..feeb05b87 100644 --- a/examples/echo_server_tls/echo_server_tls.cpp +++ b/examples/echo_server_tls/echo_server_tls.cpp @@ -15,14 +15,14 @@ typedef websocketpp::config::asio::message_type::ptr message_ptr; typedef websocketpp::lib::shared_ptr context_ptr; void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { - std::cout << "on_message called with hdl: " << hdl.lock().get() + std::cout << "on_message called with hdl: " << hdl.lock().get() << " and message: " << msg->get_payload() << std::endl; try { s->send(hdl, msg->get_payload(), msg->get_opcode()); } catch (const websocketpp::lib::error_code& e) { - std::cout << "Echo failed because: " << e + std::cout << "Echo failed because: " << e << "(" << e.message() << ")" << std::endl; } } @@ -51,7 +51,7 @@ context_ptr on_tls_init(websocketpp::connection_hdl hdl) { int main() { // Create a server endpoint server echo_server; - + // Initialize ASIO echo_server.init_asio(); @@ -59,10 +59,10 @@ int main() { echo_server.set_message_handler(bind(&on_message,&echo_server,::_1,::_2)); echo_server.set_tls_init_handler(bind(&on_tls_init,::_1)); - + // Listen on port 9002 echo_server.listen(9002); - + // Start the server accept loop echo_server.start_accept(); diff --git a/examples/handler_switch/handler_switch.cpp b/examples/handler_switch/handler_switch.cpp index e877b3fe9..c2cf6ffa4 100644 --- a/examples/handler_switch/handler_switch.cpp +++ b/examples/handler_switch/handler_switch.cpp @@ -17,12 +17,12 @@ void custom_on_msg(server & s, connection_hdl hdl, server::message_ptr msg) { void default_on_msg(server & s, connection_hdl hdl, server::message_ptr msg) { std::cout << "Message sent to default handler" << std::endl; - + if (msg->get_payload() == "upgrade") { // Upgrade our connection_hdl to a full connection_ptr server::connection_ptr con = s.get_con_from_hdl(hdl); - - // Change the on message handler for this connection only to + + // Change the on message handler for this connection only to // custom_on_mesage con->set_message_handler(bind(&custom_on_msg,ref(s),::_1,::_2)); std::cout << "Upgrading connection to custom handler" << std::endl; @@ -39,4 +39,4 @@ int main() { s.start_accept(); s.run(); -} \ No newline at end of file +} diff --git a/examples/iostream_server/iostream_server.cpp b/examples/iostream_server/iostream_server.cpp index b1c3f0769..617631369 100644 --- a/examples/iostream_server/iostream_server.cpp +++ b/examples/iostream_server/iostream_server.cpp @@ -17,17 +17,17 @@ typedef server::message_ptr message_ptr; // Define a callback to handle incoming messages void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { if (msg->get_opcode() == websocketpp::frame::opcode::text) { - s->get_alog().write(websocketpp::log::alevel::app, + s->get_alog().write(websocketpp::log::alevel::app, "Text Message Received: "+msg->get_payload()); } else { - s->get_alog().write(websocketpp::log::alevel::app, + s->get_alog().write(websocketpp::log::alevel::app, "Binary Message Received: "+websocketpp::utility::to_hex(msg->get_payload())); - } - + } + try { s->send(hdl, msg->get_payload(), msg->get_opcode()); } catch (const websocketpp::lib::error_code& e) { - s->get_alog().write(websocketpp::log::alevel::app, + s->get_alog().write(websocketpp::log::alevel::app, "Echo Failed: "+e.message()); } } @@ -35,43 +35,43 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { int main() { server s; std::ofstream log; - - try { + + try { // set up access channels to only log interesting things s.clear_access_channels(websocketpp::log::alevel::all); s.set_access_channels(websocketpp::log::alevel::connect); s.set_access_channels(websocketpp::log::alevel::disconnect); s.set_access_channels(websocketpp::log::alevel::app); - - // Log to a file rather than stdout, as we are using stdout for real + + // Log to a file rather than stdout, as we are using stdout for real // output log.open("output.log"); s.get_alog().set_ostream(&log); s.get_elog().set_ostream(&log); - + // print all output to stdout s.register_ostream(&std::cout); - + // Register our message handler s.set_message_handler(bind(&on_message,&s,::_1,::_2)); - + server::connection_ptr con = s.get_connection(); - + con->start(); - - // C++ iostream's don't support the idea of asynchronous i/o. As such - // there are two input strategies demonstrated here. Buffered I/O will - // read from stdin in chunks until EOF. This works very well for + + // C++ iostream's don't support the idea of asynchronous i/o. As such + // there are two input strategies demonstrated here. Buffered I/O will + // read from stdin in chunks until EOF. This works very well for // replaying canned connections as would be done in automated testing. // - // If the server is being used live however, assuming input is being - // piped from elsewhere in realtime, this strategy will result in small - // messages being buffered forever. The non-buffered strategy below - // reads characters from stdin one at a time. This is inefficient and - // for more serious uses should be replaced with a platform specific + // If the server is being used live however, assuming input is being + // piped from elsewhere in realtime, this strategy will result in small + // messages being buffered forever. The non-buffered strategy below + // reads characters from stdin one at a time. This is inefficient and + // for more serious uses should be replaced with a platform specific // asyncronous i/o technique like select, poll, IOCP, etc bool buffered_io = false; - + if (buffered_io) { std::cin >> *con; } else { @@ -88,4 +88,4 @@ int main() { std::cout << "other exception" << std::endl; } log.close(); -} \ No newline at end of file +} diff --git a/examples/print_server/CMakeLists.txt b/examples/print_server/CMakeLists.txt index 2204c3051..dc34879b6 100644 --- a/examples/print_server/CMakeLists.txt +++ b/examples/print_server/CMakeLists.txt @@ -1,4 +1,4 @@ - + file (GLOB SOURCE_FILES *.cpp) file (GLOB HEADER_FILES *.hpp) diff --git a/examples/simple_broadcast_server/simple_broadcast_server.cpp b/examples/simple_broadcast_server/simple_broadcast_server.cpp index e1686bcf7..7c4847693 100644 --- a/examples/simple_broadcast_server/simple_broadcast_server.cpp +++ b/examples/simple_broadcast_server/simple_broadcast_server.cpp @@ -13,20 +13,20 @@ class broadcast_server { public: broadcast_server() { m_server.init_asio(); - + m_server.set_open_handler(bind(&broadcast_server::on_open,this,::_1)); m_server.set_close_handler(bind(&broadcast_server::on_close,this,::_1)); m_server.set_message_handler(bind(&broadcast_server::on_message,this,::_1,::_2)); } - + void on_open(connection_hdl hdl) { m_connections.insert(hdl); } - + void on_close(connection_hdl hdl) { m_connections.erase(hdl); } - + void on_message(connection_hdl hdl, server::message_ptr msg) { for (auto it : m_connections) { m_server.send(it,msg); @@ -48,4 +48,4 @@ class broadcast_server { int main() { broadcast_server server; server.run(9002); -} \ No newline at end of file +} diff --git a/examples/sip_client/CMakeLists.txt b/examples/sip_client/CMakeLists.txt index 3ac386d56..65a90b01c 100644 --- a/examples/sip_client/CMakeLists.txt +++ b/examples/sip_client/CMakeLists.txt @@ -1,4 +1,4 @@ - + file (GLOB SOURCE_FILES *.cpp) file (GLOB HEADER_FILES *.hpp) diff --git a/examples/sip_client/sip_client.cpp b/examples/sip_client/sip_client.cpp index 3a4de786f..990d76fc3 100644 --- a/examples/sip_client/sip_client.cpp +++ b/examples/sip_client/sip_client.cpp @@ -6,7 +6,7 @@ #include -#include +#include typedef websocketpp::client client; @@ -21,12 +21,12 @@ typedef websocketpp::config::asio_client::message_type::ptr message_ptr; client sip_client; -bool received; +bool received; void on_open(client* c, websocketpp::connection_hdl hdl) { // now it is safe to use the connection std::cout << "connection ready" << std::endl; - + received=false; // Send a SIP OPTIONS message to the server: std::string SIP_msg="OPTIONS sip:carol@chicago.com SIP/2.0\r\nVia: SIP/2.0/WS df7jal23ls0d.invalid;rport;branch=z9hG4bKhjhs8ass877\r\nMax-Forwards: 70\r\nTo: \r\nFrom: Alice ;tag=1928301774\r\nCall-ID: a84b4c76e66710\r\nCSeq: 63104 OPTIONS\r\nContact: \r\nAccept: application/sdp\r\nContent-Length: 0\r\n\r\n"; @@ -35,32 +35,32 @@ void on_open(client* c, websocketpp::connection_hdl hdl) { void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) { client::connection_ptr con = sip_client.get_con_from_hdl(hdl); - + std::cout << "Received a reply:" << std::endl; fwrite(msg->get_payload().c_str(), msg->get_payload().size(), 1, stdout); received=true; } int main(int argc, char* argv[]) { - + std::string uri = "ws://localhost:9001"; - + if (argc == 2) { uri = argv[1]; } - + try { // We expect there to be a lot of errors, so suppress them sip_client.clear_access_channels(websocketpp::log::alevel::all); sip_client.clear_error_channels(websocketpp::log::elevel::all); - + // Initialize ASIO sip_client.init_asio(); - + // Register our handlers sip_client.set_open_handler(bind(&on_open,&sip_client,::_1)); sip_client.set_message_handler(bind(&on_message,&sip_client,::_1,::_2)); - + websocketpp::lib::error_code ec; client::connection_ptr con = sip_client.get_connection(uri, ec); @@ -68,16 +68,16 @@ int main(int argc, char* argv[]) { con->add_subprotocol("sip"); sip_client.connect(con); - + // Start the ASIO io_service run loop sip_client.run(); - + while(!received) { boost::this_thread::sleep(boost::posix_time::milliseconds(100)); } - + std::cout << "done" << std::endl; - + } catch (const std::exception & e) { std::cout << e.what() << std::endl; } catch (websocketpp::lib::error_code e) { diff --git a/examples/subprotocol_server/subprotocol_server.cpp b/examples/subprotocol_server/subprotocol_server.cpp index 0cdc1d0cd..ecf8fecbe 100644 --- a/examples/subprotocol_server/subprotocol_server.cpp +++ b/examples/subprotocol_server/subprotocol_server.cpp @@ -14,20 +14,20 @@ using websocketpp::lib::ref; bool validate(server & s, connection_hdl hdl) { server::connection_ptr con = s.get_con_from_hdl(hdl); - + std::cout << "Cache-Control: " << con->get_request_header("Cache-Control") << std::endl; - + const std::vector & subp_requests = con->get_requested_subprotocols(); std::vector::const_iterator it; - + for (it = subp_requests.begin(); it != subp_requests.end(); ++it) { std::cout << "Requested: " << *it << std::endl; } - + if (subp_requests.size() > 0) { con->select_subprotocol(subp_requests[0]); } - + return true; } @@ -49,4 +49,4 @@ int main() { } catch (...) { std::cout << "other exception" << std::endl; } -} \ No newline at end of file +} diff --git a/examples/telemetry_client/CMakeLists.txt b/examples/telemetry_client/CMakeLists.txt index 617271456..5cf4964e9 100644 --- a/examples/telemetry_client/CMakeLists.txt +++ b/examples/telemetry_client/CMakeLists.txt @@ -1,4 +1,4 @@ - + file (GLOB SOURCE_FILES *.cpp) file (GLOB HEADER_FILES *.hpp) diff --git a/examples/telemetry_client/telemetry_client.cpp b/examples/telemetry_client/telemetry_client.cpp index 700ca578a..e1bd1df0e 100644 --- a/examples/telemetry_client/telemetry_client.cpp +++ b/examples/telemetry_client/telemetry_client.cpp @@ -9,24 +9,24 @@ /** * The telemetry client connects to a WebSocket server and sends a message every * second containing an integer count. This example can be used as the basis for - * programs where a client connects and pushes data for logging, stress/load + * programs where a client connects and pushes data for logging, stress/load * testing, etc. */ class telemetry_client { public: typedef websocketpp::client client; typedef websocketpp::lib::lock_guard scoped_lock; - + telemetry_client() : m_open(false),m_done(false) { // set up access channels to only log interesting things m_client.clear_access_channels(websocketpp::log::alevel::all); m_client.set_access_channels(websocketpp::log::alevel::connect); m_client.set_access_channels(websocketpp::log::alevel::disconnect); m_client.set_access_channels(websocketpp::log::alevel::app); - + // Initialize the Asio transport policy m_client.init_asio(); - + // Bind the handlers we are using using websocketpp::lib::placeholders::_1; using websocketpp::lib::bind; @@ -34,98 +34,98 @@ class telemetry_client { m_client.set_close_handler(bind(&telemetry_client::on_close,this,::_1)); m_client.set_fail_handler(bind(&telemetry_client::on_fail,this,::_1)); } - + // This method will block until the connection is complete void run(const std::string & uri) { // Create a new connection to the given URI websocketpp::lib::error_code ec; client::connection_ptr con = m_client.get_connection(uri, ec); if (ec) { - m_client.get_alog().write(websocketpp::log::alevel::app, + m_client.get_alog().write(websocketpp::log::alevel::app, "Get Connection Error: "+ec.message()); return; } - - // Grab a handle for this connection so we can talk to it in a thread + + // Grab a handle for this connection so we can talk to it in a thread // safe manor after the event loop starts. m_hdl = con->get_handle(); - + // Queue the connection. No DNS queries or network connections will be // made until the io_service event loop is run. m_client.connect(con); - + // Create a thread to run the ASIO io_service event loop websocketpp::lib::thread asio_thread(&client::run, &m_client); - + // Create a thread to run the telemetry loop websocketpp::lib::thread telemetry_thread(&telemetry_client::telemetry_loop,this); - + asio_thread.join(); telemetry_thread.join(); } - + // The open handler will signal that we are ready to start sending telemetry void on_open(websocketpp::connection_hdl hdl) { - m_client.get_alog().write(websocketpp::log::alevel::app, + m_client.get_alog().write(websocketpp::log::alevel::app, "Connection opened, starting telemetry!"); - + scoped_lock guard(m_lock); m_open = true; } - + // The close handler will signal that we should stop sending telemetry void on_close(websocketpp::connection_hdl hdl) { - m_client.get_alog().write(websocketpp::log::alevel::app, + m_client.get_alog().write(websocketpp::log::alevel::app, "Connection closed, stopping telemetry!"); - + scoped_lock guard(m_lock); m_done = true; } - + // The fail handler will signal that we should stop sending telemetry void on_fail(websocketpp::connection_hdl hdl) { - m_client.get_alog().write(websocketpp::log::alevel::app, + m_client.get_alog().write(websocketpp::log::alevel::app, "Connection failed, stopping telemetry!"); - + scoped_lock guard(m_lock); m_done = true; } - + void telemetry_loop() { uint64_t count = 0; std::stringstream val; websocketpp::lib::error_code ec; - + while(1) { { scoped_lock guard(m_lock); // If the connection has been closed, stop generating telemetry if (m_done) {break;} - + // If the connection hasn't been opened yet wait a bit and retry if (!m_open) { sleep(1); continue; } } - + val.str(""); val << "count is " << count++; - + m_client.get_alog().write(websocketpp::log::alevel::app, val.str()); m_client.send(m_hdl,val.str(),websocketpp::frame::opcode::text,ec); - + // The most likely error that we will get is that the connection is - // not in the right state. Usually this means we tried to send a - // message to a connection that was closed or in the process of - // closing. While many errors here can be easily recovered from, + // not in the right state. Usually this means we tried to send a + // message to a connection that was closed or in the process of + // closing. While many errors here can be easily recovered from, // in this simple example, we'll stop the telemetry loop. if (ec) { - m_client.get_alog().write(websocketpp::log::alevel::app, + m_client.get_alog().write(websocketpp::log::alevel::app, "Send Error: "+ec.message()); break; } - + sleep(1); } } @@ -139,12 +139,12 @@ class telemetry_client { int main(int argc, char* argv[]) { telemetry_client c; - + std::string uri = "ws://localhost:9002"; - + if (argc == 2) { uri = argv[1]; } - + c.run(uri); } diff --git a/examples/testee_client/CMakeLists.txt b/examples/testee_client/CMakeLists.txt index da24203b1..a6ca6dd35 100644 --- a/examples/testee_client/CMakeLists.txt +++ b/examples/testee_client/CMakeLists.txt @@ -1,4 +1,4 @@ - + file (GLOB SOURCE_FILES *.cpp) file (GLOB HEADER_FILES *.hpp) diff --git a/examples/testee_client/testee_client.cpp b/examples/testee_client/testee_client.cpp index 6bdc70624..d2e0545b1 100644 --- a/examples/testee_client/testee_client.cpp +++ b/examples/testee_client/testee_client.cpp @@ -17,9 +17,9 @@ int case_count = 0; void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) { client::connection_ptr con = c->get_con_from_hdl(hdl); - + if (con->get_resource() == "/getCaseCount") { - std::cout << "Detected " << msg->get_payload() << " test cases." + std::cout << "Detected " << msg->get_payload() << " test cases." << std::endl; case_count = atoi(msg->get_payload().c_str()); } else { @@ -30,50 +30,50 @@ void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) { int main(int argc, char* argv[]) { // Create a server endpoint client c; - + std::string uri = "ws://localhost:9001"; - + if (argc == 2) { uri = argv[1]; } - + try { // We expect there to be a lot of errors, so suppress them c.clear_access_channels(websocketpp::log::alevel::all); c.clear_error_channels(websocketpp::log::elevel::all); - + // Initialize ASIO c.init_asio(); - + // Register our handlers c.set_message_handler(bind(&on_message,&c,::_1,::_2)); - + websocketpp::lib::error_code ec; client::connection_ptr con = c.get_connection(uri+"/getCaseCount", ec); c.connect(con); - + // Start the ASIO io_service run loop c.run(); - + std::cout << "case count: " << case_count << std::endl; - + for (int i = 1; i <= case_count; i++) { c.reset(); - + std::stringstream url; - - url << uri << "/runCase?case=" << i << "&agent=" + + url << uri << "/runCase?case=" << i << "&agent=" << websocketpp::user_agent; - + con = c.get_connection(url.str(), ec); - + c.connect(con); - + c.run(); } - + std::cout << "done" << std::endl; - + } catch (const std::exception & e) { std::cout << e.what() << std::endl; } catch (websocketpp::lib::error_code e) { diff --git a/examples/utility_client/utility_client.cpp b/examples/utility_client/utility_client.cpp index 2f6320b03..64282fe65 100644 --- a/examples/utility_client/utility_client.cpp +++ b/examples/utility_client/utility_client.cpp @@ -14,7 +14,7 @@ typedef websocketpp::client client; using websocketpp::lib::placeholders::_1; using websocketpp::lib::placeholders::_2; -using websocketpp::lib::bind; +using websocketpp::lib::bind; // pull out the type of messages sent by our config typedef websocketpp::config::asio_tls_client::message_type::ptr message_ptr; @@ -27,14 +27,14 @@ class perftest { public: typedef perftest type; typedef std::chrono::duration dur_type; - + perftest () { m_endpoint.set_access_channels(websocketpp::log::alevel::all); m_endpoint.set_error_channels(websocketpp::log::elevel::all); - + // Initialize ASIO m_endpoint.init_asio(); - + // Register our handlers m_endpoint.set_socket_init_handler(bind(&type::on_socket_init,this,::_1)); m_endpoint.set_tls_init_handler(bind(&type::on_tls_init,this,::_1)); @@ -42,28 +42,28 @@ class perftest { m_endpoint.set_open_handler(bind(&type::on_open,this,::_1)); m_endpoint.set_close_handler(bind(&type::on_close,this,::_1)); } - + void start(std::string uri) { websocketpp::lib::error_code ec; client::connection_ptr con = m_endpoint.get_connection(uri, ec); - + if (ec) { m_endpoint.get_alog().write(websocketpp::log::alevel::app,ec.message()); } - + //con->set_proxy("http://humupdates.uchicago.edu:8443"); - + m_endpoint.connect(con); - + // Start the ASIO io_service run loop m_start = std::chrono::high_resolution_clock::now(); m_endpoint.run(); } - + void on_socket_init(websocketpp::connection_hdl hdl) { m_socket_init = std::chrono::high_resolution_clock::now(); } - + context_ptr on_tls_init(websocketpp::connection_hdl hdl) { m_tls_init = std::chrono::high_resolution_clock::now(); context_ptr ctx(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1)); @@ -77,7 +77,7 @@ class perftest { } return ctx; } - + void on_open(websocketpp::connection_hdl hdl) { m_open = std::chrono::high_resolution_clock::now(); m_endpoint.send(hdl, "", websocketpp::frame::opcode::text); @@ -88,7 +88,7 @@ class perftest { } void on_close(websocketpp::connection_hdl hdl) { m_close = std::chrono::high_resolution_clock::now(); - + std::cout << "Socket Init: " << std::chrono::duration_cast(m_socket_init-m_start).count() << std::endl; std::cout << "TLS Init: " << std::chrono::duration_cast(m_tls_init-m_start).count() << std::endl; std::cout << "Open: " << std::chrono::duration_cast(m_open-m_start).count() << std::endl; @@ -97,7 +97,7 @@ class perftest { } private: client m_endpoint; - + std::chrono::high_resolution_clock::time_point m_start; std::chrono::high_resolution_clock::time_point m_socket_init; std::chrono::high_resolution_clock::time_point m_tls_init; @@ -108,11 +108,11 @@ class perftest { int main(int argc, char* argv[]) { std::string uri = "wss://echo.websocket.org"; - + if (argc == 2) { uri = argv[1]; } - + try { perftest endpoint; endpoint.start(uri); diff --git a/readme.md b/readme.md index 5db93361b..0c36a8a9e 100644 --- a/readme.md +++ b/readme.md @@ -22,22 +22,22 @@ Get Involved [![Build Status](https://travis-ci.org/zaphoyd/websocketpp.png)](https://travis-ci.org/zaphoyd/websocketpp) -**Project Website** +**Project Website** http://www.zaphoyd.com/websocketpp/ -**User Manual** +**User Manual** http://www.zaphoyd.com/websocketpp/manual/ -**GitHub Repository** +**GitHub Repository** https://github.com/zaphoyd/websocketpp/ -**Announcements Mailing List** +**Announcements Mailing List** http://groups.google.com/group/websocketpp-announcements/ -**IRC Channel** +**IRC Channel** #websocketpp (freenode) -**Discussion / Development / Support Mailing List / Forum** +**Discussion / Development / Support Mailing List / Forum** http://groups.google.com/group/websocketpp/ Author diff --git a/test/connection/connection.cpp b/test/connection/connection.cpp index a400020b4..c8f7db02e 100644 --- a/test/connection/connection.cpp +++ b/test/connection/connection.cpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ //#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE connection @@ -30,15 +30,15 @@ #include "connection_tu2.hpp" -// NOTE: these tests currently test against hardcoded output values. I am not -// sure how problematic this will be. If issues arise like order of headers the +// NOTE: these tests currently test against hardcoded output values. I am not +// sure how problematic this will be. If issues arise like order of headers the // output should be parsed by http::response and have values checked directly BOOST_AUTO_TEST_CASE( basic_http_request ) { std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; - std::string output = "HTTP/1.1 426 Upgrade Required\r\nServer: " + + std::string output = "HTTP/1.1 426 Upgrade Required\r\nServer: " + std::string(websocketpp::user_agent)+"\r\n\r\n"; - + std::string o2 = run_server_test(input); BOOST_CHECK(o2 == output); @@ -46,15 +46,15 @@ BOOST_AUTO_TEST_CASE( basic_http_request ) { struct connection_extension { connection_extension() : extension_value(5) {} - + int extension_method() { return extension_value; } - + bool is_server() const { return false; } - + int extension_value; }; @@ -72,17 +72,17 @@ struct stub_config : public websocketpp::config::core { typedef core::elog_type elog_type; typedef core::rng_type rng_type; - + typedef core::transport_type transport_type; - + typedef core::endpoint_base endpoint_base; typedef connection_extension connection_base; }; struct connection_setup { - connection_setup(bool server) + connection_setup(bool server) : c(server,"",alog,elog,rng) {} - + websocketpp::lib::error_code ec; stub_config::alog_type alog; stub_config::elog_type elog; @@ -106,19 +106,19 @@ bool validate_set_ua(server* s, websocketpp::connection_hdl hdl) { void http_func(server* s, websocketpp::connection_hdl hdl) { server::connection_ptr con = s->get_con_from_hdl(hdl); - + std::string res = con->get_resource(); - + con->set_body(res); con->set_status(websocketpp::http::status_code::ok); } BOOST_AUTO_TEST_CASE( connection_extensions ) { connection_setup env(true); - + BOOST_CHECK( env.c.extension_value == 5 ); BOOST_CHECK( env.c.extension_method() == 5 ); - + BOOST_CHECK( env.c.is_server() == true ); } @@ -127,10 +127,10 @@ BOOST_AUTO_TEST_CASE( basic_websocket_request ) { std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: "; output+=websocketpp::user_agent; output+="\r\nUpgrade: websocket\r\n\r\n"; - + server s; s.set_message_handler(bind(&echo_func,&s,::_1,::_2)); - + BOOST_CHECK(run_server_test(s,input) == output); } @@ -139,56 +139,56 @@ BOOST_AUTO_TEST_CASE( http_request ) { std::string output = "HTTP/1.1 200 OK\r\nContent-Length: 8\r\nServer: "; output+=websocketpp::user_agent; output+="\r\n\r\n/foo/bar"; - + server s; s.set_http_handler(bind(&http_func,&s,::_1)); - + BOOST_CHECK_EQUAL(run_server_test(s,input), output); } BOOST_AUTO_TEST_CASE( request_no_server_header ) { std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n"; std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nUpgrade: websocket\r\n\r\n"; - + server s; s.set_user_agent(""); s.set_message_handler(bind(&echo_func,&s,::_1,::_2)); - + BOOST_CHECK_EQUAL(run_server_test(s,input), output); } BOOST_AUTO_TEST_CASE( request_no_server_header_override ) { std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n"; std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: foo\r\nUpgrade: websocket\r\n\r\n"; - + server s; s.set_user_agent(""); s.set_message_handler(bind(&echo_func,&s,::_1,::_2)); s.set_validate_handler(bind(&validate_set_ua,&s,::_1)); - + BOOST_CHECK_EQUAL(run_server_test(s,input), output); } BOOST_AUTO_TEST_CASE( basic_client_websocket ) { std::string uri = "ws://localhost"; - + //std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: foo\r\nUpgrade: websocket\r\n\r\n"; - + std::string ref = "GET / HTTP/1.1\r\nConnection: Upgrade\r\nHost: localhost\r\nSec-WebSocket-Key: AAAAAAAAAAAAAAAAAAAAAA==\r\nSec-WebSocket-Version: 13\r\nUpgrade: websocket\r\nUser-Agent: foo\r\n\r\n"; - + std::stringstream output; - + client e; e.set_access_channels(websocketpp::log::alevel::none); e.set_error_channels(websocketpp::log::elevel::none); e.set_user_agent("foo"); e.register_ostream(&output); - + client::connection_ptr con; websocketpp::lib::error_code ec; con = e.get_connection(uri, ec); e.connect(con); - + BOOST_CHECK_EQUAL(ref, output.str()); } @@ -197,16 +197,16 @@ BOOST_AUTO_TEST_CASE( basic_client_websocket ) { BOOST_AUTO_TEST_CASE( user_reject_origin ) { std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example2.com\r\n\r\n"; std::string output = "HTTP/1.1 403 Forbidden\r\nServer: "+websocketpp::USER_AGENT+"\r\n\r\n"; - + BOOST_CHECK(run_server_test(input) == output); } BOOST_AUTO_TEST_CASE( basic_text_message ) { std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n"; - + unsigned char frames[8] = {0x82,0x82,0xFF,0xFF,0xFF,0xFF,0xD5,0xD5}; input.append(reinterpret_cast(frames),8); - + std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: "+websocketpp::USER_AGENT+"\r\nUpgrade: websocket\r\n\r\n**"; BOOST_CHECK( run_server_test(input) == output); diff --git a/test/connection/connection_tu2.cpp b/test/connection/connection_tu2.cpp index 3046295bd..ee0d6a980 100644 --- a/test/connection/connection_tu2.cpp +++ b/test/connection/connection_tu2.cpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ #include "connection_tu2.hpp" @@ -39,19 +39,19 @@ std::string run_server_test(std::string input) { std::string run_server_test(server & s, std::string input) { server::connection_ptr con; std::stringstream output; - + s.clear_access_channels(websocketpp::log::alevel::all); s.clear_error_channels(websocketpp::log::elevel::all); - + s.register_ostream(&output); - + con = s.get_connection(); con->start(); - + std::stringstream channel; - + channel << input; channel >> *con; - + return output.str(); -} \ No newline at end of file +} diff --git a/test/connection/connection_tu2.hpp b/test/connection/connection_tu2.hpp index f0c7c3803..b4e95216d 100644 --- a/test/connection/connection_tu2.hpp +++ b/test/connection/connection_tu2.hpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ #include @@ -36,7 +36,7 @@ typedef websocketpp::server server; /// NOTE: the "server" config is being used for the client here because we don't -/// want to pull in the real RNG. A better way to do this might be a custom +/// want to pull in the real RNG. A better way to do this might be a custom /// client config with the RNG explicitly stubbed out. typedef websocketpp::client client; typedef websocketpp::config::core::message_type::ptr message_ptr; @@ -47,4 +47,4 @@ using websocketpp::lib::bind; void echo_func(server* s, websocketpp::connection_hdl hdl, message_ptr msg); std::string run_server_test(std::string input); -std::string run_server_test(server & s, std::string input); \ No newline at end of file +std::string run_server_test(server & s, std::string input); diff --git a/test/endpoint/endpoint.cpp b/test/endpoint/endpoint.cpp index a4ed10835..da3c839ca 100644 --- a/test/endpoint/endpoint.cpp +++ b/test/endpoint/endpoint.cpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ //#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE endpoint @@ -59,15 +59,15 @@ BOOST_AUTO_TEST_CASE( initialize_server_asio_external ) { struct endpoint_extension { endpoint_extension() : extension_value(5) {} - + int extension_method() { return extension_value; } - + bool is_server() const { return false; } - + int extension_value; }; @@ -85,17 +85,17 @@ struct stub_config : public websocketpp::config::core { typedef core::elog_type elog_type; typedef core::rng_type rng_type; - + typedef core::transport_type transport_type; - + typedef endpoint_extension endpoint_base; }; BOOST_AUTO_TEST_CASE( endpoint_extensions ) { websocketpp::server s; - + BOOST_CHECK( s.extension_value == 5 ); BOOST_CHECK( s.extension_method() == 5 ); - + BOOST_CHECK( s.is_server() == true ); } diff --git a/test/extension/extension.cpp b/test/extension/extension.cpp index 63f46cf9c..5439c0741 100644 --- a/test/extension/extension.cpp +++ b/test/extension/extension.cpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ //#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE extension diff --git a/test/extension/permessage_deflate.cpp b/test/extension/permessage_deflate.cpp index 67509fd20..60e3c24d5 100644 --- a/test/extension/permessage_deflate.cpp +++ b/test/extension/permessage_deflate.cpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ //#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE permessage_deflate @@ -83,8 +83,8 @@ BOOST_AUTO_TEST_CASE( enabled_starts_disabled ) { BOOST_AUTO_TEST_CASE( negotiation_empty_attr ) { ext_vars v; - - v.esp = v.exts.negotiate(v.attr); + + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate"); @@ -93,8 +93,8 @@ BOOST_AUTO_TEST_CASE( negotiation_empty_attr ) { BOOST_AUTO_TEST_CASE( negotiation_invalid_attr ) { ext_vars v; v.attr["foo"] = "bar"; - - v.esp = v.exts.negotiate(v.attr); + + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( !v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, pmde::make_error_code(pmde::invalid_attributes) ); BOOST_CHECK_EQUAL( v.esp.second, ""); @@ -104,8 +104,8 @@ BOOST_AUTO_TEST_CASE( negotiation_invalid_attr ) { BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover_invalid ) { ext_vars v; v.attr["s2c_no_context_takeover"] = "foo"; - - v.esp = v.exts.negotiate(v.attr); + + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( !v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, pmde::make_error_code(pmde::invalid_attribute_value) ); BOOST_CHECK_EQUAL( v.esp.second, ""); @@ -114,8 +114,8 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover_invalid ) { BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover ) { ext_vars v; v.attr["s2c_no_context_takeover"] = ""; - - v.esp = v.exts.negotiate(v.attr); + + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover"); @@ -123,9 +123,9 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover ) { BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover_server_initiated ) { ext_vars v; - + v.exts.enable_s2c_no_context_takeover(); - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover"); @@ -135,8 +135,8 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover_server_initiated ) { BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover_invalid ) { ext_vars v; v.attr["c2s_no_context_takeover"] = "foo"; - - v.esp = v.exts.negotiate(v.attr); + + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( !v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, pmde::make_error_code(pmde::invalid_attribute_value) ); BOOST_CHECK_EQUAL( v.esp.second, ""); @@ -145,8 +145,8 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover_invalid ) { BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover ) { ext_vars v; v.attr["c2s_no_context_takeover"] = ""; - - v.esp = v.exts.negotiate(v.attr); + + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_no_context_takeover"); @@ -154,9 +154,9 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover ) { BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover_server_initiated ) { ext_vars v; - + v.exts.enable_c2s_no_context_takeover(); - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_no_context_takeover"); @@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover_server_initiated ) { // Negotiate s2c_max_window_bits BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_invalid ) { ext_vars v; - + std::vector values; values.push_back(""); values.push_back("foo"); @@ -176,8 +176,8 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_invalid ) { std::vector::const_iterator it; for (it = values.begin(); it != values.end(); ++it) { v.attr["s2c_max_window_bits"] = *it; - - v.esp = v.exts.negotiate(v.attr); + + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( !v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, pmde::make_error_code(pmde::invalid_attribute_value) ); BOOST_CHECK_EQUAL( v.esp.second, ""); @@ -187,15 +187,15 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_invalid ) { BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_valid ) { ext_vars v; v.attr["s2c_max_window_bits"] = "8"; - - v.esp = v.exts.negotiate(v.attr); + + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_max_window_bits=8"); v.attr["s2c_max_window_bits"] = "15"; - - v.esp = v.exts.negotiate(v.attr); + + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate"); @@ -214,9 +214,9 @@ BOOST_AUTO_TEST_CASE( invalid_set_s2c_max_window_bits ) { BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_decline ) { ext_vars v; v.attr["s2c_max_window_bits"] = "8"; - + v.ec = v.exts.set_s2c_max_window_bits(15,pmd_mode::decline); - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.ec, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); @@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_decline ) { BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_accept ) { ext_vars v; v.attr["s2c_max_window_bits"] = "8"; - + v.ec = v.exts.set_s2c_max_window_bits(15,pmd_mode::accept); v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_accept ) { BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_largest ) { ext_vars v; v.attr["s2c_max_window_bits"] = "8"; - + v.ec = v.exts.set_s2c_max_window_bits(15,pmd_mode::largest); v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); @@ -250,7 +250,7 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_largest ) { BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_smallest ) { ext_vars v; v.attr["s2c_max_window_bits"] = "8"; - + v.ec = v.exts.set_s2c_max_window_bits(15,pmd_mode::smallest); v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); @@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_smallest ) { // Negotiate s2c_max_window_bits BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_invalid ) { ext_vars v; - + std::vector values; values.push_back("foo"); values.push_back("7"); @@ -271,8 +271,8 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_invalid ) { std::vector::const_iterator it; for (it = values.begin(); it != values.end(); ++it) { v.attr["c2s_max_window_bits"] = *it; - - v.esp = v.exts.negotiate(v.attr); + + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( !v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, pmde::make_error_code(pmde::invalid_attribute_value) ); BOOST_CHECK_EQUAL( v.esp.second, ""); @@ -283,19 +283,19 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_valid ) { ext_vars v; v.attr["c2s_max_window_bits"] = ""; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate"); v.attr["c2s_max_window_bits"] = "8"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_max_window_bits=8"); v.attr["c2s_max_window_bits"] = "15"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate"); @@ -314,9 +314,9 @@ BOOST_AUTO_TEST_CASE( invalid_set_c2s_max_window_bits ) { BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_decline ) { ext_vars v; v.attr["c2s_max_window_bits"] = "8"; - + v.ec = v.exts.set_c2s_max_window_bits(8,pmd_mode::decline); - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.ec, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); @@ -326,7 +326,7 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_decline ) { BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_accept ) { ext_vars v; v.attr["c2s_max_window_bits"] = "8"; - + v.ec = v.exts.set_c2s_max_window_bits(15,pmd_mode::accept); v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); @@ -338,7 +338,7 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_accept ) { BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_largest ) { ext_vars v; v.attr["c2s_max_window_bits"] = "8"; - + v.ec = v.exts.set_c2s_max_window_bits(15,pmd_mode::largest); v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); @@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_largest ) { BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_smallest ) { ext_vars v; v.attr["c2s_max_window_bits"] = "8"; - + v.ec = v.exts.set_c2s_max_window_bits(15,pmd_mode::smallest); v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); @@ -363,11 +363,11 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_smallest ) { // Combinations with 2 BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated1 ) { ext_vars v; - + v.attr["s2c_no_context_takeover"] = ""; v.attr["c2s_no_context_takeover"] = ""; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; c2s_no_context_takeover"); @@ -375,11 +375,11 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated1 ) { BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated2 ) { ext_vars v; - + v.attr["s2c_no_context_takeover"] = ""; v.attr["s2c_max_window_bits"] = "10"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; s2c_max_window_bits=10"); @@ -387,11 +387,11 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated2 ) { BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated3 ) { ext_vars v; - + v.attr["s2c_no_context_takeover"] = ""; v.attr["c2s_max_window_bits"] = "10"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; c2s_max_window_bits=10"); @@ -399,11 +399,11 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated3 ) { BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated4 ) { ext_vars v; - + v.attr["c2s_no_context_takeover"] = ""; v.attr["s2c_max_window_bits"] = "10"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_no_context_takeover; s2c_max_window_bits=10"); @@ -411,11 +411,11 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated4 ) { BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated5 ) { ext_vars v; - + v.attr["c2s_no_context_takeover"] = ""; v.attr["c2s_max_window_bits"] = "10"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_no_context_takeover; c2s_max_window_bits=10"); @@ -423,11 +423,11 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated5 ) { BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated6 ) { ext_vars v; - + v.attr["s2c_max_window_bits"] = "10"; v.attr["c2s_max_window_bits"] = "10"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_max_window_bits=10; c2s_max_window_bits=10"); @@ -435,12 +435,12 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated6 ) { BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated1 ) { ext_vars v; - + v.attr["s2c_no_context_takeover"] = ""; v.attr["c2s_no_context_takeover"] = ""; v.attr["s2c_max_window_bits"] = "10"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; c2s_no_context_takeover; s2c_max_window_bits=10"); @@ -448,12 +448,12 @@ BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated1 ) { BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated2 ) { ext_vars v; - + v.attr["s2c_no_context_takeover"] = ""; v.attr["c2s_no_context_takeover"] = ""; v.attr["c2s_max_window_bits"] = "10"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; c2s_no_context_takeover; c2s_max_window_bits=10"); @@ -461,12 +461,12 @@ BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated2 ) { BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated3 ) { ext_vars v; - + v.attr["s2c_no_context_takeover"] = ""; v.attr["s2c_max_window_bits"] = "10"; v.attr["c2s_max_window_bits"] = "10"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; s2c_max_window_bits=10; c2s_max_window_bits=10"); @@ -474,12 +474,12 @@ BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated3 ) { BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated4 ) { ext_vars v; - + v.attr["c2s_no_context_takeover"] = ""; v.attr["s2c_max_window_bits"] = "10"; v.attr["c2s_max_window_bits"] = "10"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_no_context_takeover; s2c_max_window_bits=10; c2s_max_window_bits=10"); @@ -487,13 +487,13 @@ BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated4 ) { BOOST_AUTO_TEST_CASE( negotiate_four_client_initiated ) { ext_vars v; - + v.attr["s2c_no_context_takeover"] = ""; v.attr["c2s_no_context_takeover"] = ""; v.attr["s2c_max_window_bits"] = "10"; v.attr["c2s_max_window_bits"] = "10"; - v.esp = v.exts.negotiate(v.attr); + v.esp = v.exts.negotiate(v.attr); BOOST_CHECK( v.exts.is_enabled() ); BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() ); BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; c2s_no_context_takeover; s2c_max_window_bits=10; c2s_max_window_bits=10"); @@ -503,16 +503,16 @@ BOOST_AUTO_TEST_CASE( negotiate_four_client_initiated ) { /* BOOST_AUTO_TEST_CASE( compress_data ) { ext_vars v; - + std::string in = "Hello"; std::string out; std::string in2; std::string out2; - + v.exts.init(); v.ec = v.exts.compress(in,out); - + std::cout << "in : " << websocketpp::utility::to_hex(in) << std::endl; BOOST_CHECK_EQUAL( v.ec, websocketpp::lib::error_code() ); std::cout << "out: " << websocketpp::utility::to_hex(out) << std::endl; @@ -520,7 +520,7 @@ BOOST_AUTO_TEST_CASE( compress_data ) { in2 = out; v.ec = v.exts.decompress(reinterpret_cast(in2.data()),in2.size(),out2); - + BOOST_CHECK_EQUAL( v.ec, websocketpp::lib::error_code() ); std::cout << "out: " << websocketpp::utility::to_hex(out2) << std::endl; BOOST_CHECK_EQUAL( out, out2 ); @@ -528,16 +528,16 @@ BOOST_AUTO_TEST_CASE( compress_data ) { BOOST_AUTO_TEST_CASE( decompress_data ) { ext_vars v; - + uint8_t in[12] = {0xf2, 0x48, 0xcd, 0xc9, 0xc9, 0x07, 0x00, 0x00, 0x00, 0xff, 0xff}; std::string out; - + v.exts.init(); v.ec = v.exts.decompress(in,12,out); - + BOOST_CHECK_EQUAL( v.ec, websocketpp::lib::error_code() ); std::cout << "out: " << websocketpp::utility::to_hex(out) << std::endl; BOOST_CHECK( false ); } -*/ \ No newline at end of file +*/ diff --git a/test/http/parser.cpp b/test/http/parser.cpp index 57a1de6fc..19a4909e7 100644 --- a/test/http/parser.cpp +++ b/test/http/parser.cpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ //#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE http_parser @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE( is_token_char ) { // Valid characters - + // misc BOOST_CHECK( websocketpp::http::is_token_char('!') ); BOOST_CHECK( websocketpp::http::is_token_char('#') ); @@ -51,29 +51,29 @@ BOOST_AUTO_TEST_CASE( is_token_char ) { BOOST_CHECK( websocketpp::http::is_token_char('_') ); BOOST_CHECK( websocketpp::http::is_token_char('`') ); BOOST_CHECK( websocketpp::http::is_token_char('~') ); - + // numbers for (int i = 0x30; i < 0x3a; i++) { BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) ); } - + // upper for (int i = 0x41; i < 0x5b; i++) { BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) ); } - + // lower for (int i = 0x61; i < 0x7b; i++) { BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) ); } - + // invalid characters - + // lower unprintable for (int i = 0; i < 33; i++) { BOOST_CHECK( !websocketpp::http::is_token_char((unsigned char)(i)) ); } - + // misc BOOST_CHECK( !websocketpp::http::is_token_char('(') ); BOOST_CHECK( !websocketpp::http::is_token_char(')') ); @@ -92,12 +92,12 @@ BOOST_AUTO_TEST_CASE( is_token_char ) { BOOST_CHECK( !websocketpp::http::is_token_char('=') ); BOOST_CHECK( !websocketpp::http::is_token_char('{') ); BOOST_CHECK( !websocketpp::http::is_token_char('}') ); - + // upper unprintable and out of ascii range for (int i = 127; i < 256; i++) { BOOST_CHECK( !websocketpp::http::is_token_char((unsigned char)(i)) ); } - + // is not BOOST_CHECK( !websocketpp::http::is_not_token_char('!') ); BOOST_CHECK( websocketpp::http::is_not_token_char('(') ); @@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE( extract_quoted_string ) { std::string d5 = "foo"; std::pair ret; - + using websocketpp::http::parser::extract_quoted_string; ret = extract_quoted_string(d1.begin(),d1.end()); @@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE( extract_all_lws ) { std::string d1 = " foo bar"; d1.append(1,char(9)); d1.append("baz\r\n d\r\n \r\n e\r\nf"); - + std::string::const_iterator ret; ret = websocketpp::http::parser::extract_all_lws(d1.begin(),d1.end()); @@ -227,33 +227,33 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) { websocketpp::http::parameter_list p; websocketpp::http::attribute_list a; std::string::const_iterator it; - + using websocketpp::http::parser::extract_parameters; it = extract_parameters(s1.begin(),s1.end(),p); BOOST_CHECK( it == s1.begin() ); - + p.clear(); it = extract_parameters(s2.begin(),s2.end(),p); BOOST_CHECK( it == s2.end() ); BOOST_CHECK_EQUAL( p.size(), 1 ); BOOST_CHECK( p[0].first == "foo" ); BOOST_CHECK_EQUAL( p[0].second.size(), 0 ); - + p.clear(); it = extract_parameters(s3.begin(),s3.end(),p); BOOST_CHECK( it == s3.begin()+5 ); BOOST_CHECK_EQUAL( p.size(), 1 ); BOOST_CHECK( p[0].first == "foo" ); BOOST_CHECK_EQUAL( p[0].second.size(), 0 ); - + p.clear(); it = extract_parameters(s4.begin(),s4.end(),p); BOOST_CHECK( it == s4.end() ); BOOST_CHECK_EQUAL( p.size(), 1 ); BOOST_CHECK( p[0].first == "foo" ); BOOST_CHECK_EQUAL( p[0].second.size(), 0 ); - + p.clear(); it = extract_parameters(s5.begin(),s5.end(),p); BOOST_CHECK( it == s5.end() ); @@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) { BOOST_CHECK_EQUAL( p[0].second.size(), 0 ); BOOST_CHECK( p[1].first == "bar" ); BOOST_CHECK_EQUAL( p[1].second.size(), 0 ); - + p.clear(); it = extract_parameters(s6.begin(),s6.end(),p); BOOST_CHECK( it == s6.end() ); @@ -272,7 +272,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) { BOOST_CHECK_EQUAL( a.size(), 1 ); BOOST_CHECK( a.find("bar") != a.end() ); BOOST_CHECK_EQUAL( a.find("bar")->second, "" ); - + p.clear(); it = extract_parameters(s7.begin(),s7.end(),p); BOOST_CHECK( it == s7.end() ); @@ -285,7 +285,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) { BOOST_CHECK( p[1].first == "bar" ); a = p[1].second; BOOST_CHECK_EQUAL( a.size(), 0 ); - + p.clear(); it = extract_parameters(s8.begin(),s8.end(),p); BOOST_CHECK( it == s8.end() ); @@ -297,7 +297,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) { BOOST_CHECK_EQUAL( a.find("bar")->second, "" ); BOOST_CHECK( a.find("baz") != a.end() ); BOOST_CHECK_EQUAL( a.find("baz")->second, "" ); - + p.clear(); it = extract_parameters(s9.begin(),s9.end(),p); BOOST_CHECK( it == s9.end() ); @@ -307,7 +307,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) { BOOST_CHECK_EQUAL( a.size(), 1 ); BOOST_CHECK( a.find("bar") != a.end() ); BOOST_CHECK_EQUAL( a.find("bar")->second, "baz" ); - + p.clear(); it = extract_parameters(s10.begin(),s10.end(),p); BOOST_CHECK( it == s10.end() ); @@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) { BOOST_CHECK_EQUAL( a.find("bar")->second, "baz" ); BOOST_CHECK( a.find("boo") != a.end() ); BOOST_CHECK_EQUAL( a.find("boo")->second, "" ); - + p.clear(); it = extract_parameters(s11.begin(),s11.end(),p); BOOST_CHECK( it == s11.end() ); @@ -333,7 +333,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) { BOOST_CHECK_EQUAL( a.find("boo")->second, "" ); a = p[1].second; BOOST_CHECK_EQUAL( a.size(), 0 ); - + p.clear(); it = extract_parameters(s12.begin(),s12.end(),p); BOOST_CHECK( it == s12.end() ); @@ -343,7 +343,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) { BOOST_CHECK_EQUAL( a.size(), 1 ); BOOST_CHECK( a.find("bar") != a.end() ); BOOST_CHECK_EQUAL( a.find("bar")->second, "a b c" ); - + p.clear(); it = extract_parameters(s13.begin(),s13.end(),p); BOOST_CHECK( it == s13.end() ); @@ -357,7 +357,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) { BOOST_AUTO_TEST_CASE( case_insensitive_headers ) { websocketpp::http::parser::parser r; - + r.replace_header("foo","bar"); BOOST_CHECK_EQUAL( r.get_header("foo"), "bar" ); @@ -367,89 +367,89 @@ BOOST_AUTO_TEST_CASE( case_insensitive_headers ) { BOOST_AUTO_TEST_CASE( case_insensitive_headers_overwrite ) { websocketpp::http::parser::parser r; - + r.replace_header("foo","bar"); BOOST_CHECK_EQUAL( r.get_header("foo"), "bar" ); BOOST_CHECK_EQUAL( r.get_header("Foo"), "bar" ); - + r.replace_header("Foo","baz"); - + BOOST_CHECK_EQUAL( r.get_header("foo"), "baz" ); BOOST_CHECK_EQUAL( r.get_header("Foo"), "baz" ); - + r.remove_header("FoO"); - + BOOST_CHECK_EQUAL( r.get_header("foo"), "" ); BOOST_CHECK_EQUAL( r.get_header("Foo"), "" ); } BOOST_AUTO_TEST_CASE( blank_consume ) { websocketpp::http::parser::request r; - + std::string raw = ""; - + bool exception = false; - + try { r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( r.ready() == false ); } BOOST_AUTO_TEST_CASE( blank_request ) { websocketpp::http::parser::request r; - + std::string raw = "\r\n\r\n"; - + bool exception = false; - + try { r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == true ); BOOST_CHECK( r.ready() == false ); } BOOST_AUTO_TEST_CASE( bad_request_no_host ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\n\r\n"; - + bool exception = false; - + try { r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == true ); BOOST_CHECK( r.ready() == false ); } BOOST_AUTO_TEST_CASE( basic_request ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; - + bool exception = false; size_t pos = 0; - + try { pos = r.consume(raw.c_str(),raw.size()); } catch (std::exception &e) { exception = true; std::cout << e.what() << std::endl; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 41 ); BOOST_CHECK( r.ready() == true ); @@ -461,18 +461,18 @@ BOOST_AUTO_TEST_CASE( basic_request ) { BOOST_AUTO_TEST_CASE( trailing_body_characters ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\na"; - + bool exception = false; size_t pos = 0; - + try { pos = r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 41 ); BOOST_CHECK( r.ready() == true ); @@ -484,13 +484,13 @@ BOOST_AUTO_TEST_CASE( trailing_body_characters ) { BOOST_AUTO_TEST_CASE( basic_split1 ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\n"; std::string raw2 = "Host: www.example.com\r\n\r\na"; - + bool exception = false; size_t pos = 0; - + try { pos += r.consume(raw.c_str(),raw.size()); pos += r.consume(raw2.c_str(),raw2.size()); @@ -498,7 +498,7 @@ BOOST_AUTO_TEST_CASE( basic_split1 ) { exception = true; std::cout << e.what() << std::endl; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 41 ); BOOST_CHECK( r.ready() == true ); @@ -510,13 +510,13 @@ BOOST_AUTO_TEST_CASE( basic_split1 ) { BOOST_AUTO_TEST_CASE( basic_split2 ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r"; std::string raw2 = "\n\r\na"; - + bool exception = false; size_t pos = 0; - + try { pos += r.consume(raw.c_str(),raw.size()); pos += r.consume(raw2.c_str(),raw2.size()); @@ -524,7 +524,7 @@ BOOST_AUTO_TEST_CASE( basic_split2 ) { exception = true; std::cout << e.what() << std::endl; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 41 ); BOOST_CHECK( r.ready() == true ); @@ -536,12 +536,12 @@ BOOST_AUTO_TEST_CASE( basic_split2 ) { BOOST_AUTO_TEST_CASE( max_header_len ) { websocketpp::http::parser::request r; - + std::string raw(websocketpp::http::max_header_size+1,'*'); - + bool exception = false; size_t pos = 0; - + try { pos += r.consume(raw.c_str(),raw.size()); } catch (const websocketpp::http::exception& e) { @@ -549,19 +549,19 @@ BOOST_AUTO_TEST_CASE( max_header_len ) { exception = true; } } - + BOOST_CHECK( exception == true ); } BOOST_AUTO_TEST_CASE( max_header_len_split ) { websocketpp::http::parser::request r; - + std::string raw(websocketpp::http::max_header_size-1,'*'); std::string raw2(2,'*'); - + bool exception = false; size_t pos = 0; - + try { pos += r.consume(raw.c_str(),raw.size()); pos += r.consume(raw2.c_str(),raw2.size()); @@ -570,24 +570,24 @@ BOOST_AUTO_TEST_CASE( max_header_len_split ) { exception = true; } } - + BOOST_CHECK( exception == true ); } BOOST_AUTO_TEST_CASE( firefox_full_request ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n"; - + bool exception = false; size_t pos = 0; - + try { pos += r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 482 ); BOOST_CHECK( r.ready() == true ); @@ -610,50 +610,50 @@ BOOST_AUTO_TEST_CASE( firefox_full_request ) { BOOST_AUTO_TEST_CASE( bad_method ) { websocketpp::http::parser::request r; - + std::string raw = "GE]T / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; - + bool exception = false; - + try { r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == true ); } BOOST_AUTO_TEST_CASE( bad_header_name ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\nHo]st: www.example.com\r\n\r\n"; - + bool exception = false; - + try { r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == true ); } BOOST_AUTO_TEST_CASE( old_http_version ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n"; - + bool exception = false; size_t pos = 0; - + try { pos = r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 41 ); BOOST_CHECK( r.ready() == true ); @@ -665,18 +665,18 @@ BOOST_AUTO_TEST_CASE( old_http_version ) { BOOST_AUTO_TEST_CASE( new_http_version1 ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.12\r\nHost: www.example.com\r\n\r\n"; - + bool exception = false; size_t pos = 0; - + try { pos = r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 42 ); BOOST_CHECK( r.ready() == true ); @@ -688,18 +688,18 @@ BOOST_AUTO_TEST_CASE( new_http_version1 ) { BOOST_AUTO_TEST_CASE( new_http_version2 ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/12.12\r\nHost: www.example.com\r\n\r\n"; - + bool exception = false; size_t pos = 0; - + try { pos = r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 43 ); BOOST_CHECK( r.ready() == true ); @@ -713,35 +713,35 @@ BOOST_AUTO_TEST_CASE( new_http_version2 ) { BOOST_AUTO_TEST_CASE( new_http_version3 ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTPS/12.12\r\nHost: www.example.com\r\n\r\n"; - + bool exception = false; size_t pos = 0; - + try { pos = r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == true ); } BOOST_AUTO_TEST_CASE( header_whitespace1 ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com \r\n\r\n"; - + bool exception = false; size_t pos = 0; - + try { pos = r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 43 ); BOOST_CHECK( r.ready() == true ); @@ -753,18 +753,18 @@ BOOST_AUTO_TEST_CASE( header_whitespace1 ) { BOOST_AUTO_TEST_CASE( header_whitespace2 ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\nHost:www.example.com\r\n\r\n"; - + bool exception = false; size_t pos = 0; - + try { pos = r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 40 ); BOOST_CHECK( r.ready() == true ); @@ -776,18 +776,18 @@ BOOST_AUTO_TEST_CASE( header_whitespace2 ) { BOOST_AUTO_TEST_CASE( header_aggregation ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r\nFoo: bar\r\nFoo: bat\r\n\r\n"; - + bool exception = false; size_t pos = 0; - + try { pos = r.consume(raw.c_str(),raw.size()); } catch (...) { exception = true; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 61 ); BOOST_CHECK( r.ready() == true ); @@ -799,19 +799,19 @@ BOOST_AUTO_TEST_CASE( header_aggregation ) { BOOST_AUTO_TEST_CASE( wikipedia_example_response ) { websocketpp::http::parser::response r; - + std::string raw = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=\r\nSec-WebSocket-Protocol: chat\r\n\r\n"; - + bool exception = false; size_t pos = 0; - + try { pos += r.consume(raw.c_str(),raw.size()); } catch (std::exception &e) { exception = true; std::cout << e.what() << std::endl; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 159 ); BOOST_CHECK( r.headers_ready() == true ); @@ -826,19 +826,19 @@ BOOST_AUTO_TEST_CASE( wikipedia_example_response ) { BOOST_AUTO_TEST_CASE( plain_http_response ) { websocketpp::http::parser::response r; - + std::string raw = "HTTP/1.1 200 OK\r\nDate: Thu, 10 May 2012 11:59:25 GMT\r\nServer: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.8 with Suhosin-Patch\r\nLast-Modified: Tue, 30 Mar 2010 17:41:28 GMT\r\nETag: \"16799d-55-4830823a78200\"\r\nAccept-Ranges: bytes\r\nContent-Length: 85\r\nVary: Accept-Encoding\r\nContent-Type: text/html\r\n\r\n\n\n\nThor\n\n \n

Thor

\n"; - + bool exception = false; size_t pos = 0; - + try { pos += r.consume(raw.c_str(),raw.size()); } catch (std::exception &e) { exception = true; std::cout << e.what() << std::endl; } - + BOOST_CHECK( exception == false ); BOOST_CHECK( pos == 405 ); BOOST_CHECK( r.headers_ready() == true ); @@ -859,21 +859,21 @@ BOOST_AUTO_TEST_CASE( plain_http_response ) { BOOST_AUTO_TEST_CASE( parse_istream ) { websocketpp::http::parser::response r; - + std::stringstream s; - + s << "HTTP/1.1 200 OK\r\nDate: Thu, 10 May 2012 11:59:25 GMT\r\nServer: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.8 with Suhosin-Patch\r\nLast-Modified: Tue, 30 Mar 2010 17:41:28 GMT\r\nETag: \"16799d-55-4830823a78200\"\r\nAccept-Ranges: bytes\r\nContent-Length: 85\r\nVary: Accept-Encoding\r\nContent-Type: text/html\r\n\r\n\n\n\nThor\n\n \n

Thor

\n"; - + bool exception = false; size_t pos = 0; - + try { pos += r.consume(s); } catch (std::exception &e) { exception = true; std::cout << e.what() << std::endl; } - + BOOST_CHECK_EQUAL( exception, false ); BOOST_CHECK_EQUAL( pos, 405 ); BOOST_CHECK_EQUAL( r.headers_ready(), true ); @@ -882,40 +882,40 @@ BOOST_AUTO_TEST_CASE( parse_istream ) { BOOST_AUTO_TEST_CASE( write_request_basic ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\n\r\n"; - + r.set_version("HTTP/1.1"); r.set_method("GET"); r.set_uri("/"); - + BOOST_CHECK( r.raw() == raw ); } BOOST_AUTO_TEST_CASE( write_request_with_header ) { websocketpp::http::parser::request r; - + std::string raw = "GET / HTTP/1.1\r\nHost: http://example.com\r\n\r\n"; - + r.set_version("HTTP/1.1"); r.set_method("GET"); r.set_uri("/"); r.replace_header("Host","http://example.com"); - + BOOST_CHECK( r.raw() == raw ); } BOOST_AUTO_TEST_CASE( write_request_with_body ) { websocketpp::http::parser::request r; - + std::string raw = "POST / HTTP/1.1\r\nContent-Length: 48\r\nContent-Type: application/x-www-form-urlencoded\r\nHost: http://example.com\r\n\r\nlicenseID=string&content=string¶msXML=string"; - + r.set_version("HTTP/1.1"); r.set_method("POST"); r.set_uri("/"); r.replace_header("Host","http://example.com"); r.replace_header("Content-Type","application/x-www-form-urlencoded"); r.set_body("licenseID=string&content=string¶msXML=string"); - + BOOST_CHECK( r.raw() == raw ); } diff --git a/test/http/parser_perf.cpp b/test/http/parser_perf.cpp index fe3ed1a1e..9e3d2b5c8 100644 --- a/test/http/parser_perf.cpp +++ b/test/http/parser_perf.cpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ #include @@ -36,18 +36,18 @@ class scoped_timer { } ~scoped_timer() { std::chrono::nanoseconds time_taken = std::chrono::steady_clock::now()-m_start; - + //nanoseconds_per_test - + //tests_per_second - + //1000000000.0/(double(time_taken.count())/1000.0) - + std::cout << 1000000000.0/(double(time_taken.count())/1000.0) << std::endl; - + //std::cout << (1.0/double(time_taken.count())) * double(1000000000*1000) << std::endl; } - + private: std::string m_id; std::chrono::steady_clock::time_point m_start; @@ -55,87 +55,87 @@ class scoped_timer { int main() { std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; - + std::string firefox = "GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n"; - + std::string firefox1 = "GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\n"; - + std::string firefox2 = "Accept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n"; - - { + + { scoped_timer timer("Simplest 1 chop"); for (int i = 0; i < 1000; i++) { websocketpp::http::parser::request r; - + try { r.consume(raw.c_str(),raw.size()); } catch (...) { std::cout << "exception" << std::endl; } - + if (!r.ready()) { std::cout << "error" << std::endl; break; } } } - - { + + { scoped_timer timer("FireFox, 1 chop, consume old"); for (int i = 0; i < 1000; i++) { websocketpp::http::parser::request r; - + try { r.consume2(firefox.c_str(),firefox.size()); } catch (...) { std::cout << "exception" << std::endl; } - + if (!r.ready()) { std::cout << "error" << std::endl; break; } } } - - { + + { scoped_timer timer("FireFox, 1 chop"); for (int i = 0; i < 1000; i++) { websocketpp::http::parser::request r; - + try { r.consume(firefox.c_str(),firefox.size()); } catch (...) { std::cout << "exception" << std::endl; } - + if (!r.ready()) { std::cout << "error" << std::endl; break; } } } - - - - { + + + + { scoped_timer timer("FireFox, 2 chop"); for (int i = 0; i < 1000; i++) { websocketpp::http::parser::request r; - + try { r.consume(firefox1.c_str(),firefox1.size()); r.consume(firefox2.c_str(),firefox2.size()); } catch (...) { std::cout << "exception" << std::endl; } - + if (!r.ready()) { std::cout << "error" << std::endl; break; } } } - + return 0; } diff --git a/test/logger/basic.cpp b/test/logger/basic.cpp index ef18ab97d..f955967a2 100644 --- a/test/logger/basic.cpp +++ b/test/logger/basic.cpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ //#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE basic_log @@ -36,16 +36,16 @@ BOOST_AUTO_TEST_CASE( is_token_char ) { typedef websocketpp::log::basic error_log; - + error_log elog; - + BOOST_CHECK( elog.static_test(websocketpp::log::elevel::info ) == true ); BOOST_CHECK( elog.static_test(websocketpp::log::elevel::warn ) == true ); BOOST_CHECK( elog.static_test(websocketpp::log::elevel::rerror ) == true ); BOOST_CHECK( elog.static_test(websocketpp::log::elevel::fatal ) == true ); - + elog.set_channels(websocketpp::log::elevel::info); - + elog.write(websocketpp::log::elevel::info,"Information"); elog.write(websocketpp::log::elevel::warn,"A warning"); elog.write(websocketpp::log::elevel::rerror,"A error"); @@ -54,13 +54,13 @@ BOOST_AUTO_TEST_CASE( is_token_char ) { BOOST_AUTO_TEST_CASE( access_clear ) { typedef websocketpp::log::basic access_log; - + std::stringstream out; access_log logger(0xffffffff,&out); - + // clear all channels logger.clear_channels(0xffffffff); - + // writes shouldn't happen logger.write(websocketpp::log::alevel::devel,"devel"); //std::cout << "|" << out.str() << "|" << std::endl; @@ -69,13 +69,13 @@ BOOST_AUTO_TEST_CASE( access_clear ) { BOOST_AUTO_TEST_CASE( basic_concurrency ) { typedef websocketpp::log::basic access_log; - + std::stringstream out; access_log logger(0xffffffff,&out); - + logger.set_channels(0xffffffff); - + logger.write(websocketpp::log::alevel::devel,"devel"); //std::cout << "|" << out.str() << "|" << std::endl; BOOST_CHECK( out.str().size() > 0 ); -} \ No newline at end of file +} diff --git a/test/message_buffer/alloc.cpp b/test/message_buffer/alloc.cpp index c5ead8d64..2a0dc3203 100644 --- a/test/message_buffer/alloc.cpp +++ b/test/message_buffer/alloc.cpp @@ -11,10 +11,10 @@ * * Neither the name of the WebSocket++ Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; @@ -22,7 +22,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * */ //#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE message_buffer_alloc @@ -36,7 +36,7 @@ template