From 4202ddbd754ddb6030e6693612925d537f3e0cf6 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Tue, 27 Sep 2011 07:50:43 -0500 Subject: [PATCH] removes C++11 requirement for read_frame, allows reading unmasked frames --- src/websocket_frame.cpp | 24 ++++++++++++++---------- src/websocket_frame.hpp | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/websocket_frame.cpp b/src/websocket_frame.cpp index cf854dc2ad..3709c159c6 100644 --- a/src/websocket_frame.cpp +++ b/src/websocket_frame.cpp @@ -261,20 +261,22 @@ void frame::set_status(uint16_t status,const std::string message) { std::copy(message.begin(),message.end(),m_payload.begin()+2); } -void frame::print_frame() const { - /*unsigned int len = get_header_len(); +std::string frame::print_frame() const { + std::stringstream f; - std::cout << "frame: "; + unsigned int len = get_header_len(); + + f << "frame: "; // print header for (unsigned int i = 0; i < len; i++) { - std::cout << std::hex << (unsigned short)m_header[i] << " "; + f << std::hex << (unsigned short)m_header[i] << " "; } // print message - for (auto &i: m_payload) { - std::cout << i; + std::vector::const_iterator it; + for (it = m_payload.begin(); it != m_payload.end(); it++) { + f << *it; } - - std::cout << std::endl;*/ + return f.str(); } unsigned int frame::process_basic_header() { @@ -338,8 +340,10 @@ void frame::process_extended_header() { } void frame::process_payload() { - for (uint64_t i = 0; i < m_payload.size(); i++) { - m_payload[i] = (m_payload[i] ^ m_masking_key[i%4]); + if (get_masked()) { + for (uint64_t i = 0; i < m_payload.size(); i++) { + m_payload[i] = (m_payload[i] ^ m_masking_key[i%4]); + } } } diff --git a/src/websocket_frame.hpp b/src/websocket_frame.hpp index e1cf16177b..7370273a5a 100644 --- a/src/websocket_frame.hpp +++ b/src/websocket_frame.hpp @@ -119,7 +119,7 @@ public: bool is_control() const; - void print_frame() const; + std::string print_frame() const; // reads basic header, sets and returns m_header_bits_needed unsigned int process_basic_header();