SUBST: Dynamicaly generate contexts
[citadel.git] / webcit / roomlist.c
index f30d0d82e880224c10ee6a073f4e17db26a00a35..3dad18a29dfc54d3f04fc687d9b62a654633769f 100644 (file)
@@ -5,9 +5,9 @@
 #include "webcit.h"
 #include "webserver.h"
 
+
 HashList *GetWhoKnowsHash(StrBuf *Target, WCTemplputParams *TP)
 {
-       wcsession *WCC = WC;
        StrBuf *Line;
        StrBuf *Token;
        long State;
@@ -21,7 +21,7 @@ HashList *GetWhoKnowsHash(StrBuf *Target, WCTemplputParams *TP)
        if (GetServerStatus(Line, &State) == 1) 
        {
                Whok = NewHash(1, Flathash);
-               while(!Done && StrBuf_ServGetln(Line))
+               while(!Done && (StrBuf_ServGetln(Line) >= 0) )
                        if ( (StrLength(Line)==3) && 
                             !strcmp(ChrPtr(Line), "000")) 
                        {
@@ -42,8 +42,7 @@ HashList *GetWhoKnowsHash(StrBuf *Target, WCTemplputParams *TP)
                        }
        }
        else if (State == 550)
-               StrBufAppendBufPlain(WCC->ImportantMsg,
-                                    _("Higher access is required to access this function."), -1, 0);
+               AppendImportantMessage(_("Higher access is required to access this function."), -1);
 
 
        FreeStrBuf(&Line);
@@ -108,7 +107,7 @@ HashList *GetFloorListHash(StrBuf *Target, WCTemplputParams *TP)
        StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err); /* '100', we hope */
        if (GetServerStatus(Buf, NULL) == 1) 
        {
-               while(!Done && StrBuf_ServGetln(Buf))
+               while(!Done && StrBuf_ServGetln(Buf) >= 0)
                        if ( (StrLength(Buf)==3) && 
                             !strcmp(ChrPtr(Buf), "000")) 
                        {
@@ -166,6 +165,12 @@ HashList *GetRoomListHashLKRA(StrBuf *Target, WCTemplputParams *TP)
        return WCC->Rooms;
 }
 
+HashList *GetRoomListHashLPRM(StrBuf *Target, WCTemplputParams *TP) 
+{
+       serv_puts("LPRM");
+       return GetRoomListHash(Target, TP);
+}
+
 
 void FlushIgnetCfgs(folder *room)
 {
@@ -230,7 +235,7 @@ HashList *GetRoomListHash(StrBuf *Target, WCTemplputParams *TP)
        StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 1) 
        {
-               while(!Done && StrBuf_ServGetln(Buf))
+               while(!Done && (StrBuf_ServGetln(Buf) >= 0))
                        if ( (StrLength(Buf)==3) && 
                             !strcmp(ChrPtr(Buf), "000")) 
                        {
@@ -341,7 +346,7 @@ HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
                const char *Pos = NULL;
                int Done = 0;
 
-               while(!Done && StrBuf_ServGetln(Line))
+               while(!Done && (StrBuf_ServGetln(Line) >= 0))
                        if ( (StrLength(Line)==3) && 
                             !strcmp(ChrPtr(Line), "000"))
                        {
@@ -387,9 +392,10 @@ HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
                        }
        }
        else if (State == 550)
-               StrBufAppendBufPlain(WCC->ImportantMsg,
-                                    _("Higher access is required to access this function."), -1, 0);
+               AppendImportantMessage(_("Higher access is required to access this function."), -1);
 
+       FreeStrBuf(&Line);
+       FreeStrBuf(&Token);
 
        return WCC->CurRoom.IgnetCfgs[WantThisOne];
 }
@@ -590,7 +596,7 @@ int CompareRooms(const folder *room1, const folder *room2)
 int ConditionalRoomIsRESTSubRoom(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession  *WCC = WC;
-       folder     *Folder = (folder *)CTX;
+       folder     *Folder = (folder *)CTX(CTX_ROOMS);
        HashPos    *it;
        StrBuf     * Dir;
        void       *vDir;
@@ -607,11 +613,13 @@ int ConditionalRoomIsRESTSubRoom(StrBuf *Target, WCTemplputParams *TP)
        urlp = GetCount(WCC->Directory);
        delta = Folder->nRoomNameParts - urlp + 1;
 
-       lprintf(0, "\n->%s: %ld - %ld ", ChrPtr(Folder->name), urlp, 
-               Folder->nRoomNameParts);
+       syslog(0, "\n->%s: %d - %ld ", 
+              ChrPtr(Folder->name), 
+              urlp, 
+              Folder->nRoomNameParts);
        /* list only the floors which are in relation to the dav_depth header */
        if (WCC->Hdr->HR.dav_depth != delta) {
-               lprintf(0, "1\n");
+               syslog(0, "1\n");
                return 0;
        }
 
@@ -631,7 +639,7 @@ int ConditionalRoomIsRESTSubRoom(StrBuf *Target, WCTemplputParams *TP)
                        {
                                DeleteHashPos(&it);
 
-                               lprintf(0, "3\n");
+                               syslog(0, "3\n");
                                return 0;
                        }
                        Dir = (StrBuf*) vDir;
@@ -639,7 +647,7 @@ int ConditionalRoomIsRESTSubRoom(StrBuf *Target, WCTemplputParams *TP)
                                   ChrPtr(Dir)) != 0)
                        {
                                DeleteHashPos(&it);
-                               lprintf(0, "4\n");
+                               syslog(0, "4\n");
                                return 0;
                        }
                }
@@ -653,7 +661,7 @@ int ConditionalRoomIsRESTSubRoom(StrBuf *Target, WCTemplputParams *TP)
                {
                        DeleteHashPos(&it);
                        
-                       lprintf(0, "5\n");
+                       syslog(0, "5\n");
                        return WCC->Hdr->HR.dav_depth == 1;
                }
                DeleteHashPos(&it);
@@ -673,6 +681,9 @@ void
 InitModule_ROOMLIST
 (void)
 {
+       /* we duplicate this, just to be shure its already done. */
+       RegisterCTX(CTX_ROOMS);
+       RegisterCTX(CTX_FLOORS);
 
        RegisterIterator("ITERATE:THISROOM:WHO_KNOWS", 0, NULL, GetWhoKnowsHash, NULL, DeleteHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
        RegisterIterator("ITERATE:THISROOM:GNET", 1, NULL, GetNetConfigHash, NULL, NULL, CTX_STRBUFARR, CTX_NONE, IT_NOFLAG);
@@ -680,6 +691,10 @@ InitModule_ROOMLIST
        RegisterIterator("LFLR", 0, NULL, GetFloorListHash, NULL, NULL, CTX_FLOORS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
        RegisterIterator("LKRA", 0, NULL, GetRoomListHashLKRA, NULL, NULL, CTX_ROOMS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
        RegisterIterator("LZRM", 0, NULL, GetZappedRoomListHash, NULL, DeleteHash, CTX_ROOMS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
+       RegisterIterator("LPRM", 0, NULL, GetRoomListHashLPRM, NULL, DeleteHash, CTX_ROOMS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
+
+
+
 
        RegisterConditional(HKEY("COND:ROOM:REST:ISSUBROOM"), 0, ConditionalRoomIsRESTSubRoom, CTX_ROOMS);