]> diplodocus.org Git - nmh/commitdiff
Move contains8bit() to a common file, and make it a bit more general.
authorKen Hornstein <kenh@pobox.com>
Wed, 12 Feb 2014 20:41:04 +0000 (15:41 -0500)
committerKen Hornstein <kenh@pobox.com>
Wed, 12 Feb 2014 20:41:04 +0000 (15:41 -0500)
h/utils.h
sbr/mf.c
sbr/utils.c

index d07e46c..92c940d 100644 (file)
--- a/h/utils.h
+++ b/h/utils.h
@@ -43,3 +43,16 @@ int open_form(char **, char *);
 char *find_str (const char [], size_t, const char *);
 char *rfind_str (const char [], size_t, const char *);
 char *nmh_strcasestr (const char *, const char *);
+
+/*
+ * See if a string contains 8 bit characters (use isascii() for the test).
+ * Arguments include:
+ *
+ * start       - Pointer to start of string to test.
+ * end         - End of string to test (test will stop before reaching
+ *               this point).  If NULL, continue until reaching '\0'.
+ *
+ * This function always stops at '\0' regardless of the value of 'end'.
+ * Returns 1 if the string contains an 8-bit character, 0 if it does not.
+ */
+int contains8bit(const char *start, const char *end);
index c886817..d99d2b3 100644 (file)
--- a/sbr/mf.c
+++ b/sbr/mf.c
@@ -21,7 +21,6 @@ static int local_part (char *);
 static int domain (char *);
 static int route (char *);
 static int my_lex (char *);
-static int contains8bit (const char *);
 
 
 int
@@ -235,8 +234,8 @@ getadrx (const char *addrs)
      * Reject the address if key fields contain 8bit characters
      */
 
-    if (contains8bit(mbox) || contains8bit(host) || contains8bit(path) ||
-       contains8bit(grp)) {
+    if (contains8bit(mbox, NULL) || contains8bit(host, NULL) ||
+       contains8bit(path, NULL) || contains8bit(grp, NULL)) {
        strcpy(err, "Address contains 8-bit characters");
     }
 
@@ -728,25 +727,6 @@ got_atom: ;
 }
 
 
-/*
- * Return true if the string contains an 8-bit character
- */
-
-static int
-contains8bit(const char *p)
-{
-    if (! p)
-       return 0;
-
-    for (; *p; p++) {
-       if (! isascii((unsigned char) *p))
-           return 1;
-    }
-
-    return 0;
-}
-
-
 char *
 legal_person (const char *p)
 {
index d8b060f..99207e3 100644 (file)
@@ -352,3 +352,20 @@ nmh_init(const char *argv0, int read_context) {
         return status;
     }
 }
+
+/*
+ * Scan for any 8-bit characters.  Return 1 if they exist.
+ *
+ * Scan up until the given endpoint (but not the actual endpoint itself).
+ * If the endpoint is NULL, scan until a '\0' is reached.
+ */
+
+int
+contains8bit(const char *start, const char *end)
+{
+    while (*start != '\0' && (!end || (start < end)))
+       if (! isascii((unsigned char) *start++))
+           return 1;
+
+    return 0;
+}