A呼叫B的过程中,如果B已经接通了电话,但是200 ok还未回到A这方,但这时A挂断电话,会出现
一、A发送CANCEL到B。
二、A收到INVITE的200 ok,回复ACK,并将通话置为接通状态
三、B接收到CANCEL,回复200 ok,但接着不会发送487
(正常的CANCEL过程参考http://yeyingxian.blog.163.com/blog/static/344712420130238404943/)
A Opensips B
=====> INVITE
=====> INVITE
<==== 100 Trying
<===== 200 OK (INVITE)
=====> CANCEL
=====> CANCEL
<===== 200 OK (INVITE)
=====> ACK
<===== 200 OK (CANCEL)
<===== 200 OK (CANCEL)
=====> ACK
时序图
结果就是A想挂断电话,结果电话却是偷偷接通了。
修正方法,在A正在CANCEL的过程中,如果收到200 ok,则紧接着发送BYE来取消会话
sip_inv.c中的inv_set_state
if (pjmedia_sdp_neg_get_state(inv->neg)!=PJMEDIA_SDP_NEG_STATE_DONE &&
(tsx_inv_data && !tsx_inv_data->sdp_done) )
{
pjsip_tx_data *bye;
PJ_LOG(4,(inv->obj_name, "SDP offer/answer incomplete, ending the "
"session"));
status = pjsip_inv_end_session(inv, PJSIP_SC_NOT_ACCEPTABLE,
NULL, &bye);
if (status == PJ_SUCCESS && bye)
status = pjsip_inv_send_msg(inv, bye);
return;
}
+ if (inv->cancelling)
+ {
+ pjsip_tx_data *bye;
+
+ PJ_LOG(4,(inv->obj_name, "End session, because cancellation is in progress"));
+
+ status = pjsip_inv_end_session(inv, PJSIP_SC_NOT_ACCEPTABLE,
+ NULL, &bye);
+ if (status == PJ_SUCCESS && bye)
+ status = pjsip_inv_send_msg(inv, bye);
+
+ return;
+ }
}
/* Set state. */
inv->state = state;