From 41129c57bd77b427e98bf09d740c28462a49b5c5 Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Mon, 14 Apr 2003 20:48:30 +0000 Subject: [PATCH] Trim down gateway names with []'s in them git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@850 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_mgcp.c | 15 ++++++++++++--- rtp.c | 27 ++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 96c67ecf3c..0975072b5c 100755 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -448,7 +448,7 @@ static int mgcp_audit_endpoint(int fd, int argc, char *argv[]) struct mgcp_gateway *g; struct mgcp_endpoint *e; int found = 0; - char *ename,*gname; + char *ename,*gname, *c; if (!mgcpdebug) { return RESULT_SHOWUSAGE; } @@ -465,7 +465,10 @@ static int mgcp_audit_endpoint(int fd, int argc, char *argv[]) } gname++; } - + if (gname[0] == '[') + gname++; + if ((c = strrchr(gname, ']'))) + *c = '\0'; ast_pthread_mutex_lock(&gatelock); g = gateways; while(g) { @@ -778,7 +781,7 @@ static struct mgcp_endpoint *find_endpoint(char *name, int msgid, struct sockadd struct mgcp_endpoint *p = NULL; struct mgcp_gateway *g; char tmp[256] = ""; - char *at = NULL; + char *at = NULL, *c; if (name) { strncpy(tmp, name, sizeof(tmp) - 1); at = strchr(tmp, '@'); @@ -790,6 +793,12 @@ static struct mgcp_endpoint *find_endpoint(char *name, int msgid, struct sockadd at++; } ast_pthread_mutex_lock(&gatelock); + if (at && (at[0] == '[')) { + at++; + c = strrchr(at, ']'); + if (c) + *c = '\0'; + } g = gateways; while(g) { if ((!name || !strcasecmp(g->name, at)) && diff --git a/rtp.c b/rtp.c index 57a4854e08..3e02849e13 100755 --- a/rtp.c +++ b/rtp.c @@ -891,6 +891,9 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st struct ast_channel *who, *cs[3]; struct ast_rtp *p0, *p1; struct ast_rtp_protocol *pr0, *pr1; + struct sockaddr_in ac0, ac1; + struct sockaddr_in t0, t1; + void *pvt0, *pvt1; int to; @@ -933,8 +936,16 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st } if (pr0->set_rtp_peer(c0, p1)) ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name); - if (pr1->set_rtp_peer(c1, p0)) + else { + /* Store RTP peer */ + ast_rtp_get_peer(p1, &ac1); + } + if (pr1->set_rtp_peer(c1, p0)) ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", c1->name, c0->name); + else { + /* Store RTP peer */ + ast_rtp_get_peer(p0, &ac0); + } ast_pthread_mutex_unlock(&c0->lock); ast_pthread_mutex_unlock(&c1->lock); cs[0] = c0; @@ -957,6 +968,20 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st return -3; } to = -1; + ast_rtp_get_peer(p1, &t1); + ast_rtp_get_peer(p0, &t0); + if (inaddrcmp(&t1, &ac1)) { + ast_log(LOG_DEBUG, "Oooh, '%s' changed end address\n", c1->name); + if (pr0->set_rtp_peer(c0, p1)) + ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c0->name, c1->name); + memcpy(&ac1, &t1, sizeof(ac1)); + } + if (inaddrcmp(&t0, &ac0)) { + ast_log(LOG_DEBUG, "Oooh, '%s' changed end address\n", c0->name); + if (pr1->set_rtp_peer(c1, p0)) + ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c1->name, c0->name); + memcpy(&ac0, &t0, sizeof(ac0)); + } who = ast_waitfor_n(cs, 2, &to); if (!who) { ast_log(LOG_DEBUG, "Ooh, empty read...\n");