@@ -942,11 +942,12 @@ int nua_base_client_request(nua_client_request_t *cr, msg_t *msg, sip_t *sip,
942
942
tagi_t const * tags )
943
943
{
944
944
nua_handle_t * nh = cr -> cr_owner ;
945
+ nua_handle_t * intercept_nh = NULL ;
945
946
int proxy_is_set = NH_PISSET (nh , proxy );
946
947
url_string_t * proxy = NH_PGET (nh , proxy );
947
948
int call_tls_orq_connect_timeout_is_set = NH_PISSET (nh , call_tls_orq_connect_timeout );
948
949
uint32_t call_tls_orq_connect_timeout = NH_PGET (nh , call_tls_orq_connect_timeout );
949
- int intercept_query_results_is_set = NUA_PISSET ( nh -> nh_nua , nh , intercept_query_results );
950
+ int intercept_query_results_is_set = NH_PGET ( nh , intercept_query_results );
950
951
951
952
if (nh -> nh_auth ) {
952
953
if (cr -> cr_challenged ||
@@ -960,13 +961,17 @@ int nua_base_client_request(nua_client_request_t *cr, msg_t *msg, sip_t *sip,
960
961
961
962
assert (cr -> cr_orq == NULL );
962
963
964
+ if (intercept_query_results_is_set ) {
965
+ intercept_nh = nua_handle_ref (nh );
966
+ }
967
+
963
968
cr -> cr_orq = nta_outgoing_mcreate (nh -> nh_nua -> nua_nta ,
964
969
nua_client_orq_response ,
965
970
nua_client_request_ref (cr ),
966
971
NULL ,
967
972
msg ,
968
973
TAG_IF (intercept_query_results_is_set ,
969
- NTATAG_INTERCEPT_QUERY_RESULTS (nh )),
974
+ NTATAG_INTERCEPT_QUERY_RESULTS (intercept_nh )),
970
975
TAG_IF (proxy_is_set ,
971
976
NTATAG_DEFAULT_PROXY (proxy )),
972
977
TAG_IF (call_tls_orq_connect_timeout_is_set ,
@@ -975,6 +980,9 @@ int nua_base_client_request(nua_client_request_t *cr, msg_t *msg, sip_t *sip,
975
980
976
981
if (cr -> cr_orq == NULL ) {
977
982
nua_client_request_unref (cr );
983
+ if (intercept_nh ) {
984
+ nua_handle_unref (intercept_nh );
985
+ }
978
986
return -1 ;
979
987
}
980
988
@@ -989,7 +997,7 @@ static inline void nua_client_intercept_response(nua_client_request_t *cr,
989
997
nua_handle_t * nh = cr -> cr_owner ;
990
998
nua_t * nua = nh ? nh -> nh_nua : NULL ;
991
999
nua_dialog_usage_t * du = cr -> cr_usage ;
992
- unsigned intercept_query_results = nh ? NUA_PISSET ( nh -> nh_nua , nh , intercept_query_results ) : 0 ;
1000
+ unsigned intercept_query_results = nh ? NH_PGET ( nh , intercept_query_results ) : 0 ;
993
1001
994
1002
if (intercept_query_results && sip && status != 408 && nua ) {
995
1003
/* At this point we have a successful response */
@@ -1013,7 +1021,7 @@ static inline void nua_client_intercept_response(nua_client_request_t *cr,
1013
1021
}
1014
1022
}
1015
1023
1016
- int nua_client_intercept_query_results (const void * nua_handle , void * _cr ,
1024
+ int nua_client_intercept_query_results (const void * handle , void * _cr ,
1017
1025
nta_outgoing_t * orq ,
1018
1026
sip_t const * sip )
1019
1027
{
@@ -1023,28 +1031,43 @@ int nua_client_intercept_query_results(const void *nua_handle, void *_cr,
1023
1031
1024
1032
if (nta_outgoing_query_results (orq , & results , & found ) != NULL ) {
1025
1033
/* See NTATAG_INTERCEPT_QUERY_RESULTS and NUTAG_INTERCEPT_QUERY_RESULTS */
1026
- nua_handle_t * nh = nua_handle ? (nua_handle_t * )nua_handle : cr -> cr_owner ;
1034
+ nua_handle_t * nh = handle ? (nua_handle_t * )handle : ( cr ? cr -> cr_owner : NULL ) ;
1027
1035
nua_dialog_usage_t * du = cr ? cr -> cr_usage : NULL ;
1028
1036
nua_dialog_state_t * ds = du ? du -> du_dialog : NULL ;
1029
1037
1030
1038
SU_DEBUG_0 (("Query results have been intercepted. Trying to override...\n" VA_NONE ));
1031
1039
1032
1040
if (!ds && nh ) {
1033
- ds = nh -> nh_ds ;
1041
+ if (NH_IS_VALID (nh )) {
1042
+ ds = nh -> nh_ds ;
1043
+ } else {
1044
+ SU_DEBUG_0 (("Warning! nh is not valid! Can not intercept! No ds!\n" VA_NONE ));
1045
+ }
1034
1046
}
1035
1047
1036
1048
if (ds && ds -> ds_intercepted_ip ) {
1037
1049
if (found ) {
1038
- msg_t * response = nta_outgoing_getresponse (orq );
1039
- su_home_t * home = response ? msg_home (response ) : msg_home (nh );
1050
+ msg_t * request = nta_outgoing_getrequest (orq );
1051
+ su_home_t * home = request ? msg_home (request ) : NULL ;
1052
+
1053
+ if (!home ) {
1054
+ if (NH_IS_VALID (nh )) {
1055
+ home = msg_home (nh );
1056
+ } else {
1057
+ SU_DEBUG_0 (("Warning! nh is not valid! Can not intercept! No home!\n" VA_NONE ));
1058
+ }
1059
+ }
1040
1060
1041
- SU_DEBUG_0 (( "Intercepted IP address: [%s]->[%s]\n" , results [ 0 ], ds -> ds_intercepted_ip ));
1042
- results [0 ] = su_strdup ( home , ds -> ds_intercepted_ip );
1043
- msg_destroy ( response );
1061
+ if ( home ) {
1062
+ SU_DEBUG_0 (( "Intercepted IP address: [%s]->[%s]\n" , results [0 ], ds -> ds_intercepted_ip ) );
1063
+ results [ 0 ] = su_strdup ( home , ds -> ds_intercepted_ip );
1044
1064
1045
- if (found > 1 ) {
1046
- results [1 ] = NULL ;
1065
+ if (found > 1 ) {
1066
+ results [1 ] = NULL ;
1067
+ }
1047
1068
}
1069
+
1070
+ msg_destroy (request );
1048
1071
}
1049
1072
}
1050
1073
0 commit comments