output_headers();
wprintf("<HTML><HEAD><TITLE>FrameSet</TITLE></HEAD>\n");
- wprintf("<FRAMESET cols=\"20%, 80%\">\n");
- wprintf(" <FRAME name=\"left\" src=\"/static/velma.gif\">\n");
- wprintf(" <FRAME name=\"right\" src=\"/display_main_menu\">\n");
+ wprintf("<FRAMESET cols=\"15%, 80%\">\n");
+ wprintf(" <FRAME name=\"left\" src=\"/static/velma.gif\">\n");
+ wprintf(" <FRAME name=\"right\" src=\"/display_main_menu\">\n");
wprintf("<NOFRAMES>\n");
wprintf("Your browser doesn't support frames.<BR>\n");
wprintf("This site uses frames.<BR>\n");
sock = *socknumptr;
+ printf("Reading request from socket %d\n", sock);
+
/*
* Find out what it is that the web browser is asking for
*/
}
}
- /*
- * Send the request to the appropriate session
+ /*
+ * Grab a lock on the session, so other threads don't try to access
+ * the pipes at the same time.
*/
+ printf("Locking...\n");
pthread_mutex_lock(&TheSession->critter);
+
+ /*
+ * Send the request to the appropriate session...
+ */
+ printf(" Writing %d lines of command\n", num_lines);
+ printf("%s\n", &req[0][0]);
for (a=0; a<num_lines; ++a) {
write(TheSession->inpipe[1], &req[a][0], strlen(&req[a][0]));
write(TheSession->inpipe[1], "\n", 1);
}
+ printf(" Writing %d bytes of content\n", ContentLength);
while (ContentLength--) {
read(sock, buf, 1);
write(TheSession->inpipe[1], buf, 1);
}
/*
- * ...and get the response (FIX for non-text)
+ * ...and get the response.
*/
+ printf(" Reading response\n");
ContentLength = 0;
do {
gets0(TheSession->outpipe[0], buf);
ContentLength = atoi(&buf[16]);
} while (strlen(buf) > 0);
+ printf(" Reading %d bytes of content\n");
while(ContentLength--) {
read(TheSession->outpipe[0], buf, 1);
write(sock, buf, 1);
}
- pthread_mutex_unlock(&TheSession->critter);
-
/*
* Now our HTTP connection is done. It would be relatively easy
* to support HTTP/1.1 "persistent" connections by looping back to
- * the top of this function. For now, we'll just exit.
+ * the top of this function. For now, we'll just close.
*/
+ printf(" Closing socket\n");
close(sock);
+
+ /*
+ * Let go of the lock
+ */
+ printf("Unlocking.\n");
+ pthread_mutex_unlock(&TheSession->critter);
+
+ /*
+ * The thread handling this HTTP connection is now finished.
+ */
pthread_exit(NULL);
}
output_headers();
wprintf("<HTML><HEAD><TITLE>WebCit main menu</TITLE></HEAD><BODY>\n");
embed_main_menu();
- printf("</BODY></HTML>\n");
+ wprintf("</BODY></HTML>\n");
wDumpContent();
}
strbuf[len++] = ch;
} while((ch!=10)&&(ch!=13)&&(ch!=0)&&(len<255));
strbuf[len-1] = 0;
- fprintf(stderr, ">%s\n", strbuf);
+ /* fprintf(stderr, ">%s\n", strbuf); */
}
strcat(buf, "\n");
serv_write(buf, strlen(buf));
- fprintf(stderr, "<%s", buf);
+ /* fprintf(stderr, "<%s", buf); */
}
up = ptr;
++up;
-
- fprintf(stderr, "%s=%s\n", u->url_key, u->url_data);
}
DONE:
}
strcpy(c_roomname, "");
getz(cmd);
- fprintf(stderr, "\nCmd: %s\n", cmd);
- fflush(stderr);
do {
getz(buf);
- fprintf(stderr, "Buf: %s\n", buf);
- fflush(stderr);
if (!strncasecmp(buf, "Cookie: wc_host=", 16))
strcpy(c_host, &buf[16]);
content = malloc(ContentLength+1);
fread(content, ContentLength, 1, stdin);
content[ContentLength] = 0;
- fprintf(stderr, "CONTENT:\n%s\n", content);
addurls(content);
}
else {
#define SLEEPING 180 /* TCP connection timeout */
-#define PORT_NUM 32763 /* port number to listen on */
+#define PORT_NUM 32767 /* port number to listen on */
#define SERVER "WebCit v2.0 (Velma)" /* who's in da house */
#define DEVELOPER_ID 0
#define CLIENT_ID 4
{
struct sockaddr_in sin;
int s, i;
+ struct linger WebLinger = { 1, 9000 };
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
exit(errno);
}
- /* Set the SO_REUSEADDR socket option, because it makes sense. */
+ /* Set some socket options that make sense. */
i = 1;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
+ setsockopt(s, SOL_SOCKET, SO_LINGER, &WebLinger, sizeof(WebLinger));
if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
printf("webcit: Can't bind: %s\n", strerror(errno));