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