@@ -498,6 +498,7 @@ struct nta_outgoing_s
498498 nta_agent_t * orq_agent ;
499499 nta_response_f * orq_callback ;
500500 nta_outgoing_magic_t * orq_magic ;
501+ nta_outgoing_query_results_data_t * orq_query_results ;
501502
502503 /* Timeout/state queue */
503504 nta_outgoing_t * * orq_prev ;
@@ -533,6 +534,8 @@ struct nta_outgoing_s
533534 unsigned short orq_status ;
534535 unsigned char orq_retries ; /**< Number of tries this far */
535536
537+ const void * orq_intercept_query_results ; /** May become nua_handle_t */
538+
536539 unsigned orq_default :1 ; /**< This is default transaction */
537540 unsigned orq_inserted :1 ;
538541 unsigned orq_resolved :1 ;
@@ -600,6 +603,14 @@ ntatag_delay_sending_ref, tag_bool_vr(&(x))
600603extern tag_typedef_t ntatag_delay_sending ;
601604extern tag_typedef_t ntatag_delay_sending_ref ;
602605
606+ /* Intercept query results */
607+ #define NTATAG_INTERCEPT_QUERY_RESULTS (x ) ntatag_intercept_query_results, tag_ptr_v((x))
608+ #define NTATAG_INTERCEPT_QUERY_RESULTS_REF (x ) \
609+ ntatag_intercept_query_results_ref, tag_ptr_vr(&(x))
610+
611+ extern tag_typedef_t ntatag_intercept_query_results ;
612+ extern tag_typedef_t ntatag_intercept_query_results_ref ;
613+
603614/* Allow sending incomplete responses */
604615#define NTATAG_INCOMPLETE (x ) ntatag_incomplete, tag_bool_v((x))
605616#define NTATAG_INCOMPLETE_REF (x ) \
@@ -7817,6 +7828,29 @@ unsigned nta_outgoing_delay(nta_outgoing_t const *orq)
78177828 return orq != NULL && orq != NONE ? orq -> orq_delay : UINT_MAX ;
78187829}
78197830
7831+ /** Get the nta_outgoing_query_results_t */
7832+ nta_outgoing_query_results_data_t * nta_outgoing_query_results (nta_outgoing_t const * orq , char * * * results , size_t * found )
7833+ {
7834+ if (orq != NULL && orq != NONE ) {
7835+ if (orq -> orq_query_results && results && found ) {
7836+ * results = orq -> orq_query_results -> results ;
7837+ * found = orq -> orq_query_results -> found ;
7838+ }
7839+
7840+ return orq -> orq_query_results ;
7841+ } else return NULL ;
7842+ }
7843+
7844+ char const * nta_outgoing_cannon (nta_outgoing_t const * orq )
7845+ {
7846+ return orq != NULL && orq != NONE ? orq -> orq_tpn [0 ].tpn_canon : NULL ;
7847+ }
7848+
7849+ char const * nta_outgoing_host (nta_outgoing_t const * orq )
7850+ {
7851+ return orq != NULL && orq != NONE ? orq -> orq_tpn [0 ].tpn_host : NULL ;
7852+ }
7853+
78207854/** Get the branch parameter. @NEW_1_12_7. */
78217855char const * nta_outgoing_branch (nta_outgoing_t const * orq )
78227856{
@@ -7923,6 +7957,7 @@ nta_outgoing_t *outgoing_create(nta_agent_t *agent,
79237957 int explicit_transport = 1 ;
79247958 int call_tls_orq_connect_timeout_is_set = 0 ;
79257959 int call_tls_orq_connect_timeout = 0 ;
7960+ void * intercept_query_results = 0 ;
79267961
79277962 tagi_t const * t ;
79287963 tport_t * override_tport = NULL ;
@@ -7969,6 +8004,8 @@ nta_outgoing_t *outgoing_create(nta_agent_t *agent,
79698004 stateless = t -> t_value != 0 ;
79708005 else if (ntatag_delay_sending == tt )
79718006 delay_sending = t -> t_value != 0 ;
8007+ else if (ntatag_intercept_query_results == tt )
8008+ intercept_query_results = (void * )t -> t_value ;
79728009 else if (ntatag_branch_key == tt )
79738010 branch = (void * )t -> t_value ;
79748011 else if (ntatag_pass_100 == tt )
@@ -8013,6 +8050,7 @@ nta_outgoing_t *outgoing_create(nta_agent_t *agent,
80138050 orq -> orq_call_id = sip -> sip_call_id ;
80148051 orq -> orq_tags = tl_afilter (home , tport_tags , ta_args (ta ));
80158052 orq -> orq_delayed = delay_sending != 0 ;
8053+ orq -> orq_intercept_query_results = intercept_query_results ;
80168054 orq -> orq_pass_100 = pass_100 != 0 ;
80178055 orq -> orq_sigcomp_zap = sigcomp_zap ;
80188056 orq -> orq_sigcomp_new = comp != NONE && comp != NULL ;
@@ -11010,6 +11048,8 @@ void outgoing_answer_a(sres_context_t *orq, sres_query_t *q,
1101011048 outgoing_query_results (orq , sq , results , found );
1101111049}
1101211050
11051+ int nua_client_intercept_query_results (const void * nua_handle , void * cr , nta_outgoing_t * orq , sip_t const * sip );
11052+
1101311053/** Store A/AAAA query results */
1101411054static void
1101511055outgoing_query_results (nta_outgoing_t * orq ,
@@ -11053,6 +11093,29 @@ outgoing_query_results(nta_outgoing_t *orq,
1105311093
1105411094 if (rlen > 0 ) {
1105511095 orq -> orq_resolved = 1 ;
11096+ if (orq -> orq_intercept_query_results && orq -> orq_callback ) {
11097+ nta_outgoing_query_results_data_t orq_query_results = { 0 };
11098+
11099+ SU_DEBUG_0 (("intercepted query results\n" VA_NONE ));
11100+
11101+ orq_query_results .results = results ;
11102+ orq_query_results .found = rlen ;
11103+
11104+ /* orq->orq_query_results field works as an argument to the orq_callback function */
11105+ orq -> orq_query_results = & orq_query_results ;
11106+
11107+ if (orq -> orq_callback == outgoing_default_cb ) {
11108+ int res = nua_client_intercept_query_results (orq -> orq_intercept_query_results , NULL , orq , NULL );
11109+ /* No need to return here if res is 1 */
11110+ (void )res ;
11111+ } else {
11112+ orq -> orq_callback (orq -> orq_magic , orq , NULL );
11113+ }
11114+
11115+ /* orq->orq_query_results field argument must be NULLed after the function call */
11116+ orq -> orq_query_results = NULL ;
11117+ }
11118+
1105611119 orq -> orq_tpn -> tpn_host = results [0 ];
1105711120 if (sq -> sq_proto ) orq -> orq_tpn -> tpn_proto = sq -> sq_proto ;
1105811121 if (sq -> sq_port [0 ]) orq -> orq_tpn -> tpn_port = sq -> sq_port ;
0 commit comments