Skip to content

Instantly share code, notes, and snippets.

@ThomasSevestre
Last active October 16, 2018 14:47
Show Gist options
  • Select an option

  • Save ThomasSevestre/df9315c2152f12dafb527d67379bd03b to your computer and use it in GitHub Desktop.

Select an option

Save ThomasSevestre/df9315c2152f12dafb527d67379bd03b to your computer and use it in GitHub Desktop.
SEMS : add max_forwards decrease on SBC module (based on b260d53745220b14b20d810042078ca31210617f)
diff --git a/apps/sbc/CallLeg.cpp b/apps/sbc/CallLeg.cpp
index 84096adb..37b4cb52 100644
--- a/apps/sbc/CallLeg.cpp
+++ b/apps/sbc/CallLeg.cpp
@@ -646,7 +646,7 @@ void CallLeg::onB2BConnect(ConnectLegEvent* co_ev)
}
int res = dlg->sendRequest(SIP_METH_INVITE, &body,
- co_ev->hdrs, SIP_FLAGS_VERBATIM);
+ co_ev->hdrs, SIP_FLAGS_VERBATIM, co_ev->r_max_forwards - 1);
if (res < 0) {
DBG("sending INVITE failed, relaying back error reply\n");
relayError(SIP_METH_INVITE, co_ev->r_cseq, true, res);
@@ -913,6 +913,7 @@ void CallLeg::onInvite(const AmSipRequest& req)
if (call_status == Disconnected) { // for initial INVITE only
est_invite_cseq = req.cseq; // remember initial CSeq
+ est_invite_max_forward = req.max_forwards;
// initialize RTP relay
// relayed INVITE - we need to add the original INVITE to
@@ -1275,9 +1276,9 @@ void CallLeg::addCallee(CallLeg *callee, const string &hdrs)
// use non-hold SDP if possible
AmMimeBody body(established_body);
sdp2body(non_hold_sdp, body);
- addNewCallee(callee, new ConnectLegEvent(hdrs, body));
+ addNewCallee(callee, new ConnectLegEvent(hdrs, body, est_invite_max_forward));
}
- else addNewCallee(callee, new ConnectLegEvent(hdrs, established_body));
+ else addNewCallee(callee, new ConnectLegEvent(hdrs, established_body, est_invite_max_forward));
}
/*void CallLeg::addCallee(CallLeg *callee, const string &hdrs, AmB2BSession::RTPRelayMode mode)
diff --git a/apps/sbc/CallLegEvents.h b/apps/sbc/CallLegEvents.h
index a8492261..00911586 100644
--- a/apps/sbc/CallLegEvents.h
+++ b/apps/sbc/CallLegEvents.h
@@ -21,6 +21,7 @@ struct ConnectLegEvent: public B2BEvent
string hdrs;
unsigned int r_cseq;
+ unsigned int r_max_forwards;
bool relayed_invite;
// constructor from relayed INVITE request
@@ -29,15 +30,17 @@ struct ConnectLegEvent: public B2BEvent
body(_relayed_invite.body),
hdrs(_relayed_invite.hdrs),
r_cseq(_relayed_invite.cseq),
+ r_max_forwards(_relayed_invite.max_forwards),
relayed_invite(true)
{ }
// constructor from generated INVITE (for example blind call transfer)
- ConnectLegEvent(const string &_hdrs, const AmMimeBody &_body):
+ ConnectLegEvent(const string &_hdrs, const AmMimeBody &_body, unsigned int _max_forward):
B2BEvent(ConnectLeg),
body(_body),
hdrs(_hdrs),
r_cseq(0),
+ r_max_forwards(_max_forward),
relayed_invite(false)
{ }
};
diff --git a/apps/sbc/SBCSimpleRelay.cpp b/apps/sbc/SBCSimpleRelay.cpp
index 5b42709a..be283b83 100644
--- a/apps/sbc/SBCSimpleRelay.cpp
+++ b/apps/sbc/SBCSimpleRelay.cpp
@@ -91,7 +91,7 @@ int SimpleRelayDialog::relayRequest(const AmSipRequest& req)
if(keep_vias)
hdrs = req.vias + hdrs;
- if(sendRequest(req.method,&req.body,hdrs,SIP_FLAGS_VERBATIM)) {
+ if(sendRequest(req.method,&req.body,hdrs,SIP_FLAGS_VERBATIM, req.max_forwards - 1)) {
AmSipReply error;
error.code = 500;
diff --git a/core/AmB2BSession.cpp b/core/AmB2BSession.cpp
index 9e5d89c3..55f383e2 100644
--- a/core/AmB2BSession.cpp
+++ b/core/AmB2BSession.cpp
@@ -76,7 +76,7 @@ AmB2BSession::AmB2BSession(const string& other_local_tag, AmSipDialog* p_dlg,
enable_dtmf_rtp_filtering(false),
enable_dtmf_rtp_detection(false),
rtp_relay_transparent_seqno(true), rtp_relay_transparent_ssrc(true),
- est_invite_cseq(0),est_invite_other_cseq(0),
+ est_invite_cseq(0),est_invite_other_cseq(0), est_invite_max_forward(0),
media_session(NULL)
{
if(!subs) subs = new AmSipSubscription(dlg,this);
@@ -802,7 +802,7 @@ int AmB2BSession::relaySip(const AmSipRequest& req)
}
DBG("relaying SIP request %s %s\n", req.method.c_str(), req.r_uri.c_str());
- int err = dlg->sendRequest(req.method, &body, *hdrs, SIP_FLAGS_VERBATIM);
+ int err = dlg->sendRequest(req.method, &body, *hdrs, SIP_FLAGS_VERBATIM, req.max_forwards - 1);
if(err < 0){
ERROR("dlg->sendRequest() failed\n");
return err;
diff --git a/core/AmB2BSession.h b/core/AmB2BSession.h
index 28f4bae8..e79b252a 100644
--- a/core/AmB2BSession.h
+++ b/core/AmB2BSession.h
@@ -179,6 +179,7 @@ private:
/** CSeq of the INVITE that established this call */
unsigned int est_invite_cseq;
unsigned int est_invite_other_cseq;
+ unsigned int est_invite_max_forward;
/** SUBSCRIBE/NOTIFY handling */
AmSipSubscription* subs;
diff --git a/core/AmBasicSipDialog.cpp b/core/AmBasicSipDialog.cpp
index c4595971..02361977 100644
--- a/core/AmBasicSipDialog.cpp
+++ b/core/AmBasicSipDialog.cpp
@@ -694,7 +694,8 @@ int AmBasicSipDialog::reply_error(const AmSipRequest& req, unsigned int code,
int AmBasicSipDialog::sendRequest(const string& method,
const AmMimeBody* body,
const string& hdrs,
- int flags)
+ int flags,
+ int max_forwards)
{
AmSipRequest req;
@@ -718,6 +719,8 @@ int AmBasicSipDialog::sendRequest(const string& method,
req.route = getRoute();
+ req.max_forwards= max_forwards;
+
if(body != NULL) {
req.body = *body;
}
diff --git a/core/AmBasicSipDialog.h b/core/AmBasicSipDialog.h
index 3a460877..faabb7bd 100644
--- a/core/AmBasicSipDialog.h
+++ b/core/AmBasicSipDialog.h
@@ -388,7 +388,8 @@ public:
virtual int sendRequest(const string& method,
const AmMimeBody* body = NULL,
const string& hdrs = "",
- int flags = 0);
+ int flags = 0,
+ int max_forwards = -1 );
/**
* Terminates pending UAS/UAC transactions
diff --git a/core/SipCtrlInterface.cpp b/core/SipCtrlInterface.cpp
index c4508862..2c14e683 100644
--- a/core/SipCtrlInterface.cpp
+++ b/core/SipCtrlInterface.cpp
@@ -777,6 +777,7 @@ void _SipCtrlInterface::handle_sip_request(const trans_ticket& tt, sip_msg* msg)
DBG_PARAM(req.from_tag);
DBG_PARAM(req.to_tag);
DBG("cseq = <%i>\n",req.cseq);
+ DBG("max_forwards = <%i>\n",req.max_forwards);
DBG_PARAM(req.route);
DBG("hdrs = <%s>\n",req.hdrs.c_str());
DBG("body-ct = <%s>\n",req.body.getCTStr().c_str());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment