Browse code

sbc: moved call log functions to SBCEventLog

Raphael Coeffic authored on 12/04/2013 12:38:06
Showing 4 changed files
... ...
@@ -555,21 +555,21 @@ void SBCCallLeg::onRemoteDisappeared(const AmSipReply& reply)
555 555
 {
556 556
   CallLeg::onRemoteDisappeared(reply);
557 557
   if(a_leg)
558
-    logCallEnd("reply",NULL);
558
+    SBCEventLog::instance()->logCallEnd(dlg,"reply");
559 559
 }
560 560
 
561 561
 void SBCCallLeg::onBye(const AmSipRequest& req)
562 562
 {
563 563
   CallLeg::onBye(req);
564 564
   if(a_leg)
565
-    logCallEnd("bye",&req);
565
+    SBCEventLog::instance()->logCallEnd(req,getLocalTag(),"bye");
566 566
 }
567 567
 
568 568
 void SBCCallLeg::onOtherBye(const AmSipRequest& req)
569 569
 {
570 570
   CallLeg::onOtherBye(req);
571 571
   if(a_leg)
572
-    logCallEnd("bye",&req);
572
+    SBCEventLog::instance()->logCallEnd(req,getLocalTag(),"bye");
573 573
 }
574 574
 
575 575
 void SBCCallLeg::onDtmf(int event, int duration)
... ...
@@ -608,7 +608,7 @@ void SBCCallLeg::onControlCmd(string& cmd, AmArg& params) {
608 608
       // was for caller:
609 609
       DBG("teardown requested from control cmd\n");
610 610
       stopCall();
611
-      logCallEnd("ctrl-cmd",NULL);
611
+      SBCEventLog::instance()->logCallEnd(dlg,"ctrl-cmd");
612 612
       // FIXME: don't we want to relay the controll event as well?
613 613
     }
614 614
     else {
... ...
@@ -637,7 +637,7 @@ void SBCCallLeg::process(AmEvent* ev) {
637 637
           timer_id <= SBC_TIMER_ID_CALL_TIMERS_END) {
638 638
         DBG("timer %d timeout, stopping call\n", timer_id);
639 639
         stopCall();
640
-	logCallEnd("timeout",NULL);
640
+	SBCEventLog::instance()->logCallEnd(dlg,"timeout");
641 641
         ev->processed = true;
642 642
       }
643 643
     }
... ...
@@ -973,6 +973,7 @@ bool SBCCallLeg::CCStart(const AmSipRequest& req) {
973 973
 
974 974
     di_args.push(cc_timer_id); // current timer ID
975 975
 
976
+    bool exception_occured = false;
976 977
     try {
977 978
       (*cc_mod)->invoke("start", di_args, ret);
978 979
     } catch (const AmArg::OutOfBoundsException& e) {
... ...
@@ -980,24 +981,19 @@ bool SBCCallLeg::CCStart(const AmSipRequest& req) {
980 981
 	    "module '%s' named '%s', parameters '%s'\n",
981 982
 	    cc_if.cc_module.c_str(), cc_if.cc_name.c_str(),
982 983
 	    AmArg::print(di_args).c_str());
983
-
984
-      logCallStart(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR);
985
-      dlg->reply(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR);
986
-
987
-      // call 'end' of call control modules up to here
988
-      call_end_ts.tv_sec = call_start_ts.tv_sec;
989
-      call_end_ts.tv_usec = call_start_ts.tv_usec;
990
-      CCEnd(cc_it);
991
-
992
-      return false;
984
+      exception_occured = true;
993 985
     } catch (const AmArg::TypeMismatchException& e) {
994 986
       ERROR("TypeMismatchException executing call control interface start "
995 987
 	    "module '%s' named '%s', parameters '%s'\n",
996 988
 	    cc_if.cc_module.c_str(), cc_if.cc_name.c_str(),
997 989
 	    AmArg::print(di_args).c_str());
990
+      exception_occured = true;
991
+    }
998 992
 
999
-      logCallStart(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR);
1000
-      dlg->reply(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR);
993
+    if(exception_occured) {
994
+      SBCEventLog::instance()->
995
+	logCallStart(dlg, 500, SIP_REPLY_SERVER_INTERNAL_ERROR);
996
+      AmBasicSipDialog::reply_error(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR);
1001 997
 
1002 998
       // call 'end' of call control modules up to here
1003 999
       call_end_ts.tv_sec = call_start_ts.tv_sec;
... ...
@@ -1057,9 +1053,10 @@ bool SBCCallLeg::CCStart(const AmSipRequest& req) {
1057 1053
 	      ret[i][SBC_CC_REFUSE_CODE].asInt(), ret[i][SBC_CC_REFUSE_REASON].asCStr(),
1058 1054
 	      cc_if.cc_name.c_str(), headers.c_str());
1059 1055
 
1060
-	  logCallStart(req,
1061
-		       ret[i][SBC_CC_REFUSE_CODE].asInt(),
1062
-		       ret[i][SBC_CC_REFUSE_REASON].asCStr());
1056
+	  SBCEventLog::instance()->
1057
+	    logCallStart(dlg,
1058
+			 ret[i][SBC_CC_REFUSE_CODE].asInt(),
1059
+			 ret[i][SBC_CC_REFUSE_REASON].asCStr());
1063 1060
 
1064 1061
 	  dlg->reply(req,
1065 1062
 		     ret[i][SBC_CC_REFUSE_CODE].asInt(),
... ...
@@ -1237,90 +1234,16 @@ void SBCCallLeg::onAfterRTPRelay(AmRtpPacket* p, sockaddr_storage* remote_addr)
1237 1234
   }
1238 1235
 }
1239 1236
 
1240
-void SBCCallLeg::logCallStart(const AmSipRequest& req, 
1241
-			      int code, const string& reason)
1242
-{
1243
-  AmSipReply error_reply;
1244
-  error_reply.cseq = req.cseq;
1245
-  error_reply.code = code;
1246
-  error_reply.reason = reason;
1247
-  logCallStart(error_reply);
1248
-}
1249
-
1250 1237
 void SBCCallLeg::logCallStart(const AmSipReply& reply)
1251 1238
 {
1252 1239
   std::map<int,AmSipRequest>::iterator t_req = recvd_req.find(reply.cseq);
1253
-  AmArg start_event;
1254
-
1255
-  size_t end;
1256
-  AmUriParser uri_parser;
1257 1240
   if (t_req != recvd_req.end()) {
1258
-    AmSipRequest& orig_req = t_req->second;
1259
-    start_event["source"]   = orig_req.remote_ip + ":"
1260
-      + int2str(orig_req.remote_port);
1261
-    start_event["r-uri"]    = orig_req.r_uri;
1262
-
1263
-    if(uri_parser.parse_contact(orig_req.from,0,end))
1264
-      start_event["from"] = uri_parser.uri_str();
1265
-    else start_event["from"] = orig_req.from;
1266
-
1267
-    if(uri_parser.parse_contact(orig_req.to,0,end))
1268
-      start_event["to"] = uri_parser.uri_str();
1269
-    else start_event["to"] = orig_req.to;
1270
-  }
1271
-  else {
1272
-    start_event["r-uri"]    = dlg->getLocalUri();
1273
-
1274
-    if(uri_parser.parse_contact(dlg->getLocalParty(),0,end))
1275
-      start_event["from"] = uri_parser.uri_str();
1276
-    else start_event["from"] = dlg->getLocalParty();
1277
-
1278
-    if(uri_parser.parse_contact(dlg->getRemoteParty(),0,end))
1279
-      start_event["from"] = uri_parser.uri_str();
1280
-    else start_event["from"] = dlg->getRemoteParty();
1281
-  }
1282
-
1283
-  start_event["call-id"]  = dlg->getCallid();
1284
-  start_event["res-code"] = (int)reply.code;
1285
-  start_event["reason"]   = reply.reason;
1286
-
1287
-  SBCEventLog::instance()->logEvent(dlg->getLocalTag(),"call-start",start_event);
1288
-}
1289
-
1290
-void SBCCallLeg::logCallEnd(const string& reason, const AmSipRequest* req)
1291
-{
1292
-  AmArg end_event;
1293
-
1294
-  end_event["call-id"]  = dlg->getCallid();
1295
-  end_event["reason"]  = reason;
1296
-  
1297
-  size_t end;
1298
-  AmUriParser uri_parser;
1299
-  if (req) {
1300
-    end_event["source"]   = req->remote_ip + ":" + int2str(req->remote_port);
1301
-    end_event["r-uri"]    = req->r_uri;
1302
-
1303
-    if(uri_parser.parse_contact(req->from,0,end))
1304
-      end_event["from"] = uri_parser.uri_str();
1305
-    else end_event["from"] = req->from;
1306
-
1307
-    if(uri_parser.parse_contact(req->to,0,end))
1308
-      end_event["to"] = uri_parser.uri_str();
1309
-    else end_event["to"] = req->to;
1241
+    SBCEventLog::instance()->logCallStart(t_req->second,getLocalTag(),
1242
+					  (int)reply.code,reply.reason);
1310 1243
   }
1311 1244
   else {
1312
-    end_event["r-uri"] = dlg->getLocalUri();
1313
-
1314
-    if(uri_parser.parse_contact(dlg->getLocalParty(),0,end))
1315
-      end_event["from"] = uri_parser.uri_str();
1316
-    else end_event["from"] = dlg->getLocalParty();
1317
-
1318
-    if(uri_parser.parse_contact(dlg->getRemoteParty(),0,end))
1319
-      end_event["from"] = uri_parser.uri_str();
1320
-    else end_event["from"] = dlg->getRemoteParty();
1245
+    SBCEventLog::instance()->logCallStart(dlg,(int)reply.code,reply.reason);
1321 1246
   }
1322
-
1323
-  SBCEventLog::instance()->logEvent(dlg->getLocalTag(),"call-end",end_event);
1324 1247
 }
1325 1248
 
1326 1249
 //////////////////////////////////////////////////////////////////////////////////////////
... ...
@@ -118,8 +118,6 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
118 118
   virtual void onAfterRTPRelay(AmRtpPacket* p, sockaddr_storage* remote_addr);
119 119
 
120 120
   void logCallStart(const AmSipReply& reply);
121
-  void logCallStart(const AmSipRequest& req, int code, const string& reason);
122
-  void logCallEnd(const string& reason, const AmSipRequest* request);
123 121
 
124 122
  public:
125 123
 
... ...
@@ -4,6 +4,7 @@
4 4
 #include "AmArg.h"
5 5
 #include "ampi/MonitoringAPI.h"
6 6
 #include "AmSessionContainer.h" // monitoring ptr
7
+#include "AmUriParser.h"
7 8
 
8 9
 struct MonitoringEventLogHandler
9 10
   : public SBCEventLogHandler
... ...
@@ -52,3 +53,106 @@ void _SBCEventLog::logEvent(const string& id, const string& type,
52 53
 			  id, type, event);
53 54
   }
54 55
 }
56
+
57
+
58
+void _SBCEventLog::logCallStart(const AmSipRequest& req,
59
+				const string& local_tag,
60
+				int code, const string& reason)
61
+{
62
+  size_t end;
63
+  AmArg start_event;
64
+  AmUriParser uri_parser;
65
+
66
+  start_event["source"] = req.remote_ip + ":" + int2str(req.remote_port);
67
+  start_event["r-uri"]  = req.r_uri;
68
+
69
+  if(uri_parser.parse_contact(req.from,0,end))
70
+    start_event["from"] = uri_parser.uri_str();
71
+  else 
72
+    start_event["from"] = req.from;
73
+
74
+  if(uri_parser.parse_contact(req.to,0,end))
75
+    start_event["to"] = uri_parser.uri_str();
76
+  else 
77
+    start_event["to"] = req.to;
78
+
79
+  start_event["call-id"]  = req.callid;
80
+  start_event["res-code"] = code;
81
+  start_event["reason"]   = reason;
82
+
83
+  logEvent(local_tag,"call-start",start_event);
84
+}
85
+
86
+void _SBCEventLog::logCallStart(const AmBasicSipDialog* dlg, int code, 
87
+				const string& reason)
88
+{
89
+  size_t end;
90
+  AmArg start_event;
91
+  AmUriParser uri_parser;
92
+
93
+  if(uri_parser.parse_contact(dlg->getLocalParty(),0,end))
94
+    start_event["from"] = uri_parser.uri_str();
95
+  else start_event["from"] = dlg->getLocalParty();
96
+  
97
+  if(uri_parser.parse_contact(dlg->getRemoteParty(),0,end))
98
+    start_event["from"] = uri_parser.uri_str();
99
+  else start_event["from"] = dlg->getRemoteParty();
100
+
101
+  start_event["r-uri"]    = dlg->getLocalUri();
102
+  start_event["call-id"]  = dlg->getCallid();
103
+  start_event["res-code"] = (int)code;
104
+  start_event["reason"]   = reason;
105
+
106
+  logEvent(dlg->getLocalTag(),"call-start",start_event);
107
+}
108
+
109
+void _SBCEventLog::logCallEnd(const AmSipRequest& req,
110
+			      const string& local_tag,
111
+			      const string& reason)
112
+{
113
+  AmArg end_event;
114
+
115
+  end_event["call-id"] = req.callid;
116
+  end_event["reason"]  = reason;
117
+  end_event["source"]  = req.remote_ip + ":" + int2str(req.remote_port);
118
+  end_event["r-uri"]   = req.r_uri;
119
+  
120
+  size_t end;
121
+  AmUriParser uri_parser;
122
+  if(uri_parser.parse_contact(req.from,0,end))
123
+    end_event["from"] = uri_parser.uri_str();
124
+  else
125
+    end_event["from"] = req.from;
126
+
127
+  if(uri_parser.parse_contact(req.to,0,end))
128
+    end_event["to"] = uri_parser.uri_str();
129
+  else
130
+    end_event["to"] = req.to;
131
+
132
+  logEvent(local_tag,"call-end",end_event);
133
+}
134
+
135
+void _SBCEventLog::logCallEnd(const AmBasicSipDialog* dlg,
136
+			      const string& reason)
137
+{
138
+  AmArg end_event;
139
+
140
+  end_event["call-id"] = dlg->getCallid();
141
+  end_event["reason"]  = reason;
142
+  end_event["r-uri"]   = dlg->getLocalUri();
143
+  
144
+  size_t end;
145
+  AmUriParser uri_parser;
146
+
147
+  if(uri_parser.parse_contact(dlg->getLocalParty(),0,end))
148
+    end_event["from"] = uri_parser.uri_str();
149
+  else
150
+    end_event["from"] = dlg->getLocalParty();
151
+
152
+  if(uri_parser.parse_contact(dlg->getRemoteParty(),0,end))
153
+    end_event["from"] = uri_parser.uri_str();
154
+  else
155
+    end_event["from"] = dlg->getRemoteParty();
156
+
157
+  logEvent(dlg->getLocalTag(),"call-end",end_event);
158
+}
... ...
@@ -3,6 +3,8 @@
3 3
 
4 4
 #include "singleton.h"
5 5
 #include "AmArg.h"
6
+#include "AmSipMsg.h"
7
+#include "AmBasicSipDialog.h"
6 8
 
7 9
 #include <memory>
8 10
 #include <string>
... ...
@@ -29,6 +31,19 @@ public:
29 31
   void useMonitoringLog();
30 32
   void setEventLogHandler(SBCEventLogHandler* lh);
31 33
   void logEvent(const string& id, const string& type, const AmArg& event);
34
+
35
+  void logCallStart(const AmSipRequest& req, const string& local_tag,
36
+		    int code, const string& reason);
37
+
38
+  void logCallStart(const AmBasicSipDialog* dlg, int code, 
39
+		    const string& reason);
40
+
41
+  void logCallEnd(const AmSipRequest& req,
42
+		  const string& local_tag,
43
+		  const string& reason);
44
+
45
+  void logCallEnd(const AmBasicSipDialog* dlg,
46
+		  const string& reason);
32 47
 };
33 48
 
34 49
 typedef singleton<_SBCEventLog> SBCEventLog;