memset(&wstp->ws, 0, sizeof(wstp->ws));
- if (ws_init(&wstp->ws, socket, wstp->ws_secure ? wspri->ssl_ctx : NULL, 0, 0) < 0) {
+ if (ws_init(&wstp->ws, socket, wstp->ws_secure ? wspri->ssl_ctx : NULL, 0, 0, 0) < 0) {
ws_destroy(&wstp->ws);
wstp->ws_initialized = -1;
return *return_reason = "WS_INIT", -1;
#include "ws.h"
#include <pthread.h>
-#ifdef _MSC_VER
-/* warning C4706: assignment within conditional expression*/
-#pragma warning(disable: 4706)
-#endif
-
#ifndef _MSC_VER
#include <fcntl.h>
#endif
goto err;
}
- *(wsh->buffer+bytes) = '\0';
+ *(wsh->buffer + wsh->datalen) = '\0';
if (strncasecmp(wsh->buffer, "GET ", 4)) {
goto err;
err:
- snprintf(respond, sizeof(respond), "HTTP/1.1 400 Bad Request\r\n"
- "Sec-WebSocket-Version: 13\r\n\r\n");
+ if (!wsh->stay_open) {
- //printf("ERR:\n%s\n", respond);
+ snprintf(respond, sizeof(respond), "HTTP/1.1 400 Bad Request\r\n"
+ "Sec-WebSocket-Version: 13\r\n\r\n");
+ ws_raw_write(wsh, respond, strlen(respond));
- ws_raw_write(wsh, respond, strlen(respond));
-
- ws_close(wsh, WS_NONE);
+ ws_close(wsh, WS_NONE);
+ }
return -1;
}
-int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block)
+int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block, int stay_open)
{
memset(wsh, 0, sizeof(*wsh));
wsh->block = block;
wsh->sanity = 5000;
wsh->ssl_ctx = ssl_ctx;
+ wsh->stay_open = stay_open;
if (!ssl_ctx) {
ssl_ctx = ws_globals.ssl_ctx;
int sanity;
int secure_established;
int logical_established;
+ int stay_open;
int x;
void *write_buffer;
size_t write_buffer_len;
ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes);
ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data);
ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes);
-int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block);
+int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block, int stay_open);
ssize_t ws_close(wsh_t *wsh, int16_t reason);
void ws_destroy(wsh_t *wsh);
void init_ssl(void);