Data Structures | Enumerations | Functions
ws_parser.h File Reference

WebSocket protocol parser. More...

Data Structures

struct  vtm_ws_parser
 

Enumerations

enum  vtm_ws_parser_stage {
  VTM_WS_PARSE_MSG_BEGIN, VTM_WS_PARSE_FRAME_BEGIN, VTM_WS_PARSE_FRAME_FIN_OPCODE, VTM_WS_PARSE_FRAME_MASK_LEN7,
  VTM_WS_PARSE_FRAME_LEN16, VTM_WS_PARSE_FRAME_LEN64, VTM_WS_PARSE_FRAME_MASK32, VTM_WS_PARSE_FRAME_PAYLOAD,
  VTM_WS_PARSE_FRAME_FINISH_CTRL, VTM_WS_PARSE_FRAME_FINISH_DATA, VTM_WS_PARSE_FRAME_COMPLETE, VTM_WS_PARSE_MSG_COMPLETE,
  VTM_WS_PARSE_ERROR
}
 

Functions

VTM_API int vtm_ws_parser_init (struct vtm_ws_parser *par, enum vtm_ws_mode mode)
 
VTM_API void vtm_ws_parser_release (struct vtm_ws_parser *par)
 
VTM_API void vtm_ws_parser_reset (struct vtm_ws_parser *par)
 
VTM_API enum vtm_net_recv_stat vtm_ws_parser_run (struct vtm_ws_parser *par, struct vtm_buf *buf)
 
VTM_API int vtm_ws_parser_get_msg (struct vtm_ws_parser *par, struct vtm_ws_msg *msg)
 

Function Documentation

VTM_API int vtm_ws_parser_init ( struct vtm_ws_parser par,
enum vtm_ws_mode  mode 
)

Initializes a new parser for given mode.

Parameters
parthe parser that should be initialized
modethe mode under which the parser should run
Returns
VTM_OK if the parser was successfully initialized
VTM_ERROR if the parser could not be initialized
VTM_API void vtm_ws_parser_release ( struct vtm_ws_parser par)

Releases the parser and all allocated resources.

After this call the parser structure is no longer valid.

Parameters
parthe parser that should be released
VTM_API void vtm_ws_parser_reset ( struct vtm_ws_parser par)

Resets the parser to a clean state.

Parameters
parthe parser that should be reset
VTM_API enum vtm_net_recv_stat vtm_ws_parser_run ( struct vtm_ws_parser par,
struct vtm_buf buf 
)

Lets the parser examine the input data.

Parameters
parthe parser the should run
bufthe input buffer for the parser
Returns
VTM_NET_RECV_STAT_COMPLETE if a message was successfully parsed
VTM_NET_RECV_STAT_AGAIN if the parser need a another run with more input data
VTM_NET_RECV_STAT_INVALID if the input data is not a valid WebSocket message
VTM_NET_RECV_STAT_ERROR if an error occured for example a necessary buffer could not be allocated
VTM_API int vtm_ws_parser_get_msg ( struct vtm_ws_parser par,
struct vtm_ws_msg msg 
)

Retrieves the last parsed message

Parameters
parthe parser
[out]msgthe message is stored here
Returns
VTM_OK if the parsed message was successfully retrieved
VTM_ERROR if an error occured, for example a necessary buffer could not be allocated