@@ -369,6 +369,26 @@ static char * topo_ct_param_copy(char *buf, str *name, str *val, int should_quot
369
369
return buf ;
370
370
}
371
371
372
+ static int is_forced_sips_contact_required (const struct sip_msg * msg , const struct dlg_cell * dlg , const uri_type ct_type ) {
373
+ str top_rr ;
374
+
375
+ if (dlg -> state != DLG_STATE_UNCONFIRMED ) return 0 ;
376
+
377
+ // RURI is SIPS
378
+ if (msg -> parsed_uri_ok && msg -> parsed_uri .type == SIPS_URI_T ) return 1 ;
379
+
380
+ if (msg -> record_route == NULL ) {
381
+ // RR is NULL and Contact is SIPS
382
+ if (ct_type == SIPS_URI_T ) return 1 ;
383
+ } else {
384
+ // Top RR is SIPS
385
+ top_rr = ((rr_t * )msg -> record_route -> parsed )-> nameaddr .uri ;
386
+ if ((top_rr .len > 5 && strncmp (top_rr .s , "sips:" , 5 ) == 0 )) return 1 ;
387
+ }
388
+
389
+ return 0 ;
390
+ }
391
+
372
392
static int topo_dlg_replace_contact (struct sip_msg * msg , struct dlg_cell * dlg )
373
393
{
374
394
char * prefix = NULL ,* suffix = NULL ,* p ,* p_init ,* ct_username = NULL ;
@@ -379,6 +399,7 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
379
399
param_t * it ;
380
400
str * rr_param ;
381
401
struct lump * lump ;
402
+ uri_type ct_type ;
382
403
383
404
if (!msg -> contact )
384
405
{
@@ -408,6 +429,8 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
408
429
} else {
409
430
ct_username = ctu .user .s ;
410
431
ct_username_len = ctu .user .len ;
432
+ ct_type = ctu .type ;
433
+ if (ct_type == SIPS_URI_T ) prefix_len += 1 ;
411
434
LM_DBG ("Trying to propagate username [%.*s]\n" ,ct_username_len ,
412
435
ct_username );
413
436
if (ct_username_len > 0 ) {
@@ -419,6 +442,8 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
419
442
if (dlg_api .is_mod_flag_set (dlg ,TOPOH_DID_IN_USER ))
420
443
prefix_len += RR_DLG_PARAM_SIZE + 1 ;
421
444
445
+ if (dlg -> force_sips_contact && ct_type == SIP_URI_T ) prefix_len += 1 ;
446
+
422
447
prefix = pkg_malloc (prefix_len );
423
448
if (!prefix ) {
424
449
LM_ERR ("no more pkg\n" );
@@ -474,14 +499,22 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
474
499
rr_param = dlg_api .get_rr_param ();
475
500
476
501
p = prefix ;
477
- memcpy ( p , "<sip:" , 5 );
478
- p += 5 ;
502
+ if (dlg -> force_sips_contact ) {
503
+ memcpy (p , "<sips:" , 6 );
504
+ p += 6 ;
505
+ } else {
506
+ memcpy (p , "<sip:" , 5 );
507
+ p += 5 ;
508
+ }
509
+
510
+ if (is_forced_sips_contact_required (msg , dlg , ct_type )) dlg -> force_sips_contact = 1 ;
511
+
479
512
if (dlg_api .is_mod_flag_set (dlg ,TOPOH_KEEP_USER ) && ct_username_len > 0 ) {
480
513
memcpy ( p , ct_username , ct_username_len );
481
514
p += ct_username_len ;
482
515
}
483
516
if (dlg_api .is_mod_flag_set (dlg ,TOPOH_DID_IN_USER )) {
484
- if (p == prefix + 5 )
517
+ if (p == prefix + prefix_len )
485
518
* (p ++ ) = 'X' ;
486
519
/* add '.' */
487
520
* (p ++ ) = DLG_SEPARATOR ;
@@ -505,7 +538,7 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
505
538
return -1 ;
506
539
}
507
540
}
508
- if (p != prefix + 5 )
541
+ if (p != prefix + prefix_len )
509
542
* (p ++ ) = '@' ;
510
543
511
544
prefix_len = p - prefix ;
0 commit comments