multithreaded server.
$Log$
+Revision 1.107 1999/11/26 03:32:59 ajc
+* Started moving all of the global variables into a struct, to facilitate
+ multithreaded server.
+
Revision 1.106 1999/11/26 01:28:10 ajc
* 2.01 release
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
-
*/
void become_logged_in(char *user, char *pass, char *serv_response)
{
- logged_in = 1;
- extract(wc_username, &serv_response[4], 0);
- strcpy(wc_password, pass);
- axlevel = extract_int(&serv_response[4], 1);
- if (axlevel >= 6)
- is_aide = 1;
+ WC->logged_in = 1;
+ extract(WC->wc_username, &serv_response[4], 0);
+ strcpy(WC->wc_password, pass);
+ WC->axlevel = extract_int(&serv_response[4], 1);
+ if (WC->axlevel >= 6)
+ WC->is_aide = 1;
}
return;
}
}
- if (logged_in) {
+ if (WC->logged_in) {
serv_puts("CHEK");
serv_gets(buf);
if (buf[0] == '2') {
- new_mail = extract_int(&buf[4], 0);
+ WC->new_mail = extract_int(&buf[4], 0);
need_regi = extract_int(&buf[4], 1);
- need_vali = extract_int(&buf[4], 2);
+ WC->need_vali = extract_int(&buf[4], 2);
}
if (need_regi) {
display_reg(1);
{
char buf[256];
- strcpy(wc_username, "");
- strcpy(wc_password, "");
- strcpy(wc_roomname, "");
+ strcpy(WC->wc_username, "");
+ strcpy(WC->wc_password, "");
+ strcpy(WC->wc_roomname, "");
printf("HTTP/1.0 200 OK\n");
output_headers(2); /* note "2" causes cookies to be unset */
strcpy(buf, bstr("user"));
if (strlen(buf) > 0)
- if (strlen(bstr("axlevel")) > 0) {
- serv_printf("VALI %s|%s", buf, bstr("axlevel"));
+ if (strlen(bstr("WC->axlevel")) > 0) {
+ serv_printf("VALI %s|%s", buf, bstr("WC->axlevel"));
serv_gets(buf);
if (buf[0] != '2') {
wprintf("<EM>%s</EM><BR>\n", &buf[4]);
wprintf("</CAPTION><TR>");
for (a = 0; a <= 6; ++a) {
wprintf(
- "<TD><A HREF=\"/validate&user=%s&axlevel=%d\">%s</A></TD>\n",
+ "<TD><A HREF=\"/validate&user=%s&WC->axlevel=%d\">%s</A></TD>\n",
urlesc(user), a, axdefs[a]);
}
wprintf("</TR></TABLE><CENTER><BR>\n");
int pos = 0;
int thisblock;
- if (upload_length == 0) {
+ if (WC->upload_length == 0) {
display_error("You didn't upload a file.\n");
return;
}
display_error(&buf[4]);
return;
}
- bytes_remaining = upload_length;
+ bytes_remaining = WC->upload_length;
while (bytes_remaining) {
thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
serv_printf("WRIT %d", thisblock);
return;
}
thisblock = extract_int(&buf[4], 0);
- serv_write(&upload[pos], thisblock);
+ serv_write(&WC->upload[pos], thisblock);
pos = pos + thisblock;
bytes_remaining = bytes_remaining - thisblock;
}
wprintf("Skip to next room</B></A><BR>\n");
wprintf("(come back here later)</LI>\n");
- if ((strlen(ugname) > 0) && (strcasecmp(ugname, wc_roomname))) {
+ if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
wprintf("<LI><B><A HREF=\"/ungoto\">\n");
wprintf("Ungoto</B></A><BR>\n");
- wprintf("(oops! Back to %s)</LI>\n", ugname);
+ wprintf("(oops! Back to %s)</LI>\n", WC->ugname);
}
wprintf("</UL>\n");
wprintf("Create a new room</A>\n");
wprintf("<LI><A HREF=\"/display_zap\">");
- wprintf("Zap (forget) this room (%s)</A>\n", wc_roomname);
+ wprintf("Zap (forget) this room (%s)</A>\n", WC->wc_roomname);
wprintf("<LI><A HREF=\"/zapped_list\">");
wprintf("List all forgotten rooms</A>\n");
wprintf("</TD><TD>");
- if ((axlevel >= 6) || (is_room_aide)) {
+ if ((WC->axlevel >= 6) || (WC->is_room_aide)) {
wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007777><TR><TD>");
wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
wprintf("<B>Administrative functions</B>\n");
wprintf("<LI><A HREF=\"/display_siteconfig\">\n");
wprintf("Edit site-wide configuration</A>\n");
- if (axlevel >= 6) {
+ if (WC->axlevel >= 6) {
wprintf("<LI><A HREF=\"/validate\">\n");
wprintf("Validate new users</A>\n");
&& (strcasecmp(&buf[5], serv_info.serv_humannode)))
wprintf("(%s) ", &buf[5]);
if ((!strncasecmp(buf, "room=", 5))
- && (strcasecmp(&buf[5], wc_roomname)))
+ && (strcasecmp(&buf[5], WC->wc_roomname)))
wprintf("in %s> ", &buf[5]);
if (!strncasecmp(buf, "node=", 5)) {
- if ((room_flags & QR_NETWORK)
+ if ((WC->room_flags & QR_NETWORK)
|| ((strcasecmp(&buf[5], serv_info.serv_nodename)
&& (strcasecmp(&buf[5], serv_info.serv_fqdn))))) {
wprintf("@%s ", &buf[5]);
wprintf("****");
wprintf("</FONT></TD>");
- if (is_room_aide) {
+ if (WC->is_room_aide) {
wprintf("<TD ALIGN=RIGHT NOWRAP><FONT FACE=\"Arial,Helvetica,sans-serif\" COLOR=\"FFFF00\"><B>");
wprintf("<A HREF=\"/confirm_move_msg");
printf("HTTP/1.0 200 OK\n");
output_headers(1);
- wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><CENTER><B>%s - ", wc_roomname);
+ wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><CENTER><B>%s - ", WC->wc_roomname);
if (!strcmp(oper, "readnew")) {
strcpy(cmd, "MSGS NEW");
wprintf("new messages");
buf[strlen(buf) - 1] = 0;
strcpy(&buf[16], &buf[19]);
wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
- wprintf("from %s ", wc_username);
+ wprintf("from %s ", WC->wc_username);
if (strlen(bstr("recp")) > 0)
wprintf("to %s ", bstr("recp"));
- wprintf("in %s> ", wc_roomname);
+ wprintf("in %s> ", WC->wc_roomname);
wprintf("</B></FONT><BR><CENTER>\n");
wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
wprintf("<applet codebase=\"/static\" ");
wprintf("code=\"wcchat\" width=2 height=2>\n");
- wprintf("<PARAM NAME=username VALUE=\"%s\">\n", wc_username);
- wprintf("<PARAM NAME=password VALUE=\"%s\">\n", wc_password);
+ wprintf("<PARAM NAME=username VALUE=\"%s\">\n", WC->wc_username);
+ wprintf("<PARAM NAME=password VALUE=\"%s\">\n", WC->wc_password);
wprintf("<H2>Oops!</H2>Looks like your browser doesn't support Java, ");
wprintf("so you won't be able to access Chat. Sorry.\n");
wprintf("</applet>\n");
char floorlist[128][256];
-char ugname[128];
-long uglsn = (-1L);
-unsigned room_flags;
-int is_aide = 0;
-int is_room_aide = 0;
struct march *march = NULL;
* If it isn't supplied, we fake it by issuing our own GOTO.
*/
if (got == NULL) {
- serv_printf("GOTO %s", wc_roomname);
+ serv_printf("GOTO %s", WC->wc_roomname);
serv_gets(fakegot);
got = fakegot;
}
/* Check for new mail. */
- new_mail = extract_int(&got[4], 9);
+ WC->new_mail = extract_int(&got[4], 9);
/* Now start spewing HTML. */
wprintf("<CENTER><TABLE border=0><TR>");
- if ((strlen(ugname) > 0) && (strcasecmp(ugname, wc_roomname))) {
+ if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
wprintf("<TD VALIGN=TOP><A HREF=\"/ungoto\">");
wprintf("<IMG SRC=\"/static/back.gif\" BORDER=0></A></TD>");
}
- wprintf("<TD VALIGN=TOP><FONT FACE=\"Arial,Helvetica,sans-serif\"><FONT SIZE=+2>%s</FONT><BR>", wc_roomname);
+ wprintf("<TD VALIGN=TOP><FONT FACE=\"Arial,Helvetica,sans-serif\"><FONT SIZE=+2>%s</FONT><BR>", WC->wc_roomname);
wprintf("%d new of %d messages</FONT></TD>\n",
extract_int(&got[4], 1),
extract_int(&got[4], 2));
if (buf[0] == '2') {
wprintf("<TD><FONT FACE=\"Arial,Helvetica,sans-serif\">");
wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
- urlescputs(wc_roomname);
+ urlescputs(WC->wc_roomname);
wprintf("\"></FONT></TD>");
serv_puts("CLOS");
serv_gets(buf);
wprintf("</FONT></TD>");
/* Let the user know if new mail has arrived */
- if ( (new_mail > remember_new_mail) && (new_mail>0) ) {
+ if ( (WC->new_mail > remember_new_mail) && (WC->new_mail>0) ) {
wprintf("<TD VALIGN=TOP>"
"<IMG SRC=\"/static/mail.gif\" border=0 "
"ALT=\"You have new mail\">"
- "<BR><BLINK>%d</BLINK></TD>", new_mail);
- remember_new_mail = new_mail;
+ "<BR><BLINK>%d</BLINK></TD>", WC->new_mail);
+ remember_new_mail = WC->new_mail;
}
wprintf("<TD VALIGN=TOP><A HREF=\"/gotonext\">");
}
if (display_name != 2) {
/* store ungoto information */
- strcpy(ugname, wc_roomname);
- uglsn = ls;
+ strcpy(WC->ugname, WC->wc_roomname);
+ WC->uglsn = ls;
}
/* move to the new room */
serv_printf("GOTO %s", gname);
}
return;
}
- extract(wc_roomname, &buf[4], 0);
- room_flags = extract_int(&buf[4], 4);
+ extract(WC->wc_roomname, &buf[4], 0);
+ WC->room_flags = extract_int(&buf[4], 4);
/* highest_msg_read = extract_int(&buf[4],6);
maxmsgnum = extract_int(&buf[4],5);
is_mail = (char) extract_int(&buf[4],7); */
ls = extract_long(&buf[4], 6);
- if (is_aide)
- is_room_aide = is_aide;
+ if (WC->is_aide)
+ WC->is_room_aide = WC->is_aide;
else
- is_room_aide = (char) extract_int(&buf[4], 8);
+ WC->is_room_aide = (char) extract_int(&buf[4], 8);
- remove_march(wc_roomname);
+ remove_march(WC->wc_roomname);
if (!strcasecmp(gname, "_BASEROOM_"))
remove_march(gname);
embed_room_banner(buf);
wDumpContent(1);
}
- strcpy(wc_roomname, wc_roomname);
+ strcpy(WC->wc_roomname, WC->wc_roomname);
}
* ...and remove the room we're currently in, so a <G>oto doesn't make us
* walk around in circles
*/
- remove_march(wc_roomname);
+ remove_march(WC->wc_roomname);
}
if (march != NULL) {
strcpy(next_room, pop_march(-1));
{
char buf[256];
- if (!strcmp(ugname, "")) {
- smart_goto(wc_roomname);
+ if (!strcmp(WC->ugname, "")) {
+ smart_goto(WC->wc_roomname);
return;
}
- serv_printf("GOTO %s", ugname);
+ serv_printf("GOTO %s", WC->ugname);
serv_gets(buf);
if (buf[0] != '2') {
- smart_goto(wc_roomname);
+ smart_goto(WC->wc_roomname);
return;
}
- if (uglsn >= 0L) {
- serv_printf("SLRP %ld", uglsn);
+ if (WC->uglsn >= 0L) {
+ serv_printf("SLRP %ld", WC->uglsn);
serv_gets(buf);
}
- strcpy(buf, ugname);
- strcpy(ugname, "");
+ strcpy(buf, WC->ugname);
+ strcpy(WC->ugname, "");
smart_goto(buf);
}
display_main_menu();
return;
}
- strcpy(hold_rm, wc_roomname);
+ strcpy(hold_rm, WC->wc_roomname);
strcpy(buf, "GOTO ");
strcat(buf, bstr("gr_name"));
strcat(buf, "|");
wprintf("<B>Zap (forget) the current room</B>\n");
wprintf("</FONT></TD></TR></TABLE>\n");
- wprintf("If you select this option, <em>%s</em> will ", wc_roomname);
+ wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
wprintf("disappear from your room list. Is this what you wish ");
wprintf("to do?<BR>\n");
/* If the forget-room routine fails for any reason, we fall back
* to the current room; otherwise, we go to the Lobby
*/
- strcpy(final_destination, wc_roomname);
+ strcpy(final_destination, WC->wc_roomname);
if (!strcasecmp(bstr("sc"), "OK")) {
- serv_printf("GOTO %s", wc_roomname);
+ serv_printf("GOTO %s", WC->wc_roomname);
serv_gets(buf);
if (buf[0] != '2') {
ExpressMessageCat(&buf[4]);
wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
wprintf("Are you sure you want to delete <FONT SIZE=+1>");
- escputs(wc_roomname);
+ escputs(WC->wc_roomname);
wprintf("</FONT>?<BR>\n");
wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
struct serv_info serv_info;
/*
- * get info about the server we've connected to
+ * get info about the server we've WC->connected to
*/
void get_serv_info(char *browser_host, char *user_agent)
{
serv_puts("000");
if (regoto) {
- smart_goto(wc_roomname);
+ smart_goto(WC->wc_roomname);
} else {
printf("HTTP/1.0 200 OK\n");
output_headers(1);
extern int errno;
-int serv_sock;
-
-
RETSIGTYPE timeout(int signum)
{
fprintf(stderr, "Connection timed out.\n");
len = 0;
while (len < bytes) {
- rlen = read(serv_sock, &buf[len], bytes - len);
+ rlen = read(WC->serv_sock, &buf[len], bytes - len);
if (rlen < 1) {
fprintf(stderr, "Server connection broken: %s\n",
strerror(errno));
- connected = 0;
- logged_in = 0;
+ WC->connected = 0;
+ WC->logged_in = 0;
return;
}
len = len + rlen;
int bytes_written = 0;
int retval;
while (bytes_written < nbytes) {
- retval = write(serv_sock, &buf[bytes_written],
+ retval = write(WC->serv_sock, &buf[bytes_written],
nbytes - bytes_written);
if (retval < 1) {
fprintf(stderr, "Server connection broken: %s\n",
strerror(errno));
- connected = 0;
- logged_in = 0;
+ WC->connected = 0;
+ WC->logged_in = 0;
return;
}
bytes_written = bytes_written + retval;
#include "child.h"
#include "mime_parser.h"
-int wc_session;
-char wc_username[256];
-char wc_password[256];
-char wc_roomname[256];
int TransactionCount = 0;
-int connected = 0;
-int logged_in = 0;
-int axlevel;
char *ExpressMessages = NULL;
-int new_mail = 0;
-int need_vali = 0;
/* This variable is set to 1 if the room banner and menubar have been
* displayed, and we need to close the <TABLE> tags.
static const char *defaulthost = DEFAULT_HOST;
static const char *defaultport = DEFAULT_PORT;
-int upload_length = 0;
-char *upload;
+struct wcsession *WC = NULL; /* FIX take this out when multithreaded */
+
void unescape_input(char *buf)
{
int a, b;
printf("Pragma: no-cache\n");
printf("Cache-Control: no-store\n");
}
- stuff_to_cookie(cookie, wc_session, wc_username,
- wc_password, wc_roomname);
+ stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
+ WC->wc_password, WC->wc_roomname);
if (print_standard_html_head == 2) {
printf("X-WebCit-Session: close\n");
printf("Set-cookie: webcit=%s\n", unset);
fprintf(stderr, " length = %d\n", length);
if (strlen(name) > 0) {
- upload = malloc(length);
- if (upload != NULL) {
- upload_length = length;
- memcpy(upload, content, length);
+ WC->upload = malloc(length);
+ if (WC->upload != NULL) {
+ WC->upload_length = length;
+ memcpy(WC->upload, content, length);
}
}
}
strcpy(c_password, "");
strcpy(c_roomname, "");
- upload_length = 0;
- upload = NULL;
+ WC->upload_length = 0;
+ WC->upload = NULL;
if (getz(cmd) == NULL)
return;
cmd[a] = 0;
}
/*
- * If we're not connected to a Citadel server, try to hook up the
+ * If we're not WC->connected to a Citadel server, try to hook up the
* connection now. Preference is given to the host and port specified
* by browser cookies, if cookies have been supplied.
*/
- if (!connected) {
+ if (!WC->connected) {
if (strlen(bstr("host")) > 0)
strcpy(c_host, bstr("host"));
if (strlen(bstr("port")) > 0)
strcpy(c_port, bstr("port"));
- serv_sock = connectsock(c_host, c_port, "tcp");
- if (serv_sock < 0) {
+ WC->serv_sock = connectsock(c_host, c_port, "tcp");
+ if (WC->serv_sock < 0) {
do_logout();
}
- connected = 1;
+ WC->connected = 1;
serv_gets(buf); /* get the server welcome message */
get_serv_info(browser_host, user_agent);
}
* If we're not logged in, but we have username and password cookies
* supplied by the browser, try using them to log in.
*/
- if ((!logged_in) && (strlen(c_username) > 0) && (strlen(c_password) > 0)) {
+ if ((!WC->logged_in) && (strlen(c_username) > 0) && (strlen(c_password) > 0)) {
serv_printf("USER %s", c_username);
serv_gets(buf);
if (buf[0] == '3') {
* If we don't have a current room, but a cookie specifying the
* current room is supplied, make an effort to go there.
*/
- if ((strlen(wc_roomname) == 0) && (strlen(c_roomname) > 0)) {
+ if ((strlen(WC->wc_roomname) == 0) && (strlen(c_roomname) > 0)) {
serv_printf("GOTO %s", c_roomname);
serv_gets(buf);
if (buf[0] == '2') {
- strcpy(wc_roomname, c_roomname);
+ strcpy(WC->wc_roomname, c_roomname);
}
}
if (!strcasecmp(action, "static")) {
output_static(buf);
} else if (!strcasecmp(action, "image")) {
output_image();
- } else if ((!logged_in) && (!strcasecmp(action, "login"))) {
+ } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
do_login();
- } else if (!logged_in) {
+ } else if (!WC->logged_in) {
display_login(NULL);
}
/* Various commands... */
} else if (!strcasecmp(action, "editinfo")) {
save_edit("Room info", "EINF 1", 1);
} else if (!strcasecmp(action, "display_editbio")) {
- sprintf(buf, "RBIO %s", wc_username);
+ sprintf(buf, "RBIO %s", WC->wc_username);
display_edit("Your bio", "NOOP", buf, "editbio");
} else if (!strcasecmp(action, "editbio")) {
save_edit("Your bio", "EBIO", 0);
output_headers(1);
wprintf("TransactionCount is %d<BR>\n", TransactionCount);
- wprintf("You're in session %d<HR>\n", wc_session);
+ wprintf("You're in session %d<HR>\n", WC->wc_session);
wprintf("Command: <BR><PRE>\n");
escputs(cmd);
wprintf("</PRE><HR>\n");
content = NULL;
}
free_urls();
- if (upload_length > 0) {
- free(upload);
- upload_length = 0;
+ if (WC->upload_length > 0) {
+ free(WC->upload);
+ WC->upload_length = 0;
}
}
return 1;
}
- wc_session = atoi(argv[1]);
+ WC = (struct wcsession *) malloc(sizeof(struct wcsession));
+ memset(WC, 0, sizeof(struct wcsession));
+
+
+
+ WC->wc_session = atoi(argv[1]);
defaulthost = argv[2];
defaultport = argv[3];
- strcpy(wc_username, "");
- strcpy(wc_password, "");
- strcpy(wc_roomname, "");
+ strcpy(WC->wc_username, "");
+ strcpy(WC->wc_password, "");
+ strcpy(WC->wc_roomname, "");
/* Clear out serv_info and temporarily set the value of serv_humannode
* to a default value, because it'll be used in HTML page titles
int serv_ok_floors;
};
-extern char wc_username[256];
-extern char wc_password[256];
-extern char wc_roomname[256];
-extern int connected;
-extern int logged_in;
-extern int axlevel;
-extern int is_aide;
-extern int is_room_aide;
-extern int serv_sock;
-extern struct serv_info serv_info;
-extern unsigned room_flags;
-extern char ugname[128];
-extern long uglsn;
-extern char *axdefs[];
-extern int upload_length;
-extern char *upload;
+struct wcsession {
+ int wc_session;
+ char wc_username[256];
+ char wc_password[256];
+ char wc_roomname[256];
+ int connected;
+ int logged_in;
+ int axlevel;
+ int is_aide;
+ int is_room_aide;
+ int serv_sock;
+ struct serv_info serv_info;
+ unsigned room_flags;
+ char ugname[128];
+ long uglsn;
+ int upload_length;
+ char *upload;
+ int new_mail;
+ int need_vali;
+};
+
+extern struct wcsession *WC;
+
+struct serv_info serv_info;
extern char floorlist[128][256];
-extern int new_mail;
-extern int need_vali;
+extern char *axdefs[];
void stuff_to_cookie(char *, int, char *, char *, char *);
void cookie_to_stuff(char *, int *, char *, char *, char *);
while (wlist != NULL) {
wprintf("<TR>\n\t<TD ALIGN=center><FONT FACE=\"Arial,Helvetica,sans-serif\">%d", wlist->sessionnum);
- if ((is_aide) &&
+ if ((WC->is_aide) &&
(wlist->sessionnum != serv_info.serv_pid)) {
wprintf(" <A HREF=\"/terminate_session&which_session=%d&session_owner=", wlist->sessionnum);
urlescputs(wlist->username);
wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change host name\">");
wprintf("</FONT></TD>\n</TR>\n");
- if (is_aide) {
+ if (WC->is_aide) {
wprintf("<TR><TD><FONT FACE=\"Arial,Helvetica,sans-serif\"><B>User name:</B></FONT></TD><TD>");
wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"text\" NAME=\"fake_username\" MAXLENGTH=\"64\">\n");
wprintf("</FONT></TD>\n<TD ALIGN=center>");