X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=miscutil.c;h=5679ca2affe6307ee7dceb357ac2220b5ad35d37;hp=bde7237100449e45034583afc4115bb2e6d44e99;hb=f1509beb2fa10e04be0cb69cf52c57c699b649b7;hpb=e4aec8092bcef36685f4ce01ed83de1c024ba252 diff --git a/miscutil.c b/miscutil.c index bde72371..5679ca2a 100644 --- a/miscutil.c +++ b/miscutil.c @@ -1,7 +1,7 @@ -const char miscutil_rcs[] = "$Id: miscutil.c,v 1.35 2002/03/26 22:29:55 swa Exp $"; +const char miscutil_rcs[] = "$Id: miscutil.c,v 1.37.2.4 2003/12/01 14:45:14 oes Exp $"; /********************************************************************* * - * File : $Source: /cvsroot/ijbswa/current/miscutil.c,v $ + * File : $Source: /cvsroot/ijbswa/current/Attic/miscutil.c,v $ * * Purpose : zalloc, hash_string, safe_strerror, strcmpic, * strncmpic, chomp, and MinGW32 strdup @@ -36,6 +36,26 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 1.35 2002/03/26 22:29:55 swa Exp * * Revisions : * $Log: miscutil.c,v $ + * Revision 1.37.2.4 2003/12/01 14:45:14 oes + * Fixed two more problems with wildcarding in simplematch() + * + * Revision 1.37.2.3 2003/11/20 11:39:24 oes + * Bugfix: The "?" wildcard for domain names had never been implemented. Ooops\! + * + * Revision 1.37.2.2 2002/11/12 14:28:18 oes + * Proper backtracking in simplematch; fixes bug #632888 + * + * Revision 1.37.2.1 2002/09/25 12:58:51 oes + * Made strcmpic and strncmpic safe against NULL arguments + * (which are now treated as empty strings). + * + * Revision 1.37 2002/04/26 18:29:43 jongfoster + * Fixing this Visual C++ warning: + * miscutil.c(710) : warning C4090: '=' : different 'const' qualifiers + * + * Revision 1.36 2002/04/26 12:55:38 oes + * New function string_toupper + * * Revision 1.35 2002/03/26 22:29:55 swa * we have a new homepage! * @@ -392,6 +412,9 @@ char *safe_strerror(int err) *********************************************************************/ int strcmpic(const char *s1, const char *s2) { + if (!s1) s1 = ""; + if (!s2) s2 = ""; + while (*s1 && *s2) { if ( ( *s1 != *s2 ) && ( ijb_tolower(*s1) != ijb_tolower(*s2) ) ) @@ -422,7 +445,9 @@ int strcmpic(const char *s1, const char *s2) int strncmpic(const char *s1, const char *s2, size_t n) { if (n <= 0) return(0); - + if (!s1) s1 = ""; + if (!s2) s2 = ""; + while (*s1 && *s2) { if ( ( *s1 != *s2 ) && ( ijb_tolower(*s1) != ijb_tolower(*s2) ) ) @@ -697,7 +722,8 @@ jb_err string_join(char **target_string, char *text_to_append) *********************************************************************/ char *string_toupper(const char *string) { - char *result, *q, *p; + char *result, *p; + const char *q; if (!string || ((result = (char *) zalloc(strlen(string) + 1)) == NULL)) { @@ -744,14 +770,20 @@ int simplematch(char *pattern, char *text) unsigned i; unsigned char charmap[32]; - while (*txt) { /* EOF pattern but !EOF text? */ if (*pat == '\0') { - return 1; + if (wildcard) + { + pat = fallback; + } + else + { + return 1; + } } /* '*' in the pattern? */ @@ -800,26 +832,31 @@ int simplematch(char *pattern, char *text) } /* -END- if Character range specification */ - /* Compare: Char match, or char range match*/ - if ((*pat == *txt) - || ((*pat == ']') && (charmap[*txt / 8] & (1 << (*txt % 8)))) ) + /* + * Char match, or char range match? + */ + if ( (*pat == *txt) + || (*pat == '?') + || ((*pat == ']') && (charmap[*txt / 8] & (1 << (*txt % 8)))) ) { - /* Sucess, go ahead */ + /* + * Sucess: Go ahead + */ pat++; } - else + else if (!wildcard) { - /* In wildcard mode, just try again after failiure */ - if(wildcard) - { - pat = fallback; - } - - /* Else, bad luck */ - else - { - return 1; - } + /* + * No match && no wildcard: No luck + */ + return 1; + } + else if (pat != fallback) + { + /* + * Wildcard mode && nonmatch beyond fallback: Rewind pattern + */ + pat = fallback; } txt++; }