]> code.citadel.org Git - citadel.git/blob - webcit/roomops.c
* Finished "folder list" mode (still need to move it to a permanent location)
[citadel.git] / webcit / roomops.c
1 /* $Id$ */
2
3
4 #include <ctype.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <signal.h>
10 #include <sys/types.h>
11 #include <sys/wait.h>
12 #include <sys/socket.h>
13 #include <sys/time.h>
14 #include <limits.h>
15 #include <netinet/in.h>
16 #include <netdb.h>
17 #include <string.h>
18 #include <pwd.h>
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <pthread.h>
22 #include <signal.h>
23 #include "webcit.h"
24
25
26 char *viewdefs[] = {
27         "Messages",
28         "Summary",
29         "Address Book"
30 };
31
32 char floorlist[128][SIZ];
33
34 /*
35  * load the list of floors
36  */
37 void load_floorlist(void)
38 {
39         int a;
40         char buf[SIZ];
41
42         for (a = 0; a < 128; ++a)
43                 floorlist[a][0] = 0;
44
45         serv_puts("LFLR");
46         serv_gets(buf);
47         if (buf[0] != '1') {
48                 strcpy(floorlist[0], "Main Floor");
49                 return;
50         }
51         while (serv_gets(buf), strcmp(buf, "000")) {
52                 extract(floorlist[extract_int(buf, 0)], buf, 1);
53         }
54 }
55
56
57 /*
58  * remove a room from the march list
59  */
60 void remove_march(char *aaa)
61 {
62         struct march *mptr, *mptr2;
63
64         if (WC->march == NULL)
65                 return;
66
67         if (!strcasecmp(WC->march->march_name, aaa)) {
68                 mptr = WC->march->next;
69                 free(WC->march);
70                 WC->march = mptr;
71                 return;
72         }
73         mptr2 = WC->march;
74         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
75                 if (!strcasecmp(mptr->march_name, aaa)) {
76                         mptr2->next = mptr->next;
77                         free(mptr);
78                         mptr = mptr2;
79                 } else {
80                         mptr2 = mptr;
81                 }
82         }
83 }
84
85
86
87
88
89 void room_tree_list(struct roomlisting *rp)
90 {
91         char rmname[64];
92         int f;
93
94         if (rp == NULL)
95                 return;
96
97         if (rp->lnext != NULL) {
98                 room_tree_list(rp->lnext);
99         }
100         strcpy(rmname, rp->rlname);
101         f = rp->rlflags;
102
103         wprintf("<A HREF=\"/dotgoto&room=");
104         urlescputs(rmname);
105         wprintf("\"");
106         wprintf(">");
107         escputs1(rmname, 1);
108         if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
109                 wprintf("}");
110         else if (f & QR_DIRECTORY)
111                 wprintf("]");
112         else if (f & QR_NETWORK)
113                 wprintf(")");
114         else
115                 wprintf("&gt;");
116         wprintf("</A><TT> </TT>\n");
117
118         if (rp->rnext != NULL) {
119                 room_tree_list(rp->rnext);
120         }
121         free(rp);
122 }
123
124
125 /* 
126  * Room ordering stuff (compare first by floor, then by order)
127  */
128 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
129 {
130         if ((r1 == NULL) && (r2 == NULL))
131                 return (0);
132         if (r1 == NULL)
133                 return (-1);
134         if (r2 == NULL)
135                 return (1);
136         if (r1->rlfloor < r2->rlfloor)
137                 return (-1);
138         if (r1->rlfloor > r2->rlfloor)
139                 return (1);
140         if (r1->rlorder < r2->rlorder)
141                 return (-1);
142         if (r1->rlorder > r2->rlorder)
143                 return (1);
144         return (0);
145 }
146
147
148 /*
149  * Common code for all room listings
150  */
151 void listrms(char *variety)
152 {
153         char buf[SIZ];
154         int num_rooms = 0;
155
156         struct roomlisting *rl = NULL;
157         struct roomlisting *rp;
158         struct roomlisting *rs;
159
160
161         /* Ask the server for a room list */
162         serv_puts(variety);
163         serv_gets(buf);
164         if (buf[0] != '1') {
165                 wprintf("&nbsp;");
166                 return;
167         }
168         while (serv_gets(buf), strcmp(buf, "000")) {
169                 ++num_rooms;
170                 rp = malloc(sizeof(struct roomlisting));
171                 extract(rp->rlname, buf, 0);
172                 rp->rlflags = extract_int(buf, 1);
173                 rp->rlfloor = extract_int(buf, 2);
174                 rp->rlorder = extract_int(buf, 3);
175                 rp->lnext = NULL;
176                 rp->rnext = NULL;
177
178                 rs = rl;
179                 if (rl == NULL) {
180                         rl = rp;
181                 } else
182                         while (rp != NULL) {
183                                 if (rordercmp(rp, rs) < 0) {
184                                         if (rs->lnext == NULL) {
185                                                 rs->lnext = rp;
186                                                 rp = NULL;
187                                         } else {
188                                                 rs = rs->lnext;
189                                         }
190                                 } else {
191                                         if (rs->rnext == NULL) {
192                                                 rs->rnext = rp;
193                                                 rp = NULL;
194                                         } else {
195                                                 rs = rs->rnext;
196                                         }
197                                 }
198                         }
199         }
200
201         room_tree_list(rl);
202
203         /* If no rooms were listed, print an nbsp to make the cell
204          * borders show up anyway.
205          */
206         if (num_rooms == 0) wprintf("&nbsp;");
207 }
208
209
210
211
212
213
214
215
216
217 /*
218  * list all rooms by floor
219  */
220 void list_all_rooms_by_floor(void)
221 {
222         int a;
223         char buf[SIZ];
224
225         load_floorlist();
226
227         output_headers(1);
228
229         wprintf("<TABLE width=100%% border><TR><TH>Floor</TH>");
230         wprintf("<TH>Rooms with new messages</TH>");
231         wprintf("<TH>Rooms with no new messages</TH></TR>\n");
232
233         for (a = 0; a < 128; ++a)
234                 if (floorlist[a][0] != 0) {
235
236                         /* Floor name column */
237                         wprintf("<TR><TD>");
238
239                         serv_printf("OIMG _floorpic_|%d", a);
240                         serv_gets(buf);
241                         if (buf[0] == '2') {
242                                 serv_puts("CLOS");
243                                 serv_gets(buf);
244                                 wprintf("<IMG SRC=\"/image&name=_floorpic_&parm=%d\" ALT=\"%s\">",
245                                         a, &floorlist[a][0]);
246                         } else {
247                                 escputs(&floorlist[a][0]);
248                         }
249
250                         wprintf("</TD>");
251
252                         /* Rooms with new messages column */
253                         wprintf("<TD>");
254                         sprintf(buf, "LKRN %d", a);
255                         listrms(buf);
256                         wprintf("</TD>\n<TD>");
257
258                         /* Rooms with old messages column */
259                         sprintf(buf, "LKRO %d", a);
260                         listrms(buf);
261                         wprintf("</TD></TR>\n");
262                 }
263         wprintf("</TABLE>\n");
264         wDumpContent(1);
265 }
266
267
268 /*
269  * list all forgotten rooms
270  */
271 void zapped_list(void)
272 {
273         output_headers(1);
274         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
275         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
276         wprintf("<B>Zapped (forgotten) rooms</B>\n");
277         wprintf("</TD></TR></TABLE><BR>\n");
278         listrms("LZRM -1");
279         wprintf("<BR><BR>\n");
280         wprintf("Click on any room to un-zap it and goto that room.\n");
281         wDumpContent(1);
282 }
283
284
285 /*
286  * read this room's info file (set v to 1 for verbose mode)
287  */
288 void readinfo(void)
289 {
290         char buf[SIZ];
291
292         serv_puts("RINF");
293         serv_gets(buf);
294         if (buf[0] == '1') {
295                 wprintf("<FONT SIZE=-1>");
296                 fmout(NULL);
297                 wprintf("</FONT>");
298         }
299 }
300
301
302
303
304 /* Display room graphic.  The server doesn't actually
305  * need the room name, but we supply it in order to
306  * keep the browser from using a cached graphic from 
307  * another room.
308  */
309 void embed_room_graphic(void) {
310         char buf[SIZ];
311
312         serv_puts("OIMG _roompic_");
313         serv_gets(buf);
314         if (buf[0] == '2') {
315                 wprintf("<TD>");
316                 wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
317                 urlescputs(WC->wc_roomname);
318                 wprintf("\"></TD>");
319                 serv_puts("CLOS");
320                 serv_gets(buf);
321         }
322
323 }
324
325
326 /* Let the user know if new mail has arrived 
327  */
328 void embed_newmail_button(void) {
329         if ( (WC->new_mail > WC->remember_new_mail) && (WC->new_mail>0) ) {
330                 wprintf("<TD VALIGN=TOP>"
331                         "<A HREF=\"/dotgoto?room=_MAIL_\">"
332                         "<IMG SRC=\"/static/mail.gif\" border=0 "
333                         "ALT=\"You have new mail\">"
334                         "<BR><BLINK>%d</BLINK>", WC->new_mail);
335                 wprintf("<FONT SIZE=-2> new mail messages</FONT></A></TD>");
336                 WC->remember_new_mail = WC->new_mail;
337         }
338 }
339
340
341
342 /*
343  * Display the current view and offer an option to change it
344  */
345 void embed_view_o_matic(void) {
346         int i;
347
348         wprintf("<FORM NAME=\"viewomatic\">\n"
349                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
350                 "OnChange=\"location.href=viewomatic.newview.options"
351                 "[selectedIndex].value\">\n");
352
353         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
354                 wprintf("<OPTION %s VALUE=\"/changeview?view=%d\">",
355                         ((i == WC->wc_view) ? "SELECTED" : ""),
356                         i );
357                 escputs(viewdefs[i]);
358                 wprintf("</OPTION>\n");
359         }
360         wprintf("</SELECT></FORM>\n");
361 }
362
363
364
365 void embed_room_banner(char *got) {
366         char fakegot[SIZ];
367
368         /* We need to have the information returned by a GOTO server command.
369          * If it isn't supplied, we fake it by issuing our own GOTO.
370          */
371         if (got == NULL) {
372                 serv_printf("GOTO %s", WC->wc_roomname);
373                 serv_gets(fakegot);
374                 got = fakegot;
375         }
376
377         /* Check for new mail. */
378         WC->new_mail = extract_int(&got[4], 9);
379         WC->wc_view = extract_int(&got[4], 11);
380
381         svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
382         svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
383         svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
384         svcallback("ROOMPIC", embed_room_graphic);
385         svcallback("ROOMINFO", readinfo);
386         svcallback("YOUHAVEMAIL", embed_newmail_button);
387         svcallback("VIEWOMATIC", embed_view_o_matic);
388
389         do_template("roombanner.html");
390         clear_local_substs();
391 }
392
393
394
395
396
397 /*
398  * generic routine to take the session to a new room
399  *
400  * display_name values:  0 = goto only
401  *                       1 = goto and display
402  *                       2 = display only
403  */
404 void gotoroom(char *gname, int display_name)
405 {
406         char buf[SIZ];
407         static long ls = (-1L);
408
409
410         if (display_name) {
411                 output_headers(0);
412                 wprintf("Pragma: no-cache\n");
413                 wprintf("Cache-Control: no-store\n");
414
415                 wprintf("<HTML><HEAD>\n"
416                         "<META HTTP-EQUIV=\"refresh\" CONTENT=\"500363689;\">\n"
417                         "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
418                         "<META HTTP-EQUIV=\"expired\" CONTENT=\"28-May-1971 18:10:00 GMT\">\n"
419                         "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\">\n"
420                         "</HEAD>\n");
421                 do_template("background.html");
422         }
423         if (display_name != 2) {
424                 /* store ungoto information */
425                 strcpy(WC->ugname, WC->wc_roomname);
426                 WC->uglsn = ls;
427         }
428         /* move to the new room */
429         serv_printf("GOTO %s", gname);
430         serv_gets(buf);
431         if (buf[0] != '2') {
432                 serv_puts("GOTO _BASEROOM_");
433                 serv_gets(buf);
434         }
435         if (buf[0] != '2') {
436                 if (display_name) {
437                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
438                         wDumpContent(1);
439                 }
440                 return;
441         }
442         extract(WC->wc_roomname, &buf[4], 0);
443         WC->room_flags = extract_int(&buf[4], 4);
444         /* highest_msg_read = extract_int(&buf[4],6);
445            maxmsgnum = extract_int(&buf[4],5);
446            is_mail = (char) extract_int(&buf[4],7); */
447         ls = extract_long(&buf[4], 6);
448
449         if (WC->is_aide)
450                 WC->is_room_aide = WC->is_aide;
451         else
452                 WC->is_room_aide = (char) extract_int(&buf[4], 8);
453
454         remove_march(WC->wc_roomname);
455         if (!strcasecmp(gname, "_BASEROOM_"))
456                 remove_march(gname);
457
458         /* Display the room banner */
459         if (display_name) {
460                 embed_room_banner(buf);
461                 wDumpContent(1);
462         }
463         strcpy(WC->wc_roomname, WC->wc_roomname);
464         WC->wc_view = extract_int(&buf[4], 11);
465 }
466
467
468 /*
469  * Locate the room on the march list which we most want to go to.  Each room
470  * is measured given a "weight" of preference based on various factors.
471  */
472 char *pop_march(int desired_floor)
473 {
474         static char TheRoom[64];
475         int TheFloor = 0;
476         int TheOrder = 32767;
477         int TheWeight = 0;
478         int weight;
479         struct march *mptr = NULL;
480
481         strcpy(TheRoom, "_BASEROOM_");
482         if (WC->march == NULL)
483                 return (TheRoom);
484
485         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
486                 weight = 0;
487                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
488                         weight = weight + 10000;
489                 if (mptr->march_floor == desired_floor)
490                         weight = weight + 5000;
491
492                 weight = weight + ((128 - (mptr->march_floor)) * 128);
493                 weight = weight + (128 - (mptr->march_order));
494
495                 if (weight > TheWeight) {
496                         TheWeight = weight;
497                         strcpy(TheRoom, mptr->march_name);
498                         TheFloor = mptr->march_floor;
499                         TheOrder = mptr->march_order;
500                 }
501         }
502         return (TheRoom);
503 }
504
505
506
507 /* Goto next room having unread messages.
508  * We want to skip over rooms that the user has already been to, and take the
509  * user back to the lobby when done.  The room we end up in is placed in
510  * newroom - which is set to 0 (the lobby) initially.
511  * We start the search in the current room rather than the beginning to prevent
512  * two or more concurrent users from dragging each other back to the same room.
513  */
514 void gotonext(void)
515 {
516         char buf[SIZ];
517         struct march *mptr, *mptr2;
518         char next_room[32];
519
520         /* First check to see if the march-mode list is already allocated.
521          * If it is, pop the first room off the list and go there.
522          */
523
524         if (WC->march == NULL) {
525                 serv_puts("LKRN");
526                 serv_gets(buf);
527                 if (buf[0] == '1')
528                         while (serv_gets(buf), strcmp(buf, "000")) {
529                                 mptr = (struct march *) malloc(sizeof(struct march));
530                                 mptr->next = NULL;
531                                 extract(mptr->march_name, buf, 0);
532                                 mptr->march_floor = extract_int(buf, 2);
533                                 mptr->march_order = extract_int(buf, 3);
534                                 if (WC->march == NULL) {
535                                         WC->march = mptr;
536                                 } else {
537                                         mptr2 = WC->march;
538                                         while (mptr2->next != NULL)
539                                                 mptr2 = mptr2->next;
540                                         mptr2->next = mptr;
541                                 }
542                         }
543 /* add _BASEROOM_ to the end of the march list, so the user will end up
544  * in the system base room (usually the Lobby>) at the end of the loop
545  */
546                 mptr = (struct march *) malloc(sizeof(struct march));
547                 mptr->next = NULL;
548                 strcpy(mptr->march_name, "_BASEROOM_");
549                 if (WC->march == NULL) {
550                         WC->march = mptr;
551                 } else {
552                         mptr2 = WC->march;
553                         while (mptr2->next != NULL)
554                                 mptr2 = mptr2->next;
555                         mptr2->next = mptr;
556                 }
557 /*
558  * ...and remove the room we're currently in, so a <G>oto doesn't make us
559  * walk around in circles
560  */
561                 remove_march(WC->wc_roomname);
562         }
563         if (WC->march != NULL) {
564                 strcpy(next_room, pop_march(-1));
565         } else {
566                 strcpy(next_room, "_BASEROOM_");
567         }
568
569
570         smart_goto(next_room);
571 }
572
573
574 void smart_goto(char *next_room) {
575         gotoroom(next_room, 0);
576         readloop("readnew");
577 }
578
579
580
581 /*
582  * mark all messages in current room as having been read
583  */
584 void slrp_highest(void)
585 {
586         char buf[SIZ];
587
588         /* set pointer */
589         serv_puts("SLRP HIGHEST");
590         serv_gets(buf);
591         if (buf[0] != '2') {
592                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
593                 return;
594         }
595 }
596
597
598 /*
599  * un-goto the previous room
600  */
601 void ungoto(void)
602 {
603         char buf[SIZ];
604
605         if (!strcmp(WC->ugname, "")) {
606                 smart_goto(WC->wc_roomname);
607                 return;
608         }
609         serv_printf("GOTO %s", WC->ugname);
610         serv_gets(buf);
611         if (buf[0] != '2') {
612                 smart_goto(WC->wc_roomname);
613                 return;
614         }
615         if (WC->uglsn >= 0L) {
616                 serv_printf("SLRP %ld", WC->uglsn);
617                 serv_gets(buf);
618         }
619         strcpy(buf, WC->ugname);
620         strcpy(WC->ugname, "");
621         smart_goto(buf);
622 }
623
624 /*
625  * display the form for editing a room
626  */
627 void display_editroom(void)
628 {
629         char buf[SIZ];
630         char cmd[SIZ];
631         char node[SIZ];
632         char recp[SIZ];
633         char er_name[20];
634         char er_password[10];
635         char er_dirname[15];
636         char er_roomaide[26];
637         unsigned er_flags;
638         int er_floor;
639         int i, j;
640         char *tab;
641         char *shared_with;
642         char *not_shared_with;
643
644         tab = bstr("tab");
645         if (strlen(tab) == 0) tab = "admin";
646
647         serv_puts("GETR");
648         serv_gets(buf);
649
650         if (buf[0] != '2') {
651                 display_error(&buf[4]);
652                 return;
653         }
654         extract(er_name, &buf[4], 0);
655         extract(er_password, &buf[4], 1);
656         extract(er_dirname, &buf[4], 2);
657         er_flags = extract_int(&buf[4], 3);
658         er_floor = extract_int(&buf[4], 4);
659
660         output_headers(1);
661
662         /* print the tabbed dialog */
663         wprintf("<TABLE border=0 width=100%%><TR BGCOLOR=FFFFFF><TD> </TD>");
664
665         if (!strcmp(tab, "admin")) {
666                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
667         }
668         else {
669                 wprintf("<TD><A HREF=\"/display_editroom&tab=admin\">");
670         }
671         wprintf("Room administration");
672         if (!strcmp(tab, "admin")) {
673                 wprintf("</B></FONT></TD>\n");
674         }
675         else {
676                 wprintf("</A></TD>\n");
677         }
678
679         wprintf("<TD> </TD>\n");
680
681         if (!strcmp(tab, "config")) {
682                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
683         }
684         else {
685                 wprintf("<TD><A HREF=\"/display_editroom&tab=config\">");
686         }
687         wprintf("Room configuration");
688         if (!strcmp(tab, "config")) {
689                 wprintf("</B></FONT></TD>\n");
690         }
691         else {
692                 wprintf("</A></TD>\n");
693         }
694
695         wprintf("<TD> </TD>\n");
696
697         if (!strcmp(tab, "sharing")) {
698                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
699         }
700         else {
701                 wprintf("<TD><A HREF=\"/display_editroom&tab=sharing\">");
702         }
703         wprintf("Sharing");
704         if (!strcmp(tab, "sharing")) {
705                 wprintf("</B></FONT></TD>\n");
706         }
707         else {
708                 wprintf("</A></TD>\n");
709         }
710
711         wprintf("<TD> </TD>\n");
712
713         if (!strcmp(tab, "listserv")) {
714                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
715         }
716         else {
717                 wprintf("<TD><A HREF=\"/display_editroom&tab=listserv\">");
718         }
719         wprintf("Mailing list service");
720         if (!strcmp(tab, "listserv")) {
721                 wprintf("</B></FONT></TD>\n");
722         }
723         else {
724                 wprintf("</A></TD>\n");
725         }
726
727         wprintf("<TD> </TD></TR></TABLE>\n");
728
729         /* end tabbed dialog */ 
730
731
732         if (!strcmp(tab, "admin")) {
733                 wprintf("<UL>"
734                         "<LI><A HREF=\"/confirm_delete_room\">\n"
735                         "Delete this room</A>\n"
736                         "<LI><A HREF=\"/display_editroompic\">\n"
737                         "Set or change the graphic for this room's banner</A>\n"
738                         "<LI><A HREF=\"/display_editinfo\">\n"
739                         "Edit this room's Info file</A>\n"
740                         "</UL>");
741         }
742
743         if (!strcmp(tab, "config")) {
744                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
745         
746                 wprintf("<UL><LI>Name of room: ");
747                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
748         
749                 wprintf("<LI>Resides on floor: ");
750                 load_floorlist();
751                 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
752                 for (i = 0; i < 128; ++i)
753                         if (strlen(floorlist[i]) > 0) {
754                                 wprintf("<OPTION ");
755                                 if (i == er_floor)
756                                         wprintf("SELECTED ");
757                                 wprintf("VALUE=\"%d\">", i);
758                                 escputs(floorlist[i]);
759                                 wprintf("</OPTION>\n");
760                         }
761                 wprintf("</SELECT>\n");
762         
763                 wprintf("<LI>Type of room:<UL>\n");
764
765                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
766                 if ((er_flags & QR_PRIVATE) == 0)
767                 wprintf("CHECKED ");
768                 wprintf("> Public room\n");
769
770                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
771                 if ((er_flags & QR_PRIVATE) &&
772                     (er_flags & QR_GUESSNAME))
773                         wprintf("CHECKED ");
774                 wprintf("> Private - guess name\n");
775         
776                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
777                 if ((er_flags & QR_PRIVATE) &&
778                     (er_flags & QR_PASSWORDED))
779                         wprintf("CHECKED ");
780                 wprintf("> Private - require password:\n");
781                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
782         
783                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
784                 if ((er_flags & QR_PRIVATE)
785                     && ((er_flags & QR_GUESSNAME) == 0)
786                     && ((er_flags & QR_PASSWORDED) == 0))
787                         wprintf("CHECKED ");
788                 wprintf("> Private - invitation only\n");
789         
790                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
791                 wprintf("> If private, cause current users to forget room\n");
792         
793                 wprintf("</UL>\n");
794         
795                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
796                 if (er_flags & QR_PREFONLY)
797                         wprintf("CHECKED ");
798                 wprintf("> Preferred users only\n");
799         
800                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
801                 if (er_flags & QR_READONLY)
802                         wprintf("CHECKED ");
803                 wprintf("> Read-only room\n");
804         
805         /* directory stuff */
806                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
807                 if (er_flags & QR_DIRECTORY)
808                         wprintf("CHECKED ");
809                 wprintf("> File directory room\n");
810
811                 wprintf("<UL><LI>Directory name: ");
812                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
813
814                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
815                 if (er_flags & QR_UPLOAD)
816                         wprintf("CHECKED ");
817                 wprintf("> Uploading allowed\n");
818         
819                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
820                 if (er_flags & QR_DOWNLOAD)
821                         wprintf("CHECKED ");
822                 wprintf("> Downloading allowed\n");
823         
824                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
825                 if (er_flags & QR_VISDIR)
826                         wprintf("CHECKED ");
827                 wprintf("> Visible directory</UL>\n");
828         
829         /* end of directory stuff */
830         
831                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
832                 if (er_flags & QR_NETWORK)
833                         wprintf("CHECKED ");
834                 wprintf("> Network shared room\n");
835
836         /* start of anon options */
837         
838                 wprintf("<LI>Anonymous messages<UL>\n");
839         
840                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
841                 if (((er_flags & QR_ANONONLY) == 0)
842                     && ((er_flags & QR_ANONOPT) == 0))
843                         wprintf("CHECKED ");
844                 wprintf("> No anonymous messages\n");
845         
846                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
847                 if (er_flags & QR_ANONONLY)
848                         wprintf("CHECKED ");
849                 wprintf("> All messages are anonymous\n");
850         
851                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
852                 if (er_flags & QR_ANONOPT)
853                         wprintf("CHECKED ");
854                 wprintf("> Prompt user when entering messages</UL>\n");
855         
856         /* end of anon options */
857         
858                 wprintf("<LI>Room aide: \n");
859                 serv_puts("GETA");
860                 serv_gets(buf);
861                 if (buf[0] != '2') {
862                         wprintf("<EM>%s</EM>\n", &buf[4]);
863                 } else {
864                         extract(er_roomaide, &buf[4], 0);
865                         wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
866                 }
867         
868                 wprintf("</UL><CENTER>\n");
869                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
870                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
871                 wprintf("</CENTER>\n");
872         }
873
874
875         /* Sharing the room with other Citadel nodes... */
876         if (!strcmp(tab, "sharing")) {
877
878                 shared_with = strdup("");
879                 not_shared_with = strdup("");
880
881                 /* Learn the current configuration */
882                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
883                 serv_gets(buf);
884                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
885                         extract(node, buf, 0);
886                         not_shared_with = realloc(not_shared_with,
887                                         strlen(not_shared_with) + 32);
888                         strcat(not_shared_with, node);
889                         strcat(not_shared_with, "|");
890                 }
891
892                 serv_puts("GNET");
893                 serv_gets(buf);
894                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
895                         extract(cmd, buf, 0);
896                         extract(node, buf, 1);
897                         if (!strcasecmp(cmd, "ignet_push_share")) {
898                                 shared_with = realloc(shared_with,
899                                                 strlen(shared_with) + 32);
900                                 strcat(shared_with, node);
901                                 strcat(shared_with, "|");
902                         }
903                 }
904
905                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
906                         extract(node, shared_with, i);
907                         for (j=0; j<num_tokens(not_shared_with, '|'); ++j) {
908                                 extract(cmd, not_shared_with, j);
909                                 if (!strcasecmp(node, cmd)) {
910                                         remove_token(not_shared_with, j, '|');
911                                 }
912                         }
913                 }
914
915                 /* Display the stuff */
916                 wprintf("<CENTER><BR>"
917                         "<TABLE border=1 cellpadding=5><TR>"
918                         "<TD><B><I>Shared with</I></B></TD>"
919                         "<TD><B><I>Not shared with</I></B></TD></TR>\n"
920                         "<TR><TD>\n");
921
922                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
923                         extract(node, shared_with, i);
924                         if (strlen(node) > 0) {
925                                 wprintf("%s ", node);
926                                 wprintf("<A HREF=\"/netedit&cmd=remove&line="
927                                         "ignet_push_share|");
928                                 urlescputs(node);
929                                 wprintf("&tab=sharing\">(unshare)</A><BR>");
930                         }
931                 }
932
933                 wprintf("</TD><TD>\n");
934
935                 for (i=0; i<num_tokens(not_shared_with, '|'); ++i) {
936                         extract(node, not_shared_with, i);
937                         if (strlen(node) > 0) {
938                                 wprintf("%s ", node);
939                                 wprintf("<A HREF=\"/netedit&cmd=add&line="
940                                         "ignet_push_share|");
941                                 urlescputs(node);
942                                 wprintf("&tab=sharing\">(share)</A><BR>");
943                         }
944                 }
945
946                 wprintf("</TD></TR></TABLE><BR>\n"
947                         "<I><B>Reminder:</B> When sharing a room, "
948                         "it must be shared from both ends.  Adding a node to "
949                         "the 'shared' list sends messages out, but in order to"
950                         " receive messages, the other nodes must be configured"
951                         " to send messages out to your system as well.</I><BR>"
952                         "</CENTER>\n");
953
954         }
955
956         /* Mailing list management */
957         if (!strcmp(tab, "listserv")) {
958
959                 wprintf("<BR><center><i>The contents of this room are being "
960                         "mailed to the following list recipients:"
961                         "</i><br><br>\n");
962
963                 serv_puts("GNET");
964                 serv_gets(buf);
965                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
966                         extract(cmd, buf, 0);
967                         if (!strcasecmp(cmd, "listrecp")) {
968                                 extract(recp, buf, 1);
969                         
970                                 escputs(recp);
971                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
972                                         "listrecp|");
973                                 urlescputs(recp);
974                                 wprintf("&tab=listserv\">(remove)</A><BR>");
975
976                         }
977                 }
978                 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
979                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
980                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
981                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
982                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
983                 wprintf("</FORM><BR></CENTER>\n");
984         }
985
986         wDumpContent(1);
987 }
988
989
990 /*
991  * save new parameters for a room
992  */
993 void editroom(void)
994 {
995         char buf[SIZ];
996         char er_name[20];
997         char er_password[10];
998         char er_dirname[15];
999         char er_roomaide[26];
1000         int er_floor;
1001         unsigned er_flags;
1002         int bump;
1003
1004
1005         if (strcmp(bstr("sc"), "OK")) {
1006                 display_error("Cancelled.  Changes were not saved.");
1007                 return;
1008         }
1009         serv_puts("GETR");
1010         serv_gets(buf);
1011
1012         if (buf[0] != '2') {
1013                 display_error(&buf[4]);
1014                 return;
1015         }
1016         extract(er_name, &buf[4], 0);
1017         extract(er_password, &buf[4], 1);
1018         extract(er_dirname, &buf[4], 2);
1019         er_flags = extract_int(&buf[4], 3);
1020
1021         strcpy(er_roomaide, bstr("er_roomaide"));
1022         if (strlen(er_roomaide) == 0) {
1023                 serv_puts("GETA");
1024                 serv_gets(buf);
1025                 if (buf[0] != '2') {
1026                         strcpy(er_roomaide, "");
1027                 } else {
1028                         extract(er_roomaide, &buf[4], 0);
1029                 }
1030         }
1031         strcpy(buf, bstr("er_name"));
1032         buf[20] = 0;
1033         if (strlen(buf) > 0)
1034                 strcpy(er_name, buf);
1035
1036         strcpy(buf, bstr("er_password"));
1037         buf[10] = 0;
1038         if (strlen(buf) > 0)
1039                 strcpy(er_password, buf);
1040
1041         strcpy(buf, bstr("er_dirname"));
1042         buf[15] = 0;
1043         if (strlen(buf) > 0)
1044                 strcpy(er_dirname, buf);
1045
1046         strcpy(buf, bstr("type"));
1047         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1048
1049         if (!strcmp(buf, "invonly")) {
1050                 er_flags |= (QR_PRIVATE);
1051         }
1052         if (!strcmp(buf, "guessname")) {
1053                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1054         }
1055         if (!strcmp(buf, "passworded")) {
1056                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1057         }
1058         if (!strcmp(bstr("prefonly"), "yes")) {
1059                 er_flags |= QR_PREFONLY;
1060         } else {
1061                 er_flags &= ~QR_PREFONLY;
1062         }
1063
1064         if (!strcmp(bstr("readonly"), "yes")) {
1065                 er_flags |= QR_READONLY;
1066         } else {
1067                 er_flags &= ~QR_READONLY;
1068         }
1069
1070         if (!strcmp(bstr("network"), "yes")) {
1071                 er_flags |= QR_NETWORK;
1072         } else {
1073                 er_flags &= ~QR_NETWORK;
1074         }
1075
1076         if (!strcmp(bstr("directory"), "yes")) {
1077                 er_flags |= QR_DIRECTORY;
1078         } else {
1079                 er_flags &= ~QR_DIRECTORY;
1080         }
1081
1082         if (!strcmp(bstr("ulallowed"), "yes")) {
1083                 er_flags |= QR_UPLOAD;
1084         } else {
1085                 er_flags &= ~QR_UPLOAD;
1086         }
1087
1088         if (!strcmp(bstr("dlallowed"), "yes")) {
1089                 er_flags |= QR_DOWNLOAD;
1090         } else {
1091                 er_flags &= ~QR_DOWNLOAD;
1092         }
1093
1094         if (!strcmp(bstr("visdir"), "yes")) {
1095                 er_flags |= QR_VISDIR;
1096         } else {
1097                 er_flags &= ~QR_VISDIR;
1098         }
1099
1100         strcpy(buf, bstr("anon"));
1101
1102         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1103         if (!strcmp(buf, "anononly"))
1104                 er_flags |= QR_ANONONLY;
1105         if (!strcmp(buf, "anon2"))
1106                 er_flags |= QR_ANONOPT;
1107
1108         bump = 0;
1109         if (!strcmp(bstr("bump"), "yes"))
1110                 bump = 1;
1111
1112         er_floor = atoi(bstr("er_floor"));
1113
1114         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1115              er_name, er_password, er_dirname, er_flags, bump, er_floor);
1116         serv_puts(buf);
1117         serv_gets(buf);
1118         if (buf[0] != '2') {
1119                 display_error(&buf[4]);
1120                 return;
1121         }
1122         gotoroom(er_name, 0);
1123
1124         if (strlen(er_roomaide) > 0) {
1125                 sprintf(buf, "SETA %s", er_roomaide);
1126                 serv_puts(buf);
1127                 serv_gets(buf);
1128                 if (buf[0] != '2') {
1129                         display_error(&buf[4]);
1130                         return;
1131                 }
1132         }
1133         smart_goto(er_name);
1134 }
1135
1136 /*
1137  * Invite, Kick, and show Who Knows a room
1138  */
1139 void display_whok(void)
1140 {
1141         char buf[SIZ], room[SIZ], username[SIZ];
1142
1143         serv_puts("GETR");
1144         serv_gets(buf);
1145
1146         if (buf[0] != '2') {
1147                 display_error(&buf[4]);
1148                 return;
1149         }
1150         extract(room, &buf[4], 0);
1151
1152         strcpy(username, bstr("username"));
1153
1154         output_headers(1);
1155
1156         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
1157         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Access control list for ");
1158         escputs(WC->wc_roomname);
1159         wprintf("</B></FONT></TD></TR></TABLE>\n");
1160
1161         if(!strcmp(bstr("sc"), "Kick")) {
1162                 sprintf(buf, "KICK %s", username);
1163                 serv_puts(buf);
1164                 serv_gets(buf);
1165
1166                 if (buf[0] != '2') {
1167                         display_error(&buf[4]);
1168                         return;
1169                 } else {
1170                         wprintf("<B><I>User %s kicked out of room %s.</I></B>\n", 
1171                                 username, room);
1172                 }
1173         } else if(!strcmp(bstr("sc"), "Invite")) {
1174                 sprintf(buf, "INVT %s", username);
1175                 serv_puts(buf);
1176                 serv_gets(buf);
1177
1178                 if (buf[0] != '2') {
1179                         display_error(&buf[4]);
1180                         return;
1181                 } else {
1182                         wprintf("<B><I>User %s invited to room %s.</I></B>\n", 
1183                                 username, room);
1184                 }
1185         }
1186         
1187
1188
1189         wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1190                 "<TD>The users listed below have access to this room.  "
1191                 "To remove a user from the access list, select the user "
1192                 "name from the list and click 'Kick'.<BR><BR>");
1193         
1194         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1195         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1196         serv_puts("WHOK");
1197         serv_gets(buf);
1198         if (buf[0] == '1') {
1199                 while (serv_gets(buf), strcmp(buf, "000")) {
1200                         extract(username, buf, 0);
1201                         wprintf("<OPTION>");
1202                         escputs(username);
1203                         wprintf("\n");
1204                 }
1205         }
1206         wprintf("</SELECT><BR>\n");
1207
1208         wprintf("<input type=submit name=sc value=\"Kick\">");
1209         wprintf("</FORM></CENTER>\n");
1210
1211         wprintf("</TD><TD>"
1212                 "To grant another user access to this room, enter the "
1213                 "user name in the box below and click 'Invite'.<BR><BR>");
1214
1215         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1216         wprintf("Invite: ");
1217         wprintf("<input type=text name=username><BR>\n"
1218                 "<input type=hidden name=sc value=\"Invite\">"
1219                 "<input type=submit value=\"Invite\">"
1220                 "</FORM></CENTER>\n");
1221
1222         wprintf("</TD></TR></TABLE>\n");
1223         wDumpContent(1);
1224 }
1225
1226
1227
1228 /*
1229  * display the form for entering a new room
1230  */
1231 void display_entroom(void)
1232 {
1233         int i;
1234         char buf[SIZ];
1235
1236         serv_puts("CRE8 0");
1237         serv_gets(buf);
1238
1239         if (buf[0] != '2') {
1240                 display_error(&buf[4]);
1241                 return;
1242         }
1243         output_headers(1);
1244
1245         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
1246         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1247         wprintf("<B>Enter (create) a new room</B>\n");
1248         wprintf("</FONT></TD></TR></TABLE>\n");
1249
1250         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1251
1252         wprintf("<UL><LI>Name of room: ");
1253         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1254
1255         wprintf("<LI>Type of room:<UL>\n");
1256
1257         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1258         wprintf("CHECKED > Public room\n");
1259
1260         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1261         wprintf("> Private - guess name\n");
1262
1263         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1264         wprintf("> Private - require password:\n");
1265         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1266
1267         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1268         wprintf("> Private - invitation only\n");
1269         wprintf("</UL>\n");
1270
1271         wprintf("<LI>Resides on floor: ");
1272         load_floorlist(); 
1273         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1274         for (i = 0; i < 128; ++i)
1275                 if (strlen(floorlist[i]) > 0) {
1276                         wprintf("<OPTION ");
1277                         wprintf("VALUE=\"%d\">", i);
1278                         escputs(floorlist[i]);
1279                         wprintf("</OPTION>\n");
1280                 }
1281         wprintf("</SELECT>\n");                
1282         wprintf("</UL>\n");
1283
1284
1285         wprintf("<CENTER>\n");
1286         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1287         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1288         wprintf("</CENTER>\n");
1289         wprintf("</FORM>\n<HR>");
1290         serv_printf("MESG roomaccess");
1291         serv_gets(buf);
1292         if (buf[0] == '1') {
1293                 fmout(NULL);
1294         }
1295         wDumpContent(1);
1296 }
1297
1298
1299
1300 /*
1301  * enter a new room
1302  */
1303 void entroom(void)
1304 {
1305         char buf[SIZ];
1306         char er_name[20];
1307         char er_type[20];
1308         char er_password[10];
1309         int er_floor;
1310         int er_num_type;
1311
1312         if (strcmp(bstr("sc"), "OK")) {
1313                 display_error("Cancelled.  No new room was created.");
1314                 return;
1315         }
1316         strcpy(er_name, bstr("er_name"));
1317         strcpy(er_type, bstr("type"));
1318         strcpy(er_password, bstr("er_password"));
1319         er_floor = atoi(bstr("er_floor"));
1320
1321         er_num_type = 0;
1322         if (!strcmp(er_type, "guessname"))
1323                 er_num_type = 1;
1324         if (!strcmp(er_type, "passworded"))
1325                 er_num_type = 2;
1326         if (!strcmp(er_type, "invonly"))
1327                 er_num_type = 3;
1328
1329         sprintf(buf, "CRE8 1|%s|%d|%s|%d", 
1330                 er_name, er_num_type, er_password, er_floor);
1331         serv_puts(buf);
1332         serv_gets(buf);
1333         if (buf[0] != '2') {
1334                 display_error(&buf[4]);
1335                 return;
1336         }
1337         smart_goto(er_name);
1338 }
1339
1340
1341 /*
1342  * display the screen to enter a private room
1343  */
1344 void display_private(char *rname, int req_pass)
1345 {
1346
1347         output_headers(1);
1348
1349         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1350         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1351         wprintf("<B>Goto a private room</B>\n");
1352         wprintf("</FONT></TD></TR></TABLE>\n");
1353
1354         wprintf("<CENTER>\n");
1355         wprintf("If you know the name of a hidden (guess-name) or\n");
1356         wprintf("passworded room, you can enter that room by typing\n");
1357         wprintf("its name below.  Once you gain access to a private\n");
1358         wprintf("room, it will appear in your regular room listings\n");
1359         wprintf("so you don't have to keep returning here.\n");
1360         wprintf("<BR><BR>");
1361
1362         wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
1363
1364         wprintf("<TABLE border><TR><TD>");
1365         wprintf("Enter room name:</TD><TD>");
1366         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1367
1368         if (req_pass) {
1369                 wprintf("</TD></TR><TR><TD>");
1370                 wprintf("Enter room password:</TD><TD>");
1371                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1372         }
1373         wprintf("</TD></TR></TABLE>\n");
1374
1375         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1376         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1377         wprintf("</FORM>\n");
1378         wDumpContent(1);
1379 }
1380
1381 /* 
1382  * goto a private room
1383  */
1384 void goto_private(void)
1385 {
1386         char hold_rm[32];
1387         char buf[SIZ];
1388
1389         if (strcasecmp(bstr("sc"), "OK")) {
1390                 display_main_menu();
1391                 return;
1392         }
1393         strcpy(hold_rm, WC->wc_roomname);
1394         strcpy(buf, "GOTO ");
1395         strcat(buf, bstr("gr_name"));
1396         strcat(buf, "|");
1397         strcat(buf, bstr("gr_pass"));
1398         serv_puts(buf);
1399         serv_gets(buf);
1400
1401         if (buf[0] == '2') {
1402                 smart_goto(bstr("gr_name"));
1403                 return;
1404         }
1405         if (!strncmp(buf, "540", 3)) {
1406                 display_private(bstr("gr_name"), 1);
1407                 return;
1408         }
1409         output_headers(1);
1410         wprintf("%s\n", &buf[4]);
1411         wDumpContent(1);
1412         return;
1413 }
1414
1415
1416 /*
1417  * display the screen to zap a room
1418  */
1419 void display_zap(void)
1420 {
1421         output_headers(1);
1422
1423         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1424         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1425         wprintf("<B>Zap (forget) the current room</B>\n");
1426         wprintf("</FONT></TD></TR></TABLE>\n");
1427
1428         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1429         wprintf("disappear from your room list.  Is this what you wish ");
1430         wprintf("to do?<BR>\n");
1431
1432         wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
1433         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1434         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1435         wprintf("</FORM>\n");
1436         wDumpContent(1);
1437 }
1438
1439
1440 /* 
1441  * zap a room
1442  */
1443 void zap(void)
1444 {
1445         char buf[SIZ];
1446         char final_destination[SIZ];
1447
1448         /* If the forget-room routine fails for any reason, we fall back
1449          * to the current room; otherwise, we go to the Lobby
1450          */
1451         strcpy(final_destination, WC->wc_roomname);
1452
1453         if (!strcasecmp(bstr("sc"), "OK")) {
1454                 serv_printf("GOTO %s", WC->wc_roomname);
1455                 serv_gets(buf);
1456                 if (buf[0] != '2') {
1457                         /* ExpressMessageCat(&buf[4]); */
1458                 } else {
1459                         serv_puts("FORG");
1460                         serv_gets(buf);
1461                         if (buf[0] != '2') {
1462                                 /* ExpressMessageCat(&buf[4]); */
1463                         } else {
1464                                 strcpy(final_destination, "_BASEROOM_");
1465                         }
1466                 }
1467         }
1468         smart_goto(final_destination);
1469 }
1470
1471
1472
1473
1474 /*
1475  * Confirm deletion of the current room
1476  */
1477 void confirm_delete_room(void)
1478 {
1479         char buf[SIZ];
1480
1481         serv_puts("KILL 0");
1482         serv_gets(buf);
1483         if (buf[0] != '2') {
1484                 display_error(&buf[4]);
1485                 return;
1486         }
1487         output_headers(1);
1488         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1489         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1490         wprintf("<B>Confirm deletion of room</B>\n");
1491         wprintf("</FONT></TD></TR></TABLE>\n");
1492
1493         wprintf("<CENTER>");
1494         wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
1495
1496         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1497         escputs(WC->wc_roomname);
1498         wprintf("</FONT>?<BR>\n");
1499
1500         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1501         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1502
1503         wprintf("</FORM></CENTER>\n");
1504         wDumpContent(1);
1505 }
1506
1507
1508 /*
1509  * Delete the current room
1510  */
1511 void delete_room(void)
1512 {
1513         char buf[SIZ];
1514         char sc[SIZ];
1515
1516         strcpy(sc, bstr("sc"));
1517
1518         if (strcasecmp(sc, "Delete")) {
1519                 display_error("Cancelled.  This room was not deleted.");
1520                 return;
1521         }
1522         serv_puts("KILL 1");
1523         serv_gets(buf);
1524         if (buf[0] != '2') {
1525                 display_error(&buf[4]);
1526         } else {
1527                 smart_goto("_BASEROOM_");
1528         }
1529 }
1530
1531
1532
1533 /*
1534  * Perform changes to a room's network configuration
1535  */
1536 void netedit(void) {
1537         FILE *fp;
1538         char buf[SIZ];
1539         char line[SIZ];
1540
1541         if (strlen(bstr("line"))==0) {
1542                 display_editroom();
1543                 return;
1544         }
1545
1546         strcpy(line, bstr("prefix"));
1547         strcat(line, bstr("line"));
1548         strcat(line, bstr("suffix"));
1549
1550         fp = tmpfile();
1551         if (fp == NULL) {
1552                 display_editroom();
1553                 return;
1554         }
1555
1556         serv_puts("GNET");
1557         serv_gets(buf);
1558         if (buf[0] != '1') {
1559                 fclose(fp);
1560                 display_editroom();
1561                 return;
1562         }
1563
1564         /* This loop works for add *or* remove.  Spiffy, eh? */
1565         while (serv_gets(buf), strcmp(buf, "000")) {
1566                 if (strcasecmp(buf, line)) {
1567                         fprintf(fp, "%s\n", buf);
1568                 }
1569         }
1570
1571         rewind(fp);
1572         serv_puts("SNET");
1573         serv_gets(buf);
1574         if (buf[0] != '4') {
1575                 fclose(fp);
1576                 display_editroom();
1577                 return;
1578         }
1579
1580         while (fgets(buf, sizeof buf, fp) != NULL) {
1581                 buf[strlen(buf)-1] = 0;
1582                 serv_puts(buf);
1583         }
1584
1585         if (!strcasecmp(bstr("cmd"), "add")) {
1586                 serv_puts(line);
1587         }
1588
1589         serv_puts("000");
1590         fclose(fp);
1591         display_editroom();
1592 }
1593
1594
1595
1596 /*
1597  * Convert a room name to a folder-ish-looking name.
1598  */
1599 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
1600 {
1601         int i;
1602
1603         /*
1604          * For mailboxes, just do it straight...
1605          */
1606         if (is_mailbox) {
1607                 sprintf(folder, "My folders|%s", room);
1608         }
1609
1610         /*
1611          * Otherwise, prefix the floor name as a "public folders" moniker
1612          */
1613         else {
1614                 sprintf(folder, "%s|%s", floorlist[floor], room);
1615         }
1616
1617         /*
1618          * Replace "/" characters with "|" for pseudo-folder-delimiting
1619          */
1620         for (i=0; i<strlen(folder); ++i) {
1621                 if (folder[i] == '/') folder[i] = '|';
1622         }
1623 }
1624
1625
1626
1627
1628
1629
1630
1631 /*
1632  * Change the view for this room
1633  */
1634 void change_view(void) {
1635         int view;
1636         char buf[SIZ];
1637
1638         view = atol(bstr("view"));
1639
1640         serv_printf("VIEW %d", view);
1641         serv_gets(buf);
1642         smart_goto(WC->wc_roomname);
1643 }
1644
1645
1646 /*
1647  * Show the room list in "folders" format
1648  */
1649 void folders(void) {
1650         char buf[SIZ];
1651
1652         int levels, oldlevels;
1653
1654         struct folder {
1655                 char room[SIZ];
1656                 char name[SIZ];
1657                 int hasnewmsgs;
1658                 int is_mailbox;
1659                 int selectable;
1660         };
1661
1662         struct folder *fold = NULL;
1663         struct folder ftmp;
1664         int max_folders = 0;
1665         int alloc_folders = 0;
1666         int i, j, k;
1667         int p;
1668         int flags;
1669         int floor;
1670         int nests = 0;
1671
1672         load_floorlist();
1673
1674         output_headers(1);
1675         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>"
1676                 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
1677                 "<B>Folder list</B>\n"
1678                 "</TD></TR></TABLE><BR>\n"
1679         );
1680
1681         /* Start with the mailboxes */
1682         max_folders = 1;
1683         alloc_folders = 1;
1684         fold = malloc(sizeof(struct folder));
1685         memset(fold, 0, sizeof(struct folder));
1686         strcpy(fold[0].name, "My folders");
1687
1688         /* Then add floors */
1689         serv_puts("LFLR");
1690         serv_gets(buf);
1691         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1692                 if (max_folders >= alloc_folders) {
1693                         alloc_folders = max_folders + 100;
1694                         fold = realloc(fold,
1695                                 alloc_folders * sizeof(struct folder));
1696                 }
1697                 memset(&fold[max_folders], 0, sizeof(struct folder));
1698                 extract(fold[max_folders].name, buf, 1);
1699                 ++max_folders;
1700         }
1701
1702         /* Now add rooms */
1703         for (p = 0; p < 2; ++p) {
1704                 if (p == 0) serv_puts("LKRN");
1705                 else if (p == 1) serv_puts("LKRO");
1706                 serv_gets(buf);
1707                 if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1708                         if (max_folders >= alloc_folders) {
1709                                 alloc_folders = max_folders + 100;
1710                                 fold = realloc(fold,
1711                                         alloc_folders * sizeof(struct folder));
1712                         }
1713                         memset(&fold[max_folders], 0, sizeof(struct folder));
1714                         extract(fold[max_folders].room, buf, 0);
1715                         if (p == 0) fold[max_folders].hasnewmsgs = 1;
1716                         flags = extract_int(buf, 1);
1717                         floor = extract_int(buf, 2);
1718                         if (flags & QR_MAILBOX) {
1719                                 fold[max_folders].is_mailbox = 1;
1720                         }
1721                         room_to_folder(fold[max_folders].name,
1722                                         fold[max_folders].room,
1723                                         floor,
1724                                         fold[max_folders].is_mailbox);
1725                         fold[max_folders].selectable = 1;
1726                         ++max_folders;
1727                 }
1728         }
1729
1730         /* Bubble-sort the folder list */
1731         for (i=0; i<max_folders; ++i) {
1732                 for (j=0; j<(max_folders-1)-i; ++j) {
1733                         if (strcasecmp(fold[j].name, fold[j+1].name) > 0) {
1734                                 memcpy(&ftmp, &fold[j], sizeof(struct folder));
1735                                 memcpy(&fold[j], &fold[j+1],
1736                                                         sizeof(struct folder));
1737                                 memcpy(&fold[j+1], &ftmp,
1738                                                         sizeof(struct folder));
1739                         }
1740                 }
1741         }
1742
1743         /* Output */
1744         nests = 0;
1745         levels = 0;
1746         oldlevels = 0;
1747         for (i=0; i<max_folders; ++i) {
1748
1749                 levels = num_tokens(fold[i].name, '|');
1750                 if (levels > oldlevels) {
1751                         for (k=0; k<(levels-oldlevels); ++k) {
1752                                 wprintf("<UL>");
1753                                 ++nests;
1754                         }
1755                 }
1756                 if (levels < oldlevels) {
1757                         for (k=0; k<(oldlevels-levels); ++k) {
1758                                 wprintf("</UL>");
1759                                 --nests;
1760                         }
1761                 }
1762                 oldlevels = levels;
1763
1764                 wprintf("<LI>");
1765                 if (fold[i].selectable) {
1766                         wprintf("<A HREF=\"/dotgoto?room=");
1767                         urlescputs(fold[i].room);
1768                         wprintf("\">");
1769                 }
1770                 if (fold[i].hasnewmsgs) wprintf("<B>");
1771                 extract(buf, fold[i].name, levels-1);
1772                 escputs(buf);
1773                 if (fold[i].hasnewmsgs) wprintf("</B>");
1774                 if (fold[i].selectable) wprintf("</A>\n");
1775         }
1776         while (nests-- > 0) wprintf("</UL>\n");
1777
1778         free(fold);
1779         wDumpContent(1);
1780 }