More ast_strlen_zero changes
authorJames Golovich <james@gnuinter.net>
Sun, 9 May 2004 07:51:44 +0000 (07:51 +0000)
committerJames Golovich <james@gnuinter.net>
Sun, 9 May 2004 07:51:44 +0000 (07:51 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2930 65c4cc65-6c06-0410-ace0-fbb531ad65f3

13 files changed:
apps/app_directory.c
apps/app_enumlookup.c
apps/app_festival.c
apps/app_groupcount.c
apps/app_playback.c
apps/app_queue.c
apps/app_read.c
apps/app_senddtmf.c
apps/app_setcdruserfield.c
apps/app_setcidname.c
apps/app_setcidnum.c
channels/chan_agent.c
frame.c

index 8f0de92..b267559 100755 (executable)
@@ -19,6 +19,7 @@
 #include <asterisk/module.h>
 #include <asterisk/config.h>
 #include <asterisk/say.h>
+#include <asterisk/utils.h>
 #include <string.h>
 #include <ctype.h>
 #include <stdlib.h>
@@ -132,7 +133,7 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *
        char *start, *pos, *conv,*stringp=NULL;
        char fn[256];
        char fn2[256];
-       if (!context || !strlen(context)) {
+       if (!context || ast_strlen_zero(context)) {
                ast_log(LOG_WARNING, "Directory must be called with an argument (context in which to interpret extensions)\n");
                return -1;
        }
@@ -190,7 +191,7 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *
                                                res = ast_waitstream(chan, AST_DIGIT_ANY);
                                        ast_stopstream(chan);
                                } else {
-                                       res = ast_say_character_str(chan, strlen(name) ? name : v->name, AST_DIGIT_ANY, chan->language);
+                                       res = ast_say_character_str(chan, !ast_strlen_zero(name) ? name : v->name, AST_DIGIT_ANY, chan->language);
                                }
 ahem:
                                if (!res)
@@ -260,9 +261,9 @@ top:
        } else
                dialcontext = context;
        dirintro = ast_variable_retrieve(cfg, context, "directoryintro");
-       if (!dirintro || !strlen(dirintro))
+       if (!dirintro || ast_strlen_zero(dirintro))
                dirintro = ast_variable_retrieve(cfg, "general", "directoryintro");
-       if (!dirintro || !strlen(dirintro))
+       if (!dirintro || ast_strlen_zero(dirintro))
                dirintro = "dir-intro";
        if (chan->_state != AST_STATE_UP) 
                res = ast_answer(chan);
index c03eb97..148477e 100755 (executable)
@@ -20,6 +20,7 @@
 #include <asterisk/config.h>
 #include <asterisk/module.h>
 #include <asterisk/enum.h>
+#include <asterisk/utils.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -64,7 +65,7 @@ static int enumlookup_exec(struct ast_channel *chan, void *data)
        char tmp[256];
        char *c,*t;
        struct localuser *u;
-       if (!data || !strlen(data)) {
+       if (!data || ast_strlen_zero(data)) {
                ast_log(LOG_WARNING, "EnumLookup requires an argument (extension)\n");
                res = 1;
        }
@@ -128,7 +129,7 @@ static int enumlookup_exec(struct ast_channel *chan, void *data)
                                else
                                        res = 0;
                        }
-               } else if (strlen(tech)) {
+               } else if (!ast_strlen_zero(tech)) {
                        ast_log(LOG_NOTICE, "Don't know how to handle technology '%s'\n", tech);
                        res = 0;
                }
index 99b6226..3076d9a 100755 (executable)
@@ -19,6 +19,7 @@
 #include <asterisk/module.h>
 #include <asterisk/md5.h>
 #include <asterisk/config.h>
+#include <asterisk/utils.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -304,10 +305,7 @@ static int festival_exec(struct ast_channel *chan, void *vdata)
        if (!(festivalcommand = ast_variable_retrieve(cfg, "general", "festivalcommand"))) {
                festivalcommand = "(tts_textasterisk \"%s\" 'file)(quit)\n";
        }
-       
-               
-
-       if (!vdata || !strlen(vdata)) {
+       if (!vdata || ast_strlen_zero(vdata)) {
                ast_log(LOG_WARNING, "festival requires an argument (text)\n");
                return -1;
        }
index 778a139..ef7b92c 100755 (executable)
@@ -21,6 +21,7 @@
 #include <asterisk/channel.h>
 #include <asterisk/pbx.h>
 #include <asterisk/module.h>
+#include <asterisk/utils.h>
 
 static char *tdesc = "Group Management Routines";
 
@@ -64,7 +65,7 @@ static int group_get_count(char *group)
        struct ast_channel *chan;
        int count = 0;
        char *test;
-       if (group && strlen(group)) {
+       if (group && !ast_strlen_zero(group)) {
                chan = ast_channel_walk(NULL);
                while(chan) {
                        test = pbx_builtin_getvar_helper(chan, "GROUP");
@@ -87,7 +88,7 @@ static int group_count_exec(struct ast_channel *chan, void *data)
        LOCAL_USER_ADD(u);
 
        /* Check and parse arguments */
-       if (data && strlen(data)) {
+       if (data && !ast_strlen_zero(data)) {
                group = (char *)data;
        } else {
                group = pbx_builtin_getvar_helper(chan, "GROUP");
@@ -106,7 +107,7 @@ static int group_set_exec(struct ast_channel *chan, void *data)
 
        LOCAL_USER_ADD(u);
        /* Check and parse arguments */
-       if (data && strlen(data)) {
+       if (data && !ast_strlen_zero(data)) {
                pbx_builtin_setvar_helper(chan, "GROUP", (char *)data);
        } else
                ast_log(LOG_WARNING, "GroupSet requires an argument (group name)\n");
index aece3e6..b547547 100755 (executable)
@@ -18,6 +18,7 @@
 #include <asterisk/pbx.h>
 #include <asterisk/module.h>
 #include <asterisk/translate.h>
+#include <asterisk/utils.h>
 #include <string.h>
 #include <stdlib.h>
 #include <pthread.h>
@@ -52,7 +53,7 @@ static int playback_exec(struct ast_channel *chan, void *data)
        int option_skip=0;
        int option_noanswer = 0;
        char *stringp;
-       if (!data || !strlen((char *)data)) {
+       if (!data || ast_strlen_zero((char *)data)) {
                ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
                return -1;
        }
index a9f365d..7328a02 100755 (executable)
 #include <asterisk/parking.h>
 #include <asterisk/musiconhold.h>
 #include <asterisk/cli.h>
-#include <asterisk/manager.h> /* JDG */
+#include <asterisk/manager.h>
 #include <asterisk/config.h>
 #include <asterisk/monitor.h>
+#include <asterisk/utils.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <unistd.h>
@@ -576,7 +577,7 @@ static int ring_one(struct queue_ent *qe, struct localuser *outgoing)
 static int valid_exit(struct queue_ent *qe, char digit)
 {
        char tmp[2];
-       if (!strlen(qe->context))
+       if (ast_strlen_zero(qe->context))
                return 0;
        tmp[0] = digit;
        tmp[1] = '\0';
@@ -880,9 +881,9 @@ static int try_calling(struct queue_ent *qe, char *options, char *announceoverri
        strncpy(queuename, qe->parent->name, sizeof(queuename) - 1);
        time(&now);
        cur = qe->parent->members;
-       if (strlen(qe->announce))
+       if (!ast_strlen_zero(qe->announce))
                announce = qe->announce;
-       if (announceoverride && strlen(announceoverride))
+       if (announceoverride && !ast_strlen_zero(announceoverride))
                announce = announceoverride;
        while(cur) {
                /* Get a technology/[device:]number pair */
@@ -1022,11 +1023,10 @@ static int try_calling(struct queue_ent *qe, char *options, char *announceoverri
                }
                /* Drop out of the queue at this point, to prepare for next caller */
                leave_queue(qe);                        
-               /* JDG: sendurl */
-               if( url && strlen(url) && ast_channel_supports_html(peer) ) {
+               if( url && !ast_strlen_zero(url) && ast_channel_supports_html(peer) ) {
                        ast_log(LOG_DEBUG, "app_queue: sendurl=%s.\n", url);
                        ast_channel_sendurl( peer, url );
-               } /* /JDG */
+               }
                ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "CONNECT", "%ld", (long)time(NULL) - qe->start);
                strncpy(oldcontext, qe->chan->context, sizeof(oldcontext) - 1);
                strncpy(oldexten, qe->chan->exten, sizeof(oldexten) - 1);
index caf8478..3819afe 100755 (executable)
@@ -20,6 +20,7 @@
 #include <asterisk/module.h>
 #include <asterisk/translate.h>
 #include <asterisk/options.h>
+#include <asterisk/utils.h>
 #include <string.h>
 #include <stdlib.h>
 #include <pthread.h>
@@ -53,7 +54,7 @@ static int read_exec(struct ast_channel *chan, void *data)
        char *stringp;
        char *maxdigitstr;
        int maxdigits=255;
-       if (!data || !strlen((char *)data)) {
+       if (!data || ast_strlen_zero((char *)data)) {
                ast_log(LOG_WARNING, "Read requires an argument (variable)\n");
                return -1;
        }
@@ -63,17 +64,16 @@ static int read_exec(struct ast_channel *chan, void *data)
        varname = strsep(&stringp, "|");
        filename = strsep(&stringp, "|");
        maxdigitstr = strsep(&stringp,"|");
-       if (!(filename) || (strlen(filename)==0)) filename = NULL;
-       if (maxdigitstr)
-       {
+       if (!(filename) || ast_strlen_zero(filename)) 
+               filename = NULL;
+       if (maxdigitstr) {
            maxdigits = atoi(maxdigitstr);
            if ((maxdigits<1) || (maxdigits>255)) {
                maxdigits = 255;
-           }
-           else
+           } else
                ast_verbose(VERBOSE_PREFIX_3 "Accepting a maximum of %i digits.\n", maxdigits);
        }       
-       if (!(varname) || (strlen(varname)==0)) {
+       if (!(varname) || ast_strlen_zero(varname)) {
                ast_log(LOG_WARNING, "Read requires an variable name\n");
                return -1;
        }
index 58e99b2..a8731e5 100755 (executable)
@@ -19,6 +19,7 @@
 #include <asterisk/module.h>
 #include <asterisk/translate.h>
 #include <asterisk/options.h>
+#include <asterisk/utils.h>
 #include <string.h>
 #include <stdlib.h>
 #include <pthread.h>
@@ -44,7 +45,7 @@ static int senddtmf_exec(struct ast_channel *chan, void *data)
        struct localuser *u;
        char *digits = data;
 
-       if (!digits || !strlen(digits)) {
+       if (!digits || ast_strlen_zero(digits)) {
                ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
                return -1;
        }
index 7d2a5bb..bb1bb33 100755 (executable)
@@ -19,7 +19,7 @@
 #include <asterisk/logger.h>
 #include <asterisk/config.h>
 #include <asterisk/manager.h>
-
+#include <asterisk/utils.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -68,11 +68,11 @@ static int action_setcdruserfield(struct mansession *s, struct message *m)
        char *channel = astman_get_header(m, "Channel");
        char *append = astman_get_header(m, "Append");
 
-       if (!strlen(channel)) {
+       if (ast_strlen_zero(channel)) {
                astman_send_error(s, m, "No Channel specified");
                return 0;
        }
-       if (!strlen(userfield)) {
+       if (ast_strlen_zero(userfield)) {
                astman_send_error(s, m, "No UserField specified");
                return 0;
        }
index d590442..089d35f 100755 (executable)
@@ -20,6 +20,7 @@
 #include <asterisk/translate.h>
 #include <asterisk/image.h>
 #include <asterisk/callerid.h>
+#include <asterisk/utils.h>
 #include <string.h>
 #include <stdlib.h>
 #include <pthread.h>
@@ -63,17 +64,17 @@ static int setcallerid_exec(struct ast_channel *chan, void *data)
                strncpy(oldcid, chan->callerid, sizeof(oldcid) - 1);
                ast_callerid_parse(oldcid, &n, &l);
                n = tmp;
-               if (strlen(n)) {
-                       if (l && strlen(l))
+               if (!ast_strlen_zero(n)) {
+                       if (l && !ast_strlen_zero(l))
                                snprintf(newcid, sizeof(newcid), "\"%s\" <%s>", n, l);
                        else
                                strncpy(newcid, tmp, sizeof(newcid) - 1);
-               } else if (l && strlen(l)) {
+               } else if (l && !ast_strlen_zero(l)) {
                        strncpy(newcid, l, sizeof(newcid) - 1);
                }
        } else
                strncpy(newcid, tmp, sizeof(newcid));
-       ast_set_callerid(chan, strlen(newcid) ? newcid : NULL, anitoo);
+       ast_set_callerid(chan, !ast_strlen_zero(newcid) ? newcid : NULL, anitoo);
        LOCAL_USER_REMOVE(u);
        return res;
 }
index 97eb9bb..a4ded6b 100755 (executable)
@@ -21,6 +21,7 @@
 #include <asterisk/translate.h>
 #include <asterisk/image.h>
 #include <asterisk/callerid.h>
+#include <asterisk/utils.h>
 #include <string.h>
 #include <stdlib.h>
 #include <pthread.h>
@@ -64,17 +65,17 @@ static int setcallerid_exec(struct ast_channel *chan, void *data)
                strncpy(oldcid, chan->callerid, sizeof(oldcid) - 1);
                ast_callerid_parse(oldcid, &n, &l);
                l = tmp;
-               if (strlen(l)) {
-                       if (n && strlen(n))
+               if (!ast_strlen_zero(l)) {
+                       if (n && !ast_strlen_zero(n))
                                snprintf(newcid, sizeof(newcid), "\"%s\" <%s>", n, l);
                        else
                                strncpy(newcid, tmp, sizeof(newcid) - 1);
-               } else if (n && strlen(n)) {
+               } else if (n && !ast_strlen_zero(n)) {
                        strncpy(newcid, n, sizeof(newcid) - 1);
                }
        } else
                strncpy(newcid, tmp, sizeof(newcid));
-       ast_set_callerid(chan, strlen(newcid) ? newcid : NULL, anitoo);
+       ast_set_callerid(chan, !ast_strlen_zero(newcid) ? newcid : NULL, anitoo);
        LOCAL_USER_REMOVE(u);
        return res;
 }
index f5c4e3a..cda4eaf 100755 (executable)
@@ -34,6 +34,7 @@
 #include <asterisk/musiconhold.h>
 #include <asterisk/manager.h>
 #include <asterisk/parking.h>
+#include <asterisk/utils.h>
 #include <sys/socket.h>
 #include <errno.h>
 #include <unistd.h>
@@ -318,7 +319,7 @@ static struct ast_frame  *agent_read(struct ast_channel *ast)
                if (p->chan) {
                        /* Note that we don't hangup if it's not a callback because Asterisk will do it
                           for us when the PBX instance that called login finishes */
-                       if (strlen(p->loginchan))
+                       if (!ast_strlen_zero(p->loginchan))
                                ast_hangup(p->chan);
                        p->chan = NULL;
                        p->acknowledged = 0;
@@ -437,7 +438,7 @@ static int agent_call(struct ast_channel *ast, char *dest, int timeout)
                }
                ast_mutex_unlock(&p->lock);
                return res;
-       } else if (strlen(p->loginchan)) {
+       } else if (!ast_strlen_zero(p->loginchan)) {
                time(&p->start);
                /* Call on this agent */
                if (option_verbose > 2)
@@ -509,7 +510,7 @@ static int agent_hangup(struct ast_channel *ast)
        time(&p->start);
        if (p->chan) {
                /* If they're dead, go ahead and hang up on the agent now */
-               if (strlen(p->loginchan)) {
+               if (!ast_strlen_zero(p->loginchan)) {
                        if (p->chan) {
                                /* Recognize the hangup and pass it along immediately */
                                ast_hangup(p->chan);
@@ -975,7 +976,7 @@ static struct ast_channel *agent_request(char *type, int format, void *data)
        while(p) {
                ast_mutex_lock(&p->lock);
                if (!p->pending && ((groupmatch && (p->group & groupmatch)) || !strcmp(data, p->agent)) &&
-                               !strlen(p->loginchan)) {
+                               ast_strlen_zero(p->loginchan)) {
                        if (p->chan)
                                hasagent++;
                        if (!p->lastdisc.tv_sec) {
@@ -998,14 +999,14 @@ static struct ast_channel *agent_request(char *type, int format, void *data)
                while(p) {
                        ast_mutex_lock(&p->lock);
                        if (!p->pending && ((groupmatch && (p->group & groupmatch)) || !strcmp(data, p->agent))) {
-                               if (p->chan || strlen(p->loginchan))
+                               if (p->chan || !ast_strlen_zero(p->loginchan))
                                        hasagent++;
                                if (!p->lastdisc.tv_sec) {
                                        /* Agent must be registered, but not have any active call, and not be in a waiting state */
                                        if (!p->owner && p->chan) {
                                                /* Could still get a fixed agent */
                                                chan = agent_new(p, AST_STATE_DOWN);
-                                       } else if (!p->owner && strlen(p->loginchan)) {
+                                       } else if (!p->owner && !ast_strlen_zero(p->loginchan)) {
                                                /* Adjustable agent */
                                                p->chan = ast_request("Local", format, p->loginchan);
                                                if (p->chan)
@@ -1069,7 +1070,7 @@ static int agents_show(int fd, int argc, char **argv)
                        else
                                ast_cli(fd, "-- Pending call to agent %s\n", p->agent);
                } else {
-                       if (strlen(p->name))
+                       if (!ast_strlen_zero(p->name))
                                snprintf(username, sizeof(username), "(%s) ", p->name);
                        else
                                strcpy(username, "");
@@ -1080,7 +1081,7 @@ static int agents_show(int fd, int argc, char **argv)
                                } else {
                                        strcpy(talkingto, " is idle");
                                }
-                       } else if (strlen(p->loginchan)) {
+                       } else if (!ast_strlen_zero(p->loginchan)) {
                                snprintf(location, sizeof(location) - 20, "available at '%s'", p->loginchan);
                                strcpy(talkingto, "");
                                if (p->acknowledged)
@@ -1089,7 +1090,7 @@ static int agents_show(int fd, int argc, char **argv)
                                strcpy(location, "not logged in");
                                strcpy(talkingto, "");
                        }
-                       if (strlen(p->moh))
+                       if (!ast_strlen_zero(p->moh))
                                snprintf(moh, sizeof(moh), " (musiconhold is '%s')", p->moh);
                        ast_cli(fd, "%-12.12s %s%s%s%s\n", p->agent, 
                                        username, location, talkingto, moh);
@@ -1160,7 +1161,7 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
        if (chan->_state != AST_STATE_UP)
                res = ast_answer(chan);
        if (!res) {
-               if( opt_user && strlen(opt_user))
+               if( opt_user && !ast_strlen_zero(opt_user))
                        strncpy( user, opt_user, AST_MAX_AGENT );
                else
                        res = ast_app_getdata(chan, "agent-user", user, sizeof(user) - 1, 0);
@@ -1176,7 +1177,7 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
                }
                ast_mutex_unlock(&agentlock);
                if (!res) {
-                       if (strlen(xpass))
+                       if (!ast_strlen_zero(xpass))
                                res = ast_app_getdata(chan, "agent-pass", pass, sizeof(pass) - 1, 0);
                        else
                                strcpy(pass, "");
@@ -1205,7 +1206,7 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
                                                                        res = 0;
                                                                } else
                                                                        res = ast_app_getdata(chan, "agent-newlocation", tmpchan+pos, sizeof(tmpchan) - 2, 0);
-                                                               if (!strlen(tmpchan) || ast_exists_extension(chan, context && strlen(context) ? context : "default", tmpchan,
+                                                               if (ast_strlen_zero(tmpchan) || ast_exists_extension(chan, context && !ast_strlen_zero(context) ? context : "default", tmpchan,
                                                                                        1, NULL))
                                                                        break;
                                                                if (exten) {
@@ -1227,18 +1228,18 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
                                                                }
                                                        }
                                                        if (!res) {
-                                                               if (context && strlen(context) && strlen(tmpchan))
+                                                               if (context && !ast_strlen_zero(context) && !ast_strlen_zero(tmpchan))
                                                                        snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", tmpchan, context);
                                                                else
                                                                        strncpy(p->loginchan, tmpchan, sizeof(p->loginchan) - 1);
-                                                               if (!strlen(p->loginchan))
+                                                               if (ast_strlen_zero(p->loginchan))
                                                                        filename = "agent-loggedoff";
                                                                p->acknowledged = 0;
                                                                /* store/clear the global variable that stores agentid based on the callerid */
                                                                if (chan->callerid) {
                                                                        char agentvar[AST_MAX_BUF];
                                                                        snprintf(agentvar, sizeof(agentvar), "%s_%s",GETAGENTBYCALLERID, chan->callerid);
-                                                                       if (!strlen(p->loginchan))
+                                                                       if (ast_strlen_zero(p->loginchan))
                                                                                pbx_builtin_setvar_helper(NULL, agentvar, NULL);
                                                                        else
                                                                                pbx_builtin_setvar_helper(NULL, agentvar, p->agent);
diff --git a/frame.c b/frame.c
index b8709ee..c127ebc 100755 (executable)
--- a/frame.c
+++ b/frame.c
@@ -17,6 +17,7 @@
 #include <asterisk/options.h>
 #include <asterisk/cli.h>
 #include <asterisk/term.h>
+#include <asterisk/utils.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -703,7 +704,7 @@ void ast_frame_dump(char *name, struct ast_frame *f, char *prefix)
        default:
                snprintf(ftype, sizeof(ftype), "Unknown Frametype '%d'", f->frametype);
        }
-       if (strlen(moreinfo))
+       if (!ast_strlen_zero(moreinfo))
                ast_verbose("%s [ TYPE: %s (%d) SUBCLASS: %s (%d) '%s' ] [%s]\n",  
                        term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
                        term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),