Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv15777/channels

Modified Files:
        chan_mgcp.c 
Log Message:
Minor protocol fixes (bug #4169)


Index: chan_mgcp.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_mgcp.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- chan_mgcp.c 4 May 2005 00:40:14 -0000       1.118
+++ chan_mgcp.c 4 May 2005 19:17:09 -0000       1.119
@@ -509,7 +509,7 @@
        ast_log(LOG_DEBUG, "Released sub %d of channel [EMAIL PROTECTED]", 
sub->id, p->name, p->parent->name);
 
        sub->owner = NULL;
-       if (strlen(sub->cxident)) {
+       if (!ast_strlen_zero(sub->cxident)) {
                transmit_connection_del(sub);
        }
        sub->cxident[0] = '\0';
@@ -943,7 +943,7 @@
                        transmit_modify_request(sub);
                }
 
-               if (sub->next->owner && strlen(sub->next->cxident) && 
strlen(sub->next->callid)) {
+               if (sub->next->owner && !ast_strlen_zero(sub->next->cxident) && 
!ast_strlen_zero(sub->next->callid)) {
                        /* try to prevent a callwait from disturbing the other 
connection */
                        sub->next->cxmode = MGCP_CX_RECVONLY;
                        transmit_modify_request(sub->next);
@@ -952,7 +952,7 @@
                transmit_notify_request_with_callerid(sub, tone, 
ast->cid.cid_num, ast->cid.cid_name);
                ast_setstate(ast, AST_STATE_RINGING);
 
-               if (sub->next->owner && strlen(sub->next->cxident) && 
strlen(sub->next->callid)) {
+               if (sub->next->owner && !ast_strlen_zero(sub->next->cxident) && 
!ast_strlen_zero(sub->next->callid)) {
                        /* Put the connection back in sendrecv */
                        sub->next->cxmode = MGCP_CX_SENDRECV;
                        transmit_modify_request(sub->next);
@@ -1001,7 +1001,7 @@
        }
 
        sub->owner = NULL;
-       if (strlen(sub->cxident)) {
+       if (!ast_strlen_zero(sub->cxident)) {
                transmit_connection_del(sub);
        }
        sub->cxident[0] = '\0';
@@ -1402,9 +1402,9 @@
                tmp->readformat = fmt;
                tmp->rawreadformat = fmt;
                tmp->tech_pvt = sub;
-               if (strlen(i->language))
+               if (!ast_strlen_zero(i->language))
                        strncpy(tmp->language, i->language, 
sizeof(tmp->language)-1);
-               if (strlen(i->accountcode))
+               if (!ast_strlen_zero(i->accountcode))
                        strncpy(tmp->accountcode, i->accountcode, 
sizeof(tmp->accountcode)-1);
                if (i->amaflags)
                        tmp->amaflags = i->amaflags;
@@ -1663,7 +1663,7 @@
 #if 0
                        printf("Header: %s (%d)\n", req->header[f], 
strlen(req->header[f]));
 #endif                 
-                       if (!strlen(req->header[f])) {
+                       if (ast_strlen_zero(req->header[f])) {
                                /* Line by itself means we're now in content */
                                c++;
                                break;
@@ -1680,7 +1680,7 @@
                c++;
        }
        /* Check for last header */
-       if (strlen(req->header[f])) 
+       if (!ast_strlen_zero(req->header[f])) 
                f++;
        req->headers = f;
        /* Now we process any mime content */
@@ -1705,7 +1705,7 @@
                c++;
        }
        /* Check for last line */
-       if (strlen(req->line[f])) 
+       if (!ast_strlen_zero(req->line[f])) 
                f++;
        req->lines = f;
        /* Parse up the initial header */
@@ -1760,14 +1760,14 @@
        struct sockaddr_in sin;
        char *codecs;
        struct ast_hostent ahp; struct hostent *hp;
-       int codec;
+       int codec, codec_count=0;
        int iterator;
        struct mgcp_endpoint *p = sub->parent;
 
        /* Get codec and RTP info from SDP */
        m = get_sdp(req, "m");
        c = get_sdp(req, "c");
-       if (!strlen(m) || !strlen(c)) {
+       if (ast_strlen_zero(m) || ast_strlen_zero(c)) {
                ast_log(LOG_WARNING, "Insufficient information for SDP (m = 
'%s', c = '%s')\n", m, c);
                return -1;
        }
@@ -1794,13 +1794,16 @@
 #endif 
        /* Scan through the RTP payload types specified in a "m=" line: */
        ast_rtp_pt_clear(sub->rtp);
-       codecs = m + len;
-       while(strlen(codecs)) {
-               if (sscanf(codecs, "%d %n", &codec, &len) != 1) {
-                       ast_log(LOG_WARNING, "Error in codec string '%s'\n", 
codecs);
+       codecs = ast_strdupa(m + len);
+       while (codecs && !ast_strlen_zero(codecs)) {
+               if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
+                       if (codec_count)
+                               break;
+                       ast_log(LOG_WARNING, "Error in codec string '%s' at 
'%s'\n", m, codecs);
                        return -1;
                }
                ast_rtp_set_m_type(sub->rtp, codec);
+               codec_count++;
                codecs += len;
        }
 
@@ -2061,7 +2064,7 @@
        capability = p->capability;
        if (codecs)
                capability = codecs;
-       if (!strlen(sub->cxident) && rtp) {
+       if (ast_strlen_zero(sub->cxident) && rtp) {
                /* We don't have a CXident yet, store the destination and
                   wait a bit */
                ast_rtp_get_peer(rtp, &sub->tmpdest);
@@ -2144,7 +2147,7 @@
                add_header(&resp, "R", (sub->rtp && (p->dtmfmode & 
MGCP_DTMF_INBAND)) ? "L/hu(N),L/hf(N)" : "L/hu(N),L/hf(N),D/[0-9#*](N)");
                break;
        }
-       if (strlen(tone)) {
+       if (!ast_strlen_zero(tone)) {
                add_header(&resp, "S", tone);
        }
        /* SC: fill in new fields */
@@ -2187,7 +2190,7 @@
                add_header(&resp, "R",  (sub->rtp && (p->dtmfmode & 
MGCP_DTMF_INBAND)) ? "L/hu(N),L/hf(N)" : "L/hu(N),L/hf(N),D/[0-9#*](N)");
                break;
        }
-       if (strlen(tone2)) {
+       if (!ast_strlen_zero(tone2)) {
                add_header(&resp, "S", tone2);
        }
        if (mgcpdebug) {
@@ -2205,7 +2208,7 @@
        struct mgcp_request resp;
        struct mgcp_endpoint *p = sub->parent;
 
-       if (!strlen(sub->cxident)) {
+       if (ast_strlen_zero(sub->cxident)) {
                /* We don't have a CXident yet, store the destination and
                   wait a bit */
                return 0;
@@ -2428,10 +2431,10 @@
        if (resp) {
                if (req->cmd == MGCP_CMD_CRCX) {
                        if ((c = get_header(resp, "I"))) {
-                               if (strlen(c) && sub) {
+                               if (!ast_strlen_zero(c) && sub) {
                                        /* SC: if we are hanging up do not 
process this conn. */
                                        if (sub->owner) {
-                                               if (strlen(sub->cxident)) {
+                                               if 
(!ast_strlen_zero(sub->cxident)) {
                                                        if (strcasecmp(c, 
sub->cxident)) {
                                                                
ast_log(LOG_WARNING, "Subchannel already has a cxident. sub->cxident: %s 
requested %s\n", sub->cxident, c);
                                                        }
@@ -2477,7 +2480,7 @@
 
                        /* Try to determine the hookstate returned from an 
audit endpoint command */
                        if ((c = get_header(resp, "ES"))) {
-                               if (strlen(c)) {
+                               if (!ast_strlen_zero(c)) {
                                        if (strstr(c, "hu")) {
                                                if (p->hookstate != 
MGCP_ONHOOK) {
                                                        /* SC: XXX cleanup if 
we think we are offhook XXX */
@@ -2692,7 +2695,7 @@
                        timeout = firstdigittimeout;
                } else if (p->callreturn && !strcmp(exten, "*69")) {
                        res = 0;
-                       if (strlen(p->lastcallerid)) {
+                       if (!ast_strlen_zero(p->lastcallerid)) {
                                res = ast_say_digit_str(chan, p->lastcallerid, 
"", chan->language);
                        }
                        if (!res)
@@ -2746,7 +2749,7 @@
                                ast_verbose(VERBOSE_PREFIX_3 "Parking call to 
'%s'\n", chan->name);
                        }
                        break;
-               } else if (strlen(p->lastcallerid) && !strcmp(exten, "*60")) {
+               } else if (!ast_strlen_zero(p->lastcallerid) && !strcmp(exten, 
"*60")) {
                        if (option_verbose > 2) {
                                ast_verbose(VERBOSE_PREFIX_3 "Blacklisting 
number %s\n", p->lastcallerid);
                        }
@@ -3043,9 +3046,7 @@
                ev = get_header(req, "O");
                s = strchr(ev, '/');
                if (s) ev = s + 1;
-               if (option_verbose > 2) {
-                       ast_verbose(VERBOSE_PREFIX_3 "Endpoint '[EMAIL 
PROTECTED]' observed '%s'\n", p->name, p->parent->name, sub->id, ev);
-               }
+               ast_log(LOG_DEBUG, "Endpoint '[EMAIL PROTECTED]' observed 
'%s'\n", p->name, p->parent->name, sub->id, ev);
                /* Keep looking for events unless this was a hangup */
                if (strcasecmp(ev, "hu") && strcasecmp(ev, "hd") && 
strcasecmp(ev, "ping")) {
                        transmit_notify_request(sub, p->curtone);
@@ -3307,7 +3308,7 @@
                /* Must have at least one header */
                return 1;
        }
-       if (!req.identifier || !strlen(req.identifier)) {
+       if (!req.identifier || ast_strlen_zero(req.identifier)) {
                ast_log(LOG_NOTICE, "Message from %s missing identifier\n", 
ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr));
                return 1;
        }
@@ -3349,9 +3350,9 @@
                                gw->name, ident);
                }
        } else {
-               if (!req.endpoint || !strlen(req.endpoint) || 
-                   !req.version || !strlen(req.version) || 
-                       !req.verb || !strlen(req.verb)) {
+               if (!req.endpoint || ast_strlen_zero(req.endpoint) || 
+                   !req.version || ast_strlen_zero(req.version) || 
+                       !req.verb || ast_strlen_zero(req.verb)) {
                        ast_log(LOG_NOTICE, "Message must have a verb, an 
idenitifier, version, and endpoint\n");
                        return 1;
                }
@@ -3504,7 +3505,7 @@
                return NULL;
        }
        strncpy(tmp, dest, sizeof(tmp) - 1);
-       if (!strlen(tmp)) {
+       if (ast_strlen_zero(tmp)) {
                ast_log(LOG_NOTICE, "MGCP Channels require an endpoint\n");
                return NULL;
        }
@@ -3523,7 +3524,7 @@
        /* Must be busy */
        if (((sub->parent->callwaiting) && ((sub->owner) && 
(sub->next->owner))) ||
                ((!sub->parent->callwaiting) && (sub->owner)) ||
-                (sub->parent->dnd && (!strlen(sub->parent->call_forward)))) {
+                (sub->parent->dnd && 
(ast_strlen_zero(sub->parent->call_forward)))) {
                if (sub->parent->hookstate == MGCP_ONHOOK) {
                        if (has_voicemail(sub->parent)) {
                                transmit_notify_request(sub,"L/vmwi(+)");
@@ -3816,7 +3817,7 @@
                                        strncpy(e->language, language, 
sizeof(e->language) - 1);
                                        strncpy(e->musicclass, musicclass, 
sizeof(e->musicclass) - 1);
                                        strncpy(e->mailbox, mailbox, 
sizeof(e->mailbox)-1);
-                                       if (strlen(mailbox)) {
+                                       if (!ast_strlen_zero(mailbox)) {
                                                ast_verbose(VERBOSE_PREFIX_3 
"Setting mailbox '%s' on [EMAIL PROTECTED]", mailbox, gw->name, e->name);
                                        }
                                        if (!ep_reload) {
@@ -3995,7 +3996,7 @@
 
        for (i = 0; i < MAX_SUBS; i++) {
                ast_mutex_lock(&sub->lock);
-               if (strlen(sub->cxident)) {
+               if (!ast_strlen_zero(sub->cxident)) {
                        transmit_connection_del(sub);
                }
                if (sub->rtp) {

_______________________________________________
Asterisk-Cvs mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-cvs

Reply via email to