tests/server: make all global vars/funcs static

Also merge `util.h` into `util.c`.

Closes #17671
This commit is contained in:
Viktor Szakats 2025-06-19 12:28:49 +02:00
parent 8e47c8a764
commit 9fc05357ef
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
13 changed files with 101 additions and 194 deletions

View file

@ -42,29 +42,82 @@
#endif
#include <curlx.h> /* 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];
#ifdef USE_IPV6
bool use_ipv6 = FALSE;
/* adjust for old MSVC */
#if defined(_MSC_VER) && (_MSC_VER < 1900)
# define snprintf _snprintf
#endif
const char *ipv_inuse = "IPv4";
unsigned short server_port = 0;
const char *socket_type = "IPv4";
int socket_domain = AF_INET;
#ifdef _WIN32
# define CURL_STRNICMP(p1, p2, n) _strnicmp(p1, p2, n)
#elif defined(HAVE_STRCASECMP)
# ifdef HAVE_STRINGS_H
# include <strings.h>
# 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 <curl/curl.h> /* for curl_socket_t */
#ifdef USE_UNIX_SOCKETS
#ifdef HAVE_SYS_UN_H
#include <sys/un.h> /* for sockaddr_un */
#endif
#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;
/* 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)