Module: sip-router
Branch: admorten/sca
Commit: 5219cf7a8e10f2308ceba3f8ab7de4ae5790ee5b
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5219cf7…
Author: Andrew Mortensen <admorten(a)isc.upenn.edu>
Committer: Andrew Mortensen <admorten(a)isc.upenn.edu>
Date: Tue Aug 20 15:14:26 2013 -0400
modules/sca: improved handling of host-only Contact URIs
---
modules/sca/sca_call_info.c | 25 ++++++++++---------------
modules/sca/sca_util.c | 18 ++++++++++++++++--
modules/sca/sca_util.h | 7 +++++++
3 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/modules/sca/sca_call_info.c b/modules/sca/sca_call_info.c
index 5b6b2c7..5e758b8 100644
--- a/modules/sca/sca_call_info.c
+++ b/modules/sca/sca_call_info.c
@@ -1142,11 +1142,10 @@ done:
}
static int
-sca_call_info_insert_asserted_identity( sip_msg_t *msg, str *contact_uri,
- struct to_body *tf )
+sca_call_info_insert_asserted_identity( sip_msg_t *msg, str *display,
+ int ua_type )
{
struct lump *anchor;
- sip_uri_t c_uri;
str aor = STR_NULL;
str hdr = STR_NULL;
int len;
@@ -1158,22 +1157,17 @@ sca_call_info_insert_asserted_identity( sip_msg_t *msg, str
*contact_uri,
goto done;
}
- if ( parse_uri( contact_uri->s, contact_uri->len, &c_uri ) < 0 ) {
- LM_ERR( "insert_asserted_identity: parse_uri %.*s failed",
- STR_FMT( contact_uri ));
- return( -1 );
- }
- if ( sca_aor_create_from_info( &aor, c_uri.type, &c_uri.user,
- &GET_TO_PURI( msg )->host, &GET_TO_PURI( msg )->port ) < 0 ) {
- LM_ERR( "insert_asserted_identity: sca_aor_create_from_info failed" );
- return( -1 );
+ if ( sca_create_canonical_aor_for_ua( msg, &aor, ua_type ) < 0 ) {
+ LM_ERR( "sca_call_info_insert_asserted_identity: failed to create "
+ "canonical AoR" );
+ goto done;
}
#define SCA_P_ASSERTED_IDENTITY_HDR_PREFIX "P-Asserted-Identity: "
#define SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN strlen("P-Asserted-Identity: ")
len = SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN;
- len += tf->display.len;
+ len += display->len;
/* +1 for space, +1 for <, + 1 for > */
len += 1 + 1 + aor.len + 1 + CRLF_LEN;
@@ -1187,7 +1181,7 @@ sca_call_info_insert_asserted_identity( sip_msg_t *msg, str
*contact_uri,
SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN );
hdr.len = SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN;
- SCA_STR_APPEND( &hdr, &tf->display );
+ SCA_STR_APPEND( &hdr, display );
*(hdr.s + hdr.len) = ' ';
hdr.len++;
@@ -1246,7 +1240,8 @@ sca_call_info_invite_reply_200_handler( sip_msg_t *msg,
goto done;
}
- if ( sca_call_info_insert_asserted_identity( msg, contact_uri, to ) < 0 ) {
+ if ( sca_call_info_insert_asserted_identity( msg, &to->display,
+ SCA_AOR_TYPE_UAS ) < 0 ) {
LM_WARN( "sca_call_info_invite_reply_200_handler: failed to "
"add P-Asserted-Identity header to response from %.*s",
STR_FMT( contact_uri ));
diff --git a/modules/sca/sca_util.c b/modules/sca/sca_util.c
index a9f959e..143ac47 100644
--- a/modules/sca/sca_util.c
+++ b/modules/sca/sca_util.c
@@ -340,7 +340,7 @@ sca_aor_create_from_info( str *aor, uri_type type, str *user, str
*domain,
}
int
-sca_create_canonical_aor( sip_msg_t *msg, str *c_aor )
+sca_create_canonical_aor_for_ua( sip_msg_t *msg, str *c_aor, int ua_opts )
{
struct to_body *tf = NULL;
sip_uri_t c_uri;
@@ -353,7 +353,15 @@ sca_create_canonical_aor( sip_msg_t *msg, str *c_aor )
memset( c_aor, 0, sizeof( str ));
- if ( msg->first_line.type == SIP_REQUEST ) {
+ if (( ua_opts & SCA_AOR_TYPE_AUTO )) {
+ if ( msg->first_line.type == SIP_REQUEST ) {
+ ua_opts = SCA_AOR_TYPE_UAC;
+ } else {
+ ua_opts = SCA_AOR_TYPE_UAS;
+ }
+ }
+
+ if (( ua_opts & SCA_AOR_TYPE_UAC )) {
if ( sca_get_msg_from_header( msg, &tf ) < 0 ) {
LM_ERR( "sca_create_canonical_aor: failed to get From header" );
goto done;
@@ -410,6 +418,12 @@ done:
return( rc );
}
+ int
+sca_create_canonical_aor( sip_msg_t *msg, str *c_aor )
+{
+ return( sca_create_canonical_aor_for_ua( msg, c_aor, SCA_AOR_TYPE_AUTO ));
+}
+
/* XXX this considers any held stream to mean the call is on hold. correct? */
int
sca_call_is_held( sip_msg_t *msg )
diff --git a/modules/sca/sca_util.h b/modules/sca/sca_util.h
index 012148b..b2f01ee 100644
--- a/modules/sca/sca_util.h
+++ b/modules/sca/sca_util.h
@@ -26,6 +26,12 @@
#include "sca_common.h"
+enum {
+ SCA_AOR_TYPE_AUTO = (1 << 0),
+ SCA_AOR_TYPE_UAC = (1 << 1),
+ SCA_AOR_TYPE_UAS = (1 << 2),
+};
+
/* get method, regardless of whether message is a request or response */
int sca_get_msg_method( sip_msg_t * );
@@ -55,6 +61,7 @@ int sca_uri_build_aor( str *, int, str *, str * );
int sca_aor_create_from_info( str *, uri_type, str *, str *, str * );
+int sca_create_canonical_aor_for_ua( sip_msg_t *, str *, int );
int sca_create_canonical_aor( sip_msg_t *, str * );
/* convenient call hold detection */