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