Big reformatting of everything after a change of indent options (now --no-tabs)

master
Stephane Bortzmeyer 16 years ago
parent 5dc79b9cc8
commit 0f6aefca60

@ -7,30 +7,26 @@
#define FREE(x) if (x) {free(x); x = NULL;}
struct struct_parts
{
struct struct_parts {
char *access;
char *host;
char *absolute;
char *relative;
/* char * search; no - treated as part of path */
char *anchor;
};
};
/* Strings of any length
** ---------------------
*/
PUBLIC int strcasecomp
ARGS2 (
CONST char *, a,
CONST char *, b)
ARGS2(CONST char *, a, CONST char *, b)
{
CONST char *p = a;
CONST char *q = b;
for (p = a, q = b; *p && *q; p++, q++)
{
int diff = TOLOWER (*p) - TOLOWER (*q);
for (p = a, q = b; *p && *q; p++, q++) {
int diff = TOLOWER(*p) - TOLOWER(*q);
if (diff)
return diff;
}
@ -45,69 +41,55 @@ ARGS2 (
** ----------------
*/
PUBLIC int strncasecomp
ARGS3 (
CONST char *, a,
CONST char *, b,
int, n)
ARGS3(CONST char *, a, CONST char *, b, int, n)
{
CONST char *p = a;
CONST char *q = b;
for (p = a, q = b;;
p++, q++)
{
for (p = a, q = b;; p++, q++) {
int diff;
if (p == (a + n))
return 0; /* Match up to n characters */
if (!(*p && *q))
return (*p - *q);
diff = TOLOWER (*p) - TOLOWER (*q);
diff = TOLOWER(*p) - TOLOWER(*q);
if (diff)
return diff;
}
/*NOTREACHED */
/* NOTREACHED */
}
/* Allocate a new copy of a string, and returns it
*/
PUBLIC char *HTSACopy
ARGS2 (
char **, dest,
CONST char *, src)
ARGS2(char **, dest, CONST char *, src)
{
FREE (*dest);
if (src)
{
*dest = (char *) malloc (strlen (src) + 1);
FREE(*dest);
if (src) {
*dest = (char *) malloc(strlen(src) + 1);
if (*dest == NULL)
outofmem (__FILE__, "HTSACopy");
strcpy (*dest, src);
outofmem(__FILE__, "HTSACopy");
strcpy(*dest, src);
}
return *dest;
}
/* String Allocate and Concatenate
*/
PUBLIC char *HTSACat
ARGS2 (
char **, dest,
CONST char *, src)
ARGS2(char **, dest, CONST char *, src)
{
if (src && *src)
{
if (*dest)
{
int length = strlen (*dest);
*dest = (char *) realloc (*dest, length + strlen (src) + 1);
if (src && *src) {
if (*dest) {
int length = strlen(*dest);
*dest = (char *) realloc(*dest, length + strlen(src) + 1);
if (*dest == NULL)
outofmem (__FILE__, "HTSACat");
strcpy (*dest + length, src);
}
else
{
*dest = (char *) malloc (strlen (src) + 1);
outofmem(__FILE__, "HTSACat");
strcpy(*dest + length, src);
} else {
*dest = (char *) malloc(strlen(src) + 1);
if (*dest == NULL)
outofmem (__FILE__, "HTSACat");
strcpy (*dest, src);
outofmem(__FILE__, "HTSACat");
strcpy(*dest, src);
}
}
return *dest;
@ -123,21 +105,18 @@ ARGS2 (
** All trailing white space is OVERWRITTEN with zero.
*/
PUBLIC char *HTStrip
ARGS1 (
char *, s)
ARGS1(char *, s)
{
#define SPACE(c) ((c == ' ') || (c == '\t') || (c == '\n'))
char *p = s;
for (p = s; *p; p++)
; /* Find end of string */
for (p--; p >= s; p--)
{
if (SPACE (*p))
for (p = s; *p; p++); /* Find end of string */
for (p--; p >= s; p--) {
if (SPACE(*p))
*p = '\0'; /* Zap trailing blanks */
else
break;
}
while (SPACE (*s))
while (SPACE(*s))
s++; /* Strip leading blanks */
return s;
}
@ -153,9 +132,7 @@ ARGS1 (
** Any which are nonzero point to zero terminated strings.
*/
PRIVATE void scan
ARGS2 (
char *, name,
struct struct_parts *, parts)
ARGS2(char *, name, struct struct_parts *, parts)
{
char *after_access;
char *p;
@ -171,10 +148,8 @@ ARGS2 (
** Scan left-to-right for a scheme (access).
*/
after_access = name;
for (p = name; *p; p++)
{
if (*p == ':')
{
for (p = name; *p; p++) {
if (*p == ':') {
*p = '\0';
parts->access = name; /* Access name has been specified */
after_access = (p + 1);
@ -185,16 +160,13 @@ ARGS2 (
}
#ifdef NOTDEFINED
for (p = (name + length - 1); p >= name; p--)
{
for (p = (name + length - 1); p >= name; p--) {
#endif /* NOTDEFINED */
/*
** Scan left-to-right for a fragment (anchor).
*/
for (p = after_access; *p; p++)
{
if (*p == '#')
{
for (p = after_access; *p; p++) {
if (*p == '#') {
parts->anchor = (p + 1);
*p = '\0'; /* terminate the rest */
}
@ -204,41 +176,32 @@ ARGS2 (
** Scan left-to-right for a host or absolute path.
*/
p = after_access;
if (*p == '/')
{
if (p[1] == '/')
{
if (*p == '/') {
if (p[1] == '/') {
parts->host = (p + 2); /* host has been specified */
*p = '\0'; /* Terminate access */
p = strchr (parts->host, '/'); /* look for end of host name if any */
if (p != NULL)
{
p = strchr(parts->host, '/'); /* look for end of host name if any */
if (p != NULL) {
*p = '\0'; /* Terminate host */
parts->absolute = (p + 1); /* Root has been found */
}
}
else
{
} else {
parts->absolute = (p + 1); /* Root found but no host */
}
}
else
{
parts->relative = (*after_access) ?
after_access : NULL; /* NULL for "" */
} else {
parts->relative = (*after_access) ? after_access : NULL; /* NULL for
* "" */
}
/*
** Check schemes that commonly have unescaped hashes.
*/
if (parts->access && parts->anchor)
{
if ((!parts->host && strcasecomp (parts->access, "lynxcgi")) ||
!strcasecomp (parts->access, "nntp") ||
!strcasecomp (parts->access, "snews") ||
!strcasecomp (parts->access, "news") ||
!strcasecomp (parts->access, "data"))
{
if (parts->access && parts->anchor) {
if ((!parts->host && strcasecomp(parts->access, "lynxcgi")) ||
!strcasecomp(parts->access, "nntp") ||
!strcasecomp(parts->access, "snews") ||
!strcasecomp(parts->access, "news") ||
!strcasecomp(parts->access, "data")) {
/*
* Access specified but no host and not a lynxcgi URL, so the
* anchor may not really be one, e.g., news:j462#36487@foo.bar,
@ -249,22 +212,19 @@ ARGS2 (
parts->anchor = NULL;
}
}
#ifdef NOT_DEFINED /* search is just treated as part of path */
{
char *p = (relative ? relative : absolute);
if (p != NULL)
{
char *q = strchr (p, '?'); /* Any search string? */
if (q != NULL)
{
if (p != NULL) {
char *q = strchr(p, '?'); /* Any search string? */
if (q != NULL) {
*q = '\0'; /* If so, chop that off. */
parts->search = (q + 1);
}
}
}
#endif /* NOT_DEFINED */
} /*scan */
} /* scan */
/* Parse a Name relative to another name. HTParse()
@ -281,11 +241,8 @@ ARGS2 (
** On exit,
** returns A pointer to a malloc'd string which MUST BE FREED
*/
PUBLIC char *HTParse ARGS3 (
CONST char *, aName,
CONST char *, relatedName,
int, wanted)
{
PUBLIC char *HTParse ARGS3(CONST char *, aName,
CONST char *, relatedName, int, wanted) {
char *result = NULL;
char *return_value = NULL;
int len;
@ -296,51 +253,47 @@ ARGS2 (
struct struct_parts given, related;
if (TRACE)
fprintf (stderr,
fprintf(stderr,
"HTParse: aName:%s relatedName:%s\n", aName, relatedName);
/*
** Allocate the output string.
*/
len = strlen (aName) + strlen (relatedName) + 10;
result = (char *) malloc (len); /* Lots of space: more than enough */
len = strlen(aName) + strlen(relatedName) + 10;
result = (char *) malloc(len); /* Lots of space: more than enough */
if (result == NULL)
outofmem (__FILE__, "HTParse");
outofmem(__FILE__, "HTParse");
result[0] = '\0'; /* Clear string */
/*
** Make working copies of the input strings to cut up.
*/
StrAllocCopy (name, aName);
StrAllocCopy (rel, relatedName);
StrAllocCopy(name, aName);
StrAllocCopy(rel, relatedName);
/*
** Cut up the strings into URL fields.
*/
scan (name, &given);
scan (rel, &related);
scan(name, &given);
scan(rel, &related);
/*
** Handle the scheme (access) field.
*/
if (given.access && given.host && !given.relative && !given.absolute)
{
if (!strcmp (given.access, "http") ||
!strcmp (given.access, "https") ||
!strcmp (given.access, "ftp"))
if (given.access && given.host && !given.relative && !given.absolute) {
if (!strcmp(given.access, "http") ||
!strcmp(given.access, "https") || !strcmp(given.access, "ftp"))
/*
** Assume root.
*/
given.absolute = "";
}
access = given.access ? given.access : related.access;
if (wanted & PARSE_ACCESS)
{
if (access)
{
strcat (result, access);
if (wanted & PARSE_ACCESS) {
if (access) {
strcat(result, access);
if (wanted & PARSE_PUNCTUATION)
strcat (result, ":");
strcat(result, ":");
}
}
@ -360,10 +313,10 @@ ARGS2 (
** If you want to try it again yourself,
** uncomment the strncasecomp() below. - FM
*/
if ((given.access && related.access) &&
( /* strcasecomp(given.access, "file") || */
strcmp (given.access, related.access)))
{
if ((given.access && related.access) && ( /* strcasecomp(given.access,
* "file") || */
strcmp(given.access,
related.access))) {
related.host = NULL;
related.absolute = NULL;
related.relative = NULL;
@ -374,12 +327,11 @@ ARGS2 (
** Handle the host field.
*/
if (wanted & PARSE_HOST)
if (given.host || related.host)
{
char *tail = result + strlen (result);
if (given.host || related.host) {
char *tail = result + strlen(result);
if (wanted & PARSE_PUNCTUATION)
strcat (result, "//");
strcat (result, given.host ? given.host : related.host);
strcat(result, "//");
strcat(result, given.host ? given.host : related.host);
#define CLEAN_URLS
#ifdef CLEAN_URLS
/*
@ -388,45 +340,39 @@ ARGS2 (
*/
{
char *p, *h;
p = strchr (tail, ':');
if (p != NULL && !isdigit ((unsigned char) p[1]))
p = strchr(tail, ':');
if (p != NULL && !isdigit((unsigned char) p[1]))
/*
** Colon not followed by a port number.
*/
*p = '\0';
if (p != NULL && p != '\0' && access != NULL)
{
if (p != NULL && p != '\0' && access != NULL) {
/*
** Port specified.
*/
if ((!strcmp (access, "http") && !strcmp (p, ":80")) ||
(!strcmp (access, "gopher") && !strcmp (p, ":70")) ||
(!strcmp (access, "ftp") && !strcmp (p, ":21")) ||
(!strcmp (access, "wais") && !strcmp (p, ":210")) ||
(!strcmp (access, "nntp") && !strcmp (p, ":119")) ||
(!strcmp (access, "news") && !strcmp (p, ":119")) ||
(!strcmp (access, "snews") && !strcmp (p, ":563")) ||
(!strcmp (access, "finger") && !strcmp (p, ":79")) ||
(!strcmp (access, "cso") && !strcmp (p, ":105")))
if ((!strcmp(access, "http") && !strcmp(p, ":80")) ||
(!strcmp(access, "gopher") && !strcmp(p, ":70")) ||
(!strcmp(access, "ftp") && !strcmp(p, ":21")) ||
(!strcmp(access, "wais") && !strcmp(p, ":210")) ||
(!strcmp(access, "nntp") && !strcmp(p, ":119")) ||
(!strcmp(access, "news") && !strcmp(p, ":119")) ||
(!strcmp(access, "snews") && !strcmp(p, ":563")) ||
(!strcmp(access, "finger") && !strcmp(p, ":79")) ||
(!strcmp(access, "cso") && !strcmp(p, ":105")))
*p = '\0'; /* It is the default: ignore it */
}
if (p == NULL)
{
int len = strlen (tail);
if (p == NULL) {
int len = strlen(tail);
if (len > 0)
{
if (len > 0) {
h = tail + len - 1; /* last char of hostname */
if (*h == '.')
*h = '\0'; /* chop final . */
}
}
else
{
} else {
h = p;
h--; /* End of hostname */
if (*h == '.')
{
if (*h == '.') {
/*
** Slide p over h.
*/
@ -443,8 +389,7 @@ ARGS2 (
** If different hosts, inherit no path.
*/
if (given.host && related.host)
if (strcmp (given.host, related.host) != 0)
{
if (strcmp(given.host, related.host) != 0) {
related.absolute = NULL;
related.relative = NULL;
related.anchor = NULL;
@ -453,15 +398,12 @@ ARGS2 (
/*
** Handle the path.
*/
if (wanted & PARSE_PATH)
{
if (access && !given.absolute && given.relative)
{
if (!strcasecomp (access, "nntp") ||
!strcasecomp (access, "snews") ||
(!strcasecomp (access, "news") &&
!strncasecomp (result, "news://", 7)))
{
if (wanted & PARSE_PATH) {
if (access && !given.absolute && given.relative) {
if (!strcasecomp(access, "nntp") ||
!strcasecomp(access, "snews") ||
(!strcasecomp(access, "news") &&
!strncasecomp(result, "news://", 7))) {
/*
* Treat all given nntp or snews paths,
* or given paths for news URLs with a host,
@ -471,56 +413,44 @@ ARGS2 (
given.relative = NULL;
}
}
if (given.absolute)
{ /* All is given */
if (given.absolute) { /* All is given */
if (wanted & PARSE_PUNCTUATION)
strcat (result, "/");
strcat (result, given.absolute);
strcat(result, "/");
strcat(result, given.absolute);
if (TRACE)
fprintf (stderr, "1\n");
}
else if (related.absolute)
{ /* Adopt path not name */
strcat (result, "/");
strcat (result, related.absolute);
if (given.relative)
{
p = strchr (result, '?'); /* Search part? */
fprintf(stderr, "1\n");
} else if (related.absolute) { /* Adopt path not name */
strcat(result, "/");
strcat(result, related.absolute);
if (given.relative) {
p = strchr(result, '?'); /* Search part? */
if (p == NULL)
p = (result + strlen (result) - 1);
for (; *p != '/'; p--)
; /* last / */
p = (result + strlen(result) - 1);
for (; *p != '/'; p--); /* last / */
p[1] = '\0'; /* Remove filename */
strcat (result, given.relative); /* Add given one */
HTSimplify (result);
strcat(result, given.relative); /* Add given one */
HTSimplify(result);
}
if (TRACE)
fprintf (stderr, "2\n");
}
else if (given.relative)
{
strcat (result, given.relative); /* what we've got */
fprintf(stderr, "2\n");
} else if (given.relative) {
strcat(result, given.relative); /* what we've got */
if (TRACE)
fprintf (stderr, "3\n");
}
else if (related.relative)
{
strcat (result, related.relative);
fprintf(stderr, "3\n");
} else if (related.relative) {
strcat(result, related.relative);
if (TRACE)
fprintf (stderr, "4\n");
}
else
{ /* No inheritance */
if (strncasecomp (aName, "lynxcgi:", 8) &&
strncasecomp (aName, "lynxexec:", 9) &&
strncasecomp (aName, "lynxprog:", 9))
{
strcat (result, "/");
}
if (!strcmp (result, "news:/"))
fprintf(stderr, "4\n");
} else { /* No inheritance */
if (strncasecomp(aName, "lynxcgi:", 8) &&
strncasecomp(aName, "lynxexec:", 9) &&
strncasecomp(aName, "lynxprog:", 9)) {
strcat(result, "/");
}
if (!strcmp(result, "news:/"))
result[5] = '*';
if (TRACE)
fprintf (stderr, "5\n");
fprintf(stderr, "5\n");
}
}
@ -528,21 +458,18 @@ ARGS2 (
** Handle the fragment (anchor).
*/
if (wanted & PARSE_ANCHOR)
if ((given.anchor && *given.anchor) ||
(!given.anchor && related.anchor))
{
if ((given.anchor && *given.anchor) || (!given.anchor && related.anchor)) {
if (wanted & PARSE_PUNCTUATION)
strcat (result, "#");
strcat (result, (given.anchor) ?
given.anchor : related.anchor);
strcat(result, "#");
strcat(result, (given.anchor) ? given.anchor : related.anchor);
}
if (TRACE)
fprintf (stderr, "HTParse: result:%s\n", result);
FREE (rel);
FREE (name);
fprintf(stderr, "HTParse: result:%s\n", result);
FREE(rel);
FREE(name);
StrAllocCopy (return_value, result);
FREE (result);
StrAllocCopy(return_value, result);
FREE(result);
return return_value; /* exactly the right length */
}
@ -562,24 +489,18 @@ ARGS2 (
**
** or ../../albert.html
*/
PUBLIC void HTSimplify ARGS1 (
char *, filename)
{
PUBLIC void HTSimplify ARGS1(char *, filename) {
char *p;
char *q, *q1;
if (filename == NULL)
return;
if ((filename[0] && filename[1]) && strchr (filename, '/') != NULL)
{
for (p = (filename + 2); *p; p++)
{
if (*p == '/')
{
if ((filename[0] && filename[1]) && strchr(filename, '/') != NULL) {
for (p = (filename + 2); *p; p++) {
if (*p == '/') {
if ((p[1] == '.') && (p[2] == '.') &&
(p[3] == '/' || p[3] == '\0'))
{
(p[3] == '/' || p[3] == '\0')) {
/*
** Handle "/../" or "/..".
*/
@ -588,9 +509,8 @@ ARGS2 (
** Back up to previous slash or beginning of string.
*/
;
if ((q[0] == '/') && strncmp (q, "/../", 4) &&
!((q - 1) > filename && q[-1] == '/'))
{
if ((q[0] == '/') && strncmp(q, "/../", 4) &&
!((q - 1) > filename && q[-1] == '/')) {
/*
** Not at beginning of string or in a
** host field, so remove the "/xxx/..".
@ -604,8 +524,7 @@ ARGS2 (
/*
** Make sure filename has at least one slash.
*/
if (*filename == '\0')
{
if (*filename == '\0') {
*filename = '/';
*(filename + 1) = '\0';
}
@ -615,9 +534,7 @@ ARGS2 (
*/
p = (q - 1);
}
}
else if (p[1] == '.' && p[2] == '/')
{
} else if (p[1] == '.' && p[2] == '/') {
/*
** Handle "./" by removing the characters.
*/
@ -627,9 +544,7 @@ ARGS2 (
*q++ = *q1++;
*q = '\0'; /* terminate */
p--;
}
else if (p[1] == '.' && p[2] == '\0')
{
} else if (p[1] == '.' && p[2] == '\0') {
/*
** Handle terminal "." by removing the character.
*/
@ -657,10 +572,7 @@ ARGS2 (
** The caller is responsible for freeing the resulting name later.
**
*/
PUBLIC char *HTRelative ARGS2 (
CONST char *, aName,
CONST char *, relatedName)
{
PUBLIC char *HTRelative ARGS2(CONST char *, aName, CONST char *, relatedName) {
char *result = NULL;
CONST char *p = aName;
CONST char *q = relatedName;
@ -669,14 +581,12 @@ ARGS2 (
CONST char *last_slash = NULL;
int slashes = 0;
for (; *p; p++, q++)
{ /* Find extent of match */
for (; *p; p++, q++) { /* Find extent of match */
if (*p != *q)
break;
if (*p == ':')
after_access = p + 1;
if (*p == '/')
{
if (*p == '/') {
last_slash = p;
slashes++;
if (slashes == 3)
@ -686,34 +596,27 @@ ARGS2 (
/* q, p point to the first non-matching character or zero */
if (!after_access)
{ /* Different access */
StrAllocCopy (result, aName);
}
else if (slashes < 3)
{ /* Different nodes */
StrAllocCopy (result, after_access);
}
else if (slashes == 3)
{ /* Same node, different path */
StrAllocCopy (result, path);
}
else
{ /* Some path in common */
if (!after_access) { /* Different access */
StrAllocCopy(result, aName);
} else if (slashes < 3) { /* Different nodes */
StrAllocCopy(result, after_access);
} else if (slashes == 3) { /* Same node, different path */
StrAllocCopy(result, path);
} else { /* Some path in common */
int levels = 0;
for (; *q && (*q != '#'); q++)
if (*q == '/')
levels++;
result = (char *) malloc (3 * levels + strlen (last_slash) + 1);
result = (char *) malloc(3 * levels + strlen(last_slash) + 1);
if (result == NULL)
outofmem (__FILE__, "HTRelative");
outofmem(__FILE__, "HTRelative");
result[0] = '\0';
for (; levels; levels--)
strcat (result, "../");
strcat (result, last_slash + 1);
strcat(result, "../");
strcat(result, last_slash + 1);
}
if (TRACE)
fprintf (stderr, "HT: `%s' expressed relative to\n `%s' is\n `%s'.",
fprintf(stderr, "HT: `%s' expressed relative to\n `%s' is\n `%s'.",
aName, relatedName, result);
return result;
}

@ -7,7 +7,6 @@ void
die_if_fault_occurred(xmlrpc_env * env)
{
if (env->fault_occurred) {
err_quit("XML-RPC Fault: %s (%d)\n",
env->fault_string, env->fault_code);
err_quit("XML-RPC Fault: %s (%d)\n", env->fault_string, env->fault_code);
}
}

@ -15,8 +15,7 @@ char *
init(const int argc, const char **argv, echoping_options global_options)
{
if (global_options.udp)
err_quit
("Sorry, UDP is not yet compatible with this daytime plugin");
err_quit("Sorry, UDP is not yet compatible with this daytime plugin");
options = global_options;
return "daytime";
}

@ -36,17 +36,15 @@ execute()
smallservices_server.ai_protocol)) < 0)
err_sys("Can't open socket");
if (connect
(sockfd, smallservices_server.ai_addr,
smallservices_server.ai_addrlen) < 0)
(sockfd, smallservices_server.ai_addr, smallservices_server.ai_addrlen) < 0)
err_sys("Can't connect to server");
if (write(sockfd, TEST_STRING, strlen(TEST_STRING)) != strlen(TEST_STRING))
err_sys("Cannot write");
nr = read(sockfd, result, strlen(TEST_STRING));
if (nr != strlen(TEST_STRING))
err_sys("Cannot read (only %i bytes)", nr); /* TODO: the server
* may send the
* result in chunks,
* we should loop */
err_sys("Cannot read (only %i bytes)", nr); /* TODO: the server may send
* the result in chunks, we
* should loop */
if (strcmp(result, TEST_STRING) != 0)
err_sys("Result \"%s\" is different from test string \"%s\"",
result, TEST_STRING);

@ -226,8 +226,7 @@ main(argc, argv)
}
progname = (char *) argv[0];
poptcon =
poptGetContext(NULL, argc, argv, options, POPT_CONTEXT_POSIXMEHARDER);
poptcon = poptGetContext(NULL, argc, argv, options, POPT_CONTEXT_POSIXMEHARDER);
while ((result = poptGetNextOpt(poptcon)) != -1) {
if (result < -1) {
@ -293,8 +292,7 @@ main(argc, argv)
case 'f':
remaining--;
if (strlen(fill_s) > 1)
err_quit
("Argument --fill should be a one-character string");
err_quit("Argument --fill should be a one-character string");
fill = fill_s[0];
fill_requested = 1;
break;
@ -328,8 +326,7 @@ main(argc, argv)
exit(1);
}
if (size <= 0) {
(void) fprintf(stderr, "%s: illegal packet size.\n",
progname);
(void) fprintf(stderr, "%s: illegal packet size.\n", progname);
exit(1);
}
size_requested = 1;
@ -338,8 +335,7 @@ main(argc, argv)
remaining--;
timeout_requested = 1;
if (size <= 0) {
(void) fprintf(stderr, "%s: illegal timeout.\n",
progname);
(void) fprintf(stderr, "%s: illegal timeout.\n", progname);
exit(1);
}
break;
@ -353,8 +349,7 @@ main(argc, argv)
}
if (number <= 0) {
(void) fprintf(stderr,
"%s: illegal number of iterations.\n",
progname);
"%s: illegal number of iterations.\n", progname);
exit(1);
}
break;
@ -367,9 +362,7 @@ main(argc, argv)
* waiting.
*/
{
(void) fprintf(stderr,
"%s: illegal waiting time.\n",
progname);
(void) fprintf(stderr, "%s: illegal waiting time.\n", progname);
exit(1);
}
break;
@ -384,8 +377,7 @@ main(argc, argv)
module_find = TRUE;
break;
default:
printf("Unknown character option %d (%c)", result,
(char) result);
printf("Unknown character option %d (%c)", result, (char) result);
usage(poptcon);
}
}
@ -410,29 +402,25 @@ main(argc, argv)
}
#if ! (defined(OPENSSL) || defined(GNUTLS))
if (ssl) {
(void) fprintf(stderr,
"%s: not compiled with SSL/TLS support.\n", progname);
(void) fprintf(stderr, "%s: not compiled with SSL/TLS support.\n", progname);
exit(1);
}
#endif
#ifndef HTTP
if (http) {
(void) fprintf(stderr, "%s: Not compiled with HTTP support.\n",
progname);
(void) fprintf(stderr, "%s: Not compiled with HTTP support.\n", progname);
exit(1);
}
#endif
#ifndef SMTP
if (smtp) {
(void) fprintf(stderr, "%s: Not compiled with SMTP support.\n",
progname);
(void) fprintf(stderr, "%s: Not compiled with SMTP support.\n", progname);
exit(1);
}
#endif
#ifndef ICP
if (icp) {
(void) fprintf(stderr, "%s: Not compiled with ICP support.\n",
progname);
(void) fprintf(stderr, "%s: Not compiled with ICP support.\n", progname);
exit(1);
}
#endif
@ -444,8 +432,7 @@ main(argc, argv)
}
if (ssl && !http) {
(void) fprintf(stderr,
"%s: SSL is only supported for HTTP requests.\n",
progname);
"%s: SSL is only supported for HTTP requests.\n", progname);
exit(1);
}
if (!udp && !icp)
@ -462,23 +449,20 @@ main(argc, argv)
#ifndef USE_TOS
if (tos_requested) {
(void) fprintf(stderr,
"%s: Not compiled with Type Of Service support.\n",
progname);
"%s: Not compiled with Type Of Service support.\n", progname);
exit(1);
}
#endif
#ifndef USE_PRIORITY
if (priority_requested) {
(void) fprintf(stderr,
"%s: Not compiled with socket priority support.\n",
progname);
"%s: Not compiled with socket priority support.\n", progname);
exit(1);
}
#endif
#ifndef HAVE_SCTP
if (sctp_requested) {
(void) fprintf(stderr,
"%s: Not compiled with SCTP support.\n", progname);
(void) fprintf(stderr, "%s: Not compiled with SCTP support.\n", progname);
exit(1);
}
#endif
@ -492,8 +476,7 @@ main(argc, argv)
if (!plugin) {
/* Retries with the absolute name */
complete_plugin_name = (char *) malloc(MAX_LINE);
sprintf(complete_plugin_name, "%s/%s", PLUGINS_DIR,
plugin_name);
sprintf(complete_plugin_name, "%s/%s", PLUGINS_DIR, plugin_name);
plugin = dlopen(complete_plugin_name, RTLD_NOW);
}
if (!plugin) {
@ -510,8 +493,7 @@ main(argc, argv)
}
plugin_init = dlsym(plugin, "init");
if (!plugin_init) {
err_sys("Cannot find init in %s: %s", plugin_name,
dlerror());
err_sys("Cannot find init in %s: %s", plugin_name, dlerror());
}
global_options.udp = udp;
global_options.verbose = verbose;
@ -530,27 +512,23 @@ main(argc, argv)
plugin_raw = FALSE;
plugin_start = dlsym(plugin, "start");
if (!plugin_start) {
err_sys("Cannot find start in %s: %s", plugin_name,
dlerror());
err_sys("Cannot find start in %s: %s", plugin_name, dlerror());
}
} else {
port_name = 0;
plugin_raw = TRUE;
plugin_raw_start = dlsym(plugin, "start_raw");
if (!plugin_raw_start) {
err_sys("Cannot find start_raw in %s: %s",
plugin_name, dlerror());
err_sys("Cannot find start_raw in %s: %s", plugin_name, dlerror());
}
}
plugin_execute = dlsym(plugin, "execute");
if (!plugin_execute) {
err_sys("Cannot find execute in %s: %s", plugin_name,
dlerror());
err_sys("Cannot find execute in %s: %s", plugin_name, dlerror());
}
plugin_terminate = dlsym(plugin, "terminate");
if (!plugin_terminate) {
err_sys("Cannot find terminate in %s: %s", plugin_name,
dlerror());
err_sys("Cannot find terminate in %s: %s", plugin_name, dlerror());
}
}
if (remaining == 0) {
@ -620,10 +598,8 @@ main(argc, argv)
if (*p == ':') {
*p = 0;
text_port = p + 1;
if (strcmp(text_port, "")) /* See bug *
* #850672 */
strncpy(port_name, text_port,
NI_MAXSERV);
if (strcmp(text_port, "")) /* See bug * * #850672 */
strncpy(port_name, text_port, NI_MAXSERV);
}
}
}
@ -634,15 +610,9 @@ main(argc, argv)
if (strcmp(port_name, DEFAULT_HTTP_TCP_PORT)
== 0) {
strcpy(port_name, "80");
} else
if (strcmp
(port_name,
DEFAULT_HTTPS_TCP_PORT) == 0) {
} else if (strcmp(port_name, DEFAULT_HTTPS_TCP_PORT) == 0) {
strcpy(port_name, "443");
} else
if (strcmp
(port_name,
DEFAULT_ICP_UDP_PORT) == 0) {
} else if (strcmp(port_name, DEFAULT_ICP_UDP_PORT) == 0) {
strcpy(port_name, "3130");
}
}
@ -665,13 +635,10 @@ main(argc, argv)
idna_to_ascii_8z(utf8_server, &ace_server,
IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS) {
if (result == IDNA_CONTAINS_LDH)
err_quit("Illegal name for host: %s", server); /* foo@bar
* or
* similar
* errors */
err_quit("Illegal name for host: %s", server); /* foo@bar or
* similar errors */
else
err_quit("IDN error for host: %s %d", server,
result);
err_quit("IDN error for host: %s %d", server, result);
}
if (strcmp(utf8_server, ace_server)) {
if (verbose)
@ -694,8 +661,7 @@ main(argc, argv)
}
if (plugin) {
if (verbose) {
printf("Running start() for the plugin %s...\n",
plugin_name);
printf("Running start() for the plugin %s...\n", plugin_name);
}
if (plugin_raw)
plugin_raw_start();
@ -712,15 +678,14 @@ main(argc, argv)
#ifdef SMTP
if (smtp) {
sendline = "QUIT\r\n"; /* Surprises some SMTP servers which log a
* frightening NOQUEUE. Anyone knows better?
* * * * * See bug #1512776 */
* frightening NOQUEUE. Anyone knows better? * * *
* * See bug #1512776 */
} else
#endif
#ifdef ICP
if (icp) {
if (res->ai_family == AF_INET) {
sendline =
make_icp_sendline(url, &(res->ai_addr), opcode, &length);
sendline = make_icp_sendline(url, &(res->ai_addr), opcode, &length);
} else {
/*
@ -729,8 +694,7 @@ main(argc, argv)
* http://devel.squid-cache.org/projects.html#ipv6,
* for instance the following code.
*/
sendline =
make_icp_sendline(url, (void *) NULL, opcode, &length);
sendline = make_icp_sendline(url, (void *) NULL, opcode, &length);
/*
* - headerp->shostid = theOutICPAddr.s_addr; + ** FIXME ** we
* should get more unique data from IPv6 address +xmemcpy
@ -772,8 +736,7 @@ main(argc, argv)
#ifdef USE_SIGACTION
mysigaction.sa_handler = SIG_IGN;
sigemptyset(&mysigaction.sa_mask);
if ((sigaction(SIGPIPE, &mysigaction, NULL)) < 0); /* Ignore it
*/
if ((sigaction(SIGPIPE, &mysigaction, NULL)) < 0); /* Ignore it */
#else
signal(SIGPIPE, SIG_IGN);
#endif
@ -833,8 +796,7 @@ main(argc, argv)
protocol = IPPROTO_SCTP;
#endif
if (!plugin) {
if ((sockfd =
socket(res->ai_family, res->ai_socktype, protocol)) < 0)
if ((sockfd = socket(res->ai_family, res->ai_socktype, protocol)) < 0)
err_sys("Can't open socket");
if (udp) {
struct addrinfo hints2, *res2;
@ -847,8 +809,7 @@ main(argc, argv)
if (error) {
err_sys("getaddrinfo error");
}
if (bind(sockfd, res2->ai_addr, res2->ai_addrlen) <
0) {
if (bind(sockfd, res2->ai_addr, res2->ai_addrlen) < 0) {
err_sys("bind error");
}
}
@ -862,8 +823,7 @@ main(argc, argv)
if (setsockopt(sockfd,
SOL_SOCKET,
SO_PRIORITY,
(void *) &priority,
(socklen_t) sizeof(priority))) {
(void *) &priority, (socklen_t) sizeof(priority))) {
err_sys("Failed setting socket priority");
}
}
@ -877,10 +837,8 @@ main(argc, argv)
}
if (setsockopt(sockfd,
SOL_IP,
IP_TOS, (void *) &tos,
(socklen_t) sizeof(tos))) {
err_sys
("Failed setting IP type of service octet");
IP_TOS, (void *) &tos, (socklen_t) sizeof(tos))) {
err_sys("Failed setting IP type of service octet");
}
}
#endif
@ -906,8 +864,7 @@ main(argc, argv)
}
} else {
if (plugin_raw)
printf("Trying to call plugin %s...\n",
plugin_name);
printf("Trying to call plugin %s...\n", plugin_name);
else
printf
("Trying to call plugin %s for internet address %s %s...\n",
@ -919,10 +876,8 @@ main(argc, argv)
err_sys("I cannot flush");
}
#endif
if ((tcp || plugin) && timeout_requested) { /* echoping's
* timeout has a
* different
* semantic in TCP
if ((tcp || plugin) && timeout_requested) { /* echoping's timeout has a
* different semantic in TCP
* and UDP */
#ifdef USE_SIGACTION
mysigaction.sa_handler = to_alarm;
@ -952,10 +907,9 @@ main(argc, argv)
}
if (plugin) {
plugin_result = plugin_execute();
/* If plugin_result == -1, there is a temporary error and we
* did not get data, we must not use it in the average /
* median calculations. So, successes will not be
* incremented later. */
/* If plugin_result == -1, there is a temporary error and we did not
* get data, we must not use it in the average / median calculations.
* So, successes will not be incremented later. */
if (plugin_result == -2)
err_quit("");
} else {
@ -963,10 +917,8 @@ main(argc, argv)
/*
* Connect to the server.
*/
(void) gettimeofday(&conntv,
(struct timezone *) NULL);
if (connect(sockfd, res->ai_addr, res->ai_addrlen) <
0) {
(void) gettimeofday(&conntv, (struct timezone *) NULL);
if (connect(sockfd, res->ai_addr, res->ai_addrlen) < 0) {
if ((errno == EINTR) && (timeout_flag)) {
printf("Timeout while connecting\n");
close(sockfd);
@ -978,26 +930,20 @@ main(argc, argv)
#endif
} else
err_sys("Can't connect to server");
/* TODO: it would be better to continue: if
* -n was given, other iterations may
* succeed. A flag indicating success or
* error is probably necessary, it would
* replace the mess around 'if
* (!timeout_flag && (!plugin ||
* plugin_result >= 0))' */
/* TODO: it would be better to continue: if -n was given, other
* iterations may succeed. A flag indicating success or error is
* probably necessary, it would replace the mess around 'if
* (!timeout_flag && (!plugin || plugin_result >= 0))' */
} else {
if (tcp) {
(void) gettimeofday(&connectedtv,
(struct timezone
*) NULL);
(void) gettimeofday(&connectedtv, (struct timezone *) NULL);
temp = connectedtv;
tvsub(&temp, &conntv);
if (verbose) {
printf("Connected...\n");
printf
("TCP Latency: %d.%06d seconds\n",
(int) temp.tv_sec,
(int) temp.tv_usec);
(int) temp.tv_sec, (int) temp.tv_usec);
}
}
}
@ -1017,14 +963,12 @@ main(argc, argv)
if (SSL_connect(sslh) == -1)
if ((errno == EINTR)
&& (timeout_flag)) {
printf
("Timeout while starting SSL\n");
printf("Timeout while starting SSL\n");
close(sockfd);
continue;
}
if (verbose)
printf("SSL connection using %s\n",
SSL_get_cipher(sslh));
printf("SSL connection using %s\n", SSL_get_cipher(sslh));
/*
* We could check the server's
* certificate or other funny things
@ -1033,40 +977,32 @@ main(argc, argv)
#endif
#ifdef GNUTLS
if (ssl) {
tls_result =
gnutls_init(&session, GNUTLS_CLIENT);
tls_result = gnutls_init(&session, GNUTLS_CLIENT);
if (tls_result != 0)
err_sys
("Cannot create a new TLS session");
err_sys("Cannot create a new TLS session");
gnutls_set_default_priority(session);
gnutls_certificate_type_set_priority(session,
cert_type_priority);
gnutls_credentials_set(session,
GNUTLS_CRD_CERTIFICATE,
xcred);
gnutls_transport_set_ptr(session,
(gnutls_transport_ptr)
gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, xcred);
gnutls_transport_set_ptr(session, (gnutls_transport_ptr)
(long) sockfd);
tls_result = gnutls_handshake(session);
if (tls_result < 0) {
if ((errno == EINTR)
&& (timeout_flag)) {
printf
("Timeout while starting TLS\n");
printf("Timeout while starting TLS\n");
close(sockfd);
continue;
} else {
err_sys
("Cannot start the TLS session: %s",
gnutls_strerror
(tls_result));
gnutls_strerror(tls_result));
}
}
if (verbose)
printf
("TLS connection using \"%s\"\n",
gnutls_cipher_get_name
(gnutls_cipher_get(session)));
gnutls_cipher_get_name(gnutls_cipher_get(session)));
/*
* We could check the server's
* certificate or other funny things.
@ -1100,37 +1036,28 @@ main(argc, argv)
&& timeout_flag) {
printf
("Timeout while writing (%d byte(s) written so far)\n",
(nr ==
-1) ? 0 : nr);
(nr == -1) ? 0 : nr);
nr = n;
close(sockfd);
continue;
} else
err_sys
("writen error on TCP socket %d",
sockfd);
err_sys("writen error on TCP socket %d", sockfd);
}
}
#ifdef OPENSSL
else {
if ((rc =
SSL_write(sslh, sendline,
n)) != n) {
if ((rc = SSL_write(sslh, sendline, n)) != n) {
if ((nr < 0 || nr != n)
&& timeout_flag) {
nr = n;
printf
("Timeout while writing\n");
printf("Timeout while writing\n");
close(sockfd);
continue;
} else {
sslcode =
ERR_get_error();
sslcode = ERR_get_error();
err_sys
("SSL_write error on socket: %s",
ERR_error_string
(sslcode,
NULL));
ERR_error_string(sslcode, NULL));
}
}
}
@ -1139,24 +1066,18 @@ main(argc, argv)
else
{
if ((rc =
gnutls_record_send(session,
sendline,
strlen
(sendline)))
gnutls_record_send(session, sendline, strlen(sendline)))
!= n) {
if ((nr < 0 || nr != n)
&& timeout_flag) {
nr = n;
printf
("Timeout while writing\n");
printf("Timeout while writing\n");
close(sockfd);
continue;
} else {
err_sys
("gnutls_record_send error %d on socket: %s",
rc,
gnutls_strerror
(rc));
rc, gnutls_strerror(rc));
}
}
}
@ -1166,10 +1087,8 @@ main(argc, argv)
if (icp) {
if (sendto
(sockfd, sendline, length, 0,
res->ai_addr,
res->ai_addrlen) != length)
err_sys
("sendto error on socket");
res->ai_addr, res->ai_addrlen) != length)
err_sys("sendto error on socket");
} else
#endif
/*
@ -1181,13 +1100,11 @@ main(argc, argv)
err_sys("send error on socket");
}
if (verbose) {
(void) gettimeofday(&sendtv,
(struct timezone *)
(void) gettimeofday(&sendtv, (struct timezone *)
NULL);
#ifdef ICP
if (icp)
printf("Sent (%d bytes)...\n",
length);
printf("Sent (%d bytes)...\n", length);
else
#endif
printf("Sent (%d bytes)...\n", n);
@ -1220,16 +1137,14 @@ main(argc, argv)
#endif
FD_SET(n, &mask);
if (select(n + 1, &mask, 0, 0, NULL) > 0) {
(void) gettimeofday(&recvtv,
(struct timezone *)
(void) gettimeofday(&recvtv, (struct timezone *)
NULL);
temp = recvtv;
tvsub(&temp, &sendtv);
if (verbose)
printf
("Application Latency: %d.%06d seconds\n",
(int) temp.tv_sec,
(int) temp.tv_usec);
(int) temp.tv_sec, (int) temp.tv_usec);
}
}
if ((port_to_use == USE_ECHO) || (port_to_use == USE_CHARGEN)
@ -1238,8 +1153,7 @@ main(argc, argv)
if (!udp) {
if (!http && !smtp && !discard) {
/* Read from the server */
nr = readline(files, recvline, n,
stop_at_newlines);
nr = readline(files, recvline, n, stop_at_newlines);
} else if (discard) {
/* No reply, no read */
}
@ -1255,14 +1169,12 @@ main(argc, argv)
else
channel.tls = session;
#endif
nr = read_from_server(channel, ssl,
accept_http_redirects);
nr = read_from_server(channel, ssl, accept_http_redirects);
}
#endif
#ifdef SMTP
else if (smtp) {
nr = smtp_read_response_from_server
(files);
nr = smtp_read_response_from_server(files);
}
#endif
@ -1281,12 +1193,10 @@ main(argc, argv)
#else
signal(SIGALRM, to_alarm);
#endif
timeout_flag = 0; /* for signal
* handler */
timeout_flag = 0; /* for signal handler */
#ifdef ICP
if (icp) {
nr = recv_icp(sockfd, recvline,
retcode);
nr = recv_icp(sockfd, recvline, retcode);
if (verbose) {
printf("%s\n", retcode);
}
@ -1308,10 +1218,8 @@ main(argc, argv)
nr = n;
printf("Timeout\n");
#ifdef FLUSH_OUTPUT
if (fflush((FILE *) NULL) !=
0) {
err_sys
("I cannot flush");
if (fflush((FILE *) NULL) != 0) {
err_sys("I cannot flush");
}
#endif
}
@ -1373,21 +1281,18 @@ main(argc, argv)
} /* That's all, folks */
alarm(0);
#ifdef HAVE_TCP_INFO
/* Thanks to Perry Lorier <perry@coders.net> for the tip. See a
* longer paper in http://linuxgazette.net/136/pfeiffer.html */
/* Thanks to Perry Lorier <perry@coders.net> for the tip. See a longer paper
* in http://linuxgazette.net/136/pfeiffer.html */
if (tcp && verbose) {
if (getsockopt
(sockfd, SOL_TCP, TCP_INFO, &tcpinfo, &socket_length)
if (getsockopt(sockfd, SOL_TCP, TCP_INFO, &tcpinfo, &socket_length)
!= -1) {
/* TODO: find out the meaning of the various fields
* inthe struct tcp_info (it seems documented only
* in the Linux kernel sources) and display stuff
* like reordering (see RFC 4737), window, lost
/* TODO: find out the meaning of the various fields inthe struct
* tcp_info (it seems documented only in the Linux kernel sources)
* and display stuff like reordering (see RFC 4737), window, lost
* packets, etc. */
printf
("Estimated TCP RTT: %.04f seconds (std. deviation %0.03f)\n",
tcpinfo.tcpi_rtt / 1000000.0,
tcpinfo.tcpi_rttvar / 1000000.0);
tcpinfo.tcpi_rtt / 1000000.0, tcpinfo.tcpi_rttvar / 1000000.0);
}
}
#endif
@ -1409,9 +1314,7 @@ main(argc, argv)
(void) gettimeofday(&newtv, (struct timezone *) NULL);
temp = newtv;
tvsub(&temp, &oldtv);
if (!timeout_flag && (!plugin || plugin_result >= 0)) { /* If it
* worked...
*/
if (!timeout_flag && (!plugin || plugin_result >= 0)) { /* If it worked... */
tvadd(&total, &temp);
/* Check */
@ -1419,8 +1322,7 @@ main(argc, argv)
if (port_to_use == USE_ECHO) {
if (strcmp(sendline, recvline) != 0) {
printf(" I wrote:\n%s\n", sendline);
printf(" and I got back:\n%s\n",
recvline);
printf(" and I got back:\n%s\n", recvline);
err_quit("Strange server");
}
if (verbose) {
@ -1441,11 +1343,8 @@ main(argc, argv)
* the size is lower than the
* length of CHARGENERATED
*/
printf(" I got back:\n%s\n",
recvline);
printf
(" instead of the most common:\n%s\n",
sendline);
printf(" I got back:\n%s\n", recvline);
printf(" instead of the most common:\n%s\n", sendline);
err_ret("Strange server");
}
if (verbose) {
@ -1520,14 +1419,11 @@ printstats()
printf("---\n");
if (successes < attempts)
printf("Warning: %d message(s) lost (%d %%)\n",
attempts - successes,
((attempts - successes) * 100) / attempts);
attempts - successes, ((attempts - successes) * 100) / attempts);
printf("Minimum time: %d.%06d seconds (%.0f bytes per sec.)\n",
(int) min.tv_sec, (int) min.tv_usec,
(double) size / tv2double(min));
(int) min.tv_sec, (int) min.tv_usec, (double) size / tv2double(min));
printf("Maximum time: %d.%06d seconds (%.0f bytes per sec.)\n",
(int) max.tv_sec, (int) max.tv_usec,
(double) size / tv2double(max));
(int) max.tv_sec, (int) max.tv_usec, (double) size / tv2double(max));
tvavg(&total, successes);
printf("Average time: %d.%06d seconds (%.0f bytes per sec.)\n",
(int) total.tv_sec, (int) total.tv_usec,
@ -1546,8 +1442,7 @@ printstats()
good_results[j++] = results[i].timevalue;
}
if (successes != j) /* Todo: bug! */
err_quit("successes (%d) is different from j (%d)",
successes, j);
err_quit("successes (%d) is different from j (%d)", successes, j);
qsort(good_results, successes, sizeof(struct timeval), tvcmp);
/*
* for (i = 1; i <= number; i++) { printf("---\nTime %d th:
@ -1573,8 +1468,7 @@ printstats()
(int) median.tv_sec, (int) median.tv_usec,
(double) size / tv2double(median));
if (n_stddev) {
tvstddevavg(&stddev, successes, total, results,
(double) n_stddev);
tvstddevavg(&stddev, successes, total, results, (double) n_stddev);
printf
("Average of values within %d standard deviation%s: %d.%06d\n",
n_stddev, (n_stddev == 1 ? "" : "s"),

@ -12,46 +12,37 @@ char *
make_http_sendline(char *url, char *host, int port, int nocache)
{
short sport = (short) port;
int size = 350; /* Enough? RFC 2616, section 3.2.1 says 255
* should be enough, although there is no
* hard limit. We reserve more because there
* * are the protocol elements, the HTTP
* headers, etc */
int size = 350; /* Enough? RFC 2616, section 3.2.1 says 255 should
* be enough, although there is no hard limit. We
* reserve more because there * are the protocol
* elements, the HTTP headers, etc */
char *sendline = (char *) malloc(size);
char *hostname = (char *) malloc(size);
char *cache_directive = "";
int result;
#ifdef HTTP10
if (nocache)
cache_directive = "Pragma: no-cache\r\n"; /* RFC 1945,
* "Hypertext
* Transfer Protocol
* * -- HTTP/1.0" */
cache_directive = "Pragma: no-cache\r\n"; /* RFC 1945, "Hypertext
* Transfer Protocol * --
* HTTP/1.0" */
result = snprintf(sendline, size,
"GET %s HTTP/1.0\r\nUser-Agent: Echoping/%s\r\n%s\r\n",
url, VERSION, cache_directive);
#else
if (nocache) {
if (nocache == 1)
cache_directive = "Cache-control: max-age=0\r\n"; /* Simply
* force
* a
* recheck
* with
* the
* server
*/
cache_directive = "Cache-control: max-age=0\r\n"; /* Simply force a
* recheck with
* the server */
else
cache_directive = "Cache-control: no-cache\r\n"; /* RFC
* 2616
cache_directive = "Cache-control: no-cache\r\n"; /* RFC 2616
* "Hypertext
* Transfer
* Protocol --
* HTTP/1.1" */
* Transfer Protocol
* -- HTTP/1.1" */
}
strncpy(hostname, HTParse(url, "", PARSE_HOST), size); /* See bug #1688940
* to see why we use
* * strNcpy. */
* * * strNcpy. */
hostname[size] = '\0'; /* Not added automatically */
if (!strcmp(hostname, ""))
snprintf(hostname, size, "%s:%d", host, sport);
@ -84,8 +75,7 @@ read_from_server(CHANNEL fs, short ssl, boolean accept_redirects)
nr = SSL_readline(fs.ssl, big_recvline, MAXTOREAD, TRUE);
if (nr == -1) {
sslcode = ERR_get_error();
err_ret("SSL_readline error: %s",
ERR_error_string(sslcode, NULL));
err_ret("SSL_readline error: %s", ERR_error_string(sslcode, NULL));
}
}
#endif
@ -94,8 +84,7 @@ read_from_server(CHANNEL fs, short ssl, boolean accept_redirects)
{
nr = TLS_readline(fs.tls, big_recvline, MAXTOREAD, TRUE);
if (nr == -1) {
err_ret("TLS_readline error: %s",
gnutls_strerror(nr));
err_ret("TLS_readline error: %s", gnutls_strerror(nr));
}
}
#endif
@ -118,10 +107,8 @@ read_from_server(CHANNEL fs, short ssl, boolean accept_redirects)
* if ((int) big_recvline[nr-1] == 10) nr--;
*/
if (first_line) {
reply_code = big_recvline[9]; /* 9 because "HTTP/1.x
* 200..." */
if (reply_code != '2'
&& !(reply_code == '3' && accept_redirects))
reply_code = big_recvline[9]; /* 9 because "HTTP/1.x 200..." */
if (reply_code != '2' && !(reply_code == '3' && accept_redirects))
/*
* Status codes beginning with 3 are not
* errors See bug #850674 and RFC 2616,
@ -150,7 +137,7 @@ read_from_server(CHANNEL fs, short ssl, boolean accept_redirects)
if ((nr < 2) && (timeout_flag)) /* Probably a timeout */
return -1;
if (nr < 2) /* Hmm, if the body is empty, we'll get a * * * * *
* * meaningless error message */
* * * meaningless error message */
err_sys("Error reading HTTP body");
total = total + nr;
return total; /* How to do if we want only the body's size? */

@ -86,8 +86,7 @@ init(const int argc, const char **argv)
"no-recurse"},
POPT_AUTOHELP POPT_TABLEEND
};
dns_poptcon = poptGetContext(NULL, argc,
argv, options, POPT_CONTEXT_KEEP_FIRST);
dns_poptcon = poptGetContext(NULL, argc, argv, options, POPT_CONTEXT_KEEP_FIRST);
while ((value = poptGetNextOpt(dns_poptcon)) > 0) {
}
if (value < -1) {
@ -149,8 +148,7 @@ start(struct addrinfo *res)
&name_server_sockaddr, sizeof(struct sockaddr));
} else if (name_server_sockaddr.sa_family == AF_INET6) {
#ifdef HAVE_RES_EXT
/* TODO: the code for IPv6 servers is hopelessly broken. Start again
*/
/* TODO: the code for IPv6 servers is hopelessly broken. Start again */
fprintf(stderr,
"WARNING: IPv6 nameservers not really supported yet (experts may apply). Falling back to IPv4 and the default server. You may use -4, too\n");
/* Converts a generic sockaddr to an IPv6 sockaddr_in6 */

@ -75,11 +75,10 @@ init(const int argc, const char **argv,
base = "";
if (request == NULL || !strcmp(request, ""))
request = "(objectclass=*)"; /* Default mentioned in OpenLDAP
* documentation. Joerg Roth fears
* that it may trigger "Size limit
* exceeded" if there are many
* objects at this node. RFC 4515
* seems silent here. */
* documentation. Joerg Roth fears that it
* may trigger "Size limit exceeded" if
* there are many objects at this node. RFC
* 4515 seems silent here. */
if (scope_string != NULL) {
scope_string = (char *) to_upper(scope_string);
if (!strcmp(scope_string, "BASE"))
@ -128,7 +127,7 @@ start()
*/
result = ldap_search_s(session, base, LDAP_SCOPE_ONELEVEL, "(objectClass=dummystuff)", NULL, /* Return
* * all *
* *
* * *
* attributes
*/
1, &response);
@ -144,20 +143,16 @@ execute()
{
int result;
LDAPMessage *response;
result = ldap_search_s(session, base, scope, request, NULL, /* Return
* all
* attributes
*/
result = ldap_search_s(session, base, scope, request, NULL, /* Return all
* attributes */
0, /* Return attribute types *and* values */
&response);
if (result != 0) {
err_ret("Cannot search \"%s\": %s", request,
ldap_err2string(result));
err_ret("Cannot search \"%s\": %s", request, ldap_err2string(result));
return -1;
}
if (global_options.verbose)
printf("Retrieved: %d entries\n",
ldap_count_entries(session, response));
printf("Retrieved: %d entries\n", ldap_count_entries(session, response));
return 0;
}

@ -60,8 +60,7 @@ init(const int argc, const char **argv,
if (global_options.udp)
err_quit("UDP makes no sense for a PostgreSQL connection");
postgresql_poptcon = poptGetContext(NULL, argc,
argv, options,
POPT_CONTEXT_POSIXMEHARDER);
argv, options, POPT_CONTEXT_POSIXMEHARDER);
while ((value = poptGetNextOpt(postgresql_poptcon)) > 0) {
}
if (value < -1) {
@ -114,8 +113,7 @@ execute()
}
res = PQexec(conn, request);
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
err_ret("Cannot run \"%s\": %s\n", request,
PQresultErrorMessage(res));
err_ret("Cannot run \"%s\": %s\n", request, PQresultErrorMessage(res));
return -1;
}
if (global_options.verbose)
@ -125,12 +123,10 @@ execute()
for (column = 0; column < PQnfields(res); column++) {
result = PQgetvalue(res, row, column);
if (result == NULL) {
err_ret("Cannot retrieve value [%d,%d]\n",
row, column);
err_ret("Cannot retrieve value [%d,%d]\n", row, column);
return -1;
}
/* else { printf ("DEBUG: [%d,%d] %s\n", row,
* column, result); } */
/* else { printf ("DEBUG: [%d,%d] %s\n", row, column, result); } */
}
}
}

@ -50,8 +50,8 @@ init(const int argc, const char **argv, echoping_options global_options)
general_options = global_options;
if (global_options.udp)
err_quit("UDP is incompatible with this whois plugin");
/* Will probably be catched before because /etc/services have no entry for
* UDP port 43 */
/* Will probably be catched before because /etc/services have no entry for UDP
* port 43 */
whois_poptcon = poptGetContext(NULL, argc,
argv, options, POPT_CONTEXT_POSIXMEHARDER);
while ((value = poptGetNextOpt(whois_poptcon)) > 0) {
@ -115,8 +115,7 @@ execute()
#ifdef HAVE_TCP_INFO
/* Thanks to Perry Lorier <perry@coders.net> for the tip */
if (general_options.verbose) {
if (getsockopt
(sockfd, SOL_TCP, TCP_INFO, &tcpinfo, &socket_length)
if (getsockopt(sockfd, SOL_TCP, TCP_INFO, &tcpinfo, &socket_length)
!= -1) {
printf("Estimated TCP RTT: %.04f seconds\n",
tcpinfo.tcpi_rtt / 1000000.0);

@ -18,8 +18,8 @@ readline(fs, ptr, maxlen, ln)
char *rc;
int r;
/* Reading with fgets or fread instead of read one-character-at-a-time is
* more than ten times faster, on a local server. */
/* Reading with fgets or fread instead of read one-character-at-a-time is more
* than ten times faster, on a local server. */
if (ln) {
rc = fgets(ptr, maxlen + 1, fs);
if (rc == NULL) {
@ -79,24 +79,22 @@ SSL_readline(sslh, ptr, maxlen, ln)
return rc;
buf_end = rc;
} else if (SSL_buffer[buf_end] != '\n') {
/* We have a probleme here is the first SSL_read sent back a
* text not finished by a \n. See www.SSL.de for an example.
* We get more data. See bug #230384 */
/* We have a probleme here is the first SSL_read sent back a text not
* finished by a \n. See www.SSL.de for an example. We get more data.
* See bug #230384 */
rc = SSL_read(sslh, SSL_buffer + buf_end, maxlen);
if (rc == -1)
return rc;
buf_end = buf_end + rc;
}
for (oi = buf_ptr, i = buf_ptr;
i <= buf_end && SSL_buffer[i] != '\n'; i++) {
for (oi = buf_ptr, i = buf_ptr; i <= buf_end && SSL_buffer[i] != '\n'; i++) {
*ptr++ = SSL_buffer[i];
buf_ptr++;
}
if (SSL_buffer[i] == '\n')
buf_ptr++;
*ptr = '\0';
/* if (ln) printf ("SSL_readline returns %d (%s)\n", i - oi,
* SSL_buffer); */
/* if (ln) printf ("SSL_readline returns %d (%s)\n", i - oi, SSL_buffer); */
return (i - oi);
} else {
/* OpenSSL reads at most 4096 characters */
@ -153,22 +151,19 @@ TLS_readline(session, ptr, maxlen, ln)
return rc;
buf_end = rc;
} else if (TLS_buffer[buf_end] != '\n') {
rc = gnutls_record_recv(session, TLS_buffer + buf_end,
maxlen);
rc = gnutls_record_recv(session, TLS_buffer + buf_end, maxlen);
if (rc == -1)
return rc;
buf_end = buf_end + rc;
}
for (oi = buf_ptr, i = buf_ptr;
i <= buf_end && TLS_buffer[i] != '\n'; i++) {
for (oi = buf_ptr, i = buf_ptr; i <= buf_end && TLS_buffer[i] != '\n'; i++) {
*ptr++ = TLS_buffer[i];
buf_ptr++;
}
if (TLS_buffer[i] == '\n')
buf_ptr++;
*ptr = '\0';
/* printf ("DEBUG: TLS_readline returns %d (%s)\n", i - oi,
* TLS_buffer); */
/* printf ("DEBUG: TLS_readline returns %d (%s)\n", i - oi, TLS_buffer); */
return (i - oi);
} else {
rc = 1; /* Just to avoid exiting too soon */
@ -181,8 +176,7 @@ TLS_readline(session, ptr, maxlen, ln)
for (i = buf_ptr; i < maxlen && i <= buf_end; i++) {
*ptr++ = TLS_buffer[i];
rc++;
/* printf ("DEBUG: Now %d chars read\n",
* rc); */
/* printf ("DEBUG: Now %d chars read\n", rc); */
}
buf_ptr = i;
}

@ -43,7 +43,7 @@ to_upper(char *input)
char *result;
result = (char *) malloc(strlen(input));
for (c = 0; c < strlen(input); c++)
result[c] = toupper((int)input[c]);
result[c] = toupper((int) input[c]);
result[strlen(input)] = '\0';
return result;
}
@ -169,10 +169,9 @@ tvstddevavg(out, number, average, results, n_stddev)
if (results[i].valid == 1) {
result = results[i].timevalue;
tvsub(&result, &average);
/* printf ("value is %f (stddev is %f)\n", tv2double
* (result), tv2double (stddev)); */
/* ensure that result (difference to average) is absolute
* value */
/* printf ("value is %f (stddev is %f)\n", tv2double (result), tv2double
* (stddev)); */
/* ensure that result (difference to average) is absolute value */
if (tvcmp(&result, &null_timeval) == -1) {
result = average;
tvsub(&result, &results[i].timevalue);

@ -20,9 +20,9 @@ writen(fd, ptr, nbytes)
nwritten = write(fd, ptr, nleft);
if (nwritten <= 0)
return (nwritten); /* error */
/* Some systems, such as Digital's OSF1 (Digital Unix) doesn't set
* the returned value to -1, even when interrupted by an alarm,
* whatever says the documentation. errno is not set. */
/* Some systems, such as Digital's OSF1 (Digital Unix) doesn't set the
* returned value to -1, even when interrupted by an alarm, whatever says
* the documentation. errno is not set. */
if ((nwritten < nleft) && timeout_flag)
return nwritten;
nleft -= nwritten;

Loading…
Cancel
Save