Merge pull request #35 from dtikhonov/regex-win

If regex.h is not present (Windows), use alternative code
This commit is contained in:
LiteSpeed Tech 2018-05-18 09:32:43 -04:00 committed by GitHub
commit 1da9d1fdd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 6 deletions

View file

@ -14,6 +14,9 @@ CHECK_SYMBOL_EXISTS(
HAVE_IP_DONTFRAG
)
INCLUDE(CheckIncludeFiles)
CHECK_INCLUDE_FILES(regex.h HAVE_REGEX)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/test_config.h)

View file

@ -83,15 +83,26 @@ void
prog_print_common_options (const struct prog *prog, FILE *out)
{
fprintf(out,
#if HAVE_REGEX
" -s SERVER Server address. Takes on the form of host:port, host,\n"
" or port. If host is not an IPv4 or IPv6 address, it is\n"
" resolved. If host is not set, the value of SNI is\n"
" use (see the -H flag). If port is not set, the default\n"
" is 443. Examples:\n"
" used (see the -H flag). If port is not set, the default\n"
" is 443.\n"
#else
" -s SERVER Server address. Takes on the form of host:port or host.\n"
" If host is not an IPv4 or IPv6 address, it is resolved.\n"
" If port is not set, the default is 443. If -s is not\n"
" specified, the value of SNI is used (see the -H flag).\n"
#endif
" Examples:\n"
" 127.0.0.1:12345\n"
" ::1:12345\n"
" ::1:443\n"
" example.com\n"
" example.com:8443\n"
#if HAVE_REGEX
" 8443\n"
#endif
#if LSQUIC_DONTFRAG_SUPPORTED
" -D Set `do not fragment' flag on outgoing UDP packets\n"
#endif

View file

@ -28,7 +28,9 @@
#include <sys/queue.h>
#include <fcntl.h>
#include <sys/types.h>
#if HAVE_REGEX
#include <regex.h>
#endif
#include <event2/event.h>
@ -213,13 +215,18 @@ struct service_port *
sport_new (const char *optarg, struct prog *prog)
{
struct service_port *const sport = malloc(sizeof(*sport));
#if HAVE_REGEX
regex_t re;
regmatch_t matches[5];
int re_code, port, e;
const char *host;
int re_code;
const char *port_str;
struct addrinfo hints, *res = NULL;
char errbuf[80];
#else
char *port_str;
#endif
int port, e;
const char *host;
struct addrinfo hints, *res = NULL;
#if __linux__
sport->n_dropped = 0;
sport->drop_init = 0;
@ -240,6 +247,7 @@ sport_new (const char *optarg, struct prog *prog)
else
sport->if_name[0] = '\0';
#endif
#if HAVE_REGEX
re_code = regcomp(&re, "^(.*):([0-9][0-9]*)$"
"|^([0-9][0-9]*)$"
"|^(..*)$"
@ -281,6 +289,20 @@ sport_new (const char *optarg, struct prog *prog)
port_str = "443";
port = 443;
}
#else
host = addr;
port_str = strrchr(addr, ':');
if (port_str)
{
*port_str++ = '\0';
port = atoi(port_str);
}
else
{
port_str = "443";
port = 443;
}
#endif
assert(host);
LSQ_DEBUG("host: %s; port: %d", host, port);
if (strlen(host) > sizeof(sport->host) - 1)
@ -324,8 +346,10 @@ sport_new (const char *optarg, struct prog *prog)
prog->prog_hostname = sport->host;
}
#if HAVE_REGEX
if (0 == re_code)
regfree(&re);
#endif
if (res)
freeaddrinfo(res);
free(addr);
@ -333,8 +357,10 @@ sport_new (const char *optarg, struct prog *prog)
return sport;
err:
#if HAVE_REGEX
if (0 == re_code)
regfree(&re);
#endif
if (res)
freeaddrinfo(res);
free(sport);

View file

@ -3,6 +3,7 @@
#cmakedefine HAVE_IP_DONTFRAG 1
#cmakedefine HAVE_IP_MTU_DISCOVER 1
#cmakedefine HAVE_REGEX 1
#define LSQUIC_DONTFRAG_SUPPORTED (HAVE_IP_DONTFRAG || HAVE_IP_MTU_DISCOVER)