Fix MGCP when running without verbose (bug #3260)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4741 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2005-01-10 00:43:01 +00:00
parent 847de38584
commit 4fc6c2eb0d

View File

@@ -763,128 +763,132 @@ static int mgcp_postrequest(struct mgcp_endpoint *p, struct mgcp_subchannel *sub
static int send_request(struct mgcp_endpoint *p, struct mgcp_subchannel *sub, static int send_request(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
struct mgcp_request *req, unsigned int seqno) struct mgcp_request *req, unsigned int seqno)
{ {
int res = 0; int res = 0;
struct mgcp_request **queue, *q, *r, *t; struct mgcp_request **queue, *q, *r, *t;
char iabuf[INET_ADDRSTRLEN]; char iabuf[INET_ADDRSTRLEN];
ast_mutex_t *l; ast_mutex_t *l;
ast_log(LOG_DEBUG, "Slow sequence is %d\n", p->slowsequence); ast_log(LOG_DEBUG, "Slow sequence is %d\n", p->slowsequence);
if (p->slowsequence) { if (p->slowsequence) {
queue = &p->cmd_queue; queue = &p->cmd_queue;
l = &p->cmd_queue_lock; l = &p->cmd_queue_lock;
ast_mutex_lock(l); ast_mutex_lock(l);
} else } else {
switch (req->cmd) { switch (req->cmd) {
case MGCP_CMD_DLCX: case MGCP_CMD_DLCX:
queue = &sub->cx_queue; queue = &sub->cx_queue;
l = &sub->cx_queue_lock; l = &sub->cx_queue_lock;
ast_mutex_lock(l); ast_mutex_lock(l);
q = sub->cx_queue; q = sub->cx_queue;
/* delete pending cx cmds */ /* delete pending cx cmds */
while (q) { while (q) {
r = q->next; r = q->next;
free(q); free(q);
q = r; q = r;
} }
*queue = NULL; *queue = NULL;
break; break;
case MGCP_CMD_CRCX: case MGCP_CMD_CRCX:
case MGCP_CMD_MDCX: case MGCP_CMD_MDCX:
queue = &sub->cx_queue; queue = &sub->cx_queue;
l = &sub->cx_queue_lock; l = &sub->cx_queue_lock;
ast_mutex_lock(l); ast_mutex_lock(l);
break; break;
case MGCP_CMD_RQNT: case MGCP_CMD_RQNT:
queue = &p->rqnt_queue; queue = &p->rqnt_queue;
l = &p->rqnt_queue_lock; l = &p->rqnt_queue_lock;
ast_mutex_lock(l); ast_mutex_lock(l);
break; break;
default: default:
queue = &p->cmd_queue; queue = &p->cmd_queue;
l = &p->cmd_queue_lock; l = &p->cmd_queue_lock;
ast_mutex_lock(l); ast_mutex_lock(l);
break; break;
} }
}
r = (struct mgcp_request *) malloc (sizeof(struct mgcp_request)); r = (struct mgcp_request *) malloc (sizeof(struct mgcp_request));
if (!r) { if (!r) {
ast_log(LOG_WARNING, "Cannot post MGCP request: insufficient memory\n"); ast_log(LOG_WARNING, "Cannot post MGCP request: insufficient memory\n");
ast_mutex_unlock(l); ast_mutex_unlock(l);
return -1; return -1;
} }
memcpy(r, req, sizeof(struct mgcp_request)); memcpy(r, req, sizeof(struct mgcp_request));
if (!(*queue)) { if (!(*queue)) {
if (mgcpdebug) { if (mgcpdebug) {
ast_verbose("Posting Request:\n%s to %s:%d\n", req->data, ast_verbose("Posting Request:\n%s to %s:%d\n", req->data,
ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
} }
res = mgcp_postrequest(p, sub, req->data, req->len, seqno); res = mgcp_postrequest(p, sub, req->data, req->len, seqno);
} } else {
else { if (mgcpdebug) {
if (mgcpdebug) { ast_verbose("Queueing Request:\n%s to %s:%d\n", req->data,
ast_verbose("Queueing Request:\n%s to %s:%d\n", req->data, ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); }
} }
}
/* XXX SC: find tail. We could also keep tail in the data struct for faster access */ /* XXX SC: find tail. We could also keep tail in the data struct for faster access */
for (t = *queue; t && t->next; t = t->next); for (t = *queue; t && t->next; t = t->next);
r->next = NULL; r->next = NULL;
if (t) if (t)
t->next = r; t->next = r;
else else
*queue = r; *queue = r;
ast_mutex_unlock(l); ast_mutex_unlock(l);
return res; return res;
} }
static int mgcp_call(struct ast_channel *ast, char *dest, int timeout) static int mgcp_call(struct ast_channel *ast, char *dest, int timeout)
{ {
int res; int res;
struct mgcp_endpoint *p; struct mgcp_endpoint *p;
struct mgcp_subchannel *sub; struct mgcp_subchannel *sub;
char tone[50]=""; char tone[50] = "";
char *distinctive_ring = NULL; char *distinctive_ring = NULL;
struct varshead *headp; struct varshead *headp;
struct ast_var_t *current; struct ast_var_t *current;
if (mgcpdebug) { if (mgcpdebug) {
ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_call(%s)\n", ast->name); ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_call(%s)\n", ast->name);
} }
sub = ast->pvt->pvt; sub = ast->pvt->pvt;
p = sub->parent; p = sub->parent;
headp=&ast->varshead; headp = &ast->varshead;
AST_LIST_TRAVERSE(headp,current,entries) { AST_LIST_TRAVERSE(headp,current,entries) {
/* Check whether there is a ALERT_INFO variable */ /* Check whether there is an ALERT_INFO variable */
if (strcasecmp(ast_var_name(current),"ALERT_INFO")==0) { if (strcasecmp(ast_var_name(current),"ALERT_INFO") == 0) {
distinctive_ring = ast_var_value(current); distinctive_ring = ast_var_value(current);
} }
} }
+
ast_mutex_lock(&sub->lock); ast_mutex_lock(&sub->lock);
switch (p->hookstate) { switch (p->hookstate) {
case MGCP_OFFHOOK: case MGCP_OFFHOOK:
snprintf(tone, sizeof(tone), "L/wt"); snprintf(tone, sizeof(tone), "L/wt");
break; break;
case MGCP_ONHOOK: case MGCP_ONHOOK:
default: default:
if (distinctive_ring && !ast_strlen_zero(distinctive_ring)) { if (distinctive_ring && !ast_strlen_zero(distinctive_ring)) {
snprintf(tone, sizeof(tone), "L/r%s", distinctive_ring); snprintf(tone, sizeof(tone), "L/r%s", distinctive_ring);
ast_verbose(VERBOSE_PREFIX_2 "MGCP distinctive ring %s\n", tone); if (mgcpdebug) {
} else { ast_verbose(VERBOSE_PREFIX_3 "MGCP distinctive ring %s\n", tone);
snprintf(tone, sizeof(tone), "L/rg"); }
ast_verbose(VERBOSE_PREFIX_2 "MGCP default ring\n"); } else {
} snprintf(tone, sizeof(tone), "L/rg");
break; if (mgcpdebug) {
} ast_verbose(VERBOSE_PREFIX_3 "MGCP default ring\n");
}
}
break;
}
if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
ast_log(LOG_WARNING, "mgcp_call called on %s, neither down nor reserved\n", ast->name); ast_log(LOG_WARNING, "mgcp_call called on %s, neither down nor reserved\n", ast->name);
@@ -3143,15 +3147,13 @@ static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req,
} else { } else {
/* SC: verbose level check */ /* SC: verbose level check */
if (option_verbose > 2) { if (option_verbose > 2) {
if (option_verbose > 2) { ast_verbose(VERBOSE_PREFIX_3 "MGCP handle_request(%s@%s-%d) ast_channel already destroyed, resending DLCX.\n",
ast_verbose(VERBOSE_PREFIX_3 "MGCP handle_request(%s@%s-%d) ast_channel already destroyed, resending DLCX.\n", p->name, p->parent->name, sub->id);
p->name, p->parent->name, sub->id);
}
/* Instruct the other side to remove the connection since it apparently *
* still thinks the channel is active. *
* For Cisco IAD2421 /BAK/ */
transmit_connection_del(sub);
} }
/* Instruct the other side to remove the connection since it apparently *
* still thinks the channel is active. *
* For Cisco IAD2421 /BAK/ */
transmit_connection_del(sub);
} }
} }
if ((p->hookstate == MGCP_ONHOOK) && (!sub->rtp) && (!sub->next->rtp)) { if ((p->hookstate == MGCP_ONHOOK) && (!sub->rtp) && (!sub->next->rtp)) {