$Log$
+Revision 610.1 2005/04/08 19:36:56 ajc
+* Moved to the new string tokenizer API
+
Revision 610.0 2005/04/04 17:50:04 ajc
* THIS IS 6.10 (unfinished first time install wizard has been disabled)
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
+
char buf[SIZ];
WC->logged_in = 1;
- extract(WC->wc_username, &serv_response[4], 0);
+ extract_token(WC->wc_username, &serv_response[4], 0, '|', sizeof WC->wc_username);
strcpy(WC->wc_password, pass);
WC->axlevel = extract_int(&serv_response[4], 1);
if (WC->axlevel >= 6) {
WC->new_mail = extract_int(&buf[4], 0);
WC->need_regi = extract_int(&buf[4], 1);
WC->need_vali = extract_int(&buf[4], 2);
- extract(WC->cs_inet_email, &buf[4], 3);
+ extract_token(WC->cs_inet_email, &buf[4], 3, '|', sizeof WC->cs_inet_email);
}
}
void do_welcome(void)
{
char buf[SIZ];
+#ifdef XXX_NOT_FINISHED_YET_XXX
FILE *fp;
int i;
-#ifdef XXX_NOT_FINISHED_YET_XXX
/*
* See if we have to run the first-time setup wizard
*/
/*
* Go to the user's preferred start page
*/
- get_preference("startpage", buf);
+ get_preference("startpage", buf, sizeof buf);
if (strlen(buf)==0) {
strcpy(buf, "/dotskip&room=_BASEROOM_");
set_preference("startpage", buf);
serv_gets(buf);
if (buf[0] == '1') {
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(conflict_name, buf, 3);
+ extract_token(conflict_name, buf, 3, '|', sizeof conflict_name);
is_update = extract_int(buf, 4);
wprintf("<TR><TD><B><I>%s</I></B></TD>"
"<TD>"
while (serv_gets(buf), strcmp(buf, "000")) {
if (!strncasecmp(buf, "part=", 5)) {
- extract(mime_filename, &buf[5], 1);
- extract(mime_partnum, &buf[5], 2);
- extract(mime_disposition, &buf[5], 3);
- extract(mime_content_type, &buf[5], 4);
+ extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
+ extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
+ extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
+ extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
mime_length = extract_int(&buf[5], 5);
if (!strcasecmp(mime_content_type, "text/calendar")) {
char buf[SIZ];
char *fb;
- extract_token(who, req, 1, ' ');
+ extract_token(who, req, 1, ' ', sizeof who);
if (!strncasecmp(who, "/freebusy/", 10)) {
strcpy(who, &who[10]);
}
*/
if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
cookie_to_stuff(&buf[15], &desired_session,
- NULL, NULL, NULL);
+ NULL, 0, NULL, 0, NULL, 0);
got_cookie = 1;
}
*/
if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
CtdlDecodeBase64(httpauth_string, &buf[21], strlen(&buf[21]));
- extract_token(httpauth_user, httpauth_string, 0, ':');
- extract_token(httpauth_pass, httpauth_string, 1, ':');
+ extract_token(httpauth_user, httpauth_string, 0, ':', sizeof httpauth_user);
+ extract_token(httpauth_pass, httpauth_string, 1, ':', sizeof httpauth_pass);
}
/*
/*
* Extract all that fun stuff out of the cookie.
*/
-void cookie_to_stuff(char *cookie, int *session, char *user, char *pass, char *room)
+void cookie_to_stuff(char *cookie, int *session,
+ char *user, size_t user_len,
+ char *pass, size_t pass_len,
+ char *room, size_t room_len)
{
char buf[SIZ];
int i, len;
if (session != NULL)
*session = extract_int(buf, 0);
if (user != NULL)
- extract(user, buf, 1);
+ extract_token(user, buf, 1, '|', user_len);
if (pass != NULL)
- extract(pass, buf, 2);
+ extract_token(pass, buf, 2, '|', pass_len);
if (room != NULL)
- extract(room, buf, 3);
+ extract_token(room, buf, 3, '|', room_len);
}
/* Now iterate! */
for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
- extract_token(buf, form_attendees, i, '\n');
+ extract_token(buf, form_attendees, i, '\n', sizeof buf);
striplt(buf);
if (strlen(buf) > 0) {
lprintf(9, "Attendee: <%s>\n", buf);
striplt(attendee_string);
foundit = 0;
for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
- extract_token(buf, form_attendees, i, '\n');
+ extract_token(buf, form_attendees, i, '\n', sizeof buf);
striplt(buf);
if (!strcasecmp(buf, attendee_string)) ++foundit;
}
while (serv_gets(buf), strcmp(buf, "000")) {
floornum = extract_int(buf, 0);
- extract(floorname, buf, 1);
+ extract_token(floorname, buf, 1, '|', sizeof floorname);
refcount = extract_int(buf, 2);
wprintf("<TR><TD><TABLE border=0><TR><TD>%d", floornum);
/* Now extract the message euid */
n = num_tokens(dav_pathname, '/');
- extract_token(dav_uid, dav_pathname, n-1, '/');
+ extract_token(dav_uid, dav_pathname, n-1, '/', sizeof dav_uid);
remove_token(dav_pathname, n-1, '/');
/* What's left is the room name. Remove trailing slashes. */
/* Now extract the message euid */
n = num_tokens(dav_pathname, '/');
- extract_token(dav_uid, dav_pathname, n-1, '/');
+ extract_token(dav_uid, dav_pathname, n-1, '/', sizeof dav_uid);
remove_token(dav_pathname, n-1, '/');
/* What's left is the room name. Remove trailing slashes. */
return;
}
- extract_token(dav_method, req->line, 0, ' ');
- extract_token(dav_pathname, req->line, 1, ' ');
+ extract_token(dav_method, req->line, 0, ' ', sizeof dav_method);
+ extract_token(dav_pathname, req->line, 1, ' ', sizeof dav_pathname);
unescape_input(dav_pathname);
/*
serv_gets(buf);
if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
- extract(roomname, buf, 0);
+ extract_token(roomname, buf, 0, '|', sizeof roomname);
view = extract_int(buf, 6);
/*
/* Now extract the message euid */
n = num_tokens(dav_pathname, '/');
- extract_token(dav_uid, dav_pathname, n-1, '/');
+ extract_token(dav_uid, dav_pathname, n-1, '/', sizeof dav_uid);
remove_token(dav_pathname, n-1, '/');
/* What's left is the room name. Remove trailing slashes. */
/*
*/
- get_preference("iconbar", iconbar);
+ get_preference("iconbar", iconbar, sizeof iconbar);
for (i=0; i<num_tokens(iconbar, ','); ++i) {
- extract_token(buf, iconbar, i, ',');
- extract_token(key, buf, 0, '=');
- extract_token(value, buf, 1, '=');
+ extract_token(buf, iconbar, i, ',', sizeof buf);
+ extract_token(key, buf, 0, '=', sizeof key);
+ extract_token(value, buf, 1, '=', sizeof value);
if (!strcasecmp(key, "ib_displayas")) ib_displayas = atoi(value);
if (!strcasecmp(key, "ib_logo")) ib_logo = atoi(value);
/*
*/
- get_preference("iconbar", iconbar);
+ get_preference("iconbar", iconbar, sizeof iconbar);
for (i=0; i<num_tokens(iconbar, ','); ++i) {
- extract_token(buf, iconbar, i, ',');
- extract_token(key, buf, 0, '=');
- extract_token(value, buf, 1, '=');
+ extract_token(buf, iconbar, i, ',', sizeof buf);
+ extract_token(key, buf, 0, '=', sizeof key);
+ extract_token(value, buf, 1, '=', sizeof value);
if (!strcasecmp(key, "ib_displayas")) ib_displayas = atoi(value);
if (!strcasecmp(key, "ib_logo")) ib_logo = atoi(value);
serv_gets(buf);
if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
- extract(ename, buf, 0);
- extract(etype, buf, 1);
+ extract_token(ename, buf, 0, '|', sizeof ename);
+ extract_token(etype, buf, 1, '|', sizeof etype);
which = (-1);
for (i=0; i<ic_max; ++i) {
if (!strcasecmp(etype, ic_keyword[i])) {
if (strlen(ic_spec[which]) > 0) {
for (i=0; i<num_tokens(ic_spec[which], '\n'); ++i) {
wprintf("<TR><TD ALIGN=LEFT>");
- extract_token(buf, ic_spec[which], i, '\n');
+ extract_token(buf, ic_spec[which], i, '\n', sizeof buf);
escputs(buf);
wprintf("</TD><TD ALIGN=RIGHT>"
"<A HREF=\"/save_inetconf?oper=delete&ename=");
serv_printf("CONF GETSYS|application/x-citadel-internet-config");
serv_gets(buf);
if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
- extract(ename, buf, 0);
- extract(etype, buf, 1);
+ extract_token(ename, buf, 0, '|', sizeof ename);
+ extract_token(etype, buf, 1, '|', sizeof etype);
if (strlen(buf) == 0) {
/* skip blank lines */
}
serv_gets(buf);
if (buf[0] == '1') {
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(sroom, buf, 0);
+ extract_token(sroom, buf, 0, '|', sizeof sroom);
self = extract_int(buf, 4) & QR2_SELFLIST ;
if (self) {
wprintf("<OPTION VALUE=\"");
if (v->numprops) for (i=0; i<(v->numprops); ++i) {
thisname = strdup(v->prop[i].name);
- extract_token(firsttoken, thisname, 0, ';');
+ extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
for (j=0; j<num_tokens(thisname, ';'); ++j) {
- extract_token(buf, thisname, j, ';');
+ extract_token(buf, thisname, j, ';', sizeof buf);
if (!strcasecmp(buf, "encoding=quoted-printable")) {
is_qp = 1;
remove_token(thisname, j, ';');
if (strlen(phone) > 0) strcat(phone, "<br />");
strcat(phone, thisvalue);
for (j=0; j<num_tokens(thisname, ';'); ++j) {
- extract_token(buf, thisname, j, ';');
+ extract_token(buf, thisname, j, ';', sizeof buf);
if (!strcasecmp(buf, "tel"))
strcat(phone, "");
else if (!strcasecmp(buf, "work"))
if (pass == 2) {
wprintf("<TR><TD>Address:</TD><TD>");
for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
- extract_token(buf, thisvalue, j, ';');
+ extract_token(buf, thisvalue, j, ';', sizeof buf);
if (strlen(buf) > 0) {
escputs(buf);
if (j<3) wprintf("<br />");
}
if (!strncasecmp(buf, "part=", 5)) {
- extract(mime_filename, &buf[5], 1);
- extract(mime_partnum, &buf[5], 2);
- extract(mime_disposition, &buf[5], 3);
- extract(mime_content_type, &buf[5], 4);
+ extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
+ extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
+ extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
+ extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
mime_length = extract_int(&buf[5], 5);
if (!strcasecmp(mime_disposition, "attachment")) {
while (serv_gets(buf), strcmp(buf, "000")) {
if (!strncasecmp(buf, "part=", 5)) {
- extract(mime_filename, &buf[5], 1);
- extract(mime_partnum, &buf[5], 2);
- extract(mime_disposition, &buf[5], 3);
- extract(mime_content_type, &buf[5], 4);
+ extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
+ extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
+ extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
+ extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
mime_length = extract_int(&buf[5], 5);
if (!strcasecmp(mime_content_type, "text/x-vcard")) {
i = num_tokens(namebuf, ' ');
if (i < 2) return;
- extract_token(lastname, namebuf, i-1, ' ');
+ extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
remove_token(namebuf, i-1, ' ');
strcpy(firstname, namebuf);
sprintf(namebuf, "%s; %s", lastname, firstname);
while (serv_gets(buf), strcmp(buf, "000")) {
if (!strncasecmp(buf, "part=", 5)) {
- extract(mime_filename, &buf[5], 1);
- extract(mime_partnum, &buf[5], 2);
- extract(mime_disposition, &buf[5], 3);
- extract(mime_content_type, &buf[5], 4);
+ extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
+ extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
+ extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
+ extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
mime_length = extract_int(&buf[5], 5);
if (!strcasecmp(mime_content_type, "text/x-vcard")) {
serv_gets(buf);
if (buf[0] == '1') {
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(targ, buf, 0);
+ extract_token(targ, buf, 0, '|', sizeof targ);
wprintf("<OPTION>");
escputs(targ);
wprintf("\n");
serv_gets(buf);
if (buf[0] == '1') {
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(cnode, buf, 0);
+ extract_token(cnode, buf, 0, '|', sizeof cnode);
if (strcasecmp(node, cnode)) {
fprintf(fp, "%s\n", buf);
}
serv_gets(buf);
if (buf[0] == '1') {
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(cnode, buf, 0);
- extract(csecret, buf, 1);
- extract(chost, buf, 2);
- extract(cport, buf, 3);
+ extract_token(cnode, buf, 0, '|', sizeof cnode);
+ extract_token(csecret, buf, 1, '|', sizeof csecret);
+ extract_token(chost, buf, 2, '|', sizeof chost);
+ extract_token(cport, buf, 3, '|', sizeof cport);
if (!strcasecmp(node, cnode)) {
wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_node\">\n");
if (buf[0] == '1') {
wprintf("<CENTER><TABLE border=0>\n");
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(node, buf, 0);
+ extract_token(node, buf, 0, '|', sizeof node);
wprintf("<TR><TD><FONT SIZE=+1>");
escputs(node);
wprintf("</FONT></TD>");
serv_gets(buf);
if (buf[0] == '1') {
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(cnode, buf, 0);
+ extract_token(cnode, buf, 0, '|', sizeof cnode);
if (strcasecmp(node, cnode)) {
fprintf(fp, "%s\n", buf);
}
while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
- extract(pagefrom, &buf[4], 3);
+ extract_token(pagefrom, &buf[4], 3, '|', sizeof pagefrom);
wprintf("<table border=1 bgcolor=\"#880000\"><tr><td>");
wprintf("<span class=\"titlebar\">Instant message from ");
);
for (i=0; i<num_tokens(output_data, '\n'); ++i) {
- extract_token(buf, output_data, i, '\n');
- extract_token(cl_user, buf, 0, '|');
- extract_token(cl_text, buf, 1, '|');
+ extract_token(buf, output_data, i, '\n', sizeof buf);
+ extract_token(cl_user, buf, 0, '|', sizeof cl_user);
+ extract_token(cl_text, buf, 1, '|', sizeof cl_text);
if (strcasecmp(cl_text, "NOOP")) {
serv_gets(buf);
}
-void get_preference(char *key, char *value) {
+void get_preference(char *key, char *value, size_t value_len) {
int num_prefs;
int i;
char buf[SIZ];
num_prefs = num_tokens(WC->preferences, '\n');
for (i=0; i<num_prefs; ++i) {
- extract_token(buf, WC->preferences, i, '\n');
- extract_token(thiskey, buf, 0, '|');
+ extract_token(buf, WC->preferences, i, '\n', sizeof buf);
+ extract_token(thiskey, buf, 0, '|', sizeof thiskey);
if (!strcasecmp(thiskey, key)) {
- extract_token(value, buf, 1, '|');
+ extract_token(value, buf, 1, '|', value_len);
}
}
}
num_prefs = num_tokens(WC->preferences, '\n');
for (i=0; i<num_prefs; ++i) {
- extract_token(buf, WC->preferences, i, '\n');
+ extract_token(buf, WC->preferences, i, '\n', sizeof buf);
if (num_tokens(buf, '|') == 2) {
- extract_token(thiskey, buf, 0, '|');
+ extract_token(thiskey, buf, 0, '|', sizeof thiskey);
if (strcasecmp(thiskey, key)) {
if (newprefs == NULL) newprefs = strdup("");
newprefs = realloc(newprefs,
return;
}
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(floorlist[extract_int(buf, 0)], buf, 1);
+ extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', sizeof floorlist[0]);
}
}
while (serv_gets(buf), strcmp(buf, "000")) {
++num_rooms;
rp = malloc(sizeof(struct roomlisting));
- extract(rp->rlname, buf, 0);
+ extract_token(rp->rlname, buf, 0, '|', sizeof rp->rlname);
rp->rlflags = extract_int(buf, 1);
rp->rlfloor = extract_int(buf, 2);
rp->rlorder = extract_int(buf, 3);
if (buf[0] != '2') {
return;
}
- extract(WC->wc_roomname, &buf[4], 0);
+ extract_token(WC->wc_roomname, &buf[4], 0, '|', sizeof WC->wc_roomname);
WC->room_flags = extract_int(&buf[4], 4);
/* highest_msg_read = extract_int(&buf[4],6);
maxmsgnum = extract_int(&buf[4],5);
while (serv_gets(buf), strcmp(buf, "000")) {
mptr = (struct march *) malloc(sizeof(struct march));
mptr->next = NULL;
- extract(mptr->march_name, buf, 0);
+ extract_token(mptr->march_name, buf, 0, '|', sizeof mptr->march_name);
mptr->march_floor = extract_int(buf, 2);
mptr->march_order = extract_int(buf, 3);
if (WC->march == NULL) {
serv_gets(buf);
if (buf[0] != '2') return(0);
- extract(name, &buf[4], 0);
- extract(password, &buf[4], 1);
- extract(dirname, &buf[4], 2);
+ extract_token(name, &buf[4], 0, '|', sizeof name);
+ extract_token(password, &buf[4], 1, '|', sizeof password);
+ extract_token(dirname, &buf[4], 2, '|', sizeof dirname);
flags = extract_int(&buf[4], 3);
floor = extract_int(&buf[4], 4);
order = extract_int(&buf[4], 5);
display_main_menu();
return;
}
- extract(er_name, &buf[4], 0);
- extract(er_password, &buf[4], 1);
- extract(er_dirname, &buf[4], 2);
+ extract_token(er_name, &buf[4], 0, '|', sizeof er_name);
+ extract_token(er_password, &buf[4], 1, '|', sizeof er_password);
+ extract_token(er_dirname, &buf[4], 2, '|', sizeof er_dirname);
er_flags = extract_int(&buf[4], 3);
er_floor = extract_int(&buf[4], 4);
if (buf[0] != '2') {
wprintf("<EM>%s</EM>\n", &buf[4]);
} else {
- extract(er_roomaide, &buf[4], 0);
+ extract_token(er_roomaide, &buf[4], 0, '|', sizeof er_roomaide);
wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
}
serv_puts("CONF getsys|application/x-citadel-ignet-config");
serv_gets(buf);
if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
- extract(node, buf, 0);
+ extract_token(node, buf, 0, '|', sizeof node);
not_shared_with = realloc(not_shared_with,
strlen(not_shared_with) + 32);
strcat(not_shared_with, node);
serv_puts("GNET");
serv_gets(buf);
if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
- extract(cmd, buf, 0);
- extract(node, buf, 1);
- extract(remote_room, buf, 2);
+ extract_token(cmd, buf, 0, '|', sizeof cmd);
+ extract_token(node, buf, 1, '|', sizeof node);
+ extract_token(remote_room, buf, 2, '|', sizeof remote_room);
if (!strcasecmp(cmd, "ignet_push_share")) {
shared_with = realloc(shared_with,
strlen(shared_with) + 32);
}
for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
- extract_token(buf, shared_with, i, '\n');
- extract_token(node, buf, 0, '|');
+ extract_token(buf, shared_with, i, '\n', sizeof buf);
+ extract_token(node, buf, 0, '|', sizeof node);
for (j=0; j<num_tokens(not_shared_with, '\n'); ++j) {
- extract_token(cmd, not_shared_with, j, '\n');
+ extract_token(cmd, not_shared_with, j, '\n', sizeof cmd);
if (!strcasecmp(node, cmd)) {
remove_token(not_shared_with, j, '\n');
}
);
for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
- extract_token(buf, shared_with, i, '\n');
- extract_token(node, buf, 0, '|');
- extract_token(remote_room, buf, 1, '|');
+ extract_token(buf, shared_with, i, '\n', sizeof buf);
+ extract_token(node, buf, 0, '|', sizeof node);
+ extract_token(remote_room, buf, 1, '|', sizeof remote_room);
if (strlen(node) > 0) {
wprintf("<FORM METHOD=\"POST\" "
"ACTION=\"/netedit\">"
);
for (i=0; i<num_tokens(not_shared_with, '\n'); ++i) {
- extract_token(node, not_shared_with, i, '\n');
+ extract_token(node, not_shared_with, i, '\n', sizeof node);
if (strlen(node) > 0) {
wprintf("<FORM METHOD=\"POST\" "
"ACTION=\"/netedit\">"
serv_puts("GNET");
serv_gets(buf);
if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
- extract(cmd, buf, 0);
+ extract_token(cmd, buf, 0, '|', sizeof cmd);
if (!strcasecmp(cmd, "listrecp")) {
- extract(recp, buf, 1);
+ extract_token(recp, buf, 1, '|', sizeof recp);
escputs(recp);
wprintf(" <A HREF=\"/netedit&cmd=remove&line="
serv_puts("GNET");
serv_gets(buf);
if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
- extract(cmd, buf, 0);
+ extract_token(cmd, buf, 0, '|', sizeof cmd);
if (!strcasecmp(cmd, "digestrecp")) {
- extract(recp, buf, 1);
+ extract_token(recp, buf, 1, '|', sizeof recp);
escputs(recp);
wprintf(" <A HREF=\"/netedit&cmd=remove&line="
display_editroom();
return;
}
- extract(er_name, &buf[4], 0);
- extract(er_password, &buf[4], 1);
- extract(er_dirname, &buf[4], 2);
+ extract_token(er_name, &buf[4], 0, '|', sizeof er_name);
+ extract_token(er_password, &buf[4], 1, '|', sizeof er_password);
+ extract_token(er_dirname, &buf[4], 2, '|', sizeof er_dirname);
er_flags = extract_int(&buf[4], 3);
strcpy(er_roomaide, bstr("er_roomaide"));
if (buf[0] != '2') {
strcpy(er_roomaide, "");
} else {
- extract(er_roomaide, &buf[4], 0);
+ extract_token(er_roomaide, &buf[4], 0, '|', sizeof er_roomaide);
}
}
strcpy(buf, bstr("er_name"));
escputs(&buf[4]);
return;
}
- extract(room, &buf[4], 0);
+ extract_token(room, &buf[4], 0, '|', sizeof room);
strcpy(username, bstr("username"));
escputs(&buf[4]);
return;
}
- extract(room, &buf[4], 0);
+ extract_token(room, &buf[4], 0, '|', sizeof room);
wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
serv_gets(buf);
if (buf[0] == '1') {
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(username, buf, 0);
+ extract_token(username, buf, 0, '|', sizeof username);
wprintf("<OPTION>");
escputs(username);
wprintf("\n");
serv_gets(buf);
if (buf[0] != '2') return;
- extract(rm_name, &buf[4], 0);
- extract(rm_pass, &buf[4], 1);
- extract(rm_dir, &buf[4], 2);
+ extract_token(rm_name, &buf[4], 0, '|', sizeof rm_name);
+ extract_token(rm_pass, &buf[4], 1, '|', sizeof rm_pass);
+ extract_token(rm_dir, &buf[4], 2, '|', sizeof rm_dir);
rm_bits1 = extract_int(&buf[4], 3);
rm_floor = extract_int(&buf[4], 4);
rm_listorder = extract_int(&buf[4], 5);
/* This loop works for add *or* remove. Spiffy, eh? */
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(cmpa0, buf, 0);
- extract(cmpa1, buf, 1);
- extract(cmpb0, line, 0);
- extract(cmpb1, line, 1);
+ extract_token(cmpa0, buf, 0, '|', sizeof cmpa0);
+ extract_token(cmpa1, buf, 1, '|', sizeof cmpa1);
+ extract_token(cmpb0, line, 0, '|', sizeof cmpb0);
+ extract_token(cmpb1, line, 1, '|', sizeof cmpb1);
if ( (strcasecmp(cmpa0, cmpb0))
|| (strcasecmp(cmpa1, cmpb1)) ) {
fprintf(fp, "%s\n", buf);
else {
wprintf("<SPAN CLASS=\"roomlist_old\">");
}
- extract(buf, fold[i].name, levels-1);
+ extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
escputs(buf);
wprintf("</SPAN>");
if (levels == 1) {
/* Begin inner box */
- extract(buf, fold[i].name, levels-1);
+ extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
stresc(boxtitle, buf, 1, 0);
svprintf("BOXTITLE", WCS_STRING, boxtitle);
do_template("beginbox");
else {
wprintf("<SPAN CLASS=\"roomlist_old\">");
}
- extract(buf, fold[i].name, levels-1);
+ extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
escputs(buf);
wprintf("</SPAN>");
if (fold[i].selectable) {
alloc_folders * sizeof(struct folder));
}
memset(&fold[max_folders], 0, sizeof(struct folder));
- extract(fold[max_folders].name, buf, 1);
+ extract_token(fold[max_folders].name, buf, 1, '|', sizeof fold[max_folders].name);
++max_folders;
++num_floors;
}
alloc_folders * sizeof(struct folder));
}
memset(&fold[max_folders], 0, sizeof(struct folder));
- extract(fold[max_folders].room, buf, 0);
+ extract_token(fold[max_folders].room, buf, 0, '|', sizeof fold[max_folders].room);
ra_flags = extract_int(buf, 5);
flags = extract_int(buf, 1);
fold[max_folders].floor = extract_int(buf, 2);
}
}
- get_preference("roomlistview", listviewpref);
+ get_preference("roomlistview", listviewpref, sizeof listviewpref);
if ( (strcasecmp(listviewpref, "folders"))
&& (strcasecmp(listviewpref, "table")) ) {
while(fgets(buf, sizeof buf, fp) != NULL) {
if (num_tokens(buf, ':') == 4) {
- extract_token(entry, buf, 0, ':');
- extract_token(levels, buf, 1, ':');
- extract_token(state, buf, 2, ':');
- extract_token(prog, buf, 3, ':'); /* includes 0x0a LF */
+ extract_token(entry, buf, 0, ':', sizeof entry);
+ extract_token(levels, buf, 1, ':', sizeof levels);
+ extract_token(state, buf, 2, ':', sizeof state);
+ extract_token(prog, buf, 3, ':', sizeof prog); /* includes 0x0a LF */
if (!strcmp(entry, which_entry)) {
strcpy(state, new_state);
} else {
while (fgets(buf, sizeof buf, infp) != NULL) {
buf[strlen(buf) - 1] = 0;
- extract_token(entry, buf, 0, ':');
- extract_token(prog, buf, 3, ':');
+ extract_token(entry, buf, 0, ':', sizeof entry);
+ extract_token(prog, buf, 3, ':', sizeof prog);
if (!strncasecmp(prog, looking_for,
strlen(looking_for))) {
++have_entry;
newtCenteredWindow(76, 10, "Question");
form = newtForm(NULL, NULL, 0);
for (i=0; i<num_tokens(question, '\n'); ++i) {
- extract_token(buf, question, i, '\n');
+ extract_token(buf, question, i, '\n', sizeof buf);
newtFormAddComponent(form, newtLabel(1, 1+i, buf));
}
yesbutton = newtButton(10, 5, "Yes");
newtCenteredWindow(76, 10, "WebCit setup");
form = newtForm(NULL, NULL, 0);
for (i=0; i<num_tokens(prompt, '\n'); ++i) {
- extract_token(buf, prompt, i, '\n');
+ extract_token(buf, prompt, i, '\n', sizeof buf);
newtFormAddComponent(form, newtLabel(1, 1+i, buf));
}
newtFormAddComponent(form, newtEntry(1, 8, str, 74, &result,
newtCenteredWindow(76, 10, title);
form = newtForm(NULL, NULL, 0);
for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
- extract_token(buf, msgtext, i, '\n');
+ extract_token(buf, msgtext, i, '\n', sizeof buf);
newtFormAddComponent(form, newtLabel(1, 1+i, buf));
}
newtFormAddComponent(form, newtButton(35, 5, "OK"));
wprintf("<TABLE BORDER=0 WIDTH=100%%>\n");
for (i=0; i<number_of_rooms_to_check; ++i) {
- extract(room, rooms_to_check, i);
+ extract_token(room, rooms_to_check, i, '|', sizeof room);
serv_printf("GOTO %s", room);
serv_gets(buf);
if (buf[0] == '2') {
- extract(room, &buf[4], 0);
+ extract_token(room, &buf[4], 0, '|', sizeof room);
wprintf("<TR><TD><A HREF=\"/dotgoto?room=");
urlescputs(room);
wprintf("\">");
serv_puts("RWHO");
serv_gets(buf);
if (buf[0] == '1') while(serv_gets(buf), strcmp(buf, "000")) {
- extract(user, buf, 1);
+ extract_token(user, buf, 1, '|', sizeof user);
escputs(user);
wprintf("<br />\n");
}
}
/*
- * extract_token() - a smarter string tokenizer
+ * extract_token() - a string tokenizer
*/
-void extract_token(char *dest, char *source, int parmnum, char separator)
+void extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen)
{
- int i;
- int len;
- int curr_parm;
+ char *d; /* dest */
+ const char *s; /* source */
+ int count = 0;
+ int len = 0;
strcpy(dest, "");
- len = 0;
- curr_parm = 0;
- if (strlen(source) == 0) {
- return;
+ /* Locate desired parameter */
+ s = source;
+ while (count < parmnum) {
+ /* End of string, bail! */
+ if (!*s) {
+ s = NULL;
+ break;
+ }
+ if (*s == separator) {
+ count++;
+ }
+ s++;
}
+ if (!s) return; /* Parameter not found */
- 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];
- }
+ for (d = dest; *s && *s != separator && ++len<maxlen; s++, d++) {
+ *d = *s;
}
+ *d = 0;
}
/*
* extract_int() - extract an int parm w/o supplying a buffer
*/
-int extract_int(char *source, int parmnum)
+int extract_int(const char *source, int parmnum)
{
- char buf[SIZ];
-
- extract_token(buf, source, parmnum, '|');
- return (atoi(buf));
+ char buf[32];
+
+ extract_token(buf, source, parmnum, '|', sizeof buf);
+ return(atoi(buf));
}
/*
* extract_long() - extract an long parm w/o supplying a buffer
*/
-long extract_long(char *source, long int parmnum)
+long extract_long(const char *source, int parmnum)
{
- char buf[SIZ];
-
- extract_token(buf, source, parmnum, '|');
- return (atol(buf));
+ char buf[32];
+
+ extract_token(buf, source, parmnum, '|', sizeof buf);
+ return(atol(buf));
}
-
-
-
-
-
-
-
-
-
/*
* check for the presence of a character within a string (returns count)
*/
* Determine whether the specified message number is contained within the
* specified set.
*/
-int is_msg_in_mset(char *mset, long msgnum)
-{
+int is_msg_in_mset(char *mset, long msgnum) {
int num_sets;
int s;
char setstr[SIZ], lostr[SIZ], histr[SIZ]; /* was 1024 */
* Now set it for all specified messages.
*/
num_sets = num_tokens(mset, ',');
- for (s = 0; s < num_sets; ++s) {
- extract_token(setstr, mset, s, ',');
+ for (s=0; s<num_sets; ++s) {
+ extract_token(setstr, mset, s, ',', sizeof setstr);
- extract_token(lostr, setstr, 0, ':');
+ extract_token(lostr, setstr, 0, ':', sizeof lostr);
if (num_tokens(setstr, ':') >= 2) {
- extract_token(histr, setstr, 1, ':');
+ extract_token(histr, setstr, 1, ':', sizeof histr);
if (!strcmp(histr, "*")) {
- snprintf(histr, sizeof histr, "%ld",
- LONG_MAX);
+ snprintf(histr, sizeof histr, "%ld", LONG_MAX);
}
- } else {
+ }
+ else {
strcpy(histr, lostr);
}
lo = atol(lostr);
hi = atol(histr);
- if ((msgnum >= lo) && (msgnum <= hi))
- return (1);
+ if ((msgnum >= lo) && (msgnum <= hi)) return(1);
}
- return (0);
+ return(0);
}
+
/*
* Strip a boundarized substring out of a string (for example, remove
* parentheses and anything inside them).
serv_gets(buf);
if (buf[0] == '1') {
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(username, buf, 0);
+ extract_token(username, buf, 0, '|', sizeof username);
wprintf("<OPTION");
if (preselect != NULL)
if (!strcasecmp(username, preselect))
if (buf[0]=='1') {
while(serv_gets(buf), strcmp(buf, "000")) {
if (!strncasecmp(buf, "part=", 5)) {
- extract(partnum, &buf[5], 2);
- extract(content_type, &buf[5], 4);
+ extract_token(partnum, &buf[5], 2, '|', sizeof partnum);
+ extract_token(content_type, &buf[5], 4, '|', sizeof content_type);
if (!strcasecmp(content_type,
"text/x-vcard")) {
vcard_msgnum = stuff->msgnum;
return;
}
- extract(username, &buf[4], 0);
- extract(password, &buf[4], 1);
+ extract_token(username, &buf[4], 0, '|', sizeof username);
+ extract_token(password, &buf[4], 1, '|', sizeof password);
flags = extract_int(&buf[4], 2);
timescalled = extract_int(&buf[4], 3);
msgsposted = extract_int(&buf[4], 4);
wprintf("<TH>Last Login</TH><TH>Total Logins</TH><TH>Total Posts</TH></TR>\n");
while (serv_gets(buf), strcmp(buf, "000")) {
- extract(fl, buf, 0);
+ extract_token(fl, buf, 0, '|', sizeof fl);
has_bio = 0;
for (bptr = bio; bptr != NULL; bptr = bptr->next) {
if (!strcasecmp(fl, bptr->name))
value = vcard_get_prop(v, "", 0, i++, 0);
if (!strcasecmp(key, "n")) {
- extract_token(lastname, value, 0, ';');
- extract_token(firstname, value, 1, ';');
- extract_token(middlename, value, 2, ';');
- extract_token(prefix, value, 3, ';');
- extract_token(suffix, value, 4, ';');
+ extract_token(lastname, value, 0, ';', sizeof lastname);
+ extract_token(firstname, value, 1, ';', sizeof firstname);
+ extract_token(middlename, value, 2, ';', sizeof middlename);
+ extract_token(prefix, value, 3, ';', sizeof prefix);
+ extract_token(suffix, value, 4, ';', sizeof suffix);
}
else if (!strcasecmp(key, "title")) {
}
else if (!strcasecmp(key, "adr")) {
- extract_token(pobox, value, 0, ';');
- extract_token(extadr, value, 1, ';');
- extract_token(street, value, 2, ';');
- extract_token(city, value, 3, ';');
- extract_token(state, value, 4, ';');
- extract_token(zipcode, value, 5, ';');
- extract_token(country, value, 6, ';');
+ extract_token(pobox, value, 0, ';', sizeof pobox);
+ extract_token(extadr, value, 1, ';', sizeof extadr);
+ extract_token(street, value, 2, ';', sizeof street);
+ extract_token(city, value, 3, ';', sizeof city);
+ extract_token(state, value, 4, ';', sizeof state);
+ extract_token(zipcode, value, 5, ';', sizeof zipcode);
+ extract_token(country, value, 6, ';', sizeof country);
}
else if (!strcasecmp(key, "tel;home")) {
- extract_token(hometel, value, 0, ';');
+ extract_token(hometel, value, 0, ';', sizeof hometel);
}
else if (!strcasecmp(key, "tel;work")) {
- extract_token(worktel, value, 0, ';');
+ extract_token(worktel, value, 0, ';', sizeof worktel);
}
else if (!strcasecmp(key, "email;internet")) {
serv_printf("email;internet:%s\n", bstr("primary_inetemail"));
for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
- extract_token(buf, bstr("other_inetemail"), i, '\n');
+ extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
if (strlen(buf) > 0) {
serv_printf("email;internet:%s", buf);
}
if (buf[0] == '2') {
bytes = extract_long(&buf[4], 0);
content = malloc(bytes + 2);
- extract(content_type, &buf[4], 3);
+ extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
output_headers(0, 0, 0, 0, 0, 0, 0);
read_server_binary(content, bytes);
serv_puts("CLOS");
serv_gets(buf);
if (buf[0] == '2') {
bytes = extract_long(&buf[4], 0);
- extract(content_type, &buf[4], 3);
+ extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
content = malloc(bytes + 2);
read_server_binary(content, bytes);
strcpy(cmd, hptr->line);
hptr = hptr->next;
- extract_token(method, cmd, 0, ' ');
+ extract_token(method, cmd, 0, ' ', sizeof method);
extract_action(action, cmd);
while (hptr != NULL) {
if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
safestrncpy(cookie, &buf[15], sizeof cookie);
cookie_to_stuff(cookie, NULL,
- c_username, c_password, c_roomname);
+ c_username, sizeof c_username,
+ c_password, sizeof c_password,
+ c_roomname, sizeof c_roomname);
}
else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
- extract_token(c_httpauth_user, c_httpauth_string, 0, ':');
- extract_token(c_httpauth_pass, c_httpauth_string, 1, ':');
+ extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
+ extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
}
else if (!strncasecmp(buf, "Content-length: ", 16)) {
ContentLength = atoi(&buf[16]);
int gzip_ok; /* Nonzero if Accept-encoding: gzip */
};
-#define extract(dest,source,parmnum) extract_token(dest,source,parmnum,'|')
#define num_parms(source) num_tokens(source, '|')
/* Per-session data */
void stuff_to_cookie(char *cookie, int session,
char *user, char *pass, char *room);
void cookie_to_stuff(char *cookie, int *session,
- char *user, char *pass, char *room);
+ char *user, size_t user_len,
+ char *pass, size_t pass_len,
+ char *room, size_t room_len);
void locate_host(char *, int);
void become_logged_in(char *, char *, char *);
void do_login(void);
void escputs1(char *strbuf, int nbsp, int nolinebreaks);
void msgesc(char *target, char *strbuf);
void msgescputs(char *strbuf);
-long extract_long(char *source, long int parmnum);
-int extract_int(char *source, int parmnum);
+int extract_int(const char *source, int parmnum);
+long extract_long(const char *source, int parmnum);
void stripout(char *str, char leftboundary, char rightboundary);
void dump_vars(void);
void embed_main_menu(void);
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 extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
void remove_token(char *source, int parmnum, char separator);
char *load_mimepart(long msgnum, char *partnum);
int pattern2(char *search, char *patn);
void do_stuff_to_msgs(void);
void load_preferences(void);
void save_preferences(void);
-void get_preference(char *key, char *value);
+void get_preference(char *key, char *value, size_t value_len);
void set_preference(char *key, char *value);
void knrooms(void);
int is_msg_in_mset(char *mset, long msgnum);
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);
- extract(realroom, buf, 9);
- extract(realhost, buf, 10);
+ extract_token(user, buf, 1, '|', sizeof user);
+ extract_token(room, buf, 2, '|', sizeof room);
+ extract_token(host, buf, 3, '|', sizeof host);
+ extract_token(realroom, buf, 9, '|', sizeof realroom);
+ extract_token(realhost, buf, 10, '|', sizeof realhost);
last_activity = extract_long(buf, 5);
bg = 1 - bg;