summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-02-04 21:12:42 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-02-04 21:12:42 +0800
commitc2f38e91d221f96b7877c95becd9c5fbccbde03f (patch)
treeecd328d9f07ab6d7aeb86a0804c532490a30d957 /mbbsd
parent3dd3ec79c7807da0c31411b6981fda8c23d77dab (diff)
downloadpttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar
pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar.gz
pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar.bz2
pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar.lz
pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar.xz
pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar.zst
pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.zip
- emaildb: use fork to reduce memory wasting
- user: add more emaildb check git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3900 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/emaildb.c54
-rw-r--r--mbbsd/user.c23
2 files changed, 66 insertions, 11 deletions
diff --git a/mbbsd/emaildb.c b/mbbsd/emaildb.c
index f60d85e8..fa057102 100644
--- a/mbbsd/emaildb.c
+++ b/mbbsd/emaildb.c
@@ -4,9 +4,8 @@
#define EMAILDB_PATH BBSHOME "/emaildb.db"
-#if defined(__GLIBC__)
-void __libc_freeres();
-#endif
+// define FORK model to minimize memory usage.
+#define FORK_MODEL
static int emaildb_open(sqlite3 **Db) {
int rc;
@@ -26,9 +25,27 @@ static int emaildb_open(sqlite3 **Db) {
int emaildb_check_email(char * email, int email_len)
{
int count = -1;
+ pid_t pid = -1;
sqlite3 *Db = NULL;
sqlite3_stmt *Stmt = NULL;
+#ifdef FORK_MODEL
+ switch((pid = fork()))
+ {
+ case -1: // error
+ break;
+
+ case 0: // child
+ break;
+
+ default:
+ waitpid(pid, &count, 0);
+ count = WEXITSTATUS(count);
+ // vmsgf(ANSI_RESET "found %d emails", count);
+ return count;
+ }
+#endif
+
if (emaildb_open(&Db) != SQLITE_OK)
goto end;
@@ -68,6 +85,9 @@ end:
if (Db != NULL)
sqlite3_close(Db);
+ if (pid == 0)
+ exit(count);
+
return count;
}
#endif
@@ -75,6 +95,24 @@ end:
int emaildb_update_email(char * userid, int userid_len, char * email, int email_len)
{
int ret = -1;
+ pid_t pid = -1;
+
+#ifdef FORK_MODEL
+ switch((pid = fork()))
+ {
+ case -1: // error
+ break;
+
+ case 0: // child
+ break;
+
+ default:
+ waitpid(pid, &ret, 0);
+ ret = WEXITSTATUS(ret);
+ return ret;
+ }
+#endif
+
sqlite3 *Db = NULL;
sqlite3_stmt *Stmt = NULL;
@@ -100,10 +138,8 @@ end:
if (Db != NULL)
sqlite3_close(Db);
-#if defined(__GLIBC__)
- // seems like causing SEGV on localtime()?
- // __libc_freeres(); // discovered by wens, to reduce internal cache caused by sqlite.
-#endif
+ if (pid == 0)
+ exit(ret);
return ret;
}
@@ -200,10 +236,6 @@ int main()
if (Db != NULL)
sqlite3_close(Db);
-#if defined(__GLIBC__)
- __libc_freeres(); // discovered by wens, to reduce internal cache caused by sqlite.
-#endif
-
close(fd);
return 0;
}
diff --git a/mbbsd/user.c b/mbbsd/user.c
index 09fa58e3..d57b6ba3 100644
--- a/mbbsd/user.c
+++ b/mbbsd/user.c
@@ -700,11 +700,34 @@ uinfo_query(userec_t *u, int adminmode, int unum)
do {
getdata_str(y, 0, "電子信箱 [變動要重新認證]:", buf,
sizeof(x.email), DOECHO, x.email);
+ // TODO 這裡也要 emaildb_check
+#ifdef USE_EMAILDB
+ if (isvalidemail(buf))
+ {
+ int email_count = emaildb_check_email(buf, strlen(buf));
+ if (email_count < 0)
+ vmsg("暫時不允許\ email 認證, 請稍後再試");
+ else if (email_count >= EMAILDB_LIMIT)
+ vmsg("指定的 E-Mail 已註冊過多帳號, 請使用其他 E-Mail");
+ else // valid
+ break;
+ }
+ continue;
+#endif
} while (!isvalidemail(buf) && vmsg("認證信箱不能用使用免費信箱"));
y++;
// admins may want to use special names
if (strcmp(buf, x.email) &&
(strchr(buf, '@') || adminmode)) {
+
+ // TODO 這裡也要 emaildb_check
+#ifdef USE_EMAILDB
+ if (emaildb_update_email(cuser.userid, strlen(cuser.userid),
+ buf, strlen(buf)) < 0) {
+ vmsg("暫時不允許\ email 認證, 請稍後再試");
+ break;
+ }
+#endif
strlcpy(x.email, buf, sizeof(x.email));
mail_changed = 1;
delregcodefile();