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