-#include "config.h"
+/*
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
-/* $Id$
+#include "squid.h"
/*
* On some systems, FD_SETSIZE is set to something lower than the
#define CHANGE_FD_SETSIZE 1
/* Cannot increase FD_SETSIZE on Linux */
-#if defined(_SQUID_LINUX_)
+#if _SQUID_LINUX_
#undef CHANGE_FD_SETSIZE
#define CHANGE_FD_SETSIZE 0
#endif
* to return EINVAL. */
/* Marian Durkovic <marian@svf.stuba.sk> */
/* Peter Wemm <peter@spinner.DIALix.COM> */
-#if defined(_SQUID_FREEBSD_)
+#if _SQUID_FREEBSD_
#include <osreldate.h>
#if __FreeBSD_version < 220000
#undef CHANGE_FD_SETSIZE
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
-#if HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
-#ifdef HAVE_STRING_H
+#if HAVE_STRING_H
#include <string.h>
#endif
-#ifdef HAVE_STRINGS_H
+#if HAVE_STRINGS_H
#include <strings.h>
#endif
-#if HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#if HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
#if HAVE_TIME_H
#include <time.h>
#endif
-#if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
int nfds = 0;
int maxfd = 0;
-
static void
free_request(struct _request *r)
{
reply_done(int fd, void *data)
{
struct _request *r = data;
- if (opt_range); /* skip size checks for now */
+ if (opt_range); /* skip size checks for now */
else if (strcmp(r->method, "HEAD") == 0);
else if (r->bodysize != r->content_length && r->content_length >= 0)
fprintf(stderr, "ERROR: %s got %d of %d bytes\n",
}
struct _request *
- request(char *urlin) {
+request(char *urlin) {
int s = -1, f = -1;
char buf[4096];
char msg[8192];
checksum = "-";
r = calloc(1, sizeof *r);
assert(r != NULL);
- r->url = strdup(url);
+ r->url = xstrdup(url);
assert(r->url);
strcpy(r->method, method);
strcpy(r->requestbodyfile, file);
if (size && strcmp(size, "-") != 0)
r->validsize = atoi(size);
else
- r->validsize = -1; /* Unknown */
+ r->validsize = -1; /* Unknown */
if (checksum && strcmp(checksum, "-") != 0)
r->validsum = strtoul(checksum, NULL, 0);
if (status)
r->validstatus = atoi(status);
- r->content_length = -1; /* Unknown */
+ r->content_length = -1; /* Unknown */
if (opt_accel) {
host = strchr(url, '/') + 2;
url = strchr(host, '/');
} else {
host = NULL;
}
- sprintf(msg, "%s %s HTTP/1.0\r\n", method, url);
+ snprintf(msg, sizeof(msg)-1, "%s %s HTTP/1.0\r\n", method, url);
if (host) {
url[0] = '\0';
- sprintf(buf, "Host: %s\r\n", host);
+ snprintf(buf, sizeof(buf)-1, "Host: %s\r\n", host);
strcat(msg, buf);
url[0] = '/';
}
strcat(msg, "Accept: */*\r\n");
if (opt_ims && (lrand48() & 0x03) == 0) {
w = time(NULL) - (lrand48() & 0x3FFFF);
- sprintf(buf, "If-Modified-Since: %s\r\n", mkrfc850(&w));
+ snprintf(buf, sizeof(buf)-1, "If-Modified-Since: %s\r\n", mkrfc850(&w));
strcat(msg, buf);
}
if (file && strcmp(file, "-") != 0) {
exit(1);
}
fstat(f, &st);
- sprintf(buf, "Content-Length: %d\r\n", (int) st.st_size);
+ snprintf(buf, sizeof(buf)-1, "Content-Length: %d\r\n", (int) st.st_size);
strcat(msg, buf);
}
if (opt_range && (lrand48() & 0x03) == 0) {
strcat(msg, ",");
switch (lrand48() & 0x03) {
case 0:
- sprintf(buf, "-%d", len);
+ snprintf(buf, sizeof(buf)-1, "-%d", len);
break;
case 1:
- sprintf(buf, "%d-", offset);
+ snprintf(buf, sizeof(buf)-1, "%d-", offset);
break;
default:
- sprintf(buf, "%d-%d", offset, offset + len);
+ snprintf(buf, sizeof(buf)-1, "%d-%d", offset, offset + len);
break;
}
strcat(msg, buf);
struct timeval to;
setbuf(stdout, NULL);
setbuf(stderr, NULL);
- progname = strdup(argv[0]);
+ progname = xstrdup(argv[0]);
gettimeofday(&now, NULL);
start = last = now;
- custom_header = strdup("");
+ custom_header = xstrdup("");
while ((c = getopt(argc, argv, "ap:h:H:n:icrl:L:t:")) != -1) {
switch (c) {
case 'a':
proxy_port = atoi(optarg);
break;
case 'h':
- proxy_addr = strdup(optarg);
+ proxy_addr = xstrdup(optarg);
break;
case 'n':
max_connections = atoi(optarg);
printf("Exiting normally\n");
return 0;
}
+