Back to index

webcit  8.12-dfsg
Functions
roomlist.c File Reference
#include "webcit.h"
#include "webserver.h"

Go to the source code of this file.

Functions

HashList * GetWhoKnowsHash (StrBuf *Target, WCTemplputParams *TP)
void DeleteFloor (void *vFloor)
int SortFloorsByNameOrder (const void *vfloor1, const void *vfloor2)
HashList * GetFloorListHash (StrBuf *Target, WCTemplputParams *TP)
HashList * GetZappedRoomListHash (StrBuf *Target, WCTemplputParams *TP)
HashList * GetRoomListHashLKRA (StrBuf *Target, WCTemplputParams *TP)
HashList * GetRoomListHashLPRM (StrBuf *Target, WCTemplputParams *TP)
void FlushIgnetCfgs (folder *room)
void FlushFolder (folder *room)
void vDeleteFolder (void *vFolder)
HashList * GetRoomListHash (StrBuf *Target, WCTemplputParams *TP)
HashList * GetNetConfigHash (StrBuf *Target, WCTemplputParams *TP)
int SortRoomsByListOrder (const void *room1, const void *room2)
 Unused function that orders rooms by the listorder flag.
int CompareRoomListByFloorRoomPrivFirst (const void *room1, const void *room2)
int CompareRoomListByFloorRoomPrivFirstRev (const void *room1, const void *room2)
int GroupchangeRoomListByFloorRoomPrivFirst (const void *room1, const void *room2)
int CompareRooms (const folder *room1, const folder *room2)
int ConditionalRoomIsRESTSubRoom (StrBuf *Target, WCTemplputParams *TP)
void InitModule_ROOMLIST (void)

Function Documentation

int CompareRoomListByFloorRoomPrivFirst ( const void *  room1,
const void *  room2 
)

are we on the same floor? else sort by floor.

the private rooms are first in any case.

else decide alpaheticaly by floorname

if we have different levels of subdirectories, we want the toplevel to be first, regardless of sort sequence.

Deltas in common parts? exit here.

who's a subdirectory of whom?

else just sort alphabeticaly.

Definition at line 411 of file roomlist.c.

{
       folder *r1 = (folder*) GetSearchPayload(room1);
       folder *r2 = (folder*) GetSearchPayload(room2);
  
       if ((r1->Floor == NULL)  ||
           (r2->Floor == NULL))
              return 0;
              
       if (r1->Floor != r2->Floor)
       {
              if (r1->Floor->ID == VIRTUAL_MY_FLOOR)
                     return -1;
              if (r2->Floor->ID == VIRTUAL_MY_FLOOR)
                     return 1;
              return (r1->Floor->AlphaN > r2->Floor->AlphaN)? 1 : -1;
       }

       if (((r1->nRoomNameParts > 1) || 
           (r2->nRoomNameParts > 1)    )&&
           (r1->nRoomNameParts != r2->nRoomNameParts))
       {
              int i, ret;
              int nparts = (r1->nRoomNameParts > r2->nRoomNameParts)?
                     r2->nRoomNameParts : r1->nRoomNameParts;

              for (i=0; i < nparts; i++)
              {
                     ret = strcmp (ChrPtr(r1->name), 
                                  ChrPtr(r2->name));
                     if (ret != 0) 
                            return ret;
              }

              if (r1->nRoomNameParts > r2->nRoomNameParts)
                     return 1;
              else
                     return -1;

       }

       return strcmp (ChrPtr(r1->name), 
                     ChrPtr(r2->name));
}

Here is the caller graph for this function:

int CompareRoomListByFloorRoomPrivFirstRev ( const void *  room1,
const void *  room2 
)

are we on the same floor? else sort by floor.

the private rooms are first in any case.

else decide alpaheticaly by floorname

if we have different levels of subdirectories, we want the toplevel to be first, regardless of sort sequence.

special cases if one room is top-level...

Deltas in common parts? exit here.

who's a subdirectory of whom?

Definition at line 479 of file roomlist.c.

{
       folder *r1 = (folder*) GetSearchPayload(room1);
       folder *r2 = (folder*) GetSearchPayload(room2);

       if ((r1->Floor == NULL)  ||
           (r2->Floor == NULL))
              return 0;

       if (r2->Floor != r1->Floor)
       {
              if (r1->Floor->ID == VIRTUAL_MY_FLOOR)
                     return -1;
              if (r2->Floor->ID == VIRTUAL_MY_FLOOR)
                     return 1;
              return (r1->Floor->AlphaN < r2->Floor->AlphaN)? 1 : -1;
       }

       if (((r1->nRoomNameParts > 1) || 
           (r2->nRoomNameParts > 1)    )&&
           (r1->nRoomNameParts != r2->nRoomNameParts))
       {
              int i, ret;
              int nparts = (r1->nRoomNameParts > r2->nRoomNameParts)?
                     r2->nRoomNameParts : r1->nRoomNameParts;

              for (i=0; i < nparts; i++)
              {
                     if (r2->nRoomNameParts == 1)
                            ret = strcmp (ChrPtr(r2->name), 
                                         ChrPtr(r1->RoomNameParts[i]));
                     else if (r1->nRoomNameParts == 1)
                            ret = strcmp (ChrPtr(r2->RoomNameParts[i]),
                                         ChrPtr(r1->name));
                     else 
                            ret = strcmp (ChrPtr(r2->RoomNameParts[i]), 
                                         ChrPtr(r1->RoomNameParts[i]));
                     if (ret != 0) 
                            return ret;
              }

              if (r1->nRoomNameParts > r2->nRoomNameParts)
                     return 1;
              else
                     return -1;
       }

       return strcmp (ChrPtr(r2->name), 
                     ChrPtr(r1->name));
}

Here is the caller graph for this function:

int CompareRooms ( const folder room1,
const folder room2 
)

Definition at line 586 of file roomlist.c.

{
       if ((room1 == NULL) || (room2 == NULL))
              return -1;
       return CompareRoomListByFloorRoomPrivFirst(room1, room2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ConditionalRoomIsRESTSubRoom ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 593 of file roomlist.c.

{
       wcsession  *WCC = WC;
       folder     *Folder = (folder *)CTX;
       HashPos    *it;
       StrBuf     * Dir;
       void       *vDir;
       long        len;
        const char *Key;
       int i, j, urlp;
       int delta;


       /* list only folders relative to the current floor... */
       if (Folder->Floor != WCC->CurrentFloor)
              return 0;

       urlp = GetCount(WCC->Directory);
       delta = Folder->nRoomNameParts - urlp + 1;

       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) {
              syslog(0, "1\n");
              return 0;
       }


       it = GetNewHashPos(WCC->Directory, 0);
       /* Fast forward the floorname we checked above... */
       GetNextHashPos(WCC->Directory, it, &len, &Key, &vDir);

       if (Folder->nRoomNameParts > 1) {         
              for (i = 0, j = 1; 
                   (i > Folder->nRoomNameParts) && (j > urlp); 
                   i++, j++)
              {
                     if (!GetNextHashPos(WCC->Directory, 
                                       it, &len, &Key, &vDir) ||
                         (vDir == NULL))
                     {
                            DeleteHashPos(&it);

                            syslog(0, "3\n");
                            return 0;
                     }
                     Dir = (StrBuf*) vDir;
                     if (strcmp(ChrPtr(Folder->RoomNameParts[i]), 
                               ChrPtr(Dir)) != 0)
                     {
                            DeleteHashPos(&it);
                            syslog(0, "4\n");
                            return 0;
                     }
              }
              DeleteHashPos(&it);
              return 1;
       }
       else {
              if (!GetNextHashPos(WCC->Directory, 
                                it, &len, &Key, &vDir) ||
                  (vDir == NULL))
              {
                     DeleteHashPos(&it);
                     
                     syslog(0, "5\n");
                     return WCC->Hdr->HR.dav_depth == 1;
              }
              DeleteHashPos(&it);
              Dir = (StrBuf*) vDir;
              if (WCC->Hdr->HR.dav_depth == 0) {
                     return (strcmp(ChrPtr(Folder->name), 
                                   ChrPtr(Dir))
                            == 0);

              }
              return 0;
       }
}

Here is the caller graph for this function:

void DeleteFloor ( void *  vFloor)

Definition at line 52 of file roomlist.c.

{
       Floor *pFloor;
       pFloor = (Floor*) vFloor;
       FreeStrBuf(&pFloor->Name);
       free(pFloor);
}

Here is the caller graph for this function:

void FlushFolder ( folder room)

Definition at line 186 of file roomlist.c.

{
       int i;

       FreeStrBuf(&room->XAPass);
       FreeStrBuf(&room->Directory);
       FreeStrBuf(&room->RoomAide);
       FreeStrBuf(&room->XInfoText);
       room->XHaveInfoTextLoaded = 0;

       FreeStrBuf(&room->name);

       FlushIgnetCfgs(room);

       if (room->RoomNameParts != NULL)
       {
              for (i=0; i < room->nRoomNameParts; i++)
                     FreeStrBuf(&room->RoomNameParts[i]);
              free(room->RoomNameParts);
       }
       memset(room, 0, sizeof(folder));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void FlushIgnetCfgs ( folder room)

Definition at line 174 of file roomlist.c.

{
       int i;
       if (room->IgnetCfgs[maxRoomNetCfg] == (HashList*) StrBufNOTNULL)
       {
              for (i = ignet_push_share; i < maxRoomNetCfg; i++)
                     DeleteHash(&room->IgnetCfgs[i]);
       }
       memset(&room->IgnetCfgs, 0, sizeof(HashList *) * (maxRoomNetCfg + 1));

}

Here is the caller graph for this function:

HashList * GetFloorListHash ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 74 of file roomlist.c.

{
       int Done = 0;
       const char *Err;
       StrBuf *Buf;
       HashList *floors;
       HashList *floorsbyname;
       HashPos *it;
       Floor *pFloor;
       void *vFloor;
       const char *Pos;
       int i;
       wcsession *WCC = WC;
       const char *HashKey;
       long HKLen;


       if (WCC->Floors != NULL)
              return WCC->Floors;
       WCC->Floors = floors = NewHash(1, Flathash);
       WCC->FloorsByName = floorsbyname = NewHash(1, NULL);
       Buf = NewStrBuf();

       pFloor = (Floor*) malloc(sizeof(Floor));
       pFloor->ID = VIRTUAL_MY_FLOOR;
       pFloor->Name = NewStrBufPlain(_("My Folders"), -1);
       pFloor->NRooms = 0;
       
       Put(floors, IKEY(pFloor->ID), pFloor, DeleteFloor);
       Put(floorsbyname, SKEY(pFloor->Name), pFloor, reference_free_handler);

       serv_puts("LFLR"); /* get floors */
       StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err); /* '100', we hope */
       if (GetServerStatus(Buf, NULL) == 1) 
       {
              while(!Done && StrBuf_ServGetln(Buf) >= 0)
                     if ( (StrLength(Buf)==3) && 
                          !strcmp(ChrPtr(Buf), "000")) 
                     {
                            Done = 1;
                     }
                     else
                     {
                     
                            Pos = NULL;

                            pFloor = (Floor*) malloc(sizeof(Floor));
                            pFloor->ID = StrBufExtractNext_int(Buf, &Pos, '|');
                            pFloor->Name = NewStrBufPlain(NULL, StrLength(Buf));
                            StrBufExtract_NextToken(pFloor->Name, Buf, &Pos, '|');
                            pFloor->NRooms = StrBufExtractNext_long(Buf, &Pos, '|');

                            Put(floors, IKEY(pFloor->ID), pFloor, DeleteFloor);
                            Put(floorsbyname, SKEY(pFloor->Name), pFloor, reference_free_handler);
                     }
       }
       FreeStrBuf(&Buf);
       
       /* now lets pre-sort them alphabeticaly. */
       i = 1;
       SortByPayload(floors, SortFloorsByNameOrder);
       it = GetNewHashPos(floors, 0);
       while (       GetNextHashPos(floors, it, &HKLen, &HashKey, &vFloor)) 
              ((Floor*) vFloor)->AlphaN = i++;
       DeleteHashPos(&it);
       SortByHashKeyStr(floors);

       return floors;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HashList* GetNetConfigHash ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 322 of file roomlist.c.

{
       wcsession *WCC = WC;
       StrBuf *Line;
       StrBuf *Token;
       StrBuf *Content;
       long WantThisOne;
       long PutTo;
       long State;
       
       WantThisOne = GetTemplateTokenNumber(Target, TP, 5, -1);
       if ((WantThisOne < 0) || (WantThisOne > maxRoomNetCfg))
              return NULL;
       if (WCC->CurRoom.IgnetCfgs[maxRoomNetCfg] == (HashList*) StrBufNOTNULL)
              return WCC->CurRoom.IgnetCfgs[WantThisOne];

       WCC->CurRoom.IgnetCfgs[maxRoomNetCfg] = (HashList*) StrBufNOTNULL;
       serv_puts("GNET");
       Line = NewStrBuf();
       Token = NewStrBuf();
       StrBuf_ServGetln(Line);
       if (GetServerStatus(Line, &State) == 1) 
       {
              const char *Pos = NULL;
              int Done = 0;

              while(!Done && (StrBuf_ServGetln(Line) >= 0))
                     if ( (StrLength(Line)==3) && 
                          !strcmp(ChrPtr(Line), "000"))
                     {
                            Done = 1;
                     }
                     else
                     {
                            StrBufExtract_NextToken(Token, Line, &Pos, '|');
                            PutTo = GetTokenDefine(SKEY(Token), -1);
                            if ((PutTo >= 0) && 
                                (PutTo < maxRoomNetCfg) &&
                                (Pos != StrBufNOTNULL))
                            {
                                   int n;
                                   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);
                                   Put(WCC->CurRoom.IgnetCfgs[PutTo], 
                                       IKEY(n),
                                       SubH, 
                                       HDeleteHash);
                                   n = 1; /* #0 is the type... */
                                   while (Pos != StrBufNOTNULL) {
                                          Content = NewStrBuf();
                                          StrBufExtract_NextToken(Content, Line, &Pos, '|');
                                          Put(SubH, 
                                              IKEY(n),
                                              Content, 
                                              HFreeStrBuf);
                                          n++;
                                   }
                            }
                            Pos = NULL;
                     }
       }
       else if (State == 550)
              AppendImportantMessage(_("Higher access is required to access this function."), -1);


       return WCC->CurRoom.IgnetCfgs[WantThisOne];
}

Here is the call graph for this function:

Here is the caller graph for this function:

HashList* GetRoomListHash ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 220 of file roomlist.c.

{
       int Done = 0;
       HashList *rooms;
       folder *room;
       StrBuf *Buf;
       const char *Pos;
       void *vFloor;
       wcsession *WCC = WC;
       CompareFunc SortIt;
       WCTemplputParams SubTP;

       Buf = NewStrBuf();
       rooms = NewHash(1, NULL);
       StrBuf_ServGetln(Buf);
       if (GetServerStatus(Buf, NULL) == 1) 
       {
              while(!Done && (StrBuf_ServGetln(Buf) >= 0))
                     if ( (StrLength(Buf)==3) && 
                          !strcmp(ChrPtr(Buf), "000")) 
                     {
                            Done = 1;
                     }
                     else
                     {                           
                            Pos = NULL;
                            room = (folder*) malloc (sizeof(folder));
                            memset(room, 0, sizeof(folder));

                            /* Load the base data from the server reply */
                            room->name = NewStrBufPlain(NULL, StrLength(Buf));
                            StrBufExtract_NextToken(room->name, Buf, &Pos, '|');

                            room->QRFlags = StrBufExtractNext_long(Buf, &Pos, '|');
                            room->floorid = StrBufExtractNext_int(Buf, &Pos, '|');
                            room->Order = StrBufExtractNext_long(Buf, &Pos, '|');
                            room->QRFlags2 = StrBufExtractNext_long(Buf, &Pos, '|');

                            room->RAFlags = StrBufExtractNext_long(Buf, &Pos, '|');

/*
  ACWHUT?
  room->ACL = NewStrBufPlain(NULL, StrLength(Buf));
  StrBufExtract_NextToken(room->ACL, Buf, &Pos, '|');
*/

                            room->view = StrBufExtractNext_long(Buf, &Pos, '|');
                            room->defview = StrBufExtractNext_long(Buf, &Pos, '|');
                            room->lastchange = StrBufExtractNext_long(Buf, &Pos, '|');

                            /* Evaluate the Server sent data for later use */
                            /* find out, whether we are in a sub-room */
                            room->nRoomNameParts = StrBufNum_tokens(room->name, '\\');
                            if (room->nRoomNameParts > 1)
                            {
                                   int i;

                                   Pos = NULL;
                                   room->RoomNameParts = malloc(sizeof(StrBuf*) * (room->nRoomNameParts + 1));
                                   memset(room->RoomNameParts, 0, sizeof(StrBuf*) * (room->nRoomNameParts + 1));
                                   for (i=0; i < room->nRoomNameParts; i++)
                                   {
                                          room->RoomNameParts[i] = NewStrBuf();
                                          StrBufExtract_NextToken(room->RoomNameParts[i],
                                                               room->name, &Pos, '\\');
                                   }
                            }

                            /* Private mailboxes on the main floor get remapped to the personal folder */
                            if ((room->QRFlags & QR_MAILBOX) && 
                                (room->floorid == 0))
                            {
                                   room->floorid = VIRTUAL_MY_FLOOR;
                                   if ((room->nRoomNameParts == 1) && 
                                       (StrLength(room->name) == 4) && 
                                       (strcmp(ChrPtr(room->name), "Mail") == 0))
                                   {
                                          room->is_inbox = 1;
                                   }

                            }
                            /* get a pointer to the floor we're on: */
                            GetHash(WCC->Floors, IKEY(room->floorid), &vFloor);
                            room->Floor = (const Floor*) vFloor;



                            /* now we know everything, remember it... */
                            Put(rooms, SKEY(room->name), room, vDeleteFolder);
                     }
       }

       SubTP.Filter.ContextType = CTX_ROOMS;
       SortIt = RetrieveSort(&SubTP, NULL, 0, HKEY("fileunsorted"), 0);
       if (SortIt != NULL)
              SortByPayload(rooms, SortIt);
       else 
              SortByPayload(rooms, SortRoomsByListOrder);
       FreeStrBuf(&Buf);
       return rooms;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HashList* GetRoomListHashLKRA ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 153 of file roomlist.c.

{
       wcsession *WCC = WC;

       if (WCC->Floors == NULL)
              GetFloorListHash(Target, TP);
       if (WCC->Rooms == NULL) 
       {
              serv_puts("LKRA");
              WCC->Rooms =  GetRoomListHash(Target, TP);
       }
       return WCC->Rooms;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HashList* GetRoomListHashLPRM ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 167 of file roomlist.c.

{
       serv_puts("LPRM");
       return GetRoomListHash(Target, TP);
}

Here is the call graph for this function:

Here is the caller graph for this function:

HashList* GetWhoKnowsHash ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 8 of file roomlist.c.

{
       StrBuf *Line;
       StrBuf *Token;
       long State;
       HashList *Whok = NULL;
       int Done = 0;
       int n;

       serv_puts("WHOK");
       Line = NewStrBuf();
       StrBuf_ServGetln(Line);
       if (GetServerStatus(Line, &State) == 1) 
       {
              Whok = NewHash(1, Flathash);
              while(!Done && (StrBuf_ServGetln(Line) >= 0) )
                     if ( (StrLength(Line)==3) && 
                          !strcmp(ChrPtr(Line), "000")) 
                     {
                            Done = 1;
                     }
                     else
                     {
                     
                            const char *Pos = NULL;
                            Token = NewStrBufPlain (NULL, StrLength(Line));
                            StrBufExtract_NextToken(Token, Line, &Pos, '|');

                            Put(Whok, 
                                IKEY(n),
                                Token, 
                                HFreeStrBuf);
                            n++;
                     }
       }
       else if (State == 550)
              AppendImportantMessage(_("Higher access is required to access this function."), -1);


       FreeStrBuf(&Line);
       return Whok;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HashList* GetZappedRoomListHash ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 144 of file roomlist.c.

{
       wcsession *WCC = WC;

       if (WCC->Floors == NULL)
              GetFloorListHash(Target, TP);
       serv_puts("LZRM -1");
       return GetRoomListHash(Target, TP);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int GroupchangeRoomListByFloorRoomPrivFirst ( const void *  room1,
const void *  room2 
)

Definition at line 554 of file roomlist.c.

{
       folder *r1 = (folder*) room1;
       folder *r2 = (folder*) room2;
  

       if ((r1->Floor == NULL)  ||
           (r2->Floor == NULL))
              return 0;
              
       if (r1->Floor == r2->Floor)
              return 0;
       else 
       {
              wcsession *WCC = WC;
              static int columns = 3;
              int boxes_per_column = 0;
              int nf;

              nf = GetCount(WCC->Floors);
              while (nf % columns != 0) ++nf;
              boxes_per_column = (nf / columns);
              if (boxes_per_column < 1)
                     boxes_per_column = 1;
              if (r1->Floor->AlphaN % boxes_per_column == 0)
                     return 2;
              else 
                     return 1;
       }
}

Here is the caller graph for this function:

void InitModule_ROOMLIST ( void  )

Definition at line 679 of file roomlist.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int SortFloorsByNameOrder ( const void *  vfloor1,
const void *  vfloor2 
)

Definition at line 60 of file roomlist.c.

{
       Floor *f1 = (Floor*) GetSearchPayload(vfloor1);
       Floor *f2 = (Floor*) GetSearchPayload(vfloor2);
       
       /* prefer My floor over alpabetical sort */
       if (f1->ID == VIRTUAL_MY_FLOOR)
              return 1;
       if (f2->ID == VIRTUAL_MY_FLOOR)
              return -1;

       return strcmp(ChrPtr(f1->Name), ChrPtr(f2->Name));
}

Here is the caller graph for this function:

int SortRoomsByListOrder ( const void *  room1,
const void *  room2 
)

Unused function that orders rooms by the listorder flag.

Definition at line 401 of file roomlist.c.

{
       folder *r1 = (folder*) GetSearchPayload(room1);
       folder *r2 = (folder*) GetSearchPayload(room2);
  
       if (r1->Order == r2->Order) return 0;
       if (r1->Order > r2->Order) return 1;
       return -1;
}

Here is the caller graph for this function:

void vDeleteFolder ( void *  vFolder)

Definition at line 209 of file roomlist.c.

{
       folder *room;

       room = (folder*) vFolder;
       FlushFolder(room);

       free(room);
}

Here is the call graph for this function:

Here is the caller graph for this function: