2 * room listings and filters.
8 typedef enum __eRoomParamType {
14 HashList *GetWhoKnowsHash(StrBuf *Target, WCTemplputParams *TP)
19 HashList *Whok = NULL;
25 StrBuf_ServGetln(Line);
26 if (GetServerStatus(Line, &State) == 1)
28 Whok = NewHash(1, Flathash);
29 while(!Done && (StrBuf_ServGetln(Line) >= 0) )
30 if ( (StrLength(Line)==3) &&
31 !strcmp(ChrPtr(Line), "000"))
38 const char *Pos = NULL;
39 Token = NewStrBufPlain (NULL, StrLength(Line));
40 StrBufExtract_NextToken(Token, Line, &Pos, '|');
49 else if (State == 550)
50 AppendImportantMessage(_("Higher access is required to access this function."), -1);
58 void DeleteFloor(void *vFloor)
61 pFloor = (Floor*) vFloor;
62 FreeStrBuf(&pFloor->Name);
66 int SortFloorsByNameOrder(const void *vfloor1, const void *vfloor2)
68 Floor *f1 = (Floor*) GetSearchPayload(vfloor1);
69 Floor *f2 = (Floor*) GetSearchPayload(vfloor2);
71 /* prefer My floor over alpabetical sort */
72 if (f1->ID == VIRTUAL_MY_FLOOR)
74 if (f2->ID == VIRTUAL_MY_FLOOR)
77 return strcmp(ChrPtr(f1->Name), ChrPtr(f2->Name));
80 HashList *GetFloorListHash(StrBuf *Target, WCTemplputParams *TP)
86 HashList *floorsbyname;
97 if (WCC->Floors != NULL)
99 WCC->Floors = floors = NewHash(1, Flathash);
100 WCC->FloorsByName = floorsbyname = NewHash(1, NULL);
103 pFloor = (Floor*) malloc(sizeof(Floor));
104 pFloor->ID = VIRTUAL_MY_FLOOR;
105 pFloor->Name = NewStrBufPlain(_("My Folders"), -1);
108 Put(floors, IKEY(pFloor->ID), pFloor, DeleteFloor);
109 Put(floorsbyname, SKEY(pFloor->Name), pFloor, reference_free_handler);
111 serv_puts("LFLR"); /* get floors */
112 StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err); /* '100', we hope */
113 if (GetServerStatus(Buf, NULL) == 1)
115 while(!Done && StrBuf_ServGetln(Buf) >= 0)
116 if ( (StrLength(Buf)==3) &&
117 !strcmp(ChrPtr(Buf), "000"))
126 pFloor = (Floor*) malloc(sizeof(Floor));
127 pFloor->ID = StrBufExtractNext_int(Buf, &Pos, '|');
128 pFloor->Name = NewStrBufPlain(NULL, StrLength(Buf));
129 StrBufExtract_NextToken(pFloor->Name, Buf, &Pos, '|');
130 pFloor->NRooms = StrBufExtractNext_long(Buf, &Pos, '|');
132 Put(floors, IKEY(pFloor->ID), pFloor, DeleteFloor);
133 Put(floorsbyname, SKEY(pFloor->Name), pFloor, reference_free_handler);
138 /* now lets pre-sort them alphabeticaly. */
140 SortByPayload(floors, SortFloorsByNameOrder);
141 it = GetNewHashPos(floors, 0);
142 while ( GetNextHashPos(floors, it, &HKLen, &HashKey, &vFloor))
143 ((Floor*) vFloor)->AlphaN = i++;
145 SortByHashKeyStr(floors);
150 HashList *GetZappedRoomListHash(StrBuf *Target, WCTemplputParams *TP)
154 if (WCC->Floors == NULL)
155 GetFloorListHash(Target, TP);
156 serv_puts("LZRM -1");
157 return GetRoomListHash(Target, TP);
159 HashList *GetRoomListHashLKRA(StrBuf *Target, WCTemplputParams *TP)
163 if (WCC->Floors == NULL)
164 GetFloorListHash(Target, TP);
165 if (WCC->Rooms == NULL)
168 WCC->Rooms = GetRoomListHash(Target, TP);
173 HashList *GetRoomListHashLPRM(StrBuf *Target, WCTemplputParams *TP)
176 return GetRoomListHash(Target, TP);
180 void FlushIgnetCfgs(folder *room)
183 if (room->IgnetCfgs[maxRoomNetCfg] == (HashList*) StrBufNOTNULL)
185 for (i = ignet_push_share; i < maxRoomNetCfg; i++)
186 DeleteHash(&room->IgnetCfgs[i]);
188 memset(&room->IgnetCfgs, 0, sizeof(HashList *) * (maxRoomNetCfg + 1));
189 room->RoomAlias = NULL;
193 void FlushFolder(folder *room)
197 FreeStrBuf(&room->XAPass);
198 FreeStrBuf(&room->Directory);
199 FreeStrBuf(&room->RoomAide);
200 FreeStrBuf(&room->XInfoText);
201 room->XHaveInfoTextLoaded = 0;
203 FreeStrBuf(&room->name);
205 FlushIgnetCfgs(room);
207 if (room->RoomNameParts != NULL)
209 for (i=0; i < room->nRoomNameParts; i++)
210 FreeStrBuf(&room->RoomNameParts[i]);
211 free(room->RoomNameParts);
213 memset(room, 0, sizeof(folder));
216 void vDeleteFolder(void *vFolder)
220 room = (folder*) vFolder;
227 HashList *GetRoomListHash(StrBuf *Target, WCTemplputParams *TP)
237 WCTemplputParams SubTP;
240 rooms = NewHash(1, NULL);
241 StrBuf_ServGetln(Buf);
242 if (GetServerStatus(Buf, NULL) == 1)
244 while(!Done && (StrBuf_ServGetln(Buf) >= 0))
245 if ( (StrLength(Buf)==3) &&
246 !strcmp(ChrPtr(Buf), "000"))
253 room = (folder*) malloc (sizeof(folder));
254 memset(room, 0, sizeof(folder));
256 /* Load the base data from the server reply */
257 room->name = NewStrBufPlain(NULL, StrLength(Buf));
258 StrBufExtract_NextToken(room->name, Buf, &Pos, '|');
260 room->QRFlags = StrBufExtractNext_long(Buf, &Pos, '|');
261 room->floorid = StrBufExtractNext_int(Buf, &Pos, '|');
262 room->Order = StrBufExtractNext_long(Buf, &Pos, '|');
263 room->QRFlags2 = StrBufExtractNext_long(Buf, &Pos, '|');
265 room->RAFlags = StrBufExtractNext_long(Buf, &Pos, '|');
269 room->ACL = NewStrBufPlain(NULL, StrLength(Buf));
270 StrBufExtract_NextToken(room->ACL, Buf, &Pos, '|');
273 room->view = StrBufExtractNext_long(Buf, &Pos, '|');
274 room->defview = StrBufExtractNext_long(Buf, &Pos, '|');
275 room->lastchange = StrBufExtractNext_long(Buf, &Pos, '|');
277 /* Evaluate the Server sent data for later use */
278 /* find out, whether we are in a sub-room */
279 room->nRoomNameParts = StrBufNum_tokens(room->name, '\\');
280 if (room->nRoomNameParts > 1)
285 room->RoomNameParts = malloc(sizeof(StrBuf*) * (room->nRoomNameParts + 1));
286 memset(room->RoomNameParts, 0, sizeof(StrBuf*) * (room->nRoomNameParts + 1));
287 for (i=0; i < room->nRoomNameParts; i++)
289 room->RoomNameParts[i] = NewStrBuf();
290 StrBufExtract_NextToken(room->RoomNameParts[i],
291 room->name, &Pos, '\\');
295 /* Private mailboxes on the main floor get remapped to the personal folder */
296 if ((room->QRFlags & QR_MAILBOX) &&
297 (room->floorid == 0))
299 room->floorid = VIRTUAL_MY_FLOOR;
300 if ((room->nRoomNameParts == 1) &&
301 (StrLength(room->name) == 4) &&
302 (strcmp(ChrPtr(room->name), "Mail") == 0))
308 /* get a pointer to the floor we're on: */
309 GetHash(WCC->Floors, IKEY(room->floorid), &vFloor);
310 room->Floor = (const Floor*) vFloor;
314 /* now we know everything, remember it... */
315 Put(rooms, SKEY(room->name), room, vDeleteFolder);
319 SubTP.Filter.ContextType = CTX_ROOMS;
320 SortIt = RetrieveSort(&SubTP, NULL, 0, HKEY("fileunsorted"), 0);
322 SortByPayload(rooms, SortIt);
324 SortByPayload(rooms, SortRoomsByListOrder);
329 HashList *GetThisRoomMAlias(StrBuf *Target, WCTemplputParams *TP)
334 HashList *Aliases = NULL;
340 serv_puts("GNET "FILE_MAILALIAS);
342 StrBuf_ServGetln(Line);
343 if (GetServerStatus(Line, &State) == 1)
348 Aliases = NewHash(1, NULL);
349 while(!Done && (StrBuf_ServGetln(Line) >= 0))
350 if ( (StrLength(Line)==3) &&
351 !strcmp(ChrPtr(Line), "000"))
357 pComma = strchr(ChrPtr(Line), ',');
360 aliaslen = pComma - ChrPtr(Line);
361 locallen = StrLength(Line) - 1 - aliaslen;
362 if (locallen - 5 != StrLength(WCC->CurRoom.name))
364 if (strncmp(pComma + 1, "room_", 5) != 0)
367 if (strcasecmp(pComma + 6, ChrPtr(WCC->CurRoom.name)) != 0)
369 Token = NewStrBufPlain(ChrPtr(Line), aliaslen);
377 else if (State == 550)
378 AppendImportantMessage(_("Higher access is required to access this function."), -1);
386 void AppendPossibleAliasWithDomain(
387 HashList *PossibleAliases,
388 long *nPossibleAliases,
389 const HashList *Domains,
395 const StrBuf *OneDomain;
403 It = GetNewHashPos(Domains, 1);
404 n = *nPossibleAliases;
405 while (GetNextHashPos(Domains, It, &KLen, &Key, &pV))
407 OneDomain = (const StrBuf*) pV;
409 StrBufAppendBufPlain(Line, prefix, len, 0);
410 StrBufAppendBufPlain(Line, Alias, AliasLen, 0);
411 StrBufAppendBufPlain(Line, HKEY("@"), 0);
412 StrBufAppendBuf(Line, OneDomain, 0);
421 *nPossibleAliases = n;
424 HashList *GetThisRoomPossibleMAlias(StrBuf *Target, WCTemplputParams *TP)
430 HashList *PossibleAliases = NULL;
439 Domains = GetValidDomainNames(Target, TP);
442 PossibleAliases = NewHash(1, NULL);
445 AppendPossibleAliasWithDomain(PossibleAliases,
449 SKEY(WCC->CurRoom.name));
452 serv_puts("GNET "FILE_MAILALIAS);
453 StrBuf_ServGetln(Line);
454 if (GetServerStatus(Line, &State) == 1)
458 while(!Done && (StrBuf_ServGetln(Line) >= 0))
459 if ( (StrLength(Line)==3) &&
460 !strcmp(ChrPtr(Line), "000"))
466 pComma = strchr(ChrPtr(Line), ',');
469 aliaslen = pComma - ChrPtr(Line);
470 locallen = StrLength(Line) - 1 - aliaslen;
471 if (locallen - 5 != StrLength(WCC->CurRoom.name))
473 if (strncmp(pComma + 1, "room_", 5) != 0)
476 if (strcasecmp(pComma + 6, ChrPtr(WCC->CurRoom.name)) != 0)
478 pAt = strchr(ChrPtr(Line), '@');
479 if ((pAt == NULL) || (pAt > pComma))
481 AppendPossibleAliasWithDomain(PossibleAliases,
492 Token = NewStrBufPlain(ChrPtr(Line), aliaslen);
501 else if (State == 550)
502 AppendImportantMessage(_("Higher access is required to access this function."), -1);
506 return PossibleAliases;
510 HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
520 WantThisOne = GetTemplateTokenNumber(Target, TP, 5, -1);
521 if ((WantThisOne < 0) || (WantThisOne > maxRoomNetCfg))
523 if (WCC->CurRoom.IgnetCfgs[maxRoomNetCfg] == (HashList*) StrBufNOTNULL)
524 return WCC->CurRoom.IgnetCfgs[WantThisOne];
526 WCC->CurRoom.IgnetCfgs[maxRoomNetCfg] = (HashList*) StrBufNOTNULL;
530 StrBuf_ServGetln(Line);
531 if (GetServerStatus(Line, &State) == 1)
533 const char *Pos = NULL;
535 int HaveRoomMailAlias = 0;
537 while(!Done && (StrBuf_ServGetln(Line) >= 0))
539 if (StrLength(Line) == 0)
541 if ( (StrLength(Line)==3) &&
542 !strcmp(ChrPtr(Line), "000"))
548 StrBufExtract_NextToken(Token, Line, &Pos, '|');
549 PutTo = GetTokenDefine(SKEY(Token), -1);
550 if (PutTo == roommailalias)
552 if (HaveRoomMailAlias > 0)
553 continue; /* Only ONE alias possible! */
557 (PutTo < maxRoomNetCfg) &&
558 (Pos != StrBufNOTNULL))
563 if (WCC->CurRoom.IgnetCfgs[PutTo] == NULL)
566 WCC->CurRoom.IgnetCfgs[PutTo] = NewHash(1, NULL);
570 n = GetCount(WCC->CurRoom.IgnetCfgs[PutTo]);
572 SubH = NewHash(1, NULL);
573 Put(WCC->CurRoom.IgnetCfgs[PutTo],
577 n = 1; /* #0 is the type... */
578 while (Pos != StrBufNOTNULL) {
579 Content = NewStrBuf();
580 StrBufExtract_NextToken(Content, Line, &Pos, '|');
582 if ((PutTo == roommailalias) && n == 1)
583 WCC->CurRoom.RoomAlias = Content;
596 else if (State == 550)
597 AppendImportantMessage(_("Higher access is required to access this function."), -1);
602 return WCC->CurRoom.IgnetCfgs[WantThisOne];
605 /** Unused function that orders rooms by the listorder flag */
606 int SortRoomsByListOrder(const void *room1, const void *room2)
608 folder *r1 = (folder*) GetSearchPayload(room1);
609 folder *r2 = (folder*) GetSearchPayload(room2);
611 if (r1->Order == r2->Order) return 0;
612 if (r1->Order > r2->Order) return 1;
616 int CompareRoomListByFloorRoomPrivFirst(const void *room1, const void *room2)
618 folder *r1 = (folder*) GetSearchPayload(room1);
619 folder *r2 = (folder*) GetSearchPayload(room2);
621 if ((r1->Floor == NULL) ||
626 * are we on the same floor? else sort by floor.
628 if (r1->Floor != r2->Floor)
631 * the private rooms are first in any case.
633 if (r1->Floor->ID == VIRTUAL_MY_FLOOR)
635 if (r2->Floor->ID == VIRTUAL_MY_FLOOR)
638 * else decide alpaheticaly by floorname
640 return (r1->Floor->AlphaN > r2->Floor->AlphaN)? 1 : -1;
644 * if we have different levels of subdirectories,
645 * we want the toplevel to be first, regardless of sort
648 if (((r1->nRoomNameParts > 1) ||
649 (r2->nRoomNameParts > 1) )&&
650 (r1->nRoomNameParts != r2->nRoomNameParts))
653 int nparts = (r1->nRoomNameParts > r2->nRoomNameParts)?
654 r2->nRoomNameParts : r1->nRoomNameParts;
656 for (i=0; i < nparts; i++)
658 ret = strcmp (ChrPtr(r1->name),
661 * Deltas in common parts? exit here.
668 * who's a subdirectory of whom?
670 if (r1->nRoomNameParts > r2->nRoomNameParts)
678 * else just sort alphabeticaly.
680 return strcmp (ChrPtr(r1->name),
684 int CompareRoomListByFloorRoomPrivFirstRev(const void *room1, const void *room2)
686 folder *r1 = (folder*) GetSearchPayload(room1);
687 folder *r2 = (folder*) GetSearchPayload(room2);
689 if ((r1->Floor == NULL) ||
694 * are we on the same floor? else sort by floor.
696 if (r2->Floor != r1->Floor)
699 * the private rooms are first in any case.
701 if (r1->Floor->ID == VIRTUAL_MY_FLOOR)
703 if (r2->Floor->ID == VIRTUAL_MY_FLOOR)
706 * else decide alpaheticaly by floorname
709 return (r1->Floor->AlphaN < r2->Floor->AlphaN)? 1 : -1;
713 * if we have different levels of subdirectories,
714 * we want the toplevel to be first, regardless of sort
717 if (((r1->nRoomNameParts > 1) ||
718 (r2->nRoomNameParts > 1) )&&
719 (r1->nRoomNameParts != r2->nRoomNameParts))
722 int nparts = (r1->nRoomNameParts > r2->nRoomNameParts)?
723 r2->nRoomNameParts : r1->nRoomNameParts;
725 for (i=0; i < nparts; i++)
728 * special cases if one room is top-level...
730 if (r2->nRoomNameParts == 1)
731 ret = strcmp (ChrPtr(r2->name),
732 ChrPtr(r1->RoomNameParts[i]));
733 else if (r1->nRoomNameParts == 1)
734 ret = strcmp (ChrPtr(r2->RoomNameParts[i]),
737 ret = strcmp (ChrPtr(r2->RoomNameParts[i]),
738 ChrPtr(r1->RoomNameParts[i]));
740 * Deltas in common parts? exit here.
747 * who's a subdirectory of whom?
749 if (r1->nRoomNameParts > r2->nRoomNameParts)
755 return strcmp (ChrPtr(r2->name),
759 int GroupchangeRoomListByFloorRoomPrivFirst(const void *room1, const void *room2)
761 folder *r1 = (folder*) room1;
762 folder *r2 = (folder*) room2;
765 if ((r1->Floor == NULL) ||
769 if (r1->Floor == r2->Floor)
774 static int columns = 3;
775 int boxes_per_column = 0;
778 nf = GetCount(WCC->Floors);
779 while (nf % columns != 0) ++nf;
780 boxes_per_column = (nf / columns);
781 if (boxes_per_column < 1)
782 boxes_per_column = 1;
783 if (r1->Floor->AlphaN % boxes_per_column == 0)
791 int CompareRooms(const folder *room1, const folder *room2)
793 if ((room1 == NULL) || (room2 == NULL))
795 return CompareRoomListByFloorRoomPrivFirst(room1, room2);
798 int ConditionalThisRoomIsStrBufContextAlias(StrBuf *Target, WCTemplputParams *TP)
803 eRoomParamType ParamType;
805 ParamType = GetTemplateTokenNumber(Target, TP, 2, eNotSet);
806 GetTemplateTokenString(Target, TP, 3, &pVal, &len);
808 if (ParamType == eNotSet)
810 return StrLength(WCC->CurRoom.RoomAlias) == 0;
812 else if (ParamType == eDomain)
814 const StrBuf *CtxStr = (const StrBuf*) CTX(CTX_STRBUF);
820 if (StrLength(WCC->CurRoom.RoomAlias) == 0)
823 if (strncmp(ChrPtr(WCC->CurRoom.RoomAlias), "room_", 5) != 0)
826 pAt = strchr(ChrPtr(WCC->CurRoom.RoomAlias), '@');
829 return strcmp(pAt + 1, ChrPtr(CtxStr)) == 0;
831 else if (ParamType == eAlias)
833 const StrBuf *CtxStr = (const StrBuf*) CTX(CTX_STRBUF);
838 if (StrLength(WCC->CurRoom.RoomAlias) == 0)
841 return strcmp(ChrPtr(WCC->CurRoom.RoomAlias), ChrPtr(CtxStr)) == 0;
845 LogTemplateError(Target, "TokenParameter", 2, TP,
846 "Invalid paramtype; need one of [eNotSet|eDomain|eAlias]");
852 int ConditionalRoomIsRESTSubRoom(StrBuf *Target, WCTemplputParams *TP)
855 folder *Folder = (folder *)CTX(CTX_ROOMS);
865 /* list only folders relative to the current floor... */
866 if (Folder->Floor != WCC->CurrentFloor)
869 urlp = GetCount(WCC->Directory);
870 delta = Folder->nRoomNameParts - urlp + 1;
872 syslog(0, "\n->%s: %d - %ld ",
873 ChrPtr(Folder->name),
875 Folder->nRoomNameParts);
876 /* list only the floors which are in relation to the dav_depth header */
877 if (WCC->Hdr->HR.dav_depth != delta) {
883 it = GetNewHashPos(WCC->Directory, 0);
884 /* Fast forward the floorname we checked above... */
885 GetNextHashPos(WCC->Directory, it, &len, &Key, &vDir);
887 if (Folder->nRoomNameParts > 1) {
889 (i > Folder->nRoomNameParts) && (j > urlp);
892 if (!GetNextHashPos(WCC->Directory,
893 it, &len, &Key, &vDir) ||
901 Dir = (StrBuf*) vDir;
902 if (strcmp(ChrPtr(Folder->RoomNameParts[i]),
914 if (!GetNextHashPos(WCC->Directory,
915 it, &len, &Key, &vDir) ||
921 return WCC->Hdr->HR.dav_depth == 1;
924 Dir = (StrBuf*) vDir;
925 if (WCC->Hdr->HR.dav_depth == 0) {
926 return (strcmp(ChrPtr(Folder->name),
940 /* we duplicate this, just to be shure its already done. */
941 RegisterCTX(CTX_ROOMS);
942 RegisterCTX(CTX_FLOORS);
944 RegisterIterator("ITERATE:THISROOM:WHO_KNOWS", 0, NULL, GetWhoKnowsHash, NULL, DeleteHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
945 RegisterIterator("ITERATE:THISROOM:GNET", 1, NULL, GetNetConfigHash, NULL, NULL, CTX_STRBUFARR, CTX_NONE, IT_NOFLAG);
946 RegisterIterator("ITERATE:THISROOM:MALIAS", 1, NULL, GetThisRoomMAlias, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
947 RegisterIterator("ITERATE:THISROOM:POSSIBLE:MALIAS", 1, NULL, GetThisRoomPossibleMAlias, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
949 RegisterIterator("LFLR", 0, NULL, GetFloorListHash, NULL, NULL, CTX_FLOORS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
950 RegisterIterator("LKRA", 0, NULL, GetRoomListHashLKRA, NULL, NULL, CTX_ROOMS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
951 RegisterIterator("LZRM", 0, NULL, GetZappedRoomListHash, NULL, DeleteHash, CTX_ROOMS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
952 RegisterIterator("LPRM", 0, NULL, GetRoomListHashLPRM, NULL, DeleteHash, CTX_ROOMS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
955 REGISTERTokenParamDefine(eNotSet);
956 REGISTERTokenParamDefine(eDomain);
957 REGISTERTokenParamDefine(eAlias);
960 RegisterConditional("COND:ROOM:REST:ISSUBROOM", 0, ConditionalRoomIsRESTSubRoom, CTX_ROOMS);
962 RegisterConditional("COND:THISROOM:ISALIAS:CONTEXTSTR", 0, ConditionalThisRoomIsStrBufContextAlias, CTX_NONE);
964 RegisterSortFunc(HKEY("byfloorroom"),
966 CompareRoomListByFloorRoomPrivFirst,
967 CompareRoomListByFloorRoomPrivFirstRev,
968 GroupchangeRoomListByFloorRoomPrivFirst,