svn commit: r334317 - head/lib/libfetch
Dag-Erling Smørgrav
des at FreeBSD.org
Tue May 29 10:28:22 UTC 2018
Author: des
Date: Tue May 29 10:28:20 2018
New Revision: 334317
URL: https://svnweb.freebsd.org/changeset/base/334317
Log:
Use __VA_ARGS__ to simplify the DEBUG macro.
MFC after: 3 weeks
Modified:
head/lib/libfetch/common.c
head/lib/libfetch/common.h
head/lib/libfetch/fetch.c
head/lib/libfetch/ftp.c
head/lib/libfetch/http.c
Modified: head/lib/libfetch/common.c
==============================================================================
--- head/lib/libfetch/common.c Tue May 29 08:41:44 2018 (r334316)
+++ head/lib/libfetch/common.c Tue May 29 10:28:20 2018 (r334317)
@@ -347,7 +347,7 @@ fetch_connect(const char *host, int port, int af, int
conn_t *conn = NULL;
int err = 0, sd = -1;
- DEBUG(fprintf(stderr, "---> %s:%d\n", host, port));
+ DEBUGF("---> %s:%d\n", host, port);
/* resolve server address */
if (verbose)
@@ -1158,7 +1158,7 @@ fetch_getln(conn_t *conn)
} while (c != '\n');
conn->buf[conn->buflen] = '\0';
- DEBUG(fprintf(stderr, "<<< %s", conn->buf));
+ DEBUGF("<<< %s", conn->buf);
return (0);
}
@@ -1263,7 +1263,7 @@ fetch_putln(conn_t *conn, const char *str, size_t len)
struct iovec iov[2];
int ret;
- DEBUG(fprintf(stderr, ">>> %s\n", str));
+ DEBUGF(">>> %s\n", str);
iov[0].iov_base = __DECONST(char *, str);
iov[0].iov_len = len;
iov[1].iov_base = __DECONST(char *, ENDL);
@@ -1403,13 +1403,13 @@ fetch_netrc_auth(struct url *url)
rewind(f);
while ((word = fetch_read_word(f)) != NULL) {
if (strcmp(word, "default") == 0) {
- DEBUG(fetch_info("Using default .netrc settings"));
+ DEBUGF("Using default .netrc settings");
break;
}
if (strcmp(word, "machine") == 0 &&
(word = fetch_read_word(f)) != NULL &&
strcasecmp(word, url->host) == 0) {
- DEBUG(fetch_info("Using .netrc settings for %s", word));
+ DEBUGF("Using .netrc settings for %s", word);
break;
}
}
Modified: head/lib/libfetch/common.h
==============================================================================
--- head/lib/libfetch/common.h Tue May 29 08:41:44 2018 (r334316)
+++ head/lib/libfetch/common.h Tue May 29 10:28:20 2018 (r334317)
@@ -104,9 +104,16 @@ int fetch_no_proxy_match(const char *);
#define url_seterr(n) fetch_seterr(url_errlist, n)
#ifndef NDEBUG
-#define DEBUG(x) do { if (fetchDebug) { x; } } while (0)
+#define DEBUGF(...) \
+ do { \
+ if (fetchDebug) \
+ fprintf(stderr, __VA_ARGS__); \
+ } while (0)
#else
-#define DEBUG(x) do { } while (0)
+#define DEBUGF(...) \
+ do { \
+ /* nothing */ \
+ } while (0)
#endif
/*
Modified: head/lib/libfetch/fetch.c
==============================================================================
--- head/lib/libfetch/fetch.c Tue May 29 08:41:44 2018 (r334316)
+++ head/lib/libfetch/fetch.c Tue May 29 10:28:20 2018 (r334317)
@@ -444,15 +444,14 @@ nohost:
goto ouch;
}
- DEBUG(fprintf(stderr,
- "scheme: \"%s\"\n"
- "user: \"%s\"\n"
- "password: \"%s\"\n"
- "host: \"%s\"\n"
- "port: \"%d\"\n"
- "document: \"%s\"\n",
- u->scheme, u->user, u->pwd,
- u->host, u->port, u->doc));
+ DEBUGF("scheme: \"%s\"\n"
+ "user: \"%s\"\n"
+ "password: \"%s\"\n"
+ "host: \"%s\"\n"
+ "port: \"%d\"\n"
+ "document: \"%s\"\n",
+ u->scheme, u->user, u->pwd,
+ u->host, u->port, u->doc);
return (u);
Modified: head/lib/libfetch/ftp.c
==============================================================================
--- head/lib/libfetch/ftp.c Tue May 29 08:41:44 2018 (r334316)
+++ head/lib/libfetch/ftp.c Tue May 29 10:28:20 2018 (r334317)
@@ -259,7 +259,7 @@ ftp_pwd(conn_t *conn, char *pwd, size_t pwdlen)
return (FTP_PROTOCOL_ERROR);
*dst = '\0';
#if 0
- DEBUG(fprintf(stderr, "pwd: [%s]\n", pwd));
+ DEBUGF("pwd: [%s]\n", pwd);
#endif
return (FTP_OK);
}
@@ -291,8 +291,8 @@ ftp_cwd(conn_t *conn, const char *file)
if (pwd[i] != file[i])
break;
#if 0
- DEBUG(fprintf(stderr, "have: [%.*s|%s]\n", i, pwd, pwd + i));
- DEBUG(fprintf(stderr, "want: [%.*s|%s]\n", i, file, file + i));
+ DEBUGF("have: [%.*s|%s]\n", i, pwd, pwd + i);
+ DEBUGF("want: [%.*s|%s]\n", i, file, file + i);
#endif
/* Keep going up a dir until we have a matching prefix. */
if (pwd[i] == '\0' && (file[i - 1] == '/' || file[i] == '/'))
@@ -433,7 +433,7 @@ ftp_stat(conn_t *conn, const char *file, struct url_st
}
if (us->size == 0)
us->size = -1;
- DEBUG(fprintf(stderr, "size: [%lld]\n", (long long)us->size));
+ DEBUGF("size: [%lld]\n", (long long)us->size);
e = ftp_cmd(conn, "MDTM %.*s", filenamelen, filename);
if (e != FTP_FILE_STATUS) {
@@ -468,10 +468,9 @@ ftp_stat(conn_t *conn, const char *file, struct url_st
t = time(NULL);
us->mtime = t;
us->atime = t;
- DEBUG(fprintf(stderr,
- "last modified: [%04d-%02d-%02d %02d:%02d:%02d]\n",
+ DEBUGF("last modified: [%04d-%02d-%02d %02d:%02d:%02d]\n",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec));
+ tm.tm_hour, tm.tm_min, tm.tm_sec);
return (0);
}
@@ -585,7 +584,7 @@ ftp_closefn(void *v)
fetch_close(io->dconn);
io->dir = -1;
io->dconn = NULL;
- DEBUG(fprintf(stderr, "Waiting for final status\n"));
+ DEBUGF("Waiting for final status\n");
r = ftp_chkerr(io->cconn);
if (io->cconn == cached_connection && io->cconn->ref == 1)
cached_connection = NULL;
Modified: head/lib/libfetch/http.c
==============================================================================
--- head/lib/libfetch/http.c Tue May 29 08:41:44 2018 (r334316)
+++ head/lib/libfetch/http.c Tue May 29 10:28:20 2018 (r334317)
@@ -891,10 +891,9 @@ http_parse_mtime(const char *p, time_t *mtime)
setlocale(LC_TIME, locale);
if (r == NULL)
return (-1);
- DEBUG(fprintf(stderr, "last modified: [%04d-%02d-%02d "
- "%02d:%02d:%02d]\n",
- tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec));
+ DEBUGF("last modified: [%04d-%02d-%02d %02d:%02d:%02d]\n",
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+ tm.tm_hour, tm.tm_min, tm.tm_sec);
*mtime = timegm(&tm);
return (0);
}
@@ -911,8 +910,7 @@ http_parse_length(const char *p, off_t *length)
len = len * 10 + (*p - '0');
if (*p)
return (-1);
- DEBUG(fprintf(stderr, "content length: [%lld]\n",
- (long long)len));
+ DEBUGF("content length: [%lld]\n", (long long)len);
*length = len;
return (0);
}
@@ -946,12 +944,11 @@ http_parse_range(const char *p, off_t *offset, off_t *
if (*p || len < last - first + 1)
return (-1);
if (first == -1) {
- DEBUG(fprintf(stderr, "content range: [*/%lld]\n",
- (long long)len));
+ DEBUGF("content range: [*/%lld]\n", (long long)len);
*length = 0;
} else {
- DEBUG(fprintf(stderr, "content range: [%lld-%lld/%lld]\n",
- (long long)first, (long long)last, (long long)len));
+ DEBUGF("content range: [%lld-%lld/%lld]\n",
+ (long long)first, (long long)last, (long long)len);
*length = last - first + 1;
}
*offset = first;
@@ -1187,9 +1184,10 @@ DigestCalcResponse(
OUT HASHHEX Response /* request-digest or response-digest */
)
{
-/* DEBUG(fprintf(stderr,
- "Calc: HA1[%s] Nonce[%s] qop[%s] method[%s] URI[%s]\n",
- HA1, pszNonce, pszQop, pszMethod, pszDigestUri));*/
+#if 0
+ DEBUGF("Calc: HA1[%s] Nonce[%s] qop[%s] method[%s] URI[%s]\n",
+ HA1, pszNonce, pszQop, pszMethod, pszDigestUri);
+#endif
MD5_CTX Md5Ctx;
HASH HA2;
HASH RespHash;
@@ -1257,7 +1255,7 @@ http_digest_auth(conn_t *conn, const char *hdr, http_a
char *options = NULL;
if (!c->realm || !c->nonce) {
- DEBUG(fprintf(stderr, "realm/nonce not set in challenge\n"));
+ DEBUGF("realm/nonce not set in challenge\n");
return(-1);
}
if (!c->algo)
@@ -1282,7 +1280,7 @@ http_digest_auth(conn_t *conn, const char *hdr, http_a
HASHHEX HA1;
DigestCalcHA1(c->algo, parms->user, c->realm,
parms->password, c->nonce, cnonce, HA1);
- DEBUG(fprintf(stderr, "HA1: [%s]\n", HA1));
+ DEBUGF("HA1: [%s]\n", HA1);
HASHHEX digest;
DigestCalcResponse(HA1, c->nonce, noncecount, cnonce, c->qop,
"GET", url->doc, "", digest);
@@ -1314,8 +1312,8 @@ http_basic_auth(conn_t *conn, const char *hdr, const c
char *upw, *auth;
int r;
- DEBUG(fprintf(stderr, "basic: usr: [%s]\n", usr));
- DEBUG(fprintf(stderr, "basic: pwd: [%s]\n", pwd));
+ DEBUGF("basic: usr: [%s]\n", usr);
+ DEBUGF("basic: pwd: [%s]\n", pwd);
if (asprintf(&upw, "%s:%s", usr, pwd) == -1)
return (-1);
auth = http_base64(upw);
@@ -1340,7 +1338,7 @@ http_authorize(conn_t *conn, const char *hdr, http_aut
/* If user or pass are null we're not happy */
if (!parms->user || !parms->password) {
- DEBUG(fprintf(stderr, "NULL usr or pass\n"));
+ DEBUGF("NULL usr or pass\n");
return (-1);
}
@@ -1353,8 +1351,7 @@ http_authorize(conn_t *conn, const char *hdr, http_aut
/* Error if "Digest" was specified and there is no Digest challenge */
if (!digest && (parms->scheme &&
!strcasecmp(parms->scheme, "digest"))) {
- DEBUG(fprintf(stderr,
- "Digest auth in env, not supported by peer\n"));
+ DEBUGF("Digest auth in env, not supported by peer\n");
return (-1);
}
/*
@@ -1863,7 +1860,7 @@ http_request_body(struct url *URL, const char *op, str
new = fetchParseURL(p);
if (new == NULL) {
/* XXX should set an error code */
- DEBUG(fprintf(stderr, "failed to parse new URL\n"));
+ DEBUGF("failed to parse new URL\n");
goto ouch;
}
@@ -1909,7 +1906,7 @@ http_request_body(struct url *URL, const char *op, str
(conn->err == HTTP_NEED_PROXY_AUTH &&
!proxy_challenges.valid)) {
/* 401/7 but no www/proxy-authenticate ?? */
- DEBUG(fprintf(stderr, "401/7 and no auth header\n"));
+ DEBUGF("%03d without auth header\n", conn->err);
goto ouch;
}
fetch_close(conn);
@@ -1944,7 +1941,7 @@ http_request_body(struct url *URL, const char *op, str
fetch_close(conn);
conn = NULL;
if (!new) {
- DEBUG(fprintf(stderr, "redirect with no new location\n"));
+ DEBUGF("redirect with no new location\n");
break;
}
if (url != URL)
@@ -1958,10 +1955,9 @@ http_request_body(struct url *URL, const char *op, str
goto ouch;
}
- DEBUG(fprintf(stderr, "offset %lld, length %lld,"
- " size %lld, clength %lld\n",
- (long long)offset, (long long)length,
- (long long)size, (long long)clength));
+ DEBUGF("offset %lld, length %lld, size %lld, clength %lld\n",
+ (long long)offset, (long long)length,
+ (long long)size, (long long)clength);
if (conn->err == HTTP_NOT_MODIFIED) {
http_seterr(HTTP_NOT_MODIFIED);
More information about the svn-src-head
mailing list