use ast_strlen_zero, also fix a codec config parsing error (bug #4169)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/v1-0@5633 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Russell Bryant
2005-05-12 02:22:56 +00:00
parent 8c97879e99
commit 794d0b2c68

View File

@@ -471,7 +471,7 @@ static int unalloc_sub(struct mgcp_subchannel *sub)
ast_log(LOG_DEBUG, "Released sub %d of channel %s@%s\n", sub->id, p->name, p->parent->name); ast_log(LOG_DEBUG, "Released sub %d of channel %s@%s\n", sub->id, p->name, p->parent->name);
sub->owner = NULL; sub->owner = NULL;
if (strlen(sub->cxident)) { if (!ast_strlen_zero(sub->cxident)) {
transmit_connection_del(sub); transmit_connection_del(sub);
} }
sub->cxident[0] = '\0'; sub->cxident[0] = '\0';
@@ -833,7 +833,7 @@ static int mgcp_call(struct ast_channel *ast, char *dest, int timeout)
transmit_modify_request(sub); 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 */ /* try to prevent a callwait from disturbing the other connection */
sub->next->cxmode = MGCP_CX_RECVONLY; sub->next->cxmode = MGCP_CX_RECVONLY;
transmit_modify_request(sub->next); transmit_modify_request(sub->next);
@@ -843,7 +843,7 @@ static int mgcp_call(struct ast_channel *ast, char *dest, int timeout)
ast_setstate(ast, AST_STATE_RINGING); ast_setstate(ast, AST_STATE_RINGING);
ast_queue_control(ast, AST_CONTROL_RINGING); ast_queue_control(ast, AST_CONTROL_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 */ /* Put the connection back in sendrecv */
sub->next->cxmode = MGCP_CX_SENDRECV; sub->next->cxmode = MGCP_CX_SENDRECV;
transmit_modify_request(sub->next); transmit_modify_request(sub->next);
@@ -889,7 +889,7 @@ static int mgcp_hangup(struct ast_channel *ast)
} }
sub->owner = NULL; sub->owner = NULL;
if (strlen(sub->cxident)) { if (!ast_strlen_zero(sub->cxident)) {
transmit_connection_del(sub); transmit_connection_del(sub);
} }
sub->cxident[0] = '\0'; sub->cxident[0] = '\0';
@@ -1273,9 +1273,9 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state)
tmp->pvt->fixup = mgcp_fixup; tmp->pvt->fixup = mgcp_fixup;
tmp->pvt->send_digit = mgcp_senddigit; tmp->pvt->send_digit = mgcp_senddigit;
tmp->pvt->bridge = ast_rtp_bridge; tmp->pvt->bridge = ast_rtp_bridge;
if (strlen(i->language)) if (!ast_strlen_zero(i->language))
strncpy(tmp->language, i->language, sizeof(tmp->language)-1); 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); strncpy(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode)-1);
if (i->amaflags) if (i->amaflags)
tmp->amaflags = i->amaflags; tmp->amaflags = i->amaflags;
@@ -1530,7 +1530,7 @@ static void parse(struct mgcp_request *req)
#if 0 #if 0
printf("Header: %s (%d)\n", req->header[f], strlen(req->header[f])); printf("Header: %s (%d)\n", req->header[f], strlen(req->header[f]));
#endif #endif
if (!strlen(req->header[f])) { if (ast_strlen_zero(req->header[f])) {
/* Line by itself means we're now in content */ /* Line by itself means we're now in content */
c++; c++;
break; break;
@@ -1547,7 +1547,7 @@ static void parse(struct mgcp_request *req)
c++; c++;
} }
/* Check for last header */ /* Check for last header */
if (strlen(req->header[f])) if (!ast_strlen_zero(req->header[f]))
f++; f++;
req->headers = f; req->headers = f;
/* Now we process any mime content */ /* Now we process any mime content */
@@ -1572,7 +1572,7 @@ static void parse(struct mgcp_request *req)
c++; c++;
} }
/* Check for last line */ /* Check for last line */
if (strlen(req->line[f])) if (!ast_strlen_zero(req->line[f]))
f++; f++;
req->lines = f; req->lines = f;
/* Parse up the initial header */ /* Parse up the initial header */
@@ -1627,14 +1627,14 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
struct sockaddr_in sin; struct sockaddr_in sin;
char *codecs; char *codecs;
struct ast_hostent ahp; struct hostent *hp; struct ast_hostent ahp; struct hostent *hp;
int codec; int codec, codec_count = 0;
int iterator; int iterator;
struct mgcp_endpoint *p = sub->parent; struct mgcp_endpoint *p = sub->parent;
/* Get codec and RTP info from SDP */ /* Get codec and RTP info from SDP */
m = get_sdp(req, "m"); m = get_sdp(req, "m");
c = get_sdp(req, "c"); 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); ast_log(LOG_WARNING, "Insufficient information for SDP (m = '%s', c = '%s')\n", m, c);
return -1; return -1;
} }
@@ -1660,14 +1660,16 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
printf("Peer RTP is at port %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port)); printf("Peer RTP is at port %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
#endif #endif
/* Scan through the RTP payload types specified in a "m=" line: */ /* Scan through the RTP payload types specified in a "m=" line: */
ast_rtp_pt_clear(sub->rtp); ast_rtp_pt_clear(sub->rtp);
codecs = m + len; codecs = ast_strdupa(m + len);
while(strlen(codecs)) { while (codecs && !ast_strlen_zero(codecs)) {
if (sscanf(codecs, "%d %n", &codec, &len) != 1) { if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); if (codec_count)
break;
return -1; return -1;
} }
ast_rtp_set_m_type(sub->rtp, codec); ast_rtp_set_m_type(sub->rtp, codec);
codec_count++;
codecs += len; codecs += len;
} }
@@ -1926,7 +1928,7 @@ static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp
capability = p->capability; capability = p->capability;
if (codecs) if (codecs)
capability = 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 /* We don't have a CXident yet, store the destination and
wait a bit */ wait a bit */
ast_rtp_get_peer(rtp, &sub->tmpdest); ast_rtp_get_peer(rtp, &sub->tmpdest);
@@ -2009,7 +2011,7 @@ static int transmit_notify_request(struct mgcp_subchannel *sub, char *tone)
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)"); 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; break;
} }
if (strlen(tone)) { if (!ast_strlen_zero(tone)) {
add_header(&resp, "S", tone); add_header(&resp, "S", tone);
} }
/* SC: fill in new fields */ /* SC: fill in new fields */
@@ -2063,7 +2065,7 @@ static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, ch
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)"); 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; break;
} }
if (strlen(tone2)) { if (!ast_strlen_zero(tone2)) {
add_header(&resp, "S", tone2); add_header(&resp, "S", tone2);
} }
if (mgcpdebug) { if (mgcpdebug) {
@@ -2079,8 +2081,8 @@ static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, ch
static int transmit_modify_request(struct mgcp_subchannel *sub) static int transmit_modify_request(struct mgcp_subchannel *sub)
{ {
struct mgcp_request resp; struct mgcp_request resp;
struct mgcp_endpoint *p = sub->parent; 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 /* We don't have a CXident yet, store the destination and
wait a bit */ wait a bit */
return 0; return 0;
@@ -2304,10 +2306,10 @@ static void handle_response(struct mgcp_endpoint *p, struct mgcp_subchannel *sub
if (resp) { if (resp) {
if (req->cmd == MGCP_CMD_CRCX) { if (req->cmd == MGCP_CMD_CRCX) {
if ((c = get_header(resp, "I"))) { 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. */ /* SC: if we are hanging up do not process this conn. */
if (sub->owner) { if (sub->owner) {
if (strlen(sub->cxident)) { if (!ast_strlen_zero(sub->cxident)) {
if (strcasecmp(c, 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); ast_log(LOG_WARNING, "Subchannel already has a cxident. sub->cxident: %s requested %s\n", sub->cxident, c);
} }
@@ -2354,7 +2356,7 @@ static void handle_response(struct mgcp_endpoint *p, struct mgcp_subchannel *sub
/* Try to determine the hookstate returned from an audit endpoint command */ /* Try to determine the hookstate returned from an audit endpoint command */
if ((c = get_header(resp, "ES"))) { if ((c = get_header(resp, "ES"))) {
if (strlen(c)) { if (!ast_strlen_zero(c)) {
if (strstr(c, "hu")) { if (strstr(c, "hu")) {
if (p->hookstate != MGCP_ONHOOK) { if (p->hookstate != MGCP_ONHOOK) {
/* SC: XXX cleanup if we think we are offhook XXX */ /* SC: XXX cleanup if we think we are offhook XXX */
@@ -2559,7 +2561,7 @@ static void *mgcp_ss(void *data)
timeout = firstdigittimeout; timeout = firstdigittimeout;
} else if (p->callreturn && !strcmp(exten, "*69")) { } else if (p->callreturn && !strcmp(exten, "*69")) {
res = 0; res = 0;
if (strlen(p->lastcallerid)) { if (!ast_strlen_zero(p->lastcallerid)) {
res = ast_say_digit_str(chan, p->lastcallerid, "", chan->language); res = ast_say_digit_str(chan, p->lastcallerid, "", chan->language);
} }
if (!res) if (!res)
@@ -2614,7 +2616,7 @@ static void *mgcp_ss(void *data)
ast_verbose(VERBOSE_PREFIX_3 "Parking call to '%s'\n", chan->name); ast_verbose(VERBOSE_PREFIX_3 "Parking call to '%s'\n", chan->name);
} }
break; break;
} else if (strlen(p->lastcallerid) && !strcmp(exten, "*60")) { } else if (!ast_strlen_zero(p->lastcallerid) && !strcmp(exten, "*60")) {
if (option_verbose > 2) { if (option_verbose > 2) {
ast_verbose(VERBOSE_PREFIX_3 "Blacklisting number %s\n", p->lastcallerid); ast_verbose(VERBOSE_PREFIX_3 "Blacklisting number %s\n", p->lastcallerid);
} }
@@ -3161,7 +3163,7 @@ static int mgcpsock_read(int *id, int fd, short events, void *ignore)
/* Must have at least one header */ /* Must have at least one header */
return 1; 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)); ast_log(LOG_NOTICE, "Message from %s missing identifier\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr));
return 1; return 1;
} }
@@ -3204,9 +3206,9 @@ static int mgcpsock_read(int *id, int fd, short events, void *ignore)
gw->name, ident); gw->name, ident);
} }
} else { } else {
if (!req.endpoint || !strlen(req.endpoint) || if (!req.endpoint || ast_strlen_zero(req.endpoint) ||
!req.version || !strlen(req.version) || !req.version || ast_strlen_zero(req.version) ||
!req.verb || !strlen(req.verb)) { !req.verb || ast_strlen_zero(req.verb)) {
ast_log(LOG_NOTICE, "Message must have a verb, an idenitifier, version, and endpoint\n"); ast_log(LOG_NOTICE, "Message must have a verb, an idenitifier, version, and endpoint\n");
return 1; return 1;
} }
@@ -3360,7 +3362,7 @@ static struct ast_channel *mgcp_request(char *type, int format, void *data)
return NULL; return NULL;
} }
strncpy(tmp, dest, sizeof(tmp) - 1); strncpy(tmp, dest, sizeof(tmp) - 1);
if (!strlen(tmp)) { if (ast_strlen_zero(tmp)) {
ast_log(LOG_NOTICE, "MGCP Channels require an endpoint\n"); ast_log(LOG_NOTICE, "MGCP Channels require an endpoint\n");
return NULL; return NULL;
} }
@@ -3378,7 +3380,7 @@ static struct ast_channel *mgcp_request(char *type, int format, void *data)
/* Must be busy */ /* Must be busy */
if (((sub->parent->callwaiting) && ((sub->owner) && (sub->next->owner))) || if (((sub->parent->callwaiting) && ((sub->owner) && (sub->next->owner))) ||
((!sub->parent->callwaiting) && (sub->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 (sub->parent->hookstate == MGCP_ONHOOK) {
if (has_voicemail(sub->parent)) { if (has_voicemail(sub->parent)) {
transmit_notify_request(sub,"L/vmwi(+)"); transmit_notify_request(sub,"L/vmwi(+)");
@@ -3660,7 +3662,7 @@ static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v)
strncpy(e->language, language, sizeof(e->language) - 1); strncpy(e->language, language, sizeof(e->language) - 1);
strncpy(e->musicclass, musicclass, sizeof(e->musicclass)-1); strncpy(e->musicclass, musicclass, sizeof(e->musicclass)-1);
strncpy(e->mailbox, mailbox, sizeof(e->mailbox)-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 %s@%s\n", mailbox, gw->name, e->name); ast_verbose(VERBOSE_PREFIX_3 "Setting mailbox '%s' on %s@%s\n", mailbox, gw->name, e->name);
} }
if (!ep_reload) { if (!ep_reload) {
@@ -3839,7 +3841,7 @@ static void destroy_endpoint(struct mgcp_endpoint *e)
for (i = 0; i < MAX_SUBS; i++) { for (i = 0; i < MAX_SUBS; i++) {
ast_mutex_lock(&sub->lock); ast_mutex_lock(&sub->lock);
if (strlen(sub->cxident)) { if (!ast_strlen_zero(sub->cxident)) {
transmit_connection_del(sub); transmit_connection_del(sub);
} }
if (sub->rtp) { if (sub->rtp) {