r16489@catbus: nickm | 2007-11-06 22:51:05 -0500
authorNick Mathewson <nickm@torproject.org>
Wed, 7 Nov 2007 03:52:20 +0000 (03:52 +0000)
committerNick Mathewson <nickm@torproject.org>
Wed, 7 Nov 2007 03:52:20 +0000 (03:52 +0000)
 Do not use "class" as identifier in evdns.h; but use a backward-compatible fix. (Should fix bug 1826515, originally reported by Roger Clark)

svn:r486

ChangeLog
evdns.c
evdns.h
test/regress_dns.c

index 482d36f1f6f21f6493dc549efe0fdcc275e6e123..294319ffdaf17cff82af9702f9e7b0e81876e2ff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -37,4 +37,5 @@ Changes in current version:
  o Fix evhttp.h compilation when TAILQ_ENTRY is not defined.
  o Small code cleanups in epoll_dispatch().
  o Increase the maximum number of addresses read from a packet in evdns to 32.
- o Remove support for the rtsig method: it hasn't compiled for a while, and nobody seems to miss it very much.  Let us know if there's a good reason to put it back in.
\ No newline at end of file
+ o Remove support for the rtsig method: it hasn't compiled for a while, and nobody seems to miss it very much.  Let us know if there's a good reason to put it back in.
+ o Rename the "class" field in evdns_server_request to dns_question_class, so that it won't break compilation under C++.  Use a macro so that old code won't break.  Mark the macro as deprecated.
\ No newline at end of file
diff --git a/evdns.c b/evdns.c
index b324da16d9d6c8600eecfd173381b689bc64acc2..9caf5d540d8b143df62d4928679cd0833b9b0c3a 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -978,7 +978,7 @@ request_parse(u8 *packet, int length, struct evdns_server_port *port, struct soc
                if (!q)
                        goto err;
                q->type = type;
-               q->class = class;
+               q->dns_question_class = class;
                memcpy(q->name, tmp_name, namelen+1);
                server_req->base.questions[server_req->base.nquestions++] = q;
        }
@@ -1492,7 +1492,7 @@ evdns_server_request_add_reply(struct evdns_server_request *_req, int section, c
                return -1;
        }
        item->type = type;
-       item->class = class;
+       item->dns_question_class = class;
        item->ttl = ttl;
        item->is_name = is_name != 0;
        item->datalen = 0;
@@ -1607,7 +1607,7 @@ evdns_server_request_format_response(struct server_request *req, int err)
                        return (int) j;
                }
                APPEND16(req->base.questions[i]->type);
-               APPEND16(req->base.questions[i]->class);
+               APPEND16(req->base.questions[i]->dns_question_class);
        }
 
        /* Add answer, authority, and additional sections. */
@@ -1626,7 +1626,7 @@ evdns_server_request_format_response(struct server_request *req, int err)
                        j = r;
 
                        APPEND16(item->type);
-                       APPEND16(item->class);
+                       APPEND16(item->dns_question_class);
                        APPEND32(item->ttl);
                        if (item->is_name) {
                                off_t len_idx = j, name_start;
@@ -3043,20 +3043,20 @@ evdns_server_callback(struct evdns_server_request *req, void *data)
        for (i = 0; i < req->nquestions; ++i) {
                u32 ans = htonl(0xc0a80b0bUL);
                if (req->questions[i]->type == EVDNS_TYPE_A &&
-                       req->questions[i]->class == EVDNS_CLASS_INET) {
+                       req->questions[i]->dns_question_class == EVDNS_CLASS_INET) {
                        printf(" -- replying for %s (A)\n", req->questions[i]->name);
                        r = evdns_server_request_add_a_reply(req, req->questions[i]->name,
                                                                                  1, &ans, 10);
                        if (r<0)
                                printf("eeep, didn't work.\n");
                } else if (req->questions[i]->type == EVDNS_TYPE_PTR &&
-                                  req->questions[i]->class == EVDNS_CLASS_INET) {
+                                  req->questions[i]->dns_question_class == EVDNS_CLASS_INET) {
                        printf(" -- replying for %s (PTR)\n", req->questions[i]->name);
                        r = evdns_server_request_add_ptr_reply(req, NULL, req->questions[i]->name,
                                                                                        "foo.bar.example.com", 10);
                } else {
                        printf(" -- skipping %s [%d %d]\n", req->questions[i]->name,
-                                  req->questions[i]->type, req->questions[i]->class);
+                                  req->questions[i]->type, req->questions[i]->dns_question_class);
                }
        }
 
diff --git a/evdns.h b/evdns.h
index 6ec1834e381733b23d4be8ad4ae5b7e82f9ca34d..7922c9df52c77aafa6f8cc96a632e35bfcf03715 100644 (file)
--- a/evdns.h
+++ b/evdns.h
@@ -476,7 +476,15 @@ struct evdns_server_request {
 };
 struct evdns_server_question {
        int type;
+#ifdef __cplusplus
+       int dns_question_class;
+#else
+       /* You should refer to this field as "dns_question_class".  The
+        * name "class" works in C for backward compatibility, and will be
+        * removed in a future version. (1.5 or later). */
        int class;
+#define dns_question_class class
+#endif
        char name[1];
 };
 typedef void (*evdns_request_callback_fn_type)(struct evdns_server_request *, void *);
@@ -501,7 +509,7 @@ typedef void (*evdns_request_callback_fn_type)(struct evdns_server_request *, vo
 struct evdns_server_port *evdns_add_server_port(int socket, int is_tcp, evdns_request_callback_fn_type callback, void *user_data);
 void evdns_close_server_port(struct evdns_server_port *port);
 
-int evdns_server_request_add_reply(struct evdns_server_request *req, int section, const char *name, int type, int class, int ttl, int datalen, int is_name, const char *data);
+int evdns_server_request_add_reply(struct evdns_server_request *req, int section, const char *name, int type, int dns_class, int ttl, int datalen, int is_name, const char *data);
 int evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, void *addrs, int ttl);
 int evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, void *addrs, int ttl);
 int evdns_server_request_add_ptr_reply(struct evdns_server_request *req, struct in_addr *in, const char *inaddr_name, const char *hostname, int ttl);
index a674754ad15f04ec744c058192403c72f3d2f444..1b14adc6332fd0d2b492e71e6aa241397ba47829 100644 (file)
@@ -183,14 +183,14 @@ dns_server_request_cb(struct evdns_server_request *req, void *data)
                struct in_addr ans;
                ans.s_addr = htonl(0xc0a80b0bUL); /* 192.168.11.11 */
                if (req->questions[i]->type == EVDNS_TYPE_A &&
-                       req->questions[i]->class == EVDNS_CLASS_INET &&
+                       req->questions[i]->dns_question_class == EVDNS_CLASS_INET &&
                        !strcmp(req->questions[i]->name, "zz.example.com")) {
                        r = evdns_server_request_add_a_reply(req, "zz.example.com",
                                                                                                 1, &ans.s_addr, 12345);
                        if (r<0)
                                dns_ok = 0;
                } else if (req->questions[i]->type == EVDNS_TYPE_AAAA &&
-                                  req->questions[i]->class == EVDNS_CLASS_INET &&
+                                  req->questions[i]->dns_question_class == EVDNS_CLASS_INET &&
                                   !strcmp(req->questions[i]->name, "zz.example.com")) {
                        char addr6[17] = "abcdefghijklmnop";
                        r = evdns_server_request_add_aaaa_reply(req, "zz.example.com",
@@ -198,7 +198,7 @@ dns_server_request_cb(struct evdns_server_request *req, void *data)
                        if (r<0)
                                dns_ok = 0;
                } else if (req->questions[i]->type == EVDNS_TYPE_PTR &&
-                                  req->questions[i]->class == EVDNS_CLASS_INET &&
+                                  req->questions[i]->dns_question_class == EVDNS_CLASS_INET &&
                                   !strcmp(req->questions[i]->name, TEST_ARPA)) {
                        r = evdns_server_request_add_ptr_reply(req, NULL, TEST_ARPA,
                                           "ZZ.EXAMPLE.COM", 54321);
@@ -207,7 +207,7 @@ dns_server_request_cb(struct evdns_server_request *req, void *data)
                } else {
                        fprintf(stdout, "Unexpected question %d %d \"%s\" ",
                                        req->questions[i]->type,
-                                       req->questions[i]->class,
+                                       req->questions[i]->dns_question_class,
                                        req->questions[i]->name);
                        dns_ok = 0;
                }