Browse Source

dialog: Set the dialog context on incoming replies

Before, the dialog context would be derived from the callid and tags. This
could select the wrong dialog in case of spirals. This patch sets the correct
dialog context by storing the it in the transaction and restoring it on an
incoming response. Now the correct dialog variables are available in
onreply_route.
Alex Hermann 11 years ago
parent
commit
25a3297915
1 changed files with 22 additions and 1 deletions
  1. 22 1
      modules/dialog/dlg_handlers.c

+ 22 - 1
modules/dialog/dlg_handlers.c

@@ -453,6 +453,13 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param)
 		return;
 
 	unref = 0;
+	if (type==TMCB_RESPONSE_IN) {
+		/* Set the dialog context so it is available in onreply_route */
+		set_current_dialog( req, dlg);
+		dlg_set_ctx_iuid(dlg);
+		goto done;
+	}
+
 	if (type==TMCB_RESPONSE_FWDED) {
 		/* The state does not change, but the msg is mutable in this callback*/
 		run_dlg_callbacks(DLGCB_RESPONSE_FWDED, dlg, req, rpl, DLG_DIR_UPSTREAM, 0);
@@ -920,7 +927,7 @@ int dlg_set_tm_callbacks(tm_cell_t *t, sip_msg_t *req, dlg_cell_t *dlg,
 			goto error;
 		}
 		if ( d_tmb.register_tmcb( req, t,
-				TMCB_RESPONSE_READY|TMCB_RESPONSE_FWDED,
+				TMCB_RESPONSE_IN|TMCB_RESPONSE_READY|TMCB_RESPONSE_FWDED,
 				dlg_onreply, (void*)iuid, dlg_iuid_sfree)<0 ) {
 			LM_ERR("failed to register TMCB\n");
 			goto error;
@@ -1186,6 +1193,20 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
     _dlg_ctx.iuid.h_entry = dlg->h_entry;
     _dlg_ctx.iuid.h_id = dlg->h_id;
 
+	if (req->first_line.u.request.method_value != METHOD_ACK) {
+		iuid = dlg_get_iuid_shm_clone(dlg);
+		if(iuid!=NULL)
+		{
+			/* register callback for the replies of this request */
+			if ( d_tmb.register_tmcb( req, 0, TMCB_RESPONSE_IN,
+					dlg_onreply, (void*)iuid, dlg_iuid_sfree)<0 ) {
+				LM_ERR("failed to register TMCB (3)\n");
+				shm_free(iuid);
+			}
+			iuid = NULL;
+		}
+	}
+	
 	/* run state machine */
 	switch ( req->first_line.u.request.method_value ) {
 		case METHOD_PRACK: