@@ -942,11 +942,12 @@ int nua_base_client_request(nua_client_request_t *cr, msg_t *msg, sip_t *sip,
942942 tagi_t const * tags )
943943{
944944 nua_handle_t * nh = cr -> cr_owner ;
945+ nua_handle_t * intercept_nh = NULL ;
945946 int proxy_is_set = NH_PISSET (nh , proxy );
946947 url_string_t * proxy = NH_PGET (nh , proxy );
947948 int call_tls_orq_connect_timeout_is_set = NH_PISSET (nh , call_tls_orq_connect_timeout );
948949 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 );
950951
951952 if (nh -> nh_auth ) {
952953 if (cr -> cr_challenged ||
@@ -960,13 +961,17 @@ int nua_base_client_request(nua_client_request_t *cr, msg_t *msg, sip_t *sip,
960961
961962 assert (cr -> cr_orq == NULL );
962963
964+ if (intercept_query_results_is_set ) {
965+ intercept_nh = nua_handle_ref (nh );
966+ }
967+
963968 cr -> cr_orq = nta_outgoing_mcreate (nh -> nh_nua -> nua_nta ,
964969 nua_client_orq_response ,
965970 nua_client_request_ref (cr ),
966971 NULL ,
967972 msg ,
968973 TAG_IF (intercept_query_results_is_set ,
969- NTATAG_INTERCEPT_QUERY_RESULTS (nh )),
974+ NTATAG_INTERCEPT_QUERY_RESULTS (intercept_nh )),
970975 TAG_IF (proxy_is_set ,
971976 NTATAG_DEFAULT_PROXY (proxy )),
972977 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,
975980
976981 if (cr -> cr_orq == NULL ) {
977982 nua_client_request_unref (cr );
983+ if (intercept_nh ) {
984+ nua_handle_unref (intercept_nh );
985+ }
978986 return -1 ;
979987 }
980988
@@ -989,7 +997,7 @@ static inline void nua_client_intercept_response(nua_client_request_t *cr,
989997 nua_handle_t * nh = cr -> cr_owner ;
990998 nua_t * nua = nh ? nh -> nh_nua : NULL ;
991999 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 ;
9931001
9941002 if (intercept_query_results && sip && status != 408 && nua ) {
9951003 /* At this point we have a successful response */
@@ -1013,7 +1021,7 @@ static inline void nua_client_intercept_response(nua_client_request_t *cr,
10131021 }
10141022}
10151023
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 ,
10171025 nta_outgoing_t * orq ,
10181026 sip_t const * sip )
10191027{
@@ -1023,28 +1031,43 @@ int nua_client_intercept_query_results(const void *nua_handle, void *_cr,
10231031
10241032 if (nta_outgoing_query_results (orq , & results , & found ) != NULL ) {
10251033 /* 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 ) ;
10271035 nua_dialog_usage_t * du = cr ? cr -> cr_usage : NULL ;
10281036 nua_dialog_state_t * ds = du ? du -> du_dialog : NULL ;
10291037
10301038 SU_DEBUG_0 (("Query results have been intercepted. Trying to override...\n" VA_NONE ));
10311039
10321040 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+ }
10341046 }
10351047
10361048 if (ds && ds -> ds_intercepted_ip ) {
10371049 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+ }
10401060
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 );
10441064
1045- if (found > 1 ) {
1046- results [1 ] = NULL ;
1065+ if (found > 1 ) {
1066+ results [1 ] = NULL ;
1067+ }
10471068 }
1069+
1070+ msg_destroy (request );
10481071 }
10491072 }
10501073
0 commit comments