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