A little more with the API coding style.
authorDave West <davew@uncensored.citadel.org>
Sun, 25 Oct 2009 22:05:03 +0000 (22:05 +0000)
committerDave West <davew@uncensored.citadel.org>
Sun, 25 Oct 2009 22:05:03 +0000 (22:05 +0000)
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
citadel/msgbase.h
citadel/room_ops.c

index 9c66304a58dfcc648a537f7620a20e037538976f..71fa155340686ef1876aabcbf5f01f78f2edfa77 100644 (file)
@@ -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 */
index 999f46138c9a7cc2d16dffbbb09387987ec55614..67470b23b5bf7d94d925f85426b131453f76f07f 100644 (file)
@@ -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? */
index 386c3c9947c184976dcaeb1af80decc824df2048..5c2dec0c3cd5e61a647bc7fb05a4208392d7fb58 100644 (file)
@@ -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...
  */