12 #ifndef TW_WEBSOCKET_H
13 #define TW_WEBSOCKET_H
18 #include "twPasswds.h"
27 #define FRAME_OPCODE_CONTINUATION 0x00
28 #define FRAME_OPCODE_TEXT 0x01
29 #define FRAME_OPCODE_BINARY 0x02
30 #define FRAME_OPCODE_CONNECTION_CLOSE 0x08
31 #define FRAME_OPCODE_PING 0x09
32 #define FRAME_OPCODE_PONG 0x0A
36 #define READ_CONTROL_FRAME 1
37 #define READ_TEXT_FRAME 2
38 #define READ_BINARY_FRAME 3
41 #define ZLIB_WINDOW_BITS_RAW_DEFLATE -15
42 #define ZLIB_DEFAULT_MEM_LEVEL 8
49 struct http_parser_settings;
56 typedef int (*ws_cb) (
struct twWs * ws);
57 typedef int (*ws_data_cb) (
struct twWs * ws,
const char *at,
size_t length);
58 typedef int (*ws_binary_data_cb) (
struct twWs * ws,
const char *at,
size_t length,
char bCompressed);
63 #define WS_TLS_CONN(a) (twTlsClient *)a->connection
92 char previous_read_state;
101 twPasswdCallbackFunction api_key_callback;
176 int twWs_Create(
char * host, uint16_t port,
char * resource, twPasswdCallbackFunction app_key_function,
char * gatewayName,
177 uint32_t messageChunkSize, uint16_t frameSize,
twWs ** entity);
366 int twWs_SendDataFrame (
twWs * ws,
char * msg, uint16_t length,
char isContinuation,
char isFinal,
char isText);
char bSupportsPermessageDeflate
Definition: twWebsocket.h:141
struct twWs twWs
Websocket entity structure definition.
Definition: twWebsocket.h:76
Definition: twWebsocket.h:81
int32_t bytesNeeded
Definition: twWebsocket.h:90
char bCompressedMsg
Definition: twWebsocket.h:138
int twWs_RegisterPongCallback(twWs *ws, ws_data_cb cb)
Registers a function to be called when the websocket receives a Pong message.
Definition: twWebsocket.c:632
int twWs_Create(char *host, uint16_t port, char *resource, twPasswdCallbackFunction app_key_function, char *gatewayName, uint32_t messageChunkSize, uint16_t frameSize, twWs **entity)
Creates a new websocket struct and the underlying dependent components.
Definition: twWebsocket.c:149
char twWs_IsConnected(twWs *ws)
Gets the connection status of a websocket entity structure.
Definition: twWebsocket.c:514
ws_binary_data_cb on_ws_binaryMessage
Definition: twWebsocket.h:127
char bInflateInitialized
Definition: twWebsocket.h:136
#define TW_MUTEX
For Linux builds a TW_MUTEX is a pthread_mutex_t.
Definition: twLinux-openssl.h:81
char bDisableCompression
Definition: twWebsocket.h:142
uint32_t sessionId
Definition: twWebsocket.h:119
signed char isConnected
Definition: twWebsocket.h:125
uint16_t frameSize
Definition: twWebsocket.h:93
char * gatewayType
Definition: twWebsocket.h:116
int twWs_SendPing(twWs *ws, char *msg)
Send a Ping message over the websocket.
Definition: twWebsocket.c:1072
Dynamically allocated byte array. Automatically expands its length as needed.
Definition: twBaseTypes.h:35
int twWs_Disconnect(twWs *ws, enum close_status code, char *reason)
Disconnect a websocket connection from the server.
Definition: twWebsocket.c:519
Wrappers for OS-specific functionality.
int twWs_SendDataFrame(twWs *ws, char *msg, uint16_t length, char isContinuation, char isFinal, char isText)
Definition: twWebsocket.c:1142
unsigned char * security_key
Definition: twWebsocket.h:118
Definition: twWebsocket.h:77
ws_cb on_ws_connected
Definition: twWebsocket.h:126
char * frameBufferPtr
Definition: twWebsocket.h:95
int twWs_RegisterPingCallback(twWs *ws, ws_data_cb cb)
Registers a function to be called when the websocket receives a Ping message.
Definition: twWebsocket.c:623
struct twTlsClient * connection
Definition: twWebsocket.h:88
twStream * multiframeRecvStream
Definition: twWebsocket.h:98
TW_MUTEX decompressionMutex
Definition: twWebsocket.h:137
Definition: twWebsocket.h:78
Definition: twWebsocket.h:74
int twWs_RegisterCloseCallback(twWs *ws, ws_data_cb cb)
Registers a function to be called when the websocket is closed by the server.
Definition: twWebsocket.c:596
char bDeflateInitialized
Definition: twWebsocket.h:133
uint32_t messageChunkSize
Definition: twWebsocket.h:89
uint16_t port
Definition: twWebsocket.h:100
signed char connect_state
Definition: twWebsocket.h:124
Definition: twWebsocket.h:69
int twWs_SendMessage(twWs *ws, char *buf, uint32_t length, char isText)
Send a message over the websocket.
Definition: twWebsocket.c:985
char read_state
Definition: twWebsocket.h:91
Common definitions for C SDK.
Definition: twWebsocket.h:70
int twWs_RegisterConnectCallback(twWs *ws, ws_cb cb)
Registers a function to be called when the websocket is successfully connected.
Definition: twWebsocket.c:587
ws_data_cb on_ws_close
Definition: twWebsocket.h:131
int twWs_RegisterBinaryMessageCallback(twWs *ws, ws_binary_data_cb cb)
Registers a function to be called when the websocket receives a complete binary message.
Definition: twWebsocket.c:605
Definition: inftree9.h:24
Definition: twWebsocket.h:71
ThingWorx BaseType definitions and functions.
Definition: twWebsocket.h:79
int twWs_Receive(twWs *ws, uint32_t timeout)
Check the websocket for data and drive the state machine of the websocket.
Definition: twWebsocket.c:642
Definition: twWebsocket.h:80
close_status
Websocket close reasoning enumeration.
Definition: twWebsocket.h:68
ws_data_cb on_ws_pong
Definition: twWebsocket.h:130
int twWs_SendPong(twWs *ws, char *msg)
Send a Pong message over the websocket.
Definition: twWebsocket.c:1082
char * resource
Definition: twWebsocket.h:120
int twWs_RegisterTextMessageCallback(twWs *ws, ws_data_cb cb)
Registers a function to be called when the websocket receives a complete text message.
Definition: twWebsocket.c:614
ws_data_cb on_ws_textMessage
Definition: twWebsocket.h:128
TW_MUTEX compressionMutex
Definition: twWebsocket.h:134
TW_MUTEX sendMessageMutex
Definition: twWebsocket.h:121
TW_MUTEX recvMutex
Definition: twWebsocket.h:123
unsigned char ws_header[64]
Definition: twWebsocket.h:96
TW_MUTEX sendFrameMutex
Definition: twWebsocket.h:122
Definition: twWebsocket.h:75
TLS client structure definition.
Definition: twTls.h:34
Websocket entity structure definition.
Definition: twWebsocket.h:87
Definition: twWebsocket.h:72
int twWs_Delete(twWs *ws)
Frees all memory associated with a twWs structure and all its owned substructures.
Definition: twWebsocket.c:238
char * gatewayName
Definition: twWebsocket.h:114
ws_data_cb on_ws_ping
Definition: twWebsocket.h:129
char * host
Definition: twWebsocket.h:99
int twWs_Connect(twWs *ws, uint32_t timeout)
Establishes a websocket connection to the server.
Definition: twWebsocket.c:267
z_stream inflstream
Definition: twWebsocket.h:135
Definition: twWebsocket.h:73
char * frameBuffer
Definition: twWebsocket.h:94
unsigned char * headerPtr
Definition: twWebsocket.h:97