* Created IsEmptyStr define to be used rather then using some weird strlen constructs
authorWilfried Göesgens <willi@citadel.org>
Thu, 12 Jul 2007 21:49:12 +0000 (21:49 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 12 Jul 2007 21:49:12 +0000 (21:49 +0000)
* moved strlens out of loops everywhere possible anyhow.
* evaded about half of our strlen()'s; more to come.

37 files changed:
webcit/auth.c
webcit/calendar.c
webcit/calendar_view.c
webcit/context_loop.c
webcit/cookie_conversion.c
webcit/event.c
webcit/graphics.c
webcit/groupdav_delete.c
webcit/groupdav_get.c
webcit/groupdav_main.c
webcit/groupdav_options.c
webcit/groupdav_propfind.c
webcit/groupdav_put.c
webcit/iconbar.c
webcit/inetconf.c
webcit/mainmenu.c
webcit/messages.c
webcit/mime_parser.c
webcit/netconf.c
webcit/notes.c
webcit/paging.c
webcit/preferences.c
webcit/roomops.c
webcit/rss.c
webcit/serv_func.c
webcit/sieve.c
webcit/smtpqueue.c
webcit/sysmsgs.c
webcit/tools.c
webcit/useredit.c
webcit/vcard.c
webcit/vcard_edit.c
webcit/webcit.c
webcit/webcit.h
webcit/webserver.c
webcit/who.c
webcit/wiki.c

index 748028f85a0a79228ba0cd374ce62fadba2f83d8..ecde8065b7d0537b594af9900208456e321303f2 100644 (file)
@@ -43,7 +43,7 @@ void display_login(char *mesg)
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"login_screen\">\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<strlen(wizard_filename); ++i) {
+                       len = strlen(wizard_filename);
+                       for (i=0; i<len; ++i) {
                                if (    (wizard_filename[i]==' ')
                                        || (wizard_filename[i] == '/')
                                ) {
@@ -245,7 +247,7 @@ void do_welcome(void)
         * Go to the user's preferred start page
         */
        get_preference("startpage", buf, sizeof buf);
-       if (strlen(buf)==0) {
+       if (IsEmptyStr(buf)) {
                safestrncpy(buf, "dotskip&room=_BASEROOM_", sizeof buf);
                set_preference("startpage", buf, 1);
        }
@@ -336,8 +338,8 @@ void validate(void)
 
        /** If the user just submitted a validation, process it... */
        safestrncpy(buf, bstr("user"), sizeof buf);
-       if (strlen(buf) > 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)
                "</div>\n<div id=\"content\">\n"
        );
 
-       if (strlen(WC->ImportantMessage) > 0) {
+       if (!IsEmptyStr(WC->ImportantMessage)) {
                do_template("beginbox_nt");
                wprintf("<SPAN CLASS=\"errormsg\">"
                        "%s</SPAN><br />\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);
index 489d58a1f9ed9ff7caf506910848eaaf307bfe2d..64d32d50cc27477ef68f4346d16197f3e35a69b2 100644 (file)
@@ -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);
index 9315c55565b344dc95a9222628a976ad863a89b1..54ebc2be1432340600fb1202575a3e69da6bdeb1 100644 (file)
@@ -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 {
index cb1a907f62771e01c281dd84139fbaba86025ab3..b693ff992676dd15632bdc45dcc9209fcfedf549 100644 (file)
@@ -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;
index ad8717b07af0947d88e1e01f58e8ad08518758dd..edba4eebfa37cdde5472dcb9bf8cb042798eec57 100644 (file)
@@ -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<strlen(buf); ++i) {
+       len = strlen(buf);
+       for (i=0; i<len; ++i) {
                sprintf(&cookie[i*2], "%02X", buf[i]);
        }
 }
index 37d6af5651cdd69178181fcd5b1880720bf63b6a..4aa7f9ef1e7bc1a67f7453bf51809e1e63d0468b 100644 (file)
@@ -175,12 +175,12 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
        }
        else {
                localtime_r(&now, &tm_now);
-               if (strlen(bstr("year")) > 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<num_tokens(form_attendees, '\n'); ++i) {
                        extract_token(buf, form_attendees, i, '\n', sizeof buf);
                        striplt(buf);
-                       if (strlen(buf) > 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");
        }
 }
index daeff6d349c32c9adbe5f91e032fed979be48ca2..55adb98d7f1c66cc94aeda37b0bf438ee5fce8b3 100644 (file)
@@ -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();
index 2d44b8fc1cce551e46ce49752b7d7cdac227e91f..f731daa5a7cf6878f9b0d4c323a64c0557cab4a4 100644 (file)
@@ -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();
index 8ebee42ab84d1cb3f0f1f85aedd657c87453c5e1..2cf1885235aca9c7468d0c9c533917b372e2eeda 100644 (file)
@@ -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];
        
index ca31fe21e4dd9ae63b53781276b68ef5e4b24520..fe3bbe64343a45aaad15990cbd7d742f55cba5bc 100644 (file)
@@ -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<strlen(source); ++i) {
+       len = strlen(source);
+       for (i=0; i<len; ++i) {
                if ( (isalnum(source[i])) || (source[i]=='-') || (source[i]=='_') ) {
                        target[target_length] = source[i];
                        target[++target_length] = 0;
@@ -52,13 +53,14 @@ void euid_escapize(char *target, char *source) {
  * string conversion function
  */
 void euid_unescapize(char *target, char *source) {
-       int a, b;
+       int a, b, len;
        char hex[3];
        int target_length = 0;
 
        strcpy(target, "");
 
-       for (a = 0; a < strlen(source); ++a) {
+       len = strlen(source);
+       for (a = 0; a < len; ++a) {
                if (source[a] == '=') {
                        hex[0] = source[a + 1];
                        hex[1] = source[a + 2];
@@ -93,7 +95,7 @@ void groupdav_main(struct httprequest *req,
        char dav_ifmatch[256];
        int dav_depth;
        char *ds;
-       int i;
+       int i, len;
 
        strcpy(dav_method, "");
        strcpy(dav_pathname, "");
@@ -102,7 +104,7 @@ void groupdav_main(struct httprequest *req,
 
        for (rptr=req; rptr!=NULL; rptr=rptr->next) {
                if (!strncasecmp(rptr->line, "Host: ", 6)) {
-                       if (strlen(WC->http_host) == 0) {
+                       if (IsEmptyStr(WC->http_host)) {
                                safestrncpy(WC->http_host, &rptr->line[6],
                                        sizeof WC->http_host);
                        }
@@ -160,13 +162,16 @@ void groupdav_main(struct httprequest *req,
         * If there's an If-Match: header, strip out the quotes if present, and
         * then if all that's left is an asterisk, make it go away entirely.
         */
-       if (strlen(dav_ifmatch) > 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; i<strlen(dav_ifmatch); ++i) {
+                       memmove (dav_ifmatch, &dav_ifmatch[1], len);
+                       len --;
+                       for (i=0; i<len; ++i) {
                                if (dav_ifmatch[i] == '\"') {
                                        dav_ifmatch[i] = 0;
+                                       len = i - 1;
                                }
                        }
                }
@@ -238,7 +243,7 @@ void groupdav_main(struct httprequest *req,
  * Output our host prefix for globally absolute URL's.
  */  
 void groupdav_identify_host(void) {
-       if (strlen(WC->http_host) > 0) {
+       if (!IsEmptyStr(WC->http_host)) {
                wprintf("%s://%s",
                        (is_https ? "https" : "http"),
                        WC->http_host);
index b92b79478285110ebb17db69061ee61138f96224..ce69b2c1bdba6e6311a415c29dabae4c8403eba8 100644 (file)
@@ -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) {
index 738ea266cb4851ea91d9c433c48c047c19fe2a3e..6d3092ae87951ed75033acbe09b675abbdcba9b8 100644 (file)
@@ -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("<response>");
                                wprintf("<href>");
                                        groupdav_identify_host();
index 21eaefbb858271711a7373f08fd70877c3cbbe4b..512896049242fc5e16e7a25fb2562548742876e7 100644 (file)
@@ -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);
index a69aab1602f967360582ab6c81c47c18acead2dc..15729cfdec32b5ccc70c1990ed70322187f0a922 100644 (file)
@@ -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);
index c7066cda9d06198263b4b3da9e9cc0408da69373..56989f73f3182404f2f5a3235df5ad095a043161 100644 (file)
@@ -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("</span><br />");
                wprintf("<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>\n");
-               if (strlen(ic_spec[which]) > 0) {
+               if (!IsEmptyStr(ic_spec[which])) {
                        for (i=0; i<num_tokens(ic_spec[which], '\n'); ++i) {
                                wprintf("<TR><TD ALIGN=LEFT>");
                                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);
                }
        }
index 0436a77a270abb0c7783ebff2052da8ed70f8b32..352687760a6c97726faebdec976bf9148efeadea 100644 (file)
@@ -48,7 +48,7 @@ void display_main_menu(void)
        wprintf(_("(come back here later)"));
        wprintf("</span></li>\n");
 
-       if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
+       if ((!IsEmptyStr(WC->ugname)) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
                wprintf("<li><a href=\"ungoto\">");
                wprintf(_("Ungoto"));
                wprintf("</a><span>");
@@ -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;
        }
index 9e469b271fe612c9621356fc08cf3097e412398b..2635365b21c7a3c98ac5fabcc1ae33d59cd0593a 100644 (file)
@@ -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<strlen(buf); ++i) {
+       len = strlen(buf);
+       for (i=0; i<len; ++i) {
                if ((buf[i] < 32) || (buf[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<strlen(source); ++i) {
+       len = strlen(source);
+       for (i=0; i<len; ++i) {
                if ((source[i] < 32) || (source[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<strlen(source); ++i) {
+       for (i=0; i<len; ++i) {
                ch = (unsigned char) source[i];
                if ((ch < 32) || (ch > 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; i<strlen(original_name); ++i) {
+       j=0;
+       for (i=0; i<len; ++i) {
                if (original_name[i] == ';') {
-                       strcat(name, ", ");
+                       name[j++] = ',';
+                       name[j++] = ' ';                        
                }
                else {
-                       name[strlen(name)+1] = 0;
-                       name[strlen(name)] = original_name[i];
+                       name[j++] = original_name[i];
                }
        }
+       name[j] = '\0';
        free(original_name);
 }
 
@@ -422,7 +427,7 @@ void display_parsed_vcard(struct vCard *v, int full) {
        for (pass=1; pass<=2; ++pass) {
 
                if (v->numprops) 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, "<br />");
+                               if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
                                strcat(mailto,
                                        "<a href=\"display_enter"
                                        "?force_room=_MAIL_?recp=");
@@ -496,7 +505,7 @@ void display_parsed_vcard(struct vCard *v, int full) {
                                strcat(mailto, "</A>");
                        }
                        else if (!strcasecmp(firsttoken, "tel")) {
-                               if (strlen(phone) > 0) strcat(phone, "<br />");
+                               if (!IsEmptyStr(phone)) strcat(phone, "<br />");
                                strcat(phone, thisvalue);
                                for (j=0; j<num_tokens(thisname, ';'); ++j) {
                                        extract_token(buf, thisname, j, ';', sizeof buf);
@@ -522,7 +531,7 @@ void display_parsed_vcard(struct vCard *v, int full) {
                                        wprintf("</TD><TD>");
                                        for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
                                                extract_token(buf, thisvalue, j, ';', sizeof buf);
-                                               if (strlen(buf) > 0) {
+                                               if (!IsEmptyStr(buf)) {
                                                        escputs(buf);
                                                        if (j<3) wprintf("<br />");
                                                        else wprintf(" ");
@@ -564,24 +573,24 @@ void display_parsed_vcard(struct vCard *v, int full) {
                        "<FONT SIZE=+1><B>");
                        escputs(fullname);
                        wprintf("</B></FONT>");
-                       if (strlen(title) > 0) {
+                       if (!IsEmptyStr(title)) {
                                wprintf("<div align=right>");
                                escputs(title);
                                wprintf("</div>");
                        }
-                       if (strlen(org) > 0) {
+                       if (!IsEmptyStr(org)) {
                                wprintf("<div align=right>");
                                escputs(org);
                                wprintf("</div>");
                        }
                        wprintf("</TD></TR>\n");
                
-                       if (strlen(phone) > 0) {
+                       if (!IsEmptyStr(phone)) {
                                wprintf("<tr><td>");
                                wprintf(_("Telephone:"));
                                wprintf("</td><td>%s</td></tr>\n", phone);
                        }
-                       if (strlen(mailto) > 0) {
+                       if (!IsEmptyStr(mailto)) {
                                wprintf("<tr><td>");
                                wprintf(_("E-mail:"));
                                wprintf("</td><td>%s</td></tr>\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&gt; ", &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("<div class=\"message_subject\">");
                wprintf(_("CC:"));
                wprintf(" ");
                escputs(m_cc);
                wprintf("</div>");
        }
-       if (strlen(m_subject) > 0) {
+       if (!IsEmptyStr(m_subject)) {
                wprintf("<div class=\"message_subject\">");
                wprintf(_("Subject:"));
                wprintf(" ");
@@ -1010,9 +1023,6 @@ void read_message(long msgnum, int printable_view, char *section) {
                wprintf("</div>");
        }
 
-
-
-
        /** Begin body */
        wprintf("<div class=\"message_content\">");
 
@@ -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("<i>");
                        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<strlen(mime_content_type); ++i) {
+                       len = strlen(mime_content_type);
+                       for (i=0; i<len; ++i) {
                                if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
                                        safestrncpy(mime_charset, &mime_content_type[i+8],
                                                sizeof mime_charset);
                                }
                        }
-                       for (i=0; i<strlen(mime_content_type); ++i) {
+                       for (i=0; i<len; ++i) {
                                if (mime_content_type[i] == ';') {
                                        mime_content_type[i] = 0;
+                                       len = i - 1;
                                }
                        }
-                       for (i=0; i<strlen(mime_charset); ++i) {
+                       len = strlen(mime_charset);
+                       for (i=0; i<len; ++i) {
                                if (mime_charset[i] == ';') {
                                        mime_charset[i] = 0;
+                                       len = i - 1;
                                }
                        }
                }
@@ -1077,8 +1092,10 @@ void read_message(long msgnum, int printable_view, char *section) {
        else if ( (!strcasecmp(mime_content_type, "text/plain"))
                || (!strcasecmp(mime_content_type, "text")) ) {
                while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                       if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
-                       if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
+                       int len;
+                       len = strlen(buf);
+                       if (buf[len-1] == '\n') buf[--len] = 0;
+                       if (buf[len-1] == '\r') buf[--len] = 0;
 
 #ifdef HAVE_ICONV
                        if (ic != (iconv_t)(-1) ) {
@@ -1094,8 +1111,9 @@ void read_message(long msgnum, int printable_view, char *section) {
                        }
 #endif
 
-                       while ((strlen(buf) > 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("<blockquote>");
@@ -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<num_tokens(mime_submessages, '|'); ++i) {
                        extract_token(buf, mime_submessages, i, '|', sizeof buf);
                        /** use printable_view to suppress buttons */
@@ -1147,7 +1165,7 @@ void read_message(long msgnum, int printable_view, char *section) {
        }
 
        /** Handler for vCard parts */
-       if (strlen(vcard_partnum) > 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&gt; ", &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<strlen(mime_content_type); ++i) {
@@ -1455,14 +1474,18 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
                                                sizeof mime_charset);
                                }
                        }
-                       for (i=0; i<strlen(mime_content_type); ++i) {
+                       len = strlen(mime_content_type);
+                       for (i=0; i<len; ++i) {
                                if (mime_content_type[i] == ';') {
                                        mime_content_type[i] = 0;
+                                       len = i - 1;
                                }
                        }
-                       for (i=0; i<strlen(mime_charset); ++i) {
+                       len = strlen(mime_charset);
+                       for (i=0; i<len; ++i) {
                                if (mime_charset[i] == ';') {
                                        mime_charset[i] = 0;
+                                       len = i - 1;
                                }
                        }
                }
@@ -1490,13 +1513,15 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
        /* Boring old 80-column fixed format text gets handled this way... */
        else if (!strcasecmp(mime_content_type, "text/plain")) {
                while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                       if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
-                       if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
+                       int len;
+                       len = strlen(buf);
+                       if (buf[len-1] == '\n') buf[--len] = 0;
+                       if (buf[len-1] == '\r') buf[--len] = 0;
 
 #ifdef HAVE_ICONV
                        if (ic != (iconv_t)(-1) ) {
                                ibuf = buf;
-                               ibuflen = strlen(ibuf);
+                               ibuflen = len;
                                obuflen = SIZ;
                                obuf = (char *) malloc(obuflen);
                                osav = obuf;
@@ -1507,8 +1532,9 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
                        }
 #endif
 
-                       while ((strlen(buf) > 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("<blockquote>");
@@ -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; i<strlen(namebuf); ++i) {
+       len = strlen(namebuf);
+       for (i=0; i<len; ++i) {
                if (namebuf[i] != ';') return;
        }
        strcpy(namebuf, _("(no name)"));
@@ -1969,11 +1996,11 @@ int load_msg_ptrs(char *servcmd, int with_headers)
                                WC->summ[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("<br>--<br>");
-                       for (i=0; i<strlen(buf); ++i) {
+                       len = strlen(buf);
+                       for (i=0; i<len; ++i) {
                                if (buf[i] == '\n') {
                                        wprintf("<br>");
                                }
@@ -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);
index e68f99c317d9b9fa02897bd9bf1d853d5f3484fe..223cd04f6de5b22f85a04bcbb5c3f24c3aad96e4 100644 (file)
@@ -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,
index 7479fb2b3a360ca527d07e46ef9403c69cf0cd0a..bfb9388708df9a24f15290e24daff3974ed741e6 100644 (file)
@@ -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);
index 38cd1b7def8b7f0fb341f755639579601119b384..76db3909bbd5d1c5f3b74440f68c3da9a7bb3907 100644 (file)
@@ -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("<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\">\n");
 
@@ -51,13 +51,14 @@ void display_note(long msgnum)
        }
 
        /** Now sanitize the buffer */
-       for (i=0; i<strlen(notetext); ++i) {
+       len = strlen(notetext);
+       for (i=0; i<len; ++i) {
                if (isspace(notetext[i])) notetext[i] = ' ';
        }
 
        /** Make it HTML-happy and print it. */
        stresc(display_notetext, notetext, 0, 0);
-       if (strlen(eid) > 0) {
+       if (!IsEmptyStr(eid)) {
                wprintf("<span id=\"note%s\">%s</span><br />\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("<script type=\"text/javascript\">"
                        "new Ajax.InPlaceEditor('note%s', 'updatenote?nonce=%ld?eid=%s', {rows:5,cols:72});"
                        "</script>\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; i<strlen(notetext); ++i) {
+                       len = strlen(notetext);
+                       for (i=0; i<len; ++i) {
                                if (isspace(notetext[i])) notetext[i] = ' ';
                        }
                
index 0932db026f6fc84f756de5455980816cf7869b7b..1e6a9e394ce3f3068fce6d8fad6ba79cde9cc639 100644 (file)
@@ -69,7 +69,7 @@ void page_user(void)
 
        safestrncpy(recp, bstr("recp"), sizeof recp);
 
-       if (strlen(bstr("send_button")) == 0) {
+       if (IsEmptyStr(bstr("send_button"))) {
                safestrncpy(WC->ImportantMessage,
                        _("Message was not sent."),
                        sizeof WC->ImportantMessage
@@ -339,10 +339,11 @@ void chat_recv(void) {
                wprintf("<img src=\"static/blank.gif\" onLoad=\"parent.window.close();\">\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, "");
index fac58a6b45e04ff3eadd69c9c87ff36ffb396941..b60d36dc8d11018348ac2845931c11fc3961ed5d 100644 (file)
@@ -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);
index 636334e69298927d0ffa1f13e6c645796bfe2f95..1efc8149ff3ed8eb37a78560cb4ef24032f0b896 100644 (file)
@@ -625,9 +625,9 @@ void embed_room_banner(char *got, int navbar_style) {
                                case VIEW_CALENDAR:
                                case VIEW_CALBRIEF:
                                        wprintf("<li class=\"addevent\"><a href=\"display_enter");
-                                       if (strlen(bstr("year")) > 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("\">"
                                                "<img align=\"middle\" src=\"static/addevent_24x.gif\" "
                                                "border=\"0\"><span class=\"navbar_link\">"
@@ -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("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
                for (i = 0; i < 128; ++i)
-                       if (strlen(floorlist[i]) > 0) {
+                       if (!IsEmptyStr(floorlist[i])) {
                                wprintf("<OPTION ");
                                if (i == er_floor)
                                        wprintf("SELECTED ");
@@ -1392,7 +1392,7 @@ void display_editroom(void)
                                shared_with = realloc(shared_with,
                                                strlen(shared_with) + 32);
                                strcat(shared_with, node);
-                               if (strlen(remote_room) > 0) {
+                               if (!IsEmptyStr(remote_room)) {
                                        strcat(shared_with, "|");
                                        strcat(shared_with, remote_room);
                                }
@@ -1434,13 +1434,13 @@ void display_editroom(void)
                        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) {
+                       if (!IsEmptyStr(node)) {
                                wprintf("<FORM METHOD=\"POST\" action=\"netedit\">");
                                wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
                                wprintf("<TR><TD>%s</TD>\n", node);
 
                                wprintf("<TD>");
-                               if (strlen(remote_room) > 0) {
+                               if (!IsEmptyStr(remote_room)) {
                                        escputs(remote_room);
                                }
                                wprintf("</TD>");
@@ -1450,7 +1450,7 @@ void display_editroom(void)
                                wprintf("<INPUT TYPE=\"hidden\" NAME=\"line\" "
                                        "VALUE=\"ignet_push_share|");
                                urlescputs(node);
-                               if (strlen(remote_room) > 0) {
+                               if (!IsEmptyStr(remote_room)) {
                                        wprintf("|");
                                        urlescputs(remote_room);
                                }
@@ -1477,7 +1477,7 @@ void display_editroom(void)
 
                for (i=0; i<num_tokens(not_shared_with, '\n'); ++i) {
                        extract_token(node, not_shared_with, i, '\n', sizeof node);
-                       if (strlen(node) > 0) {
+                       if (!IsEmptyStr(node)) {
                                wprintf("<FORM METHOD=\"POST\" action=\"netedit\">");
                                wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
                                wprintf("<TR><TD>");
@@ -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("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
         for (i = 0; i < 128; ++i)
-                if (strlen(floorlist[i]) > 0) {
+                if (!IsEmptyStr(floorlist[i])) {
                         wprintf("<OPTION ");
                         wprintf("VALUE=\"%d\">", i);
                         escputs(floorlist[i]);
@@ -2225,7 +2225,7 @@ void entroom(void)
        int er_num_type;
        int er_view;
 
-       if (strlen(bstr("ok_button")) == 0) {
+       if (IsEmptyStr(bstr("ok_button"))) {
                strcpy(WC->ImportantMessage,
                        _("Cancelled.  No new room was created."));
                display_main_menu();
@@ -2326,7 +2326,7 @@ void goto_private(void)
        char hold_rm[SIZ];
        char buf[SIZ];
 
-       if (strlen(bstr("ok_button")) == 0) {
+       if (IsEmptyStr(bstr("ok_button"))) {
                display_main_menu();
                return;
        }
@@ -2396,7 +2396,7 @@ void zap(void)
         */
        strcpy(final_destination, WC->wc_roomname);
 
-       if (strlen(bstr("ok_button")) > 0) {
+       if (!IsEmptyStr(bstr("ok_button"))) {
                serv_printf("GOTO %s", WC->wc_roomname);
                serv_getln(buf, sizeof buf);
                if (buf[0] == '2') {
@@ -2445,7 +2445,7 @@ void netedit(void) {
        char cmpb1[SIZ];
        int i, num_addrs;
 
-       if (strlen(bstr("line"))==0) {
+       if (IsEmptyStr(bstr("line"))) {
                display_editroom();
                return;
        }
@@ -2494,7 +2494,7 @@ void netedit(void) {
                serv_puts(buf);
        }
 
-       if (strlen(bstr("add_button")) > 0) {
+       if (!IsEmptyStr(bstr("add_button"))) {
                num_addrs = num_tokens(bstr("line"), ',');
                if (num_addrs < 2) {
                        /* just adding one node or address */
@@ -2529,7 +2529,7 @@ void netedit(void) {
  */
 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
 {
-       int i;
+       int i, len;
 
        /**
         * For mailboxes, just do it straight...
@@ -2548,7 +2548,8 @@ void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
        /**
         * Replace "\" characters with "|" for pseudo-folder-delimiting
         */
-       for (i=0; i<strlen(folder); ++i) {
+       len = strlen (folder);
+       for (i=0; i<len; ++i) {
                if (folder[i] == '\\') folder[i] = '|';
        }
 }
@@ -2623,8 +2624,10 @@ void do_folder_view(struct folder *fold, int max_folders, int num_floors) {
 
                has_subfolders = 0;
                if ((i+1) < max_folders) {
-                       if ( (!strncasecmp(fold[i].name, fold[i+1].name, strlen(fold[i].name)))
-                          && (fold[i+1].name[strlen(fold[i].name)] == '|') ) {
+                       int len;
+                       len = strlen(fold[i].name);
+                       if ( (!strncasecmp(fold[i].name, fold[i+1].name, len))
+                          && (fold[i+1].name[len] == '|') ) {
                                has_subfolders = 1;
                        }
                }
@@ -2739,7 +2742,7 @@ void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
                        '|', sizeof floor_name);
 
                if ( (strcasecmp(floor_name, old_floor_name))
-                  && (strlen(old_floor_name) > 0) ) {
+                  && (!IsEmptyStr(old_floor_name)) ) {
                        /* End inner box */
                        do_template("endbox");
 
@@ -2839,7 +2842,7 @@ void do_iconbar_view(struct folder *fold, int max_folders, int num_floors) {
                        '|', sizeof floor_name);
 
                if ( (strcasecmp(floor_name, old_floor_name))
-                  && (strlen(old_floor_name) > 0) ) {
+                  && (!IsEmptyStr(old_floor_name)) ) {
                        /** End inner box */
                        wprintf("<br>\n");
                        wprintf("</div>\n");    /** floordiv */
@@ -2940,7 +2943,8 @@ void do_iconbar_view(struct folder *fold, int max_folders, int num_floors) {
        }
 
        wprintf("num_drop_targets = %d;\n", num_drop_targets);
-       if (strlen(WC->floordiv_expanded) > 1) {
+       if ((WC->floordiv_expanded[0] != '\0')&&
+           (WC->floordiv_expanded[1] != '\0')){
                wprintf("which_div_expanded = '%s';\n", WC->floordiv_expanded);
        }
 
@@ -3105,7 +3109,7 @@ void knrooms(void)
 
        /** Determine whether the user is trying to change views */
        if (bstr("view") != NULL) {
-               if (strlen(bstr("view")) > 0) {
+               if (!IsEmptyStr(bstr("view"))) {
                        set_preference("roomlistview", bstr("view"), 1);
                }
        }
@@ -3171,7 +3175,7 @@ void knrooms(void)
 void set_room_policy(void) {
        char buf[SIZ];
 
-       if (strlen(bstr("ok_button")) == 0) {
+       if (IsEmptyStr(bstr("ok_button"))) {
                strcpy(WC->ImportantMessage,
                        _("Cancelled.  Changes were not saved."));
                display_editroom();
index 6a962559a27b9b6f95ead77cc68ac6dd9096f76b..f34c4920953dea4306805edb3940b729b885b959 100644 (file)
@@ -214,7 +214,7 @@ void display_rss(char *roomname, char *request_method)
                }
                wprintf(" %s", from);
                wprintf(" in %s", room);
-               if (strcmp(hnod, serv_info.serv_humannode) && strlen(hnod) > 0) {
+               if (strcmp(hnod, serv_info.serv_humannode) && !IsEmptyStr(hnod)) {
                        wprintf(" on %s", hnod);
                }
                wprintf("</title>\n");
@@ -224,20 +224,23 @@ void display_rss(char *roomname, char *request_method)
                wprintf("      <guid isPermaLink=\"false\">%s</guid>\n", msgn);
                /** Now the hard part, the message itself */
                strcpy(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")) {
                                goto ENDBODY;
                        }
                        if (!strncasecmp(buf, "Content-type: ", 14)) {
+                               int len;
                                safestrncpy(content_type, &buf[14], sizeof content_type);
-                               for (b = 0; b < strlen(content_type); ++b) {
+                               len = strlen (content_type);
+                               for (b = 0; b < len; ++b) {
                                        if (!strncasecmp(&content_type[b], "charset=", 8)) {
                                                safestrncpy(charset, &content_type[b + 8], sizeof charset);
                                        }
                                }
-                               for (b = 0; b < strlen(content_type); ++b) {
+                               for (b = 0; b < len; ++b) {
                                        if (content_type[b] == ';') {
                                                content_type[b] = 0;
+                                               len = b - 1;
                                        }
                                }
                        }
@@ -290,13 +293,15 @@ void display_rss(char *roomname, char *request_method)
                else if (!strcasecmp(content_type, "text/plain")) {
                        wprintf("      <description><![CDATA[");
                        while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                               if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
-                               if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
+                               int len;
+                               len = strlen(buf);
+                               if (buf[len-1] == '\n') buf[--len] = 0;
+                               if (buf[len-1] == '\r') buf[--len] = 0;
        
 #ifdef HAVE_ICONV
                                if (ic != (iconv_t)(-1) ) {
                                        ibuf = buf;
-                                       ibuflen = strlen(ibuf);
+                                       ibuflen = len;
                                        obuflen = SIZ;
                                        obuf = (char *) malloc(obuflen);
                                        osav = obuf;
@@ -306,9 +311,9 @@ void display_rss(char *roomname, char *request_method)
                                        free(osav);
                                }
 #endif
-
-                               while ((strlen(buf) > 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)) || (!strncmp(buf, " :-)", 4)))) {
                                        wprintf("<blockquote>");
index d5a54d95559f9b3833464e8d2e1459d04c05e830..12c349dd875e18162b0750ae0280ed0fd655c52b 100644 (file)
@@ -198,7 +198,7 @@ void pullquote_fmout(void) {
 void text_to_server(char *ptr)
 {
        char buf[256];
-       int ch, a, pos;
+       int ch, a, pos, len;
 
        pos = 0;
        buf[0] = 0;
@@ -206,9 +206,11 @@ void text_to_server(char *ptr)
        while (ptr[pos] != 0) {
                ch = ptr[pos++];
                if (ch == 10) {
-                       while ( (isspace(buf[strlen(buf) - 1]))
-                         && (strlen(buf) > 1) )
-                               buf[strlen(buf) - 1] = 0;
+                       len = strlen(buf);
+                       while ( (isspace(buf[len - 1]))
+                               && (buf[0] !=  '\0') 
+                               && (buf[1] !=  '\0') )
+                               buf[--len] = 0;
                        serv_puts(buf);
                        buf[0] = 0;
                        if (ptr[pos] != 0) strcat(buf, " ");
index 929faafc598eb3f01981d492b2311fe0d7a056cb..352c9e76706458188cebc256f7b7b254ba57059b 100644 (file)
@@ -197,10 +197,11 @@ void display_sieve(void)
  * \brief      Helper function for output_sieve_rule() to output strings with quotes escaped
  */
 void osr_sanitize(char *str) {
-       int i;
+       int i, len;
 
        if (str == NULL) return;
-       for (i=0; i<strlen(str); ++i) {
+       len = strlen(str);
+       for (i=0; i<len; ++i) {
                if (str[i]=='\"') {
                        str[i] = '\'' ;
                }
@@ -519,7 +520,7 @@ void save_sieve(void) {
        char this_name[64];
        char buf[256];
 
-       if (strlen(bstr("save_button")) == 0) {
+       if (IsEmptyStr(bstr("save_button"))) {
                strcpy(WC->ImportantMessage,
                        _("Cancelled.  Changes were not saved."));
                display_main_menu();
index d51ec4d78c67940ab1fc4a5f44b59eea97d1f237..b7d6011b20201cdb45619a7b5858fd7b1ae989e8 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * $Id$
+ * $Id$
  */
 /**
  * \defgroup SMTPqueue Display the outbound SMTP queue
@@ -26,6 +26,7 @@ void display_queue_msg(long msgnum)
        char thisrecp[256];
        char thisdsn[256];
        long msgid = 0;
+       int len;
 
        strcpy(sender, "");
        strcpy(recipients, "");
@@ -36,13 +37,14 @@ void display_queue_msg(long msgnum)
 
        while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
 
-               if (strlen(buf) > 0) {
-                       if (buf[strlen(buf)-1] == 13) {
-                               buf[strlen(buf)-1] = 0;
+               if (!IsEmptyStr(buf)) {
+                       len = strlen(buf);
+                       if (buf[len - 1] == 13) {
+                               buf[len - 1] = 0;
                        }
                }
 
-               if ( (strlen(buf) == 0) && (in_body == 0) ) {
+               if ( (IsEmptyStr(buf) == 0) && (in_body == 0) ) {
                        in_body = 1;
                }
 
@@ -99,7 +101,7 @@ void display_queue_msg(long msgnum)
 
                                if (strlen(recipients) + strlen(thisrecp) + strlen(thisdsn) + 100
                                   < sizeof recipients) {
-                                       if (strlen(recipients) > 0) {
+                                       if (!IsEmptyStr(recipients)) {
                                                strcat(recipients, "<br />");
                                        }
                                        stresc(&recipients[strlen(recipients)], thisrecp, 1, 1);
index f4222ccb14d51c8f9b35512eb43069f3ce04d43f..3bc886653b15f99747b0ad65111e68e0761f37dd 100644 (file)
@@ -75,7 +75,7 @@ void save_edit(char *description, char *enter_cmd, int regoto)
 {
        char buf[SIZ];
 
-       if (strlen(bstr("save_button")) == 0) {
+       if (IsEmptyStr(bstr("save_button"))) {
                sprintf(WC->ImportantMessage,
                        _("Cancelled.  %s was not saved."),
                        description);
index 98c3bb584a8405d8fe61024223d03bfa6926326b..1078e8beda7728c8b001fe6093ca8f25031d0827 100644 (file)
@@ -47,10 +47,12 @@ int num_tokens(char *source, char tok)
 {
        int a = 0;
        int count = 1;
+       int len;
 
        if (source == NULL)
                return (0);
-       for (a = 0; a < strlen(source); ++a) {
+       len = strlen(source);
+       for (a = 0; a < len; ++a) {
                if (source[a] == tok)
                        ++count;
        }
@@ -186,9 +188,10 @@ long extract_long(const char *source, int parmnum)
  */
 int haschar(char *st,char ch)
 {
-       int a, b;
+       int a, b, len;
        b = 0;
-       for (a = 0; a < strlen(st); ++a)
+       len = strlen(st);
+       for (a = 0; a < len; ++a)
                if (st[a] == ch)
                        ++b;
        return (b);
@@ -213,10 +216,9 @@ char *memreadline(char *start, char *buf, int maxlen)
 
        while (1) {
                ch = *ptr++;
-               if ((len < (maxlen - 1)) && (ch != 13) && (ch != 10)) {
-                       buf[strlen(buf) + 1] = 0;
-                       buf[strlen(buf)] = ch;
-                       ++len;
+               if ((len + 1 < (maxlen)) && (ch != 13) && (ch != 10)) {
+                       buf[len++] = ch;
+                       buf[len] = 0;
                }
                if ((ch == 10) || (ch == 0)) {
                        return ptr;
@@ -235,33 +237,47 @@ char *memreadline(char *start, char *buf, int maxlen)
 int pattern2(char *search, char *patn)
 {
        int a;
-       for (a = 0; a < strlen(search); ++a) {
-               if (!strncasecmp(&search[a], patn, strlen(patn)))
+       int len, plen;
+       len = strlen (search);
+       plen = strlen (patn);
+       for (a = 0; a < len; ++a) {
+               if (!strncasecmp(&search[a], patn, plen))
                        return (a);
        }
        return (-1);
 }
 
 
+/**
+ * \brief Strip leading and trailing spaces from a string; with premeasured and adjusted length.
+ * \param buf the string to modify
+ * \param len length of the string. 
+ */
+void stripltlen(char *buf, int *len)
+{
+       int delta = 0;
+       if (*len == 0) return;
+       while ((*len > delta) && (isspace(buf[delta]))){
+               delta ++;
+       }
+       memmove (buf, &buf[delta], *len - delta + 1);
+       (*len) -=delta;
+
+       if (*len == 0) return;
+       while (isspace(buf[(*len) - 1])){
+               buf[--(*len)] = '\0';
+       }
+}
+
 /**
  * \brief Strip leading and trailing spaces from a string
  * \param buf the string to modify
  */
 void striplt(char *buf)
 {
-       long len;
-
+       int len;
        len = strlen(buf);
-       if (len == 0) return;
-       while ((len > 0) && (isspace(buf[0]))){
-               memmove (buf, &buf[1], len);
-               len --;
-       }
-       if (len == 0) return;
-       while (isspace(buf[len - 1])){
-               buf[len - 1] = 0;
-               len --;
-       }
+       stripltlen(buf, &len);
 }
 
 
@@ -323,12 +339,13 @@ void stripout(char *str, char leftboundary, char rightboundary)
        int a;
        int lb = (-1);
        int rb = (-1);
+       int len = strlen(str);
 
        do {
                lb = (-1);
                rb = (-1);
 
-               for (a = 0; a < strlen(str); ++a) {
+               for (a = 0; a < len; ++a) {
                        if (str[a] == leftboundary)
                                lb = a;
                        if (str[a] == rightboundary)
@@ -336,7 +353,8 @@ void stripout(char *str, char leftboundary, char rightboundary)
                }
 
                if ((lb > 0) && (rb > lb)) {
-                       strcpy(&str[lb - 1], &str[rb + 1]);
+                       memmove(&str[lb - 1], &str[rb + 1], len - rb);
+                       len -= (rb - lb + 2);
                }
 
        } while ((lb > 0) && (rb > lb));
index 06b54b1759955d04e0dd232431d4782076e03ac9..a69787c07e5fcd2070dba2842327303d44b10495 100644 (file)
@@ -268,12 +268,12 @@ void display_edituser(char *supplied_username, int is_new) {
        lastcall = extract_long(&buf[4], 7);
        purgedays = extract_long(&buf[4], 8);
 
-       if (strlen(bstr("edit_abe_button")) > 0) {
+       if (!IsEmptyStr(bstr("edit_abe_button"))) {
                display_edit_address_book_entry(username, usernum);
                return;
        }
 
-       if (strlen(bstr("delete_button")) > 0) {
+       if (!IsEmptyStr(bstr("delete_button"))) {
                delete_user(username);
                return;
        }
@@ -401,7 +401,7 @@ void edituser(void) {
 
        is_new = atoi(bstr("is_new"));
 
-       if (strlen(bstr("ok_button")) == 0) {
+       if (IsEmptyStr(bstr("ok_button"))) {
                safestrncpy(message, _("Changes were not saved."), sizeof message);
        }
        else {
index 65dfd1c0fc5cbd632eb0b1f0fac6c2ab2a5cb25e..50675cc5353585a46753973b1f89e12e1e72eee6 100644 (file)
@@ -48,9 +48,11 @@ void remove_charset_attribute(char *strbuf)
                        remove_token(strbuf, i, ';');
                }
        }
-       if (strlen(strbuf) > 0) {
-               if (strbuf[strlen(strbuf)-1] == ';') {
-                       strbuf[strlen(strbuf)-1] = 0;
+       if (!IsEmptyStr(strbuf)) {
+               int len;
+               len = strlen(strbuf);
+               if (strbuf[len-1] == ';') {
+                       strbuf[len-1] = 0;
                }
        }
 }
@@ -180,13 +182,15 @@ char *vcard_get_prop(struct vCard *v, char *propname,
                        int is_partial, int instance, int get_propname) {
        int i;
        int found_instance = 0;
+       int len;
 
+       len = strlen(propname);
        if (v->numprops) for (i=0; i<(v->numprops); ++i) {
                if ( (!strcasecmp(v->prop[i].name, propname))
                   || (propname[0] == 0)
                   || (  (!strncasecmp(v->prop[i].name,
-                                       propname, strlen(propname)))
-                        && (v->prop[i].name[strlen(propname)] == ';')
+                                       propname, len))
+                        && (v->prop[i].name[len] == ';')
                         && (is_partial) ) ) {
                        if (instance == found_instance++) {
                                if (get_propname) {
index a0d143636a1062bbaf2f25f3cad4962f5a049c31..24a0c14e33b32ad66a8c96ff8a80859d9d2ce2a4 100644 (file)
@@ -363,7 +363,7 @@ void submit_vcard(void) {
        char buf[SIZ];
        int i;
 
-       if (strlen(bstr("ok_button")) == 0) { 
+       if (IsEmptyStr(bstr("ok_button"))) { 
                readloop("readnew");
                return;
        }
@@ -419,7 +419,7 @@ void submit_vcard(void) {
 
        for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
                extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
-               if (strlen(buf) > 0) {
+               if (!IsEmptyStr(buf)) {
                        vcard_add_prop(v, "email;internet", buf);
                }
        }
index 0368e6429cc27bfde7db3f3c00b6a7425906ad39..785d2287caaf82fec97fc798b4aa1f625c4067dc 100644 (file)
@@ -63,11 +63,11 @@ void addurls(char *url)
 {
        char *up, *ptr;
        char buf[SIZ];
-       int a, b;
+       int a, b, len;
        struct urlcontent *u;
 
        up = url;
-       while (strlen(up) > 0) {
+       while (!IsEmptyStr(up)) {
 
                /** locate the = sign */
                safestrncpy(buf, up, sizeof buf);
@@ -90,21 +90,20 @@ void addurls(char *url)
 
                /** locate "&" and "?" delimiters */
                ptr = up;
-               b = strlen(up);
-               for (a = 0; a < strlen(up); ++a) {
+               len = b = strlen(up);
+               for (a = 0; a < len; ++a) {
                        if ( (ptr[0] == '&') || (ptr[0] == '?') ) {
                                b = a;
                                break;
                        }
                        ++ptr;
                }
-               ptr = up;
-               for (a = 0; a < b; ++a)
-                       ++ptr;
-               strcpy(ptr, "");
+               ptr = up + b;
+               *ptr = '\0';
 
-               u->url_data = malloc(strlen(up) + 2);
-               safestrncpy(u->url_data, up, strlen(up) + 1);
+               len = b;
+               u->url_data = malloc(len + 2);
+               safestrncpy(u->url_data, up, b + 1);
                u->url_data[b] = 0;
                unescape_input(u->url_data);
                up = ptr;
@@ -204,10 +203,11 @@ void wDumpContent(int print_standard_html_footer)
  */
 void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks)
 {
-       int a;
+       int a, len;
        strcpy(target, "");
 
-       for (a = 0; a < strlen(strbuf); ++a) {
+       len = strlen(strbuf);
+       for (a = 0; a < len; ++a) {
                if (strbuf[a] == '<')
                        strcat(target, "&lt;");
                else if (strbuf[a] == '>')
@@ -268,23 +268,27 @@ void escputs(char *strbuf)
  */
 void urlesc(char *outbuf, char *strbuf)
 {
-       int a, b, c;
+       int a, b, c, len, eclen, olen;
        char *ec = " #&;`'|*?-~<>^()[]{}/$\"\\";
 
        strcpy(outbuf, "");
-
-       for (a = 0; a < strlen(strbuf); ++a) {
+       len = strlen(strbuf);
+       eclen = strlen(ec);
+       olen = 0;
+       for (a = 0; a < len; ++a) {
                c = 0;
-               for (b = 0; b < strlen(ec); ++b) {
+               for (b = 0; b < eclen; ++b) {
                        if (strbuf[a] == ec[b])
                                c = 1;
                }
-               b = strlen(outbuf);
-               if (c == 1)
-                       sprintf(&outbuf[b], "%%%02x", strbuf[a]);
-               else
-                       sprintf(&outbuf[b], "%c", strbuf[a]);
+               if (c == 1) {
+                       sprintf(&outbuf[olen], "%%%02x", strbuf[a]);
+                       olen += 3;
+               }
+               else 
+                       outbuf[olen ++] = strbuf[a];
        }
+       outbuf[olen] = '\0';
 }
 
 /**
@@ -307,10 +311,11 @@ void urlescputs(char *strbuf)
  */
 void jsesc(char *target, char *strbuf)
 {
-       int a;
-       strcpy(target, "");
+       int a, len;
 
-       for (a = 0; a < strlen(strbuf); ++a) {
+       target[0]='\0';
+       len = strlen (strbuf);
+       for (a = 0; a < len; ++a) {
                if (strbuf[a] == '<')
                        strcat(target, "[");
                else if (strbuf[a] == '>')
@@ -346,10 +351,11 @@ void jsescputs(char *strbuf)
  */
 void msgesc(char *target, char *strbuf)
 {
-       int a;
-       strcpy(target, "");
+       int a, len;
 
-       for (a = 0; a < strlen(strbuf); ++a) {
+       *target='\0';
+       len = strlen(strbuf);
+       for (a = 0; a < len; ++a) {
                if (strbuf[a] == '\n')
                        strcat(target, " ");
                else if (strbuf[a] == '\r')
@@ -448,7 +454,7 @@ void output_headers(        int do_httpheaders,     /**< 1 = output HTTP headers
 
 
                /** check for ImportantMessages (these display in a div overlaying the main screen) */
-               if (strlen(WC->ImportantMessage) > 0) {
+               if (!IsEmptyStr(WC->ImportantMessage)) {
                        wprintf("<div id=\"important_message\">\n");
                        wprintf("<span class=\"imsg\">"
                                "%s</span><br />\n", WC->ImportantMessage);
@@ -556,6 +562,7 @@ void output_static(char *what)
        off_t bytes;
        char *bigbuffer;
        char content_type[128];
+       int len;
 
        fp = fopen(what, "rb");
        if (fp == NULL) {
@@ -565,33 +572,34 @@ void output_static(char *what)
                wprintf("\r\n");
                wprintf("Cannot open %s: %s\n", what, strerror(errno));
        } else {
-               if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
+               len = strlen (what);
+               if (!strncasecmp(&what[len - 4], ".gif", 4))
                        safestrncpy(content_type, "image/gif", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
+               else if (!strncasecmp(&what[len - 4], ".txt", 4))
                        safestrncpy(content_type, "text/plain", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 4], ".css", 4))
+               else if (!strncasecmp(&what[len - 4], ".css", 4))
                        safestrncpy(content_type, "text/css", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
+               else if (!strncasecmp(&what[len - 4], ".jpg", 4))
                        safestrncpy(content_type, "image/jpeg", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
+               else if (!strncasecmp(&what[len - 4], ".png", 4))
                        safestrncpy(content_type, "image/png", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 4], ".ico", 4))
+               else if (!strncasecmp(&what[len - 4], ".ico", 4))
                        safestrncpy(content_type, "image/x-icon", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
+               else if (!strncasecmp(&what[len - 5], ".html", 5))
                        safestrncpy(content_type, "text/html", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 4], ".htm", 4))
+               else if (!strncasecmp(&what[len - 4], ".htm", 4))
                        safestrncpy(content_type, "text/html", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
+               else if (!strncasecmp(&what[len - 4], ".wml", 4))
                        safestrncpy(content_type, "text/vnd.wap.wml", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
+               else if (!strncasecmp(&what[len - 5], ".wmls", 5))
                        safestrncpy(content_type, "text/vnd.wap.wmlscript", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 5], ".wmlc", 5))
+               else if (!strncasecmp(&what[len - 5], ".wmlc", 5))
                        safestrncpy(content_type, "application/vnd.wap.wmlc", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
+               else if (!strncasecmp(&what[len - 6], ".wmlsc", 6))
                        safestrncpy(content_type, "application/vnd.wap.wmlscriptc", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
+               else if (!strncasecmp(&what[len - 5], ".wbmp", 5))
                        safestrncpy(content_type, "image/vnd.wap.wbmp", sizeof content_type);
-               else if (!strncasecmp(&what[strlen(what) - 3], ".js", 3))
+               else if (!strncasecmp(&what[len - 3], ".js", 3))
                        safestrncpy(content_type, "text/javascript", sizeof content_type);
                else
                        safestrncpy(content_type, "application/octet-stream", sizeof content_type);
@@ -858,7 +866,7 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
        lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
 
        /* Form fields */
-       if ( (length > 0) && (strlen(cbtype) == 0) ) {
+       if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
                u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
                u->next = WC->urlstrings;
                WC->urlstrings = u;
@@ -870,7 +878,7 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
        }
 
        /** Uploaded files */
-       if ( (length > 0) && (strlen(cbtype) > 0) ) {
+       if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
                WC->upload = malloc(length);
                if (WC->upload != NULL) {
                        WC->upload_length = length;
@@ -1020,6 +1028,7 @@ void session_loop(struct httprequest *req)
        int body_start = 0;
        int is_static = 0;
        int n_static = 0;
+       int len = 0;
        /**
         * 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.
@@ -1108,7 +1117,7 @@ void session_loop(struct httprequest *req)
                        }
                }
                else if (!strncasecmp(buf, "Host: ", 6)) {
-                       if (strlen(WC->http_host) == 0) {
+                       if (IsEmptyStr(WC->http_host)) {
                                safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
                        }
                }
@@ -1152,13 +1161,18 @@ void session_loop(struct httprequest *req)
        remove_token(WC->this_page, 0, ' ');
 
        /** If there are variables in the URL, we must grab them now */
-       for (a = 0; a < strlen(cmd); ++a) {
+       len = strlen(cmd);
+       for (a = 0; a < len; ++a) {
                if ((cmd[a] == '?') || (cmd[a] == '&')) {
-                       for (b = a; b < strlen(cmd); ++b)
-                               if (isspace(cmd[b]))
+                       for (b = a; b < len; ++b) {
+                               if (isspace(cmd[b])){
                                        cmd[b] = 0;
+                                       len = b - 1;
+                               }
+                       }
                        addurls(&cmd[a + 1]);
                        cmd[a] = 0;
+                       len = a - 1;
                }
        }
 
@@ -1350,8 +1364,8 @@ void session_loop(struct httprequest *req)
         * supplied by the browser, try using them to log in.
         */
        if ((!WC->logged_in)
-          && (strlen(c_username) > 0)
-          && (strlen(c_password) > 0)) {
+          && (!IsEmptyStr(c_username))
+          && (!IsEmptyStr(c_password))) {
                serv_printf("USER %s", c_username);
                serv_getln(buf, sizeof buf);
                if (buf[0] == '3') {
@@ -1366,7 +1380,7 @@ void session_loop(struct httprequest *req)
         * If we don't have a current room, but a cookie specifying the
         * current room is supplied, make an effort to go there.
         */
-       if ((strlen(WC->wc_roomname) == 0) && (strlen(c_roomname) > 0)) {
+       if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
                serv_printf("GOTO %s", c_roomname);
                serv_getln(buf, sizeof buf);
                if (buf[0] == '2') {
index b1d7e2f2c60afecaa4c6c2aa8442be8cb704bc2b..e4ae3b7d7b20f5c1d7d75c0b3f3ce6690be81767 100644 (file)
@@ -53,6 +53,7 @@ extern locale_t wc_locales[];
 #define _(string)      (string)
 #endif
 
+#define IsEmptyStr(a) ((a)[0] == '\0')
 /*
  * Uncomment to dump an HTTP trace to stderr
 #define HTTP_TRACING 1
@@ -590,6 +591,7 @@ void do_edit_vcard(long, char *, char *);
 void edit_vcard(void);
 void submit_vcard(void);
 void striplt(char *);
+void stripltlen(char *, int *);
 void select_user_to_edit(char *message, char *preselect);
 void delete_user(char *);
 void display_edituser(char *who, int is_new);
index 012ec470d825411a32d4be1231e4bc6085587cc7..b56e15bdd40a142ef65d355f96234632c8a7a9ac 100644 (file)
@@ -444,8 +444,8 @@ int client_getln(int sock, char *buf, int bufsiz)
         * Strip any trailing non-printable characters.
         */
        buf[i] = 0;
-       while ((strlen(buf) > 0) && (!isprint(buf[strlen(buf) - 1]))) {
-               buf[strlen(buf) - 1] = 0;
+       while ((i > 0) && (!isprint(buf[i - 1]))) {
+               buf[--i] = 0;
        }
        return (retval);
 }
@@ -787,7 +787,7 @@ int main(int argc, char **argv)
         * exits if it doesn't succeed.
         */
 
-       if (strlen(uds_listen_path) > 0) {
+       if (!IsEmptyStr(uds_listen_path)) {
                lprintf(2, "Attempting to create listener socket at %s...\n", uds_listen_path);
                msock = ig_uds_server(uds_listen_path, LISTEN_QUEUE_LENGTH);
        }
index 3ac20bc3865a075d45d7f1c9c17813056ca80d8d..f5de0ddf32a0f0302ac571a8fa9c420550e53120 100644 (file)
@@ -105,7 +105,7 @@ void who_inner_div(void) {
                        /** room */
                        wprintf("</td>\n\t<td>");
                        escputs(room);
-                       if (strlen(realroom) > 0) {
+                       if (!IsEmptyStr(realroom) ) {
                                wprintf("<br /><i>");
                                escputs(realroom);
                                wprintf("</i>");
@@ -114,7 +114,7 @@ void who_inner_div(void) {
 
                        /** hostname */
                        escputs(host);
-                       if (strlen(realhost) > 0) {
+                       if (!IsEmptyStr(realhost)) {
                                wprintf("<br /><i>");
                                escputs(realhost);
                                wprintf("</i>");
@@ -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);
index 0f35b6150a2a8b00e8b689c138fbf613ec9bd034..40fe296fbbe0548c1d7aadb34f904e2d5fd6b295 100644 (file)
@@ -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");
        }