From afd5646ca52123de48fee949f2745eb8d0e2755c Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 28 Mar 2013 22:58:54 -0500 Subject: [PATCH] adds more client functionality and associated tests --- test/roles/SConscript | 2 +- test/roles/client.cpp | 20 +++++++++++++- websocketpp/roles/client_endpoint.hpp | 39 ++++++++++++++++----------- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/test/roles/SConscript b/test/roles/SConscript index 0eef4bbacd..189675cf01 100644 --- a/test/roles/SConscript +++ b/test/roles/SConscript @@ -10,7 +10,7 @@ Import('polyfill_libs') env = env.Clone () env_cpp11 = env_cpp11.Clone () -BOOST_LIBS = boostlibs(['unit_test_framework','system'],env) + [platform_libs] +BOOST_LIBS = boostlibs(['unit_test_framework','system','regex'],env) + [platform_libs] objs = env.Object('client_boost.o', ["client.cpp"], LIBS = BOOST_LIBS) objs += env.Object('server_boost.o', ["server.cpp"], LIBS = BOOST_LIBS) diff --git a/test/roles/client.cpp b/test/roles/client.cpp index 0b0f385fde..369c7661d0 100644 --- a/test/roles/client.cpp +++ b/test/roles/client.cpp @@ -56,7 +56,7 @@ struct stub_config : public websocketpp::config::core { typedef websocketpp::client client; typedef client::connection_ptr connection_ptr; -BOOST_AUTO_TEST_CASE( get_connection ) { +BOOST_AUTO_TEST_CASE( invalid_uri ) { client c; websocketpp::lib::error_code ec; @@ -64,3 +64,21 @@ BOOST_AUTO_TEST_CASE( get_connection ) { BOOST_CHECK( ec == websocketpp::error::make_error_code(websocketpp::error::invalid_uri) ); } + +BOOST_AUTO_TEST_CASE( unsecure_endpoint ) { + client c; + websocketpp::lib::error_code ec; + + connection_ptr con = c.get_connection("wss://localhost/", ec); + + BOOST_CHECK( ec == websocketpp::error::make_error_code(websocketpp::error::endpoint_not_secure) ); +} + +BOOST_AUTO_TEST_CASE( get_connection ) { + client c; + websocketpp::lib::error_code ec; + + connection_ptr con = c.get_connection("ws://localhost/", ec); + + BOOST_CHECK( con ); +} \ No newline at end of file diff --git a/websocketpp/roles/client_endpoint.hpp b/websocketpp/roles/client_endpoint.hpp index 224bead1d1..38abb429e5 100644 --- a/websocketpp/roles/client_endpoint.hpp +++ b/websocketpp/roles/client_endpoint.hpp @@ -82,24 +82,29 @@ public: connection_ptr get_connection(const std::string& u, lib::error_code &ec) { // parse uri try { + // uri validation + uri_ptr location(new uri(u)); + if (location->get_secure() && !transport_type::is_secure()) { + ec = error::make_error_code(error::endpoint_not_secure); + return connection_ptr(); + } + + // create connection + connection_ptr con = endpoint_type::create_connection(); + + if (!con) { + ec = error::make_error_code(error::con_creation_failed); + return con; + } + + // Success + ec = lib::error_code(); + return con; } catch (uri_exception) { - + ec = error::make_error_code(error::invalid_uri); + return connection_ptr(); } - - // uri validation - - // create connection - connection_ptr con = endpoint_type::create_connection(); - - if (!con) { - ec = error::make_error_code(error::con_creation_failed); - return con; - } - - // Success - ec = lib::error_code(); - return con; } /// Begin the connection process for the given connection @@ -120,6 +125,10 @@ public: // connect(...) private: // handle_connect + void handle_connect(connection_ptr con, const lib::error_code & ec) { + // start connection if successful + // set failure information if not and call con->terminate + } }; } // namespace websocketpp