Changeover to new room structure. See ChangeLog for details.
authorArt Cancro <ajc@citadel.org>
Mon, 5 Oct 1998 15:35:21 +0000 (15:35 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 5 Oct 1998 15:35:21 +0000 (15:35 +0000)
22 files changed:
citadel/ChangeLog
citadel/citadel.c
citadel/citadel.h
citadel/citserver.c
citadel/file_ops.c
citadel/housekeeping.c
citadel/ipcdef.h
citadel/locate_host.c
citadel/messages.c
citadel/msgbase.c
citadel/netmailer.c
citadel/netproc.c
citadel/room_ops.c
citadel/room_ops.h
citadel/rooms.c
citadel/routines2.c
citadel/serv_chat.c
citadel/serv_test.c
citadel/server.h
citadel/sysconfig.h
citadel/sysdep.c
citadel/user_ops.c

index f26bd23d875a435b9f1abfa5398e3d99841e52e1..e1b12ea86d93701e6f36bca658c80035ec16d250 100644 (file)
@@ -1,3 +1,8 @@
+Sun Oct  4 23:35:18 EDT 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
+       * Did the big migration to the new data structures.  Lots of stuff is
+         now broken.  Basic moving from room to room works, but Mail is
+         broken, and some of the administrative commands are unimplemented.
+
 1998-10-02 Nathan Bryant <bryant@cs.usm.maine.edu>
        * configure.in: autologin now defaults to disabled
 
index c57f1bfadd472ce8a52abbc2c48acf4b966db989..abbf44dc1f3fcab3d5856a487fb8f8f16b8b3736 100644 (file)
@@ -60,7 +60,7 @@ int screenwidth;
 int screenheight;
 unsigned room_flags;
 char room_name[32];
-char ugname[20];
+char ugname[ROOMNAMELEN];
 long uglsn;                            /* holds <u>ngoto info */
 char is_mail = 0;                      /* nonzero when we're in a mail room */
 char axlevel = 0;                      /* access level */
index 559fe56e022b6061b0a699b366d0294b9e249c65..89ef7a9c89aa6b526c4862a5eeefa37343172d38 100644 (file)
@@ -27,6 +27,8 @@
  */
 typedef unsigned char CIT_UBYTE;
 
+#define ROOMNAMELEN    128
+
 struct config {
        char c_nodename[16];            /* UUCP and Citadel nodename        */
        char c_fqdn[64];                /* Fully Qualified Domain Name      */
@@ -38,7 +40,7 @@ struct config {
        char c_initax;                  /* initial access level             */
        char c_regiscall;               /* call number to register on       */
        char c_twitdetect;              /* twit detect flag                 */
-       char c_twitroom[20];            /* twit detect msg move to room     */
+       char c_twitroom[ROOMNAMELEN];   /* twit detect msg move to room     */
        int c_defent;                   /* command generated by <E> key     */
        char c_moreprompt[80];          /* paginator prompt                 */
        char c_restrict;                /* restrict Internet mail flag      */
@@ -67,7 +69,7 @@ struct config {
 
 /* Defines the relationship of a user to a particular room */
 struct visit {
-       char v_roomname[20];
+       char v_roomname[ROOMNAMELEN];
        long v_generation;
        long v_lastseen;
        unsigned int v_flags;
@@ -129,7 +131,7 @@ struct CitControl {
  * Room records
  */
 struct quickroom {
-       char QRname[20];                /* Max. len is 19, plus null term   */
+       char QRname[ROOMNAMELEN];       /* Name of room                     */
        char QRpasswd[10];              /* Only valid if it's a private rm  */
        long QRroomaide;                /* User number of room aide         */
        long QRhighest;                 /* Highest message NUMBER in room   */
@@ -236,3 +238,10 @@ struct floor {
 #define MT_CITADEL     0               /* Citadel proprietary */
 #define MT_RFC822      2               /* RFC822 */
 #define MT_RAW         3               /* IGnet raw format */
+
+
+
+#define BASEROOM       "Lobby"
+#define MAILROOM       "Mail"
+#define AIDEROOM       "Aide"
+
index 31aaa68bf9527dced353115e812c8dd7d7dba0b1..68011009c586b2777cb5266c5cbd7ad5ffa55cc1 100644 (file)
@@ -39,6 +39,11 @@ void master_startup(void) {
 
        lprintf(7, "Checking floor reference counts\n");
        check_ref_counts();
+
+       lprintf(7, "Creating base rooms (if necessary)\n");
+       create_room(BASEROOM, 0, "", 0);
+       create_room(AIDEROOM, 4, "", 0);
+       create_room(config.c_twitroom, 0, "", 0);
        }
 
 /*
@@ -124,8 +129,8 @@ void cleanup_stuff(void *arg)
  */
 void set_wtmpsupp(char *newtext)
 {
-       strncpy(CC->cs_room,newtext,19);
-       CC->cs_room[19] = 0;
+       strncpy(CC->cs_room,newtext,ROOMNAMELEN-1);
+       CC->cs_room[ROOMNAMELEN-1] = 0;
        time(&CC->cs_lastupdt);
 
        /* Run any routines registered by loadable modules */
@@ -156,8 +161,8 @@ void cmd_rchg(char *newroomname)
 {
    if ((newroomname) && (newroomname[0]))
    {
-      bzero(CC->fake_roomname, 20);
-      strncpy(CC->fake_roomname, newroomname, 19);
+      bzero(CC->fake_roomname, ROOMNAMELEN);
+      strncpy(CC->fake_roomname, newroomname, ROOMNAMELEN-1);
    }
    else
       CC->fake_roomname[0] = '\0';
@@ -642,7 +647,6 @@ void *context_loop(struct CitContext *con)
        /* 
         * Initialize some variables specific to our context.
         */
-       CC->curr_rm = (-1);
        CC->logged_in = 0;
        CC->internal_pgm = 0;
        CC->download_fp = NULL;
index 436ff717e5760050b82a7e1e96f35d5df87c8f96..3f2c6c36df6807d83782df7edb0bafe4fd1cf781 100644 (file)
@@ -7,6 +7,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <time.h>
+#include <limits.h>
 #include <pthread.h>
 #include "citadel.h"
 #include "server.h"
@@ -67,7 +68,6 @@ void cmd_movf(char *cmdbuf)
        char newroom[256];
        char buf[256];
        int a;
-       int target_room = (-1);
        struct quickroom qrbuf;
 
        extract(filename,cmdbuf,0);
@@ -104,16 +104,11 @@ void cmd_movf(char *cmdbuf)
                return;
                }
 
-       for (a=0; a<MAXROOMS; ++a) {
-               getroom(&qrbuf,a);
-               if (!strcasecmp(qrbuf.QRname,newroom)) target_room = a;
-               }
-       if (target_room < 0) {
-               cprintf("%d Room '%s' not found.\n",
-                       ERROR+ROOM_NOT_FOUND,newroom);
+       if (getroom(&qrbuf, newroom)!=0) {
+               cprintf("%d '%s' does not exist.\n",
+                       ERROR, newroom);
                return;
                }
-       getroom(&qrbuf, target_room);
        if ((qrbuf.QRflags & QR_DIRECTORY) == 0) {
                cprintf("%d '%s' is not a directory room.\n",
                        ERROR+NOT_HERE,qrbuf.QRname);
@@ -318,7 +313,7 @@ void cmd_oimg(char *cmdbuf)
                sprintf(pathname, "./images/floor.%d.gif", which_floor);
                }
        else if (!strcasecmp(filename, "_roompic_")) {
-               sprintf(pathname, "./images/room.%d.gif", CC->curr_rm);
+               assoc_file_name(pathname, &CC->quickroom, "images");
                }
        else {
                for (a=0; a<strlen(filename); ++a) {
@@ -438,7 +433,7 @@ void cmd_uimg(char *cmdbuf)
                }
 
        if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
-               sprintf(CC->upl_path, "./images/room.%d.gif", CC->curr_rm);
+               assoc_file_name(CC->upl_path, &CC->quickroom, "images");
                }
 
        if (strlen(CC->upl_path) == 0) {
index 2458fa861ff20e128f802bfcbeeb3a1e9fa81d62..f54e3122f2375ab1907cd7274f863ddcafe7ddc5 100644 (file)
@@ -11,6 +11,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <errno.h>
+#include <limits.h>
 #include <pthread.h>
 #include "citadel.h"
 #include "server.h"
index f21408a28c35d77e18d054cccc602aca5f2ed938..49eb61943af5e700ccea09ee0f67fcb0a5e9d866 100644 (file)
@@ -50,11 +50,11 @@ struct CtdlServInfo {
 #define QR_DOWNLOAD    128             /* Allowed to download              */
 #define QR_VISDIR      256             /* Visible directory                */
 #define QR_ANONONLY    512             /* Anonymous-Only room              */
-#define QR_ANON2       1024            /* Anonymous-Option room            */
+#define QR_ANONOPT     1024            /* Anonymous-Option room            */
 #define QR_NETWORK     2048            /* Shared network room              */
 #define QR_PREFONLY    4096            /* Preferred status needed to enter */
 #define QR_READONLY    8192            /* Aide status required to post     */
-
+#define QR_MAILBOX     16384           /* Set if this is a private mailbox */
 
 #define US_NEEDVALID   1               /* User needs to be validated       */
 #define US_PERM                4               /* Permanent user                   */
@@ -72,18 +72,3 @@ struct CtdlServInfo {
 
 void serv_puts(char *buf);
 void serv_gets(char *buf);
-
-struct CtdlServerHandle {
-       char ServerAddress[64];
-       int ServerPort;
-       char ipgmSecret[32];
-       char UserName[32];
-       char Password[32];
-       char InitialRoom[32];
-       int AssocClientSession;
-       };
-
-struct CtdlRoomInfo {
-       char RoomName[32];
-       time_t mtime;
-       };
index c45c86430f2e4d93414d8f1dff2fdbc77ba62285..e4708cdf95a443b24bbc18ad38742ea7e0497f17 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <limits.h>
 #include <netdb.h>
 #include <string.h>
 #include <pthread.h>
index 3f42cf95ec5be9f21cbdcd8ae4e9517c9b5e6773..9fb2997cc832ad92d06595ffa87dbbcea45e9c33 100644 (file)
@@ -812,7 +812,7 @@ int entmsg(int is_reply, int c)
                }
 
        b=0;
-       if (room_flags&QR_ANON2) {
+       if (room_flags&QR_ANONOPT) {
                printf("Anonymous (Y/N)? ");
                if (yesno()==1) b=1;
                }
@@ -944,7 +944,7 @@ void readmsgs(int c, int rdir, int q)       /* read contents of a room */
        char prtfile[16];
        char pagin;
        char cmd[256];
-       char targ[20];
+       char targ[ROOMNAMELEN];
 
        signal(SIGINT,SIG_IGN);
        signal(SIGQUIT,SIG_IGN);
@@ -1076,7 +1076,8 @@ RMSGREAD: fflush(stdout);
                   case 'a':    goto RAGAIN;
                   case 'b':    a=a-(rdir*2);
                                break;
-                  case 'm':    newprompt("Enter target room: ",targ,19);
+                  case 'm':    newprompt("Enter target room: ",
+                                       targ,ROOMNAMELEN-1);
                                if (strlen(targ)>0) {
                                        sprintf(cmd,"MOVE %ld|%s",
                                                msg_arr[a],targ);
index 009214aa6ed64febbc52d10a4525c0110f77c015..630af049a0b3c28885beec947a364ec3e79409c5 100644 (file)
@@ -28,7 +28,6 @@
 #define MSGS_GT                5
 
 extern struct config config;
-int twitroom=-1;
 
 
 /*
@@ -169,12 +168,8 @@ void cmd_msgs(char *cmdbuf)
                cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
                return;
                }
-       if (CC->curr_rm < 0) {
-               cprintf("%d no room\n",ERROR);
-               return;
-               }
        get_mm();
-       get_msglist(CC->curr_rm);
+       get_msglist(&CC->quickroom);
        getuser(&CC->usersupp,CC->curr_user);
        CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
 
@@ -249,7 +244,9 @@ void memfmout(int width, char *mptr, char subst)
                        /* where are we going to get our text from? */
                        /* nonzero if we should use hypertext mode */
        {
-       int a,b,c,real,old;
+       int a,b,c;
+       int real = 0;
+       int old = 0;
        CIT_UBYTE ch;
        char aaa[140];
        char buffer[256];
@@ -348,10 +345,6 @@ void output_message(char *msgid, int mode,
                cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
                return;
                }
-       if (CC->curr_rm < 0) {
-               cprintf("%d No room selected.\n",ERROR);
-               return;
-               }
 
        /* We used to need to check in the current room's message list
         * to determine where the message's disk position.  We no longer need
@@ -650,39 +643,6 @@ long send_message(char *message_in_memory, /* pointer to buffer */
 
 
 
-
-
-/* FIX ... rewrite this to simply check for the existence of the twitroom,
- * and create it if necessary.  No slot-numbers will need to be loaded.
- * (Actually, twitroom should be created during the same portion of startup
- * that creates Lobby/Mail/Aide.)
- */
-void loadtroom(void) {
-       struct quickroom qrbuf;
-       int a;
-       unsigned newflags;
-
-       /* first try to locate the twit room */
-       for (a=0; a<MAXROOMS; ++a) {
-               getroom(&qrbuf,a);
-               if (!strcasecmp(qrbuf.QRname,config.c_twitroom)) {
-                       twitroom = a;
-                       return;
-                       }
-               }
-
-       /* if not found, try to create it  -  put it in the last slot */
-       twitroom = get_free_room_slot(-1);
-       if (twitroom>=0) {
-               newflags = create_room(twitroom,config.c_twitroom,0,"",0);
-               return;
-               }
-
-       /* as a last resort, point to Aide> */
-       twitroom = 2;
-       }
-
-
 /*
  * this is a simple file copy routine.
  */
@@ -717,12 +677,8 @@ void save_message(char *mtmp,      /* file containing proper message */
                int mailtype,   /* local or remote type, see citadel.h */
                int generate_id) /* set to 1 to generate an 'I' field */
 {
-       struct usersupp tempUS;
        char aaa[100];
-       int hold_rm;
-       struct cdbdata *cdbmb;
-       long *dmailbox;
-       int dnum_mails;
+       char hold_rm[ROOMNAMELEN];
        long newmsgid;
        char *message_in_memory;
        struct stat statbuf;
@@ -750,63 +706,64 @@ void save_message(char *mtmp,     /* file containing proper message */
        newmsgid = send_message(message_in_memory, templen, generate_id);
        free(message_in_memory);
        if (newmsgid <= 0L) return;
-       hold_rm=(-1);
+
+       strcpy(hold_rm, "");
 
        /* If the user is a twit, move to the twit room for posting... */
        if (TWITDETECT) if (CC->usersupp.axlevel==2) {
-               if (twitroom<0) loadtroom();
-               hold_rm=CC->curr_rm;
-               CC->curr_rm=twitroom;
+               strcpy(hold_rm, CC->cs_room);
+               strcpy(CC->cs_room, config.c_twitroom);
                }
 
        /* ...or if this message is destined for Aide> then go there. */
        if (mtsflag) {
-               hold_rm=CC->curr_rm;
-               CC->curr_rm=2;
+               strcpy(hold_rm, CC->cs_room);
+               strcpy(CC->cs_room, "Aide");
                }
 
+       /* ...or if this is a private message, go to the target mailbox. */
+       /* FIX FIX FIX do this! */
+
        /* This call to usergoto() changes rooms if necessary.  It also
         * causes the latest message list to be read into memory.
         */
-       usergoto(CC->curr_rm,0);
-
-       /* Store the message pointer, but NOT for sent mail! */
-       if (CC->curr_rm != 1) {
+       lprintf(9, "Changing rooms if necessary...\n");
+       usergoto(CC->cs_room, 0);
 
-               /* read in the quickroom record, obtaining a lock... */
-               lgetroom(&CC->quickroom,CC->curr_rm);
-               get_msglist(CC->curr_rm);
+       /* read in the quickroom record, obtaining a lock... */
+       lprintf(9, "Reading/locking <%s>...\n", CC->cs_room);
+       lgetroom(&CC->quickroom, CC->cs_room);
+       lprintf(9, "Fetching message list...\n");
+       get_msglist(&CC->quickroom);
 
-               /* FIX here's where we have to to message expiry!! */
+       /* FIX here's where we have to to message expiry!! */
 
-               /* Now add the new message */
-               CC->num_msgs = CC->num_msgs + 1;
-               CC->msglist = realloc(CC->msglist,
-                       ((CC->num_msgs) * sizeof(long)) );
-               if (CC->msglist == NULL) {
-                       lprintf(3, "ERROR can't realloc message list!\n");
-                       }
-               SetMessageInList(CC->num_msgs - 1, newmsgid);
-       
-               /* Write it back to disk. */
-               put_msglist(CC->curr_rm);
-       
-               /* update quickroom */
-               CC->quickroom.QRhighest = newmsgid;
-               lputroom(&CC->quickroom,CC->curr_rm);
+       /* Now add the new message */
+       CC->num_msgs = CC->num_msgs + 1;
+       CC->msglist = realloc(CC->msglist,
+               ((CC->num_msgs) * sizeof(long)) );
+       if (CC->msglist == NULL) {
+               lprintf(3, "ERROR can't realloc message list!\n");
                }
+       SetMessageInList(CC->num_msgs - 1, newmsgid);
+
+       /* Write it back to disk. */
+       lprintf(9, "Writing message list...\n");
+       put_msglist(&CC->quickroom);
+
+       /* update quickroom */
+       CC->quickroom.QRhighest = newmsgid;
+       lprintf(9, "Writing/unlocking room <%s>...\n", CC->cs_room);
+       lputroom(&CC->quickroom,CC->cs_room);
 
        /* Bump this user's messages posted counter.  Also, if the user is a
         * twit, give them access to the twit room.
         */
-       lgetuser(&CC->usersupp,CC->curr_user);
+       lgetuser(&CC->usersupp, CC->curr_user);
        CC->usersupp.posted = CC->usersupp.posted + 1;
        /* FIX if user is twit, grant access to twitroom here */
        lputuser(&CC->usersupp, CC->curr_user);
 
-       /* If mail, there's still more to do, if not, skip it. */
-       if ((CC->curr_rm!=1)||(mtsflag)) goto ENTFIN;
-
        /* Network mail - send a copy to the network program. */
        if (mailtype!=M_LOCAL) {
                sprintf(aaa,"./network/spoolin/nm.%d",getpid());
@@ -814,47 +771,16 @@ void save_message(char *mtmp,     /* file containing proper message */
                system("exec nohup ./netproc >/dev/null 2>&1 &");
                }
 
-       /* Local mail - put a copy in the recipient's mailbox. */
-       /* FIX here's where we have to handle expiry, stuffed boxes, etc. */
-       if (mailtype == M_LOCAL) {
-               if (lgetuser(&tempUS,rec)==0) {
-
-                       cdbmb = cdb_fetch(CDB_MAILBOXES,
-                                       &tempUS.usernum, sizeof(long));
-                       if (cdbmb != NULL) {
-                               memcpy(dmailbox, cdbmb->ptr, cdbmb->len);
-                               dnum_mails = cdbmb->len / sizeof(long);
-                               cdb_free(cdbmb);
-                               }
-                       else {
-                               dmailbox = NULL;
-                               dnum_mails = 0;
-                               }
-       
-                       ++dnum_mails;
-                       if (dmailbox == NULL) {
-                               dmailbox = malloc(sizeof(long) * dnum_mails);
-                               }
-                       else {
-                               dmailbox = realloc(dmailbox,
-                                               sizeof(long) * dnum_mails);
-                               }
-                       
-                       dmailbox[dnum_mails - 1] = newmsgid;
-                       cdb_store(CDB_MAILBOXES, &tempUS.usernum, sizeof(long),
-                               dmailbox, (dnum_mails * sizeof(long)) );
-                       lputuser(&tempUS,rec);
-                       free(dmailbox);
-                       }
-               }
-
        /* If we've posted in a room other than the current room, then we
         * have to now go back to the current room...
         */
-ENTFIN:        if (hold_rm!=(-1)) {
-               usergoto(hold_rm,0);
+       if (strlen(hold_rm) > 0) {
+               lprintf(9, "Returning to <%s>\n", hold_rm);
+               usergoto(hold_rm, 0);
                }
+       lprintf(9, "Deleting temporary file\n");
        unlink(mtmp);           /* delete the temporary file */
+       lprintf(9, "Finished with save_message()\n");
        }
 
 
@@ -970,7 +896,8 @@ void cmd_ent0(char *entargs)
        char newusername[256];          /* <bc> */
        char boundary[256];
 
-       int a,b,e;
+       int a,b;
+       int e = 0;
        int mtsflag = 0;
        struct usersupp tempUS;
        char buf[256];
@@ -987,13 +914,10 @@ void cmd_ent0(char *entargs)
                cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
                return;
                }
-       if (CC->curr_rm < 0) {
-               cprintf("%d No room selected.\n",ERROR);
-               return;
-               }
-       if ((CC->usersupp.axlevel<2)&&(CC->curr_rm!=1)) {
-               cprintf("%d Need to be validated to enter (except in Mail> to sysop)\n",
+       if ((CC->usersupp.axlevel<2)&&((CC->quickroom.QRflags&QR_MAILBOX)==0)) {
+               cprintf("%d Need to be validated to enter ",
                        ERROR+HIGHER_ACCESS_REQUIRED);
+               cprintf("(except in %s> to sysop)\n", MAILROOM);
                return;
                }
        if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
@@ -1013,7 +937,8 @@ void cmd_ent0(char *entargs)
         if (post==2) {                 /* <bc> */
            if (CC->usersupp.axlevel<6)
            {
-              cprintf("%d\nYou don't have sufficient permission to do an aide post.\n", ERROR+HIGHER_ACCESS_REQUIRED);
+              cprintf("%d You don't have permission to do an aide post.\n",
+               ERROR+HIGHER_ACCESS_REQUIRED);
               return;
            }
           extract(newusername,entargs,4);
@@ -1026,7 +951,7 @@ void cmd_ent0(char *entargs)
        CC->cs_flags |= CS_POSTING;
        
        buf[0]=0;
-       if (CC->curr_rm==1) {
+       if (CC->quickroom.QRflags & QR_MAILBOX) {
                if (CC->usersupp.axlevel>=2) {
                        strcpy(buf,recipient);
                        }
@@ -1077,10 +1002,10 @@ void cmd_ent0(char *entargs)
        
 SKFALL: b=MES_NORMAL;
        if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
-       if (CC->quickroom.QRflags&QR_ANON2) {
+       if (CC->quickroom.QRflags&QR_ANONOPT) {
                if (anon_flag==1) b=MES_AN2;
                }
-       if (CC->curr_rm!=1) buf[0]=0;
+       if ((CC->quickroom.QRflags & QR_MAILBOX) == 0) buf[0]=0;
 
        /* If we're only checking the validity of the request, return
         * success without creating the message.
@@ -1112,7 +1037,8 @@ void cmd_ent3(char *entargs)
 {
        char recp[256];
        char buf[256];
-       int a, e;
+       int a;
+       int e = 0;
        struct usersupp tempUS;
        long msglen;
        long bloklen;
@@ -1124,12 +1050,8 @@ void cmd_ent3(char *entargs)
                return;
                }
 
-       if (CC->curr_rm < 0) {
-               cprintf("%d No room selected.\n",ERROR);
-               return;
-               }
-
-       if (CC->curr_rm == 1) { /* If we're in Mail, check the recipient */
+       /* If we're in Mail, check the recipient */
+       if (CC->quickroom.QRflags & QR_MAILBOX) {
                extract(recp, entargs, 1);
                lprintf(9, "aliasing...\n");
                e=alias(recp);                  /* alias and mail type */
@@ -1194,14 +1116,14 @@ void cmd_dele(char *delstr)
                }
 
        delnum = atol(delstr);
-       if (CC->curr_rm==1) {
+       if (CC->quickroom.QRflags & QR_MAILBOX) {
                cprintf("%d Can't delete mail.\n",ERROR);
                return;
                }
        
        /* get room records, obtaining a lock... */
-       lgetroom(&CC->quickroom,CC->curr_rm);
-       get_msglist(CC->curr_rm);
+       lgetroom(&CC->quickroom,CC->cs_room);
+       get_msglist(&CC->quickroom);
 
        ok = 0;
        if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
@@ -1214,8 +1136,8 @@ void cmd_dele(char *delstr)
        CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
        CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
 
-       put_msglist(CC->curr_rm);
-       lputroom(&CC->quickroom,CC->curr_rm);
+       put_msglist(&CC->quickroom);
+       lputroom(&CC->quickroom,CC->cs_room);
        if (ok==1) {
                cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
                cprintf("%d Message deleted.\n",OK);
@@ -1225,28 +1147,19 @@ void cmd_dele(char *delstr)
 
 
 /*
- * move a message to another room    FIX  Rework this to use name indices
+ * move a message to another room
  */
 void cmd_move(char *args)
 {
        long num;
        char targ[32];
        int a;
-       int targ_slot;
        struct quickroom qtemp;
        int foundit;
-       struct cdbdata *cdbtarg;
-       long *targmsgs;
-       int targ_count;
 
        num = extract_long(args,0);
        extract(targ,args,1);
        
-       if (CC->curr_rm < 0) {
-               cprintf("%d no room\n",ERROR);
-               return;
-               }
-
        getuser(&CC->usersupp,CC->curr_user);
        if ((CC->usersupp.axlevel < 6)
           && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
@@ -1255,22 +1168,14 @@ void cmd_move(char *args)
                return;
                }
 
-       targ_slot = (-1);
-       for (a=0; a<MAXROOMS; ++a) {
-               getroom(&qtemp,a);
-               if (!strcasecmp(qtemp.QRname,targ)) {
-                       targ_slot = a;
-                       a = MAXROOMS;
-                       }
-               }
-       if (targ_slot < 0) {
+       if (getroom(&qtemp, targ) != 0) {
                cprintf("%d '%s' does not exist.\n",ERROR,targ);
                return;
                }
 
        /* yank the message out of the current room... */
-       lgetroom(&CC->quickroom,CC->curr_rm);
-       get_msglist(CC->curr_rm);
+       lgetroom(&CC->quickroom, CC->cs_room);
+       get_msglist(&CC->quickroom);
 
        foundit = 0;
        for (a=0; a<(CC->num_msgs); ++a) {
@@ -1281,37 +1186,16 @@ void cmd_move(char *args)
                }
        if (foundit) {
                CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
-               put_msglist(CC->curr_rm);
+               put_msglist(&CC->quickroom);
                CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
                }
-       lputroom(&CC->quickroom,CC->curr_rm);
+       lputroom(&CC->quickroom,CC->cs_room);
        if (!foundit) {
                cprintf("%d msg %ld does not exist.\n",ERROR,num);
                return;
                }
 
        /* put the message into the target room */
-       lgetroom(&qtemp,targ_slot);
-       cdbtarg = cdb_fetch(CDB_MSGLISTS, &targ_slot, sizeof(int));
-       if (cdbtarg != NULL) {
-               targmsgs = malloc(cdbtarg->len);
-               memcpy(targmsgs, cdbtarg->ptr, cdbtarg->len);
-               targ_count = cdbtarg->len / sizeof(long);
-               cdb_free(cdbtarg);
-               }
-       else {
-               targmsgs = NULL;
-               targ_count = 0;
-               }
 
-       ++targ_count;
-       targmsgs = realloc(targmsgs, ((CC->num_msgs) * sizeof(long)));
-       targmsgs[targ_count - 1] = num;
-       targ_count = sort_msglist(targmsgs, targ_count);
-       qtemp.QRhighest = targmsgs[targ_count - 1];
-       cdb_store(CDB_MSGLISTS, &targ_slot, sizeof(int),
-                       targmsgs, targ_count * sizeof(long));
-       free(targmsgs);
-       lputroom(&qtemp,targ_slot);
-       cprintf("%d ok\n",OK);
+       cprintf("%d FIX FIX FIX implement this!!!!!\n", ERROR);
        }
index 312ae1edc47b2bfcead1632f4077a55bee79051b..913b64f16d4249668f42262d845daf36af774edb 100644 (file)
@@ -20,7 +20,7 @@ void LoadInternetConfig(void);
 void get_config(void);
 struct config config;
 
-char temp[20];
+char temp[32];
 
 char ALIASES[128];
 char CIT86NET[128];
index d410f7f66f09b982a86323d87e8156b1b4324158..a665961e5ab32818758b3e2ea4fbd0bd49961e5b 100644 (file)
 struct msglist {
        struct msglist *next;
        long m_num;
-       char m_rmname[20];
+       char m_rmname[ROOMNAMELEN];
        };
 
 struct rmlist {
        struct rmlist *next;
-       char rm_name[20];
+       char rm_name[ROOMNAMELEN];
        long rm_lastsent;
        };
 
index 1e3df6ffa858877314ade57ba33adc1b0a2c64fb..c16c1cac43bdf9aba23a18f7cdca839ec0cc862d 100644 (file)
@@ -5,6 +5,7 @@
 #include <string.h>
 #include <pthread.h>
 #include <time.h>
+#include <limits.h>
 #include "citadel.h"
 #include "server.h"
 #include "database.h"
@@ -94,88 +95,13 @@ int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
        return(retval);
        }
 
-/*************** START OF OLD ROOM DATABASE FUNCTIONS ***********************/
 /*
  * getroom()  -  retrieve room data from disk
  */
-void getroom(struct quickroom *qrbuf, int room_num)
+int getroom(struct quickroom *qrbuf, char *room_name)
 {
        struct cdbdata *cdbqr;
-       int a;
-
-       bzero(qrbuf, sizeof(struct quickroom));
-       cdbqr = cdb_fetch(CDB_QUICKROOM, &room_num, sizeof(int));
-       if (cdbqr != NULL) {
-               memcpy(qrbuf, cdbqr->ptr,
-                       ( (cdbqr->len > sizeof(struct quickroom)) ?
-                       sizeof(struct quickroom) : cdbqr->len) );
-               cdb_free(cdbqr);
-               }
-       else {
-               if (room_num < 3) {
-                       qrbuf->QRflags = QR_INUSE;
-                       time(&qrbuf->QRgen);
-                       switch(room_num) {
-                               case 0: strcpy(qrbuf->QRname, "Lobby");
-                                       break;
-                               case 1: strcpy(qrbuf->QRname, "Mail");
-                                       break;
-                               case 2: strcpy(qrbuf->QRname, "Aide");
-                                       break;
-                               }
-                       }
-               }
-
-
-       /** FIX **   VILE SLEAZY HACK ALERT!!  
-        * This is a temporary fix until we can track down where room names
-        * are getting corrupted on some systems.
-        */
-       for (a=0; a<20; ++a) if (qrbuf->QRname[a] < 32) qrbuf->QRname[a] = 0;
-       qrbuf->QRname[19] = 0;
-       }
-
-/*
- * lgetroom()  -  same as getroom() but locks the record (if supported)
- */
-void lgetroom(struct quickroom *qrbuf, int room_num)
-{
-       begin_critical_section(S_QUICKROOM);
-       getroom(qrbuf,room_num);
-       }
-
-
-/*
- * putroom()  -  store room data on disk
- */
-void putroom(struct quickroom *qrbuf, int room_num)
-{
-       time(&qrbuf->QRmtime);
-       cdb_store(CDB_QUICKROOM, &room_num, sizeof(int),
-               qrbuf, sizeof(struct quickroom));
-       }
-
-
-/*
- * lputroom()  -  same as putroom() but unlocks the record (if supported)
- */
-void lputroom(struct quickroom *qrbuf, int room_num)
-{
-
-       putroom(qrbuf,room_num);
-       end_critical_section(S_QUICKROOM);
-
-       }
-
-
-/*************** START OF NEW ROOM DATABASE FUNCTIONS ***********************/
-/*
- * ngetroom()  -  retrieve room data from disk
- */
-void ngetroom(struct quickroom *qrbuf, char *room_name)
-{
-       struct cdbdata *cdbqr;
-       char lowercase_name[20];
+       char lowercase_name[ROOMNAMELEN];
        int a;
 
        for (a=0; a<=strlen(room_name); ++a) {
@@ -190,32 +116,29 @@ void ngetroom(struct quickroom *qrbuf, char *room_name)
                        ( (cdbqr->len > sizeof(struct quickroom)) ?
                        sizeof(struct quickroom) : cdbqr->len) );
                cdb_free(cdbqr);
+               return(0);
+               }
+       else {
+               return(1);
                }
-
-       /** FIX **   VILE SLEAZY HACK ALERT!!  
-        * This is a temporary fix until we can track down where room names
-        * are getting corrupted on some systems.
-        */
-       for (a=0; a<20; ++a) if (qrbuf->QRname[a] < 32) qrbuf->QRname[a] = 0;
-       qrbuf->QRname[19] = 0;
        }
 
 /*
- * lngetroom()  -  same as ngetroom() but locks the record (if supported)
+ * lgetroom()  -  same as getroom() but locks the record (if supported)
  */
-void lngetroom(struct quickroom *qrbuf, char *room_name)
+int lgetroom(struct quickroom *qrbuf, char *room_name)
 {
        begin_critical_section(S_QUICKROOM);
-       ngetroom(qrbuf, room_name);
+       return(getroom(qrbuf, room_name));
        }
 
 
 /*
- * nputroom()  -  store room data on disk
+ * putroom()  -  store room data on disk
  */
-void nputroom(struct quickroom *qrbuf, char *room_name)
+void putroom(struct quickroom *qrbuf, char *room_name)
 {
-       char lowercase_name[20];
+       char lowercase_name[ROOMNAMELEN];
        int a;
 
        for (a=0; a<=strlen(room_name); ++a) {
@@ -229,12 +152,12 @@ void nputroom(struct quickroom *qrbuf, char *room_name)
 
 
 /*
- * lnputroom()  -  same as nputroom() but unlocks the record (if supported)
+ * lputroom()  -  same as putroom() but unlocks the record (if supported)
  */
-void lnputroom(struct quickroom *qrbuf, char *room_name)
+void lputroom(struct quickroom *qrbuf, char *room_name)
 {
 
-       nputroom(qrbuf, room_name);
+       putroom(qrbuf, room_name);
        end_critical_section(S_QUICKROOM);
 
        }
@@ -323,9 +246,13 @@ void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
 /*
  * get_msglist()  -  retrieve room message pointers
  */
-void get_msglist(int room_num)
-{
+void get_msglist(struct quickroom *whichroom) {
        struct cdbdata *cdbfr;
+       char dbkey[256];
+       int a;
+
+       sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
+       for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
 
        if (CC->msglist != NULL) {
                free(CC->msglist);
@@ -333,13 +260,7 @@ void get_msglist(int room_num)
        CC->msglist = NULL;
        CC->num_msgs = 0;
 
-       if (room_num != 1) {
-               cdbfr = cdb_fetch(CDB_MSGLISTS, &room_num, sizeof(int));
-               }
-       else {
-               cdbfr = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum,
-                                       sizeof(long));
-               }
+       cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
 
        if (cdbfr == NULL) {
                return;
@@ -355,17 +276,29 @@ void get_msglist(int room_num)
 /*
  * put_msglist()  -  retrieve room message pointers
  */
-void put_msglist(int room_num)
-{
+void put_msglist(struct quickroom *whichroom) {
+       char dbkey[256];
+       int a;
 
-       if (room_num != 1) {
-               cdb_store(CDB_MSGLISTS, &room_num, sizeof(int),
-                       CC->msglist, (CC->num_msgs * sizeof(long)) );
-               }
-       else {
-               cdb_store(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long),
-                       CC->msglist, (CC->num_msgs * sizeof(long)) );
-               }
+       sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
+       for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
+
+       cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
+               CC->msglist, CC->num_msgs * sizeof(long));
+       }
+
+
+/*
+ * delete_msglist()  -  delete room message pointers
+ */
+void delete_msglist(struct quickroom *whichroom) {
+       char dbkey[256];
+       int a;
+
+       sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
+       for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
+
+       cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
        }
 
 
@@ -614,7 +547,7 @@ void cmd_lzrm(char *argbuf)
 
 
 
-void usergoto(int where, int display_result)
+void usergoto(char *where, int display_result)
 {
        int a;
        int new_messages = 0;
@@ -625,8 +558,8 @@ void usergoto(int where, int display_result)
        int newmailcount = 0;
        struct visit vbuf;
 
-       CC->curr_rm=where;
-       getroom(&CC->quickroom,CC->curr_rm);
+       strcpy(CC->cs_room, where);
+       getroom(&CC->quickroom, CC->cs_room);
        lgetuser(&CC->usersupp,CC->curr_user);
        CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
 
@@ -643,7 +576,7 @@ void usergoto(int where, int display_result)
        if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
 
        get_mm();
-       get_msglist(CC->curr_rm);
+       get_msglist(&CC->quickroom);
        for (a=0; a<CC->num_msgs; ++a) {
                if (MessageFromList(a)>0L) {
                        ++total_messages;
@@ -654,7 +587,7 @@ void usergoto(int where, int display_result)
                }
 
 
-       if (CC->curr_rm == 1) rmailflag = 1;
+       if (0) rmailflag = 1; /* FIX to handle mail rooms!!! */
        else rmailflag = 0;
 
        if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
@@ -685,9 +618,10 @@ void usergoto(int where, int display_result)
 void cmd_goto(char *gargs)
 {
        struct quickroom QRscratch;
-       int a,c;
-       int ok, ra;
-       char bbb[20],towhere[32],password[20];
+       int c;
+       int ok = 0;
+       int ra;
+       char bbb[ROOMNAMELEN],towhere[32],password[20];
 
        if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
                cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
@@ -700,56 +634,46 @@ void cmd_goto(char *gargs)
        c=0;
        getuser(&CC->usersupp,CC->curr_user);
 
-       /* FIX  This is the primary bit of code that needs to be rewritten
-        * during the cutover.  Search for rooms by name rather than by
-        * position in the file.  A total rewrite may be necessary.
-        */
-       for (a=0; a<MAXROOMS; ++a) {
-               getroom(&QRscratch,a);
-               if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
-                       strncpy(towhere,QRscratch.QRname,31);
-                       }
-               if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
-                       strncpy(towhere,QRscratch.QRname,31);
-                       }
-               if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
-                  &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
-                       strncpy(towhere,QRscratch.QRname,31);
-                       }
-               strcpy(bbb,QRscratch.QRname);
-               ok = 0;
+       if (!strcasecmp(towhere, "_BASEROOM_"))
+               strcpy(towhere, BASEROOM);
 
-               /* let internal programs go directly to any room */
-               if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
-                       usergoto(a,1);
-                       return;
-                       }
+       if (!strcasecmp(towhere, "_MAIL_"))
+               strcpy(towhere, MAILROOM);
 
-               if (!strcasecmp(bbb, towhere)) {
+       if (!strcasecmp(towhere, "_BITBUCKET_"))
+               strcpy(towhere, config.c_twitroom);
 
-                       /* See if there is an existing user/room relationship */
-                       ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
-       
-                       /* normal clients have to pass through security */
-                       if (ra & UA_GOTOALLOWED) ok = 1;
-       
-                       if (ok==1) {
-                               if (  (QRscratch.QRflags&QR_PASSWORDED) &&
-                                       ((ra & UA_KNOWN) == 0) &&
-                                       (strcasecmp(QRscratch.QRpasswd,password))
-                                       ) {
-                                               cprintf("%d wrong or missing passwd\n",
-                                                       ERROR+PASSWORD_REQUIRED);
-                                               return;
-                                               }
-                               else {
-                                       usergoto(a,1);
+
+       /* let internal programs go directly to any room */
+       if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
+               usergoto(towhere, 1);
+               return;
+               }
+
+       if (getroom(&QRscratch, towhere) == 0) {
+
+               /* See if there is an existing user/room relationship */
+               ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
+
+               /* normal clients have to pass through security */
+               if (ra & UA_GOTOALLOWED) ok = 1;
+
+               if (ok==1) {
+                       if (  (QRscratch.QRflags&QR_PASSWORDED) &&
+                               ((ra & UA_KNOWN) == 0) &&
+                               (strcasecmp(QRscratch.QRpasswd,password))
+                               ) {
+                                       cprintf("%d wrong or missing passwd\n",
+                                               ERROR+PASSWORD_REQUIRED);
                                        return;
                                        }
+                       else {
+                               usergoto(towhere, 1);
+                               return;
                                }
                        }
                }
-       
+
        cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
        }
 
@@ -800,8 +724,8 @@ void cmd_rdir(void) {
                return;
                }
 
-       getroom(&CC->quickroom,CC->curr_rm);
-       getuser(&CC->usersupp,CC->curr_user);
+       getroom(&CC->quickroom, CC->cs_room);
+       getuser(&CC->usersupp, CC->curr_user);
 
        if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
                cprintf("%d not here.\n",ERROR+NOT_HERE);
@@ -868,12 +792,13 @@ void cmd_getr(void) {
                return;
                }
 
-       if (CC->curr_rm < 3) {
+       if ( (!strcasecmp(CC->cs_room, BASEROOM))
+            || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
                cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
                return;
                }
 
-       getroom(&CC->quickroom,CC->curr_rm);
+       getroom(&CC->quickroom, CC->cs_room);
        cprintf("%d%c%s|%s|%s|%d|%d\n",
                OK,check_express(),
                CC->quickroom.QRname,
@@ -903,7 +828,8 @@ void cmd_setr(char *args) {
                return;
                }
 
-       if (CC->curr_rm < 3) {
+       if ( (!strcasecmp(CC->cs_room, BASEROOM))
+            || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
                cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
                return;
                }
@@ -917,9 +843,9 @@ void cmd_setr(char *args) {
                        }
                }
 
-       lgetroom(&CC->quickroom,CC->curr_rm);
-       extract(buf,args,0); buf[20]=0;
-       strncpy(CC->quickroom.QRname,buf,19);
+       lgetroom(&CC->quickroom, CC->cs_room);
+       extract(buf,args,0); buf[ROOMNAMELEN]=0;
+       strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
        extract(buf,args,1); buf[10]=0;
        strncpy(CC->quickroom.QRpasswd,buf,9);
        extract(buf,args,2); buf[15]=0;
@@ -946,7 +872,7 @@ void cmd_setr(char *args) {
                CC->quickroom.QRfloor = extract_int(args,5);
                }
 
-       lputroom(&CC->quickroom,CC->curr_rm);
+       lputroom(&CC->quickroom, CC->cs_room);
 
        /* adjust the floor reference counts */
        lgetfloor(&flbuf,old_floor);
@@ -982,8 +908,9 @@ void cmd_geta(void) {
                return;
                }
 
-       if (CC->curr_rm < 0) {
-               cprintf("%d No current room.\n",ERROR);
+       if ( (!strcasecmp(CC->cs_room, BASEROOM))
+            || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
+               cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
                return;
                }
 
@@ -1017,11 +944,6 @@ void cmd_seta(char *new_ra)
                return;
                }
 
-       if (CC->curr_rm < 3) {
-               cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
-               return;
-               }
-
        if (getuser(&usbuf,new_ra)!=0) {
                newu = (-1L);
                }
@@ -1029,13 +951,13 @@ void cmd_seta(char *new_ra)
                newu = usbuf.usernum;
                }
 
-       lgetroom(&CC->quickroom,CC->curr_rm);
+       lgetroom(&CC->quickroom, CC->cs_room);
        post_notice = 0;
        if (CC->quickroom.QRroomaide != newu) {
                post_notice = 1;
                }
        CC->quickroom.QRroomaide = newu;
-       lputroom(&CC->quickroom,CC->curr_rm);
+       lputroom(&CC->quickroom, CC->cs_room);
 
        /*
         * We have to post the change notice _after_ writing changes to 
@@ -1049,16 +971,27 @@ void cmd_seta(char *new_ra)
        cprintf("%d Ok\n",OK);
        }
 
+/*
+ * Generate an associated file name for a room
+ */
+void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
+       int a;
+
+       sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
+       for (a=0; a<strlen(buf); ++a) {
+               if (buf[a]==32) buf[a]='.';
+               }
+       }
 
 /* 
  * retrieve info file for this room
  */
 void cmd_rinf(void) {
-       char filename[64];
+       char filename[128];
        char buf[256];
        FILE *info_fp;
        
-       sprintf(filename,"./info/%d",CC->curr_rm);
+       assoc_file_name(filename, &CC->quickroom, "info");
        info_fp = fopen(filename,"r");
 
        if (info_fp==NULL) {
@@ -1099,30 +1032,39 @@ void cmd_kill(char *argbuf)
                return;
                }
 
-       if (CC->curr_rm < 3) {
-               cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
+       if ( (!strcasecmp(CC->cs_room, BASEROOM))
+            || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
+               cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
                return;
                }
 
        if (kill_ok) {
 
+               /* Delete the info file */
+               assoc_file_name(aaa, &CC->quickroom, "info");
+               unlink(aaa);
+
                /* first flag the room record as not in use */
-               lgetroom(&CC->quickroom,CC->curr_rm);
+               lgetroom(&CC->quickroom, CC->cs_room);
                CC->quickroom.QRflags=0;
 
                /* then delete the messages in the room */
-               get_msglist(CC->curr_rm);
+               get_msglist(&CC->quickroom);
                if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
                        MsgToDelete = MessageFromList(a);
                        cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
                        }
-               put_msglist(CC->curr_rm);
+               put_msglist(&CC->quickroom);
                free(CC->msglist);
                CC->num_msgs = 0;
-               cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
-
-               lputroom(&CC->quickroom,CC->curr_rm);
+               delete_msglist(&CC->quickroom);
+               lputroom(&CC->quickroom, CC->cs_room);
 
+               /*    FIX FIX FIX
+                * To do at this location in the code:
+                * 1. Delete the associated files (info, image)
+                * 2. Delete the room record from the database
+                */ 
 
                /* then decrement the reference count for the floor */
                lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
@@ -1132,7 +1074,7 @@ void cmd_kill(char *argbuf)
                /* tell the world what we did */
                sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
                aide_message(aaa);
-               CC->curr_rm=(-1);
+               usergoto(BASEROOM, 0);
                cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
                }
        else {
@@ -1142,43 +1084,29 @@ void cmd_kill(char *argbuf)
 
 
 /*
- * Find a free slot to create a new room in, or return -1 for error.
- * search_dir is the direction to search in.  1 causes this function to
- * return the first available slot, -1 gets the last available slot.
+ * Internal code to create a new room (returns room flags)
  *
- * FIX   This function can be eliminated during the cutover.
+ * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
  */
-int get_free_room_slot(int search_dir)
-{
-       int a,st;
-       struct quickroom qrbuf;
-
-       st = ((search_dir>0) ? 3 : (MAXROOMS-1));
-
-       for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
-               getroom(&qrbuf,a);
-               if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
-               }
-       return(-1);
-       }
+unsigned create_room(char *new_room_name,
+                       int new_room_type,
+                       char *new_room_pass,
+                       int new_room_floor) {
 
-
-/*
- * internal code to create a new room (returns room flags)
- */
-unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
-{
        struct quickroom qrbuf;
        struct floor flbuf;
        struct visit vbuf;
 
-       lgetroom(&qrbuf,free_slot);
-       strncpy(qrbuf.QRname,new_room_name,19);
+       if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
+
+       bzero(&qrbuf, sizeof(struct quickroom));
+       strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
        strncpy(qrbuf.QRpasswd,new_room_pass,9);
        qrbuf.QRflags = QR_INUSE;
        if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
        if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
        if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
+       if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
        qrbuf.QRroomaide = (-1L);
        if ((new_room_type > 0)&&(CREATAIDE==1))
                qrbuf.QRroomaide=CC->usersupp.usernum;
@@ -1187,7 +1115,7 @@ unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char
        qrbuf.QRfloor = new_room_floor;
 
        /* save what we just did... */
-       lputroom(&qrbuf,free_slot);
+       putroom(&qrbuf, qrbuf.QRname);
 
        /* bump the reference count on whatever floor the room is on */
        lgetfloor(&flbuf,(int)qrbuf.QRfloor);
@@ -1208,13 +1136,11 @@ unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char
 
 
 /*
- * create a new room        FIX  Rework this to use name indexing
+ * create a new room
  */
 void cmd_cre8(char *args)
 {
        int cre8_ok;
-       int free_slot;
-       int a;
        char new_room_name[256];
        int new_room_type;
        char new_room_pass[256];
@@ -1226,7 +1152,7 @@ void cmd_cre8(char *args)
 
        cre8_ok = extract_int(args,0);
        extract(new_room_name,args,1);
-       new_room_name[19] = 0;
+       new_room_name[ROOMNAMELEN-1] = 0;
        new_room_type = extract_int(args,2);
        extract(new_room_pass,args,3);
        new_room_pass[9] = 0;
@@ -1260,34 +1186,29 @@ void cmd_cre8(char *args)
                return;
                }
 
-       free_slot = get_free_room_slot(1);
-       if (free_slot<0) {
-               cprintf("%d There is no space available for a new room.\n",
-                       ERROR);
+       if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
+               cprintf("%d Ok to create rooms.\n", OK);
                return;
                }
 
-       if (cre8_ok==0) {
-               cprintf("%d ok to create...\n",OK);
+       /* Check to make sure the requested room name doesn't already exist */
+       if (getroom(&qrbuf, new_room_name)==0) {
+               cprintf("%d '%s' already exists.\n",
+                       ERROR,qrbuf.QRname);
                return;
                }
 
-       for (a=0; a<MAXROOMS; ++a) {
-               getroom(&qrbuf,a);
-               if ( (!strcasecmp(qrbuf.QRname,new_room_name))
-                  && (qrbuf.QRflags & QR_INUSE) ) {
-                       cprintf("%d '%s' already exists.\n",
-                               ERROR,qrbuf.QRname);
-                       return;
-                       }
-               }
-
        if ((new_room_type < 0) || (new_room_type > 3)) {
                cprintf("%d Invalid room type.\n",ERROR);
                return;
                }
 
-       newflags = create_room(free_slot,new_room_name,
+       if (cre8_ok == 0) {
+               cprintf("%d OK to create '%s'\n", OK, new_room_name);
+               return;
+               }
+
+       newflags = create_room(new_room_name,
                        new_room_type,new_room_pass,new_room_floor);
 
        /* post a message in Aide> describing the new room */
@@ -1302,11 +1223,6 @@ void cmd_cre8(char *args)
                }
        aide_message(aaa); 
 
-       sprintf(aaa,"./info/%d",free_slot);     /* delete old info file */
-       unlink(aaa);    
-       sprintf(aaa,"./images/room.%d.gif",free_slot);  /* and picture */
-       unlink(aaa);    
-
        cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
        }
 
@@ -1315,7 +1231,7 @@ void cmd_cre8(char *args)
 void cmd_einf(char *ok)
 {      /* enter info file for current room */
        FILE *fp;
-       char infofilename[32];
+       char infofilename[64];
        char buf[256];
 
        if (!(CC->logged_in)) {
@@ -1336,7 +1252,7 @@ void cmd_einf(char *ok)
 
        cprintf("%d Send info...\n",SEND_LISTING);
 
-       sprintf(infofilename,"./info/%d",CC->curr_rm);
+       assoc_file_name(infofilename, &CC->quickroom, "info");
 
        fp=fopen(infofilename,"w");
        do {
@@ -1346,9 +1262,9 @@ void cmd_einf(char *ok)
        fclose(fp);
 
        /* now update the room index so people will see our new info */
-       lgetroom(&CC->quickroom,CC->curr_rm);   /* lock so no one steps on us */
+       lgetroom(&CC->quickroom,CC->cs_room); /* lock so no one steps on us */
        CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
-       lputroom(&CC->quickroom,CC->curr_rm);
+       lputroom(&CC->quickroom,CC->cs_room);
        }
 
 
index 88e92cabd8a9e2fb57831d496ac073991ce3ee34..1b3ea9536f8ec573975f6c425c3238e7752e757f 100644 (file)
@@ -4,16 +4,16 @@ int has_newmsgs (struct quickroom *roombuf, int roomnum,
                 struct usersupp *userbuf);
 int is_zapped (struct quickroom *roombuf, int roomnum,
               struct usersupp *userbuf);
-void getroom (struct quickroom *qrbuf, int room_num);
-void lgetroom (struct quickroom *qrbuf, int room_num);
-void putroom (struct quickroom *qrbuf, int room_num);
-void lputroom (struct quickroom *qrbuf, int room_num);
+int getroom(struct quickroom *qrbuf, char *room_name);
+void putroom(struct quickroom *qrbuf, char *room_name);
+int lgetroom(struct quickroom *qrbuf, char *room_name);
+void lputroom(struct quickroom *qrbuf, char *room_name);
 void getfloor (struct floor *flbuf, int floor_num);
 void lgetfloor (struct floor *flbuf, int floor_num);
 void putfloor (struct floor *flbuf, int floor_num);
 void lputfloor (struct floor *flbuf, int floor_num);
-void get_msglist (int room_num);
-void put_msglist (int room_num);
+void get_msglist (struct quickroom *whichroom);
+void put_msglist (struct quickroom *whichroom);
 long int MessageFromList (int whichpos);
 void SetMessageInList (int whichpos, long int newmsgnum);
 int sort_msglist (long int *listptrs, int oldcount);
@@ -22,7 +22,7 @@ void cmd_lkra (char *argbuf);
 void cmd_lkrn (char *argbuf);
 void cmd_lkro (char *argbuf);
 void cmd_lzrm (char *argbuf);
-void usergoto (int where, int display_result);
+void usergoto (char *where, int display_result);
 void cmd_goto (char *gargs);
 void cmd_whok (void);
 void cmd_rdir (void);
@@ -32,10 +32,10 @@ void cmd_geta (void);
 void cmd_seta (char *new_ra);
 void cmd_rinf (void);
 void cmd_kill (char *argbuf);
-int get_free_room_slot (int search_dir);
-unsigned int create_room (int free_slot, char *new_room_name,
-                         int new_room_type, char *new_room_pass,
-                         int new_room_floor);
+unsigned create_room(char *new_room_name,
+                       int new_room_type,
+                       char *new_room_pass,
+                       int new_room_floor);
 void cmd_cre8 (char *args);
 void cmd_einf (char *ok);
 void cmd_lflr (void);
@@ -43,3 +43,4 @@ void cmd_cflr (char *argbuf);
 void cmd_kflr (char *argbuf);
 void cmd_eflr (char *argbuf);
 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom));
+void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix);
index c2d76ddae4ee56eebe03db5afd6ed94cda890e10..d16e43e3326cc91e17321c4e72461a48cab85e8c 100644 (file)
@@ -255,7 +255,7 @@ int select_floor(int rfloor)
  * .<A>ide <E>dit room
  */
 void editthisroom(void) {
-       char rname[20];
+       char rname[ROOMNAMELEN];
        char rpass[10];
        char rdir[15];
        unsigned rflags;
@@ -284,7 +284,7 @@ void editthisroom(void) {
        else strcpy(raide,"");
        if (strlen(raide)==0) strcpy(raide,"none");
 
-       strprompt("Room name",rname,19);
+       strprompt("Room name",rname,ROOMNAMELEN-1);
 
        rfloor = select_floor(rfloor);
        rflags = set_room_attr(rflags,"Private room",QR_PRIVATE);
@@ -331,7 +331,7 @@ void editthisroom(void) {
        if ( (rflags & QR_ANONONLY) == 0) {
                rflags = set_room_attr(rflags,
                        "Ask users whether to make messages anonymous",
-                       QR_ANON2);
+                       QR_ANONOPT);
                }
 
        do {
@@ -690,7 +690,7 @@ void forget(void) { /* forget the current room */
  */
 void entroom(void) {
        char cmd[256];
-       char new_room_name[20];
+       char new_room_name[ROOMNAMELEN];
        int new_room_type;
        char new_room_pass[10];
        int new_room_floor;
@@ -704,7 +704,7 @@ void entroom(void) {
                return;
                }
        
-       newprompt("Name for new room? ",new_room_name,19);
+       newprompt("Name for new room? ",new_room_name,ROOMNAMELEN-1);
        if (strlen(new_room_name)==0) return;
        for (a=0; a<strlen(new_room_name); ++a)
                if (new_room_name[a] == '|') new_room_name[a]='_';
index 1ec9ce2fba978eb3ab2b4b7f9df51c20a0b8b922..b75124c209875cd212f152579d6092d59b5683d2 100644 (file)
@@ -514,12 +514,12 @@ void netsendfile(void) {
  */
 void movefile(void) {
        char filename[64];
-       char newroom[20];
+       char newroom[ROOMNAMELEN];
        char cmd[256];
 
        newprompt("Filename: ",filename,63);
        if (strlen(filename)==0) return;
-       newprompt("Enter target room: ",newroom,19);
+       newprompt("Enter target room: ",newroom,ROOMNAMELEN-1);
 
        sprintf(cmd,"MOVF %s|%s",filename,newroom);
        serv_puts(cmd);
index e9182d347236d3b4e52a61dba64a10f34025748f..f11aec85bbb83ffa5b303e58b9f848d3cd7290de 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/time.h>
 #include <sys/wait.h>
 #include <string.h>
+#include <limits.h>
 #include <pthread.h>
 #include "citadel.h"
 #include "server.h"
@@ -95,7 +96,7 @@ void allwrite(char *cmdbuf, int flag, char *roomname, char *username)
        time(&now);
        clnew->next = NULL;
        clnew->chat_time = now;
-       strncpy(clnew->chat_room, roomname, 19);
+       strncpy(clnew->chat_room, roomname, ROOMNAMELEN-1);
        if (username)
           strncpy(clnew->chat_username, username, 31); 
        else
@@ -195,7 +196,7 @@ void cmd_chat(char *argbuf)
        char cmdbuf[256];
        char *un;
        char *strptr1;
-       char hold_cs_room[20];
+       char hold_cs_room[ROOMNAMELEN];
        int MyLastMsg, ThisLastMsg;
        struct ChatLine *clptr;
        struct CitContext *t_context;
@@ -308,7 +309,7 @@ void cmd_chat(char *argbuf)
                              strcpy(CC->chat_room, "Main room");
                           else
                           {
-                             strncpy(CC->chat_room, &cmdbuf[6], 20);
+                             strncpy(CC->chat_room, &cmdbuf[6], ROOMNAMELEN);
                           }
                           allwrite("<joining room>",0, CC->chat_room, NULL);
                           cprintf("\n");
@@ -337,7 +338,7 @@ void cmd_chat(char *argbuf)
                        {
                           if ((clptr->chat_seq > MyLastMsg) && ((!clptr->chat_username[0]) || (!strncasecmp(un, clptr->chat_username, 32))))
                           {
-                             if ((!clptr->chat_room[0]) || (!strncasecmp(CC->chat_room, clptr->chat_room, 20)))
+                             if ((!clptr->chat_room[0]) || (!strncasecmp(CC->chat_room, clptr->chat_room, ROOMNAMELEN)))
                              {
                                 cprintf("%s\n", clptr->chat_text);
                              }
index 8b8c5383529772c32cf11823ec1fca163ca3108f..dc7915a599b0de295543fd38c0efd02d60e97863 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/time.h>
 #include <sys/wait.h>
 #include <string.h>
+#include <limits.h>
 #include <pthread.h>
 #include "citadel.h"
 #include "server.h"
index 86713b2cb53ecd04bb975cf67f2dba45ef06ed0a..615ec37370b59bfec17d16b81e3f87683e898c4d 100644 (file)
@@ -1,4 +1,3 @@
-
 typedef pthread_t THREAD;
 
 
@@ -26,7 +25,6 @@ struct CitContext {
        int num_msgs;
 
         char curr_user[32];            /* name of current user */
-        int curr_rm;                   /* index of current room */
         int logged_in;                 /* logged in */
         int internal_pgm;              /* authenticated as internal program */
         char temp[32];                 /* temp file name */
index ee1ccac687d73aef5e6bf0307185f53776d987e4..6726a7fd0635082e68db3760d87ad4b4c11fd8f2 100644 (file)
@@ -54,8 +54,7 @@
 
 /*** STRUCTURE SIZE VARIABLES ***/
 
-/* You may NOT change these values once you set up your system.            */
-#define MAXROOMS       128             /* Number of rooms in system        */
+/* You may NOT change this value once you set up your system.      */
 #define MAXFLOORS      16              /* Do not set higher than 127       */
 
 /*** END OF STRUCTURE SIZE VARIABLES ***/
index 1220155690896468ff7673d47196ad43c0db0945..9f5adf9bf1e80cfb1232d8b92f0a7f5032630f82 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/wait.h>
 #include <sys/socket.h>
 #include <sys/time.h>
+#include <limits.h>
 #include <netinet/in.h>
 #include <netdb.h>
 #include <string.h>
index 6a18dcf517968be82c0b4ee77ce38186522cc2fc..4efd6b7f0c2e488a9441693f6889ed697cf9d78d 100644 (file)
@@ -196,7 +196,12 @@ void CtdlGetRelationship(struct visit *vbuf,
        
        free(visits);
        }
-       
+
+
+void MailboxName(char *buf, struct usersupp *who, char *prefix) {
+       sprintf(buf, "%010ld.%s", who->usernum, prefix);
+       }
+
        
 /*
  * Is the user currently logged in an Aide?
@@ -323,7 +328,7 @@ void session_startup(void) {
        cprintf("%d %s|%d|%d|%d|%u|%ld\n",OK,CC->usersupp.fullname,CC->usersupp.axlevel,
                CC->usersupp.timescalled,CC->usersupp.posted,CC->usersupp.flags,
                CC->usersupp.usernum);
-       usergoto(0,0);          /* Enter the lobby */   
+       usergoto(BASEROOM,0);           /* Enter the lobby */   
        rec_log(CL_LOGIN,CC->curr_user);
        }
 
@@ -461,6 +466,7 @@ int create_user(char *newusername)
        int a;
        struct passwd *p = NULL;
        char username[64];
+       char mailboxname[ROOMNAMELEN];
 
        strcpy(username, newusername);
        strproc(username);
@@ -517,6 +523,11 @@ int create_user(char *newusername)
        if (getuser(&CC->usersupp,CC->curr_user)) {
                return(ERROR+INTERNAL_ERROR);
                }
+       
+       /* give the user a private mailbox */
+       MailboxName(mailboxname, &CC->usersupp, MAILROOM);
+       create_room(mailboxname, 4, "", 0);
+
        rec_log(CL_NEWUSER,CC->curr_user);
        return(0);
        }
@@ -661,16 +672,8 @@ void cmd_slrp(char *new_ptr)
                return;
                }
 
-       if (CC->curr_rm < 0) {
-               cprintf("%d No current room.\n",ERROR);
-               return;
-               }
-
        if (!strncasecmp(new_ptr,"highest",7)) {
                newlr = CC->quickroom.QRhighest;
-/* FIX ... if the current room is 1 (Mail), newlr needs to be set to the
- * number of the highest mail message
- */
                }
        else {
                newlr = atol(new_ptr);
@@ -702,11 +705,6 @@ void cmd_invt_kick(char *iuser, int op)
                return;
                }
 
-       if (CC->curr_rm < 0) {
-               cprintf("%d No current room.\n",ERROR);
-               return;
-               }
-
        if (is_room_aide()==0) {
                cprintf("%d Higher access required.\n",
                        ERROR+HIGHER_ACCESS_REQUIRED);
@@ -770,16 +768,6 @@ void cmd_forg(void) {
                return;
                }
 
-       if (CC->curr_rm < 0) {
-               cprintf("%d No current room.\n",ERROR);
-               return;
-               }
-
-       if (CC->curr_rm < 3) {
-               cprintf("%d You cannot forget this room.\n",ERROR+NOT_HERE);
-               return;
-               }
-
        if (is_aide()) {
                cprintf("%d Aides cannot forget rooms.\n",ERROR);
                return;
@@ -793,7 +781,7 @@ void cmd_forg(void) {
        CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
        lputuser(&CC->usersupp,CC->curr_user);
        cprintf("%d Ok\n",OK);
-       CC->curr_rm = (-1);
+       usergoto(BASEROOM, 0);
        }
 
 /*
@@ -1304,8 +1292,14 @@ int NewMailCount() {
        int num_mails;
        long *mailbox;
        int a;
+       char mailboxname[32];
+
+       MailboxName(mailboxname, &CC->usersupp, MAILROOM);
+       for (a=0; a<=strlen(mailboxname); ++a) {
+               mailboxname[a] = tolower(mailboxname[a]);
+               }
 
-       cdbmb = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long));
+       cdbmb = cdb_fetch(CDB_MAILBOXES, mailboxname, strlen(mailboxname));
        if (cdbmb != NULL) {
                num_mails = cdbmb->len / sizeof(long);
                mailbox = (long *) cdbmb->ptr;