mirror of
https://github.com/tsl0922/ttyd.git
synced 2025-12-25 05:04:19 +01:00
all: remove the vla usage
This commit is contained in:
@@ -17,7 +17,7 @@ if(GIT_FOUND)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -Wvla")
|
||||
if(CMAKE_VERSION VERSION_LESS "3.1")
|
||||
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
|
||||
|
||||
@@ -18,8 +18,7 @@ static size_t html_cache_len = 0;
|
||||
static int check_auth(struct lws *wsi, struct pss_http *pss) {
|
||||
if (server->credential == NULL) return AUTH_OK;
|
||||
|
||||
int hdr_length = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_AUTHORIZATION);
|
||||
char buf[hdr_length + 1];
|
||||
char buf[256];
|
||||
int len = lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_HTTP_AUTHORIZATION);
|
||||
if (len > 0) {
|
||||
// extract base64 text from authorization header
|
||||
@@ -59,8 +58,7 @@ static int check_auth(struct lws *wsi, struct pss_http *pss) {
|
||||
}
|
||||
|
||||
static bool accept_gzip(struct lws *wsi) {
|
||||
int hdr_length = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_ACCEPT_ENCODING);
|
||||
char buf[hdr_length + 1];
|
||||
char buf[256];
|
||||
int len = lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_HTTP_ACCEPT_ENCODING);
|
||||
return len > 0 && strstr(buf, "gzip") != NULL;
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@ static json_object* parse_window_size(const char *buf, size_t len, uint16_t *col
|
||||
}
|
||||
|
||||
static bool check_host_origin(struct lws *wsi) {
|
||||
int origin_length = lws_hdr_total_length(wsi, WSI_TOKEN_ORIGIN);
|
||||
char buf[origin_length + 1];
|
||||
char buf[256];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
int len = lws_hdr_copy(wsi, buf, (int) sizeof(buf), WSI_TOKEN_ORIGIN);
|
||||
if (len <= 0) {
|
||||
@@ -67,9 +66,7 @@ static bool check_host_origin(struct lws *wsi) {
|
||||
sprintf(buf, "%s:%d", address, port);
|
||||
}
|
||||
|
||||
int host_length = lws_hdr_total_length(wsi, WSI_TOKEN_HOST);
|
||||
if (host_length != strlen(buf)) return false;
|
||||
char host_buf[host_length + 1];
|
||||
char host_buf[256];
|
||||
memset(host_buf, 0, sizeof(host_buf));
|
||||
len = lws_hdr_copy(wsi, host_buf, (int) sizeof(host_buf), WSI_TOKEN_HOST);
|
||||
|
||||
@@ -100,7 +97,7 @@ static void process_exit_cb(void *ctx, pty_process *process) {
|
||||
|
||||
static bool spawn_process(struct pss_tty *pss, uint16_t columns, uint16_t rows) {
|
||||
// append url args to arguments
|
||||
char *argv[server->argc + pss->argc + 1];
|
||||
char **argv = xmalloc((server->argc + pss->argc + 1) * sizeof(char *));
|
||||
int i, n = 0;
|
||||
for (i = 0; i < server->argc; i++) {
|
||||
argv[n++] = server->argv[i];
|
||||
@@ -127,8 +124,8 @@ static bool spawn_process(struct pss_tty *pss, uint16_t columns, uint16_t rows)
|
||||
|
||||
static void wsi_output(struct lws *wsi, pty_buf_t *buf) {
|
||||
if (buf == NULL) return;
|
||||
char message[LWS_PRE + 1 + buf->len];
|
||||
char *ptr= &message[LWS_PRE];
|
||||
char *message = xmalloc(LWS_PRE + 1 + buf->len);
|
||||
char *ptr= message + LWS_PRE;
|
||||
|
||||
*ptr = OUTPUT;
|
||||
memcpy(ptr + 1, buf->base, buf->len);
|
||||
@@ -137,6 +134,8 @@ static void wsi_output(struct lws *wsi, pty_buf_t *buf) {
|
||||
if (lws_write(wsi, (unsigned char *) ptr, n, LWS_WRITE_BINARY) < n) {
|
||||
lwsl_err("write OUTPUT to WS\n");
|
||||
}
|
||||
|
||||
free(message);
|
||||
}
|
||||
|
||||
int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in,
|
||||
|
||||
@@ -117,6 +117,7 @@ void process_free(pty_process *process) {
|
||||
uv_thread_join(&process->tid);
|
||||
#endif
|
||||
if (process->io != NULL) pty_io_free(process->io);
|
||||
if (process->argv != NULL) free(process->argv);
|
||||
free(process);
|
||||
}
|
||||
|
||||
|
||||
@@ -578,19 +578,20 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
#if LWS_LIBRARY_VERSION_MAJOR >= 3
|
||||
#define sig_count 2
|
||||
int sig_nums[] = {SIGINT, SIGTERM};
|
||||
int ns = sizeof(sig_nums) / sizeof(sig_nums[0]);
|
||||
uv_signal_t signals[ns];
|
||||
for (int i = 0; i < ns; i++) {
|
||||
uv_signal_t signals[sig_count];
|
||||
for (int i = 0; i < sig_count; i++) {
|
||||
uv_signal_init(server->loop, &signals[i]);
|
||||
uv_signal_start(&signals[i], signal_cb, sig_nums[i]);
|
||||
}
|
||||
|
||||
lws_service(context, 0);
|
||||
|
||||
for (int i = 0; i < ns; i++) {
|
||||
for (int i = 0; i < sig_count; i++) {
|
||||
uv_signal_stop(&signals[i]);
|
||||
}
|
||||
#undef sig_count
|
||||
#else
|
||||
#if LWS_LIBRARY_VERSION_MAJOR < 2
|
||||
lws_uv_initloop(context, server->loop, signal_cb, 0);
|
||||
|
||||
Reference in New Issue
Block a user