From c90b9009ad3b2411389d3dad969c19ec17688268 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 7 Mar 1999 03:09:55 +0000 Subject: [PATCH] * wildmat.c, braindamage.c: added --- webcit/ChangeLog | 3 +- webcit/Makefile.in | 12 +- webcit/auth.c | 312 +++++++------- webcit/braindamage.c | 58 +++ webcit/child.h | 11 +- webcit/context_loop.c | 212 ++++----- webcit/cookie_conversion.c | 31 +- webcit/graphics.c | 64 +-- webcit/locate_host.c | 40 +- webcit/mainmenu.c | 249 ++++++----- webcit/messages.c | 395 ++++++++--------- webcit/mime_parser.c | 182 ++++---- webcit/mime_parser.h | 62 +-- webcit/netconf.c | 118 ++--- webcit/paging.c | 83 ++-- webcit/roomops.c | 856 +++++++++++++++++++------------------ webcit/serv_func.c | 169 ++++---- webcit/siteconfig.c | 100 +++-- webcit/snprintf.c | 70 ++- webcit/sysmsgs.c | 47 +- webcit/tcp_sockets.c | 148 +++---- webcit/tools.c | 100 ++--- webcit/userlist.c | 107 +++-- webcit/webcit.c | 782 +++++++++++++++------------------ webcit/webcit.h | 53 +-- webcit/webserver.c | 161 ++++--- webcit/who.c | 143 +++---- webcit/wildmat.c | 198 +++++++++ 28 files changed, 2497 insertions(+), 2269 deletions(-) create mode 100644 webcit/braindamage.c create mode 100644 webcit/wildmat.c diff --git a/webcit/ChangeLog b/webcit/ChangeLog index ec5a6f0d1..384b571f7 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -2,7 +2,8 @@ Sat Mar 6 19:56:07 EST 1999 Art Cancro * 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 * context_loop.c: warning fix diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 0ed4d6452..17fc32ea8 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -38,10 +38,12 @@ snprintf.o: snprintf.c 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 @@ -97,6 +99,12 @@ netconf.o: netconf.c webcit.h child.h 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 diff --git a/webcit/auth.c b/webcit/auth.c index 3588631fc..624844a4c 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -17,7 +17,8 @@ #include "webcit.h" #include "child.h" -char *axdefs[] = { +char *axdefs[] = +{ "Deleted", "New User", "Problem User", @@ -25,12 +26,13 @@ char *axdefs[] = { "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"); @@ -43,12 +45,12 @@ void display_login(char *mesg) { if (mesg != NULL) { wprintf("%s", mesg); - } - else { + } else { serv_puts("MESG hello"); serv_gets(buf); - if (buf[0]=='1') fmout(NULL); - } + if (buf[0] == '1') + fmout(NULL); + } wprintf("\n"); wprintf("
\n"); @@ -63,12 +65,12 @@ void display_login(char *mesg) { wprintf("\n"); wprintf("\n"); wprintf("\n"); - wprintf("\n"); - wprintf("\n"); - + wprintf("\n"); + wprintf("\n"); + wprintf("
"); wprintf(" Check here to disable frames\n"); - wprintf("\n"); + wprintf("\n"); /* Da instructions */ wprintf("
  • If you already have an account on %s,", @@ -80,12 +82,10 @@ void display_login(char *mesg) { wprintf("\"New User.\"
  • "); wprintf("Please log off properly when finished."); wprintf("
  • You must use a browser that supports cookies.
    \n"); - wprintf("
  • Your browser is: "); - escputs(browser); wprintf("\n"); wDumpContent(1); - } +} @@ -93,16 +93,19 @@ void display_login(char *mesg) { /* * 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; @@ -114,64 +117,57 @@ void do_login(void) { 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"); @@ -181,15 +177,14 @@ void do_welcome(void) { wprintf("\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, ""); @@ -199,18 +194,20 @@ void do_logout(void) { printf("HTTP/1.0 200 OK\n"); output_headers(2, "_top"); /* note "2" causes cookies to be unset */ - wprintf("
    "); + wprintf("
    "); 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("
    Log in again
    \n"); wDumpContent(2); serv_puts("QUIT"); exit(0); - } +} @@ -219,7 +216,8 @@ void do_logout(void) { /* * validate new users */ -void validate(void) { +void validate(void) +{ char cmd[256]; char user[256]; char buf[256]; @@ -228,59 +226,66 @@ void validate(void) { 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("%s
    \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("%s
    \n", &buf[4]); } } - serv_puts("GNUR"); serv_gets(buf); - if (buf[0]!='3') { + if (buf[0] != '3') { wprintf("%s
    \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

    %s

    ", - buf,&cmd[4]); - if (a==2) wprintf("PW: %s
    \n",buf); - if (a==3) wprintf("%s
    \n",buf); - if (a==4) wprintf("%s
    \n",buf); - if (a==5) wprintf("%s, ",buf); - if (a==6) wprintf("%s ",buf); - if (a==7) wprintf("%s
    \n",buf); - if (a==8) wprintf("%s
    \n",buf); - if (a==9) wprintf("Current access level: %d (%s)\n", - atoi(buf),axdefs[atoi(buf)]); - } while(strcmp(buf,"000")); - } - else { - wprintf("

    %s

    %s
    \n",user,&cmd[4]); - } + if (a == 1) + wprintf("User #%s

    %s

    ", + buf, &cmd[4]); + if (a == 2) + wprintf("PW: %s
    \n", buf); + if (a == 3) + wprintf("%s
    \n", buf); + if (a == 4) + wprintf("%s
    \n", buf); + if (a == 5) + wprintf("%s, ", buf); + if (a == 6) + wprintf("%s ", buf); + if (a == 7) + wprintf("%s
    \n", buf); + if (a == 8) + wprintf("%s
    \n", buf); + if (a == 9) + wprintf("Current access level: %d (%s)\n", + atoi(buf), axdefs[atoi(buf)]); + } while (strcmp(buf, "000")); + } else { + wprintf("

    %s

    %s
    \n", user, &cmd[4]); + } wprintf("
    "); - for (a=0; a<=6; ++a) { + for (a = 0; a <= 6; ++a) { wprintf( - "\n", - urlesc(user), a, axdefs[a]); - } + "\n", + urlesc(user), a, axdefs[a]); + } wprintf("
    Select access level:"); wprintf("
    %s%s

    \n"); wDumpContent(1); - } +} @@ -292,81 +297,88 @@ void validate(void) { * (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("
    "); - wprintf("Enter registration info\n"); - wprintf("
    \n"); + wprintf("
    "); + wprintf("Enter registration info\n"); + wprintf("
    \n"); wprintf("
    "); serv_puts("MESG register"); serv_gets(buf); - if (buf[0]=='1') fmout(NULL); + if (buf[0] == '1') + fmout(NULL); wprintf("
    \n"); wprintf("\n", during_login); serv_puts("GREG _SELF_"); serv_gets(buf); - if (buf[0]!='1') { - wprintf("%s
    \n",&buf[4]); - } - else { - - wprintf("

    %s

    \n",&buf[4]); + if (buf[0] != '1') { + wprintf("%s
    \n", &buf[4]); + } else { + + wprintf("

    %s

    \n", &buf[4]); a = 0; - while (serv_gets(buf), strcmp(buf,"000")) { + while (serv_gets(buf), strcmp(buf, "000")) { ++a; wprintf("\n"); + switch (a) { + case 3: + wprintf("Real Name:
    "); - switch(a) { - case 3: wprintf("Real Name:
    \n",buf); - break; - case 4: wprintf("Street Address:

    \n",buf); - break; - case 5: wprintf("City/town:

    \n",buf); - break; - case 6: wprintf("State/province:

    \n",buf); - break; - case 7: wprintf("ZIP code:

    \n",buf); - break; - case 8: wprintf("Telephone:

    \n",buf); - break; - case 9: wprintf("E-Mail:

    \n",buf); - break; - } - wprintf("

    \n", buf); + break; + case 4: + wprintf("Street Address:

    \n", buf); + break; + case 5: + wprintf("City/town:

    \n", buf); + break; + case 6: + wprintf("State/province:

    \n", buf); + break; + case 7: + wprintf("ZIP code:

    \n", buf); + break; + case 8: + wprintf("Telephone:

    \n", buf); + break; + case 9: + wprintf("E-Mail:

    \n", buf); + break; } - wprintf("

    "); + wprintf("\n"); } + wprintf("

    "); + } wprintf("\n"); wprintf("\n"); wprintf("

    \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")); @@ -375,14 +387,13 @@ void register_user(void) { 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."); - } } +} @@ -391,56 +402,59 @@ void register_user(void) { /* * 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("
    "); - wprintf("Change your password\n"); - wprintf("
    \n"); + wprintf("
    "); + wprintf("Change your password\n"); + wprintf("
    \n"); wprintf("
    "); serv_puts("MESG changepw"); serv_gets(buf); - if (buf[0]=='1') fmout(NULL); + if (buf[0] == '1') + fmout(NULL); wprintf("\n"); wprintf("
    \n"); wprintf("\n"); wprintf("\n"); wprintf("\n"); - wprintf("
    Enter new password:
    Enter it again to confirm:
    \n"); + wprintf("\n"); wprintf("\n"); wprintf("\n"); wprintf("
    \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]); +} diff --git a/webcit/braindamage.c b/webcit/braindamage.c new file mode 100644 index 000000000..71056f5af --- /dev/null +++ b/webcit/braindamage.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#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); +} diff --git a/webcit/child.h b/webcit/child.h index 7cfbc2f3e..640ab36f9 100644 --- a/webcit/child.h +++ b/webcit/child.h @@ -20,14 +20,14 @@ int connectsock(char *host, char *service, char *protocol); 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); @@ -66,7 +66,7 @@ void editroom(void); 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); @@ -77,7 +77,7 @@ void serv_read(char *buf, int bytes); 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); @@ -100,3 +100,4 @@ void display_siteconfig(void); void siteconfig(void); void display_generic(void); void do_generic(void); +int browser_braindamage_check(char *); diff --git a/webcit/context_loop.c b/webcit/context_loop.c index be6c646c8..e128256df 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -43,13 +43,13 @@ */ 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; @@ -63,133 +63,144 @@ pthread_mutex_t MasterCritter; * 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; a0); + } while (strlen(buf) > 0); /* * See if there's an existing session open with the desired ID @@ -276,15 +286,14 @@ void *context_loop(int sock) { 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. @@ -294,9 +303,8 @@ void *context_loop(int sock) { printf(" Session is *DEAD* !!\n"); remove_session(TheSession, 1); TheSession = NULL; - } } - + } /* * Create a new session if we have to */ @@ -305,7 +313,7 @@ void *context_loop(int sock) { 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); @@ -316,10 +324,12 @@ void *context_loop(int sock) { 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); @@ -328,7 +338,7 @@ void *context_loop(int sock) { /* 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); @@ -346,32 +356,33 @@ void *context_loop(int sock) { printf("Error\n"); printf("execlp() failed: %s\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; ainpipe[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. @@ -386,14 +397,14 @@ void *context_loop(int sock) { 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, @@ -401,18 +412,17 @@ void *context_loop(int sock) { */ 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)); @@ -422,4 +432,4 @@ end: unlock_session(TheSession); * thing, and supresses a compiler warning. */ return NULL; - } +} diff --git a/webcit/cookie_conversion.c b/webcit/cookie_conversion.c index dd082849e..a4865f7d9 100644 --- a/webcit/cookie_conversion.c +++ b/webcit/cookie_conversion.c @@ -11,14 +11,15 @@ /* * 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"); - wprintf("Set/change %s\n", description); - wprintf("\n"); + wprintf("
    "); + wprintf("Set/change %s\n", description); + wprintf("
    \n"); wprintf("
    \n"); wprintf("\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).

    \n"); wprintf("Please select a file to upload:
    \n"); - wprintf("\n"); + wprintf("\n"); wprintf("
    "); - wprintf("\n"); - wprintf("\n"); - wprintf("\n"); + wprintf("\n"); + wprintf("\n"); + wprintf("\n"); wprintf("Cancel\n"); wprintf("
    \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; @@ -54,15 +55,13 @@ void do_graphics_upload(char *upl_cmd) { 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); @@ -73,40 +72,41 @@ void do_graphics_upload(char *upl_cmd) { 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("
    "); - wprintf("Select floor to edit label graphic\n"); - wprintf("
    \n"); + wprintf("
    "); + wprintf("Select floor to edit label graphic\n"); + wprintf("
    \n"); load_floorlist(); - for (a=0; a<128; ++a) if (strlen(floorlist[a])>0) { - wprintf("", a); - escputs(floorlist[a]); - wprintf("\n"); + for (a = 0; a < 128; ++a) + if (strlen(floorlist[a]) > 0) { + wprintf("", a); + escputs(floorlist[a]); + wprintf("\n"); } - wDumpContent(1); - } +} diff --git a/webcit/locate_host.c b/webcit/locate_host.c index 9a19f9b5b..fba5d8847 100644 --- a/webcit/locate_host.c +++ b/webcit/locate_host.c @@ -15,29 +15,27 @@ 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, ""); - return; + int a1, a2, a3, a4; + + len = sizeof(cs); + if (getpeername(client_socket, (struct sockaddr *) &cs, &len) < 0) { + strcpy(tbuf, ""); + 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; +} diff --git a/webcit/mainmenu.c b/webcit/mainmenu.c index 1ef9dc625..c780ef4ef 100644 --- a/webcit/mainmenu.c +++ b/webcit/mainmenu.c @@ -16,7 +16,8 @@ * menu of commands (just the menu html itself) */ -void embed_main_menu(void) { +void embed_main_menu(void) +{ wprintf("
    "); wprintf("
    "); /* start of first column */ @@ -25,29 +26,28 @@ void embed_main_menu(void) { wprintf("
  • \n"); wprintf("List known rooms
    \n"); wprintf("Where can I go from here?
  • \n"); - + wprintf("
  • \n"); wprintf("Goto next room
    \n"); wprintf("...with unread messages
  • \n"); - + wprintf("
  • \n"); wprintf("Skip to next room
    \n"); wprintf("(come back here later)
  • \n"); - - if ( (strlen(ugname)>0) && (strcasecmp(ugname,wc_roomname)) ) { + + if ((strlen(ugname) > 0) && (strcasecmp(ugname, wc_roomname))) { wprintf("
  • \n"); wprintf("Ungoto
    \n"); - wprintf("(oops! Back to %s)
  • \n",ugname); - } - + wprintf("(oops! Back to %s)\n", ugname); + } wprintf("\n"); - - wprintf("
    \n"); /* start of second column */ - + + wprintf("\n"); /* start of second column */ + wprintf("\n"); - wprintf(""); /* start of third column */ + wprintf(""); /* start of third column */ wprintf("
    \n"); wprintf("
    \n"); - } +} /* * advanced options */ -void embed_advanced_menu(void) { +void embed_advanced_menu(void) +{ -wprintf("
    "); + wprintf("
    "); -wprintf("
    "); -wprintf("Interaction\n"); -wprintf("
    \n"); + wprintf("
    "); + wprintf("Interaction\n"); + wprintf("
    \n"); -wprintf("\n"); -wprintf("
    "); + wprintf(""); -wprintf("
    "); -wprintf("Your info\n"); -wprintf("
    \n"); + wprintf("
    "); + wprintf("Your info\n"); + wprintf("
    \n"); -wprintf("\n"); -wprintf("
    "); + wprintf("
    "); -wprintf("
    "); -wprintf("Advanced room commands\n"); -wprintf("
    \n"); + wprintf("
    "); + wprintf("Advanced room commands\n"); + wprintf("
    \n"); -wprintf("\n"); -wprintf("
    "); + wprintf(""); -if ((axlevel>=6) || (is_room_aide)) { - wprintf("
    "); - wprintf("Administrative functions\n"); - wprintf("
    \n"); + if ((axlevel >= 6) || (is_room_aide)) { + wprintf("
    "); + wprintf("Administrative functions\n"); + wprintf("
    \n"); - wprintf("
    "); + if (axlevel >= 6) { + wprintf("
  • \n"); + wprintf("Validate new users\n"); -wprintf("
    "); -wprintf("Basic commands\n"); -wprintf("
    \n"); + wprintf("
  • \n"); + wprintf("Set or change a floor label graphic\n"); + wprintf("
  • \n"); + wprintf("Configure networking with other systems\n"); + } + wprintf("\n"); } + wprintf("
  • "); + + wprintf("
    "); + wprintf("Basic commands\n"); + wprintf("
    \n"); + +} @@ -199,30 +198,33 @@ wprintf("\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("
    "); wprintf("Enter a server command\n"); @@ -246,9 +248,10 @@ void display_generic(void) { wprintf("\n"); wDumpContent(1); - } +} -void do_generic(void) { +void do_generic(void) +{ char buf[256]; char gcontent[256]; char *junk; @@ -257,8 +260,7 @@ void do_generic(void) { if (strcasecmp(bstr("sc"), "Send command")) { display_main_menu(); return; - } - + } serv_printf("%s", bstr("g_cmd")); serv_gets(buf); @@ -275,40 +277,35 @@ void do_generic(void) { escputs(buf); wprintf("

    \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("
    \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("
    "); wprintf("Enter another command
    \n"); wprintf("Return to menu\n"); wDumpContent(1); - } +} diff --git a/webcit/messages.c b/webcit/messages.c index 07ebc2be4..9719518c1 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -16,10 +16,11 @@ long msgarr[1024]; * 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]; @@ -28,37 +29,46 @@ char buf[]; { end = strlen(buf); ench = 0; - for (pos=0; pos0)&&(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]; @@ -68,70 +78,69 @@ char *oper; { 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("ERROR: %s
    \n",&buf[4]); + if (buf[0] != '1') { + wprintf("ERROR: %s
    \n", &buf[4]); return; - } - + } wprintf(""); - + if (is_room_aide) { wprintf(""); - } - + } wprintf("
    \n"); wprintf(" "); - 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(""); @@ -146,39 +155,35 @@ char *oper; { wprintf("\">Del"); wprintf("
    \n"); - if (strlen(m_subject)>0) { - wprintf("Subject: %s
    \n",m_subject); - } - + if (strlen(m_subject) > 0) { + wprintf("Subject: %s
    \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(""); 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(""); bq = 0; - } + } wprintf(""); url(buf); escputs(buf); wprintf("
    \n"); - } } - wprintf("
    "); } + wprintf("
    "); +} @@ -186,29 +191,31 @@ char *oper; { * 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("%s
    \n",&buf[4]); - return(nummsgs); - } - while (serv_gets(buf), strcmp(buf,"000")) { + if (buf[0] != '1') { + wprintf("%s
    \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; @@ -216,49 +223,45 @@ void readloop(char *oper) { printf("HTTP/1.0 200 OK\n"); output_headers(1, "bottom"); - wprintf("
    %s - ",wc_roomname); - if (!strcmp(oper,"readnew")) { - strcpy(cmd,"MSGS NEW"); + wprintf("
    %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("

    \n"); nummsgs = load_msg_ptrs(cmd); if (nummsgs == 0) { - if (!strcmp(oper,"readnew")) { + if (!strcmp(oper, "readnew")) { wprintf("No new messages in this room.\n"); - } - else if (!strcmp(oper,"readold")) { + } else if (!strcmp(oper, "readold")) { wprintf("No old messages in this room.\n"); - } - else { + } else { wprintf("This room is empty.\n"); - } - goto DONE; } - - for (a=0; a\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.
    \n"); - } - else { - wprintf("%s
    \n",&buf[4]); - } + } else { + wprintf("%s
    \n", &buf[4]); } + } wDumpContent(1); - } +} @@ -296,12 +296,13 @@ void post_message(void) { /* * prompt for a recipient (to be called from display_enter() only) */ -void prompt_for_recipient() { +void prompt_for_recipient() +{ - wprintf("
    "); - wprintf("Send private e-mail\n"); - wprintf("
    \n"); + wprintf("
    "); + wprintf("Send private e-mail\n"); + wprintf("
    \n"); wprintf("
    "); wprintf("
    \n"); @@ -310,14 +311,15 @@ void prompt_for_recipient() { wprintf(""); wprintf(""); wprintf("
    \n"); - } +} /* * display the message entry screen */ -void display_enter(void) { +void display_enter(void) +{ char buf[256]; long now; struct tm *tm; @@ -325,36 +327,36 @@ void display_enter(void) { 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("%s
    \n",&buf[4]); - } + if (!strncmp(buf, "570", 3)) { + if (strlen(bstr("recp")) > 0) { + wprintf("%s
    \n", &buf[4]); + } prompt_for_recipient(); goto DONE; - } - - if (buf[0]!='2') { - wprintf("%s
    \n",&buf[4]); + } + if (buf[0] != '2') { + wprintf("%s
    \n", &buf[4]); goto DONE; - } - + } wprintf("
    Enter message below. Messages are formatted to\n"); wprintf("the reader's screen width. To defeat the\n"); wprintf("formatting, indent a line at least one space. \n"); wprintf("
    "); time(&now); - tm=(struct tm *)localtime(&now); - strcpy(buf,(char *)asctime(tm)); buf[strlen(buf)-1]=0; - strcpy(&buf[16],&buf[19]); - wprintf("
    %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("
    %s ", &buf[4]); + wprintf("from %s ", wc_username); + if (strlen(bstr("recp")) > 0) + wprintf("to %s ", bstr("recp")); + wprintf("in %s> ", wc_roomname); wprintf("
    \n"); wprintf("
    \n"); @@ -366,8 +368,8 @@ void display_enter(void) { wprintf("

    \n"); wprintf("

    \n"); -DONE: wDumpContent(1); - } + DONE:wDumpContent(1); +} @@ -379,11 +381,12 @@ 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"); @@ -405,11 +408,12 @@ void confirm_delete_msg(void) { wprintf("
    \n"); wDumpContent(1); - } +} -void delete_msg(void) { +void delete_msg(void) +{ long msgid; char buf[256]; @@ -423,13 +427,12 @@ void delete_msg(void) { serv_puts(buf); serv_gets(buf); wprintf("%s
    \n", &buf[4]); - } - else { + } else { wprintf("Message not deleted.
    \n"); - } + } wDumpContent(1); - } +} @@ -437,13 +440,14 @@ void delete_msg(void) { /* * 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"); @@ -461,19 +465,19 @@ void confirm_move_msg(void) { bstr("msgid")); - wprintf("\n"); - wprintf("
    \n"); + wprintf("\n"); + wprintf("
    \n"); wprintf(""); wprintf(""); @@ -481,11 +485,12 @@ void confirm_move_msg(void) { wprintf("
    \n"); wDumpContent(1); - } +} -void move_msg(void) { +void move_msg(void) +{ long msgid; char buf[256]; @@ -499,11 +504,9 @@ void move_msg(void) { serv_puts(buf); serv_gets(buf); wprintf("%s
    \n", &buf[4]); - } - else { + } else { wprintf("Message not deleted.
    \n"); - } - - wDumpContent(1); } + wDumpContent(1); +} diff --git a/webcit/mime_parser.c b/webcit/mime_parser.c index ed23f3518..91c15b9dc 100644 --- a/webcit/mime_parser.c +++ b/webcit/mime_parser.c @@ -18,22 +18,25 @@ -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; a0)); - 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) @@ -146,16 +153,17 @@ void handle_part(char *content, 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; @@ -168,27 +176,27 @@ void mime_parser(char *content, /* 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(UnShare)"); wprintf("\n"); - } - wprintf("
    \n"); } - - wDumpContent(1); + wprintf("
    \n"); } - + wDumpContent(1); +} + -void display_netconf(void) { +void display_netconf(void) +{ char buf[256]; char node[256]; @@ -98,15 +99,15 @@ void display_netconf(void) { urlescputs(node); wprintf("\">(Delete)"); wprintf("\n"); - } - wprintf("\n"); } - - wDumpContent(1); + wprintf("\n"); } + wDumpContent(1); +} -void display_confirm_unshare(void) { +void display_confirm_unshare(void) +{ char node[256]; char sroom[256]; @@ -131,10 +132,11 @@ void display_confirm_unshare(void) { urlescputs(node); wprintf("\">No
    \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"); @@ -153,56 +155,57 @@ void display_confirm_delete_node(void) { wprintf("\">Yes   "); wprintf("No
    \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("Back to menu\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("Back to menu\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("
    "); @@ -221,11 +224,12 @@ void display_add_node(void) { wprintf("\n"); wDumpContent(1); - } +} -void add_node(void) { +void add_node(void) +{ char node[256]; char buf[256]; char sc[256]; @@ -237,23 +241,22 @@ void add_node(void) { 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("Back to menu\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]; @@ -279,36 +282,34 @@ void display_share(void) { 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("\n"); wprintf("
    \n"); @@ -323,18 +324,19 @@ void display_share(void) { 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")); @@ -343,17 +345,15 @@ void share(void) { 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("Back to menu\n"); wDumpContent(1); - } - else { + } else { display_error(&buf[4]); - } - } - } + } +} diff --git a/webcit/paging.c b/webcit/paging.c index 47a565435..5cfbdddb9 100644 --- a/webcit/paging.c +++ b/webcit/paging.c @@ -15,17 +15,18 @@ /* * 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("
    "); - wprintf("Page another user\n"); - wprintf("
    \n"); + wprintf("
    "); + wprintf("Page another user\n"); + wprintf("
    \n"); wprintf("This command sends a near-real-time message to any currently\n"); wprintf("logged in user.

    \n"); @@ -37,14 +38,14 @@ void display_page(void) { wprintf("\n"); wprintf("
    \n"); @@ -56,59 +57,59 @@ void display_page(void) { wprintf("
    \n"); wprintf("\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("Message was not sent.
    \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("Message has been sent to "); escputs(recp); wprintf(".
    \n"); - } - else { - wprintf("%s
    \n",&buf[4]); - } - - wDumpContent(1); + } else { + wprintf("%s
    \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("
    "); - wprintf("Real-time chat\n"); - wprintf("
    \n"); + wprintf("
    "); + wprintf("Real-time chat\n"); + wprintf("
    \n"); wprintf("A chat window should be appearing on your screen "); wprintf("momentarily. When you're "); @@ -122,5 +123,5 @@ void do_chat(void) { wprintf("

    Oops!

    Looks like your browser doesn't support Java, "); wprintf("so you won't be able to access Chat. Sorry.\n"); wprintf("\n"); - wDumpContent(1); - } + wDumpContent(1); +} diff --git a/webcit/roomops.c b/webcit/roomops.c index e331afc16..f2f205705 100644 --- a/webcit/roomops.c +++ b/webcit/roomops.c @@ -19,20 +19,20 @@ struct march { 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]; @@ -47,22 +47,24 @@ struct march *march = NULL; /* * 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); + } +} /* @@ -70,63 +72,66 @@ void load_floorlist(void) { */ 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(""); - 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(" \n"); if (rp->rnext != NULL) { room_tree_list(rp->rnext); - } - - free(rp); } + free(rp); +} /* @@ -134,15 +139,22 @@ void room_tree_list(struct roomlisting *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); +} /* @@ -160,7 +172,8 @@ void listrms(char *variety) /* 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); @@ -173,31 +186,28 @@ void listrms(char *variety) 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); - } +} @@ -210,70 +220,72 @@ void listrms(char *variety) /* * 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(""); wprintf(""); wprintf("\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(""); + wprintf(""); - /* Rooms with new messages column */ - wprintf("\n"); + /* Rooms with old messages column */ + sprintf(buf, "LKRO %d", a); + listrms(buf); + wprintf("\n"); } wprintf("
    FloorRooms with new messagesRooms with no new messages
    "); - - serv_printf("OIMG _floorpic_|%d", a); - serv_gets(buf); - if (buf[0] == '2') { - serv_puts("CLOS"); + /* Floor name column */ + wprintf("
    "); + + serv_printf("OIMG _floorpic_|%d", a); serv_gets(buf); - wprintf("\"%s\"", - a, &floorlist[a][0]); - } - else { - escputs(&floorlist[a][0]); + if (buf[0] == '2') { + serv_puts("CLOS"); + serv_gets(buf); + wprintf("\"%s\"", + a, &floorlist[a][0]); + } else { + escputs(&floorlist[a][0]); } - wprintf(""); - sprintf(buf,"LKRN %d",a); - listrms(buf); - wprintf("\n"); + /* Rooms with new messages column */ + wprintf(""); + sprintf(buf, "LKRN %d", a); + listrms(buf); + wprintf("\n"); - /* Rooms with old messages column */ - sprintf(buf,"LKRO %d",a); - listrms(buf); - wprintf("
    \n"); wDumpContent(1); - } +} /* * list all forgotten rooms */ -void zapped_list(void) { - printf("HTTP/1.0 200 OK\n"); - output_headers(1, "bottom"); - wprintf("
    "); - wprintf("Zapped (forgotten) rooms\n"); - wprintf("

    \n"); +void zapped_list(void) +{ + printf("HTTP/1.0 200 OK\n"); + output_headers(1, "bottom"); + wprintf("
    "); + wprintf("Zapped (forgotten) rooms\n"); + wprintf("

    \n"); listrms("LZRM -1"); wprintf("

    \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) @@ -284,11 +296,13 @@ void readinfo(int v) serv_puts("RINF"); serv_gets(buf); - if (buf[0]=='1') fmout(NULL); + if (buf[0] == '1') + fmout(NULL); else { - if (v==1) wprintf("%s
    \n",&buf[4]); - } + if (v == 1) + wprintf("%s
    \n", &buf[4]); } +} /* @@ -307,62 +321,61 @@ void gotoroom(char *gname, int display_name) if (display_name) { printf("HTTP/1.0 200 OK\n"); output_headers(0, "top"); - wprintf("\n\n\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("%s
    \n",&buf[4]); + wprintf("%s
    \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("
    "); - if ( (strlen(ugname)>0) && (strcasecmp(ugname,wc_roomname)) ) { + if ((strlen(ugname) > 0) && (strcasecmp(ugname, wc_roomname))) { wprintf(""); - } - - wprintf("\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 @@ -371,15 +384,14 @@ void gotoroom(char *gname, int display_name) */ serv_puts("OIMG _roompic_"); serv_gets(buf); - if (buf[0]=='2') { + if (buf[0] == '2') { wprintf(""); serv_puts("CLOS"); serv_gets(buf); - } - + } wprintf(""); @@ -389,17 +401,17 @@ void gotoroom(char *gname, int display_name) wprintf("
    "); wprintf("

    %s

    ",wc_roomname); + } + wprintf("

    %s

    ", wc_roomname); wprintf("%d new of %d messages
    "); wprintf(""); readinfo(0); wprintf("
    \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; @@ -408,7 +420,8 @@ char *pop_march(int desired_floor) { 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; @@ -417,18 +430,18 @@ char *pop_march(int desired_floor) { 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); +} @@ -439,115 +452,113 @@ char *pop_march(int desired_floor) { * 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 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("%s
    \n",&buf[4]); + if (buf[0] != '2') { + wprintf("%s
    \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]; @@ -560,64 +571,68 @@ void display_editroom(void) { 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("
    "); - wprintf("Edit this room\n"); - wprintf("
    \n"); + wprintf("
    "); + wprintf("Edit this room\n"); + wprintf("
    \n"); wprintf("
    \n"); - wprintf("
    • Name of room: "); - wprintf("\n",er_name); + wprintf("
      • Name of room: "); + wprintf("\n", er_name); wprintf("
      • Resides on floor: "); load_floorlist(); wprintf("\n"); wprintf("
      • Type of room:
          \n"); wprintf("
        • Public room\n"); wprintf("
        • Private - guess name\n"); wprintf("
        • Private - require password:\n"); - wprintf("\n",er_password); + wprintf("\n", er_password); wprintf("
        • Private - invitation only\n"); @@ -627,54 +642,64 @@ void display_editroom(void) { wprintf("
        \n"); wprintf("
      • Preferred users only\n"); wprintf("
      • Read-only room\n"); /* directory stuff */ wprintf("
      • File directory room\n"); wprintf("
        • Directory name: "); - wprintf("\n",er_dirname); + wprintf("\n", er_dirname); wprintf("
        • Uploading allowed\n"); wprintf("
        • Downloading allowed\n"); wprintf("
        • Visible directory
        \n"); /* end of directory stuff */ - + wprintf("
      • Network shared room\n"); /* start of anon options */ wprintf("
      • Anonymous messages
          \n"); - + wprintf("
        • No anonymous messages\n"); wprintf("
        • All messages are anonymous\n"); wprintf("
        • Prompt user when entering messages
        \n"); /* end of anon options */ @@ -682,27 +707,27 @@ void display_editroom(void) { wprintf("
      • Room aide: \n"); serv_puts("GETA"); serv_gets(buf); - if (buf[0]!='2') { - wprintf("%s\n",&buf[4]); - } - else { - extract(er_roomaide,&buf[4],0); - wprintf("\n",er_roomaide); - } - + if (buf[0] != '2') { + wprintf("%s\n", &buf[4]); + } else { + extract(er_roomaide, &buf[4], 0); + wprintf("\n", er_roomaide); + } + wprintf("
      \n"); wprintf(""); wprintf(""); wprintf("
      \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]; @@ -713,168 +738,164 @@ void editroom(void) { 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("
      "); - wprintf("Enter (create) a new room\n"); - wprintf("
      \n"); + wprintf("
      "); + wprintf("Enter (create) a new room\n"); + wprintf("
      \n"); wprintf("\n"); - wprintf("
      • Name of room: "); + wprintf("
        • Name of room: "); wprintf("\n"); wprintf("
        • Type of room:
            \n"); @@ -898,43 +919,46 @@ void display_entroom(void) { wprintf("\n"); wprintf("\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); +} /* @@ -943,13 +967,13 @@ void entroom(void) { 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("
            "); - wprintf("Goto a private room\n"); - wprintf("
            \n"); + wprintf("
            "); + wprintf("Goto a private room\n"); + wprintf("
            \n"); wprintf("
            \n"); wprintf("If you know the name of a hidden (guess-name) or\n"); @@ -958,76 +982,74 @@ void display_private(char *rname, int req_pass) wprintf("room, it will appear in your regular room listings\n"); wprintf("so you don't have to keep returning here.\n"); wprintf("

            "); - + wprintf("
            \n"); wprintf("
            "); wprintf("Enter room name:"); - wprintf("\n",rname); + wprintf("\n", rname); if (req_pass) { wprintf("
            "); wprintf("Enter room password:"); wprintf("\n"); - } - + } wprintf("
            \n"); - + wprintf(""); wprintf(""); wprintf("
            \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("
            "); - wprintf("Zap (forget) the current room\n"); - wprintf("
            \n"); +void display_zap(void) +{ + printf("HTTP/1.0 200 OK\n"); + output_headers(1, "bottom"); + + wprintf("
            "); + wprintf("Zap (forget) the current room\n"); + wprintf("
            \n"); wprintf("If you select this option, %s will ", wc_roomname); wprintf("disappear from your room list. Is this what you wish "); @@ -1038,36 +1060,34 @@ void display_zap(void) { wprintf(""); wprintf("\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); +} @@ -1075,16 +1095,16 @@ void zap(void) { /* * 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("
            "); @@ -1104,32 +1124,28 @@ void confirm_delete_room(void) { wprintf("\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); - } } - - - +} diff --git a/webcit/serv_func.c b/webcit/serv_func.c index 878ba9f5c..686dcc1bb 100644 --- a/webcit/serv_func.c +++ b/webcit/serv_func.c @@ -15,48 +15,59 @@ struct serv_info serv_info; /* * 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; } +} @@ -65,51 +76,52 @@ void get_serv_info(char *browser_host) { * 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(""); + 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(""); wprintf("

            \n"); return; - } - if ( (intext==1) && (isspace(buf[0])) ) { + } + if ((intext == 1) && (isspace(buf[0]))) { wprintf("
            "); - } + } 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(""); bq = 1; - } - else if ((bq==1)&& - (strncmp(buf," >",2))&&(strncmp(buf," :-)",4))) { + } else if ((bq == 1) && + (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) { wprintf(""); bq = 0; - } - + } /* Activate embedded URL's */ url(buf); escputs(buf); wprintf("\n"); - } } +} @@ -119,38 +131,38 @@ void fmout(FILE *fp) /* * 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); +} @@ -161,20 +173,17 @@ void text_to_server(char *ptr) { * 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; - } } - - - - +} diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c index ce582e2c9..2fe475387 100644 --- a/webcit/siteconfig.c +++ b/webcit/siteconfig.c @@ -14,107 +14,126 @@ #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("
            "); - wprintf("Site configuration"); - wprintf("
            \n"); + wprintf("
            "); + wprintf("Site configuration"); + wprintf("
            \n"); wprintf("

            \n"); wprintf("\n"); while (serv_gets(buf), strcmp(buf, "000")) { - ++i; - switch(i) { - case 1: wprintf("\n"); break; - case 2: wprintf("\n"); break; - case 3: wprintf("\n"); break; - case 4: wprintf("\n"); break; - case 5: wprintf("\n"); break; - case 6: wprintf("\n"); break; - case 7: wprintf("\n"); break; - case 8: wprintf("\n"); break; - case 9: wprintf("\n"); break; - case 10:wprintf("\n"); break; - case 11:wprintf("\n"); break; - case 12:wprintf("\n"); break; - case 13:wprintf("\n"); break; - case 14:wprintf("\n"); break; - case 15:wprintf("\n"); break; - case 16:wprintf("\n"); break; - case 17:wprintf("\n"); break; - case 18:wprintf("\n"); break; - case 19:wprintf("\n"); break; - } + } } wprintf("
            Node name"); + ++i; + switch (i) { + case 1: + wprintf("
            Node name"); wprintf("", buf); wprintf("
            Fully qualified domain name"); + case 2: + wprintf("
            Fully qualified domain name"); wprintf("", buf); wprintf("
            Human-readable node name"); + case 3: + wprintf("
            Human-readable node name"); wprintf("", buf); wprintf("
            Landline telephone number"); + case 4: + wprintf("
            Landline telephone number"); wprintf("", buf); wprintf("
            Automatically grant room-aide status to users who create private rooms"); - wprintf("", ((atoi(buf)!=0) ? "CHECKED" : "")); + case 5: + wprintf("
            Automatically grant room-aide status to users who create private rooms"); + wprintf("", ((atoi(buf) != 0) ? "CHECKED" : "")); wprintf("
            Server connection idle timeout (in seconds)"); + case 6: + wprintf("
            Server connection idle timeout (in seconds)"); wprintf("", buf); wprintf("
            Initial access level for new users"); + case 7: + wprintf("
            Initial access level for new users"); wprintf("", buf); wprintf("
            Require registration for new users"); - wprintf("", ((atoi(buf)!=0) ? "CHECKED" : "")); + case 8: + wprintf("
            Require registration for new users"); + wprintf("", ((atoi(buf) != 0) ? "CHECKED" : "")); wprintf("
            Move problem user messages to twitroom"); - wprintf("", ((atoi(buf)!=0) ? "CHECKED" : "")); + case 9: + wprintf("
            Move problem user messages to twitroom"); + wprintf("", ((atoi(buf) != 0) ? "CHECKED" : "")); wprintf("
            Name of twitroom"); + case 10: + wprintf("
            Name of twitroom"); wprintf("", buf); wprintf("
            Paginator prompt"); + case 11: + wprintf("
            Paginator prompt"); wprintf("", buf); wprintf("
            Restrict access to Internet mail"); - wprintf("", ((atoi(buf)!=0) ? "CHECKED" : "")); + case 12: + wprintf("
            Restrict access to Internet mail"); + wprintf("", ((atoi(buf) != 0) ? "CHECKED" : "")); wprintf("
            Geographic location of this system"); + case 13: + wprintf("
            Geographic location of this system"); wprintf("", buf); wprintf("
            Name of system administrator"); + case 14: + wprintf("
            Name of system administrator"); wprintf("", buf); wprintf("
            Maximum concurrent sessions"); + case 15: + wprintf("
            Maximum concurrent sessions"); wprintf("", buf); wprintf("
            Server-to-server networking password"); + case 16: + wprintf("
            Server-to-server networking password"); wprintf("", buf); wprintf("
            Default user purge time (days)"); + case 17: + wprintf("
            Default user purge time (days)"); wprintf("", buf); wprintf("
            Default room purge time (days)"); + case 18: + wprintf("
            Default room purge time (days)"); wprintf("", buf); wprintf("
            Name of room to log pages"); + case 19: + wprintf("
            Name of room to log pages"); wprintf("", buf); wprintf("
            "); @@ -125,33 +144,32 @@ void display_siteconfig(void) { } -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")); @@ -161,4 +179,4 @@ void siteconfig(void) { serv_printf("%s", bstr("c_logpages")); serv_printf("000"); display_success("System configuration has been updated."); - } +} diff --git a/webcit/snprintf.c b/webcit/snprintf.c index 89d650d7d..5cf567fd6 100644 --- a/webcit/snprintf.c +++ b/webcit/snprintf.c @@ -27,57 +27,49 @@ #include #include -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; } diff --git a/webcit/sysmsgs.c b/webcit/sysmsgs.c index 7021ad16e..2ba2e43fb 100644 --- a/webcit/sysmsgs.c +++ b/webcit/sysmsgs.c @@ -12,25 +12,25 @@ * 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("
            "); - wprintf("Edit "); + wprintf("
            "); + wprintf("Edit "); escputs(description); - wprintf("
            \n"); + wprintf("
            \n"); wprintf("
            Enter %s below. Text is formatted to\n", description); wprintf("the reader's screen width. To defeat the\n"); @@ -43,45 +43,44 @@ void display_edit(char *description, char *check_cmd, wprintf("

            \n"); wprintf("

            \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.
            \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); - } - } + } +} diff --git a/webcit/tcp_sockets.c b/webcit/tcp_sockets.c index 017e1ea73..bafeea9b5 100644 --- a/webcit/tcp_sockets.c +++ b/webcit/tcp_sockets.c @@ -32,10 +32,11 @@ extern int errno; 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) { @@ -43,62 +44,54 @@ 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); +} @@ -108,21 +101,21 @@ int connectsock(char *host, char *service, char *protocol) */ void serv_read(char *buf, int bytes) { - int len,rlen; + int len, rlen; - len = 0; - while(len%s\n", strbuf); */ - } +} @@ -151,21 +144,21 @@ void serv_gets(char *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; + } +} /* @@ -175,25 +168,24 @@ void serv_puts(char *string) { 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); */ - } - - +} diff --git a/webcit/tools.c b/webcit/tools.c index 22e09a353..13fb03342 100644 --- a/webcit/tools.c +++ b/webcit/tools.c @@ -9,14 +9,13 @@ 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; } @@ -28,10 +27,11 @@ int num_parms(char *source) int a; int count = 1; - for (a=0; a= n) { - strcpy(dest,""); + strcpy(dest, ""); return; - } - strcpy(buf,source); - if ( (parmnum == 0) && (n == 1) ) { - strcpy(dest,buf); - for (n=0; n0) && (buf[0]!='|') ); - if (buf[0]=='|') strcpy(buf,&buf[1]); - for (count = 0; count 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 @@ -76,10 +78,10 @@ void extract(char *dest, char *source, int parmnum) 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 @@ -87,21 +89,23 @@ int extract_int(char *source, int parmnum) 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; anext = 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("%s
            \n",&buf[4]); + if (buf[0] != '1') { + wprintf("%s
            \n", &buf[4]); goto DONE; - } - - - wprintf("
            "); - wprintf("User list for "); + } + wprintf("
            "); + wprintf("User list for "); escputs(serv_info.serv_humannode); - wprintf("
            \n"); + wprintf("
            \n"); wprintf("
            "); wprintf(""); wprintf("\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("\n", - extract_long(buf,4),extract_long(buf,5)); + extract_long(buf, 4), extract_long(buf, 5)); - } - wprintf("
            User NameNumberAccess LevelLast CallTotal CallsTotal Posts
            "); if (has_bio) { wprintf(""); escputs(fl); wprintf(""); - } - else { + } else { escputs(fl); - } + } wprintf("%ld%d", - 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("%ld%5ld
            \n"); -DONE: wDumpContent(1); } + wprintf("
            \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("
            "); - wprintf("User profile"); - wprintf("
            \n"); + wprintf("
            "); + wprintf("User profile"); + wprintf("
            \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("
            "); if (have_pic == 1) { wprintf(""); - } - wprintf("

            %s

            \n",who); - serv_printf("RBIO %s",who); - serv_gets(buf); - if (buf[0]=='1') fmout(NULL); - wDumpContent(1); } + wprintf("

    %s

    \n", who); + serv_printf("RBIO %s", who); + serv_gets(buf); + if (buf[0] == '1') + fmout(NULL); + wDumpContent(1); +} diff --git a/webcit/webcit.c b/webcit/webcit.c index 407c4a92b..03bc0a053 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -26,7 +26,6 @@ int wc_session; 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; @@ -48,75 +47,83 @@ char *upload; 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 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; aurl_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) { @@ -124,61 +131,65 @@ void free_urls(void) { 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. @@ -189,17 +200,17 @@ int wContentLength(void) { * 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("
    "); embed_main_menu(); - } - wprintf("\n"); } - + wprintf("\n"); + } printf("Content-type: text/html\n"); printf("Content-length: %d\n", wContentLength()); printf("\n"); @@ -209,77 +220,86 @@ void wDumpContent(int print_standard_html_footer) { wptr = wlist->next; free(wlist); wlist = wptr; - } - wlast = NULL; } + wlast = NULL; +} void escputs1(char *strbuf, int nbsp) { int a; - for (a=0; 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; a0)&&(!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 @@ -287,7 +307,8 @@ char *getz(char *buf) { * 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]; @@ -295,29 +316,25 @@ void output_headers(int print_standard_html_head, char *target) { 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(""); - escputs("WebCit"); /* FIX -- add BBS name here */ + wprintf("<HTML><HEAD><TITLE>"); + escputs("WebCit"); /* FIX -- add BBS name here */ wprintf(""); if (ExpressMessages != NULL) { wprintf("\n"); - } + } wprintf("\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; @@ -381,33 +398,33 @@ void output_static(char *what) { 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; @@ -417,30 +434,31 @@ void output_image() { 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"); @@ -448,60 +466,79 @@ void output_image() { 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("
    ", titlebarcolor); - wprintf("%s\n", titlebarmsg); - wprintf("

    \n"); +void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext) +{ + printf("HTTP/1.0 200 OK\n"); + output_headers(1, "bottom"); + wprintf("
    ", titlebarcolor); + wprintf("%s\n", titlebarmsg); + wprintf("

    \n"); escputs(messagetext); - + if (noframes) { wprintf("
    \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; i0) { - 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]; @@ -549,405 +586,267 @@ void session_loop(char *browser_host) { 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; a0) 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\n", TransactionCount); wprintf("You're in session %d
    \n", wc_session); wprintf("Command:
    \n");
    @@ -957,29 +856,32 @@ void session_loop(char *browser_host) {
     		dump_vars();
     		wprintf("

    \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]; @@ -987,9 +889,11 @@ int main(int argc, char *argv[]) { 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); } +} diff --git a/webcit/webcit.h b/webcit/webcit.h index 8968551aa..3d99a11f0 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -1,8 +1,8 @@ /* $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 @@ -13,37 +13,44 @@ #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; @@ -56,7 +63,7 @@ struct serv_info { char serv_sysadm[64]; char serv_moreprompt[256]; int serv_ok_floors; - }; +}; extern char wc_username[256]; extern char wc_password[256]; @@ -76,9 +83,7 @@ extern int upload_length; 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); - diff --git a/webcit/webserver.c b/webcit/webserver.c index 48f874d83..5b62c7e7b 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -38,10 +38,10 @@ #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; @@ -65,33 +65,29 @@ int ig_tcp_server(int port_number, int queue_len) 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); +} /* @@ -103,69 +99,69 @@ void client_write(int sock, char *buf, int nbytes) 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(len0)&&(!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. @@ -233,37 +231,37 @@ void start_daemon(int do_close_stdio) { 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. @@ -285,42 +283,39 @@ int main(int argc, char **argv) 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)); } } } - +} diff --git a/webcit/who.c b/webcit/who.c index c4a654650..4fb70a56c 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -19,24 +19,25 @@ struct whouser { 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("
    "); - wprintf("Users currently on "); + wprintf("
    "); + wprintf("Users currently on "); escputs(serv_info.serv_humannode); - wprintf("
    \n"); + wprintf("
    \n"); wprintf("
    \n\n\n"); wprintf("\n"); @@ -45,58 +46,58 @@ void whobbs(void) { wprintf("\n\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("\n\t\n\t\n\t
    Session IDFrom host
    %d", wlist->sessionnum); - if ( (is_aide) && - (wlist->sessionnum != serv_info.serv_pid) ) { + if ((is_aide) && + (wlist->sessionnum != serv_info.serv_pid)) { wprintf(" sessionnum); urlescputs(wlist->username); wprintf("\">(kill)"); - } + } if (wlist->sessionnum == serv_info.serv_pid) { wprintf(" (edit)"); - } + } /* username */ wprintf("username); @@ -108,10 +109,9 @@ void whobbs(void) { /* room */ wprintf(""); /* handle chat */ - if(strstr(wlist->roomname,"chat") != NULL){ + if (strstr(wlist->roomname, "chat") != NULL) { wprintf("<chat>"); - } - else { + } else { wprintf("roomname); wprintf("\" onMouseOver=\"window.status='Go to room "); @@ -119,7 +119,7 @@ void whobbs(void) { wprintf("'; return true\">"); escputs(wlist->roomname); wprintf(""); - } + } wprintf(""); /* hostname */ escputs(wlist->hostname); @@ -127,61 +127,60 @@ void whobbs(void) { wptr = wlist->next; free(wlist); wlist = wptr; - } } + } wprintf("
    \n

    \n"); wprintf("\n\n
    \n"); wprintf("Refresh\n"); wprintf("
    \n
    "); - 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("
    "); - wprintf("Confirm session termination"); - wprintf("
    \n"); - + wprintf("
    "); + wprintf("Confirm session termination"); + wprintf("
    \n"); + wprintf("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("?

    \n"); - + wprintf("", bstr("which_session")); wprintf("Yes   "); wprintf("No
    "); 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"); @@ -191,26 +190,22 @@ void edit_me(void) { 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("
    "); - wprintf(""); + wprintf("
    "); + wprintf(""); wprintf("Edit your session display"); - wprintf("
    \n"); + wprintf("
    \n"); wprintf(""); wprintf("This screen allows you to change the way your\n"); wprintf("session appears in the 'Who is online' listing.\n"); @@ -219,36 +214,34 @@ void edit_me(void) { wprintf("without typing anything in the corresponding box.\n"); wprintf("
    \n
    \n"); - wprintf("
    \n"); + wprintf("\n"); wprintf("\n"); - wprintf("\n\n\n\n\n"); - wprintf("\n\n\n"); if (is_aide) { - wprintf("\n\n\n"); - } - + } wprintf("
    Room name:"); - wprintf("\n"); + wprintf("
    Room name:"); + wprintf("\n"); wprintf(""); - wprintf(""); + wprintf(""); wprintf("
    Host name:"); - wprintf("\n"); + wprintf("
    Host name:"); + wprintf("\n"); wprintf(""); - wprintf(""); + wprintf(""); wprintf("
    User name:"); - wprintf("\n"); + wprintf("
    User name:"); + wprintf("\n"); wprintf(""); - wprintf(""); + wprintf(""); wprintf("
      "); - wprintf(""); + wprintf(""); wprintf("
    \n"); - wprintf("
    \n"); + wprintf("\n"); wDumpContent(1); - } } - +} diff --git a/webcit/wildmat.c b/webcit/wildmat.c new file mode 100644 index 000000000..1e5f6f493 --- /dev/null +++ b/webcit/wildmat.c @@ -0,0 +1,198 @@ +/* $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 +#include +#include + + + +/* 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 == '/'); +} -- 2.30.2