Index: channels/chan_mgcp.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_mgcp.c,v retrieving revision 1.103 diff -u -r1.103 chan_mgcp.c --- channels/chan_mgcp.c 6 Jan 2005 08:16:43 -0000 1.103 +++ channels/chan_mgcp.c 8 Jan 2005 16:38:59 -0000 @@ -763,10 +763,10 @@ static int send_request(struct mgcp_endpoint *p, struct mgcp_subchannel *sub, struct mgcp_request *req, unsigned int seqno) { - int res = 0; - struct mgcp_request **queue, *q, *r, *t; + int res = 0; + struct mgcp_request **queue, *q, *r, *t; char iabuf[INET_ADDRSTRLEN]; - ast_mutex_t *l; + ast_mutex_t *l; ast_log(LOG_DEBUG, "Slow sequence is %d\n", p->slowsequence); if (p->slowsequence) { @@ -774,117 +774,116 @@ l = &p->cmd_queue_lock; ast_mutex_lock(l); } else - switch (req->cmd) { - case MGCP_CMD_DLCX: - queue = &sub->cx_queue; - l = &sub->cx_queue_lock; - ast_mutex_lock(l); - q = sub->cx_queue; - /* delete pending cx cmds */ - while (q) { - r = q->next; - free(q); - q = r; - } - *queue = NULL; - break; - - case MGCP_CMD_CRCX: - case MGCP_CMD_MDCX: - queue = &sub->cx_queue; - l = &sub->cx_queue_lock; - ast_mutex_lock(l); - break; - - case MGCP_CMD_RQNT: - queue = &p->rqnt_queue; - l = &p->rqnt_queue_lock; - ast_mutex_lock(l); - break; - - default: - queue = &p->cmd_queue; - l = &p->cmd_queue_lock; - ast_mutex_lock(l); - break; - } - - r = (struct mgcp_request *) malloc (sizeof(struct mgcp_request)); - if (!r) { - ast_log(LOG_WARNING, "Cannot post MGCP request: insufficient memory\n"); - ast_mutex_unlock(l); - return -1; - } - memcpy(r, req, sizeof(struct mgcp_request)); - - if (!(*queue)) { - if (mgcpdebug) { - 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)); - } - - res = mgcp_postrequest(p, sub, req->data, req->len, seqno); - } - else { - if (mgcpdebug) { - 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)); - } - } - - /* 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); - - r->next = NULL; - if (t) - t->next = r; - else - *queue = r; + switch (req->cmd) { + case MGCP_CMD_DLCX: + queue = &sub->cx_queue; + l = &sub->cx_queue_lock; + ast_mutex_lock(l); + q = sub->cx_queue; + /* delete pending cx cmds */ + while (q) { + r = q->next; + free(q); + q = r; + } + *queue = NULL; + break; + case MGCP_CMD_CRCX: + case MGCP_CMD_MDCX: + queue = &sub->cx_queue; + l = &sub->cx_queue_lock; + ast_mutex_lock(l); + break; + + case MGCP_CMD_RQNT: + queue = &p->rqnt_queue; + l = &p->rqnt_queue_lock; + ast_mutex_lock(l); + break; - ast_mutex_unlock(l); + default: + queue = &p->cmd_queue; + l = &p->cmd_queue_lock; + ast_mutex_lock(l); + break; + } + + r = (struct mgcp_request *) malloc (sizeof(struct mgcp_request)); + if (!r) { + ast_log(LOG_WARNING, "Cannot post MGCP request: insufficient memory\n"); + ast_mutex_unlock(l); + return -1; + } + memcpy(r, req, sizeof(struct mgcp_request)); - return res; + if (!(*queue)) { + if (mgcpdebug) { + 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)); + } + res = mgcp_postrequest(p, sub, req->data, req->len, seqno); + } else { + if (mgcpdebug) { + 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)); + } + } + + /* 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); + + r->next = NULL; + if (t) + t->next = r; + else + *queue = r; + + ast_mutex_unlock(l); + return res; } +/*--- mgcp_call: Interface to PBX core for placing a call from dial() ---*/ static int mgcp_call(struct ast_channel *ast, char *dest, int timeout) { - int res; - struct mgcp_endpoint *p; - struct mgcp_subchannel *sub; - char tone[50]=""; - char *distinctive_ring = NULL; - struct varshead *headp; - struct ast_var_t *current; - - if (mgcpdebug) { - ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_call(%s)\n", ast->name); - } - sub = ast->pvt->pvt; - p = sub->parent; - headp=&ast->varshead; - AST_LIST_TRAVERSE(headp,current,entries) { - /* Check whether there is a ALERT_INFO variable */ - if (strcasecmp(ast_var_name(current),"ALERT_INFO")==0) { - distinctive_ring = ast_var_value(current); - } - } - + - ast_mutex_lock(&sub->lock); - switch (p->hookstate) { - case MGCP_OFFHOOK: - snprintf(tone, sizeof(tone), "L/wt"); - break; - case MGCP_ONHOOK: - default: - if (distinctive_ring && !ast_strlen_zero(distinctive_ring)) { - snprintf(tone, sizeof(tone), "L/r%s", distinctive_ring); - ast_verbose(VERBOSE_PREFIX_2 "MGCP distinctive ring %s\n", tone); - } else { - snprintf(tone, sizeof(tone), "L/rg"); - ast_verbose(VERBOSE_PREFIX_2 "MGCP default ring\n"); - } - break; - } + int res; + struct mgcp_endpoint *p; + struct mgcp_subchannel *sub; + char tone[50]=""; + char *distinctive_ring = NULL; + struct varshead *headp; + struct ast_var_t *current; + + if (mgcpdebug && option_verbose > 2 ) { + ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_call(%s)\n", ast->name); + } + sub = ast->pvt->pvt; + p = sub->parent; + headp=&ast->varshead; + AST_LIST_TRAVERSE(headp,current,entries) { + /* Check whether there is a ALERT_INFO variable */ + if (strcasecmp(ast_var_name(current),"ALERT_INFO")==0) { + distinctive_ring = ast_var_value(current); + } + } + ast_mutex_lock(&sub->lock); + switch (p->hookstate) { + case MGCP_OFFHOOK: + snprintf(tone, sizeof(tone), "L/wt"); + break; + case MGCP_ONHOOK: + default: + if (distinctive_ring && !ast_strlen_zero(distinctive_ring)) { + snprintf(tone, sizeof(tone), "L/r%s", distinctive_ring); + if (option_verbose > 1) + ast_verbose(VERBOSE_PREFIX_2 "MGCP distinctive ring %s\n", tone); + } else { + snprintf(tone, sizeof(tone), "L/rg"); + if (option_verbose > 1) + ast_verbose(VERBOSE_PREFIX_2 "MGCP default ring\n"); + } + break; + } 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); @@ -917,7 +916,7 @@ transmit_modify_request(sub->next); } } else { - ast_log(LOG_NOTICE, "Don't know how to dial on trunks yet\n"); + ast_log(LOG_NOTICE, "Don't know how to dial on MGCP trunks yet\n"); res = -1; } ast_mutex_unlock(&sub->lock); @@ -930,7 +929,7 @@ struct mgcp_subchannel *sub = ast->pvt->pvt; struct mgcp_endpoint *p = sub->parent; - if (option_debug) { + if (mgcpdebug) { ast_log(LOG_DEBUG, "mgcp_hangup(%s)\n", ast->name); } if (!ast->pvt->pvt) { @@ -1055,7 +1054,7 @@ static char show_endpoints_usage[] = "Usage: mgcp show endpoints\n" -" Lists all endpoints known to the MGCP (Media Gateway Control Protocol) subsystem.\n"; +" Lists all endpoints known to the MGCP (Media Gateway Control Protocol) channel.\n"; static struct ast_cli_entry cli_show_endpoints = { { "mgcp", "show", "endpoints", NULL }, mgcp_show_endpoints, "Show defined MGCP endpoints", show_endpoints_usage }; @@ -1115,7 +1114,7 @@ static char audit_endpoint_usage[] = "Usage: mgcp audit endpoint \n" -" Lists the capabilities of an endpoint in the MGCP (Media Gateway Control Protocol) subsystem.\n" +" Lists the capabilities of an endpoint in the MGCP (Media Gateway Control Protocol) channel.\n" " mgcp debug MUST be on to see the results of this command.\n"; static struct ast_cli_entry cli_audit_endpoint = @@ -1134,7 +1133,6 @@ } else { transmit_modify_request(sub); } - /* SC: verbose level check */ if (option_verbose > 2) { ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_answer(%s) on %s@%s-%d\n", ast->name, p->name, p->parent->name, sub->id); @@ -1186,6 +1184,7 @@ { struct ast_frame *f; struct mgcp_subchannel *sub = ast->pvt->pvt; + ast_mutex_lock(&sub->lock); f = mgcp_rtp_read(sub); ast_mutex_unlock(&sub->lock); @@ -1196,6 +1195,7 @@ { struct mgcp_subchannel *sub = ast->pvt->pvt; int res = 0; + if (frame->frametype != AST_FRAME_VOICE) { if (frame->frametype == AST_FRAME_IMAGE) return 0; @@ -1392,7 +1392,6 @@ tmp = NULL; } } - /* SC: verbose level check */ if (option_verbose > 2) { ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_new(%s) created in state: %s\n", tmp->name, ast_state2str(state)); @@ -1449,7 +1448,7 @@ char *r; for (x=*start;xheaders;x++) { if (!strncasecmp(req->header[x], name, len) && - (req->header[x][len] == ':')) { + (req->header[x][len] == ':')) { r = req->header[x] + len + 1; while(*r && (*r < 33)) r++; @@ -1467,7 +1466,7 @@ return __get_header(req, name, &start); } -/* SC: get comma separated value */ +/* get_csv: get comma separated value */ static char *get_csv(char *c, int *len, char **next) { char *s; @@ -1558,11 +1557,11 @@ #if 0 /* SC: new transport mech */ sub = p->sub; do { - if (option_debug) + if (option_debug > 1) ast_log(LOG_DEBUG, "Searching on %s@%s-%d for subchannel with lastout: %d\n", p->name, g->name, sub->id, msgid); if (sub->lastout == msgid) { - if (option_debug) + if (option_debug > 1) ast_log(LOG_DEBUG, "Found subchannel sub%d to handle request %d sub->lastout: %d\n", sub->id, msgid, sub->lastout); found = 1; @@ -1574,13 +1573,12 @@ break; } #endif - /* SC */ sub = p->sub; found = 1; - /* SC */ break; } else if (name && !strcasecmp(p->name, tmp)) { - ast_log(LOG_DEBUG, "Coundn't determine subchannel, assuming current master %s@%s-%d\n", + if (option_debug) + ast_log(LOG_DEBUG, "Coundn't determine subchannel, assuming current master %s@%s-%d\n", p->name, g->name, p->sub->id); sub = p->sub; found = 1; @@ -1933,6 +1931,7 @@ int x; struct sockaddr_in dest; struct mgcp_endpoint *p = sub->parent; + /* XXX We break with the "recommendation" and send our IP, in order that our peer doesn't have to ast_gethostbyname() us XXX */ len = 0; @@ -2060,7 +2059,7 @@ struct mgcp_endpoint *p = sub->parent; snprintf(local, sizeof(local), "p:20"); - for (x=1;x<= AST_FORMAT_MAX_AUDIO; x <<= 1) { + for (x=1; x<= AST_FORMAT_MAX_AUDIO; x <<= 1) { if (p->capability & x) { snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x)); strncat(local, tmp, sizeof(local) - strlen(local) - 1); @@ -3468,7 +3467,7 @@ return NULL; } - if (option_verbose > 2) { + if (mgcpdebug) { ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_request(%s)\n", tmp); ast_verbose(VERBOSE_PREFIX_3 "MGCP cw: %d, dnd: %d, so: %d, sno: %d\n", sub->parent->callwaiting, sub->parent->dnd, sub->owner ? 1 : 0, sub->next->owner ? 1: 0); @@ -4188,7 +4187,8 @@ while (e && e->needaudit) { e->needaudit = 0; transmit_audit_endpoint(e); - ast_verbose(VERBOSE_PREFIX_3 "MGCP Auditing endpoint %s@%s for hookstate\n", e->name, g->name); + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "MGCP Auditing endpoint %s@%s for hookstate\n", e->name, g->name); e = e->next; } g = g->next; @@ -4308,6 +4308,11 @@ return -1; } #endif + ast_cli_unregister(&cli_show_endpoints); + ast_cli_unregister(&cli_audit_endpoint); + ast_cli_unregister(&cli_debug); + ast_cli_unregister(&cli_no_debug); + ast_cli_register(&cli_mgcp_reload); return -1; }