* Brought over the newer string tokenizer from Citadel
authorArt Cancro <ajc@citadel.org>
Sun, 18 Nov 2001 01:41:09 +0000 (01:41 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 18 Nov 2001 01:41:09 +0000 (01:41 +0000)
* Upgraded all the generic string buffers to 4096 bytes, using the Citadel
  server's convention of #define SIZ 4096

21 files changed:
webcit/ChangeLog
webcit/auth.c
webcit/context_loop.c
webcit/cookie_conversion.c
webcit/graphics.c
webcit/mainmenu.c
webcit/messages.c
webcit/netconf.c
webcit/paging.c
webcit/roomops.c
webcit/serv_func.c
webcit/siteconfig.c
webcit/subst.c
webcit/sysmsgs.c
webcit/tcp_sockets.c
webcit/tools.c
webcit/userlist.c
webcit/webcit.c
webcit/webcit.h
webcit/webserver.c
webcit/who.c

index 5a2c0c853c74a50d5d41afc3d4c994b5308bee53..2221f1066399c69bb953c3c2ead40250464dca33 100644 (file)
@@ -1,4 +1,9 @@
 $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
 
@@ -631,4 +636,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index c7ab697b1c8d0f4cfbf77ec945daaf08a156e40e..a5177ced17e810528d8593876ac85550c0e2fb1c 100644 (file)
@@ -28,7 +28,6 @@
 #include <signal.h>
 #include "webcit.h"
 
-
 char *axdefs[] =
 {
        "Deleted",
@@ -45,7 +44,7 @@ char *axdefs[] =
  */
 void display_login(char *mesg)
 {
-       char buf[256];
+       char buf[SIZ];
 
        output_headers(3);
 
@@ -84,7 +83,7 @@ void become_logged_in(char *user, char *pass, char *serv_response)
 
 void do_login(void)
 {
-       char buf[256];
+       char buf[SIZ];
        int need_regi = 0;
 
 
@@ -159,7 +158,7 @@ void end_webcit_session(void) {
 
 void do_logout(void)
 {
-       char buf[256];
+       char buf[SIZ];
 
        strcpy(WC->wc_username, "");
        strcpy(WC->wc_password, "");
@@ -190,9 +189,9 @@ void do_logout(void)
  */
 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);
@@ -270,7 +269,7 @@ void validate(void)
  */
 void display_reg(int during_login)
 {
-       char buf[256];
+       char buf[SIZ];
        int a;
 
        output_headers(1);
@@ -341,7 +340,7 @@ void display_reg(int during_login)
  */
 void register_user(void)
 {
-       char buf[256];
+       char buf[SIZ];
 
        if (strcmp(bstr("action"), "Register")) {
                display_error("Cancelled.  Registration was not saved.");
@@ -378,7 +377,7 @@ void register_user(void)
  */
 void display_changepw(void)
 {
-       char buf[256];
+       char buf[SIZ];
 
        output_headers(1);
 
@@ -410,7 +409,7 @@ void display_changepw(void)
  */
 void changepw(void)
 {
-       char buf[256];
+       char buf[SIZ];
        char newpass1[32], newpass2[32];
 
        if (strcmp(bstr("action"), "Change")) {
index 83448ffbe42363293e67ed85343ab3c5765621f2..03ec66e1a00a563360aed972325801304d42c927 100644 (file)
@@ -157,7 +157,7 @@ int req_gets(int sock, char *buf, char *hold)
 
 int lingering_close(int fd)
 {
-       char buf[256];
+       char buf[SIZ];
        int i;
        fd_set set;
        struct timeval tv, start;
@@ -222,7 +222,7 @@ void context_loop(int sock)
        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;
index 22bdb58a0d9e799b4a5155eb3856878ddb8a0a63..dd39f1bb10ca259fbb79fa859ba989693abbb63d 100644 (file)
@@ -24,7 +24,7 @@
 #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
@@ -157,7 +157,7 @@ void decode_base64(char *dest, char *source)
  */
 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);
@@ -169,7 +169,7 @@ void stuff_to_cookie(char *cookie, int session, char *user, char *pass, char *ro
  */
 void cookie_to_stuff(char *cookie, int *session, char *user, char *pass, char *room)
 {
-       char buf[256];
+       char buf[SIZ];
 
        decode_base64(buf, cookie);
 
index d2fa9994caa1a91eb8431cc1ceed2c6cfe03c576..6593d9a057278f1d5cf16370ea75beb67164f07b 100644 (file)
@@ -22,7 +22,7 @@
 
 void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
 {
-       char buf[256];
+       char buf[SIZ];
 
        serv_puts(check_cmd);
        serv_gets(buf);
@@ -57,7 +57,7 @@ void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
 
 void do_graphics_upload(char *upl_cmd)
 {
-       char buf[256];
+       char buf[SIZ];
        int bytes_remaining;
        int pos = 0;
        int thisblock;
index 5623d2aeb7ae445803bb6c123aedc8ea4be93ff3..5dce575abb28a865ebf9642eedec065e66bafeea 100644 (file)
@@ -225,8 +225,8 @@ void display_generic(void)
 
 void do_generic(void)
 {
-       char buf[256];
-       char gcontent[256];
+       char buf[SIZ];
+       char gcontent[SIZ];
        char *junk;
        size_t len;
 
index 55ad24e758a3eea9389d13591012d0bd3c061660..4bc642ba9201092eb63e2d9ad239f0b303c4f89a 100644 (file)
@@ -37,7 +37,7 @@ char buf[];
        int pos;
        int start, end;
        char ench;
-       char urlbuf[256];
+       char urlbuf[SIZ];
        char outbuf[1024];
 
        start = (-1);
@@ -82,19 +82,19 @@ char buf[];
 
 
 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;
@@ -319,7 +319,7 @@ void read_message(long msgnum, int is_summary) {
 int load_msg_ptrs(servcmd)
 char *servcmd;
 {
-       char buf[256];
+       char buf[SIZ];
        int nummsgs;
 
        nummsgs = 0;
@@ -342,7 +342,7 @@ char *servcmd;
  */
 void readloop(char *oper)
 {
-       char cmd[256];
+       char cmd[SIZ];
        int a, b;
        int nummsgs;
        long startmsg;
@@ -470,7 +470,7 @@ DONE:       wDumpContent(1);
  */
 void post_message(void)
 {
-       char buf[256];
+       char buf[SIZ];
        static long dont_post = (-1L);
 
        output_headers(1);
@@ -533,7 +533,7 @@ void prompt_for_recipient()
  */
 void display_enter(void)
 {
-       char buf[256];
+       char buf[SIZ];
        long now;
        struct tm *tm;
 
@@ -599,7 +599,7 @@ DONE:       wDumpContent(1);
 void delete_msg(void)
 {
        long msgid;
-       char buf[256];
+       char buf[SIZ];
 
        msgid = atol(bstr("msgid"));
 
@@ -622,8 +622,8 @@ void delete_msg(void)
 void confirm_move_msg(void)
 {
        long msgid;
-       char buf[256];
-       char targ[256];
+       char buf[SIZ];
+       char targ[SIZ];
 
        msgid = atol(bstr("msgid"));
 
@@ -670,7 +670,7 @@ void confirm_move_msg(void)
 void move_msg(void)
 {
        long msgid;
-       char buf[256];
+       char buf[SIZ];
 
        msgid = atol(bstr("msgid"));
 
index ee2095031028c24f7700ec29c4bb12a9654bb78b..3a3d80e8c2df246a8a5654acf7294bbbc4d716c2 100644 (file)
 
 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"));
 
@@ -82,8 +82,8 @@ void display_edit_node(void)
 
 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>");
@@ -125,8 +125,8 @@ void display_netconf(void)
 
 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>");
@@ -153,7 +153,7 @@ void display_confirm_unshare(void)
 
 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>");
@@ -175,8 +175,8 @@ void display_confirm_delete_node(void)
 
 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);
@@ -195,9 +195,9 @@ void delete_node(void)
 
 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"));
@@ -242,9 +242,9 @@ void display_add_node(void)
 
 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"));
@@ -268,9 +268,9 @@ void add_node(void)
 
 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;
@@ -342,10 +342,10 @@ void display_share(void)
 
 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"));
index 797ae02191d30706bd103cfaf857084fec81112b..9b506109ff9b35e151843f65623d26970bf23f70 100644 (file)
@@ -27,7 +27,7 @@
  */
 void display_page(void)
 {
-       char recp[256];
+       char recp[SIZ];
 
        strcpy(recp, bstr("recp"));
 
@@ -69,9 +69,9 @@ void display_page(void)
  */
 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);
 
@@ -135,8 +135,8 @@ void do_chat(void)
  */
 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);
index f249351a6d4fbbcc01894b4cb968ee8233c32e93..1a3c2960c9d42f403e1d1a0d0d45b7b3d72d2689 100644 (file)
@@ -28,7 +28,7 @@
 
 
 
-char floorlist[128][256];
+char floorlist[128][SIZ];
 
 
 /*
@@ -37,7 +37,7 @@ char floorlist[128][256];
 void load_floorlist(void)
 {
        int a;
-       char buf[256];
+       char buf[SIZ];
 
        for (a = 0; a < 128; ++a)
                floorlist[a][0] = 0;
@@ -150,7 +150,7 @@ int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
  */
 void listrms(char *variety)
 {
-       char buf[256];
+       char buf[SIZ];
        int num_rooms = 0;
 
        struct roomlisting *rl = NULL;
@@ -220,7 +220,7 @@ void listrms(char *variety)
 void list_all_rooms_by_floor(void)
 {
        int a;
-       char buf[256];
+       char buf[SIZ];
 
        load_floorlist();
 
@@ -287,7 +287,7 @@ void zapped_list(void)
  */
 void readinfo(void)
 {
-       char buf[256];
+       char buf[SIZ];
 
        serv_puts("RINF");
        serv_gets(buf);
@@ -307,7 +307,7 @@ void readinfo(void)
  * another room.
  */
 void embed_room_graphic(void) {
-       char buf[256];
+       char buf[SIZ];
 
        serv_puts("OIMG _roompic_");
        serv_gets(buf);
@@ -339,7 +339,7 @@ void embed_newmail_button(void) {
 
 
 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.
@@ -377,7 +377,7 @@ void embed_room_banner(char *got) {
  */
 void gotoroom(char *gname, int display_name)
 {
-       char buf[256];
+       char buf[SIZ];
        static long ls = (-1L);
 
 
@@ -486,7 +486,7 @@ char *pop_march(int desired_floor)
  */
 void gotonext(void)
 {
-       char buf[256];
+       char buf[SIZ];
        struct march *mptr, *mptr2;
        char next_room[32];
 
@@ -556,7 +556,7 @@ void smart_goto(char *next_room) {
  */
 void slrp_highest(void)
 {
-       char buf[256];
+       char buf[SIZ];
 
        /* set pointer */
        serv_puts("SLRP HIGHEST");
@@ -573,7 +573,7 @@ void slrp_highest(void)
  */
 void ungoto(void)
 {
-       char buf[256];
+       char buf[SIZ];
 
        if (!strcmp(WC->ugname, "")) {
                smart_goto(WC->wc_roomname);
@@ -599,7 +599,7 @@ void ungoto(void)
  */
 void display_editroom(void)
 {
-       char buf[256];
+       char buf[SIZ];
        char er_name[20];
        char er_password[10];
        char er_dirname[15];
@@ -781,7 +781,7 @@ void display_editroom(void)
  */
 void editroom(void)
 {
-       char buf[256];
+       char buf[SIZ];
        char er_name[20];
        char er_password[10];
        char er_dirname[15];
@@ -927,7 +927,7 @@ void editroom(void)
  */
 void display_whok(void)
 {
-        char buf[256], room[256], username[256];
+        char buf[SIZ], room[SIZ], username[SIZ];
 
         serv_puts("GETR");
         serv_gets(buf);
@@ -1003,7 +1003,7 @@ void display_whok(void)
 void display_entroom(void)
 {
        int i;
-       char buf[256];
+       char buf[SIZ];
 
        serv_puts("CRE8 0");
        serv_gets(buf);
@@ -1074,7 +1074,7 @@ void display_entroom(void)
  */
 void entroom(void)
 {
-       char buf[256];
+       char buf[SIZ];
        char er_name[20];
        char er_type[20];
        char er_password[10];
@@ -1156,7 +1156,7 @@ void display_private(char *rname, int req_pass)
 void goto_private(void)
 {
        char hold_rm[32];
-       char buf[256];
+       char buf[SIZ];
 
        if (strcasecmp(bstr("sc"), "OK")) {
                display_main_menu();
@@ -1214,8 +1214,8 @@ void display_zap(void)
  */
 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
@@ -1248,7 +1248,7 @@ void zap(void)
  */
 void confirm_delete_room(void)
 {
-       char buf[256];
+       char buf[SIZ];
 
        serv_puts("KILL 0");
        serv_gets(buf);
@@ -1282,8 +1282,8 @@ void confirm_delete_room(void)
  */
 void delete_room(void)
 {
-       char buf[256];
-       char sc[256];
+       char buf[SIZ];
+       char sc[SIZ];
 
        strcpy(sc, bstr("sc"));
 
index 38b4fdd80c18069c9f8954a9c9426b793985b92e..be9e41323e8f132ff8e61afece156853c488c498 100644 (file)
@@ -36,7 +36,7 @@ struct serv_info serv_info;
  */
 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",
@@ -100,14 +100,14 @@ void fmout(FILE * fp)
 
        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;
                }
@@ -153,7 +153,7 @@ void fmout(FILE * fp)
  */
 void text_to_server(char *ptr)
 {
-       char buf[256];
+       char buf[SIZ];
        int ch, a, pos;
 
        pos = 0;
@@ -197,7 +197,7 @@ void text_to_server(char *ptr)
  */
 void server_to_text()
 {
-       char buf[256];
+       char buf[SIZ];
 
        int count = 0;
 
index 50bf0a4e0f974c287fadf29d31f8542d0905dec4..5f3ba114447a1d9c04de7c6f733117858d718fb7 100644 (file)
@@ -31,7 +31,7 @@
 
 void display_siteconfig(void)
 {
-       char buf[256];
+       char buf[SIZ];
        int i;
 
        output_headers(1);
@@ -208,7 +208,7 @@ void display_siteconfig(void)
 
 void siteconfig(void)
 {
-       char buf[256];
+       char buf[SIZ];
 
        if (strcasecmp(bstr("sc"), "OK")) {
                display_main_menu();
index 6e348dae33e41c1c522a514522d10fec72ba470e..23d83386edc6e58a5fd62c72edcba74efe28b2eb 100644 (file)
@@ -95,7 +95,7 @@ void svcallback(char *keyname, void (*fcn_ptr)() )
  * 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);
index 5934e3db16b5bff84161152656109aa6ec7de023..87604bdd3562ceb777beb80513d1d36c2ec40264 100644 (file)
@@ -34,7 +34,7 @@
 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);
@@ -76,7 +76,7 @@ void display_edit(char *description, char *check_cmd,
  */
 void save_edit(char *description, char *enter_cmd, int regoto)
 {
-       char buf[256];
+       char buf[SIZ];
 
        if (strcmp(bstr("sc"), "Save")) {
                output_headers(1);
index 9501a79fb9b7ff88e45e064eb98e314fa9c109f0..d457e71c6a18cb693521f23a54bc4835c5a719d7 100644 (file)
@@ -198,7 +198,7 @@ void serv_write(char *buf, int nbytes)
  */
 void serv_puts(char *string)
 {
-       char buf[256];
+       char buf[SIZ];
 
        sprintf(buf, "%s\n", string);
        serv_write(buf, strlen(buf));
@@ -211,7 +211,7 @@ void serv_puts(char *string)
 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);
index 0bf0dcc24fe95348908b5d28c378a023d08012ac..d8512115037dfbf4a8e4bfb4ea364a6a12033eba 100644 (file)
@@ -49,68 +49,103 @@ char *safestrncpy(char *dest, const char *src, size_t n)
 }
 
 
+
 /*
- * 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));
 }
 
 /*
@@ -118,13 +153,26 @@ 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));
+       char buf[SIZ];
+       
+       extract_token(buf, source, parmnum, '|');
+       return(atol(buf));
 }
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
 /*
  * check for the presence of a character within a string (returns count)
  */
index bcc96edb0d819aabb08b87c812548f6889efa6c9..8fd97db3538772189e4f33c83c35cfe44b58d9e1 100644 (file)
@@ -32,8 +32,8 @@ struct namelist {
  */
 void userlist(void)
 {
-       char buf[256];
-       char fl[256];
+       char buf[SIZ];
+       char fl[SIZ];
        struct tm *tmbuf;
        long lc;
        struct namelist *bio = NULL;
@@ -109,8 +109,8 @@ void userlist(void)
  */
 void showuser(void)
 {
-       char who[256];
-       char buf[256];
+       char who[SIZ];
+       char buf[SIZ];
        int have_pic;
 
        output_headers(1);
index 243edf6c8b332775ffb375523a98c79bd98e8d1f..6e884e88a8002e7469c67778bf9c6a45db982a00 100644 (file)
@@ -65,7 +65,7 @@ void unescape_input(char *buf)
 void addurls(char *url)
 {
        char *up, *ptr;
-       char buf[256];
+       char buf[SIZ];
        int a, b;
        struct urlcontent *u;
 
@@ -287,11 +287,11 @@ void urlescputs(char *strbuf)
  */
 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;
@@ -389,7 +389,7 @@ void http_redirect(char *whichpage) {
 
 void check_for_express_messages()
 {
-       char buf[256];
+       char buf[SIZ];
 
        serv_puts("NOOP");
        serv_gets(buf);
@@ -451,7 +451,7 @@ void output_static(char *what)
  */
 void output_image()
 {
-       char buf[256];
+       char buf[SIZ];
        char xferbuf[4096];
        off_t bytes;
        off_t thisblock;
@@ -501,12 +501,12 @@ void output_image()
  */
 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);
@@ -648,9 +648,9 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
  */
 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;
@@ -658,18 +658,18 @@ void session_loop(struct httprequest *req)
        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);
index 5bdbd4158f4a2d8c45bed6f45393e669b51ccb8e..b0e25f4f8beec63dded2fa941b6dbdafaed3da4d 100644 (file)
@@ -1,5 +1,7 @@
 /* $Id$ */
 
+#define SIZ                    4096            /* generic buffer size */
+
 #define TRACE fprintf(stderr, "Checkpoint: %s, %d\n", __FILE__, __LINE__)
 
 #define SLEEPING               180             /* TCP connection timeout */
@@ -40,7 +42,7 @@
 
 struct httprequest {
        struct httprequest *next;
-       char line[256];
+       char line[SIZ];
 };
 
 struct urlcontent {
@@ -58,7 +60,7 @@ struct serv_info {
        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;
 };
 
@@ -117,9 +119,9 @@ enum {
 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;
@@ -147,13 +149,14 @@ struct wcsession {
        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;
@@ -191,14 +194,13 @@ char *urlesc(char *);
 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);
@@ -281,3 +283,6 @@ void svcallback(char *keyname, void (*fcn_ptr)() );
 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);
index 2f05519fab730aa8fdb63ddfe2ad612fee1e551d..266cd692998c77e3b88cf1700b943888fd38c329 100644 (file)
@@ -240,7 +240,7 @@ int main(int argc, char **argv)
                        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(
index 04c39bf1921d0dcccc41077d3229d59bd62e6f14..c2690f936dcb5a5e1f40ffacfd080de8a7da12ec 100644 (file)
@@ -31,8 +31,8 @@
  */
 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);
 
@@ -126,7 +126,7 @@ void whobbs(void)
 
 void terminate_session(void)
 {
-       char buf[256];
+       char buf[SIZ];
 
        serv_printf("TERM %s", bstr("which_session"));
        serv_gets(buf);
@@ -139,7 +139,7 @@ void terminate_session(void)
  */
 void edit_me(void)
 {
-       char buf[256];
+       char buf[SIZ];
 
        if (!strcasecmp(bstr("sc"), "Change room name")) {
                serv_printf("RCHG %s", bstr("fake_roomname"));