From: Art Cancro Date: Fri, 9 Sep 2005 17:21:55 +0000 (+0000) Subject: * Removed the bmstrstr() function, and replaced all calls to it with calls X-Git-Tag: v7.86~4676 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=eb7e7fa868c9b3a61efe0e89b2600e588e6e9f7c * Removed the bmstrstr() function, and replaced all calls to it with calls to strstr() or strcasestr(). This code was not performing reliable substring searches, so we are going to sacrifice speed for reliability until better code is either written or found. --- diff --git a/citadel/docs/citadel.html b/citadel/docs/citadel.html index 49716cde2..08b54b77a 100644 --- a/citadel/docs/citadel.html +++ b/citadel/docs/citadel.html @@ -8,8 +8,7 @@

C I T A D E L

-

a messaging and collaboration platform -for groupware and BBS applications

+

an open source messaging and collaboration platform

Copyright ©1987-2005 by the Citadel development team:

@@ -70,13 +69,6 @@ developer
- - - - diff --git a/citadel/imap_search.c b/citadel/imap_search.c index 560a25d38..905a84a85 100644 --- a/citadel/imap_search.c +++ b/citadel/imap_search.c @@ -113,7 +113,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, } fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Bcc"); if (fieldptr != NULL) { - if (bmstrstr(fieldptr, itemlist[pos+1], strncasecmp)) { + if (strcasestr(fieldptr, itemlist[pos+1])) { match = 1; } free(fieldptr); @@ -140,7 +140,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (bmstrstr(msg->cm_fields['M'], itemlist[pos+1], strncasecmp)) { + if (strcasestr(msg->cm_fields['M'], itemlist[pos+1])) { match = 1; } pos += 2; @@ -153,7 +153,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, } fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Cc"); if (fieldptr != NULL) { - if (bmstrstr(fieldptr, itemlist[pos+1], strncasecmp)) { + if (strcasestr(fieldptr, itemlist[pos+1])) { match = 1; } free(fieldptr); @@ -187,7 +187,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (bmstrstr(msg->cm_fields['A'], itemlist[pos+1], strncasecmp)) { + if (strcasestr(msg->cm_fields['A'], itemlist[pos+1])) { match = 1; } pos += 2; @@ -328,7 +328,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (bmstrstr(msg->cm_fields['U'], itemlist[pos+1], strncasecmp)) { + if (strcasestr(msg->cm_fields['U'], itemlist[pos+1])) { match = 1; } pos += 2; @@ -340,7 +340,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, need_to_free_msg = 1; } for (i='A'; i<='Z'; ++i) { - if (bmstrstr(msg->cm_fields[i], itemlist[pos+1], strncasecmp)) { + if (strcasestr(msg->cm_fields[i], itemlist[pos+1])) { match = 1; } } @@ -352,7 +352,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (bmstrstr(msg->cm_fields['R'], itemlist[pos+1], strncasecmp)) { + if (strcasestr(msg->cm_fields['R'], itemlist[pos+1])) { match = 1; } pos += 2; diff --git a/citadel/internet_addressing.c b/citadel/internet_addressing.c index 9dbc5b875..e53954dfd 100644 --- a/citadel/internet_addressing.c +++ b/citadel/internet_addressing.c @@ -491,13 +491,13 @@ char *rfc822_fetch_field(char *rfc822, char *fieldname) { snprintf(fieldhdr, sizeof fieldhdr, "%s:", fieldname); /* Locate the end of the headers, so we don't run past that point */ - end_of_headers = bmstrstr(rfc822, "\n\r\n", strncmp); + end_of_headers = strcasestr(rfc822, "\n\r\n"); if (end_of_headers == NULL) { - end_of_headers = bmstrstr(rfc822, "\n\n", strncmp); + end_of_headers = strcasestr(rfc822, "\n\n"); } if (end_of_headers == NULL) return (NULL); - field_start = bmstrstr(rfc822, fieldhdr, strncasecmp); + field_start = strcasestr(rfc822, fieldhdr); if (field_start == NULL) return(NULL); if (field_start > end_of_headers) return(NULL); diff --git a/citadel/mime_parser.c b/citadel/mime_parser.c index 01636b163..beffe3c93 100644 --- a/citadel/mime_parser.c +++ b/citadel/mime_parser.c @@ -415,8 +415,6 @@ void the_mime_parser(char *partnum, part_start = NULL; do { - - /* next_boundary = bmstrstr(ptr, startary, memcmp); */ next_boundary = NULL; for (srch=ptr; srchcm_fields['M'], - "Content-type: ", strncasecmp); + mptr = strcasestr(msg->cm_fields['M'], "Content-type: "); if (mptr != NULL) { safestrncpy(content_type, &mptr[14], sizeof content_type); diff --git a/citadel/serv_imap.c b/citadel/serv_imap.c index ff340b007..c297ac788 100644 --- a/citadel/serv_imap.c +++ b/citadel/serv_imap.c @@ -1386,7 +1386,7 @@ void imap_command_loop(void) if (IMAP->authstate == imap_as_expecting_password) { lprintf(CTDL_INFO, "IMAP: \n"); } - else if (bmstrstr(cmdbuf, " LOGIN ", strncasecmp)) { + else if (strcasestr(cmdbuf, " LOGIN ")) { lprintf(CTDL_INFO, "IMAP: LOGIN...\n"); } else { diff --git a/citadel/tools.c b/citadel/tools.c index 69961493e..69cb23d44 100644 --- a/citadel/tools.c +++ b/citadel/tools.c @@ -550,70 +550,6 @@ void urlesc(char *outbuf, char *strbuf) } -/* - * bmstrstr() is a variant of strstr() that uses the Boyer-Moore search - * algorithm, and can use any caller-supplied string compare function whose - * calling syntax is similar to strncmp(). For example, we can supply it - * with strncasecmp() to do a case-insensitive search. - * - * Original code: copyright (c) 1997-1998 by Urs Janssen - * Modifications: copyright (c) 2003 by Art Cancro - */ -char *bmstrstr(char *text, char *pattern, - int (*cmpfunc)(const char *, const char *, size_t) ) -{ - register unsigned char *p, *t; - register int i, j, *delta; - register size_t p1; - int deltaspace[256]; - size_t textlen; - size_t patlen; - - if (text == NULL) return(NULL); - if (pattern == NULL) return(NULL); - - textlen = strlen(text); - patlen = strlen(pattern); - - /* algorithm fails if pattern is empty */ - if ((p1 = patlen) == 0) - return (text); - - /* code below fails (whenever i is unsigned) if pattern too long */ - if (p1 > textlen) - return (NULL); - - /* set up deltas */ - delta = deltaspace; - for (i = 0; i <= 255; i++) - delta[i] = p1; - for (p = (unsigned char *) pattern, i = p1; --i > 0;) - delta[*p++] = i; - - /* - * From now on, we want patlen - 1. - * In the loop below, p points to the end of the pattern, - * t points to the end of the text to be tested against the - * pattern, and i counts the amount of text remaining, not - * including the part to be tested. - */ - p1--; - p = (unsigned char *) pattern + p1; - t = (unsigned char *) text + p1; - i = textlen - patlen; - while (1) { - if (tolower(*p) == tolower(*t) - && cmpfunc((p - p1), (t - p1), p1) == 0) - return ((char *) t - p1); - j = delta[*t]; - if (i < j) - break; - i -= j; - t += j; - } - return (NULL); -} - /* * In our world, we want strcpy() to be able to work with overlapping strings. diff --git a/citadel/tools.h b/citadel/tools.h index 32c02f11f..cb63f75bd 100644 --- a/citadel/tools.h +++ b/citadel/tools.h @@ -29,8 +29,5 @@ char *myfgets(char *s, int size, FILE *stream); void urlesc(char *outbuf, char *strbuf); char *CtdlTempFileName(char *prefix1, int prefix2); FILE *CtdlTempFile(void); -char *bmstrstr(char *text, char *pattern, - int (*cmpfunc)(const char *, const char *, size_t) ); - char *ascmonths[12]; void generate_uuid(char *buf); diff --git a/citadel/user_ops.c b/citadel/user_ops.c index b506bd9ff..abb388924 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -1370,7 +1370,7 @@ void ListThisUser(struct ctdluser *usbuf, void *data) char *searchstring; searchstring = (char *)data; - if (bmstrstr(usbuf->fullname, searchstring, strncasecmp) == NULL) { + if (strcasestr(usbuf->fullname, searchstring) == NULL) { return; }
client software development
Urs Jannsen
-
text -search algorithm
-
Andru Luvisi