summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/proto.h1
-rw-r--r--mbbsd/bbs.c22
-rw-r--r--mbbsd/record.c67
3 files changed, 53 insertions, 37 deletions
diff --git a/include/proto.h b/include/proto.h
index e26d806d..b2dff6bc 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -525,6 +525,7 @@ int search_rec(const char* dirname, int (*filecheck)());
int append_record_forward(char *fpath, fileheader_t *record, int size, const char *origid);
int get_sum_records(const char* fpath, int size);
int substitute_ref_record(const char* direct, fileheader_t *fhdr, int ent);
+inline
int getindex(const char *fpath, fileheader_t *fh, int start);
/* register */
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 4dbae34b..a5d72bd5 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -545,10 +545,11 @@ cancelpost(const fileheader_t *fh, int by_BM, char *newpath)
}
static void
-do_deleteCrossPost(fileheader_t *fh, char bname[])
+do_deleteCrossPost(const fileheader_t *fh, char bname[])
{
char bdir[MAXPATHLEN]="", file[MAXPATHLEN]="";
- if(!bname) return;
+ fileheader_t newfh;
+ if(!bname || !fh) return;
int i, bid = getbnum(bname);
if(bid <=0 || !fh->filename[0]) return;
@@ -558,11 +559,14 @@ do_deleteCrossPost(fileheader_t *fh, char bname[])
setbdir(bdir, bname);
setbfile(file, bname, fh->filename);
- if( (i=getindex(bdir, fh, 0))>0)
+ memcpy(&newfh, fh, sizeof(fileheader_t));
+ // Ptt: protect original fh
+ // because getindex safe_article_delete will change fh in some case
+ if( (i=getindex(bdir, &newfh, 0))>0)
{
#ifdef SAFE_ARTICLE_DELETE
if(bp && !(currmode & MODE_DIGEST) && bp->nuser > 30 )
- safe_article_delete(i, fh, bdir);
+ safe_article_delete(i, &newfh, bdir);
else
#endif
delete_record(bdir, sizeof(fileheader_t), i);
@@ -572,17 +576,21 @@ do_deleteCrossPost(fileheader_t *fh, char bname[])
}
static void
-deleteCrossPost(fileheader_t *fh, char *bname)
+deleteCrossPost(const fileheader_t *fh, char *bname)
{
if(!fh || !fh->filename[0]) return;
if(!strcmp(bname, ALLPOST) || !strcmp(bname, "NEWIDPOST") ||
!strcmp(bname, ALLHIDPOST) || !strcmp(bname, "UnAnonymous"))
{
+ int len=0;
char xbname[TTLEN + 1], *po = strrchr(fh->title, '.');
if(!po) return;
-
- sprintf(xbname, "%.*s", (int) strlen(po)-3, po+1);
+ po++;
+ len = (int) strlen(po)-2;
+
+ if(len > TTLEN) return;
+ sprintf(xbname, "%.*s", len, po);
do_deleteCrossPost(fh, xbname);
}
else
diff --git a/mbbsd/record.c b/mbbsd/record.c
index 7a2fc429..c58b7ecc 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -132,41 +132,13 @@ substitute_record(const char *fpath, const void *rptr, int size, int id)
return 0;
}
-int
-substitute_ref_record(const char *direct, fileheader_t * fhdr, int ent)
-{
- fileheader_t hdr;
- char fname[PATHLEN];
- int num = 0;
-
- /* rocker.011018: 串接模式用reference增進效率 */
- if (!(fhdr->filemode & FILE_BOTTOM) && (fhdr->multi.refer.flag) &&
- (num = fhdr->multi.refer.ref)){
- setdirpath(fname, direct, ".DIR");
- get_record(fname, &hdr, sizeof(hdr), num);
- if (strcmp(hdr.filename, fhdr->filename)) {
- if((num = getindex(fname, fhdr, num))>0) {
- substitute_record(fname, fhdr, sizeof(*fhdr), num);
- }
- }
- else if(num>0) {
- fhdr->multi.money = hdr.multi.money;
- substitute_record(fname, fhdr, sizeof(*fhdr), num);
- }
- fhdr->multi.refer.flag = 1;
- fhdr->multi.refer.ref = num; // Ptt: update now!
- }
- substitute_record(direct, fhdr, sizeof(*fhdr), ent);
- return num;
-}
-
/* return index>0 if thisstamp==stamp[index],
* return -index<0 if stamp[index-1]<thisstamp<stamp[index+1], XXX thisstamp ?<>? stamp[index]
* or XXX filename[index]=""
* return 0 if error
*/
int
-getindex(const char *direct, fileheader_t *fhdr, int end)
+getindex_m(const char *direct, fileheader_t *fhdr, int end, int isloadmoney)
{ // Ptt: 從前面找很費力 太暴力
int fd = -1, begin = 1, i, s, times, stamp;
fileheader_t fh;
@@ -186,7 +158,8 @@ getindex(const char *direct, fileheader_t *fhdr, int end)
end = i - 1;
else if( s == stamp ){
close(fd);
- fhdr->multi.money = fh.multi.money;
+ if(isloadmoney)
+ fhdr->multi.money = fh.multi.money;
return i;
}
else
@@ -203,6 +176,40 @@ getindex(const char *direct, fileheader_t *fhdr, int end)
return 0;
}
+inline int
+getindex(const char *direct, fileheader_t *fhdr, int end)
+{
+ return getindex_m(direct, fhdr, end, 0);
+}
+
+int
+substitute_ref_record(const char *direct, fileheader_t * fhdr, int ent)
+{
+ fileheader_t hdr;
+ char fname[PATHLEN];
+ int num = 0;
+
+ /* rocker.011018: 串接模式用reference增進效率 */
+ if (!(fhdr->filemode & FILE_BOTTOM) && (fhdr->multi.refer.flag) &&
+ (num = fhdr->multi.refer.ref)){
+ setdirpath(fname, direct, ".DIR");
+ get_record(fname, &hdr, sizeof(hdr), num);
+ if (strcmp(hdr.filename, fhdr->filename)) {
+ if((num = getindex_m(fname, fhdr, num, 1))>0) {
+ substitute_record(fname, fhdr, sizeof(*fhdr), num);
+ }
+ }
+ else if(num>0) {
+ fhdr->multi.money = hdr.multi.money;
+ substitute_record(fname, fhdr, sizeof(*fhdr), num);
+ }
+ fhdr->multi.refer.flag = 1;
+ fhdr->multi.refer.ref = num; // Ptt: update now!
+ }
+ substitute_record(direct, fhdr, sizeof(*fhdr), ent);
+ return num;
+}
+
/* rocker.011022: 避免lock檔開啟時不正常斷線,造成永久lock */
#ifndef _BBS_UTIL_C_