diff --git a/CMakeLists.txt b/CMakeLists.txt index cd731345a..826827f37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -669,7 +669,7 @@ if (LWS_WITH_LIBUV) CHECK_INCLUDE_FILE(uv-version.h LWS_HAVE_UV_VERSION_H) # libuv changed the location in 1.21.0. Retain both # checks temporarily to ensure a smooth transition. - if(NOT LWS_HAVE_UV_VERSION_H) + if (NOT LWS_HAVE_UV_VERSION_H) CHECK_INCLUDE_FILE(uv/version.h LWS_HAVE_NEW_UV_VERSION_H) endif() endif() @@ -1795,6 +1795,9 @@ if ((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS) INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins" ) + SET_TARGET_PROPERTIES(${PLUGIN_NAME} + PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS}) + # set_target_properties(${PLUGIN_NAME} # PROPERTIES # OUTPUT_NAME ${PLUGIN_NAME}) diff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c index ffdcffc43..0104fbc6c 100644 --- a/lib/core/libwebsockets.c +++ b/lib/core/libwebsockets.c @@ -2733,6 +2733,27 @@ lws_json_purify(char *escaped, const char *string, int len) } while (*p && len-- > 6) { + if (*p == '\t') { + p++; + *q++ = '\\'; + *q++ = 't'; + continue; + } + + if (*p == '\n') { + p++; + *q++ = '\\'; + *q++ = 'n'; + continue; + } + + if (*p == '\r') { + p++; + *q++ = '\\'; + *q++ = 'r'; + continue; + } + if (*p == '\"' || *p == '\\' || *p < 0x20) { *q++ = '\\'; *q++ = 'u'; diff --git a/lib/core/private.h b/lib/core/private.h index fd69e3023..28b310c15 100644 --- a/lib/core/private.h +++ b/lib/core/private.h @@ -1320,7 +1320,7 @@ lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len); LWS_EXTERN int lws_access_log(struct lws *wsi); LWS_EXTERN void -lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int meth); +lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int len, int meth); #else #define lws_access_log(_a) #endif diff --git a/lib/event-libs/libuv/libuv.c b/lib/event-libs/libuv/libuv.c index 502dd1886..ec37e09e8 100644 --- a/lib/event-libs/libuv/libuv.c +++ b/lib/event-libs/libuv/libuv.c @@ -442,6 +442,8 @@ lws_plat_plugins_destroy(struct lws_context *context) void *v; int m; +// return 0; + #if defined(__MINGW32__) || !defined(WIN32) pofs = 3; #endif diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index b1abe0ce8..ad074ec30 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -4101,7 +4101,7 @@ LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx); /** - * lws_hdr_copy() - copy a single fragment of the given header to a buffer + * lws_hdr_copy() - copy all fragments of the given header to a buffer * The buffer length len must include space for an additional * terminating '\0', or it will fail returning -1. * @@ -4111,7 +4111,8 @@ lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx) * \param h: which header index we are interested in * * copies the whole, aggregated header, even if it was delivered in - * several actual headers piece by piece + * several actual headers piece by piece. Returns -1 or length of the whole + * header. */ LWS_VISIBLE LWS_EXTERN int lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h); diff --git a/lib/roles/h2/http2.c b/lib/roles/h2/http2.c index 4e71adc45..5ade1c7f3 100644 --- a/lib/roles/h2/http2.c +++ b/lib/roles/h2/http2.c @@ -2073,7 +2073,7 @@ lws_h2_client_handshake(struct lws *wsi) if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_COLON_SCHEME, - (unsigned char *)"http", 4, + (unsigned char *)"https", 4, &p, end)) goto fail_length; diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index b84dac1d6..bc9513787 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -319,7 +319,7 @@ create_new_conn: } #endif } else { - lwsl_err("getaddrinfo failed\n"); + lwsl_err("getaddrinfo failed: %d\n", n); cce = "getaddrinfo failed"; goto oom4; } diff --git a/lib/roles/http/server/access-log.c b/lib/roles/http/server/access-log.c index 0e75309d7..dc016a5be 100644 --- a/lib/roles/http/server/access-log.c +++ b/lib/roles/http/server/access-log.c @@ -38,14 +38,14 @@ static const char * const hver[] = { }; void -lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int meth) +lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int meth) { #ifdef LWS_WITH_IPV6 char ads[INET6_ADDRSTRLEN]; #else char ads[INET_ADDRSTRLEN]; #endif - char da[64]; + char da[64], uri[256]; const char *pa, *me; struct tm *tmp; time_t t = time(NULL); @@ -81,11 +81,20 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int meth) if (!me) me = "(null)"; + m = uri_len; + if (m > (int)sizeof(uri) - 1) + m = sizeof(uri) - 1; + + strncpy(uri, uri_ptr, m); + uri[m] = '\0'; + lws_snprintf(wsi->http.access_log.header_log, l, "%s - - [%s] \"%s %s %s\"", - pa, da, me, uri_ptr, + pa, da, me, uri, hver[wsi->http.request_version]); + lwsl_notice("%s\n", wsi->http.access_log.header_log); + l = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_USER_AGENT); if (l) { wsi->http.access_log.user_agent = lws_malloc(l + 2, "access log"); diff --git a/lib/roles/http/server/parsers.c b/lib/roles/http/server/parsers.c index 82cf5ba76..62778b8a0 100644 --- a/lib/roles/http/server/parsers.c +++ b/lib/roles/http/server/parsers.c @@ -599,7 +599,8 @@ issue_char(struct lws *wsi, unsigned char c) * If we haven't hit the token limit, just copy the character into * the header */ - if (frag_len < wsi->http.ah->current_token_limit) { + if (!wsi->http.ah->current_token_limit || + frag_len < wsi->http.ah->current_token_limit) { wsi->http.ah->data[wsi->http.ah->pos++] = c; if (c) wsi->http.ah->frags[wsi->http.ah->nfrag].len++; diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index 9377f18bb..147d0d6d6 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -1001,7 +1001,7 @@ lws_http_action(struct lws *wsi) #endif #ifdef LWS_WITH_ACCESS_LOG - lws_prepare_access_log_info(wsi, uri_ptr, meth); + lws_prepare_access_log_info(wsi, uri_ptr, uri_len, meth); #endif /* can we serve it from the mount list? */ @@ -1292,7 +1292,7 @@ lws_http_action(struct lws *wsi) } #endif - n = (int)strlen(s); + n = uri_len - (s - uri_ptr); // (int)strlen(s); if (s[0] == '\0' || (n == 1 && s[n - 1] == '/')) s = (char *)hit->def; if (!s) @@ -1548,7 +1548,7 @@ raw_transition: &uri_ptr, &uri_len); if (meth >= 0) lws_prepare_access_log_info(wsi, - uri_ptr, meth); + uri_ptr, uri_len, meth); /* wsi close will do the log */ #endif @@ -1714,7 +1714,7 @@ lws_http_transaction_completed(struct lws *wsi) /* if we can't go back to accept new headers, drop the connection */ if (wsi->http2_substream) - return 0; + return 1; if (wsi->seen_zero_length_recv) return 1; diff --git a/lwsws/main.c b/lwsws/main.c index fba948ef6..2055d774b 100644 --- a/lwsws/main.c +++ b/lwsws/main.c @@ -208,7 +208,7 @@ reload_handler(int signum) int main(int argc, char **argv) { - int n = 0, budget = 100, debug_level = 7; + int n = 0, budget = 100, debug_level = 1024 + 7; #ifndef _WIN32 int m; int status, syslog_options = LOG_PID | LOG_PERROR; diff --git a/plugins/protocol_lws_sshd_demo.c b/plugins/protocol_lws_sshd_demo.c index 1590416f4..bca536bb8 100644 --- a/plugins/protocol_lws_sshd_demo.c +++ b/plugins/protocol_lws_sshd_demo.c @@ -415,6 +415,9 @@ callback_lws_sshd_demo(struct lws *wsi, enum lws_callback_reasons reason, case LWS_CALLBACK_VHOST_CERT_AGING: break; + case LWS_CALLBACK_EVENT_WAIT_CANCELLED: + break; + default: if (!vhd->ssh_base_protocol) { vhd->ssh_base_protocol = lws_vhost_name_to_protocol( diff --git a/test-apps/.gitignore b/test-apps/.gitignore deleted file mode 100644 index 53ba6cb40..000000000 --- a/test-apps/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -#Ignore build files -libwebsockets-test-* -Makefile -*.o -*.lo -*.la -.libs -.deps -