Browse code

sbc events q/f: log canceled calls

Václav Kubart authored on 13/06/2013 12:51:47
Showing 5 changed files
... ...
@@ -365,7 +365,7 @@ void CallLeg::b2bInitialErr(AmSipReply& reply, bool forward)
365 365
   // relay current response
366 366
   if (!other_legs.empty()) return;
367 367
 
368
-  onCallFailed(reply);
368
+  onCallFailed(CallRefused, &reply);
369 369
   if (forward) relaySipReply(reply);
370 370
 
371 371
   // no other B legs, terminate
... ...
@@ -894,6 +894,7 @@ void CallLeg::onCancel(const AmSipRequest& req)
894 894
   if ((call_status == Ringing) || (call_status == NoReply)) {
895 895
     if (a_leg) {
896 896
       // terminate whole B2B call if the caller receives CANCEL
897
+      onCallFailed(CallCanceled, NULL);
897 898
       stopCall();
898 899
     }
899 900
     // else { } ... ignore for B leg
... ...
@@ -185,6 +185,12 @@ class CallLeg: public AmB2BSession
185 185
       Disconnecting //< we were connected and now going to be disconnected (waiting for reINVITE reply for example)
186 186
     };
187 187
 
188
+    /** reason reported in onCallFailed method */
189
+    enum CallFailureReason {
190
+      CallRefused, //< non-ok reply received and no more B-legs exit
191
+      CallCanceled //< call canceled
192
+    };
193
+
188 194
   private:
189 195
 
190 196
     CallStatus call_status; //< status of the call (replaces callee's status)
... ...
@@ -265,9 +271,9 @@ class CallLeg: public AmB2BSession
265 271
      * Redefine to implement serial fork or handle redirect. */
266 272
     virtual void onBLegRefused(const AmSipReply& reply) { }
267 273
 
268
-    /** handler called when all B-legs failed. 
274
+    /** handler called when all B-legs failed or the call has been canceled. 
269 275
 	The reply passed is the last final reply. */
270
-    virtual void onCallFailed(const AmSipReply& reply) { }
276
+    virtual void onCallFailed(CallFailureReason reason, const AmSipReply *reply) { }
271 277
 
272 278
     /** add newly created callee with prepared ConnectLegEvent */
273 279
     void addNewCallee(CallLeg *callee, ConnectLegEvent *e) { addNewCallee(callee, e, rtp_relay_mode); }
... ...
@@ -1232,9 +1232,17 @@ void SBCCallLeg::onBLegRefused(const AmSipReply& reply)
1232 1232
   }
1233 1233
 }
1234 1234
 
1235
-void SBCCallLeg::onCallFailed(const AmSipReply& reply)
1235
+void SBCCallLeg::onCallFailed(CallFailureReason reason, const AmSipReply *reply)
1236 1236
 {
1237
-  logCallStart(reply);
1237
+  switch (reason) {
1238
+    case CallRefused:
1239
+      if (reply) logCallStart(*reply);
1240
+      break;
1241
+
1242
+    case CallCanceled:
1243
+      logCanceledCall();
1244
+      break;
1245
+  }
1238 1246
 }
1239 1247
 
1240 1248
 bool SBCCallLeg::onBeforeRTPRelay(AmRtpPacket* p, sockaddr_storage* remote_addr)
... ...
@@ -1269,6 +1277,20 @@ void SBCCallLeg::logCallStart(const AmSipReply& reply)
1269 1277
   }
1270 1278
 }
1271 1279
 
1280
+void SBCCallLeg::logCanceledCall()
1281
+{
1282
+  std::map<int,AmSipRequest>::iterator t_req = recvd_req.find(est_invite_cseq);
1283
+  if (t_req != recvd_req.end()) {
1284
+    SBCEventLog::instance()->logCallStart(t_req->second,getLocalTag(),
1285
+					  "","",
1286
+					  0,"canceled");
1287
+  }
1288
+  else {
1289
+    ERROR("could not log call-attempt (canceled, ci='%s';lt='%s')",
1290
+	  getCallID().c_str(),getLocalTag().c_str());
1291
+  }
1292
+}
1293
+
1272 1294
 //////////////////////////////////////////////////////////////////////////////////////////
1273 1295
 // body filtering
1274 1296
 
... ...
@@ -63,9 +63,6 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
63 63
 
64 64
   void fixupCCInterface(const string& val, CCInterface& cc_if);
65 65
 
66
-  /** handler called when the second leg is connected */
67
-  virtual void onCallConnected(const AmSipReply& reply);
68
-
69 66
   /** handler called when call is stopped (see AmSession) */
70 67
   virtual void onStop();
71 68
 
... ...
@@ -98,7 +95,12 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
98 95
 
99 96
   virtual void onCallStatusChange();
100 97
   virtual void onBLegRefused(const AmSipReply& reply);
101
-  virtual void onCallFailed(const AmSipReply& reply);
98
+
99
+  /** handler called when the call is refused with a non-ok reply or canceled */
100
+  virtual void onCallFailed(CallFailureReason reason, const AmSipReply *reply);
101
+
102
+  /** handler called when the second leg is connected */
103
+  virtual void onCallConnected(const AmSipReply& reply);
102 104
 
103 105
   /** Call-backs used by RTP stream(s)
104 106
    *  Note: these methods will be called from the RTP receiver thread.
... ...
@@ -107,6 +109,8 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
107 109
   virtual void onAfterRTPRelay(AmRtpPacket* p, sockaddr_storage* remote_addr);
108 110
 
109 111
   void logCallStart(const AmSipReply& reply);
112
+  void logCanceledCall();
113
+
110 114
 
111 115
  public:
112 116
 
... ...
@@ -86,7 +86,7 @@ void _SBCEventLog::logCallStart(const AmSipRequest& req,
86 86
   DBG("to-ua: '%s'",to_remote_ua.c_str());
87 87
 
88 88
   start_event["call-id"]  = req.callid;
89
-  start_event["res-code"] = code;
89
+  if (code) start_event["res-code"] = code;
90 90
   start_event["reason"]   = reason;
91 91
 
92 92
   logEvent(local_tag,