From 0a439bdd0fbd3ea69c92da0e10c4ac1413f33681 Mon Sep 17 00:00:00 2001 From: wens Date: Sun, 26 Jun 2011 05:39:16 +0000 Subject: Add article content support git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5366 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/daemon/boardd/boardd.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pttbbs/daemon/boardd/boardd.c b/pttbbs/daemon/boardd/boardd.c index 4ff29eb1..6ec09610 100644 --- a/pttbbs/daemon/boardd/boardd.c +++ b/pttbbs/daemon/boardd/boardd.c @@ -9,13 +9,14 @@ // 2. [done] rewrite with libevent 2.0 // 3. [done] split out independent server code // 4. [done] add article list support -// 5. add article content support +// 5. [done] add article content support // 6. encode output in UTF-8 (with UAO support) // 7. encode article list in JSON for better structure #include #include #include +#include #include #include @@ -128,6 +129,19 @@ answer_key(struct evbuffer *buf, const char *key) length = DEFAULT_ARTICLE_LIST; return article_list(buf, bptr, offset, length); + } else if (strncmp(key, "article.", 8) == 0) { + if (strncmp(key + 9, "M.", 2) != 0) + return; + + char path[PATH_MAX]; + struct stat st; + int fd; + + setbfile(path, bptr->brdname, key + 8); + if ((fd = open(path, O_RDONLY)) < 0 || fstat(fd, &st) < 0) + return; + + evbuffer_add_file(buf, fd, 0, st.st_size); } else return; } else if (strncmp(key, "tobid.", 6) == 0) { -- cgit v1.2.3