* Removed the bmstrstr() function, and replaced all calls to it with calls
authorArt Cancro <ajc@citadel.org>
Fri, 9 Sep 2005 17:21:55 +0000 (17:21 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 9 Sep 2005 17:21:55 +0000 (17:21 +0000)
  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.

citadel/docs/citadel.html
citadel/imap_search.c
citadel/internet_addressing.c
citadel/mime_parser.c
citadel/msgbase.c
citadel/serv_imap.c
citadel/tools.c
citadel/tools.h
citadel/user_ops.c

index 49716cde28cfdce2df0290a9af91eb919a04a8c8..08b54b77a9c8f1986a5b41a6b91853fcaa8b73c4 100644 (file)
@@ -8,8 +8,7 @@
 <body>
 <div align="center">
 <h1>C I T A D E L</h1>
-<h2>a messaging and collaboration platform
-for groupware and BBS applications</h2>
+<h2>an open source messaging and collaboration platform</h2>
 Copyright &copy;1987-2005 by the Citadel development team:<br>
 <br>
 <table align="center" border="0" cellpadding="2" cellspacing="2">
@@ -70,13 +69,6 @@ developer<br>
       <td valign="top"><i>client software development<br>
       </i></td>
     </tr>
-    <tr>
-      <td style="vertical-align: top;">Urs Jannsen<br>
-      </td>
-      <td style="vertical-align: top;"><span style="font-style: italic;">text
-search algorithm</span><br>
-      </td>
-    </tr>
     <tr>
       <td valign="top">Andru Luvisi<br>
       </td>
index 560a25d3891895cd68a8ae5566f2624ff653cfa2..905a84a8541b9ac67088192a288eb75ed9e850fb 100644 (file)
@@ -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;
index 9dbc5b875c99573c402656e4cdeb975e8ca628f4..e53954dfd4024af0b23a5316c5a127ace4a03cfd 100644 (file)
@@ -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);
 
index 01636b1633c14fa1f94232290ee26385dc88a6d8..beffe3c934964d68bfd25dee6bc6f2005301b0ca 100644 (file)
@@ -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; srch<content_end; ++srch) {
                                if (!memcmp(srch, startary, startary_len)) {
index a5035ce27644915ec79a25e61efc2b63c945d477..07accb07b810a20443775e7a9a44eaac7eed8865 100644 (file)
@@ -2109,8 +2109,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
                break;
        case 4:
                strcpy(content_type, "text/plain");
-               mptr = bmstrstr(msg->cm_fields['M'],
-                               "Content-type: ", strncasecmp);
+               mptr = strcasestr(msg->cm_fields['M'], "Content-type: ");
                if (mptr != NULL) {
                        safestrncpy(content_type, &mptr[14], 
                                        sizeof content_type);
index ff340b007909fe5f669d87e608e4030758f76772..c297ac7886c573c167bc182259996a02367f8bcb 100644 (file)
@@ -1386,7 +1386,7 @@ void imap_command_loop(void)
        if (IMAP->authstate == imap_as_expecting_password) {
                lprintf(CTDL_INFO, "IMAP: <password>\n");
        }
-       else if (bmstrstr(cmdbuf, " LOGIN ", strncasecmp)) {
+       else if (strcasestr(cmdbuf, " LOGIN ")) {
                lprintf(CTDL_INFO, "IMAP: LOGIN...\n");
        }
        else {
index 69961493efbbbe85e59e6b0200c928028dabaea8..69cb23d443d2382c015af575854250154f85248f 100644 (file)
@@ -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 <urs@tin.org>
- * Modifications: copyright (c) 2003 by Art Cancro <ajc@uncensored.citadel.org>
- */
-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.
index 32c02f11fdffe9ec68eb7ef3597660da1a767b55..cb63f75bd7febc7c3782c5ee4ae10b5d8f57941b 100644 (file)
@@ -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);
index b506bd9ff39995709f7eaf91014383235381dc25..abb388924a2fbafbf9e38714b8a590d4ec3c959b 100644 (file)
@@ -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;
        }