From 2098650a879880ecc28b4f328dc84a3ee390d629 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 11 Feb 2014 09:54:49 -0500 Subject: [PATCH] More work on ARTICLE/HEAD/BODY/STAT --- citadel/modules/nntp/serv_nntp.c | 45 ++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/citadel/modules/nntp/serv_nntp.c b/citadel/modules/nntp/serv_nntp.c index 6f6f41fa7..0970e68b4 100644 --- a/citadel/modules/nntp/serv_nntp.c +++ b/citadel/modules/nntp/serv_nntp.c @@ -718,6 +718,11 @@ void nntp_article(const char *cmd) { return; } + // Which NNTP command was issued, determines whether we will fetch headers, body, or both. + int headers_only = HEADERS_ALL; + if (acmd == HEAD) headers_only = HEADERS_FAST; + if (acmd == BODY) headers_only = HEADERS_NONE; + // now figure out what the client is asking for. char requested_article[256]; long requested_msgnum = 0; @@ -747,15 +752,51 @@ void nntp_article(const char *cmd) { } // Anything else is noncompliant gobbledygook and should die in a car fire. + // Also, the weasel who is spreading untrue rumors about me at work should die in a slow and painful car fire. else { cprintf("500 syntax error\r\n"); return; } + // At this point we know the message number of the "article" being requested. + // We have an awesome API call that does all the heavy lifting for us. + CC->redirect_buffer = NewStrBufPlain(NULL, SIZ); + int fetch = CtdlOutputMsg(requested_msgnum, + MT_RFC822, // output in RFC822 format ... sort of + headers_only, // headers, body, or both? + 0, // don't do Citadel protocol responses + 1, // CRLF newlines + NULL, // teh whole thing, not just a section + 0, // no flags yet ... maybe new ones for Path: etc ? + NULL, + NULL + ); + StrBuf *msgtext = CC->redirect_buffer; + CC->redirect_buffer = NULL; + + if (fetch != om_ok) { + cprintf("423 no article with that number\r\n"); + FreeStrBuf(&msgtext); + return; + } + if (acmd == ARTICLE) { + cprintf("220 %ld \r\n", requested_msgnum); + } + if (acmd == HEAD) { + cprintf("221 %ld \r\n", requested_msgnum); + } + if (acmd == BODY) { + cprintf("222 %ld \r\n", requested_msgnum); + } + if (acmd == STAT) { + // crash FIXME + cprintf("223 %ld \r\n", requested_msgnum); + } - - cprintf("500 FIXME write the rest of cmd=%d msgnum=%ld\r\n", acmd, requested_msgnum); + client_write(SKEY(msgtext)); + cprintf(".\r\n"); // this protocol uses a dot terminator + FreeStrBuf(&msgtext); } -- 2.30.2