]> granicus.if.org Git - libevent/commitdiff
Export evutil_str[n]casecmp as evutil_ascii_str[n]casecmp.
authorNick Mathewson <nickm@torproject.org>
Tue, 28 Jul 2009 19:41:57 +0000 (19:41 +0000)
committerNick Mathewson <nickm@torproject.org>
Tue, 28 Jul 2009 19:41:57 +0000 (19:41 +0000)
svn:r1387

ChangeLog
evdns.c
evutil.c
http.c
include/event2/util.h
test/regress_dns.c
test/regress_util.c
util-internal.h

index 0a1a9df93375078cc11b5bab93d6c5a13613f4db..c46171cea9f8c4b63577a3fa3a0b51691039c554 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@ Changes in 2.0.3-alpha:
  o Add a new code to support SSL/TLS on bufferevents, using the OpenSSL library (where available).
  o Fix a bug where we didn't allocate enough memory in event_get_supported_methods().
  o Avoid segfault during failed allocation of locked evdns_base. (Found by Rocco Carbone.)
+ o Export new evutil_ascii_* functions to perform locale-independent character type operations.
 
 Changes in 2.0.2-alpha:
  o Add a new flag to bufferevents to make all callbacks automatically deferred.
diff --git a/evdns.c b/evdns.c
index 9b255002f94264241989bd348a292e2b6ff3cf42..98d51424c65e80e0c397fc117a78e68f49b51c84 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -1005,7 +1005,7 @@ reply_parse(struct evdns_base *base, u8 *packet, int length) {
                        if (strcmp(tmp_name, cmp_name) == 0)            \
                                name_matches = 1;                       \
                } else {                                                \
-                       if (evutil_strcasecmp(tmp_name, cmp_name) == 0) \
+                       if (evutil_ascii_strcasecmp(tmp_name, cmp_name) == 0) \
                                name_matches = 1;                       \
                }                                                       \
        } while(0)
index 3b6d3ca6fc36f3eca2588d9c9f73d1d406253f46..5477047e954010a3dec38fb620f45c8a77d0e626 100644 (file)
--- a/evutil.c
+++ b/evutil.c
@@ -773,7 +773,7 @@ const char EVUTIL_TOLOWER_TABLE[256] = {
 };
 
 int
-evutil_strcasecmp(const char *s1, const char *s2)
+evutil_ascii_strcasecmp(const char *s1, const char *s2)
 {
        char c1, c2;
        while (1) {
@@ -787,7 +787,7 @@ evutil_strcasecmp(const char *s1, const char *s2)
                        return 0;
        }
 }
-int evutil_strncasecmp(const char *s1, const char *s2, size_t n)
+int evutil_ascii_strncasecmp(const char *s1, const char *s2, size_t n)
 {
        char c1, c2;
        while (n--) {
diff --git a/http.c b/http.c
index 75a0f6885bde57077b82a64f9dfd319832fd2e47..7828966bdb043f3394b14b54dec4fbb20cea29cb 100644 (file)
--- a/http.c
+++ b/http.c
@@ -418,10 +418,10 @@ evhttp_is_connection_close(int flags, struct evkeyvalq* headers)
        if (flags & EVHTTP_PROXY_REQUEST) {
                /* proxy connection */
                const char *connection = evhttp_find_header(headers, "Proxy-Connection");
-               return (connection == NULL || evutil_strcasecmp(connection, "keep-alive") != 0);
+               return (connection == NULL || evutil_ascii_strcasecmp(connection, "keep-alive") != 0);
        } else {
                const char *connection = evhttp_find_header(headers, "Connection");
-               return (connection != NULL && evutil_strcasecmp(connection, "close") == 0);
+               return (connection != NULL && evutil_ascii_strcasecmp(connection, "close") == 0);
        }
 }
 
@@ -430,7 +430,7 @@ evhttp_is_connection_keepalive(struct evkeyvalq* headers)
 {
        const char *connection = evhttp_find_header(headers, "Connection");
        return (connection != NULL
-           && evutil_strncasecmp(connection, "keep-alive", 10) == 0);
+           && evutil_ascii_strncasecmp(connection, "keep-alive", 10) == 0);
 }
 
 static void
@@ -1325,7 +1325,7 @@ evhttp_find_header(const struct evkeyvalq *headers, const char *key)
        struct evkeyval *header;
 
        TAILQ_FOREACH(header, headers, next) {
-               if (evutil_strcasecmp(header->key, key) == 0)
+               if (evutil_ascii_strcasecmp(header->key, key) == 0)
                        return (header->value);
        }
 
@@ -1358,7 +1358,7 @@ evhttp_remove_header(struct evkeyvalq *headers, const char *key)
        struct evkeyval *header;
 
        TAILQ_FOREACH(header, headers, next) {
-               if (evutil_strcasecmp(header->key, key) == 0)
+               if (evutil_ascii_strcasecmp(header->key, key) == 0)
                        break;
        }
 
@@ -1554,7 +1554,7 @@ evhttp_get_body_length(struct evhttp_request *req)
        if (content_length == NULL && connection == NULL)
                req->ntoread = -1;
        else if (content_length == NULL &&
-           evutil_strcasecmp(connection, "Close") != 0) {
+           evutil_ascii_strcasecmp(connection, "Close") != 0) {
                /* Bad combination, we don't know when it will end */
                event_warnx("%s: we got no content length, but the "
                    "server wants to keep the connection open: %s.",
@@ -1593,7 +1593,7 @@ evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req)
        }
        evcon->state = EVCON_READING_BODY;
        xfer_enc = evhttp_find_header(req->input_headers, "Transfer-Encoding");
-       if (xfer_enc != NULL && evutil_strcasecmp(xfer_enc, "chunked") == 0) {
+       if (xfer_enc != NULL && evutil_ascii_strcasecmp(xfer_enc, "chunked") == 0) {
                req->chunked = 1;
                req->ntoread = -1;
        } else {
index 9a9dade6df2893cc775272f78d122a4dd7a03126..0b9865ec8b4e4c8b8c484d9c5a9fa0652a9f8cec 100644 (file)
@@ -295,6 +295,14 @@ struct sockaddr;
 */
 int evutil_parse_sockaddr_port(const char *str, struct sockaddr *out, int *outlen);
 
+/** As strcasecmp, but always compares the characters in locale-independent
+    ASCII.  That's useful if you're handling data in ASCII-based protocols.
+ */
+int evutil_ascii_strcasecmp(const char *str1, const char *str2);
+/** As strncasecmp, but always compares the characters in locale-independent
+    ASCII.  That's useful if you're handling data in ASCII-based protocols.
+ */
+int evutil_ascii_strncasecmp(const char *str1, const char *str2, size_t n);
 
 #ifdef __cplusplus
 }
index c535006e2dc2b54c364c363d2593fd0740a22dd2..21214c1bfd5ee8888ed556a9487760fe8643dfcf 100644 (file)
@@ -70,9 +70,6 @@ static int dns_ok = 0;
 static int dns_got_cancel = 0;
 static int dns_err = 0;
 
-/* XXXXX have evutil export this. */
-int evutil_strcasecmp(const char *, const char *);
-
 static void
 dns_gethostbyname_cb(int result, char type, int count, int ttl,
     void *addresses, void *arg)
@@ -226,7 +223,7 @@ dns_server_request_cb(struct evdns_server_request *req, void *data)
                ans.s_addr = htonl(0xc0a80b0bUL); /* 192.168.11.11 */
                if (req->questions[i]->type == EVDNS_TYPE_A &&
                        req->questions[i]->dns_question_class == EVDNS_CLASS_INET &&
-                       !evutil_strcasecmp(req->questions[i]->name, "zz.example.com")) {
+                       !evutil_ascii_strcasecmp(req->questions[i]->name, "zz.example.com")) {
                        r = evdns_server_request_add_a_reply(req,
                                                                                                 req->questions[i]->name,
                                                                                                 1, &ans.s_addr, 12345);
@@ -234,7 +231,7 @@ dns_server_request_cb(struct evdns_server_request *req, void *data)
                                dns_ok = 0;
                } else if (req->questions[i]->type == EVDNS_TYPE_AAAA &&
                                   req->questions[i]->dns_question_class == EVDNS_CLASS_INET &&
-                                  !evutil_strcasecmp(req->questions[i]->name, "zz.example.com")) {
+                                  !evutil_ascii_strcasecmp(req->questions[i]->name, "zz.example.com")) {
                        char addr6[17] = "abcdefghijklmnop";
                        r = evdns_server_request_add_aaaa_reply(req,
                                                                                                        req->questions[i]->name,
@@ -243,7 +240,7 @@ dns_server_request_cb(struct evdns_server_request *req, void *data)
                                dns_ok = 0;
                } else if (req->questions[i]->type == EVDNS_TYPE_PTR &&
                                   req->questions[i]->dns_question_class == EVDNS_CLASS_INET &&
-                                  !evutil_strcasecmp(req->questions[i]->name, TEST_ARPA)) {
+                                  !evutil_ascii_strcasecmp(req->questions[i]->name, TEST_ARPA)) {
                        r = evdns_server_request_add_ptr_reply(req, NULL,
                                                                                                   req->questions[i]->name,
                                                                                                   "ZZ.EXAMPLE.COM", 54321);
@@ -251,7 +248,7 @@ dns_server_request_cb(struct evdns_server_request *req, void *data)
                                dns_ok = 0;
                 } else if (req->questions[i]->type == EVDNS_TYPE_A &&
                    req->questions[i]->dns_question_class == EVDNS_CLASS_INET &&
-                   !evutil_strcasecmp(req->questions[i]->name, "drop.example.com")) {
+                   !evutil_ascii_strcasecmp(req->questions[i]->name, "drop.example.com")) {
                        if (evdns_server_request_drop(req)<0)
                                dns_ok = 0;
                        return;
index 489b8e24ce4cddf81b331010e988923259aca60f..b602e31628b0d82b1e0073763efe540a622296e0 100644 (file)
@@ -304,20 +304,20 @@ test_evutil_snprintf(void *ptr)
 static void
 test_evutil_casecmp(void *ptr)
 {
-       tt_int_op(evutil_strcasecmp("ABC", "ABC"), ==, 0);
-       tt_int_op(evutil_strcasecmp("ABC", "abc"), ==, 0);
-       tt_int_op(evutil_strcasecmp("ABC", "abcd"), <, 0);
-       tt_int_op(evutil_strcasecmp("ABC", "abb"), >, 0);
-       tt_int_op(evutil_strcasecmp("ABCd", "abc"), >, 0);
+       tt_int_op(evutil_ascii_strcasecmp("ABC", "ABC"), ==, 0);
+       tt_int_op(evutil_ascii_strcasecmp("ABC", "abc"), ==, 0);
+       tt_int_op(evutil_ascii_strcasecmp("ABC", "abcd"), <, 0);
+       tt_int_op(evutil_ascii_strcasecmp("ABC", "abb"), >, 0);
+       tt_int_op(evutil_ascii_strcasecmp("ABCd", "abc"), >, 0);
 
-       tt_int_op(evutil_strncasecmp("Libevent", "LibEvEnT", 100), ==, 0);
-       tt_int_op(evutil_strncasecmp("Libevent", "LibEvEnT", 4), ==, 0);
-       tt_int_op(evutil_strncasecmp("Libevent", "LibEXXXX", 4), ==, 0);
-       tt_int_op(evutil_strncasecmp("Libevent", "LibE", 4), ==, 0);
-       tt_int_op(evutil_strncasecmp("Libe", "LibEvEnT", 4), ==, 0);
-       tt_int_op(evutil_strncasecmp("Lib", "LibEvEnT", 4), <, 0);
-       tt_int_op(evutil_strncasecmp("abc", "def", 99), <, 0);
-       tt_int_op(evutil_strncasecmp("Z", "qrst", 1), >, 0);
+       tt_int_op(evutil_ascii_strncasecmp("Libevent", "LibEvEnT", 100), ==, 0);
+       tt_int_op(evutil_ascii_strncasecmp("Libevent", "LibEvEnT", 4), ==, 0);
+       tt_int_op(evutil_ascii_strncasecmp("Libevent", "LibEXXXX", 4), ==, 0);
+       tt_int_op(evutil_ascii_strncasecmp("Libevent", "LibE", 4), ==, 0);
+       tt_int_op(evutil_ascii_strncasecmp("Libe", "LibEvEnT", 4), ==, 0);
+       tt_int_op(evutil_ascii_strncasecmp("Lib", "LibEvEnT", 4), <, 0);
+       tt_int_op(evutil_ascii_strncasecmp("abc", "def", 99), <, 0);
+       tt_int_op(evutil_ascii_strncasecmp("Z", "qrst", 1), >, 0);
 end:
        ;
 }
index 5423a112958682b616e7b4e727ec5b021e189797..3a84209469b9ed3f6a8fd5a2e1aeb8553972cb8e 100644 (file)
@@ -108,8 +108,6 @@ extern const char EVUTIL_TOUPPER_TABLE[];
 extern const char EVUTIL_TOLOWER_TABLE[];
 #define EVUTIL_TOLOWER(c) (EVUTIL_TOLOWER_TABLE[(ev_uint8_t)c])
 #define EVUTIL_TOUPPER(c) (EVUTIL_TOUPPER_TABLE[(ev_uint8_t)c])
-int evutil_strcasecmp(const char *, const char *);
-int evutil_strncasecmp(const char *, const char *, size_t);
 
 /** Helper macro.  If we know that a given pointer points to a field in a
     structure, return a pointer to the structure itself.  Used to implement