3 * Lots of different room-related operations.
5 * Copyright (c) 1996-2016 by the citadel.org team
7 * This program is open source software. You can redistribute it and/or
8 * modify it under the terms of the GNU General Public License, version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include "webserver.h"
19 ConstStr QRFlagList[] = {
20 { HKEY(strof(QR_PERMANENT)) },
21 { HKEY(strof(QR_INUSE)) },
22 { HKEY(strof(QR_PRIVATE)) },
23 { HKEY(strof(QR_PASSWORDED)) },
24 { HKEY(strof(QR_GUESSNAME)) },
25 { HKEY(strof(QR_DIRECTORY)) },
26 { HKEY(strof(QR_UPLOAD)) },
27 { HKEY(strof(QR_DOWNLOAD)) },
28 { HKEY(strof(QR_VISDIR)) },
29 { HKEY(strof(QR_ANONONLY)) },
30 { HKEY(strof(QR_ANONOPT)) },
31 { HKEY(strof(QR_NETWORK)) },
32 { HKEY(strof(QR_PREFONLY)) },
33 { HKEY(strof(QR_READONLY)) },
34 { HKEY(strof(QR_MAILBOX)) }
37 ConstStr QR2FlagList[] = {
38 { HKEY(strof(QR2_SYSTEM)) },
39 { HKEY(strof(QR2_SELFLIST)) },
40 { HKEY(strof(QR2_COLLABDEL)) },
41 { HKEY(strof(QR2_SUBJECTREQ)) },
42 { HKEY(strof(QR2_SMTP_PUBLIC)) },
43 { HKEY(strof(QR2_MODERATED)) },
44 { HKEY(strof(QR2_NOUPLMSG)) },
55 void _DBG_QR(long QR) {
60 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) {
81 QR2Vec = NewStrBufPlain(NULL, 256);
84 if (StrLength(QR2Vec) > 0)
85 StrBufAppendBufPlain(QR2Vec, HKEY(" | "), 0);
86 StrBufAppendBufPlain(QR2Vec, CKEY(QR2FlagList[j]), 0);
91 syslog(LOG_DEBUG, "DBG: QR2-Vec [%ld] [%s]\n", QR2, ChrPtr(QR2Vec));
105 /*******************************************************************************
106 ***************************** Goto Commands ***********************************
107 ******************************************************************************/
110 smart_goto(sbstr("room"));
114 if (!havebstr("room")) {
115 readloop(readnew, eUseDefault);
118 if (WC->CurRoom.view != VIEW_MAILBOX) {
119 /* dotgoto acts like dotskip when we're in a mailbox view */
122 smart_goto(sbstr("room"));
128 void smart_goto(const StrBuf * next_room) {
129 if (gotoroom(next_room) / 100 == 2)
130 readloop(readnew, eUseDefault);
136 * goto a private room
138 void goto_private(void) {
141 const StrBuf *gr_name;
144 if (!havebstr("ok_button")) {
148 gr_name = sbstr("gr_name");
150 strcpy(hold_rm, ChrPtr(WC->CurRoom.name));
151 serv_printf("GOTO %s|%s", ChrPtr(gr_name), bstr("gr_pass"));
152 StrBuf_ServGetln(Buf);
153 if (GetServerStatus(Buf, &err) == 2) {
160 DoTemplate(HKEY("room_display_private"), NULL, &NoCtx);
164 StrBufCutLeft(Buf, 4);
165 AppendImportantMessage(SKEY(Buf));
166 Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
173 * back end routine to take the session to a new room
175 long gotoroom(const StrBuf * gname) {
178 static long ls = (-1L);
180 int room_name_supplied = 0;
184 /* on fail, should we fallback to _BASEROOM_? */
185 failvisibly = ibstr("failvisibly");
187 /* store ungoto information */
188 if (StrLength(gname) > 0) {
189 room_name_supplied = 1;
191 if (room_name_supplied) {
192 strcpy(WCC->ugname, ChrPtr(WCC->CurRoom.name));
193 if (!strcasecmp(ChrPtr(gname), "_BASEROOM_")) {
200 /* move to the new room */
201 if (room_name_supplied) {
202 serv_printf("GOTO %s", ChrPtr(gname));
205 /* or just refresh the current state... */
206 serv_printf("GOTO 00000000000000000000");
208 StrBuf_ServGetln(Buf);
209 if (GetServerStatus(Buf, &err) != 2) {
214 serv_puts("GOTO _BASEROOM_");
215 StrBuf_ServGetln(Buf);
217 * well, we know that this is the fallback case,
218 * but we're interested that the first command
219 * didn't work out in first place.
221 if (GetServerStatus(Buf, NULL) != 2) {
226 FlushFolder(&WCC->CurRoom);
227 ParseGoto(&WCC->CurRoom, Buf);
229 if (room_name_supplied) {
230 remove_march(WCC->CurRoom.name);
242 void ParseGoto(folder * room, StrBuf * Line) {
249 if (StrLength(Line) < 4) {
253 /* ignore the commandstate... */
254 Pos = ChrPtr(Line) + 4;
256 if (room->RoomNameParts != NULL) {
258 for (i = 0; i < room->nRoomNameParts; i++)
259 FreeStrBuf(&room->RoomNameParts[i]);
260 free(room->RoomNameParts);
261 room->RoomNameParts = NULL;
266 pBuf = NewStrBufPlain(NULL, StrLength(Line));
269 memset(room, 0, sizeof(folder));
272 StrBufExtract_NextToken(room->name, Line, &Pos, '|');
274 room->nNewMessages = StrBufExtractNext_long(Line, &Pos, '|');
275 if (room->nNewMessages > 0)
276 room->RAFlags |= UA_HASNEWMSGS;
278 room->nTotalMessages = StrBufExtractNext_long(Line, &Pos, '|');
280 room->ShowInfo = StrBufExtractNext_long(Line, &Pos, '|');
282 room->QRFlags = StrBufExtractNext_long(Line, &Pos, '|');
284 DBG_QR(room->QRFlags);
286 room->HighestRead = StrBufExtractNext_long(Line, &Pos, '|');
287 room->LastMessageRead = StrBufExtractNext_long(Line, &Pos, '|');
289 room->is_inbox = StrBufExtractNext_long(Line, &Pos, '|');
291 flag = StrBufExtractNext_long(Line, &Pos, '|');
292 if (WCC->is_aide || flag) {
293 room->RAFlags |= UA_ADMINALLOWED;
296 room->UsersNewMAilboxMessages = StrBufExtractNext_long(Line, &Pos, '|');
298 room->floorid = StrBufExtractNext_int(Line, &Pos, '|');
300 room->view = StrBufExtractNext_long(Line, &Pos, '|');
302 room->defview = StrBufExtractNext_long(Line, &Pos, '|');
304 flag = StrBufExtractNext_long(Line, &Pos, '|');
306 room->RAFlags |= UA_ISTRASH;
308 room->QRFlags2 = StrBufExtractNext_long(Line, &Pos, '|');
309 DBG_QR2(room->QRFlags2);
311 /* find out, whether we are in a sub-room */
312 room->nRoomNameParts = StrBufNum_tokens(room->name, '\\');
313 if (room->nRoomNameParts > 1) {
317 room->RoomNameParts = malloc(sizeof(StrBuf *) * (room->nRoomNameParts + 1));
318 memset(room->RoomNameParts, 0, sizeof(StrBuf *) * (room->nRoomNameParts + 1));
319 for (i = 0; i < room->nRoomNameParts; i++) {
320 room->RoomNameParts[i] = NewStrBuf();
321 StrBufExtract_NextToken(room->RoomNameParts[i], room->name, &Pos, '\\');
325 /* Private mailboxes on the main floor get remapped to the personal folder */
326 if ((room->QRFlags & QR_MAILBOX) && (room->floorid == 0)) {
327 room->floorid = VIRTUAL_MY_FLOOR;
328 if ((room->nRoomNameParts == 1) && (StrLength(room->name) == 4) && (strcmp(ChrPtr(room->name), "Mail") == 0)) {
333 /* get a pointer to the floor we're on: */
334 if (WCC->Floors == NULL)
335 GetFloorListHash(NULL, NULL);
337 GetHash(WCC->Floors, IKEY(room->floorid), &vFloor);
338 room->Floor = (const Floor *) vFloor;
342 * Delete the current room
344 void delete_room(void) {
345 StrBuf *Line = NewStrBuf();
346 const StrBuf *GoBstr;
348 GoBstr = sbstr("go");
350 if (GoBstr != NULL) {
351 if (gotoroom(GoBstr) == 200) {
353 StrBuf_ServGetln(Line);
354 if (GetServerStatusMsg(Line, NULL, 1, 2) == 2) {
358 Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
375 StrBuf *final_destination;
378 * If the forget-room routine fails for any reason, we fall back
379 * to the current room; otherwise, we go to the Lobby
381 final_destination = NewStrBufDup(WC->CurRoom.name);
383 if (havebstr("ok_button")) {
384 serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
385 serv_getln(buf, sizeof buf);
388 serv_getln(buf, sizeof buf);
390 FlushStrBuf(final_destination);
391 StrBufAppendBufPlain(final_destination, HKEY("_BASEROOM_"), 0);
396 smart_goto(final_destination);
397 FreeStrBuf(&final_destination);
402 * mark all messages in current room as having been read
404 void slrp_highest(void) {
407 serv_puts("SLRP HIGHEST");
408 serv_getln(buf, sizeof buf);
424 /*******************************************************************************
425 ***************************** Modify Rooms ************************************
426 ******************************************************************************/
432 void LoadRoomAide(void) {
436 if (WCC->CurRoom.RoomAideLoaded)
439 WCC->CurRoom.RoomAideLoaded = 1;
442 StrBuf_ServGetln(Buf);
443 if (GetServerStatus(Buf, NULL) != 2) {
444 FlushStrBuf(WCC->CurRoom.RoomAide);
445 AppendImportantMessage(ChrPtr(Buf) + 4, StrLength(Buf) - 4);
450 Pos = ChrPtr(Buf) + 4;
452 FreeStrBuf(&WCC->CurRoom.RoomAide);
453 WCC->CurRoom.RoomAide = NewStrBufPlain(NULL, StrLength(Buf));
455 StrBufExtract_NextToken(WCC->CurRoom.RoomAide, Buf, &Pos, '|');
460 int SaveRoomAide(folder * Room) {
463 serv_printf("SETA %s", ChrPtr(Room->RoomAide));
464 StrBuf_ServGetln(Buf);
465 if (GetServerStatus(Buf, NULL) != 2) {
466 StrBufCutLeft(Buf, 4);
467 AppendImportantMessage(SKEY(Buf));
476 int GetCurrentRoomFlags(folder * Room, int CareForStatusMessage) {
481 StrBuf_ServGetln(Buf);
482 if (GetServerStatus(Buf, NULL) != 2) {
483 FlushStrBuf(Room->XAPass);
484 FlushStrBuf(Room->Directory);
485 StrBufCutLeft(Buf, 4);
486 if (CareForStatusMessage)
487 AppendImportantMessage(SKEY(Buf));
495 Pos = ChrPtr(Buf) + 4;
497 FreeStrBuf(&Room->XAPass);
498 FreeStrBuf(&Room->Directory);
500 Room->XAPass = NewStrBufPlain(NULL, StrLength(Buf));
501 Room->Directory = NewStrBufPlain(NULL, StrLength(Buf));
503 FreeStrBuf(&Room->name);
504 Room->name = NewStrBufPlain(NULL, StrLength(Buf));
505 StrBufExtract_NextToken(Room->name, Buf, &Pos, '|');
507 StrBufExtract_NextToken(Room->XAPass, Buf, &Pos, '|');
508 StrBufExtract_NextToken(Room->Directory, Buf, &Pos, '|');
510 Room->QRFlags = StrBufExtractNext_long(Buf, &Pos, '|');
511 Room->floorid = StrBufExtractNext_long(Buf, &Pos, '|');
512 Room->Order = StrBufExtractNext_long(Buf, &Pos, '|');
513 Room->defview = StrBufExtractNext_long(Buf, &Pos, '|');
514 Room->QRFlags2 = StrBufExtractNext_long(Buf, &Pos, '|');
522 int SetCurrentRoomFlags(folder * Room) {
526 DBG_QR(Room->QRFlags);
527 DBG_QR2(Room->QRFlags2);
529 serv_printf("SETR %s|%s|%s|%ld|%d|%d|%ld|%ld|%ld",
531 ChrPtr(Room->XAPass),
532 ChrPtr(Room->Directory),
533 Room->QRFlags, Room->BumpUsers, Room->floorid, Room->Order, Room->defview, Room->QRFlags2);
535 StrBuf_ServGetln(Buf);
536 if (GetServerStatus(Buf, NULL) != 2) {
537 StrBufCutLeft(Buf, 4);
538 AppendImportantMessage(SKEY(Buf));
548 void LoadRoomXA(void) {
551 if (WCC->CurRoom.XALoaded > 0)
554 GetCurrentRoomFlags(&WCC->CurRoom, 0);
558 void LoadXRoomPic(void) {
563 if (WCC->CurRoom.XHaveRoomPicLoaded) {
567 WCC->CurRoom.XHaveRoomPicLoaded = 1;
570 StrBuf_ServGetln(Buf);
571 if (GetServerStatus(Buf, NULL) == 6) {
572 StrBufCutLeft(Buf, 4);
573 bytes = StrBufExtract_long(Buf, 0, '|');
574 WCC->CurRoom.XHaveRoomPic = 1;
575 StrBuf_ServGetBLOBBuffered(Buf, bytes); // discard the data
578 WCC->CurRoom.XHaveRoomPic = 0;
584 void LoadXRoomInfoText(void) {
589 if (WCC->CurRoom.XHaveInfoTextLoaded) {
593 WCC->CurRoom.XHaveInfoTextLoaded = 1;
598 StrBuf_ServGetln(Buf);
599 if (GetServerStatus(Buf, NULL) == 1) {
600 WCC->CurRoom.XInfoText = NewStrBuf();
602 while (!Done && StrBuf_ServGetln(Buf) >= 0) {
603 if ((StrLength(Buf) == 3) && !strcmp(ChrPtr(Buf), "000"))
606 StrBufAppendBuf(WCC->CurRoom.XInfoText, Buf, 0);
614 void LoadXRoomXCountFiles(void) {
619 if (WCC->CurRoom.XHaveDownloadCount)
622 WCC->CurRoom.XHaveDownloadCount = 1;
626 StrBuf_ServGetln(Buf);
627 if (GetServerStatus(Buf, NULL) == 1) {
629 while (!Done && StrBuf_ServGetln(Buf) >= 0) {
630 if ((StrLength(Buf) == 3) && !strcmp(ChrPtr(Buf), "000"))
633 WCC->CurRoom.XDownloadCount++;
642 * Toggle self-service list subscription
644 void toggle_self_service(void) {
647 if (GetCurrentRoomFlags(&WCC->CurRoom, 1) == 0)
650 if (yesbstr("QR2_SelfList"))
651 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SELFLIST;
653 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SELFLIST;
655 if (yesbstr("QR2_SMTP_PUBLIC"))
656 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SMTP_PUBLIC;
658 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SMTP_PUBLIC;
660 if (yesbstr("QR2_Moderated"))
661 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_MODERATED;
663 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_MODERATED;
664 if (yesbstr("QR2_SubsOnly"))
665 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SMTP_PUBLIC;
667 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SMTP_PUBLIC;
669 SetCurrentRoomFlags(&WCC->CurRoom);
671 output_headers(1, 1, 1, 0, 0, 0);
672 do_template("room_edit");
679 * save new parameters for a room
681 void editroom(void) {
684 const StrBuf *er_name;
685 const StrBuf *er_password;
686 const StrBuf *er_dirname;
687 const StrBuf *er_roomaide;
691 templ = sbstr("template");
692 if (!havebstr("ok_button")) {
693 putlbstr("success", 0);
694 AppendImportantMessage(_("Cancelled. Changes were not saved."), -1);
696 output_headers(1, 0, 0, 0, 0, 0);
697 DoTemplate(SKEY(templ), NULL, &NoCtx);
701 output_headers(1, 1, 1, 0, 0, 0);
702 do_template("room_edit");
708 if (GetCurrentRoomFlags(&WCC->CurRoom, 1) == 0) {
709 putlbstr("success", 0);
711 output_headers(1, 0, 0, 0, 0, 0);
712 DoTemplate(SKEY(templ), NULL, &NoCtx);
716 output_headers(1, 1, 1, 0, 0, 0);
717 do_template("room_edit");
724 WCC->CurRoom.QRFlags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
727 if (!strcmp(ChrPtr(Ptr), "invonly")) {
728 WCC->CurRoom.QRFlags |= (QR_PRIVATE);
730 if (!strcmp(ChrPtr(Ptr), "hidden")) {
731 WCC->CurRoom.QRFlags |= (QR_PRIVATE | QR_GUESSNAME);
733 if (!strcmp(ChrPtr(Ptr), "passworded")) {
734 WCC->CurRoom.QRFlags |= (QR_PRIVATE | QR_PASSWORDED);
736 if (!strcmp(ChrPtr(Ptr), "personal")) {
737 WCC->CurRoom.QRFlags |= QR_MAILBOX;
740 WCC->CurRoom.QRFlags &= ~QR_MAILBOX;
743 if (yesbstr("prefonly")) {
744 WCC->CurRoom.QRFlags |= QR_PREFONLY;
747 WCC->CurRoom.QRFlags &= ~QR_PREFONLY;
750 if (yesbstr("readonly")) {
751 WCC->CurRoom.QRFlags |= QR_READONLY;
754 WCC->CurRoom.QRFlags &= ~QR_READONLY;
757 if (yesbstr("collabdel")) {
758 WCC->CurRoom.QRFlags2 |= QR2_COLLABDEL;
761 WCC->CurRoom.QRFlags2 &= ~QR2_COLLABDEL;
764 if (yesbstr("permanent")) {
765 WCC->CurRoom.QRFlags |= QR_PERMANENT;
768 WCC->CurRoom.QRFlags &= ~QR_PERMANENT;
771 if (yesbstr("subjectreq")) {
772 WCC->CurRoom.QRFlags2 |= QR2_SUBJECTREQ;
775 WCC->CurRoom.QRFlags2 &= ~QR2_SUBJECTREQ;
778 if (yesbstr("network")) {
779 WCC->CurRoom.QRFlags |= QR_NETWORK;
782 WCC->CurRoom.QRFlags &= ~QR_NETWORK;
785 if (yesbstr("directory")) {
786 WCC->CurRoom.QRFlags |= QR_DIRECTORY;
789 WCC->CurRoom.QRFlags &= ~QR_DIRECTORY;
792 if (yesbstr("ulallowed")) {
793 WCC->CurRoom.QRFlags |= QR_UPLOAD;
796 WCC->CurRoom.QRFlags &= ~QR_UPLOAD;
799 if (yesbstr("dlallowed")) {
800 WCC->CurRoom.QRFlags |= QR_DOWNLOAD;
803 WCC->CurRoom.QRFlags &= ~QR_DOWNLOAD;
806 if (yesbstr("ulmsg")) {
807 WCC->CurRoom.QRFlags2 |= QR2_NOUPLMSG;
810 WCC->CurRoom.QRFlags2 &= ~QR2_NOUPLMSG;
813 if (yesbstr("visdir")) {
814 WCC->CurRoom.QRFlags |= QR_VISDIR;
817 WCC->CurRoom.QRFlags &= ~QR_VISDIR;
822 WCC->CurRoom.QRFlags &= ~(QR_ANONONLY | QR_ANONOPT);
823 if (!strcmp(ChrPtr(Ptr), "anononly"))
824 WCC->CurRoom.QRFlags |= QR_ANONONLY;
825 if (!strcmp(ChrPtr(Ptr), "anon2"))
826 WCC->CurRoom.QRFlags |= QR_ANONOPT;
828 er_name = sbstr("er_name");
829 er_dirname = sbstr("er_dirname");
830 er_roomaide = sbstr("er_roomaide");
831 er_password = sbstr("er_password");
833 FlushStrBuf(WCC->CurRoom.name);
834 StrBufAppendBuf(WCC->CurRoom.name, er_name, 0);
836 FlushStrBuf(WCC->CurRoom.Directory);
837 StrBufAppendBuf(WCC->CurRoom.Directory, er_dirname, 0);
839 FlushStrBuf(WCC->CurRoom.RoomAide);
840 StrBufAppendBuf(WCC->CurRoom.RoomAide, er_roomaide, 0);
842 FlushStrBuf(WCC->CurRoom.XAPass);
843 StrBufAppendBuf(WCC->CurRoom.XAPass, er_password, 0);
845 WCC->CurRoom.BumpUsers = yesbstr("bump");
847 WCC->CurRoom.floorid = ibstr("er_floor");
849 succ1 = SetCurrentRoomFlags(&WCC->CurRoom);
851 succ2 = SaveRoomAide(&WCC->CurRoom);
853 if (succ1 + succ2 == 0) {
854 putlbstr("success", 1);
855 AppendImportantMessage(_("Your changes have been saved."), -1);
858 putlbstr("success", 0);
861 output_headers(1, 0, 0, 0, 0, 0);
862 DoTemplate(SKEY(templ), NULL, &NoCtx);
866 output_headers(1, 1, 1, 0, 0, 0);
867 do_template("room_edit");
876 * Display form for Invite, Kick, and show Who Knows a room
878 void do_invt_kick(void) {
880 const StrBuf *UserNames;
885 if (GetCurrentRoomFlags(&WCC->CurRoom, 1) == 1) {
887 UserNames = sbstr("username");
888 Kick = havebstr("kick_button");
889 Invite = havebstr("invite_button");
891 User = NewStrBufPlain(NULL, StrLength(UserNames));
894 Pos = ChrPtr(UserNames);
895 while (Pos != StrBufNOTNULL) {
896 StrBufExtract_NextToken(User, UserNames, &Pos, ',');
898 if ((StrLength(User) > 0) && (Kick)) {
899 serv_printf("KICK %s", ChrPtr(User));
900 if (StrBuf_ServGetln(Buf) < 0)
902 if (GetServerStatus(Buf, NULL) != 2) {
903 StrBufCutLeft(Buf, 4);
904 AppendImportantMessage(SKEY(Buf));
908 _("User '%s' kicked out of room '%s'."),
909 ChrPtr(User), ChrPtr(WCC->CurRoom.name)
911 AppendImportantMessage(SKEY(Buf));
914 else if ((StrLength(User) > 0) && (Invite)) {
915 serv_printf("INVT %s", ChrPtr(User));
916 if (StrBuf_ServGetln(Buf) < 0)
918 if (GetServerStatus(Buf, NULL) != 2) {
919 StrBufCutLeft(Buf, 4);
920 AppendImportantMessage(SKEY(Buf));
924 _("User '%s' invited to room '%s'."), ChrPtr(User), ChrPtr(WCC->CurRoom.name)
926 AppendImportantMessage(SKEY(Buf));
932 output_headers(1, 1, 1, 0, 0, 0);
933 do_template("room_edit");
943 const StrBuf *er_name;
944 const StrBuf *er_type;
945 const StrBuf *er_password;
946 const StrBuf *template;
952 template = sbstr("template");
953 if ((WCC == NULL) || !havebstr("ok_button")) {
954 putlbstr("success", 0);
955 AppendImportantMessage(_("Cancelled. No new room was created."), -1);
956 if (template != NULL) {
957 output_headers(1, 0, 0, 0, 0, 0);
958 DoTemplate(SKEY(template), NULL, &NoCtx);
966 er_name = sbstr("er_name");
967 er_type = sbstr("type");
968 er_password = sbstr("er_password");
969 er_floor = ibstr("er_floor");
970 er_view = ibstr("er_view");
973 if (!strcmp(ChrPtr(er_type), "hidden"))
975 else if (!strcmp(ChrPtr(er_type), "passworded"))
977 else if (!strcmp(ChrPtr(er_type), "invonly"))
979 else if (!strcmp(ChrPtr(er_type), "personal"))
982 serv_printf("CRE8 1|%s|%d|%s|%d|%d|%d", ChrPtr(er_name), er_num_type, ChrPtr(er_password), er_floor, 0, er_view);
985 StrBuf_ServGetln(Line);
986 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
987 putlbstr("success", 0);
989 if (template != NULL) {
990 output_headers(1, 0, 0, 0, 0, 0);
991 DoTemplate(SKEY(template), NULL, &NoCtx);
1000 /** TODO: Room created, now update the left hand icon bar for this user */
1003 serv_printf("VIEW %d", er_view);
1004 StrBuf_ServGetln(Line);
1005 FreeStrBuf(&Line); /* TODO: should we care about errors? */
1006 WCC->CurRoom.view = er_view;
1008 putlbstr("success", 1);
1009 if (template != NULL) {
1010 output_headers(1, 0, 0, 0, 0, 0);
1011 DoTemplate(SKEY(template), NULL, &NoCtx);
1014 else if ((WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) {
1015 output_headers(1, 1, 1, 0, 0, 0);
1016 do_template("room_edit");
1020 smart_goto(WCC->CurRoom.name);
1030 * Change the view for this room
1032 void change_view(void) {
1036 newview = lbstr("view");
1037 serv_printf("VIEW %d", newview);
1038 serv_getln(buf, sizeof buf);
1039 WC->CurRoom.view = newview;
1040 smart_goto(WC->CurRoom.name);
1046 * Set the message expire policy for this room and/or floor
1048 void set_room_policy(void) {
1051 if (!havebstr("ok_button")) {
1052 AppendImportantMessage(_("Cancelled. Changes were not saved."), -1);
1053 output_headers(1, 1, 1, 0, 0, 0);
1054 do_template("room_edit");
1061 serv_printf("SPEX room|%d|%d", ibstr("roompolicy"), ibstr("roomvalue"));
1062 StrBuf_ServGetln(Line);
1063 GetServerStatusMsg(Line, NULL, 1, 0);
1064 if (WC->axlevel >= 6) {
1065 serv_printf("SPEX floor|%d|%d", ibstr("floorpolicy"), ibstr("floorvalue"));
1066 StrBuf_ServGetln(Line);
1067 GetServerStatusMsg(Line, NULL, 1, 0);
1070 ReloadCurrentRoom();
1072 output_headers(1, 1, 1, 0, 0, 0);
1073 do_template("room_edit");
1080 * Perform changes to a room's network configuration
1082 void netedit(void) {
1093 int malias_set_default = 0;
1098 if (havebstr("force_room")) {
1099 gotoroom(sbstr("force_room"));
1101 /*/ TODO: do line dynamic! */
1102 if (havebstr("line_pop3host")) {
1103 strcpy(line, bstr("prefix"));
1104 strcat(line, bstr("line_pop3host"));
1106 strcat(line, bstr("line_pop3user"));
1108 strcat(line, bstr("line_pop3pass"));
1110 strcat(line, ibstr("line_pop3keep") ? "1" : "0");
1112 sprintf(&line[strlen(line)], "%ld", lbstr("line_pop3int"));
1113 strcat(line, bstr("suffix"));
1115 else if (havebstr("line")) {
1116 strcpy(line, bstr("prefix"));
1117 strcat(line, bstr("line"));
1118 strcat(line, bstr("suffix"));
1120 else if (havebstr("alias")) {
1122 domain = bstr("aliasdomain");
1123 if ((domain == NULL) || IsEmptyStr(domain)) {
1124 malias_set_default = 1;
1125 strcpy(line, bstr("prefix"));
1126 strcat(line, bstr("default_aliasdomain"));
1131 strcat(line, bstr("prefix"));
1132 if (!IsEmptyStr(domain)) {
1134 strcat(line, domain);
1137 strcat(line, "room_");
1138 strcat(line, ChrPtr(WC->CurRoom.name));
1142 output_headers(1, 1, 1, 0, 0, 0);
1143 do_template("room_edit");
1149 TmpBuf = NewStrBuf();
1151 serv_puts("GNET " FILE_MAILALIAS);
1154 StrBuf_ServGetln(Line);
1155 if (GetServerStatus(Line, NULL) != 1) {
1156 AppendImportantMessage(SRV_STATUS_MSG(Line));
1158 output_headers(1, 1, 1, 0, 0, 0);
1159 do_template("room_edit");
1164 /** This loop works for add *or* remove. Spiffy, eh? */
1166 extract_token(cmpb0, line, 0, sepchar, sizeof cmpb0);
1167 extract_token(cmpb1, line, 1, sepchar, sizeof cmpb1);
1168 while (!Done && StrBuf_ServGetln(Line) >= 0) {
1169 if ((StrLength(Line) == 3) && !strcmp(ChrPtr(Line), "000")) {
1173 if (StrLength(Line) == 0)
1176 if (malias_set_default) {
1177 if (strncasecmp(ChrPtr(Line), HKEY("roommailalias|")) != 0) {
1178 StrBufAppendBufPlain(Line, HKEY("\n"), 0);
1179 StrBufAppendBuf(TmpBuf, Line, 0);
1183 extract_token(cmpa0, ChrPtr(Line), 0, sepchar, sizeof cmpa0);
1184 extract_token(cmpa1, ChrPtr(Line), 1, sepchar, sizeof cmpa1);
1185 if ((strcasecmp(cmpa0, cmpb0)) || (strcasecmp(cmpa1, cmpb1))) {
1186 StrBufAppendBufPlain(Line, HKEY("\n"), 0);
1187 StrBufAppendBuf(TmpBuf, Line, 0);
1194 serv_puts("SNET " FILE_MAILALIAS);
1197 StrBuf_ServGetln(Line);
1198 if (GetServerStatus(Line, NULL) != 4) {
1200 AppendImportantMessage(SRV_STATUS_MSG(Line));
1201 output_headers(1, 1, 1, 0, 0, 0);
1202 do_template("room_edit");
1205 FreeStrBuf(&TmpBuf);
1209 serv_putbuf(TmpBuf);
1210 FreeStrBuf(&TmpBuf);
1212 if (havebstr("add_button")) {
1213 num_addrs = num_tokens(bstr("line"), ',');
1214 if (num_addrs < 2) {
1215 /* just adding one node or address */
1219 /* adding multiple addresses separated by commas */
1220 for (i = 0; i < num_addrs; ++i) {
1221 strcpy(line, bstr("prefix"));
1222 extract_token(buf, bstr("line"), i, ',', sizeof buf);
1225 strcat(line, bstr("suffix"));
1233 StrBuf_ServGetln(Line);
1234 if (GetServerStatus(Line, NULL) != 2) { /* WHOOOPS? ERROR? */
1235 AppendImportantMessage(SRV_STATUS_MSG(Line));
1236 StrBuf_ServGetln(Line); /* resync... */
1240 FlushIgnetCfgs(&WC->CurRoom);
1243 output_headers(1, 1, 1, 0, 0, 0);
1244 do_template("room_edit");
1249 * Known rooms list (box style)
1251 void knrooms(void) {
1252 DeleteHash(&WC->Rooms);
1253 output_headers(1, 1, 1, 0, 0, 0);
1254 do_template("knrooms");
1275 /*******************************************************************************
1276 ********************** FLOOR Coomands *****************************************
1277 ******************************************************************************/
1282 * delete the actual floor
1284 void delete_floor(void) {
1289 floornum = ibstr("floornum");
1291 serv_printf("KFLR %d|1", floornum);
1293 StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
1295 if (GetServerStatus(Buf, NULL) == 2) {
1296 StrBufPlain(Buf, _("Floor has been deleted."), -1);
1299 StrBufCutLeft(Buf, 4);
1301 AppendImportantMessage(SKEY(Buf));
1304 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1309 * start creating a new floor
1311 void create_floor(void) {
1316 serv_printf("CFLR %s|1", bstr("floorname"));
1317 StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
1319 if (GetServerStatus(Buf, NULL) == 2) {
1320 StrBufPlain(Buf, _("New floor has been created."), -1);
1323 StrBufCutLeft(Buf, 4);
1325 AppendImportantMessage(SKEY(Buf));
1327 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1335 void rename_floor(void) {
1341 serv_printf("EFLR %d|%s", ibstr("floornum"), bstr("floorname"));
1342 StrBuf_ServGetln(Buf);
1344 StrBufCutLeft(Buf, 4);
1345 AppendImportantMessage(SKEY(Buf));
1347 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1353 void jsonRoomFlr(void) {
1354 /* Send as our own (application/json) content type */
1355 hprintf("HTTP/1.1 200 OK\r\n");
1356 hprintf("Content-type: application/json; charset=utf-8\r\n");
1357 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1358 hprintf("Connection: close\r\n");
1359 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1361 DoTemplate(HKEY("json_roomflr"), NULL, &NoCtx);
1365 void _FlushRoomList(wcsession * WCC) {
1366 free_march_list(WCC);
1367 DeleteHash(&WCC->Floors);
1368 DeleteHash(&WCC->Rooms);
1369 DeleteHash(&WCC->FloorsByName);
1370 FlushFolder(&WCC->CurRoom);
1373 void ReloadCurrentRoom(void) {
1374 wcsession *WCC = WC;
1377 CurRoom = WCC->CurRoom.name;
1378 WCC->CurRoom.name = NULL;
1379 _FlushRoomList(WCC);
1381 FreeStrBuf(&CurRoom);
1384 void FlushRoomlist(void) {
1385 wcsession *WCC = WC;
1386 _FlushRoomList(WCC);
1390 void InitModule_ROOMOPS(void) {
1391 RegisterPreference("roomlistview", _("Room list view"), PRF_STRING, NULL);
1392 RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO, NULL);
1394 WebcitAddUrlHandler(HKEY("json_roomflr"), "", 0, jsonRoomFlr, 0);
1396 WebcitAddUrlHandler(HKEY("delete_floor"), "", 0, delete_floor, 0);
1397 WebcitAddUrlHandler(HKEY("rename_floor"), "", 0, rename_floor, 0);
1398 WebcitAddUrlHandler(HKEY("create_floor"), "", 0, create_floor, 0);
1400 WebcitAddUrlHandler(HKEY("knrooms"), "", 0, knrooms, ANONYMOUS);
1401 WebcitAddUrlHandler(HKEY("dotgoto"), "", 0, dotgoto, NEED_URL);
1402 WebcitAddUrlHandler(HKEY("dotskip"), "", 0, dotskip, NEED_URL);
1404 WebcitAddUrlHandler(HKEY("goto_private"), "", 0, goto_private, NEED_URL);
1405 WebcitAddUrlHandler(HKEY("zap"), "", 0, zap, 0);
1406 WebcitAddUrlHandler(HKEY("entroom"), "", 0, entroom, 0);
1407 WebcitAddUrlHandler(HKEY("do_invt_kick"), "", 0, do_invt_kick, 0);
1409 WebcitAddUrlHandler(HKEY("netedit"), "", 0, netedit, 0);
1410 WebcitAddUrlHandler(HKEY("editroom"), "", 0, editroom, 0);
1411 WebcitAddUrlHandler(HKEY("delete_room"), "", 0, delete_room, 0);
1412 WebcitAddUrlHandler(HKEY("set_room_policy"), "", 0, set_room_policy, 0);
1413 WebcitAddUrlHandler(HKEY("changeview"), "", 0, change_view, 0);
1414 WebcitAddUrlHandler(HKEY("toggle_self_service"), "", 0, toggle_self_service, 0);
1417 REGISTERTokenParamDefine(QR_PERMANENT);
1418 REGISTERTokenParamDefine(QR_INUSE);
1419 REGISTERTokenParamDefine(QR_PRIVATE);
1420 REGISTERTokenParamDefine(QR_PASSWORDED);
1421 REGISTERTokenParamDefine(QR_GUESSNAME);
1422 REGISTERTokenParamDefine(QR_DIRECTORY);
1423 REGISTERTokenParamDefine(QR_UPLOAD);
1424 REGISTERTokenParamDefine(QR_DOWNLOAD);
1425 REGISTERTokenParamDefine(QR_VISDIR);
1426 REGISTERTokenParamDefine(QR_ANONONLY);
1427 REGISTERTokenParamDefine(QR_ANONOPT);
1428 REGISTERTokenParamDefine(QR_NETWORK);
1429 REGISTERTokenParamDefine(QR_PREFONLY);
1430 REGISTERTokenParamDefine(QR_READONLY);
1431 REGISTERTokenParamDefine(QR_MAILBOX);
1432 REGISTERTokenParamDefine(QR2_SYSTEM);
1433 REGISTERTokenParamDefine(QR2_SELFLIST);
1434 REGISTERTokenParamDefine(QR2_COLLABDEL);
1435 REGISTERTokenParamDefine(QR2_SUBJECTREQ);
1436 REGISTERTokenParamDefine(QR2_SMTP_PUBLIC);
1437 REGISTERTokenParamDefine(QR2_MODERATED);
1438 REGISTERTokenParamDefine(QR2_NOUPLMSG);
1440 REGISTERTokenParamDefine(UA_KNOWN);
1441 REGISTERTokenParamDefine(UA_GOTOALLOWED);
1442 REGISTERTokenParamDefine(UA_HASNEWMSGS);
1443 REGISTERTokenParamDefine(UA_ZAPPED);
1444 REGISTERTokenParamDefine(UA_POSTALLOWED);
1445 REGISTERTokenParamDefine(UA_ADMINALLOWED);
1446 REGISTERTokenParamDefine(UA_DELETEALLOWED);
1447 REGISTERTokenParamDefine(UA_REPLYALLOWED);
1448 REGISTERTokenParamDefine(UA_ISTRASH);
1450 REGISTERTokenParamDefine(US_NEEDVALID);
1451 REGISTERTokenParamDefine(US_PERM);
1452 REGISTERTokenParamDefine(US_LASTOLD);
1453 REGISTERTokenParamDefine(US_EXPERT);
1454 REGISTERTokenParamDefine(US_UNLISTED);
1455 REGISTERTokenParamDefine(US_NOPROMPT);
1456 REGISTERTokenParamDefine(US_PROMPTCTL);
1457 REGISTERTokenParamDefine(US_DISAPPEAR);
1458 REGISTERTokenParamDefine(US_REGIS);
1459 REGISTERTokenParamDefine(US_PAGINATOR);
1460 REGISTERTokenParamDefine(US_INTERNET);
1461 REGISTERTokenParamDefine(US_FLOORS);
1462 REGISTERTokenParamDefine(US_COLOR);
1463 REGISTERTokenParamDefine(US_USER_SET);
1465 REGISTERTokenParamDefine(VIEW_BBS);
1466 REGISTERTokenParamDefine(VIEW_MAILBOX);
1467 REGISTERTokenParamDefine(VIEW_ADDRESSBOOK);
1468 REGISTERTokenParamDefine(VIEW_CALENDAR);
1469 REGISTERTokenParamDefine(VIEW_TASKS);
1470 REGISTERTokenParamDefine(VIEW_NOTES);
1471 REGISTERTokenParamDefine(VIEW_WIKI);
1472 REGISTERTokenParamDefine(VIEW_CALBRIEF);
1473 REGISTERTokenParamDefine(VIEW_JOURNAL);
1474 REGISTERTokenParamDefine(VIEW_BLOG);
1475 REGISTERTokenParamDefine(VIEW_QUEUE);
1478 /* server internal, we need to know but ignore them. */
1479 REGISTERTokenParamDefine(subpending);
1480 REGISTERTokenParamDefine(unsubpending);
1481 REGISTERTokenParamDefine(lastsent);
1483 REGISTERTokenParamDefine(ignet_push_share);
1484 { /* these are the parts of an IGNET push config */
1485 REGISTERTokenParamDefine(GNET_IGNET_NODE);
1486 REGISTERTokenParamDefine(GNET_IGNET_ROOM);
1488 REGISTERTokenParamDefine(listrecp);
1489 REGISTERTokenParamDefine(digestrecp);
1490 REGISTERTokenParamDefine(pop3client);
1491 { /* These are the parts of a pop3 client line... */
1492 REGISTERTokenParamDefine(GNET_POP3_HOST);
1493 REGISTERTokenParamDefine(GNET_POP3_USER);
1494 REGISTERTokenParamDefine(GNET_POP3_DONT_DELETE_REMOTE);
1495 REGISTERTokenParamDefine(GNET_POP3_INTERVAL);
1497 REGISTERTokenParamDefine(rssclient);
1498 REGISTERTokenParamDefine(participate);
1499 REGISTERTokenParamDefine(roommailalias);
1506 void SessionDestroyModule_ROOMOPS(wcsession * sess) {
1507 _FlushRoomList(sess);