]> granicus.if.org Git - libevent/commitdiff
Remove the stupid brokenness where DNS option names needed to end with a
authorNick Mathewson <nickm@torproject.org>
Mon, 16 Nov 2009 22:23:55 +0000 (22:23 +0000)
committerNick Mathewson <nickm@torproject.org>
Mon, 16 Nov 2009 22:23:55 +0000 (22:23 +0000)
colon.

svn:r1536

ChangeLog
evdns.c
include/event2/dns.h
test/regress_dns.c

index 4798c6089c96209910291259cbb23d1e44297900..41cc49353853a605faa3b3df27befe2f2efb7e1a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -46,6 +46,7 @@ Changes in 2.0.3-alpha:
  o Fix a problem with excessive memory allocation when using multiple event priorities.
  o Default to using arc4random for DNS transaction IDs on systems that have it; from OpenBSD.
  o Never check the environment when we're running setuid or setgid; from OpenBSD.
+ o Options passed to evdns_set_option() no longer need to end with a colon.
 
 
 Changes in 2.0.2-alpha:
diff --git a/evdns.c b/evdns.c
index 7645ada18458ba2cb722cf31c0948e7521961b22..e6d6888a0daa13e60bdcdc3c0bdf7c66f2515370 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -3174,12 +3174,25 @@ evdns_base_set_option(struct evdns_base *base,
        return res;
 }
 
+static inline int
+str_matches_option(const char *s1, const char *optionname)
+{
+        /* Option names are given as "option:" We accept either 'option' in
+        * s1, or 'option:randomjunk'.  The latter form is to implement the
+        * resolv.conf parser. */
+       size_t optlen = strlen(optionname);
+       if (strlen(s1) == optlen)
+               return !strncmp(s1, optionname, optlen-1);
+       else
+               return !strncmp(s1, optionname, optlen);
+}
+
 static int
 evdns_base_set_option_impl(struct evdns_base *base,
     const char *option, const char *val, int flags)
 {
        ASSERT_LOCKED(base);
-       if (!strncmp(option, "ndots:", 6)) {
+       if (str_matches_option(option, "ndots:")) {
                const int ndots = strtoint(val);
                if (ndots == -1) return -1;
                if (!(flags & DNS_OPTION_SEARCH)) return 0;
@@ -3187,38 +3200,38 @@ evdns_base_set_option_impl(struct evdns_base *base,
                if (!base->global_search_state) base->global_search_state = search_state_new();
                if (!base->global_search_state) return -1;
                base->global_search_state->ndots = ndots;
-       } else if (!strncmp(option, "timeout:", 8)) {
+       } else if (str_matches_option(option, "timeout:")) {
                struct timeval tv;
                if (strtotimeval(val, &tv) == -1) return -1;
                if (!(flags & DNS_OPTION_MISC)) return 0;
                log(EVDNS_LOG_DEBUG, "Setting timeout to %s", val);
                memcpy(&base->global_timeout, &tv, sizeof(struct timeval));
-       } else if (!strncmp(option, "max-timeouts:", 12)) {
+       } else if (str_matches_option(option, "max-timeouts:")) {
                const int maxtimeout = strtoint_clipped(val, 1, 255);
                if (maxtimeout == -1) return -1;
                if (!(flags & DNS_OPTION_MISC)) return 0;
                log(EVDNS_LOG_DEBUG, "Setting maximum allowed timeouts to %d",
                        maxtimeout);
                base->global_max_nameserver_timeout = maxtimeout;
-       } else if (!strncmp(option, "max-inflight:", 13)) {
+       } else if (str_matches_option(option, "max-inflight:")) {
                const int maxinflight = strtoint_clipped(val, 1, 65000);
                if (maxinflight == -1) return -1;
                if (!(flags & DNS_OPTION_MISC)) return 0;
                log(EVDNS_LOG_DEBUG, "Setting maximum inflight requests to %d",
                        maxinflight);
                evdns_base_set_max_requests_inflight(base, maxinflight);
-       } else if (!strncmp(option, "attempts:", 9)) {
+       } else if (str_matches_option(option, "attempts:")) {
                int retries = strtoint(val);
                if (retries == -1) return -1;
                if (retries > 255) retries = 255;
                if (!(flags & DNS_OPTION_MISC)) return 0;
                log(EVDNS_LOG_DEBUG, "Setting retries to %d", retries);
                base->global_max_retransmits = retries;
-       } else if (!strncmp(option, "randomize-case:", 15)) {
+       } else if (str_matches_option(option, "randomize-case:")) {
                int randcase = strtoint(val);
                if (!(flags & DNS_OPTION_MISC)) return 0;
                base->global_randomize_case = randcase;
-       } else if (!strncmp(option, "bind-to:", 8)) {
+       } else if (str_matches_option(option, "bind-to:")) {
                /* XXX This only applies to successive nameservers, not
                 * to already-configured ones.  We might want to fix that. */
                int len = sizeof(base->global_outgoing_address);
index 5abcc2cf9cb1c0b0e083de9e9913ed363394077c..f05f71d143aea98f007f6b8d3c32d0161801a885 100644 (file)
@@ -403,7 +403,8 @@ void evdns_cancel_request(struct evdns_base *base, struct evdns_request *req);
     ndots, timeout, max-timeouts, max-inflight, attempts, randomize-case,
     bind-to.
 
-  The option name needs to end with a colon.
+  In versions before Libevent 2.0.3-alpha, the option name needed to end with
+  a colon.
 
   @param base the evdns_base to which to apply this operation
   @param option the name of the configuration option to be modified
index 7bd33866214ef5b3a786f8001cb6a9bcbbf093c3..d6f6783b575454cbe488d36a4db55d89b16aa55e 100644 (file)
@@ -664,7 +664,7 @@ dns_retry_test(void *arg)
 
        dns = evdns_base_new(base, 0);
        tt_assert(!evdns_base_nameserver_ip_add(dns, "127.0.0.1:53900"));
-       tt_assert(! evdns_base_set_option(dns, "timeout:", "0.3", DNS_OPTIONS_ALL));
+       tt_assert(! evdns_base_set_option(dns, "timeout", "0.3", DNS_OPTIONS_ALL));
        tt_assert(! evdns_base_set_option(dns, "max-timeouts:", "10", DNS_OPTIONS_ALL));
 
        evdns_base_resolve_ipv4(dns, "host.example.com", 0,