]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/nntp/serv_nntp.c
Set up per-session NNTP state structure, alloc and free
[citadel.git] / citadel / modules / nntp / serv_nntp.c
index 495771d59c797d14d5731e2d551c58f3fd257194..1978c269ad85146ec9289551ecfe7b6dde4fa51d 100644 (file)
@@ -185,9 +185,9 @@ void nntp_greeting(void)
        strcpy(CC->cs_clientname, "NNTP session");
        CC->cs_flags |= CS_STEALTH;
 
-       /* CC->session_specific_data = malloc(sizeof(citnntp));
-       memset(NNTP, 0, sizeof(citnntp));
-       */
+       CC->session_specific_data = malloc(sizeof(citnntp));
+       citnntp *nntpstate = (citnntp *) CC->session_specific_data;
+       memset(nntpstate, 0, sizeof(citnntp));
 
        if (CC->nologin==1) {
                cprintf("451 Too many connections are already open; please try again later.\r\n");
@@ -761,6 +761,7 @@ void nntp_article(const char *cmd) {
 
        // 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.
+       char *fetched_message_id = NULL;
        CC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
        int fetch = CtdlOutputMsg(requested_msgnum,
                        MT_RFC822,              // output in RFC822 format ... sort of
@@ -770,7 +771,8 @@ void nntp_article(const char *cmd) {
                        NULL,                   // teh whole thing, not just a section
                        0,                      // no flags yet ... maybe new ones for Path: etc ?
                        NULL,
-                       NULL
+                       NULL,
+                       &fetched_message_id     // extract the message ID from the message as we go...
        );
        StrBuf *msgtext = CC->redirect_buffer;
        CC->redirect_buffer = NULL;
@@ -782,16 +784,16 @@ void nntp_article(const char *cmd) {
        }
 
        if (acmd == ARTICLE) {
-               cprintf("220 %ld <FIXME@FIXME>\r\n", requested_msgnum);
+               cprintf("220 %ld <%s>\r\n", requested_msgnum, fetched_message_id);
        }
        if (acmd == HEAD) {
-               cprintf("221 %ld <FIXME@FIXME>\r\n", requested_msgnum);
+               cprintf("221 %ld <%s>\r\n", requested_msgnum, fetched_message_id);
        }
        if (acmd == BODY) {
-               cprintf("222 %ld <FIXME@FIXME>\r\n", requested_msgnum);
+               cprintf("222 %ld <%s>\r\n", requested_msgnum, fetched_message_id);
        }
        if (acmd == STAT) {
-               cprintf("223 %ld <FIXME@FIXME>\r\n", requested_msgnum);
+               cprintf("223 %ld <%s>\r\n", requested_msgnum, fetched_message_id);
                FreeStrBuf(&msgtext);
                return;
        }
@@ -799,6 +801,7 @@ void nntp_article(const char *cmd) {
        client_write(SKEY(msgtext));
        cprintf(".\r\n");                       // this protocol uses a dot terminator
        FreeStrBuf(&msgtext);
+       if (fetched_message_id) free(fetched_message_id);
 }
 
 
@@ -894,6 +897,11 @@ void nntp_cleanup_function(void)
        if (CC->h_command_function != nntp_command_loop) return;
 
        syslog(LOG_DEBUG, "Performing NNTP cleanup hook\n");
+       citnntp *nntpstate = (citnntp *) CC->session_specific_data;
+       if (nntpstate != NULL) {
+               free(nntpstate);
+               nntpstate = NULL;
+       }
 }
 
 const char *CitadelServiceNNTP="NNTP";