]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/nntp/serv_nntp.c
abortion is murder
[citadel.git] / citadel / modules / nntp / serv_nntp.c
index 07bb5f443695b3bc8d6e33b18835acc031f0007e..79d73dd779b4b7f31ae709e66445109030dd61f3 100644 (file)
@@ -335,18 +335,82 @@ void nntp_authinfo(const char *cmd) {
 }
 
 
+// FIXME move this to a header file
+struct nntp_msglist {
+       int num_msgs;
+       long *msgnums;
+};
 
-/* FIXME not finished need to add water marks
+
+/*
+ * Utility function to fetch the current list of message numbers in a room
  */
-void output_roomname_in_list_active_format(struct ctdlroom *qrbuf) {
+struct nntp_msglist nntp_fetch_msglist(struct ctdlroom *qrbuf) {
+       struct nntp_msglist nm;
+       struct cdbdata *cdbfr;
+
+       cdbfr = cdb_fetch(CDB_MSGLISTS, &qrbuf->QRnumber, sizeof(long));
+       if (cdbfr != NULL) {
+               nm.msgnums = (long*)cdbfr->ptr;
+               cdbfr->ptr = NULL;
+               nm.num_msgs = cdbfr->len / sizeof(long);
+               cdbfr->len = 0;
+               cdb_free(cdbfr);
+       } else {
+               nm.num_msgs = 0;
+               nm.msgnums = NULL;
+       }
+       return(nm);
+}
+
+
+
+
+enum {
+       NNTP_LIST_ACTIVE,
+       NNTP_LIST_ACTIVE_TIMES,
+       NNTP_LIST_DISTRIB_PATS,
+       NNTP_LIST_HEADERS,
+       NNTP_LIST_NEWSGROUPS,
+       NNTP_LIST_OVERVIEW_FMT
+};
+
+
+/*
+ * 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) {
        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);
-       cprintf("%s\r\n", n_name);
+       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];
+       }
+
+       switch(which_format) {
+       case NNTP_LIST_ACTIVE:
+               // FIXME we have hardcoded "n" for "no posting allowed" -- fix when we add posting
+               cprintf("%s %ld %ld n\r\n", n_name, high_water_mark, low_water_mark);
+               break;
+       case NNTP_LIST_NEWSGROUPS:
+               cprintf("%s %s\r\n", n_name, qrbuf->QRname);
+               break;
+       }
+
+       if (nm.msgnums != NULL) {
+               free(nm.msgnums);
+       }
 }
 
 
 
-/* 
+/*
+ * Called once per room by nntp_newgroups() to qualify and possibly output a single room
  */
 void nntp_newgroups_backend(struct ctdlroom *qrbuf, void *data)
 {
@@ -365,7 +429,7 @@ void nntp_newgroups_backend(struct ctdlroom *qrbuf, void *data)
 
        if (ra & UA_KNOWN) {
                if (qrbuf->QRgen >= thetime) {
-                       output_roomname_in_list_active_format(qrbuf);
+                       output_roomname_in_list_format(qrbuf, NNTP_LIST_ACTIVE);
                }
        }
 }
@@ -463,6 +527,10 @@ void nntp_command_loop(void)
                nntp_newgroups(ChrPtr(Cmd));
        }
 
+       //else if (!strcasecmp(cmdname, "list")) {
+               //nntp_list(ChrPtr(Cmd));
+       //}
+
        else {
                cprintf("500 I'm afraid I can't do that.\r\n");
        }