]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests/server: make all global vars/funcs static
authorViktor Szakats <commit@vsz.me>
Thu, 19 Jun 2025 10:28:49 +0000 (12:28 +0200)
committerViktor Szakats <commit@vsz.me>
Thu, 19 Jun 2025 11:28:45 +0000 (13:28 +0200)
Also merge `util.h` into `util.c`.

Closes #17671

13 files changed:
tests/server/Makefile.inc
tests/server/dnsd.c
tests/server/getpart.c
tests/server/getpart.h
tests/server/mqttd.c
tests/server/resolve.c
tests/server/rtspd.c
tests/server/sockfilt.c
tests/server/socksd.c
tests/server/sws.c
tests/server/tftpd.c
tests/server/util.c
tests/server/util.h [deleted file]

index 49cafe9b839c1923168911e4ba84b03a9ed07e46..378106435230454938117ecddad4ef1ac3b5e93f 100644 (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 \
index a77246dc8919255d7ea904e075aff16eacbddf40..52e2951c0c3209573f6ac2e291b60f3438ff3769 100644 (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>
index 3ef9aca9487349f657128e7381fc60b401e706ea..ae64becd4f2caabbd3bafd628568c30a1bb3c7dc 100644 (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 */
index 636d75239ee71695b635e37c427476652fd281b5..e9b56f88d766688603a5ca8eb72862a3aed059df 100644 (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 */
index 03cb4ef78225d0ba3c707603cae8331a8a2777e5..4ece4ff8c9e9172dd02f49c3d341aed54d3f711e 100644 (file)
@@ -24,7 +24,6 @@
 #include "curl_setup.h"
 #include <stdlib.h>
 #include <string.h>
-#include "util.h"
 
 /* Function
  *
index 8461552dce1f099831233ac2b68d79c2ebbb9bd1..cf13c12caf692827bcadbb4fbe6b30df24993a5d 100644 (file)
@@ -44,8 +44,6 @@
 #include <netdb.h>
 #endif
 
-#include "util.h"
-
 /* include memdebug.h last */
 #include <memdebug.h>
 
index df7a02568cacb6cfa934d706a19dfe6c2b2b7e14..0e99365393f6856a0c2f22fca24a2c81fb32ed2e 100644 (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>
index 8b0d147f3fafda78a7bca833732d0a47568fe921..85314a6288eb8e713f50565b678cb1b4c7d08565 100644 (file)
 
 #include <curlx.h> /* from the private lib dir */
 #include "inet_pton.h"
-#include "util.h"
 #include "timediff.h"
 #include "warnless.h" /* for read() */
 
index 03234b99130564f750d339ac6dd6ff7a327e76ce..9739f532e336bed12c2c254d6bb31a6466abbb04 100644 (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 */
index 096534f2d59716e79dcc2b1b1a1b676b2c052663..b8f12bedc46094b3fb9916d0ce577e2b3b5b190d 100644 (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>
index 3bbd3be1dd31fa444f0b18a37d6db363949fa290..0216b5960c67b94efe8d8ff3e238326e8cc63889 100644 (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.   *
index 04e3f60a936d69d345bfbf1ab269990bc3e00858..1e0531f51499ee35e548d11a8834b389cbf50ba8 100644 (file)
 #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];
+
+/* 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
+};
+
+#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
-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 (file)
index 5afaa03..0000000
+++ /dev/null
@@ -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 */