diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2007-09-23 16:02:39 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2007-09-23 16:02:39 +0800 |
commit | 20150280476994d7f9395a26c8bbb78a72c04918 (patch) | |
tree | 49da89160e95163dbe63970446e0ecf70adc03f3 /mbbsd | |
parent | cae5ea8fa7f94b023e4d4cc8754854ac7ae9c7aa (diff) | |
download | pttbbs-20150280476994d7f9395a26c8bbb78a72c04918.tar pttbbs-20150280476994d7f9395a26c8bbb78a72c04918.tar.gz pttbbs-20150280476994d7f9395a26c8bbb78a72c04918.tar.bz2 pttbbs-20150280476994d7f9395a26c8bbb78a72c04918.tar.lz pttbbs-20150280476994d7f9395a26c8bbb78a72c04918.tar.xz pttbbs-20150280476994d7f9395a26c8bbb78a72c04918.tar.zst pttbbs-20150280476994d7f9395a26c8bbb78a72c04918.zip |
* revise code for entering board.
* fix board permission.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3571 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/bbs.c | 40 | ||||
-rw-r--r-- | mbbsd/board.c | 52 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 6 | ||||
-rw-r--r-- | mbbsd/talk.c | 9 |
4 files changed, 66 insertions, 41 deletions
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 263fe384..5d8b6a82 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -418,13 +418,15 @@ whereami(void) { boardheader_t *bh, *p[WHEREAMI_LEVEL]; int i, j; + int bid = currbid; - if (!currutmp->brc_id) + if (!bid) return 0; move(1, 0); clrtobot(); - bh = getbcache(currutmp->brc_id); + assert(0<=bid-1 && bid-1<MAX_BOARD); + bh = getbcache(bid); p[0] = bh; for (i = 0; i+1 < WHEREAMI_LEVEL && p[i]->parent>1 && p[i]->parent < numboards; i++) p[i + 1] = getbcache(p[i]->parent); @@ -444,37 +446,14 @@ static int do_select(void) { char bname[20]; - char bpath[60]; - boardheader_t *bh; - struct stat st; - int i; setutmpmode(SELECT); move(0, 0); clrtoeol(); CompleteBoard(MSG_SELECT_BOARD, bname); - if (bname[0] == '\0' || !(i = getbnum(bname))) - return FULLUPDATE; - assert(0<=i-1 && i-1<MAX_BOARD); - bh = getbcache(i); - if (!HasBoardPerm(bh)) - return FULLUPDATE; - strlcpy(bname, bh->brdname, sizeof(bname)); - brc_update(); - currbid = i; - setbpath(bpath, bname); - if ((*bname == '\0') || (stat(bpath, &st) == -1)) { - move(2, 0); - clrtoeol(); - outs(err_bid); + if(enter_board(bname) < 0) return FULLUPDATE; - } - setutmpbid(currbid); - - brc_initial_board(bname); - set_board(); - setbdir(currdirect, currboard); move(1, 0); clrtoeol(); @@ -3740,11 +3719,11 @@ Read(void) time4_t usetime = now; #endif - if ( !currboard[0] ) - brc_initial_board(DEFAULT_BOARD); + char *bname = currboard[0] ? currboard : DEFAULT_BOARD; + if (enter_board(bname) < 0) + return 0; setutmpmode(READING); - set_board(); if (board_note_time && board_visit_time < *board_note_time) { int mr; @@ -3756,9 +3735,6 @@ Read(void) else if (mr != READ_NEXT) pressanykey(); } - setutmpbid(currbid); - setbdir(buf, currboard); - curredit &= ~EDIT_MAIL; i_read(READING, buf, readtitle, readdoent, read_comms, currbid); currmode &= ~MODE_POSTCHECKED; diff --git a/mbbsd/board.c b/mbbsd/board.c index a7c5e382..bf0993a3 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -63,6 +63,55 @@ inline boardheader_t *getparent(const boardheader_t *fh) return NULL; } +/** + * @param[in] boardname board name, case insensitive + * @return 0 if success + * -1 if not found + * -2 permission denied + * -3 error + * @note enter board: + * 1. setup brc (currbid, currboard, currbrdattr) + * 2. set currbid, currBM, currmode, currdirect + * 3. utmp brc_id + */ +int enter_board(const char *boardname) +{ + boardheader_t *bh; + int bid; + char bname[IDLEN+1]; + char bpath[60]; + struct stat st; + + /* checking ... */ + if (boardname[0] == '\0' || !(bid = getbnum(boardname))) + return -1; + assert(0<=bid-1 && bid-1<MAX_BOARD); + bh = getbcache(bid); + if (!HasBoardPerm(bh)) + return -2; + + strlcpy(bname, bh->brdname, sizeof(bname)); + if (bname[0] == '\0') + return -3; + + setbpath(bpath, bname); + if (stat(bpath, &st) == -1) { + return -3; + } + + /* really enter board */ + brc_update(); + brc_initial_board(bname); + setutmpbid(currbid); + + set_board(); + setbdir(currdirect, currboard); + curredit &= ~EDIT_MAIL; + + return 0; +} + + void imovefav(int old) { char buf[5]; @@ -82,8 +131,7 @@ init_brdbuf(void) { if (brc_initialize()) return; - brc_initial_board(DEFAULT_BOARD); - set_board(); + enter_board(DEFAULT_BOARD); } void diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 61a6a266..8bceabc9 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1005,9 +1005,9 @@ inline static void birthday_make_a_wish(const struct tm *ptime, const struct tm { if (tmp->tm_mday != ptime->tm_mday) { more("etc/birth.post", YEA); - brc_initial_board("WhoAmI"); - set_board(); - do_post(); + if (enter_board("WhoAmI")==0) { + do_post(); + } } } diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 85d1300b..48ad1424 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -3376,14 +3376,15 @@ static inline void GotoNewHand(){ if (currutmp && currutmp->mode != EDITING){ char old_board[IDLEN + 1] = ""; - if (currboard) + if (currboard[0]) strlcpy(old_board, currboard, IDLEN + 1); - brc_initial_board("PttNewHand"); - Read(); + if (enter_board("PttNewHand")==0) { + Read(); + } if (old_board[0]) - brc_initial_board(old_board); + enter_board(old_board); } } |