From baa910a873b24bd5835a59bc41da2470b0af6a36 Mon Sep 17 00:00:00 2001 From: piaip Date: Thu, 7 Aug 2014 11:39:10 +0000 Subject: Fix offset-by-one and add GetContent request type. git-svn-id: http://opensvn.csie.org/pttbbs/trunk@6041 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/daemon/postd/postd.py | 5 +++++ pttbbs/daemon/postd/rebuild.c | 2 +- pttbbs/include/daemons.h | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pttbbs/daemon/postd/postd.py b/pttbbs/daemon/postd/postd.py index 56eedc9f..911ceaa6 100755 --- a/pttbbs/daemon/postd/postd.py +++ b/pttbbs/daemon/postd/postd.py @@ -102,6 +102,11 @@ def SavePost2(content, keypak, data, extra=None): logging.error('%s/%s: save time (%d bytes): %.3fs.', keypak.board, keypak.file, content_length, exec_time) +def GetPostContent(keypak): + logging.debug("GetPostContent: %r", keypak) + key = '%s/%s:content' % (keypak.board, keypak.file) + return g_db.get(key) or '' + def open_database(db_path): global g_db diff --git a/pttbbs/daemon/postd/rebuild.c b/pttbbs/daemon/postd/rebuild.c index f336a78e..cf6c73fd 100644 --- a/pttbbs/daemon/postd/rebuild.c +++ b/pttbbs/daemon/postd/rebuild.c @@ -136,8 +136,8 @@ char *ProcessPost(const char *filename) { fseek(fp, offBegin, SEEK_SET); content = malloc(offEnd - offBegin + 1); assert(content); + fread(content, 1, offEnd - offBegin, fp); content[offEnd - offBegin] = 0; - fread(content, 1, offEnd - offBegin + 1, fp); // Try to parse comments fseek(fp, offEnd, SEEK_SET); diff --git a/pttbbs/include/daemons.h b/pttbbs/include/daemons.h index 1066e602..b7f18b1a 100644 --- a/pttbbs/include/daemons.h +++ b/pttbbs/include/daemons.h @@ -210,6 +210,12 @@ typedef struct { PostKeyReq key; } PACKSTRUCT PostAddRequest; +typedef struct { + short cb; + short operation; + PostKeyReq key; +} PACKSTRUCT PostGetContentRequest; + /////////////////////////////////////////////////////////////////////// // online friend relation daemon // -- cgit v1.2.3