RESTinio
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
restinio::websocket::basic::impl::ws_protocol_validator_t Class Reference

Class for websocket protocol validations. More...

#include <ws_protocol_validator.hpp>

Public Member Functions

 ws_protocol_validator_t ()=default
 
 ws_protocol_validator_t (bool do_unmask)
 
validation_state_t process_new_frame (const message_details_t &frame)
 Start work with new frame. More...
 
validation_state_t process_next_payload_part (const char *data, size_t size)
 Validate next part of current frame. More...
 
validation_state_t process_and_unmask_next_payload_part (char *data, size_t size)
 Validate next part of current frame and reset source part to unmasked data. More...
 
validation_state_t finish_frame ()
 Make final checks of payload if it is necessary and reset state. More...
 
void reset ()
 Reset to initial state. More...
 

Private Types

enum class  working_state_t { empty_state , processing_frame }
 Validator's orking states. More...
 
enum class  previous_data_frame_t { none , text , binary }
 Previous unfinished data frame type. More...
 

Private Member Functions

bool validate_frame_header (const message_details_t &frame)
 Validate frame header. More...
 
std::uint8_t process_payload_byte (std::uint8_t byte)
 Process payload byte. More...
 
bool check_previous_frame_type (opcode_t opcode)
 Check previous frame type. More...
 
void validate_close_code (uint16_t close_code)
 Validate close code. More...
 
bool is_state_still_valid () const
 Check validation state is still valid. More...
 
void set_validation_state (validation_state_t state)
 Try to set validation state. More...
 

Private Attributes

validation_state_t m_validation_state
 Current validation state. More...
 
working_state_t m_working_state { working_state_t::empty_state }
 Working state. More...
 
previous_data_frame_t m_previous_data_frame
 Previous unfinished data frame. More...
 
message_details_t m_current_frame
 Current frame details. More...
 
expected_data_t m_expected_close_code
 Buffer for accumulating 2 bytes of close code. More...
 
restinio::utils::utf8_checker_t m_utf8_checker
 UTF-8 checker for text frames and close frames. More...
 
bool m_unmask_flag { false }
 This flag set if it's need to unmask payload parts. More...
 
unmasker_t m_unmasker
 Unmask payload coming from client side. More...
 

Detailed Description

Class for websocket protocol validations.

This class checks:

text frame and close frame are with valid uff-8 payload; close frame has a valid close code; continuation chunks of text frame have valid utf-8 text; there is invalid situation when continuation frame came without any data frame. continuation frame or control frame is wating after data frame with fin flag set in 0. opcode has a valid code control frame can't be fragmented.

Definition at line 194 of file ws_protocol_validator.hpp.

Member Enumeration Documentation

◆ previous_data_frame_t

Previous unfinished data frame type.

It needs for understanding what kind of data is present in current continued frames.

Enumerator
none 
text 
binary 

Definition at line 553 of file ws_protocol_validator.hpp.

◆ working_state_t

Validator's orking states.

Enumerator
empty_state 

Waiting for new frame.

processing_frame 

Frame is processing now.

Definition at line 540 of file ws_protocol_validator.hpp.

Constructor & Destructor Documentation

◆ ws_protocol_validator_t() [1/2]

restinio::websocket::basic::impl::ws_protocol_validator_t::ws_protocol_validator_t ( )
default

◆ ws_protocol_validator_t() [2/2]

restinio::websocket::basic::impl::ws_protocol_validator_t::ws_protocol_validator_t ( bool  do_unmask)
inline

Definition at line 200 of file ws_protocol_validator.hpp.

Member Function Documentation

◆ check_previous_frame_type()

bool restinio::websocket::basic::impl::ws_protocol_validator_t::check_previous_frame_type ( opcode_t  opcode)
inlineprivate

Check previous frame type.

Need for following cases:

1) check current frame is not continuation frame withot any data frame before. 2) check current frame is not new data frame with unfinished other data frame before.

Returns
true if previous and current frames are without any conflicts.
false otherwise.

Definition at line 460 of file ws_protocol_validator.hpp.

◆ finish_frame()

validation_state_t restinio::websocket::basic::impl::ws_protocol_validator_t::finish_frame ( )
inline

Make final checks of payload if it is necessary and reset state.

Definition at line 303 of file ws_protocol_validator.hpp.

◆ is_state_still_valid()

bool restinio::websocket::basic::impl::ws_protocol_validator_t::is_state_still_valid ( ) const
inlineprivate

Check validation state is still valid.

Definition at line 510 of file ws_protocol_validator.hpp.

◆ process_and_unmask_next_payload_part()

validation_state_t restinio::websocket::basic::impl::ws_protocol_validator_t::process_and_unmask_next_payload_part ( char *  data,
size_t  size 
)
inline

Validate next part of current frame and reset source part to unmasked data.

Definition at line 278 of file ws_protocol_validator.hpp.

◆ process_new_frame()

validation_state_t restinio::websocket::basic::impl::ws_protocol_validator_t::process_new_frame ( const message_details_t frame)
inline

Start work with new frame.

Attention
methods finish_frame() or reset() should be called before processing a new frame.

Definition at line 211 of file ws_protocol_validator.hpp.

◆ process_next_payload_part()

validation_state_t restinio::websocket::basic::impl::ws_protocol_validator_t::process_next_payload_part ( const char *  data,
size_t  size 
)
inline

Validate next part of current frame.

Definition at line 253 of file ws_protocol_validator.hpp.

◆ process_payload_byte()

std::uint8_t restinio::websocket::basic::impl::ws_protocol_validator_t::process_payload_byte ( std::uint8_t  byte)
inlineprivate

Process payload byte.

Do all necessary validations with payload byte.

Returns
unmasked byte if unmask flag is set.
copy of original byte if unmask flag isn't set.

Definition at line 406 of file ws_protocol_validator.hpp.

◆ reset()

void restinio::websocket::basic::impl::ws_protocol_validator_t::reset ( )
inline

Reset to initial state.

Definition at line 341 of file ws_protocol_validator.hpp.

◆ set_validation_state()

void restinio::websocket::basic::impl::ws_protocol_validator_t::set_validation_state ( validation_state_t  state)
inlineprivate

Try to set validation state.

Set validation state with new value.

Definition at line 523 of file ws_protocol_validator.hpp.

◆ validate_close_code()

void restinio::websocket::basic::impl::ws_protocol_validator_t::validate_close_code ( uint16_t  close_code)
inlineprivate

Validate close code.

Definition at line 485 of file ws_protocol_validator.hpp.

◆ validate_frame_header()

bool restinio::websocket::basic::impl::ws_protocol_validator_t::validate_frame_header ( const message_details_t frame)
inlineprivate

Validate frame header.

Returns
true if current validation state is 'frame_header_is_valid' after all validation operations.
false otherwise.

Definition at line 361 of file ws_protocol_validator.hpp.

Member Data Documentation

◆ m_current_frame

message_details_t restinio::websocket::basic::impl::ws_protocol_validator_t::m_current_frame
private

Current frame details.

Definition at line 568 of file ws_protocol_validator.hpp.

◆ m_expected_close_code

expected_data_t restinio::websocket::basic::impl::ws_protocol_validator_t::m_expected_close_code
private

Buffer for accumulating 2 bytes of close code.

Definition at line 571 of file ws_protocol_validator.hpp.

◆ m_previous_data_frame

previous_data_frame_t restinio::websocket::basic::impl::ws_protocol_validator_t::m_previous_data_frame
private

◆ m_unmask_flag

bool restinio::websocket::basic::impl::ws_protocol_validator_t::m_unmask_flag { false }
private

This flag set if it's need to unmask payload parts.

Definition at line 577 of file ws_protocol_validator.hpp.

◆ m_unmasker

unmasker_t restinio::websocket::basic::impl::ws_protocol_validator_t::m_unmasker
private

Unmask payload coming from client side.

Definition at line 580 of file ws_protocol_validator.hpp.

◆ m_utf8_checker

restinio::utils::utf8_checker_t restinio::websocket::basic::impl::ws_protocol_validator_t::m_utf8_checker
private

UTF-8 checker for text frames and close frames.

Definition at line 574 of file ws_protocol_validator.hpp.

◆ m_validation_state

validation_state_t restinio::websocket::basic::impl::ws_protocol_validator_t::m_validation_state
private
Initial value:

Current validation state.

Normal case is sequence of states: frame_header_is_valid -> payload_part_is_valid -> frame_is_valid.

After set in invalid state validator will save this state until frame will be finished or validator will be reset.

Definition at line 536 of file ws_protocol_validator.hpp.

◆ m_working_state

working_state_t restinio::websocket::basic::impl::ws_protocol_validator_t::m_working_state { working_state_t::empty_state }
private

Working state.

Definition at line 561 of file ws_protocol_validator.hpp.


The documentation for this class was generated from the following file: