* webcit.c: added to getz() the ability to return an error code;
implemented this in the main loop, hopefully fixing problems
* Added "braindamage" file (frames/JS browser compatibility list)
- * Added HTTP "User-agent:" detection (still need to DO SOMETHING)
+ * Added HTTP "User-agent:" detection
+ * wildmat.c, braindamage.c: added
1999-02-24 Nathan Bryant <bryant@cs.usm.maine.edu>
* context_loop.c: warning fix
webcit: webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \
roomops.o tools.o messages.o userlist.o paging.o sysmsgs.o \
- mime_parser.o graphics.o netconf.o cookie_conversion.o siteconfig.o
+ mime_parser.o graphics.o netconf.o cookie_conversion.o siteconfig.o \
+ wildmat.o braindamage.o
$(CC) webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \
tools.o roomops.o messages.o userlist.o paging.o sysmsgs.o siteconfig.o \
- mime_parser.o graphics.o netconf.o cookie_conversion.o -o webcit
+ mime_parser.o graphics.o netconf.o cookie_conversion.o \
+ wildmat.o braindamage.o -o webcit
webcit.o: webcit.c webcit.h child.h
$(CC) $(CFLAGS) $(DEFS) -c webcit.c
locate_host.o: locate_host.c webcit.h child.h
$(CC) $(CFLAGS) $(DEFS) -c locate_host.c
+wildmat.o: wildmat.c webcit.h child.h
+ $(CC) $(CFLAGS) $(DEFS) -c wildmat.c
+
+braindamage.o: braindamage.c webcit.h child.h
+ $(CC) $(CFLAGS) $(DEFS) -c braindamage.c
+
Makefile: $(srcdir)/Makefile.in config.status
CONFIG_FILES=Makefile CONFIG_HEADERS= $(SHELL) ./config.status
#include "webcit.h"
#include "child.h"
-char *axdefs[] = {
+char *axdefs[] =
+{
"Deleted",
"New User",
"Problem User",
"Network User",
"Preferred User",
"Aide"
- };
+};
/*
* Display the login screen
*/
-void display_login(char *mesg) {
+void display_login(char *mesg)
+{
char buf[256];
printf("HTTP/1.0 200 OK\n");
if (mesg != NULL) {
wprintf("<font size=+1><b>%s</b></font>", mesg);
- }
- else {
+ } else {
serv_puts("MESG hello");
serv_gets(buf);
- if (buf[0]=='1') fmout(NULL);
- }
+ if (buf[0] == '1')
+ fmout(NULL);
+ }
wprintf("</CENTER></TD></TR></TABLE></CENTER>\n");
wprintf("<HR>\n");
wprintf("<TD><INPUT TYPE=\"password\" NAME=\"pass\" MAXLENGTH=\"20\"></TD>\n");
wprintf("</TR></TABLE>\n");
wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Login\">\n");
- wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"New User\">\n");
- wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Exit\">\n");
-
+ wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"New User\">\n");
+ wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Exit\">\n");
+
wprintf("<BR><INPUT TYPE=\"checkbox\" NAME=\"noframes\">");
wprintf("<FONT SIZE=-1> Check here to disable frames</FONT>\n");
- wprintf("</FORM></CENTER>\n");
+ wprintf("</FORM></CENTER>\n");
/* Da instructions */
wprintf("<LI><EM>If you already have an account on %s,",
wprintf("\"New User.\"<BR><LI>");
wprintf("<EM>Please log off properly when finished.</EM>");
wprintf("<LI>You must use a browser that supports <i>cookies</i>.<BR>\n");
- wprintf("<LI>Your browser is: ");
- escputs(browser);
wprintf("</EM></UL>\n");
wDumpContent(1);
- }
+}
/*
* This function needs to get called whenever a PASS or NEWU succeeds.
*/
-void become_logged_in(char *user, char *pass, char *serv_response) {
+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;
- }
+ if (axlevel >= 6)
+ is_aide = 1;
+}
-void do_login(void) {
+void do_login(void)
+{
char buf[256];
int need_regi = 0;
if (!strcasecmp(bstr("action"), "Exit")) {
do_logout();
- }
-
+ }
if (!strcasecmp(bstr("action"), "Login")) {
serv_printf("USER %s", bstr("name"));
serv_gets(buf);
- if (buf[0]=='3') {
+ if (buf[0] == '3') {
serv_printf("PASS %s", bstr("pass"));
serv_gets(buf);
- if (buf[0]=='2') {
+ if (buf[0] == '2') {
become_logged_in(bstr("name"),
- bstr("pass"), buf);
- }
- else {
+ bstr("pass"), buf);
+ } else {
display_login(&buf[4]);
return;
- }
}
- else {
+ } else {
display_login(&buf[4]);
return;
- }
}
-
+ }
if (!strcasecmp(bstr("action"), "New User")) {
serv_printf("NEWU %s", bstr("name"));
serv_gets(buf);
- if (buf[0]=='2') {
+ if (buf[0] == '2') {
become_logged_in(bstr("name"), bstr("pass"), buf);
serv_printf("SETP %s", bstr("pass"));
serv_gets(buf);
- }
- else {
+ } else {
display_login(&buf[4]);
return;
- }
}
-
+ }
if (logged_in) {
serv_puts("CHEK");
serv_gets(buf);
- if (buf[0]=='2') {
+ if (buf[0] == '2') {
need_regi = extract_int(&buf[4], 1);
/* FIX also check for new mail etc. here */
- }
+ }
if (need_regi) {
display_reg(1);
- }
- else {
+ } else {
do_welcome();
- }
}
- else {
+ } else {
display_login("Your password was not accepted.");
- }
-
}
-void do_welcome(void) {
+}
+
+void do_welcome(void)
+{
if (noframes) {
printf("HTTP/1.0 200 OK\n");
wprintf("</H1>\n");
/* FIX add user stats here */
wDumpContent(1);
- }
-
- else {
+ } else {
output_static("frameset.html");
- }
}
+}
-void do_logout(void) {
+void do_logout(void)
+{
char buf[256];
strcpy(wc_username, "");
printf("HTTP/1.0 200 OK\n");
output_headers(2, "_top"); /* note "2" causes cookies to be unset */
- wprintf("<CENTER>");
+ wprintf("<CENTER>");
serv_puts("MESG goodbye");
serv_gets(buf);
- if (buf[0]=='1') fmout(NULL);
- else wprintf("Goodbye\n");
+ if (buf[0] == '1')
+ fmout(NULL);
+ else
+ wprintf("Goodbye\n");
wprintf("<HR><A HREF=\"/\">Log in again</A></CENTER>\n");
wDumpContent(2);
serv_puts("QUIT");
exit(0);
- }
+}
/*
* validate new users
*/
-void validate(void) {
+void validate(void)
+{
char cmd[256];
char user[256];
char buf[256];
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
- strcpy(buf,bstr("user"));
- if (strlen(buf)>0) if (strlen(bstr("axlevel"))>0) {
- serv_printf("VALI %s|%s",buf,bstr("axlevel"));
- serv_gets(buf);
- if (buf[0]!='2') {
- wprintf("<EM>%s</EM><BR>\n", &buf[4]);
+ strcpy(buf, bstr("user"));
+ if (strlen(buf) > 0)
+ if (strlen(bstr("axlevel")) > 0) {
+ serv_printf("VALI %s|%s", buf, bstr("axlevel"));
+ serv_gets(buf);
+ if (buf[0] != '2') {
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
}
}
-
serv_puts("GNUR");
serv_gets(buf);
- if (buf[0]!='3') {
+ if (buf[0] != '3') {
wprintf("<EM>%s</EM><BR>\n", &buf[4]);
wDumpContent(1);
return;
- }
-
- strcpy(user,&buf[4]);
- serv_printf("GREG %s",user);
+ }
+ strcpy(user, &buf[4]);
+ serv_printf("GREG %s", user);
serv_gets(cmd);
- if (cmd[0]=='1') {
+ if (cmd[0] == '1') {
a = 0;
do {
serv_gets(buf);
++a;
- if (a==1) wprintf("User #%s<BR><H1>%s</H1>",
- buf,&cmd[4]);
- if (a==2) wprintf("PW: %s<BR>\n",buf);
- if (a==3) wprintf("%s<BR>\n",buf);
- if (a==4) wprintf("%s<BR>\n",buf);
- if (a==5) wprintf("%s, ",buf);
- if (a==6) wprintf("%s ",buf);
- if (a==7) wprintf("%s<BR>\n",buf);
- if (a==8) wprintf("%s<BR>\n",buf);
- if (a==9) wprintf("Current access level: %d (%s)\n",
- atoi(buf),axdefs[atoi(buf)]);
- } while(strcmp(buf,"000"));
- }
- else {
- wprintf("<H1>%s</H1>%s<BR>\n",user,&cmd[4]);
- }
+ if (a == 1)
+ wprintf("User #%s<BR><H1>%s</H1>",
+ buf, &cmd[4]);
+ if (a == 2)
+ wprintf("PW: %s<BR>\n", buf);
+ if (a == 3)
+ wprintf("%s<BR>\n", buf);
+ if (a == 4)
+ wprintf("%s<BR>\n", buf);
+ if (a == 5)
+ wprintf("%s, ", buf);
+ if (a == 6)
+ wprintf("%s ", buf);
+ if (a == 7)
+ wprintf("%s<BR>\n", buf);
+ if (a == 8)
+ wprintf("%s<BR>\n", buf);
+ if (a == 9)
+ wprintf("Current access level: %d (%s)\n",
+ atoi(buf), axdefs[atoi(buf)]);
+ } while (strcmp(buf, "000"));
+ } else {
+ wprintf("<H1>%s</H1>%s<BR>\n", user, &cmd[4]);
+ }
wprintf("<CENTER><TABLE border><CAPTION>Select access level:");
wprintf("</CAPTION><TR>");
- for (a=0; a<=6; ++a) {
+ for (a = 0; a <= 6; ++a) {
wprintf(
- "<TD><A HREF=\"/validate&user=%s&axlevel=%d\">%s</A></TD>\n",
- urlesc(user), a, axdefs[a]);
- }
+ "<TD><A HREF=\"/validate&user=%s&axlevel=%d\">%s</A></TD>\n",
+ urlesc(user), a, axdefs[a]);
+ }
wprintf("</TR></TABLE><CENTER><BR>\n");
wDumpContent(1);
- }
+}
* (Set during_login to 1 if this registration is being performed during
* new user login and will require chaining to the proper screen.)
*/
-void display_reg(int during_login) {
+void display_reg(int during_login)
+{
char buf[256];
int a;
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Enter registration info</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Enter registration info</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
wprintf("<CENTER>");
serv_puts("MESG register");
serv_gets(buf);
- if (buf[0]=='1') fmout(NULL);
+ if (buf[0] == '1')
+ fmout(NULL);
wprintf("<FORM ACTION=\"/register\" METHOD=\"POST\">\n");
wprintf("<INPUT TYPE=\"hidden\" NAME=\"during_login\" VALUE=\"%d\">\n", during_login);
serv_puts("GREG _SELF_");
serv_gets(buf);
- if (buf[0]!='1') {
- wprintf("<EM>%s</EM><BR>\n",&buf[4]);
- }
- else {
-
- wprintf("<H1>%s</H1><TABLE border>\n",&buf[4]);
+ if (buf[0] != '1') {
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
+ } else {
+
+ wprintf("<H1>%s</H1><TABLE border>\n", &buf[4]);
a = 0;
- while (serv_gets(buf), strcmp(buf,"000")) {
+ while (serv_gets(buf), strcmp(buf, "000")) {
++a;
wprintf("<TR><TD>");
- switch(a) {
- case 3: wprintf("Real Name:</TD><TD><INPUT TYPE=\"text\" NAME=\"realname\" VALUE=\"%s\" MAXLENGTH=\"29\"><BR>\n",buf);
- break;
- case 4: wprintf("Street Address:</TD><TD><INPUT TYPE=\"text\" NAME=\"address\" VALUE=\"%s\" MAXLENGTH=\"24\"><BR>\n",buf);
- break;
- case 5: wprintf("City/town:</TD><TD><INPUT TYPE=\"text\" NAME=\"city\" VALUE=\"%s\" MAXLENGTH=\"14\"><BR>\n",buf);
- break;
- case 6: wprintf("State/province:</TD><TD><INPUT TYPE=\"text\" NAME=\"state\" VALUE=\"%s\" MAXLENGTH=\"2\"><BR>\n",buf);
- break;
- case 7: wprintf("ZIP code:</TD><TD><INPUT TYPE=\"text\" NAME=\"zip\" VALUE=\"%s\" MAXLENGTH=\"10\"><BR>\n",buf);
- break;
- case 8: wprintf("Telephone:</TD><TD><INPUT TYPE=\"text\" NAME=\"phone\" VALUE=\"%s\" MAXLENGTH=\"14\"><BR>\n",buf);
- break;
- case 9: wprintf("E-Mail:</TD><TD><INPUT TYPE=\"text\" NAME=\"email\" VALUE=\"%s\" MAXLENGTH=\"31\"><BR>\n",buf);
- break;
- }
- wprintf("</TD></TR>\n");
+ switch (a) {
+ case 3:
+ wprintf("Real Name:</TD><TD><INPUT TYPE=\"text\" NAME=\"realname\" VALUE=\"%s\" MAXLENGTH=\"29\"><BR>\n", buf);
+ break;
+ case 4:
+ wprintf("Street Address:</TD><TD><INPUT TYPE=\"text\" NAME=\"address\" VALUE=\"%s\" MAXLENGTH=\"24\"><BR>\n", buf);
+ break;
+ case 5:
+ wprintf("City/town:</TD><TD><INPUT TYPE=\"text\" NAME=\"city\" VALUE=\"%s\" MAXLENGTH=\"14\"><BR>\n", buf);
+ break;
+ case 6:
+ wprintf("State/province:</TD><TD><INPUT TYPE=\"text\" NAME=\"state\" VALUE=\"%s\" MAXLENGTH=\"2\"><BR>\n", buf);
+ break;
+ case 7:
+ wprintf("ZIP code:</TD><TD><INPUT TYPE=\"text\" NAME=\"zip\" VALUE=\"%s\" MAXLENGTH=\"10\"><BR>\n", buf);
+ break;
+ case 8:
+ wprintf("Telephone:</TD><TD><INPUT TYPE=\"text\" NAME=\"phone\" VALUE=\"%s\" MAXLENGTH=\"14\"><BR>\n", buf);
+ break;
+ case 9:
+ wprintf("E-Mail:</TD><TD><INPUT TYPE=\"text\" NAME=\"email\" VALUE=\"%s\" MAXLENGTH=\"31\"><BR>\n", buf);
+ break;
}
- wprintf("</TABLE><P>");
+ wprintf("</TD></TR>\n");
}
+ wprintf("</TABLE><P>");
+ }
wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Register\">\n");
wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n");
wprintf("</CENTER>\n");
wDumpContent(1);
- }
+}
/*
* register
*/
-void register_user(void) {
+void register_user(void)
+{
char buf[256];
-
- if (strcmp(bstr("action"),"Register")) {
+
+ if (strcmp(bstr("action"), "Register")) {
display_error("Cancelled. Registration was not saved.");
return;
- }
-
+ }
serv_puts("REGI");
serv_gets(buf);
- if (buf[0]!='4') {
+ if (buf[0] != '4') {
display_error(&buf[4]);
- }
-
+ }
serv_puts(bstr("realname"));
serv_puts(bstr("address"));
serv_puts(bstr("city"));
serv_puts(bstr("phone"));
serv_puts(bstr("email"));
serv_puts("000");
-
+
if (atoi(bstr("during_login"))) {
do_welcome();
- }
- else {
+ } else {
display_error("Registration information has been saved.");
- }
}
+}
/*
* display form for changing your password
*/
-void display_changepw(void) {
+void display_changepw(void)
+{
char buf[256];
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Change your password</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Change your password</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
wprintf("<CENTER>");
serv_puts("MESG changepw");
serv_gets(buf);
- if (buf[0]=='1') fmout(NULL);
+ if (buf[0] == '1')
+ fmout(NULL);
wprintf("<FORM ACTION=\"changepw\" METHOD=\"POST\">\n");
wprintf("<CENTER><TABLE border><TR><TD>Enter new password:</TD>\n");
wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
wprintf("<TR><TD>Enter it again to confirm:</TD>\n");
wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
- wprintf("</TABLE>\n");
+ wprintf("</TABLE>\n");
wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Change\">\n");
wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n");
wprintf("</CENTER>\n");
wDumpContent(1);
- }
+}
/*
* change password
*/
-void changepw(void) {
+void changepw(void)
+{
char buf[256];
char newpass1[32], newpass2[32];
-
- if (strcmp(bstr("action"),"Change")) {
+
+ if (strcmp(bstr("action"), "Change")) {
display_error("Cancelled. Password was not changed.");
return;
- }
-
+ }
strcpy(newpass1, bstr("newpass1"));
strcpy(newpass2, bstr("newpass2"));
if (strcasecmp(newpass1, newpass2)) {
display_error("They don't match. Password was not changed.");
return;
- }
-
+ }
serv_printf("SETP %s", newpass1);
serv_gets(buf);
- if (buf[0]=='2') display_success(&buf[4]);
- else display_error(&buf[4]);
- }
+ if (buf[0] == '2')
+ display_success(&buf[4]);
+ else
+ display_error(&buf[4]);
+}
--- /dev/null
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <stdarg.h>
+#include "webcit.h"
+#include "child.h"
+
+/*
+ * browser_braindamage_check()
+ *
+ * Given the value of the HTTP "User-agent:" directive supplied by
+ * a web browser, determine using a local configuration file whether
+ * the browser is capable of handling WebCit's frames/JavaScript mode.
+ *
+ * This function returns one of the following values:
+ * B_YES (Yes, it's ok to use frames and JavaScript)
+ * B_NO (No, fall back to the noframes version)
+ * B_ASK (We don't know; ask the user)
+ */
+
+int browser_braindamage_check(char *browser)
+{
+ FILE *fp;
+ char buf[256];
+ int thisval;
+
+ fp = fopen("static/braindamage", "r");
+ if (fp == NULL)
+ return (B_ASK);
+
+ while (fgets(buf, 256, fp) != NULL) {
+ buf[strlen(buf)-1] = 0;
+ thisval = (-1);
+ if (!strncasecmp(buf, "YES", 3)) {
+ thisval = B_YES;
+ strcpy(buf, &buf[3]);
+ } else if (!strncasecmp(buf, "NO", 2)) {
+ thisval = B_NO;
+ strcpy(buf, &buf[2]);
+ } else if (!strncasecmp(buf, "ASK", 3)) {
+ thisval = B_ASK;
+ strcpy(buf, &buf[3]);
+ }
+ if (thisval >= 0) {
+ while (isspace(buf[0])) strcpy(buf, &buf[1]);
+ if (wildmat(buf, browser)) {
+ return(thisval);
+ }
+ }
+ }
+
+ fclose(fp);
+ return (B_ASK);
+}
void serv_gets(char *strbuf);
void serv_puts(char *string);
void whobbs(void);
-void fmout(FILE *fp);
+void fmout(FILE * fp);
void wDumpContent(int);
-void serv_printf(const char *format, ...);
+void serv_printf(const char *format,...);
char *bstr(char *key);
char *urlesc(char *);
void urlescputs(char *);
void output_headers(int, char *);
-void wprintf(const char *format, ...);
+void wprintf(const char *format,...);
void extract(char *dest, char *source, int parmnum);
int extract_int(char *source, int parmnum);
void output_static(char *what);
void server_to_text(void);
void save_edit(char *description, char *enter_cmd, int regoto);
void display_edit(char *description, char *check_cmd,
- char *read_cmd, char *save_cmd);
+ char *read_cmd, char *save_cmd);
void gotoroom(char *gname, int display_name);
void confirm_delete_room(void);
void delete_room(void);
void serv_gets(char *strbuf);
void serv_write(char *buf, int nbytes);
void serv_puts(char *string);
-void serv_printf(const char *format, ...);
+void serv_printf(const char *format,...);
void load_floorlist(void);
void select_floor_to_edit_pic(void);
void display_reg(int);
void siteconfig(void);
void display_generic(void);
void do_generic(void);
+int browser_braindamage_check(char *);
*/
struct wc_session {
struct wc_session *next; /* Next session in list */
- int session_id; /* Session ID */
- pid_t webcit_pid; /* PID of the webcit process */
- int inpipe[2]; /* Data from webserver to session */
- int outpipe[2]; /* Data from session to webserver */
+ int session_id; /* Session ID */
+ pid_t webcit_pid; /* PID of the webcit process */
+ int inpipe[2]; /* Data from webserver to session */
+ int outpipe[2]; /* Data from session to webserver */
pthread_mutex_t critter; /* Critical section uses pipes */
- time_t lastreq; /* Timestamp of most recent http */
- };
+ time_t lastreq; /* Timestamp of most recent http */
+};
struct wc_session *SessionList = NULL;
extern const char *defaulthost;
* Grab a lock on the session, so other threads don't try to access
* the pipes at the same time.
*/
-static void lock_session(struct wc_session *session) {
- printf("Locking session %d...\n", session->session_id);
- pthread_mutex_lock(&session->critter);
- printf(" ...got lock\n");
- }
+static void lock_session(struct wc_session *session)
+{
+ printf("Locking session %d...\n", session->session_id);
+ pthread_mutex_lock(&session->critter);
+ printf(" ...got lock\n");
+}
/*
* Let go of the lock.
*/
-static void unlock_session(struct wc_session *session) {
+static void unlock_session(struct wc_session *session)
+{
printf("Unlocking.\n");
pthread_mutex_unlock(&session->critter);
- }
+}
/*
* Remove a session context from the list
*/
-void remove_session(struct wc_session *TheSession, int do_lock) {
+void remove_session(struct wc_session *TheSession, int do_lock)
+{
struct wc_session *sptr;
printf("Removing session.\n");
- if (do_lock) pthread_mutex_lock(&MasterCritter);
+ if (do_lock)
+ pthread_mutex_lock(&MasterCritter);
- if (SessionList==TheSession) {
+ if (SessionList == TheSession) {
SessionList = SessionList->next;
- }
- else {
- for (sptr=SessionList; sptr!=NULL; sptr=sptr->next) {
+ } else {
+ for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
if (sptr->next == TheSession) {
sptr->next = TheSession->next;
- }
}
}
+ }
close(TheSession->inpipe[1]);
close(TheSession->outpipe[0]);
- if (do_lock) unlock_session(TheSession);
+ if (do_lock)
+ unlock_session(TheSession);
free(TheSession);
pthread_mutex_unlock(&MasterCritter);
- }
+}
-void do_housekeeping(void) {
+void do_housekeeping(void)
+{
struct wc_session *sptr;
pthread_mutex_lock(&MasterCritter);
/* Kill idle sessions */
- for (sptr=SessionList; sptr!=NULL; sptr=sptr->next) {
- if ((time(NULL) - (sptr->lastreq)) > (time_t)WEBCIT_TIMEOUT) {
+ for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
+ if ((time(NULL) - (sptr->lastreq)) > (time_t) WEBCIT_TIMEOUT) {
kill(sptr->webcit_pid, 15);
- }
}
+ }
/* Remove dead sessions */
- for (sptr=SessionList; sptr!=NULL; sptr=sptr->next) {
+ for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
if (kill(sptr->webcit_pid, 0)) {
remove_session(sptr, 0);
- }
}
+ }
pthread_mutex_unlock(&MasterCritter);
- }
+}
/*
* Wake up occasionally and clean house
*/
-void housekeeping_loop(void) {
- while(1) {
+void housekeeping_loop(void)
+{
+ while (1) {
sleep(HOUSEKEEPING);
do_housekeeping();
- }
}
+}
-int GenerateSessionID(void) {
+int GenerateSessionID(void)
+{
return getpid();
- }
+}
-void gets0(int fd, char buf[]) {
+void gets0(int fd, char buf[])
+{
buf[0] = 0;
do {
- buf[strlen(buf)+1] = 0;
+ buf[strlen(buf) + 1] = 0;
read(fd, &buf[strlen(buf)], 1);
- } while (buf[strlen(buf)-1] >= 32);
- buf[strlen(buf)-1] = 0;
- }
+ } while (buf[strlen(buf) - 1] >= 32);
+ buf[strlen(buf) - 1] = 0;
+}
/*
* Collapse multiple cookies on one line
*/
-void req_gets(int sock, char *buf, char *hold) {
+void req_gets(int sock, char *buf, char *hold)
+{
int a;
- if (strlen(hold)==0) {
+ if (strlen(hold) == 0) {
client_gets(sock, buf);
- }
- else {
+ } else {
strcpy(buf, hold);
- }
+ }
strcpy(hold, "");
if (!strncasecmp(buf, "Cookie: ", 8)) {
- for (a=0; a<strlen(buf); ++a) if (buf[a]==';') {
- sprintf(hold, "Cookie: %s", &buf[a+1]);
- buf[a]=0;
- while (isspace(hold[8])) strcpy(&hold[8], &hold[9]);
- return;
+ for (a = 0; a < strlen(buf); ++a)
+ if (buf[a] == ';') {
+ sprintf(hold, "Cookie: %s", &buf[a + 1]);
+ buf[a] = 0;
+ while (isspace(hold[8]))
+ strcpy(&hold[8], &hold[9]);
+ return;
}
- }
}
+}
/*
* lingering_close() a`la Apache. see
* http://www.apache.org/docs/misc/fin_wait_2.html for rationale
*/
-static int lingering_close(int fd) {
+static int lingering_close(int fd)
+{
char buf[256];
int i;
fd_set set;
if (tv.tv_usec < 0) {
tv.tv_sec--;
tv.tv_usec += 1000000;
- }
-
+ }
FD_ZERO(&set);
FD_SET(fd, &set);
i = select(fd + 1, &set, NULL, NULL, &tv);
- } while (i == -1 && errno == EINTR);
+ } while (i == -1 && errno == EINTR);
if (i <= 0)
break;
i = read(fd, buf, sizeof buf);
- } while (i != 0 && (i != -1 || errno == EINTR));
+ } while (i != 0 && (i != -1 || errno == EINTR));
return close(fd);
- }
+}
/*
* This loop gets called once for every HTTP connection made to WebCit.
*/
-void *context_loop(int sock) {
+void *context_loop(int sock)
+{
char (*req)[256];
char buf[256], hold[256];
char browser_host[256];
int ContentLength;
int CloseSession = 0;
- if ((req = malloc((long)sizeof(char[256][256]))) == NULL) {
+ if ((req = malloc((long) sizeof(char[256][256]))) == NULL) {
sprintf(buf, "Can't malloc buffers; dropping connection.\n");
fprintf(stderr, "%s", buf);
write(sock, buf, strlen(buf));
- close (sock);
+ close(sock);
pthread_exit(NULL);
- }
-
+ }
bzero(req, sizeof(char[256][256])); /* clear it out */
strcpy(browser, "unknown");
req_gets(sock, buf, hold);
if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
cookie_to_stuff(&buf[15], &desired_session, NULL, NULL, NULL, NULL);
- }
+ }
if (!strncasecmp(buf, "Content-length: ", 16)) {
ContentLength = atoi(&buf[16]);
- }
+ }
if (!strncasecmp(buf, "User-agent: ", 12)) {
strcpy(browser, &buf[12]);
- }
+ }
strcpy(&req[num_lines++][0], buf);
- } while(strlen(buf)>0);
+ } while (strlen(buf) > 0);
/*
* See if there's an existing session open with the desired ID
TheSession = NULL;
if (desired_session != 0) {
pthread_mutex_lock(&MasterCritter);
- for (sptr=SessionList; sptr!=NULL; sptr=sptr->next) {
+ for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
if (sptr->session_id == desired_session) {
TheSession = sptr;
lock_session(TheSession);
- }
}
- pthread_mutex_unlock(&MasterCritter);
}
-
+ pthread_mutex_unlock(&MasterCritter);
+ }
/*
* Before we trumpet to the universe that the session we're looking
* for actually exists, check first to make sure it's still there.
printf(" Session is *DEAD* !!\n");
remove_session(TheSession, 1);
TheSession = NULL;
- }
}
-
+ }
/*
* Create a new session if we have to
*/
locate_host(browser_host, sock);
pthread_mutex_lock(&MasterCritter);
TheSession = (struct wc_session *)
- malloc(sizeof(struct wc_session));
+ malloc(sizeof(struct wc_session));
TheSession->session_id = GenerateSessionID();
pipe(TheSession->inpipe);
pipe(TheSession->outpipe);
pthread_mutex_unlock(&MasterCritter);
sprintf(str_session, "%d", TheSession->session_id);
f = fork();
- if (f > 0) TheSession->webcit_pid = f;
-
- fflush(stdout); fflush(stdin);
- if (f==0) {
+ if (f > 0)
+ TheSession->webcit_pid = f;
+
+ fflush(stdout);
+ fflush(stdin);
+ if (f == 0) {
/* Hook stdio to the ends of the pipe we're using */
dup2(TheSession->inpipe[0], 0);
/* Close the ends of the pipes that we're not using */
close(TheSession->inpipe[1]);
close(TheSession->outpipe[0]);
-
+
/* Close the HTTP socket in this pid; don't need it */
close(sock);
printf("<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>\n");
printf("execlp() failed: %s</BODY></HTML>\n", strerror(errno));
exit(0);
- }
- else {
+ } else {
/* Close the ends of the pipes that we're not using */
close(TheSession->inpipe[0]);
close(TheSession->outpipe[1]);
- }
}
-
+ }
/*
* Send the request to the appropriate session...
*/
TheSession->lastreq = time(NULL);
printf(" Writing %d lines of command\n", num_lines);
printf("%s\n", &req[0][0]);
- for (a=0; a<num_lines; ++a) {
+ 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 > 0) {
a = ContentLength;
- if (a > sizeof buf) a = sizeof buf;
- if (!client_read(sock, buf, a)) goto end;
- if (write(TheSession->inpipe[1], buf, a) != a) goto end;
+ if (a > sizeof buf)
+ a = sizeof buf;
+ if (!client_read(sock, buf, a))
+ goto end;
+ if (write(TheSession->inpipe[1], buf, a) != a)
+ goto end;
ContentLength -= a;
- }
+ }
/*
* ...and get the response.
ContentLength = atoi(&buf[16]);
if (!strcasecmp(buf, "X-WebCit-Session: close")) {
CloseSession = 1;
- }
- } while (strlen(buf) > 0);
+ }
+ } while (strlen(buf) > 0);
printf(" Reading %d bytes of content\n", ContentLength);
- while(ContentLength--) {
+ while (ContentLength--) {
read(TheSession->outpipe[0], buf, 1);
write(sock, buf, 1);
- }
+ }
/*
* If the last response included a "close session" directive,
*/
if (CloseSession) {
remove_session(TheSession, 1);
- }
- else {
-end: unlock_session(TheSession);
- }
+ } else {
+ end:unlock_session(TheSession);
+ }
free(req);
- /*
- * 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 close.
- */
+ /*
+ * 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 close.
+ */
printf(" Closing socket %d ... ret=%d\n", sock,
lingering_close(sock));
* thing, and supresses a compiler warning.
*/
return NULL;
- }
+}
/*
* Pack all session info into one easy-to-digest cookie. Healthy and delicious!
*/
-void stuff_to_cookie(char *cookie, int session, char *user, char *pass, char *room, int nofr) {
+void stuff_to_cookie(char *cookie, int session, char *user, char *pass, char *room, int nofr)
+{
char buf[256];
int i;
sprintf(buf, "%d|%s|%s|%s|%d", session, user, pass, room, nofr);
strcpy(cookie, "");
-
- for (i=0; i<strlen(buf); ++i)
+
+ for (i = 0; i < strlen(buf); ++i)
sprintf(&cookie[strlen(cookie)], "%02X", buf[i]);
}
/*
* Extract all that fun stuff out of the cookie.
*/
-void cookie_to_stuff(char *cookie, int *session, char *user, char *pass, char *room, int *nofr) {
+void cookie_to_stuff(char *cookie, int *session, char *user, char *pass, char *room, int *nofr)
+{
char buf[256];
int i;
- for (i=0; i<strlen(cookie); i=i+2) {
- sscanf(&cookie[i], "%02x", (unsigned int *)&buf[i/2]);
- buf[(i/2)+1] = 0;
+ for (i = 0; i < strlen(cookie); i = i + 2) {
+ sscanf(&cookie[i], "%02x", (unsigned int *) &buf[i / 2]);
+ buf[(i / 2) + 1] = 0;
}
- if (session != NULL) *session = extract_int(buf, 0);
- if (user != NULL) extract(user, buf, 1);
- if (pass != NULL) extract(pass, buf, 2);
- if (room != NULL) extract(room, buf, 3);
- if (nofr != NULL) *nofr = extract_int(buf, 4);
+ if (session != NULL)
+ *session = extract_int(buf, 0);
+ if (user != NULL)
+ extract(user, buf, 1);
+ if (pass != NULL)
+ extract(pass, buf, 2);
+ if (room != NULL)
+ extract(room, buf, 3);
+ if (nofr != NULL)
+ *nofr = extract_int(buf, 4);
}
#include "child.h"
-void display_graphics_upload(char *description, char *check_cmd, char *uplurl) {
+void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
+{
char buf[256];
serv_puts(check_cmd);
if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
-
+ }
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Set/change %s</B>\n", description);
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Set/change %s</B>\n", description);
+ wprintf("</FONT></TD></TR></TABLE>\n");
wprintf("<CENTER>\n");
wprintf("<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"%s&which_room=%s\" METHOD=\"POST\">\n", uplurl, bstr("which_room"));
-
+
wprintf("You can upload any image directly from your computer,\n");
wprintf("as long as it is in GIF format (JPEG, PNG, etc. won't\n");
wprintf("work).<BR><BR>\n");
wprintf("Please select a file to upload:<BR>\n");
- wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
+ wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
wprintf("<BR>");
- wprintf("<INPUT TYPE=\"SUBMIT\" VALUE=\"Upload\">\n");
- wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
- wprintf("</FORM>\n");
+ wprintf("<INPUT TYPE=\"SUBMIT\" VALUE=\"Upload\">\n");
+ wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
+ wprintf("</FORM>\n");
wprintf("<A HREF=\"/display_main_menu\">Cancel</A>\n");
wprintf("</CENTER>\n");
wDumpContent(1);
- }
+}
-void do_graphics_upload(char *upl_cmd) {
+void do_graphics_upload(char *upl_cmd)
+{
char buf[256];
int bytes_remaining;
int pos = 0;
if (upload_length == 0) {
display_error("You didn't upload a file.\n");
return;
- }
-
+ }
serv_puts(upl_cmd);
serv_gets(buf);
if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
-
+ }
bytes_remaining = upload_length;
while (bytes_remaining) {
thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
serv_puts("UCLS 0");
serv_gets(buf);
return;
- }
+ }
thisblock = extract_int(&buf[4], 0);
serv_write(&upload[pos], thisblock);
pos = pos + thisblock;
bytes_remaining = bytes_remaining - thisblock;
- }
+ }
serv_puts("UCLS 1");
serv_gets(buf);
if (buf[0] != 'x') {
display_success(&buf[4]);
return;
- }
}
+}
-void select_floor_to_edit_pic(void) {
+void select_floor_to_edit_pic(void)
+{
int a;
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Select floor to edit label graphic</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Select floor to edit label graphic</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
load_floorlist();
- for (a=0; a<128; ++a) if (strlen(floorlist[a])>0) {
- wprintf("<A HREF=\"/display_editfloorpic&which_floor=%d\">", a);
- escputs(floorlist[a]);
- wprintf("</A>\n");
+ for (a = 0; a < 128; ++a)
+ if (strlen(floorlist[a]) > 0) {
+ wprintf("<A HREF=\"/display_editfloorpic&which_floor=%d\">", a);
+ escputs(floorlist[a]);
+ wprintf("</A>\n");
}
-
wDumpContent(1);
- }
+}
void locate_host(char *tbuf, int client_socket)
{
- struct sockaddr_in cs;
- struct hostent * ch;
- int len;
+ struct sockaddr_in cs;
+ struct hostent *ch;
+ int len;
char *i;
- int a1,a2,a3,a4;
-
- len = sizeof(cs);
- if (getpeername(client_socket, (struct sockaddr *)&cs,&len) < 0) {
- strcpy(tbuf, "<unknown>");
- return;
+ int a1, a2, a3, a4;
+
+ len = sizeof(cs);
+ if (getpeername(client_socket, (struct sockaddr *) &cs, &len) < 0) {
+ strcpy(tbuf, "<unknown>");
+ return;
}
-
- if((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),
- AF_INET)) == NULL) {
+ if ((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),
+ AF_INET)) == NULL) {
i = (char *) &cs.sin_addr;
- a1 = ((*i++)&0xff);
- a2 = ((*i++)&0xff);
- a3 = ((*i++)&0xff);
- a4 = ((*i++)&0xff);
- sprintf(tbuf,"%d.%d.%d.%d",a1,a2,a3,a4);
+ a1 = ((*i++) & 0xff);
+ a2 = ((*i++) & 0xff);
+ a3 = ((*i++) & 0xff);
+ a4 = ((*i++) & 0xff);
+ sprintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
return;
- }
-
- strncpy(tbuf,ch->h_name, 24);
- tbuf[24] = 0;
}
+ strncpy(tbuf, ch->h_name, 24);
+ tbuf[24] = 0;
+}
* menu of commands (just the menu html itself)
*/
-void embed_main_menu(void) {
+void embed_main_menu(void)
+{
wprintf("<CENTER><TABLE border=0><TR>");
wprintf("<TD>"); /* start of first column */
wprintf("<LI><B><A HREF=\"/knrooms\">\n");
wprintf("List known rooms</B></A><BR>\n");
wprintf("Where can I go from here?</LI>\n");
-
+
wprintf("<LI><B><A HREF=\"/gotonext\">\n");
wprintf("Goto next room</B></A><BR>\n");
wprintf("...with <EM>unread</EM> messages</LI>\n");
-
+
wprintf("<LI><B><A HREF=\"/skip\">\n");
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(ugname) > 0) && (strcasecmp(ugname, 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", ugname);
+ }
wprintf("</UL>\n");
-
- wprintf("</TD><TD>\n"); /* start of second column */
-
+
+ wprintf("</TD><TD>\n"); /* start of second column */
+
wprintf("<UL>");
wprintf("<LI><B><A HREF=\"/readnew\">\n");
wprintf("Read new messages</B></A><BR>...in this room</LI>\n");
-
+
wprintf("<LI><B><A HREF=\"/readfwd\">\n");
wprintf("Read all messages</B></A><BR>...old <EM>and</EM> new</LI>\n");
wprintf("Enter a message</B></A><BR>(post in this room)</LI>");
wprintf("</UL>\n");
- wprintf("</TD><TD>"); /* start of third column */
+ wprintf("</TD><TD>"); /* start of third column */
wprintf("<UL>");
wprintf("<LI><B><A HREF=\"/whobbs\">\n");
wprintf("Who is online?</B></A><BR>(users <EM>currently</EM> logged on)</LI>\n");
-
+
wprintf("<LI><B><A HREF=\"/userlist\">\n");
wprintf("User list</B></A><BR>(all registered users)</LI>\n");
wprintf("</TR></TABLE>\n");
wprintf("</CENTER>\n");
- }
+}
/*
* advanced options
*/
-void embed_advanced_menu(void) {
+void embed_advanced_menu(void)
+{
-wprintf("<TABLE WIDTH=100%><TR VALIGN=TOP><TD>");
+ wprintf("<TABLE WIDTH=100%><TR VALIGN=TOP><TD>");
-wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
-wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
-wprintf("<B>Interaction</B>\n");
-wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Interaction</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
-wprintf("<UL>");
-wprintf("<LI><A HREF=\"/display_page\">\n");
-wprintf("Page another user</A>\n");
+ wprintf("<UL>");
+ wprintf("<LI><A HREF=\"/display_page\">\n");
+ wprintf("Page another user</A>\n");
-wprintf("<LI><A HREF=\"/chat\">");
-wprintf("Chat with other online users</A>\n");
+ wprintf("<LI><A HREF=\"/chat\">");
+ wprintf("Chat with other online users</A>\n");
-wprintf("<LI><A HREF=\"/display_generic\">\n");
-wprintf("<FONT SIZE=-2>Generic server command</FONT></A>\n");
+ wprintf("<LI><A HREF=\"/display_generic\">\n");
+ wprintf("<FONT SIZE=-2>Generic server command</FONT></A>\n");
-wprintf("</UL>\n");
+ wprintf("</UL>\n");
-wprintf("</TD><TD>");
+ wprintf("</TD><TD>");
-wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
-wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
-wprintf("<B>Your info</B>\n");
-wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Your info</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
-wprintf("<UL>");
-wprintf("<LI><A HREF=\"/display_editbio\">\n");
-wprintf("Enter your 'bio' (a few words about yourself)</A>\n");
+ wprintf("<UL>");
+ wprintf("<LI><A HREF=\"/display_editbio\">\n");
+ wprintf("Enter your 'bio' (a few words about yourself)</A>\n");
-wprintf("<LI><A HREF=\"/display_editpic\">\n");
-wprintf("Edit your online photo</A>\n");
+ wprintf("<LI><A HREF=\"/display_editpic\">\n");
+ wprintf("Edit your online photo</A>\n");
-wprintf("<LI><A HREF=\"/display_reg\">\n");
-wprintf("Re-enter your registration info (name, address, etc.)</A>\n");
+ wprintf("<LI><A HREF=\"/display_reg\">\n");
+ wprintf("Re-enter your registration info (name, address, etc.)</A>\n");
-wprintf("<LI><A HREF=\"/display_changepw\">\n");
-wprintf("Change your password</A>\n");
+ wprintf("<LI><A HREF=\"/display_changepw\">\n");
+ wprintf("Change your password</A>\n");
-wprintf("</UL>\n");
+ wprintf("</UL>\n");
-wprintf("</TD></TR><TR VALIGN=TOP><TD>");
+ wprintf("</TD></TR><TR VALIGN=TOP><TD>");
-wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
-wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
-wprintf("<B>Advanced room commands</B>\n");
-wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Advanced room commands</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
-wprintf("<UL>");
-wprintf("<LI><A HREF=\"/display_private\">\n");
-wprintf("Go to a 'hidden' room</A>\n");
+ wprintf("<UL>");
+ wprintf("<LI><A HREF=\"/display_private\">\n");
+ wprintf("Go to a 'hidden' room</A>\n");
-wprintf("<LI><A HREF=\"/display_entroom\">");
-wprintf("Create a new room</A>\n");
+ wprintf("<LI><A HREF=\"/display_entroom\">");
+ wprintf("Create a new room</A>\n");
-wprintf("<LI><A HREF=\"/display_zap\">");
-wprintf("Zap (forget) this room (%s)</A>\n", wc_roomname);
+ wprintf("<LI><A HREF=\"/display_zap\">");
+ wprintf("Zap (forget) this room (%s)</A>\n", wc_roomname);
-wprintf("<LI><A HREF=\"/zapped_list\">");
-wprintf("List all forgotten rooms</A>\n");
+ wprintf("<LI><A HREF=\"/zapped_list\">");
+ wprintf("List all forgotten rooms</A>\n");
-wprintf("</UL>\n");
+ wprintf("</UL>\n");
-wprintf("</TD><TD>");
+ wprintf("</TD><TD>");
-if ((axlevel>=6) || (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("</FONT></TD></TR></TABLE>\n");
+ if ((axlevel >= 6) || (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("</FONT></TD></TR></TABLE>\n");
- wprintf("<UL>");
- wprintf("<LI><A HREF=\"/display_editroom\">\n");
- wprintf("Edit this room</A>\n");
-
- wprintf("<LI><A HREF=\"/confirm_delete_room\">\n");
- wprintf("Delete this room</A>\n");
-
- wprintf("<LI><A HREF=\"/display_editroompic\">\n");
- wprintf("Set or change the graphic for this room's banner</A>\n");
-
- wprintf("<LI><A HREF=\"/display_editinfo\">\n");
- wprintf("Edit this room's Info file</A>\n");
-
- wprintf("<LI><A HREF=\"/display_siteconfig\">\n");
- wprintf("Edit site-wide configuration</A>\n");
-
- if (axlevel>=6) {
- wprintf("<LI><A HREF=\"/validate\">\n");
- wprintf("Validate new users</A>\n");
-
- wprintf("<LI><A HREF=\"/select_floor_to_edit_pic\">\n");
- wprintf("Set or change a floor label graphic</A>\n");
-
- wprintf("<LI><A HREF=\"/display_netconf\">\n");
- wprintf("Configure networking with other systems</A>\n");
- }
+ wprintf("<UL>");
+ wprintf("<LI><A HREF=\"/display_editroom\">\n");
+ wprintf("Edit this room</A>\n");
- wprintf("</UL>\n");
- }
+ wprintf("<LI><A HREF=\"/confirm_delete_room\">\n");
+ wprintf("Delete this room</A>\n");
+
+ wprintf("<LI><A HREF=\"/display_editroompic\">\n");
+ wprintf("Set or change the graphic for this room's banner</A>\n");
+
+ wprintf("<LI><A HREF=\"/display_editinfo\">\n");
+ wprintf("Edit this room's Info file</A>\n");
+
+ wprintf("<LI><A HREF=\"/display_siteconfig\">\n");
+ wprintf("Edit site-wide configuration</A>\n");
-wprintf("</TD></TR></TABLE>");
+ if (axlevel >= 6) {
+ wprintf("<LI><A HREF=\"/validate\">\n");
+ wprintf("Validate new users</A>\n");
-wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770077><TR><TD>");
-wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
-wprintf("<B>Basic commands</B>\n");
-wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<LI><A HREF=\"/select_floor_to_edit_pic\">\n");
+ wprintf("Set or change a floor label graphic</A>\n");
+ wprintf("<LI><A HREF=\"/display_netconf\">\n");
+ wprintf("Configure networking with other systems</A>\n");
+ }
+ wprintf("</UL>\n");
}
+ wprintf("</TD></TR></TABLE>");
+
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770077><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Basic commands</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
+
+}
/*
* menu of commands (as a page)
*/
-void display_main_menu(void) {
+void display_main_menu(void)
+{
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
embed_main_menu();
wDumpContent(2);
- }
+}
-void display_advanced_menu(void) {
+void display_advanced_menu(void)
+{
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
embed_advanced_menu();
embed_main_menu();
wDumpContent(2);
- }
+}
/*
* Display the screen to enter a generic server command
*/
-void display_generic(void) {
+void display_generic(void)
+{
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
-
+
wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770077><TR><TD>");
wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
wprintf("<B>Enter a server command</B>\n");
wprintf("</FORM></CENTER>\n");
wDumpContent(1);
- }
+}
-void do_generic(void) {
+void do_generic(void)
+{
char buf[256];
char gcontent[256];
char *junk;
if (strcasecmp(bstr("sc"), "Send command")) {
display_main_menu();
return;
- }
-
+ }
serv_printf("%s", bstr("g_cmd"));
serv_gets(buf);
escputs(buf);
wprintf("</TT></TD></TR></TABLE><BR>\n");
- if (buf[0]=='8') {
+ if (buf[0] == '8') {
serv_printf("\n\n000");
- }
-
- if ( (buf[0]=='1') || (buf[0]=='8') ) {
- while(serv_gets(gcontent), strcmp(gcontent, "000")) {
+ }
+ if ((buf[0] == '1') || (buf[0] == '8')) {
+ while (serv_gets(gcontent), strcmp(gcontent, "000")) {
escputs(gcontent);
wprintf("<BR>\n");
- }
- wprintf("000");
}
-
- if (buf[0]=='4') {
+ wprintf("000");
+ }
+ if (buf[0] == '4') {
text_to_server(bstr("g_input"));
serv_puts("000");
- }
-
- if (buf[0]=='6') {
+ }
+ if (buf[0] == '6') {
len = atol(&buf[4]);
junk = malloc(len);
serv_read(junk, len);
free(junk);
- }
-
- if (buf[0]=='7') {
+ }
+ if (buf[0] == '7') {
len = atol(&buf[4]);
junk = malloc(len);
bzero(junk, len);
serv_write(junk, len);
free(junk);
- }
-
+ }
wprintf("<HR>");
wprintf("<A HREF=\"/display_generic\">Enter another command</A><BR>\n");
wprintf("<A HREF=\"/display_advanced\">Return to menu</A>\n");
wDumpContent(1);
- }
+}
* target window in order to keep the BBS session in its own window.
*/
void url(buf)
-char buf[]; {
+char buf[];
+{
int pos;
- int start,end;
+ int start, end;
char ench;
char urlbuf[256];
char outbuf[256];
end = strlen(buf);
ench = 0;
- for (pos=0; pos<strlen(buf); ++pos) {
- if (!strncasecmp(&buf[pos],"http://",7)) start = pos;
- if (!strncasecmp(&buf[pos],"ftp://",6)) start = pos;
- }
-
- if (start<0) return;
+ for (pos = 0; pos < strlen(buf); ++pos) {
+ if (!strncasecmp(&buf[pos], "http://", 7))
+ start = pos;
+ if (!strncasecmp(&buf[pos], "ftp://", 6))
+ start = pos;
+ }
- if ((start>0)&&(buf[start-1]=='<')) ench = '>';
- if ((start>0)&&(buf[start-1]=='[')) ench = ']';
- if ((start>0)&&(buf[start-1]=='(')) ench = ')';
- if ((start>0)&&(buf[start-1]=='{')) ench = '}';
+ if (start < 0)
+ return;
- for (pos=strlen(buf); pos>start; --pos) {
- if ((buf[pos]==' ')||(buf[pos]==ench)) end = pos;
- }
+ if ((start > 0) && (buf[start - 1] == '<'))
+ ench = '>';
+ if ((start > 0) && (buf[start - 1] == '['))
+ ench = ']';
+ if ((start > 0) && (buf[start - 1] == '('))
+ ench = ')';
+ if ((start > 0) && (buf[start - 1] == '{'))
+ ench = '}';
+
+ for (pos = strlen(buf); pos > start; --pos) {
+ if ((buf[pos] == ' ') || (buf[pos] == ench))
+ end = pos;
+ }
- strncpy(urlbuf,&buf[start],end-start);
- urlbuf[end-start] = 0;
+ strncpy(urlbuf, &buf[start], end - start);
+ urlbuf[end - start] = 0;
- strncpy(outbuf,buf,start);
- sprintf(&outbuf[start],"%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
- LB,QU,urlbuf,QU,QU,TARGET,QU,RB,urlbuf,LB,RB);
- strcat(outbuf,&buf[end]);
- strcpy(buf,outbuf);
- }
+ strncpy(outbuf, buf, start);
+ sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
+ LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
+ strcat(outbuf, &buf[end]);
+ strcpy(buf, outbuf);
+}
void read_message(msgnum, oper)
long msgnum;
-char *oper; {
+char *oper;
+{
char buf[256];
char m_subject[256];
char from[256];
int nhdr = 0;
int bq = 0;
- sprintf(buf,"MSG0 %ld",msgnum);
+ sprintf(buf, "MSG0 %ld", msgnum);
serv_puts(buf);
serv_gets(buf);
- if (buf[0]!='1') {
- wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n",&buf[4]);
+ if (buf[0] != '1') {
+ wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
return;
- }
-
+ }
wprintf("<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=000077><TR><TD>\n");
wprintf("<FONT SIZE=+1 COLOR=\"FFFF00\"> ");
- strcpy(m_subject,"");
-
- strcpy(reply_to,"nobody...xxxxx");
- while(serv_gets(buf), strncasecmp(buf,"text",4)) {
- if (!strncasecmp(buf,"nhdr=yes",8)) nhdr=1;
- if (nhdr==1) buf[0]='_';
- if (!strncasecmp(buf,"type=",5))
- format_type=atoi(&buf[5]);
- if (!strncasecmp(buf,"from=",5)) {
- wprintf("from %s ",&buf[5]);
- strcpy(from,&buf[5]);
- }
- if (!strncasecmp(buf,"path=",5))
- strcpy(reply_to,&buf[5]);
- if (!strncasecmp(buf,"subj=",5))
- strcpy(m_subject,&buf[5]);
- if ((!strncasecmp(buf,"hnod=",5))
- && (strcasecmp(&buf[5],serv_info.serv_humannode)))
- wprintf("(%s) ",&buf[5]);
- if ((!strncasecmp(buf,"room=",5))
- && (strcasecmp(&buf[5],wc_roomname)))
- wprintf("in %s> ",&buf[5]);
-
- if (!strncasecmp(buf,"node=",5)) {
- if ( (room_flags&QR_NETWORK)
- || ((strcasecmp(&buf[5],serv_info.serv_nodename)
- &&(strcasecmp(&buf[5],serv_info.serv_fqdn)))))
- {
- wprintf("@%s ",&buf[5]);
- }
- if ((!strcasecmp(&buf[5],serv_info.serv_nodename))
- ||(!strcasecmp(&buf[5],serv_info.serv_fqdn)))
- {
- strcpy(reply_to,from);
- }
- else if (haschar(&buf[5],'.')==0) {
- sprintf(reply_to,"%s @ %s",from,&buf[5]);
- }
+ strcpy(m_subject, "");
+
+ strcpy(reply_to, "nobody...xxxxx");
+ while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
+ if (!strncasecmp(buf, "nhdr=yes", 8))
+ nhdr = 1;
+ if (nhdr == 1)
+ buf[0] = '_';
+ if (!strncasecmp(buf, "type=", 5))
+ format_type = atoi(&buf[5]);
+ if (!strncasecmp(buf, "from=", 5)) {
+ wprintf("from %s ", &buf[5]);
+ strcpy(from, &buf[5]);
+ }
+ if (!strncasecmp(buf, "path=", 5))
+ strcpy(reply_to, &buf[5]);
+ if (!strncasecmp(buf, "subj=", 5))
+ strcpy(m_subject, &buf[5]);
+ if ((!strncasecmp(buf, "hnod=", 5))
+ && (strcasecmp(&buf[5], serv_info.serv_humannode)))
+ wprintf("(%s) ", &buf[5]);
+ if ((!strncasecmp(buf, "room=", 5))
+ && (strcasecmp(&buf[5], wc_roomname)))
+ wprintf("in %s> ", &buf[5]);
+
+ if (!strncasecmp(buf, "node=", 5)) {
+ if ((room_flags & QR_NETWORK)
+ || ((strcasecmp(&buf[5], serv_info.serv_nodename)
+ && (strcasecmp(&buf[5], serv_info.serv_fqdn))))) {
+ wprintf("@%s ", &buf[5]);
}
-
- if (!strncasecmp(buf,"rcpt=",5))
- wprintf("to %s ",&buf[5]);
- if (!strncasecmp(buf,"time=",5)) {
- now=atol(&buf[5]);
- tm=(struct tm *)localtime(&now);
- strcpy(buf,(char *)asctime(tm)); buf[strlen(buf)-1]=0;
- strcpy(&buf[16],&buf[19]);
- wprintf("%s ",&buf[4]);
+ if ((!strcasecmp(&buf[5], serv_info.serv_nodename))
+ || (!strcasecmp(&buf[5], serv_info.serv_fqdn))) {
+ strcpy(reply_to, from);
+ } else if (haschar(&buf[5], '.') == 0) {
+ sprintf(reply_to, "%s @ %s", from, &buf[5]);
}
}
+ if (!strncasecmp(buf, "rcpt=", 5))
+ wprintf("to %s ", &buf[5]);
+ if (!strncasecmp(buf, "time=", 5)) {
+ now = atol(&buf[5]);
+ tm = (struct tm *) localtime(&now);
+ strcpy(buf, (char *) asctime(tm));
+ buf[strlen(buf) - 1] = 0;
+ strcpy(&buf[16], &buf[19]);
+ wprintf("%s ", &buf[4]);
+ }
+ }
- if (nhdr==1) wprintf("****");
+ if (nhdr == 1)
+ wprintf("****");
wprintf("</FONT></TD>");
-
+
if (is_room_aide) {
wprintf("<TD ALIGN=RIGHT NOWRAP><FONT COLOR=\"FFFF00\"><B>");
wprintf("\">Del</A>");
wprintf("</B></FONT></TD>");
- }
-
+ }
wprintf("</TR></TABLE>\n");
- if (strlen(m_subject)>0) {
- wprintf("Subject: %s<BR>\n",m_subject);
- }
-
+ if (strlen(m_subject) > 0) {
+ wprintf("Subject: %s<BR>\n", m_subject);
+ }
if (format_type == 0) {
fmout(NULL);
- }
- else {
- while(serv_gets(buf), strcmp(buf,"000")) {
- while ((strlen(buf)>0)&&(isspace(buf[strlen(buf)-1])))
- buf[strlen(buf)-1] = 0;
- if ((bq==0)&&
-((!strncmp(buf,">",1))||(!strncmp(buf," >",2))||(!strncmp(buf," :-)",4)))) {
+ } else {
+ while (serv_gets(buf), strcmp(buf, "000")) {
+ while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
+ buf[strlen(buf) - 1] = 0;
+ if ((bq == 0) &&
+ ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
wprintf("<FONT COLOR=\"000044\"><I>");
bq = 1;
- }
- else if ((bq==1)&&
-(strncmp(buf,">",1))&&(strncmp(buf," >",2))&&(strncmp(buf," :-)",4))) {
+ } else if ((bq == 1) &&
+ (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
wprintf("</FONT></I>");
bq = 0;
- }
+ }
wprintf("<TT>");
url(buf);
escputs(buf);
wprintf("</TT><BR>\n");
- }
}
- wprintf("<BR>");
}
+ wprintf("<BR>");
+}
* load message pointers from the server
*/
int load_msg_ptrs(servcmd)
-char *servcmd; {
+char *servcmd;
+{
char buf[256];
int nummsgs;
nummsgs = 0;
serv_puts(servcmd);
serv_gets(buf);
- if (buf[0]!='1') {
- wprintf("<EM>%s</EM><BR>\n",&buf[4]);
- return(nummsgs);
- }
- while (serv_gets(buf), strcmp(buf,"000")) {
+ if (buf[0] != '1') {
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
+ return (nummsgs);
+ }
+ while (serv_gets(buf), strcmp(buf, "000")) {
msgarr[nummsgs] = atol(buf);
++nummsgs;
- }
- return(nummsgs);
}
+ return (nummsgs);
+}
/*
* command loop for reading messages
*/
-void readloop(char *oper) {
+void readloop(char *oper)
+{
char cmd[256];
int a;
int nummsgs;
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
- wprintf("<CENTER><B>%s - ",wc_roomname);
- if (!strcmp(oper,"readnew")) {
- strcpy(cmd,"MSGS NEW");
+ wprintf("<CENTER><B>%s - ", wc_roomname);
+ if (!strcmp(oper, "readnew")) {
+ strcpy(cmd, "MSGS NEW");
wprintf("new messages");
- }
- else if (!strcmp(oper,"readold")) {
- strcpy(cmd,"MSGS OLD");
+ } else if (!strcmp(oper, "readold")) {
+ strcpy(cmd, "MSGS OLD");
wprintf("old messages");
- }
- else {
- strcpy(cmd,"MSGS ALL");
+ } else {
+ strcpy(cmd, "MSGS ALL");
wprintf("all messages");
- }
+ }
wprintf("</B></CENTER><BR>\n");
nummsgs = load_msg_ptrs(cmd);
if (nummsgs == 0) {
- if (!strcmp(oper,"readnew")) {
+ if (!strcmp(oper, "readnew")) {
wprintf("<EM>No new messages in this room.</EM>\n");
- }
- else if (!strcmp(oper,"readold")) {
+ } else if (!strcmp(oper, "readold")) {
wprintf("<EM>No old messages in this room.</EM>\n");
- }
- else {
+ } else {
wprintf("<EM>This room is empty.</EM>\n");
- }
- goto DONE;
}
-
- for (a=0; a<nummsgs; ++a) {
+ goto DONE;
+ }
+ for (a = 0; a < nummsgs; ++a) {
read_message(msgarr[a], oper);
- }
-
-DONE: wDumpContent(1);
}
+ DONE:wDumpContent(1);
+}
+
/*
* post message (or don't post message)
*/
-void post_message(void) {
+void post_message(void)
+{
char buf[256];
printf("HTTP/1.0 200 OK\n");
strcpy(buf, bstr("sc"));
if (strcasecmp(buf, "Save message")) {
wprintf("Cancelled. Message was not posted.<BR>\n");
- }
-
- else {
- sprintf(buf,"ENT0 1|%s|0|0",bstr("recp"));
+ } else {
+ sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
serv_puts(buf);
serv_gets(buf);
- if (buf[0]=='4') {
+ if (buf[0] == '4') {
text_to_server(bstr("msgtext"));
serv_puts("000");
wprintf("Message has been posted.<BR>\n");
- }
- else {
- wprintf("<EM>%s</EM><BR>\n",&buf[4]);
- }
+ } else {
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
}
+ }
wDumpContent(1);
- }
+}
/*
* prompt for a recipient (to be called from display_enter() only)
*/
-void prompt_for_recipient() {
+void prompt_for_recipient()
+{
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Send private e-mail</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Send private e-mail</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
wprintf("<CENTER>");
wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
wprintf("</FORM></CENTER>\n");
- }
+}
/*
* display the message entry screen
*/
-void display_enter(void) {
+void display_enter(void)
+{
char buf[256];
long now;
struct tm *tm;
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
- sprintf(buf,"ENT0 0|%s|0|0",bstr("recp"));
+ sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
serv_puts(buf);
serv_gets(buf);
- if (!strncmp(buf,"570",3)) {
- if (strlen(bstr("recp"))>0) {
- wprintf("<EM>%s</EM><BR>\n",&buf[4]);
- }
+ if (!strncmp(buf, "570", 3)) {
+ if (strlen(bstr("recp")) > 0) {
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
+ }
prompt_for_recipient();
goto DONE;
- }
-
- if (buf[0]!='2') {
- wprintf("<EM>%s</EM><BR>\n",&buf[4]);
+ }
+ if (buf[0] != '2') {
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
goto DONE;
- }
-
+ }
wprintf("<CENTER>Enter message below. Messages are formatted to\n");
wprintf("the <EM>reader's</EM> screen width. To defeat the\n");
wprintf("formatting, indent a line at least one space. \n");
wprintf("<BR>");
time(&now);
- tm=(struct tm *)localtime(&now);
- strcpy(buf,(char *)asctime(tm)); buf[strlen(buf)-1]=0;
- strcpy(&buf[16],&buf[19]);
- wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ",&buf[4]);
- wprintf("from %s ",wc_username);
- if (strlen(bstr("recp"))>0) wprintf("to %s ",bstr("recp"));
- wprintf("in %s> ",wc_roomname);
+ tm = (struct tm *) localtime(&now);
+ strcpy(buf, (char *) asctime(tm));
+ buf[strlen(buf) - 1] = 0;
+ strcpy(&buf[16], &buf[19]);
+ wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
+ wprintf("from %s ", wc_username);
+ if (strlen(bstr("recp")) > 0)
+ wprintf("to %s ", bstr("recp"));
+ wprintf("in %s> ", wc_roomname);
wprintf("</B></FONT><BR><CENTER>\n");
wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 WIDTH=80></TEXTAREA><P>\n");
wprintf("</FORM></CENTER>\n");
-DONE: wDumpContent(1);
- }
+ DONE:wDumpContent(1);
+}
/*
* Confirm deletion of a message
*/
-void confirm_delete_msg(void) {
+void confirm_delete_msg(void)
+{
long msgid;
msgid = atol(bstr("msgid"));
-
+
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
wprintf("</CENTER>\n");
wDumpContent(1);
- }
+}
-void delete_msg(void) {
+void delete_msg(void)
+{
long msgid;
char buf[256];
serv_puts(buf);
serv_gets(buf);
wprintf("<EM>%s</EM><BR>\n", &buf[4]);
- }
- else {
+ } else {
wprintf("<EM>Message not deleted.</EM><BR>\n");
- }
+ }
wDumpContent(1);
- }
+}
/*
* Confirm move of a message
*/
-void confirm_move_msg(void) {
+void confirm_move_msg(void)
+{
long msgid;
char buf[256];
char targ[256];
msgid = atol(bstr("msgid"));
-
+
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
bstr("msgid"));
- wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
- serv_puts("LKRA");
- serv_gets(buf);
- if (buf[0]=='1') {
- while(serv_gets(buf), strcmp(buf,"000")) {
- extract(targ,buf,0);
- wprintf("<OPTION>");
- escputs(targ);
- wprintf("\n");
- }
- }
- wprintf("</SELECT>\n");
- wprintf("<BR>\n");
+ wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
+ serv_puts("LKRA");
+ serv_gets(buf);
+ if (buf[0] == '1') {
+ while (serv_gets(buf), strcmp(buf, "000")) {
+ extract(targ, buf, 0);
+ wprintf("<OPTION>");
+ escputs(targ);
+ wprintf("\n");
+ }
+ }
+ wprintf("</SELECT>\n");
+ wprintf("<BR>\n");
wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
wprintf("</CENTER>\n");
wDumpContent(1);
- }
+}
-void move_msg(void) {
+void move_msg(void)
+{
long msgid;
char buf[256];
serv_puts(buf);
serv_gets(buf);
wprintf("<EM>%s</EM><BR>\n", &buf[4]);
- }
- else {
+ } else {
wprintf("<EM>Message not deleted.</EM><BR>\n");
- }
-
- wDumpContent(1);
}
+ wDumpContent(1);
+}
-void extract_key(char *target, char *source, char *key) {
+void extract_key(char *target, char *source, char *key)
+{
int a, b;
strcpy(target, source);
- for (a=0; a<strlen(target); ++a) {
+ for (a = 0; a < strlen(target); ++a) {
if ((!strncasecmp(&target[a], key, strlen(key)))
- && (target[a+strlen(key)]=='=')) {
- strcpy(target, &target[a+strlen(key)+1]);
- if (target[0]==34) strcpy(target, &target[1]);
- for (b=0; b<strlen(target); ++b)
- if (target[b]==34) target[b]=0;
+ && (target[a + strlen(key)] == '=')) {
+ strcpy(target, &target[a + strlen(key) + 1]);
+ if (target[0] == 34)
+ strcpy(target, &target[1]);
+ for (b = 0; b < strlen(target); ++b)
+ if (target[b] == 34)
+ target[b] = 0;
return;
- }
}
- strcpy(target, "");
}
+ strcpy(target, "");
+}
* (This function expects to be fed CONTENT ONLY, no headers)
*/
void do_something_with_it(char *content,
- int length,
- char *content_type,
- char *content_disposition,
- void (*CallBack)
- (char *cbname,
- char *cbfilename,
- char *cbencoding,
- void *cbcontent,
- char *cbtype,
- size_t cblength)
- ) {
+ int length,
+ char *content_type,
+ char *content_disposition,
+ void (*CallBack)
+ (char *cbname,
+ char *cbfilename,
+ char *cbencoding,
+ void *cbcontent,
+ char *cbtype,
+ size_t cblength)
+)
+{
char name[256];
char filename[256];
/* Nested multipart gets recursively fed back into the parser */
if (!strncasecmp(content_type, "multipart", 9)) {
mime_parser(content, length, content_type, CallBack);
- }
-
- /**** OTHERWISE, HERE'S WHERE WE HANDLE THE STUFF!! *****/
+ }
+/**** OTHERWISE, HERE'S WHERE WE HANDLE THE STUFF!! *****/
CallBack(name, filename, "", content, content_type, length);
- /**** END OF STUFF-HANDLER ****/
+/**** END OF STUFF-HANDLER ****/
- }
+}
/*
* (This function expects to be fed HEADERS+CONTENT)
*/
void handle_part(char *content,
- int part_length,
- char *supplied_content_type,
- void (*CallBack)
- (char *cbname,
- char *cbfilename,
- char *cbencoding,
- void *cbcontent,
- char *cbtype,
- size_t cblength)
- ) {
+ int part_length,
+ char *supplied_content_type,
+ void (*CallBack)
+ (char *cbname,
+ char *cbfilename,
+ char *cbencoding,
+ void *cbcontent,
+ char *cbtype,
+ size_t cblength)
+)
+{
char content_type[256];
char content_disposition[256];
char *start;
char buf[512];
- int crlf = 0; /* set to 1 for crlf-style newlines */
+ int crlf = 0; /* set to 1 for crlf-style newlines */
int actual_length;
strcpy(content_type, supplied_content_type);
while ((!strncmp(start, "\r", 1)) || (!strncmp(start, "\n", 1))) {
++start;
--part_length;
- }
+ }
/* At this point all we have left is the headers and the content. */
do {
strcpy(buf, "");
do {
- buf[strlen(buf)+1] = 0;
- if (strlen(buf)<((sizeof buf)-1)) {
+ buf[strlen(buf) + 1] = 0;
+ if (strlen(buf) < ((sizeof buf) - 1)) {
strncpy(&buf[strlen(buf)], start, 1);
- }
+ }
++start;
--part_length;
- } while((buf[strlen(buf)-1] != 10) && (part_length>0));
- if (part_length <= 0) return;
- buf[strlen(buf)-1] = 0;
- if (buf[strlen(buf)-1]==13) {
- buf[strlen(buf)-1] = 0;
+ } while ((buf[strlen(buf) - 1] != 10) && (part_length > 0));
+ if (part_length <= 0)
+ return;
+ buf[strlen(buf) - 1] = 0;
+ if (buf[strlen(buf) - 1] == 13) {
+ buf[strlen(buf) - 1] = 0;
crlf = 1;
- }
+ }
if (!strncasecmp(buf, "Content-type: ", 14)) {
strcpy(content_type, &buf[14]);
- }
+ }
if (!strncasecmp(buf, "Content-disposition: ", 21)) {
strcpy(content_disposition, &buf[21]);
- }
- } while (strlen(buf)>0);
-
- if (crlf) actual_length = part_length - 2;
- else actual_length = part_length - 1;
+ }
+ } while (strlen(buf) > 0);
+
+ if (crlf)
+ actual_length = part_length - 2;
+ else
+ actual_length = part_length - 1;
/* Now that we've got this component isolated, what to do with it? */
do_something_with_it(start, actual_length,
- content_type, content_disposition, CallBack);
+ content_type, content_disposition, CallBack);
+
+}
- }
-
/*
* Break out the components of a multipart message
* (This function expects to be fed CONTENT ONLY, no headers)
void mime_parser(char *content,
- int ContentLength,
- char *ContentType,
- void (*CallBack)
- (char *cbname,
- char *cbfilename,
- char *cbencoding,
- void *cbcontent,
- char *cbtype,
- size_t cblength)
- ) {
+ int ContentLength,
+ char *ContentType,
+ void (*CallBack)
+ (char *cbname,
+ char *cbfilename,
+ char *cbencoding,
+ void *cbcontent,
+ char *cbtype,
+ size_t cblength)
+)
+{
char boundary[256];
char endary[256];
int have_boundary = 0;
/* If it's not multipart, don't process it as multipart */
if (strncasecmp(ContentType, "multipart", 9)) {
do_something_with_it(content, ContentLength,
- ContentType, "", CallBack);
+ ContentType, "", CallBack);
return;
- }
-
+ }
/* Figure out what the boundary is */
strcpy(boundary, ContentType);
- for (a=0; a<strlen(boundary); ++a) {
+ for (a = 0; a < strlen(boundary); ++a) {
if (!strncasecmp(&boundary[a], "boundary=", 9)) {
- boundary[0]='-';
- boundary[1]='-';
- strcpy(&boundary[2], &boundary[a+9]);
+ boundary[0] = '-';
+ boundary[1] = '-';
+ strcpy(&boundary[2], &boundary[a + 9]);
have_boundary = 1;
a = 0;
- }
- if ((boundary[a]==13) || (boundary[a]==10)) {
+ }
+ if ((boundary[a] == 13) || (boundary[a] == 10)) {
boundary[a] = 0;
- }
}
+ }
/* We can't process multipart messages without a boundary. */
- if (have_boundary == 0) return;
+ if (have_boundary == 0)
+ return;
strcpy(endary, boundary);
strcat(endary, "--");
/* Seek to the beginning of the next boundary */
while (bytes_processed < ContentLength) {
- /* && (strncasecmp(ptr, boundary, strlen(boundary))) ) { */
+ /* && (strncasecmp(ptr, boundary, strlen(boundary))) ) { */
if (strncasecmp(ptr, boundary, strlen(boundary))) {
++ptr;
++bytes_processed;
- }
-
+ }
/* See if we're at the end */
if (!strncasecmp(ptr, endary, strlen(endary))) {
return;
- }
-
+ }
/* Seek to the end of the boundary string */
if (!strncasecmp(ptr, boundary, strlen(boundary))) {
- while ( (bytes_processed < ContentLength)
- && (strncasecmp(ptr, "\n", 1)) ) {
+ while ((bytes_processed < ContentLength)
+ && (strncasecmp(ptr, "\n", 1))) {
++ptr;
++bytes_processed;
- }
+ }
beginning = ptr;
part_length = 0;
- while ( (bytes_processed < ContentLength)
- && (strncasecmp(ptr, boundary, strlen(boundary))) ) {
+ while ((bytes_processed < ContentLength)
+ && (strncasecmp(ptr, boundary, strlen(boundary)))) {
++ptr;
++bytes_processed;
++part_length;
- }
+ }
handle_part(beginning, part_length, "", CallBack);
/* Back off so we can see the next boundary */
--ptr;
--bytes_processed;
- }
}
}
+}
void extract_key(char *target, char *source, char *key);
void do_something_with_it(char *content,
- int length,
- char *content_type,
- char *content_disposition,
- void (*CallBack)
- (char *cbname,
- char *cbfilename,
- char *cbencoding,
- void *cbcontent,
- char *cbtype,
- size_t cblength)
- );
+ int length,
+ char *content_type,
+ char *content_disposition,
+ void (*CallBack)
+ (char *cbname,
+ char *cbfilename,
+ char *cbencoding,
+ void *cbcontent,
+ char *cbtype,
+ size_t cblength)
+);
void handle_part(char *content,
- int part_length,
- char *supplied_content_type,
- void (*CallBack)
- (char *cbname,
- char *cbfilename,
- char *cbencoding,
- void *cbcontent,
- char *cbtype,
- size_t cblength)
- );
+ int part_length,
+ char *supplied_content_type,
+ void (*CallBack)
+ (char *cbname,
+ char *cbfilename,
+ char *cbencoding,
+ void *cbcontent,
+ char *cbtype,
+ size_t cblength)
+);
void mime_parser(char *content,
- int ContentLength,
- char *ContentType,
- void (*CallBack)
- (char *cbname,
- char *cbfilename,
- char *cbencoding,
- void *cbcontent,
- char *cbtype,
- size_t cblength)
- );
+ int ContentLength,
+ char *ContentType,
+ void (*CallBack)
+ (char *cbname,
+ char *cbfilename,
+ char *cbencoding,
+ void *cbcontent,
+ char *cbtype,
+ size_t cblength)
+);
struct sharelist {
struct sharelist *next;
char shname[256];
- };
+};
-void display_edit_node(void) {
+void display_edit_node(void)
+{
char buf[256];
char node[256];
char sroom[256];
urlescputs(node);
wprintf("\">(UnShare)</A></TD>");
wprintf("</TR>\n");
- }
- wprintf("</TABLE></CENTER>\n");
}
-
- wDumpContent(1);
+ wprintf("</TABLE></CENTER>\n");
}
-
+ wDumpContent(1);
+}
+
-void display_netconf(void) {
+void display_netconf(void)
+{
char buf[256];
char node[256];
urlescputs(node);
wprintf("\">(Delete)</A></TD>");
wprintf("</TR>\n");
- }
- wprintf("</TABLE></CENTER>\n");
}
-
- wDumpContent(1);
+ wprintf("</TABLE></CENTER>\n");
}
+ wDumpContent(1);
+}
-void display_confirm_unshare(void) {
+void display_confirm_unshare(void)
+{
char node[256];
char sroom[256];
urlescputs(node);
wprintf("\">No</A><BR>\n");
wDumpContent(1);
- }
+}
-void display_confirm_delete_node(void) {
+void display_confirm_delete_node(void)
+{
char node[256];
printf("HTTP/1.0 200 OK\n");
wprintf("\">Yes</A> ");
wprintf("<A HREF=\"/display_netconf\">No</A><BR>\n");
wDumpContent(1);
- }
+}
-void delete_node(void) {
+void delete_node(void)
+{
char node[256];
char buf[256];
-
+
strcpy(node, bstr("node"));
sprintf(buf, "NSET deletenode|%s", node);
serv_puts(buf);
serv_gets(buf);
- if (buf[0]=='1') {
+ if (buf[0] == '1') {
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
server_to_text();
wprintf("<A HREF=\"/display_netconf\">Back to menu</A>\n");
wDumpContent(1);
- }
- else {
+ } else {
display_error(&buf[4]);
- }
}
+}
-void unshare(void) {
+void unshare(void)
+{
char node[256];
char sroom[256];
char buf[256];
-
+
strcpy(node, bstr("node"));
strcpy(sroom, bstr("sroom"));
sprintf(buf, "NSET unshare|%s|%s", node, sroom);
serv_puts(buf);
serv_gets(buf);
- if (buf[0]=='1') {
+ if (buf[0] == '1') {
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
server_to_text();
wprintf("<A HREF=\"/display_netconf\">Back to menu</A>\n");
wDumpContent(1);
- }
- else {
+ } else {
display_error(&buf[4]);
- }
}
+}
-void display_add_node(void) {
-
+void display_add_node(void)
+{
+
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
wprintf("</FORM></CENTER>\n");
wDumpContent(1);
- }
+}
-void add_node(void) {
+void add_node(void)
+{
char node[256];
char buf[256];
char sc[256];
sprintf(buf, "NSET addnode|%s", node);
serv_puts(buf);
serv_gets(buf);
- if (buf[0]=='1') {
+ if (buf[0] == '1') {
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
server_to_text();
wprintf("<A HREF=\"/display_netconf\">Back to menu</A>\n");
wDumpContent(1);
- }
- else {
+ } else {
display_error(&buf[4]);
- }
}
-
}
+}
-void display_share(void) {
+void display_share(void)
+{
char buf[256];
char node[256];
char sroom[256];
sprintf(buf, "NSET roomlist|%s", node);
serv_puts(buf);
serv_gets(buf);
- if (buf[0]=='1') {
- while(serv_gets(buf), strcmp(buf,"000")) {
+ if (buf[0] == '1') {
+ while (serv_gets(buf), strcmp(buf, "000")) {
shptr = (struct sharelist *)
- malloc(sizeof(struct sharelist));
- shptr -> next = shlist;
+ malloc(sizeof(struct sharelist));
+ shptr->next = shlist;
extract(shptr->shname, buf, 0);
shlist = shptr;
- }
}
-
+ }
wprintf("<SELECT NAME=\"sroom\" SIZE=5 WIDTH=30>\n");
serv_puts("LKRA");
serv_gets(buf);
- if (buf[0]=='1') {
- while(serv_gets(buf), strcmp(buf,"000")) {
+ if (buf[0] == '1') {
+ while (serv_gets(buf), strcmp(buf, "000")) {
extract(sroom, buf, 0);
already_shared = 0;
for (shptr = shlist; shptr != NULL; shptr = shptr->next) {
if (!strcasecmp(sroom, shptr->shname))
already_shared = 1;
- }
+ }
if (already_shared == 0) {
wprintf("<OPTION>");
escputs(sroom);
wprintf("\n");
- }
-
}
}
+ }
wprintf("</SELECT>\n");
wprintf("<BR>\n");
shptr = shlist->next;
free(shlist);
shlist = shptr;
- }
-
}
+}
+
-void share(void) {
+void share(void)
+{
char node[256];
char buf[256];
char sc[256];
char sroom[256];
-
+
strcpy(node, bstr("node"));
strcpy(sc, bstr("sc"));
strcpy(sroom, bstr("sroom"));
sprintf(buf, "NSET share|%s|%s", node, sroom);
serv_puts(buf);
serv_gets(buf);
- if (buf[0]=='1') {
+ if (buf[0] == '1') {
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
server_to_text();
wprintf("<A HREF=\"/display_netconf\">Back to menu</A>\n");
wDumpContent(1);
- }
- else {
+ } else {
display_error(&buf[4]);
- }
-
}
- }
+ }
+}
/*
* display the form for paging (x-messaging) another user
*/
-void display_page(void) {
+void display_page(void)
+{
char buf[256];
char user[256];
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Page another user</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Page another user</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
wprintf("This command sends a near-real-time message to any currently\n");
wprintf("logged in user.<BR><BR>\n");
wprintf("<SELECT NAME=\"recp\" SIZE=10>\n");
serv_puts("RWHO");
serv_gets(buf);
- if (buf[0]=='1') {
- while(serv_gets(buf), strcmp(buf,"000")) {
- extract(user,buf,1);
+ if (buf[0] == '1') {
+ while (serv_gets(buf), strcmp(buf, "000")) {
+ extract(user, buf, 1);
wprintf("<OPTION>");
escputs(user);
wprintf("\n");
- }
}
+ }
wprintf("</SELECT>\n");
wprintf("<BR>\n");
wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
wprintf("</FORM></CENTER>\n");
- wDumpContent(1);
- }
+ wDumpContent(1);
+}
/*
* page another user
-*/
-void page_user(void) {
+ */
+void page_user(void)
+{
char recp[256];
char msgtext[256];
char sc[256];
char buf[256];
-
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
- strcpy(recp,bstr("recp"));
- strcpy(msgtext,bstr("msgtext"));
- strcpy(sc,bstr("sc"));
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
+
+ strcpy(recp, bstr("recp"));
+ strcpy(msgtext, bstr("msgtext"));
+ strcpy(sc, bstr("sc"));
- if (strcmp(sc,"Send message")) {
+ if (strcmp(sc, "Send message")) {
wprintf("<EM>Message was not sent.</EM><BR>\n");
return;
- }
-
- serv_printf("SEXP %s|%s",recp,msgtext);
- serv_gets(buf);
+ }
+ serv_printf("SEXP %s|%s", recp, msgtext);
+ serv_gets(buf);
if (buf[0] == '2') {
wprintf("<EM>Message has been sent to ");
escputs(recp);
wprintf(".</EM><BR>\n");
- }
- else {
- wprintf("<EM>%s</EM><BR>\n",&buf[4]);
- }
-
- wDumpContent(1);
+ } else {
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
}
+ wDumpContent(1);
+}
+
/*
* multiuser chat
*/
-void do_chat(void) {
+void do_chat(void)
+{
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Real-time chat</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Real-time chat</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
wprintf("A chat window should be appearing on your screen ");
wprintf("momentarily. When you're ");
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");
- wDumpContent(1);
- }
+ wDumpContent(1);
+}
char march_name[32];
int march_floor;
int march_order;
- };
+};
/*
* This struct holds a list of rooms for client display.
* (oooh, a tree!)
*/
struct roomlisting {
- struct roomlisting *lnext;
+ struct roomlisting *lnext;
struct roomlisting *rnext;
- char rlname[64];
- unsigned rlflags;
+ char rlname[64];
+ unsigned rlflags;
int rlfloor;
- int rlorder;
- };
+ int rlorder;
+};
char floorlist[128][256];
/*
* load the list of floors
*/
-void load_floorlist(void) {
+void load_floorlist(void)
+{
int a;
char buf[256];
- for (a=0; a<128; ++a) floorlist[a][0] = 0;
+ for (a = 0; a < 128; ++a)
+ floorlist[a][0] = 0;
serv_puts("LFLR");
serv_gets(buf);
- if (buf[0]!='1') {
- strcpy(floorlist[0],"Main Floor");
+ if (buf[0] != '1') {
+ strcpy(floorlist[0], "Main Floor");
return;
- }
- while (serv_gets(buf), strcmp(buf,"000")) {
- extract(floorlist[extract_int(buf,0)],buf,1);
- }
}
+ while (serv_gets(buf), strcmp(buf, "000")) {
+ extract(floorlist[extract_int(buf, 0)], buf, 1);
+ }
+}
/*
*/
void remove_march(char *aaa)
{
- struct march *mptr,*mptr2;
+ struct march *mptr, *mptr2;
- if (march==NULL) return;
+ if (march == NULL)
+ return;
- if (!strcasecmp(march->march_name,aaa)) {
+ if (!strcasecmp(march->march_name, aaa)) {
mptr = march->next;
free(march);
march = mptr;
return;
- }
-
+ }
mptr2 = march;
- for (mptr=march; mptr!=NULL; mptr=mptr->next) {
- if (!strcasecmp(mptr->march_name,aaa)) {
+ for (mptr = march; mptr != NULL; mptr = mptr->next) {
+ if (!strcasecmp(mptr->march_name, aaa)) {
mptr2->next = mptr->next;
free(mptr);
- mptr=mptr2;
- }
- else {
- mptr2=mptr;
- }
+ mptr = mptr2;
+ } else {
+ mptr2 = mptr;
}
}
+}
-void room_tree_list(struct roomlisting *rp) {
+void room_tree_list(struct roomlisting *rp)
+{
char rmname[64];
int f;
- if (rp == NULL) return;
+ if (rp == NULL)
+ return;
if (rp->lnext != NULL) {
room_tree_list(rp->lnext);
- }
-
+ }
strcpy(rmname, rp->rlname);
f = rp->rlflags;
wprintf("<A HREF=\"/dotgoto&room=");
urlescputs(rmname);
wprintf("\">");
- escputs1(rmname,1);
- if ((f & QR_DIRECTORY) && (f & QR_NETWORK)) wprintf("}");
- else if (f & QR_DIRECTORY) wprintf("]");
- else if (f & QR_NETWORK) wprintf(")");
- else wprintf(">");
+ escputs1(rmname, 1);
+ if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
+ wprintf("}");
+ else if (f & QR_DIRECTORY)
+ wprintf("]");
+ else if (f & QR_NETWORK)
+ wprintf(")");
+ else
+ wprintf(">");
wprintf("</A><TT> </TT>\n");
if (rp->rnext != NULL) {
room_tree_list(rp->rnext);
- }
-
- free(rp);
}
+ free(rp);
+}
/*
*/
int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
{
- if ((r1==NULL)&&(r2==NULL)) return(0);
- if (r1==NULL) return(-1);
- if (r2==NULL) return(1);
- if (r1->rlfloor < r2->rlfloor) return(-1);
- if (r1->rlfloor > r2->rlfloor) return(1);
- if (r1->rlorder < r2->rlorder) return(-1);
- if (r1->rlorder > r2->rlorder) return(1);
- return(0);
- }
+ if ((r1 == NULL) && (r2 == NULL))
+ return (0);
+ if (r1 == NULL)
+ return (-1);
+ if (r2 == NULL)
+ return (1);
+ if (r1->rlfloor < r2->rlfloor)
+ return (-1);
+ if (r1->rlfloor > r2->rlfloor)
+ return (1);
+ if (r1->rlorder < r2->rlorder)
+ return (-1);
+ if (r1->rlorder > r2->rlorder)
+ return (1);
+ return (0);
+}
/*
/* Ask the server for a room list */
serv_puts(variety);
serv_gets(buf);
- if (buf[0]!='1') return;
+ if (buf[0] != '1')
+ return;
while (serv_gets(buf), strcmp(buf, "000")) {
rp = malloc(sizeof(struct roomlisting));
extract(rp->rlname, buf, 0);
rs = rl;
if (rl == NULL) {
rl = rp;
- }
- else while (rp != NULL) {
- if (rordercmp(rp, rs)<0) {
- if (rs->lnext == NULL) {
- rs->lnext = rp;
- rp = NULL;
+ } else
+ while (rp != NULL) {
+ if (rordercmp(rp, rs) < 0) {
+ if (rs->lnext == NULL) {
+ rs->lnext = rp;
+ rp = NULL;
+ } else {
+ rs = rs->lnext;
}
- else {
- rs = rs->lnext;
- }
- }
- else {
- if (rs->rnext == NULL) {
- rs->rnext = rp;
- rp = NULL;
- }
- else {
- rs = rs->rnext;
+ } else {
+ if (rs->rnext == NULL) {
+ rs->rnext = rp;
+ rp = NULL;
+ } else {
+ rs = rs->rnext;
}
}
}
- }
+ }
room_tree_list(rl);
- }
+}
/*
* list all rooms by floor
*/
-void list_all_rooms_by_floor(void) {
+void list_all_rooms_by_floor(void)
+{
int a;
char buf[256];
load_floorlist();
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
wprintf("<TABLE width=100% border><TR><TH>Floor</TH>");
wprintf("<TH>Rooms with new messages</TH>");
wprintf("<TH>Rooms with no new messages</TH></TR>\n");
- for (a=0; a<128; ++a) if (floorlist[a][0]!=0) {
+ for (a = 0; a < 128; ++a)
+ if (floorlist[a][0] != 0) {
- /* Floor name column */
- wprintf("<TR><TD>");
-
- serv_printf("OIMG _floorpic_|%d", a);
- serv_gets(buf);
- if (buf[0] == '2') {
- serv_puts("CLOS");
+ /* Floor name column */
+ wprintf("<TR><TD>");
+
+ serv_printf("OIMG _floorpic_|%d", a);
serv_gets(buf);
- wprintf("<IMG SRC=\"/image&name=_floorpic_&parm=%d\" ALT=\"%s\">",
- a, &floorlist[a][0]);
- }
- else {
- escputs(&floorlist[a][0]);
+ if (buf[0] == '2') {
+ serv_puts("CLOS");
+ serv_gets(buf);
+ wprintf("<IMG SRC=\"/image&name=_floorpic_&parm=%d\" ALT=\"%s\">",
+ a, &floorlist[a][0]);
+ } else {
+ escputs(&floorlist[a][0]);
}
- wprintf("</TD>");
+ wprintf("</TD>");
- /* Rooms with new messages column */
- wprintf("<TD>");
- sprintf(buf,"LKRN %d",a);
- listrms(buf);
- wprintf("</TD><TD>\n");
+ /* Rooms with new messages column */
+ wprintf("<TD>");
+ sprintf(buf, "LKRN %d", a);
+ listrms(buf);
+ wprintf("</TD><TD>\n");
- /* Rooms with old messages column */
- sprintf(buf,"LKRO %d",a);
- listrms(buf);
- wprintf("</TD></TR>\n");
+ /* Rooms with old messages column */
+ sprintf(buf, "LKRO %d", a);
+ listrms(buf);
+ wprintf("</TD></TR>\n");
}
wprintf("</TABLE>\n");
wDumpContent(1);
- }
+}
/*
* list all forgotten rooms
*/
-void zapped_list(void) {
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Zapped (forgotten) rooms</B>\n");
- wprintf("</FONT></TD></TR></TABLE><BR>\n");
+void zapped_list(void)
+{
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Zapped (forgotten) rooms</B>\n");
+ wprintf("</FONT></TD></TR></TABLE><BR>\n");
listrms("LZRM -1");
wprintf("<BR><BR>\n");
wprintf("Click on any room to un-zap it and goto that room.\n");
wDumpContent(1);
- }
-
+}
+
/*
* read this room's info file (set v to 1 for verbose mode)
serv_puts("RINF");
serv_gets(buf);
- if (buf[0]=='1') fmout(NULL);
+ if (buf[0] == '1')
+ fmout(NULL);
else {
- if (v==1) wprintf("<EM>%s</EM><BR>\n",&buf[4]);
- }
+ if (v == 1)
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
}
+}
/*
if (display_name) {
printf("HTTP/1.0 200 OK\n");
output_headers(0, "top");
- wprintf("<HTML><HEAD></HEAD>\n<BODY ");
-
+ wprintf("<HTML><HEAD></HEAD>\n<BODY ");
+
/* automatically fire up a read-new-msgs in the bottom frame */
if (!noframes)
wprintf("onload=location=\"/readnew\" ");
- wprintf("BACKGROUND=\"/image&name=background\" TEXT=\"#000000\" LINK=\"#004400\">\n");
- }
-
+ wprintf("BACKGROUND=\"/image&name=background\" TEXT=\"#000000\" LINK=\"#004400\">\n");
+ }
if (display_name != 2) {
/* store ungoto information */
strcpy(ugname, wc_roomname);
uglsn = ls;
- }
-
+ }
/* move to the new room */
serv_printf("GOTO %s", gname);
serv_gets(buf);
- if (buf[0]!='2') {
+ if (buf[0] != '2') {
serv_puts("GOTO _BASEROOM_");
serv_gets(buf);
- }
- if (buf[0]!='2') {
+ }
+ if (buf[0] != '2') {
if (display_name) {
- wprintf("<EM>%s</EM><BR>\n",&buf[4]);
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
wDumpContent(1);
- }
- return;
}
-
- extract(wc_roomname,&buf[4],0);
- room_flags = extract_int(&buf[4],4);
+ return;
+ }
+ extract(wc_roomname, &buf[4], 0);
+ 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); */
+ 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;
- else is_room_aide = (char) extract_int(&buf[4],8);
+ if (is_aide)
+ is_room_aide = is_aide;
+ else
+ is_room_aide = (char) extract_int(&buf[4], 8);
remove_march(wc_roomname);
- if (!strcasecmp(gname,"_BASEROOM_")) remove_march(gname);
+ if (!strcasecmp(gname, "_BASEROOM_"))
+ remove_march(gname);
/* Display the room banner */
if (display_name) {
wprintf("<CENTER><TABLE border=0><TR>");
- if ( (strlen(ugname)>0) && (strcasecmp(ugname,wc_roomname)) ) {
+ if ((strlen(ugname) > 0) && (strcasecmp(ugname, 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\"><H1>%s</H1>",wc_roomname);
+ }
+ wprintf("<TD VALIGN=TOP><FONT FACE=\"Arial,Helvetica,sans-serif\"><H1>%s</H1>", wc_roomname);
wprintf("%d new of %d messages</FONT></TD>\n",
- extract_int(&buf[4],1),
- extract_int(&buf[4],2));
+ extract_int(&buf[4], 1),
+ extract_int(&buf[4], 2));
/* Display room graphic. The server doesn't actually
* need the room name, but we supply it in order to
*/
serv_puts("OIMG _roompic_");
serv_gets(buf);
- if (buf[0]=='2') {
+ if (buf[0] == '2') {
wprintf("<TD><FONT FACE=\"Arial,Helvetica,sans-serif\">");
wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
escputs(wc_roomname);
wprintf("\"></FONT></TD>");
serv_puts("CLOS");
serv_gets(buf);
- }
-
+ }
wprintf("<TD VALIGN=TOP><FONT FACE=\"Arial,Helvetica,sans-serif\">");
readinfo(0);
wprintf("</FONT></TD>");
wprintf("</TR></TABLE></CENTER>\n");
wDumpContent(1);
- }
-
- strcpy(wc_roomname, wc_roomname);
}
+ strcpy(wc_roomname, wc_roomname);
+}
/*
* Locate the room on the march list which we most want to go to. Each room
* is measured given a "weight" of preference based on various factors.
*/
-char *pop_march(int desired_floor) {
+char *pop_march(int desired_floor)
+{
static char TheRoom[64];
int TheFloor = 0;
int TheOrder = 32767;
struct march *mptr = NULL;
strcpy(TheRoom, "_BASEROOM_");
- if (march == NULL) return(TheRoom);
+ if (march == NULL)
+ return (TheRoom);
for (mptr = march; mptr != NULL; mptr = mptr->next) {
weight = 0;
if (mptr->march_floor == desired_floor)
weight = weight + 5000;
- weight = weight + ((128-(mptr->march_floor))*128);
- weight = weight + (128-(mptr->march_order));
+ weight = weight + ((128 - (mptr->march_floor)) * 128);
+ weight = weight + (128 - (mptr->march_order));
if (weight > TheWeight) {
TheWeight = weight;
strcpy(TheRoom, mptr->march_name);
TheFloor = mptr->march_floor;
TheOrder = mptr->march_order;
- }
}
- return(TheRoom);
}
+ return (TheRoom);
+}
* We start the search in the current room rather than the beginning to prevent
* two or more concurrent users from dragging each other back to the same room.
*/
-void gotonext(void) {
+void gotonext(void)
+{
char buf[256];
- struct march *mptr,*mptr2;
+ struct march *mptr, *mptr2;
char next_room[32];
/* First check to see if the march-mode list is already allocated.
* If it is, pop the first room off the list and go there.
*/
- if (march==NULL) {
+ if (march == NULL) {
serv_puts("LKRN");
serv_gets(buf);
- if (buf[0]=='1')
- while (serv_gets(buf), strcmp(buf,"000")) {
- mptr = (struct march *) malloc(sizeof(struct march));
- mptr->next = NULL;
- extract(mptr->march_name,buf,0);
- mptr->march_floor = extract_int(buf, 2);
- mptr->march_order = extract_int(buf, 3);
- if (march==NULL) {
- march = mptr;
- }
- else {
- mptr2 = march;
- while (mptr2->next != NULL)
- mptr2 = mptr2->next;
- mptr2->next = mptr;
+ if (buf[0] == '1')
+ while (serv_gets(buf), strcmp(buf, "000")) {
+ mptr = (struct march *) malloc(sizeof(struct march));
+ mptr->next = NULL;
+ extract(mptr->march_name, buf, 0);
+ mptr->march_floor = extract_int(buf, 2);
+ mptr->march_order = extract_int(buf, 3);
+ if (march == NULL) {
+ march = mptr;
+ } else {
+ mptr2 = march;
+ while (mptr2->next != NULL)
+ mptr2 = mptr2->next;
+ mptr2->next = mptr;
}
}
-
/* add _BASEROOM_ to the end of the march list, so the user will end up
* in the system base room (usually the Lobby>) at the end of the loop
*/
mptr = (struct march *) malloc(sizeof(struct march));
mptr->next = NULL;
- strcpy(mptr->march_name,"_BASEROOM_");
- if (march==NULL) {
+ strcpy(mptr->march_name, "_BASEROOM_");
+ if (march == NULL) {
march = mptr;
- }
- else {
+ } else {
mptr2 = march;
while (mptr2->next != NULL)
mptr2 = mptr2->next;
mptr2->next = mptr;
- }
+ }
/*
* ...and remove the room we're currently in, so a <G>oto doesn't make us
* walk around in circles
*/
remove_march(wc_roomname);
- }
-
-
- if (march!=NULL) {
+ }
+ if (march != NULL) {
strcpy(next_room, pop_march(-1));
- }
- else {
- strcpy(next_room,"_BASEROOM_");
- }
- gotoroom(next_room,1);
- }
+ } else {
+ strcpy(next_room, "_BASEROOM_");
+ }
+ gotoroom(next_room, 1);
+}
/*
* mark all messages in current room as having been read
*/
-void slrp_highest(void) {
+void slrp_highest(void)
+{
char buf[256];
/* set pointer */
serv_puts("SLRP HIGHEST");
serv_gets(buf);
- if (buf[0]!='2') {
- wprintf("<EM>%s</EM><BR>\n",&buf[4]);
+ if (buf[0] != '2') {
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
return;
- }
}
+}
/*
* un-goto the previous room
*/
-void ungoto(void) {
+void ungoto(void)
+{
char buf[256];
-
+
if (!strcmp(ugname, "")) {
gotoroom(wc_roomname, 1);
return;
- }
+ }
serv_printf("GOTO %s", ugname);
serv_gets(buf);
- if (buf[0]!='2') {
+ if (buf[0] != '2') {
gotoroom(wc_roomname, 1);
return;
- }
+ }
if (uglsn >= 0L) {
- serv_printf("SLRP %ld",uglsn);
+ serv_printf("SLRP %ld", uglsn);
serv_gets(buf);
- }
- strcpy(buf,ugname);
- strcpy(ugname, "");
- gotoroom(buf,1);
}
+ strcpy(buf, ugname);
+ strcpy(ugname, "");
+ gotoroom(buf, 1);
+}
/*
* display the form for editing a room
*/
-void display_editroom(void) {
+void display_editroom(void)
+{
char buf[256];
char er_name[20];
char er_password[10];
serv_puts("GETR");
serv_gets(buf);
- if (buf[0]!='2') {
+ if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
-
- extract(er_name,&buf[4],0);
- extract(er_password,&buf[4],1);
- extract(er_dirname,&buf[4],2);
- er_flags=extract_int(&buf[4],3);
- er_floor=extract_int(&buf[4],4);
+ }
+ extract(er_name, &buf[4], 0);
+ extract(er_password, &buf[4], 1);
+ extract(er_dirname, &buf[4], 2);
+ er_flags = extract_int(&buf[4], 3);
+ er_floor = extract_int(&buf[4], 4);
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Edit this room</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Edit this room</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
- wprintf("<UL><LI>Name of room: ");
- wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n",er_name);
+ wprintf("<UL><LI>Name of room: ");
+ wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
wprintf("<LI>Resides on floor: ");
load_floorlist();
wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
- for (i=0; i<128; ++i) if (strlen(floorlist[i])>0) {
- wprintf("<OPTION ");
- if (i == er_floor) wprintf("SELECTED ");
- wprintf("VALUE=\"%d\">", i);
- escputs(floorlist[i]);
- wprintf("</OPTION>\n");
+ for (i = 0; i < 128; ++i)
+ if (strlen(floorlist[i]) > 0) {
+ wprintf("<OPTION ");
+ if (i == er_floor)
+ wprintf("SELECTED ");
+ wprintf("VALUE=\"%d\">", i);
+ escputs(floorlist[i]);
+ wprintf("</OPTION>\n");
}
wprintf("</SELECT>\n");
wprintf("<LI>Type of room:<UL>\n");
wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
- if ((er_flags & QR_PRIVATE) == 0) wprintf("CHECKED ");
+ if ((er_flags & QR_PRIVATE) == 0)
+ wprintf("CHECKED ");
wprintf("> Public room\n");
wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
- if ((er_flags & QR_PRIVATE)&&
- (er_flags & QR_GUESSNAME)) wprintf("CHECKED ");
+ if ((er_flags & QR_PRIVATE) &&
+ (er_flags & QR_GUESSNAME))
+ wprintf("CHECKED ");
wprintf("> Private - guess name\n");
wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
- if ((er_flags & QR_PRIVATE)&&
- (er_flags & QR_PASSWORDED)) wprintf("CHECKED ");
+ if ((er_flags & QR_PRIVATE) &&
+ (er_flags & QR_PASSWORDED))
+ wprintf("CHECKED ");
wprintf("> Private - require password:\n");
- wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n",er_password);
+ wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
- if ( (er_flags & QR_PRIVATE)
- && ((er_flags & QR_GUESSNAME) == 0)
- && ((er_flags & QR_PASSWORDED) == 0) )
+ if ((er_flags & QR_PRIVATE)
+ && ((er_flags & QR_GUESSNAME) == 0)
+ && ((er_flags & QR_PASSWORDED) == 0))
wprintf("CHECKED ");
wprintf("> Private - invitation only\n");
wprintf("</UL>\n");
wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
- if (er_flags & QR_PREFONLY) wprintf("CHECKED ");
+ if (er_flags & QR_PREFONLY)
+ wprintf("CHECKED ");
wprintf("> Preferred users only\n");
wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
- if (er_flags & QR_READONLY) wprintf("CHECKED ");
+ if (er_flags & QR_READONLY)
+ wprintf("CHECKED ");
wprintf("> Read-only room\n");
/* directory stuff */
wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
- if (er_flags & QR_DIRECTORY) wprintf("CHECKED ");
+ if (er_flags & QR_DIRECTORY)
+ wprintf("CHECKED ");
wprintf("> File directory room\n");
wprintf("<UL><LI>Directory name: ");
- wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n",er_dirname);
+ wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
- if (er_flags & QR_UPLOAD) wprintf("CHECKED ");
+ if (er_flags & QR_UPLOAD)
+ wprintf("CHECKED ");
wprintf("> Uploading allowed\n");
wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
- if (er_flags & QR_DOWNLOAD) wprintf("CHECKED ");
+ if (er_flags & QR_DOWNLOAD)
+ wprintf("CHECKED ");
wprintf("> Downloading allowed\n");
wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
- if (er_flags & QR_VISDIR) wprintf("CHECKED ");
+ if (er_flags & QR_VISDIR)
+ wprintf("CHECKED ");
wprintf("> Visible directory</UL>\n");
/* end of directory stuff */
-
+
wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
- if (er_flags & QR_NETWORK) wprintf("CHECKED ");
+ if (er_flags & QR_NETWORK)
+ wprintf("CHECKED ");
wprintf("> Network shared room\n");
/* start of anon options */
wprintf("<LI>Anonymous messages<UL>\n");
-
+
wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
- if ( ((er_flags & QR_ANONONLY)==0)
- && ((er_flags & QR_ANONOPT)==0)) wprintf("CHECKED ");
+ if (((er_flags & QR_ANONONLY) == 0)
+ && ((er_flags & QR_ANONOPT) == 0))
+ wprintf("CHECKED ");
wprintf("> No anonymous messages\n");
wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
- if (er_flags & QR_ANONONLY) wprintf("CHECKED ");
+ if (er_flags & QR_ANONONLY)
+ wprintf("CHECKED ");
wprintf("> All messages are anonymous\n");
wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
- if (er_flags & QR_ANONOPT) wprintf("CHECKED ");
+ if (er_flags & QR_ANONOPT)
+ wprintf("CHECKED ");
wprintf("> Prompt user when entering messages</UL>\n");
/* end of anon options */
wprintf("<LI>Room aide: \n");
serv_puts("GETA");
serv_gets(buf);
- if (buf[0]!='2') {
- wprintf("<EM>%s</EM>\n",&buf[4]);
- }
- else {
- extract(er_roomaide,&buf[4],0);
- wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n",er_roomaide);
- }
-
+ if (buf[0] != '2') {
+ wprintf("<EM>%s</EM>\n", &buf[4]);
+ } else {
+ extract(er_roomaide, &buf[4], 0);
+ wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
+ }
+
wprintf("</UL><CENTER>\n");
wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
wprintf("</CENTER>\n");
wDumpContent(1);
- }
+}
/*
* save new parameters for a room
*/
-void editroom(void) {
+void editroom(void)
+{
char buf[256];
char er_name[20];
char er_password[10];
int bump;
- if (strcmp(bstr("sc"),"OK")) {
+ if (strcmp(bstr("sc"), "OK")) {
display_error("Cancelled. Changes were not saved.");
return;
- }
-
+ }
serv_puts("GETR");
serv_gets(buf);
- if (buf[0]!='2') {
+ if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
-
- extract(er_name,&buf[4],0);
- extract(er_password,&buf[4],1);
- extract(er_dirname,&buf[4],2);
- er_flags=extract_int(&buf[4],3);
+ }
+ extract(er_name, &buf[4], 0);
+ extract(er_password, &buf[4], 1);
+ extract(er_dirname, &buf[4], 2);
+ er_flags = extract_int(&buf[4], 3);
- strcpy(er_roomaide,bstr("er_roomaide"));
- if (strlen(er_roomaide)==0) {
+ strcpy(er_roomaide, bstr("er_roomaide"));
+ if (strlen(er_roomaide) == 0) {
serv_puts("GETA");
serv_gets(buf);
- if (buf[0]!='2') {
- strcpy(er_roomaide,"");
- }
- else {
- extract(er_roomaide,&buf[4],0);
- }
+ if (buf[0] != '2') {
+ strcpy(er_roomaide, "");
+ } else {
+ extract(er_roomaide, &buf[4], 0);
}
+ }
+ strcpy(buf, bstr("er_name"));
+ buf[20] = 0;
+ if (strlen(buf) > 0)
+ strcpy(er_name, buf);
- strcpy(buf,bstr("er_name")); buf[20] = 0;
- if (strlen(buf)>0) strcpy(er_name,buf);
-
- strcpy(buf,bstr("er_password")); buf[10] = 0;
- if (strlen(buf)>0) strcpy(er_password,buf);
+ strcpy(buf, bstr("er_password"));
+ buf[10] = 0;
+ if (strlen(buf) > 0)
+ strcpy(er_password, buf);
- strcpy(buf,bstr("er_dirname")); buf[15] = 0;
- if (strlen(buf)>0) strcpy(er_dirname,buf);
+ strcpy(buf, bstr("er_dirname"));
+ buf[15] = 0;
+ if (strlen(buf) > 0)
+ strcpy(er_dirname, buf);
- strcpy(buf,bstr("type"));
- er_flags &= !(QR_PRIVATE|QR_PASSWORDED|QR_GUESSNAME);
+ strcpy(buf, bstr("type"));
+ er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
- if (!strcmp(buf,"invonly")) {
+ if (!strcmp(buf, "invonly")) {
er_flags |= (QR_PRIVATE);
- }
- if (!strcmp(buf,"guessname")) {
+ }
+ if (!strcmp(buf, "guessname")) {
er_flags |= (QR_PRIVATE | QR_GUESSNAME);
- }
- if (!strcmp(buf,"passworded")) {
+ }
+ if (!strcmp(buf, "passworded")) {
er_flags |= (QR_PRIVATE | QR_PASSWORDED);
- }
-
- if (!strcmp(bstr("prefonly"),"yes")) {
+ }
+ if (!strcmp(bstr("prefonly"), "yes")) {
er_flags |= QR_PREFONLY;
- }
- else {
+ } else {
er_flags &= ~QR_PREFONLY;
- }
+ }
- if (!strcmp(bstr("readonly"),"yes")) {
+ if (!strcmp(bstr("readonly"), "yes")) {
er_flags |= QR_READONLY;
- }
- else {
+ } else {
er_flags &= ~QR_READONLY;
- }
+ }
- if (!strcmp(bstr("network"),"yes")) {
+ if (!strcmp(bstr("network"), "yes")) {
er_flags |= QR_NETWORK;
- }
- else {
+ } else {
er_flags &= ~QR_NETWORK;
- }
+ }
- if (!strcmp(bstr("directory"),"yes")) {
+ if (!strcmp(bstr("directory"), "yes")) {
er_flags |= QR_DIRECTORY;
- }
- else {
+ } else {
er_flags &= ~QR_DIRECTORY;
- }
+ }
- if (!strcmp(bstr("ulallowed"),"yes")) {
+ if (!strcmp(bstr("ulallowed"), "yes")) {
er_flags |= QR_UPLOAD;
- }
- else {
+ } else {
er_flags &= ~QR_UPLOAD;
- }
+ }
- if (!strcmp(bstr("dlallowed"),"yes")) {
+ if (!strcmp(bstr("dlallowed"), "yes")) {
er_flags |= QR_DOWNLOAD;
- }
- else {
+ } else {
er_flags &= ~QR_DOWNLOAD;
- }
+ }
- if (!strcmp(bstr("visdir"),"yes")) {
+ if (!strcmp(bstr("visdir"), "yes")) {
er_flags |= QR_VISDIR;
- }
- else {
+ } else {
er_flags &= ~QR_VISDIR;
- }
+ }
- strcpy(buf,bstr("anon"));
+ strcpy(buf, bstr("anon"));
er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
- if (!strcmp(buf,"anononly")) er_flags |= QR_ANONONLY;
- if (!strcmp(buf,"anon2")) er_flags |= QR_ANONOPT;
+ if (!strcmp(buf, "anononly"))
+ er_flags |= QR_ANONONLY;
+ if (!strcmp(buf, "anon2"))
+ er_flags |= QR_ANONOPT;
bump = 0;
- if (!strcmp(bstr("bump"),"yes")) bump = 1;
+ if (!strcmp(bstr("bump"), "yes"))
+ bump = 1;
er_floor = atoi(bstr("er_floor"));
- sprintf(buf,"SETR %s|%s|%s|%u|%d|%d",
- er_name,er_password,er_dirname,er_flags,bump,er_floor);
+ sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
+ er_name, er_password, er_dirname, er_flags, bump, er_floor);
serv_puts(buf);
serv_gets(buf);
- if (buf[0]!='2') {
+ if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
+ }
gotoroom(er_name, 0);
- if (strlen(er_roomaide)>0) {
- sprintf(buf,"SETA %s",er_roomaide);
+ if (strlen(er_roomaide) > 0) {
+ sprintf(buf, "SETA %s", er_roomaide);
serv_puts(buf);
serv_gets(buf);
- if (buf[0]!='2') {
+ if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
}
-
- gotoroom(er_name, 1);
}
+ gotoroom(er_name, 1);
+}
/*
* display the form for entering a new room
*/
-void display_entroom(void) {
+void display_entroom(void)
+{
char buf[256];
serv_puts("CRE8 0");
serv_gets(buf);
-
- if (buf[0]!='2') {
+
+ if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
-
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
+ }
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Enter (create) a new room</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Enter (create) a new room</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
- wprintf("<UL><LI>Name of room: ");
+ wprintf("<UL><LI>Name of room: ");
wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
wprintf("<LI>Type of room:<UL>\n");
wprintf("</CENTER>\n");
wprintf("</FORM>\n");
wDumpContent(1);
- }
+}
/*
* enter a new room
*/
-void entroom(void) {
+void entroom(void)
+{
char buf[256];
char er_name[20];
char er_type[20];
char er_password[10];
int er_num_type;
- if (strcmp(bstr("sc"),"OK")) {
+ if (strcmp(bstr("sc"), "OK")) {
display_error("Cancelled. No new room was created.");
return;
- }
-
- strcpy(er_name,bstr("er_name"));
- strcpy(er_type,bstr("type"));
- strcpy(er_password,bstr("er_password"));
+ }
+ strcpy(er_name, bstr("er_name"));
+ strcpy(er_type, bstr("type"));
+ strcpy(er_password, bstr("er_password"));
er_num_type = 0;
- if (!strcmp(er_type,"guessname")) er_num_type = 1;
- if (!strcmp(er_type,"passworded")) er_num_type = 2;
- if (!strcmp(er_type,"invonly")) er_num_type = 3;
-
- sprintf(buf,"CRE8 1|%s|%d|%s",er_name,er_num_type,er_password);
+ if (!strcmp(er_type, "guessname"))
+ er_num_type = 1;
+ if (!strcmp(er_type, "passworded"))
+ er_num_type = 2;
+ if (!strcmp(er_type, "invonly"))
+ er_num_type = 3;
+
+ sprintf(buf, "CRE8 1|%s|%d|%s", er_name, er_num_type, er_password);
serv_puts(buf);
serv_gets(buf);
- if (buf[0]!='2') {
+ if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
- gotoroom(er_name, 1);
}
+ gotoroom(er_name, 1);
+}
/*
void display_private(char *rname, int req_pass)
{
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Goto a private room</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Goto a private room</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
wprintf("<CENTER>\n");
wprintf("If you know the name of a hidden (guess-name) or\n");
wprintf("room, it will appear in your regular room listings\n");
wprintf("so you don't have to keep returning here.\n");
wprintf("<BR><BR>");
-
+
wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
wprintf("<TABLE border><TR><TD>");
wprintf("Enter room name:</TD><TD>");
- wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n",rname);
+ wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
if (req_pass) {
wprintf("</TD></TR><TR><TD>");
wprintf("Enter room password:</TD><TD>");
wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
- }
-
+ }
wprintf("</TD></TR></TABLE>\n");
-
+
wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
wprintf("</FORM>\n");
wDumpContent(1);
- }
+}
/*
* goto a private room
*/
-void goto_private(void) {
+void goto_private(void)
+{
char hold_rm[32];
char buf[256];
-
- if (strcasecmp(bstr("sc"),"OK")) {
+
+ if (strcasecmp(bstr("sc"), "OK")) {
display_main_menu();
return;
- }
-
- strcpy(hold_rm,wc_roomname);
- strcpy(buf,"GOTO ");
- strcat(buf,bstr("gr_name"));
- strcat(buf,"|");
- strcat(buf,bstr("gr_pass"));
+ }
+ strcpy(hold_rm, wc_roomname);
+ strcpy(buf, "GOTO ");
+ strcat(buf, bstr("gr_name"));
+ strcat(buf, "|");
+ strcat(buf, bstr("gr_pass"));
serv_puts(buf);
serv_gets(buf);
- if (buf[0]=='2') {
- gotoroom(bstr("gr_name"),1);
+ if (buf[0] == '2') {
+ gotoroom(bstr("gr_name"), 1);
return;
- }
-
- if (!strncmp(buf,"540",3)) {
- display_private(bstr("gr_name"),1);
+ }
+ if (!strncmp(buf, "540", 3)) {
+ display_private(bstr("gr_name"), 1);
return;
- }
-
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
- wprintf("%s\n",&buf[4]);
+ }
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
+ wprintf("%s\n", &buf[4]);
wDumpContent(1);
return;
- }
+}
/*
* display the screen to zap a room
*/
-void display_zap(void) {
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
-
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Zap (forget) the current room</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+void display_zap(void)
+{
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
+
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ 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("disappear from your room list. Is this what you wish ");
wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
wprintf("</FORM>\n");
wDumpContent(1);
- }
+}
/*
* zap a room
*/
-void zap(void) {
+void zap(void)
+{
char buf[256];
- if (strcmp(bstr("sc"),"OK")) {
+ if (strcmp(bstr("sc"), "OK")) {
display_main_menu();
return;
- }
-
+ }
serv_printf("GOTO %s", wc_roomname);
serv_gets(buf);
if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
-
+ }
serv_puts("FORG");
serv_gets(buf);
if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
-
- gotoroom(bstr("_BASEROOM_"),1);
}
+ gotoroom(bstr("_BASEROOM_"), 1);
+}
/*
* Confirm deletion of the current room
*/
-void confirm_delete_room(void) {
+void confirm_delete_room(void)
+{
char buf[256];
-
+
serv_puts("KILL 0");
serv_gets(buf);
if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
-
+ }
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
wprintf("</FORM></CENTER>\n");
wDumpContent(1);
- }
+}
/*
* Delete the current room
*/
-void delete_room(void) {
+void delete_room(void)
+{
char buf[256];
char sc[256];
strcpy(sc, bstr("sc"));
-
+
if (strcasecmp(sc, "Delete")) {
display_error("Cancelled. This room was not deleted.");
return;
- }
-
+ }
serv_puts("KILL 1");
serv_gets(buf);
if (buf[0] != '2') {
display_error(&buf[4]);
- }
- else {
+ } else {
gotoroom("_BASEROOM_", 1);
- }
}
-
-
-
+}
/*
* get info about the server we've connected to
*/
-void get_serv_info(char *browser_host) {
+void get_serv_info(char *browser_host)
+{
char buf[256];
int a;
serv_printf("IDEN %d|%d|%d|%s|%s",
- DEVELOPER_ID,
- CLIENT_ID,
- CLIENT_VERSION,
- SERVER,
- browser_host
- );
+ DEVELOPER_ID,
+ CLIENT_ID,
+ CLIENT_VERSION,
+ SERVER,
+ browser_host
+ );
serv_gets(buf);
serv_puts("INFO");
serv_gets(buf);
- if (buf[0]!='1') return;
+ if (buf[0] != '1')
+ return;
a = 0;
- while(serv_gets(buf), strcmp(buf,"000")) {
- switch(a) {
- case 0: serv_info.serv_pid = atoi(buf);
- break;
- case 1: strcpy(serv_info.serv_nodename,buf);
- break;
- case 2: strcpy(serv_info.serv_humannode,buf);
- break;
- case 3: strcpy(serv_info.serv_fqdn,buf);
- break;
- case 4: strcpy(serv_info.serv_software,buf);
- break;
- case 5: serv_info.serv_rev_level = atoi(buf);
- break;
- case 6: strcpy(serv_info.serv_bbs_city,buf);
- break;
- case 7: strcpy(serv_info.serv_sysadm,buf);
- break;
- case 9: strcpy(serv_info.serv_moreprompt,buf);
- break;
+ while (serv_gets(buf), strcmp(buf, "000")) {
+ switch (a) {
+ case 0:
+ serv_info.serv_pid = atoi(buf);
+ break;
+ case 1:
+ strcpy(serv_info.serv_nodename, buf);
+ break;
+ case 2:
+ strcpy(serv_info.serv_humannode, buf);
+ break;
+ case 3:
+ strcpy(serv_info.serv_fqdn, buf);
+ break;
+ case 4:
+ strcpy(serv_info.serv_software, buf);
+ break;
+ case 5:
+ serv_info.serv_rev_level = atoi(buf);
+ break;
+ case 6:
+ strcpy(serv_info.serv_bbs_city, buf);
+ break;
+ case 7:
+ strcpy(serv_info.serv_sysadm, buf);
+ break;
+ case 9:
+ strcpy(serv_info.serv_moreprompt, buf);
+ break;
}
- ++a;
- }
+ ++a;
}
+}
* If fp is non-null, it is considered to be the file handle to read the
* text from. Otherwise, text is read from the server.
*/
-void fmout(FILE *fp)
+void fmout(FILE * fp)
{
int intext = 0;
int bq = 0;
char buf[256];
- while(1) {
- if (fp==NULL) serv_gets(buf);
- if (fp!=NULL) {
- if (fgets(buf,256,fp)==NULL) strcpy(buf,"000");
- buf[strlen(buf)-1] = 0;
- }
- if (!strcmp(buf,"000")) {
- if (bq==1) wprintf("</I>");
+ while (1) {
+ if (fp == NULL)
+ serv_gets(buf);
+ if (fp != NULL) {
+ if (fgets(buf, 256, fp) == NULL)
+ strcpy(buf, "000");
+ buf[strlen(buf) - 1] = 0;
+ }
+ if (!strcmp(buf, "000")) {
+ if (bq == 1)
+ wprintf("</I>");
wprintf("<P>\n");
return;
- }
- if ( (intext==1) && (isspace(buf[0])) ) {
+ }
+ if ((intext == 1) && (isspace(buf[0]))) {
wprintf("<BR>");
- }
+ }
intext = 1;
/* Quoted text should be displayed in italics and in a
* different colour. This code understands both Citadel/UX
* style " >" quotes and FordBoard-style " :-)" quotes.
*/
- if ((bq==0)&&
- ((!strncmp(buf," >",2))||(!strncmp(buf," :-)",4)))) {
+ if ((bq == 0) &&
+ ((!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
wprintf("<FONT COLOR=\"000044\"><I>");
bq = 1;
- }
- else if ((bq==1)&&
- (strncmp(buf," >",2))&&(strncmp(buf," :-)",4))) {
+ } else if ((bq == 1) &&
+ (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
wprintf("</FONT></I>");
bq = 0;
- }
-
+ }
/* Activate embedded URL's */
url(buf);
escputs(buf);
wprintf("\n");
- }
}
+}
/*
* transmit message text (in memory) to the server
*/
-void text_to_server(char *ptr) {
+void text_to_server(char *ptr)
+{
char buf[256];
- int ch,a,pos;
+ int ch, a, pos;
pos = 0;
-
- strcpy(buf,"");
- while (ptr[pos]!=0) {
+
+ strcpy(buf, "");
+ while (ptr[pos] != 0) {
ch = ptr[pos++];
- if (ch==10) {
- while (isspace(buf[strlen(buf)-1]))
- buf[strlen(buf)-1]=0;
+ if (ch == 10) {
+ while (isspace(buf[strlen(buf) - 1]))
+ buf[strlen(buf) - 1] = 0;
serv_puts(buf);
- strcpy(buf,"");
- }
- else {
+ strcpy(buf, "");
+ } else {
a = strlen(buf);
- buf[a+1] = 0;
+ buf[a + 1] = 0;
buf[a] = ch;
- if ((ch==32)&&(strlen(buf)>200)) {
- buf[a]=0;
+ if ((ch == 32) && (strlen(buf) > 200)) {
+ buf[a] = 0;
serv_puts(buf);
- strcpy(buf,"");
- }
- if (strlen(buf)>250) {
+ strcpy(buf, "");
+ }
+ if (strlen(buf) > 250) {
serv_puts(buf);
- strcpy(buf,"");
- }
+ strcpy(buf, "");
}
}
- serv_puts(buf);
}
+ serv_puts(buf);
+}
* translate server message output to text
* (used for editing room info files and such)
*/
-void server_to_text() {
- char buf[256];
+void server_to_text()
+{
+ char buf[256];
int count = 0;
- while (serv_gets(buf), strcmp(buf, "000") ) {
- if ( (buf[0] == 32) && (count > 0) ) {
+ while (serv_gets(buf), strcmp(buf, "000")) {
+ if ((buf[0] == 32) && (count > 0)) {
wprintf("\n");
- }
+ }
wprintf("%s", buf);
++count;
- }
}
-
-
-
-
+}
#include "child.h"
-void display_siteconfig(void) {
+void display_siteconfig(void)
+{
char buf[256];
int i = 0;
serv_printf("CONF get");
serv_gets(buf);
- if (buf[0]!='1') {
+ if (buf[0] != '1') {
display_error(&buf[4]);
return;
}
-
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Site configuration");
- wprintf("</B></FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Site configuration");
+ wprintf("</B></FONT></TD></TR></TABLE>\n");
wprintf("<FORM METHOD=\"POST\" ACTION=\"/siteconfig\">\n");
wprintf("<TABLE border=0>\n");
while (serv_gets(buf), strcmp(buf, "000")) {
- ++i;
- switch(i) {
- case 1: wprintf("<TR><TD>Node name</TD><TD>");
+ ++i;
+ switch (i) {
+ case 1:
+ wprintf("<TR><TD>Node name</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_nodename\" MAXLENGTH=\"15\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 2: wprintf("<TR><TD>Fully qualified domain name</TD><TD>");
+ case 2:
+ wprintf("<TR><TD>Fully qualified domain name</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_fqdn\" MAXLENGTH=\"63\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 3: wprintf("<TR><TD>Human-readable node name</TD><TD>");
+ case 3:
+ wprintf("<TR><TD>Human-readable node name</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_humannode\" MAXLENGTH=\"20\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 4: wprintf("<TR><TD>Landline telephone number</TD><TD>");
+ case 4:
+ wprintf("<TR><TD>Landline telephone number</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_phonenum\" MAXLENGTH=\"15\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 5: wprintf("<TR><TD>Automatically grant room-aide status to users who create private rooms</TD><TD>");
- wprintf("<INPUT TYPE=\"checkbox\" NAME=\"c_creataide\" VALUE=\"yes\" %s>", ((atoi(buf)!=0) ? "CHECKED" : ""));
+ case 5:
+ wprintf("<TR><TD>Automatically grant room-aide status to users who create private rooms</TD><TD>");
+ wprintf("<INPUT TYPE=\"checkbox\" NAME=\"c_creataide\" VALUE=\"yes\" %s>", ((atoi(buf) != 0) ? "CHECKED" : ""));
wprintf("</TD></TR>\n");
break;
- case 6: wprintf("<TR><TD>Server connection idle timeout (in seconds)</TD><TD>");
+ case 6:
+ wprintf("<TR><TD>Server connection idle timeout (in seconds)</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_sleeping\" MAXLENGTH=\"15\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 7: wprintf("<TR><TD>Initial access level for new users</TD><TD>");
+ case 7:
+ wprintf("<TR><TD>Initial access level for new users</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_initax\" MAXLENGTH=\"1\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 8: wprintf("<TR><TD>Require registration for new users</TD><TD>");
- wprintf("<INPUT TYPE=\"checkbox\" NAME=\"c_regiscall\" VALUE=\"yes\" %s>", ((atoi(buf)!=0) ? "CHECKED" : ""));
+ case 8:
+ wprintf("<TR><TD>Require registration for new users</TD><TD>");
+ wprintf("<INPUT TYPE=\"checkbox\" NAME=\"c_regiscall\" VALUE=\"yes\" %s>", ((atoi(buf) != 0) ? "CHECKED" : ""));
wprintf("</TD></TR>\n");
break;
- case 9: wprintf("<TR><TD>Move problem user messages to twitroom</TD><TD>");
- wprintf("<INPUT TYPE=\"checkbox\" NAME=\"c_twitdetect\" VALUE=\"yes\" %s>", ((atoi(buf)!=0) ? "CHECKED" : ""));
+ case 9:
+ wprintf("<TR><TD>Move problem user messages to twitroom</TD><TD>");
+ wprintf("<INPUT TYPE=\"checkbox\" NAME=\"c_twitdetect\" VALUE=\"yes\" %s>", ((atoi(buf) != 0) ? "CHECKED" : ""));
wprintf("</TD></TR>\n");
break;
- case 10:wprintf("<TR><TD>Name of twitroom</TD><TD>");
+ case 10:
+ wprintf("<TR><TD>Name of twitroom</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_twitroom\" MAXLENGTH=\"63\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 11:wprintf("<TR><TD>Paginator prompt</TD><TD>");
+ case 11:
+ wprintf("<TR><TD>Paginator prompt</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_moreprompt\" MAXLENGTH=\"79\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 12:wprintf("<TR><TD>Restrict access to Internet mail</TD><TD>");
- wprintf("<INPUT TYPE=\"checkbox\" NAME=\"c_restrict\" VALUE=\"yes\" %s>", ((atoi(buf)!=0) ? "CHECKED" : ""));
+ case 12:
+ wprintf("<TR><TD>Restrict access to Internet mail</TD><TD>");
+ wprintf("<INPUT TYPE=\"checkbox\" NAME=\"c_restrict\" VALUE=\"yes\" %s>", ((atoi(buf) != 0) ? "CHECKED" : ""));
wprintf("</TD></TR>\n");
break;
- case 13:wprintf("<TR><TD>Geographic location of this system</TD><TD>");
+ case 13:
+ wprintf("<TR><TD>Geographic location of this system</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_bbs_city\" MAXLENGTH=\"31\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 14:wprintf("<TR><TD>Name of system administrator</TD><TD>");
+ case 14:
+ wprintf("<TR><TD>Name of system administrator</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_sysadm\" MAXLENGTH=\"25\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 15:wprintf("<TR><TD>Maximum concurrent sessions</TD><TD>");
+ case 15:
+ wprintf("<TR><TD>Maximum concurrent sessions</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_maxsessions\" MAXLENGTH=\"5\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 16:wprintf("<TR><TD>Server-to-server networking password</TD><TD>");
+ case 16:
+ wprintf("<TR><TD>Server-to-server networking password</TD><TD>");
wprintf("<INPUT TYPE=\"password\" NAME=\"c_net_password\" MAXLENGTH=\"19\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 17:wprintf("<TR><TD>Default user purge time (days)</TD><TD>");
+ case 17:
+ wprintf("<TR><TD>Default user purge time (days)</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_userpurge\" MAXLENGTH=\"5\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 18:wprintf("<TR><TD>Default room purge time (days)</TD><TD>");
+ case 18:
+ wprintf("<TR><TD>Default room purge time (days)</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_roompurge\" MAXLENGTH=\"5\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- case 19:wprintf("<TR><TD>Name of room to log pages</TD><TD>");
+ case 19:
+ wprintf("<TR><TD>Name of room to log pages</TD><TD>");
wprintf("<INPUT TYPE=\"text\" NAME=\"c_logpages\" MAXLENGTH=\"63\" VALUE=\"%s\">", buf);
wprintf("</TD></TR>\n");
break;
- }
+ }
}
wprintf("</TABLE><CENTER>");
}
-void siteconfig(void) {
+void siteconfig(void)
+{
char buf[256];
if (strcasecmp(bstr("sc"), "OK")) {
display_main_menu();
return;
}
-
serv_printf("CONF set");
serv_gets(buf);
- if (buf[0]!='4') {
+ if (buf[0] != '4') {
display_error(&buf[4]);
return;
}
-
serv_printf("%s", bstr("c_nodename"));
serv_printf("%s", bstr("c_fqdn"));
serv_printf("%s", bstr("c_humannode"));
serv_printf("%s", bstr("c_phonenum"));
- serv_printf("%s", ( (!strcasecmp(bstr("c_creataide"), "yes") ? "1" : "0")));
+ serv_printf("%s", ((!strcasecmp(bstr("c_creataide"), "yes") ? "1" : "0")));
serv_printf("%s", bstr("c_sleeping"));
serv_printf("%s", bstr("c_initax"));
- serv_printf("%s", ( (!strcasecmp(bstr("c_regiscall"), "yes") ? "1" : "0")));
- serv_printf("%s", ( (!strcasecmp(bstr("c_twitdetect"), "yes") ? "1" : "0")));
+ serv_printf("%s", ((!strcasecmp(bstr("c_regiscall"), "yes") ? "1" : "0")));
+ serv_printf("%s", ((!strcasecmp(bstr("c_twitdetect"), "yes") ? "1" : "0")));
serv_printf("%s", bstr("c_twitroom"));
serv_printf("%s", bstr("c_moreprompt"));
- serv_printf("%s", ( (!strcasecmp(bstr("c_restrict"), "yes") ? "1" : "0")));
+ serv_printf("%s", ((!strcasecmp(bstr("c_restrict"), "yes") ? "1" : "0")));
serv_printf("%s", bstr("c_bbs_city"));
serv_printf("%s", bstr("c_sysadm"));
serv_printf("%s", bstr("c_maxsessions"));
serv_printf("%s", bstr("c_logpages"));
serv_printf("000");
display_success("System configuration has been updated.");
- }
+}
#include <stdarg.h>
#include <string.h>
-static int
-needed (const char *fmt, va_list argp)
+static int needed(const char *fmt, va_list argp)
{
- static FILE *sink = NULL;
+ static FILE *sink = NULL;
- /* ok, there's a small race here that could result in the sink being
- * opened more than once if we're threaded, but I'd rather ignore it than
- * spend cycles synchronizing :-) */
+ /* ok, there's a small race here that could result in the sink being
+ * opened more than once if we're threaded, but I'd rather ignore it than
+ * spend cycles synchronizing :-) */
- if (sink == NULL)
- {
- if ((sink = fopen("/dev/null", "w")) == NULL)
- {
- perror("/dev/null");
- exit(1);
+ if (sink == NULL) {
+ if ((sink = fopen("/dev/null", "w")) == NULL) {
+ perror("/dev/null");
+ exit(1);
+ }
}
- }
-
- return vfprintf(sink, fmt, argp);
+ return vfprintf(sink, fmt, argp);
}
-int
-vsnprintf (char *buf, size_t max, const char *fmt, va_list argp)
+int vsnprintf(char *buf, size_t max, const char *fmt, va_list argp)
{
- char *p;
- int size;
-
- if ((p = malloc(needed(fmt, argp) + 1)) == NULL)
- {
- fprintf(stderr, "vsnprintf: malloc failed, aborting\n");
- abort();
- }
+ char *p;
+ int size;
- if ((size = vsprintf(p, fmt, argp)) >= max)
- size = -1;
+ if ((p = malloc(needed(fmt, argp) + 1)) == NULL) {
+ fprintf(stderr, "vsnprintf: malloc failed, aborting\n");
+ abort();
+ }
+ if ((size = vsprintf(p, fmt, argp)) >= max)
+ size = -1;
- strncpy(buf, p, max);
- buf[max - 1] = 0;
- free(p);
- return size;
+ strncpy(buf, p, max);
+ buf[max - 1] = 0;
+ free(p);
+ return size;
}
-int
-snprintf (char *buf, size_t max, const char *fmt, ...)
+int snprintf(char *buf, size_t max, const char *fmt,...)
{
- va_list argp;
- int bytes;
+ va_list argp;
+ int bytes;
- va_start(argp, fmt);
- bytes = vsnprintf(buf, max, fmt, argp);
- va_end(argp);
+ va_start(argp, fmt);
+ bytes = vsnprintf(buf, max, fmt, argp);
+ va_end(argp);
- return bytes;
+ return bytes;
}
* display the form for editing something (room info, bio, etc)
*/
void display_edit(char *description, char *check_cmd,
- char *read_cmd, char *save_cmd) {
+ char *read_cmd, char *save_cmd)
+{
char buf[256];
serv_puts(check_cmd);
serv_gets(buf);
- if (buf[0]!='2') {
+ if (buf[0] != '2') {
display_error(&buf[4]);
return;
- }
-
- printf("HTTP/1.0 200 OK\n");
+ }
+ printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Edit ");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>Edit ");
escputs(description);
- wprintf("</B></FONT></TD></TR></TABLE>\n");
+ wprintf("</B></FONT></TD></TR></TABLE>\n");
wprintf("<CENTER>Enter %s below. Text is formatted to\n", description);
wprintf("the <EM>reader's</EM> screen width. To defeat the\n");
wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 WIDTH=80>");
serv_puts(read_cmd);
serv_gets(buf);
- if (buf[0] == '1') server_to_text();
+ if (buf[0] == '1')
+ server_to_text();
wprintf("</TEXTAREA><P>\n");
wprintf("</FORM></CENTER>\n");
wDumpContent(1);
- }
+}
/*
* save a screen which was displayed with display_edit()
*/
-void save_edit(char *description, char *enter_cmd, int regoto) {
+void save_edit(char *description, char *enter_cmd, int regoto)
+{
char buf[256];
- if (strcmp(bstr("sc"),"Save")) {
- printf("HTTP/1.0 200 OK\n");
+ if (strcmp(bstr("sc"), "Save")) {
+ printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
wprintf("Cancelled. %s was not saved.<BR>\n", description);
wDumpContent(1);
return;
- }
-
+ }
serv_puts(enter_cmd);
serv_gets(buf);
- if (buf[0]!='4') {
+ if (buf[0] != '4') {
display_error(&buf[4]);
return;
- }
-
+ }
text_to_server(bstr("msgtext"));
serv_puts("000");
if (regoto) {
gotoroom(wc_roomname, 1);
- }
- else {
- printf("HTTP/1.0 200 OK\n");
+ } else {
+ printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
wprintf("%s has been saved.\n", description);
wDumpContent(1);
- }
- }
+ }
+}
int serv_sock;
-RETSIGTYPE timeout(int signum) {
+RETSIGTYPE timeout(int signum)
+{
fprintf(stderr, "Connection timed out.\n");
exit(3);
- }
+}
int connectsock(char *host, char *service, char *protocol)
{
struct servent *pse;
struct protoent *ppe;
struct sockaddr_in sin;
- int s,type;
+ int s, type;
- bzero((char *)&sin,sizeof(sin));
+ bzero((char *) &sin, sizeof(sin));
sin.sin_family = AF_INET;
- pse=getservbyname(service,protocol);
+ pse = getservbyname(service, protocol);
if (pse) {
sin.sin_port = pse->s_port;
- }
- else if ((sin.sin_port = htons((u_short)atoi(service))) == 0) {
+ } else if ((sin.sin_port = htons((u_short) atoi(service))) == 0) {
fprintf(stderr, "Can't get %s service entry\n", service);
- return(-1);
- }
-
- phe=gethostbyname(host);
+ return (-1);
+ }
+ phe = gethostbyname(host);
if (phe) {
- bcopy(phe->h_addr,(char *)&sin.sin_addr,phe->h_length);
- }
- else if ((sin.sin_addr.s_addr = inet_addr(host))==INADDR_NONE) {
+ bcopy(phe->h_addr, (char *) &sin.sin_addr, phe->h_length);
+ } else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
fprintf(stderr, "Can't get %s host entry: %s\n",
- host,strerror(errno));
- return(-1);
- }
-
- if ((ppe=getprotobyname(protocol))==0) {
+ host, strerror(errno));
+ return (-1);
+ }
+ if ((ppe = getprotobyname(protocol)) == 0) {
fprintf(stderr, "Can't get %s protocol entry: %s\n",
- protocol,strerror(errno));
- return(-1);
- }
-
- if (!strcmp(protocol,"udp"))
+ protocol, strerror(errno));
+ return (-1);
+ }
+ if (!strcmp(protocol, "udp"))
type = SOCK_DGRAM;
else
type = SOCK_STREAM;
- s = socket(PF_INET,type,ppe->p_proto);
- if (s<0) {
+ s = socket(PF_INET, type, ppe->p_proto);
+ if (s < 0) {
fprintf(stderr, "Can't create socket: %s\n", strerror(errno));
- return(-1);
- }
-
-
- signal(SIGALRM,timeout);
+ return (-1);
+ }
+ signal(SIGALRM, timeout);
alarm(30);
- if (connect(s,(struct sockaddr *)&sin,sizeof(sin))<0) {
- fprintf(stderr,"can't connect to %s.%s: %s\n",
- host,service,strerror(errno));
- return(-1);
- }
-
+ if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
+ fprintf(stderr, "can't connect to %s.%s: %s\n",
+ host, service, strerror(errno));
+ return (-1);
+ }
alarm(0);
- signal(SIGALRM,SIG_IGN);
+ signal(SIGALRM, SIG_IGN);
- return(s);
- }
+ return (s);
+}
*/
void serv_read(char *buf, int bytes)
{
- int len,rlen;
+ int len, rlen;
- len = 0;
- while(len<bytes) {
- rlen = read(serv_sock,&buf[len],bytes-len);
- if (rlen<1) {
- fprintf(stderr, "Server connection broken: %s\n",
+ len = 0;
+ while (len < bytes) {
+ rlen = read(serv_sock, &buf[len], bytes - len);
+ if (rlen < 1) {
+ fprintf(stderr, "Server connection broken: %s\n",
strerror(errno));
- connected = 0;
+ connected = 0;
logged_in = 0;
return;
- }
- len = len + rlen;
- }
- }
+ }
+ len = len + rlen;
+ }
+}
/*
*/
void serv_gets(char *strbuf)
{
- int ch,len;
+ int ch, len;
char buf[2];
len = 0;
- strcpy(strbuf,"");
+ strcpy(strbuf, "");
do {
serv_read(&buf[0], 1);
ch = buf[0];
strbuf[len++] = ch;
- } while((ch!=10)&&(ch!=13)&&(ch!=0)&&(len<255));
- strbuf[len-1] = 0;
+ } while ((ch != 10) && (ch != 13) && (ch != 0) && (len < 255));
+ strbuf[len - 1] = 0;
/* fprintf(stderr, ">%s\n", strbuf); */
- }
+}
*/
void serv_write(char *buf, int nbytes)
{
- int bytes_written = 0;
- int retval;
- while (bytes_written < nbytes) {
- retval = write(serv_sock, &buf[bytes_written],
- nbytes - bytes_written);
- if (retval < 1) {
- fprintf(stderr, "Server connection broken: %s\n",
+ int bytes_written = 0;
+ int retval;
+ while (bytes_written < nbytes) {
+ retval = write(serv_sock, &buf[bytes_written],
+ nbytes - bytes_written);
+ if (retval < 1) {
+ fprintf(stderr, "Server connection broken: %s\n",
strerror(errno));
- connected = 0;
+ connected = 0;
logged_in = 0;
return;
- }
- bytes_written = bytes_written + retval;
- }
- }
+ }
+ bytes_written = bytes_written + retval;
+ }
+}
/*
{
char buf[256];
- sprintf(buf,"%s\n", string);
+ sprintf(buf, "%s\n", string);
serv_write(buf, strlen(buf));
- }
+}
/*
* convenience function to send stuff to the server
*/
-void serv_printf(const char *format, ...) {
- va_list arg_ptr;
+void serv_printf(const char *format,...)
+{
+ va_list arg_ptr;
char buf[256];
- va_start(arg_ptr, format);
- vsprintf(buf, format, arg_ptr);
- va_end(arg_ptr);
+ va_start(arg_ptr, format);
+ vsprintf(buf, format, arg_ptr);
+ va_end(arg_ptr);
strcat(buf, "\n");
serv_write(buf, strlen(buf));
/* fprintf(stderr, "<%s", buf); */
- }
-
-
+}
char *safestrncpy(char *dest, const char *src, size_t n)
{
- if (dest == NULL || src == NULL)
- {
- fprintf(stderr, "safestrncpy: NULL argument\n");
- abort();
- }
- strncpy(dest, src, n);
- dest[n - 1] = 0;
- return dest;
+ if (dest == NULL || src == NULL) {
+ fprintf(stderr, "safestrncpy: NULL argument\n");
+ abort();
+ }
+ strncpy(dest, src, n);
+ dest[n - 1] = 0;
+ return dest;
}
int a;
int count = 1;
- for (a=0; a<strlen(source); ++a)
- if (source[a]=='|') ++count;
- return(count);
- }
+ for (a = 0; a < strlen(source); ++a)
+ if (source[a] == '|')
+ ++count;
+ return (count);
+}
/*
* extract() - extract a parameter from a series of "|" separated...
int count = 0;
int n;
- if (strlen(source)==0) {
- strcpy(dest,"");
+ if (strlen(source) == 0) {
+ strcpy(dest, "");
return;
- }
-
+ }
n = num_parms(source);
if (parmnum >= n) {
- strcpy(dest,"");
+ strcpy(dest, "");
return;
- }
- strcpy(buf,source);
- if ( (parmnum == 0) && (n == 1) ) {
- strcpy(dest,buf);
- for (n=0; n<strlen(dest); ++n)
- if (dest[n]=='|') dest[n] = 0;
+ }
+ strcpy(buf, source);
+ if ((parmnum == 0) && (n == 1)) {
+ strcpy(dest, buf);
+ for (n = 0; n < strlen(dest); ++n)
+ if (dest[n] == '|')
+ dest[n] = 0;
return;
- }
-
- while (count++ < parmnum) do {
- strcpy(buf,&buf[1]);
- } while( (strlen(buf)>0) && (buf[0]!='|') );
- if (buf[0]=='|') strcpy(buf,&buf[1]);
- for (count = 0; count<strlen(buf); ++count)
- if (buf[count] == '|') buf[count] = 0;
- strcpy(dest,buf);
}
+ while (count++ < parmnum)
+ do {
+ strcpy(buf, &buf[1]);
+ } while ((strlen(buf) > 0) && (buf[0] != '|'));
+ if (buf[0] == '|')
+ strcpy(buf, &buf[1]);
+ for (count = 0; count < strlen(buf); ++count)
+ if (buf[count] == '|')
+ buf[count] = 0;
+ strcpy(dest, buf);
+}
/*
* extract_int() - extract an int parm w/o supplying a buffer
int extract_int(char *source, int parmnum)
{
char buf[256];
-
- extract(buf,source,parmnum);
- return(atoi(buf));
- }
+
+ extract(buf, source, parmnum);
+ return (atoi(buf));
+}
/*
* extract_long() - extract an long parm w/o supplying a buffer
long extract_long(char *source, long int parmnum)
{
char buf[256];
-
- extract(buf,source,parmnum);
- return(atol(buf));
- }
+
+ extract(buf, source, parmnum);
+ return (atol(buf));
+}
/*
* check for the presence of a character within a string (returns count)
*/
-int haschar(st,ch)
+int haschar(st, ch)
char st[];
-int ch; {
- int a,b;
- b=0;
- for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
- return(b);
- }
-
+int ch;
+{
+ int a, b;
+ b = 0;
+ for (a = 0; a < strlen(st); ++a)
+ if (st[a] == ch)
+ ++b;
+ return (b);
+}
struct namelist {
struct namelist *next;
char name[32];
- };
+};
/*
* display the userlist
*/
-void userlist(void) {
+void userlist(void)
+{
char buf[256];
char fl[256];
struct tm *tmbuf;
serv_puts("LBIO");
serv_gets(buf);
- if (buf[0]=='1') while (serv_gets(buf), strcmp(buf,"000")) {
- bptr = (struct namelist *) malloc(sizeof(struct namelist));
- bptr->next = bio;
- strcpy(bptr->name, buf);
- bio = bptr;
+ if (buf[0] == '1')
+ while (serv_gets(buf), strcmp(buf, "000")) {
+ bptr = (struct namelist *) malloc(sizeof(struct namelist));
+ bptr->next = bio;
+ strcpy(bptr->name, buf);
+ bio = bptr;
}
-
-
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
serv_puts("LIST");
serv_gets(buf);
- if (buf[0]!='1') {
- wprintf("<EM>%s</EM><BR>\n",&buf[4]);
+ if (buf[0] != '1') {
+ wprintf("<EM>%s</EM><BR>\n", &buf[4]);
goto DONE;
- }
-
-
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>User list for ");
+ }
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>User list for ");
escputs(serv_info.serv_humannode);
- wprintf("</B></FONT></TD></TR></TABLE>\n");
+ wprintf("</B></FONT></TD></TR></TABLE>\n");
wprintf("<CENTER><TABLE border>");
wprintf("<TR><TH>User Name</TH><TH>Number</TH><TH>Access Level</TH>");
wprintf("<TH>Last Call</TH><TH>Total Calls</TH><TH>Total Posts</TH></TR>\n");
- while (serv_gets(buf), strcmp(buf,"000")) {
- extract(fl,buf,0);
+ while (serv_gets(buf), strcmp(buf, "000")) {
+ extract(fl, buf, 0);
has_bio = 0;
- for (bptr=bio; bptr!=NULL; bptr=bptr->next) {
- if (!strcasecmp(fl,bptr->name)) has_bio = 1;
- }
+ for (bptr = bio; bptr != NULL; bptr = bptr->next) {
+ if (!strcasecmp(fl, bptr->name))
+ has_bio = 1;
+ }
wprintf("<TR><TD>");
if (has_bio) {
wprintf("<A HREF=\"/showuser&who=");
wprintf("\">");
escputs(fl);
wprintf("</A>");
- }
- else {
+ } else {
escputs(fl);
- }
+ }
wprintf("</TD><TD>%ld</TD><TD>%d</TD><TD>",
- extract_long(buf,2),
- extract_int(buf,1));
- lc = extract_long(buf,3);
- tmbuf = (struct tm *)localtime(&lc);
+ extract_long(buf, 2),
+ extract_int(buf, 1));
+ lc = extract_long(buf, 3);
+ tmbuf = (struct tm *) localtime(&lc);
wprintf("%02d/%02d/%04d ",
- (tmbuf->tm_mon+1),
+ (tmbuf->tm_mon + 1),
tmbuf->tm_mday,
(tmbuf->tm_year + 1900));
-
+
wprintf("</TD><TD>%ld</TD><TD>%5ld</TD></TR>\n",
- extract_long(buf,4),extract_long(buf,5));
+ extract_long(buf, 4), extract_long(buf, 5));
- }
- wprintf("</TABLE></CENTER>\n");
-DONE: wDumpContent(1);
}
+ wprintf("</TABLE></CENTER>\n");
+ DONE:wDumpContent(1);
+}
/*
* Display (non confidential) information about a particular user
*/
-void showuser(void) {
+void showuser(void)
+{
char who[256];
char buf[256];
int have_pic;
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>User profile");
- wprintf("</B></FONT></TD></TR></TABLE>\n");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>User profile");
+ wprintf("</B></FONT></TD></TR></TABLE>\n");
strcpy(who, bstr("who"));
serv_printf("OIMG _userpic_|%s", who);
serv_gets(buf);
- if (buf[0]=='2') {
+ if (buf[0] == '2') {
have_pic = 1;
serv_puts("CLOS");
serv_gets(buf);
- }
- else {
+ } else {
have_pic = 0;
- }
+ }
wprintf("<CENTER><TABLE><TR><TD>");
if (have_pic == 1) {
wprintf("<IMG SRC=\"/image&name=_userpic_&parm=");
urlescputs(who);
wprintf("\">");
- }
- wprintf("</TD><TD><H1>%s</H1></TD></TR></TABLE></CENTER>\n",who);
- serv_printf("RBIO %s",who);
- serv_gets(buf);
- if (buf[0]=='1') fmout(NULL);
- wDumpContent(1);
}
+ wprintf("</TD><TD><H1>%s</H1></TD></TR></TABLE></CENTER>\n", who);
+ serv_printf("RBIO %s", who);
+ serv_gets(buf);
+ if (buf[0] == '1')
+ fmout(NULL);
+ wDumpContent(1);
+}
char wc_username[256];
char wc_password[256];
char wc_roomname[256];
-char browser[256];
int TransactionCount = 0;
int connected = 0;
int logged_in = 0;
void unescape_input(char *buf)
{
- int a,b;
+ int a, b;
char hex[3];
- while ((isspace(buf[strlen(buf)-1]))&&(strlen(buf)>0))
- buf[strlen(buf)-1] = 0;
-
- for (a=0; a<strlen(buf); ++a) {
- if (buf[a]=='+') buf[a]=' ';
- if (buf[a]=='%') {
- hex[0]=buf[a+1];
- hex[1]=buf[a+2];
- hex[2]=0;
- sscanf(hex,"%02x",&b);
+ while ((isspace(buf[strlen(buf) - 1])) && (strlen(buf) > 0))
+ buf[strlen(buf) - 1] = 0;
+
+ for (a = 0; a < strlen(buf); ++a) {
+ if (buf[a] == '+')
+ buf[a] = ' ';
+ if (buf[a] == '%') {
+ hex[0] = buf[a + 1];
+ hex[1] = buf[a + 2];
+ hex[2] = 0;
+ sscanf(hex, "%02x", &b);
buf[a] = (char) b;
- strcpy(&buf[a+1],&buf[a+3]);
- }
+ strcpy(&buf[a + 1], &buf[a + 3]);
}
-
}
+}
+
-void addurls(char *url) {
+void addurls(char *url)
+{
char *up, *ptr;
char buf[256];
- int a,b;
+ int a, b;
struct urlcontent *u;
up = url;
- while (strlen(up)>0) {
-
+ while (strlen(up) > 0) {
+
/* locate the = sign */
- strncpy(buf,up,255);
+ strncpy(buf, up, 255);
b = (-1);
- for (a=255; a>=0; --a) if (buf[a]=='=') b=a;
- if (b<0) return;
- buf[b]=0;
-
- u = (struct urlcontent *)malloc(sizeof(struct urlcontent));
+ for (a = 255; a >= 0; --a)
+ if (buf[a] == '=')
+ b = a;
+ if (b < 0)
+ return;
+ buf[b] = 0;
+
+ u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
u->next = urlstrings;
urlstrings = u;
strcpy(u->url_key, buf);
-
+
/* now chop that part off */
- for (a=0; a<=b; ++a) ++up;
-
+ for (a = 0; a <= b; ++a)
+ ++up;
+
/* locate the & sign */
ptr = up;
b = strlen(up);
- for (a=0; a<strlen(up); ++a) {
- if (!strncmp(ptr,"&",1)) {
- b=a;
+ for (a = 0; a < strlen(up); ++a) {
+ if (!strncmp(ptr, "&", 1)) {
+ b = a;
break;
- }
- ++ptr;
}
+ ++ptr;
+ }
ptr = up;
- for (a=0; a<b; ++a) ++ptr;
- strcpy(ptr,"");
-
- u->url_data = malloc(strlen(up)+1);
+ for (a = 0; a < b; ++a)
+ ++ptr;
+ strcpy(ptr, "");
+
+ u->url_data = malloc(strlen(up) + 1);
strcpy(u->url_data, up);
u->url_data[b] = 0;
unescape_input(u->url_data);
up = ptr;
++up;
- }
}
+}
-void free_urls(void) {
+void free_urls(void)
+{
struct urlcontent *u;
while (urlstrings != NULL) {
u = urlstrings->next;
free(urlstrings);
urlstrings = u;
- }
}
+}
/*
* Diagnostic function to display the contents of all variables
*/
-void dump_vars(void) {
+void dump_vars(void)
+{
struct urlcontent *u;
for (u = urlstrings; u != NULL; u = u->next) {
wprintf("%38s = %s\n", u->url_key, u->url_data);
- }
}
+}
-char *bstr(char *key) {
+char *bstr(char *key)
+{
struct urlcontent *u;
for (u = urlstrings; u != NULL; u = u->next) {
- if (!strcasecmp(u->url_key, key)) return(u->url_data);
- }
- return("");
+ if (!strcasecmp(u->url_key, key))
+ return (u->url_data);
}
+ return ("");
+}
-void wprintf(const char *format, ...) {
- va_list arg_ptr;
+void wprintf(const char *format,...)
+{
+ va_list arg_ptr;
struct webcontent *wptr;
- wptr = (struct webcontent *)malloc(sizeof(struct webcontent));
+ wptr = (struct webcontent *) malloc(sizeof(struct webcontent));
wptr->next = NULL;
if (wlist == NULL) {
wlist = wptr;
wlast = wptr;
- }
- else {
+ } else {
wlast->next = wptr;
wlast = wptr;
- }
-
- va_start(arg_ptr, format);
- vsprintf(wptr->w_data, format, arg_ptr);
- va_end(arg_ptr);
}
-int wContentLength(void) {
+ va_start(arg_ptr, format);
+ vsprintf(wptr->w_data, format, arg_ptr);
+ va_end(arg_ptr);
+}
+
+int wContentLength(void)
+{
struct webcontent *wptr;
int len = 0;
for (wptr = wlist; wptr != NULL; wptr = wptr->next) {
len = len + strlen(wptr->w_data);
- }
-
- return(len);
}
+ return (len);
+}
+
/*
* wDumpContent() takes all the stuff that's been queued up using
* the wprintf() and escputs() functions, and sends it out to the browser.
* append the main menu (if in noframes mode) and closing tags, or 2 to
* append the closing tags only.
*/
-void wDumpContent(int print_standard_html_footer) {
+void wDumpContent(int print_standard_html_footer)
+{
struct webcontent *wptr;
if (print_standard_html_footer) {
- if ( (noframes) && (print_standard_html_footer != 2) ) {
+ if ((noframes) && (print_standard_html_footer != 2)) {
wprintf("<BR>");
embed_main_menu();
- }
- wprintf("</BODY></HTML>\n");
}
-
+ wprintf("</BODY></HTML>\n");
+ }
printf("Content-type: text/html\n");
printf("Content-length: %d\n", wContentLength());
printf("\n");
wptr = wlist->next;
free(wlist);
wlist = wptr;
- }
- wlast = NULL;
}
+ wlast = NULL;
+}
void escputs1(char *strbuf, int nbsp)
{
int a;
- for (a=0; a<strlen(strbuf); ++a) {
- if (strbuf[a]=='<') wprintf("<");
- else if (strbuf[a]=='>') wprintf(">");
- else if (strbuf[a]=='&') wprintf("&");
- else if (strbuf[a]==34) wprintf(""");
- else if (strbuf[a]==LB) wprintf("<");
- else if (strbuf[a]==RB) wprintf(">");
- else if (strbuf[a]==QU) wprintf("\"");
- else if ((strbuf[a]==32)&&(nbsp==1)) {
+ for (a = 0; a < strlen(strbuf); ++a) {
+ if (strbuf[a] == '<')
+ wprintf("<");
+ else if (strbuf[a] == '>')
+ wprintf(">");
+ else if (strbuf[a] == '&')
+ wprintf("&");
+ else if (strbuf[a] == 34)
+ wprintf(""");
+ else if (strbuf[a] == LB)
+ wprintf("<");
+ else if (strbuf[a] == RB)
+ wprintf(">");
+ else if (strbuf[a] == QU)
+ wprintf("\"");
+ else if ((strbuf[a] == 32) && (nbsp == 1)) {
wprintf(" ");
- }
- else {
+ } else {
wprintf("%c", strbuf[a]);
- }
}
}
+}
void escputs(char *strbuf)
{
- escputs1(strbuf,0);
- }
+ escputs1(strbuf, 0);
+}
char *urlesc(char *strbuf)
{
- int a,b,c;
- char *ec = " #&;`'|*?-~<>^()[]{}$\\";
+ int a, b, c;
+ char *ec = " #&;`'|*?-~<>^()[]{}$\\";
static char outbuf[512];
-
- strcpy(outbuf,"");
- for (a=0; a<strlen(strbuf); ++a) {
+ strcpy(outbuf, "");
+
+ for (a = 0; a < strlen(strbuf); ++a) {
c = 0;
- for (b=0; b<strlen(ec); ++b) {
- if (strbuf[a]==ec[b]) c=1;
- }
- b = strlen(outbuf);
- if (c==1) sprintf(&outbuf[b],"%%%02x",strbuf[a]);
- else sprintf(&outbuf[b],"%c",strbuf[a]);
+ for (b = 0; b < strlen(ec); ++b) {
+ if (strbuf[a] == ec[b])
+ c = 1;
}
- return(outbuf);
+ b = strlen(outbuf);
+ if (c == 1)
+ sprintf(&outbuf[b], "%%%02x", strbuf[a]);
+ else
+ sprintf(&outbuf[b], "%c", strbuf[a]);
}
+ return (outbuf);
+}
void urlescputs(char *strbuf)
{
- wprintf("%s",urlesc(strbuf));
- }
+ wprintf("%s", urlesc(strbuf));
+}
-char *getz(char *buf) {
+char *getz(char *buf)
+{
bzero(buf, 256);
if (fgets(buf, 256, stdin) == NULL) {
strcpy(buf, "");
return NULL;
- }
- else {
- while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1])))
- buf[strlen(buf)-1] = 0;
+ } else {
+ while ((strlen(buf) > 0) && (!isprint(buf[strlen(buf) - 1])))
+ buf[strlen(buf) - 1] = 0;
return buf;
- }
}
+}
/*
* Output all that important stuff that the browser will want to see
* If print_standard_html_head is nonzero, we also get some standard HTML
* headers. If it's set to 2, the session is considered to be closing.
*/
-void output_headers(int print_standard_html_head, char *target) {
+void output_headers(int print_standard_html_head, char *target)
+{
static char *unset = "; expires=28-May-1971 18:10:00 GMT";
char cookie[256];
printf("Server: %s\n", SERVER);
printf("Connection: close\n");
- if ( (strlen(target)>0) && (noframes == 0) ) {
+ if ((strlen(target) > 0) && (noframes == 0)) {
printf("Window-target: %s\n", target);
- }
-
-
+ }
if (print_standard_html_head > 0) {
printf("Pragma: no-cache\n");
printf("Cache-Control: no-store\n");
- }
-
+ }
stuff_to_cookie(cookie, wc_session, wc_username, wc_password,
wc_roomname, noframes);
- if (print_standard_html_head==2) {
+ if (print_standard_html_head == 2) {
printf("X-WebCit-Session: close\n");
printf("Set-cookie: webcit=%s\n", unset);
- }
- else {
+ } else {
printf("Set-cookie: webcit=%s\n", cookie);
- }
+ }
if (print_standard_html_head > 0) {
- wprintf("<HTML><HEAD><TITLE>");
- escputs("WebCit"); /* FIX -- add BBS name here */
+ wprintf("<HTML><HEAD><TITLE>");
+ escputs("WebCit"); /* FIX -- add BBS name here */
wprintf("</TITLE></HEAD>");
if (ExpressMessages != NULL) {
wprintf("<SCRIPT language=\"javascript\">\n");
escputs(ExpressMessages);
wprintf("\")\n");
wprintf(" }\n </SCRIPT>\n");
- }
+ }
wprintf("<BODY ");
if (ExpressMessages != NULL) {
wprintf("onload=\"ExpressMessage()\" ");
free(ExpressMessages);
ExpressMessages = NULL;
- }
- wprintf("BACKGROUND=\"/image&name=background\" TEXT=\"#000000\" LINK=\"#004400\">\n");
}
-
+ wprintf("BACKGROUND=\"/image&name=background\" TEXT=\"#000000\" LINK=\"#004400\">\n");
}
+}
-void check_for_express_messages() {
+void check_for_express_messages()
+{
char buf[256];
serv_puts("PEXP");
serv_gets(buf);
- if (buf[0]=='1') {
+ if (buf[0] == '1') {
while (serv_gets(buf), strcmp(buf, "000")) {
if (ExpressMessages == NULL) {
ExpressMessages = malloc(strlen(buf) + 4);
strcpy(ExpressMessages, "");
- }
- else {
+ } else {
ExpressMessages = realloc(ExpressMessages,
- (strlen(ExpressMessages) + strlen(buf) + 4) );
- }
+ (strlen(ExpressMessages) + strlen(buf) + 4));
+ }
strcat(ExpressMessages, buf);
strcat(ExpressMessages, "\\n");
- }
}
}
+}
-void output_static(char *what) {
+void output_static(char *what)
+{
char buf[256];
FILE *fp;
struct stat statbuf;
printf("Content-length: %d\n", strlen(buf));
printf("\n");
fwrite(buf, strlen(buf), 1, stdout);
- }
- else {
+ } else {
printf("HTTP/1.0 200 OK\n");
output_headers(0, "");
- if (!strncasecmp(&what[strlen(what)-4], ".gif", 4))
+ if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
printf("Content-type: image/gif\n");
- else if (!strncasecmp(&what[strlen(what)-4], ".jpg", 4))
+ else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
printf("Content-type: image/jpeg\n");
- else if (!strncasecmp(&what[strlen(what)-5], ".html", 5))
+ else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
printf("Content-type: text/html\n");
else
printf("Content-type: application/octet-stream\n");
fstat(fileno(fp), &statbuf);
bytes = statbuf.st_size;
- printf("Content-length: %ld\n", (long)bytes);
+ printf("Content-length: %ld\n", (long) bytes);
printf("\n");
while (bytes--) {
putc(getc(fp), stdout);
- }
+ }
fflush(stdout);
fclose(fp);
- }
}
+}
-void output_image() {
+void output_image()
+{
char buf[256];
char xferbuf[4096];
off_t bytes;
serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
serv_gets(buf);
- if (buf[0]=='2') {
+ if (buf[0] == '2') {
bytes = extract_long(&buf[4], 0);
printf("HTTP/1.0 200 OK\n");
output_headers(0, "");
printf("Content-type: image/gif\n");
- printf("Content-length: %ld\n", (long)bytes);
+ printf("Content-length: %ld\n", (long) bytes);
printf("\n");
- while (bytes > (off_t)0) {
- thisblock = (off_t)sizeof(xferbuf);
- if (thisblock > bytes) thisblock = bytes;
+ while (bytes > (off_t) 0) {
+ thisblock = (off_t) sizeof(xferbuf);
+ if (thisblock > bytes)
+ thisblock = bytes;
serv_printf("READ %ld|%ld", accomplished, thisblock);
serv_gets(buf);
- if (buf[0]=='6') thisblock = extract_long(&buf[4],0);
- serv_read(xferbuf, (int)thisblock);
+ if (buf[0] == '6')
+ thisblock = extract_long(&buf[4], 0);
+ serv_read(xferbuf, (int) thisblock);
fwrite(xferbuf, thisblock, 1, stdout);
bytes = bytes - thisblock;
accomplished = accomplished + thisblock;
- }
+ }
fflush(stdout);
serv_puts("CLOS");
serv_gets(buf);
- }
- else {
+ } else {
printf("HTTP/1.0 404 %s\n", strerror(errno));
output_headers(0, "");
printf("Content-Type: text/plain\n");
printf("Content-length: %d\n", strlen(buf));
printf("\n");
fwrite(buf, strlen(buf), 1, stdout);
- }
-
}
+}
+
/*
* Convenience functions to display a page containing only a string
*/
-void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext) {
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=%s><TR><TD>", titlebarcolor);
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>%s</B>\n", titlebarmsg);
- wprintf("</FONT></TD></TR></TABLE><BR>\n");
+void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
+{
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=%s><TR><TD>", titlebarcolor);
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>%s</B>\n", titlebarmsg);
+ wprintf("</FONT></TD></TR></TABLE><BR>\n");
escputs(messagetext);
-
+
if (noframes) {
wprintf("<HR>\n");
embed_main_menu();
- }
-
- wDumpContent(1);
}
+ wDumpContent(1);
+}
-void display_error(char *errormessage) {
+void display_error(char *errormessage)
+{
convenience_page("770000", "Error", errormessage);
- }
+}
-void display_success(char *successmessage) {
+void display_success(char *successmessage)
+{
convenience_page("007700", "OK", successmessage);
- }
+}
-void extract_action(char *actbuf, char *cmdbuf) {
+void extract_action(char *actbuf, char *cmdbuf)
+{
int i;
strcpy(actbuf, cmdbuf);
- if (!strncasecmp(actbuf, "GET /", 5)) strcpy(actbuf, &actbuf[5]);
- if (!strncasecmp(actbuf, "PUT /", 5)) strcpy(actbuf, &actbuf[5]);
- if (!strncasecmp(actbuf, "POST /", 6)) strcpy(actbuf, &actbuf[6]);
-
- for (i=0; i<strlen(actbuf); ++i) {
- if (actbuf[i]==' ') { actbuf[i]=0; i=0; }
- if (actbuf[i]=='/') { actbuf[i]=0; i=0; }
- if (actbuf[i]=='?') { actbuf[i]=0; i=0; }
- if (actbuf[i]=='&') { actbuf[i]=0; i=0; }
+ if (!strncasecmp(actbuf, "GET /", 5))
+ strcpy(actbuf, &actbuf[5]);
+ if (!strncasecmp(actbuf, "PUT /", 5))
+ strcpy(actbuf, &actbuf[5]);
+ if (!strncasecmp(actbuf, "POST /", 6))
+ strcpy(actbuf, &actbuf[6]);
+
+ for (i = 0; i < strlen(actbuf); ++i) {
+ if (actbuf[i] == ' ') {
+ actbuf[i] = 0;
+ i = 0;
+ }
+ if (actbuf[i] == '/') {
+ actbuf[i] = 0;
+ i = 0;
+ }
+ if (actbuf[i] == '?') {
+ actbuf[i] = 0;
+ i = 0;
+ }
+ if (actbuf[i] == '&') {
+ actbuf[i] = 0;
+ i = 0;
}
}
+}
void upload_handler(char *name, char *filename, char *encoding,
- void *content, char *cbtype, size_t length) {
+ void *content, char *cbtype, size_t length)
+{
fprintf(stderr, "UPLOAD HANDLER CALLED\n");
fprintf(stderr, " name = %s\n", name);
fprintf(stderr, " type = %s\n", cbtype);
fprintf(stderr, " length = %d\n", length);
- if (strlen(name)>0) {
- upload = malloc(length);
- if (upload != NULL) {
- upload_length = length;
- memcpy(upload, content, length);
- }
- }
-
+ if (strlen(name) > 0) {
+ upload = malloc(length);
+ if (upload != NULL) {
+ upload_length = length;
+ memcpy(upload, content, length);
+ }
}
+}
-void session_loop(char *browser_host) {
+void session_loop(char *browser_host, int bd_use_frames)
+{
char cmd[256];
char action[256];
char buf[256];
upload_length = 0;
upload = NULL;
- if (getz(cmd)==NULL) return;
+ if (getz(cmd) == NULL)
+ return;
extract_action(action, cmd);
do {
- if (getz(buf)==NULL) return;
+ if (getz(buf) == NULL)
+ return;
if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
strcpy(cookie, &buf[15]);
cookie_to_stuff(cookie, NULL,
- c_username, c_password, c_roomname,
+ c_username, c_password, c_roomname,
&noframes);
- }
-
+ }
if (!strncasecmp(buf, "Content-length: ", 16)) {
ContentLength = atoi(&buf[16]);
- }
+ }
if (!strncasecmp(buf, "Content-type: ", 14)) {
strcpy(ContentType, &buf[14]);
- }
- } while(strlen(buf)>0);
+ }
+ } while (strlen(buf) > 0);
++TransactionCount;
if (ContentLength > 0) {
- content = malloc(ContentLength+1);
+ content = malloc(ContentLength + 1);
fread(content, ContentLength, 1, stdin);
content[ContentLength] = 0;
if (!strncasecmp(ContentType,
- "application/x-www-form-urlencoded", 33)) {
+ "application/x-www-form-urlencoded", 33)) {
addurls(content);
- }
- else if (!strncasecmp(ContentType, "multipart", 9)) {
+ } else if (!strncasecmp(ContentType, "multipart", 9)) {
mime_parser(content, ContentLength, ContentType,
- *upload_handler);
- }
+ *upload_handler);
}
- else {
+ } else {
content = NULL;
- }
+ }
- /* If there are variables in the URL, we must grab them now */
- for (a=0; a<strlen(cmd); ++a) if ((cmd[a]=='?')||(cmd[a]=='&')) {
- for (b=a; b<strlen(cmd); ++b) if (isspace(cmd[b])) cmd[b]=0;
- addurls(&cmd[a+1]);
- cmd[a] = 0;
+ /* If there are variables in the URL, we must grab them now */
+ for (a = 0; a < strlen(cmd); ++a)
+ if ((cmd[a] == '?') || (cmd[a] == '&')) {
+ for (b = a; b < strlen(cmd); ++b)
+ if (isspace(cmd[b]))
+ cmd[b] = 0;
+ addurls(&cmd[a + 1]);
+ cmd[a] = 0;
}
-
/*
* If we're not 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 (strlen(bstr("host"))>0) strcpy(c_host, bstr("host"));
- if (strlen(bstr("port"))>0) strcpy(c_port, bstr("port"));
+ 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");
connected = 1;
serv_gets(buf); /* get the server welcome message */
get_serv_info(browser_host);
- }
-
+ }
check_for_express_messages();
/*
* 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 ((!logged_in) && (strlen(c_username) > 0) && (strlen(c_password) > 0)) {
serv_printf("USER %s", c_username);
serv_gets(buf);
- if (buf[0]=='3') {
+ if (buf[0] == '3') {
serv_printf("PASS %s", c_password);
serv_gets(buf);
- if (buf[0]=='2') {
+ if (buf[0] == '2') {
become_logged_in(c_username, c_password, buf);
- }
}
}
-
+ }
/*
* 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_roomname) == 0) && (strlen(c_roomname) > 0)) {
serv_printf("GOTO %s", c_roomname);
serv_gets(buf);
- if (buf[0]=='2') {
+ if (buf[0] == '2') {
strcpy(wc_roomname, c_roomname);
- }
}
-
+ }
if (!strcasecmp(action, "static")) {
strcpy(buf, &cmd[12]);
- for (a=0; a<strlen(buf); ++a) if (isspace(buf[a])) buf[a]=0;
+ for (a = 0; a < strlen(buf); ++a)
+ if (isspace(buf[a]))
+ buf[a] = 0;
output_static(buf);
- }
-
- else if (!strcasecmp(action, "image")) {
+ } else if (!strcasecmp(action, "image")) {
output_image();
- }
-
- else if ((!logged_in)&&(!strcasecmp(action, "login"))) {
+ } else if ((!logged_in) && (!strcasecmp(action, "login"))) {
do_login();
- }
-
- else if (!logged_in) {
+ } else if (!logged_in) {
display_login(NULL);
- }
-
+ }
/* Various commands... */
-
+
else if (!strcasecmp(action, "do_welcome")) {
do_welcome();
- }
-
- else if (!strcasecmp(action, "display_main_menu")) {
+ } else if (!strcasecmp(action, "display_main_menu")) {
display_main_menu();
- }
-
- else if (!strcasecmp(action, "advanced")) {
+ } else if (!strcasecmp(action, "advanced")) {
display_advanced_menu();
- }
-
- else if (!strcasecmp(action, "whobbs")) {
+ } else if (!strcasecmp(action, "whobbs")) {
whobbs();
- }
-
- else if (!strcasecmp(action, "knrooms")) {
+ } else if (!strcasecmp(action, "knrooms")) {
list_all_rooms_by_floor();
- }
-
- else if (!strcasecmp(action, "gotonext")) {
+ } else if (!strcasecmp(action, "gotonext")) {
slrp_highest();
gotonext();
- }
-
- else if (!strcasecmp(action, "skip")) {
+ } else if (!strcasecmp(action, "skip")) {
gotonext();
- }
-
- else if (!strcasecmp(action, "ungoto")) {
+ } else if (!strcasecmp(action, "ungoto")) {
ungoto();
- }
-
- else if (!strcasecmp(action, "dotgoto")) {
+ } else if (!strcasecmp(action, "dotgoto")) {
slrp_highest();
gotoroom(bstr("room"), 1);
- }
-
- else if (!strcasecmp(action, "termquit")) {
+ } else if (!strcasecmp(action, "termquit")) {
do_logout();
- }
-
- else if (!strcasecmp(action, "readnew")) {
+ } else if (!strcasecmp(action, "readnew")) {
readloop("readnew");
- }
-
- else if (!strcasecmp(action, "readold")) {
+ } else if (!strcasecmp(action, "readold")) {
readloop("readold");
- }
-
- else if (!strcasecmp(action, "readfwd")) {
+ } else if (!strcasecmp(action, "readfwd")) {
readloop("readfwd");
- }
-
- else if (!strcasecmp(action, "display_enter")) {
+ } else if (!strcasecmp(action, "display_enter")) {
display_enter();
- }
-
- else if (!strcasecmp(action, "post")) {
+ } else if (!strcasecmp(action, "post")) {
post_message();
- }
-
- else if (!strcasecmp(action, "confirm_delete_msg")) {
+ } else if (!strcasecmp(action, "confirm_delete_msg")) {
confirm_delete_msg();
- }
-
- else if (!strcasecmp(action, "delete_msg")) {
+ } else if (!strcasecmp(action, "delete_msg")) {
delete_msg();
- }
-
- else if (!strcasecmp(action, "confirm_move_msg")) {
+ } else if (!strcasecmp(action, "confirm_move_msg")) {
confirm_move_msg();
- }
-
- else if (!strcasecmp(action, "move_msg")) {
+ } else if (!strcasecmp(action, "move_msg")) {
move_msg();
- }
-
- else if (!strcasecmp(action, "userlist")) {
+ } else if (!strcasecmp(action, "userlist")) {
userlist();
- }
-
- else if (!strcasecmp(action, "showuser")) {
+ } else if (!strcasecmp(action, "showuser")) {
showuser();
- }
-
- else if (!strcasecmp(action, "display_page")) {
+ } else if (!strcasecmp(action, "display_page")) {
display_page();
- }
-
- else if (!strcasecmp(action, "page_user")) {
+ } else if (!strcasecmp(action, "page_user")) {
page_user();
- }
-
- else if (!strcasecmp(action, "chat")) {
+ } else if (!strcasecmp(action, "chat")) {
do_chat();
- }
-
- else if (!strcasecmp(action, "display_private")) {
+ } else if (!strcasecmp(action, "display_private")) {
display_private("", 0);
- }
-
- else if (!strcasecmp(action, "goto_private")) {
+ } else if (!strcasecmp(action, "goto_private")) {
goto_private();
- }
-
- else if (!strcasecmp(action, "zapped_list")) {
+ } else if (!strcasecmp(action, "zapped_list")) {
zapped_list();
- }
-
- else if (!strcasecmp(action, "display_zap")) {
+ } else if (!strcasecmp(action, "display_zap")) {
display_zap();
- }
-
- else if (!strcasecmp(action, "zap")) {
+ } else if (!strcasecmp(action, "zap")) {
zap();
- }
-
- else if (!strcasecmp(action, "display_entroom")) {
+ } else if (!strcasecmp(action, "display_entroom")) {
display_entroom();
- }
-
- else if (!strcasecmp(action, "entroom")) {
+ } else if (!strcasecmp(action, "entroom")) {
entroom();
- }
-
- else if (!strcasecmp(action, "display_editroom")) {
+ } else if (!strcasecmp(action, "display_editroom")) {
display_editroom();
- }
-
- else if (!strcasecmp(action, "editroom")) {
+ } else if (!strcasecmp(action, "editroom")) {
editroom();
- }
-
- else if (!strcasecmp(action, "display_editinfo")) {
+ } else if (!strcasecmp(action, "display_editinfo")) {
display_edit("Room info", "EINF 0", "RINF", "/editinfo");
- }
-
- else if (!strcasecmp(action, "editinfo")) {
+ } else if (!strcasecmp(action, "editinfo")) {
save_edit("Room info", "EINF 1", 1);
- }
-
- else if (!strcasecmp(action, "display_editbio")) {
+ } else if (!strcasecmp(action, "display_editbio")) {
sprintf(buf, "RBIO %s", wc_username);
display_edit("Your bio", "NOOP", buf, "editbio");
- }
-
- else if (!strcasecmp(action, "editbio")) {
+ } else if (!strcasecmp(action, "editbio")) {
save_edit("Your bio", "EBIO", 0);
- }
-
- else if (!strcasecmp(action, "confirm_delete_room")) {
+ } else if (!strcasecmp(action, "confirm_delete_room")) {
confirm_delete_room();
- }
-
- else if (!strcasecmp(action, "delete_room")) {
+ } else if (!strcasecmp(action, "delete_room")) {
delete_room();
- }
-
- else if (!strcasecmp(action, "validate")) {
+ } else if (!strcasecmp(action, "validate")) {
validate();
- }
-
- else if (!strcasecmp(action, "display_editpic")) {
+ } else if (!strcasecmp(action, "display_editpic")) {
display_graphics_upload("your photo",
"UIMG 0|_userpic_",
"/editpic");
- }
-
- else if (!strcasecmp(action, "editpic")) {
+ } else if (!strcasecmp(action, "editpic")) {
do_graphics_upload("UIMG 1|_userpic_");
- }
-
- else if (!strcasecmp(action, "display_editroompic")) {
+ } else if (!strcasecmp(action, "display_editroompic")) {
display_graphics_upload("the graphic for this room",
"UIMG 0|_roompic_",
"/editroompic");
- }
-
- else if (!strcasecmp(action, "editroompic")) {
+ } else if (!strcasecmp(action, "editroompic")) {
do_graphics_upload("UIMG 1|_roompic_");
- }
-
- else if (!strcasecmp(action, "select_floor_to_edit_pic")) {
+ } else if (!strcasecmp(action, "select_floor_to_edit_pic")) {
select_floor_to_edit_pic();
- }
-
- else if (!strcasecmp(action, "display_editfloorpic")) {
+ } else if (!strcasecmp(action, "display_editfloorpic")) {
sprintf(buf, "UIMG 0|_floorpic_|%s",
bstr("which_floor"));
display_graphics_upload("the graphic for this floor",
buf,
"/editfloorpic");
- }
-
- else if (!strcasecmp(action, "editfloorpic")) {
+ } else if (!strcasecmp(action, "editfloorpic")) {
sprintf(buf, "UIMG 1|_floorpic_|%s",
bstr("which_floor"));
do_graphics_upload(buf);
- }
-
- else if (!strcasecmp(action, "display_reg")) {
+ } else if (!strcasecmp(action, "display_reg")) {
display_reg(0);
- }
-
- else if (!strcasecmp(action, "register")) {
+ } else if (!strcasecmp(action, "register")) {
register_user();
- }
-
- else if (!strcasecmp(action, "display_changepw")) {
+ } else if (!strcasecmp(action, "display_changepw")) {
display_changepw();
- }
-
- else if (!strcasecmp(action, "changepw")) {
+ } else if (!strcasecmp(action, "changepw")) {
changepw();
- }
-
- else if (!strcasecmp(action, "display_edit_node")) {
+ } else if (!strcasecmp(action, "display_edit_node")) {
display_edit_node();
- }
-
- else if (!strcasecmp(action, "display_netconf")) {
+ } else if (!strcasecmp(action, "display_netconf")) {
display_netconf();
- }
-
- else if (!strcasecmp(action, "display_confirm_unshare")) {
+ } else if (!strcasecmp(action, "display_confirm_unshare")) {
display_confirm_unshare();
- }
-
- else if (!strcasecmp(action, "display_confirm_delete_node")) {
+ } else if (!strcasecmp(action, "display_confirm_delete_node")) {
display_confirm_delete_node();
- }
-
- else if (!strcasecmp(action, "delete_node")) {
+ } else if (!strcasecmp(action, "delete_node")) {
delete_node();
- }
-
- else if (!strcasecmp(action, "unshare")) {
+ } else if (!strcasecmp(action, "unshare")) {
unshare();
- }
-
- else if (!strcasecmp(action, "display_add_node")) {
+ } else if (!strcasecmp(action, "display_add_node")) {
display_add_node();
- }
-
- else if (!strcasecmp(action, "add_node")) {
+ } else if (!strcasecmp(action, "add_node")) {
add_node();
- }
-
- else if (!strcasecmp(action, "display_share")) {
+ } else if (!strcasecmp(action, "display_share")) {
display_share();
- }
-
- else if (!strcasecmp(action, "share")) {
+ } else if (!strcasecmp(action, "share")) {
share();
- }
-
- else if (!strcasecmp(action, "terminate_session")) {
+ } else if (!strcasecmp(action, "terminate_session")) {
terminate_session();
- }
-
- else if (!strcasecmp(action, "edit_me")) {
+ } else if (!strcasecmp(action, "edit_me")) {
edit_me();
- }
-
- else if (!strcasecmp(action, "display_siteconfig")) {
+ } else if (!strcasecmp(action, "display_siteconfig")) {
display_siteconfig();
- }
-
- else if (!strcasecmp(action, "siteconfig")) {
+ } else if (!strcasecmp(action, "siteconfig")) {
siteconfig();
- }
-
- else if (!strcasecmp(action, "display_generic")) {
+ } else if (!strcasecmp(action, "display_generic")) {
display_generic();
- }
-
- else if (!strcasecmp(action, "do_generic")) {
+ } else if (!strcasecmp(action, "do_generic")) {
do_generic();
- }
-
+ }
/* When all else fails... */
else {
printf("HTTP/1.0 200 OK\n");
output_headers(1, "");
-
+
wprintf("TransactionCount is %d<BR>\n", TransactionCount);
wprintf("You're in session %d<HR>\n", wc_session);
wprintf("Command: <BR><PRE>\n");
dump_vars();
wprintf("</PRE><HR>\n");
wDumpContent(1);
- }
+ }
fflush(stdout);
if (content != NULL) {
free(content);
content = NULL;
- }
+ }
free_urls();
if (upload_length > 0) {
free(upload);
upload_length = 0;
- }
}
+}
+
+int main(int argc, char *argv[])
+{
-int main(int argc, char *argv[]) {
+ char browser[256];
+ int bd_use_frames;
if (argc != 6) {
fprintf(stderr,
"webcit: usage error (argc must be 6, not %d)\n",
argc);
return 1;
- }
-
+ }
wc_session = atoi(argv[1]);
defaulthost = argv[2];
defaultport = argv[3];
strcpy(wc_username, "");
strcpy(wc_password, "");
strcpy(wc_roomname, "");
+
strcpy(browser, argv[5]);
+ bd_use_frames = browser_braindamage_check(browser);
while (1) {
- session_loop(argv[4]);
- }
+ session_loop(argv[4], bd_use_frames);
}
+}
/* $Id$ */
-#define SLEEPING 180 /* TCP connection timeout */
-#define WEBCIT_TIMEOUT 900 /* WebCit session timeout */
-#define PORT_NUM 2000 /* port number to listen on */
+#define SLEEPING 180 /* TCP connection timeout */
+#define WEBCIT_TIMEOUT 900 /* WebCit session timeout */
+#define PORT_NUM 2000 /* port number to listen on */
#define SERVER "WebCit v2.0 (Velma)" /* who's in da house */
#define DEVELOPER_ID 0
#define CLIENT_ID 4
#define RB (2)
#define QU (3)
#define TARGET "webcit01"
-#define HOUSEKEEPING 60 /* Housekeeping frequency */
+#define HOUSEKEEPING 60 /* Housekeeping frequency */
-#define QR_PERMANENT 1 /* Room does not purge */
-#define QR_INUSE 2 /* Set if in use, clear if avail */
-#define QR_PRIVATE 4 /* Set for any type of private room */
-#define QR_PASSWORDED 8 /* Set if there's a password too */
-#define QR_GUESSNAME 16 /* Set if it's a guessname room */
-#define QR_DIRECTORY 32 /* Directory room */
-#define QR_UPLOAD 64 /* Allowed to upload */
-#define QR_DOWNLOAD 128 /* Allowed to download */
-#define QR_VISDIR 256 /* Visible directory */
-#define QR_ANONONLY 512 /* Anonymous-Only room */
-#define QR_ANONOPT 1024 /* Anonymous-Option room */
-#define QR_NETWORK 2048 /* Shared network room */
-#define QR_PREFONLY 4096 /* Preferred status needed to enter */
-#define QR_READONLY 8192 /* Aide status required to post */
-#define QR_MAILBOX 16384 /* Set if this is a private mailbox */
+/* Values that can be returned by browser_braindamage_check() */
+#define B_YES 0 /* Ok to use frames and JavaScript */
+#define B_NO 1 /* Do not use frames and JavaScript */
+#define B_ASK 2 /* Ask the user */
+
+
+/* Room flags (from Citadel) */
+#define QR_PERMANENT 1 /* Room does not purge */
+#define QR_INUSE 2 /* Set if in use, clear if avail */
+#define QR_PRIVATE 4 /* Set for any type of private room */
+#define QR_PASSWORDED 8 /* Set if there's a password too */
+#define QR_GUESSNAME 16 /* Set if it's a guessname room */
+#define QR_DIRECTORY 32 /* Directory room */
+#define QR_UPLOAD 64 /* Allowed to upload */
+#define QR_DOWNLOAD 128 /* Allowed to download */
+#define QR_VISDIR 256 /* Visible directory */
+#define QR_ANONONLY 512 /* Anonymous-Only room */
+#define QR_ANONOPT 1024 /* Anonymous-Option room */
+#define QR_NETWORK 2048 /* Shared network room */
+#define QR_PREFONLY 4096 /* Preferred status needed to enter */
+#define QR_READONLY 8192 /* Aide status required to post */
+#define QR_MAILBOX 16384 /* Set if this is a private mailbox */
struct webcontent {
struct webcontent *next;
char w_data[256];
- };
+};
struct urlcontent {
struct urlcontent *next;
char url_key[32];
char *url_data;
- };
+};
struct serv_info {
int serv_pid;
char serv_sysadm[64];
char serv_moreprompt[256];
int serv_ok_floors;
- };
+};
extern char wc_username[256];
extern char wc_password[256];
extern char *upload;
extern char floorlist[128][256];
extern int noframes;
-extern char browser[256];
void stuff_to_cookie(char *, int, char *, char *, char *, int);
void cookie_to_stuff(char *, int *, char *, char *, char *, int *);
void locate_host(char *, int);
-
#include "webcit.h"
#ifndef HAVE_SNPRINTF
-int vsnprintf (char *buf, size_t max, const char *fmt, va_list argp);
+int vsnprintf(char *buf, size_t max, const char *fmt, va_list argp);
#endif
-int msock; /* master listening socket */
+int msock; /* master listening socket */
extern void *context_loop(int);
extern void *housekeeping_loop(void);
extern pthread_mutex_t MasterCritter;
if (port_number == 0) {
printf("webcit: Cannot start: no port number specified.\n");
exit(1);
- }
-
- sin.sin_port = htons((u_short)port_number);
+ }
+ sin.sin_port = htons((u_short) port_number);
s = socket(PF_INET, SOCK_STREAM, (getprotobyname("tcp")->p_proto));
if (s < 0) {
printf("webcit: Can't create a socket: %s\n",
- strerror(errno));
+ strerror(errno));
exit(errno);
- }
-
+ }
/* Set some socket options that make sense. */
i = 1;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
- if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+ if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
printf("webcit: Can't bind: %s\n", strerror(errno));
exit(errno);
- }
-
+ }
if (listen(s, queue_len) < 0) {
printf("webcit: Can't listen: %s\n", strerror(errno));
exit(errno);
- }
-
- return(s);
}
+ return (s);
+}
/*
int retval;
while (bytes_written < nbytes) {
retval = write(sock, &buf[bytes_written],
- nbytes - bytes_written);
+ nbytes - bytes_written);
if (retval < 1) {
printf("client_write() failed: %s\n",
- strerror(errno));
+ strerror(errno));
pthread_exit(NULL);
- }
- bytes_written = bytes_written + retval;
}
+ bytes_written = bytes_written + retval;
}
+}
/*
* cprintf() ... Send formatted printable data to the client.
*/
-void cprintf(int sock, const char *format, ...) {
- va_list arg_ptr;
- char buf[256];
-
- va_start(arg_ptr, format);
- if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
+void cprintf(int sock, const char *format,...)
+{
+ va_list arg_ptr;
+ char buf[256];
+
+ va_start(arg_ptr, format);
+ if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
buf[sizeof buf - 2] = '\n';
- client_write(sock, buf, strlen(buf));
+ client_write(sock, buf, strlen(buf));
va_end(arg_ptr);
- }
+}
/*
* Read data from the client socket.
* Return values are:
- * 1 Requested number of bytes has been read.
- * 0 Request timed out.
+ * 1 Requested number of bytes has been read.
+ * 0 Request timed out.
* If the socket breaks, the session is immediately terminated.
*/
int client_read_to(int sock, char *buf, int bytes, int timeout)
{
- int len,rlen;
+ int len, rlen;
fd_set rfds;
struct timeval tv;
int retval;
len = 0;
- while(len<bytes) {
+ while (len < bytes) {
FD_ZERO(&rfds);
FD_SET(sock, &rfds);
tv.tv_sec = timeout;
tv.tv_usec = 0;
- retval = select( (sock)+1,
- &rfds, NULL, NULL, &tv);
+ retval = select((sock) + 1,
+ &rfds, NULL, NULL, &tv);
if (FD_ISSET(sock, &rfds) == 0) {
- return(0);
- }
-
- rlen = read(sock, &buf[len], bytes-len);
- if (rlen<1) {
+ return (0);
+ }
+ rlen = read(sock, &buf[len], bytes - len);
+ if (rlen < 1) {
printf("client_read() failed: %s\n",
- strerror(errno));
+ strerror(errno));
pthread_exit(NULL);
- }
- len = len + rlen;
}
- return(1);
+ len = len + rlen;
}
+ return (1);
+}
/*
* Read data from the client socket with default timeout.
*/
int client_read(int sock, char *buf, int bytes)
{
- return(client_read_to(sock, buf, bytes, SLEEPING));
- }
+ return (client_read_to(sock, buf, bytes, SLEEPING));
+}
/*
/* Read one character at a time.
*/
- for (i = 0;;i++) {
+ for (i = 0;; i++) {
retval = client_read(sock, &buf[i], 1);
if (retval != 1 || buf[i] == '\n' || i == 255)
break;
- }
+ }
/* If we got a long line, discard characters until the newline.
*/
* Strip any trailing not-printable characters.
*/
buf[i] = 0;
- while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1]))) {
- buf[strlen(buf)-1] = 0;
- }
- return(retval);
+ while ((strlen(buf) > 0) && (!isprint(buf[strlen(buf) - 1]))) {
+ buf[strlen(buf) - 1] = 0;
}
+ return (retval);
+}
/*
* Start running as a daemon. Only close stdio if do_close_stdio is set.
*/
-void start_daemon(int do_close_stdio) {
+void start_daemon(int do_close_stdio)
+{
if (do_close_stdio) {
/* close(0); */
close(1);
close(2);
- }
- signal(SIGHUP,SIG_IGN);
- signal(SIGINT,SIG_IGN);
- signal(SIGQUIT,SIG_IGN);
- if (fork()!=0) exit(0);
}
+ signal(SIGHUP, SIG_IGN);
+ signal(SIGINT, SIG_IGN);
+ signal(SIGQUIT, SIG_IGN);
+ if (fork() != 0)
+ exit(0);
+}
/*
* Here's where it all begins.
int main(int argc, char **argv)
{
struct sockaddr_in fsin; /* Data for master socket */
- int alen; /* Data for master socket */
- int ssock; /* Descriptor for master socket */
- pthread_t SessThread; /* Thread descriptor */
- pthread_attr_t attr; /* Thread attributes */
- int a, i; /* General-purpose variables */
- int port = PORT_NUM; /* Port to listen on */
+ int alen; /* Data for master socket */
+ int ssock; /* Descriptor for master socket */
+ pthread_t SessThread; /* Thread descriptor */
+ pthread_attr_t attr; /* Thread attributes */
+ int a, i; /* General-purpose variables */
+ int port = PORT_NUM; /* Port to listen on */
/* Parse command line */
while ((a = getopt(argc, argv, "hp:")) != EOF)
switch (a) {
- case 'p':
+ case 'p':
port = atoi(optarg);
break;
- default:
+ default:
fprintf(stderr, "usage: webserver [-p localport] "
"[remotehost [remoteport]]\n");
return 1;
- }
+ }
if (optind < argc) {
defaulthost = argv[optind];
if (++optind < argc)
defaultport = argv[optind];
- }
-
+ }
/* Tell 'em who's in da house */
printf("WebCit v2 experimental\n");
printf("Copyright (C) 1996-1998 by Art Cancro. ");
printf("All rights reserved.\n\n");
- if (chdir(WEBCITDIR)!=0) perror("chdir");
+ if (chdir(WEBCITDIR) != 0)
+ perror("chdir");
/*
* Bind the server to our favourite port.
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&SessThread, &attr,
- (void* (*)(void*)) housekeeping_loop, NULL);
+ (void *(*)(void *)) housekeeping_loop, NULL);
/*
* Endless loop. Listen on the master socket. When a connection
* comes in, create a socket, a context, and a thread.
- */
+ */
while (1) {
- ssock = accept(msock, (struct sockaddr *)&fsin, &alen);
+ ssock = accept(msock, (struct sockaddr *) &fsin, &alen);
printf("New connection on socket %d\n", ssock);
if (ssock < 0) {
printf("webcit: accept() failed: %s\n",
- strerror(errno));
- }
- else {
+ strerror(errno));
+ } else {
/* Set the SO_REUSEADDR socket option */
i = 1;
setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR,
- &i, sizeof(i));
+ &i, sizeof(i));
/* set attributes for the new thread */
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr,
- PTHREAD_CREATE_DETACHED);
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr,
+ PTHREAD_CREATE_DETACHED);
/* now create the thread */
if (pthread_create(&SessThread, &attr,
- (void* (*)(void*)) context_loop,
- (void*) ssock)
+ (void *(*)(void *)) context_loop,
+ (void *) ssock)
!= 0) {
printf("webcit: can't create thread: %s\n",
- strerror(errno));
- }
-
+ strerror(errno));
}
}
}
-
+}
char roomname[256];
char hostname[256];
char clientsoftware[256];
- };
-
+};
+
/*
* who is on?
*/
-void whobbs(void) {
+void whobbs(void)
+{
struct whouser *wlist = NULL;
struct whouser *wptr = NULL;
- char buf[256],sess,user[256],room[256],host[256];
+ char buf[256], sess, user[256], room[256], host[256];
int foundit;
- printf("HTTP/1.0 200 OK\n");
- output_headers(1, "bottom");
+ printf("HTTP/1.0 200 OK\n");
+ output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Users currently on ");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Users currently on ");
escputs(serv_info.serv_humannode);
- wprintf("</B></FONT></TD></TR></TABLE>\n");
+ wprintf("</B></FONT></TD></TR></TABLE>\n");
wprintf("<CENTER>\n<TABLE BORDER=1>\n<TR>\n");
wprintf("<TH><FONT FACE=\"Arial,Helvetica,sans-serif\">Session ID</FONT></TH>\n");
wprintf("<TH><FONT FACE=\"Arial,Helvetica,sans-serif\">From host</FONT></TH>\n</TR>\n");
serv_puts("RWHO");
serv_gets(buf);
- if (buf[0]=='1') {
- while(serv_gets(buf), strcmp(buf,"000")) {
+ if (buf[0] == '1') {
+ while (serv_gets(buf), strcmp(buf, "000")) {
sess = extract_int(buf, 0);
extract(user, buf, 1);
extract(room, buf, 2);
extract(host, buf, 3);
foundit = 0;
- for (wptr = wlist; wptr != NULL; wptr = wptr -> next) {
+ for (wptr = wlist; wptr != NULL; wptr = wptr->next) {
if (wptr->sessionnum == sess) {
foundit = 1;
if (strcasecmp(user, wptr->username)) {
- sprintf(buf, "%cBR%c%s",
+ sprintf(buf, "%cBR%c%s",
LB, RB, user);
strcat(wptr->username, buf);
- }
+ }
if (strcasecmp(room, wptr->roomname)) {
- sprintf(buf, "%cBR%c%s",
+ sprintf(buf, "%cBR%c%s",
LB, RB, room);
strcat(wptr->roomname, buf);
- }
+ }
if (strcasecmp(host, wptr->hostname)) {
- sprintf(buf, "%cBR%c%s",
+ sprintf(buf, "%cBR%c%s",
LB, RB, host);
strcat(wptr->hostname, buf);
- }
}
}
+ }
if (foundit == 0) {
wptr = (struct whouser *)
- malloc(sizeof(struct whouser));
+ malloc(sizeof(struct whouser));
wptr->next = wlist;
wlist = wptr;
strcpy(wlist->username, user);
strcpy(wlist->roomname, room);
strcpy(wlist->hostname, host);
wlist->sessionnum = sess;
- }
}
+ }
while (wlist != NULL) {
wprintf("<TR>\n\t<TD ALIGN=center><FONT FACE=\"Arial,Helvetica,sans-serif\">%d", wlist->sessionnum);
- if ( (is_aide) &&
- (wlist->sessionnum != serv_info.serv_pid) ) {
+ if ((is_aide) &&
+ (wlist->sessionnum != serv_info.serv_pid)) {
wprintf(" <A HREF=\"/terminate_session&which_session=%d&session_owner=", wlist->sessionnum);
urlescputs(wlist->username);
wprintf("\">(kill)</A>");
- }
+ }
if (wlist->sessionnum == serv_info.serv_pid) {
wprintf(" <A HREF=\"/edit_me\">(edit)</A>");
- }
+ }
/* username */
wprintf("</FONT></TD>\n\t<TD><FONT FACE=\"Arial,Helvetica,sans-serif\"><A HREF=\"/showuser?who=");
escputs(wlist->username);
/* room */
wprintf("</FONT></TD>\n\t<TD><FONT FACE=\"Arial,Helvetica,sans-serif\">");
/* handle chat */
- if(strstr(wlist->roomname,"chat") != NULL){
+ if (strstr(wlist->roomname, "chat") != NULL) {
wprintf("<A HREF=\"/chat\" onMouseOver=\"window.status='Chat'; return true\"><chat></A>");
- }
- else {
+ } else {
wprintf("<A HREF=\"/dotgoto&room=");
escputs(wlist->roomname);
wprintf("\" onMouseOver=\"window.status='Go to room ");
wprintf("'; return true\">");
escputs(wlist->roomname);
wprintf("</A>");
- }
+ }
wprintf("</FONT></TD><TD><FONT FACE=\"Arial,Helvetica,sans-serif\">");
/* hostname */
escputs(wlist->hostname);
wptr = wlist->next;
free(wlist);
wlist = wptr;
- }
}
+ }
wprintf("</TABLE>\n<BR><BR>\n");
wprintf("<TABLE BORDER=0 BGCOLOR=\"#003399\">\n<TR><TD ALIGN=center VALIGN=center CELLPADING=10>\n");
wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+2><B><A HREF=\"/whobbs\"><FONT COLOR=\"#FF0000\">Refresh</FONT></A></B></FONT>\n");
wprintf("</TD></TR>\n</TABLE>\n</CENTER>");
- wDumpContent(1);
- }
+ wDumpContent(1);
+}
-void terminate_session(void) {
+void terminate_session(void)
+{
char buf[256];
if (!strcasecmp(bstr("confirm"), "Yes")) {
serv_printf("TERM %s", bstr("which_session"));
serv_gets(buf);
- if (buf[0]=='2') {
+ if (buf[0] == '2') {
whobbs();
- }
- else {
+ } else {
display_error(&buf[4]);
- }
}
-
- else {
+ } else {
printf("HTTP/1.0 200 OK\n");
output_headers(1, "bottom");
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
- wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+1 COLOR=\"FFFFFF\"<B>Confirm session termination");
- wprintf("</B></FONT></TD></TR></TABLE>\n");
-
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
+ wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+1 COLOR=\"FFFFFF\"<B>Confirm session termination");
+ wprintf("</B></FONT></TD></TR></TABLE>\n");
+
wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">Are you sure you want to terminate session %s",
bstr("which_session"));
- if (strlen(bstr("session_owner"))>0) {
+ if (strlen(bstr("session_owner")) > 0) {
wprintf(" (");
escputs(bstr("session_owner"));
wprintf(")");
- }
+ }
wprintf("?<BR><BR>\n");
-
+
wprintf("<A HREF=\"/terminate_session&which_session=%s&confirm=yes\">",
bstr("which_session"));
wprintf("Yes</A> ");
wprintf("<A HREF=\"/whobbs\">No</A></FONT>");
wDumpContent(1);
- }
-
}
+}
+
/*
* Change your session info (fake roomname and hostname)
*/
-void edit_me(void) {
+void edit_me(void)
+{
char buf[256];
printf("HTTP/1.0 200 OK\n");
serv_printf("RCHG %s", bstr("fake_roomname"));
serv_gets(buf);
whobbs();
- }
- else if (!strcasecmp(bstr("sc"), "Change host name")) {
+ } else if (!strcasecmp(bstr("sc"), "Change host name")) {
serv_printf("HCHG %s", bstr("fake_hostname"));
serv_gets(buf);
whobbs();
- }
- else if (!strcasecmp(bstr("sc"), "Change user name")) {
+ } else if (!strcasecmp(bstr("sc"), "Change user name")) {
serv_printf("UCHG %s", bstr("fake_username"));
serv_gets(buf);
whobbs();
- }
- else if (!strcasecmp(bstr("sc"), "Cancel")) {
+ } else if (!strcasecmp(bstr("sc"), "Cancel")) {
whobbs();
- }
- else {
+ } else {
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
- wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+1 COLOR=\"FFFFFF\"><B>");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
+ wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+1 COLOR=\"FFFFFF\"><B>");
wprintf("Edit your session display");
- wprintf("</B></FONT></TD></TR></TABLE>\n");
+ wprintf("</B></FONT></TD></TR></TABLE>\n");
wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
wprintf("This screen allows you to change the way your\n");
wprintf("session appears in the 'Who is online' listing.\n");
wprintf("without typing anything in the corresponding box.\n");
wprintf("<BR>\n</FONT>\n");
- wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_me\">\n");
+ wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_me\">\n");
wprintf("<TABLE border=0 width=100%>\n");
- wprintf("<TR><TD><FONT FACE=\"Arial,Helvetica,sans-serif\"><B>Room name:</B></FONT></TD>\n<TD>");
- wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"text\" NAME=\"fake_roomname\" MAXLENGTH=\"64\">\n");
+ wprintf("<TR><TD><FONT FACE=\"Arial,Helvetica,sans-serif\"><B>Room name:</B></FONT></TD>\n<TD>");
+ wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"text\" NAME=\"fake_roomname\" MAXLENGTH=\"64\">\n");
wprintf("</FONT></TD>\n<TD ALIGN=center>");
- wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change room name\">");
+ wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change room name\">");
wprintf("</FONT></TD>\n</TR>\n");
- wprintf("<TR><TD><FONT FACE=\"Arial,Helvetica,sans-serif\"><B>Host name:</B></FONT></TD><TD>");
- wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"text\" NAME=\"fake_hostname\" MAXLENGTH=\"64\">\n");
+ wprintf("<TR><TD><FONT FACE=\"Arial,Helvetica,sans-serif\"><B>Host name:</B></FONT></TD><TD>");
+ wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"text\" NAME=\"fake_hostname\" MAXLENGTH=\"64\">\n");
wprintf("</FONT></TD>\n<TD ALIGN=center>");
- wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change host name\">");
+ 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) {
- 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("<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>");
- wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change user name\">");
+ wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change user name\">");
wprintf("</FONT></TD>\n</TR>\n");
- }
-
+ }
wprintf("<TR><TD> </TD><TD> </TD><TD ALIGN=center>");
- wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
+ wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
wprintf("</TD></TR></TABLE>\n");
- wprintf("</FORM></CENTER>\n");
+ wprintf("</FORM></CENTER>\n");
wDumpContent(1);
- }
}
-
+}
--- /dev/null
+/* $Source$
+
+ * $Revision$
+ *
+ * wildmat.c - simple regular expression pattern matching routines
+ *
+ * DESCRIPTION
+ *
+ * These routines provide simple UNIX style regular expression matching.
+ * They were originally written by Rich Salz, the comp.sources.unix
+ * moderator for inclusion in some of his software. These routines
+ * were released into the public domain and used by John Gilmore in
+ * USTAR.
+ *
+ * AUTHORS
+ *
+ * Mark H. Colburn, NAPS International (mark@jhereg.mn.org)
+ * John Gilmore (gnu@hoptoad)
+ * Rich Salz (rs@uunet.uu.net)
+ *
+ *
+ * Sponsored by The USENIX Association for public distribution.
+ *
+ * Copyright (c) 1989 Mark H. Colburn.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice is duplicated in all such
+ * forms and that any documentation, advertising materials, and other
+ * materials related to such distribution and use acknowledge that the
+ * software was developed * by Mark H. Colburn and sponsored by The
+ * USENIX Association.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Log$
+ * Revision 1.1 1999/03/07 03:09:55 ajc
+ * * wildmat.c, braindamage.c: added
+ *
+ * Revision 1.1 88/12/23 18:02:41 mark
+ * Initial revision
+ *
+ */
+
+#ifndef lint
+static char *ident = "$Id$";
+static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
+#endif /* ! lint */
+
+
+/* Includes */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+
+
+
+/* Function Prototypes */
+
+#ifdef __STDC__
+static int star(char *, char *);
+#else /* !__STDC__ */
+static int star();
+#endif /* __STDC__ */
+
+
+/*
+ * star - handle trailing * in a regular expression
+ *
+ * DESCRIPTION
+ *
+ * Star is used to match filename expansions containing a trailing
+ * asterisk ('*'). Star call wildmat() to determine if the substring
+ * passed to it is matches the regular expression.
+ *
+ * PARAMETERS
+ *
+ * char *source - The source string which is to be compared to the
+ * regular expression pattern.
+ * char *pattern - The regular expression which we are supposed to
+ * match to.
+ *
+ * RETURNS
+ *
+ * Returns non-zero if the entire source string is completely matched by
+ * the regular expression pattern, returns 0 otherwise. This is used to
+ * see if *'s in a pattern matched the entire source string.
+ *
+ */
+
+#ifdef __STDC__
+
+static int star(char *source, char *pattern)
+#else
+
+static int star(source, pattern)
+char *source; /* source operand */
+char *pattern; /* regular expression to match */
+
+#endif
+{
+ while (!wildmat(source, pattern)) {
+ if (*++source == '\0') {
+ return (0);
+ }
+ }
+ return (1);
+}
+
+
+/*
+ * wildmat - match a regular expression
+ *
+ * DESCRIPTION
+ *
+ * Wildmat attempts to match the string pointed to by source to the
+ * regular expression pointed to by pattern. The subset of regular
+ * expression syntax which is supported is defined by POSIX P1003.2
+ * FILENAME EXPANSION rules.
+ *
+ * PARAMETERS
+ *
+ * char *source - The source string which is to be compared to the
+ * regular expression pattern.
+ * char *pattern - The regular expression which we are supposed to
+ * match to.
+ *
+ * RETURNS
+ *
+ * Returns non-zero if the source string matches the regular expression
+ * pattern specified, returns 0 otherwise.
+ *
+ */
+
+#ifdef __STDC__
+
+int wildmat(char *pattern, char *source)
+#else
+
+int wildmat(pattern, source)
+char *pattern; /* regular expression to match */
+char *source; /* source operand */
+
+#endif
+{
+ int last; /* last character matched */
+ int matched; /* !0 if a match occurred */
+ int reverse; /* !0 if sense of match is reversed */
+
+ for (; *pattern; source++, pattern++) {
+ switch (*pattern) {
+ case '\\':
+ /* Literal match with following character */
+ pattern++;
+ /* FALLTHRU */
+ default:
+ if (*source != *pattern) {
+ return (0);
+ }
+ continue;
+ case '?':
+ /* Match anything. */
+ if (*source == '\0') {
+ return (0);
+ }
+ continue;
+ case '*':
+ /* Trailing star matches everything. */
+ return (*++pattern ? star(source, pattern) : 1);
+ case '[':
+ /* [^....] means inverse character class. */
+ if (reverse = pattern[1] == '^') {
+ pattern++;
+ }
+ for (last = 0400, matched = 0;
+ *++pattern && *pattern != ']'; last = *pattern) {
+ /* This next line requires a good C compiler. */
+ if (*pattern == '-'
+ ? *source <= *++pattern && *source >= last
+ : *source == *pattern) {
+ matched = 1;
+ }
+ }
+ if (matched == reverse) {
+ return (0);
+ }
+ continue;
+ }
+ }
+
+ /*
+ * For "tar" use, matches that end at a slash also work. --hoptoad!gnu
+ */
+ return (*source == '\0' || *source == '/');
+}