15 Terminating a Session 15 终止会话 This section describes the procedures for terminating a session established by SIP. The state of the session and the state of the dialog are very closely related. When a session is initiated with an INVITE, each 1xx or 2xx response from a distinct UAS creates a dialog, and if that response completes the offer/answer exchange, it also creates a session. As a result, each session is "associated" with a single dialog - the one which resulted in its creation. If an initial INVITE generates a non-2xx final response, that terminates all sessions (if any) and all dialogs (if any) that were created through responses to the request. By virtue of completing the transaction, a non-2xx final response also prevents further sessions from being created as a result of the INVITE. The BYE request is used to terminate a specific session or attempted session. In this case, the specific session is the one with the peer UA on the other side of the dialog. When a BYE is received on a dialog, any session associated with that dialog SHOULD terminate. A UA MUST NOT send a BYE outside of a dialog. The caller's UA MAY send a BYE for either confirmed or early dialogs, and the callee's UA MAY send a BYE on confirmed dialogs, but MUST NOT send a BYE on early dialogs.
本节描述了终止SIP建立的会话的过程。会话的状态和对话的状态密切相关。当使用INVITE启动会话时,来自不同UAS的每个1xx或2xx响应都会创建一个对话,如果该响应完成了offer/answer交换,它还会创建一个会话。因此,每个会话都与一个对话“关联”在一起,即创建会话的对话。如果初始INVITE生成非2xx的最终响应,则终止通过响应请求创建的所有会话(如果有)和所有对话(如果有的话)。通过完成事务,非2xx最终响应还可以防止由于INVITE而创建更多会话。BYE请求用于终止特定会话或尝试的会话。在这种情况下,特定会话是与对话另一侧的对等UA的会话。当在对话上接收到BYE时,与该对话相关联的任何会话都应终止。UA不得在对话之外发送BYE。主叫方的UA可以为已确认或早期对话框发送BYE,被叫方的UA在已确认对话上可以发送BYE但在早期对话上不得发送BYE。
However, the callee's UA MUST NOT send a BYE on a confirmed dialog until it has received an ACK for its 2xx response or until the server transaction times out. If no SIP extensions have defined other application layer states associated with the dialog, the BYE also terminates the dialog. 但是,被调用者的UA在收到2xx响应的ACK或服务器事务超时之前,不得在已确认的对话上发送BYE。如果没有SIP扩展定义与该对话相关联的其他应用程序层状态,BYE也会终止该对话。 The impact of a non-2xx final response to INVITE on dialogs and sessions makes the use of CANCEL attractive. The CANCEL attempts to force a non-2xx response to the INVITE (in particular, a 487). Therefore, if a UAC wishes to give up on its call attempt entirely, it can send a CANCEL. If the INVITE results in 2xx final response(s) to the INVITE, this means that a UAS accepted the invitation while the CANCEL was in progress. The UAC MAY continue with the sessions established by any 2xx responses, or MAY terminate them with BYE. INVITE的非2xx最终响应对对话和会话的影响使CANCEL的使用具有吸引力。CANCEL试图强制对INVITE(特别是487)做出非2xx响应。因此,如果UAC希望完全放弃其呼叫尝试,它可以发送CANCEL。如果INVITE导致对INVITE的2xx最终响应,这意味着UAS在CANCEL进行时接受了邀请。UAC可以继续使用任何2xx响应建立的会话,也可以使用BYE终止会话。 The notion of "hanging up" is not well defined within SIP. It is specific to a particular, albeit common, user interface. Typically, when the user hangs up, it indicates a desire to terminate the attempt to establish a session, and to terminate any sessions already created. For the caller's UA, this would imply a CANCEL request if the initial INVITE has not generated a final response, and a BYE to all confirmed dialogs after a final response. For the callee's UA, it would typically imply a BYE; presumably, when the user picked up the phone, a 2xx was generated, and so hanging up would result in a BYE after the ACK is received. This does not mean a user cannot hang up before receipt of the ACK, it just means that the software in his phone needs to maintain state for a short while in order to clean up properly. If the particular UI allows for the user to reject a call before its answered, a 403 (Forbidden) is a good way to express that. As per the rules above, a BYE can't be sent.
SIP中没有很好地定义“挂断”的概念。它特定于一个特定的用户界面,尽管它很常见。通常,当用户挂断电话时,它表示希望终止建立会话的尝试,并终止已经创建的任何会话。对于呼叫者的UA,如果初始INVITE没有生成最终响应,这将意味着CANCEL请求,并且在最终响应之后对所有确认的对话都是BYE。对于被叫方的UA,它通常意味着BYE;据推测,当用户拿起电话时,会生成一个2xx,因此在收到ACK后挂断会导致BYE。这并不意味着用户不能在收到ACK之前挂断电话,这只是意味着他的手机中的软件需要保持一段时间的状态才能正常清理。如果特定的UI允许用户在呼叫应答之前拒绝呼叫,那么403(Forbidden)是表达这一点的好方法。根据上述规则,不能发送BYE。