summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-04-15 20:05:52 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-04-15 20:05:52 +0800
commit1a77a39f25006a3f73b36365220c3168c59f9fd2 (patch)
tree9c4fc1c9715dfeaad11cb8bcc159b6cf23e9c417
parent5894f7afe1f35469e766a3c3fd6f6b0ee806a31a (diff)
downloadpttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.gz
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.bz2
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.lz
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.xz
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.zst
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.zip
MDCACHE
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@103 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/proto.h4
-rw-r--r--include/pttstruct.h5
-rw-r--r--mbbsd/cache.c46
-rw-r--r--mbbsd/edit.c6
-rw-r--r--mbbsd/more.c21
5 files changed, 74 insertions, 8 deletions
diff --git a/include/proto.h b/include/proto.h
index 8604aab5..f5ceeb6e 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -1,4 +1,4 @@
-/* $Id: proto.h,v 1.4 2002/03/14 08:17:43 in2 Exp $ */
+/* $Id: proto.h,v 1.5 2002/04/15 12:05:49 in2 Exp $ */
#ifndef INCLUDE_PROTO_H
#define INCLUDE_PROTO_H
@@ -108,6 +108,8 @@ userinfo_t *search_ulist_pid(int pid);
int moneyof(int uid);
void hbflreload(int bid);
int hbflcheck(int bid, int uid);
+char *cachepath(const char *fpath);
+int updatemdcache(const char *cpath, const char *fpath);
/* cal */
int vice(int money, char* item);
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 1b1dc44e..a88bafab 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -1,4 +1,4 @@
-/* $Id: pttstruct.h,v 1.6 2002/04/04 18:02:24 ptt Exp $ */
+/* $Id: pttstruct.h,v 1.7 2002/04/15 12:05:50 in2 Exp $ */
#ifndef INCLUDE_STRUCT_H
#define INCLUDE_STRUCT_H
@@ -333,6 +333,9 @@ struct pttcache_t {
time_t uptime;
time_t touchtime;
int busystate;
+
+ int GLOBE[10]; /* mbbsd間的 globe var
+ 用以做統計等資料 */
};
typedef struct fromcache_t {
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index daef6628..8fceef65 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -1,4 +1,4 @@
-/* $Id: cache.c,v 1.8 2002/04/09 20:33:52 in2 Exp $ */
+/* $Id: cache.c,v 1.9 2002/04/15 12:05:52 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -826,7 +826,8 @@ int haspostperm(char *bname) {
/* cachefor 動態看版 */
struct pttcache_t *ptt;
-static void reload_pttcache() {
+static void reload_pttcache()
+{
if(ptt->busystate)
safe_sleep(1);
else { /* jochang: temporary workaround */
@@ -895,11 +896,13 @@ static void reload_pttcache() {
}
}
+int *GLOBE;
void resolve_garbage() {
int count=0;
if(ptt == NULL) {
ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt));
+ GLOBE = ptt->GLOBE;
if(ptt->touchtime == 0)
ptt->touchtime = 1;
}
@@ -1021,3 +1024,42 @@ int hbflcheck(int bid, int uid)
}
return 1;
}
+
+#ifdef MDCACHE
+char *cachepath(const char *fpath)
+{
+ static char cpath[128];
+ char *ptr;
+ snprintf(cpath, sizeof(cpath), "cache/%s", fpath);
+ for( ptr = &cpath[6] ; *ptr != 0 ; ++ptr )
+ if( *ptr == '/' )
+ *ptr = '.';
+ return cpath;
+}
+
+int updatemdcache(const char *CPATH, const char *fpath)
+{
+ /* save file to mdcache with *cpath and *fpath,
+ return: -1 if error
+ else the fd
+ */
+ int len, sourcefd, targetfd;
+ char buf[1024], *cpath;
+ cpath = (CPATH == NULL) ? cachepath(fpath) : CPATH;
+ if( (sourcefd = open(fpath, O_RDONLY)) < 0 )
+ return -1;
+ if( (targetfd = open(cpath, O_RDWR | O_CREAT, 0600)) < 0 )
+ /* md is full? */
+ return -1;
+ while( (len = read(sourcefd, buf, sizeof(buf))) > 0 )
+ if( write(targetfd, buf, len) < len ){
+ /* md is full? */
+ close(targetfd);
+ unlink(cpath);
+ return sourcefd;
+ }
+ close(sourcefd);
+ lseek(targetfd, 0, SEEK_SET);
+ return targetfd;
+}
+#endif
diff --git a/mbbsd/edit.c b/mbbsd/edit.c
index 19f437af..0c722105 100644
--- a/mbbsd/edit.c
+++ b/mbbsd/edit.c
@@ -1,4 +1,4 @@
-/* $Id: edit.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */
+/* $Id: edit.c,v 1.2 2002/04/15 12:05:52 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -1014,6 +1014,10 @@ write_file(char *fpath, int saveheader, int *islocal) {
}
fclose(fp);
+
+#ifdef MDCACHE
+ updatemdcache(NULL, fpath);
+#endif
if(local_article && (currstat == POSTING))
return 0;
return 0;
diff --git a/mbbsd/more.c b/mbbsd/more.c
index f7755874..a65c1ee5 100644
--- a/mbbsd/more.c
+++ b/mbbsd/more.c
@@ -1,4 +1,4 @@
-/* $Id: more.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */
+/* $Id: more.c,v 1.2 2002/04/15 12:05:52 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -193,7 +193,7 @@ static int readln(FILE *fp, char *buf) {
extern userec_t cuser;
static int more_web(char *fpath, int promptend);
-
+extern int *GLOBE;
int more(char *fpath, int promptend) {
extern char* strcasestr();
static char *head[4] = {"作者", "標題", "時間" ,"轉信"};
@@ -232,8 +232,23 @@ int more(char *fpath, int promptend) {
search_char0 = *search_str;
*search_str = 0;
-
+#ifdef MDCACHE
+ if( strncmp(fpath, "boards/", 7) == 0 || strncmp(fpath, "etc/", 4) == 0 ){
+ /* we only cache boards/ and etc/ */
+ char *cpath = cachepath(fpath);
+ ++GLOBE[0];
+ if( (fd = open(cpath, O_RDONLY)) < 0 ){
+ if( (fd = updatemdcache(cpath, fpath)) < 0 )
+ return -1;
+ }
+ else
+ ++GLOBE[1];
+ }
+ else
+ fd = open (fpath, O_RDONLY, 0600);
+#else
fd = open (fpath, O_RDONLY, 0600);
+#endif
if (fd < 0) return -1;
if(fstat(fd, &st) || ((fsize = st.st_size) <= 0) || S_ISDIR (st.st_mode))