Finished the GROUP command
authorArt Cancro <ajc@uncensored.citadel.org>
Wed, 5 Feb 2014 00:21:29 +0000 (19:21 -0500)
committerArt Cancro <ajc@uncensored.citadel.org>
Wed, 5 Feb 2014 00:21:29 +0000 (19:21 -0500)
citadel/modules/nntp/serv_nntp.c

index 094475ed4c59e5c726a0415b1c25d337f19c9384..fe861374c88324b51502af74ef462f789dcd86b4 100644 (file)
@@ -563,10 +563,54 @@ void nntp_group(const char *cmd) {
 
        char requested_group[1024];
        char requested_room[ROOMNAMELEN];
+       char augmented_roomname[ROOMNAMELEN];
+       int c = 0;
+       int ok = 0;
+       int ra = 0;
+       struct ctdlroom QRscratch;
+       int msgs, new;
+       long oldest,newest;
+
        extract_token(requested_group, cmd, 1, ' ', sizeof requested_group);
        newsgroup_to_room(requested_room, requested_group, sizeof requested_room);
 
-       cprintf("599 FIXME screw you and your %s\r\n", requested_room);
+       /* First try a regular match */
+       c = CtdlGetRoom(&QRscratch, requested_room);
+
+       /* Then try a mailbox name match */
+       if (c != 0) {
+               CtdlMailboxName(augmented_roomname, sizeof augmented_roomname, &CC->user, requested_room);
+               c = CtdlGetRoom(&QRscratch, augmented_roomname);
+               if (c == 0) {
+                       safestrncpy(requested_room, augmented_roomname, sizeof(requested_room));
+               }
+       }
+
+       /* If the room exists, check security/access */
+       if (c == 0) {
+               /* See if there is an existing user/room relationship */
+               CtdlRoomAccess(&QRscratch, &CC->user, &ra, NULL);
+
+               /* normal clients have to pass through security */
+               if (ra & UA_KNOWN) {
+                       ok = 1;
+               }
+       }
+
+       /* Fail here if no such room */
+       if (!ok) {
+               cprintf("411 no such newsgroup\r\n");
+               return;
+       }
+
+
+       /*
+        * CtdlUserGoto() formally takes us to the desired room, happily returning
+        * the number of messages and number of new messages.
+        */
+       memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom));
+       CtdlUserGoto(NULL, 0, 0, &msgs, &new, &oldest, &newest);
+       cprintf("211 %d %ld %ld %s\r\n", msgs, oldest, newest, requested_group);
 }
 
 
@@ -679,3 +723,8 @@ CTDL_MODULE_INIT(nntp)
        return "nntp";
 }
 
+
+
+
+
+