From: Ken Hornstein Date: Wed, 12 Feb 2014 20:41:04 +0000 (-0500) Subject: Move contains8bit() to a common file, and make it a bit more general. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/5c34a38ad47b5bec1535a4c6c3272f8b4b2364bd?hp=3b11b987c2e48062f9db46cf6006faf9b1bbf454 Move contains8bit() to a common file, and make it a bit more general. --- diff --git a/h/utils.h b/h/utils.h index d07e46c1..92c940de 100644 --- 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); diff --git a/sbr/mf.c b/sbr/mf.c index c8868178..d99d2b38 100644 --- 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) { diff --git a/sbr/utils.c b/sbr/utils.c index d8b060fb..99207e32 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -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; +}