summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-09-15 17:00:55 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-09-15 17:00:55 +0800
commit53923bff58000761fcfa19c346727fb9eb877047 (patch)
treebbf758258d48059688b74719ab7569bba6519816
parent74f24ed0c4f5309d4ff0fb896a168a11c3a6094e (diff)
downloadpttbbs-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
-rw-r--r--include/common.h2
-rw-r--r--include/fpg.h4
-rw-r--r--include/proto.h2
-rw-r--r--include/pttstruct.h15
-rw-r--r--mbbsd/bbs.c64
-rw-r--r--mbbsd/edit.c2
-rw-r--r--mbbsd/kaede.c52
7 files changed, 118 insertions, 23 deletions
diff --git a/include/common.h b/include/common.h
index e9c5fdec..9e7d7b23 100644
--- a/include/common.h
+++ b/include/common.h
@@ -133,7 +133,7 @@
#define YEA 1 /* Booleans (Yep, for true and false) */
#define NA 0
-#define STREQU 0 /* for strcmp */
+#define EQUSTR 0 /* for strcmp */
/* 好友關係 */
#define IRH 1 /* I reject him. */
diff --git a/include/fpg.h b/include/fpg.h
index 0065cba5..13045dae 100644
--- a/include/fpg.h
+++ b/include/fpg.h
@@ -2,8 +2,8 @@
#define BRC_STRLEN 15 /* Length of boardname */
#define BTLEN 48 /* Length of board title */
#define NAMELEN 40 /* Length of username/realname */
-#define FNLEN 33 /* Length of filename */
- /* XXX Ptt 說這裡有bug*/
+//#define FNLEN 33 /* Length of filename */
+// /* XXX Ptt 說這裡有bug*/
#define IDLEN 12 /* Length of bid/uid */
#define PASSLEN 14 /* Length of encrypted passwd field */
#define REGLEN 38 /* Length of registration data */
diff --git a/include/proto.h b/include/proto.h
index ce0c49f7..d577f36f 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -331,6 +331,8 @@ int ochar(int c);
/* kaede */
int Rename(const char* src, const char* dst);
int Copy(const char *src, const char *dst);
+int CopyN(const char *src, const char *dst, int n);
+int AppendTail(const char *src, const char *dst, int off);
int Link(const char* src, const char* dst);
char *Ptt_prints(char *str, int mode);
char *my_ctime(const time4_t *t, char *ans, int len);
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 52b7881a..096b91da 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -235,24 +235,27 @@ typedef struct boardheader_t {
#define TTLEN 64 /* Length of title */
-#define FNLEN 33 /* Length of filename */
+#define FNLEN 28 /* Length of filename */
typedef struct fileheader_t {
- char filename[FNLEN]; /* M.9876543210.A */
+ char filename[FNLEN]; /* M.1120582370.A.1EA [19+1] */
+ int textlen; /* main text length in post */
+ char pad; /* padding, not used */
char recommend; /* important level */
char owner[IDLEN + 2]; /* uid[.] */
char date[6]; /* [02/02] or space(5) */
char title[TTLEN + 1];
+ /* TODO this multi is a mess now. */
union {
/* TODO: MOVE money to outside multi!!!!!! */
int money;
int anon_uid;
/* different order to match alignment */
struct {
- unsigned char posts; /* money & 0xff */
- unsigned char logins; /* money & 0xff00 */
- unsigned char regtime; /* money & 0xff0000 */
- unsigned char pad[1]; /* money & 0xffff0000 */
+ unsigned char posts;
+ unsigned char logins;
+ unsigned char regtime;
+ unsigned char pad[1];
} vote_limits;
struct {
/* is this ordering correct? */
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)
{