mirror of
https://github.com/curl/curl.git
synced 2026-08-24 11:43:38 +03:00
tests: make individual test sources compile cleanly
Tidy up headers and includes to ensure all individual test source compile cleanly (but not link). To allow running clang-tidy (and possibly other static analyzers) on them. It also improves readability and allows to verify them locally, without the bundle logic. clang-tidy ignores #included C files, so it's blind to bundle C files the include these tests. The current workaround of embedding has a couple of downsides:. meaningless filenames and line numbers, missing issues, messing up self header paths. Thus, running it on individual sources would be beneficial. Also: - de-duplicate includes. - untangle some includes. - formatting/indentation fixes. - merge `getpart.h` into `first.h`. Ref: https://github.com/curl/curl/pull/17680#issuecomment-2991730158 Closes #17703
This commit is contained in:
parent
4d4d09eb7f
commit
6a0cd4feb7
259 changed files with 440 additions and 570 deletions
|
|
@ -29,7 +29,7 @@ BUNDLE = servers
|
|||
FIRSTFILES = first.c first.h
|
||||
|
||||
# Common files used by test programs
|
||||
UTILS = getpart.c getpart.h util.c
|
||||
UTILS = getpart.c util.c
|
||||
|
||||
CURLX_CFILES = \
|
||||
../../lib/curlx/base64.c \
|
||||
|
|
|
|||
|
|
@ -21,32 +21,7 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifndef UNDER_CE
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <curlx.h> /* from the private lib dir */
|
||||
#include "getpart.h"
|
||||
#include "first.h"
|
||||
|
||||
static int dnsd_wrotepidfile = 0;
|
||||
static int dnsd_wroteportfile = 0;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "first.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
@ -37,7 +39,7 @@ int main(int argc, char **argv)
|
|||
|
||||
entry_name = argv[1];
|
||||
entry_func = NULL;
|
||||
for(tmp = 0; tmp < CURL_ARRAYSIZE(s_entries); ++tmp) {
|
||||
for(tmp = 0; s_entries[tmp].ptr; ++tmp) {
|
||||
if(strcmp(entry_name, s_entries[tmp].name) == 0) {
|
||||
entry_func = s_entries[tmp].ptr;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
typedef int (*entry_func_t)(int, char **);
|
||||
|
||||
struct entry_s {
|
||||
|
|
@ -30,4 +32,127 @@ struct entry_s {
|
|||
entry_func_t ptr;
|
||||
};
|
||||
|
||||
extern const struct entry_s s_entries[];
|
||||
|
||||
#ifndef UNDER_CE
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN6_H
|
||||
#include <netinet/in6.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include <curlx.h> /* from the private lib dir */
|
||||
|
||||
/* 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
|
||||
};
|
||||
|
||||
#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;
|
||||
|
||||
/* getpart */
|
||||
#define GPE_NO_BUFFER_SPACE -2
|
||||
#define GPE_OUT_OF_MEMORY -1
|
||||
#define GPE_OK 0
|
||||
#define GPE_END_OF_FILE 1
|
||||
|
||||
extern int getpart(char **outbuf, size_t *outlen,
|
||||
const char *main, const char *sub, FILE *stream);
|
||||
|
||||
/* utility functions */
|
||||
extern char *data_to_hex(char *data, size_t len);
|
||||
extern void logmsg(const char *msg, ...);
|
||||
extern void loghex(unsigned char *buffer, ssize_t len);
|
||||
extern unsigned char byteval(char *value);
|
||||
extern int win32_init(void);
|
||||
extern const char *sstrerror(int err);
|
||||
extern FILE *test2fopen(long testno, const char *logdir2);
|
||||
extern curl_off_t our_getpid(void);
|
||||
extern int write_pidfile(const char *filename);
|
||||
extern int write_portfile(const char *filename, int port);
|
||||
extern void set_advisor_read_lock(const char *filename);
|
||||
extern void clear_advisor_read_lock(const char *filename);
|
||||
static volatile int got_exit_signal = 0;
|
||||
static volatile int exit_signal = 0;
|
||||
#ifdef _WIN32
|
||||
static HANDLE exit_event = NULL;
|
||||
#endif
|
||||
extern void install_signal_handlers(bool keep_sigalrm);
|
||||
extern void restore_signal_handlers(bool keep_sigalrm);
|
||||
#ifdef USE_UNIX_SOCKETS
|
||||
extern int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
|
||||
struct sockaddr_un *sau);
|
||||
#endif
|
||||
extern unsigned short util_ultous(unsigned long ulnum);
|
||||
|
||||
/* 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;
|
||||
|
||||
#define SERVERLOGS_LOCKDIR "lock" /* within logdir */
|
||||
|
||||
#endif /* HEADER_SERVER_FIRST_H */
|
||||
|
|
|
|||
|
|
@ -21,11 +21,7 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#include "getpart.h"
|
||||
#include <curlx.h> /* from the private lib dir */
|
||||
#include "curl_memory.h"
|
||||
#include "first.h"
|
||||
|
||||
#define EAT_SPACE(p) while(*(p) && ISSPACE(*(p))) (p)++
|
||||
|
||||
|
|
@ -43,6 +39,8 @@
|
|||
#define system_strdup strdup
|
||||
#endif
|
||||
|
||||
#include "curl_memory.h"
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DLL)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4232) /* MSVC extension, dllimport identity */
|
||||
|
|
@ -268,8 +266,8 @@ static int decodedata(char **buf, /* dest buffer */
|
|||
* GPE_OUT_OF_MEMORY
|
||||
* GPE_OK
|
||||
*/
|
||||
static int getpart(char **outbuf, size_t *outlen,
|
||||
const char *main, const char *sub, FILE *stream)
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
#ifndef HEADER_CURL_SERVER_GETPART_H
|
||||
#define HEADER_CURL_SERVER_GETPART_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"
|
||||
|
||||
#include "strdup.h"
|
||||
|
||||
#define GPE_NO_BUFFER_SPACE -2
|
||||
#define GPE_OUT_OF_MEMORY -1
|
||||
#define GPE_OK 0
|
||||
#define GPE_END_OF_FILE 1
|
||||
|
||||
static int getpart(char **outbuf, size_t *outlen,
|
||||
const char *main, const char *sub, FILE *stream);
|
||||
|
||||
#endif /* HEADER_CURL_SERVER_GETPART_H */
|
||||
|
|
@ -21,7 +21,8 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
#include "first.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
@ -36,25 +37,6 @@
|
|||
|
||||
/* based on sockfilt.c */
|
||||
|
||||
#ifndef UNDER_CE
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN6_H
|
||||
#include <netinet/in6.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include <curlx.h> /* from the private lib dir */
|
||||
#include "getpart.h"
|
||||
|
||||
#define MQTT_MSG_CONNECT 0x10
|
||||
#define MQTT_MSG_CONNACK 0x20
|
||||
#define MQTT_MSG_PUBLISH 0x30
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
#include "first.h"
|
||||
|
||||
/* Purpose
|
||||
*
|
||||
|
|
@ -33,17 +33,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef _XOPEN_SOURCE_EXTENDED
|
||||
/* This define is "almost" required to build on HP-UX 11 */
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
static int test_resolve(int argc, char *argv[])
|
||||
{
|
||||
int arg = 1;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
#include "first.h"
|
||||
|
||||
/*
|
||||
* curl's test suite Real Time Streaming Protocol (RTSP) server.
|
||||
|
|
@ -29,28 +29,10 @@
|
|||
* This source file was started based on curl's HTTP test suite server.
|
||||
*/
|
||||
|
||||
#ifndef UNDER_CE
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN6_H
|
||||
#include <netinet/in6.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_TCP_H
|
||||
#include <netinet/tcp.h> /* for TCP_NODELAY */
|
||||
#endif
|
||||
|
||||
#include <curlx.h> /* from the private lib dir */
|
||||
#include "getpart.h"
|
||||
|
||||
#undef REQBUFSIZ
|
||||
#define REQBUFSIZ 150000
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
#include "first.h"
|
||||
|
||||
/* Purpose
|
||||
*
|
||||
|
|
@ -85,23 +85,6 @@
|
|||
* it!
|
||||
*/
|
||||
|
||||
#ifndef UNDER_CE
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN6_H
|
||||
#include <netinet/in6.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include <curlx.h> /* from the private lib dir */
|
||||
|
||||
/* buffer is this excessively large only to be able to support things like
|
||||
test 1003 which tests exceedingly large server response lines */
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
#include "first.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Function
|
||||
|
|
@ -57,24 +58,6 @@
|
|||
|
||||
/* based on sockfilt.c */
|
||||
|
||||
#ifndef UNDER_CE
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN6_H
|
||||
#include <netinet/in6.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include <curlx.h> /* from the private lib dir */
|
||||
|
||||
static const char *backendaddr = "127.0.0.1";
|
||||
static unsigned short backendport = 0; /* default is use client's */
|
||||
|
||||
|
|
@ -824,7 +807,7 @@ static curl_socket_t socksd_sockdaemon(curl_socket_t sock,
|
|||
#endif /* USE_IPV6 */
|
||||
#ifdef USE_UNIX_SOCKETS
|
||||
case AF_UNIX:
|
||||
rc = bind_unix_socket(sock, unix_socket, &listener.sau);
|
||||
rc = bind_unix_socket(sock, unix_socket, &listener.sau);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
#include "first.h"
|
||||
|
||||
/* sws.c: simple (silly?) web server
|
||||
|
||||
|
|
@ -30,28 +30,10 @@
|
|||
|
||||
*/
|
||||
|
||||
#ifndef UNDER_CE
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN6_H
|
||||
#include <netinet/in6.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_TCP_H
|
||||
#include <netinet/tcp.h> /* for TCP_NODELAY */
|
||||
#endif
|
||||
|
||||
#include <curlx.h> /* from the private lib dir */
|
||||
#include "getpart.h"
|
||||
|
||||
static bool use_gopher = FALSE;
|
||||
static bool is_proxy = FALSE;
|
||||
|
||||
|
|
|
|||
|
|
@ -49,27 +49,14 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-4-Clause-UC
|
||||
*/
|
||||
|
||||
#include "curl_setup.h"
|
||||
#include "first.h"
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifndef UNDER_CE
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h> /* for ioctl() */
|
||||
#endif
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#include <sys/filio.h> /* FIONREAD on Solaris 7 */
|
||||
#endif
|
||||
|
|
@ -82,9 +69,6 @@
|
|||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <curlx.h> /* from the private lib dir */
|
||||
#include "getpart.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* This is a rewrite/clone of the arpa/tftp.h file for systems without it. *
|
||||
*****************************************************************************/
|
||||
|
|
@ -119,7 +103,6 @@ struct tftphdr {
|
|||
#define TFTP_EBADID 5
|
||||
#define TFTP_EEXISTS 6
|
||||
#define TFTP_ENOUSER 7
|
||||
/****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* STRUCT DECLARATIONS AND DEFINES *
|
||||
|
|
|
|||
|
|
@ -21,102 +21,17 @@
|
|||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
#include "first.h"
|
||||
|
||||
#ifndef UNDER_CE
|
||||
#include <signal.h>
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN6_H
|
||||
#include <netinet/in6.h>
|
||||
#endif
|
||||
#ifdef _XOPEN_SOURCE_EXTENDED
|
||||
/* This define is "almost" required to build on HP-UX 11 */
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include <curlx.h> /* from the private lib dir */
|
||||
|
||||
/* 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
|
||||
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.
|
||||
*/
|
||||
static char *data_to_hex(char *data, size_t len)
|
||||
char *data_to_hex(char *data, size_t len)
|
||||
{
|
||||
static char buf[256*3];
|
||||
size_t i;
|
||||
|
|
@ -139,7 +54,26 @@ static char *data_to_hex(char *data, size_t len)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static void logmsg(const char *msg, ...)
|
||||
void loghex(unsigned char *buffer, ssize_t len)
|
||||
{
|
||||
char data[12000];
|
||||
ssize_t i;
|
||||
unsigned char *ptr = buffer;
|
||||
char *optr = data;
|
||||
ssize_t width = 0;
|
||||
int left = sizeof(data);
|
||||
|
||||
for(i = 0; i < len && (left >= 0); i++) {
|
||||
snprintf(optr, left, "%02x", ptr[i]);
|
||||
width += 2;
|
||||
optr += 2;
|
||||
left -= 2;
|
||||
}
|
||||
if(width)
|
||||
logmsg("'%s'", data);
|
||||
}
|
||||
|
||||
void logmsg(const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buffer[2048 + 1];
|
||||
|
|
@ -197,26 +131,7 @@ static void logmsg(const char *msg, ...)
|
|||
}
|
||||
}
|
||||
|
||||
static void loghex(unsigned char *buffer, ssize_t len)
|
||||
{
|
||||
char data[12000];
|
||||
ssize_t i;
|
||||
unsigned char *ptr = buffer;
|
||||
char *optr = data;
|
||||
ssize_t width = 0;
|
||||
int left = sizeof(data);
|
||||
|
||||
for(i = 0; i < len && (left >= 0); i++) {
|
||||
snprintf(optr, left, "%02x", ptr[i]);
|
||||
width += 2;
|
||||
optr += 2;
|
||||
left -= 2;
|
||||
}
|
||||
if(width)
|
||||
logmsg("'%s'", data);
|
||||
}
|
||||
|
||||
static unsigned char byteval(char *value)
|
||||
unsigned char byteval(char *value)
|
||||
{
|
||||
unsigned long num = strtoul(value, NULL, 10);
|
||||
return num & 0xff;
|
||||
|
|
@ -244,7 +159,7 @@ static void win32_cleanup(void)
|
|||
_flushall();
|
||||
}
|
||||
|
||||
static int win32_init(void)
|
||||
int win32_init(void)
|
||||
{
|
||||
curlx_now_init();
|
||||
#ifdef USE_WINSOCK
|
||||
|
|
@ -276,7 +191,7 @@ static int win32_init(void)
|
|||
}
|
||||
|
||||
/* socket-safe strerror (works on Winsock errors, too) */
|
||||
static const char *sstrerror(int err)
|
||||
const char *sstrerror(int err)
|
||||
{
|
||||
static char buf[512];
|
||||
return curlx_winapi_strerror(err, buf, sizeof(buf));
|
||||
|
|
@ -286,7 +201,7 @@ static const char *sstrerror(int err)
|
|||
#endif /* _WIN32 */
|
||||
|
||||
/* fopens the test case file */
|
||||
static FILE *test2fopen(long testno, const char *logdir2)
|
||||
FILE *test2fopen(long testno, const char *logdir2)
|
||||
{
|
||||
FILE *stream;
|
||||
char filename[256];
|
||||
|
|
@ -309,7 +224,7 @@ static FILE *test2fopen(long testno, const char *logdir2)
|
|||
#define t_getpid() getpid()
|
||||
#endif
|
||||
|
||||
static curl_off_t our_getpid(void)
|
||||
curl_off_t our_getpid(void)
|
||||
{
|
||||
curl_off_t pid = (curl_off_t)t_getpid();
|
||||
#ifdef _WIN32
|
||||
|
|
@ -326,7 +241,7 @@ static curl_off_t our_getpid(void)
|
|||
return pid;
|
||||
}
|
||||
|
||||
static int write_pidfile(const char *filename)
|
||||
int write_pidfile(const char *filename)
|
||||
{
|
||||
FILE *pidfile;
|
||||
curl_off_t pid;
|
||||
|
|
@ -344,7 +259,7 @@ static int write_pidfile(const char *filename)
|
|||
}
|
||||
|
||||
/* store the used port number in a file */
|
||||
static int write_portfile(const char *filename, int port)
|
||||
int write_portfile(const char *filename, int port)
|
||||
{
|
||||
FILE *portfile = fopen(filename, "wb");
|
||||
if(!portfile) {
|
||||
|
|
@ -357,7 +272,7 @@ static int write_portfile(const char *filename, int port)
|
|||
return 1; /* success */
|
||||
}
|
||||
|
||||
static void set_advisor_read_lock(const char *filename)
|
||||
void set_advisor_read_lock(const char *filename)
|
||||
{
|
||||
FILE *lockfile;
|
||||
int error = 0;
|
||||
|
|
@ -379,7 +294,7 @@ static void set_advisor_read_lock(const char *filename)
|
|||
filename, errno, strerror(errno));
|
||||
}
|
||||
|
||||
static void clear_advisor_read_lock(const char *filename)
|
||||
void clear_advisor_read_lock(const char *filename)
|
||||
{
|
||||
int error = 0;
|
||||
int res;
|
||||
|
|
@ -440,18 +355,6 @@ static HANDLE thread_main_window = NULL;
|
|||
static HWND hidden_main_window = NULL;
|
||||
#endif
|
||||
|
||||
/* global variable which if set indicates that the program should finish */
|
||||
static volatile int got_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
|
||||
/* 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
|
||||
* should finish its execution in a controlled manner as soon as possible.
|
||||
* The first time this is called it will set got_exit_signal to one and
|
||||
|
|
@ -665,7 +568,7 @@ static SIGHANDLER_T set_signal(int signum, SIGHANDLER_T handler,
|
|||
}
|
||||
#endif
|
||||
|
||||
static void install_signal_handlers(bool keep_sigalrm)
|
||||
void install_signal_handlers(bool keep_sigalrm)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
/* setup Windows exit event before any signal can trigger */
|
||||
|
|
@ -733,7 +636,7 @@ static void install_signal_handlers(bool keep_sigalrm)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void restore_signal_handlers(bool keep_sigalrm)
|
||||
void restore_signal_handlers(bool keep_sigalrm)
|
||||
{
|
||||
#ifdef SIGHUP
|
||||
if(SIG_ERR != old_sighup_handler)
|
||||
|
|
@ -789,8 +692,8 @@ static void restore_signal_handlers(bool keep_sigalrm)
|
|||
|
||||
#ifdef USE_UNIX_SOCKETS
|
||||
|
||||
static int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
|
||||
struct sockaddr_un *sau)
|
||||
int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
|
||||
struct sockaddr_un *sau)
|
||||
{
|
||||
int error;
|
||||
int rc;
|
||||
|
|
@ -860,7 +763,7 @@ static 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)
|
||||
|
||||
static unsigned short util_ultous(unsigned long ulnum)
|
||||
unsigned short util_ultous(unsigned long ulnum)
|
||||
{
|
||||
#ifdef __INTEL_COMPILER
|
||||
# pragma warning(push)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue