1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

rtos diet: make raw_file role optional

This commit is contained in:
Andy Green 2020-02-28 15:50:15 +00:00
parent 3c663da99e
commit ed04a266ea
8 changed files with 43 additions and 20 deletions

View file

@ -30,6 +30,7 @@ option(LWS_ROLE_H1 "Compile with support for http/1 (needed for ws)" ON)
option(LWS_ROLE_WS "Compile with support for websockets" ON)
option(LWS_ROLE_DBUS "Compile with support for DBUS" OFF)
option(LWS_ROLE_RAW_PROXY "Raw packet proxy" OFF)
option(LWS_ROLE_RAW_FILE "Compile with support for raw files" ON)
option(LWS_WITH_HTTP2 "Compile with server support for HTTP/2" ON)
option(LWS_WITH_LWSWS "Libwebsockets Webserver" OFF)
option(LWS_WITH_CGI "Include CGI (spawn process with network-connected stdin/out/err) APIs" OFF)
@ -1208,8 +1209,10 @@ endif()
if (LWS_ROLE_RAW)
list(APPEND SOURCES
lib/roles/raw-skt/ops-raw-skt.c
lib/roles/raw-file/ops-raw-file.c)
lib/roles/raw-skt/ops-raw-skt.c)
if (LWS_ROLE_RAW_FILE)
list(APPEND SOURCES lib/roles/raw-file/ops-raw-file.c)
endif()
if (LWS_WITH_ABSTRACT)
list(APPEND SOURCES

View file

@ -91,6 +91,7 @@
#cmakedefine LWS_ROLE_H1
#cmakedefine LWS_ROLE_H2
#cmakedefine LWS_ROLE_RAW
#cmakedefine LWS_ROLE_RAW_FILE
#cmakedefine LWS_ROLE_RAW_PROXY
#cmakedefine LWS_ROLE_WS
#cmakedefine LWS_SHA1_USE_OPENSSL_NAME

View file

@ -282,6 +282,7 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason,
wsi->child_list = NULL;
}
#if defined(LWS_ROLE_RAW_FILE)
if (wsi->role_ops == &role_ops_raw_file) {
lws_remove_child_from_any_parent(wsi);
__remove_wsi_socket_from_fds(wsi);
@ -290,6 +291,7 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason,
wsi->user_space, NULL, 0);
goto async_close;
}
#endif
wsi->wsistate_pre_close = wsi->wsistate;
@ -598,7 +600,9 @@ just_kill_connection:
wsi->told_user_closed = 1;
}
#if defined(LWS_ROLE_RAW_FILE)
async_close:
#endif
lws_remove_child_from_any_parent(wsi);
wsi->socket_is_permanently_unusable = 1;

View file

@ -89,8 +89,10 @@ lws_role_by_name(const char *name)
if (!strcmp(name, role_ops_raw_skt.name))
return &role_ops_raw_skt;
#if defined(LWS_ROLE_RAW_FILE)
if (!strcmp(name, role_ops_raw_file.name))
return &role_ops_raw_file;
#endif
return NULL;
}
@ -170,11 +172,14 @@ lws_role_call_adoption_bind(struct lws *wsi, int type, const char *prot)
role_ops_raw_skt.adoption_bind(wsi, type, prot))
return 0;
#if defined(LWS_ROLE_RAW_FILE)
/* fall back to raw file role if, eg, h1 not configured */
if (role_ops_raw_file.adoption_bind &&
role_ops_raw_file.adoption_bind(wsi, type, prot))
return 0;
#endif
return 1;
}

View file

@ -80,8 +80,12 @@ lws_read_h1(struct lws *wsi, unsigned char *buf, lws_filepos_t len)
goto bail;
/* we might have transitioned to RAW */
if (wsi->role_ops == &role_ops_raw_skt ||
wsi->role_ops == &role_ops_raw_file)
if (wsi->role_ops == &role_ops_raw_skt
#if defined(LWS_ROLE_RAW_FILE)
||
wsi->role_ops == &role_ops_raw_file
#endif
)
/* we gave the read buffer to RAW handler already */
goto read_ok;

View file

@ -228,8 +228,11 @@ start_ws_handshake:
case LRS_H1C_ISSUE_HANDSHAKE2:
p = lws_generate_client_handshake(wsi, p);
if (p == NULL) {
if (wsi->role_ops == &role_ops_raw_skt ||
wsi->role_ops == &role_ops_raw_file)
if (wsi->role_ops == &role_ops_raw_skt
#if defined(LWS_ROLE_RAW_FILE)
|| wsi->role_ops == &role_ops_raw_file
#endif
)
return 0;
lwsl_err("Failed to generate handshake for client\n");

View file

@ -24,7 +24,7 @@
#include "private-lib-core.h"
static const unsigned char lextable[] = {
static const unsigned char lextable_h1[] = {
#include "lextable.h"
};
@ -1169,27 +1169,27 @@ swallow:
break;
while (1) {
if (lextable[pos] & (1 << 7)) {
if (lextable_h1[pos] & (1 << 7)) {
/* 1-byte, fail on mismatch */
if ((lextable[pos] & 0x7f) != c) {
if ((lextable_h1[pos] & 0x7f) != c) {
nope:
ah->lextable_pos = -1;
break;
}
/* fall thru */
pos++;
if (lextable[pos] == FAIL_CHAR)
if (lextable_h1[pos] == FAIL_CHAR)
goto nope;
ah->lextable_pos = pos;
break;
}
if (lextable[pos] == FAIL_CHAR)
if (lextable_h1[pos] == FAIL_CHAR)
goto nope;
/* b7 = 0, end or 3-byte */
if (lextable[pos] < FAIL_CHAR) {
if (lextable_h1[pos] < FAIL_CHAR) {
#if defined(LWS_WITH_CUSTOM_HEADERS)
if (!wsi->mux_substream) {
/*
@ -1206,10 +1206,10 @@ nope:
break;
}
if (lextable[pos] == c) { /* goto */
if (lextable_h1[pos] == c) { /* goto */
ah->lextable_pos = pos +
(lextable[pos + 1]) +
(lextable[pos + 2] << 8);
(lextable_h1[pos + 1]) +
(lextable_h1[pos + 2] << 8);
break;
}
@ -1287,11 +1287,11 @@ nope:
break;
}
if (lextable[ah->lextable_pos] < FAIL_CHAR) {
if (lextable_h1[ah->lextable_pos] < FAIL_CHAR) {
/* terminal state */
n = ((unsigned int)lextable[ah->lextable_pos] << 8) |
lextable[ah->lextable_pos + 1];
n = ((unsigned int)lextable_h1[ah->lextable_pos] << 8) |
lextable_h1[ah->lextable_pos + 1];
lwsl_parser("known hdr %d\n", n);
for (m = 0; m < LWS_ARRAY_SIZE(methods); m++)

View file

@ -1366,8 +1366,11 @@ int rops_handle_POLLOUT_ws(struct lws *wsi)
*/
ret = 1;
if (wsi->role_ops == &role_ops_raw_skt ||
wsi->role_ops == &role_ops_raw_file)
if (wsi->role_ops == &role_ops_raw_skt
#if defined(LWS_ROLE_RAW_FILE)
|| wsi->role_ops == &role_ops_raw_file
#endif
)
ret = 0;
while (ret == 1) {