]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/nntp/serv_nntp.c
Added mandatory HELP command; removed nonstandard NOOP command.
[citadel.git] / citadel / modules / nntp / serv_nntp.c
index c99b588d7e45a1d303704c9f88ccdba3e282468f..2b094586d9520f369cb72fe4edabc2b34b21611a 100644 (file)
@@ -60,7 +60,7 @@
 #include "locate_host.h"
 #include "citadel_dirs.h"
 #include "ctdl_module.h"
-
+#include "serv_nntp.h"
 
 extern long timezone;
 
@@ -231,15 +231,13 @@ void nntp_starttls(void)
 }
 
 
-void nntp_noop(void)
-{
-       cprintf("250 NOOP\r\n");
-}
-
-
 void nntp_capabilities(void)
 {
        cprintf("101 Capability list:\r\n");
+       cprintf("VERSION 2\r\n");
+       cprintf("READER\r\n");
+       cprintf("LIST ACTIVE NEWSGROUPS\r\n");
+       cprintf("IMPLEMENTATION Citadel v%d.%02d\r\n", (REV_LEVEL/100), (REV_LEVEL%100));
 #ifdef HAVE_OPENSSL
        cprintf("STARTTLS\r\n");
 #endif
@@ -335,13 +333,6 @@ void nntp_authinfo(const char *cmd) {
 }
 
 
-// FIXME move this to a header file
-struct nntp_msglist {
-       int num_msgs;
-       long *msgnums;
-};
-
-
 /*
  * Utility function to fetch the current list of message numbers in a room
  */
@@ -381,19 +372,27 @@ enum {
 /*
  * Output a room name (newsgroup name) in formats required for LIST and NEWGROUPS command
  */
-void output_roomname_in_list_format(struct ctdlroom *qrbuf, int which_format) {
+void output_roomname_in_list_format(struct ctdlroom *qrbuf, int which_format, char *wildmat_pattern) {
        char n_name[1024];
        struct nntp_msglist nm;
        long low_water_mark = 0;
        long high_water_mark = 0;
 
        room_to_newsgroup(n_name, qrbuf->QRname, sizeof n_name);
+
+       if ((wildmat_pattern != NULL) && (!IsEmptyStr(wildmat_pattern))) {
+               if (!wildmat(n_name, wildmat_pattern)) {
+                       return;
+               }
+       }
+
        nm = nntp_fetch_msglist(qrbuf);
        if ((nm.num_msgs > 0) && (nm.msgnums != NULL)) {
                low_water_mark = nm.msgnums[0];
                high_water_mark = nm.msgnums[nm.num_msgs - 1];
        }
 
+       // Only the mandatory formats are supported
        switch(which_format) {
        case NNTP_LIST_ACTIVE:
                // FIXME we have hardcoded "n" for "no posting allowed" -- fix when we add posting
@@ -403,7 +402,6 @@ void output_roomname_in_list_format(struct ctdlroom *qrbuf, int which_format) {
                cprintf("%s %s\r\n", n_name, qrbuf->QRname);
                break;
        }
-       // FIXME do all the other formats, bitch
 
        if (nm.msgnums != NULL) {
                free(nm.msgnums);
@@ -432,7 +430,7 @@ void nntp_newgroups_backend(struct ctdlroom *qrbuf, void *data)
 
        if (ra & UA_KNOWN) {
                if (qrbuf->QRgen >= thetime) {
-                       output_roomname_in_list_format(qrbuf, NNTP_LIST_ACTIVE);
+                       output_roomname_in_list_format(qrbuf, NNTP_LIST_ACTIVE, NULL);
                }
        }
 }
@@ -485,11 +483,6 @@ void nntp_newgroups(const char *cmd) {
 }
 
 
-struct nntp_list_data {
-       int list_format;
-};
-
-
 /*
  * Called once per room by nntp_list() to qualify and possibly output a single room
  */
@@ -501,7 +494,7 @@ void nntp_list_backend(struct ctdlroom *qrbuf, void *data)
 
        CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
        if (ra & UA_KNOWN) {
-               output_roomname_in_list_format(qrbuf, nld->list_format);
+               output_roomname_in_list_format(qrbuf, nld->list_format, nld->wildmat_pattern);
        }
 }
 
@@ -517,11 +510,18 @@ void nntp_list(const char *cmd) {
        if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
 
        char list_format[64];
-       char wildmat[1024];
+       char wildmat_pattern[1024];
        struct nntp_list_data nld;
 
        extract_token(list_format, cmd, 1, ' ', sizeof list_format);
-       extract_token(wildmat, cmd, 2, ' ', sizeof wildmat);
+       extract_token(wildmat_pattern, cmd, 2, ' ', sizeof wildmat_pattern);
+
+       if (strlen(wildmat_pattern) > 0) {
+               nld.wildmat_pattern = wildmat_pattern;
+       }
+       else {
+               nld.wildmat_pattern = NULL;
+       }
 
        if ( (strlen(cmd) < 6) || (!strcasecmp(list_format, "ACTIVE")) ) {
                nld.list_format = NNTP_LIST_ACTIVE;
@@ -533,8 +533,6 @@ void nntp_list(const char *cmd) {
                cprintf("501 syntax error , unsupported list format\r\n");
                return;
        }
-       // FIXME do all of the other variants, bitch
-
 
        cprintf("231 list of newsgroups follows\r\n");
        CtdlGetUser(&CC->user, CC->curr_user);
@@ -543,6 +541,16 @@ void nntp_list(const char *cmd) {
 }
 
 
+/*
+ * Implement HELP command.
+ */
+void nntp_help(void) {
+       cprintf("100 This is the Citadel NNTP service.\r\n");
+       cprintf("RTFM http://www.ietf.org/rfc/rfc3977.txt\r\n");
+       cprintf(".\r\n");
+}
+
+
 /* 
  * Main command loop for NNTP server sessions.
  */
@@ -569,6 +577,10 @@ void nntp_command_loop(void)
                nntp_quit();
        }
 
+       else if (!strcasecmp(cmdname, "help")) {
+               nntp_help();
+       }
+
        else if (!strcasecmp(cmdname, "capabilities")) {
                nntp_capabilities();
        }
@@ -577,10 +589,6 @@ void nntp_command_loop(void)
                nntp_starttls();
        }
 
-       else if (!strcasecmp(cmdname, "noop")) {
-               nntp_noop();
-       }
-
        else if (!strcasecmp(cmdname, "authinfo")) {
                nntp_authinfo(ChrPtr(Cmd));
        }