Module: sems Branch: master Commit: a5ba4c937d0533072039f9e0e761edc580fd78c8 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=a5ba4c937d0533072039f9e0e761edc580fd78c8
Author: Raphael Coeffic <[email protected]> Committer: Raphael Coeffic <[email protected]> Date: Wed Apr 3 12:35:36 2013 +0200 sbc: added call basic logging (start/end/failed) --- apps/sbc/CallLeg.cpp | 16 +++++--- apps/sbc/CallLeg.h | 4 ++ apps/sbc/SBCCallLeg.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++++++- apps/sbc/SBCCallLeg.h | 8 ++++ 4 files changed, 112 insertions(+), 7 deletions(-) diff --git a/apps/sbc/CallLeg.cpp b/apps/sbc/CallLeg.cpp index b1d7ab3..cea21de 100644 --- a/apps/sbc/CallLeg.cpp +++ b/apps/sbc/CallLeg.cpp @@ -380,6 +380,7 @@ void CallLeg::onB2BReply(B2BSipReplyEvent *ev) if (ev->forward) relaySipReply(reply); // no other B legs, terminate + onCallFailed(reply); updateCallStatus(Disconnected); stopCall(); } @@ -792,7 +793,9 @@ void CallLeg::onSipRequest(const AmSipRequest& req) TRACE("handling request %s in disconnected state", req.method.c_str()); // this is not correct but what is? AmSession::onSipRequest(req); - if (req.method == SIP_METH_BYE) stopCall(); // is this needed? + if (req.method == SIP_METH_BYE) { + stopCall(); // is this needed? + } } else AmB2BSession::onSipRequest(req); } @@ -877,8 +880,6 @@ void CallLeg::onCancel(const AmSipRequest& req) } // else { } ... ignore for B leg } - // FIXME: was it really expected to terminate the call for CANCELed re-INVITEs - // (in both directions) as well? } void CallLeg::terminateLeg() @@ -890,10 +891,12 @@ void CallLeg::terminateLeg() void CallLeg::onRemoteDisappeared(const AmSipReply& reply) { if (call_status == Connected) { - // only in case we are really connected (called on timeout or 481 from the remote) + // only in case we are really connected + // (called on timeout or 481 from the remote) DBG("remote unreachable, ending B2BUA call\n"); - clearRtpReceiverRelay(); // FIXME: shouldn't be cleared in AmB2BSession as well? + // FIXME: shouldn't be cleared in AmB2BSession as well? + clearRtpReceiverRelay(); AmB2BSession::onRemoteDisappeared(reply); // terminates the other leg updateCallStatus(Disconnected); } @@ -906,7 +909,8 @@ void CallLeg::onBye(const AmSipRequest& req) AmB2BSession::onBye(req); } -void CallLeg::addNewCallee(CallLeg *callee, ConnectLegEvent *e, AmB2BSession::RTPRelayMode mode) +void CallLeg::addNewCallee(CallLeg *callee, ConnectLegEvent *e, + AmB2BSession::RTPRelayMode mode) { OtherLegInfo b; b.id = callee->getLocalTag(); diff --git a/apps/sbc/CallLeg.h b/apps/sbc/CallLeg.h index 6f6caba..912b00b 100644 --- a/apps/sbc/CallLeg.h +++ b/apps/sbc/CallLeg.h @@ -256,6 +256,10 @@ class CallLeg: public AmB2BSession * Redefine to implement serial fork or handle redirect. */ virtual void onBLegRefused(const AmSipReply& reply) { } + /** handler called when all B-legs failed. + The reply passed is the last final reply. */ + virtual void onCallFailed(const AmSipReply& reply) { } + /** add newly created callee with prepared ConnectLegEvent */ void addNewCallee(CallLeg *callee, ConnectLegEvent *e) { addNewCallee(callee, e, rtp_relay_mode); } diff --git a/apps/sbc/SBCCallLeg.cpp b/apps/sbc/SBCCallLeg.cpp index 38076a0..29e01b7 100644 --- a/apps/sbc/SBCCallLeg.cpp +++ b/apps/sbc/SBCCallLeg.cpp @@ -21,6 +21,8 @@ #include "HeaderFilter.h" #include "ParamReplacer.h" #include "SDPFilter.h" +#include "SBCEventLog.h" + #include <algorithm> using namespace std; @@ -543,6 +545,20 @@ void SBCCallLeg::onSendRequest(AmSipRequest& req, int &flags) { CallLeg::onSendRequest(req, flags); } +void SBCCallLeg::onRemoteDisappeared(const AmSipReply& reply) +{ + CallLeg::onRemoteDisappeared(reply); + if(a_leg) + logCallEnd("reply",NULL); +} + +void SBCCallLeg::onBye(const AmSipRequest& req) +{ + CallLeg::onBye(req); + if(a_leg) + logCallEnd("bye",&req); +} + void SBCCallLeg::onDtmf(int event, int duration) { if(media_session) { @@ -577,6 +593,7 @@ void SBCCallLeg::onControlCmd(string& cmd, AmArg& params) { // was for caller: DBG("teardown requested from control cmd\n"); stopCall(); + logCallEnd("ctrl-cmd",NULL); // FIXME: don't we want to relay the controll event as well? } else { @@ -605,6 +622,7 @@ void SBCCallLeg::process(AmEvent* ev) { timer_id <= SBC_TIMER_ID_CALL_TIMERS_END) { DBG("timer %d timeout, stopping call\n", timer_id); stopCall(); + logCallEnd("timeout",NULL); ev->processed = true; } } @@ -857,6 +875,7 @@ void SBCCallLeg::onCallConnected(const AmSipReply& reply) { gettimeofday(&call_connect_ts, NULL); } + logCallStart(reply); CCConnect(reply); } } @@ -946,6 +965,8 @@ bool SBCCallLeg::CCStart(const AmSipRequest& req) { "module '%s' named '%s', parameters '%s'\n", cc_if.cc_module.c_str(), cc_if.cc_name.c_str(), AmArg::print(di_args).c_str()); + + logCallStart(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR); dlg->reply(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR); // call 'end' of call control modules up to here @@ -959,6 +980,8 @@ bool SBCCallLeg::CCStart(const AmSipRequest& req) { "module '%s' named '%s', parameters '%s'\n", cc_if.cc_module.c_str(), cc_if.cc_name.c_str(), AmArg::print(di_args).c_str()); + + logCallStart(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR); dlg->reply(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR); // call 'end' of call control modules up to here @@ -1030,8 +1053,12 @@ bool SBCCallLeg::CCStart(const AmSipRequest& req) { ret[i][SBC_CC_REFUSE_CODE].asInt(), ret[i][SBC_CC_REFUSE_REASON].asCStr(), cc_if.cc_name.c_str(), headers.c_str()); + logCallStart(req, + ret[i][SBC_CC_REFUSE_CODE].asInt(), + ret[i][SBC_CC_REFUSE_REASON].asCStr()); + dlg->reply(req, - ret[i][SBC_CC_REFUSE_CODE].asInt(), + ret[i][SBC_CC_REFUSE_CODE].asInt(), ret[i][SBC_CC_REFUSE_REASON].asCStr(), NULL, headers); @@ -1184,6 +1211,10 @@ void SBCCallLeg::onBLegRefused(const AmSipReply& reply) } } +void SBCCallLeg::onCallFailed(const AmSipReply& reply) +{ + logCallStart(reply); +} bool SBCCallLeg::onBeforeRTPRelay(AmRtpPacket* p, sockaddr_storage* remote_addr) { @@ -1202,6 +1233,64 @@ void SBCCallLeg::onAfterRTPRelay(AmRtpPacket* p, sockaddr_storage* remote_addr) } } +void SBCCallLeg::logCallStart(const AmSipRequest& req, + int code, const string& reason) +{ + AmSipReply error_reply; + error_reply.cseq = req.cseq; + error_reply.code = code; + error_reply.reason = reason; + logCallStart(error_reply); +} + +void SBCCallLeg::logCallStart(const AmSipReply& reply) +{ + std::map<int,AmSipRequest>::iterator t_req = recvd_req.find(reply.cseq); + AmArg start_event; + + if (t_req != recvd_req.end()) { + AmSipRequest& orig_req = t_req->second; + start_event["source"] = orig_req.remote_ip + ":" + + int2str(orig_req.remote_port); + start_event["r-uri"] = orig_req.r_uri; + start_event["from"] = orig_req.from; + start_event["to"] = orig_req.to; + } + else { + start_event["r-uri"] = dlg->getLocalUri(); + start_event["from"] = dlg->getLocalParty(); + start_event["to"] = dlg->getRemoteParty(); + } + + start_event["call-id"] = dlg->getCallid(); + start_event["res-code"] = (int)reply.code; + start_event["reason"] = reply.reason; + + SBCEventLog::instance()->logEvent(dlg->getLocalTag(),"call-start",start_event); +} + +void SBCCallLeg::logCallEnd(const string& reason, const AmSipRequest* req) +{ + AmArg end_event; + + end_event["call-id"] = dlg->getCallid(); + end_event["reason"] = reason; + + if (req) { + end_event["source"] = req->remote_ip + ":" + int2str(req->remote_port); + end_event["r-uri"] = req->r_uri; + end_event["from"] = req->from; + end_event["to"] = req->to; + } + else { + end_event["r-uri"] = dlg->getLocalUri(); + end_event["from"] = dlg->getRemoteParty(); + end_event["to"] = dlg->getLocalParty(); + } + + SBCEventLog::instance()->logEvent(dlg->getLocalTag(),"call-end",end_event); +} + ////////////////////////////////////////////////////////////////////////////////////////// // body filtering diff --git a/apps/sbc/SBCCallLeg.h b/apps/sbc/SBCCallLeg.h index 8d42f20..866818f 100644 --- a/apps/sbc/SBCCallLeg.h +++ b/apps/sbc/SBCCallLeg.h @@ -101,6 +101,7 @@ class SBCCallLeg : public CallLeg, public CredentialHolder virtual void onCallStatusChange(); virtual void onBLegRefused(const AmSipReply& reply); + virtual void onCallFailed(const AmSipReply& reply); /** Call-backs used by RTP stream(s) * Note: these methods will be called from the RTP receiver thread. @@ -108,6 +109,10 @@ class SBCCallLeg : public CallLeg, public CredentialHolder virtual bool onBeforeRTPRelay(AmRtpPacket* p, sockaddr_storage* remote_addr); virtual void onAfterRTPRelay(AmRtpPacket* p, sockaddr_storage* remote_addr); + void logCallStart(const AmSipReply& reply); + void logCallStart(const AmSipRequest& req, int code, const string& reason); + void logCallEnd(const string& reason, const AmSipRequest* request); + public: SBCCallLeg(const SBCCallProfile& call_profile, AmSipDialog* dlg=NULL); @@ -171,6 +176,9 @@ class SBCCallLeg : public CallLeg, public CredentialHolder void onSipReply(const AmSipRequest& req, const AmSipReply& reply, AmSipDialog::Status old_dlg_status); void onSendRequest(AmSipRequest& req, int &flags); + void onRemoteDisappeared(const AmSipReply& reply); + void onBye(const AmSipRequest& req); + void onControlCmd(string& cmd, AmArg& params); void createCalleeSession(); _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
