2 * Lots of different room-related operations.
4 * Copyright (c) 1996-2012 by the citadel.org team
6 * This program is open source software. You can redistribute it and/or
7 * modify it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include "webserver.h"
18 ConstStr QRFlagList[] = {
19 {HKEY(strof(QR_PERMANENT))},
20 {HKEY(strof(QR_INUSE))},
21 {HKEY(strof(QR_PRIVATE))},
22 {HKEY(strof(QR_PASSWORDED))},
23 {HKEY(strof(QR_GUESSNAME))},
24 {HKEY(strof(QR_DIRECTORY))},
25 {HKEY(strof(QR_UPLOAD))},
26 {HKEY(strof(QR_DOWNLOAD))},
27 {HKEY(strof(QR_VISDIR))},
28 {HKEY(strof(QR_ANONONLY))},
29 {HKEY(strof(QR_ANONOPT))},
30 {HKEY(strof(QR_NETWORK))},
31 {HKEY(strof(QR_PREFONLY))},
32 {HKEY(strof(QR_READONLY))},
33 {HKEY(strof(QR_MAILBOX))}
35 ConstStr QR2FlagList[] = {
36 {HKEY(strof(QR2_SYSTEM))},
37 {HKEY(strof(QR2_SELFLIST))},
38 {HKEY(strof(QR2_COLLABDEL))},
39 {HKEY(strof(QR2_SUBJECTREQ))},
40 {HKEY(strof(QR2_SMTP_PUBLIC))},
41 {HKEY(strof(QR2_MODERATED))},
42 {HKEY(strof(QR2_NOUPLMSG))},
59 QRVec = NewStrBufPlain(NULL, 256);
63 if (StrLength(QRVec) > 0)
64 StrBufAppendBufPlain(QRVec, HKEY(" | "), 0);
65 StrBufAppendBufPlain(QRVec, CKEY(QRFlagList[j]), 0);
70 syslog(LOG_DEBUG, "DBG: QR-Vec [%ld] [%s]\n", QR, ChrPtr(QRVec));
76 void _DBG_QR2(long QR2)
82 QR2Vec = NewStrBufPlain(NULL, 256);
86 if (StrLength(QR2Vec) > 0)
87 StrBufAppendBufPlain(QR2Vec, HKEY(" | "), 0);
88 StrBufAppendBufPlain(QR2Vec, CKEY(QR2FlagList[j]), 0);
93 syslog(LOG_DEBUG, "DBG: QR2-Vec [%ld] [%s]\n", QR2, ChrPtr(QR2Vec));
107 /*******************************************************************************
108 ***************************** Goto Commands ***********************************
109 ******************************************************************************/
112 smart_goto(sbstr("room"));
116 if (!havebstr("room")) {
117 readloop(readnew, eUseDefault);
120 if (WC->CurRoom.view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
123 smart_goto(sbstr("room"));
129 void smart_goto(const StrBuf *next_room) {
130 if (gotoroom(next_room) / 100 == 2)
131 readloop(readnew, eUseDefault);
137 * goto a private room
139 void goto_private(void)
143 const StrBuf *gr_name;
146 if (!havebstr("ok_button")) {
150 gr_name = sbstr("gr_name");
152 strcpy(hold_rm, ChrPtr(WC->CurRoom.name));
153 serv_printf("GOTO %s|%s",
156 StrBuf_ServGetln(Buf);
157 if (GetServerStatus(Buf, &err) == 2) {
164 DoTemplate(HKEY("room_display_private"), NULL, &NoCtx);
168 StrBufCutLeft(Buf, 4);
169 AppendImportantMessage (SKEY(Buf));
170 Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
177 * back end routine to take the session to a new room
179 long gotoroom(const StrBuf *gname)
183 static long ls = (-1L);
185 int room_name_supplied = 0;
189 /* on fail, should we fallback to _BASEROOM_? */
190 failvisibly = ibstr("failvisibly");
192 /* store ungoto information */
193 if (StrLength(gname) > 0) {
194 room_name_supplied = 1;
196 if (room_name_supplied) {
197 strcpy(WCC->ugname, ChrPtr(WCC->CurRoom.name));
198 if (!strcasecmp(ChrPtr(gname), "_BASEROOM_")) {
205 /* move to the new room */
206 if (room_name_supplied) {
207 serv_printf("GOTO %s", ChrPtr(gname));
210 /* or just refresh the current state... */
211 serv_printf("GOTO 00000000000000000000");
213 StrBuf_ServGetln(Buf);
214 if (GetServerStatus(Buf, &err) != 2) {
219 serv_puts("GOTO _BASEROOM_");
220 StrBuf_ServGetln(Buf);
222 * well, we know that this is the fallback case,
223 * but we're interested that the first command
224 * didn't work out in first place.
226 if (GetServerStatus(Buf, NULL) != 2) {
231 FlushFolder(&WCC->CurRoom);
232 ParseGoto(&WCC->CurRoom, Buf);
234 if (room_name_supplied) {
235 remove_march(WCC->CurRoom.name);
247 void ParseGoto(folder *room, StrBuf *Line)
255 if (StrLength(Line) < 4) {
259 /* ignore the commandstate... */
260 Pos = ChrPtr(Line) + 4;
262 if (room->RoomNameParts != NULL)
265 for (i=0; i < room->nRoomNameParts; i++)
266 FreeStrBuf(&room->RoomNameParts[i]);
267 free(room->RoomNameParts);
268 room->RoomNameParts = NULL;
273 pBuf = NewStrBufPlain(NULL, StrLength(Line));
276 memset(room, 0, sizeof(folder));
279 StrBufExtract_NextToken(room->name, Line, &Pos, '|');
281 room->nNewMessages = StrBufExtractNext_long(Line, &Pos, '|');
282 if (room->nNewMessages > 0)
283 room->RAFlags |= UA_HASNEWMSGS;
285 room->nTotalMessages = StrBufExtractNext_long(Line, &Pos, '|');
287 room->ShowInfo = StrBufExtractNext_long(Line, &Pos, '|');
289 room->QRFlags = StrBufExtractNext_long(Line, &Pos, '|');
291 DBG_QR(room->QRFlags);
293 room->HighestRead = StrBufExtractNext_long(Line, &Pos, '|');
294 room->LastMessageRead = StrBufExtractNext_long(Line, &Pos, '|');
296 room->is_inbox = StrBufExtractNext_long(Line, &Pos, '|');
298 flag = StrBufExtractNext_long(Line, &Pos, '|');
299 if (WCC->is_aide || flag) {
300 room->RAFlags |= UA_ADMINALLOWED;
303 room->UsersNewMAilboxMessages = StrBufExtractNext_long(Line, &Pos, '|');
305 room->floorid = StrBufExtractNext_int(Line, &Pos, '|');
307 room->view = StrBufExtractNext_long(Line, &Pos, '|');
309 room->defview = StrBufExtractNext_long(Line, &Pos, '|');
311 flag = StrBufExtractNext_long(Line, &Pos, '|');
313 room->RAFlags |= UA_ISTRASH;
315 room->QRFlags2 = StrBufExtractNext_long(Line, &Pos, '|');
316 DBG_QR2(room->QRFlags2);
318 /* find out, whether we are in a sub-room */
319 room->nRoomNameParts = StrBufNum_tokens(room->name, '\\');
320 if (room->nRoomNameParts > 1)
325 room->RoomNameParts = malloc(sizeof(StrBuf*) * (room->nRoomNameParts + 1));
326 memset(room->RoomNameParts, 0, sizeof(StrBuf*) * (room->nRoomNameParts + 1));
327 for (i=0; i < room->nRoomNameParts; i++)
329 room->RoomNameParts[i] = NewStrBuf();
330 StrBufExtract_NextToken(room->RoomNameParts[i],
331 room->name, &Pos, '\\');
335 /* Private mailboxes on the main floor get remapped to the personal folder */
336 if ((room->QRFlags & QR_MAILBOX) &&
337 (room->floorid == 0))
339 room->floorid = VIRTUAL_MY_FLOOR;
340 if ((room->nRoomNameParts == 1) &&
341 (StrLength(room->name) == 4) &&
342 (strcmp(ChrPtr(room->name), "Mail") == 0))
348 /* get a pointer to the floor we're on: */
349 if (WCC->Floors == NULL)
350 GetFloorListHash(NULL, NULL);
352 GetHash(WCC->Floors, IKEY(room->floorid), &vFloor);
353 room->Floor = (const Floor*) vFloor;
357 * Delete the current room
359 void delete_room(void)
361 StrBuf *Line = NewStrBuf();
362 const StrBuf *GoBstr;
364 GoBstr = sbstr("go");
368 if (gotoroom(GoBstr) == 200)
371 StrBuf_ServGetln(Line);
372 if (GetServerStatusMsg(Line, NULL, 1, 2) == 2) {
376 Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
394 StrBuf *final_destination;
397 * If the forget-room routine fails for any reason, we fall back
398 * to the current room; otherwise, we go to the Lobby
400 final_destination = NewStrBufDup(WC->CurRoom.name);
402 if (havebstr("ok_button")) {
403 serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
404 serv_getln(buf, sizeof buf);
407 serv_getln(buf, sizeof buf);
409 FlushStrBuf(final_destination);
410 StrBufAppendBufPlain(final_destination, HKEY("_BASEROOM_"), 0);
415 smart_goto(final_destination);
416 FreeStrBuf(&final_destination);
421 * mark all messages in current room as having been read
423 void slrp_highest(void)
427 serv_puts("SLRP HIGHEST");
428 serv_getln(buf, sizeof buf);
444 /*******************************************************************************
445 ***************************** Modify Rooms ************************************
446 ******************************************************************************/
452 void LoadRoomAide(void)
457 if (WCC->CurRoom.RoomAideLoaded)
460 WCC->CurRoom.RoomAideLoaded = 1;
463 StrBuf_ServGetln(Buf);
464 if (GetServerStatus(Buf, NULL) != 2) {
465 FlushStrBuf(WCC->CurRoom.RoomAide);
466 AppendImportantMessage (ChrPtr(Buf) + 4,
471 Pos = ChrPtr(Buf) + 4;
473 FreeStrBuf(&WCC->CurRoom.RoomAide);
474 WCC->CurRoom.RoomAide = NewStrBufPlain (NULL, StrLength (Buf));
476 StrBufExtract_NextToken(WCC->CurRoom.RoomAide, Buf, &Pos, '|');
481 int SaveRoomAide(folder *Room)
485 serv_printf("SETA %s", ChrPtr(Room->RoomAide));
486 StrBuf_ServGetln(Buf);
487 if (GetServerStatus(Buf, NULL) != 2) {
488 StrBufCutLeft(Buf, 4);
489 AppendImportantMessage (SKEY(Buf));
498 int GetCurrentRoomFlags(folder *Room, int CareForStatusMessage)
504 StrBuf_ServGetln(Buf);
505 if (GetServerStatus(Buf, NULL) != 2) {
506 FlushStrBuf(Room->XAPass);
507 FlushStrBuf(Room->Directory);
508 StrBufCutLeft(Buf, 4);
509 if (CareForStatusMessage)
510 AppendImportantMessage (SKEY(Buf));
517 Pos = ChrPtr(Buf) + 4;
519 FreeStrBuf(&Room->XAPass);
520 FreeStrBuf(&Room->Directory);
522 Room->XAPass = NewStrBufPlain (NULL, StrLength (Buf));
523 Room->Directory = NewStrBufPlain (NULL, StrLength (Buf));
525 FreeStrBuf(&Room->name);
526 Room->name = NewStrBufPlain(NULL, StrLength(Buf));
527 StrBufExtract_NextToken(Room->name, Buf, &Pos, '|');
529 StrBufExtract_NextToken(Room->XAPass, Buf, &Pos, '|');
530 StrBufExtract_NextToken(Room->Directory, Buf, &Pos, '|');
532 Room->QRFlags = StrBufExtractNext_long(Buf, &Pos, '|');
533 Room->floorid = StrBufExtractNext_long(Buf, &Pos, '|');
534 Room->Order = StrBufExtractNext_long(Buf, &Pos, '|');
535 Room->defview = StrBufExtractNext_long(Buf, &Pos, '|');
536 Room->QRFlags2 = StrBufExtractNext_long(Buf, &Pos, '|');
544 int SetCurrentRoomFlags(folder *Room)
549 DBG_QR(Room->QRFlags);
550 DBG_QR2(Room->QRFlags2);
552 serv_printf("SETR %s|%s|%s|%ld|%d|%d|%ld|%ld|%ld",
554 ChrPtr(Room->XAPass),
555 ChrPtr(Room->Directory),
563 StrBuf_ServGetln(Buf);
564 if (GetServerStatus(Buf, NULL) != 2) {
565 StrBufCutLeft(Buf, 4);
566 AppendImportantMessage (SKEY(Buf));
575 void LoadRoomXA (void)
579 if (WCC->CurRoom.XALoaded > 0)
582 GetCurrentRoomFlags(&WCC->CurRoom, 0);
586 void LoadXRoomPic(void)
591 if (WCC->CurRoom.XHaveRoomPicLoaded)
594 WCC->CurRoom.XHaveRoomPicLoaded = 1;
596 serv_puts("OIMG _roompic_");
597 StrBuf_ServGetln(Buf);
598 if (GetServerStatus(Buf, NULL) != 2) {
599 WCC->CurRoom.XHaveRoomPic = 0;
601 WCC->CurRoom.XHaveRoomPic = 1;
604 StrBuf_ServGetln(Buf);
605 GetServerStatus(Buf, NULL);
610 void LoadXRoomInfoText(void)
616 if (WCC->CurRoom.XHaveInfoTextLoaded) {
620 WCC->CurRoom.XHaveInfoTextLoaded = 1;
625 StrBuf_ServGetln(Buf);
626 if (GetServerStatus(Buf, NULL) == 1) {
627 WCC->CurRoom.XInfoText = NewStrBuf ();
629 while (!Done && StrBuf_ServGetln(Buf)>=0) {
630 if ( (StrLength(Buf)==3) &&
631 !strcmp(ChrPtr(Buf), "000"))
634 StrBufAppendBuf(WCC->CurRoom.XInfoText, Buf, 0);
642 void LoadXRoomXCountFiles(void)
648 if (WCC->CurRoom.XHaveDownloadCount)
651 WCC->CurRoom.XHaveDownloadCount = 1;
655 StrBuf_ServGetln(Buf);
656 if (GetServerStatus(Buf, NULL) == 1) {
658 while (!Done && StrBuf_ServGetln(Buf)>=0) {
659 if ( (StrLength(Buf)==3) &&
660 !strcmp(ChrPtr(Buf), "000"))
663 WCC->CurRoom.XDownloadCount++;
672 * Toggle self-service list subscription
674 void toggle_self_service(void) {
677 if (GetCurrentRoomFlags (&WCC->CurRoom, 1) == 0)
680 if (yesbstr("QR2_SelfList"))
681 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SELFLIST;
683 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SELFLIST;
685 if (yesbstr("QR2_SMTP_PUBLIC"))
686 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SMTP_PUBLIC;
688 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SMTP_PUBLIC;
690 if (yesbstr("QR2_Moderated"))
691 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_MODERATED;
693 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_MODERATED;
694 if (yesbstr("QR2_SubsOnly"))
695 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SMTP_PUBLIC;
697 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SMTP_PUBLIC;
699 SetCurrentRoomFlags (&WCC->CurRoom);
701 output_headers(1, 1, 1, 0, 0, 0);
702 do_template("room_edit");
709 * save new parameters for a room
715 const StrBuf *er_name;
716 const StrBuf *er_password;
717 const StrBuf *er_dirname;
718 const StrBuf *er_roomaide;
722 templ = sbstr("template");
723 if (!havebstr("ok_button")) {
724 putlbstr("success", 0);
725 AppendImportantMessage(_("Cancelled. Changes were not saved."), -1);
727 output_headers(1, 0, 0, 0, 0, 0);
728 DoTemplate(SKEY(templ), NULL, &NoCtx);
732 output_headers(1, 1, 1, 0, 0, 0);
733 do_template("room_edit");
739 if (GetCurrentRoomFlags (&WCC->CurRoom, 1) == 0) {
740 putlbstr("success", 0);
742 output_headers(1, 0, 0, 0, 0, 0);
743 DoTemplate(SKEY(templ), NULL, &NoCtx);
747 output_headers(1, 1, 1, 0, 0, 0);
748 do_template("room_edit");
755 WCC->CurRoom.QRFlags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
758 if (!strcmp(ChrPtr(Ptr), "invonly")) {
759 WCC->CurRoom.QRFlags |= (QR_PRIVATE);
761 if (!strcmp(ChrPtr(Ptr), "hidden")) {
762 WCC->CurRoom.QRFlags |= (QR_PRIVATE | QR_GUESSNAME);
764 if (!strcmp(ChrPtr(Ptr), "passworded")) {
765 WCC->CurRoom.QRFlags |= (QR_PRIVATE | QR_PASSWORDED);
767 if (!strcmp(ChrPtr(Ptr), "personal")) {
768 WCC->CurRoom.QRFlags |= QR_MAILBOX;
770 WCC->CurRoom.QRFlags &= ~QR_MAILBOX;
773 if (yesbstr("prefonly")) {
774 WCC->CurRoom.QRFlags |= QR_PREFONLY;
776 WCC->CurRoom.QRFlags &= ~QR_PREFONLY;
779 if (yesbstr("readonly")) {
780 WCC->CurRoom.QRFlags |= QR_READONLY;
782 WCC->CurRoom.QRFlags &= ~QR_READONLY;
785 if (yesbstr("collabdel")) {
786 WCC->CurRoom.QRFlags2 |= QR2_COLLABDEL;
788 WCC->CurRoom.QRFlags2 &= ~QR2_COLLABDEL;
791 if (yesbstr("permanent")) {
792 WCC->CurRoom.QRFlags |= QR_PERMANENT;
794 WCC->CurRoom.QRFlags &= ~QR_PERMANENT;
797 if (yesbstr("subjectreq")) {
798 WCC->CurRoom.QRFlags2 |= QR2_SUBJECTREQ;
800 WCC->CurRoom.QRFlags2 &= ~QR2_SUBJECTREQ;
803 if (yesbstr("network")) {
804 WCC->CurRoom.QRFlags |= QR_NETWORK;
806 WCC->CurRoom.QRFlags &= ~QR_NETWORK;
809 if (yesbstr("directory")) {
810 WCC->CurRoom.QRFlags |= QR_DIRECTORY;
812 WCC->CurRoom.QRFlags &= ~QR_DIRECTORY;
815 if (yesbstr("ulallowed")) {
816 WCC->CurRoom.QRFlags |= QR_UPLOAD;
818 WCC->CurRoom.QRFlags &= ~QR_UPLOAD;
821 if (yesbstr("dlallowed")) {
822 WCC->CurRoom.QRFlags |= QR_DOWNLOAD;
824 WCC->CurRoom.QRFlags &= ~QR_DOWNLOAD;
827 if (yesbstr("ulmsg")) {
828 WCC->CurRoom.QRFlags2 |= QR2_NOUPLMSG;
830 WCC->CurRoom.QRFlags2 &= ~QR2_NOUPLMSG;
833 if (yesbstr("visdir")) {
834 WCC->CurRoom.QRFlags |= QR_VISDIR;
836 WCC->CurRoom.QRFlags &= ~QR_VISDIR;
841 WCC->CurRoom.QRFlags &= ~(QR_ANONONLY | QR_ANONOPT);
842 if (!strcmp(ChrPtr(Ptr), "anononly"))
843 WCC->CurRoom.QRFlags |= QR_ANONONLY;
844 if (!strcmp(ChrPtr(Ptr), "anon2"))
845 WCC->CurRoom.QRFlags |= QR_ANONOPT;
847 er_name = sbstr("er_name");
848 er_dirname = sbstr("er_dirname");
849 er_roomaide = sbstr("er_roomaide");
850 er_password = sbstr("er_password");
852 FlushStrBuf(WCC->CurRoom.name);
853 StrBufAppendBuf(WCC->CurRoom.name, er_name, 0);
855 FlushStrBuf(WCC->CurRoom.Directory);
856 StrBufAppendBuf(WCC->CurRoom.Directory, er_dirname, 0);
858 FlushStrBuf(WCC->CurRoom.RoomAide);
859 StrBufAppendBuf(WCC->CurRoom.RoomAide, er_roomaide, 0);
861 FlushStrBuf(WCC->CurRoom.XAPass);
862 StrBufAppendBuf(WCC->CurRoom.XAPass, er_password, 0);
864 WCC->CurRoom.BumpUsers = yesbstr("bump");
866 WCC->CurRoom.floorid = ibstr("er_floor");
868 succ1 = SetCurrentRoomFlags(&WCC->CurRoom);
870 succ2 = SaveRoomAide (&WCC->CurRoom);
872 if (succ1 + succ2 == 0) {
873 putlbstr("success", 1);
874 AppendImportantMessage (_("Your changes have been saved."), -1);
877 putlbstr("success", 0);
880 output_headers(1, 0, 0, 0, 0, 0);
881 DoTemplate(SKEY(templ), NULL, &NoCtx);
885 output_headers(1, 1, 1, 0, 0, 0);
886 do_template("room_edit");
895 * Display form for Invite, Kick, and show Who Knows a room
897 void do_invt_kick(void)
900 const StrBuf *UserNames;
905 if (GetCurrentRoomFlags(&WCC->CurRoom, 1) == 1)
908 UserNames = sbstr("username");
909 Kick = havebstr("kick_button");
910 Invite = havebstr("invite_button");
912 User = NewStrBufPlain(NULL, StrLength(UserNames));
915 Pos = ChrPtr(UserNames);
916 while (Pos != StrBufNOTNULL)
918 StrBufExtract_NextToken(User, UserNames, &Pos, ',');
920 if ((StrLength(User) > 0) && (Kick))
922 serv_printf("KICK %s", ChrPtr(User));
923 if (StrBuf_ServGetln(Buf) < 0)
925 if (GetServerStatus(Buf, NULL) != 2) {
926 StrBufCutLeft(Buf, 4);
927 AppendImportantMessage(SKEY(Buf));
930 _("User '%s' kicked out of room '%s'."),
932 ChrPtr(WCC->CurRoom.name)
934 AppendImportantMessage(SKEY(Buf));
937 else if ((StrLength(User) > 0) && (Invite))
939 serv_printf("INVT %s", ChrPtr(User));
940 if (StrBuf_ServGetln(Buf) < 0)
942 if (GetServerStatus(Buf, NULL) != 2) {
943 StrBufCutLeft(Buf, 4);
944 AppendImportantMessage(SKEY(Buf));
947 _("User '%s' invited to room '%s'."),
949 ChrPtr(WCC->CurRoom.name)
951 AppendImportantMessage(SKEY(Buf));
957 output_headers(1, 1, 1, 0, 0, 0);
958 do_template("room_edit");
969 const StrBuf *er_name;
970 const StrBuf *er_type;
971 const StrBuf *er_password;
972 const StrBuf *template;
978 template = sbstr("template");
979 if ((WCC == NULL) || !havebstr("ok_button")) {
980 putlbstr("success", 0);
981 AppendImportantMessage(_("Cancelled. No new room was created."), -1);
982 if (template != NULL) {
983 output_headers(1, 0, 0, 0, 0, 0);
984 DoTemplate(SKEY(template), NULL, &NoCtx);
992 er_name = sbstr("er_name");
993 er_type = sbstr("type");
994 er_password = sbstr("er_password");
995 er_floor = ibstr("er_floor");
996 er_view = ibstr("er_view");
999 if (!strcmp(ChrPtr(er_type), "hidden"))
1001 else if (!strcmp(ChrPtr(er_type), "passworded"))
1003 else if (!strcmp(ChrPtr(er_type), "invonly"))
1005 else if (!strcmp(ChrPtr(er_type), "personal"))
1008 serv_printf("CRE8 1|%s|%d|%s|%d|%d|%d",
1011 ChrPtr(er_password),
1017 StrBuf_ServGetln(Line);
1018 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
1019 putlbstr("success", 0);
1021 if (template != NULL) {
1022 output_headers(1, 0, 0, 0, 0, 0);
1023 DoTemplate(SKEY(template), NULL, &NoCtx);
1027 display_main_menu();
1031 /** TODO: Room created, now update the left hand icon bar for this user */
1034 serv_printf("VIEW %d", er_view);
1035 StrBuf_ServGetln(Line);
1036 FreeStrBuf(&Line); /* TODO: should we care about errors? */
1037 WCC->CurRoom.view = er_view;
1039 putlbstr("success", 1);
1040 if (template != NULL) {
1041 output_headers(1, 0, 0, 0, 0, 0);
1042 DoTemplate(SKEY(template), NULL, &NoCtx);
1045 else if ( (WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) {
1046 output_headers(1, 1, 1, 0, 0, 0);
1047 do_template("room_edit");
1050 smart_goto(WCC->CurRoom.name);
1060 * Change the view for this room
1062 void change_view(void) {
1066 newview = lbstr("view");
1067 serv_printf("VIEW %d", newview);
1068 serv_getln(buf, sizeof buf);
1069 WC->CurRoom.view = newview;
1070 smart_goto(WC->CurRoom.name);
1076 * Set the message expire policy for this room and/or floor
1078 void set_room_policy(void) {
1081 if (!havebstr("ok_button")) {
1082 AppendImportantMessage(_("Cancelled. Changes were not saved."), -1);
1083 output_headers(1, 1, 1, 0, 0, 0);
1084 do_template("room_edit");
1091 serv_printf("SPEX room|%d|%d", ibstr("roompolicy"), ibstr("roomvalue"));
1092 StrBuf_ServGetln(Line);
1093 GetServerStatusMsg(Line, NULL, 1, 0);
1094 if (WC->axlevel >= 6) {
1095 serv_printf("SPEX floor|%d|%d", ibstr("floorpolicy"), ibstr("floorvalue"));
1096 StrBuf_ServGetln(Line);
1097 GetServerStatusMsg(Line, NULL, 1, 0);
1100 ReloadCurrentRoom();
1102 output_headers(1, 1, 1, 0, 0, 0);
1103 do_template("room_edit");
1110 * Perform changes to a room's network configuration
1112 void netedit(void) {
1123 int malias_set_default = 0;
1128 if (havebstr("force_room")) {
1129 gotoroom(sbstr("force_room"));
1131 /*/ TODO: do line dynamic! */
1132 if (havebstr("line_pop3host")) {
1133 strcpy(line, bstr("prefix"));
1134 strcat(line, bstr("line_pop3host"));
1136 strcat(line, bstr("line_pop3user"));
1138 strcat(line, bstr("line_pop3pass"));
1140 strcat(line, ibstr("line_pop3keep") ? "1" : "0" );
1142 sprintf(&line[strlen(line)],"%ld", lbstr("line_pop3int"));
1143 strcat(line, bstr("suffix"));
1145 else if (havebstr("line")) {
1146 strcpy(line, bstr("prefix"));
1147 strcat(line, bstr("line"));
1148 strcat(line, bstr("suffix"));
1150 else if (havebstr("alias")) {
1152 domain = bstr("aliasdomain");
1153 if ((domain == NULL) || IsEmptyStr(domain))
1155 malias_set_default = 1;
1156 strcpy(line, bstr("prefix"));
1157 strcat(line, bstr("default_aliasdomain"));
1163 strcat(line, bstr("prefix"));
1164 if (!IsEmptyStr(domain))
1167 strcat(line, domain);
1170 strcat(line, "room_");
1171 strcat(line, ChrPtr(WC->CurRoom.name));
1175 output_headers(1, 1, 1, 0, 0, 0);
1176 do_template("room_edit");
1182 TmpBuf = NewStrBuf();
1184 serv_puts("GNET "FILE_MAILALIAS);
1187 StrBuf_ServGetln(Line);
1188 if (GetServerStatus(Line, NULL) != 1) {
1189 AppendImportantMessage(SRV_STATUS_MSG(Line));
1191 output_headers(1, 1, 1, 0, 0, 0);
1192 do_template("room_edit");
1197 /** This loop works for add *or* remove. Spiffy, eh? */
1199 extract_token(cmpb0, line, 0, sepchar, sizeof cmpb0);
1200 extract_token(cmpb1, line, 1, sepchar, sizeof cmpb1);
1201 while (!Done && StrBuf_ServGetln(Line)>=0) {
1202 if ( (StrLength(Line)==3) &&
1203 !strcmp(ChrPtr(Line), "000"))
1209 if (StrLength(Line) == 0)
1212 if (malias_set_default)
1214 if (strncasecmp(ChrPtr(Line), HKEY("roommailalias|")) != 0)
1216 StrBufAppendBufPlain(Line, HKEY("\n"), 0);
1217 StrBufAppendBuf(TmpBuf, Line, 0);
1222 extract_token(cmpa0, ChrPtr(Line), 0, sepchar, sizeof cmpa0);
1223 extract_token(cmpa1, ChrPtr(Line), 1, sepchar, sizeof cmpa1);
1224 if ( (strcasecmp(cmpa0, cmpb0)) || (strcasecmp(cmpa1, cmpb1)) )
1226 StrBufAppendBufPlain(Line, HKEY("\n"), 0);
1227 StrBufAppendBuf(TmpBuf, Line, 0);
1234 serv_puts("SNET "FILE_MAILALIAS);
1237 StrBuf_ServGetln(Line);
1238 if (GetServerStatus(Line, NULL) != 4) {
1240 AppendImportantMessage(SRV_STATUS_MSG(Line));
1241 output_headers(1, 1, 1, 0, 0, 0);
1242 do_template("room_edit");
1245 FreeStrBuf(&TmpBuf);
1249 serv_putbuf(TmpBuf);
1250 FreeStrBuf(&TmpBuf);
1252 if (havebstr("add_button")) {
1253 num_addrs = num_tokens(bstr("line"), ',');
1254 if (num_addrs < 2) {
1255 /* just adding one node or address */
1259 /* adding multiple addresses separated by commas */
1260 for (i=0; i<num_addrs; ++i) {
1261 strcpy(line, bstr("prefix"));
1262 extract_token(buf, bstr("line"), i, ',', sizeof buf);
1265 strcat(line, bstr("suffix"));
1273 StrBuf_ServGetln(Line);
1274 if (GetServerStatus(Line, NULL) != 2) { /* WHOOOPS? ERROR? */
1275 AppendImportantMessage(SRV_STATUS_MSG(Line));
1276 StrBuf_ServGetln(Line); /* resync... */
1280 FlushIgnetCfgs(&WC->CurRoom);
1283 output_headers(1, 1, 1, 0, 0, 0);
1284 do_template("room_edit");
1289 * Known rooms list (box style)
1293 DeleteHash(&WC->Rooms);
1294 output_headers(1, 1, 1, 0, 0, 0);
1295 do_template("knrooms");
1316 /*******************************************************************************
1317 ********************** FLOOR Coomands *****************************************
1318 ******************************************************************************/
1323 * delete the actual floor
1325 void delete_floor(void) {
1330 floornum = ibstr("floornum");
1332 serv_printf("KFLR %d|1", floornum);
1334 StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
1336 if (GetServerStatus(Buf, NULL) == 2) {
1337 StrBufPlain(Buf, _("Floor has been deleted."),-1);
1340 StrBufCutLeft(Buf, 4);
1342 AppendImportantMessage (SKEY(Buf));
1345 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1350 * start creating a new floor
1352 void create_floor(void) {
1357 serv_printf("CFLR %s|1", bstr("floorname"));
1358 StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
1360 if (GetServerStatus(Buf, NULL) == 2) {
1361 StrBufPlain(Buf, _("New floor has been created."),-1);
1364 StrBufCutLeft(Buf, 4);
1366 AppendImportantMessage (SKEY(Buf));
1368 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1376 void rename_floor(void) {
1382 serv_printf("EFLR %d|%s", ibstr("floornum"), bstr("floorname"));
1383 StrBuf_ServGetln(Buf);
1385 StrBufCutLeft(Buf, 4);
1386 AppendImportantMessage (SKEY(Buf));
1388 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1394 void jsonRoomFlr(void)
1396 /* Send as our own (application/json) content type */
1397 hprintf("HTTP/1.1 200 OK\r\n");
1398 hprintf("Content-type: application/json; charset=utf-8\r\n");
1399 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1400 hprintf("Connection: close\r\n");
1401 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1403 DoTemplate(HKEY("json_roomflr"),NULL,&NoCtx);
1407 void _FlushRoomList(wcsession *WCC)
1409 free_march_list(WCC);
1410 DeleteHash(&WCC->Floors);
1411 DeleteHash(&WCC->Rooms);
1412 DeleteHash(&WCC->FloorsByName);
1413 FlushFolder(&WCC->CurRoom);
1416 void ReloadCurrentRoom(void)
1418 wcsession *WCC = WC;
1421 CurRoom = WCC->CurRoom.name;
1422 WCC->CurRoom.name = NULL;
1423 _FlushRoomList(WCC);
1425 FreeStrBuf(&CurRoom);
1428 void FlushRoomlist(void)
1430 wcsession *WCC = WC;
1431 _FlushRoomList(WCC);
1439 RegisterPreference("roomlistview",
1440 _("Room list view"),
1443 RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO, NULL);
1445 WebcitAddUrlHandler(HKEY("json_roomflr"), "", 0, jsonRoomFlr, 0);
1447 WebcitAddUrlHandler(HKEY("delete_floor"), "", 0, delete_floor, 0);
1448 WebcitAddUrlHandler(HKEY("rename_floor"), "", 0, rename_floor, 0);
1449 WebcitAddUrlHandler(HKEY("create_floor"), "", 0, create_floor, 0);
1451 WebcitAddUrlHandler(HKEY("knrooms"), "", 0, knrooms, ANONYMOUS);
1452 WebcitAddUrlHandler(HKEY("dotgoto"), "", 0, dotgoto, NEED_URL);
1453 WebcitAddUrlHandler(HKEY("dotskip"), "", 0, dotskip, NEED_URL);
1455 WebcitAddUrlHandler(HKEY("goto_private"), "", 0, goto_private, NEED_URL);
1456 WebcitAddUrlHandler(HKEY("zap"), "", 0, zap, 0);
1457 WebcitAddUrlHandler(HKEY("entroom"), "", 0, entroom, 0);
1458 WebcitAddUrlHandler(HKEY("do_invt_kick"), "", 0, do_invt_kick, 0);
1460 WebcitAddUrlHandler(HKEY("netedit"), "", 0, netedit, 0);
1461 WebcitAddUrlHandler(HKEY("editroom"), "", 0, editroom, 0);
1462 WebcitAddUrlHandler(HKEY("delete_room"), "", 0, delete_room, 0);
1463 WebcitAddUrlHandler(HKEY("set_room_policy"), "", 0, set_room_policy, 0);
1464 WebcitAddUrlHandler(HKEY("changeview"), "", 0, change_view, 0);
1465 WebcitAddUrlHandler(HKEY("toggle_self_service"), "", 0, toggle_self_service, 0);
1468 REGISTERTokenParamDefine(QR_PERMANENT);
1469 REGISTERTokenParamDefine(QR_INUSE);
1470 REGISTERTokenParamDefine(QR_PRIVATE);
1471 REGISTERTokenParamDefine(QR_PASSWORDED);
1472 REGISTERTokenParamDefine(QR_GUESSNAME);
1473 REGISTERTokenParamDefine(QR_DIRECTORY);
1474 REGISTERTokenParamDefine(QR_UPLOAD);
1475 REGISTERTokenParamDefine(QR_DOWNLOAD);
1476 REGISTERTokenParamDefine(QR_VISDIR);
1477 REGISTERTokenParamDefine(QR_ANONONLY);
1478 REGISTERTokenParamDefine(QR_ANONOPT);
1479 REGISTERTokenParamDefine(QR_NETWORK);
1480 REGISTERTokenParamDefine(QR_PREFONLY);
1481 REGISTERTokenParamDefine(QR_READONLY);
1482 REGISTERTokenParamDefine(QR_MAILBOX);
1483 REGISTERTokenParamDefine(QR2_SYSTEM);
1484 REGISTERTokenParamDefine(QR2_SELFLIST);
1485 REGISTERTokenParamDefine(QR2_COLLABDEL);
1486 REGISTERTokenParamDefine(QR2_SUBJECTREQ);
1487 REGISTERTokenParamDefine(QR2_SMTP_PUBLIC);
1488 REGISTERTokenParamDefine(QR2_MODERATED);
1489 REGISTERTokenParamDefine(QR2_NOUPLMSG);
1491 REGISTERTokenParamDefine(UA_KNOWN);
1492 REGISTERTokenParamDefine(UA_GOTOALLOWED);
1493 REGISTERTokenParamDefine(UA_HASNEWMSGS);
1494 REGISTERTokenParamDefine(UA_ZAPPED);
1495 REGISTERTokenParamDefine(UA_POSTALLOWED);
1496 REGISTERTokenParamDefine(UA_ADMINALLOWED);
1497 REGISTERTokenParamDefine(UA_DELETEALLOWED);
1498 REGISTERTokenParamDefine(UA_REPLYALLOWED);
1499 REGISTERTokenParamDefine(UA_ISTRASH);
1501 REGISTERTokenParamDefine(US_NEEDVALID);
1502 REGISTERTokenParamDefine(US_PERM);
1503 REGISTERTokenParamDefine(US_LASTOLD);
1504 REGISTERTokenParamDefine(US_EXPERT);
1505 REGISTERTokenParamDefine(US_UNLISTED);
1506 REGISTERTokenParamDefine(US_NOPROMPT);
1507 REGISTERTokenParamDefine(US_PROMPTCTL);
1508 REGISTERTokenParamDefine(US_DISAPPEAR);
1509 REGISTERTokenParamDefine(US_REGIS);
1510 REGISTERTokenParamDefine(US_PAGINATOR);
1511 REGISTERTokenParamDefine(US_INTERNET);
1512 REGISTERTokenParamDefine(US_FLOORS);
1513 REGISTERTokenParamDefine(US_COLOR);
1514 REGISTERTokenParamDefine(US_USER_SET);
1516 REGISTERTokenParamDefine(VIEW_BBS);
1517 REGISTERTokenParamDefine(VIEW_MAILBOX);
1518 REGISTERTokenParamDefine(VIEW_ADDRESSBOOK);
1519 REGISTERTokenParamDefine(VIEW_CALENDAR);
1520 REGISTERTokenParamDefine(VIEW_TASKS);
1521 REGISTERTokenParamDefine(VIEW_NOTES);
1522 REGISTERTokenParamDefine(VIEW_WIKI);
1523 REGISTERTokenParamDefine(VIEW_CALBRIEF);
1524 REGISTERTokenParamDefine(VIEW_JOURNAL);
1525 REGISTERTokenParamDefine(VIEW_BLOG);
1526 REGISTERTokenParamDefine(VIEW_QUEUE);
1527 REGISTERTokenParamDefine(VIEW_WIKIMD);
1530 /* server internal, we need to know but ignore them. */
1531 REGISTERTokenParamDefine(subpending);
1532 REGISTERTokenParamDefine(unsubpending);
1533 REGISTERTokenParamDefine(lastsent);
1535 REGISTERTokenParamDefine(ignet_push_share);
1536 { /* these are the parts of an IGNET push config */
1537 REGISTERTokenParamDefine(GNET_IGNET_NODE);
1538 REGISTERTokenParamDefine(GNET_IGNET_ROOM);
1540 REGISTERTokenParamDefine(listrecp);
1541 REGISTERTokenParamDefine(digestrecp);
1542 REGISTERTokenParamDefine(pop3client);
1543 { /* These are the parts of a pop3 client line... */
1544 REGISTERTokenParamDefine(GNET_POP3_HOST);
1545 REGISTERTokenParamDefine(GNET_POP3_USER);
1546 REGISTERTokenParamDefine(GNET_POP3_DONT_DELETE_REMOTE);
1547 REGISTERTokenParamDefine(GNET_POP3_INTERVAL);
1549 REGISTERTokenParamDefine(rssclient);
1550 REGISTERTokenParamDefine(participate);
1551 REGISTERTokenParamDefine(roommailalias);
1559 SessionDestroyModule_ROOMOPS
1562 _FlushRoomList (sess);