diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-09-15 17:00:55 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-09-15 17:00:55 +0800 |
commit | 53923bff58000761fcfa19c346727fb9eb877047 (patch) | |
tree | bbf758258d48059688b74719ab7569bba6519816 /mbbsd | |
parent | 74f24ed0c4f5309d4ff0fb896a168a11c3a6094e (diff) | |
download | pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar.gz pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar.bz2 pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar.lz pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar.xz pttbbs-53923bff58000761fcfa19c346727fb9eb877047.tar.zst pttbbs-53923bff58000761fcfa19c346727fb9eb877047.zip |
real main text editing.
recommendation/comments are not modifiable now.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3172 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/bbs.c | 64 | ||||
-rw-r--r-- | mbbsd/edit.c | 2 | ||||
-rw-r--r-- | mbbsd/kaede.c | 52 |
3 files changed, 104 insertions, 14 deletions
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 37dac779..7f14c9b6 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -795,7 +795,7 @@ do_general(int isbid) pressanykey(); return FULLUPDATE; } - /* set owner to Anonymous , for Anonymous board */ + /* set owner to Anonymous for Anonymous board */ #ifdef HAVE_ANONYMOUS /* Ptt and Jaky */ @@ -823,7 +823,17 @@ do_general(int isbid) postfile.multi.anon_uid = currutmp->uid; } else if(!isbid) - postfile.multi.money = aborted; + { + /* general article */ + struct stat st; + + postfile.multi.money = aborted; + if (stat(fpath, &st) != -1) + { + /* put original file (text) length. */ + postfile.textlen = st.st_size; + } + } strlcpy(postfile.owner, owner, sizeof(postfile.owner)); strlcpy(postfile.title, save_title, sizeof(postfile.title)); @@ -964,7 +974,7 @@ do_post_openbid(void) } static void -do_generalboardreply(const fileheader_t * fhdr) +do_generalboardreply(/*const*/ fileheader_t * fhdr) { char genbuf[3]; @@ -1084,7 +1094,7 @@ b_posttype(int ent, const fileheader_t * fhdr, const char *direct) } static int -do_reply(const fileheader_t * fhdr) +do_reply(/*const*/ fileheader_t * fhdr) { boardheader_t *bp; if (!CheckPostPerm() ) return DONOTHING; @@ -1110,7 +1120,7 @@ do_reply(const fileheader_t * fhdr) } static int -reply_post(int ent, const fileheader_t * fhdr, const char *direct) +reply_post(int ent, /*const*/ fileheader_t * fhdr, const char *direct) { return do_reply(fhdr); } @@ -1123,16 +1133,18 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct) fileheader_t postfile; boardheader_t *bp = getbcache(currbid); struct stat oldstat, newstat; + int isSysop = 0; if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; - if (!HasUserPerm(PERM_SYSOP) && - ((bp->brdattr & BRD_VOTEBOARD) || - (fhdr->filemode & FILE_VOTE) || - !CheckPostPerm() || - strcmp(fhdr->owner, cuser.userid) != 0 || - strcmp(cuser.userid, STR_GUEST) == 0)) + if (HasUserPerm(PERM_SYSOP)) + isSysop = 1; + else if ((bp->brdattr & BRD_VOTEBOARD) || + (fhdr->filemode & FILE_VOTE) || + !CheckPostPerm() || + strcmp(fhdr->owner, cuser.userid) != EQUSTR || + strcmp(cuser.userid, STR_GUEST) == EQUSTR) return DONOTHING; if( currmode & MODE_SELECT ) @@ -1148,7 +1160,15 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct) stampfile(fpath, &postfile); setdirpath(genbuf, direct, fhdr->filename); local_article = fhdr->filemode & FILE_LOCAL; - Copy(genbuf, fpath); + + if(fhdr->textlen <= 0) + Copy(genbuf, fpath); + else + { + /* TODO SYSOP may need some function to edit entire file. */ + CopyN(genbuf, fpath, fhdr->textlen); + } + strlcpy(save_title, fhdr->title, sizeof(save_title)); do { @@ -1158,6 +1178,24 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct) break; stat(genbuf, &newstat); + + /* check textlen */ + if(fhdr->textlen > 0) + { + if(fhdr->textlen != newstat.st_size) + { + /* load and append tail data */ +#ifdef DEBUG + vmsg("textlen != st_size, append tail."); +#endif + if(stat(fpath, &newstat) != -1) + fhdr->textlen = newstat.st_size; + else + fhdr->textlen = 0; + + AppendTail(genbuf, fpath, fhdr->textlen); + } + } else /* old flavor, no textlen info */ if (oldstat.st_mtime != newstat.st_mtime) { if (tolower(getans( @@ -2059,7 +2097,7 @@ recommend(int ent, fileheader_t * fhdr, const char *direct) if ( !CheckPostPerm() || bp->brdattr & BRD_VOTEBOARD || #ifndef GUESTRECOMMEND - strcmp(cuser.userid, STR_GUEST) == STREQU || + strcmp(cuser.userid, STR_GUEST) == EQUSTR || #endif fhdr->filemode & FILE_VOTE) { vmsg("您權限不足, 無法推薦!"); diff --git a/mbbsd/edit.c b/mbbsd/edit.c index aa4aca83..5a38289b 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -1679,7 +1679,9 @@ write_file(char *fpath, int saveheader, int *islocal, char *mytitle) if (islocal) *islocal = local_article; if (currstat == POSTING || currstat == SMAIL) + { addsignature(fp, curr_buf->ifuseanony); + } else if (currstat == REEDIT #ifndef ALL_REEDIT_LOG && strcmp(currboard, str_sysop) == 0 diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c index eef5bb03..150d13f3 100644 --- a/mbbsd/kaede.c +++ b/mbbsd/kaede.c @@ -104,12 +104,62 @@ Copy(const char *src, const char *dst) if(fi<0) return -1; fo=open(dst, O_WRONLY | O_TRUNC | O_CREAT, 0600); if(fo<0) {close(fi); return -1;} - while((bytes=read(fi, buf, 8192))>0) + while((bytes=read(fi, buf, sizeof(buf)))>0) write(fo, buf, bytes); close(fo); close(fi); return 0; } + +int +CopyN(const char *src, const char *dst, int n) +{ + int fi, fo, bytes; + char buf[8192]; + + fi=open(src, O_RDONLY); + if(fi<0) return -1; + + fo=open(dst, O_WRONLY | O_TRUNC | O_CREAT, 0600); + if(fo<0) {close(fi); return -1;} + + while(n > 0 && (bytes=read(fi, buf, sizeof(buf)))>0) + { + n -= bytes; + if (n < 0) + bytes += n; + write(fo, buf, bytes); + } + close(fo); + close(fi); + return 0; +} + +/* append data from tail of src (starting point=off) to dst */ +int +AppendTail(const char *src, const char *dst, int off) +{ + int fi, fo, bytes; + char buf[8192]; + + fi=open(src, O_RDONLY); + if(fi<0) return -1; + + fo=open(dst, O_WRONLY | O_APPEND | O_CREAT, 0600); + if(fo<0) {close(fi); return -1;} + + if(off > 0) + lseek(fi, (off_t)off, SEEK_SET); + + while((bytes=read(fi, buf, sizeof(buf)))>0) + { + write(fo, buf, bytes); + } + close(fo); + close(fi); + return 0; +} + int Link(const char *src, const char *dst) { |