1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

Created Curl_raw_nequal() which does a C-locale string case comparison.

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.
This commit is contained in:
Dan Fandrich 2008-10-23 01:20:57 +00:00
parent 0abaf22467
commit bab5183820
10 changed files with 38 additions and 24 deletions

View 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);
}
/*

View 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) {

View File

@ -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;
}

View 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);

View 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;
}

View File

@ -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];

View 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! */

View 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

View File

@ -28,10 +28,6 @@
#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
@ -40,6 +36,11 @@
* 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)

View File

@ -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;