Implement HTTP/2 and WebSocket support; remove legacy JavaScript and CSS files
- Added HTTP/2 support in src/http2.c and src/http2.h, including session management, frame handling, and response sending. - Introduced WebSocket functionality in src/websocket.c and src/websocket.h, covering handshake, frame parsing, and message sending. - Created a WebSocket test page (www/websocket-test.html) for client-side interaction. - Removed outdated JavaScript (www/script.js) and CSS (www/style.css) files.
This commit is contained in:
47
src/websocket.h
Normal file
47
src/websocket.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef WEBSOCKET_H
|
||||
#define WEBSOCKET_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
// WebSocket opcodes
|
||||
#define WS_OPCODE_CONTINUATION 0x0
|
||||
#define WS_OPCODE_TEXT 0x1
|
||||
#define WS_OPCODE_BINARY 0x2
|
||||
#define WS_OPCODE_CLOSE 0x8
|
||||
#define WS_OPCODE_PING 0x9
|
||||
#define WS_OPCODE_PONG 0xA
|
||||
|
||||
// WebSocket frame header structure
|
||||
typedef struct {
|
||||
uint8_t fin;
|
||||
uint8_t opcode;
|
||||
uint8_t mask;
|
||||
uint64_t payload_length;
|
||||
uint8_t masking_key[4];
|
||||
} ws_frame_header_t;
|
||||
|
||||
// WebSocket connection context
|
||||
typedef struct {
|
||||
int socket_fd;
|
||||
SSL *ssl;
|
||||
bool is_ssl;
|
||||
bool handshake_complete;
|
||||
} ws_connection_t;
|
||||
|
||||
// Function prototypes
|
||||
int ws_handle_handshake(int client_socket, const char *request, char *response, size_t response_size);
|
||||
int ws_handle_handshake_ssl(SSL *ssl, const char *request, char *response, size_t response_size);
|
||||
int ws_parse_frame(const uint8_t *data, size_t len, ws_frame_header_t *header, uint8_t **payload);
|
||||
int ws_create_frame(uint8_t *buffer, size_t buffer_size, uint8_t opcode, const uint8_t *payload, size_t payload_len);
|
||||
int ws_send_frame(ws_connection_t *conn, uint8_t opcode, const uint8_t *payload, size_t payload_len);
|
||||
int ws_send_text(ws_connection_t *conn, const char *text);
|
||||
int ws_send_pong(ws_connection_t *conn, const uint8_t *payload, size_t payload_len);
|
||||
void ws_close_connection(ws_connection_t *conn, uint16_t status_code);
|
||||
|
||||
// Helper functions
|
||||
char* ws_generate_accept_key(const char *client_key);
|
||||
bool ws_is_valid_utf8(const uint8_t *data, size_t len);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user