瀏覽代碼

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 年之前
父節點
當前提交
25a3297915
共有 1 個文件被更改,包括 22 次插入1 次删除
  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;
 		return;
 
 
 	unref = 0;
 	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) {
 	if (type==TMCB_RESPONSE_FWDED) {
 		/* The state does not change, but the msg is mutable in this callback*/
 		/* 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);
 		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;
 			goto error;
 		}
 		}
 		if ( d_tmb.register_tmcb( req, t,
 		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 ) {
 				dlg_onreply, (void*)iuid, dlg_iuid_sfree)<0 ) {
 			LM_ERR("failed to register TMCB\n");
 			LM_ERR("failed to register TMCB\n");
 			goto error;
 			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_entry = dlg->h_entry;
     _dlg_ctx.iuid.h_id = dlg->h_id;
     _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 */
 	/* run state machine */
 	switch ( req->first_line.u.request.method_value ) {
 	switch ( req->first_line.u.request.method_value ) {
 		case METHOD_PRACK:
 		case METHOD_PRACK: