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
68 
69 #define WSOP_Binary 0x82
70 
71 #define WSOP_Close 0x88
72 
73 #define WSOP_Ping 0x89
74 
75 #define WSOP_Pong 0x8A
76  /* end group WebSocketOpcodes */
78 
79 
80 
84 typedef struct
85 {
86 #ifdef WSC_DUAL
87 
88  U8* recBuf;
90  U8* sendBuf;
92  int recBufLen;
95 #endif
96 
101  int frameLen;
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
118 extern "C" {
119 #endif
120 
121 
149 int wscProtocolHandshake(WscState* wss,U32 tmo, const char* host,
150  const char* path,const char* origin);
151 
152 
160 int wscSendBin(WscState* wss, U8* buf, int len);
161 
169 int wscSendCtrl(WscState* wss, U8 opCode, const U8* buf,int len);
170 
178 int wscClose(WscState* wss, int statusCode);
179 
180 
204 int wscRead(WscState* wss, U8 **buf, U32 timeout);
205 
206 #ifdef __cplusplus
207 }
208 #endif
209  /* end group WsClientLib */
211 
212 #endif
WscState
WebSocket Client State Information, initialize using: WscState wss={0}; however, several members must...
Definition: WsClientLib.h:85
WscState::sendBufLen
int sendBufLen
The send buffer length must be set to the sendBuf length.
Definition: WsClientLib.h:94
WscState::sock
SOCKET * sock
The SOCKET object must be set.
Definition: WsClientLib.h:99
wscProtocolHandshake
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.
SharkSslCon
struct SharkSslCon SharkSslCon
SharkSslCon is an opaque handle returned by function SharkSsl_createCon.
Definition: SharkSSL.h:534
WscState::isTimeout
U8 isTimeout
Set when the read function returns due to a timeout.
Definition: WsClientLib.h:113
wscSendBin
int wscSendBin(WscState *wss, U8 *buf, int len)
Sends binary data to server.
wscClose
int wscClose(WscState *wss, int statusCode)
Sends a WebSocket close control frame to the server and closes the connection.
WscState::frameLen
int frameLen
The WebSocket frame length.
Definition: WsClientLib.h:101
WscState::recBufLen
int recBufLen
The receive buffer length must be set to the recBuf length.
Definition: WsClientLib.h:92
wscRead
int wscRead(WscState *wss, U8 **buf, U32 timeout)
Wait for WebSocket frames sent by the server.
SOCKET
#define SOCKET
Infinite wait time option for socket read functions.
Definition: selib.h:102
WscState::scon
SharkSslCon * scon
The SharkSslCon object must be set when using secure mode.
Definition: WsClientLib.h:97
WscState::bytesRead
int bytesRead
Read frame data until: frameLen - bytesRead = 0.
Definition: WsClientLib.h:103
WscState::sendBuf
U8 * sendBuf
The send buffer must be set when not in secure mode.
Definition: WsClientLib.h:90
wscSendCtrl
int wscSendCtrl(WscState *wss, U8 opCode, const U8 *buf, int len)
Sends a WebSocket control frame.
WscState::recBuf
U8 * recBuf
The receive buffer must be set when not in secure mode.
Definition: WsClientLib.h:88