From ad48457183c132d21f978dc4ba32487769947266 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 22 Oct 2022 19:20:03 +0800 Subject: [PATCH] Fix nxstyle wanring as much as we can Signed-off-by: Xiang Xiao --- netutils/thttpd/libhttpd.c | 48 ++++++++++++++++++------------------ netutils/thttpd/libhttpd.h | 44 ++++++++++++++++++++++++--------- netutils/thttpd/thttpd.c | 20 +++++++-------- netutils/thttpd/thttpd_cgi.c | 2 +- netutils/thttpd/timers.h | 16 +++++++----- 5 files changed, 77 insertions(+), 53 deletions(-) diff --git a/netutils/thttpd/libhttpd.c b/netutils/thttpd/libhttpd.c index e040744e3..b4009d28a 100644 --- a/netutils/thttpd/libhttpd.c +++ b/netutils/thttpd/libhttpd.c @@ -120,7 +120,7 @@ extern CODE char *crypt(const char *key, const char *setting); ****************************************************************************/ static void free_httpd_server(httpd_server *hs); -static int initialize_listen_socket(httpd_sockaddr *saP); +static int initialize_listen_socket(httpd_sockaddr *sap); static void add_response(httpd_conn *hc, const char *str); static void send_mime(httpd_conn *hc, int status, const char *title, const char *encodings, const char *extraheads, @@ -150,7 +150,7 @@ static int httpd_tilde_map2(httpd_conn *hc); #ifdef CONFIG_THTTPD_VHOST static int vhost_map(httpd_conn *hc); #endif -static char *expand_filename(char *path, char **restP, bool tildemapped); +static char *expand_filename(char *path, char **restp, bool tildemapped); static char *bufgets(httpd_conn *hc); static void de_dotdot(char *file); static void init_mime(void); @@ -168,11 +168,11 @@ static int check_referer(httpd_conn *hc); static int really_check_referer(httpd_conn *hc); #endif #ifdef CONFIG_DEBUG_FEATURES_FEATURES -static int sockaddr_check(httpd_sockaddr *saP); +static int sockaddr_check(httpd_sockaddr *sap); #else -# define sockaddr_check(saP) (1) +# define sockaddr_check(sap) (1) #endif -static size_t sockaddr_len(httpd_sockaddr *saP); +static size_t sockaddr_len(httpd_sockaddr *sap); /**************************************************************************** * Private Data @@ -217,7 +217,7 @@ static void free_httpd_server(httpd_server * hs) } } -static int initialize_listen_socket(httpd_sockaddr *saP) +static int initialize_listen_socket(httpd_sockaddr *sap) { int listen_fd; int on; @@ -226,7 +226,7 @@ static int initialize_listen_socket(httpd_sockaddr *saP) /* Check sockaddr. */ #ifdef CONFIG_DEBUG_FEATURES_FEATURES - if (!sockaddr_check(saP)) + if (!sockaddr_check(sap)) { nerr("ERROR: unknown sockaddr family on listen socket\n"); return -1; @@ -236,7 +236,7 @@ static int initialize_listen_socket(httpd_sockaddr *saP) /* Create socket. */ ninfo("Create listen socket\n"); - listen_fd = socket(saP->sin_family, SOCK_STREAM, 0); + listen_fd = socket(sap->sin_family, SOCK_STREAM, 0); if (listen_fd < 0) { nerr("ERROR: socket failed: %d\n", errno); @@ -253,9 +253,9 @@ static int initialize_listen_socket(httpd_sockaddr *saP) /* Bind to it. */ - if (bind(listen_fd, (struct sockaddr *)saP, sockaddr_len(saP)) < 0) + if (bind(listen_fd, (struct sockaddr *)sap, sockaddr_len(sap)) < 0) { - nerr("ERROR: bind to %s failed: %d\n", httpd_ntoa(saP), errno); + nerr("ERROR: bind to %s failed: %d\n", httpd_ntoa(sap), errno); close(listen_fd); return -1; } @@ -1129,11 +1129,11 @@ static int vhost_map(httpd_conn *hc) /* Expands filename, deleting ..'s and leading /'s. * Returns the expanded path (pointer to static string), or NULL on - * errors. Also returns, in the string pointed to by restP, any trailing + * errors. Also returns, in the string pointed to by restp, any trailing * parts of the path that don't exist. */ -static char *expand_filename(char *path, char **restP, bool tildemapped) +static char *expand_filename(char *path, char **restp, bool tildemapped) { static char *checked; static char *rest; @@ -1152,7 +1152,7 @@ static char *expand_filename(char *path, char **restP, bool tildemapped) ninfo("path: \"%s\"\n", path); #if 0 // REVISIT /* We need to do the pathinfo check. we do a single stat() of the whole - * filename - if it exists, then we return it as is with nothing in restP. + * filename - if it exists, then we return it as is with nothing in restp. * If it doesn't exist, we fall through to the existing code. */ @@ -1172,7 +1172,7 @@ static char *expand_filename(char *path, char **restP, bool tildemapped) httpd_realloc_str(&rest, &maxrest, 0); rest[0] = '\0'; - *restP = rest; + *restp = rest; return checked; } #endif /* 0 */ @@ -1332,7 +1332,7 @@ static char *expand_filename(char *path, char **restP, bool tildemapped) /* Ok. */ - *restP = r; + *restp = r; if (checked[0] == '\0') { strcpy(checked, httpd_root); @@ -2097,9 +2097,9 @@ static int really_check_referer(httpd_conn *hc) #endif /* CONFIG_THTTPD_URLPATTERN */ #ifdef CONFIG_DEBUG_FEATURES_FEATURES -static int sockaddr_check(httpd_sockaddr *saP) +static int sockaddr_check(httpd_sockaddr *sap) { - switch (saP->sin_family) + switch (sap->sin_family) { case AF_INET: return 1; @@ -2115,9 +2115,9 @@ static int sockaddr_check(httpd_sockaddr *saP) } #endif /* CONFIG_DEBUG_FEATURES_FEATURES */ -static size_t sockaddr_len(httpd_sockaddr *saP) +static size_t sockaddr_len(httpd_sockaddr *sap) { - switch (saP->sin_family) + switch (sap->sin_family) { case AF_INET: return sizeof(struct sockaddr_in); @@ -3210,7 +3210,7 @@ void httpd_destroy_conn(httpd_conn *hc) } } -int httpd_start_request(httpd_conn *hc, struct timeval *nowP) +int httpd_start_request(httpd_conn *hc, struct timeval *nowp) { static char *indexname; static size_t maxindexname = 0; @@ -3541,7 +3541,7 @@ int httpd_start_request(httpd_conn *hc, struct timeval *nowP) return 0; } -char *httpd_ntoa(httpd_sockaddr *saP) +char *httpd_ntoa(httpd_sockaddr *sap) { #ifdef CONFIG_NET_IPv6 static char str[200]; @@ -3551,13 +3551,13 @@ char *httpd_ntoa(httpd_sockaddr *saP) #ifdef CONFIG_NET_IPv6 if (getnameinfo - (&saP->sa, sockaddr_len(saP), str, sizeof(str), 0, 0, + (&sap->sa, sockaddr_len(sap), str, sizeof(str), 0, 0, NI_NUMERICHOST) != 0) { str[0] = '?'; str[1] = '\0'; } - else if (IN6_IS_ADDR_V4MAPPED(&saP->sa_in6.sin6_addr) && + else if (IN6_IS_ADDR_V4MAPPED(&sap->sa_in6.sin6_addr) && strncmp(str, "::ffff:", 7) == 0) { /* Elide IPv6ish prefix for IPv4 addresses. */ @@ -3569,7 +3569,7 @@ char *httpd_ntoa(httpd_sockaddr *saP) #else /* CONFIG_NET_IPv6 */ - return inet_ntoa_r(saP->sin_addr, str, sizeof(str)); + return inet_ntoa_r(sap->sin_addr, str, sizeof(str)); #endif /* CONFIG_NET_IPv6 */ } diff --git a/netutils/thttpd/libhttpd.h b/netutils/thttpd/libhttpd.h index 8dd4edd9b..4422fcf07 100644 --- a/netutils/thttpd/libhttpd.h +++ b/netutils/thttpd/libhttpd.h @@ -7,7 +7,8 @@ * * Derived from the file of the same name in the original THTTPD package: * - * Copyright (C) 1995,1998,1999,2000,2001 by Jef Poskanzer . + * Copyright (C) 1995,1998,1999,2000,2001 by Jef Poskanzer + * . * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -78,7 +79,9 @@ # define BADREQUEST(s) #endif -/* Enable special instrumentation to track down "501 Not Implemented" problems */ +/* Enable special instrumentation to track down + * "501 Not Implemented" problems + */ #undef CONFIG_THTTPD_NOTIMPLEMENTED /* Define to enable "Not Implemented" instrumentation */ @@ -95,7 +98,9 @@ # define NOTIMPLEMENTED(s) #endif -/* Enable special instrumentation to track down "500 Internal Error" problems */ +/* Enable special instrumentation to track down + * "500 Internal Error" problems + */ #undef CONFIG_THTTPD_INTERNALERROR /* Define to enable "Internal Error" instrumentation */ @@ -171,7 +176,9 @@ typedef struct httpd_server *hs; httpd_sockaddr client_addr; char *read_buf; - size_t read_size, read_idx, checked_idx; + size_t read_size; + size_t read_idx; + size_t checked_idx; int checked_state; int method; off_t bytes_to_send; @@ -196,14 +203,24 @@ typedef struct char *hostdir; char *authorization; char *remoteuser; - size_t maxdecodedurl, maxorigfilename, maxexpnfilename, maxencodings, - maxpathinfo, maxquery, maxaccept, maxaccepte, maxreqhost, maxhostdir, - maxremoteuser, maxresponse; + size_t maxdecodedurl; + size_t maxorigfilename; + size_t maxexpnfilename; + size_t maxencodings; + size_t maxpathinfo; + size_t maxquery; + size_t maxaccept; + size_t maxaccepte; + size_t maxreqhost; + size_t maxhostdir; + size_t maxremoteuser; + size_t maxresponse; #ifdef CONFIG_THTTPD_TILDE_MAP2 char *altdir; size_t maxaltdir; #endif - time_t if_modified_since, range_if; + time_t if_modified_since; + time_t range_if; size_t contentlength; char *type; /* not malloc()ed */ #ifdef CONFIG_THTTPD_VHOST @@ -221,7 +238,9 @@ typedef struct off_t range_end; /* File range end from Range= */ struct stat sb; - /* This is the I/O buffer that is used to buffer portions of outgoing files */ + /* This is the I/O buffer that is used to buffer portions of + * outgoing files + */ uint16_t buflen; /* Index to first valid data in buffer */ uint8_t buffer[CONFIG_THTTPD_IOBUFFERSIZE]; @@ -285,7 +304,7 @@ extern int httpd_parse_request(httpd_conn *hc); * Returns -1 on error. */ -extern int httpd_start_request(httpd_conn *hc, struct timeval *nowP); +extern int httpd_start_request(httpd_conn *hc, struct timeval *nowp); /* Actually sends any buffered response text. */ @@ -304,7 +323,8 @@ extern void httpd_destroy_conn(httpd_conn *hc); /* Send an error message back to the client. */ extern void httpd_send_err(httpd_conn *hc, int status, const char *title, - const char *extraheads, const char *form, const char *arg); + const char *extraheads, const char *form, + const char *arg); /* Generate a string representation of a method number. */ @@ -312,7 +332,7 @@ extern const char *httpd_method_str(int method); /* Format a network socket to a string representation. */ -extern char *httpd_ntoa(httpd_sockaddr * saP); +extern char *httpd_ntoa(httpd_sockaddr *sap); /* Set NDELAY mode on a socket. */ diff --git a/netutils/thttpd/thttpd.c b/netutils/thttpd/thttpd.c index 07cb4da5f..6d9ca78ba 100644 --- a/netutils/thttpd/thttpd.c +++ b/netutils/thttpd/thttpd.c @@ -129,10 +129,10 @@ static void handle_linger(struct connect_s *conn, struct timeval *tv); static void finish_connection(struct connect_s *conn, struct timeval *tv); static void clear_connection(struct connect_s *conn, struct timeval *tv); static void really_clear_connection(struct connect_s *conn); -static void idle(ClientData client_data, struct timeval *nowP); +static void idle(ClientData client_data, struct timeval *nowp); static void linger_clear_connection(ClientData client_data, - struct timeval *nowP); -static void occasional(ClientData client_data, struct timeval *nowP); + struct timeval *nowp); +static void occasional(ClientData client_data, struct timeval *nowp); /**************************************************************************** * Private Functions @@ -597,7 +597,7 @@ static void really_clear_connection(struct connect_s *conn) free_connections = conn; } -static void idle(ClientData client_data, struct timeval *nowP) +static void idle(ClientData client_data, struct timeval *nowp) { int cnum; struct connect_s *conn; @@ -608,24 +608,24 @@ static void idle(ClientData client_data, struct timeval *nowP) switch (conn->conn_state) { case CNST_READING: - if (nowP->tv_sec - conn->active_at >= + if (nowp->tv_sec - conn->active_at >= CONFIG_THTTPD_IDLE_READ_LIMIT_SEC) { nerr("ERROR: %s connection timed out reading\n", httpd_ntoa(&conn->hc->client_addr)); httpd_send_err(conn->hc, 408, httpd_err408title, "", httpd_err408form, ""); - finish_connection(conn, nowP); + finish_connection(conn, nowp); } break; case CNST_SENDING: - if (nowP->tv_sec - conn->active_at >= + if (nowp->tv_sec - conn->active_at >= CONFIG_THTTPD_IDLE_SEND_LIMIT_SEC) { nerr("ERROR: %s connection timed out sending\n", httpd_ntoa(&conn->hc->client_addr)); - clear_connection(conn, nowP); + clear_connection(conn, nowp); } break; } @@ -633,7 +633,7 @@ static void idle(ClientData client_data, struct timeval *nowP) } static void linger_clear_connection(ClientData client_data, - struct timeval *nowP) + struct timeval *nowp) { struct connect_s *conn; @@ -643,7 +643,7 @@ static void linger_clear_connection(ClientData client_data, really_clear_connection(conn); } -static void occasional(ClientData client_data, struct timeval *nowP) +static void occasional(ClientData client_data, struct timeval *nowp) { tmr_cleanup(); } diff --git a/netutils/thttpd/thttpd_cgi.c b/netutils/thttpd/thttpd_cgi.c index 1c45af2ba..38416f860 100644 --- a/netutils/thttpd/thttpd_cgi.c +++ b/netutils/thttpd/thttpd_cgi.c @@ -1097,7 +1097,7 @@ errout_with_sem: } #if CONFIG_THTTPD_CGI_TIMELIMIT > 0 -static void cgi_kill(ClientData client_data, struct timeval *nowP) +static void cgi_kill(ClientData client_data, struct timeval *nowp) { pid_t pid = (pid_t)client_data.i; diff --git a/netutils/thttpd/timers.h b/netutils/thttpd/timers.h index 185aeba92..a23462608 100644 --- a/netutils/thttpd/timers.h +++ b/netutils/thttpd/timers.h @@ -72,7 +72,7 @@ typedef union * it wants to schedule another timer. */ -typedef void TimerProc(ClientData client_data, struct timeval *nowP); +typedef void TimerProc(ClientData client_data, struct timeval *nowp); /* The Timer struct. */ @@ -102,9 +102,11 @@ extern ClientData JunkClientData; /* For use when you don't care */ extern void tmr_init(void); -/* Set up a timer, either periodic or one-shot. Returns (Timer*) 0 on errors. */ +/* Set up a timer, either periodic or one-shot. + * Returns (Timer *)0 on errors. + */ -extern Timer *tmr_create(struct timeval *nowP, TimerProc * timer_proc, +extern Timer *tmr_create(struct timeval *nowp, TimerProc *timer_proc, ClientData client_data, long msecs, int periodic); /* Returns a timeout in milliseconds indicating how long until the next timer @@ -112,11 +114,13 @@ extern Timer *tmr_create(struct timeval *nowP, TimerProc * timer_proc, * Returns INFTIM (-1) if no timers are pending. */ -extern long tmr_mstimeout(struct timeval *nowP); +extern long tmr_mstimeout(struct timeval *nowp); -/* Run the list of timers. Your main program needs to call this every so often. */ +/* Run the list of timers. + * Your main program needs to call this every so often. + */ -extern void tmr_run(struct timeval *nowP); +extern void tmr_run(struct timeval *nowp); /* Deschedule a timer. Note that non-periodic timers are automatically * descheduled when they run, so you don't have to call this on them.