From f01c33f6bffec99c474f109a31c8481012a83075 Mon Sep 17 00:00:00 2001 From: piaip Date: Thu, 3 Apr 2008 06:32:36 +0000 Subject: - (internal) change mail/log to specific API. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4070 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/chat.c | 19 +++++-------------- mbbsd/mail.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- mbbsd/mbbsd.c | 14 ++++++++------ mbbsd/talk.c | 40 +++++++++++++--------------------------- 4 files changed, 70 insertions(+), 52 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/chat.c b/mbbsd/chat.c index 1bc12472..b205b188 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -578,20 +578,11 @@ t_chat(void) getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M) (C/M)?[C]", ans, sizeof(ans), LCECHO); if (*ans == 'm') { - fileheader_t mymail; - char title[128]; - char genbuf[200]; - - sethomepath(genbuf, cuser.userid); - stampfile(genbuf, &mymail); - mymail.filemode = FILE_READ ; - strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); - strlcpy(mymail.title, "會議" ANSI_COLOR(1;33) "記錄" ANSI_RESET, sizeof(mymail.title)); - sethomedir(title, cuser.userid); - append_record(title, &mymail, sizeof(mymail)); - Rename(fpath, genbuf); - } else - unlink(fpath); + if (mail_log2id(cuser.userid, "會議記錄", + fpath, "[備.忘.錄]", 0, 1) < 0) + vmsg("備忘錄儲存失敗。"); + } + unlink(fpath); } return 0; } diff --git a/mbbsd/mail.c b/mbbsd/mail.c index 64a61ca9..58068c3b 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -26,8 +26,7 @@ setforward(void) int flIdiotSent2Self = 0; int oidlen = strlen(cuser.userid); - sethomepath(buf, cuser.userid); - strlcat(buf, "/.forward", sizeof(buf)); + setuserfile(buf, ".forward"); if ((fp = fopen(buf, "r"))) { fscanf(fp, "%" toSTR(sizeof(ip)) "s", ip); fclose(fp); @@ -117,18 +116,52 @@ mail_muser(userec_t muser, const char *title, const char *filename) return mail_id(muser.userid, title, filename, cuser.userid); } +int +mail_log2id(const char *id, const char *title, const char *src, const char *owner, char newmail, char trymove) +{ + fileheader_t mhdr; + char dst[PATHLEN], dirf[PATHLEN]; + + sethomepath(dst, id); + if (stampfile(dst, &mhdr) < 0) + return -1; + + strlcpy(mhdr.owner, owner, sizeof(mhdr.owner)); + strlcpy(mhdr.title, title, sizeof(mhdr.title)); + mhdr.filemode = newmail ? 0 : FILE_READ; + + // XXX try link first? + //if (HardLink(src, dst) < 0 && Copy(src, dst) < 0) + // return -1; + if (trymove) + { + if (Rename(src, dst) < 0) + return -1; + } else { + if (Copy(src, dst) < 0) + return -1; + } + + sethomedir(dirf, id); + // do not forward. + append_record(dirf, &mhdr, sizeof(mhdr)); + return 0; +} + int mail_id(const char *id, const char *title, const char *src, const char *owner) { fileheader_t mhdr; char dst[PATHLEN], dirf[PATHLEN]; sethomepath(dst, id); - if (stampfile(dst, &mhdr)) - return 0; + if (stampfile(dst, &mhdr) < 0) + return -1; + strlcpy(mhdr.owner, owner, sizeof(mhdr.owner)); strlcpy(mhdr.title, title, sizeof(mhdr.title)); mhdr.filemode = 0; - Copy(src, dst); + if (Copy(src, dst) < 0) + return -1; sethomedir(dirf, id); append_record_forward(dirf, &mhdr, sizeof(mhdr), id); @@ -1788,6 +1821,12 @@ int m_read(void) { int back_bid; + + /* // deprecated because now we kicks online people. + if (HasUserPerm(PERM_BASIC) && !HasUserPerm(PERM_LOGINOK)) + check_register_notify(); + */ + if (get_num_records(currmaildir, sizeof(fileheader_t))) { curredit = EDIT_MAIL; curredit &= ~EDIT_ITEM; diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 23e20f41..d6bcb407 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -181,11 +181,14 @@ u_exit(const char *mode) close(0); close(1); + // verify if utmp is valid. only flush data if utmp is correct. assert(strncmp(currutmp->userid,cuser.userid, IDLEN)==0); if(strncmp(currutmp->userid,cuser.userid, IDLEN)!=0) return; - reload_money(); + auto_backup(); + save_brdbuf(); + brc_finalize(); /* cuser.goodpost = currutmp->goodpost; cuser.badpost = currutmp->badpost; @@ -193,11 +196,11 @@ u_exit(const char *mode) cuser.badsale = currutmp->badsale; */ - auto_backup(); + // no need because in later passwd_update will reload money from SHM. + // reload_money(); + setflags(PAGER_FLAG, currutmp->pager != PAGER_ON); setflags(CLOAK_FLAG, currutmp->invisible); - save_brdbuf(); - brc_finalize(); cuser.invisible = currutmp->invisible; cuser.withme = currutmp->withme; @@ -211,7 +214,6 @@ u_exit(const char *mode) do_aloha("<<下站通知>> -- 我走囉!"); } - if ((cuser.uflag != enter_uflag) || dirty || diff) { if (!diff && cuser.numlogins) cuser.numlogins = --cuser.numlogins; @@ -300,7 +302,7 @@ abort_bbs_debug(int sig) /* log */ /* assume vsnprintf() in log_file() is signal-safe, is it? */ log_filef("log/crash.log", LOG_CREAT, - "%d %d %d %.12s\n", time4(NULL), getpid(), sig, cuser.userid); + "%d %d %d %.12s\n", (int)time4(NULL), getpid(), sig, cuser.userid); /* try logout... not a good idea, maybe crash again. now disabled */ /* diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 013aca6b..aebf3fd4 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -1087,18 +1087,11 @@ t_display(void) getdata(b_lines - 1, 0, "清除(C) 存入信箱(M) 保留(R) (C/M/R)?[R]", ans, sizeof(ans), LCECHO); if (*ans == 'm') { - fileheader_t mymail; - char title[128], buf[80]; - - sethomepath(buf, cuser.userid); - stampfile(buf, &mymail); - - mymail.filemode = FILE_READ ; - strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); - strlcpy(mymail.title, "熱線記錄", sizeof(mymail.title)); - sethomedir(title, cuser.userid); - Rename(genbuf, buf); - append_record(title, &mymail, sizeof(mymail)); + // only delete if success because the file can be re-used. + if (mail_log2id(cuser.userid, "熱線記錄", genbuf, "[備.忘.錄]", 0, 1) == 0) + unlink(genbuf); + else + vmsg("信箱儲存失敗。"); } else if (*ans == 'c') unlink(genbuf); return FULLUPDATE; @@ -1510,21 +1503,14 @@ do_talk(int fd) } if (*ans == 'm') { - fileheader_t mymail; - char title[128]; - - sethomepath(genbuf, cuser.userid); - stampfile(genbuf, &mymail); - mymail.filemode = FILE_READ ; - strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); - snprintf(mymail.title, sizeof(mymail.title), - "對話記錄 " ANSI_COLOR(1;36) "(%s)" ANSI_RESET, - getuserid(currutmp->destuid)); - sethomedir(title, cuser.userid); - Rename(fpath, genbuf); - append_record(title, &mymail, sizeof(mymail)); - } else - unlink(fpath); + char title[STRLEN]; + const char *tuid = NULL; + if (currutmp) tuid = getuserid(currutmp->destuid); + snprintf(title, sizeof(title), "對話記錄 (%s)", tuid ? tuid : "未知"); + if (mail_log2id(cuser.userid, title, fpath, "[備.忘.錄]", 0, 1) < 0) + vmsg("儲存失敗。"); + } + unlink(fpath); flog = 0; } -- cgit v1.2.3