From: Viktor Szakats Date: Thu, 19 Jun 2025 10:28:49 +0000 (+0200) Subject: tests/server: make all global vars/funcs static X-Git-Tag: curl-8_15_0~232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fc05357ef91e9d5a3c6662a30a67c96cac0b2e5;p=thirdparty%2Fcurl.git tests/server: make all global vars/funcs static Also merge `util.h` into `util.c`. Closes #17671 --- diff --git a/tests/server/Makefile.inc b/tests/server/Makefile.inc index 49cafe9b83..3781064352 100644 --- a/tests/server/Makefile.inc +++ b/tests/server/Makefile.inc @@ -30,7 +30,7 @@ BUNDLE_SRC = servers.c FIRSTFILES = first.c first.h # Common files used by test programs -UTILS = getpart.c getpart.h util.c util.h +UTILS = getpart.c getpart.h util.c CURLX_SRCS = \ ../../lib/curlx/base64.c \ diff --git a/tests/server/dnsd.c b/tests/server/dnsd.c index a77246dc89..52e2951c0c 100644 --- a/tests/server/dnsd.c +++ b/tests/server/dnsd.c @@ -53,7 +53,6 @@ #include /* from the private lib dir */ #include "getpart.h" -#include "util.h" /* include memdebug.h last */ #include diff --git a/tests/server/getpart.c b/tests/server/getpart.c index 3ef9aca948..ae64becd4f 100644 --- a/tests/server/getpart.c +++ b/tests/server/getpart.c @@ -271,8 +271,8 @@ static int decodedata(char **buf, /* dest buffer */ * GPE_OUT_OF_MEMORY * GPE_OK */ -int getpart(char **outbuf, size_t *outlen, - const char *main, const char *sub, FILE *stream) +static int getpart(char **outbuf, size_t *outlen, + const char *main, const char *sub, FILE *stream) { # define MAX_TAG_LEN 200 char couter[MAX_TAG_LEN + 1]; /* current outermost section */ diff --git a/tests/server/getpart.h b/tests/server/getpart.h index 636d75239e..e9b56f88d7 100644 --- a/tests/server/getpart.h +++ b/tests/server/getpart.h @@ -32,7 +32,7 @@ #define GPE_OK 0 #define GPE_END_OF_FILE 1 -int getpart(char **outbuf, size_t *outlen, - const char *main, const char *sub, FILE *stream); +static int getpart(char **outbuf, size_t *outlen, + const char *main, const char *sub, FILE *stream); #endif /* HEADER_CURL_SERVER_GETPART_H */ diff --git a/tests/server/mqttd.c b/tests/server/mqttd.c index 03cb4ef782..4ece4ff8c9 100644 --- a/tests/server/mqttd.c +++ b/tests/server/mqttd.c @@ -24,7 +24,6 @@ #include "curl_setup.h" #include #include -#include "util.h" /* Function * diff --git a/tests/server/resolve.c b/tests/server/resolve.c index 8461552dce..cf13c12caf 100644 --- a/tests/server/resolve.c +++ b/tests/server/resolve.c @@ -44,8 +44,6 @@ #include #endif -#include "util.h" - /* include memdebug.h last */ #include diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index df7a02568c..0e99365393 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -50,7 +50,6 @@ #include /* from the private lib dir */ #include "getpart.h" -#include "util.h" /* include memdebug.h last */ #include diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c index 8b0d147f3f..85314a6288 100644 --- a/tests/server/sockfilt.c +++ b/tests/server/sockfilt.c @@ -103,7 +103,6 @@ #include /* from the private lib dir */ #include "inet_pton.h" -#include "util.h" #include "timediff.h" #include "warnless.h" /* for read() */ diff --git a/tests/server/socksd.c b/tests/server/socksd.c index 03234b9913..9739f532e3 100644 --- a/tests/server/socksd.c +++ b/tests/server/socksd.c @@ -75,7 +75,6 @@ #include /* from the private lib dir */ #include "inet_pton.h" -#include "util.h" #include "tool_binmode.h" /* include memdebug.h last */ diff --git a/tests/server/sws.c b/tests/server/sws.c index 096534f2d5..b8f12bedc4 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -52,7 +52,6 @@ #include /* from the private lib dir */ #include "getpart.h" #include "inet_pton.h" -#include "util.h" /* include memdebug.h last */ #include diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index 3bbd3be1dd..0216b5960c 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -85,7 +85,6 @@ #include /* from the private lib dir */ #include "getpart.h" -#include "util.h" /***************************************************************************** * This is a rewrite/clone of the arpa/tftp.h file for systems without it. * diff --git a/tests/server/util.c b/tests/server/util.c index 04e3f60a93..1e0531f514 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -42,29 +42,82 @@ #endif #include /* from the private lib dir */ -#include "util.h" - -/* need init from main() */ -const char *pidname = NULL; -const char *portname = NULL; /* none by default */ -const char *serverlogfile = NULL; -int serverlogslocked; -const char *configfile = NULL; -const char *logdir = "log"; -char loglockfile[256]; + +/* adjust for old MSVC */ +#if defined(_MSC_VER) && (_MSC_VER < 1900) +# define snprintf _snprintf +#endif + +#ifdef _WIN32 +# define CURL_STRNICMP(p1, p2, n) _strnicmp(p1, p2, n) +#elif defined(HAVE_STRCASECMP) +# ifdef HAVE_STRINGS_H +# include +# endif +# define CURL_STRNICMP(p1, p2, n) strncasecmp(p1, p2, n) +#elif defined(HAVE_STRCMPI) +# define CURL_STRNICMP(p1, p2, n) strncmpi(p1, p2, n) +#elif defined(HAVE_STRICMP) +# define CURL_STRNICMP(p1, p2, n) strnicmp(p1, p2, n) +#else +# error "missing case insensitive comparison function" +#endif + +enum { + DOCNUMBER_NOTHING = -7, + DOCNUMBER_QUIT = -6, + DOCNUMBER_BADCONNECT = -5, + DOCNUMBER_INTERNAL = -4, + DOCNUMBER_CONNECT = -3, + DOCNUMBER_WERULEZ = -2, + DOCNUMBER_404 = -1 +}; + +#define SERVERLOGS_LOCKDIR "lock" /* within logdir */ + +#include "timeval.h" + +#include /* for curl_socket_t */ + +#ifdef USE_UNIX_SOCKETS +#ifdef HAVE_SYS_UN_H +#include /* for sockaddr_un */ +#endif +#endif /* USE_UNIX_SOCKETS */ + +typedef union { + struct sockaddr sa; + struct sockaddr_in sa4; #ifdef USE_IPV6 -bool use_ipv6 = FALSE; + struct sockaddr_in6 sa6; #endif -const char *ipv_inuse = "IPv4"; -unsigned short server_port = 0; -const char *socket_type = "IPv4"; -int socket_domain = AF_INET; +#ifdef USE_UNIX_SOCKETS + struct sockaddr_un sau; +#endif +} srvr_sockaddr_union_t; + +/* global variables */ +static const char *srcpath = "."; /* pointing to the test dir */ +static const char *pidname = NULL; +static const char *portname = NULL; /* none by default */ +static const char *serverlogfile = NULL; +static int serverlogslocked; +static const char *configfile = NULL; +static const char *logdir = "log"; +static char loglockfile[256]; +#ifdef USE_IPV6 +static bool use_ipv6 = FALSE; +#endif +static const char *ipv_inuse = "IPv4"; +static unsigned short server_port = 0; +static const char *socket_type = "IPv4"; +static int socket_domain = AF_INET; /* This function returns a pointer to STATIC memory. It converts the given * binary lump to a hex formatted string usable for output in logs or * whatever. */ -char *data_to_hex(char *data, size_t len) +static char *data_to_hex(char *data, size_t len) { static char buf[256*3]; size_t i; @@ -87,7 +140,7 @@ char *data_to_hex(char *data, size_t len) return buf; } -void logmsg(const char *msg, ...) +static void logmsg(const char *msg, ...) { va_list ap; char buffer[2048 + 1]; @@ -145,7 +198,7 @@ void logmsg(const char *msg, ...) } } -void loghex(unsigned char *buffer, ssize_t len) +static void loghex(unsigned char *buffer, ssize_t len) { char data[12000]; ssize_t i; @@ -164,7 +217,7 @@ void loghex(unsigned char *buffer, ssize_t len) logmsg("'%s'", data); } -unsigned char byteval(char *value) +static unsigned char byteval(char *value) { unsigned long num = strtoul(value, NULL, 10); return num & 0xff; @@ -192,7 +245,7 @@ static void win32_cleanup(void) _flushall(); } -int win32_init(void) +static int win32_init(void) { curlx_now_init(); #ifdef USE_WINSOCK @@ -224,17 +277,17 @@ int win32_init(void) } /* socket-safe strerror (works on Winsock errors, too) */ -const char *sstrerror(int err) +static const char *sstrerror(int err) { static char buf[512]; return curlx_winapi_strerror(err, buf, sizeof(buf)); } +#else +#define sstrerror(e) strerror(e) #endif /* _WIN32 */ -/* set by the main code to point to where the test dir is */ -const char *srcpath = "."; - -FILE *test2fopen(long testno, const char *logdir2) +/* fopens the test case file */ +static FILE *test2fopen(long testno, const char *logdir2) { FILE *stream; char filename[256]; @@ -260,7 +313,7 @@ FILE *test2fopen(long testno, const char *logdir2) * -1 = system call error, or invalid timeout value * 0 = specified timeout has elapsed */ -int wait_ms(timediff_t timeout_ms) +static int wait_ms(timediff_t timeout_ms) { int r = 0; @@ -304,7 +357,7 @@ int wait_ms(timediff_t timeout_ms) #define t_getpid() getpid() #endif -curl_off_t our_getpid(void) +static curl_off_t our_getpid(void) { curl_off_t pid = (curl_off_t)t_getpid(); #ifdef _WIN32 @@ -321,7 +374,7 @@ curl_off_t our_getpid(void) return pid; } -int write_pidfile(const char *filename) +static int write_pidfile(const char *filename) { FILE *pidfile; curl_off_t pid; @@ -339,7 +392,7 @@ int write_pidfile(const char *filename) } /* store the used port number in a file */ -int write_portfile(const char *filename, int port) +static int write_portfile(const char *filename, int port) { FILE *portfile = fopen(filename, "wb"); if(!portfile) { @@ -352,7 +405,7 @@ int write_portfile(const char *filename, int port) return 1; /* success */ } -void set_advisor_read_lock(const char *filename) +static void set_advisor_read_lock(const char *filename) { FILE *lockfile; int error = 0; @@ -374,7 +427,7 @@ void set_advisor_read_lock(const char *filename) filename, errno, strerror(errno)); } -void clear_advisor_read_lock(const char *filename) +static void clear_advisor_read_lock(const char *filename) { int error = 0; int res; @@ -435,15 +488,16 @@ static HANDLE thread_main_window = NULL; static HWND hidden_main_window = NULL; #endif -/* var which if set indicates that the program should finish execution */ -volatile int got_exit_signal = 0; +/* global variable which if set indicates that the program should finish */ +static volatile int got_exit_signal = 0; -/* if next is set indicates the first signal handled in exit_signal_handler */ -volatile int exit_signal = 0; +/* global variable which if set indicates the first signal handled in + exit_signal_handler */ +static volatile int exit_signal = 0; #ifdef _WIN32 -/* event which if set indicates that the program should finish */ -HANDLE exit_event = NULL; +/* global event which if set indicates that the program should finish */ +static HANDLE exit_event = NULL; #endif /* signal handler that will be triggered to indicate that the program @@ -659,7 +713,7 @@ static SIGHANDLER_T set_signal(int signum, SIGHANDLER_T handler, } #endif -void install_signal_handlers(bool keep_sigalrm) +static void install_signal_handlers(bool keep_sigalrm) { #ifdef _WIN32 /* setup Windows exit event before any signal can trigger */ @@ -727,7 +781,7 @@ void install_signal_handlers(bool keep_sigalrm) #endif } -void restore_signal_handlers(bool keep_sigalrm) +static void restore_signal_handlers(bool keep_sigalrm) { #ifdef SIGHUP if(SIG_ERR != old_sighup_handler) @@ -783,8 +837,8 @@ void restore_signal_handlers(bool keep_sigalrm) #ifdef USE_UNIX_SOCKETS -int bind_unix_socket(curl_socket_t sock, const char *unix_socket, - struct sockaddr_un *sau) +static int bind_unix_socket(curl_socket_t sock, const char *unix_socket, + struct sockaddr_un *sau) { int error; int rc; @@ -854,7 +908,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket, #define CURL_MASK_USHORT ((unsigned short)~0) #define CURL_MASK_SSHORT (CURL_MASK_USHORT >> 1) -unsigned short util_ultous(unsigned long ulnum) +static unsigned short util_ultous(unsigned long ulnum) { #ifdef __INTEL_COMPILER # pragma warning(push) diff --git a/tests/server/util.h b/tests/server/util.h deleted file mode 100644 index 5afaa03b78..0000000000 --- a/tests/server/util.h +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef HEADER_CURL_SERVER_UTIL_H -#define HEADER_CURL_SERVER_UTIL_H -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ -#include "curl_setup.h" - -/* adjust for old MSVC */ -#if defined(_MSC_VER) && (_MSC_VER < 1900) -# define snprintf _snprintf -#endif - -#ifdef _WIN32 -# define CURL_STRNICMP(p1, p2, n) _strnicmp(p1, p2, n) -#elif defined(HAVE_STRCASECMP) -# ifdef HAVE_STRINGS_H -# include -# endif -# define CURL_STRNICMP(p1, p2, n) strncasecmp(p1, p2, n) -#elif defined(HAVE_STRCMPI) -# define CURL_STRNICMP(p1, p2, n) strncmpi(p1, p2, n) -#elif defined(HAVE_STRICMP) -# define CURL_STRNICMP(p1, p2, n) strnicmp(p1, p2, n) -#else -# error "missing case insensitive comparison function" -#endif - -enum { - DOCNUMBER_NOTHING = -7, - DOCNUMBER_QUIT = -6, - DOCNUMBER_BADCONNECT = -5, - DOCNUMBER_INTERNAL = -4, - DOCNUMBER_CONNECT = -3, - DOCNUMBER_WERULEZ = -2, - DOCNUMBER_404 = -1 -}; - -char *data_to_hex(char *data, size_t len); -void logmsg(const char *msg, ...) CURL_PRINTF(1, 2); -void loghex(unsigned char *buffer, ssize_t len); -unsigned char byteval(char *value); - -#define SERVERLOGS_LOCKDIR "lock" /* within logdir */ - -/* global variables */ -extern const char *srcpath; /* where to find the 'data' dir */ -extern const char *pidname; -extern const char *portname; -extern const char *serverlogfile; /* log file name */ -extern int serverlogslocked; -extern const char *configfile; -extern const char *logdir; -extern char loglockfile[256]; -#ifdef USE_IPV6 -extern bool use_ipv6; -#endif -extern const char *ipv_inuse; -extern unsigned short server_port; -extern const char *socket_type; -extern int socket_domain; - -#ifdef _WIN32 -int win32_init(void); -const char *sstrerror(int err); -#else -#define sstrerror(e) strerror(e) -#endif - -/* fopens the test case file */ -FILE *test2fopen(long testno, const char *logdir); - -#include "timeval.h" - -int wait_ms(timediff_t timeout_ms); -curl_off_t our_getpid(void); -int write_pidfile(const char *filename); -int write_portfile(const char *filename, int port); -void set_advisor_read_lock(const char *filename); -void clear_advisor_read_lock(const char *filename); - -/* global variable which if set indicates that the program should finish */ -extern volatile int got_exit_signal; - -/* global variable which if set indicates the first signal handled */ -extern volatile int exit_signal; - -#ifdef _WIN32 -/* global event which if set indicates that the program should finish */ -extern HANDLE exit_event; -#endif - -void install_signal_handlers(bool keep_sigalrm); -void restore_signal_handlers(bool keep_sigalrm); - -#include /* for curl_socket_t */ - -#ifdef USE_UNIX_SOCKETS -#ifdef HAVE_SYS_UN_H -#include /* for sockaddr_un */ -#endif -int bind_unix_socket(curl_socket_t sock, const char *unix_socket, - struct sockaddr_un *sau); -#endif /* USE_UNIX_SOCKETS */ - -typedef union { - struct sockaddr sa; - struct sockaddr_in sa4; -#ifdef USE_IPV6 - struct sockaddr_in6 sa6; -#endif -#ifdef USE_UNIX_SOCKETS - struct sockaddr_un sau; -#endif -} srvr_sockaddr_union_t; - -unsigned short util_ultous(unsigned long ulnum); - -#endif /* HEADER_CURL_SERVER_UTIL_H */