don't issue slrp_highest if we're viewing users mailboxes.
[citadel.git] / webcit / roomops.c
1 /*
2  * Lots of different room-related operations.
3  *
4  * Copyright (c) 1996-2012 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         
594         if (WCC->CurRoom.XHaveRoomPicLoaded)
595                 return;
596
597         WCC->CurRoom.XHaveRoomPicLoaded = 1;
598         Buf = NewStrBuf();
599         serv_puts("OIMG _roompic_");
600         StrBuf_ServGetln(Buf);
601         if (GetServerStatus(Buf, NULL) != 2) {
602                 WCC->CurRoom.XHaveRoomPic = 0;
603         } else {
604                 WCC->CurRoom.XHaveRoomPic = 1;
605         }
606         serv_puts("CLOS");
607         StrBuf_ServGetln(Buf);
608         GetServerStatus(Buf, NULL);
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