summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2014-05-21 20:49:39 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2014-05-21 20:49:39 +0800
commitae4c306acdff72da05e706829e022dc0d8c3ba39 (patch)
treea9e2b6e62c431a0c77617fe17eecab3b221caa5d
parentf507182108f70c6049ff238a4188f2b0f86e601b (diff)
downloadpttbbs-ae4c306acdff72da05e706829e022dc0d8c3ba39.tar
pttbbs-ae4c306acdff72da05e706829e022dc0d8c3ba39.tar.gz
pttbbs-ae4c306acdff72da05e706829e022dc0d8c3ba39.tar.bz2
pttbbs-ae4c306acdff72da05e706829e022dc0d8c3ba39.tar.lz
pttbbs-ae4c306acdff72da05e706829e022dc0d8c3ba39.tar.xz
pttbbs-ae4c306acdff72da05e706829e022dc0d8c3ba39.tar.zst
pttbbs-ae4c306acdff72da05e706829e022dc0d8c3ba39.zip
Commentd: Add "delete" API.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@6001 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rwxr-xr-xpttbbs/daemon/commentd/commentd.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/pttbbs/daemon/commentd/commentd.py b/pttbbs/daemon/commentd/commentd.py
index 262655a4..4084504d 100755
--- a/pttbbs/daemon/commentd/commentd.py
+++ b/pttbbs/daemon/commentd/commentd.py
@@ -30,6 +30,7 @@ Query = collections.namedtuple('Query', 'start board file')
REQ_ADD = 1
REQ_QUERY_COUNT = 2
REQ_QUERY_BODY = 3
+REQ_MARK_DELETE = 4
REQ_LIST = 0x204c # ' L' for console debug.
_SERVER_ADDR = '127.0.0.1'
_SERVER_PORT = 5134
@@ -78,6 +79,23 @@ def LoadCommentCount(query):
logging.debug('LoadCommentCount: key: %s, value: %r', key, g_db.get(key))
return num
+def MarkCommentDeleted(query):
+ logging.debug("MarkCommentDeleted: %r", query)
+ key = '%s/%s' % (query.board, query.file)
+ num = int(g_db.get(key) or '0')
+ if query.start >= num:
+ return -1
+ key += '#%08d' % (query.start + 1)
+ data = g_db.get(key)
+ comment = UnpackComment(data)
+ if comment.type & 0x80000000:
+ return -2
+ # Comment is a named tuple, sorry. We have to reconstruct one.
+ comment = comment._replace(type = (comment.type | 0x80000000))
+ g_db.set(key, PackComment(comment))
+ logging.debug(' Deleted: %s', key)
+ return 0
+
def SaveComment(keypak, comment):
logging.debug("SaveComment: %r => %r", keypak, comment)
key = '%s/%s' % (keypak.board, keypak.file)
@@ -145,6 +163,11 @@ def handle_request(socket, _):
data = PackComment(comment)
fd.write(struct.pack('H', len(data)))
fd.write(data)
+ elif req.operation == REQ_MARK_DELETE:
+ blob = fd.read(struct.calcsize(QueryFormatString))
+ ret = MarkCommentDeleted(UnpackQuery(blob))
+ logging.debug('Marked comment as deleted: %d.', ret)
+ fd.write(struct.pack('i', ret))
elif req.operation == REQ_LIST:
ListComments()
else: