From 91092ca4a95027230b5090cc8889b0bce61d2042 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 18 Nov 1998 03:38:30 +0000 Subject: [PATCH] Started implementing global room numbers. --- citadel/ChangeLog | 3 +++ citadel/citadel.h | 2 ++ citadel/control.c | 14 ++++++++++++++ citadel/control.h | 1 + citadel/room_ops.c | 31 +++++++------------------------ citadel/serv_upgrade.c | 3 +++ 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 951b9cce0..3e2c02cd3 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,3 +1,6 @@ +Tue Nov 17 22:37:48 EST 1998 Art Cancro + * Started implementing global room numbers. + Sun Nov 15 20:32:34 EST 1998 Art Cancro * room_ops.c: mailbox rooms always appear on the main floor * made QR_MAILBOX rooms non-editable diff --git a/citadel/citadel.h b/citadel/citadel.h index e4d82e0a2..f18162ef1 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -120,6 +120,7 @@ struct CitControl { long MMhighest; /* highest message number in file */ unsigned MMflags; /* Global system flags */ long MMnextuser; /* highest user number on system */ + long MMnextroom; /* highest room number on system */ }; /* Bits which may appear in CitControl.MMflags. Note that these don't @@ -143,6 +144,7 @@ struct quickroom { char QRfloor; /* Which floor this room is on */ time_t QRmtime; /* Date/time of last post */ struct ExpirePolicy QRep; /* Message expiration policy */ + long QRnumber; /* Globally unique room number */ }; diff --git a/citadel/control.c b/citadel/control.c index d6623b999..f902bb169 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -88,6 +88,20 @@ long get_new_user_number(void) { +/* + * get_new_room_number() - Obtain a new, unique ID to be used for a room. + */ +long get_new_room_number(void) { + begin_critical_section(S_CONTROL); + get_control(); + ++CitControl.MMnextroom; + put_control(); + end_critical_section(S_CONTROL); + return(CitControl.MMnextroom); + } + + + /* * Get or set global configuration options */ diff --git a/citadel/control.h b/citadel/control.h index 04f73036f..2c8fee8d6 100644 --- a/citadel/control.h +++ b/citadel/control.h @@ -3,4 +3,5 @@ void get_control (void); void put_control (void); long int get_new_message_number (void); long int get_new_user_number (void); +long int get_new_room_number (void); void cmd_conf(char *argbuf); diff --git a/citadel/room_ops.c b/citadel/room_ops.c index e0ab0b5ae..7b306ae58 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -18,6 +18,7 @@ #include "msgbase.h" #include "serv_chat.h" #include "citserver.h" +#include "control.h" /* * Generic routine for determining user access to rooms @@ -278,32 +279,19 @@ void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) { -/* - * Create a database key for storage of message lists - */ -void msglist_key(char *dbkey, struct quickroom *whichroom) { - int a; - - sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen); - for (a=0; amsglist != NULL) { free(CC->msglist); } CC->msglist = NULL; CC->num_msgs = 0; - cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey)); + cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long)); if (cdbfr == NULL) { return; } @@ -319,10 +307,8 @@ void get_msglist(struct quickroom *whichroom) { * put_msglist() - retrieve room message pointers */ void put_msglist(struct quickroom *whichroom) { - char dbkey[256]; - msglist_key(dbkey, whichroom); - cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey), + cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long), CC->msglist, CC->num_msgs * sizeof(long)); } @@ -335,10 +321,8 @@ void put_msglist(struct quickroom *whichroom) { * like "gdbm: illegal data" (no big deal, but could use fixing). */ void delete_msglist(struct quickroom *whichroom) { - char dbkey[256]; - msglist_key(dbkey, whichroom); - cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey)); + cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long)); } @@ -349,13 +333,11 @@ void delete_msglist(struct quickroom *whichroom) { * may not be the current room (as is the case with cmd_move() for example). */ void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) { - char dbkey[256]; struct cdbdata *cdbfr; int num_msgs; long *msglist; - msglist_key(dbkey, whichroom); - cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey)); + cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long)); if (cdbfr == NULL) { msglist = NULL; num_msgs = 0; @@ -379,7 +361,7 @@ void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) { msglist[num_msgs - 1] = newmsgid; /* Write it back to disk. */ - cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey), + cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long), msglist, num_msgs * sizeof(long)); /* And finally, free up the memory we used. */ @@ -1260,6 +1242,7 @@ unsigned create_room(char *new_room_name, strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN); strncpy(qrbuf.QRpasswd,new_room_pass,9); qrbuf.QRflags = QR_INUSE; + qrbuf.QRnumber = get_new_room_number(); 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); diff --git a/citadel/serv_upgrade.c b/citadel/serv_upgrade.c index c5a5af080..c8c395b95 100644 --- a/citadel/serv_upgrade.c +++ b/citadel/serv_upgrade.c @@ -341,6 +341,8 @@ void imp_globals(void) { CitControl.MMhighest = atol(value); if (!strcasecmp(key, "mmnextuser")) CitControl.MMnextuser = atol(value); + if (!strcasecmp(key, "mmnextroom")) + CitControl.MMnextroom = atol(value); } put_control(); @@ -693,6 +695,7 @@ void do_export(char *argbuf) { fprintf(exfp, "globals%c", 0); fprintf(exfp, "mmhighest%c%ld%c", 0, CitControl.MMhighest, 0); fprintf(exfp, "mmnextuser%c%ld%c", 0, CitControl.MMnextuser, 0); + fprintf(exfp, "mmnextroom%c%ld%c", 0, CitControl.MMnextroom, 0); fprintf(exfp, "mmflags%c%d%c", 0, CitControl.MMflags, 0); fprintf(exfp, "endsection%c", 0); -- 2.30.2