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