]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Kill rfc1035_errno & error_message globals. We always have the error code available...
authorHenrik Nordstrom <henrik@henriknordstrom.net>
Sun, 9 May 2010 14:21:38 +0000 (16:21 +0200)
committerHenrik Nordstrom <henrik@henriknordstrom.net>
Sun, 9 May 2010 14:21:38 +0000 (16:21 +0200)
include/rfc1035.h
include/rfc3596.h
lib/rfc1035.c
lib/rfc3596.c
lib/tests/testRFC1035.cc
src/dns_internal.cc

index 65cf250c2f628522e76a4bd28bbd5f6846bd3e19..e00f462fc17c9f1ed0aa4e9a1111a36f884cec89 100644 (file)
@@ -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
index 3785ccff703a2b5d9d51d9b5fa8eca53e80e5915..dab50acdf985374f98442d5b4e9aff9986c18326 100644 (file)
@@ -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 */
index e960855070b2e44a7188d42ba35df48aafdad2f8..33832676d28759bcb29a507e599662a8ff2d2285 100644 (file)
@@ -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 {
index f362f11cb5a98460ba1c33c7a916e777acc54ec1..c99b6ec6ac4067fca1539107ab9a6a765bb49847 100644 (file)
@@ -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);
index 986eb01ebabdd056486e8040d1a14b7288fafb7d..d716e9c4d5e89581d64a9de183cd0067b08cab54 100644 (file)
@@ -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);
 }
index 525d59a76b24be3cdf23f6d251e48563aa4a72bf..cf855428897ccbe5b3be0351872c7d329bc033a6 100644 (file)
@@ -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) {
             /*