Skip to content

Commit

Permalink
strcasecompare: is the new name for strequal()
Browse files Browse the repository at this point in the history
... to make it less likely that we forget that the function actually
does case insentive compares. Also replaced several invokes of the
function with a plain strcmp when case sensitivity is not an issue (like
comparing with "-").
  • Loading branch information
bagder committed Oct 31, 2016
1 parent 1833a45 commit 502acba
Show file tree
Hide file tree
Showing 36 changed files with 98 additions and 111 deletions.
4 changes: 2 additions & 2 deletions lib/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LIB_VTLS_HFILES = vtls/openssl.h vtls/vtls.h vtls/gtls.h \
LIB_CFILES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
cookie.c http.c sendf.c ftp.c url.c dict.c if2ip.c speedcheck.c \
ldap.c version.c getenv.c escape.c mprintf.c telnet.c netrc.c \
getinfo.c transfer.c strequal.c easy.c security.c curl_fnmatch.c \
getinfo.c transfer.c strcase.c easy.c security.c curl_fnmatch.c \
fileinfo.c ftplistparser.c wildcard.c krb5.c memdebug.c http_chunks.c \
strtok.c connect.c llist.c hash.c multi.c content_encoding.c share.c \
http_digest.c md4.c md5.c http_negotiate.c inet_pton.c strtoofft.c \
Expand All @@ -58,7 +58,7 @@ LIB_CFILES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
LIB_HFILES = arpa_telnet.h netrc.h file.h timeval.h hostip.h progress.h \
formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h if2ip.h \
speedcheck.h urldata.h curl_ldap.h escape.h telnet.h getinfo.h \
strequal.h curl_sec.h memdebug.h http_chunks.h curl_fnmatch.h \
strcase.h curl_sec.h memdebug.h http_chunks.h curl_fnmatch.h \
wildcard.h fileinfo.h ftplistparser.h strtok.h connect.h llist.h \
hash.h content_encoding.h share.h curl_md4.h curl_md5.h http_digest.h \
http_negotiate.h inet_pton.h amigaos.h strtoofft.h strerror.h \
Expand Down
5 changes: 2 additions & 3 deletions lib/cookie.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ Example set of cookies:

#include "urldata.h"
#include "cookie.h"
#include "strequal.h"
#include "strtok.h"
#include "sendf.h"
#include "slist.h"
Expand Down Expand Up @@ -939,7 +938,7 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
}
c->running = FALSE; /* this is not running, this is init */

if(file && strequal(file, "-")) {
if(file && !strcmp(file, "-")) {
fp = stdin;
fromfile=FALSE;
}
Expand Down Expand Up @@ -1310,7 +1309,7 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
/* at first, remove expired cookies */
remove_expired(c);

if(strequal("-", dumphere)) {
if(!strcmp("-", dumphere)) {
/* use stdout */
out = stdout;
use_stdout=TRUE;
Expand Down
3 changes: 1 addition & 2 deletions lib/curl_sasl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "curl_sasl.h"
#include "warnless.h"
#include "strtok.h"
#include "strequal.h"
#include "rawstr.h"
#include "sendf.h"
#include "non-ascii.h" /* included for Curl_convert_... prototypes */
Expand Down Expand Up @@ -159,7 +158,7 @@ CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
sasl->prefmech = SASL_AUTH_NONE;
}

if(strnequal(value, "*", len))
if(!strncmp(value, "*", len))
sasl->prefmech = SASL_AUTH_DEFAULT;
else {
mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
Expand Down
10 changes: 5 additions & 5 deletions lib/curlx.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand All @@ -34,8 +34,8 @@
functions while they still are offered publicly. They will be made library-
private one day */

#include "strequal.h"
/* "strequal.h" provides the strequal protos */
#include "strcase.h"
/* "strcase.h" provides the strcasecompare protos */

#include "strtoofft.h"
/* "strtoofft.h" provides this function: curlx_strtoofft(), returns a
Expand Down Expand Up @@ -73,8 +73,8 @@
*/

#define curlx_getenv curl_getenv
#define curlx_strequal curl_strequal
#define curlx_strnequal curl_strnequal
#define curlx_strcasecompare curl_strcasecompare
#define curlx_strncasecompare curl_strncasecompare
#define curlx_raw_equal Curl_raw_equal
#define curlx_mvsnprintf curl_mvsnprintf
#define curlx_msnprintf curl_msnprintf
Expand Down
1 change: 0 additions & 1 deletion lib/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include "sendf.h"
#include "escape.h"
#include "progress.h"
#include "strequal.h"
#include "dict.h"
#include "rawstr.h"
#include "curl_memory.h"
Expand Down
1 change: 0 additions & 1 deletion lib/easy.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
#include <sys/param.h>
#endif

#include "strequal.h"
#include "urldata.h"
#include <curl/curl.h>
#include "transfer.h"
Expand Down
12 changes: 6 additions & 6 deletions lib/formdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "urldata.h" /* for struct Curl_easy */
#include "formdata.h"
#include "vtls/vtls.h"
#include "strequal.h"
#include "strcase.h"
#include "sendf.h"
#include "strdup.h"
/* The last 3 #include files should be in this order */
Expand Down Expand Up @@ -201,9 +201,9 @@ static const char *ContentTypeForFilename(const char *filename,
if(filename) { /* in case a NULL was passed in */
for(i=0; i<sizeof(ctts)/sizeof(ctts[0]); i++) {
if(strlen(filename) >= strlen(ctts[i].extension)) {
if(strequal(filename +
strlen(filename) - strlen(ctts[i].extension),
ctts[i].extension)) {
if(strcasecompare(filename +
strlen(filename) - strlen(ctts[i].extension),
ctts[i].extension)) {
contenttype = ctts[i].type;
break;
}
Expand Down Expand Up @@ -878,7 +878,7 @@ static CURLcode AddFormData(struct FormData **formp,
else {
/* Since this is a file to be uploaded here, add the size of the actual
file */
if(!strequal("-", newform->line)) {
if(strcmp("-", newform->line)) {
struct_stat file;
if(!stat(newform->line, &file) && !S_ISDIR(file.st_mode))
*size += filesize(newform->line, file);
Expand Down Expand Up @@ -1305,7 +1305,7 @@ CURLcode Curl_getformdata(struct Curl_easy *data,
/* we should include the contents from the specified file */
FILE *fileread;

fileread = strequal("-", file->contents)?
fileread = !strcmp("-", file->contents)?
stdin:fopen(file->contents, "rb"); /* binary read for win32 */

/*
Expand Down
6 changes: 3 additions & 3 deletions lib/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#include "ftplistparser.h"
#include "curl_sec.h"
#include "strtoofft.h"
#include "strequal.h"
#include "strcase.h"
#include "vtls/vtls.h"
#include "connect.h"
#include "strerror.h"
Expand Down Expand Up @@ -2999,7 +2999,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)

/* Check for special servers here. */

if(strequal(os, "OS/400")) {
if(strcasecompare(os, "OS/400")) {
/* Force OS400 name format 1. */
result = Curl_pp_sendf(&ftpc->pp, "%s", "SITE NAMEFMT 1");
if(result) {
Expand Down Expand Up @@ -4320,7 +4320,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
return CURLE_OUT_OF_MEMORY;

/* we have a special case for listing the root dir only */
if(strequal(path_to_use, "/")) {
if(!strcmp(path_to_use, "/")) {
cur_pos++; /* make it point to the zero byte */
ftpc->dirs[0] = strdup("/");
ftpc->dirdepth++;
Expand Down
1 change: 0 additions & 1 deletion lib/gopher.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "sendf.h"

#include "progress.h"
#include "strequal.h"
#include "gopher.h"
#include "rawstr.h"
#include "select.h"
Expand Down
1 change: 0 additions & 1 deletion lib/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#include "progress.h"
#include "curl_base64.h"
#include "cookie.h"
#include "strequal.h"
#include "vauth/vauth.h"
#include "vtls/vtls.h"
#include "http_digest.h"
Expand Down
8 changes: 4 additions & 4 deletions lib/if2ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#endif

#include "inet_ntop.h"
#include "strequal.h"
#include "strcase.h"
#include "if2ip.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
Expand Down Expand Up @@ -102,7 +102,7 @@ bool Curl_if_is_interface_name(const char *interf)

if(getifaddrs(&head) >= 0) {
for(iface=head; iface != NULL; iface=iface->ifa_next) {
if(curl_strequal(iface->ifa_name, interf)) {
if(strcasecompare(iface->ifa_name, interf)) {
result = TRUE;
break;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
for(iface = head; iface != NULL; iface=iface->ifa_next) {
if(iface->ifa_addr != NULL) {
if(iface->ifa_addr->sa_family == af) {
if(curl_strequal(iface->ifa_name, interf)) {
if(strcasecompare(iface->ifa_name, interf)) {
void *addr;
char *ip;
char scope[12] = "";
Expand Down Expand Up @@ -180,7 +180,7 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
}
}
else if((res == IF2IP_NOT_FOUND) &&
curl_strequal(iface->ifa_name, interf)) {
strcasecompare(iface->ifa_name, interf)) {
res = IF2IP_AF_NOT_SUPPORTED;
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/imap.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@
#include "http.h" /* for HTTP proxy tunnel stuff */
#include "socks.h"
#include "imap.h"

#include "strtoofft.h"
#include "strequal.h"
#include "strcase.h"
#include "vtls/vtls.h"
#include "connect.h"
#include "strerror.h"
Expand Down Expand Up @@ -1935,7 +1934,7 @@ static CURLcode imap_parse_url_options(struct connectdata *conn)
while(*ptr && *ptr != ';')
ptr++;

if(strnequal(key, "AUTH=", 5))
if(strncasecompare(key, "AUTH=", 5))
result = Curl_sasl_parse_url_auth_option(&imapc->sasl,
value, ptr - value);
else
Expand Down
2 changes: 0 additions & 2 deletions lib/netrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include <curl/curl.h>
#include "netrc.h"

#include "strequal.h"
#include "strtok.h"
#include "rawstr.h"

Expand Down
7 changes: 3 additions & 4 deletions lib/pop3.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@
#include "http.h" /* for HTTP proxy tunnel stuff */
#include "socks.h"
#include "pop3.h"

#include "strtoofft.h"
#include "strequal.h"
#include "strcase.h"
#include "vtls/vtls.h"
#include "connect.h"
#include "strerror.h"
Expand Down Expand Up @@ -1412,11 +1411,11 @@ static CURLcode pop3_parse_url_options(struct connectdata *conn)
while(*ptr && *ptr != ';')
ptr++;

if(strnequal(key, "AUTH=", 5)) {
if(strncasecompare(key, "AUTH=", 5)) {
result = Curl_sasl_parse_url_auth_option(&pop3c->sasl,
value, ptr - value);

if(result && strnequal(value, "+APOP", ptr - value)) {
if(result && strncasecompare(value, "+APOP", ptr - value)) {
pop3c->preftype = POP3_TYPE_APOP;
pop3c->sasl.prefmech = SASL_AUTH_NONE;
result = CURLE_OK;
Expand Down
5 changes: 2 additions & 3 deletions lib/smtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@
#include "http.h" /* for HTTP proxy tunnel stuff */
#include "socks.h"
#include "smtp.h"

#include "strtoofft.h"
#include "strequal.h"
#include "strcase.h"
#include "vtls/vtls.h"
#include "connect.h"
#include "strerror.h"
Expand Down Expand Up @@ -1512,7 +1511,7 @@ static CURLcode smtp_parse_url_options(struct connectdata *conn)
while(*ptr && *ptr != ';')
ptr++;

if(strnequal(key, "AUTH=", 5))
if(strncasecompare(key, "AUTH=", 5))
result = Curl_sasl_parse_url_auth_option(&smtpc->sasl,
value, ptr - value);
else
Expand Down
1 change: 0 additions & 1 deletion lib/socks.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#include "urldata.h"
#include "sendf.h"
#include "strequal.h"
#include "select.h"
#include "connect.h"
#include "timeval.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
sshc->acceptfail = TRUE;
}

if(curl_strequal("pwd", cmd)) {
if(strcasecompare("pwd", cmd)) {
/* output debug output if that is requested */
char *tmp = aprintf("257 \"%s\" is current directory.\n",
sftp_scp->path);
Expand Down
8 changes: 4 additions & 4 deletions lib/strequal.c → lib/strcase.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand All @@ -26,12 +26,12 @@
#include <strings.h>
#endif

#include "strequal.h"
#include "strcase.h"

/*
* @unittest: 1301
*/
int curl_strequal(const char *first, const char *second)
int curl_strcasecompare(const char *first, const char *second)
{
#if defined(HAVE_STRCASECMP)
return !(strcasecmp)(first, second);
Expand All @@ -54,7 +54,7 @@ int curl_strequal(const char *first, const char *second)
/*
* @unittest: 1301
*/
int curl_strnequal(const char *first, const char *second, size_t max)
int curl_strncasecompare(const char *first, const char *second, size_t max)
{
#if defined(HAVE_STRNCASECMP)
return !strncasecmp(first, second, max);
Expand Down
15 changes: 9 additions & 6 deletions lib/strequal.h → lib/strcase.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef HEADER_CURL_STREQUAL_H
#define HEADER_CURL_STREQUAL_H
#ifndef HEADER_CURL_STRCASE_H
#define HEADER_CURL_STRCASE_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand All @@ -24,8 +24,11 @@

#include <curl/curl.h>

#define strequal(a,b) curl_strequal(a,b)
#define strnequal(a,b,c) curl_strnequal(a,b,c)
#define strcasecompare(a,b) curl_strcasecompare(a,b)
#define strncasecompare(a,b,c) curl_strncasecompare(a,b,c)

#endif /* HEADER_CURL_STREQUAL_H */
int curl_strcasecompare(const char *first, const char *second);
int curl_strncasecompare(const char *first, const char *second, size_t max);


#endif /* HEADER_CURL_STRCASE_H */
1 change: 0 additions & 1 deletion lib/telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@

#include "arpa_telnet.h"
#include "select.h"
#include "strequal.h"
#include "rawstr.h"
#include "warnless.h"

Expand Down
Loading

0 comments on commit 502acba

Please sign in to comment.