SharkSSL™ Embedded SSL/TLS Stack
WsClientLib.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * SharkSSL Embedded SSL/TLS Stack
10 ****************************************************************************
11 * PROGRAM MODULE
12 *
13 * $Id: WsClientLib.h 5120 2022-03-24 15:25:13Z wini $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2014 - 2022
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://realtimelogic.com
33 * http://sharkssl.com
34 ****************************************************************************
35 *
36 */
37
38#ifndef _WsClientLib_h
39#define _WsClientLib_h
40
41
42#include "selib.h"
43
44#ifdef _DOXYGEN
45/* For documentation purposes */
46#define WSC_DUAL
47#endif
48
67#define WSOP_Text 0x81
69#define WSOP_Binary 0x82
71#define WSOP_Close 0x88
73#define WSOP_Ping 0x89
75#define WSOP_Pong 0x8A
76 /* end group WebSocketOpcodes */
78
79
80
84typedef struct
85{
86#ifdef WSC_DUAL
88 U8* recBuf;
95#endif
104
105 /* Begin private */
106 U8* overflowPtr; /* Set if: consumed more data from stream than frame len */
107 int overflowLen; /* overflowPtr len is used internally in wsRawRead */
108 int frameHeaderIx; /* Cursor used when reading frameHeader from socket */
109 U8 frameHeader[4]; /*[0] FIN+opcode, [1] Payload len, [2-3] Ext payload len*/
110 /* End private */
111
114} WscState;
115
116
117#ifdef __cplusplus
118extern "C" {
119#endif
120
121
149int wscProtocolHandshake(WscState* wss,U32 tmo, const char* host,
150 const char* path,const char* origin);
151
152
160int wscSendBin(WscState* wss, U8* buf, int len);
161
169int wscSendCtrl(WscState* wss, U8 opCode, const U8* buf,int len);
170
178int wscClose(WscState* wss, int statusCode);
179
180
204int wscRead(WscState* wss, U8 **buf, U32 timeout);
205
206#ifdef __cplusplus
207}
208#endif
209 /* end group WsClientLib */
211
212#endif
struct SharkSslCon SharkSslCon
SharkSslCon is an opaque handle returned by function SharkSsl_createCon.
Definition: SharkSSL.h:553
int wscProtocolHandshake(WscState *wss, U32 tmo, const char *host, const char *path, const char *origin)
Upgrades (morphs) an HTTPS request/response pair to a WebSocket connection.
int wscSendCtrl(WscState *wss, U8 opCode, const U8 *buf, int len)
Sends a WebSocket control frame.
int wscRead(WscState *wss, U8 **buf, U32 timeout)
Wait for WebSocket frames sent by the server.
int wscClose(WscState *wss, int statusCode)
Sends a WebSocket close control frame to the server and closes the connection.
int wscSendBin(WscState *wss, U8 *buf, int len)
Sends binary data to server.
#define SOCKET
Infinite wait time option for socket read functions.
Definition: selib.h:102
WebSocket Client State Information, initialize using: WscState wss={0}; however, several members must...
Definition: WsClientLib.h:85
int sendBufLen
The send buffer length must be set to the sendBuf length.
Definition: WsClientLib.h:94
U8 * recBuf
The receive buffer must be set when not in secure mode.
Definition: WsClientLib.h:88
U8 * sendBuf
The send buffer must be set when not in secure mode.
Definition: WsClientLib.h:90
U8 isTimeout
Set when the read function returns due to a timeout.
Definition: WsClientLib.h:113
int bytesRead
Read frame data until: frameLen - bytesRead = 0.
Definition: WsClientLib.h:103
SOCKET * sock
The SOCKET object must be set.
Definition: WsClientLib.h:99
int frameLen
The WebSocket frame length.
Definition: WsClientLib.h:101
int recBufLen
The receive buffer length must be set to the recBuf length.
Definition: WsClientLib.h:92
SharkSslCon * scon
The SharkSslCon object must be set when using secure mode.
Definition: WsClientLib.h:97