Module: sip-router
Branch: master
Commit: 635ac3061b55566b08d31cafcb75e716631c1096
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=635ac30…
Author: Juha Heinanen <jh(a)tutpro.com>
Committer: Juha Heinanen <jh(a)tutpro.com>
Date: Wed Apr 21 10:55:53 2010 +0300
modules/mediaproxy: some minor bug fixes and code cleanups
- Changed some comparisons to be case insensitive.
- Renamed some variables.
- Fixed testing of existence of to tag.
- Some editorial cleanups.
---
modules/mediaproxy/mediaproxy.c | 89 +++++++++++++++++++--------------------
1 files changed, 43 insertions(+), 46 deletions(-)
diff --git a/modules/mediaproxy/mediaproxy.c b/modules/mediaproxy/mediaproxy.c
index 1308c8b..c2d072c 100644
--- a/modules/mediaproxy/mediaproxy.c
+++ b/modules/mediaproxy/mediaproxy.c
@@ -1,16 +1,15 @@
-/* $Id$
- *
+/*
* Copyright (C) 2004-2008 Dan Pascu
* Copyright (C) 2009 Juha Heinanen (multipart hack)
*
- * This file is part of Kamailio, a free SIP server.
+ * This file is part of SIP-Router, a free SIP server.
*
- * Kamailio is free software; you can redistribute it and/or modify
+ * SIP-router is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
- * Kamailio is distributed in the hope that it will be useful,
+ * SIP-router is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
@@ -18,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
*/
#include <stdio.h>
@@ -79,7 +77,7 @@ MODULE_VERSION
#endif
// As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall,
-//it is defined as 0
+// it is defined as 0
#ifndef MSG_NOSIGNAL
# define MSG_NOSIGNAL 0
#endif
@@ -501,21 +499,21 @@ get_cseq_number(struct sip_msg *msg, str *cseq)
static str
get_from_uri(struct sip_msg *msg)
{
- static str notfound = str_init("unknown");
+ static str unknown = str_init("unknown");
str uri;
char *ptr;
if (parse_from_header(msg) < 0) {
LM_ERR("cannot parse the From header\n");
- return notfound;
+ return unknown;
}
uri = get_from(msg)->uri;
if (uri.len == 0)
- return notfound;
+ return unknown;
- if (strncmp(uri.s, "sip:", 4)==0) {
+ if (strncasecmp(uri.s, "sip:", 4)==0) {
uri.s += 4;
uri.len -= 4;
}
@@ -531,21 +529,21 @@ get_from_uri(struct sip_msg *msg)
static str
get_to_uri(struct sip_msg *msg)
{
- static str notfound = str_init("unknown");
+ static str unknown = str_init("unknown");
str uri;
char *ptr;
if (!msg->to) {
LM_ERR("missing To header\n");
- return notfound;
+ return unknown;
}
uri = get_to(msg)->uri;
if (uri.len == 0)
- return notfound;
+ return unknown;
- if (strncmp(uri.s, "sip:", 4)==0) {
+ if (strncasecmp(uri.s, "sip:", 4)==0) {
uri.s += 4;
uri.len -= 4;
}
@@ -561,18 +559,18 @@ get_to_uri(struct sip_msg *msg)
static str
get_from_tag(struct sip_msg *msg)
{
- static str notfound = str_init("");
+ static str undefined = str_init("");
str tag;
if (parse_from_header(msg) < 0) {
LM_ERR("cannot parse the From header\n");
- return notfound;
+ return undefined;
}
tag = get_from(msg)->tag_value;
if (tag.len == 0)
- return notfound;
+ return undefined;
return tag;
}
@@ -581,23 +579,23 @@ get_from_tag(struct sip_msg *msg)
static str
get_to_tag(struct sip_msg *msg)
{
- static str notfound = str_init("");
+ static str undefined = str_init("");
str tag;
- if (!msg->to) {
- LM_ERR("missing To header\n");
- return notfound;
+ if (msg->first_line.type==SIP_REPLY && msg->REPLY_STATUS<200) {
+ // Ignore the To tag for provisional replies
+ return undefined;
}
- if (msg->first_line.type==SIP_REPLY && msg->REPLY_STATUS<200) {
- // Ignore the To tag for provisional replies
- return notfound;
+ if (!msg->to) {
+ LM_ERR("missing To header\n");
+ return undefined;
}
tag = get_to(msg)->tag_value;
if (tag.len == 0)
- return notfound;
+ return undefined;
return tag;
}
@@ -606,7 +604,7 @@ get_to_tag(struct sip_msg *msg)
static str
get_user_agent(struct sip_msg* msg)
{
- static str notfound = str_init("unknown agent");
+ static str unknown = str_init("unknown agent");
str block, server;
char *ptr;
@@ -616,21 +614,21 @@ get_user_agent(struct sip_msg* msg)
}
// If we can't find user-agent, look after the `Server' header
- // This is a temporary hack. Normally it should be extracted by openser.
+ // This is a temporary hack. Normally it should be extracted by sip-router.
block.s = msg->buf;
block.len = msg->len;
ptr = find_line_starting_with(&block, "Server:", True);
if (!ptr)
- return notfound;
+ return unknown;
server.s = ptr + 7;
server.len = findendline(server.s, block.s+block.len-server.s) - server.s;
trim(&server);
if (server.len == 0)
- return notfound;
+ return unknown;
return server;
}
@@ -657,12 +655,12 @@ get_signaling_ip(struct sip_msg* msg)
static str
get_media_relay(struct sip_msg* msg)
{
- static str notfound = str_init("");
+ static str undefined = str_init("");
int_str value;
if (!search_first_avp(media_relay_avp.type | AVP_VAL_STR,
media_relay_avp.name, &value, NULL) || value.s.s==NULL ||
value.s.len==0) {
- return notfound;
+ return undefined;
}
return value.s;
@@ -672,6 +670,7 @@ get_media_relay(struct sip_msg* msg)
// Functions to manipulate the SDP message body
//
+
static int
find_content_type_application_sdp(struct sip_msg *msg, str *sdp)
{
@@ -848,8 +847,8 @@ get_direction_attribute(str *block, str *default_direction)
line.len = findendline(line.s, zone.s + zone.len - line.s) - line.s;
if (line.len==8) {
- if (strncmp(line.s, "sendrecv", 8)==0 || strncmp(line.s,
"sendonly", 8)==0 ||
- strncmp(line.s, "recvonly", 8)==0 || strncmp(line.s,
"inactive", 8)==0) {
+ if (strncasecmp(line.s, "sendrecv", 8)==0 || strncasecmp(line.s,
"sendonly", 8)==0 ||
+ strncasecmp(line.s, "recvonly", 8)==0 || strncasecmp(line.s,
"inactive", 8)==0) {
return line;
}
}
@@ -865,14 +864,14 @@ get_direction_attribute(str *block, str *default_direction)
static str
get_rtcp_port_attribute(str *block)
{
- str zone, rtcp_port, notfound = {NULL, 0};
+ str zone, rtcp_port, undefined = {NULL, 0};
char *ptr;
int count;
ptr = find_line_starting_with(block, "a=rtcp:", False);
if (!ptr)
- return notfound;
+ return undefined;
zone.s = ptr + 7;
zone.len = findendline(zone.s, block->s + block->len - zone.s) - zone.s;
@@ -881,7 +880,7 @@ get_rtcp_port_attribute(str *block)
if (count != 1) {
LM_ERR("invalid `a=rtcp' line in SDP body\n");
- return notfound;
+ return undefined;
}
return rtcp_port;
@@ -1611,8 +1610,7 @@ use_media_proxy(struct sip_msg *msg, char *dialog_id,
ice_candidate_data *ice_da
media_relay.len, media_relay.s, media_str);
if (len >= sizeof(request)) {
- LM_ERR("mediaproxy request is longer than %lu bytes\n",
- (unsigned long)sizeof(request));
+ LM_ERR("mediaproxy request is longer than %lu bytes\n", (unsigned
long)sizeof(request));
return -1;
}
@@ -1791,8 +1789,7 @@ end_media_session(str callid, str from_tag, str to_tag)
to_tag.len, to_tag.s);
if (len >= sizeof(request)) {
- LM_ERR("mediaproxy request is longer than %lu bytes\n",
- (unsigned long)sizeof(request));
+ LM_ERR("mediaproxy request is longer than %lu bytes\n", (unsigned
long)sizeof(request));
return -1;
}
@@ -1953,7 +1950,7 @@ mod_init(void)
{
pv_spec_t avp_spec;
int *param;
- modparam_t type;
+ modparam_t type;
// initialize the signaling_ip_avp structure
if (signaling_ip_avp.spec.s==NULL || *(signaling_ip_avp.spec.s)==0) {
@@ -2018,10 +2015,10 @@ mod_init(void)
return -1;
}
- if (type != INT_PARAM) {
- LM_CRIT("dlg_flag parameter found but with wrong type: %d\n", type);
- return -1;
- }
+ if (type != INT_PARAM) {
+ LM_CRIT("dlg_flag parameter found but with wrong type: %d\n", type);
+ return -1;
+ }
dialog_flag = *param;