Renderers cleanup part 1
[citadel.git] / webcit / roomops.c
1 /*
2  * Lots of different room-related operations.
3  *
4  * Copyright (c) 1996-2016 by the citadel.org team
5  *
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.
8  *
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.
13  */
14
15 #include "webcit.h"
16 #include "webserver.h"
17
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))}
34 };
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))}, 
43         {HKEY("")}, 
44         {HKEY("")}, 
45         {HKEY("")}, 
46         {HKEY("")}, 
47         {HKEY("")}, 
48         {HKEY("")}, 
49         {HKEY("")}, 
50         {HKEY("")}
51 };
52
53 void _DBG_QR(long QR)
54 {
55         int i = 1;
56         int j=0;
57         StrBuf *QRVec;
58
59         QRVec = NewStrBufPlain(NULL, 256);
60         while (i != 0)
61         {
62                 if ((QR & i) != 0) {
63                         if (StrLength(QRVec) > 0)
64                                 StrBufAppendBufPlain(QRVec, HKEY(" | "), 0);
65                         StrBufAppendBufPlain(QRVec, CKEY(QRFlagList[j]), 0);
66                 }
67                 i = i << 1;
68                 j++;
69         }
70         syslog(LOG_DEBUG, "DBG: QR-Vec [%ld] [%s]\n", QR, ChrPtr(QRVec));
71         FreeStrBuf(&QRVec);
72 }
73
74
75
76 void _DBG_QR2(long QR2)
77 {
78         int i = 1;
79         int j=0;
80         StrBuf *QR2Vec;
81
82         QR2Vec = NewStrBufPlain(NULL, 256);
83         while (i != 0)
84         {
85                 if ((QR2 & i) != 0) {
86                         if (StrLength(QR2Vec) > 0)
87                                 StrBufAppendBufPlain(QR2Vec, HKEY(" | "), 0);
88                         StrBufAppendBufPlain(QR2Vec, CKEY(QR2FlagList[j]), 0);
89                 }
90                 i = i << 1;
91                 j++;
92         }
93         syslog(LOG_DEBUG, "DBG: QR2-Vec [%ld] [%s]\n", QR2, ChrPtr(QR2Vec));
94         FreeStrBuf(&QR2Vec);
95 }
96
97
98
99
100
101
102
103
104
105
106
107 /*******************************************************************************
108  ***************************** Goto Commands ***********************************
109  ******************************************************************************/
110
111 void dotskip(void) {
112         smart_goto(sbstr("room"));
113 }
114
115 void dotgoto(void) {
116         if (!havebstr("room")) {
117                 readloop(readnew, eUseDefault);
118                 return;
119         }
120         if (WC->CurRoom.view != VIEW_MAILBOX) {
121                 /* dotgoto acts like dotskip when we're in a mailbox view */
122                 slrp_highest();
123         }
124         smart_goto(sbstr("room"));
125 }
126
127 /*
128  * goto next room
129  */
130 void smart_goto(const StrBuf *next_room) {
131         if (gotoroom(next_room) / 100 == 2)
132                 readloop(readnew, eUseDefault);
133         else
134                 do_404();
135 }
136
137 /*
138  * goto a private room
139  */
140 void goto_private(void)
141 {
142         char hold_rm[SIZ];
143         StrBuf *Buf;
144         const StrBuf *gr_name;
145         long err;
146
147         if (!havebstr("ok_button")) {
148                 display_main_menu();
149                 return;
150         }
151         gr_name = sbstr("gr_name");
152         Buf = NewStrBuf();
153         strcpy(hold_rm, ChrPtr(WC->CurRoom.name));
154         serv_printf("GOTO %s|%s",
155                     ChrPtr(gr_name),
156                     bstr("gr_pass"));
157         StrBuf_ServGetln(Buf);
158         if  (GetServerStatus(Buf, &err) == 2) {
159                 FlushRoomlist();
160                 smart_goto(gr_name);
161                 FreeStrBuf(&Buf);
162                 return;
163         }
164         if (err == 540) {
165                 DoTemplate(HKEY("room_display_private"), NULL, &NoCtx);
166                 FreeStrBuf(&Buf);
167                 return;
168         }
169         StrBufCutLeft(Buf, 4);
170         AppendImportantMessage (SKEY(Buf));
171         Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
172         smart_goto(Buf);
173         FreeStrBuf(&Buf);
174         return;
175 }
176
177 /*
178  * back end routine to take the session to a new room
179  */
180 long gotoroom(const StrBuf *gname)
181 {
182         wcsession *WCC = WC;
183         StrBuf *Buf;
184         static long ls = (-1L);
185         long err = 0;
186         int room_name_supplied = 0;
187         int is_baseroom = 0;
188         int failvisibly;
189
190         /* on fail, should we fallback to _BASEROOM_? */
191         failvisibly = ibstr("failvisibly");
192
193         /* store ungoto information */
194         if (StrLength(gname) > 0) {
195                 room_name_supplied = 1;
196         }
197         if (room_name_supplied) {
198                 strcpy(WCC->ugname, ChrPtr(WCC->CurRoom.name));
199                 if (!strcasecmp(ChrPtr(gname), "_BASEROOM_")) {
200                         is_baseroom = 1;
201                 }
202         }
203         WCC->uglsn = ls;
204         Buf = NewStrBuf();
205
206         /* move to the new room */
207         if (room_name_supplied) {
208                 serv_printf("GOTO %s", ChrPtr(gname));
209         }
210         else {
211                 /* or just refresh the current state... */
212                 serv_printf("GOTO 00000000000000000000");
213         }
214         StrBuf_ServGetln(Buf);
215         if  (GetServerStatus(Buf, &err) != 2) {
216                 if (failvisibly) {
217                         FreeStrBuf(&Buf);
218                         return err;
219                 }
220                 serv_puts("GOTO _BASEROOM_");
221                 StrBuf_ServGetln(Buf);
222                 /* 
223                  * well, we know that this is the fallback case, 
224                  * but we're interested that the first command 
225                  * didn't work out in first place.
226                  */
227                 if (GetServerStatus(Buf, NULL) != 2) {
228                         FreeStrBuf(&Buf);
229                         return err;
230                 }
231         }
232         FlushFolder(&WCC->CurRoom);
233         ParseGoto(&WCC->CurRoom, Buf);
234
235         if (room_name_supplied) {
236                 remove_march(WCC->CurRoom.name);
237                 if (is_baseroom) {
238                         remove_march(gname);
239                 }
240         }
241         FreeStrBuf(&Buf);
242
243         return err;
244 }
245
246
247
248 void ParseGoto(folder *room, StrBuf *Line)
249 {
250         wcsession *WCC = WC;
251         const char *Pos;
252         int flag;
253         void *vFloor = NULL;
254         StrBuf *pBuf;
255
256         if (StrLength(Line) < 4) {
257                 return;
258         }
259         
260         /* ignore the commandstate... */
261         Pos = ChrPtr(Line) + 4;
262
263         if (room->RoomNameParts != NULL)
264         {
265                 int i;
266                 for (i=0; i < room->nRoomNameParts; i++)
267                         FreeStrBuf(&room->RoomNameParts[i]);
268                 free(room->RoomNameParts);
269                 room->RoomNameParts = NULL;
270         }
271
272         pBuf = room->name;  
273         if (pBuf == NULL)
274                 pBuf = NewStrBufPlain(NULL, StrLength(Line));
275         else
276                 FlushStrBuf(pBuf);
277         memset(room, 0, sizeof(folder));
278         room->name = pBuf;
279
280         StrBufExtract_NextToken(room->name, Line, &Pos, '|');
281
282         room->nNewMessages = StrBufExtractNext_long(Line, &Pos, '|'); 
283         if (room->nNewMessages > 0)
284                 room->RAFlags |= UA_HASNEWMSGS;
285
286         room->nTotalMessages = StrBufExtractNext_long(Line, &Pos, '|');
287
288         room->ShowInfo =  StrBufExtractNext_long(Line, &Pos, '|');
289         
290         room->QRFlags = StrBufExtractNext_long(Line, &Pos, '|');
291
292         DBG_QR(room->QRFlags);
293
294         room->HighestRead = StrBufExtractNext_long(Line, &Pos, '|');
295         room->LastMessageRead = StrBufExtractNext_long(Line, &Pos, '|');
296
297         room->is_inbox = StrBufExtractNext_long(Line, &Pos, '|');
298
299         flag = StrBufExtractNext_long(Line, &Pos, '|');
300         if (WCC->is_aide || flag) {
301                 room->RAFlags |= UA_ADMINALLOWED;
302         }
303
304         room->UsersNewMAilboxMessages = StrBufExtractNext_long(Line, &Pos, '|');
305
306         room->floorid = StrBufExtractNext_int(Line, &Pos, '|');
307
308         room->view = StrBufExtractNext_long(Line, &Pos, '|');
309
310         room->defview = StrBufExtractNext_long(Line, &Pos, '|');
311
312         flag = StrBufExtractNext_long(Line, &Pos, '|');
313         if (flag)
314                 room->RAFlags |= UA_ISTRASH;
315
316         room->QRFlags2 = StrBufExtractNext_long(Line, &Pos, '|');
317         DBG_QR2(room->QRFlags2);
318
319         /* find out, whether we are in a sub-room */
320         room->nRoomNameParts = StrBufNum_tokens(room->name, '\\');
321         if (room->nRoomNameParts > 1)
322         {
323                 int i;
324                 
325                 Pos = NULL;
326                 room->RoomNameParts = malloc(sizeof(StrBuf*) * (room->nRoomNameParts + 1));
327                 memset(room->RoomNameParts, 0, sizeof(StrBuf*) * (room->nRoomNameParts + 1));
328                 for (i=0; i < room->nRoomNameParts; i++)
329                 {
330                         room->RoomNameParts[i] = NewStrBuf();
331                         StrBufExtract_NextToken(room->RoomNameParts[i],
332                                                 room->name, &Pos, '\\');
333                 }
334         }
335
336         /* Private mailboxes on the main floor get remapped to the personal folder */
337         if ((room->QRFlags & QR_MAILBOX) && 
338             (room->floorid == 0))
339         {
340                 room->floorid = VIRTUAL_MY_FLOOR;
341                 if ((room->nRoomNameParts == 1) && 
342                     (StrLength(room->name) == 4) && 
343                     (strcmp(ChrPtr(room->name), "Mail") == 0))
344                 {
345                         room->is_inbox = 1;
346                 }
347                 
348         }
349         /* get a pointer to the floor we're on: */
350         if (WCC->Floors == NULL)
351                 GetFloorListHash(NULL, NULL);
352
353         GetHash(WCC->Floors, IKEY(room->floorid), &vFloor);
354         room->Floor = (const Floor*) vFloor;
355 }
356
357 /*
358  * Delete the current room
359  */
360 void delete_room(void)
361 {
362         StrBuf *Line = NewStrBuf();
363         const StrBuf *GoBstr;
364         
365         GoBstr = sbstr("go");
366
367         if (GoBstr != NULL)
368         {
369                 if (gotoroom(GoBstr) == 200)
370                 {
371                         serv_puts("KILL 1");
372                         StrBuf_ServGetln(Line);
373                         if (GetServerStatusMsg(Line, NULL, 1, 2) == 2) {
374                                 StrBuf *Buf;
375                                 
376                                 FlushRoomlist ();
377                                 Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
378                                 smart_goto(Buf);
379                                 FreeStrBuf(&Buf);
380                                 FreeStrBuf(&Line);
381                                 return;
382                         }
383                 }
384         }
385         display_main_menu();
386         FreeStrBuf(&Line);
387 }
388
389 /*
390  * zap a room
391  */
392 void zap(void)
393 {
394         char buf[SIZ];
395         StrBuf *final_destination;
396
397         /**
398          * If the forget-room routine fails for any reason, we fall back
399          * to the current room; otherwise, we go to the Lobby
400          */
401         final_destination = NewStrBufDup(WC->CurRoom.name);
402
403         if (havebstr("ok_button")) {
404                 serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
405                 serv_getln(buf, sizeof buf);
406                 if (buf[0] == '2') {
407                         serv_puts("FORG");
408                         serv_getln(buf, sizeof buf);
409                         if (buf[0] == '2') {
410                                 FlushStrBuf(final_destination);
411                                 StrBufAppendBufPlain(final_destination, HKEY("_BASEROOM_"), 0);
412                         }
413                 }
414                 FlushRoomlist ();
415         }
416         smart_goto(final_destination);
417         FreeStrBuf(&final_destination);
418 }
419
420
421 /*
422  * mark all messages in current room as having been read
423  */
424 void slrp_highest(void)
425 {
426         char buf[256];
427
428         serv_puts("SLRP HIGHEST");
429         serv_getln(buf, sizeof buf);
430 }
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445 /*******************************************************************************
446  ***************************** Modify Rooms ************************************
447  ******************************************************************************/
448
449
450
451
452
453 void LoadRoomAide(void)
454 {
455         wcsession *WCC = WC;
456         StrBuf *Buf;
457         
458         if (WCC->CurRoom.RoomAideLoaded)
459                 return;
460
461         WCC->CurRoom.RoomAideLoaded = 1;
462         Buf = NewStrBuf();
463         serv_puts("GETA");
464         StrBuf_ServGetln(Buf);
465         if (GetServerStatus(Buf, NULL) != 2) {
466                 FlushStrBuf(WCC->CurRoom.RoomAide);
467                 AppendImportantMessage (ChrPtr(Buf) + 4, 
468                                         StrLength(Buf) - 4);
469         } else {
470                 const char *Pos;
471
472                 Pos = ChrPtr(Buf) + 4;
473
474                 FreeStrBuf(&WCC->CurRoom.RoomAide);
475                 WCC->CurRoom.RoomAide = NewStrBufPlain (NULL, StrLength (Buf));
476
477                 StrBufExtract_NextToken(WCC->CurRoom.RoomAide, Buf, &Pos, '|'); 
478         }
479         FreeStrBuf (&Buf);
480 }
481
482 int SaveRoomAide(folder *Room)
483 {
484         StrBuf *Buf;
485         Buf = NewStrBuf ();
486         serv_printf("SETA %s", ChrPtr(Room->RoomAide));
487         StrBuf_ServGetln(Buf);
488         if (GetServerStatus(Buf, NULL) != 2) {
489                 StrBufCutLeft(Buf, 4);
490                 AppendImportantMessage (SKEY(Buf));
491                 FreeStrBuf(&Buf);
492                 return 0;
493         }
494         FreeStrBuf(&Buf);
495         return 1;
496 }
497
498
499 int GetCurrentRoomFlags(folder *Room, int CareForStatusMessage)
500 {
501         StrBuf *Buf;
502
503         Buf = NewStrBuf();
504         serv_puts("GETR");
505         StrBuf_ServGetln(Buf);
506         if (GetServerStatus(Buf, NULL) != 2) {
507                 FlushStrBuf(Room->XAPass);
508                 FlushStrBuf(Room->Directory);
509                 StrBufCutLeft(Buf, 4);
510                 if (CareForStatusMessage)
511                         AppendImportantMessage (SKEY(Buf));
512                 FreeStrBuf(&Buf);
513                 Room->XALoaded = 2;
514                 return 0;
515         } else {
516                 const char *Pos;
517
518                 Pos = ChrPtr(Buf) + 4;
519
520                 FreeStrBuf(&Room->XAPass);
521                 FreeStrBuf(&Room->Directory);
522
523                 Room->XAPass = NewStrBufPlain (NULL, StrLength (Buf));
524                 Room->Directory = NewStrBufPlain (NULL, StrLength (Buf));
525
526                 FreeStrBuf(&Room->name);
527                 Room->name = NewStrBufPlain(NULL, StrLength(Buf));
528                 StrBufExtract_NextToken(Room->name, Buf, &Pos, '|'); 
529                                         
530                 StrBufExtract_NextToken(Room->XAPass, Buf, &Pos, '|'); 
531                 StrBufExtract_NextToken(Room->Directory, Buf, &Pos, '|'); 
532                 
533                 Room->QRFlags = StrBufExtractNext_long(Buf, &Pos, '|');
534                 Room->floorid = StrBufExtractNext_long(Buf, &Pos, '|');
535                 Room->Order = StrBufExtractNext_long(Buf, &Pos, '|');
536                 Room->defview = StrBufExtractNext_long(Buf, &Pos, '|');
537                 Room->QRFlags2 = StrBufExtractNext_long(Buf, &Pos, '|');
538                 FreeStrBuf (&Buf);
539                 Room->XALoaded = 1;
540                 return 1;
541         }
542 }
543
544
545 int SetCurrentRoomFlags(folder *Room)
546 {
547         StrBuf *Buf;
548
549         Buf = NewStrBuf();
550         DBG_QR(Room->QRFlags);
551         DBG_QR2(Room->QRFlags2);
552
553         serv_printf("SETR %s|%s|%s|%ld|%d|%d|%ld|%ld|%ld",
554                     ChrPtr(Room->name),
555                     ChrPtr(Room->XAPass),
556                     ChrPtr(Room->Directory),
557                     Room->QRFlags, 
558                     Room->BumpUsers,
559                     Room->floorid, 
560                     Room->Order,
561                     Room->defview,
562                     Room->QRFlags2);
563
564         StrBuf_ServGetln(Buf);
565         if (GetServerStatus(Buf, NULL) != 2) {
566                 StrBufCutLeft(Buf, 4);
567                 AppendImportantMessage (SKEY(Buf));
568                 FreeStrBuf(&Buf);
569                 return 0;
570         } else {
571                 FreeStrBuf(&Buf);
572                 return 1;
573         }
574 }
575
576 void LoadRoomXA (void)
577 {
578         wcsession *WCC = WC;
579                 
580         if (WCC->CurRoom.XALoaded > 0)
581                 return;
582
583         GetCurrentRoomFlags(&WCC->CurRoom, 0);
584 }
585
586
587 void LoadXRoomPic(void)
588 {
589         wcsession *WCC = WC;
590         StrBuf *Buf;
591         off_t bytes;
592         
593         if (WCC->CurRoom.XHaveRoomPicLoaded) {
594                 return;
595         }
596
597         WCC->CurRoom.XHaveRoomPicLoaded = 1;
598         Buf = NewStrBuf();
599         serv_puts("DLRI");
600         StrBuf_ServGetln(Buf);
601         if (GetServerStatus(Buf, NULL) == 6) {
602                 StrBufCutLeft(Buf, 4);
603                 bytes = StrBufExtract_long(Buf, 0, '|');
604                 WCC->CurRoom.XHaveRoomPic = 1;
605                 StrBuf_ServGetBLOBBuffered(Buf, bytes);         // discard the data
606         } else {
607                 WCC->CurRoom.XHaveRoomPic = 0;
608         }
609         FreeStrBuf (&Buf);
610 }
611
612
613 void LoadXRoomInfoText(void)
614 {
615         wcsession *WCC = WC;
616         StrBuf *Buf;
617         int Done = 0;
618         
619         if (WCC->CurRoom.XHaveInfoTextLoaded) {
620                 return;
621         }
622
623         WCC->CurRoom.XHaveInfoTextLoaded = 1;
624         Buf = NewStrBuf();
625
626         serv_puts("RINF");
627
628         StrBuf_ServGetln(Buf);
629         if (GetServerStatus(Buf, NULL) == 1) {
630                 WCC->CurRoom.XInfoText = NewStrBuf ();
631                 
632                 while (!Done && StrBuf_ServGetln(Buf)>=0) {
633                         if ( (StrLength(Buf)==3) && 
634                              !strcmp(ChrPtr(Buf), "000")) 
635                                 Done = 1;
636                         else 
637                                 StrBufAppendBuf(WCC->CurRoom.XInfoText, Buf, 0);
638                 }
639         }
640
641         FreeStrBuf(&Buf);
642 }
643
644
645 void LoadXRoomXCountFiles(void)
646 {
647         wcsession *WCC = WC;
648         StrBuf *Buf;
649         int Done = 0;
650         
651         if (WCC->CurRoom.XHaveDownloadCount)
652                 return;
653
654         WCC->CurRoom.XHaveDownloadCount = 1;
655
656         Buf = NewStrBuf();
657         serv_puts("RDIR");
658         StrBuf_ServGetln(Buf);
659         if (GetServerStatus(Buf, NULL) == 1) {
660                 
661                 while (!Done && StrBuf_ServGetln(Buf)>=0) {
662                         if ( (StrLength(Buf)==3) && 
663                              !strcmp(ChrPtr(Buf), "000")) 
664                                 Done = 1;
665                         else 
666                                 WCC->CurRoom.XDownloadCount++;
667                 }
668         }
669
670         FreeStrBuf (&Buf);
671 }
672
673
674 /* 
675  * Toggle self-service list subscription
676  */
677 void toggle_self_service(void) {
678         wcsession *WCC = WC;
679
680         if (GetCurrentRoomFlags (&WCC->CurRoom, 1) == 0)
681                 return;
682
683         if (yesbstr("QR2_SelfList")) 
684                 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SELFLIST;
685         else 
686                 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SELFLIST;
687
688         if (yesbstr("QR2_SMTP_PUBLIC")) 
689                 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SMTP_PUBLIC;
690         else
691                 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SMTP_PUBLIC;
692
693         if (yesbstr("QR2_Moderated")) 
694                 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_MODERATED;
695         else
696                 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_MODERATED;
697         if (yesbstr("QR2_SubsOnly")) 
698                 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SMTP_PUBLIC;
699         else
700                 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SMTP_PUBLIC;
701
702         SetCurrentRoomFlags (&WCC->CurRoom);
703
704         output_headers(1, 1, 1, 0, 0, 0);       
705         do_template("room_edit");
706         wDumpContent(1);
707 }
708
709
710
711 /*
712  * save new parameters for a room
713  */
714 void editroom(void)
715 {
716         wcsession *WCC = WC;
717         const StrBuf *Ptr;
718         const StrBuf *er_name;
719         const StrBuf *er_password;
720         const StrBuf *er_dirname;
721         const StrBuf *er_roomaide;
722         const StrBuf *templ;
723         int succ1, succ2;
724
725         templ = sbstr("template");
726         if (!havebstr("ok_button")) {
727                 putlbstr("success", 0);
728                 AppendImportantMessage(_("Cancelled.  Changes were not saved."), -1);
729                 if (templ != NULL) {
730                         output_headers(1, 0, 0, 0, 0, 0);       
731                         DoTemplate(SKEY(templ), NULL, &NoCtx);
732                         end_burst();
733                 }
734                 else {
735                         output_headers(1, 1, 1, 0, 0, 0);       
736                         do_template("room_edit");
737                         wDumpContent(1);
738                 }
739                 return;
740         }
741
742         if (GetCurrentRoomFlags (&WCC->CurRoom, 1) == 0) {
743                 putlbstr("success", 0);
744                 if (templ != NULL) {
745                         output_headers(1, 0, 0, 0, 0, 0);       
746                         DoTemplate(SKEY(templ), NULL, &NoCtx);
747                         end_burst();
748                 }
749                 else {
750                         output_headers(1, 1, 1, 0, 0, 0);       
751                         do_template("room_edit");
752                         wDumpContent(1);
753                 }
754                 return;
755         }
756
757         LoadRoomAide();
758         WCC->CurRoom.QRFlags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
759
760         Ptr = sbstr("type");
761         if (!strcmp(ChrPtr(Ptr), "invonly")) {
762                 WCC->CurRoom.QRFlags |= (QR_PRIVATE);
763         }
764         if (!strcmp(ChrPtr(Ptr), "hidden")) {
765                 WCC->CurRoom.QRFlags |= (QR_PRIVATE | QR_GUESSNAME);
766         }
767         if (!strcmp(ChrPtr(Ptr), "passworded")) {
768                 WCC->CurRoom.QRFlags |= (QR_PRIVATE | QR_PASSWORDED);
769         }
770         if (!strcmp(ChrPtr(Ptr), "personal")) {
771                 WCC->CurRoom.QRFlags |= QR_MAILBOX;
772         } else {
773                 WCC->CurRoom.QRFlags &= ~QR_MAILBOX;
774         }
775
776         if (yesbstr("prefonly")) {
777                 WCC->CurRoom.QRFlags |= QR_PREFONLY;
778         } else {
779                 WCC->CurRoom.QRFlags &= ~QR_PREFONLY;
780         }
781
782         if (yesbstr("readonly")) {
783                 WCC->CurRoom.QRFlags |= QR_READONLY;
784         } else {
785                 WCC->CurRoom.QRFlags &= ~QR_READONLY;
786         }
787
788         if (yesbstr("collabdel")) {
789                 WCC->CurRoom.QRFlags2 |= QR2_COLLABDEL;
790         } else {
791                 WCC->CurRoom.QRFlags2 &= ~QR2_COLLABDEL;
792         }
793
794         if (yesbstr("permanent")) {
795                 WCC->CurRoom.QRFlags |= QR_PERMANENT;
796         } else {
797                 WCC->CurRoom.QRFlags &= ~QR_PERMANENT;
798         }
799
800         if (yesbstr("subjectreq")) {
801                 WCC->CurRoom.QRFlags2 |= QR2_SUBJECTREQ;
802         } else {
803                 WCC->CurRoom.QRFlags2 &= ~QR2_SUBJECTREQ;
804         }
805
806         if (yesbstr("network")) {
807                 WCC->CurRoom.QRFlags |= QR_NETWORK;
808         } else {
809                 WCC->CurRoom.QRFlags &= ~QR_NETWORK;
810         }
811
812         if (yesbstr("directory")) {
813                 WCC->CurRoom.QRFlags |= QR_DIRECTORY;
814         } else {
815                 WCC->CurRoom.QRFlags &= ~QR_DIRECTORY;
816         }
817
818         if (yesbstr("ulallowed")) {
819                 WCC->CurRoom.QRFlags |= QR_UPLOAD;
820         } else {
821                 WCC->CurRoom.QRFlags &= ~QR_UPLOAD;
822         }
823
824         if (yesbstr("dlallowed")) {
825                 WCC->CurRoom.QRFlags |= QR_DOWNLOAD;
826         } else {
827                 WCC->CurRoom.QRFlags &= ~QR_DOWNLOAD;
828         }
829
830         if (yesbstr("ulmsg")) {
831                 WCC->CurRoom.QRFlags2 |= QR2_NOUPLMSG;
832         } else {
833                 WCC->CurRoom.QRFlags2 &= ~QR2_NOUPLMSG;
834         }
835
836         if (yesbstr("visdir")) {
837                 WCC->CurRoom.QRFlags |= QR_VISDIR;
838         } else {
839                 WCC->CurRoom.QRFlags &= ~QR_VISDIR;
840         }
841
842         Ptr = sbstr("anon");
843
844         WCC->CurRoom.QRFlags &= ~(QR_ANONONLY | QR_ANONOPT);
845         if (!strcmp(ChrPtr(Ptr), "anononly"))
846                 WCC->CurRoom.QRFlags |= QR_ANONONLY;
847         if (!strcmp(ChrPtr(Ptr), "anon2"))
848                 WCC->CurRoom.QRFlags |= QR_ANONOPT;
849
850         er_name     = sbstr("er_name");
851         er_dirname  = sbstr("er_dirname");
852         er_roomaide = sbstr("er_roomaide");
853         er_password = sbstr("er_password");
854
855         FlushStrBuf(WCC->CurRoom.name);
856         StrBufAppendBuf(WCC->CurRoom.name, er_name, 0);
857
858         FlushStrBuf(WCC->CurRoom.Directory);
859         StrBufAppendBuf(WCC->CurRoom.Directory, er_dirname, 0);
860
861         FlushStrBuf(WCC->CurRoom.RoomAide);
862         StrBufAppendBuf(WCC->CurRoom.RoomAide, er_roomaide, 0);
863
864         FlushStrBuf(WCC->CurRoom.XAPass);
865         StrBufAppendBuf(WCC->CurRoom.XAPass, er_password, 0);
866
867         WCC->CurRoom.BumpUsers = yesbstr("bump");
868
869         WCC->CurRoom.floorid = ibstr("er_floor");
870
871         succ1 = SetCurrentRoomFlags(&WCC->CurRoom);
872
873         succ2 = SaveRoomAide (&WCC->CurRoom);
874         
875         if (succ1 + succ2 == 0) {
876                 putlbstr("success", 1);
877                 AppendImportantMessage (_("Your changes have been saved."), -1);
878         }
879         else {
880                 putlbstr("success", 0);
881         }
882         if (templ != NULL) {
883                 output_headers(1, 0, 0, 0, 0, 0);       
884                 DoTemplate(SKEY(templ), NULL, &NoCtx);
885                 end_burst();
886         }
887         else {
888                 output_headers(1, 1, 1, 0, 0, 0);       
889                 do_template("room_edit");
890                 wDumpContent(1);
891         }
892         return;
893 }
894
895
896
897 /*
898  * Display form for Invite, Kick, and show Who Knows a room
899  */
900 void do_invt_kick(void) 
901 {
902         StrBuf *Buf, *User;
903         const StrBuf *UserNames;
904         int Kick, Invite;
905         wcsession *WCC = WC;
906
907
908         if (GetCurrentRoomFlags(&WCC->CurRoom, 1) == 1)
909         {
910                 const char *Pos;
911                 UserNames = sbstr("username");
912                 Kick = havebstr("kick_button");
913                 Invite = havebstr("invite_button");
914
915                 User = NewStrBufPlain(NULL, StrLength(UserNames));
916                 Buf = NewStrBuf();
917                 
918                 Pos = ChrPtr(UserNames);
919                 while (Pos != StrBufNOTNULL)
920                 {
921                         StrBufExtract_NextToken(User, UserNames, &Pos, ',');
922                         StrBufTrim(User);
923                         if ((StrLength(User) > 0) && (Kick))
924                         {
925                                 serv_printf("KICK %s", ChrPtr(User));
926                                 if (StrBuf_ServGetln(Buf) < 0)
927                                         break;
928                                 if (GetServerStatus(Buf, NULL) != 2) {
929                                         StrBufCutLeft(Buf, 4);
930                                         AppendImportantMessage(SKEY(Buf));
931                                 } else {
932                                         StrBufPrintf(Buf, 
933                                                      _("User '%s' kicked out of room '%s'."), 
934                                                      ChrPtr(User), 
935                                                      ChrPtr(WCC->CurRoom.name)
936                                                 );
937                                         AppendImportantMessage(SKEY(Buf));
938                                 }
939                         }
940                         else if ((StrLength(User) > 0) && (Invite))
941                         {
942                                 serv_printf("INVT %s", ChrPtr(User));
943                                 if (StrBuf_ServGetln(Buf) < 0)
944                                         break;
945                                 if (GetServerStatus(Buf, NULL) != 2) {
946                                         StrBufCutLeft(Buf, 4);
947                                         AppendImportantMessage(SKEY(Buf));
948                                 } else {
949                                         StrBufPrintf(Buf, 
950                                                      _("User '%s' invited to room '%s'."), 
951                                                      ChrPtr(User), 
952                                                      ChrPtr(WCC->CurRoom.name)
953                                                 );
954                                         AppendImportantMessage(SKEY(Buf));
955                                 }
956                         }
957                 }
958         }
959
960         output_headers(1, 1, 1, 0, 0, 0);       
961         do_template("room_edit");
962         wDumpContent(1);
963 }
964
965
966 /*
967  * Create a new room
968  */
969 void entroom(void)
970 {
971         StrBuf *Line;
972         const StrBuf *er_name;
973         const StrBuf *er_type;
974         const StrBuf *er_password;
975         const StrBuf *template;
976         int er_floor;
977         int er_num_type;
978         int er_view;
979         wcsession *WCC = WC;
980
981         template = sbstr("template");
982         if ((WCC == NULL) || !havebstr("ok_button")) {
983                 putlbstr("success", 0);
984                 AppendImportantMessage(_("Cancelled.  No new room was created."), -1);
985                 if (template != NULL) {
986                         output_headers(1, 0, 0, 0, 0, 0);       
987                         DoTemplate(SKEY(template), NULL, &NoCtx);
988                         end_burst();
989                 }
990                 else {
991                         display_main_menu();
992                 }
993                 return;
994         }
995         er_name = sbstr("er_name");
996         er_type = sbstr("type");
997         er_password = sbstr("er_password");
998         er_floor = ibstr("er_floor");
999         er_view = ibstr("er_view");
1000
1001         er_num_type = 0;
1002         if (!strcmp(ChrPtr(er_type), "hidden"))
1003                 er_num_type = 1;
1004         else if (!strcmp(ChrPtr(er_type), "passworded"))
1005                 er_num_type = 2;
1006         else if (!strcmp(ChrPtr(er_type), "invonly"))
1007                 er_num_type = 3;
1008         else if (!strcmp(ChrPtr(er_type), "personal"))
1009                 er_num_type = 4;
1010
1011         serv_printf("CRE8 1|%s|%d|%s|%d|%d|%d", 
1012                     ChrPtr(er_name), 
1013                     er_num_type, 
1014                     ChrPtr(er_password), 
1015                     er_floor, 
1016                     0, 
1017                     er_view);
1018
1019         Line = NewStrBuf();
1020         StrBuf_ServGetln(Line);
1021         if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
1022                 putlbstr("success", 0);
1023                 FreeStrBuf(&Line);
1024                 if (template != NULL) {
1025                         output_headers(1, 0, 0, 0, 0, 0);       
1026                         DoTemplate(SKEY(template), NULL, &NoCtx);
1027                         end_burst();
1028                 }
1029                 else {
1030                         display_main_menu();
1031                 }
1032                 return;
1033         }
1034         /** TODO: Room created, now update the left hand icon bar for this user */
1035         gotoroom(er_name);
1036
1037         serv_printf("VIEW %d", er_view);
1038         StrBuf_ServGetln(Line);
1039         FreeStrBuf(&Line); /* TODO: should we care about errors? */
1040         WCC->CurRoom.view = er_view;
1041
1042         putlbstr("success", 1);
1043         if (template != NULL) {
1044                 output_headers(1, 0, 0, 0, 0, 0);       
1045                 DoTemplate(SKEY(template), NULL, &NoCtx);
1046                 end_burst();
1047         }
1048         else if ( (WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) {
1049                 output_headers(1, 1, 1, 0, 0, 0);       
1050                 do_template("room_edit");
1051                 wDumpContent(1);
1052         } else {
1053                 smart_goto(WCC->CurRoom.name);
1054         }
1055         FreeStrBuf(&Line);
1056 }
1057
1058
1059
1060
1061
1062 /*
1063  * Change the view for this room
1064  */
1065 void change_view(void) {
1066         int newview;
1067         char buf[SIZ];
1068
1069         newview = lbstr("view");
1070         serv_printf("VIEW %d", newview);
1071         serv_getln(buf, sizeof buf);
1072         WC->CurRoom.view = newview;
1073         smart_goto(WC->CurRoom.name);
1074 }
1075
1076
1077
1078 /*
1079  * Set the message expire policy for this room and/or floor
1080  */
1081 void set_room_policy(void) {
1082         StrBuf *Line;
1083
1084         if (!havebstr("ok_button")) {
1085                 AppendImportantMessage(_("Cancelled.  Changes were not saved."), -1);
1086                 output_headers(1, 1, 1, 0, 0, 0);       
1087                 do_template("room_edit");
1088                 wDumpContent(1);
1089                 return;
1090         }
1091
1092         Line = NewStrBuf();
1093
1094         serv_printf("SPEX room|%d|%d", ibstr("roompolicy"), ibstr("roomvalue"));
1095         StrBuf_ServGetln(Line);
1096         GetServerStatusMsg(Line, NULL, 1, 0);
1097         if (WC->axlevel >= 6) {
1098                 serv_printf("SPEX floor|%d|%d", ibstr("floorpolicy"), ibstr("floorvalue"));
1099                 StrBuf_ServGetln(Line);
1100                 GetServerStatusMsg(Line, NULL, 1, 0);
1101         }
1102         FreeStrBuf(&Line);
1103         ReloadCurrentRoom();
1104
1105         output_headers(1, 1, 1, 0, 0, 0);       
1106         do_template("room_edit");
1107         wDumpContent(1);
1108 }
1109
1110
1111
1112 /*
1113  * Perform changes to a room's network configuration
1114  */
1115 void netedit(void) {
1116         char buf[SIZ];
1117         char line[SIZ];
1118         char cmpa0[SIZ];
1119         char cmpa1[SIZ];
1120         char cmpb0[SIZ];
1121         char cmpb1[SIZ];
1122         int i, num_addrs;
1123         StrBuf *Line;
1124         StrBuf *TmpBuf;
1125         int malias = 0;
1126         int malias_set_default = 0;
1127         char sepchar = '|';
1128         int Done;
1129
1130         line[0] = '\0';
1131         if (havebstr("force_room")) {
1132                 gotoroom(sbstr("force_room"));
1133         }
1134         /*/ TODO: do line dynamic! */
1135         if (havebstr("line_pop3host")) {
1136                 strcpy(line, bstr("prefix"));
1137                 strcat(line, bstr("line_pop3host"));
1138                 strcat(line, "|");
1139                 strcat(line, bstr("line_pop3user"));
1140                 strcat(line, "|");
1141                 strcat(line, bstr("line_pop3pass"));
1142                 strcat(line, "|");
1143                 strcat(line, ibstr("line_pop3keep") ? "1" : "0" );
1144                 strcat(line, "|");
1145                 sprintf(&line[strlen(line)],"%ld", lbstr("line_pop3int"));
1146                 strcat(line, bstr("suffix"));
1147         }
1148         else if (havebstr("line")) {
1149                 strcpy(line, bstr("prefix"));
1150                 strcat(line, bstr("line"));
1151                 strcat(line, bstr("suffix"));
1152         }
1153         else if (havebstr("alias")) {
1154                 const char *domain;
1155                 domain = bstr("aliasdomain");
1156                 if ((domain == NULL) || IsEmptyStr(domain))
1157                 {
1158                         malias_set_default = 1;
1159                         strcpy(line, bstr("prefix"));
1160                         strcat(line, bstr("default_aliasdomain"));
1161                 }
1162                 else
1163                 {
1164                         malias = 1;
1165                         sepchar = ',';
1166                         strcat(line, bstr("prefix"));
1167                         if (!IsEmptyStr(domain))
1168                         {
1169                                 strcat(line, "@");
1170                                 strcat(line, domain);
1171                         }
1172                         strcat(line, ",");
1173                         strcat(line, "room_");
1174                         strcat(line, ChrPtr(WC->CurRoom.name));
1175                 }
1176         }
1177         else {
1178                 output_headers(1, 1, 1, 0, 0, 0);       
1179                 do_template("room_edit");
1180                 wDumpContent(1);
1181                 return;
1182         }
1183
1184         Line = NewStrBuf();
1185         TmpBuf = NewStrBuf();
1186         if (malias)
1187                 serv_puts("GNET "FILE_MAILALIAS);
1188         else
1189                 serv_puts("GNET");
1190         StrBuf_ServGetln(Line);
1191         if  (GetServerStatus(Line, NULL) != 1) {
1192                 AppendImportantMessage(SRV_STATUS_MSG(Line));   
1193                 FreeStrBuf(&Line);
1194                 output_headers(1, 1, 1, 0, 0, 0);       
1195                 do_template("room_edit");
1196                 wDumpContent(1);
1197                 return;
1198         }
1199
1200         /** This loop works for add *or* remove.  Spiffy, eh? */
1201         Done = 0;
1202         extract_token(cmpb0, line, 0, sepchar, sizeof cmpb0);
1203         extract_token(cmpb1, line, 1, sepchar, sizeof cmpb1);
1204         while (!Done && StrBuf_ServGetln(Line)>=0) {
1205                 if ( (StrLength(Line)==3) && 
1206                      !strcmp(ChrPtr(Line), "000")) 
1207                 {
1208                         Done = 1;
1209                 }
1210                 else
1211                 {
1212                         if (StrLength(Line) == 0)
1213                                 continue;
1214
1215                         if (malias_set_default)
1216                         {
1217                                 if (strncasecmp(ChrPtr(Line), HKEY("roommailalias|")) != 0)
1218                                 {
1219                                         StrBufAppendBufPlain(Line, HKEY("\n"), 0);
1220                                         StrBufAppendBuf(TmpBuf, Line, 0);
1221                                 }
1222                         }
1223                         else
1224                         {
1225                                 extract_token(cmpa0, ChrPtr(Line), 0, sepchar, sizeof cmpa0);
1226                                 extract_token(cmpa1, ChrPtr(Line), 1, sepchar, sizeof cmpa1);
1227                                 if ( (strcasecmp(cmpa0, cmpb0)) || (strcasecmp(cmpa1, cmpb1)) )
1228                                 {
1229                                         StrBufAppendBufPlain(Line, HKEY("\n"), 0);
1230                                         StrBufAppendBuf(TmpBuf, Line, 0);
1231                                 }
1232                         }
1233                 }
1234         }
1235
1236         if (malias)
1237                 serv_puts("SNET "FILE_MAILALIAS);
1238         else
1239                 serv_puts("SNET");
1240         StrBuf_ServGetln(Line);
1241         if  (GetServerStatus(Line, NULL) != 4) {
1242
1243                 AppendImportantMessage(SRV_STATUS_MSG(Line));   
1244                 output_headers(1, 1, 1, 0, 0, 0);       
1245                 do_template("room_edit");
1246                 wDumpContent(1);
1247                 FreeStrBuf(&Line);
1248                 FreeStrBuf(&TmpBuf);
1249                 return;
1250         }
1251
1252         serv_putbuf(TmpBuf);
1253         FreeStrBuf(&TmpBuf);
1254
1255         if (havebstr("add_button")) {
1256                 num_addrs = num_tokens(bstr("line"), ',');
1257                 if (num_addrs < 2) {
1258                         /* just adding one node or address */
1259                         serv_puts(line);
1260                 }
1261                 else {
1262                         /* adding multiple addresses separated by commas */
1263                         for (i=0; i<num_addrs; ++i) {
1264                                 strcpy(line, bstr("prefix"));
1265                                 extract_token(buf, bstr("line"), i, ',', sizeof buf);
1266                                 striplt(buf);
1267                                 strcat(line, buf);
1268                                 strcat(line, bstr("suffix"));
1269                                 serv_puts(line);
1270                         }
1271                 }
1272         }
1273
1274         serv_puts("000");
1275         serv_puts("NOOP");
1276         StrBuf_ServGetln(Line);
1277         if  (GetServerStatus(Line, NULL) != 2) { /* WHOOOPS? ERROR? */
1278                 AppendImportantMessage(SRV_STATUS_MSG(Line));   
1279                 StrBuf_ServGetln(Line); /* resync... */
1280         }
1281
1282
1283         FlushIgnetCfgs(&WC->CurRoom);
1284         FreeStrBuf(&Line);
1285
1286         output_headers(1, 1, 1, 0, 0, 0);       
1287         do_template("room_edit");
1288         wDumpContent(1);
1289 }
1290
1291 /*
1292  * Known rooms list (box style)
1293  */
1294 void knrooms(void)
1295 {
1296         DeleteHash(&WC->Rooms);
1297         output_headers(1, 1, 1, 0, 0, 0); 
1298         do_template("knrooms");
1299         wDumpContent(1);
1300 }
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319 /*******************************************************************************
1320  ********************** FLOOR Coomands *****************************************
1321  ******************************************************************************/
1322
1323
1324
1325 /*
1326  * delete the actual floor
1327  */
1328 void delete_floor(void) {
1329         int floornum;
1330         StrBuf *Buf;
1331         const char *Err;
1332                 
1333         floornum = ibstr("floornum");
1334         Buf = NewStrBuf();
1335         serv_printf("KFLR %d|1", floornum);
1336         
1337         StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
1338
1339         if (GetServerStatus(Buf, NULL) == 2) {
1340                 StrBufPlain(Buf, _("Floor has been deleted."),-1);
1341         }
1342         else {
1343                 StrBufCutLeft(Buf, 4);
1344         }
1345         AppendImportantMessage (SKEY(Buf));
1346
1347         FlushRoomlist();
1348         http_transmit_thing(ChrPtr(do_template("floors")), 0);
1349         FreeStrBuf(&Buf);
1350 }
1351
1352 /*
1353  * start creating a new floor
1354  */
1355 void create_floor(void) {
1356         StrBuf *Buf;
1357         const char *Err;
1358
1359         Buf = NewStrBuf();
1360         serv_printf("CFLR %s|1", bstr("floorname"));
1361         StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
1362
1363         if (GetServerStatus(Buf, NULL) == 2) {
1364                 StrBufPlain(Buf, _("New floor has been created."),-1);
1365         }
1366         else {
1367                 StrBufCutLeft(Buf, 4);
1368         }
1369         AppendImportantMessage (SKEY(Buf));
1370         FlushRoomlist();
1371         http_transmit_thing(ChrPtr(do_template("floors")), 0);
1372         FreeStrBuf(&Buf);
1373 }
1374
1375
1376 /*
1377  * rename this floor
1378  */
1379 void rename_floor(void) {
1380         StrBuf *Buf;
1381
1382         Buf = NewStrBuf();
1383         FlushRoomlist();
1384
1385         serv_printf("EFLR %d|%s", ibstr("floornum"), bstr("floorname"));
1386         StrBuf_ServGetln(Buf);
1387
1388         StrBufCutLeft(Buf, 4);
1389         AppendImportantMessage (SKEY(Buf));
1390
1391         http_transmit_thing(ChrPtr(do_template("floors")), 0);
1392         FreeStrBuf(&Buf);
1393 }
1394
1395
1396
1397 void jsonRoomFlr(void) 
1398 {
1399         /* Send as our own (application/json) content type */
1400         hprintf("HTTP/1.1 200 OK\r\n");
1401         hprintf("Content-type: application/json; charset=utf-8\r\n");
1402         hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1403         hprintf("Connection: close\r\n");
1404         hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1405         begin_burst();
1406         DoTemplate(HKEY("json_roomflr"),NULL,&NoCtx);
1407         end_burst(); 
1408 }
1409
1410 void _FlushRoomList(wcsession *WCC)
1411 {
1412         free_march_list(WCC);
1413         DeleteHash(&WCC->Floors);
1414         DeleteHash(&WCC->Rooms);
1415         DeleteHash(&WCC->FloorsByName);
1416         FlushFolder(&WCC->CurRoom);
1417 }
1418
1419 void ReloadCurrentRoom(void)
1420 {
1421         wcsession *WCC = WC;
1422         StrBuf *CurRoom;
1423
1424         CurRoom = WCC->CurRoom.name;
1425         WCC->CurRoom.name = NULL;
1426         _FlushRoomList(WCC);
1427         gotoroom(CurRoom);
1428         FreeStrBuf(&CurRoom);
1429 }
1430
1431 void FlushRoomlist(void)
1432 {
1433         wcsession *WCC = WC;
1434         _FlushRoomList(WCC);
1435 }
1436
1437
1438 void 
1439 InitModule_ROOMOPS
1440 (void)
1441 {
1442         RegisterPreference("roomlistview",
1443                            _("Room list view"),
1444                            PRF_STRING,
1445                            NULL);
1446         RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO, NULL);
1447
1448         WebcitAddUrlHandler(HKEY("json_roomflr"), "", 0, jsonRoomFlr, 0);
1449
1450         WebcitAddUrlHandler(HKEY("delete_floor"), "", 0, delete_floor, 0);
1451         WebcitAddUrlHandler(HKEY("rename_floor"), "", 0, rename_floor, 0);
1452         WebcitAddUrlHandler(HKEY("create_floor"), "", 0, create_floor, 0);
1453
1454         WebcitAddUrlHandler(HKEY("knrooms"), "", 0, knrooms, ANONYMOUS);
1455         WebcitAddUrlHandler(HKEY("dotgoto"), "", 0, dotgoto, NEED_URL);
1456         WebcitAddUrlHandler(HKEY("dotskip"), "", 0, dotskip, NEED_URL);
1457
1458         WebcitAddUrlHandler(HKEY("goto_private"), "", 0, goto_private, NEED_URL);
1459         WebcitAddUrlHandler(HKEY("zap"), "", 0, zap, 0);
1460         WebcitAddUrlHandler(HKEY("entroom"), "", 0, entroom, 0);
1461         WebcitAddUrlHandler(HKEY("do_invt_kick"), "", 0, do_invt_kick, 0);
1462         
1463         WebcitAddUrlHandler(HKEY("netedit"), "", 0, netedit, 0);
1464         WebcitAddUrlHandler(HKEY("editroom"), "", 0, editroom, 0);
1465         WebcitAddUrlHandler(HKEY("delete_room"), "", 0, delete_room, 0);
1466         WebcitAddUrlHandler(HKEY("set_room_policy"), "", 0, set_room_policy, 0);
1467         WebcitAddUrlHandler(HKEY("changeview"), "", 0, change_view, 0);
1468         WebcitAddUrlHandler(HKEY("toggle_self_service"), "", 0, toggle_self_service, 0);
1469
1470
1471         REGISTERTokenParamDefine(QR_PERMANENT);
1472         REGISTERTokenParamDefine(QR_INUSE);
1473         REGISTERTokenParamDefine(QR_PRIVATE);
1474         REGISTERTokenParamDefine(QR_PASSWORDED);
1475         REGISTERTokenParamDefine(QR_GUESSNAME);
1476         REGISTERTokenParamDefine(QR_DIRECTORY);
1477         REGISTERTokenParamDefine(QR_UPLOAD);
1478         REGISTERTokenParamDefine(QR_DOWNLOAD);
1479         REGISTERTokenParamDefine(QR_VISDIR);
1480         REGISTERTokenParamDefine(QR_ANONONLY);
1481         REGISTERTokenParamDefine(QR_ANONOPT);
1482         REGISTERTokenParamDefine(QR_NETWORK);
1483         REGISTERTokenParamDefine(QR_PREFONLY);
1484         REGISTERTokenParamDefine(QR_READONLY);
1485         REGISTERTokenParamDefine(QR_MAILBOX);
1486         REGISTERTokenParamDefine(QR2_SYSTEM);
1487         REGISTERTokenParamDefine(QR2_SELFLIST);
1488         REGISTERTokenParamDefine(QR2_COLLABDEL);
1489         REGISTERTokenParamDefine(QR2_SUBJECTREQ);
1490         REGISTERTokenParamDefine(QR2_SMTP_PUBLIC);
1491         REGISTERTokenParamDefine(QR2_MODERATED);
1492         REGISTERTokenParamDefine(QR2_NOUPLMSG);
1493
1494         REGISTERTokenParamDefine(UA_KNOWN);
1495         REGISTERTokenParamDefine(UA_GOTOALLOWED);
1496         REGISTERTokenParamDefine(UA_HASNEWMSGS);
1497         REGISTERTokenParamDefine(UA_ZAPPED);
1498         REGISTERTokenParamDefine(UA_POSTALLOWED);
1499         REGISTERTokenParamDefine(UA_ADMINALLOWED);
1500         REGISTERTokenParamDefine(UA_DELETEALLOWED);
1501         REGISTERTokenParamDefine(UA_REPLYALLOWED);
1502         REGISTERTokenParamDefine(UA_ISTRASH);
1503
1504         REGISTERTokenParamDefine(US_NEEDVALID);
1505         REGISTERTokenParamDefine(US_PERM);
1506         REGISTERTokenParamDefine(US_LASTOLD);
1507         REGISTERTokenParamDefine(US_EXPERT);
1508         REGISTERTokenParamDefine(US_UNLISTED);
1509         REGISTERTokenParamDefine(US_NOPROMPT);
1510         REGISTERTokenParamDefine(US_PROMPTCTL);
1511         REGISTERTokenParamDefine(US_DISAPPEAR);
1512         REGISTERTokenParamDefine(US_REGIS);
1513         REGISTERTokenParamDefine(US_PAGINATOR);
1514         REGISTERTokenParamDefine(US_INTERNET);
1515         REGISTERTokenParamDefine(US_FLOORS);
1516         REGISTERTokenParamDefine(US_COLOR);
1517         REGISTERTokenParamDefine(US_USER_SET);
1518
1519         REGISTERTokenParamDefine(VIEW_BBS);
1520         REGISTERTokenParamDefine(VIEW_MAILBOX); 
1521         REGISTERTokenParamDefine(VIEW_ADDRESSBOOK);
1522         REGISTERTokenParamDefine(VIEW_CALENDAR);        
1523         REGISTERTokenParamDefine(VIEW_TASKS);   
1524         REGISTERTokenParamDefine(VIEW_NOTES);           
1525         REGISTERTokenParamDefine(VIEW_WIKI);            
1526         REGISTERTokenParamDefine(VIEW_CALBRIEF);
1527         REGISTERTokenParamDefine(VIEW_JOURNAL);
1528         REGISTERTokenParamDefine(VIEW_BLOG);
1529         REGISTERTokenParamDefine(VIEW_QUEUE);
1530         REGISTERTokenParamDefine(VIEW_WIKIMD);          
1531
1532         /* GNET types: */
1533         /* server internal, we need to know but ignore them. */
1534         REGISTERTokenParamDefine(subpending);
1535         REGISTERTokenParamDefine(unsubpending);
1536         REGISTERTokenParamDefine(lastsent);
1537
1538         REGISTERTokenParamDefine(ignet_push_share);
1539         { /* these are the parts of an IGNET push config */
1540                 REGISTERTokenParamDefine(GNET_IGNET_NODE);
1541                 REGISTERTokenParamDefine(GNET_IGNET_ROOM);
1542         }
1543         REGISTERTokenParamDefine(listrecp);
1544         REGISTERTokenParamDefine(digestrecp);
1545         REGISTERTokenParamDefine(pop3client);
1546         { /* These are the parts of a pop3 client line... */
1547                 REGISTERTokenParamDefine(GNET_POP3_HOST);
1548                 REGISTERTokenParamDefine(GNET_POP3_USER);
1549                 REGISTERTokenParamDefine(GNET_POP3_DONT_DELETE_REMOTE);
1550                 REGISTERTokenParamDefine(GNET_POP3_INTERVAL);
1551         }
1552         REGISTERTokenParamDefine(rssclient);
1553         REGISTERTokenParamDefine(participate);
1554         REGISTERTokenParamDefine(roommailalias);
1555
1556
1557
1558 }
1559
1560
1561 void 
1562 SessionDestroyModule_ROOMOPS
1563 (wcsession *sess)
1564 {
1565         _FlushRoomList (sess);
1566 }
1567