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.
19 char wc_username[256];
20 char wc_password[256];
21 char wc_roomname[256];
23 void getz(char *buf) {
24 if (fgets(buf, 256, stdin) == NULL) strcpy(buf, "");
26 while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1])))
27 buf[strlen(buf)-1] = 0;
31 void output_reconnect_cookies() {
32 printf("Set-cookie: wc_session=%d\n", wc_session);
33 if (strlen(wc_host)>0) printf("Set-cookie: wc_host=%s\n", wc_host);
34 if (wc_port != 0) printf("Set-cookie: wc_port=%d\n", wc_port);
35 if (strlen(wc_username)>0) printf("Set-cookie: wc_username=%s\n",
37 if (strlen(wc_password)>0) printf("Set-cookie: wc_password=%s\n",
39 if (strlen(wc_roomname)>0) printf("Set-cookie: wc_roomname=%s\n",
43 void output_static(char *what) {
47 sprintf(buf, "static/%s", what);
48 fp = fopen(buf, "rb");
50 printf("HTTP/1.0 404 %s\n", strerror(errno));
51 printf("Server: WebCit v2 (Velma)\n");
52 printf("Connection: close\n");
53 output_reconnect_cookies();
54 printf("Content-Type: text/plain\n");
55 sprintf(buf, "%s: %s\n", what, strerror(errno));
56 printf("Content-length: %d\n", strlen(buf));
58 fwrite(buf, strlen(buf), 1, stdout);
61 printf("HTTP/1.0 200 OK\n");
62 printf("Server: WebCit v2 (Velma)\n");
63 printf("Connection: close\n");
64 output_reconnect_cookies();
65 printf("Content-Type: text/plain\n");
66 printf("Content-length: 11\n");
68 printf("Hi from IG\n");
78 static int TransactionCount = 0;
84 } while(strlen(buf)>0);
86 fprintf(stderr, "Command: %s\n", cmd);
89 if (!strncasecmp(cmd, "GET /static/", 12)) {
90 strcpy(buf, &cmd[12]);
91 for (a=0; a<strlen(buf); ++a) if (isspace(buf[a])) buf[a]=0;
96 printf("HTTP/1.0 200 OK\n");
97 printf("Server: WebCit v2 (Velma)\n");
98 printf("Connection: close\n");
99 output_reconnect_cookies();
100 printf("Content-Type: text/html\n");
104 sprintf(&content[strlen(content)],
105 "<HTML><HEAD><TITLE>WebCit</TITLE></HEAD><BODY>\n");
106 sprintf(&content[strlen(content)],
107 "TransactionCount is %d<HR>\n", ++TransactionCount);
108 sprintf(&content[strlen(content)],
109 "You're in session %d<BR>\n", wc_session);
110 sprintf(&content[strlen(content)],
113 printf("Content-length: %d\n", strlen(content));
115 fwrite(content, strlen(content), 1, stdout);
123 int main(int argc, char *argv[]) {
126 printf("%s: usage: %s <session_id>\n", argv[0], argv[0]);
130 wc_session = atoi(argv[1]);
133 strcpy(wc_username, "");
134 strcpy(wc_password, "");
135 strcpy(wc_roomname, "");