diff --git a/CMakeLists.txt b/CMakeLists.txt index 573bc5fbf..817dec9e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake/lws_config.h.in b/cmake/lws_config.h.in index d95ab4a9e..2719640da 100644 --- a/cmake/lws_config.h.in +++ b/cmake/lws_config.h.in @@ -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 diff --git a/lib/core-net/close.c b/lib/core-net/close.c index 91cae6a67..cd6e218ab 100644 --- a/lib/core-net/close.c +++ b/lib/core-net/close.c @@ -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; diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index 705f1c006..1fa67a97b 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -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; } diff --git a/lib/roles/h1/ops-h1.c b/lib/roles/h1/ops-h1.c index 1ff208480..bc9de63d0 100644 --- a/lib/roles/h1/ops-h1.c +++ b/lib/roles/h1/ops-h1.c @@ -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; diff --git a/lib/roles/http/client/client-http.c b/lib/roles/http/client/client-http.c index fc130e5f0..e158901fa 100644 --- a/lib/roles/http/client/client-http.c +++ b/lib/roles/http/client/client-http.c @@ -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"); diff --git a/lib/roles/http/parsers.c b/lib/roles/http/parsers.c index 94e8490bd..05ab70405 100644 --- a/lib/roles/http/parsers.c +++ b/lib/roles/http/parsers.c @@ -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++) diff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c index 61408bdb6..13ce89ab0 100644 --- a/lib/roles/ws/ops-ws.c +++ b/lib/roles/ws/ops-ws.c @@ -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) {