* use constr structs for our static string arrays
authorWilfried Göesgens <willi@citadel.org>
Tue, 16 Jun 2009 23:38:12 +0000 (23:38 +0000)
committerWilfried Göesgens <willi@citadel.org>
Tue, 16 Jun 2009 23:38:12 +0000 (23:38 +0000)
* remove unneded macros and stuff
* fix leaks

webcit/roomops.c
webcit/webcit.h

index bda4375edacfbb3cbbf64a96613c5a9da6dd810e..498e7e537ccf719cbf8177195c28e4816afea15d 100644 (file)
@@ -11,20 +11,22 @@ char floorlist[MAX_FLOORS][SIZ]; /**< list of our floor names */
 char *viewdefs[9]; /**< the different kinds of available views */
 
 /** See GetFloorListHash and GetRoomListHash for info on these. Basically we pull LFLR/LKRA etc. and set up a room HashList with these keys. */
-const char FLOOR_PARAM_NAMES[(FLOOR_PARAM_LEN + 1)][15] = {"ID",
-                                                          "NAME", 
-                                                          "ROOMS"};
-const char ROOM_PARAM_NAMES[(ROOM_PARAM_LEN + 1)][20] = {"NAME",
-                                                        "FLAG",
-                                                        "FLOOR",
-                                                        "LISTORDER",
-                                                        "ACL",
-                                                        "CURVIEW",
-                                                        "DEFVIEW",
-                                                        "LASTCHANGE"};
-/* Because avoiding strlen at run time is a Good Thing(TM) */
-const int FLOOR_PARAM_NAMELEN[(FLOOR_PARAM_LEN +1)] = {2, 4, 5};
-const int ROOM_PARAM_NAMELEN[(ROOM_PARAM_LEN +1)] = {4, 4, 5, 9, 3, 7, 7, 8};
+
+#define FLOOR_PARAM_LEN 3
+const ConstStr FLOOR_PARAM_NAMES[] = {{HKEY("ID")},
+                                     {HKEY("NAME")}, 
+                                     {HKEY("ROOMS")}};
+
+#define ROOM_PARAM_LEN 8
+const ConstStr ROOM_PARAM_NAMES[] = {{HKEY("NAME")},
+                                    {HKEY("FLAG")},
+                                    {HKEY("FLOOR")},
+                                    {HKEY("LISTORDER")},
+                                    {HKEY("ACL")},
+                                    {HKEY("CURVIEW")},
+                                    {HKEY("DEFVIEW")},
+                                    {HKEY("LASTCHANGE")}};
+
 
 void display_whok(void);
 
@@ -3766,17 +3768,18 @@ HashList *GetFloorListHash(StrBuf *Target, WCTemplputParams *TP) {
        if (GetServerStatus(Buf, NULL) == 1) 
                while(StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err), strcmp(ChrPtr(Buf), "000")) {
                        int a;
-                       const char *floorNum = NULL;
+                       const StrBuf *floorNum = NULL;
                        floor = NewHash(1, NULL);
                        for(a=0; a<FLOOR_PARAM_LEN; a++) {
                                Buf2 = NewStrBuf();
                                StrBufExtract_token(Buf2, Buf, a, '|');
                                if (a==0) {
-                                       floorNum = ChrPtr(Buf2); /* hmm, should we copy Buf2 first? */
+                                       floorNum = Buf2; /* hmm, should we copy Buf2 first? */
+                                       
                                }
-                               Put(floor, FPKEY(a), Buf2, NULL);
+                               Put(floor, CKEY(FLOOR_PARAM_NAMES[a]), Buf2, HFreeStrBuf);
                        }
-                       Put(floors, HKEY(floorNum), floor, NULL);
+                       Put(floors, SKEY(floorNum), floor, HDeleteHash);
                }
        FreeStrBuf(&Buf);
        return floors;
@@ -3810,17 +3813,17 @@ HashList *GetRoomListHash(StrBuf *Target, WCTemplputParams *TP)
        if (GetServerStatus(buf, NULL) == 1) 
                while(StrBufTCP_read_line(buf, &WC->serv_sock, 0, &Err), strcmp(ChrPtr(buf), "000")) {
                        int i;
-                       const char *rmName = NULL;
+                       StrBuf *rmName = NULL;
                        room = NewHash(1, NULL);
                        for(i=0; i<ROOM_PARAM_LEN; i++) {
                                buf2 = NewStrBuf();
                                StrBufExtract_token(buf2, buf, i, '|');
                                if (i==0) {
-                                       rmName = ChrPtr(buf2);
+                                       rmName = buf2;
                                }
-                               Put(room, RPKEY(i), buf2, HFreeStrBuf);
+                               Put(room, CKEY(ROOM_PARAM_NAMES[i]), buf2, HFreeStrBuf);
                        }
-                       Put(rooms, rmName, strlen(rmName), room, HDeleteHash);
+                       Put(rooms, SKEY(rmName), room, HDeleteHash);
                }
        SortByHashKey(rooms, 1);
        /*SortByPayload(rooms, SortRoomsByListOrder);  */
@@ -3837,8 +3840,8 @@ int SortRoomsByListOrder(const void *room1, const void *room2)
        StrBuf *listOrderBuf1;
        StrBuf *listOrderBuf2;
   
-       GetHash(r1, RPKEY(3), (void *)&listOrderBuf1);
-       GetHash(r2, RPKEY(3), (void *)&listOrderBuf2);
+       GetHash(r1, CKEY(ROOM_PARAM_NAMES[3]), (void *)&listOrderBuf1);
+       GetHash(r2, CKEY(ROOM_PARAM_NAMES[3]), (void *)&listOrderBuf2);
        l1 = atoi(ChrPtr(listOrderBuf1));
        l2 = atoi(ChrPtr(listOrderBuf2));
        if (l1 < l2) return -1;
@@ -4135,7 +4138,7 @@ InitModule_ROOMOPS
        RegisterNamespace("ROOM:UNGOTO", 0, 0, tmplput_ungoto, 0);
        RegisterIterator("FLOORS", 0, NULL, GetFloorListHash, NULL, DeleteHash, CTX_FLOORS, CTX_NONE, IT_NOFLAG);
        RegisterNamespace("FLOOR:INFO", 1, 2, tmplput_FLOOR_Value, CTX_FLOORS);
-       RegisterIterator("LKRA", 0, NULL, GetRoomListHashLKRA, NULL, NULL, CTX_ROOMS, CTX_NONE, IT_NOFLAG);
+       RegisterIterator("LKRA", 0, NULL, GetRoomListHashLKRA, NULL, DeleteHash, CTX_ROOMS, CTX_NONE, IT_NOFLAG);
        RegisterNamespace("ROOM:INFO", 1, 2, tmplput_ROOM_Value, CTX_ROOMS);
 }
 
index c120412626594f0b7c1cd4547be5391a59fd6fed..bc7341dc755b3179abd9634a64a6ec0c9f9dcdbf 100644 (file)
@@ -869,14 +869,6 @@ void summary(void);
 int is_mobile_ua(char *user_agent);
 
 void embed_room_banner(char *, int);
-#define FLOOR_PARAM_LEN 3
-extern const char FLOOR_PARAM_NAMES[(FLOOR_PARAM_LEN + 1)][15];
-extern const int FLOOR_PARAM_NAMELEN[(FLOOR_PARAM_LEN + 1)];
-#define FPKEY(a) FLOOR_PARAM_NAMES[a], FLOOR_PARAM_NAMELEN[a]
-#define ROOM_PARAM_LEN 8
-extern const char ROOM_PARAM_NAMES[(ROOM_PARAM_LEN + 1)][20];
-extern const int ROOM_PARAM_NAMELEN[(ROOM_PARAM_LEN +1)];
-#define RPKEY(a) ROOM_PARAM_NAMES[a], ROOM_PARAM_NAMELEN[a]
 HashList *GetFloorListHash(StrBuf *Target, WCTemplputParams *TP);
 HashList *GetRoomListHash(StrBuf *Target, WCTemplputParams *TP);
 int SortRoomsByListOrder(const void *room1, const void *room2);