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

@ -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 \

View file

@ -53,7 +53,6 @@
#include <curlx.h> /* from the private lib dir */
#include "getpart.h"
#include "util.h"
/* include memdebug.h last */
#include <memdebug.h>

View file

@ -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 */

View file

@ -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 */

View file

@ -24,7 +24,6 @@
#include "curl_setup.h"
#include <stdlib.h>
#include <string.h>
#include "util.h"
/* Function
*

View file

@ -44,8 +44,6 @@
#include <netdb.h>
#endif
#include "util.h"
/* include memdebug.h last */
#include <memdebug.h>

View file

@ -50,7 +50,6 @@
#include <curlx.h> /* from the private lib dir */
#include "getpart.h"
#include "util.h"
/* include memdebug.h last */
#include <memdebug.h>

View file

@ -103,7 +103,6 @@
#include <curlx.h> /* from the private lib dir */
#include "inet_pton.h"
#include "util.h"
#include "timediff.h"
#include "warnless.h" /* for read() */

View file

@ -75,7 +75,6 @@
#include <curlx.h> /* from the private lib dir */
#include "inet_pton.h"
#include "util.h"
#include "tool_binmode.h"
/* include memdebug.h last */

View file

@ -52,7 +52,6 @@
#include <curlx.h> /* from the private lib dir */
#include "getpart.h"
#include "inet_pton.h"
#include "util.h"
/* include memdebug.h last */
#include <memdebug.h>

View file

@ -85,7 +85,6 @@
#include <curlx.h> /* 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. *

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)

View file

@ -1,138 +0,0 @@
#ifndef HEADER_CURL_SERVER_UTIL_H
#define HEADER_CURL_SERVER_UTIL_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 <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
};
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 <curl/curl.h> /* for curl_socket_t */
#ifdef USE_UNIX_SOCKETS
#ifdef HAVE_SYS_UN_H
#include <sys/un.h> /* 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 */