From 1b1616ca8b0d20b9454fbc13bdbf5d7bc8f1ee7b Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 15 Mar 2008 03:20:27 +0000 Subject: [PATCH] New utility function convert_spaces_to_underscores() We do this in a couple of different places so it's going into libcitadel. --- citadel/citadel.h | 2 +- citadel/msgbase.c | 6 +----- citadel/user_ops.c | 6 +----- libcitadel/lib/libcitadel.h | 3 ++- libcitadel/lib/tools.c | 26 ++++++++++++++++++++++---- webcit/webcit.h | 2 +- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/citadel/citadel.h b/citadel/citadel.h index 2db49b597..ff2406563 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -50,7 +50,7 @@ extern "C" { #define REV_LEVEL 732 /* This version */ #define REV_MIN 591 /* Oldest compatible database */ #define EXPORT_REV_MIN 725 /* Oldest compatible export files */ -#define LIBCITADEL_MIN 108 /* Minimum required version of libcitadel */ +#define LIBCITADEL_MIN 109 /* Minimum required version of libcitadel */ #define SERVER_TYPE 0 /* zero for stock Citadel; other developers please obtain SERVER_TYPE codes for your implementations */ diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 10ec60887..8f61f3329 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -3010,11 +3010,7 @@ struct CtdlMessage *CtdlMakeMessage( snprintf(buf, sizeof buf, "%s", author->fullname); msg->cm_fields['P'] = strdup(buf); } - for (i=0; (msg->cm_fields['P'][i]!=0); ++i) { - if (isspace(msg->cm_fields['P'][i])) { - msg->cm_fields['P'][i] = '_'; - } - } + convert_spaces_to_underscores(msg->cm_fields['P']); snprintf(buf, sizeof buf, "%ld", (long)time(NULL)); /* timestamp */ msg->cm_fields['T'] = strdup(buf); diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 3fd6b4a85..85f21d695 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -590,11 +590,7 @@ void session_startup(void) */ snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s", CC->user.fullname, config.c_fqdn); - for (i=0; !IsEmptyStr(&CC->cs_inet_email[i]); ++i) { - if (isspace(CC->cs_inet_email[i])) { - CC->cs_inet_email[i] = '_'; - } - } + convert_spaces_to_underscores(CC->cs_inet_email); /* Create any personal rooms required by the system. * (Technically, MAILROOM should be there already, but just in case...) diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 3a9bbbd67..90bbb3530 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -10,7 +10,7 @@ */ #include #include -#define LIBCITADEL_VERSION_NUMBER 108 +#define LIBCITADEL_VERSION_NUMBER 109 /* * Here's a bunch of stupid magic to make the MIME parser portable. @@ -291,3 +291,4 @@ void SortByHashKeyStr(HashList *Hash); const void *GetSearchPayload(const void *HashVoid); void SortByPayload(HashList *Hash, CompareFunc SortBy); +void convert_spaces_to_underscores(char *str); diff --git a/libcitadel/lib/tools.c b/libcitadel/lib/tools.c index c056fe94d..32c96e035 100644 --- a/libcitadel/lib/tools.c +++ b/libcitadel/lib/tools.c @@ -895,10 +895,10 @@ int pattern2(char *search, char *patn) } -/** - * \brief Strip leading and trailing spaces from a string; with premeasured and adjusted length. - * \param buf the string to modify - * \param len length of the string. +/* + * Strip leading and trailing spaces from a string; with premeasured and adjusted length. + * buf - the string to modify + * len - length of the string. */ void stripltlen(char *buf, int *len) { @@ -916,3 +916,21 @@ void stripltlen(char *buf, int *len) } } + +/* + * Convert all whitespace characters in a supplied string to underscores + */ +void convert_spaces_to_underscores(char *str) +{ + int len; + int i; + + if (!str) return; + + len = strlen(str); + for (i=0; i