jabberd2  2.3.6
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
websocket.c File Reference
#include "sx.h"
#include <stdarg.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  _libwebsock_frame
 

Macros

#define MASK_LENGTH   4
 
#define FRAME_CHUNK_LENGTH   1024
 
#define WS_OPCODE_CONTINUE   0x0
 
#define WS_OPCODE_TEXT   0x1
 
#define WS_OPCODE_BINARY   0x2
 
#define WS_OPCODE_CLOSE   0x8
 
#define WS_OPCODE_PING   0x9
 
#define WS_OPCODE_PONG   0xa
 
#define WS_FRAGMENT_FIN   (1 << 7)
 
#define WS_CLOSE_NORMAL   1000
 
#define WS_CLOSE_GOING_AWAY   1001
 
#define WS_CLOSE_PROTOCOL_ERROR   1002
 
#define WS_CLOSE_NOT_ALLOWED   1003
 
#define WS_CLOSE_RESERVED   1004
 
#define WS_CLOSE_NO_CODE   1005
 
#define WS_CLOSE_DIRTY   1006
 
#define WS_CLOSE_WRONG_TYPE   1007
 
#define WS_CLOSE_POLICY_VIOLATION   1008
 
#define WS_CLOSE_MESSAGE_TOO_BIG   1009
 
#define WS_CLOSE_UNEXPECTED_ERROR   1011
 

Typedefs

typedef struct _libwebsock_frame libwebsock_frame
 

Enumerations

enum  WS_FRAME_STATE {
  sw_start = 0, sw_got_two, sw_got_short_len, sw_got_full_len,
  sw_loaded_mask
}
 

Functions

static int libwebsock_read_header (libwebsock_frame *frame)
 
sx_buf_t libwebsock_fragment_buffer (const char *data, unsigned int len, int flags)
 
int libwebsock_close_with_reason (sx_t s, _sx_websocket_conn_t sc, unsigned short code, const char *reason)
 
int libwebsock_send_fragment (sx_t s, _sx_websocket_conn_t sc, const char *data, unsigned int len, int flags)
 
int libwebsock_close (sx_t s, _sx_websocket_conn_t sc)
 
void libwebsock_fail_connection (sx_t s, _sx_websocket_conn_t sc, unsigned short close_code)
 
static int _sx_websocket_http_header_field (http_parser *parser, const char *chars, size_t length)
 
static int _sx_websocket_http_header_value (http_parser *parser, const char *chars, size_t length)
 
static int _sx_websocket_http_headers_complete (http_parser *parser)
 
static void _sx_websocket_http_return (sx_t s, char *status, char *headers_format,...)
 
static int _sx_websocket_rio (sx_t s, sx_plugin_t p, sx_buf_t buf)
 
static int _sx_websocket_wio (sx_t s, sx_plugin_t p, sx_buf_t buf)
 
static void _sx_websocket_new (sx_t s, sx_plugin_t p)
 
static void _sx_websocket_free (sx_t s, sx_plugin_t p)
 cleanup More...
 
int sx_websocket_init (sx_env_t env, sx_plugin_t p, va_list args)
 args: none More...
 

Variables

static const char websocket_guid [] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
 this plugin implements WebSocket C2S access RFC 7395 : An Extensible Messaging and Presence Protocol (XMPP) Subprotocol for WebSocket http://tools.ietf.org/html/rfc7395 More...
 
static http_parser_settings settings
 

Macro Definition Documentation

#define MASK_LENGTH   4

Definition at line 34 of file websocket.c.

Referenced by libwebsock_read_header().

#define FRAME_CHUNK_LENGTH   1024

Definition at line 35 of file websocket.c.

Referenced by _sx_websocket_rio().

#define WS_OPCODE_CONTINUE   0x0

Definition at line 37 of file websocket.c.

Referenced by _sx_websocket_rio().

#define WS_OPCODE_TEXT   0x1

Definition at line 38 of file websocket.c.

Referenced by _sx_websocket_rio(), and _sx_websocket_wio().

#define WS_OPCODE_BINARY   0x2

Definition at line 39 of file websocket.c.

#define WS_OPCODE_CLOSE   0x8

Definition at line 40 of file websocket.c.

Referenced by _sx_websocket_rio(), and libwebsock_close_with_reason().

#define WS_OPCODE_PING   0x9

Definition at line 41 of file websocket.c.

Referenced by _sx_websocket_rio().

#define WS_OPCODE_PONG   0xa

Definition at line 42 of file websocket.c.

Referenced by _sx_websocket_rio().

#define WS_FRAGMENT_FIN   (1 << 7)

Definition at line 44 of file websocket.c.

Referenced by _sx_websocket_rio(), _sx_websocket_wio(), and libwebsock_close_with_reason().

#define WS_CLOSE_NORMAL   1000

Definition at line 46 of file websocket.c.

Referenced by libwebsock_close().

#define WS_CLOSE_GOING_AWAY   1001

Definition at line 47 of file websocket.c.

#define WS_CLOSE_PROTOCOL_ERROR   1002

Definition at line 48 of file websocket.c.

Referenced by _sx_websocket_rio(), and libwebsock_fail_connection().

#define WS_CLOSE_NOT_ALLOWED   1003

Definition at line 49 of file websocket.c.

#define WS_CLOSE_RESERVED   1004

Definition at line 50 of file websocket.c.

#define WS_CLOSE_NO_CODE   1005

Definition at line 51 of file websocket.c.

#define WS_CLOSE_DIRTY   1006

Definition at line 52 of file websocket.c.

#define WS_CLOSE_WRONG_TYPE   1007

Definition at line 53 of file websocket.c.

#define WS_CLOSE_POLICY_VIOLATION   1008

Definition at line 54 of file websocket.c.

#define WS_CLOSE_MESSAGE_TOO_BIG   1009

Definition at line 55 of file websocket.c.

#define WS_CLOSE_UNEXPECTED_ERROR   1011

Definition at line 56 of file websocket.c.

Referenced by _sx_websocket_wio(), and libwebsock_send_fragment().

Typedef Documentation

Enumeration Type Documentation

Enumerator
sw_start 
sw_got_two 
sw_got_short_len 
sw_got_full_len 
sw_loaded_mask 

Definition at line 58 of file websocket.c.

Function Documentation

static int libwebsock_read_header ( libwebsock_frame frame)
inlinestatic
sx_buf_t libwebsock_fragment_buffer ( const char *  data,
unsigned int  len,
int  flags 
)

Definition at line 153 of file websocket.c.

References _sx_buffer_new(), _sx_debug, _sx_buf_st::data, and ZONE.

Referenced by _sx_websocket_wio(), and libwebsock_send_fragment().

int libwebsock_close_with_reason ( sx_t  s,
_sx_websocket_conn_t  sc,
unsigned short  code,
const char *  reason 
)
int libwebsock_send_fragment ( sx_t  s,
_sx_websocket_conn_t  sc,
const char *  data,
unsigned int  len,
int  flags 
)
int libwebsock_close ( sx_t  s,
_sx_websocket_conn_t  sc 
)

Definition at line 230 of file websocket.c.

References libwebsock_close_with_reason(), and WS_CLOSE_NORMAL.

Referenced by _sx_websocket_rio().

void libwebsock_fail_connection ( sx_t  s,
_sx_websocket_conn_t  sc,
unsigned short  close_code 
)
static int _sx_websocket_http_header_field ( http_parser *  parser,
const char *  chars,
size_t  length 
)
static
static int _sx_websocket_http_header_value ( http_parser *  parser,
const char *  chars,
size_t  length 
)
static

Definition at line 265 of file websocket.c.

References _sx_debug, spool_escape(), spool_new(), and ZONE.

Referenced by sx_websocket_init().

static int _sx_websocket_http_headers_complete ( http_parser *  parser)
static

Definition at line 277 of file websocket.c.

References _sx_debug, _sx_websocket_http_header_field(), and ZONE.

Referenced by sx_websocket_init().

static void _sx_websocket_http_return ( sx_t  s,
char *  status,
char *  headers_format,
  ... 
)
static
static int _sx_websocket_rio ( sx_t  s,
sx_plugin_t  p,
sx_buf_t  buf 
)
static
static int _sx_websocket_wio ( sx_t  s,
sx_plugin_t  p,
sx_buf_t  buf 
)
static
static void _sx_websocket_new ( sx_t  s,
sx_plugin_t  p 
)
static
static void _sx_websocket_free ( sx_t  s,
sx_plugin_t  p 
)
static

cleanup

Definition at line 567 of file websocket.c.

References _sx_plugin_st::index, log_debug, _sx_st::plugin_data, pool_free(), and ZONE.

Referenced by sx_websocket_init().

int sx_websocket_init ( sx_env_t  env,
sx_plugin_t  p,
va_list  args 
)

Variable Documentation

const char websocket_guid[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
static

this plugin implements WebSocket C2S access RFC 7395 : An Extensible Messaging and Presence Protocol (XMPP) Subprotocol for WebSocket http://tools.ietf.org/html/rfc7395

Definition at line 29 of file websocket.c.

Referenced by _sx_websocket_rio().

http_parser_settings settings
static

Definition at line 31 of file websocket.c.

Referenced by _sx_websocket_rio(), and sx_websocket_init().