]> code.citadel.org Git - citadel.git/blobdiff - citadel/rooms.c
Create some directories to hold the source files for the utility
[citadel.git] / citadel / rooms.c
index c1a066bd093d2ea22145132ffea9a17bcc8a6d6c..5fbc76c7f78c210fd8b7657d2c26fd8eddf2aa9a 100644 (file)
 #include <sys/wait.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "citadel_decls.h"
 #include "rooms.h"
 #include "commands.h"
-#include "tools.h"
 #include "messages.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
@@ -79,7 +79,7 @@ void load_floorlist(CtdlIPC *ipc)
                strcpy(floorlist[0], "Main Floor");
                return;
        }
-       while (*listing && strlen(listing)) {
+       while (*listing && !IsEmptyStr(listing)) {
                extract_token(buf, listing, 0, '\n', sizeof buf);
                remove_token(listing, 0, '\n');
                extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
@@ -165,7 +165,7 @@ int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
 /*
  * Common code for all room listings
  */
-static void listrms(struct march *listing, int new_only, int floor_only)
+static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
 {
        struct march *mptr;
        struct ctdlroomlisting *rl = NULL;
@@ -188,6 +188,12 @@ static void listrms(struct march *listing, int new_only, int floor_only)
                   && (mptr->march_floor != floor_only))
                        list_it = 0;
 
+               if (flags && (mptr->march_flags & flags) == 0)
+                   list_it = 0;
+
+           if (match && (pattern(mptr->march_name, match) == -1))
+                       list_it = 0;
+
                if (list_it) {
                        rp = malloc(sizeof(struct ctdlroomlisting));
                        strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
@@ -271,10 +277,10 @@ void knrooms(CtdlIPC *ipc, int kn_floor_mode)
        if (kn_floor_mode == 0) {
                color(BRIGHT_CYAN);
                pprintf("\n   Rooms with unread messages:\n");
-               listrms(listing, LISTRMS_NEW_ONLY, -1);
+               listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
                color(BRIGHT_CYAN);
                pprintf("\n\n   No unseen messages in:\n");
-               listrms(listing, LISTRMS_OLD_ONLY, -1);
+               listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
                pprintf("\n");
        }
 
@@ -282,11 +288,11 @@ void knrooms(CtdlIPC *ipc, int kn_floor_mode)
                color(BRIGHT_CYAN);
                pprintf("\n   Rooms with unread messages on %s:\n",
                        floorlist[(int) curr_floor]);
-               listrms(listing, LISTRMS_NEW_ONLY, curr_floor);
+               listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
                color(BRIGHT_CYAN);
                pprintf("\n\n   Rooms with no new messages on %s:\n",
                        floorlist[(int) curr_floor]);
-               listrms(listing, LISTRMS_OLD_ONLY, curr_floor);
+               listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
                color(BRIGHT_CYAN);
                pprintf("\n\n   Other floors:\n");
                list_other_floors();
@@ -299,7 +305,7 @@ void knrooms(CtdlIPC *ipc, int kn_floor_mode)
                                color(BRIGHT_CYAN);
                                pprintf("\n   Rooms on %s:\n",
                                        floorlist[a]);
-                               listrms(listing, LISTRMS_ALL, a);
+                               listrms(listing, LISTRMS_ALL, a, 0, NULL);
                                pprintf("\n");
                        }
                }
@@ -333,7 +339,7 @@ void listzrooms(CtdlIPC *ipc)
 
        color(BRIGHT_CYAN);
        pprintf("\n   Forgotten public rooms:\n");
-       listrms(listing, LISTRMS_ALL, -1);
+       listrms(listing, LISTRMS_ALL, -1, 0, NULL);
        pprintf("\n");
 
        /* Free the room list */
@@ -347,6 +353,70 @@ void listzrooms(CtdlIPC *ipc)
        IFNEXPERT hit_any_key(ipc);
 }
 
+void dotknown(CtdlIPC *ipc, int what, char *match)
+{                              /* list rooms according to attribute */
+       struct march *listing = NULL;
+       struct march *mptr;
+       int r;          /* IPC response code */
+       char buf[SIZ];
+
+       /* Ask the server for a room list */
+       r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
+       if (r / 100 != 1) {
+               listing = NULL;
+       }
+
+       color(BRIGHT_CYAN);
+
+       switch (what) {
+    case 0:
+       pprintf("\n   Anonymous rooms:\n");
+           listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
+       pprintf("\n");
+               break;
+    case 1:
+       pprintf("\n   Directory rooms:\n");
+           listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
+       pprintf("\n");
+               break;
+    case 2:
+       pprintf("\n   Matching \"%s\" rooms:\n", match);
+           listrms(listing, LISTRMS_ALL, -1, 0, match);
+       pprintf("\n");
+               break;
+    case 3:
+       pprintf("\n   Preferred only rooms:\n");
+           listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
+       pprintf("\n");
+               break;
+    case 4:
+       pprintf("\n   Private rooms:\n");
+           listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
+       pprintf("\n");
+               break;
+    case 5:
+       pprintf("\n   Read only rooms:\n");
+           listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
+       pprintf("\n");
+               break;
+    case 6:
+       pprintf("\n   Shared rooms:\n");
+           listrms(listing, LISTRMS_ALL, -1, QR_NETWORK, NULL);
+       pprintf("\n");
+               break;
+       }
+
+       /* Free the room list */
+       while (listing) {
+               mptr = listing->next;
+               free(listing);
+               listing = mptr;
+       };
+
+       color(DIM_WHITE);
+       IFNEXPERT hit_any_key(ipc);
+}
+
 
 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
 {
@@ -448,7 +518,7 @@ void editthisroom(CtdlIPC *ipc)
        } else {
                strcpy(raide, "");
        }
-       if (strlen(raide) == 0) {
+       if (IsEmptyStr(raide)) {
                strcpy(raide, "none");
        }
 
@@ -464,7 +534,7 @@ void editthisroom(CtdlIPC *ipc)
        attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
        if (attr->QRflags & QR_PRIVATE) {
                attr->QRflags = set_room_attr(ipc, attr->QRflags,
-                                      "Accessible by guessing room name",
+                                      "Hidden room (accessible to anyone who knows the room name)",
                                       QR_GUESSNAME);
        }
 
@@ -498,10 +568,17 @@ void editthisroom(CtdlIPC *ipc)
                                        "Preferred users only", QR_PREFONLY);
        attr->QRflags = set_room_attr(ipc, attr->QRflags,
                                        "Read-only room", QR_READONLY);
-       attr->QRflags = set_room_attr(ipc, attr->QRflags,
-                                       "Directory room", QR_DIRECTORY);
+       attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
+                               "Allow message deletion by anyone who can post",
+                               QR2_COLLABDEL);
        attr->QRflags = set_room_attr(ipc, attr->QRflags,
                                        "Permanent room", QR_PERMANENT);
+       attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
+                                                                  "Subject Required (Force "
+                                                                  "users to specify a message "
+                                   "subject)", QR2_SUBJECTREQ);
+       attr->QRflags = set_room_attr(ipc, attr->QRflags,
+                                       "Directory room", QR_DIRECTORY);
        if (attr->QRflags & QR_DIRECTORY) {
                strprompt("Directory name", attr->QRdirname, 14);
                attr->QRflags =
@@ -519,6 +596,12 @@ void editthisroom(CtdlIPC *ipc)
        attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
                                "Self-service list subscribe/unsubscribe",
                                QR2_SELFLIST);
+       attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
+                               "public posting to this room via room_roomname@yourcitadel.org",
+                               QR2_SMTP_PUBLIC);
+       attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
+                               "moderated mailinglist",
+                               QR2_MODERATED);
        attr->QRflags = set_room_attr(ipc, attr->QRflags,
                               "Automatically make all messages anonymous",
                               QR_ANONONLY);
@@ -527,7 +610,7 @@ void editthisroom(CtdlIPC *ipc)
                                       "Ask users whether to make messages anonymous",
                                       QR_ANONOPT);
        }
-       attr->QRorder = intprompt("Listing order", attr->QRorder, 1, 127);
+       attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
 
        /* Ask about the room aide */
        do {
@@ -542,11 +625,6 @@ void editthisroom(CtdlIPC *ipc)
                }
        } while (r / 100 != 2);
 
-       /* FIXME: Duplicate code??? */
-       if (!strcasecmp(raide, "none")) {
-               strcpy(raide, "");
-       }
-
        /* Angels and demons dancing in my head... */
        do {
                snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
@@ -624,7 +702,7 @@ void dotungoto(CtdlIPC *ipc, char *towhere)
                scr_printf("Must specify a room to ungoto.\n");
                return;
       }
-       if (strlen(towhere) == 0)
+       if (IsEmptyStr(towhere))
       {
                scr_printf("Must specify a room to ungoto.\n");
                return;
@@ -724,7 +802,7 @@ void destination_directory(char *dest, const char *supplied_filename)
 {
        static char save_dir[SIZ] = { 0 };
 
-       if (strlen(save_dir) == 0) {
+       if (IsEmptyStr(save_dir)) {
                if (getenv("HOME") == NULL) {
                        strcpy(save_dir, ".");
                }
@@ -767,6 +845,7 @@ void download(CtdlIPC *ipc, int proto)
        FILE *tpipe = NULL;
        int broken = 0;
        int r;
+       int rv = 0;
        void *file = NULL;      /* The downloaded file */
        size_t filelen = 0L;    /* The downloaded file length */
 
@@ -827,7 +906,7 @@ void download(CtdlIPC *ipc, int proto)
 
        screen_reset();
        stty_ctdl(SB_RESTORE);
-       system(transmit_cmd);
+       rv = system(transmit_cmd);
        stty_ctdl(SB_NO_INTR);
        screen_set();
 
@@ -845,6 +924,7 @@ void roomdir(CtdlIPC *ipc)
        char flnm[256];
        char flsz[32];
        char comment[256];
+       char mimetype[256];
        char buf[256];
        char *listing = NULL;   /* Returned directory listing */
        int r;
@@ -859,19 +939,21 @@ void roomdir(CtdlIPC *ipc)
        extract_token(flnm, buf, 1, '|', sizeof flnm);
        pprintf("\nDirectory of %s on %s\n", flnm, comment);
        pprintf("-----------------------\n");
-       while (*listing && strlen(listing)) {
+       while (listing && *listing && !IsEmptyStr(listing)) {
                extract_token(buf, listing, 0, '\n', sizeof buf);
                remove_token(listing, 0, '\n');
 
                extract_token(flnm, buf, 0, '|', sizeof flnm);
                extract_token(flsz, buf, 1, '|', sizeof flsz);
-               extract_token(comment, buf, 2, '|', sizeof comment);
+               extract_token(mimetype, buf, 2, '|', sizeof mimetype);
+               extract_token(comment, buf, 3, '|', sizeof comment);
                if (strlen(flnm) <= 14)
-                       pprintf("%-14s %8s %s\n", flnm, flsz, comment);
+                       pprintf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
                else
-                       pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
-                               comment);
+                       pprintf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz,
+                               comment, mimetype);
        }
+       if (listing) free(listing);
 }
 
 
@@ -976,10 +1058,10 @@ void entroom(CtdlIPC *ipc)
        }
 
        newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
-       if (strlen(new_room_name) == 0) {
+       if (IsEmptyStr(new_room_name)) {
                return;
        }
-       for (a = 0; a < strlen(new_room_name); ++a) {
+       for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
                if (new_room_name[a] == '|') {
                        new_room_name[a] = '_';
                }
@@ -989,10 +1071,14 @@ void entroom(CtdlIPC *ipc)
 
        IFNEXPERT formout(ipc, "roomaccess");
        do {
-               scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
-                      "<3>Passworded room\n<4>Invitation-only room\n"
-                      "<5>Personal room\n"
-                       "Enter room type: ");
+               scr_printf("<?>Help\n"
+                       "<1>Public room (shown to all users by default)\n"
+                       "<2>Hidden room (accessible to anyone who knows the room name)\n"
+                       "<3>Passworded room (hidden, plus requires a password to enter)\n"
+                       "<4>Invitation-only room (requires access to be granted by an Aide)\n"
+                       "<5>Personal room (accessible to you only)\n"
+                       "Enter room type: "
+               );
                do {
                        b = inkey();
                } while (((b < '1') || (b > '5')) && (b != '?'));
@@ -1006,7 +1092,7 @@ void entroom(CtdlIPC *ipc)
        new_room_type = b - 1;
        if (new_room_type == 2) {
                newprompt("Enter a room password: ", new_room_pass, 9);
-               for (a = 0; a < strlen(new_room_pass); ++a)
+               for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
                        if (new_room_pass[a] == '|')
                                new_room_pass[a] = '_';
        } else {
@@ -1017,7 +1103,7 @@ void entroom(CtdlIPC *ipc)
        if (b == 1)
                scr_printf(" public room.");
        if (b == 2)
-               scr_printf(" guess-name room.");
+               scr_printf(" hidden room.");
        if (b == 3)
                scr_printf(" passworded room, password: %s", new_room_pass);
        if (b == 4)
@@ -1056,7 +1142,7 @@ void readinfo(CtdlIPC *ipc)
        else
                strcpy(raide, "");
 
-       if (strlen(raide) > 0)
+       if (!IsEmptyStr(raide))
                scr_printf("Room aide is %s.\n\n", raide);
 
        r = CtdlIPCRoomInfo(ipc, &text, buf);
@@ -1086,7 +1172,7 @@ void whoknows(CtdlIPC *ipc)
                pprintf("%s\n", buf);
                return;
        }
-       while (strlen(listing) > 0) {
+       while (!IsEmptyStr(listing)) {
                extract_token(buf, listing, 0, '\n', sizeof buf);
                remove_token(listing, 0, '\n');
                if (sigcaught == 0)
@@ -1103,7 +1189,7 @@ void do_edit(CtdlIPC *ipc,
        char cmd[SIZ];
        int b, cksum, editor_exit;
 
-       if (strlen(editor_paths[0]) == 0) {
+       if (IsEmptyStr(editor_paths[0])) {
                scr_printf("Do you wish to re-enter %s? ", desc);
                if (yesno() == 0)
                        return;
@@ -1119,7 +1205,7 @@ void do_edit(CtdlIPC *ipc,
                return;
        }
 
-       if (strlen(editor_paths[0]) > 0) {
+       if (!IsEmptyStr(editor_paths[0])) {
                CtdlIPC_chat_send(ipc, read_cmd);
                CtdlIPC_chat_recv(ipc, cmd);
                if (cmd[0] == '1') {
@@ -1133,7 +1219,7 @@ void do_edit(CtdlIPC *ipc,
 
        cksum = file_checksum(temp);
 
-       if (strlen(editor_paths[0]) > 0) {
+       if (!IsEmptyStr(editor_paths[0])) {
                char tmp[SIZ];
 
                snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
@@ -1302,7 +1388,7 @@ void kill_floor(CtdlIPC *ipc)
                floornum_to_delete = (-1);
                scr_printf("(Press return to abort)\n");
                newprompt("Delete which floor? ", buf, 255);
-               if (strlen(buf) == 0)
+               if (IsEmptyStr(buf))
                        return;
                for (a = 0; a < 128; ++a)
                        if (!strcasecmp(&floorlist[a][0], buf))