$Log$
+Revision 301.9 2001/11/18 01:41:09 ajc
+* Brought over the newer string tokenizer from Citadel
+* Upgraded all the generic string buffers to 4096 bytes, using the Citadel
+ server's convention of #define SIZ 4096
+
Revision 301.8 2001/11/14 03:20:22 ajc
* Add some more of the newer config settings to the site config screen
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
-
#include <signal.h>
#include "webcit.h"
-
char *axdefs[] =
{
"Deleted",
*/
void display_login(char *mesg)
{
- char buf[256];
+ char buf[SIZ];
output_headers(3);
void do_login(void)
{
- char buf[256];
+ char buf[SIZ];
int need_regi = 0;
void do_logout(void)
{
- char buf[256];
+ char buf[SIZ];
strcpy(WC->wc_username, "");
strcpy(WC->wc_password, "");
*/
void validate(void)
{
- char cmd[256];
- char user[256];
- char buf[256];
+ char cmd[SIZ];
+ char user[SIZ];
+ char buf[SIZ];
int a;
output_headers(1);
*/
void display_reg(int during_login)
{
- char buf[256];
+ char buf[SIZ];
int a;
output_headers(1);
*/
void register_user(void)
{
- char buf[256];
+ char buf[SIZ];
if (strcmp(bstr("action"), "Register")) {
display_error("Cancelled. Registration was not saved.");
*/
void display_changepw(void)
{
- char buf[256];
+ char buf[SIZ];
output_headers(1);
*/
void changepw(void)
{
- char buf[256];
+ char buf[SIZ];
char newpass1[32], newpass2[32];
if (strcmp(bstr("action"), "Change")) {
int lingering_close(int fd)
{
- char buf[256];
+ char buf[SIZ];
int i;
fd_set set;
struct timeval tv, start;
struct httprequest *req = NULL;
struct httprequest *last = NULL;
struct httprequest *hptr;
- char buf[256], hold[256];
+ char buf[SIZ], hold[SIZ];
int desired_session = 0;
int got_cookie = 0;
struct wcsession *TheSession, *sptr;
#define FALSE 0
typedef unsigned char byte; /* Byte type */
-static byte dtable[256]; /* base64 encode / decode table */
+static byte dtable[SIZ]; /* base64 encode / decode table */
/*
* decode_base64() and encode_base64() are adaptations of code by
*/
void stuff_to_cookie(char *cookie, int session, char *user, char *pass, char *room)
{
- char buf[256];
+ char buf[SIZ];
sprintf(buf, "%d|%s|%s|%s", session, user, pass, room);
encode_base64(cookie, buf);
*/
void cookie_to_stuff(char *cookie, int *session, char *user, char *pass, char *room)
{
- char buf[256];
+ char buf[SIZ];
decode_base64(buf, cookie);
void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
{
- char buf[256];
+ char buf[SIZ];
serv_puts(check_cmd);
serv_gets(buf);
void do_graphics_upload(char *upl_cmd)
{
- char buf[256];
+ char buf[SIZ];
int bytes_remaining;
int pos = 0;
int thisblock;
void do_generic(void)
{
- char buf[256];
- char gcontent[256];
+ char buf[SIZ];
+ char gcontent[SIZ];
char *junk;
size_t len;
int pos;
int start, end;
char ench;
- char urlbuf[256];
+ char urlbuf[SIZ];
char outbuf[1024];
start = (-1);
void read_message(long msgnum, int is_summary) {
- char buf[256];
- char mime_partnum[256];
- char mime_filename[256];
- char mime_content_type[256];
- char mime_disposition[256];
+ char buf[SIZ];
+ char mime_partnum[SIZ];
+ char mime_filename[SIZ];
+ char mime_content_type[SIZ];
+ char mime_disposition[SIZ];
int mime_length;
char *mime_http = NULL;
- char m_subject[256];
- char from[256];
- char node[256];
- char rfca[256];
+ char m_subject[SIZ];
+ char from[SIZ];
+ char node[SIZ];
+ char rfca[SIZ];
char reply_to[512];
- char now[256];
+ char now[SIZ];
int format_type = 0;
int nhdr = 0;
int bq = 0;
int load_msg_ptrs(servcmd)
char *servcmd;
{
- char buf[256];
+ char buf[SIZ];
int nummsgs;
nummsgs = 0;
*/
void readloop(char *oper)
{
- char cmd[256];
+ char cmd[SIZ];
int a, b;
int nummsgs;
long startmsg;
*/
void post_message(void)
{
- char buf[256];
+ char buf[SIZ];
static long dont_post = (-1L);
output_headers(1);
*/
void display_enter(void)
{
- char buf[256];
+ char buf[SIZ];
long now;
struct tm *tm;
void delete_msg(void)
{
long msgid;
- char buf[256];
+ char buf[SIZ];
msgid = atol(bstr("msgid"));
void confirm_move_msg(void)
{
long msgid;
- char buf[256];
- char targ[256];
+ char buf[SIZ];
+ char targ[SIZ];
msgid = atol(bstr("msgid"));
void move_msg(void)
{
long msgid;
- char buf[256];
+ char buf[SIZ];
msgid = atol(bstr("msgid"));
struct sharelist {
struct sharelist *next;
- char shname[256];
+ char shname[SIZ];
};
void display_edit_node(void)
{
- char buf[256];
- char node[256];
- char sroom[256];
+ char buf[SIZ];
+ char node[SIZ];
+ char sroom[SIZ];
strcpy(node, bstr("node"));
void display_netconf(void)
{
- char buf[256];
- char node[256];
+ char buf[SIZ];
+ char node[SIZ];
output_headers(1);
wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
void display_confirm_unshare(void)
{
- char node[256];
- char sroom[256];
+ char node[SIZ];
+ char sroom[SIZ];
output_headers(1);
wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
void display_confirm_delete_node(void)
{
- char node[256];
+ char node[SIZ];
output_headers(1);
wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
void delete_node(void)
{
- char node[256];
- char buf[256];
+ char node[SIZ];
+ char buf[SIZ];
strcpy(node, bstr("node"));
sprintf(buf, "NSET deletenode|%s", node);
void unshare(void)
{
- char node[256];
- char sroom[256];
- char buf[256];
+ char node[SIZ];
+ char sroom[SIZ];
+ char buf[SIZ];
strcpy(node, bstr("node"));
strcpy(sroom, bstr("sroom"));
void add_node(void)
{
- char node[256];
- char buf[256];
- char sc[256];
+ char node[SIZ];
+ char buf[SIZ];
+ char sc[SIZ];
strcpy(node, bstr("node"));
strcpy(sc, bstr("sc"));
void display_share(void)
{
- char buf[256];
- char node[256];
- char sroom[256];
+ char buf[SIZ];
+ char node[SIZ];
+ char sroom[SIZ];
struct sharelist *shlist = NULL;
struct sharelist *shptr;
int already_shared;
void share(void)
{
- char node[256];
- char buf[256];
- char sc[256];
- char sroom[256];
+ char node[SIZ];
+ char buf[SIZ];
+ char sc[SIZ];
+ char sroom[SIZ];
strcpy(node, bstr("node"));
strcpy(sc, bstr("sc"));
*/
void display_page(void)
{
- char recp[256];
+ char recp[SIZ];
strcpy(recp, bstr("recp"));
*/
void page_user(void)
{
- char recp[256];
- char sc[256];
- char buf[256];
+ char recp[SIZ];
+ char sc[SIZ];
+ char buf[SIZ];
output_headers(1);
*/
void page_popup(void)
{
- char buf[256];
- char pagefrom[256];
+ char buf[SIZ];
+ char pagefrom[SIZ];
/* suppress express message check, do headers but no fake frames */
output_headers(0x08 | 0x03);
-char floorlist[128][256];
+char floorlist[128][SIZ];
/*
void load_floorlist(void)
{
int a;
- char buf[256];
+ char buf[SIZ];
for (a = 0; a < 128; ++a)
floorlist[a][0] = 0;
*/
void listrms(char *variety)
{
- char buf[256];
+ char buf[SIZ];
int num_rooms = 0;
struct roomlisting *rl = NULL;
void list_all_rooms_by_floor(void)
{
int a;
- char buf[256];
+ char buf[SIZ];
load_floorlist();
*/
void readinfo(void)
{
- char buf[256];
+ char buf[SIZ];
serv_puts("RINF");
serv_gets(buf);
* another room.
*/
void embed_room_graphic(void) {
- char buf[256];
+ char buf[SIZ];
serv_puts("OIMG _roompic_");
serv_gets(buf);
void embed_room_banner(char *got) {
- char fakegot[256];
+ char fakegot[SIZ];
/* We need to have the information returned by a GOTO server command.
* If it isn't supplied, we fake it by issuing our own GOTO.
*/
void gotoroom(char *gname, int display_name)
{
- char buf[256];
+ char buf[SIZ];
static long ls = (-1L);
*/
void gotonext(void)
{
- char buf[256];
+ char buf[SIZ];
struct march *mptr, *mptr2;
char next_room[32];
*/
void slrp_highest(void)
{
- char buf[256];
+ char buf[SIZ];
/* set pointer */
serv_puts("SLRP HIGHEST");
*/
void ungoto(void)
{
- char buf[256];
+ char buf[SIZ];
if (!strcmp(WC->ugname, "")) {
smart_goto(WC->wc_roomname);
*/
void display_editroom(void)
{
- char buf[256];
+ char buf[SIZ];
char er_name[20];
char er_password[10];
char er_dirname[15];
*/
void editroom(void)
{
- char buf[256];
+ char buf[SIZ];
char er_name[20];
char er_password[10];
char er_dirname[15];
*/
void display_whok(void)
{
- char buf[256], room[256], username[256];
+ char buf[SIZ], room[SIZ], username[SIZ];
serv_puts("GETR");
serv_gets(buf);
void display_entroom(void)
{
int i;
- char buf[256];
+ char buf[SIZ];
serv_puts("CRE8 0");
serv_gets(buf);
*/
void entroom(void)
{
- char buf[256];
+ char buf[SIZ];
char er_name[20];
char er_type[20];
char er_password[10];
void goto_private(void)
{
char hold_rm[32];
- char buf[256];
+ char buf[SIZ];
if (strcasecmp(bstr("sc"), "OK")) {
display_main_menu();
*/
void zap(void)
{
- char buf[256];
- char final_destination[256];
+ char buf[SIZ];
+ char final_destination[SIZ];
/* If the forget-room routine fails for any reason, we fall back
* to the current room; otherwise, we go to the Lobby
*/
void confirm_delete_room(void)
{
- char buf[256];
+ char buf[SIZ];
serv_puts("KILL 0");
serv_gets(buf);
*/
void delete_room(void)
{
- char buf[256];
- char sc[256];
+ char buf[SIZ];
+ char sc[SIZ];
strcpy(sc, bstr("sc"));
*/
void get_serv_info(char *browser_host, char *user_agent)
{
- char buf[256];
+ char buf[SIZ];
int a;
serv_printf("IDEN %d|%d|%d|%s|%s",
int intext = 0;
int bq = 0;
- char buf[256];
+ char buf[SIZ];
wprintf("<DIV ALIGN=JUSTIFY>\n");
while (1) {
if (fp == NULL)
serv_gets(buf);
if (fp != NULL) {
- if (fgets(buf, 256, fp) == NULL)
+ if (fgets(buf, SIZ, fp) == NULL)
strcpy(buf, "000");
buf[strlen(buf) - 1] = 0;
}
*/
void text_to_server(char *ptr)
{
- char buf[256];
+ char buf[SIZ];
int ch, a, pos;
pos = 0;
*/
void server_to_text()
{
- char buf[256];
+ char buf[SIZ];
int count = 0;
void display_siteconfig(void)
{
- char buf[256];
+ char buf[SIZ];
int i;
output_headers(1);
void siteconfig(void)
{
- char buf[256];
+ char buf[SIZ];
if (strcasecmp(bstr("sc"), "OK")) {
display_main_menu();
* back end for print_value_of() ... does a server command
*/
void pvo_do_cmd(char *servcmd) {
- char buf[256];
+ char buf[SIZ];
serv_puts(servcmd);
serv_gets(buf);
void display_edit(char *description, char *check_cmd,
char *read_cmd, char *save_cmd)
{
- char buf[256];
+ char buf[SIZ];
serv_puts(check_cmd);
serv_gets(buf);
*/
void save_edit(char *description, char *enter_cmd, int regoto)
{
- char buf[256];
+ char buf[SIZ];
if (strcmp(bstr("sc"), "Save")) {
output_headers(1);
*/
void serv_puts(char *string)
{
- char buf[256];
+ char buf[SIZ];
sprintf(buf, "%s\n", string);
serv_write(buf, strlen(buf));
void serv_printf(const char *format,...)
{
va_list arg_ptr;
- char buf[256];
+ char buf[SIZ];
va_start(arg_ptr, format);
vsprintf(buf, format, arg_ptr);
}
+
/*
- * num_parms() - discover number of parameters...
+ * num_tokens() - discover number of parameters/tokens in a string
*/
-int num_parms(char *source)
-{
+int num_tokens(char *source, char tok) {
int a;
int count = 1;
- for (a = 0; a < strlen(source); ++a)
- if (source[a] == '|')
- ++count;
- return (count);
+ if (source == NULL) return(0);
+ for (a=0; a<strlen(source); ++a) {
+ if (source[a]==tok) ++count;
+ }
+ return(count);
}
/*
- * extract() - extract a parameter from a series of "|" separated...
+ * extract_token() - a smarter string tokenizer
*/
-void extract(char *dest, char *source, int parmnum)
+void extract_token(char *dest, char *source, int parmnum, char separator)
{
- char buf[256];
- int count = 0;
- int n;
+ int i;
+ int len;
+ int curr_parm;
- if (strlen(source) == 0) {
- strcpy(dest, "");
- return;
- }
- n = num_parms(source);
+ strcpy(dest,"");
+ len = 0;
+ curr_parm = 0;
- if (parmnum >= n) {
- strcpy(dest, "");
+ if (strlen(source)==0) {
return;
+ }
+
+ for (i=0; i<strlen(source); ++i) {
+ if (source[i]==separator) {
+ ++curr_parm;
+ }
+ else if (curr_parm == parmnum) {
+ dest[len+1] = 0;
+ dest[len++] = source[i];
+ }
}
- strcpy(buf, source);
- if ((parmnum == 0) && (n == 1)) {
- strcpy(dest, buf);
- for (n = 0; n < strlen(dest); ++n)
- if (dest[n] == '|')
- dest[n] = 0;
+}
+
+
+
+/*
+ * remove_token() - a tokenizer that kills, maims, and destroys
+ */
+void remove_token(char *source, int parmnum, char separator)
+{
+ int i;
+ int len;
+ int curr_parm;
+ int start, end;
+
+ len = 0;
+ curr_parm = 0;
+ start = (-1);
+ end = (-1);
+
+ if (strlen(source)==0) {
return;
+ }
+
+ for (i=0; i<strlen(source); ++i) {
+ if ( (start < 0) && (curr_parm == parmnum) ) {
+ start = i;
+ }
+
+ if ( (end < 0) && (curr_parm == (parmnum+1)) ) {
+ end = i;
+ }
+
+ if (source[i]==separator) {
+ ++curr_parm;
+ }
}
- while (count++ < parmnum)
- do {
- strcpy(buf, &buf[1]);
- } while ((strlen(buf) > 0) && (buf[0] != '|'));
- if (buf[0] == '|')
- strcpy(buf, &buf[1]);
- for (count = 0; count < strlen(buf); ++count)
- if (buf[count] == '|')
- buf[count] = 0;
- strcpy(dest, buf);
+
+ if (end < 0) end = strlen(source);
+
+ printf("%d .. %d\n", start, end);
+
+ strcpy(&source[start], &source[end]);
}
+
+
+
/*
* extract_int() - extract an int parm w/o supplying a buffer
*/
int extract_int(char *source, int parmnum)
{
- char buf[256];
-
- extract(buf, source, parmnum);
- return (atoi(buf));
+ char buf[SIZ];
+
+ extract_token(buf, source, parmnum, '|');
+ return(atoi(buf));
}
/*
*/
long extract_long(char *source, long int parmnum)
{
- char buf[256];
-
- extract(buf, source, parmnum);
- return (atol(buf));
+ char buf[SIZ];
+
+ extract_token(buf, source, parmnum, '|');
+ return(atol(buf));
}
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
* check for the presence of a character within a string (returns count)
*/
*/
void userlist(void)
{
- char buf[256];
- char fl[256];
+ char buf[SIZ];
+ char fl[SIZ];
struct tm *tmbuf;
long lc;
struct namelist *bio = NULL;
*/
void showuser(void)
{
- char who[256];
- char buf[256];
+ char who[SIZ];
+ char buf[SIZ];
int have_pic;
output_headers(1);
void addurls(char *url)
{
char *up, *ptr;
- char buf[256];
+ char buf[SIZ];
int a, b;
struct urlcontent *u;
*/
void output_headers(int controlcode)
{
- char cookie[256];
+ char cookie[SIZ];
int print_standard_html_head = 0;
int refresh30 = 0;
int suppress_check = 0;
- char httpnow[256];
+ char httpnow[SIZ];
static int pageseq = 0;
print_standard_html_head = controlcode & 0x03;
void check_for_express_messages()
{
- char buf[256];
+ char buf[SIZ];
serv_puts("NOOP");
serv_gets(buf);
*/
void output_image()
{
- char buf[256];
+ char buf[SIZ];
char xferbuf[4096];
off_t bytes;
off_t thisblock;
*/
void output_mimepart()
{
- char buf[256];
+ char buf[SIZ];
char xferbuf[4096];
off_t bytes;
off_t thisblock;
off_t accomplished = 0L;
- char content_type[256];
+ char content_type[SIZ];
serv_printf("OPNA %s|%s", bstr("msgnum"), bstr("partnum"));
serv_gets(buf);
*/
void session_loop(struct httprequest *req)
{
- char cmd[256];
- char action[256];
- char buf[256];
+ char cmd[SIZ];
+ char action[SIZ];
+ char buf[SIZ];
int a, b;
int ContentLength = 0;
int BytesRead;
char *content;
char *content_end;
struct httprequest *hptr;
- char browser_host[256];
- char user_agent[256];
+ char browser_host[SIZ];
+ char user_agent[SIZ];
/* We stuff these with the values coming from the client cookies,
* so we can use them to reconnect a timed out session if we have to.
*/
- char c_host[256];
- char c_port[256];
- char c_username[256];
- char c_password[256];
- char c_roomname[256];
- char cookie[256];
+ char c_host[SIZ];
+ char c_port[SIZ];
+ char c_username[SIZ];
+ char c_password[SIZ];
+ char c_roomname[SIZ];
+ char cookie[SIZ];
strcpy(c_host, defaulthost);
strcpy(c_port, defaultport);
/* $Id$ */
+#define SIZ 4096 /* generic buffer size */
+
#define TRACE fprintf(stderr, "Checkpoint: %s, %d\n", __FILE__, __LINE__)
#define SLEEPING 180 /* TCP connection timeout */
struct httprequest {
struct httprequest *next;
- char line[256];
+ char line[SIZ];
};
struct urlcontent {
int serv_rev_level;
char serv_bbs_city[64];
char serv_sysadm[64];
- char serv_moreprompt[256];
+ char serv_moreprompt[SIZ];
int serv_ok_floors;
};
struct wcsession {
struct wcsession *next; /* Linked list */
int wc_session; /* WebCit session ID */
- char wc_username[256];
- char wc_password[256];
- char wc_roomname[256];
+ char wc_username[SIZ];
+ char wc_password[SIZ];
+ char wc_roomname[SIZ];
int connected;
int logged_in;
int axlevel;
struct wcsubst *vars;
};
-
+#define extract(dest,source,parmnum) extract_token(dest,source,parmnum,'|')
+#define num_parms(source) num_tokens(source, '|')
#define WC ((struct wcsession *)pthread_getspecific(MyConKey))
extern pthread_key_t MyConKey;
struct serv_info serv_info;
-extern char floorlist[128][256];
+extern char floorlist[128][SIZ];
extern char *axdefs[];
extern char *defaulthost, *defaultport;
extern char *server_cookie;
void urlescputs(char *);
void output_headers(int);
void wprintf(const char *format,...);
-void extract(char *dest, char *source, int parmnum);
-int extract_int(char *source, int parmnum);
void output_static(char *what);
void stresc(char *target, char *strbuf, int nbsp);
void escputs(char *strbuf);
void url(char *buf);
void escputs1(char *strbuf, int nbsp);
long extract_long(char *source, long int parmnum);
+int extract_int(char *source, int parmnum);
void dump_vars(void);
void embed_main_menu(void);
void serv_read(char *buf, int bytes);
void do_template(void *templatename);
int lingering_close(int fd);
char *memreadline(char *start, char *buf, int maxlen);
+int num_tokens (char *source, char tok);
+void extract_token(char *dest, char *source, int parmnum, char separator);
+void remove_token(char *source, int parmnum, char separator);
freopen(tracefile, "r", stdin);
break;
case 'c':
- server_cookie = malloc(256);
+ server_cookie = malloc(SIZ);
if (server_cookie != NULL) {
strcpy(server_cookie, "Set-cookie: wcserver=");
if (gethostname(
*/
void whobbs(void)
{
- char buf[256], sess, user[256], room[256], host[256],
- realroom[256], realhost[256];
+ char buf[SIZ], sess, user[SIZ], room[SIZ], host[SIZ],
+ realroom[SIZ], realhost[SIZ];
output_headers(7);
void terminate_session(void)
{
- char buf[256];
+ char buf[SIZ];
serv_printf("TERM %s", bstr("which_session"));
serv_gets(buf);
*/
void edit_me(void)
{
- char buf[256];
+ char buf[SIZ];
if (!strcasecmp(bstr("sc"), "Change room name")) {
serv_printf("RCHG %s", bstr("fake_roomname"));