Shellminator V3.0.1
Simple Terminal
Loading...
Searching...
No Matches
ShellminatorWebSocket Class Reference

#include <Shellminator-Websocket.hpp>

Inheritance diagram for ShellminatorWebSocket:
Collaboration diagram for ShellminatorWebSocket:

Public Types

enum  wsState_t { WS_DISCONNECTED_STATE , WS_HEADER_STATE , WS_CONNECTED_STATE }
 
enum  wsDecodedHeaderType_t {
  WS_COMM = 0x00 , WS_TXT = 0x01 , WS_CLOSE = 0x08 , WS_PING = 0x09 ,
  WS_PONG = 0x0A
}
 

Public Member Functions

 ShellminatorWebSocket ()
 
 ShellminatorWebSocket (int port_p)
 
int available () override
 Available bytes in the channel. More...
 
int read () override
 Read one byte form the channel. More...
 
int peek () override
 Peek the firtst byte from the channel. More...
 
void flush () override
 Flush the channel. More...
 
size_t write (uint8_t b) override
 Write one byte to the channel. More...
 
size_t write (const uint8_t *data, size_t size) override
 
void begin ()
 
void update ()
 
void attachDebugChannel (Stream *dbg_p)
 
void attachConnectCallback (void(*connectCallback_p)(ShellminatorWebSocket *))
 
void attachDisconnectCallback (void(*disconnectCallback_p)(ShellminatorWebSocket *))
 

Private Member Functions

void resetVariables ()
 
void resetDataVariables ()
 
void wsHeaderProcessing (char newChar)
 
void wsDataProcessing (char newChar)
 
void closeClient (bool sendCloseFrame=false)
 
bool generateServerKey ()
 
void finishDecoding ()
 
bool sendFrame (wsDecodedHeaderType_t type, const uint8_t *data=NULL, uint32_t dataSize=0)
 
bool sendFrame125 (wsDecodedHeaderType_t type, const uint8_t *data=NULL, uint8_t dataSize=0)
 
void appendToCircularBuffer (uint8_t data)
 
void appendToCircularBuffer (uint8_t *data, int dataSize)
 

Private Attributes

int port = 443
 
bool clientConnected = false
 
Stream * dbg = NULL
 
WiFiServer * server
 
WiFiClient client
 
uint8_t streamBuffer [SHELLMINATOR_WS_STREAM_BUFFER_SIZE]
 
uint32_t streamBufferWritePointer
 
uint32_t streamBufferReadPointer
 
char clientBuffer [SHELLMINATOR_WS_CLIENT_BUFFER_SIZE+1]
 
int clientBufferCounter = 0
 
char clientLineNameBuffer [SHELLMINATOR_WS_CLIENT_LINE_NAME_SIZE]
 
char clientLineValueBuffer [SHELLMINATOR_WS_CLIENT_LINE_VALUE_SIZE]
 
char clientKey [SHELLMINATOR_WS_CLIENT_KEY_SIZE]
 
char serverKey [SHELLMINATOR_WS_SERVER_KEY_SIZE]
 
bool httpGetLineFound
 
bool connectionUpgradeLineFound
 
bool upgradeWebsocketLineFound
 
int clientVersion
 
bool decodedHdrFin
 
wsDecodedHeaderType_t decodedHdrType
 
bool decodedHdrMask
 
uint8_t decodedHdrPayloadLen
 
uint8_t decodedHdrMaskKeys [4]
 
uint8_t decodedHdrPayloadCntr
 
uint8_t decodedDataXorCntr
 
wsState_t wsState
 
void(* connectCallback )(ShellminatorWebSocket *parent) = NULL
 
void(* disconnectCallback )(ShellminatorWebSocket *parent) = NULL
 

Static Private Attributes

static const char * serverHeader
 

Detailed Description

Definition at line 96 of file Shellminator-Websocket.hpp.

Member Enumeration Documentation

◆ wsDecodedHeaderType_t

Enumerator
WS_COMM 
WS_TXT 
WS_CLOSE 
WS_PING 
WS_PONG 

Definition at line 106 of file Shellminator-Websocket.hpp.

◆ wsState_t

Enumerator
WS_DISCONNECTED_STATE 
WS_HEADER_STATE 
WS_CONNECTED_STATE 

Definition at line 100 of file Shellminator-Websocket.hpp.

Constructor & Destructor Documentation

◆ ShellminatorWebSocket() [1/2]

ShellminatorWebSocket::ShellminatorWebSocket ( )

Definition at line 53 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:

◆ ShellminatorWebSocket() [2/2]

ShellminatorWebSocket::ShellminatorWebSocket ( int  port_p)

Definition at line 46 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ appendToCircularBuffer() [1/2]

void ShellminatorWebSocket::appendToCircularBuffer ( uint8_t *  data,
int  dataSize 
)
private

Definition at line 90 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:

◆ appendToCircularBuffer() [2/2]

void ShellminatorWebSocket::appendToCircularBuffer ( uint8_t  data)
private

Definition at line 73 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ attachConnectCallback()

void ShellminatorWebSocket::attachConnectCallback ( void(*)(ShellminatorWebSocket *)  connectCallback_p)

Definition at line 697 of file Shellminator-Websocket.cpp.

◆ attachDebugChannel()

void ShellminatorWebSocket::attachDebugChannel ( Stream *  dbg_p)

Definition at line 60 of file Shellminator-Websocket.cpp.

◆ attachDisconnectCallback()

void ShellminatorWebSocket::attachDisconnectCallback ( void(*)(ShellminatorWebSocket *)  disconnectCallback_p)

Definition at line 701 of file Shellminator-Websocket.cpp.

◆ available()

int ShellminatorWebSocket::available ( )
override

Available bytes in the channel.

Returns
The available bytes in the channel.

Definition at line 631 of file Shellminator-Websocket.cpp.

◆ begin()

void ShellminatorWebSocket::begin ( )

Definition at line 64 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ closeClient()

void ShellminatorWebSocket::closeClient ( bool  sendCloseFrame = false)
private

Definition at line 611 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finishDecoding()

void ShellminatorWebSocket::finishDecoding ( )
private

Definition at line 245 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flush()

void ShellminatorWebSocket::flush ( )
override

Flush the channel.

Definition at line 672 of file Shellminator-Websocket.cpp.

◆ generateServerKey()

bool ShellminatorWebSocket::generateServerKey ( )
private

Definition at line 583 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ peek()

int ShellminatorWebSocket::peek ( )
override

Peek the firtst byte from the channel.

Returns
Read and return one byte form the channel. The byte will NOT be removed from the channel.

Definition at line 662 of file Shellminator-Websocket.cpp.

◆ read()

int ShellminatorWebSocket::read ( )
override

Read one byte form the channel.

Returns
Read and return one byte form the channel. The byte will be removed from the channel.

Definition at line 644 of file Shellminator-Websocket.cpp.

◆ resetDataVariables()

void ShellminatorWebSocket::resetDataVariables ( )
private

Definition at line 229 of file Shellminator-Websocket.cpp.

Here is the caller graph for this function:

◆ resetVariables()

void ShellminatorWebSocket::resetVariables ( )
private

Definition at line 213 of file Shellminator-Websocket.cpp.

Here is the caller graph for this function:

◆ sendFrame()

bool ShellminatorWebSocket::sendFrame ( ShellminatorWebSocket::wsDecodedHeaderType_t  type,
const uint8_t *  data = NULL,
uint32_t  dataSize = 0 
)
private

Definition at line 97 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendFrame125()

bool ShellminatorWebSocket::sendFrame125 ( ShellminatorWebSocket::wsDecodedHeaderType_t  type,
const uint8_t *  data = NULL,
uint8_t  dataSize = 0 
)
private

Definition at line 117 of file Shellminator-Websocket.cpp.

Here is the caller graph for this function:

◆ update()

void ShellminatorWebSocket::update ( )

Definition at line 161 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:

◆ write() [1/2]

size_t ShellminatorWebSocket::write ( const uint8_t *  data,
size_t  size 
)
override

Definition at line 687 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:

◆ write() [2/2]

size_t ShellminatorWebSocket::write ( uint8_t  b)
override

Write one byte to the channel.

Parameters
bThe value that has to be written to the channel.
Returns
The number of bytes that has been successfully written to the channel. Because it is the base class, it returns 0.

Definition at line 677 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:

◆ wsDataProcessing()

void ShellminatorWebSocket::wsDataProcessing ( char  newChar)
private

Definition at line 272 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wsHeaderProcessing()

void ShellminatorWebSocket::wsHeaderProcessing ( char  newChar)
private

Definition at line 406 of file Shellminator-Websocket.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ client

WiFiClient ShellminatorWebSocket::client
private

Definition at line 156 of file Shellminator-Websocket.hpp.

◆ clientBuffer

char ShellminatorWebSocket::clientBuffer[SHELLMINATOR_WS_CLIENT_BUFFER_SIZE+1]
private

Definition at line 162 of file Shellminator-Websocket.hpp.

◆ clientBufferCounter

int ShellminatorWebSocket::clientBufferCounter = 0
private

Definition at line 163 of file Shellminator-Websocket.hpp.

◆ clientConnected

bool ShellminatorWebSocket::clientConnected = false
private

Definition at line 152 of file Shellminator-Websocket.hpp.

◆ clientKey

char ShellminatorWebSocket::clientKey[SHELLMINATOR_WS_CLIENT_KEY_SIZE]
private

Definition at line 167 of file Shellminator-Websocket.hpp.

◆ clientLineNameBuffer

char ShellminatorWebSocket::clientLineNameBuffer[SHELLMINATOR_WS_CLIENT_LINE_NAME_SIZE]
private

Definition at line 165 of file Shellminator-Websocket.hpp.

◆ clientLineValueBuffer

char ShellminatorWebSocket::clientLineValueBuffer[SHELLMINATOR_WS_CLIENT_LINE_VALUE_SIZE]
private

Definition at line 166 of file Shellminator-Websocket.hpp.

◆ clientVersion

int ShellminatorWebSocket::clientVersion
private

Definition at line 191 of file Shellminator-Websocket.hpp.

◆ connectCallback

void(* ShellminatorWebSocket::connectCallback) (ShellminatorWebSocket *parent) = NULL
private

Definition at line 203 of file Shellminator-Websocket.hpp.

◆ connectionUpgradeLineFound

bool ShellminatorWebSocket::connectionUpgradeLineFound
private

Definition at line 189 of file Shellminator-Websocket.hpp.

◆ dbg

Stream* ShellminatorWebSocket::dbg = NULL
private

Definition at line 153 of file Shellminator-Websocket.hpp.

◆ decodedDataXorCntr

uint8_t ShellminatorWebSocket::decodedDataXorCntr
private

Definition at line 199 of file Shellminator-Websocket.hpp.

◆ decodedHdrFin

bool ShellminatorWebSocket::decodedHdrFin
private

Definition at line 193 of file Shellminator-Websocket.hpp.

◆ decodedHdrMask

bool ShellminatorWebSocket::decodedHdrMask
private

Definition at line 195 of file Shellminator-Websocket.hpp.

◆ decodedHdrMaskKeys

uint8_t ShellminatorWebSocket::decodedHdrMaskKeys[4]
private

Definition at line 197 of file Shellminator-Websocket.hpp.

◆ decodedHdrPayloadCntr

uint8_t ShellminatorWebSocket::decodedHdrPayloadCntr
private

Definition at line 198 of file Shellminator-Websocket.hpp.

◆ decodedHdrPayloadLen

uint8_t ShellminatorWebSocket::decodedHdrPayloadLen
private

Definition at line 196 of file Shellminator-Websocket.hpp.

◆ decodedHdrType

wsDecodedHeaderType_t ShellminatorWebSocket::decodedHdrType
private

Definition at line 194 of file Shellminator-Websocket.hpp.

◆ disconnectCallback

void(* ShellminatorWebSocket::disconnectCallback) (ShellminatorWebSocket *parent) = NULL
private

Definition at line 204 of file Shellminator-Websocket.hpp.

◆ httpGetLineFound

bool ShellminatorWebSocket::httpGetLineFound
private

Definition at line 188 of file Shellminator-Websocket.hpp.

◆ port

int ShellminatorWebSocket::port = 443
private

Definition at line 151 of file Shellminator-Websocket.hpp.

◆ server

WiFiServer* ShellminatorWebSocket::server
private

Definition at line 155 of file Shellminator-Websocket.hpp.

◆ serverHeader

const char * ShellminatorWebSocket::serverHeader
staticprivate
Initial value:
=
"HTTP/1.1 101 Switching Protocols\r\n"
"Server: Shellminator\r\n"
"Upgrade: websocket\r\n"
"Connection: Upgrade\r\n"
"Sec-WebSocket-Version: 13\r\n"
"Sec-WebSocket-Accept: "

Definition at line 170 of file Shellminator-Websocket.hpp.

◆ serverKey

char ShellminatorWebSocket::serverKey[SHELLMINATOR_WS_SERVER_KEY_SIZE]
private

Definition at line 168 of file Shellminator-Websocket.hpp.

◆ streamBuffer

uint8_t ShellminatorWebSocket::streamBuffer[SHELLMINATOR_WS_STREAM_BUFFER_SIZE]
private

Definition at line 158 of file Shellminator-Websocket.hpp.

◆ streamBufferReadPointer

uint32_t ShellminatorWebSocket::streamBufferReadPointer
private

Definition at line 160 of file Shellminator-Websocket.hpp.

◆ streamBufferWritePointer

uint32_t ShellminatorWebSocket::streamBufferWritePointer
private

Definition at line 159 of file Shellminator-Websocket.hpp.

◆ upgradeWebsocketLineFound

bool ShellminatorWebSocket::upgradeWebsocketLineFound
private

Definition at line 190 of file Shellminator-Websocket.hpp.

◆ wsState

wsState_t ShellminatorWebSocket::wsState
private

Definition at line 201 of file Shellminator-Websocket.hpp.