diff options
author | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2011-06-26 13:39:16 +0800 |
---|---|---|
committer | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2011-06-26 13:39:16 +0800 |
commit | 0a439bdd0fbd3ea69c92da0e10c4ac1413f33681 (patch) | |
tree | 124b56fa3d50569ec200864b5e0e18b5e098a27b | |
parent | f41c5e014e4c1eac55a60c05adb990ab75eab41b (diff) | |
download | pttbbs-0a439bdd0fbd3ea69c92da0e10c4ac1413f33681.tar pttbbs-0a439bdd0fbd3ea69c92da0e10c4ac1413f33681.tar.gz pttbbs-0a439bdd0fbd3ea69c92da0e10c4ac1413f33681.tar.bz2 pttbbs-0a439bdd0fbd3ea69c92da0e10c4ac1413f33681.tar.lz pttbbs-0a439bdd0fbd3ea69c92da0e10c4ac1413f33681.tar.xz pttbbs-0a439bdd0fbd3ea69c92da0e10c4ac1413f33681.tar.zst pttbbs-0a439bdd0fbd3ea69c92da0e10c4ac1413f33681.zip |
Add article content support
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5366 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/daemon/boardd/boardd.c | 16 |
1 files changed, 15 insertions, 1 deletions
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 <stdlib.h> #include <string.h> #include <ctype.h> +#include <sys/stat.h> #include <event2/buffer.h> #include <event2/bufferevent.h> @@ -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) { |