diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-06-11 00:47:34 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-06-11 00:47:34 +0800 |
commit | 1b1142e4431812346c0d49e9581b6c1a964e949d (patch) | |
tree | 0bbfd351539dbd6505dcbd8c601adbd3558fbc53 /common | |
parent | cc97eef7be4a7c4beeff5789e00bedbe505a3e85 (diff) | |
download | pttbbs-1b1142e4431812346c0d49e9581b6c1a964e949d.tar pttbbs-1b1142e4431812346c0d49e9581b6c1a964e949d.tar.gz pttbbs-1b1142e4431812346c0d49e9581b6c1a964e949d.tar.bz2 pttbbs-1b1142e4431812346c0d49e9581b6c1a964e949d.tar.lz pttbbs-1b1142e4431812346c0d49e9581b6c1a964e949d.tar.xz pttbbs-1b1142e4431812346c0d49e9581b6c1a964e949d.tar.zst pttbbs-1b1142e4431812346c0d49e9581b6c1a964e949d.zip |
* add is_valid_brdname() to cmbbs
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4553 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'common')
-rw-r--r-- | common/bbs/string.c | 29 |
1 files changed, 29 insertions, 0 deletions
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 <stdio.h> #include <stdlib.h> #include <string.h> +#include <assert.h> +#include <ctype.h> #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; +} + |