From b0c4ad97f0ff9dbe9d457cdaf1070e1f8e2fbd6b Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Wed, 11 Mar 2020 00:52:06 +0800 Subject: [PATCH] all: use the static keyword on functions --- src/http.c | 15 ++++++++------- src/protocol.c | 22 +++++++++++----------- src/server.c | 11 ++++++----- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/http.c b/src/http.c index 9c39e32..deefe92 100644 --- a/src/http.c +++ b/src/http.c @@ -11,10 +11,10 @@ enum { AUTH_OK, AUTH_FAIL, AUTH_ERROR }; -char * html_cache = NULL; -size_t html_cache_len = 0; +static char * html_cache = NULL; +static size_t html_cache_len = 0; -int +static int check_auth(struct lws *wsi, struct pss_http *pss) { if (server->credential == NULL) return AUTH_OK; @@ -67,14 +67,15 @@ check_auth(struct lws *wsi, struct pss_http *pss) { return AUTH_FAIL; } -bool accept_gzip(struct lws *wsi) { +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]; int len = lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_HTTP_ACCEPT_ENCODING); return len > 0 && strstr(buf, "gzip") != NULL; } -bool +static bool uncompress_html(char **output, size_t *output_len) { if (html_cache == NULL || html_cache_len == 0) { z_stream stream; @@ -106,13 +107,13 @@ uncompress_html(char **output, size_t *output_len) { return true; } -void +static void pss_buffer_free(struct pss_http *pss) { if (pss->buffer != (char *) index_html && pss->buffer != html_cache) free(pss->buffer); } -void +static void access_log(struct lws *wsi, const char *path) { char rip[50]; diff --git a/src/protocol.c b/src/protocol.c index dccee3b..9949759 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -14,12 +14,12 @@ #include "utils.h" // initial message list -char initial_cmds[] = { +static char initial_cmds[] = { SET_WINDOW_TITLE, SET_PREFERENCES }; -int +static int send_initial_message(struct lws *wsi, int index) { unsigned char message[LWS_PRE + 1 + 4096]; unsigned char *p = &message[LWS_PRE]; @@ -42,7 +42,7 @@ send_initial_message(struct lws *wsi, int index) { return lws_write(wsi, p, (size_t) n, LWS_WRITE_BINARY); } -bool +static bool parse_window_size(struct pss_tty *pss, int *cols, int *rows) { char json[pss->len]; strncpy(json, pss->buffer + 1, pss->len - 1); @@ -66,7 +66,7 @@ parse_window_size(struct pss_tty *pss, int *cols, int *rows) { return true; } -bool +static bool check_host_origin(struct lws *wsi) { int origin_length = lws_hdr_total_length(wsi, WSI_TOKEN_ORIGIN); char buf[origin_length + 1]; @@ -96,7 +96,7 @@ check_host_origin(struct lws *wsi) { return len > 0 && strcasecmp(buf, host_buf) == 0; } -void +static void pty_proc_free(struct pty_proc *proc) { uv_read_stop((uv_stream_t *) &proc->pipe); uv_close((uv_handle_t*) &proc->pipe, NULL); @@ -115,13 +115,13 @@ pty_proc_free(struct pty_proc *proc) { free(proc); } -void +static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { buf->base = xmalloc(suggested_size); buf->len = suggested_size; } -void +static void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { struct pss_tty *pss = (struct pss_tty *) stream->data; struct pty_proc *proc = pss->proc; @@ -146,7 +146,7 @@ read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { lws_callback_on_writable(pss->wsi); } -void +static void child_cb(uv_signal_t *handle, int signum) { pid_t pid; int stat; @@ -182,7 +182,7 @@ child_cb(uv_signal_t *handle, int signum) { } } -int +static int spawn_process(struct pss_tty *pss) { struct pty_proc *proc = pss->proc; // append url args to arguments @@ -218,7 +218,7 @@ spawn_process(struct pss_tty *pss) { return 0; } -void +static void kill_process(struct pty_proc *proc) { if (proc->pid <= 0) return; @@ -233,7 +233,7 @@ kill_process(struct pty_proc *proc) { } } -void +static void write_cb(uv_write_t* req, int status) { if (status != 0) lwsl_warn("uv_write callback returned status: %d\n", status); diff --git a/src/server.c b/src/server.c index dbe0b14..7a58d62 100644 --- a/src/server.c +++ b/src/server.c @@ -68,7 +68,8 @@ static const struct option options[] = { }; static const char *opt_string = "p:i:c:u:g:s:I:b:6aSC:K:A:Rt:T:Om:oBd:vh"; -void print_help() { +static void +print_help() { fprintf(stderr, "ttyd is a tool for sharing terminal over the web\n\n" "USAGE:\n" " ttyd [options] []\n\n" @@ -106,7 +107,7 @@ void print_help() { ); } -struct server * +static struct server * server_new(int argc, char **argv, int start) { struct server *ts; size_t cmd_len = 0; @@ -153,7 +154,7 @@ server_new(int argc, char **argv, int start) { return ts; } -void +static void server_free(struct server *ts) { if (ts == NULL) return; @@ -180,7 +181,7 @@ server_free(struct server *ts) { free(ts); } -void +static void signal_cb(uv_signal_t *watcher, int signum) { char sig_name[20]; @@ -208,7 +209,7 @@ signal_cb(uv_signal_t *watcher, int signum) { #endif } -int +static int calc_command_start(int argc, char **argv) { // make a copy of argc and argv int argc_copy = argc; -- 2.43.4