Module: sems Branch: master Commit: 411ba01bc1a83e0f2c61776f2d326d6320c5d000 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=411ba01bc1a83e0f2c61776f2d326d6320c5d000
Author: Václav Kubart <[email protected]> Committer: Václav Kubart <[email protected]> Date: Mon Feb 20 12:09:28 2012 +0100 AmB2BSession replies 488 if all media lines are filtered out fixes bug #61 https://bugtracker.iptel.org/view.php?id=61 --- apps/sbc/SDPFilter.cpp | 11 ++++++++- core/AmB2BSession.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++---- core/AmSipHeaders.h | 1 + 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/apps/sbc/SDPFilter.cpp b/apps/sbc/SDPFilter.cpp index 613092a..c1ee07c 100644 --- a/apps/sbc/SDPFilter.cpp +++ b/apps/sbc/SDPFilter.cpp @@ -54,8 +54,15 @@ int filterSDP(AmSdp& sdp, FilterType sdpfilter, const std::set<string>& sdpfilte if (!is_filtered) new_pl.push_back(*p_it); } - // todo: what if no payload supported any more? - media.payloads = new_pl; + if (new_pl.empty()) { + // in case of SDP offer we could remove media line but in case of answer + // we should just reject the stream by setting port to 0 (at least one + // format must be given; see RFC 3264, sect. 6) + media.port = 0; + if (media.payloads.size() > 1) + media.payloads.erase(media.payloads.begin() + 1, media.payloads.end()); + } + else media.payloads = new_pl; } return 0; diff --git a/core/AmB2BSession.cpp b/core/AmB2BSession.cpp index 06787c3..54e355e 100644 --- a/core/AmB2BSession.cpp +++ b/core/AmB2BSession.cpp @@ -35,6 +35,21 @@ #include <assert.h> // +// helper functions +// + +/** count active and inactive media streams in given SDP */ +static void countStreams(const AmSdp &sdp, int &active, int &inactive) +{ + active = 0; + inactive = 0; + for (vector<SdpMedia>::const_iterator m = sdp.media.begin(); m != sdp.media.end(); ++m) { + if (m->port == 0) inactive++; + else active++; + } +} + +// // AmB2BSession methods // @@ -267,6 +282,25 @@ void AmB2BSession::onSipRequest(const AmSipRequest& req) req.method.c_str(), req.content_type.c_str()); // todo: handle filtering errors filterBody(r_ev->req.content_type, r_ev->req.body, *req_sdp.get(), a_leg); + + int active, inactive; + countStreams(*req_sdp, active, inactive); + if ((inactive > 0) && (active == 0)) { + // no active streams remaining => reply 488 (FIXME: does it matter if we + // filtered them out or they were already inactive?) + + DBG("all streams are marked as inactive\n"); + dlg.reply(req, 488, SIP_REPLY_NOT_ACCEPTABLE_HERE); + + // cleanup + delete r_ev; + if(req.method != SIP_METH_ACK) { + std::map<int,AmSipRequest>::iterator r = recvd_req.find(req.cseq); + if (r != recvd_req.end()) recvd_req.erase(r); + } + + return; + } } if (rtp_relay_enabled && @@ -1102,6 +1136,19 @@ void AmB2BCallerSession::connectCallee(const string& remote_party, if(callee_status != None) terminateOtherLeg(); + if (b2b_mode == B2BMode_SDPFilter) { + AmSdp filter_sdp; + filterBody(invite_req.content_type, invite_req.body, filter_sdp, true); + int active, inactive; + countStreams(filter_sdp, active, inactive); + if ((inactive > 0) && (active == 0)) { + // no active streams remaining => reply 488 (FIXME: does it matter if we + // filtered them out or they were already inactive?) + DBG("all streams are marked as inactive\n"); + throw AmSession::Exception(488, SIP_REPLY_NOT_ACCEPTABLE_HERE); + } + } + if (relayed_invite) { // relayed INVITE - we need to add the original INVITE to // list of received (relayed) requests @@ -1113,11 +1160,6 @@ void AmB2BCallerSession::connectCallee(const string& remote_party, B2BConnectEvent* ev = new B2BConnectEvent(remote_party,remote_uri); - if (b2b_mode == B2BMode_SDPFilter) { - AmSdp filter_sdp; - filterBody(invite_req.content_type, invite_req.body, filter_sdp, true); - } - ev->content_type = invite_req.content_type; ev->body = invite_req.body; ev->hdrs = invite_req.hdrs; diff --git a/core/AmSipHeaders.h b/core/AmSipHeaders.h index 1ea0d08..85fc1ac 100644 --- a/core/AmSipHeaders.h +++ b/core/AmSipHeaders.h @@ -62,5 +62,6 @@ #define SIP_REPLY_LOOP_DETECTED "Loop Detected" #define SIP_REPLY_NOT_EXIST "Call Leg/Transaction Does Not Exist" #define SIP_REPLY_PENDING "Request Pending" +#define SIP_REPLY_NOT_ACCEPTABLE_HERE "Not Acceptable Here" #endif /* __AMSIPHEADERS_H__ */ _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
