This should be STAT
[citadel.git] / citadel / modules / nntp / serv_nntp.c
index e135aad159c5ff5435446ea4a0d2002c539ea596..495771d59c797d14d5731e2d551c58f3fd257194 100644 (file)
@@ -64,7 +64,7 @@
 
 extern long timezone;
 
-//***************** BEGIN UTILITY FUNCTIONS THAT COULD BE MOVED ELSEWHERE LATER **************/
+//     ***************** BEGIN UTILITY FUNCTIONS THAT COULD BE MOVED ELSEWHERE LATER **************
 
 
 //
@@ -173,7 +173,7 @@ void newsgroup_to_room(char *target, char *source, size_t target_size) {
 }
 
 
-//*****************  END  UTILITY FUNCTIONS THAT COULD BE MOVED ELSEWHERE LATER **************/
+//     *****************  END  UTILITY FUNCTIONS THAT COULD BE MOVED ELSEWHERE LATER **************
 
 
 
@@ -580,10 +580,10 @@ void nntp_listgroup_backend(long msgnum, void *userdata) {
 // Implements the GROUP and LISTGROUP commands
 //
 void nntp_group(const char *cmd) {
-       /*
-        * HACK: this works because the 5XX series error codes from citadel
-        * protocol will also be considered error codes by an NNTP client
-        */
+       //
+       // HACK: this works because the 5XX series error codes from citadel
+       // protocol will also be considered error codes by an NNTP client
+       //
        if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
 
        char verb[16];
@@ -718,6 +718,12 @@ 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;
+       else if (acmd == BODY)  headers_only = HEADERS_NONE;
+       else if (acmd == STAT)  headers_only = HEADERS_FAST;
+
        // now figure out what the client is asking for.
        char requested_article[256];
        long requested_msgnum = 0;
@@ -747,15 +753,52 @@ 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 <FIXME@FIXME>\r\n", requested_msgnum);
+       }
+       if (acmd == HEAD) {
+               cprintf("221 %ld <FIXME@FIXME>\r\n", requested_msgnum);
+       }
+       if (acmd == BODY) {
+               cprintf("222 %ld <FIXME@FIXME>\r\n", requested_msgnum);
+       }
+       if (acmd == STAT) {
+               cprintf("223 %ld <FIXME@FIXME>\r\n", requested_msgnum);
+               FreeStrBuf(&msgtext);
+               return;
+       }
 
-
-       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);
 }
 
 
@@ -777,9 +820,7 @@ void nntp_command_loop(void)
        syslog(LOG_DEBUG, "NNTP: %s\n", ((!strncasecmp(ChrPtr(Cmd), "AUTHINFO", 8)) ? "AUTHINFO ..." : ChrPtr(Cmd)));
        extract_token(cmdname, ChrPtr(Cmd), 0, ' ', sizeof cmdname);
 
-       /*
-        * Rumpelstiltskin lookups are awesome
-        */
+       // Rumpelstiltskin lookups are *awesome*
 
        if (!strcasecmp(cmdname, "quit")) {
                nntp_quit();
@@ -838,9 +879,9 @@ void nntp_command_loop(void)
 }
 
 
-//****************************************************************************/
-//                   MODULE INITIALIZATION STUFF                         */
-//****************************************************************************/
+//     ****************************************************************************
+//                           MODULE INITIALIZATION STUFF
+//     ****************************************************************************
 
 
 //