mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
adds hybi00 support for writing messages
This commit is contained in:
@@ -59,6 +59,8 @@ struct processor_setup {
|
||||
websocketpp::processor::hybi00<stub_config> p;
|
||||
};
|
||||
|
||||
typedef stub_config::message_type::ptr message_ptr;
|
||||
|
||||
BOOST_AUTO_TEST_CASE( exact_match ) {
|
||||
processor_setup env(true);
|
||||
|
||||
@@ -167,3 +169,45 @@ BOOST_AUTO_TEST_CASE( extract_subprotocols ) {
|
||||
BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
|
||||
BOOST_CHECK_EQUAL( subps.size(), 0 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( prepare_data_frame_null ) {
|
||||
processor_setup env(true);
|
||||
|
||||
message_ptr in = env.msg_manager->get_message();
|
||||
message_ptr out = env.msg_manager->get_message();
|
||||
message_ptr invalid;
|
||||
|
||||
|
||||
// empty pointers arguements should return sane error
|
||||
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,invalid), websocketpp::processor::error::invalid_arguments );
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(in,invalid), websocketpp::processor::error::invalid_arguments );
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,out), websocketpp::processor::error::invalid_arguments );
|
||||
|
||||
// test valid opcodes
|
||||
// text (1) should be the only valid opcode
|
||||
for (int i = 0; i < 0xF; i++) {
|
||||
in->set_opcode(websocketpp::frame::opcode::value(i));
|
||||
|
||||
env.ec = env.p.prepare_data_frame(in,out);
|
||||
|
||||
if (i != 1) {
|
||||
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
|
||||
} else {
|
||||
BOOST_CHECK_NE( env.ec, websocketpp::processor::error::invalid_opcode );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: tests for invalid UTF8
|
||||
char buf[2] = {0x00, 0x00};
|
||||
|
||||
in->set_opcode(websocketpp::frame::opcode::text);
|
||||
in->set_payload("foo");
|
||||
|
||||
env.ec = env.p.prepare_data_frame(in,out);
|
||||
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_payload );
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <websocketpp/processors/processor.hpp>
|
||||
|
||||
#include <websocketpp/frame.hpp>
|
||||
#include <websocketpp/md5/md5.hpp>
|
||||
|
||||
namespace websocketpp {
|
||||
@@ -218,19 +219,39 @@ public:
|
||||
*/
|
||||
virtual lib::error_code prepare_data_frame(message_ptr in, message_ptr out)
|
||||
{
|
||||
// assert msg
|
||||
if (!in || !out) {
|
||||
return make_error_code(error::invalid_arguments);
|
||||
}
|
||||
|
||||
// check if the message is prepared already
|
||||
// TODO: check if the message is prepared already
|
||||
|
||||
// validate opcode
|
||||
if (in->get_opcode() != frame::opcode::text) {
|
||||
return make_error_code(error::invalid_opcode);
|
||||
}
|
||||
|
||||
std::string& i = in->get_raw_payload();
|
||||
//std::string& o = out->get_raw_payload();
|
||||
|
||||
// validate payload utf8
|
||||
|
||||
// if we are a client generate a masking key
|
||||
|
||||
if (!utf8_validator::validate(i)) {
|
||||
return make_error_code(error::invalid_payload);
|
||||
}
|
||||
|
||||
// generate header
|
||||
// perform compression
|
||||
// perform masking
|
||||
char h = 0x00;
|
||||
char f = 0xff;
|
||||
out->set_header(std::string(&h,1));
|
||||
|
||||
// process payload
|
||||
out->set_payload(i);
|
||||
out->append_payload(std::string(&f,1));
|
||||
|
||||
// hybi00 doesn't support compression
|
||||
// hybi00 doesn't have masking
|
||||
|
||||
out->set_prepared(true);
|
||||
|
||||
return lib::error_code();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user