diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-04-03 14:32:36 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-04-03 14:32:36 +0800 |
commit | f01c33f6bffec99c474f109a31c8481012a83075 (patch) | |
tree | feb254dc325224cdbf9ee40c6494d1e7ce334ee8 | |
parent | b25a423c98a1ef5763b9810d554417546214417d (diff) | |
download | pttbbs-f01c33f6bffec99c474f109a31c8481012a83075.tar pttbbs-f01c33f6bffec99c474f109a31c8481012a83075.tar.gz pttbbs-f01c33f6bffec99c474f109a31c8481012a83075.tar.bz2 pttbbs-f01c33f6bffec99c474f109a31c8481012a83075.tar.lz pttbbs-f01c33f6bffec99c474f109a31c8481012a83075.tar.xz pttbbs-f01c33f6bffec99c474f109a31c8481012a83075.tar.zst pttbbs-f01c33f6bffec99c474f109a31c8481012a83075.zip |
- (internal) change mail/log to specific API.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4070 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | common/sys/file.c | 14 | ||||
-rw-r--r-- | common/sys/log.c | 2 | ||||
-rw-r--r-- | include/cmsys.h | 3 | ||||
-rw-r--r-- | include/proto.h | 3 | ||||
-rw-r--r-- | mbbsd/chat.c | 19 | ||||
-rw-r--r-- | mbbsd/mail.c | 49 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 14 | ||||
-rw-r--r-- | mbbsd/talk.c | 40 |
8 files changed, 90 insertions, 54 deletions
diff --git a/common/sys/file.c b/common/sys/file.c index 48b7fceb..9e993905 100644 --- a/common/sys/file.c +++ b/common/sys/file.c @@ -301,6 +301,20 @@ Link(const char *src, const char *dst) return Copy(src, dst); } +/** + * @param src file + * @param dst file + * @return 0 if success + */ +int +HardLink(const char *src, const char *dst) +{ + if (link(src, dst) == 0) + return 0; + + return Copy(src, dst); +} + /* ----------------------------------------------------- */ /* 檔案內容處理函數:以「行」為單位 */ /* ----------------------------------------------------- */ diff --git a/common/sys/log.c b/common/sys/log.c index 7923caca..bfaf2e13 100644 --- a/common/sys/log.c +++ b/common/sys/log.c @@ -9,7 +9,7 @@ int log_filef(const char *fn, int log_flag, const char *fmt,...) { - char msg[256]; + char msg[512]; va_list ap; va_start(ap, fmt); diff --git a/include/cmsys.h b/include/cmsys.h index 42b0d032..7300183e 100644 --- a/include/cmsys.h +++ b/include/cmsys.h @@ -35,7 +35,7 @@ typedef time_t time4_t; char *fcrypt(const char *key, const char *salt); /* file.c */ -extern off_t dashs(const char *fname); +extern off_t dashs(const char *fname); extern time4_t dasht(const char *fname); extern time4_t dashc(const char *fname); extern int dashl(const char *fname); @@ -50,6 +50,7 @@ extern int Copy(const char *src, const char *dst); extern int CopyN(const char *src, const char *dst, int n); extern int AppendTail(const char *src, const char *dst, int off); extern int Link(const char *src, const char *dst); +extern int HardLink(const char *src, const char *dst); extern int file_count_line(const char *file); extern int file_append_line(const char *file, const char *string); // does not append "\n" extern int file_append_record(const char *file, const char *key); // will append "\n" diff --git a/include/proto.h b/include/proto.h index dabdbc18..b51e0147 100644 --- a/include/proto.h +++ b/include/proto.h @@ -357,6 +357,7 @@ int x_love(void); int load_mailalert(const char *userid); int sendalert(const char *userid, int alert); int mail_muser(const userec_t muser, const char *title, const char *filename); +int mail_log2id(const char *id, const char *title, const char *srcfile, const char *owner, char newmail, char trymove); int mail_id(const char* id, const char *title, const char *filename, const char *owner); int m_read(void); int doforward(const char *direct, const fileheader_t *fh, int mode); @@ -528,6 +529,7 @@ int setupnewuser(const userec_t *user); int regform_estimate_queuesize(); void new_register(void); void check_register(void); +// void check_register_notify(void); void delregcodefile(void); char *genpasswd(char *pw); @@ -776,6 +778,7 @@ int passwd_update_money(int num); void passwd_force_update(int flag); int initcuser(const char *userid); int freecuser(void); +int passwd_add_my_numpost(int diff); // temporary hack before new account system ready. /* calendar */ 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); @@ -118,17 +117,51 @@ mail_muser(userec_t muser, const char *title, const char *filename) } 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; } |