web_socket_misc.h
Go to the documentation of this file.
1 /**
2  * @file web_socket_misc.h
3  * @brief Helper functions for WebSockets
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _WEB_SOCKET_MISC_H
30 #define _WEB_SOCKET_MISC_H
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "web_socket/web_socket.h"
35 
36 //C++ guard
37 #ifdef __cplusplus
38  extern "C" {
39 #endif
40 
41 
42 /**
43  * @brief HTTP status code
44  **/
45 
46 typedef struct
47 {
49  const char_t message[28];
51 
52 
53 //WebSocket related functions
54 void webSocketChangeState(WebSocket *webSocket, WebSocketState newState);
55 
60 
62 
63 error_t webSocketFormatClientHandshake(WebSocket *webSocket, uint16_t serverPort);
65 
68 
71 
74 
77 
79 
81  char_t *output, size_t outputSize);
82 
84  const uint8_t *data, size_t length, size_t remaining);
85 
86 //C++ guard
87 #ifdef __cplusplus
88  }
89 #endif
90 
91 #endif
error_t webSocketVerifyClientKey(WebSocket *webSocket)
Verify client's key.
char char_t
Definition: compiler_port.h:41
error_t webSocketFormatServerHandshake(WebSocket *webSocket)
Format server's handshake.
bool_t webSocketCheckStatusCode(uint16_t statusCode)
Check whether a status code is valid.
TCP/IP stack core.
WebSocketState
WebSocket states.
Definition: web_socket.h:222
error_t webSocketFormatErrorResponse(WebSocket *webSocket, uint_t statusCode, const char_t *message)
Format HTTP error response.
#define WebSocket
Definition: web_socket.h:175
uint8_t message[]
Definition: chap.h:150
UTF-8 decoding context.
Definition: web_socket.h:412
void webSocketChangeState(WebSocket *webSocket, WebSocketState newState)
Update WebSocket state.
uint16_t statusCode
error_t webSocketFormatClientHandshake(WebSocket *webSocket, uint16_t serverPort)
Format client's handshake.
error_t webSocketGenerateServerKey(WebSocket *webSocket)
Generate server's key.
HTTP status code.
error_t webSocketVerifyServerHandshake(WebSocket *webSocket)
Verify server's handshake.
error_t webSocketParseHeaderField(WebSocket *webSocket, char_t *line)
Parse a header field.
bool_t webSocketCheckUtf8Stream(WebSocketUtf8Context *context, const uint8_t *data, size_t length, size_t remaining)
Check whether a an UTF-8 stream is valid.
error_t webSocketParseHandshake(WebSocket *webSocket)
Parse client or server handshake.
error_t webSocketVerifyClientHandshake(WebSocket *webSocket)
Verify client's handshake.
error_t webSocketParseStatusLine(WebSocket *webSocket, char_t *line)
Parse the Status-Line of the server's handshake.
error_t webSocketDecodePercentEncodedString(const char_t *input, char_t *output, size_t outputSize)
Decode a percent-encoded string.
void webSocketParseConnectionField(WebSocket *webSocket, char_t *value)
Parse Connection header field.
error_t
Error codes.
Definition: error.h:40
unsigned int uint_t
Definition: compiler_port.h:43
error_t webSocketParseRequestLine(WebSocket *webSocket, char_t *line)
Parse the Request-Line of the client's handshake.
uint8_t data[]
Definition: dtls_misc.h:167
uint8_t value[]
Definition: dtls_misc.h:141
error_t webSocketVerifyServerKey(WebSocket *webSocket)
Verify server's key.
error_t webSocketGenerateClientKey(WebSocket *webSocket)
Generate client's key.
uint8_t length
Definition: dtls_misc.h:140
int bool_t
Definition: compiler_port.h:47
WebSocket API (client and server)