web_socket_misc.h File Reference

Helper functions for WebSockets. More...

#include "core/net.h"
#include "web_socket/web_socket.h"

Go to the source code of this file.

Data Structures

struct  WebSocketStatusCodeDesc
 HTTP status code. More...
 

Functions

void webSocketChangeState (WebSocket *webSocket, WebSocketState newState)
 Update WebSocket state. More...
 
error_t webSocketParseHandshake (WebSocket *webSocket)
 Parse client or server handshake. More...
 
error_t webSocketParseRequestLine (WebSocket *webSocket, char_t *line)
 Parse the Request-Line of the client's handshake. More...
 
error_t webSocketParseStatusLine (WebSocket *webSocket, char_t *line)
 Parse the Status-Line of the server's handshake. More...
 
error_t webSocketParseHeaderField (WebSocket *webSocket, char_t *line)
 Parse a header field. More...
 
void webSocketParseConnectionField (WebSocket *webSocket, char_t *value)
 Parse Connection header field. More...
 
error_t webSocketFormatClientHandshake (WebSocket *webSocket, uint16_t serverPort)
 Format client's handshake. More...
 
error_t webSocketFormatServerHandshake (WebSocket *webSocket)
 Format server's handshake. More...
 
error_t webSocketFormatErrorResponse (WebSocket *webSocket, uint_t statusCode, const char_t *message)
 Format HTTP error response. More...
 
error_t webSocketVerifyClientHandshake (WebSocket *webSocket)
 Verify client's handshake. More...
 
error_t webSocketVerifyServerHandshake (WebSocket *webSocket)
 Verify server's handshake. More...
 
error_t webSocketGenerateClientKey (WebSocket *webSocket)
 Generate client's key. More...
 
error_t webSocketGenerateServerKey (WebSocket *webSocket)
 Generate server's key. More...
 
error_t webSocketVerifyClientKey (WebSocket *webSocket)
 Verify client's key. More...
 
error_t webSocketVerifyServerKey (WebSocket *webSocket)
 Verify server's key. More...
 
bool_t webSocketCheckStatusCode (uint16_t statusCode)
 Check whether a status code is valid. More...
 
error_t webSocketDecodePercentEncodedString (const char_t *input, char_t *output, size_t outputSize)
 Decode a percent-encoded string. More...
 
bool_t webSocketCheckUtf8Stream (WebSocketUtf8Context *context, const uint8_t *data, size_t length, size_t remaining)
 Check whether a an UTF-8 stream is valid. More...
 

Detailed Description

Helper functions for WebSockets.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file web_socket_misc.h.

Function Documentation

◆ webSocketChangeState()

void webSocketChangeState ( WebSocket webSocket,
WebSocketState  newState 
)

Update WebSocket state.

Parameters
[in]webSocketHandle to a WebSocket
[in]newStateNew state to switch to

Definition at line 88 of file web_socket_misc.c.

◆ webSocketCheckStatusCode()

bool_t webSocketCheckStatusCode ( uint16_t  statusCode)

Check whether a status code is valid.

Parameters
[in]statusCodeStatus code
Returns
The function returns TRUE is the specified status code is valid. Otherwise, FALSE is returned

Definition at line 1146 of file web_socket_misc.c.

◆ webSocketCheckUtf8Stream()

bool_t webSocketCheckUtf8Stream ( WebSocketUtf8Context context,
const uint8_t *  data,
size_t  length,
size_t  remaining 
)

Check whether a an UTF-8 stream is valid.

Parameters
[in]contextUTF-8 decoding context
[in]dataPointer to the chunk of data to be processed
[in]lengthData chunk length
[in]remainingnumber of remaining bytes in the UTF-8 stream
Returns
The function returns TRUE is the specified UTF-8 stream is valid. Otherwise, FALSE is returned

Definition at line 1247 of file web_socket_misc.c.

◆ webSocketDecodePercentEncodedString()

error_t webSocketDecodePercentEncodedString ( const char_t input,
char_t output,
size_t  outputSize 
)

Decode a percent-encoded string.

Parameters
[in]inputNULL-terminated string to be decoded
[out]outputNULL-terminated string resulting from the decoding process
[in]outputSizeSize of the output buffer in bytes
Returns
Error code

Definition at line 1185 of file web_socket_misc.c.

◆ webSocketFormatClientHandshake()

error_t webSocketFormatClientHandshake ( WebSocket webSocket,
uint16_t  serverPort 
)

Format client's handshake.

Parameters
[in]webSocketHandle to a WebSocket
[in]serverPortTCP port number used to establish the connection
Returns
Error code

Definition at line 645 of file web_socket_misc.c.

◆ webSocketFormatErrorResponse()

error_t webSocketFormatErrorResponse ( WebSocket webSocket,
uint_t  statusCode,
const char_t message 
)

Format HTTP error response.

Parameters
[in]webSocketHandle to a WebSocket
[in]statusCodeHTTP status code
[in]messageUser message
Returns
Error code

Definition at line 783 of file web_socket_misc.c.

◆ webSocketFormatServerHandshake()

error_t webSocketFormatServerHandshake ( WebSocket webSocket)

Format server's handshake.

Parameters
[in]webSocketHandle to a WebSocket
Returns
Error code

Definition at line 731 of file web_socket_misc.c.

◆ webSocketGenerateClientKey()

error_t webSocketGenerateClientKey ( WebSocket webSocket)

Generate client's key.

Parameters
[in]webSocketHandle to a WebSocket
Returns
Error code

Definition at line 971 of file web_socket_misc.c.

◆ webSocketGenerateServerKey()

error_t webSocketGenerateServerKey ( WebSocket webSocket)

Generate server's key.

Parameters
[in]webSocketHandle to a WebSocket
Returns
Error code

Definition at line 1015 of file web_socket_misc.c.

◆ webSocketParseConnectionField()

void webSocketParseConnectionField ( WebSocket webSocket,
char_t value 
)

Parse Connection header field.

Parameters
[in]webSocketHandle to a WebSocket
[in]valueNULL-terminated string that contains the value of header field

Definition at line 601 of file web_socket_misc.c.

◆ webSocketParseHandshake()

error_t webSocketParseHandshake ( WebSocket webSocket)

Parse client or server handshake.

Parameters
[in]webSocketHandle to a WebSocket
Returns
Error code

Definition at line 107 of file web_socket_misc.c.

◆ webSocketParseHeaderField()

error_t webSocketParseHeaderField ( WebSocket webSocket,
char_t line 
)

Parse a header field.

Parameters
[in]webSocketHandle to a WebSocket
[in]lineNULL-terminated string that contains the header field
Returns
Error code

Definition at line 514 of file web_socket_misc.c.

◆ webSocketParseRequestLine()

error_t webSocketParseRequestLine ( WebSocket webSocket,
char_t line 
)

Parse the Request-Line of the client's handshake.

Parameters
[in]webSocketHandle to a WebSocket
[in]lineNULL-terminated string that contains the Request-Line
Returns
Error code

Definition at line 368 of file web_socket_misc.c.

◆ webSocketParseStatusLine()

error_t webSocketParseStatusLine ( WebSocket webSocket,
char_t line 
)

Parse the Status-Line of the server's handshake.

Parameters
[in]webSocketHandle to a WebSocket
[in]lineNULL-terminated string that contains the Status-Line
Returns
Error code

Definition at line 476 of file web_socket_misc.c.

◆ webSocketVerifyClientHandshake()

error_t webSocketVerifyClientHandshake ( WebSocket webSocket)

Verify client's handshake.

Parameters
[in]webSocketHandle to a WebSocket
Returns
Error code

Definition at line 859 of file web_socket_misc.c.

◆ webSocketVerifyClientKey()

error_t webSocketVerifyClientKey ( WebSocket webSocket)

Verify client's key.

Parameters
[in]webSocketHandle to a WebSocket
Returns
Error code

Definition at line 1055 of file web_socket_misc.c.

◆ webSocketVerifyServerHandshake()

error_t webSocketVerifyServerHandshake ( WebSocket webSocket)

Verify server's handshake.

Parameters
[in]webSocketHandle to a WebSocket
Returns
Error code

Definition at line 908 of file web_socket_misc.c.

◆ webSocketVerifyServerKey()

error_t webSocketVerifyServerKey ( WebSocket webSocket)

Verify server's key.

Parameters
[in]webSocketHandle to a WebSocket
Returns
Error code

Definition at line 1096 of file web_socket_misc.c.