From c477d6a73cf3afdc47913e2c775ceb5938b6a469 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Thu, 12 Jul 2007 21:49:12 +0000 Subject: [PATCH] * Created IsEmptyStr define to be used rather then using some weird strlen constructs * moved strlens out of loops everywhere possible anyhow. * evaded about half of our strlen()'s; more to come. --- webcit/auth.c | 28 ++--- webcit/calendar.c | 18 +-- webcit/calendar_view.c | 12 +- webcit/context_loop.c | 23 ++-- webcit/cookie_conversion.c | 4 +- webcit/event.c | 28 ++--- webcit/graphics.c | 2 +- webcit/groupdav_delete.c | 8 +- webcit/groupdav_get.c | 8 +- webcit/groupdav_main.c | 27 +++-- webcit/groupdav_options.c | 4 +- webcit/groupdav_propfind.c | 6 +- webcit/groupdav_put.c | 2 +- webcit/iconbar.c | 9 +- webcit/inetconf.c | 10 +- webcit/mainmenu.c | 4 +- webcit/messages.c | 227 +++++++++++++++++++++---------------- webcit/mime_parser.c | 18 +-- webcit/netconf.c | 4 +- webcit/notes.c | 14 ++- webcit/paging.c | 19 ++-- webcit/preferences.c | 2 +- webcit/roomops.c | 70 ++++++------ webcit/rss.c | 25 ++-- webcit/serv_func.c | 10 +- webcit/sieve.c | 7 +- webcit/smtpqueue.c | 14 ++- webcit/sysmsgs.c | 2 +- webcit/tools.c | 64 +++++++---- webcit/useredit.c | 6 +- webcit/vcard.c | 14 ++- webcit/vcard_edit.c | 4 +- webcit/webcit.c | 116 ++++++++++--------- webcit/webcit.h | 2 + webcit/webserver.c | 6 +- webcit/who.c | 12 +- webcit/wiki.c | 6 +- 37 files changed, 473 insertions(+), 362 deletions(-) diff --git a/webcit/auth.c b/webcit/auth.c index 748028f85..ecde8065b 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -43,7 +43,7 @@ void display_login(char *mesg) output_headers(1, 1, 2, 0, 0, 0); wprintf("
\n"); - if (mesg != NULL) if (strlen(mesg) > 0) { + if (mesg != NULL) if (!IsEmptyStr(mesg)) { stresc(buf, mesg, 0, 0); svprintf("mesg", WCS_STRING, "%s", buf); } @@ -142,16 +142,16 @@ void do_login(void) { char buf[SIZ]; - if (strlen(bstr("language")) > 0) { + if (!IsEmptyStr(bstr("language"))) { set_selected_language(bstr("language")); go_selected_language(); } - if (strlen(bstr("exit_action")) > 0) { + if (!IsEmptyStr(bstr("exit_action"))) { do_logout(); return; } - if (strlen(bstr("login_action")) > 0) { + if (!IsEmptyStr(bstr("login_action"))) { serv_printf("USER %s", bstr("name")); serv_getln(buf, sizeof buf); if (buf[0] == '3') { @@ -169,8 +169,8 @@ void do_login(void) return; } } - if (strlen(bstr("newuser_action")) > 0) { - if (strlen(bstr("pass")) == 0) { + if (!IsEmptyStr(bstr("newuser_action"))) { + if (IsEmptyStr(bstr("pass"))) { display_login(_("Blank passwords are not allowed.")); return; } @@ -214,9 +214,11 @@ void do_welcome(void) */ if (WC->is_aide) { if (!setup_wizard) { + int len; sprintf(wizard_filename, "setupwiz.%s.%s", ctdlhost, ctdlport); - for (i=0; i 0) { - if (strlen(bstr("axlevel")) > 0) { + if (!IsEmptyStr(buf)) { + if (!IsEmptyStr(bstr("axlevel"))) { serv_printf("VALI %s|%s", buf, bstr("axlevel")); serv_getln(buf, sizeof buf); if (buf[0] != '2') { @@ -469,7 +471,7 @@ void display_changepw(void) "
\n
\n" ); - if (strlen(WC->ImportantMessage) > 0) { + if (!IsEmptyStr(WC->ImportantMessage)) { do_template("beginbox_nt"); wprintf("" "%s
\n", WC->ImportantMessage); @@ -519,7 +521,7 @@ void changepw(void) char buf[SIZ]; char newpass1[32], newpass2[32]; - if (strlen(bstr("change_action")) == 0) { + if (IsEmptyStr(bstr("change_action"))) { safestrncpy(WC->ImportantMessage, _("Cancelled. Password was not changed."), sizeof WC->ImportantMessage); @@ -538,7 +540,7 @@ void changepw(void) return; } - if (strlen(newpass1) == 0) { + if (IsEmptyStr(newpass1)) { safestrncpy(WC->ImportantMessage, _("Blank passwords are not allowed."), sizeof WC->ImportantMessage); diff --git a/webcit/calendar.c b/webcit/calendar.c index 489d58a1f..64d32d50c 100644 --- a/webcit/calendar.c +++ b/webcit/calendar.c @@ -632,7 +632,7 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) { created_new_vtodo = 1; } - if (strlen(bstr("save_button")) > 0) { + if (!IsEmptyStr(bstr("save_button"))) { /** Replace values in the component with ones from the form */ @@ -730,7 +730,7 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) { /** * If the user clicked 'Delete' then explicitly delete the message. */ - if (strlen(bstr("delete_button")) > 0) { + if (!IsEmptyStr(bstr("delete_button"))) { delete_existing = 1; } @@ -796,7 +796,7 @@ void display_using_handler(long msgnum, } } - if (strlen(relevant_partnum) > 0) { + if (!IsEmptyStr(relevant_partnum)) { relevant_source = load_mimepart(msgnum, relevant_partnum); if (relevant_source != NULL) { @@ -853,7 +853,7 @@ void display_edit_task(void) { long msgnum = 0L; /** Force change the room if we have to */ - if (strlen(bstr("taskrm")) > 0) { + if (!IsEmptyStr(bstr("taskrm"))) { gotoroom(bstr("taskrm")); } @@ -936,6 +936,7 @@ void do_freebusy(char *req) { char who[SIZ]; char buf[SIZ]; char *fb; + int len; extract_token(who, req, 1, ' ', sizeof who); if (!strncasecmp(who, "/freebusy/", 10)) { @@ -943,10 +944,11 @@ void do_freebusy(char *req) { } unescape_input(who); - if ( (!strcasecmp(&who[strlen(who)-4], ".vcf")) - || (!strcasecmp(&who[strlen(who)-4], ".ifb")) - || (!strcasecmp(&who[strlen(who)-4], ".vfb")) ) { - who[strlen(who)-4] = 0; + len = strlen(who); + if ( (!strcasecmp(&who[len-4], ".vcf")) + || (!strcasecmp(&who[len-4], ".ifb")) + || (!strcasecmp(&who[len-4], ".vfb")) ) { + who[len-4] = 0; } lprintf(9, "freebusy requested for <%s>\n", who); diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index 9315c5556..54ebc2be1 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -675,9 +675,9 @@ void calendar_day_view(int year, int month, int day) { get_preference("calhourformat", calhourformat, sizeof calhourformat); get_preference("daystart", daystart_str, sizeof daystart_str); - if (strlen(daystart_str) > 0) daystart = atoi(daystart_str); + if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str); get_preference("dayend", dayend_str, sizeof dayend_str); - if (strlen(dayend_str) > 0) dayend = atoi(dayend_str); + if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str); /** Figure out the dates for "yesterday" and "tomorrow" links */ @@ -915,12 +915,12 @@ void do_calendar_view(void) { day = tm.tm_mday; /** Now see if a date was specified */ - if (strlen(bstr("year")) > 0) year = atoi(bstr("year")); - if (strlen(bstr("month")) > 0) month = atoi(bstr("month")); - if (strlen(bstr("day")) > 0) day = atoi(bstr("day")); + if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year")); + if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month")); + if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day")); /** How would you like that cooked? */ - if (strlen(bstr("calview")) > 0) { + if (!IsEmptyStr(bstr("calview"))) { strcpy(calview, bstr("calview")); } else { diff --git a/webcit/context_loop.c b/webcit/context_loop.c index cb1a907f6..b693ff992 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -155,12 +155,13 @@ int GenerateSessionID(void) * \param sock a socket? * \param buf some bunch of chars? * \param hold hold what? + * TODO: get this comment right */ int req_gets(int sock, char *buf, char *hold) { - int a; + int a, b; - if (strlen(hold) == 0) { + if (IsEmptyStr(hold)) { strcpy(buf, ""); a = client_getln(sock, buf, SIZ); if (a<1) return(-1); @@ -170,12 +171,19 @@ int req_gets(int sock, char *buf, char *hold) strcpy(hold, ""); if (!strncasecmp(buf, "Cookie: ", 8)) { - for (a = 0; a < strlen(buf); ++a) + int len; + len = strlen(buf); + for (a = 0; a < len; ++a) if (buf[a] == ';') { + // we don't refresh len, because of we + // only exit from here. sprintf(hold, "Cookie: %s", &buf[a + 1]); buf[a] = 0; - while (isspace(hold[8])) - strcpy(&hold[8], &hold[9]); + b = 8; + while (isspace(hold[b])) + b++; + + memmove(&hold[8], &hold[b], len - b + 1); return(0); } } @@ -188,6 +196,7 @@ int req_gets(int sock, char *buf, char *hold) * \param fd the fd to close?????? * lingering_close() a`la Apache. see * http://www.apache.org/docs/misc/fin_wait_2.html for rationale + * TODO: get this comment precise. */ int lingering_close(int fd) @@ -349,7 +358,7 @@ void context_loop(int sock) safestrncpy(hptr->line, buf, sizeof hptr->line); - } while (strlen(buf) > 0); + } while (!IsEmptyStr(buf)); /** * If the request is prefixed by "/webcit" then chop that off. This @@ -425,7 +434,7 @@ void context_loop(int sock) for (sptr = SessionList; sptr != NULL; sptr = sptr->next) { /** If HTTP-AUTH, look for a session with matching credentials */ - if ( (strlen(httpauth_user) > 0) + if ( (!IsEmptyStr(httpauth_user)) &&(!strcasecmp(sptr->httpauth_user, httpauth_user)) &&(!strcasecmp(sptr->httpauth_pass, httpauth_pass)) ) { TheSession = sptr; diff --git a/webcit/cookie_conversion.c b/webcit/cookie_conversion.c index ad8717b07..edba4eebf 100644 --- a/webcit/cookie_conversion.c +++ b/webcit/cookie_conversion.c @@ -31,10 +31,12 @@ void stuff_to_cookie(char *cookie, int session, { char buf[SIZ]; int i; + int len; sprintf(buf, "%d|%s|%s|%s|", session, user, pass, room); strcpy(cookie, ""); - for (i=0; i 0) { + if (!IsEmptyStr(bstr("year"))) { tm_now.tm_year = atoi(bstr("year")) - 1900; tm_now.tm_mon = atoi(bstr("month")) - 1; tm_now.tm_mday = atoi(bstr("day")); } - if (strlen(bstr("hour")) > 0) { + if (!IsEmptyStr(bstr("hour"))) { tm_now.tm_hour = atoi(bstr("hour")); tm_now.tm_min = atoi(bstr("minute")); tm_now.tm_sec = 0; @@ -465,8 +465,8 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) { created_new_vevent = 1; } - if ( (strlen(bstr("save_button")) > 0) - || (strlen(bstr("check_button")) > 0) ) { + if ( (!IsEmptyStr(bstr("save_button"))) + || (!IsEmptyStr(bstr("check_button"))) ) { /** Replace values in the component with ones from the form */ @@ -476,7 +476,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) { icalproperty_free(prop); } - if (strlen(bstr("summary")) > 0) { + if (!IsEmptyStr(bstr("summary"))) { icalcomponent_add_property(vevent, icalproperty_new_summary(bstr("summary"))); @@ -490,7 +490,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) { icalcomponent_remove_property(vevent, prop); icalproperty_free(prop); } - if (strlen(bstr("location")) > 0) { + if (!IsEmptyStr(bstr("location"))) { icalcomponent_add_property(vevent, icalproperty_new_location(bstr("location"))); } @@ -499,7 +499,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) { icalcomponent_remove_property(vevent, prop); icalproperty_free(prop); } - if (strlen(bstr("description")) > 0) { + if (!IsEmptyStr(bstr("description"))) { icalcomponent_add_property(vevent, icalproperty_new_description(bstr("description"))); } @@ -562,7 +562,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) { } /** See if transparency is indicated */ - if (strlen(bstr("transp")) > 0) { + if (!IsEmptyStr(bstr("transp"))) { if (!strcasecmp(bstr("transp"), "opaque")) { formtransp = ICAL_TRANSP_OPAQUE; } @@ -615,7 +615,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) { strcpy(buf, bstr("organizer")); if ( (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY) == NULL) - && (strlen(buf) > 0) ) { + && (!IsEmptyStr(buf)) ) { /** set new organizer */ sprintf(organizer_string, "MAILTO:%s", buf); @@ -649,7 +649,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) { for (i=0; i 0) { + if (!IsEmptyStr(buf)) { lprintf(9, "Attendee: <%s>\n", buf); sprintf(attendee_string, "MAILTO:%s", buf); foundit = 0; @@ -707,7 +707,7 @@ STARTOVER: lprintf(9, "Remove unlisted attendees\n"); /** If the user clicked 'Save' then save it to the server. */ lprintf(9, "Serializing it for saving\n"); - if ( (encaps != NULL) && (strlen(bstr("save_button")) > 0) ) { + if ( (encaps != NULL) && (!IsEmptyStr(bstr("save_button"))) ) { serv_puts("ENT0 1|||4|||1|"); serv_getln(buf, sizeof buf); if (buf[0] == '8') { @@ -728,7 +728,7 @@ STARTOVER: lprintf(9, "Remove unlisted attendees\n"); } /** Or, check attendee availability if the user asked for that. */ - if ( (encaps != NULL) && (strlen(bstr("check_button")) > 0) ) { + if ( (encaps != NULL) && (!IsEmptyStr(bstr("check_button"))) ) { /** Call this function, which does the real work */ check_attendee_availability(encaps); @@ -745,7 +745,7 @@ STARTOVER: lprintf(9, "Remove unlisted attendees\n"); * If the user clicked 'Delete' then delete it. */ lprintf(9, "Checking to see if we have to delete an old event\n"); - if ( (strlen(bstr("delete_button")) > 0) && (msgnum > 0L) ) { + if ( (!IsEmptyStr(bstr("delete_button"))) && (msgnum > 0L) ) { serv_printf("DELE %ld", atol(bstr("msgnum"))); serv_getln(buf, sizeof buf); } @@ -755,7 +755,7 @@ STARTOVER: lprintf(9, "Remove unlisted attendees\n"); } /** If this was a save or delete, go back to the calendar view. */ - if (strlen(bstr("check_button")) == 0) { + if (IsEmptyStr(bstr("check_button"))) { readloop("readfwd"); } } diff --git a/webcit/graphics.c b/webcit/graphics.c index daeff6d34..55adb98d7 100644 --- a/webcit/graphics.c +++ b/webcit/graphics.c @@ -70,7 +70,7 @@ void do_graphics_upload(char *upl_cmd) int pos = 0; int thisblock; - if (strlen(bstr("cancel_button")) > 0) { + if (!IsEmptyStr(bstr("cancel_button"))) { strcpy(WC->ImportantMessage, _("Graphics upload has been cancelled.")); display_main_menu(); diff --git a/webcit/groupdav_delete.c b/webcit/groupdav_delete.c index 2d44b8fc1..f731daa5a 100644 --- a/webcit/groupdav_delete.c +++ b/webcit/groupdav_delete.c @@ -19,6 +19,7 @@ void groupdav_delete(char *dav_pathname, char *dav_ifmatch) { long dav_msgnum = (-1); char buf[SIZ]; int n = 0; + int len; /* First, break off the "/groupdav/" prefix */ remove_token(dav_pathname, 0, '/'); @@ -30,8 +31,9 @@ void groupdav_delete(char *dav_pathname, char *dav_ifmatch) { remove_token(dav_pathname, n-1, '/'); /* What's left is the room name. Remove trailing slashes. */ - if (dav_pathname[strlen(dav_pathname)-1] == '/') { - dav_pathname[strlen(dav_pathname)-1] = 0; + len = strlen(dav_pathname); + if (dav_pathname[len-1] == '/') { + dav_pathname[len-1] = 0; } strcpy(dav_roomname, dav_pathname); @@ -62,7 +64,7 @@ void groupdav_delete(char *dav_pathname, char *dav_ifmatch) { * It's there ... check the ETag and make sure it matches * the message number. */ - if (strlen(dav_ifmatch) > 0) { + if (!IsEmptyStr(dav_ifmatch)) { if (atol(dav_ifmatch) != dav_msgnum) { wprintf("HTTP/1.1 412 Precondition Failed\r\n"); groupdav_common_headers(); diff --git a/webcit/groupdav_get.c b/webcit/groupdav_get.c index 8ebee42ab..2cf188523 100644 --- a/webcit/groupdav_get.c +++ b/webcit/groupdav_get.c @@ -55,7 +55,7 @@ void extract_preferred(char *name, char *filename, char *partnum, char *disp, int hit = 0; /* We only want the first one that we found */ - if (strlen(epdata->found_section) > 0) return; + if (!IsEmptyStr(epdata->found_section)) return; /* Check for a content type match */ if (strlen(epdata->desired_content_type_1) > 0) { @@ -63,7 +63,7 @@ void extract_preferred(char *name, char *filename, char *partnum, char *disp, hit = 1; } } - if (strlen(epdata->desired_content_type_2) > 0) { + if (!IsEmptyStr(epdata->desired_content_type_2)) { if (!strcasecmp(epdata->desired_content_type_2, cbtype)) { hit = 1; } @@ -72,7 +72,7 @@ void extract_preferred(char *name, char *filename, char *partnum, char *disp, /* Is this the one? If so, output it. */ if (hit) { safestrncpy(epdata->found_section, partnum, sizeof epdata->found_section); - if (strlen(cbcharset) > 0) { + if (!IsEmptyStr(cbcharset)) { safestrncpy(epdata->charset, cbcharset, sizeof epdata->charset); } wprintf("Content-type: %s; charset=%s\r\n", cbtype, epdata->charset); @@ -238,7 +238,7 @@ void groupdav_get(char *dav_pathname) { /* If epdata.found_section is empty, we haven't output anything yet, so output the whole thing */ - if (strlen(epdata.found_section) == 0) { + if (IsEmptyStr(epdata.found_section)) { ptr = msgtext; endptr = &msgtext[msglen]; diff --git a/webcit/groupdav_main.c b/webcit/groupdav_main.c index ca31fe21e..fe3bbe643 100644 --- a/webcit/groupdav_main.c +++ b/webcit/groupdav_main.c @@ -32,11 +32,12 @@ void groupdav_common_headers(void) { * string conversion function */ void euid_escapize(char *target, char *source) { - int i; + int i, len; int target_length = 0; strcpy(target, ""); - for (i=0; i 0) { - striplt(dav_ifmatch); + len = strlen(dav_ifmatch); + if (len > 0) { + stripltlen(dav_ifmatch, &len); if (dav_ifmatch[0] == '\"') { - strcpy(dav_ifmatch, &dav_ifmatch[1]); - for (i=0; ihttp_host) > 0) { + if (!IsEmptyStr(WC->http_host)) { wprintf("%s://%s", (is_https ? "https" : "http"), WC->http_host); diff --git a/webcit/groupdav_options.c b/webcit/groupdav_options.c index b92b79478..ce69b2c1b 100644 --- a/webcit/groupdav_options.c +++ b/webcit/groupdav_options.c @@ -28,7 +28,7 @@ void groupdav_options(char *dav_pathname) { /* * If the room name is blank, the client is doing a top-level OPTIONS. */ - if (strlen(dav_roomname) == 0) { + if (IsEmptyStr(dav_roomname)) { wprintf("HTTP/1.1 200 OK\r\n"); groupdav_common_headers(); wprintf("Date: %s\r\n", datestring); @@ -59,7 +59,7 @@ void groupdav_options(char *dav_pathname) { /* If dav_uid is non-empty, client is requesting an OPTIONS on * a specific item in the room. */ - if (strlen(dav_uid) > 0) { + if (!IsEmptyStr(dav_uid)) { dav_msgnum = locate_message_by_uid(dav_uid); if (dav_msgnum < 0) { diff --git a/webcit/groupdav_propfind.c b/webcit/groupdav_propfind.c index 738ea266c..6d3092ae8 100644 --- a/webcit/groupdav_propfind.c +++ b/webcit/groupdav_propfind.c @@ -251,7 +251,7 @@ void groupdav_propfind(char *dav_pathname, int dav_depth, char *dav_content_type * If the room name is blank, the client is requesting a * folder list. */ - if (strlen(dav_roomname) == 0) { + if (IsEmptyStr(dav_roomname)) { groupdav_collection_list(dav_pathname, dav_depth); return; } @@ -277,7 +277,7 @@ void groupdav_propfind(char *dav_pathname, int dav_depth, char *dav_content_type * a specific item in the room. This is not valid GroupDAV, but * it is valid WebDAV. */ - if (strlen(dav_uid) > 0) { + if (!IsEmptyStr(dav_uid)) { dav_msgnum = locate_message_by_uid(dav_uid); if (dav_msgnum < 0) { @@ -410,7 +410,7 @@ void groupdav_propfind(char *dav_pathname, int dav_depth, char *dav_content_type } } - if (strlen(uid) > 0) { + if (!IsEmptyStr(uid)) { wprintf(""); wprintf(""); groupdav_identify_host(); diff --git a/webcit/groupdav_put.c b/webcit/groupdav_put.c index 21eaefbb8..512896049 100644 --- a/webcit/groupdav_put.c +++ b/webcit/groupdav_put.c @@ -99,7 +99,7 @@ void groupdav_put(char *dav_pathname, char *dav_ifmatch, * client is expecting. If not, the server probably contains a newer * version, so we fail... */ - if (strlen(dav_ifmatch) > 0) { + if (!IsEmptyStr(dav_ifmatch)) { lprintf(9, "dav_ifmatch: %s\n", dav_ifmatch); old_msgnum = locate_message_by_uid(dav_uid); lprintf(9, "old_msgnum: %ld\n", old_msgnum); diff --git a/webcit/iconbar.c b/webcit/iconbar.c index a69aab160..15729cfde 100644 --- a/webcit/iconbar.c +++ b/webcit/iconbar.c @@ -746,7 +746,7 @@ void commit_iconbar(void) { "ib_citadel" }; - if (strlen(bstr("ok_button")) == 0) { + if (IsEmptyStr(bstr("ok_button"))) { display_main_menu(); return; } @@ -754,13 +754,14 @@ void commit_iconbar(void) { sprintf(iconbar, "ib_displayas=%d", atoi(bstr("ib_displayas"))); for (i=0; i<(sizeof(boxen)/sizeof(char *)); ++i) { - sprintf(&iconbar[strlen(iconbar)], ",%s=", boxen[i]); + char *Val; if (!strcasecmp(bstr(boxen[i]), "yes")) { - sprintf(&iconbar[strlen(iconbar)], "1"); + Val = "1"; } else { - sprintf(&iconbar[strlen(iconbar)], "0"); + Val = "0"; } + sprintf(&iconbar[strlen(iconbar)], ",%s=%s", boxen[i], Val); } set_preference("iconbar", iconbar, 1); diff --git a/webcit/inetconf.c b/webcit/inetconf.c index c7066cda9..56989f73f 100644 --- a/webcit/inetconf.c +++ b/webcit/inetconf.c @@ -82,12 +82,12 @@ void display_inetconf(void) if (which >= 0) { ic_spec[which] = realloc(ic_spec[which], strlen(ic_spec[which]) + strlen(ename) + 2); - if (strlen(ic_spec[which]) > 0) strcat(ic_spec[which], "\n"); + if (!IsEmptyStr(ic_spec[which])) strcat(ic_spec[which], "\n"); strcat(ic_spec[which], ename); } else { ic_misc = realloc(ic_misc, strlen(ic_misc) + strlen(buf) + 2); - if (strlen(ic_misc) > 0) strcat(ic_misc, "\n"); + if (!IsEmptyStr(ic_misc)) strcat(ic_misc, "\n"); strcat(ic_misc, buf); } @@ -114,7 +114,7 @@ void display_inetconf(void) escputs(ic_desc[which]); wprintf("
"); wprintf("\n"); - if (strlen(ic_spec[which]) > 0) { + if (!IsEmptyStr(ic_spec[which])) { for (i=0; i\n"); - if (strlen(phone) > 0) { + if (!IsEmptyStr(phone)) { wprintf("\n", phone); } - if (strlen(mailto) > 0) { + if (!IsEmptyStr(mailto)) { wprintf("\n", mailto); @@ -724,7 +733,7 @@ void read_message(long msgnum, int printable_view, char *section) { } wprintf("?recp="); urlescputs(reply_to); - if (strlen(m_subject) > 0) { + if (!IsEmptyStr(m_subject)) { wprintf("?subject="); if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20"); urlescputs(m_subject); @@ -739,7 +748,7 @@ void read_message(long msgnum, int printable_view, char *section) { wprintf("?replyquote=%ld", msgnum); wprintf("?recp="); urlescputs(reply_to); - if (strlen(m_subject) > 0) { + if (!IsEmptyStr(m_subject)) { wprintf("?subject="); if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20"); urlescputs(m_subject); @@ -756,7 +765,7 @@ void read_message(long msgnum, int printable_view, char *section) { urlescputs(reply_to); wprintf("?cc="); urlescputs(reply_all); - if (strlen(m_subject) > 0) { + if (!IsEmptyStr(m_subject)) { wprintf("?subject="); if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20"); urlescputs(m_subject); @@ -838,12 +847,14 @@ void read_message(long msgnum, int printable_view, char *section) { safestrncpy(m_subject, &buf[5], sizeof m_subject); } if (!strncasecmp(buf, "cccc=", 5)) { + int len; safestrncpy(m_cc, &buf[5], sizeof m_cc); - if (strlen(reply_all) > 0) { + if (!IsEmptyStr(reply_all)) { strcat(reply_all, ", "); } - safestrncpy(&reply_all[strlen(reply_all)], &buf[5], - (sizeof reply_all - strlen(reply_all)) ); + len = strlen(reply_all); + safestrncpy(&reply_all[len], &buf[5], + (sizeof reply_all - len) ); } if ((!strncasecmp(buf, "hnod=", 5)) && (strcasecmp(&buf[5], serv_info.serv_humannode))) { @@ -851,7 +862,7 @@ void read_message(long msgnum, int printable_view, char *section) { } if ((!strncasecmp(buf, "room=", 5)) && (strcasecmp(&buf[5], WC->wc_roomname)) - && (strlen(&buf[5])>0) ) { + && (!IsEmptyStr(&buf[5])) ) { wprintf(_("in ")); wprintf("%s> ", &buf[5]); } @@ -867,18 +878,20 @@ void read_message(long msgnum, int printable_view, char *section) { if ( ((WC->room_flags & QR_NETWORK) || ((strcasecmp(&buf[5], serv_info.serv_nodename) && (strcasecmp(&buf[5], serv_info.serv_fqdn))))) - && (strlen(rfca)==0) + && (IsEmptyStr(rfca)) ) { wprintf("@%s ", &buf[5]); } } if (!strncasecmp(buf, "rcpt=", 5)) { + int len; wprintf(_("to ")); - if (strlen(reply_all) > 0) { + if (!IsEmptyStr(reply_all)) { strcat(reply_all, ", "); } - safestrncpy(&reply_all[strlen(reply_all)], &buf[5], - (sizeof reply_all - strlen(reply_all)) ); + len = strlen(reply_all); + safestrncpy(&reply_all[len], &buf[5], + (sizeof reply_all - len) ); #ifdef HAVE_ICONV utf8ify_rfc822_string(&buf[5]); #endif @@ -900,12 +913,12 @@ void read_message(long msgnum, int printable_view, char *section) { striplt(mime_name); striplt(mime_filename); - if ( (strlen(mime_filename) == 0) && (strlen(mime_name) > 0) ) { + if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) { strcpy(mime_filename, mime_name); } if (!strcasecmp(mime_content_type, "message/rfc822")) { - if (strlen(mime_submessages) > 0) { + if (!IsEmptyStr(mime_submessages)) { strcat(mime_submessages, "|"); } strcat(mime_submessages, mime_partnum); @@ -923,7 +936,7 @@ void read_message(long msgnum, int printable_view, char *section) { else if ( ( (!strcasecmp(mime_disposition, "attachment")) || (!strcasecmp(mime_disposition, "inline")) || (!strcasecmp(mime_disposition, "")) - ) && (strlen(mime_content_type) > 0) + ) && (!IsEmptyStr(mime_content_type)) ) { ++num_attach_links; attach_links = realloc(attach_links, @@ -965,8 +978,8 @@ void read_message(long msgnum, int printable_view, char *section) { } /** Generate a reply-to address */ - if (strlen(rfca) > 0) { - if (strlen(from) > 0) { + if (!IsEmptyStr(rfca)) { + if (!IsEmptyStr(from)) { snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca); } else { @@ -974,7 +987,7 @@ void read_message(long msgnum, int printable_view, char *section) { } } else { - if ( (strlen(node) > 0) + if ((!IsEmptyStr(node)) && (strcasecmp(node, serv_info.serv_nodename)) && (strcasecmp(node, serv_info.serv_humannode)) ) { snprintf(reply_to, sizeof(reply_to), "%s @ %s", @@ -995,14 +1008,14 @@ void read_message(long msgnum, int printable_view, char *section) { utf8ify_rfc822_string(m_cc); utf8ify_rfc822_string(m_subject); #endif - if (strlen(m_cc) > 0) { + if (!IsEmptyStr(m_cc)) { wprintf("
"); wprintf(_("CC:")); wprintf(" "); escputs(m_cc); wprintf("
"); } - if (strlen(m_subject) > 0) { + if (!IsEmptyStr(m_subject)) { wprintf("
"); wprintf(_("Subject:")); wprintf(" "); @@ -1010,9 +1023,6 @@ void read_message(long msgnum, int printable_view, char *section) { wprintf("
"); } - - - /** Begin body */ wprintf("
"); @@ -1020,7 +1030,7 @@ void read_message(long msgnum, int printable_view, char *section) { * Learn the content type */ strcpy(mime_content_type, "text/plain"); - while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) { + while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) { if (!strcmp(buf, "000")) { wprintf(""); wprintf(_("unexpected end of message")); @@ -1032,22 +1042,27 @@ void read_message(long msgnum, int printable_view, char *section) { striplt(msg4_partnum); } if (!strncasecmp(buf, "Content-type:", 13)) { + int len; safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type)); striplt(mime_content_type); - for (i=0; i 0) && (isspace(buf[strlen(buf) - 1]))) - buf[strlen(buf) - 1] = 0; + len = strlen(buf); + while ((!IsEmptyStr(buf)) && (isspace(buf[len-1]))) + buf[--len] = 0; if ((bq == 0) && ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) { wprintf("
"); @@ -1126,7 +1144,7 @@ void read_message(long msgnum, int printable_view, char *section) { } /** If there are attached submessages, display them now... */ - if ( (strlen(mime_submessages) > 0) && (!section[0]) ) { + if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) { for (i=0; i 0) { + if (!IsEmptyStr(vcard_partnum)) { part_source = load_mimepart(msgnum, vcard_partnum); if (part_source != NULL) { @@ -1168,7 +1186,7 @@ void read_message(long msgnum, int printable_view, char *section) { } /** Handler for calendar parts */ - if (strlen(cal_partnum) > 0) { + if (!IsEmptyStr(cal_partnum)) { part_source = load_mimepart(msgnum, cal_partnum); if (part_source != NULL) { cal_process_attachment(part_source, @@ -1367,7 +1385,7 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers } if ((!strncasecmp(buf, "room=", 5)) && (strcasecmp(&buf[5], WC->wc_roomname)) - && (strlen(&buf[5])>0) ) { + && (!IsEmptyStr(&buf[5])) ) { wprintf(_("in ")); wprintf("%s> ", &buf[5]); } @@ -1383,7 +1401,7 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers if ( ((WC->room_flags & QR_NETWORK) || ((strcasecmp(&buf[5], serv_info.serv_nodename) && (strcasecmp(&buf[5], serv_info.serv_fqdn))))) - && (strlen(rfca)==0) + && (IsEmptyStr(rfca)) ) { wprintf("@%s ", &buf[5]); } @@ -1424,7 +1442,7 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers #ifdef HAVE_ICONV utf8ify_rfc822_string(m_subject); #endif - if (strlen(m_subject) > 0) { + if (!IsEmptyStr(m_subject)) { wprintf(_("Subject:")); wprintf(" "); msgescputs(m_subject); @@ -1441,12 +1459,13 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers * Learn the content type */ strcpy(mime_content_type, "text/plain"); - while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) { + while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) { if (!strcmp(buf, "000")) { wprintf("%s (4)", _("unexpected end of message")); goto ENDBODY; } if (!strncasecmp(buf, "Content-type: ", 14)) { + int len; safestrncpy(mime_content_type, &buf[14], sizeof(mime_content_type)); for (i=0; i 0) && (isspace(buf[strlen(buf) - 1]))) - buf[strlen(buf) - 1] = 0; + len = strlen(buf); + while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1]))) + buf[--len] = 0; if ((bq == 0) && ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) { wprintf("
"); @@ -1675,7 +1701,7 @@ void display_addressbook(long msgnum, char alpha) { } } - if (strlen(vcard_partnum) > 0) { + if (!IsEmptyStr(vcard_partnum)) { vcard_source = load_mimepart(msgnum, vcard_partnum); if (vcard_source != NULL) { @@ -1736,7 +1762,7 @@ void fetch_ab_name(long msgnum, char *namebuf) { int mime_length; char vcard_partnum[SIZ]; char *vcard_source = NULL; - int i; + int i, len; struct message_summary summ; if (namebuf == NULL) return; @@ -1766,7 +1792,7 @@ void fetch_ab_name(long msgnum, char *namebuf) { } } - if (strlen(vcard_partnum) > 0) { + if (!IsEmptyStr(vcard_partnum)) { vcard_source = load_mimepart(msgnum, vcard_partnum); if (vcard_source != NULL) { @@ -1779,7 +1805,8 @@ void fetch_ab_name(long msgnum, char *namebuf) { lastfirst_firstlast(namebuf); striplt(namebuf); - for (i=0; isumm[nummsgs-1].msgnum = WC->msgarr[nummsgs-1]; safestrncpy(WC->summ[nummsgs-1].subj, _("(no subject)"), sizeof WC->summ[nummsgs-1].subj); - if (strlen(fullname) > 0) { + if (!IsEmptyStr(fullname)) { safestrncpy(WC->summ[nummsgs-1].from, fullname, sizeof WC->summ[nummsgs-1].from); } - if (strlen(subject) > 0) { + if (!IsEmptyStr(subject)) { safestrncpy(WC->summ[nummsgs-1].subj, subject, sizeof WC->summ[nummsgs-1].subj); } @@ -1985,7 +2012,7 @@ int load_msg_ptrs(char *servcmd, int with_headers) strcpy(&WC->summ[nummsgs-1].subj[72], "..."); } - if (strlen(nodename) > 0) { + if (!IsEmptyStr(nodename)) { if ( ((WC->room_flags & QR_NETWORK) || ((strcasecmp(nodename, serv_info.serv_nodename) && (strcasecmp(nodename, serv_info.serv_fqdn))))) @@ -2178,13 +2205,13 @@ void readloop(char *oper) get_preference(sortpref_name, sortpref_value, sizeof sortpref_value); sortby = bstr("sortby"); - if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) { + if ( (!IsEmptyStr(sortby)) && (strcasecmp(sortby, sortpref_value)) ) { set_preference(sortpref_name, sortby, 1); } - if (strlen(sortby) == 0) sortby = sortpref_value; + if (IsEmptyStr(sortby)) sortby = sortpref_value; /** mailbox sort */ - if (strlen(sortby) == 0) sortby = "rdate"; + if (IsEmptyStr(sortby)) sortby = "rdate"; /** message board sort */ if (!strcasecmp(sortby, "reverse")) { @@ -2761,10 +2788,10 @@ void post_message(void) return; } - if (strlen(bstr("cancel_button")) > 0) { + if (!IsEmptyStr(bstr("cancel_button"))) { sprintf(WC->ImportantMessage, _("Cancelled. Message was not posted.")); - } else if (strlen(bstr("attach_button")) > 0) { + } else if (!IsEmptyStr(bstr("attach_button"))) { display_enter(); return; } else if (atol(bstr("postseq")) == dont_post) { @@ -2787,9 +2814,9 @@ void post_message(void) serv_getln(buf, sizeof buf); if (buf[0] == '4') { post_mime_to_server(); - if ( (strlen(bstr("recp")) > 0) - || (strlen(bstr("cc")) > 0) - || (strlen(bstr("bcc")) > 0) + if ( (!IsEmptyStr(bstr("recp"))) + || (!IsEmptyStr(bstr("cc" ))) + || (!IsEmptyStr(bstr("bcc" ))) ) { sprintf(WC->ImportantMessage, _("Message has been sent.\n")); } @@ -2811,13 +2838,13 @@ void post_message(void) * We may have been supplied with instructions regarding the location * to which we must return after posting. If found, go there. */ - if (strlen(bstr("return_to")) > 0) { + if (!IsEmptyStr(bstr("return_to"))) { http_redirect(bstr("return_to")); } /** * If we were editing a page in a wiki room, go to that page now. */ - else if (strlen(bstr("wikipage")) > 0) { + else if (!IsEmptyStr(bstr("wikipage"))) { snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage")); http_redirect(buf); } @@ -2851,7 +2878,7 @@ void display_enter(void) now = time(NULL); - if (strlen(bstr("force_room")) > 0) { + if (!IsEmptyStr(bstr("force_room"))) { gotoroom(bstr("force_room")); } @@ -2930,7 +2957,9 @@ void display_enter(void) serv_getln(buf, sizeof buf); if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */ - if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) { + if (!IsEmptyStr(bstr("recp")) && + !IsEmptyStr(bstr("cc" )) && + !IsEmptyStr(bstr("bcc" ))) { recipient_bad = 1; } } @@ -3126,10 +3155,12 @@ void display_enter(void) if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) { get_preference("use_sig", buf, sizeof buf); if (!strcasecmp(buf, "yes")) { + int len; get_preference("signature", ebuf, sizeof ebuf); euid_unescapize(buf, ebuf); wprintf("
--
"); - for (i=0; i"); } @@ -3234,7 +3265,7 @@ void move_msg(void) msgid = atol(bstr("msgid")); - if (strlen(bstr("move_button")) > 0) { + if (!IsEmptyStr(bstr("move_button"))) { sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room")); serv_puts(buf); serv_getln(buf, sizeof buf); diff --git a/webcit/mime_parser.c b/webcit/mime_parser.c index e68f99c31..223cd04f6 100644 --- a/webcit/mime_parser.c +++ b/webcit/mime_parser.c @@ -40,7 +40,7 @@ void extract_key(char *target, char *source, char *key) */ char *fixed_partnum(char *supplied_partnum) { if (supplied_partnum == NULL) return "1"; - if (strlen(supplied_partnum)==0) return "1"; + if (IsEmptyStr(supplied_partnum)) return "1"; return supplied_partnum; } @@ -142,7 +142,7 @@ void mime_decode(char *partnum, strcpy(encoding, ""); /* If this part is not encoded, send as-is */ - if ( (strlen(encoding) == 0) || (dont_decode)) { + if ( (IsEmptyStr(encoding)) || (dont_decode)) { if (CallBack != NULL) { CallBack(name, filename, fixed_partnum(partnum), disposition, part_start, @@ -301,12 +301,14 @@ void the_mime_parser(char *partnum, /* Learn interesting things from the headers */ strcpy(header, ""); do { + int len; ptr = memreadline(ptr, buf, SIZ); if (ptr >= content_end) { goto end_parser; } - for (i = 0; i < strlen(buf); ++i) { + len = strlen (buf); + for (i = 0; i < len; ++i) { if (isspace(buf[i])) { buf[i] = ' '; } @@ -340,14 +342,14 @@ void the_mime_parser(char *partnum, strcpy(encoding, &header[26]); striplt(encoding); } - if (strlen(boundary) == 0) + if (IsEmptyStr(boundary)) extract_key(boundary, header, "boundary"); strcpy(header, ""); } if ((strlen(header) + strlen(buf) + 2) < SIZ) { strcat(header, buf); } - } while ((strlen(buf) > 0) && (*ptr != 0)); + } while ((!IsEmptyStr(buf)) && (*ptr != 0)); if (strchr(disposition, ';')) *(strchr(disposition, ';')) = '\0'; @@ -356,7 +358,7 @@ void the_mime_parser(char *partnum, *(strchr(content_type, ';')) = '\0'; striplt(content_type); - if (strlen(boundary) > 0) { + if (!IsEmptyStr(boundary)) { is_multipart = 1; } else { is_multipart = 0; @@ -395,7 +397,7 @@ void the_mime_parser(char *partnum, --part_end; /* omit the trailing CR */ } - if (strlen(partnum) > 0) { + if (!IsEmptyStr(partnum)) { snprintf(nested_partnum, sizeof nested_partnum, "%s.%d", partnum, @@ -511,7 +513,7 @@ void the_mime_parser(char *partnum, 0, encoding, userdata); } if (CallBack != NULL) { - if (strlen(partnum) > 0) { + if (!IsEmptyStr(partnum)) { snprintf(nested_partnum, sizeof nested_partnum, "%s.%d", partnum, diff --git a/webcit/netconf.c b/webcit/netconf.c index 7479fb2b3..bfb938870 100644 --- a/webcit/netconf.c +++ b/webcit/netconf.c @@ -18,7 +18,7 @@ void edit_node(void) { char cnode[SIZ]; FILE *fp; - if (strlen(bstr("ok_button")) > 0) { + if (!IsEmptyStr(bstr("ok_button"))) { strcpy(node, bstr("node") ); fp = tmpfile(); if (fp != NULL) { @@ -300,7 +300,7 @@ void add_node(void) strcpy(node, bstr("node")); - if (strlen(bstr("add_button")) > 0) { + if (!IsEmptyStr(bstr("add_button"))) { sprintf(buf, "NSET addnode|%s", node); serv_puts(buf); serv_getln(buf, sizeof buf); diff --git a/webcit/notes.c b/webcit/notes.c index 38cd1b7de..76db3909b 100644 --- a/webcit/notes.c +++ b/webcit/notes.c @@ -21,7 +21,7 @@ void display_note(long msgnum) char display_notetext[SIZ]; char eid[128]; int in_text = 0; - int i; + int i, len; wprintf("\n"); @@ -51,13 +51,14 @@ void display_note(long msgnum) } /** Now sanitize the buffer */ - for (i=0; i 0) { + if (!IsEmptyStr(eid)) { wprintf("%s
\n", eid, display_notetext); } else { @@ -65,7 +66,7 @@ void display_note(long msgnum) } /** Offer in-place editing. */ - if (strlen(eid) > 0) { + if (!IsEmptyStr(eid)) { wprintf("\n", @@ -87,7 +88,7 @@ void updatenote(void) char display_notetext[SIZ]; long msgnum; int in_text = 0; - int i; + int i, len; serv_printf("ENT0 1||0|0||||||%s", bstr("eid")); serv_getln(buf, sizeof buf); @@ -114,7 +115,8 @@ void updatenote(void) } } /** Now sanitize the buffer */ - for (i=0; iImportantMessage, _("Message was not sent."), sizeof WC->ImportantMessage @@ -339,10 +339,11 @@ void chat_recv(void) { wprintf("\n"); } - if (strlen(output_data) > 0) { - - if (output_data[strlen(output_data)-1] == '\n') { - output_data[strlen(output_data)-1] = 0; + if (!IsEmptyStr(output_data)) { + int len; + len = strlen(output_data); + if (output_data[len-1] == '\n') { + output_data[len-1] = 0; } /** Output our fun to the other frame. */ @@ -438,15 +439,15 @@ void chat_send(void) { strcpy(send_this, ""); } - if (strlen(bstr("help_button")) > 0) { + if (!IsEmptyStr(bstr("help_button"))) { strcpy(send_this, "/help"); } - if (strlen(bstr("list_button")) > 0) { + if (!IsEmptyStr(bstr("list_button"))) { strcpy(send_this, "/who"); } - if (strlen(bstr("exit_button")) > 0) { + if (!IsEmptyStr(bstr("exit_button"))) { strcpy(send_this, "/quit"); } @@ -462,7 +463,7 @@ void chat_send(void) { WC->serv_sock = WC->chat_sock; WC->chat_sock = i; - while (strlen(send_this) > 0) { + while (!IsEmptyStr(send_this)) { if (strlen(send_this) < 67) { serv_puts(send_this); strcpy(send_this, ""); diff --git a/webcit/preferences.c b/webcit/preferences.c index fac58a6b4..b60d36dc8 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -405,7 +405,7 @@ void set_preferences(void) { char ebuf[300]; - if (strlen(bstr("change_button")) == 0) { + if (IsEmptyStr(bstr("change_button"))) { safestrncpy(WC->ImportantMessage, _("Cancelled. No settings were changed."), sizeof WC->ImportantMessage); diff --git a/webcit/roomops.c b/webcit/roomops.c index 636334e69..1efc8149f 100644 --- a/webcit/roomops.c +++ b/webcit/roomops.c @@ -625,9 +625,9 @@ void embed_room_banner(char *got, int navbar_style) { case VIEW_CALENDAR: case VIEW_CALBRIEF: wprintf("
  • 0) wprintf("?year=%s", bstr("year")); - if (strlen(bstr("month")) > 0) wprintf("?month=%s", bstr("month")); - if (strlen(bstr("day")) > 0) wprintf("?day=%s", bstr("day")); + if (!IsEmptyStr(bstr("year" ))) wprintf("?year=%s", bstr("year")); + if (!IsEmptyStr(bstr("month"))) wprintf("?month=%s", bstr("month")); + if (!IsEmptyStr(bstr("day" ))) wprintf("?day=%s", bstr("day")); wprintf("\">" "" @@ -1031,7 +1031,7 @@ void display_editroom(void) int floorvalue = 0; tab = bstr("tab"); - if (strlen(tab) == 0) tab = "admin"; + if (IsEmptyStr(tab)) tab = "admin"; load_floorlist(); serv_puts("GETR"); @@ -1194,7 +1194,7 @@ void display_editroom(void) wprintf(_("Resides on floor: ")); wprintf("\n", WC->nonce); wprintf("
  • \n", node); wprintf(""); @@ -1450,7 +1450,7 @@ void display_editroom(void) wprintf(" 0) { + if (!IsEmptyStr(remote_room)) { wprintf("|"); urlescputs(remote_room); } @@ -1477,7 +1477,7 @@ void display_editroom(void) for (i=0; i 0) { + if (!IsEmptyStr(node)) { wprintf("
    "); wprintf("\n", WC->nonce); wprintf("
    \n\t
    "); extract_token(buf, ic_spec[which], i, '\n', sizeof buf); @@ -170,7 +170,7 @@ void save_inetconf(void) { if (buf[0] == '1') while (serv_getln(buf, SIZ), strcmp(buf, "000")) { extract_token(ename, buf, 0, '|', SIZ); extract_token(etype, buf, 1, '|', SIZ); - if (strlen(buf) == 0) { + if (IsEmptyStr(buf)) { /** skip blank lines */ } else if ((!strcasecmp(ename, bstr("ename"))) @@ -180,7 +180,7 @@ void save_inetconf(void) { sprintf(WC->ImportantMessage, _("%s has been deleted."), ename); } else { - if (strlen(newconfig) > 0) strcat(newconfig, "\n"); + if (!IsEmptyStr(newconfig)) strcat(newconfig, "\n"); strcat(newconfig, buf); } } diff --git a/webcit/mainmenu.c b/webcit/mainmenu.c index 0436a77a2..352687760 100644 --- a/webcit/mainmenu.c +++ b/webcit/mainmenu.c @@ -48,7 +48,7 @@ void display_main_menu(void) wprintf(_("(come back here later)")); wprintf("\n"); - if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) { + if ((!IsEmptyStr(WC->ugname)) && (strcasecmp(WC->ugname, WC->wc_roomname))) { wprintf("
  • "); wprintf(_("Ungoto")); wprintf(""); @@ -332,7 +332,7 @@ void do_generic(void) char *junk; size_t len; - if (strlen(bstr("sc_button")) == 0) { + if (IsEmptyStr(bstr("sc_button"))) { display_main_menu(); return; } diff --git a/webcit/messages.c b/webcit/messages.c index 9e469b271..2635365b2 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -74,7 +74,7 @@ void utf8ify_rfc822_string(char *buf) { char *isav; /**< Saved pointer to input buffer */ char *osav; /**< Saved pointer to output buffer */ int passes = 0; - int i; + int i, len; int illegal_non_rfc2047_encoding = 0; /** Sometimes, badly formed messages contain strings which were simply @@ -83,9 +83,11 @@ void utf8ify_rfc822_string(char *buf) { * handle it anyway by converting from a user-specified default * charset to UTF-8 if we see any nonprintable characters. */ - for (i=0; i 126)) { illegal_non_rfc2047_encoding = 1; + i = len; ///< take a shortcut, it won't be more than one. } } if (illegal_non_rfc2047_encoding) { @@ -211,14 +213,15 @@ void utf8ify_rfc822_string(char *buf) { void rfc2047encode(char *target, int maxlen, char *source) { int need_to_encode = 0; - int i; + int i, len; unsigned char ch; if (target == NULL) return; - - for (i=0; i 126)) { need_to_encode = 1; + i = len; ///< shortcut. won't become more than 1 } } @@ -228,7 +231,7 @@ void rfc2047encode(char *target, int maxlen, char *source) } strcpy(target, "=?UTF-8?Q?"); - for (i=0; i 126) || (ch == 61)) { sprintf(&target[strlen(target)], "=%02X", ch); @@ -251,15 +254,14 @@ void rfc2047encode(char *target, int maxlen, char *source) */ void url(char *buf) { - - int pos; + int pos, len; int start, end; char urlbuf[SIZ]; char outbuf[1024]; start = (-1); - end = strlen(buf); + len = end = strlen(buf); - for (pos = 0; pos < strlen(buf); ++pos) { + for (pos = 0; pos < len; ++pos) { if (!strncasecmp(&buf[pos], "http://", 7)) start = pos; if (!strncasecmp(&buf[pos], "ftp://", 6)) @@ -269,7 +271,7 @@ void url(char *buf) if (start < 0) return; - for (pos = strlen(buf); pos > start; --pos) { + for (pos = len; pos > start; --pos) { if ( (!isprint(buf[pos])) || (isspace(buf[pos])) || (buf[pos] == '{') @@ -308,29 +310,32 @@ void url(char *buf) void vcard_n_prettyize(char *name) { char *original_name; - int i; + int i, j, len; original_name = strdup(name); + len = strlen(original_name); for (i=0; i<5; ++i) { - if (strlen(original_name) > 0) { - if (original_name[strlen(original_name)-1] == ' ') { - original_name[strlen(original_name)-1] = 0; + if (len > 0) { + if (original_name[len-1] == ' ') { + original_name[--len] = 0; } - if (original_name[strlen(original_name)-1] == ';') { - original_name[strlen(original_name)-1] = 0; + if (original_name[len-1] == ';') { + original_name[--len] = 0; } } } strcpy(name, ""); - for (i=0; inumprops) for (i=0; i<(v->numprops); ++i) { - + int len; thisname = strdup(v->prop[i].name); extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken); @@ -437,16 +442,20 @@ void display_parsed_vcard(struct vCard *v, int full) { remove_token(thisname, j, ';'); } } + + len = strlen(v->prop[i].value); if (is_qp) { - thisvalue = malloc(strlen(v->prop[i].value) + 50); + // %ff can become 6 bytes in utf8 + thisvalue = malloc(len * 2 + 3); j = CtdlDecodeQuotedPrintable( thisvalue, v->prop[i].value, - strlen(v->prop[i].value) ); + len); thisvalue[j] = 0; } else if (is_b64) { - thisvalue = malloc(strlen(v->prop[i].value) + 50); + // ff will become one byte.. + thisvalue = malloc(len + 50); CtdlDecodeBase64( thisvalue, v->prop[i].value, strlen(v->prop[i].value) ); @@ -459,7 +468,7 @@ void display_parsed_vcard(struct vCard *v, int full) { /** N is name, but only if there's no FN already there */ if (!strcasecmp(firsttoken, "n")) { - if (strlen(fullname) == 0) { + if (IsEmptyStr(fullname)) { strcpy(fullname, thisvalue); vcard_n_prettyize(fullname); } @@ -481,7 +490,7 @@ void display_parsed_vcard(struct vCard *v, int full) { } else if (!strcasecmp(firsttoken, "email")) { - if (strlen(mailto) > 0) strcat(mailto, "
    "); + if (!IsEmptyStr(mailto)) strcat(mailto, "
    "); strcat(mailto, ""); } else if (!strcasecmp(firsttoken, "tel")) { - if (strlen(phone) > 0) strcat(phone, "
    "); + if (!IsEmptyStr(phone)) strcat(phone, "
    "); strcat(phone, thisvalue); for (j=0; j
  • "); for (j=0; j 0) { + if (!IsEmptyStr(buf)) { escputs(buf); if (j<3) wprintf("
    "); else wprintf(" "); @@ -564,24 +573,24 @@ void display_parsed_vcard(struct vCard *v, int full) { ""); escputs(fullname); wprintf(""); - if (strlen(title) > 0) { + if (!IsEmptyStr(title)) { wprintf("
    "); escputs(title); wprintf("
    "); } - if (strlen(org) > 0) { + if (!IsEmptyStr(org)) { wprintf("
    "); escputs(org); wprintf("
    "); } wprintf("
    "); wprintf(_("Telephone:")); wprintf("%s
    "); wprintf(_("E-mail:")); wprintf("%s
    %s"); - if (strlen(remote_room) > 0) { + if (!IsEmptyStr(remote_room)) { escputs(remote_room); } wprintf("
    "); @@ -1759,7 +1759,7 @@ void editroom(void) int bump; - if (strlen(bstr("ok_button")) == 0) { + if (IsEmptyStr(bstr("ok_button"))) { strcpy(WC->ImportantMessage, _("Cancelled. Changes were not saved.")); display_editroom(); @@ -1782,7 +1782,7 @@ void editroom(void) er_flags2 = extract_int(&buf[4], 7); strcpy(er_roomaide, bstr("er_roomaide")); - if (strlen(er_roomaide) == 0) { + if (IsEmptyStr(er_roomaide)) { serv_puts("GETA"); serv_getln(buf, sizeof buf); if (buf[0] != '2') { @@ -1793,18 +1793,18 @@ void editroom(void) } strcpy(buf, bstr("er_name")); buf[128] = 0; - if (strlen(buf) > 0) { + if (!IsEmptyStr(buf)) { strcpy(er_name, buf); } strcpy(buf, bstr("er_password")); buf[10] = 0; - if (strlen(buf) > 0) + if (!IsEmptyStr(buf)) strcpy(er_password, buf); strcpy(buf, bstr("er_dirname")); buf[15] = 0; - if (strlen(buf) > 0) + if (!IsEmptyStr(buf)) strcpy(er_dirname, buf); strcpy(buf, bstr("type")); @@ -1905,7 +1905,7 @@ void editroom(void) } gotoroom(er_name); - if (strlen(er_roomaide) > 0) { + if (!IsEmptyStr(er_roomaide)) { sprintf(buf, "SETA %s", er_roomaide); serv_puts(buf); serv_getln(buf, sizeof buf); @@ -1939,7 +1939,7 @@ void do_invt_kick(void) { strcpy(username, bstr("username")); - if (strlen(bstr("kick_button")) > 0) { + if (!IsEmptyStr(bstr("kick_button"))) { sprintf(buf, "KICK %s", username); serv_puts(buf); serv_getln(buf, sizeof buf); @@ -1953,7 +1953,7 @@ void do_invt_kick(void) { } } - if (strlen(bstr("invite_button")) > 0) { + if (!IsEmptyStr(bstr("invite_button"))) { sprintf(buf, "INVT %s", username); serv_puts(buf); serv_getln(buf, sizeof buf); @@ -2077,7 +2077,7 @@ void display_entroom(void) load_floorlist(); wprintf(""); escputs(room); - if (strlen(realroom) > 0) { + if (!IsEmptyStr(realroom) ) { wprintf("
    "); escputs(realroom); wprintf(""); @@ -114,7 +114,7 @@ void who_inner_div(void) { /** hostname */ escputs(host); - if (strlen(realhost) > 0) { + if (!IsEmptyStr(realhost)) { wprintf("
    "); escputs(realhost); wprintf(""); @@ -206,19 +206,19 @@ void edit_me(void) { char buf[SIZ]; - if (strlen(bstr("change_room_name_button")) > 0) { + if (!IsEmptyStr(bstr("change_room_name_button"))) { serv_printf("RCHG %s", bstr("fake_roomname")); serv_getln(buf, sizeof buf); http_redirect("who"); - } else if (strlen(bstr("change_host_name_button")) > 0) { + } else if (!IsEmptyStr(bstr("change_host_name_button"))) { serv_printf("HCHG %s", bstr("fake_hostname")); serv_getln(buf, sizeof buf); http_redirect("who"); - } else if (strlen(bstr("change_user_name_button")) > 0) { + } else if (!IsEmptyStr(bstr("change_user_name_button"))) { serv_printf("UCHG %s", bstr("fake_username")); serv_getln(buf, sizeof buf); http_redirect("who"); - } else if (strlen(bstr("cancel_button")) > 0) { + } else if (!IsEmptyStr(bstr("cancel_button"))) { http_redirect("who"); } else { output_headers(1, 1, 0, 0, 0, 0); diff --git a/webcit/wiki.c b/webcit/wiki.c index 0f35b6150..40fe296fb 100644 --- a/webcit/wiki.c +++ b/webcit/wiki.c @@ -1,5 +1,5 @@ /* - * $Id: $ + * $Id$ */ /** * @@ -51,7 +51,7 @@ void display_wiki_page(void) safestrncpy(pagename, bstr("page"), sizeof pagename); str_wiki_index(pagename); - if (strlen(roomname) > 0) { + if (!IsEmptyStr(roomname)) { /* If we're not in the correct room, try going there. */ if (strcasecmp(roomname, WC->wc_roomname)) { @@ -77,7 +77,7 @@ void display_wiki_page(void) return; } - if (strlen(pagename) == 0) { + if (IsEmptyStr(pagename)) { strcpy(pagename, "home"); } -- 2.30.2