Janitor work converting !ast_strlen_zero(a)?a:b
authorMatt O'Gorman <mogorman@digium.com>
Mon, 27 Mar 2006 19:31:54 +0000 (19:31 +0000)
committerMatt O'Gorman <mogorman@digium.com>
Mon, 27 Mar 2006 19:31:54 +0000 (19:31 +0000)
to S_OR functions. from bug note 6805 with minor
modifications.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@15283 65c4cc65-6c06-0410-ace0-fbb531ad65f3

14 files changed:
app.c
apps/app_dial.c
apps/app_directory.c
apps/app_dumpchan.c
apps/app_meetme.c
channels/chan_agent.c
channels/chan_iax2.c
channels/chan_misdn.c
channels/chan_sip.c
channels/chan_vpb.c
channels/chan_zap.c
cli.c
pbx.c
res/res_musiconhold.c

diff --git a/app.c b/app.c
index f43bd1d..470369c 100644 (file)
--- a/app.c
+++ b/app.c
@@ -1059,7 +1059,7 @@ int ast_app_group_get_count(const char *group, const char *category)
        if (ast_strlen_zero(group))
                return 0;
 
-       s = (!ast_strlen_zero(category)) ? category : GROUP_CATEGORY_PREFIX;
+       s = S_OR(category, GROUP_CATEGORY_PREFIX);
        ast_copy_string(cat, s, sizeof(cat));
 
        chan = NULL;
@@ -1089,7 +1089,7 @@ int ast_app_group_match_get_count(const char *groupmatch, const char *category)
        if (regcomp(&regexbuf, groupmatch, REG_EXTENDED | REG_NOSUB))
                return 0;
 
-       s = (!ast_strlen_zero(category)) ? category : GROUP_CATEGORY_PREFIX;
+       s = S_OR(category, GROUP_CATEGORY_PREFIX);
        ast_copy_string(cat, s, sizeof(cat));
 
        chan = NULL;
index 22f3e21..2f9a4b0 100644 (file)
@@ -541,7 +541,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
                                                        senddialevent(in, o->chan);
                                                        /* After calling, set callerid to extension */
                                                        if (!ast_test_flag(peerflags, OPT_ORIGINAL_CLID))
-                                                               ast_set_callerid(o->chan, ast_strlen_zero(in->macroexten) ? in->exten : in->macroexten, get_cid_name(cidname, sizeof(cidname), in), NULL);
+                                                               ast_set_callerid(o->chan, S_OR(in->macroexten, in->exten), get_cid_name(cidname, sizeof(cidname), in), NULL);
                                                }
                                        }
                                        /* Hangup the original channel now, in case we needed it */
@@ -1135,7 +1135,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
                        if (option_verbose > 2)
                                ast_verbose(VERBOSE_PREFIX_3 "Called %s\n", numsubst);
                        if (!ast_test_flag(peerflags, OPT_ORIGINAL_CLID))
-                               ast_set_callerid(tmp->chan, ast_strlen_zero(chan->macroexten) ? chan->exten : chan->macroexten, get_cid_name(cidname, sizeof(cidname), chan), NULL);
+                               ast_set_callerid(tmp->chan, S_OR(chan->macroexten, chan->exten), get_cid_name(cidname, sizeof(cidname), chan), NULL);
                }
                /* Put them in the list of outgoing thingies...  We're ready now. 
                   XXX If we're forcibly removed, these outgoing calls won't get
index 1935a0c..63dd3c6 100644 (file)
@@ -179,7 +179,7 @@ static int play_mailbox_owner(struct ast_channel *chan, char *context, char *dia
                }
                ast_stopstream(chan);
        } else {
-               res = ast_say_character_str(chan, !ast_strlen_zero(name) ? name : ext,
+               res = ast_say_character_str(chan, S_OR(name, ext),
                                        AST_DIGIT_ANY, chan->language);
        }
 
index 115f149..5125354 100644 (file)
@@ -126,7 +126,7 @@ static int ast_serialize_showchan(struct ast_channel *c, char *buf, size_t size)
                         ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
                         ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
                         ( c->appl ? c->appl : "(N/A)" ),
-                        ( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
+                        ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
                         (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
 
        return 0;
index 200144f..22ee8df 100644 (file)
@@ -1845,8 +1845,8 @@ static struct ast_conference *find_conf(struct ast_channel *chan, char *confno,
                                if (!strcasecmp(args.confno, confno)) {
                                        /* Bingo it's a valid conference */
                                        cnf = build_conf(args.confno,
-                                                       ast_strlen_zero(args.pin) ? "" : args.pin,
-                                                       ast_strlen_zero(args.pinadmin) ? "" : args.pinadmin,
+                                                       S_OR(args.pin, ""),
+                                                       S_OR(args.pinadmin, ""),
                                                        make, dynamic, refcount);
                                        break;
                                }
index 6199dad..9317aad 100644 (file)
@@ -1825,7 +1825,7 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
                                                                res = ast_app_getdata(chan, "agent-newlocation", tmpchan+pos, sizeof(tmpchan) - 2, 0);
                                                        if (ast_strlen_zero(tmpchan) )
                                                                break;
-                                                       if(ast_exists_extension(chan, !ast_strlen_zero(context) ? context : "default", tmpchan,1, NULL) ) {
+                                                       if(ast_exists_extension(chan, S_OR(context,"default"), tmpchan,1, NULL) ) {
                                                                if(!allow_multiple_login(tmpchan,context) ) {
                                                                        args.extension = NULL;
                                                                        pos = 0;
@@ -1837,7 +1837,7 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
                                                                args.extension = NULL;
                                                                pos = 0;
                                                        } else {
-                                                               ast_log(LOG_WARNING, "Extension '%s@%s' is not valid for automatic login of agent '%s'\n", tmpchan, !ast_strlen_zero(context) ? context : "default", p->agent);
+                                                               ast_log(LOG_WARNING, "Extension '%s@%s' is not valid for automatic login of agent '%s'\n", tmpchan, S_OR(context, "default"), p->agent);
                                                                res = ast_streamfile(chan, "invalid", chan->language);
                                                                if (!res)
                                                                        res = ast_waitstream(chan, AST_DIGIT_ANY);
index 69fccbb..0078202 100644 (file)
@@ -4618,10 +4618,10 @@ static int iax2_show_channels(int fd, int argc, char *argv[])
                        if (iaxs[x]->bridgecallno)
                                ast_cli(fd, FORMATB,
                                                iaxs[x]->owner ? iaxs[x]->owner->name : "(None)",
-                                               ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[x]->addr.sin_addr), 
-                                               !ast_strlen_zero(iaxs[x]->username) ? iaxs[x]->username : "(None)", 
-                                               iaxs[x]->callno, iaxs[x]->peercallno, 
-                                               iaxs[x]->oseqno, iaxs[x]->iseqno, 
+                                               ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[x]->addr.sin_addr),
+                                               S_OR(iaxs[x]->username, "(None)"),
+                                               iaxs[x]->callno, iaxs[x]->peercallno,
+                                               iaxs[x]->oseqno, iaxs[x]->iseqno,
                                                iaxs[x]->bridgecallno );
                        else
 #endif
@@ -4646,9 +4646,9 @@ static int iax2_show_channels(int fd, int argc, char *argv[])
                                ast_cli(fd, FORMAT,
                                                iaxs[x]->owner ? iaxs[x]->owner->name : "(None)",
                                                ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[x]->addr.sin_addr), 
-                                               !ast_strlen_zero(iaxs[x]->username) ? iaxs[x]->username : "(None)", 
-                                               iaxs[x]->callno, iaxs[x]->peercallno, 
-                                               iaxs[x]->oseqno, iaxs[x]->iseqno, 
+                                               S_OR(iaxs[x]->username, "(None)"),
+                                               iaxs[x]->callno, iaxs[x]->peercallno,
+                                               iaxs[x]->oseqno, iaxs[x]->iseqno,
                                                lag,
                                                jitter,
                                                localdelay,
@@ -5795,7 +5795,7 @@ static void register_peer_exten(struct iax2_peer *peer, int onoff)
        char multi[256];
        char *stringp, *ext;
        if (!ast_strlen_zero(regcontext)) {
-               ast_copy_string(multi, ast_strlen_zero(peer->regexten) ? peer->name : peer->regexten, sizeof(multi));
+               ast_copy_string(multi, S_OR(peer->regexten, peer->name), sizeof(multi));
                stringp = multi;
                while((ext = strsep(&stringp, "&"))) {
                        if (onoff) {
index ba9aacc..c2bf772 100644 (file)
@@ -2641,7 +2641,7 @@ static int misdn_tx2ast_frm(struct chan_list * tmp, char * buf,  int len )
                                if (!tmp->faxhandled) {
                                        tmp->faxhandled++;
                                        if (strcmp(ast->exten, "fax")) {
-                                               if (ast_exists_extension(ast, ast_strlen_zero(ast->macrocontext)? ast->context : ast->macrocontext, "fax", 1, AST_CID_P(ast))) {
+                                               if (ast_exists_extension(ast, S_OR(ast->macrocontext, ast->context), "fax", 1, AST_CID_P(ast))) {
                                                        if (option_verbose > 2)
                                                                ast_verbose(VERBOSE_PREFIX_3 "Redirecting %s to fax extension\n", ast->name);
                                                        /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
index fc3c3eb..0e47c6e 100644 (file)
@@ -1681,7 +1681,8 @@ static void register_peer_exten(struct sip_peer *peer, int onoff)
        char multi[256];
        char *stringp, *ext;
        if (!ast_strlen_zero(global_regcontext)) {
-               ast_copy_string(multi, ast_strlen_zero(peer->regexten) ? peer->name : peer->regexten, sizeof(multi));
+
+               ast_copy_string(multi, S_OR(peer->regexten, peer->name), sizeof(multi));
                stringp = multi;
                while((ext = strsep(&stringp, "&"))) {
                        if (onoff)
@@ -3190,7 +3191,7 @@ static void build_callid_pvt(struct sip_pvt *pvt)
        char iabuf[INET_ADDRSTRLEN];
        char buf[33];
 
-       const char *host = ast_strlen_zero(pvt->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), pvt->ourip) : pvt->fromdomain;
+       const char *host = S_OR(pvt->fromdomain, ast_inet_ntoa(iabuf, sizeof(iabuf), pvt->ourip));
        
        ast_string_field_build(pvt, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host);
 
@@ -3202,7 +3203,7 @@ static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip
        char iabuf[INET_ADDRSTRLEN];
        char buf[33];
 
-       const char *host = ast_strlen_zero(fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), ourip) : fromdomain;
+       const char *host = S_OR(fromdomain, ast_inet_ntoa(iabuf, sizeof(iabuf), ourip));
 
        ast_string_field_build(reg, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host);
 }
@@ -8161,7 +8162,7 @@ static int _sip_show_peer(int type, int fd, struct mansession *s, struct message
                        auth = auth->next;
                }
                ast_cli(fd, "  Context      : %s\n", peer->context);
-               ast_cli(fd, "  Subscr.Cont. : %s\n", ast_strlen_zero(peer->subscribecontext)?"<Not set>":peer->subscribecontext);
+               ast_cli(fd, "  Subscr.Cont. : %s\n", S_OR(peer->subscribecontext, "<Not set>") );
                ast_cli(fd, "  Language     : %s\n", peer->language);
                if (!ast_strlen_zero(peer->accountcode))
                        ast_cli(fd, "  Accountcode  : %s\n", peer->accountcode);
index a43a1f4..87a655c 100644 (file)
@@ -923,7 +923,7 @@ static inline int monitor_handle_owned(struct vpb_pvt *p, VPB_EVENT *e)
                        else if (e->data == VPB_FAX){
                                if (!p->faxhandled){
                                        if (strcmp(p->owner->exten, "fax")) {
-                                               const char *target_context = ast_strlen_zero(p->owner->macrocontext) ? p->owner->context : p->owner->macrocontext;
+                                               const char *target_context = S_OR(p->owner->macrocontext, p->owner->context);
                                                
                                                if (ast_exists_extension(p->owner, target_context, "fax", 1, p->owner->cid.cid_num)) {
                                                        if (option_verbose > 2)
index 9ce7c5d..1dbf6df 100644 (file)
@@ -4559,9 +4559,9 @@ struct ast_frame  *zt_read(struct ast_channel *ast)
        }
 
        if (p->subs[index].needcallerid) {
-               ast_set_callerid(ast, !ast_strlen_zero(p->lastcid_num) ? p->lastcid_num : NULL, 
-                                                       !ast_strlen_zero(p->lastcid_name) ? p->lastcid_name : NULL,
-                                                       !ast_strlen_zero(p->lastcid_num) ? p->lastcid_num : NULL
+               ast_set_callerid(ast, S_OR(p->lastcid_num, NULL),
+                                                       S_OR(p->lastcid_name, NULL),
+                                                       S_OR(p->lastcid_num, NULL)
                                                        );
                p->subs[index].needcallerid = 0;
        }
@@ -4751,7 +4751,7 @@ struct ast_frame  *zt_read(struct ast_channel *ast)
                        if (!p->faxhandled) {
                                p->faxhandled++;
                                if (strcmp(ast->exten, "fax")) {
-                                       const char *target_context = ast_strlen_zero(ast->macrocontext) ? ast->context : ast->macrocontext;
+                                       const char *target_context = S_OR(ast->macrocontext, ast->context);
 
                                        if (ast_exists_extension(ast, target_context, "fax", 1, ast->cid.cid_num)) {
                                                if (option_verbose > 2)
@@ -5213,7 +5213,7 @@ static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int
                        tmp->cid.cid_dnid = ast_strdup(i->dnid);
 
 #ifdef PRI_ANI
-               ast_set_callerid(tmp, i->cid_num, i->cid_name, ast_strlen_zero(i->cid_ani) ? i->cid_num : i->cid_ani);
+               ast_set_callerid(tmp, i->cid_num, i->cid_name, S_OR(i->cid_ani, i->cid_num));
 #else
                ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
 #endif
@@ -8760,7 +8760,7 @@ static void *pri_dchannel(void *vpri)
                                                        if (c && !ast_pthread_create(&threadid, &attr, ss_thread, c)) {
                                                                if (option_verbose > 2)
                                                                        ast_verbose(VERBOSE_PREFIX_3 "Accepting overlap call from '%s' to '%s' on channel %d/%d, span %d\n",
-                                                                               plancallingnum, !ast_strlen_zero(pri->pvts[chanpos]->exten) ? pri->pvts[chanpos]->exten : "<unspecified>", 
+                                                                               plancallingnum, S_OR(pri->pvts[chanpos]->exten, "<unspecified>"),
                                                                                pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
                                                        } else {
                                                                ast_log(LOG_WARNING, "Unable to start PBX on channel %d/%d, span %d\n", 
diff --git a/cli.c b/cli.c
index 9531165..e57cb59 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -425,7 +425,7 @@ static int handle_chanlist(int fd, int argc, char *argv[])
                                durbuf, bc ? bc->name : "(None)");
                } else if (verbose) {
                        ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
-                               c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "(Empty)" ): "(None)",
+                               c->appl ? c->appl : "(None)", c->data ? S_OR(c->data, "(Empty)" ): "(None)",
                                c->cid.cid_num ? c->cid.cid_num : "", durbuf,
                                c->accountcode ? c->accountcode : "", bc ? bc->name : "(None)");
                } else {
@@ -746,7 +746,7 @@ static int handle_showchan(int fd, int argc, char *argv[])
                c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
                cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>", 
                c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
-               ( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
+               ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
                (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
        
        if(pbx_builtin_serialize_variables(c,buf,sizeof(buf)))
diff --git a/pbx.c b/pbx.c
index 278c180..296e54c 100644 (file)
--- a/pbx.c
+++ b/pbx.c
@@ -4311,8 +4311,8 @@ int ast_async_goto(struct ast_channel *chan, const char *context, const char *ex
                        tmpchan->writeformat = chan->writeformat;
                        /* Setup proper location */
                        ast_explicit_goto(tmpchan,
-                                         (!ast_strlen_zero(context)) ? context : chan->context,
-                                         (!ast_strlen_zero(exten)) ? exten : chan->exten,
+                                         S_OR(context, chan->context),
+                                         S_OR(exten, chan->exten),
                                          priority);
 
                        /* Masquerade into temp channel */
index bca584d..289d139 100644 (file)
@@ -1127,10 +1127,10 @@ static int moh_classes_show(int fd, int argc, char *argv[])
        ast_mutex_lock(&moh_lock);
        for (class = mohclasses; class; class = class->next) {
                ast_cli(fd, "Class: %s\n", class->name);
-               ast_cli(fd, "\tMode: %s\n", ast_strlen_zero(class->mode) ? "<none>" : class->mode);
-               ast_cli(fd, "\tDirectory: %s\n", ast_strlen_zero(class->dir) ? "<none>" : class->dir);
+               ast_cli(fd, "\tMode: %s\n", S_OR(class->mode,"<none>"));
+               ast_cli(fd, "\tDirectory: %s\n", S_OR(class->dir, "<none>"));
                if (ast_test_flag(class, MOH_CUSTOM))
-                       ast_cli(fd, "\tApplication: %s\n", ast_strlen_zero(class->args) ? "<none>" : class->args);
+                       ast_cli(fd, "\tApplication: %s\n", S_OR(class->args, "<none>"));
                ast_cli(fd, "\tFormat: %s\n", ast_getformatname(class->format));
        }
        ast_mutex_unlock(&moh_lock);