Browse code

modules/sca: improved handling of host-only Contact URIs (cherry picked from commit bf747c2d65aeaa74d1cea4e0a531607415e8d17d)

Andrew Mortensen authored on 20/08/2013 19:14:26
Showing 3 changed files
... ...
@@ -1142,11 +1142,10 @@ done:
1142 1142
 }
1143 1143
 
1144 1144
     static int
1145
-sca_call_info_insert_asserted_identity( sip_msg_t *msg, str *contact_uri,
1146
-	struct to_body *tf )
1145
+sca_call_info_insert_asserted_identity( sip_msg_t *msg, str *display,
1146
+	int ua_type )
1147 1147
 {
1148 1148
     struct lump		*anchor;
1149
-    sip_uri_t		c_uri;
1150 1149
     str			aor = STR_NULL;
1151 1150
     str			hdr = STR_NULL;
1152 1151
     int			len;
... ...
@@ -1158,22 +1157,17 @@ sca_call_info_insert_asserted_identity( sip_msg_t *msg, str *contact_uri,
1158 1157
 	goto done;
1159 1158
     }
1160 1159
     
1161
-    if ( parse_uri( contact_uri->s, contact_uri->len, &c_uri ) < 0 ) {
1162
-	LM_ERR( "insert_asserted_identity: parse_uri %.*s failed",
1163
-		STR_FMT( contact_uri ));
1164
-	return( -1 );
1165
-    }
1166
-    if ( sca_aor_create_from_info( &aor, c_uri.type, &c_uri.user,
1167
-		&GET_TO_PURI( msg )->host, &GET_TO_PURI( msg )->port ) < 0 ) {
1168
-	LM_ERR( "insert_asserted_identity: sca_aor_create_from_info failed" );
1169
-	return( -1 );
1160
+    if ( sca_create_canonical_aor_for_ua( msg, &aor, ua_type ) < 0 ) {
1161
+	LM_ERR( "sca_call_info_insert_asserted_identity: failed to create "
1162
+		"canonical AoR" );
1163
+	goto done;
1170 1164
     }
1171 1165
 
1172 1166
 #define SCA_P_ASSERTED_IDENTITY_HDR_PREFIX	"P-Asserted-Identity: "
1173 1167
 #define SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN	strlen("P-Asserted-Identity: ")
1174 1168
 
1175 1169
     len = SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN;
1176
-    len += tf->display.len;
1170
+    len += display->len;
1177 1171
     /* +1 for space, +1 for <, + 1 for > */
1178 1172
     len += 1 + 1 + aor.len + 1 + CRLF_LEN;
1179 1173
 
... ...
@@ -1187,7 +1181,7 @@ sca_call_info_insert_asserted_identity( sip_msg_t *msg, str *contact_uri,
1187 1181
 		    SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN );
1188 1182
     hdr.len = SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN;
1189 1183
 
1190
-    SCA_STR_APPEND( &hdr, &tf->display );
1184
+    SCA_STR_APPEND( &hdr, display );
1191 1185
 
1192 1186
     *(hdr.s + hdr.len) = ' ';
1193 1187
     hdr.len++;
... ...
@@ -1246,7 +1240,8 @@ sca_call_info_invite_reply_200_handler( sip_msg_t *msg,
1246 1240
 	goto done;
1247 1241
     }
1248 1242
 
1249
-    if ( sca_call_info_insert_asserted_identity( msg, contact_uri, to ) < 0 ) {
1243
+    if ( sca_call_info_insert_asserted_identity( msg, &to->display,
1244
+		SCA_AOR_TYPE_UAS ) < 0 ) {
1250 1245
 	LM_WARN( "sca_call_info_invite_reply_200_handler: failed to "
1251 1246
 		"add P-Asserted-Identity header to response from %.*s",
1252 1247
 		STR_FMT( contact_uri ));
... ...
@@ -340,7 +340,7 @@ sca_aor_create_from_info( str *aor, uri_type type, str *user, str *domain,
340 340
 }
341 341
 
342 342
     int
343
-sca_create_canonical_aor( sip_msg_t *msg, str *c_aor )
343
+sca_create_canonical_aor_for_ua( sip_msg_t *msg, str *c_aor, int ua_opts )
344 344
 {
345 345
     struct to_body	*tf = NULL;
346 346
     sip_uri_t		c_uri;
... ...
@@ -353,7 +353,15 @@ sca_create_canonical_aor( sip_msg_t *msg, str *c_aor )
353 353
 
354 354
     memset( c_aor, 0, sizeof( str ));
355 355
 
356
-    if ( msg->first_line.type == SIP_REQUEST ) {
356
+    if (( ua_opts & SCA_AOR_TYPE_AUTO )) {
357
+	if ( msg->first_line.type == SIP_REQUEST ) {
358
+	    ua_opts = SCA_AOR_TYPE_UAC;
359
+	} else {
360
+	    ua_opts = SCA_AOR_TYPE_UAS;
361
+	}
362
+    }
363
+
364
+    if (( ua_opts & SCA_AOR_TYPE_UAC )) {
357 365
 	if ( sca_get_msg_from_header( msg, &tf ) < 0 ) {
358 366
 	    LM_ERR( "sca_create_canonical_aor: failed to get From header" );
359 367
 	    goto done;
... ...
@@ -410,6 +418,12 @@ done:
410 418
     return( rc );
411 419
 }
412 420
 
421
+    int
422
+sca_create_canonical_aor( sip_msg_t *msg, str *c_aor )
423
+{
424
+    return( sca_create_canonical_aor_for_ua( msg, c_aor, SCA_AOR_TYPE_AUTO ));
425
+}
426
+
413 427
 /* XXX this considers any held stream to mean the call is on hold. correct? */
414 428
     int
415 429
 sca_call_is_held( sip_msg_t *msg )
... ...
@@ -26,6 +26,12 @@
26 26
 
27 27
 #include "sca_common.h"
28 28
 
29
+enum {
30
+    SCA_AOR_TYPE_AUTO = (1 << 0),
31
+    SCA_AOR_TYPE_UAC = (1 << 1),
32
+    SCA_AOR_TYPE_UAS = (1 << 2),
33
+};
34
+
29 35
 /* get method, regardless of whether message is a request or response */
30 36
 int	sca_get_msg_method( sip_msg_t * );
31 37
 
... ...
@@ -55,6 +61,7 @@ int	sca_uri_build_aor( str *, int, str *, str * );
55 61
 
56 62
 int	sca_aor_create_from_info( str *, uri_type, str *, str *, str * );
57 63
 
64
+int	sca_create_canonical_aor_for_ua( sip_msg_t *, str *, int );
58 65
 int	sca_create_canonical_aor( sip_msg_t *, str * );
59 66
 
60 67
 /* convenient call hold detection */