]> code.citadel.org Git - citadel.git/blob - webcit/webcit.c
* ooooops
[citadel.git] / webcit / webcit.c
1 /*
2  * webcit.c
3  *
4  * This is the actual program called by the webserver.  It maintains a
5  * persistent session to the Citadel server, handling HTTP WebCit requests as
6  * they arrive and presenting a user interface.
7  *
8  * $Id$
9  */
10
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <stdio.h>
15 #include <fcntl.h>
16 #include <signal.h>
17 #include <sys/types.h>
18 #include <sys/wait.h>
19 #include <sys/socket.h>
20 #include <sys/time.h>
21 #include <sys/stat.h>
22 #include <limits.h>
23 #include <netinet/in.h>
24 #include <netdb.h>
25 #include <string.h>
26 #include <pwd.h>
27 #include <errno.h>
28 #include <stdarg.h>
29 #include <pthread.h>
30 #include <signal.h>
31 #include "webcit.h"
32
33
34
35 char *ExpressMessages = NULL;   /* FIX move to session context */
36
37 /* This variable is set to 1 if the room banner and menubar have been
38  * displayed, and we need to close the <TABLE> tags.
39  */
40 int fake_frames = 0;    /* FIX move to session context */
41
42 struct urlcontent *urlstrings = NULL;
43
44
45 void unescape_input(char *buf)
46 {
47         int a, b;
48         char hex[3];
49
50         while ((isspace(buf[strlen(buf) - 1])) && (strlen(buf) > 0))
51                 buf[strlen(buf) - 1] = 0;
52
53         for (a = 0; a < strlen(buf); ++a) {
54                 if (buf[a] == '+')
55                         buf[a] = ' ';
56                 if (buf[a] == '%') {
57                         hex[0] = buf[a + 1];
58                         hex[1] = buf[a + 2];
59                         hex[2] = 0;
60                         sscanf(hex, "%02x", &b);
61                         buf[a] = (char) b;
62                         strcpy(&buf[a + 1], &buf[a + 3]);
63                 }
64         }
65
66 }
67
68
69 void addurls(char *url)
70 {
71         char *up, *ptr;
72         char buf[256];
73         int a, b;
74         struct urlcontent *u;
75
76         up = url;
77         while (strlen(up) > 0) {
78
79                 /* locate the = sign */
80                 strncpy(buf, up, 255);
81                 b = (-1);
82                 for (a = 255; a >= 0; --a)
83                         if (buf[a] == '=')
84                                 b = a;
85                 if (b < 0)
86                         return;
87                 buf[b] = 0;
88
89                 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
90                 u->next = urlstrings;
91                 urlstrings = u;
92                 strcpy(u->url_key, buf);
93
94                 /* now chop that part off */
95                 for (a = 0; a <= b; ++a)
96                         ++up;
97
98                 /* locate the & sign */
99                 ptr = up;
100                 b = strlen(up);
101                 for (a = 0; a < strlen(up); ++a) {
102                         if (!strncmp(ptr, "&", 1)) {
103                                 b = a;
104                                 break;
105                         }
106                         ++ptr;
107                 }
108                 ptr = up;
109                 for (a = 0; a < b; ++a)
110                         ++ptr;
111                 strcpy(ptr, "");
112
113                 u->url_data = malloc(strlen(up) + 1);
114                 strcpy(u->url_data, up);
115                 u->url_data[b] = 0;
116                 unescape_input(u->url_data);
117                 up = ptr;
118                 ++up;
119         }
120 }
121
122 void free_urls(void)
123 {
124         struct urlcontent *u;
125
126         while (urlstrings != NULL) {
127                 free(urlstrings->url_data);
128                 u = urlstrings->next;
129                 free(urlstrings);
130                 urlstrings = u;
131         }
132 }
133
134 /*
135  * Diagnostic function to display the contents of all variables
136  */
137 void dump_vars(void)
138 {
139         struct urlcontent *u;
140
141         for (u = urlstrings; u != NULL; u = u->next) {
142                 wprintf("%38s = %s\n", u->url_key, u->url_data);
143         }
144 }
145
146 char *bstr(char *key)
147 {
148         struct urlcontent *u;
149
150         for (u = urlstrings; u != NULL; u = u->next) {
151                 if (!strcasecmp(u->url_key, key))
152                         return (u->url_data);
153         }
154         return ("");
155 }
156
157
158 void wprintf(const char *format,...)
159 {
160         va_list arg_ptr;
161         char wbuf[1024];
162
163         va_start(arg_ptr, format);
164         vsprintf(wbuf, format, arg_ptr);
165         va_end(arg_ptr);
166
167         write(WC->http_sock, wbuf, strlen(wbuf));
168 }
169
170
171 /*
172  * wDumpContent() wraps up an HTTP session, closes tags, etc.
173  *
174  * print_standard_html_footer should be set to 0 to transmit only, 1 to
175  * append the main menu and closing tags, or 2 to
176  * append the closing tags only.
177  */
178 void wDumpContent(int print_standard_html_footer)
179 {
180         if (fake_frames) {
181                 wprintf("<CENTER><FONT SIZE=-1>"
182                         "<TABLE border=0 width=100%><TR>"
183                         "<TD><A HREF=\"/ungoto\">"
184                         "<IMG SRC=\"/static/back.gif\" BORDER=0>"
185                         "Ungoto</A></TD>");
186                 wprintf("<TD><A HREF=\"#TheTop\">"
187                         "<IMG SRC=\"/static/up.gif\" BORDER=0>"
188                         "Top of page</A></TD>");
189                 wprintf("<TD><A HREF=\"/display_enter\">"
190                         "<IMG SRC=\"/static/enter.gif\" BORDER=0>"
191                         "Enter a message</A></TD>");
192                 wprintf("<TD><A HREF=\"/gotonext\">"
193                         "Goto next room"
194                         "<IMG SRC=\"/static/forward.gif\" BORDER=0></A></TD>"
195                         "</TR></TABLE>"
196                         "</FONT>\n"
197                         "</TD></TR></TABLE></TABLE>\n");
198                 fake_frames = 0;
199         }
200
201         if (print_standard_html_footer) {
202                 if (print_standard_html_footer != 2) {
203                         wprintf("<BR>");
204                 }
205                 wprintf("</BODY></HTML>\n");
206         }
207
208
209 }
210
211
212 void escputs1(char *strbuf, int nbsp)
213 {
214         int a;
215
216         for (a = 0; a < strlen(strbuf); ++a) {
217                 if (strbuf[a] == '<')
218                         wprintf("&lt;");
219                 else if (strbuf[a] == '>')
220                         wprintf("&gt;");
221                 else if (strbuf[a] == '&')
222                         wprintf("&amp;");
223                 else if (strbuf[a] == '\"')
224                         wprintf("&quot;");
225                 else if (strbuf[a] == '\'') 
226                         wprintf("&#39;");
227                 else if (strbuf[a] == LB)
228                         wprintf("<");
229                 else if (strbuf[a] == RB)
230                         wprintf(">");
231                 else if (strbuf[a] == QU)
232                         wprintf("\"");
233                 else if ((strbuf[a] == 32) && (nbsp == 1)) {
234                         wprintf("&nbsp;");
235                 } else {
236                         wprintf("%c", strbuf[a]);
237                 }
238         }
239 }
240
241 void escputs(char *strbuf)
242 {
243         escputs1(strbuf, 0);
244 }
245
246
247
248 char *urlesc(char *strbuf)
249 {
250         int a, b, c;
251         char *ec = " #&;`'|*?-~<>^()[]{}$\\";
252         static char outbuf[512];
253
254         strcpy(outbuf, "");
255
256         for (a = 0; a < strlen(strbuf); ++a) {
257                 c = 0;
258                 for (b = 0; b < strlen(ec); ++b) {
259                         if (strbuf[a] == ec[b])
260                                 c = 1;
261                 }
262                 b = strlen(outbuf);
263                 if (c == 1)
264                         sprintf(&outbuf[b], "%%%02x", strbuf[a]);
265                 else
266                         sprintf(&outbuf[b], "%c", strbuf[a]);
267         }
268         return (outbuf);
269 }
270
271 void urlescputs(char *strbuf)
272 {
273         wprintf("%s", urlesc(strbuf));
274 }
275
276
277
278
279 /*
280  * Output all that important stuff that the browser will want to see
281  *
282  * print_standard_html_head values:
283  * 0 = Nothing.  Do not display any leading HTTP or HTML.
284  * 1 = HTTP headers plus the "fake frames" found in most windows.
285  * 2 = HTTP headers required to terminate the session (unset cookies)
286  * 3 = HTTP headers only.
287  */
288 void output_headers(int print_standard_html_head)
289 {
290
291         static char *unset = "; expires=28-May-1971 18:10:00 GMT";
292         char cookie[256];
293
294         wprintf("HTTP/1.0 200 OK\n");
295
296         if (print_standard_html_head > 0) {
297                 wprintf("Content-type: text/html\n");
298                 wprintf("Server: %s\n", SERVER);
299                 wprintf("Connection: close\n");
300                 wprintf("Pragma: no-cache\n");
301                 wprintf("Cache-Control: no-store\n");
302         }
303         stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
304                         WC->wc_password, WC->wc_roomname);
305         if (print_standard_html_head == 2) {
306                 wprintf("X-WebCit-Session: close\n");
307                 wprintf("Set-cookie: webcit=%s\n", unset);
308         } else {
309                 wprintf("Set-cookie: webcit=%s\n", cookie);
310         }
311
312         if (print_standard_html_head > 0) {
313                 wprintf("\n");
314                 wprintf("<HTML><HEAD><TITLE>");
315                 escputs(serv_info.serv_humannode);
316                 wprintf("</TITLE>\n"
317                         "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
318                         "</HEAD>\n");
319                 if (ExpressMessages != NULL) {
320                         wprintf("<SCRIPT language=\"javascript\">\n");
321                         wprintf("function ExpressMessage() {\n");
322                         wprintf(" alert(\"");
323                         escputs(ExpressMessages);
324                         wprintf("\")\n");
325                         wprintf(" }\n </SCRIPT>\n");
326                 }
327
328
329
330                 /* JavaScript key-based navigation would go here if it
331                  * were finished
332                  */
333
334                 wprintf("<BODY ");
335                 if (ExpressMessages != NULL) {
336                         wprintf("onload=\"ExpressMessage()\" ");
337                         free(ExpressMessages);
338                         ExpressMessages = NULL;
339                 }
340                 wprintf("BACKGROUND=\"/image&name=background\" TEXT=\"#000000\" LINK=\"#004400\">\n");
341         
342         
343         if (print_standard_html_head == 1) {
344                 wprintf("<A NAME=\"TheTop\"></A>"
345                         "<TABLE border=0 width=100%>"
346                         "<TR VALIGN=TOP><TD>");
347
348                 display_menubar(0);
349
350                 wprintf("</TD><TD VALIGN=TOP>"
351                         "<TABLE border=0 width=100%><TR VALIGN=TOP>"
352                         "<TD>\n");
353
354                 embed_room_banner(NULL);
355
356                 wprintf("</TD></TR><TR VALIGN=TOP><TD>\n");
357                 
358                 fake_frames = 1;
359                 }
360         }
361 }
362
363
364
365 void ExpressMessageCat(char *buf) {
366         if (ExpressMessages == NULL) {
367                 ExpressMessages = malloc(strlen(buf) + 4);
368                 strcpy(ExpressMessages, "");
369         } else {
370                 ExpressMessages = realloc(ExpressMessages,
371                         (strlen(ExpressMessages) + strlen(buf) + 4));
372         }
373         strcat(ExpressMessages, buf);
374         strcat(ExpressMessages, "\\n");
375 }
376
377
378 void check_for_express_messages()
379 {
380         char buf[256];
381
382         serv_puts("PEXP");
383         serv_gets(buf);
384         if (buf[0] == '1') {
385                 while (serv_gets(buf), strcmp(buf, "000")) {
386                         ExpressMessageCat(buf);
387                 }
388         }
389 }
390
391
392
393
394 void output_static(char *what)
395 {
396         char buf[4096];
397         long thisblock;
398         FILE *fp;
399         struct stat statbuf;
400         off_t bytes;
401
402         sprintf(buf, "static/%s", what);
403         fp = fopen(buf, "rb");
404         if (fp == NULL) {
405                 wprintf("HTTP/1.0 404 %s\n", strerror(errno));
406                 wprintf("Content-Type: text/plain\n");
407                 wprintf("\n");
408                 wprintf("Cannot open %s: %s\n", what, strerror(errno));
409         } else {
410                 output_headers(0);
411
412                 if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
413                         wprintf("Content-type: image/gif\n");
414                 else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
415                         wprintf("Content-type: text/plain\n");
416                 else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
417                         wprintf("Content-type: image/jpeg\n");
418                 else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
419                         wprintf("Content-type: text/html\n");
420                 else
421                         wprintf("Content-type: application/octet-stream\n");
422
423                 fstat(fileno(fp), &statbuf);
424                 bytes = statbuf.st_size;
425                 fprintf(stderr, "Static: %s, %ld bytes\n", what, bytes);
426                 wprintf("Content-length: %ld\n", (long) bytes);
427                 wprintf("\n");
428                 while (bytes > 0) {
429                         thisblock = sizeof(buf);
430                         if (thisblock > bytes) thisblock = bytes;
431                         fread(buf, thisblock, 1, fp);
432                         write(WC->http_sock, buf, thisblock);
433                         bytes = bytes - thisblock;
434                 }
435                 fclose(fp);
436         }
437 }
438
439 /*
440  * When the browser requests an image file from the Citadel server,
441  * this function is called to transmit it.
442  */
443 void output_image()
444 {
445         char buf[256];
446         char xferbuf[4096];
447         off_t bytes;
448         off_t thisblock;
449         off_t accomplished = 0L;
450
451
452         serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
453         serv_gets(buf);
454         if (buf[0] == '2') {
455                 bytes = extract_long(&buf[4], 0);
456                 output_headers(0);
457                 wprintf("Content-type: image/gif\n");
458                 wprintf("Content-length: %ld\n", (long) bytes);
459                 wprintf("\n");
460
461                 while (bytes > (off_t) 0) {
462                         thisblock = (off_t) sizeof(xferbuf);
463                         if (thisblock > bytes)
464                                 thisblock = bytes;
465                         serv_printf("READ %ld|%ld", accomplished, thisblock);
466                         serv_gets(buf);
467                         if (buf[0] == '6')
468                                 thisblock = extract_long(&buf[4], 0);
469                         serv_read(xferbuf, (int) thisblock);
470                         write(WC->http_sock, xferbuf, thisblock);
471                         bytes = bytes - thisblock;
472                         accomplished = accomplished + thisblock;
473                 }
474                 serv_puts("CLOS");
475                 serv_gets(buf);
476         } else {
477                 wprintf("HTTP/1.0 404 %s\n", strerror(errno));
478                 output_headers(0);
479                 wprintf("Content-Type: text/plain\n");
480                 wprintf("\n");
481                 wprintf("Error retrieving image\n");
482         }
483
484 }
485
486
487 /*
488  * Convenience functions to display a page containing only a string
489  */
490 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
491 {
492         wprintf("HTTP/1.0 200 OK\n");
493         output_headers(1);
494         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=%s><TR><TD>", titlebarcolor);
495         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
496         wprintf("<B>%s</B>\n", titlebarmsg);
497         wprintf("</FONT></TD></TR></TABLE><BR>\n");
498         escputs(messagetext);
499
500         wprintf("<HR>\n");
501         embed_main_menu();
502         wDumpContent(1);
503 }
504
505 void display_error(char *errormessage)
506 {
507         convenience_page("770000", "Error", errormessage);
508 }
509
510 void display_success(char *successmessage)
511 {
512         convenience_page("007700", "OK", successmessage);
513 }
514
515
516
517 void extract_action(char *actbuf, char *cmdbuf)
518 {
519         int i;
520
521         strcpy(actbuf, cmdbuf);
522         if (!strncasecmp(actbuf, "GET /", 5))
523                 strcpy(actbuf, &actbuf[5]);
524         if (!strncasecmp(actbuf, "PUT /", 5))
525                 strcpy(actbuf, &actbuf[5]);
526         if (!strncasecmp(actbuf, "POST /", 6))
527                 strcpy(actbuf, &actbuf[6]);
528
529         for (i = 0; i < strlen(actbuf); ++i) {
530                 if (actbuf[i] == ' ') {
531                         actbuf[i] = 0;
532                         i = 0;
533                 }
534                 if (actbuf[i] == '/') {
535                         actbuf[i] = 0;
536                         i = 0;
537                 }
538                 if (actbuf[i] == '?') {
539                         actbuf[i] = 0;
540                         i = 0;
541                 }
542                 if (actbuf[i] == '&') {
543                         actbuf[i] = 0;
544                         i = 0;
545                 }
546         }
547 }
548
549
550 void upload_handler(char *name, char *filename, char *encoding,
551                     void *content, char *cbtype, size_t length)
552 {
553
554         fprintf(stderr, "UPLOAD HANDLER CALLED\n");
555         fprintf(stderr, "    name = %s\n", name);
556         fprintf(stderr, "filename = %s\n", filename);
557         fprintf(stderr, "encoding = %s\n", encoding);
558         fprintf(stderr, "    type = %s\n", cbtype);
559         fprintf(stderr, "  length = %d\n", length);
560
561         if (strlen(name) > 0) {
562                 WC->upload = malloc(length);
563                 if (WC->upload != NULL) {
564                         WC->upload_length = length;
565                         memcpy(WC->upload, content, length);
566                 }
567         }
568 }
569
570
571 /*
572  * Entry point for WebCit transaction
573  */
574 void session_loop(struct httprequest *req)
575 {
576         char cmd[256];
577         char action[256];
578         char buf[256];
579         int a, b;
580         int ContentLength = 0;
581         char ContentType[512];
582         char *content;
583         struct httprequest *hptr;
584         char browser_host[256];
585         char user_agent[256];
586
587         /* We stuff these with the values coming from the client cookies,
588          * so we can use them to reconnect a timed out session if we have to.
589          */
590         char c_host[256];
591         char c_port[256];
592         char c_username[256];
593         char c_password[256];
594         char c_roomname[256];
595         char cookie[256];
596
597         strcpy(c_host, defaulthost);
598         strcpy(c_port, defaultport);
599         strcpy(c_username, "");
600         strcpy(c_password, "");
601         strcpy(c_roomname, "");
602
603         WC->upload_length = 0;
604         WC->upload = NULL;
605
606         hptr = req;
607         if (hptr == NULL) return;
608
609         strcpy(cmd, hptr->line);
610         hptr = hptr->next;
611         extract_action(action, cmd);
612
613         while (hptr != NULL) {
614                 strcpy(buf, hptr->line);
615                 hptr = hptr->next;
616
617                 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
618                         strcpy(cookie, &buf[15]);
619                         cookie_to_stuff(cookie, NULL,
620                                       c_username, c_password, c_roomname);
621                 }
622                 else if (!strncasecmp(buf, "Content-length: ", 16)) {
623                         ContentLength = atoi(&buf[16]);
624                 }
625                 else if (!strncasecmp(buf, "Content-type: ", 14)) {
626                         strcpy(ContentType, &buf[14]);
627                 }
628                 else if (!strncasecmp(buf, "User-agent: ", 12)) {
629                         strcpy(user_agent, &buf[12]);
630                 }
631         }
632
633         if (ContentLength > 0) {
634                 content = malloc(ContentLength + 1);
635                 read(WC->http_sock, content, ContentLength);
636
637                 content[ContentLength] = 0;
638
639                 if (!strncasecmp(ContentType,
640                               "application/x-www-form-urlencoded", 33)) {
641                         addurls(content);
642                 } else if (!strncasecmp(ContentType, "multipart", 9)) {
643                         mime_parser(content, ContentLength, ContentType,
644                                     *upload_handler);
645                 }
646         } else {
647                 content = NULL;
648         }
649
650         /* If there are variables in the URL, we must grab them now */
651         for (a = 0; a < strlen(cmd); ++a)
652                 if ((cmd[a] == '?') || (cmd[a] == '&')) {
653                         for (b = a; b < strlen(cmd); ++b)
654                                 if (isspace(cmd[b]))
655                                         cmd[b] = 0;
656                         addurls(&cmd[a + 1]);
657                         cmd[a] = 0;
658                 }
659         /*
660          * If we're not connected to a Citadel server, try to hook up the
661          * connection now.  Preference is given to the host and port specified
662          * by browser cookies, if cookies have been supplied.
663          */
664         if (!WC->connected) {
665                 if (strlen(bstr("host")) > 0)
666                         strcpy(c_host, bstr("host"));
667                 if (strlen(bstr("port")) > 0)
668                         strcpy(c_port, bstr("port"));
669                 WC->serv_sock = connectsock(c_host, c_port, "tcp");
670                 if (WC->serv_sock < 0) {
671                         do_logout();
672                 }
673
674                 WC->connected = 1;
675                 serv_gets(buf); /* get the server welcome message */
676                 locate_host(browser_host, WC->http_sock);
677                 get_serv_info(browser_host, user_agent);
678         }
679         check_for_express_messages();
680
681         /*
682          * If we're not logged in, but we have username and password cookies
683          * supplied by the browser, try using them to log in.
684          */
685         if ((!WC->logged_in) && (strlen(c_username) > 0) && (strlen(c_password) > 0)) {
686                 serv_printf("USER %s", c_username);
687                 serv_gets(buf);
688                 if (buf[0] == '3') {
689                         serv_printf("PASS %s", c_password);
690                         serv_gets(buf);
691                         if (buf[0] == '2') {
692                                 become_logged_in(c_username, c_password, buf);
693                         }
694                 }
695         }
696         /*
697          * If we don't have a current room, but a cookie specifying the
698          * current room is supplied, make an effort to go there.
699          */
700         if ((strlen(WC->wc_roomname) == 0) && (strlen(c_roomname) > 0)) {
701                 serv_printf("GOTO %s", c_roomname);
702                 serv_gets(buf);
703                 if (buf[0] == '2') {
704                         strcpy(WC->wc_roomname, c_roomname);
705                 }
706         }
707         if (!strcasecmp(action, "static")) {
708                 strcpy(buf, &cmd[12]);
709                 for (a = 0; a < strlen(buf); ++a)
710                         if (isspace(buf[a]))
711                                 buf[a] = 0;
712                 output_static(buf);
713         } else if (!strcasecmp(action, "image")) {
714                 output_image();
715         } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
716                 do_login();
717         } else if (!WC->logged_in) {
718                 display_login(NULL);
719         }
720         /* Various commands... */
721
722         else if (!strcasecmp(action, "do_welcome")) {
723                 do_welcome();
724         } else if (!strcasecmp(action, "display_main_menu")) {
725                 display_main_menu();
726         } else if (!strcasecmp(action, "advanced")) {
727                 display_advanced_menu();
728         } else if (!strcasecmp(action, "whobbs")) {
729                 whobbs();
730         } else if (!strcasecmp(action, "knrooms")) {
731                 list_all_rooms_by_floor();
732         } else if (!strcasecmp(action, "gotonext")) {
733                 slrp_highest();
734                 gotonext();
735         } else if (!strcasecmp(action, "skip")) {
736                 gotonext();
737         } else if (!strcasecmp(action, "ungoto")) {
738                 ungoto();
739         } else if (!strcasecmp(action, "dotgoto")) {
740                 slrp_highest();
741                 smart_goto(bstr("room"));
742         } else if (!strcasecmp(action, "termquit")) {
743                 do_logout();
744         } else if (!strcasecmp(action, "readnew")) {
745                 readloop("readnew");
746         } else if (!strcasecmp(action, "readold")) {
747                 readloop("readold");
748         } else if (!strcasecmp(action, "readfwd")) {
749                 readloop("readfwd");
750         } else if (!strcasecmp(action, "display_enter")) {
751                 display_enter();
752         } else if (!strcasecmp(action, "post")) {
753                 post_message();
754         } else if (!strcasecmp(action, "confirm_delete_msg")) {
755                 confirm_delete_msg();
756         } else if (!strcasecmp(action, "delete_msg")) {
757                 delete_msg();
758         } else if (!strcasecmp(action, "confirm_move_msg")) {
759                 confirm_move_msg();
760         } else if (!strcasecmp(action, "move_msg")) {
761                 move_msg();
762         } else if (!strcasecmp(action, "userlist")) {
763                 userlist();
764         } else if (!strcasecmp(action, "showuser")) {
765                 showuser();
766         } else if (!strcasecmp(action, "display_page")) {
767                 display_page();
768         } else if (!strcasecmp(action, "page_user")) {
769                 page_user();
770         } else if (!strcasecmp(action, "chat")) {
771                 do_chat();
772         } else if (!strcasecmp(action, "display_private")) {
773                 display_private("", 0);
774         } else if (!strcasecmp(action, "goto_private")) {
775                 goto_private();
776         } else if (!strcasecmp(action, "zapped_list")) {
777                 zapped_list();
778         } else if (!strcasecmp(action, "display_zap")) {
779                 display_zap();
780         } else if (!strcasecmp(action, "zap")) {
781                 zap();
782         } else if (!strcasecmp(action, "display_entroom")) {
783                 display_entroom();
784         } else if (!strcasecmp(action, "entroom")) {
785                 entroom();
786         } else if (!strcasecmp(action, "display_editroom")) {
787                 display_editroom();
788         } else if (!strcasecmp(action, "editroom")) {
789                 editroom();
790         } else if (!strcasecmp(action, "display_editinfo")) {
791                 display_edit("Room info", "EINF 0", "RINF", "/editinfo");
792         } else if (!strcasecmp(action, "editinfo")) {
793                 save_edit("Room info", "EINF 1", 1);
794         } else if (!strcasecmp(action, "display_editbio")) {
795                 sprintf(buf, "RBIO %s", WC->wc_username);
796                 display_edit("Your bio", "NOOP", buf, "editbio");
797         } else if (!strcasecmp(action, "editbio")) {
798                 save_edit("Your bio", "EBIO", 0);
799         } else if (!strcasecmp(action, "confirm_delete_room")) {
800                 confirm_delete_room();
801         } else if (!strcasecmp(action, "delete_room")) {
802                 delete_room();
803         } else if (!strcasecmp(action, "validate")) {
804                 validate();
805         } else if (!strcasecmp(action, "display_editpic")) {
806                 display_graphics_upload("your photo",
807                                         "UIMG 0|_userpic_",
808                                         "/editpic");
809         } else if (!strcasecmp(action, "editpic")) {
810                 do_graphics_upload("UIMG 1|_userpic_");
811         } else if (!strcasecmp(action, "display_editroompic")) {
812                 display_graphics_upload("the graphic for this room",
813                                         "UIMG 0|_roompic_",
814                                         "/editroompic");
815         } else if (!strcasecmp(action, "editroompic")) {
816                 do_graphics_upload("UIMG 1|_roompic_");
817         } else if (!strcasecmp(action, "select_floor_to_edit_pic")) {
818                 select_floor_to_edit_pic();
819         } else if (!strcasecmp(action, "display_editfloorpic")) {
820                 sprintf(buf, "UIMG 0|_floorpic_|%s",
821                         bstr("which_floor"));
822                 display_graphics_upload("the graphic for this floor",
823                                         buf,
824                                         "/editfloorpic");
825         } else if (!strcasecmp(action, "editfloorpic")) {
826                 sprintf(buf, "UIMG 1|_floorpic_|%s",
827                         bstr("which_floor"));
828                 do_graphics_upload(buf);
829         } else if (!strcasecmp(action, "display_reg")) {
830                 display_reg(0);
831         } else if (!strcasecmp(action, "register")) {
832                 register_user();
833         } else if (!strcasecmp(action, "display_changepw")) {
834                 display_changepw();
835         } else if (!strcasecmp(action, "changepw")) {
836                 changepw();
837         } else if (!strcasecmp(action, "display_edit_node")) {
838                 display_edit_node();
839         } else if (!strcasecmp(action, "display_netconf")) {
840                 display_netconf();
841         } else if (!strcasecmp(action, "display_confirm_unshare")) {
842                 display_confirm_unshare();
843         } else if (!strcasecmp(action, "display_confirm_delete_node")) {
844                 display_confirm_delete_node();
845         } else if (!strcasecmp(action, "delete_node")) {
846                 delete_node();
847         } else if (!strcasecmp(action, "unshare")) {
848                 unshare();
849         } else if (!strcasecmp(action, "display_add_node")) {
850                 display_add_node();
851         } else if (!strcasecmp(action, "add_node")) {
852                 add_node();
853         } else if (!strcasecmp(action, "display_share")) {
854                 display_share();
855         } else if (!strcasecmp(action, "share")) {
856                 share();
857         } else if (!strcasecmp(action, "terminate_session")) {
858                 slrp_highest();
859                 terminate_session();
860         } else if (!strcasecmp(action, "edit_me")) {
861                 edit_me();
862         } else if (!strcasecmp(action, "display_siteconfig")) {
863                 display_siteconfig();
864         } else if (!strcasecmp(action, "siteconfig")) {
865                 siteconfig();
866         } else if (!strcasecmp(action, "display_generic")) {
867                 display_generic();
868         } else if (!strcasecmp(action, "do_generic")) {
869                 do_generic();
870         } else if (!strcasecmp(action, "display_menubar")) {
871                 display_menubar(1);
872         } else if (!strcasecmp(action, "diagnostics")) {
873                 output_headers(1);
874
875                 wprintf("You're in session %d<HR>\n", WC->wc_session);
876                 wprintf("Command: <BR><PRE>\n");
877                 escputs(cmd);
878                 wprintf("</PRE><HR>\n");
879                 wprintf("Variables: <BR><PRE>\n");
880                 dump_vars();
881                 wprintf("</PRE><HR>\n");
882                 wDumpContent(1);
883         }
884         /* When all else fais, display the main menu. */
885         else {
886                 display_main_menu();
887         }
888
889         fflush(stdout);
890         if (content != NULL) {
891                 free(content);
892                 content = NULL;
893         }
894         free_urls();
895         if (WC->upload_length > 0) {
896                 free(WC->upload);
897                 WC->upload_length = 0;
898         }
899 }