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))},
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;
721 if (!havebstr("ok_button")) {
722 AppendImportantMessage(_("Cancelled. Changes were not saved."), -1);
723 output_headers(1, 1, 1, 0, 0, 0);
724 do_template("room_edit");
729 if (GetCurrentRoomFlags (&WCC->CurRoom, 1) == 0) {
730 output_headers(1, 1, 1, 0, 0, 0);
731 do_template("room_edit");
737 WCC->CurRoom.QRFlags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
740 if (!strcmp(ChrPtr(Ptr), "invonly")) {
741 WCC->CurRoom.QRFlags |= (QR_PRIVATE);
743 if (!strcmp(ChrPtr(Ptr), "hidden")) {
744 WCC->CurRoom.QRFlags |= (QR_PRIVATE | QR_GUESSNAME);
746 if (!strcmp(ChrPtr(Ptr), "passworded")) {
747 WCC->CurRoom.QRFlags |= (QR_PRIVATE | QR_PASSWORDED);
749 if (!strcmp(ChrPtr(Ptr), "personal")) {
750 WCC->CurRoom.QRFlags |= QR_MAILBOX;
752 WCC->CurRoom.QRFlags &= ~QR_MAILBOX;
755 if (yesbstr("prefonly")) {
756 WCC->CurRoom.QRFlags |= QR_PREFONLY;
758 WCC->CurRoom.QRFlags &= ~QR_PREFONLY;
761 if (yesbstr("readonly")) {
762 WCC->CurRoom.QRFlags |= QR_READONLY;
764 WCC->CurRoom.QRFlags &= ~QR_READONLY;
767 if (yesbstr("collabdel")) {
768 WCC->CurRoom.QRFlags2 |= QR2_COLLABDEL;
770 WCC->CurRoom.QRFlags2 &= ~QR2_COLLABDEL;
773 if (yesbstr("permanent")) {
774 WCC->CurRoom.QRFlags |= QR_PERMANENT;
776 WCC->CurRoom.QRFlags &= ~QR_PERMANENT;
779 if (yesbstr("subjectreq")) {
780 WCC->CurRoom.QRFlags2 |= QR2_SUBJECTREQ;
782 WCC->CurRoom.QRFlags2 &= ~QR2_SUBJECTREQ;
785 if (yesbstr("network")) {
786 WCC->CurRoom.QRFlags |= QR_NETWORK;
788 WCC->CurRoom.QRFlags &= ~QR_NETWORK;
791 if (yesbstr("directory")) {
792 WCC->CurRoom.QRFlags |= QR_DIRECTORY;
794 WCC->CurRoom.QRFlags &= ~QR_DIRECTORY;
797 if (yesbstr("ulallowed")) {
798 WCC->CurRoom.QRFlags |= QR_UPLOAD;
800 WCC->CurRoom.QRFlags &= ~QR_UPLOAD;
803 if (yesbstr("dlallowed")) {
804 WCC->CurRoom.QRFlags |= QR_DOWNLOAD;
806 WCC->CurRoom.QRFlags &= ~QR_DOWNLOAD;
809 if (yesbstr("visdir")) {
810 WCC->CurRoom.QRFlags |= QR_VISDIR;
812 WCC->CurRoom.QRFlags &= ~QR_VISDIR;
817 WCC->CurRoom.QRFlags &= ~(QR_ANONONLY | QR_ANONOPT);
818 if (!strcmp(ChrPtr(Ptr), "anononly"))
819 WCC->CurRoom.QRFlags |= QR_ANONONLY;
820 if (!strcmp(ChrPtr(Ptr), "anon2"))
821 WCC->CurRoom.QRFlags |= QR_ANONOPT;
823 er_name = sbstr("er_name");
824 er_dirname = sbstr("er_dirname");
825 er_roomaide = sbstr("er_roomaide");
826 er_password = sbstr("er_password");
828 FlushStrBuf(WCC->CurRoom.name);
829 StrBufAppendBuf(WCC->CurRoom.name, er_name, 0);
831 FlushStrBuf(WCC->CurRoom.Directory);
832 StrBufAppendBuf(WCC->CurRoom.Directory, er_dirname, 0);
834 FlushStrBuf(WCC->CurRoom.RoomAide);
835 StrBufAppendBuf(WCC->CurRoom.RoomAide, er_roomaide, 0);
837 FlushStrBuf(WCC->CurRoom.XAPass);
838 StrBufAppendBuf(WCC->CurRoom.XAPass, er_password, 0);
840 WCC->CurRoom.BumpUsers = yesbstr("bump");
842 WCC->CurRoom.floorid = ibstr("er_floor");
844 succ1 = SetCurrentRoomFlags(&WCC->CurRoom);
846 succ2 = SaveRoomAide (&WCC->CurRoom);
848 if (succ1 + succ2 == 0) {
849 AppendImportantMessage (_("Your changes have been saved."), -1);
851 output_headers(1, 1, 1, 0, 0, 0);
852 do_template("room_edit");
860 * Display form for Invite, Kick, and show Who Knows a room
862 void do_invt_kick(void)
865 const StrBuf *UserNames;
870 if (GetCurrentRoomFlags(&WCC->CurRoom, 1) == 1)
873 UserNames = sbstr("username");
874 Kick = havebstr("kick_button");
875 Invite = havebstr("invite_button");
877 User = NewStrBufPlain(NULL, StrLength(UserNames));
880 Pos = ChrPtr(UserNames);
881 while (Pos != StrBufNOTNULL)
883 StrBufExtract_NextToken(User, UserNames, &Pos, ',');
885 if ((StrLength(User) > 0) && (Kick))
887 serv_printf("KICK %s", ChrPtr(User));
888 if (StrBuf_ServGetln(Buf) < 0)
890 if (GetServerStatus(Buf, NULL) != 2) {
891 StrBufCutLeft(Buf, 4);
892 AppendImportantMessage(SKEY(Buf));
895 _("User '%s' kicked out of room '%s'."),
897 ChrPtr(WCC->CurRoom.name)
899 AppendImportantMessage(SKEY(Buf));
902 else if ((StrLength(User) > 0) && (Invite))
904 serv_printf("INVT %s", ChrPtr(User));
905 if (StrBuf_ServGetln(Buf) < 0)
907 if (GetServerStatus(Buf, NULL) != 2) {
908 StrBufCutLeft(Buf, 4);
909 AppendImportantMessage(SKEY(Buf));
912 _("User '%s' invited to room '%s'."),
914 ChrPtr(WCC->CurRoom.name)
916 AppendImportantMessage(SKEY(Buf));
922 output_headers(1, 1, 1, 0, 0, 0);
923 do_template("room_edit");
934 const StrBuf *er_name;
935 const StrBuf *er_type;
936 const StrBuf *er_password;
942 if (!havebstr("ok_button")) {
943 AppendImportantMessage(_("Cancelled. No new room was created."), -1);
947 er_name = sbstr("er_name");
948 er_type = sbstr("type");
949 er_password = sbstr("er_password");
950 er_floor = ibstr("er_floor");
951 er_view = ibstr("er_view");
954 if (!strcmp(ChrPtr(er_type), "hidden"))
956 else if (!strcmp(ChrPtr(er_type), "passworded"))
958 else if (!strcmp(ChrPtr(er_type), "invonly"))
960 else if (!strcmp(ChrPtr(er_type), "personal"))
963 serv_printf("CRE8 1|%s|%d|%s|%d|%d|%d",
972 StrBuf_ServGetln(Line);
973 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
978 /** TODO: Room created, now update the left hand icon bar for this user */
981 serv_printf("VIEW %d", er_view);
982 StrBuf_ServGetln(Line);
983 FreeStrBuf(&Line); /* TODO: should we care about errors? */
984 WCC->CurRoom.view = er_view;
986 if ( (WCC != NULL) && ( (WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) ) {
987 output_headers(1, 1, 1, 0, 0, 0);
988 do_template("room_edit");
991 smart_goto(WCC->CurRoom.name);
1001 * Change the view for this room
1003 void change_view(void) {
1007 newview = lbstr("view");
1008 serv_printf("VIEW %d", newview);
1009 serv_getln(buf, sizeof buf);
1010 WC->CurRoom.view = newview;
1011 smart_goto(WC->CurRoom.name);
1017 * Set the message expire policy for this room and/or floor
1019 void set_room_policy(void) {
1022 if (!havebstr("ok_button")) {
1023 AppendImportantMessage(_("Cancelled. Changes were not saved."), -1);
1024 output_headers(1, 1, 1, 0, 0, 0);
1025 do_template("room_edit");
1032 serv_printf("SPEX room|%d|%d", ibstr("roompolicy"), ibstr("roomvalue"));
1033 StrBuf_ServGetln(Line);
1034 GetServerStatusMsg(Line, NULL, 1, 0);
1035 if (WC->axlevel >= 6) {
1036 serv_printf("SPEX floor|%d|%d", ibstr("floorpolicy"), ibstr("floorvalue"));
1037 StrBuf_ServGetln(Line);
1038 GetServerStatusMsg(Line, NULL, 1, 0);
1041 ReloadCurrentRoom();
1043 output_headers(1, 1, 1, 0, 0, 0);
1044 do_template("room_edit");
1051 * Perform changes to a room's network configuration
1053 void netedit(void) {
1064 int malias_set_default = 0;
1069 if (havebstr("force_room")) {
1070 gotoroom(sbstr("force_room"));
1072 /*/ TODO: do line dynamic! */
1073 if (havebstr("line_pop3host")) {
1074 strcpy(line, bstr("prefix"));
1075 strcat(line, bstr("line_pop3host"));
1077 strcat(line, bstr("line_pop3user"));
1079 strcat(line, bstr("line_pop3pass"));
1081 strcat(line, ibstr("line_pop3keep") ? "1" : "0" );
1083 sprintf(&line[strlen(line)],"%ld", lbstr("line_pop3int"));
1084 strcat(line, bstr("suffix"));
1086 else if (havebstr("line")) {
1087 strcpy(line, bstr("prefix"));
1088 strcat(line, bstr("line"));
1089 strcat(line, bstr("suffix"));
1091 else if (havebstr("alias")) {
1093 domain = bstr("aliasdomain");
1094 if ((domain == NULL) || IsEmptyStr(domain))
1096 malias_set_default = 1;
1097 strcpy(line, bstr("prefix"));
1098 strcat(line, bstr("default_aliasdomain"));
1104 strcat(line, bstr("prefix"));
1105 if (!IsEmptyStr(domain))
1108 strcat(line, domain);
1111 strcat(line, "room_");
1112 strcat(line, ChrPtr(WC->CurRoom.name));
1116 output_headers(1, 1, 1, 0, 0, 0);
1117 do_template("room_edit");
1123 TmpBuf = NewStrBuf();
1125 serv_puts("GNET "FILE_MAILALIAS);
1128 StrBuf_ServGetln(Line);
1129 if (GetServerStatus(Line, NULL) != 1) {
1130 AppendImportantMessage(SRV_STATUS_MSG(Line));
1132 output_headers(1, 1, 1, 0, 0, 0);
1133 do_template("room_edit");
1138 /** This loop works for add *or* remove. Spiffy, eh? */
1140 extract_token(cmpb0, line, 0, sepchar, sizeof cmpb0);
1141 extract_token(cmpb1, line, 1, sepchar, sizeof cmpb1);
1142 while (!Done && StrBuf_ServGetln(Line)>=0) {
1143 if ( (StrLength(Line)==3) &&
1144 !strcmp(ChrPtr(Line), "000"))
1150 if (StrLength(Line) == 0)
1153 if (malias_set_default)
1155 if (strncasecmp(ChrPtr(Line), HKEY("roommailalias|")) != 0)
1157 StrBufAppendBufPlain(Line, HKEY("\n"), 0);
1158 StrBufAppendBuf(TmpBuf, Line, 0);
1163 extract_token(cmpa0, ChrPtr(Line), 0, sepchar, sizeof cmpa0);
1164 extract_token(cmpa1, ChrPtr(Line), 1, sepchar, sizeof cmpa1);
1165 if ( (strcasecmp(cmpa0, cmpb0)) || (strcasecmp(cmpa1, cmpb1)) )
1167 StrBufAppendBufPlain(Line, HKEY("\n"), 0);
1168 StrBufAppendBuf(TmpBuf, Line, 0);
1175 serv_puts("SNET "FILE_MAILALIAS);
1178 StrBuf_ServGetln(Line);
1179 if (GetServerStatus(Line, NULL) != 4) {
1181 AppendImportantMessage(SRV_STATUS_MSG(Line));
1182 output_headers(1, 1, 1, 0, 0, 0);
1183 do_template("room_edit");
1186 FreeStrBuf(&TmpBuf);
1190 serv_putbuf(TmpBuf);
1191 FreeStrBuf(&TmpBuf);
1193 if (havebstr("add_button")) {
1194 num_addrs = num_tokens(bstr("line"), ',');
1195 if (num_addrs < 2) {
1196 /* just adding one node or address */
1200 /* adding multiple addresses separated by commas */
1201 for (i=0; i<num_addrs; ++i) {
1202 strcpy(line, bstr("prefix"));
1203 extract_token(buf, bstr("line"), i, ',', sizeof buf);
1206 strcat(line, bstr("suffix"));
1214 StrBuf_ServGetln(Line);
1215 if (GetServerStatus(Line, NULL) != 2) { /* WHOOOPS? ERROR? */
1216 AppendImportantMessage(SRV_STATUS_MSG(Line));
1217 StrBuf_ServGetln(Line); /* resync... */
1221 FlushIgnetCfgs(&WC->CurRoom);
1224 output_headers(1, 1, 1, 0, 0, 0);
1225 do_template("room_edit");
1230 * Known rooms list (box style)
1234 DeleteHash(&WC->Rooms);
1235 output_headers(1, 1, 1, 0, 0, 0);
1236 do_template("knrooms");
1257 /*******************************************************************************
1258 ********************** FLOOR Coomands *****************************************
1259 ******************************************************************************/
1264 * delete the actual floor
1266 void delete_floor(void) {
1271 floornum = ibstr("floornum");
1273 serv_printf("KFLR %d|1", floornum);
1275 StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
1277 if (GetServerStatus(Buf, NULL) == 2) {
1278 StrBufPlain(Buf, _("Floor has been deleted."),-1);
1281 StrBufCutLeft(Buf, 4);
1283 AppendImportantMessage (SKEY(Buf));
1286 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1291 * start creating a new floor
1293 void create_floor(void) {
1298 serv_printf("CFLR %s|1", bstr("floorname"));
1299 StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
1301 if (GetServerStatus(Buf, NULL) == 2) {
1302 StrBufPlain(Buf, _("New floor has been created."),-1);
1305 StrBufCutLeft(Buf, 4);
1307 AppendImportantMessage (SKEY(Buf));
1309 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1317 void rename_floor(void) {
1323 serv_printf("EFLR %d|%s", ibstr("floornum"), bstr("floorname"));
1324 StrBuf_ServGetln(Buf);
1326 StrBufCutLeft(Buf, 4);
1327 AppendImportantMessage (SKEY(Buf));
1329 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1335 void jsonRoomFlr(void)
1337 /* Send as our own (application/json) content type */
1338 hprintf("HTTP/1.1 200 OK\r\n");
1339 hprintf("Content-type: application/json; charset=utf-8\r\n");
1340 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1341 hprintf("Connection: close\r\n");
1342 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1344 DoTemplate(HKEY("json_roomflr"),NULL,&NoCtx);
1348 void _FlushRoomList(wcsession *WCC)
1350 free_march_list(WCC);
1351 DeleteHash(&WCC->Floors);
1352 DeleteHash(&WCC->Rooms);
1353 DeleteHash(&WCC->FloorsByName);
1354 FlushFolder(&WCC->CurRoom);
1357 void ReloadCurrentRoom(void)
1359 wcsession *WCC = WC;
1362 CurRoom = WCC->CurRoom.name;
1363 WCC->CurRoom.name = NULL;
1364 _FlushRoomList(WCC);
1366 FreeStrBuf(&CurRoom);
1369 void FlushRoomlist(void)
1371 wcsession *WCC = WC;
1372 _FlushRoomList(WCC);
1380 RegisterPreference("roomlistview",
1381 _("Room list view"),
1384 RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO, NULL);
1386 WebcitAddUrlHandler(HKEY("json_roomflr"), "", 0, jsonRoomFlr, 0);
1388 WebcitAddUrlHandler(HKEY("delete_floor"), "", 0, delete_floor, 0);
1389 WebcitAddUrlHandler(HKEY("rename_floor"), "", 0, rename_floor, 0);
1390 WebcitAddUrlHandler(HKEY("create_floor"), "", 0, create_floor, 0);
1392 WebcitAddUrlHandler(HKEY("knrooms"), "", 0, knrooms, ANONYMOUS);
1393 WebcitAddUrlHandler(HKEY("dotgoto"), "", 0, dotgoto, NEED_URL);
1394 WebcitAddUrlHandler(HKEY("dotskip"), "", 0, dotskip, NEED_URL);
1396 WebcitAddUrlHandler(HKEY("goto_private"), "", 0, goto_private, NEED_URL);
1397 WebcitAddUrlHandler(HKEY("zap"), "", 0, zap, 0);
1398 WebcitAddUrlHandler(HKEY("entroom"), "", 0, entroom, 0);
1399 WebcitAddUrlHandler(HKEY("do_invt_kick"), "", 0, do_invt_kick, 0);
1401 WebcitAddUrlHandler(HKEY("netedit"), "", 0, netedit, 0);
1402 WebcitAddUrlHandler(HKEY("editroom"), "", 0, editroom, 0);
1403 WebcitAddUrlHandler(HKEY("delete_room"), "", 0, delete_room, 0);
1404 WebcitAddUrlHandler(HKEY("set_room_policy"), "", 0, set_room_policy, 0);
1405 WebcitAddUrlHandler(HKEY("changeview"), "", 0, change_view, 0);
1406 WebcitAddUrlHandler(HKEY("toggle_self_service"), "", 0, toggle_self_service, 0);
1409 REGISTERTokenParamDefine(QR_PERMANENT);
1410 REGISTERTokenParamDefine(QR_INUSE);
1411 REGISTERTokenParamDefine(QR_PRIVATE);
1412 REGISTERTokenParamDefine(QR_PASSWORDED);
1413 REGISTERTokenParamDefine(QR_GUESSNAME);
1414 REGISTERTokenParamDefine(QR_DIRECTORY);
1415 REGISTERTokenParamDefine(QR_UPLOAD);
1416 REGISTERTokenParamDefine(QR_DOWNLOAD);
1417 REGISTERTokenParamDefine(QR_VISDIR);
1418 REGISTERTokenParamDefine(QR_ANONONLY);
1419 REGISTERTokenParamDefine(QR_ANONOPT);
1420 REGISTERTokenParamDefine(QR_NETWORK);
1421 REGISTERTokenParamDefine(QR_PREFONLY);
1422 REGISTERTokenParamDefine(QR_READONLY);
1423 REGISTERTokenParamDefine(QR_MAILBOX);
1424 REGISTERTokenParamDefine(QR2_SYSTEM);
1425 REGISTERTokenParamDefine(QR2_SELFLIST);
1426 REGISTERTokenParamDefine(QR2_COLLABDEL);
1427 REGISTERTokenParamDefine(QR2_SUBJECTREQ);
1428 REGISTERTokenParamDefine(QR2_SMTP_PUBLIC);
1429 REGISTERTokenParamDefine(QR2_MODERATED);
1431 REGISTERTokenParamDefine(UA_KNOWN);
1432 REGISTERTokenParamDefine(UA_GOTOALLOWED);
1433 REGISTERTokenParamDefine(UA_HASNEWMSGS);
1434 REGISTERTokenParamDefine(UA_ZAPPED);
1435 REGISTERTokenParamDefine(UA_POSTALLOWED);
1436 REGISTERTokenParamDefine(UA_ADMINALLOWED);
1437 REGISTERTokenParamDefine(UA_DELETEALLOWED);
1438 REGISTERTokenParamDefine(UA_REPLYALLOWED);
1439 REGISTERTokenParamDefine(UA_ISTRASH);
1441 REGISTERTokenParamDefine(US_NEEDVALID);
1442 REGISTERTokenParamDefine(US_PERM);
1443 REGISTERTokenParamDefine(US_LASTOLD);
1444 REGISTERTokenParamDefine(US_EXPERT);
1445 REGISTERTokenParamDefine(US_UNLISTED);
1446 REGISTERTokenParamDefine(US_NOPROMPT);
1447 REGISTERTokenParamDefine(US_PROMPTCTL);
1448 REGISTERTokenParamDefine(US_DISAPPEAR);
1449 REGISTERTokenParamDefine(US_REGIS);
1450 REGISTERTokenParamDefine(US_PAGINATOR);
1451 REGISTERTokenParamDefine(US_INTERNET);
1452 REGISTERTokenParamDefine(US_FLOORS);
1453 REGISTERTokenParamDefine(US_COLOR);
1454 REGISTERTokenParamDefine(US_USER_SET);
1456 REGISTERTokenParamDefine(VIEW_BBS);
1457 REGISTERTokenParamDefine(VIEW_MAILBOX);
1458 REGISTERTokenParamDefine(VIEW_ADDRESSBOOK);
1459 REGISTERTokenParamDefine(VIEW_CALENDAR);
1460 REGISTERTokenParamDefine(VIEW_TASKS);
1461 REGISTERTokenParamDefine(VIEW_NOTES);
1462 REGISTERTokenParamDefine(VIEW_WIKI);
1463 REGISTERTokenParamDefine(VIEW_CALBRIEF);
1464 REGISTERTokenParamDefine(VIEW_JOURNAL);
1465 REGISTERTokenParamDefine(VIEW_BLOG);
1466 REGISTERTokenParamDefine(VIEW_QUEUE);
1467 REGISTERTokenParamDefine(VIEW_WIKIMD);
1470 /* server internal, we need to know but ignore them. */
1471 REGISTERTokenParamDefine(subpending);
1472 REGISTERTokenParamDefine(unsubpending);
1473 REGISTERTokenParamDefine(lastsent);
1475 REGISTERTokenParamDefine(ignet_push_share);
1476 { /* these are the parts of an IGNET push config */
1477 REGISTERTokenParamDefine(GNET_IGNET_NODE);
1478 REGISTERTokenParamDefine(GNET_IGNET_ROOM);
1480 REGISTERTokenParamDefine(listrecp);
1481 REGISTERTokenParamDefine(digestrecp);
1482 REGISTERTokenParamDefine(pop3client);
1483 { /* These are the parts of a pop3 client line... */
1484 REGISTERTokenParamDefine(GNET_POP3_HOST);
1485 REGISTERTokenParamDefine(GNET_POP3_USER);
1486 REGISTERTokenParamDefine(GNET_POP3_DONT_DELETE_REMOTE);
1487 REGISTERTokenParamDefine(GNET_POP3_INTERVAL);
1489 REGISTERTokenParamDefine(rssclient);
1490 REGISTERTokenParamDefine(participate);
1491 REGISTERTokenParamDefine(roommailalias);
1499 SessionDestroyModule_ROOMOPS
1502 _FlushRoomList (sess);