From 62a97aad6ba26f4fb084b2f3fefa2083db785034 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 27 Oct 2011 17:26:37 -0500 Subject: [PATCH] starts work on program options --- src/websocket_frame.hpp | 7 ++ src/websocket_server.cpp | 16 +++- src/websocket_server.hpp | 111 ++++++++++++++------------ websocketpp.xcodeproj/project.pbxproj | 4 + 4 files changed, 85 insertions(+), 53 deletions(-) diff --git a/src/websocket_frame.hpp b/src/websocket_frame.hpp index ab74ef76b6..9c719f38b2 100644 --- a/src/websocket_frame.hpp +++ b/src/websocket_frame.hpp @@ -39,6 +39,13 @@ namespace websocketpp { +/* policies to abstract out + + - random number generation + - utf8 validation + + */ + class frame { public: enum opcode_s { diff --git a/src/websocket_server.cpp b/src/websocket_server.cpp index a3fbdc56c6..c0040e9031 100644 --- a/src/websocket_server.cpp +++ b/src/websocket_server.cpp @@ -30,6 +30,8 @@ #include #include +#include + #include using websocketpp::server; @@ -42,7 +44,19 @@ server::server(boost::asio::io_service& io_service, m_max_message_size(DEFAULT_MAX_MESSAGE_SIZE), m_io_service(io_service), m_acceptor(io_service, endpoint), - m_def_con_handler(defc) {} + m_def_con_handler(defc), + m_desc("test") { + m_desc.add_options() + ("help", "produce help message") + ("intval",po::value(), "set compression level") + ; + +} + +void server::parse_command_line(int ac, char* av[]) { + po::store(po::parse_command_line(ac,av, m_desc),m_vm); + po::notify(m_vm); +} void server::add_host(std::string host) { m_hosts.insert(host); diff --git a/src/websocket_server.hpp b/src/websocket_server.hpp index d294c13505..dc9b4f03cb 100644 --- a/src/websocket_server.hpp +++ b/src/websocket_server.hpp @@ -30,6 +30,8 @@ #include #include +#include +namespace po = boost::program_options; #include @@ -60,61 +62,66 @@ private: }; class server : public boost::enable_shared_from_this { - public: - server(boost::asio::io_service& io_service, - const tcp::endpoint& endpoint, - connection_handler_ptr defc); - - // creates a new session object and connects the next websocket - // connection to it. - void start_accept(); - - // INTERFACE FOR LOCAL APPLICATIONS +public: + server(boost::asio::io_service& io_service, + const tcp::endpoint& endpoint, + connection_handler_ptr defc); + + // creates a new session object and connects the next websocket + // connection to it. + void start_accept(); + + // INTERFACE FOR LOCAL APPLICATIONS - // Add or remove a host string (host:port) to the list of acceptable - // hosts to accept websocket connections from. Additions/deletions here - // only affect new connections. - void add_host(std::string host); - void remove_host(std::string host); - - void set_max_message_size(uint64_t val); - - // Test methods determine if a message of the given level should be - // written. elog shows all values above the level set. alog shows only - // the values explicitly set. - bool test_elog_level(uint16_t level); - void set_elog_level(uint16_t level); - - bool test_alog_level(uint16_t level); - void set_alog_level(uint16_t level); - void unset_alog_level(uint16_t level); + // Add or remove a host string (host:port) to the list of acceptable + // hosts to accept websocket connections from. Additions/deletions here + // only affect new connections. + void add_host(std::string host); + void remove_host(std::string host); + + void set_max_message_size(uint64_t val); + + // Test methods determine if a message of the given level should be + // written. elog shows all values above the level set. alog shows only + // the values explicitly set. + bool test_elog_level(uint16_t level); + void set_elog_level(uint16_t level); + + bool test_alog_level(uint16_t level); + void set_alog_level(uint16_t level); + void unset_alog_level(uint16_t level); + + void parse_command_line(int ac, char* av[]); + + // INTERFACE FOR SESSIONS - // INTERFACE FOR SESSIONS + // Check if this server will respond to this host. + bool validate_host(std::string host); + + // Check if message size is within server's acceptable parameters + bool validate_message_size(uint64_t val); + + // write to the server's logs + void log(std::string msg,uint16_t level = LOG_ERROR); + void access_log(std::string msg,uint16_t level); +private: + // if no errors starts the session's read loop and returns to the + // start_accept phase. + void handle_accept(server_session_ptr session, + const boost::system::error_code& error); + +private: + uint16_t m_elog_level; + uint16_t m_alog_level; - // Check if this server will respond to this host. - bool validate_host(std::string host); - - // Check if message size is within server's acceptable parameters - bool validate_message_size(uint64_t val); - - // write to the server's logs - void log(std::string msg,uint16_t level = LOG_ERROR); - void access_log(std::string msg,uint16_t level); - private: - // if no errors starts the session's read loop and returns to the - // start_accept phase. - void handle_accept(server_session_ptr session, - const boost::system::error_code& error); - - private: - uint16_t m_elog_level; - uint16_t m_alog_level; - - std::set m_hosts; - uint64_t m_max_message_size; - boost::asio::io_service& m_io_service; - tcp::acceptor m_acceptor; - connection_handler_ptr m_def_con_handler; + std::set m_hosts; + uint64_t m_max_message_size; + boost::asio::io_service& m_io_service; + tcp::acceptor m_acceptor; + connection_handler_ptr m_def_con_handler; + + po::options_description m_desc; + po::variables_map m_vm; }; } diff --git a/websocketpp.xcodeproj/project.pbxproj b/websocketpp.xcodeproj/project.pbxproj index ac6f6b3ddc..ae545d4e8b 100644 --- a/websocketpp.xcodeproj/project.pbxproj +++ b/websocketpp.xcodeproj/project.pbxproj @@ -69,6 +69,7 @@ B6DF1CDE1435EDF00029A1B1 /* libwebsocketpp.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B6DF1C721434A8280029A1B1 /* libwebsocketpp.dylib */; }; B6DF1CE21435F1860029A1B1 /* libboost_system.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B6DF1CE11435F1860029A1B1 /* libboost_system.dylib */; }; B6DF1CE41435F8250029A1B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6DF1CE31435F8250029A1B1 /* Foundation.framework */; }; + B6FE8CEC145A0F1900B32547 /* libboost_program_options.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B6FE8CEB145A0F1900B32547 /* libboost_program_options.dylib */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -167,6 +168,7 @@ B6DF1CE11435F1860029A1B1 /* libboost_system.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libboost_system.dylib; path = usr/local/lib/libboost_system.dylib; sourceTree = SDKROOT; }; B6DF1CE31435F8250029A1B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; B6FE8CE2144DE17F00B32547 /* readme.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = readme.txt; sourceTree = ""; }; + B6FE8CEB145A0F1900B32547 /* libboost_program_options.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libboost_program_options.dylib; path = usr/local/lib/libboost_program_options.dylib; sourceTree = SDKROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -200,6 +202,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + B6FE8CEC145A0F1900B32547 /* libboost_program_options.dylib in Frameworks */, B682888D1437464A002BA48B /* libboost_random.dylib in Frameworks */, B6DF1CC11434AF6A0029A1B1 /* libboost_date_time.dylib in Frameworks */, B6DF1CC21434AF6A0029A1B1 /* libboost_regex.dylib in Frameworks */, @@ -235,6 +238,7 @@ B6DF1C451434A5940029A1B1 = { isa = PBXGroup; children = ( + B6FE8CEB145A0F1900B32547 /* libboost_program_options.dylib */, B6CF182B1437C3CA009295BE /* libboost_system.dylib */, B682888E14374689002BA48B /* libboost_thread.dylib */, B682888C1437464A002BA48B /* libboost_random.dylib */,