From db96f0d5e16098e0087d5c179cc5fd90453581f9 Mon Sep 17 00:00:00 2001 From: Dave West Date: Sun, 25 Oct 2009 22:05:03 +0000 Subject: [PATCH] A little more with the API coding style. Also added following functions CtdlGetFloorByName Gets floor by name. Return -1 if not found. CtdlGetFloorByNameLock As above but locks the floors. CtdlGetAvailableFloor Returns number of first unused floor. These functions make use of the floor cache for performance. The idea is if you want to create a floor you first check that the name is available with CtdlGetFloorByNameLock If the name is available you get -1 back and you then do CtdlGetAvailableFloor Now you have a floor number to use so you can CtdlGetFloor and fill in the structure information before doing CtdlPutFloorLock --- citadel/include/ctdl_module.h | 10 +++++ citadel/msgbase.h | 2 - citadel/room_ops.c | 71 ++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index 9c66304a5..71fa15534 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -225,6 +225,10 @@ struct floor *CtdlGetCachedFloor(int floor_num); void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf); void CtdlGetFloor (struct floor *flbuf, int floor_num); void CtdlPutFloor (struct floor *flbuf, int floor_num); +void CtdlPutFloorLock(struct floor *flbuf, int floor_num); +int CtdlGetFloorByName(const char *floor_name); +int CtdlGetFloorByNameLock(const char *floor_name); +int CtdlGetAvailableFloor(void); int CtdlIsNonEditable(struct ctdlroom *qrbuf); void CtdlPutRoom(struct ctdlroom *); @@ -292,4 +296,10 @@ void CtdlSetRelationship(struct visit *newvisit, void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix); +/* + * Expose API calls from msgbase.c + */ +char *CtdlGetSysConfig(char *sysconfname); +void CtdlPutSysConfig(char *sysconfname, char *sysconfdata); + #endif /* CTDL_MODULE_H */ diff --git a/citadel/msgbase.h b/citadel/msgbase.h index 999f46138..67470b23b 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -146,8 +146,6 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms int do_repl_check, struct CtdlMessage *supplied_msg); int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg); char *CtdlReadMessageBody(char *terminator, size_t maxlen, char *exist, int crlf, int sock); -char *CtdlGetSysConfig(char *sysconfname); -void CtdlPutSysConfig(char *sysconfname, char *sysconfdata); int CtdlOutputMsg(long msg_num, /* message number (local) to fetch */ int mode, /* how would you like that message? */ int headers_only, /* eschew the message body? */ diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 386c3c994..5c2dec0c3 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -344,6 +344,62 @@ void CtdlPutRoomLock(struct ctdlroom *qrbuf) /****************************************************************************/ + +/* + * CtdlGetFloorByName() - retrieve the number of the named floor + * return < 0 if not found else return floor number + */ +int CtdlGetFloorByName(const char *floor_name) +{ + int a; + struct floor *flbuf = NULL; + + for (a = 0; a < MAXFLOORS; ++a) { + flbuf = CtdlGetCachedFloor(a); + + /* check to see if it already exists */ + if ((!strcasecmp(flbuf->f_name, floor_name)) + && (flbuf->f_flags & F_INUSE)) { + return a; + } + } + return -1; +} + + + +/* + * CtdlGetFloorByNameLock() - retrieve floor number for given floor and lock the floor list. + */ +int CtdlGetFloorByNameLock(const char *floor_name) +{ + begin_critical_section(S_FLOORTAB); + return CtdlGetFloorByName(floor_name); +} + + + +/* + * CtdlGetAvailableFloor() - Return number of first unused floor + * return < 0 if none available + */ +int CtdlGetAvailableFloor(void) +{ + int a; + struct floor *flbuf = NULL; + + for (a = 0; a < MAXFLOORS; a++) { + flbuf = CtdlGetCachedFloor(a); + + /* check to see if it already exists */ + if ((flbuf->f_flags & F_INUSE) == 0) { + return a; + } + } + return -1; +} + + /* * CtdlGetFloor() - retrieve floor data from disk */ @@ -438,10 +494,11 @@ void CtdlPutFloor(struct floor *flbuf, int floor_num) } + /* - * lputfloor() - same as CtdlPutFloor() but unlocks the record (if supported) + * CtdlPutFloorLock() - same as CtdlPutFloor() but unlocks the record (if supported) */ -void lputfloor(struct floor *flbuf, int floor_num) +void CtdlPutFloorLock(struct floor *flbuf, int floor_num) { CtdlPutFloor(flbuf, floor_num); @@ -450,6 +507,16 @@ void lputfloor(struct floor *flbuf, int floor_num) } + +/* + * lputfloor() - same as CtdlPutFloor() but unlocks the record (if supported) + */ +void lputfloor(struct floor *flbuf, int floor_num) +{ + CtdlPutFloorLock(flbuf, floor_num); +} + + /* * Traverse the room file... */ -- 2.30.2