From: Henrik Nordstrom Date: Sun, 9 May 2010 14:21:38 +0000 (+0200) Subject: Kill rfc1035_errno & error_message globals. We always have the error code available... X-Git-Tag: SQUID_3_2_0_1~228 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=42687bb299c004cd94424c85c9a0fa6bf38344bb;p=thirdparty%2Fsquid.git Kill rfc1035_errno & error_message globals. We always have the error code available anyway --- diff --git a/include/rfc1035.h b/include/rfc1035.h index 65cf250c2f..e00f462fc1 100644 --- a/include/rfc1035.h +++ b/include/rfc1035.h @@ -110,8 +110,7 @@ SQUIDCEXTERN int rfc1035MessageUnpack(const char *buf, SQUIDCEXTERN int rfc1035QueryCompare(const rfc1035_query *, const rfc1035_query *); SQUIDCEXTERN void rfc1035RRDestroy(rfc1035_rr ** rr, int n); SQUIDCEXTERN void rfc1035MessageDestroy(rfc1035_message ** message); -SQUIDCEXTERN int rfc1035_errno; -SQUIDCEXTERN const char *rfc1035_error_message; +SQUIDCEXTERN const char * rfc1035ErrorMessage(int n); #define RFC1035_TYPE_A 1 #define RFC1035_TYPE_CNAME 5 diff --git a/include/rfc3596.h b/include/rfc3596.h index 3785ccff70..dab50acdf9 100644 --- a/include/rfc3596.h +++ b/include/rfc3596.h @@ -78,9 +78,4 @@ SQUIDCEXTERN ssize_t rfc3596BuildHostQuery(const char *hostname, /* RFC3596 section 2.1 defines new RR type AAAA as 28 */ #define RFC1035_TYPE_AAAA 28 -/* rfc3596 library wraps rfc1035 errno and error_message */ -#define rfc3596_errno rfc1035_errno -#define rfc3596_error_message rfc1035_error_message - - #endif /* SQUID_RFC3596_H */ diff --git a/lib/rfc1035.c b/lib/rfc1035.c index e960855070..33832676d2 100644 --- a/lib/rfc1035.c +++ b/lib/rfc1035.c @@ -76,9 +76,6 @@ -int rfc1035_errno; -const char *rfc1035_error_message; - /* * rfc1035HeaderPack() * @@ -432,39 +429,41 @@ rfc1035RRUnpack(const char *buf, size_t sz, unsigned int *off, rfc1035_rr * RR) return 0; } -static void -rfc1035SetErrno(int n) +const char * +rfc1035ErrorMessage(int n) { - switch (rfc1035_errno = n) { + if (n < 0) + n = -n; + switch (n) { case 0: - rfc1035_error_message = "No error condition"; + return "No error condition"; break; case 1: - rfc1035_error_message = "Format Error: The name server was " + return "Format Error: The name server was " "unable to interpret the query."; break; case 2: - rfc1035_error_message = "Server Failure: The name server was " + return "Server Failure: The name server was " "unable to process this query."; break; case 3: - rfc1035_error_message = "Name Error: The domain name does " + return "Name Error: The domain name does " "not exist."; break; case 4: - rfc1035_error_message = "Not Implemented: The name server does " + return "Not Implemented: The name server does " "not support the requested kind of query."; break; case 5: - rfc1035_error_message = "Refused: The name server refuses to " + return "Refused: The name server refuses to " "perform the specified operation."; break; case rfc1035_unpack_error: - rfc1035_error_message = "The DNS reply message is corrupt or could " + return "The DNS reply message is corrupt or could " "not be safely parsed."; break; default: - rfc1035_error_message = "Unknown Error"; + return "Unknown Error"; break; } } @@ -584,17 +583,13 @@ rfc1035MessageUnpack(const char *buf, msg = (rfc1035_message*)xcalloc(1, sizeof(*msg)); if (rfc1035HeaderUnpack(buf + off, sz - off, &off, msg)) { RFC1035_UNPACK_DEBUG; - rfc1035SetErrno(rfc1035_unpack_error); xfree(msg); return -rfc1035_unpack_error; } - rfc1035_errno = 0; - rfc1035_error_message = NULL; i = (unsigned int) msg->qdcount; if (i != 1) { /* This can not be an answer to our queries.. */ RFC1035_UNPACK_DEBUG; - rfc1035SetErrno(rfc1035_unpack_error); xfree(msg); return -rfc1035_unpack_error; } @@ -602,7 +597,6 @@ rfc1035MessageUnpack(const char *buf, for (j = 0; j < i; j++) { if (rfc1035QueryUnpack(buf, sz, &off, &querys[j])) { RFC1035_UNPACK_DEBUG; - rfc1035SetErrno(rfc1035_unpack_error); rfc1035MessageDestroy(&msg); return -rfc1035_unpack_error; } @@ -610,8 +604,7 @@ rfc1035MessageUnpack(const char *buf, *answer = msg; if (msg->rcode) { RFC1035_UNPACK_DEBUG; - rfc1035SetErrno((int) msg->rcode); - return -rfc1035_errno; + return -msg->rcode; } if (msg->ancount == 0) return 0; @@ -635,7 +628,6 @@ rfc1035MessageUnpack(const char *buf, */ rfc1035MessageDestroy(&msg); *answer = NULL; - rfc1035SetErrno(rfc1035_unpack_error); return -rfc1035_unpack_error; } return nr; @@ -797,7 +789,7 @@ main(int argc, char *argv[]) &answers, &rid); if (n < 0) { - printf("ERROR %d\n", rfc1035_errno); + printf("ERROR %d\n", -n); } else if (rid != sid) { printf("ERROR, ID mismatch (%#hx, %#hx)\n", sid, rid); } else { diff --git a/lib/rfc3596.c b/lib/rfc3596.c index f362f11cb5..c99b6ec6ac 100644 --- a/lib/rfc3596.c +++ b/lib/rfc3596.c @@ -327,7 +327,7 @@ while (fgets(input, 512, stdin)) &rid); if (n < 0) { - printf("ERROR %d\n", rfc1035_errno); + printf("ERROR %d\n", -n); } else if (rid != sid && rid != sidb) { printf("ERROR, ID mismatch (%#hx, %#hx)\n", sid, rid); printf("ERROR, ID mismatch (%#hx, %#hx)\n", sidb, rid); diff --git a/lib/tests/testRFC1035.cc b/lib/tests/testRFC1035.cc index 986eb01eba..d716e9c4d5 100644 --- a/lib/tests/testRFC1035.cc +++ b/lib/tests/testRFC1035.cc @@ -106,7 +106,6 @@ void testRFC1035::testBugPacketEndingOnCompressionPtr() /* Test the MessageUnpack function itself */ res = rfc1035MessageUnpack(buf, len, &msg); - CPPUNIT_ASSERT_EQUAL((const char*)NULL, rfc1035_error_message); CPPUNIT_ASSERT_EQUAL(1, res); CPPUNIT_ASSERT(msg != NULL); rfc1035MessageDestroy(&msg); @@ -132,8 +131,7 @@ void testRFC1035::testBugPacketHeadersOnly() /* Test the MessageUnpack function itself */ res = rfc1035MessageUnpack(buf, len, &msg); - CPPUNIT_ASSERT(rfc1035_error_message != NULL); - CPPUNIT_ASSERT(0 == memcmp("The DNS reply message is corrupt or could not be safely parsed.", rfc1035_error_message, 63)); - CPPUNIT_ASSERT(res < 0); + CPPUNIT_ASSERT(0 == memcmp("The DNS reply message is corrupt or could not be safely parsed.", rfc1035ErrorMessage(res), 63)); + CPPUNIT_ASSERT(res == 0); CPPUNIT_ASSERT(msg == NULL); } diff --git a/src/dns_internal.cc b/src/dns_internal.cc index 525d59a76b..cf85542889 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -996,10 +996,8 @@ idnsGrokReply(const char *buf, size_t sz) q->error = NULL; if (n < 0) { - debugs(78, 3, "idnsGrokReply: error " << rfc1035_error_message << " (" << rfc1035_errno << ")"); - - q->error = rfc1035_error_message; q->rcode = -n; + debugs(78, 3, "idnsGrokReply: error " << rfc1035ErrorMessage(n) << " (" << q->rcode << ")"); if (q->rcode == 2 && ++q->attempt < MAX_ATTEMPT) { /*