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.
22 char wc_username[256];
23 char wc_password[256];
24 char wc_roomname[256];
25 int TransactionCount = 0;
28 struct webcontent *wlist = NULL;
29 struct webcontent *wlast = NULL;
32 void wprintf(const char *format, ...) {
34 struct webcontent *wptr;
36 wptr = (struct webcontent *)malloc(sizeof(struct webcontent));
47 va_start(arg_ptr, format);
48 vsprintf(wptr->w_data, format, arg_ptr);
53 int wContentLength() {
54 struct webcontent *wptr;
57 for (wptr = wlist; wptr != NULL; wptr = wptr->next) {
58 len = len + strlen(wptr->w_data);
65 struct webcontent *wptr;
67 printf("Content-type: text/html\n");
68 printf("Content-length: %d\n", wContentLength());
71 while (wlist != NULL) {
72 fwrite(wlist->w_data, strlen(wlist->w_data), 1, stdout);
80 void getz(char *buf) {
81 if (fgets(buf, 256, stdin) == NULL) strcpy(buf, "");
83 while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1])))
84 buf[strlen(buf)-1] = 0;
89 * Output all that important stuff that the browser will want to see
91 void output_headers() {
92 printf("Server: %s\n", SERVER);
93 printf("Connection: close\n");
94 printf("Set-cookie: wc_session=%d\n", wc_session);
95 if (strlen(wc_host)>0) printf("Set-cookie: wc_host=%s\n", wc_host);
96 if (wc_port != 0) printf("Set-cookie: wc_port=%d\n", wc_port);
97 if (strlen(wc_username)>0) printf("Set-cookie: wc_username=%s\n",
99 if (strlen(wc_password)>0) printf("Set-cookie: wc_password=%s\n",
101 if (strlen(wc_roomname)>0) printf("Set-cookie: wc_roomname=%s\n",
105 void output_static(char *what) {
111 sprintf(buf, "static/%s", what);
112 fp = fopen(buf, "rb");
114 printf("HTTP/1.0 404 %s\n", strerror(errno));
116 printf("Content-Type: text/plain\n");
117 sprintf(buf, "%s: %s\n", what, strerror(errno));
118 printf("Content-length: %d\n", strlen(buf));
120 fwrite(buf, strlen(buf), 1, stdout);
123 printf("HTTP/1.0 200 OK\n");
126 if (!strncasecmp(&what[strlen(what)-4], ".gif", 4))
127 printf("Content-type: image/gif\n");
129 printf("Content-type: junk/data\n");
131 fstat(fileno(fp), &statbuf);
132 bytes = statbuf.st_size;
133 printf("Content-length: %d\n", bytes);
136 putc(getc(fp), stdout);
143 void session_loop() {
149 fprintf(stderr, "Cmd: %s\n", cmd);
154 } while(strlen(buf)>0);
158 if (!strncasecmp(cmd, "GET /static/", 12)) {
159 strcpy(buf, &cmd[12]);
160 for (a=0; a<strlen(buf); ++a) if (isspace(buf[a])) buf[a]=0;
164 else if (!strncasecmp(cmd, "GET /demographics", 17)) {
165 printf("HTTP/1.0 200 OK\n");
168 wprintf("<HTML><HEAD><TITLE>Stuff</TITLE></HEAD><BODY>\n");
169 wprintf("It's time to include an image...\n");
170 wprintf("<IMG SRC=\"/static/netscape.gif\">\n");
171 wprintf("...in the page.</BODY></HTML>\n");
176 printf("HTTP/1.0 200 OK\n");
179 wprintf("<HTML><HEAD><TITLE>WebCit</TITLE></HEAD><BODY>\n");
180 wprintf("TransactionCount is %d<HR>\n", TransactionCount);
181 wprintf("You're in session %d<BR>\n", wc_session);
182 wprintf("</BODY></HTML>\n");
191 int main(int argc, char *argv[]) {
194 printf("%s: usage: %s <session_id>\n", argv[0], argv[0]);
198 wc_session = atoi(argv[1]);
201 strcpy(wc_username, "");
202 strcpy(wc_password, "");
203 strcpy(wc_roomname, "");