From 1b1142e4431812346c0d49e9581b6c1a964e949d Mon Sep 17 00:00:00 2001 From: kcwu Date: Wed, 10 Jun 2009 16:47:34 +0000 Subject: * add is_valid_brdname() to cmbbs git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4553 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- common/bbs/string.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'common') diff --git a/common/bbs/string.c b/common/bbs/string.c index 60b03b37..22c93abb 100644 --- a/common/bbs/string.c +++ b/common/bbs/string.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "cmbbs.h" void obfuscate_ipstr(char *s) @@ -12,3 +14,30 @@ void obfuscate_ipstr(char *s) *s++ = '*'; *s = 0; } + +bool +is_valid_brdname(const char *brdname) +{ + int i; + char ch; + int len; + + assert(brdname); + + len = strlen(brdname); + if (len < 2 || len > IDLEN) + return false; + + for (i = 0; i < len; i++) { + char ch = brdname[i]; + if (i == 0) { + if (!isalpha((int)ch)) + return false; + } else { + if (!isalnum(ch) && ch != '_' && ch != '-' && ch != '.') + return false; + } + } + return true; +} + -- cgit v1.2.3