mirror of
https://github.com/curl/curl.git
synced 2025-09-10 06:02:42 +03:00
tests/server: round of tidy-ups
Dedupe, merge macros, globals, make symbols local where possible. Drop unused macros and headers. Drop `DEFAULT_LOGFILE` macro in favour of `--logfile` command-line option. Ref: #15000 Closes #16525
This commit is contained in:
parent
387311012c
commit
9213e4e497
|
@ -64,17 +64,8 @@
|
|||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
#undef EINTR
|
||||
#define EINTR 4 /* errno.h value */
|
||||
#endif
|
||||
|
||||
#define DEFAULT_PORT 1883 /* MQTT default port */
|
||||
|
||||
#ifndef DEFAULT_LOGFILE
|
||||
#define DEFAULT_LOGFILE "log/mqttd.log"
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_CONFIG
|
||||
#define DEFAULT_CONFIG "mqttd.config"
|
||||
#endif
|
||||
|
@ -102,7 +93,6 @@ struct configurable {
|
|||
|
||||
static struct configurable config;
|
||||
|
||||
const char *serverlogfile = DEFAULT_LOGFILE;
|
||||
static const char *configfile = DEFAULT_CONFIG;
|
||||
static const char *logdir = "log";
|
||||
static char loglockfile[256];
|
||||
|
@ -933,6 +923,8 @@ int main(int argc, char *argv[])
|
|||
int error;
|
||||
int arg = 1;
|
||||
|
||||
serverlogfile = "log/mqttd.log";
|
||||
|
||||
while(argc > arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
printf("mqttd IPv4%s\n",
|
||||
|
|
|
@ -53,8 +53,6 @@
|
|||
static bool use_ipv6 = FALSE;
|
||||
static const char *ipv_inuse = "IPv4";
|
||||
|
||||
const char *serverlogfile = ""; /* for a util.c function we don't use */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int arg = 1;
|
||||
|
|
|
@ -56,13 +56,6 @@
|
|||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
#undef EINTR
|
||||
#define EINTR 4 /* errno.h value */
|
||||
#undef ERANGE
|
||||
#define ERANGE 34 /* errno.h value */
|
||||
#endif
|
||||
|
||||
#ifdef USE_IPV6
|
||||
static bool use_ipv6 = FALSE;
|
||||
#endif
|
||||
|
@ -124,11 +117,6 @@ static void storerequest(char *reqbuf, size_t totalsize);
|
|||
|
||||
#define DEFAULT_PORT 8999
|
||||
|
||||
#ifndef DEFAULT_LOGFILE
|
||||
#define DEFAULT_LOGFILE "log/rtspd.log"
|
||||
#endif
|
||||
|
||||
const char *serverlogfile = DEFAULT_LOGFILE;
|
||||
static const char *logdir = "log";
|
||||
static char loglockfile[256];
|
||||
|
||||
|
@ -155,16 +143,6 @@ static char loglockfile[256];
|
|||
|
||||
#define END_OF_HEADERS "\r\n\r\n"
|
||||
|
||||
enum {
|
||||
DOCNUMBER_NOTHING = -7,
|
||||
DOCNUMBER_QUIT = -6,
|
||||
DOCNUMBER_BADCONNECT = -5,
|
||||
DOCNUMBER_INTERNAL = -4,
|
||||
DOCNUMBER_CONNECT = -3,
|
||||
DOCNUMBER_WERULEZ = -2,
|
||||
DOCNUMBER_404 = -1
|
||||
};
|
||||
|
||||
|
||||
/* sent as reply to a QUIT */
|
||||
static const char *docquit =
|
||||
|
@ -1063,6 +1041,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
memset(&req, 0, sizeof(req));
|
||||
|
||||
serverlogfile = "log/rtspd.log";
|
||||
|
||||
while(argc > arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
printf("rtspd IPv4%s"
|
||||
|
|
|
@ -114,29 +114,12 @@
|
|||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
#undef EINTR
|
||||
#define EINTR 4 /* errno.h value */
|
||||
#undef EAGAIN
|
||||
#define EAGAIN 11 /* errno.h value */
|
||||
#undef ENOMEM
|
||||
#define ENOMEM 12 /* errno.h value */
|
||||
#undef EINVAL
|
||||
#define EINVAL 22 /* errno.h value */
|
||||
#endif
|
||||
|
||||
#define DEFAULT_PORT 8999
|
||||
|
||||
#ifndef DEFAULT_LOGFILE
|
||||
#define DEFAULT_LOGFILE "log/sockfilt.log"
|
||||
#endif
|
||||
|
||||
/* buffer is this excessively large only to be able to support things like
|
||||
test 1003 which tests exceedingly large server response lines */
|
||||
#define BUFFER_SIZE 17010
|
||||
|
||||
const char *serverlogfile = DEFAULT_LOGFILE;
|
||||
|
||||
static bool verbose = FALSE;
|
||||
static bool bind_only = FALSE;
|
||||
#ifdef USE_IPV6
|
||||
|
@ -1406,6 +1389,8 @@ int main(int argc, char *argv[])
|
|||
enum sockmode mode = PASSIVE_LISTEN; /* default */
|
||||
const char *addr = NULL;
|
||||
|
||||
serverlogfile = "log/sockfilt.log";
|
||||
|
||||
while(argc > arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
printf("sockfilt IPv4%s\n",
|
||||
|
|
|
@ -85,17 +85,8 @@
|
|||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
#undef EINTR
|
||||
#define EINTR 4 /* errno.h value */
|
||||
#endif
|
||||
|
||||
#define DEFAULT_PORT 8905
|
||||
|
||||
#ifndef DEFAULT_LOGFILE
|
||||
#define DEFAULT_LOGFILE "log/socksd.log"
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_REQFILE
|
||||
#define DEFAULT_REQFILE "log/socksd-request.log"
|
||||
#endif
|
||||
|
@ -134,7 +125,6 @@ struct configurable {
|
|||
|
||||
static struct configurable config;
|
||||
|
||||
const char *serverlogfile = DEFAULT_LOGFILE;
|
||||
static const char *reqlogfile = DEFAULT_REQFILE;
|
||||
static const char *configfile = DEFAULT_CONFIG;
|
||||
|
||||
|
@ -979,6 +969,8 @@ int main(int argc, char *argv[])
|
|||
bool unlink_socket = false;
|
||||
#endif
|
||||
|
||||
serverlogfile = "log/socksd.log";
|
||||
|
||||
while(argc > arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
printf("socksd IPv4%s\n",
|
||||
|
|
|
@ -58,15 +58,6 @@
|
|||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
#undef EINTR
|
||||
#define EINTR 4 /* errno.h value */
|
||||
#undef EAGAIN
|
||||
#define EAGAIN 11 /* errno.h value */
|
||||
#undef ERANGE
|
||||
#define ERANGE 34 /* errno.h value */
|
||||
#endif
|
||||
|
||||
static int socket_domain = AF_INET;
|
||||
static bool use_gopher = FALSE;
|
||||
static int serverlogslocked = 0;
|
||||
|
@ -131,11 +122,6 @@ static void storerequest(const char *reqbuf, size_t totalsize);
|
|||
|
||||
#define DEFAULT_PORT 8999
|
||||
|
||||
#ifndef DEFAULT_LOGFILE
|
||||
#define DEFAULT_LOGFILE "log/sws.log"
|
||||
#endif
|
||||
|
||||
const char *serverlogfile = DEFAULT_LOGFILE;
|
||||
static const char *logdir = "log";
|
||||
static char loglockfile[256];
|
||||
|
||||
|
@ -151,7 +137,7 @@ static char loglockfile[256];
|
|||
|
||||
/* file in which additional instructions may be found */
|
||||
#define DEFAULT_CMDFILE "log/server.cmd"
|
||||
const char *cmdfile = DEFAULT_CMDFILE;
|
||||
static const char *cmdfile = DEFAULT_CMDFILE;
|
||||
|
||||
/* very-big-path support */
|
||||
#define MAXDOCNAMELEN 140000
|
||||
|
@ -185,13 +171,6 @@ const char *cmdfile = DEFAULT_CMDFILE;
|
|||
|
||||
#define END_OF_HEADERS "\r\n\r\n"
|
||||
|
||||
enum {
|
||||
DOCNUMBER_NOTHING = -4,
|
||||
DOCNUMBER_QUIT = -3,
|
||||
DOCNUMBER_WERULEZ = -2,
|
||||
DOCNUMBER_404 = -1
|
||||
};
|
||||
|
||||
static const char *end_of_headers = END_OF_HEADERS;
|
||||
|
||||
/* sent as reply to a QUIT */
|
||||
|
@ -2060,6 +2039,8 @@ int main(int argc, char *argv[])
|
|||
/* a default CONNECT port is basically pointless but still ... */
|
||||
size_t socket_idx;
|
||||
|
||||
serverlogfile = "log/sws.log";
|
||||
|
||||
while(argc > arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
puts("sws IPv4"
|
||||
|
|
|
@ -150,10 +150,6 @@ struct bf {
|
|||
#undef MIN
|
||||
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||
|
||||
#ifndef DEFAULT_LOGFILE
|
||||
#define DEFAULT_LOGFILE "log/tftpd.log"
|
||||
#endif
|
||||
|
||||
#define REQUEST_DUMP "server.input"
|
||||
|
||||
#define DEFAULT_PORT 8999 /* UDP */
|
||||
|
@ -205,7 +201,6 @@ static bool use_ipv6 = FALSE;
|
|||
#endif
|
||||
static const char *ipv_inuse = "IPv4";
|
||||
|
||||
const char *serverlogfile = DEFAULT_LOGFILE;
|
||||
static const char *logdir = "log";
|
||||
static char loglockfile[256];
|
||||
static const char *pidname = ".tftpd.pid";
|
||||
|
@ -564,6 +559,8 @@ int main(int argc, char **argv)
|
|||
|
||||
memset(&test, 0, sizeof(test));
|
||||
|
||||
serverlogfile = "log/tftpd.log";
|
||||
|
||||
while(argc > arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
printf("tftpd IPv4%s\n",
|
||||
|
|
|
@ -54,13 +54,9 @@
|
|||
#include "getpart.h"
|
||||
#include "util.h"
|
||||
#include "timeval.h"
|
||||
#include "timediff.h"
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
#undef EINTR
|
||||
#define EINTR 4 /* errno.h value */
|
||||
#undef EINVAL
|
||||
#define EINVAL 22 /* errno.h value */
|
||||
#endif
|
||||
const char *serverlogfile = NULL; /* needs init from main() */
|
||||
|
||||
static struct timeval tvnow(void);
|
||||
|
||||
|
@ -143,7 +139,7 @@ void logmsg(const char *msg, ...)
|
|||
|
||||
#ifdef _WIN32
|
||||
/* use instead of perror() on generic Windows */
|
||||
void win32_perror(const char *msg)
|
||||
static void win32_perror(const char *msg)
|
||||
{
|
||||
char buf[512];
|
||||
int err = SOCKERRNO;
|
||||
|
@ -174,7 +170,7 @@ int win32_init(void)
|
|||
err = WSAStartup(wVersionRequested, &wsaData);
|
||||
|
||||
if(err) {
|
||||
perror("Winsock init failed");
|
||||
win32_perror("Winsock init failed");
|
||||
logmsg("Error initialising Winsock -- aborting");
|
||||
return 1;
|
||||
}
|
||||
|
@ -182,7 +178,7 @@ int win32_init(void)
|
|||
if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) ||
|
||||
HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested) ) {
|
||||
WSACleanup();
|
||||
perror("Winsock init failed");
|
||||
win32_perror("Winsock init failed");
|
||||
logmsg("No suitable winsock.dll found -- aborting");
|
||||
return 1;
|
||||
}
|
||||
|
@ -202,23 +198,36 @@ const char *sstrerror(int err)
|
|||
/* set by the main code to point to where the test dir is */
|
||||
const char *path = ".";
|
||||
|
||||
FILE *test2fopen(long testno, const char *logdir)
|
||||
FILE *test2fopen(long testno, const char *logdir2)
|
||||
{
|
||||
FILE *stream;
|
||||
char filename[256];
|
||||
/* first try the alternative, preprocessed, file */
|
||||
msnprintf(filename, sizeof(filename), ALTTEST_DATA_PATH, logdir, testno);
|
||||
msnprintf(filename, sizeof(filename), "%s/test%ld", logdir2, testno);
|
||||
stream = fopen(filename, "rb");
|
||||
if(stream)
|
||||
return stream;
|
||||
|
||||
/* then try the source version */
|
||||
msnprintf(filename, sizeof(filename), TEST_DATA_PATH, path, testno);
|
||||
msnprintf(filename, sizeof(filename), "%s/data/test%ld", path, testno);
|
||||
stream = fopen(filename, "rb");
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
#if !defined(MSDOS) && !defined(USE_WINSOCK)
|
||||
static long timediff(struct timeval newer, struct timeval older)
|
||||
{
|
||||
timediff_t diff = newer.tv_sec-older.tv_sec;
|
||||
if(diff >= (LONG_MAX/1000))
|
||||
return LONG_MAX;
|
||||
else if(diff <= (LONG_MIN/1000))
|
||||
return LONG_MIN;
|
||||
return (long)(newer.tv_sec-older.tv_sec)*1000+
|
||||
(long)(newer.tv_usec-older.tv_usec)/1000;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Portable function used for waiting a specific amount of ms.
|
||||
* Waiting indefinitely with this function is not allowed, a
|
||||
|
@ -455,17 +464,6 @@ static struct timeval tvnow(void)
|
|||
|
||||
#endif
|
||||
|
||||
long timediff(struct timeval newer, struct timeval older)
|
||||
{
|
||||
timediff_t diff = newer.tv_sec-older.tv_sec;
|
||||
if(diff >= (LONG_MAX/1000))
|
||||
return LONG_MAX;
|
||||
else if(diff <= (LONG_MIN/1000))
|
||||
return LONG_MIN;
|
||||
return (long)(newer.tv_sec-older.tv_sec)*1000+
|
||||
(long)(newer.tv_usec-older.tv_usec)/1000;
|
||||
}
|
||||
|
||||
/* vars used to keep around previous signal handlers */
|
||||
|
||||
typedef void (*SIGHANDLER_T)(int);
|
||||
|
@ -633,7 +631,7 @@ static unsigned int WINAPI main_window_loop(void *lpParameter)
|
|||
wc.hInstance = (HINSTANCE)lpParameter;
|
||||
wc.lpszClassName = TEXT("MainWClass");
|
||||
if(!RegisterClass(&wc)) {
|
||||
perror("RegisterClass failed");
|
||||
win32_perror("RegisterClass failed");
|
||||
return (DWORD)-1;
|
||||
}
|
||||
|
||||
|
@ -645,14 +643,14 @@ static unsigned int WINAPI main_window_loop(void *lpParameter)
|
|||
(HWND)NULL, (HMENU)NULL,
|
||||
wc.hInstance, (LPVOID)NULL);
|
||||
if(!hidden_main_window) {
|
||||
perror("CreateWindowEx failed");
|
||||
win32_perror("CreateWindowEx failed");
|
||||
return (DWORD)-1;
|
||||
}
|
||||
|
||||
do {
|
||||
ret = GetMessage(&msg, NULL, 0, 0);
|
||||
if(ret == -1) {
|
||||
perror("GetMessage failed");
|
||||
win32_perror("GetMessage failed");
|
||||
return (DWORD)-1;
|
||||
}
|
||||
else if(ret) {
|
||||
|
|
|
@ -25,12 +25,33 @@
|
|||
***************************************************************************/
|
||||
#include "server_setup.h"
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
/* errno.h values */
|
||||
#undef EINTR
|
||||
#define EINTR 4
|
||||
#undef EAGAIN
|
||||
#define EAGAIN 11
|
||||
#undef ENOMEM
|
||||
#define ENOMEM 12
|
||||
#undef EINVAL
|
||||
#define EINVAL 22
|
||||
#undef ERANGE
|
||||
#define ERANGE 34
|
||||
#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);
|
||||
long timediff(struct timeval newer, struct timeval older);
|
||||
|
||||
#define TEST_DATA_PATH "%s/data/test%ld"
|
||||
#define ALTTEST_DATA_PATH "%s/test%ld"
|
||||
#define SERVERLOGS_LOCKDIR "lock" /* within logdir */
|
||||
|
||||
/* global variable, where to find the 'data' dir */
|
||||
|
@ -39,24 +60,12 @@ extern const char *path;
|
|||
/* global variable, log file name */
|
||||
extern const char *serverlogfile;
|
||||
|
||||
extern const char *cmdfile;
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <process.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define sleep(sec) Sleep ((sec)*1000)
|
||||
|
||||
#undef perror
|
||||
#define perror(m) win32_perror(m)
|
||||
void win32_perror(const char *msg);
|
||||
|
||||
int win32_init(void);
|
||||
const char *sstrerror(int err);
|
||||
#else /* _WIN32 */
|
||||
|
||||
#else
|
||||
#define sstrerror(e) strerror(e)
|
||||
#endif /* _WIN32 */
|
||||
#endif
|
||||
|
||||
/* fopens the test case file */
|
||||
FILE *test2fopen(long testno, const char *logdir);
|
||||
|
@ -83,13 +92,10 @@ void install_signal_handlers(bool keep_sigalrm);
|
|||
void restore_signal_handlers(bool keep_sigalrm);
|
||||
|
||||
#ifdef USE_UNIX_SOCKETS
|
||||
|
||||
#include <curl/curl.h> /* for curl_socket_t */
|
||||
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
#include <sys/un.h> /* for sockaddr_un */
|
||||
#endif /* HAVE_SYS_UN_H */
|
||||
|
||||
#endif
|
||||
int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
|
||||
struct sockaddr_un *sau);
|
||||
#endif /* USE_UNIX_SOCKETS */
|
||||
|
|
Loading…
Reference in New Issue
Block a user