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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save