From 241ca6a30c547e91fcea5fb37c14d4341c34d558 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Wed, 17 Jan 2024 10:35:51 +0100 Subject: [PATCH] MT#59022 `AmSipDialog::bye()` code refactoring No functional changes, just refactoring to make the code readability better. Change-Id: Iaedac78d112b10e131e1ade1fe97f28b2f90a6fe --- core/AmSipDialog.cpp | 104 ++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 47 deletions(-) diff --git a/core/AmSipDialog.cpp b/core/AmSipDialog.cpp index 659d041a..23fa4dcd 100644 --- a/core/AmSipDialog.cpp +++ b/core/AmSipDialog.cpp @@ -664,75 +664,85 @@ AmSipRequest* AmSipDialog::getUASPendingInv() int AmSipDialog::bye(const string& hdrs, int flags) { - switch(status){ + switch (status) { case Disconnecting: - case Connected: { - // collect INVITE UAC transactions + case Connected: + { + /* collect INVITE UAC transactions */ vector ack_trans; - for (TransMap::iterator it=uac_trans.begin(); it != uac_trans.end(); it++) { - if (it->second.method == SIP_METH_INVITE){ - ack_trans.push_back(it->second.cseq); - } + for (TransMap::iterator it = uac_trans.begin(); + it != uac_trans.end(); + it++) + { + if (it->second.method == SIP_METH_INVITE) { + ack_trans.push_back(it->second.cseq); + } } - // finish any UAC transaction before sending BYE - for (vector::iterator it= - ack_trans.begin(); it != ack_trans.end(); it++) { - send_200_ack(*it); + + /* finish any UAC transaction before sending BYE */ + for (vector::iterator it = ack_trans.begin(); + it != ack_trans.end(); + it++) + { + send_200_ack(*it); } if (status != Disconnecting) { - setStatus(Disconnected); - return sendRequest(SIP_METH_BYE, NULL, hdrs, flags); + setStatus(Disconnected); + return sendRequest(SIP_METH_BYE, NULL, hdrs, flags); } else { - return 0; + return 0; } } case Trying: case Proceeding: case Early: - if(getUACInvTransPending()) - return cancel(); - else { - for (TransMap::iterator it=uas_trans.begin(); - it != uas_trans.end(); it++) { - if (it->second.method == SIP_METH_INVITE){ - // let quit this call by sending final reply - return reply(it->second, - 487,"Request terminated"); - } - } - - // missing AmSipRequest to be able - // to send the reply on behalf of the app. - ERROR("ignoring bye() in %s state: " - "no UAC transaction to cancel or UAS transaction to reply.\n", - getStatusStr()); - setStatus(Disconnected); - } - return 0; + if (getUACInvTransPending()) { + return cancel(); + } else { + for (TransMap::iterator it = uas_trans.begin(); + it != uas_trans.end(); + it++) + { + if (it->second.method == SIP_METH_INVITE) { + /* let quit this call by sending final reply */ + return reply(it->second, 487, "Request terminated"); + } + } + + /* missing AmSipRequest to be able + * to send the reply on behalf of the app. */ + ERROR("ignoring bye() in %s state: " + "no UAC transaction to cancel or UAS transaction to reply.\n", + getStatusStr()); + setStatus(Disconnected); + } + return 0; case Cancelling: - for (TransMap::iterator it=uas_trans.begin(); - it != uas_trans.end(); it++) { - if (it->second.method == SIP_METH_INVITE){ - // let's quit this call by sending final reply - return reply(it->second, 487,"Request terminated"); - } + for (TransMap::iterator it = uas_trans.begin(); + it != uas_trans.end(); + it++) + { + if (it->second.method == SIP_METH_INVITE){ + /* let's quit this call by sending final reply */ + return reply(it->second, 487,"Request terminated"); + } } - // missing AmSipRequest to be able - // to send the reply on behalf of the app. - DBG("ignoring bye() in %s state: no UAS transaction to reply",getStatusStr()); + /* missing AmSipRequest to be able + * to send the reply on behalf of the app. */ + DBG("ignoring bye() in %s state: no UAS transaction to reply", getStatusStr()); setStatus(Disconnected); return 0; default: - DBG("bye(): we are not connected " - "(status=%s). do nothing!\n",getStatusStr()); - return 0; - } + DBG("bye(): we are not connected " + "(status=%s). do nothing!\n", getStatusStr()); + return 0; + } } int AmSipDialog::reinvite(const string& hdrs,