]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/nntp/serv_nntp.c
Writing some cool code instead of thinking about BJG and LJG.
[citadel.git] / citadel / modules / nntp / serv_nntp.c
index 8b86178270ff7ece54f7d253271b33ef31b8ee7b..2d1a2c52e75fea6ab815678ebe926b272c0b7e3a 100644 (file)
@@ -429,13 +429,8 @@ void nntp_newgroups_backend(struct ctdlroom *qrbuf, void *data)
 // Implements the NEWGROUPS command
 //
 void nntp_newgroups(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
-        */
        if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
 
-
        char stringy_date[16];
        char stringy_time[16];
        char stringy_gmt[16];
@@ -492,10 +487,6 @@ void nntp_list_backend(struct ctdlroom *qrbuf, void *data)
 // Implements the LIST commands
 //
 void nntp_list(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
-       //
        if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
 
        char list_format[64];
@@ -559,10 +550,6 @@ 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
-       //
        if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
 
        citnntp *nntpstate = (citnntp *) CC->session_specific_data;
@@ -668,10 +655,6 @@ void nntp_mode(const char *cmd) {
 // (These commands all accept the same parameters; they differ only in how they output the retrieved message.)
 //
 void nntp_article(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
-        */
        if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
 
        citnntp *nntpstate = (citnntp *) CC->session_specific_data;
@@ -683,6 +666,7 @@ void nntp_article(const char *cmd) {
        int must_change_currently_selected_article = 0;
 
        // We're going to store one of these values in the variable 'acmd' so that
+       // we can quickly check later which version of the output we want.
        enum {
                ARTICLE,
                HEAD,
@@ -806,6 +790,57 @@ void nntp_article(const char *cmd) {
 }
 
 
+//
+// The LAST and NEXT commands are so similar that they are handled by a single function.
+//
+void nntp_last_next(const char *cmd) {
+       if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
+
+       citnntp *nntpstate = (citnntp *) CC->session_specific_data;
+       char which_command[16];
+       int acmd = 0;
+
+       // We're going to store one of these values in the variable 'acmd' so that
+       // we can quickly check later which version of the output we want.
+       enum {
+               NNTP_LAST,
+               NNTP_NEXT
+       };
+
+       extract_token(which_command, cmd, 0, ' ', sizeof which_command);
+
+       if (!strcasecmp(which_command, "last")) {
+               acmd = NNTP_LAST;
+       }
+       else if (!strcasecmp(which_command, "next")) {
+               acmd = NNTP_NEXT;
+       }
+       else {
+               cprintf("500 I'm afraid I can't do that.\r\n");
+               return;
+       }
+
+       // ok, here we go ... fetch the msglist so we can figure out our place in the universe
+       struct nntp_msglist nm;
+       long low_water_mark = 0;
+       long high_water_mark = 0;
+
+       nm = nntp_fetch_msglist(&CC->room);
+       if ((nm.num_msgs > 0) && (nm.msgnums != NULL)) {
+               low_water_mark = nm.msgnums[0];
+               high_water_mark = nm.msgnums[nm.num_msgs - 1];
+       }
+       else {
+               cprintf("500 something bad happened\r\n");
+               return;
+       }
+
+       // ok now let's get all up in this msglist FIXME
+
+       cprintf("500 FIXME cmd=%d current_article_number=%ld\r\n", acmd, nntpstate->current_article_number);
+}
+
+
 // 
 // Main command loop for NNTP server sessions.
 //
@@ -871,10 +906,19 @@ void nntp_command_loop(void)
                        || (!strcasecmp(cmdname, "head"))
                        || (!strcasecmp(cmdname, "body"))
                        || (!strcasecmp(cmdname, "stat"))
-               ) {
+               )
+       {
                nntp_article(ChrPtr(Cmd));
        }
 
+       else if (
+                       (!strcasecmp(cmdname, "last"))
+                       || (!strcasecmp(cmdname, "next"))
+               )
+       {
+               nntp_last_next(ChrPtr(Cmd));
+       }
+
        else {
                cprintf("500 I'm afraid I can't do that.\r\n");
        }