]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Created Curl_raw_nequal() which does a C-locale string case comparison.
authorDan Fandrich <dan@coneharvesters.com>
Thu, 23 Oct 2008 01:20:57 +0000 (01:20 +0000)
committerDan Fandrich <dan@coneharvesters.com>
Thu, 23 Oct 2008 01:20:57 +0000 (01:20 +0000)
Changed checkprefix() to use it and those instances of strnequal() that
compare host names or other protocol strings that are defined to be
independent of case in the C locale.  This should fix a few more
Turkish locale problems.

lib/cookie.c
lib/dict.c
lib/ftp.c
lib/http.c
lib/security.c
lib/ssh.c
lib/sslgen.c
lib/strequal.c
lib/strequal.h
lib/url.c

index f2de8eaf9aa17a8870056afcef678dec59fb78c5..fed4a44f607e6df1f39b405f5f9c3a3ccb401371 100644 (file)
@@ -131,7 +131,7 @@ static bool tailmatch(const char *little, const char *bigone)
   if(littlelen > biglen)
     return FALSE;
 
-  return (bool)strequal(little, bigone+biglen-littlelen);
+  return (bool)Curl_raw_equal(little, bigone+biglen-littlelen);
 }
 
 /*
index b1f5b6810e0eb4b2588b2434930ace8b9d9502cb..f9ce50efcf8a8d7e75b867aba529e34f81b18cfd 100644 (file)
@@ -163,9 +163,9 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
     /* AUTH is missing */
   }
 
-  if(strnequal(path, DICT_MATCH, sizeof(DICT_MATCH)-1) ||
-      strnequal(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) ||
-      strnequal(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) {
+  if(Curl_raw_nequal(path, DICT_MATCH, sizeof(DICT_MATCH)-1) ||
+      Curl_raw_nequal(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) ||
+      Curl_raw_nequal(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) {
 
     word = strchr(path, ':');
     if(word) {
@@ -222,9 +222,9 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
     if(result)
       return result;
   }
-  else if(strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) ||
-           strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) ||
-           strnequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) {
+  else if(Curl_raw_nequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) ||
+           Curl_raw_nequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) ||
+           Curl_raw_nequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) {
 
     word = strchr(path, ':');
     if(word) {
index ca8ef11353c5e07c6658e9f3201908527ba54fd1..cdce060613bb16028e23ded24ce8ab8e854dd827 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -4019,7 +4019,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
 
     dlen -= ftpc->file?strlen(ftpc->file):0;
     if((dlen == (int)strlen(ftpc->prevpath)) &&
-       curl_strnequal(path, ftpc->prevpath, dlen)) {
+       strnequal(path, ftpc->prevpath, dlen)) {
       infof(data, "Request has same path as previous transfer\n");
       ftpc->cwddone = TRUE;
     }
index b1b70ce4e41e1b0911b0f40a8b9b2768f7a67ac3..503ceb0c19ba59d44ad56d4def6ab9f02703e06a 100644 (file)
@@ -173,7 +173,7 @@ static char *checkheaders(struct SessionHandle *data, const char *thisheader)
   size_t thislen = strlen(thisheader);
 
   for(head = data->set.headers; head; head=head->next) {
-    if(strnequal(head->data, thisheader, thislen))
+    if(Curl_raw_nequal(head->data, thisheader, thislen))
       return head->data;
   }
   return NULL;
@@ -1246,7 +1246,7 @@ Curl_compareheader(const char *headerline, /* line to check */
   const char *start;
   const char *end;
 
-  if(!strnequal(headerline, header, hlen))
+  if(!Curl_raw_nequal(headerline, header, hlen))
     return FALSE; /* doesn't start with header */
 
   /* pass the header */
@@ -1272,7 +1272,7 @@ Curl_compareheader(const char *headerline, /* line to check */
 
   /* find the content string in the rest of the line */
   for(;len>=clen;len--, start++) {
-    if(strnequal(start, content, clen))
+    if(Curl_raw_nequal(start, content, clen))
       return TRUE; /* match! */
   }
 
@@ -2026,12 +2026,11 @@ static CURLcode add_custom_headers(struct connectdata *conn,
         if(conn->allocptr.host &&
            /* a Host: header was sent already, don't pass on any custom Host:
               header as that will produce *two* in the same request! */
-           curl_strnequal("Host:", headers->data, 5))
+           checkprefix("Host:", headers->data))
           ;
         else if(conn->data->set.httpreq == HTTPREQ_POST_FORM &&
                 /* this header (extended by formdata.c) is sent later */
-                curl_strnequal("Content-Type:", headers->data,
-                               strlen("Content-Type:")))
+                checkprefix("Content-Type:", headers->data))
           ;
         else {
           CURLcode result = add_bufferf(req_buffer, "%s\r\n", headers->data);
index bec751045e275ee4f5e839aff2f4406b26f8374d..01143938a529d5f993707c98c8400a054a572f12 100644 (file)
@@ -85,7 +85,7 @@ name_to_level(const char *name)
 {
   int i;
   for(i = 0; i < (int)sizeof(level_names)/(int)sizeof(level_names[0]); i++)
-    if(curl_strnequal(level_names[i].name, name, strlen(name)))
+    if(checkprefix(name, level_names[i].name))
       return level_names[i].level;
   return (enum protection_level)-1;
 }
index 32057a3c45fce9ac74c7362f0d5392b710dd37e6..6d2108bef1da2ac91985cb04d1b7e1f5bbb5b95a 100644 (file)
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -822,7 +822,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn)
     /*
      * Support some of the "FTP" commands
      */
-    if(curl_strnequal(sshc->quote_item->data, "PWD", 3)) {
+    if(curl_strequal("pwd", sshc->quote_item->data)) {
       /* output debug output if that is requested */
       if(data->set.verbose) {
         char tmp[PATH_MAX+1];
index eee46b91298f20c37324c8030cf941698a20730a..1bfeda7130a1f3f5c2a77950b140d40074ef1325 100644 (file)
@@ -64,8 +64,6 @@
 /* The last #include file should be: */
 #include "memdebug.h"
 
-static bool safe_strequal(char* str1, char* str2);
-
 static bool safe_strequal(char* str1, char* str2)
 {
   if(str1 && str2)
@@ -228,7 +226,7 @@ int Curl_ssl_getsessionid(struct connectdata *conn,
     if(!check->sessionid)
       /* not session ID means blank entry */
       continue;
-    if(curl_strequal(conn->host.name, check->name) &&
+    if(Curl_raw_equal(conn->host.name, check->name) &&
        (conn->remote_port == check->remote_port) &&
        Curl_ssl_config_matches(&conn->ssl_config, &check->ssl_config)) {
       /* yes, we have a session ID! */
index 5065b387157292e4d2746663bb00eac2d4e73e87..3d00aa21395765806f96c24351dce63bb7f66387 100644 (file)
@@ -161,6 +161,22 @@ int Curl_raw_equal(const char *first, const char *second)
   return (my_toupper(*first) == my_toupper(*second));
 }
 
+int Curl_raw_nequal(const char *first, const char *second, size_t max)
+{
+  while(*first && *second && max) {
+    if(my_toupper(*first) != my_toupper(*second)) {
+      break;
+    }
+    max--;
+    first++;
+    second++;
+  }
+  if(0 == max)
+    return 1; /* they are equal this far */
+
+  return my_toupper(*first) == my_toupper(*second);
+}
+
 #ifndef HAVE_STRLCAT
 /*
  * The strlcat() function appends the NUL-terminated string src to the end
index 778b23cd9ff6b9ecf5c64d26b11ccfcfb4049079..eac40020295aaf16a20ea2b4195fa11c9120a439 100644 (file)
 #define strequal(a,b) curl_strequal(a,b)
 #define strnequal(a,b,c) curl_strnequal(a,b,c)
 
-/* checkprefix() is a shorter version of the above, used when the first
-   argument is zero-byte terminated */
-#define checkprefix(a,b)    strnequal(a,b,strlen(a))
-
 /*
  * Curl_raw_equal() is for doing "raw" case insensitive strings. This is meant
  * to be locale independent and only compare strings we know are safe for
  * The function is capable of comparing a-z case insensitively even for non-ascii.
  */
 int Curl_raw_equal(const char *first, const char *second);
+int Curl_raw_nequal(const char *first, const char *second, size_t max);
+
+/* checkprefix() is a shorter version of the above, used when the first
+   argument is zero-byte terminated */
+#define checkprefix(a,b)    Curl_raw_nequal(a,b,strlen(a))
 
 #ifndef HAVE_STRLCAT
 #define strlcat(x,y,z) Curl_strlcat(x,y,z)
index a21cda0aeceee186b4711f5510f616586964d5df..bf77eab95e43c76fcba10a2268d011346cf1d7a5 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3337,7 +3337,7 @@ static char *detect_proxy(struct connectdata *conn)
   if(!no_proxy)
     no_proxy=curl_getenv("NO_PROXY");
 
-  if(!no_proxy || !strequal("*", no_proxy)) {
+  if(!no_proxy || !Curl_raw_equal("*", no_proxy)) {
     /* NO_PROXY wasn't specified or it wasn't just an asterisk */
     char *nope;