Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End 2 end CANCEL Reason (and other additional CANCEL headers) #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions apps/sbc/CallLeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,16 @@ CallLeg::~CallLeg()
SBCCallRegistry::removeCall(getLocalTag());
}

void CallLeg::terminateOtherLeg()
void CallLeg::terminateOtherLeg(const string &cancel_hdrs)
{
if (call_status != Connected) {
DBG("trying to terminate other leg in %s state -> terminating the others as well\n", callStatus2str(call_status));
// FIXME: may happen when for example reply forward fails, do we want to terminate
// all other legs in such case?
terminateNotConnectedLegs(); // terminates all except the one identified by other_id
terminateNotConnectedLegs(cancel_hdrs); // terminates all except the one identified by other_id
}

AmB2BSession::terminateOtherLeg();
AmB2BSession::terminateOtherLeg(cancel_hdrs);

// remove this one from the list of other legs
for (vector<OtherLegInfo>::iterator i = other_legs.begin(); i != other_legs.end(); ++i) {
Expand All @@ -304,15 +304,19 @@ void CallLeg::terminateOtherLeg()
if (getCallStatus() != Disconnected) updateCallStatus(Disconnected); // no B legs should be remaining
}

void CallLeg::terminateNotConnectedLegs()
void CallLeg::terminateNotConnectedLegs(const string &cancel_hdrs)
{
bool found = false;
OtherLegInfo b;

for (vector<OtherLegInfo>::iterator i = other_legs.begin(); i != other_legs.end(); ++i) {
if (i->id != getOtherId()) {
i->releaseMediaSession();
AmSessionContainer::instance()->postEvent(i->id, new B2BEvent(B2BTerminateLeg));
B2BEvent* ev = new B2BEvent(B2BTerminateLeg);
if (!cancel_hdrs.empty()) {
ev->params["cancel_hdrs"]= cancel_hdrs;
}
AmSessionContainer::instance()->postEvent(i->id, ev);
}
else {
found = true; // other_id is there
Expand Down Expand Up @@ -1068,15 +1072,15 @@ void CallLeg::onCancel(const AmSipRequest& req)
// terminate whole B2B call if the caller receives CANCEL
onCallFailed(CallCanceled, NULL);
updateCallStatus(Disconnected, StatusChangeCause::Canceled);
stopCall(StatusChangeCause::Canceled);
stopCall(StatusChangeCause::Canceled, req.hdrs);
}
// else { } ... ignore for B leg
}
}

void CallLeg::terminateLeg()
void CallLeg::terminateLeg(const string &cancel_hdrs)
{
AmB2BSession::terminateLeg();
AmB2BSession::terminateLeg(cancel_hdrs);
}

// was for caller only
Expand Down Expand Up @@ -1352,10 +1356,10 @@ void CallLeg::clear_other()
AmB2BSession::clear_other();
}

void CallLeg::stopCall(const StatusChangeCause &cause) {
void CallLeg::stopCall(const StatusChangeCause &cause, const string &cancel_hdrs) {
if (getCallStatus() != Disconnected) updateCallStatus(Disconnected, cause);
terminateNotConnectedLegs();
terminateOtherLeg();
terminateNotConnectedLegs(cancel_hdrs);
terminateOtherLeg(cancel_hdrs);
terminateLeg();
}

Expand Down
8 changes: 4 additions & 4 deletions apps/sbc/CallLeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class CallLeg: public AmB2BSession

/** terminate all other B legs than the connected one (should not be used
* directly by successors, right?) */
void terminateNotConnectedLegs();
void terminateNotConnectedLegs(const string &cancel_hdrs = "");

/** choose given B leg from the list of other B legs */
bool setOther(const string &id, bool use_initial_sdp);
Expand Down Expand Up @@ -295,8 +295,8 @@ class CallLeg: public AmB2BSession
virtual void resumeAccepted();
virtual void resumeRejected() { }

virtual void terminateOtherLeg();
virtual void terminateLeg();
virtual void terminateOtherLeg(const string &cancel_hdrs = "");
virtual void terminateLeg(const string &cancel_hdrs = "");

/** change RTP mode (and AmB2BMedia if needed) but do not send reINVITE
*
Expand Down Expand Up @@ -329,7 +329,7 @@ class CallLeg: public AmB2BSession

/** Terminate the whole B2B call (if there is no other leg only this one is
* stopped). */
virtual void stopCall(const StatusChangeCause &cause);
virtual void stopCall(const StatusChangeCause &cause, const string &cancel_hdrs = "");


/** Put remote party on hold (may change RTP relay mode!). Note that this
Expand Down
23 changes: 16 additions & 7 deletions core/AmB2ABSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ void AmB2ABSession::onB2ABEvent(B2ABEvent* ev)
switch(ev->event_id){

case B2ABTerminateLeg:
terminateLeg();
std::map<string,string>::const_iterator it;
it= ev->params.find("cancel_hdrs");
if (it != ev->params.end())
terminateLeg(it->second);
else
terminateLeg();
break;
}
}
Expand Down Expand Up @@ -110,16 +115,20 @@ void AmB2ABSession::onBye(const AmSipRequest& req) {
setStopped();
}

void AmB2ABSession::terminateLeg()
void AmB2ABSession::terminateLeg(const string &cancel_hdrs)
{
dlg->bye();
dlg->bye(cancel_hdrs);
disconnectSession();
setStopped();
}

void AmB2ABSession::terminateOtherLeg()
void AmB2ABSession::terminateOtherLeg(const string &cancel_hdrs)
{
relayEvent(new B2ABEvent(B2ABTerminateLeg));
B2ABEvent* ev = new B2ABEvent(B2ABTerminateLeg);
if (!cancel_hdrs.empty()) {
ev->params["cancel_hdrs"]= cancel_hdrs;
}
relayEvent(ev);
clear_other();
}

Expand All @@ -142,10 +151,10 @@ void AmB2ABCallerSession::onBeforeDestroy() {
DBG("OK, got release from callee session.\n");
}

void AmB2ABCallerSession::terminateOtherLeg()
void AmB2ABCallerSession::terminateOtherLeg(const string &cancel_hdrs)
{
if (callee_status != None)
AmB2ABSession::terminateOtherLeg();
AmB2ABSession::terminateOtherLeg(cancel_hdrs);

callee_status = None;
}
Expand Down
8 changes: 5 additions & 3 deletions core/AmB2ABSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ enum { B2ABTerminateLeg,
/** \brief base class for event in B2AB session */
struct B2ABEvent: public AmEvent
{
map<string, string> params;

B2ABEvent(int ev_id)
: AmEvent(ev_id)
{}
Expand Down Expand Up @@ -153,10 +155,10 @@ class AmB2ABSession: public AmSession
virtual void relayEvent(AmEvent* ev);

/** Terminate our leg and forget the other. */
virtual void terminateLeg();
virtual void terminateLeg(const string &cancel_hdrs = "");

/** Terminate the other leg and forget it.*/
virtual void terminateOtherLeg();
virtual void terminateOtherLeg(const string &cancel_hdrs = "");


/** B2ABEvent handler */
Expand Down Expand Up @@ -226,7 +228,7 @@ class AmB2ABCallerSession: public AmB2ABSession
const string& headers = "");

// @see AmB2ABSession
void terminateOtherLeg();
void terminateOtherLeg(const string &cancel_hdrs = "");

protected:
void onB2ABEvent(B2ABEvent* ev);
Expand Down
32 changes: 21 additions & 11 deletions core/AmB2BSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,12 @@ void AmB2BSession::onB2BEvent(B2BEvent* ev)

case B2BTerminateLeg:
DBG("terminateLeg()\n");
terminateLeg();
std::map<string,string>::const_iterator it;
it= ev->params.find("cancel_hdrs");
if (it != ev->params.end())
terminateLeg(it->second);
else
terminateLeg();
break;
}

Expand Down Expand Up @@ -619,19 +624,24 @@ bool AmB2BSession::onOtherReply(const AmSipReply& reply)
return false;
}

void AmB2BSession::terminateLeg()
void AmB2BSession::terminateLeg(const string &cancel_hdrs)
{
setStopped();

clearRtpReceiverRelay();

dlg->bye("", SIP_FLAGS_VERBATIM);
dlg->bye(cancel_hdrs, SIP_FLAGS_VERBATIM);
}

void AmB2BSession::terminateOtherLeg()
void AmB2BSession::terminateOtherLeg(const string &cancel_hdrs)
{
if (!other_id.empty())
relayEvent(new B2BEvent(B2BTerminateLeg));
if (!other_id.empty()) {
B2BEvent* ev = new B2BEvent(B2BTerminateLeg);
if (!cancel_hdrs.empty()) {
ev->params["cancel_hdrs"]= cancel_hdrs;
}
relayEvent(ev);
}
}

void AmB2BSession::onRtpTimeout() {
Expand Down Expand Up @@ -1013,14 +1023,14 @@ void AmB2BCallerSession::set_sip_relay_early_media_sdp(bool r)
sip_relay_early_media_sdp = r;
}

void AmB2BCallerSession::terminateLeg()
void AmB2BCallerSession::terminateLeg(const string &cancel_hdrs)
{
AmB2BSession::terminateLeg();
AmB2BSession::terminateLeg(cancel_hdrs);
}

void AmB2BCallerSession::terminateOtherLeg()
void AmB2BCallerSession::terminateOtherLeg(const string &cancel_hdrs)
{
AmB2BSession::terminateOtherLeg();
AmB2BSession::terminateOtherLeg(cancel_hdrs);
callee_status = None;
}

Expand Down Expand Up @@ -1160,7 +1170,7 @@ void AmB2BCallerSession::onInvite2xx(const AmSipReply& reply)

void AmB2BCallerSession::onCancel(const AmSipRequest& req)
{
terminateOtherLeg();
terminateOtherLeg(req.hdrs);
terminateLeg();
}

Expand Down
8 changes: 4 additions & 4 deletions core/AmB2BSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ class AmB2BSession: public AmSession, protected RelayController

protected:
/** Terminate our leg and forget the other. */
virtual void terminateLeg();
virtual void terminateLeg(const string &cancel_hdrs = "");

/** Terminate the other leg and forget it.*/
virtual void terminateOtherLeg();
virtual void terminateOtherLeg(const string &cancel_hdrs = "");


/** @see AmSession */
Expand Down Expand Up @@ -416,8 +416,8 @@ class AmB2BCallerSession: public AmB2BSession
void onSystemEvent(AmSystemEvent* ev);

// @see AmB2BSession
void terminateLeg();
void terminateOtherLeg();
void terminateLeg(const string &cancel_hdrs = "");
void terminateOtherLeg(const string &cancel_hdrs = "");
virtual void onB2BEvent(B2BEvent* ev);

AmSipRequest* getInviteReq() { return &invite_req; }
Expand Down