Fix nxstyle wanring as much as we can

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-10-22 19:20:03 +08:00 committed by Xiang Xiao
parent 041cec1af8
commit ad48457183
5 changed files with 77 additions and 53 deletions

View File

@ -120,7 +120,7 @@ extern CODE char *crypt(const char *key, const char *setting);
****************************************************************************/ ****************************************************************************/
static void free_httpd_server(httpd_server *hs); 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 add_response(httpd_conn *hc, const char *str);
static void send_mime(httpd_conn *hc, int status, const char *title, static void send_mime(httpd_conn *hc, int status, const char *title,
const char *encodings, const char *extraheads, const char *encodings, const char *extraheads,
@ -150,7 +150,7 @@ static int httpd_tilde_map2(httpd_conn *hc);
#ifdef CONFIG_THTTPD_VHOST #ifdef CONFIG_THTTPD_VHOST
static int vhost_map(httpd_conn *hc); static int vhost_map(httpd_conn *hc);
#endif #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 char *bufgets(httpd_conn *hc);
static void de_dotdot(char *file); static void de_dotdot(char *file);
static void init_mime(void); static void init_mime(void);
@ -168,11 +168,11 @@ static int check_referer(httpd_conn *hc);
static int really_check_referer(httpd_conn *hc); static int really_check_referer(httpd_conn *hc);
#endif #endif
#ifdef CONFIG_DEBUG_FEATURES_FEATURES #ifdef CONFIG_DEBUG_FEATURES_FEATURES
static int sockaddr_check(httpd_sockaddr *saP); static int sockaddr_check(httpd_sockaddr *sap);
#else #else
# define sockaddr_check(saP) (1) # define sockaddr_check(sap) (1)
#endif #endif
static size_t sockaddr_len(httpd_sockaddr *saP); static size_t sockaddr_len(httpd_sockaddr *sap);
/**************************************************************************** /****************************************************************************
* Private Data * 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 listen_fd;
int on; int on;
@ -226,7 +226,7 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
/* Check sockaddr. */ /* Check sockaddr. */
#ifdef CONFIG_DEBUG_FEATURES_FEATURES #ifdef CONFIG_DEBUG_FEATURES_FEATURES
if (!sockaddr_check(saP)) if (!sockaddr_check(sap))
{ {
nerr("ERROR: unknown sockaddr family on listen socket\n"); nerr("ERROR: unknown sockaddr family on listen socket\n");
return -1; return -1;
@ -236,7 +236,7 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
/* Create socket. */ /* Create socket. */
ninfo("Create listen socket\n"); 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) if (listen_fd < 0)
{ {
nerr("ERROR: socket failed: %d\n", errno); nerr("ERROR: socket failed: %d\n", errno);
@ -253,9 +253,9 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
/* Bind to it. */ /* 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); close(listen_fd);
return -1; return -1;
} }
@ -1129,11 +1129,11 @@ static int vhost_map(httpd_conn *hc)
/* Expands filename, deleting ..'s and leading /'s. /* Expands filename, deleting ..'s and leading /'s.
* Returns the expanded path (pointer to static string), or NULL on * 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. * 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 *checked;
static char *rest; static char *rest;
@ -1152,7 +1152,7 @@ static char *expand_filename(char *path, char **restP, bool tildemapped)
ninfo("path: \"%s\"\n", path); ninfo("path: \"%s\"\n", path);
#if 0 // REVISIT #if 0 // REVISIT
/* We need to do the pathinfo check. we do a single stat() of the whole /* 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. * 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); httpd_realloc_str(&rest, &maxrest, 0);
rest[0] = '\0'; rest[0] = '\0';
*restP = rest; *restp = rest;
return checked; return checked;
} }
#endif /* 0 */ #endif /* 0 */
@ -1332,7 +1332,7 @@ static char *expand_filename(char *path, char **restP, bool tildemapped)
/* Ok. */ /* Ok. */
*restP = r; *restp = r;
if (checked[0] == '\0') if (checked[0] == '\0')
{ {
strcpy(checked, httpd_root); strcpy(checked, httpd_root);
@ -2097,9 +2097,9 @@ static int really_check_referer(httpd_conn *hc)
#endif /* CONFIG_THTTPD_URLPATTERN */ #endif /* CONFIG_THTTPD_URLPATTERN */
#ifdef CONFIG_DEBUG_FEATURES_FEATURES #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: case AF_INET:
return 1; return 1;
@ -2115,9 +2115,9 @@ static int sockaddr_check(httpd_sockaddr *saP)
} }
#endif /* CONFIG_DEBUG_FEATURES_FEATURES */ #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: case AF_INET:
return sizeof(struct sockaddr_in); 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 char *indexname;
static size_t maxindexname = 0; static size_t maxindexname = 0;
@ -3541,7 +3541,7 @@ int httpd_start_request(httpd_conn *hc, struct timeval *nowP)
return 0; return 0;
} }
char *httpd_ntoa(httpd_sockaddr *saP) char *httpd_ntoa(httpd_sockaddr *sap)
{ {
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
static char str[200]; static char str[200];
@ -3551,13 +3551,13 @@ char *httpd_ntoa(httpd_sockaddr *saP)
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
if (getnameinfo 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) NI_NUMERICHOST) != 0)
{ {
str[0] = '?'; str[0] = '?';
str[1] = '\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) strncmp(str, "::ffff:", 7) == 0)
{ {
/* Elide IPv6ish prefix for IPv4 addresses. */ /* Elide IPv6ish prefix for IPv4 addresses. */
@ -3569,7 +3569,7 @@ char *httpd_ntoa(httpd_sockaddr *saP)
#else /* CONFIG_NET_IPv6 */ #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 */ #endif /* CONFIG_NET_IPv6 */
} }

View File

@ -7,7 +7,8 @@
* *
* Derived from the file of the same name in the original THTTPD package: * Derived from the file of the same name in the original THTTPD package:
* *
* Copyright (C) 1995,1998,1999,2000,2001 by Jef Poskanzer <jef@mail.acme.com>. * Copyright (C) 1995,1998,1999,2000,2001 by Jef Poskanzer
* <jef@mail.acme.com>.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -78,7 +79,9 @@
# define BADREQUEST(s) # define BADREQUEST(s)
#endif #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 */ #undef CONFIG_THTTPD_NOTIMPLEMENTED /* Define to enable "Not Implemented" instrumentation */
@ -95,7 +98,9 @@
# define NOTIMPLEMENTED(s) # define NOTIMPLEMENTED(s)
#endif #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 */ #undef CONFIG_THTTPD_INTERNALERROR /* Define to enable "Internal Error" instrumentation */
@ -171,7 +176,9 @@ typedef struct
httpd_server *hs; httpd_server *hs;
httpd_sockaddr client_addr; httpd_sockaddr client_addr;
char *read_buf; 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 checked_state;
int method; int method;
off_t bytes_to_send; off_t bytes_to_send;
@ -196,14 +203,24 @@ typedef struct
char *hostdir; char *hostdir;
char *authorization; char *authorization;
char *remoteuser; char *remoteuser;
size_t maxdecodedurl, maxorigfilename, maxexpnfilename, maxencodings, size_t maxdecodedurl;
maxpathinfo, maxquery, maxaccept, maxaccepte, maxreqhost, maxhostdir, size_t maxorigfilename;
maxremoteuser, maxresponse; 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 #ifdef CONFIG_THTTPD_TILDE_MAP2
char *altdir; char *altdir;
size_t maxaltdir; size_t maxaltdir;
#endif #endif
time_t if_modified_since, range_if; time_t if_modified_since;
time_t range_if;
size_t contentlength; size_t contentlength;
char *type; /* not malloc()ed */ char *type; /* not malloc()ed */
#ifdef CONFIG_THTTPD_VHOST #ifdef CONFIG_THTTPD_VHOST
@ -221,7 +238,9 @@ typedef struct
off_t range_end; /* File range end from Range= */ off_t range_end; /* File range end from Range= */
struct stat sb; 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 */ uint16_t buflen; /* Index to first valid data in buffer */
uint8_t buffer[CONFIG_THTTPD_IOBUFFERSIZE]; uint8_t buffer[CONFIG_THTTPD_IOBUFFERSIZE];
@ -285,7 +304,7 @@ extern int httpd_parse_request(httpd_conn *hc);
* Returns -1 on error. * 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. */ /* 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. */ /* Send an error message back to the client. */
extern void httpd_send_err(httpd_conn *hc, int status, const char *title, 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. */ /* 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. */ /* 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. */ /* Set NDELAY mode on a socket. */

View File

@ -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 finish_connection(struct connect_s *conn, struct timeval *tv);
static void clear_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 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, static void linger_clear_connection(ClientData client_data,
struct timeval *nowP); struct timeval *nowp);
static void occasional(ClientData client_data, struct timeval *nowP); static void occasional(ClientData client_data, struct timeval *nowp);
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@ -597,7 +597,7 @@ static void really_clear_connection(struct connect_s *conn)
free_connections = conn; free_connections = conn;
} }
static void idle(ClientData client_data, struct timeval *nowP) static void idle(ClientData client_data, struct timeval *nowp)
{ {
int cnum; int cnum;
struct connect_s *conn; struct connect_s *conn;
@ -608,24 +608,24 @@ static void idle(ClientData client_data, struct timeval *nowP)
switch (conn->conn_state) switch (conn->conn_state)
{ {
case CNST_READING: case CNST_READING:
if (nowP->tv_sec - conn->active_at >= if (nowp->tv_sec - conn->active_at >=
CONFIG_THTTPD_IDLE_READ_LIMIT_SEC) CONFIG_THTTPD_IDLE_READ_LIMIT_SEC)
{ {
nerr("ERROR: %s connection timed out reading\n", nerr("ERROR: %s connection timed out reading\n",
httpd_ntoa(&conn->hc->client_addr)); httpd_ntoa(&conn->hc->client_addr));
httpd_send_err(conn->hc, 408, httpd_err408title, "", httpd_send_err(conn->hc, 408, httpd_err408title, "",
httpd_err408form, ""); httpd_err408form, "");
finish_connection(conn, nowP); finish_connection(conn, nowp);
} }
break; break;
case CNST_SENDING: case CNST_SENDING:
if (nowP->tv_sec - conn->active_at >= if (nowp->tv_sec - conn->active_at >=
CONFIG_THTTPD_IDLE_SEND_LIMIT_SEC) CONFIG_THTTPD_IDLE_SEND_LIMIT_SEC)
{ {
nerr("ERROR: %s connection timed out sending\n", nerr("ERROR: %s connection timed out sending\n",
httpd_ntoa(&conn->hc->client_addr)); httpd_ntoa(&conn->hc->client_addr));
clear_connection(conn, nowP); clear_connection(conn, nowp);
} }
break; break;
} }
@ -633,7 +633,7 @@ static void idle(ClientData client_data, struct timeval *nowP)
} }
static void linger_clear_connection(ClientData client_data, static void linger_clear_connection(ClientData client_data,
struct timeval *nowP) struct timeval *nowp)
{ {
struct connect_s *conn; struct connect_s *conn;
@ -643,7 +643,7 @@ static void linger_clear_connection(ClientData client_data,
really_clear_connection(conn); really_clear_connection(conn);
} }
static void occasional(ClientData client_data, struct timeval *nowP) static void occasional(ClientData client_data, struct timeval *nowp)
{ {
tmr_cleanup(); tmr_cleanup();
} }

View File

@ -1097,7 +1097,7 @@ errout_with_sem:
} }
#if CONFIG_THTTPD_CGI_TIMELIMIT > 0 #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; pid_t pid = (pid_t)client_data.i;

View File

@ -72,7 +72,7 @@ typedef union
* it wants to schedule another timer. * 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. */ /* The Timer struct. */
@ -102,9 +102,11 @@ extern ClientData JunkClientData; /* For use when you don't care */
extern void tmr_init(void); 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); ClientData client_data, long msecs, int periodic);
/* Returns a timeout in milliseconds indicating how long until the next timer /* 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. * 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 /* Deschedule a timer. Note that non-periodic timers are automatically
* descheduled when they run, so you don't have to call this on them. * descheduled when they run, so you don't have to call this on them.