* GetNetConfigHash(): fix some edge cases
[citadel.git] / webcit / roomlist.c
index 24017f291a1bccad8e087eba374b5360660dd551..ec6ef59248efcdc661650a46f5cb0da1fe595679 100644 (file)
@@ -214,7 +214,7 @@ HashList *GetRoomListHash(StrBuf *Target, WCTemplputParams *TP)
 
                                room->QRFlags = StrBufExtractNext_long(Buf, &Pos, '|');
                                room->floorid = StrBufExtractNext_int(Buf, &Pos, '|');
-                               room->listorder = StrBufExtractNext_long(Buf, &Pos, '|');
+                               room->Order = StrBufExtractNext_long(Buf, &Pos, '|');
                                room->QRFlags2 = StrBufExtractNext_long(Buf, &Pos, '|');
 
                                room->RAFlags = StrBufExtractNext_long(Buf, &Pos, '|');
@@ -291,13 +291,13 @@ HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
        long PutTo;
        long State;
        
-       WantThisOne = GetTemplateTokenNumber(Target, TP, 5, 0);
-       if (WantThisOne == 0)
+       WantThisOne = GetTemplateTokenNumber(Target, TP, 5, -1);
+       if ((WantThisOne < 0) || (WantThisOne > maxRoomNetCfg))
                return NULL;
-       if (WCC->CurRoom.IgnetCfgs[0] == (HashList*) StrBufNOTNULL)
+       if (WCC->CurRoom.IgnetCfgs[maxRoomNetCfg] == (HashList*) StrBufNOTNULL)
                return WCC->CurRoom.IgnetCfgs[WantThisOne];
 
-       WCC->CurRoom.IgnetCfgs[0] = (HashList*) StrBufNOTNULL;
+       WCC->CurRoom.IgnetCfgs[maxRoomNetCfg] = (HashList*) StrBufNOTNULL;
        serv_puts("GNET");
        Line = NewStrBuf();
        Token = NewStrBuf();
@@ -308,7 +308,7 @@ HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
                StrBuf_ServGetln(Line);
                StrBufExtract_NextToken(Token, Line, &Pos, '|');
                PutTo = GetTokenDefine(SKEY(Token), -1);
-               if ((PutTo > 0) && 
+               if ((PutTo >= 0) && 
                    (PutTo < maxRoomNetCfg) &&
                    (Pos != StrBufNOTNULL))
                {
@@ -316,13 +316,20 @@ HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
                        HashList *SubH;
 
                        if (WCC->CurRoom.IgnetCfgs[PutTo] == NULL)
+                       {
+                               n = 0;
                                WCC->CurRoom.IgnetCfgs[PutTo] = NewHash(1, NULL);
+                       }
+                       else 
+                       {
+                               n = GetCount(WCC->CurRoom.IgnetCfgs[PutTo]);
+                       }
                        SubH = NewHash(1, NULL);
-                       n = GetCount(WCC->CurRoom.IgnetCfgs[PutTo]) + 1;
                        Put(WCC->CurRoom.IgnetCfgs[PutTo], 
                            IKEY(n),
                            SubH, 
                            HDeleteHash);
+                       n = 0;
                        while (Pos != StrBufNOTNULL) {
                                Content = NewStrBuf();
                                StrBufExtract_NextToken(Content, Line, &Pos, '|');
@@ -348,8 +355,8 @@ int SortRoomsByListOrder(const void *room1, const void *room2)
        folder *r1 = (folder*) GetSearchPayload(room1);
        folder *r2 = (folder*) GetSearchPayload(room2);
   
-       if (r1->listorder == r2->listorder) return 0;
-       if (r1->listorder > r2->listorder) return 1;
+       if (r1->Order == r2->Order) return 0;
+       if (r1->Order > r2->Order) return 1;
        return -1;
 }
 
@@ -607,7 +614,7 @@ void tmplput_ROOM_FLOORID(StrBuf *Target, WCTemplputParams *TP)
 void tmplput_ROOM_LISTORDER(StrBuf *Target, WCTemplputParams *TP) 
 {
        folder *Folder = (folder *)CTX;
-       StrBufAppendPrintf(Target, "%d", Folder->listorder);
+       StrBufAppendPrintf(Target, "%d", Folder->Order);
 }
 void tmplput_ROOM_VIEW(StrBuf *Target, WCTemplputParams *TP) 
 {