Browse code

b2b: make other-id private and add setter and getter.

Raphael Coeffic authored on 19/03/2013 22:01:42
Showing 6 changed files
... ...
@@ -128,7 +128,7 @@ void CallLeg::terminateNotConnectedLegs()
128 128
   OtherLegInfo b;
129 129
 
130 130
   for (vector<OtherLegInfo>::iterator i = other_legs.begin(); i != other_legs.end(); ++i) {
131
-    if (i->id != other_id) {
131
+    if (i->id != getOtherId()) {
132 132
       i->releaseMediaSession();
133 133
       AmSessionContainer::instance()->postEvent(i->id, new B2BEvent(B2BTerminateLeg));
134 134
     }
... ...
@@ -145,7 +145,7 @@ void CallLeg::terminateNotConnectedLegs()
145 145
 
146 146
 void CallLeg::removeOtherLeg(const string &id)
147 147
 {
148
-  if (other_id == id) other_id.clear();
148
+  if (getOtherId() == id) AmB2BSession::clear_other();
149 149
 
150 150
   // remove the call leg from list of B legs
151 151
   for (vector<OtherLegInfo>::iterator i = other_legs.begin(); i != other_legs.end(); ++i) {
... ...
@@ -254,7 +254,7 @@ void CallLeg::onB2BReply(B2BSipReplyEvent *ev)
254 254
   // possible so the check can stay as it is for Connected state but for other
255 255
   // should check other_legs instead of other_id
256 256
 #if 0
257
-  if(other_id.empty()){
257
+  if(getOtherId().empty()){
258 258
     //DBG("Discarding B2BSipReply from other leg (other_id empty)\n");
259 259
     DBG("B2BSipReply: other_id empty ("
260 260
         "reply code=%i; method=%s; callid=%s; from_tag=%s; "
... ...
@@ -263,9 +263,9 @@ void CallLeg::onB2BReply(B2BSipReplyEvent *ev)
263 263
         reply.to_tag.c_str(),reply.cseq);
264 264
     //return;
265 265
   }
266
-  else if(other_id != reply.from_tag){// was: local_tag
266
+  else if(getOtherId() != reply.from_tag){// was: local_tag
267 267
     DBG("Dialog mismatch! (oi=%s;ft=%s)\n",
268
-        other_id.c_str(),reply.from_tag.c_str());
268
+        getOtherId().c_str(),reply.from_tag.c_str());
269 269
     return;
270 270
   }
271 271
 #endif
... ...
@@ -290,7 +290,7 @@ void CallLeg::onB2BReply(B2BSipReplyEvent *ev)
290 290
           setOtherId(reply);
291 291
           TRACE("1xx reply with to-tag received in NoReply state,"
292 292
 		" changing status to Ringing and remembering the"
293
-		" other leg ID (%s)\n", other_id.c_str());
293
+		" other leg ID (%s)\n", getOtherId().c_str());
294 294
           updateCallStatus(Ringing);
295 295
         }
296 296
         if (ev->forward && relaySipReply(reply) != 0) {
... ...
@@ -299,7 +299,7 @@ void CallLeg::onB2BReply(B2BSipReplyEvent *ev)
299 299
         }
300 300
       }
301 301
       else {
302
-        if (other_id != reply.from_tag) {
302
+        if (getOtherId() != reply.from_tag) {
303 303
            // in Ringing state but the reply comes from another B leg than
304 304
            // previous 1xx reply => do not relay or process other way
305 305
           DBG("1xx reply received in %s state from another B leg, ignoring\n", callStatus2str(call_status));
... ...
@@ -324,7 +324,8 @@ void CallLeg::onB2BReply(B2BSipReplyEvent *ev)
324 324
       }
325 325
     } else if (reply.code < 300) { // 2xx replies
326 326
       setOtherId(reply);
327
-      TRACE("setting call status to connected with leg %s\n", other_id.c_str());
327
+      TRACE("setting call status to connected with leg %s\n", 
328
+	    getOtherId().c_str());
328 329
 
329 330
       // terminate all other legs than the connected one (determined by other_id)
330 331
       terminateNotConnectedLegs();
... ...
@@ -341,7 +342,8 @@ void CallLeg::onB2BReply(B2BSipReplyEvent *ev)
341 342
       other_legs.begin()->releaseMediaSession(); // remove reference hold by OtherLegInfo
342 343
       other_legs.clear(); // no need to remember the connected leg here
343 344
       if (media_session) {
344
-        TRACE("connecting media session: %s to %s\n", dlg->getLocalTag().c_str(), other_id.c_str());
345
+        TRACE("connecting media session: %s to %s\n", 
346
+	      dlg->getLocalTag().c_str(), getOtherId().c_str());
345 347
         media_session->changeSession(a_leg, this);
346 348
         if (initial_sdp_stored && ev->forward) updateRemoteSdp(initial_sdp);
347 349
       }
... ...
@@ -386,7 +388,7 @@ void CallLeg::onB2BReply(B2BSipReplyEvent *ev)
386 388
   }
387 389
 
388 390
   // reply not from our peer (might be one of the discarded ones)
389
-  if (other_id != reply.from_tag) {
391
+  if (getOtherId() != reply.from_tag) {
390 392
     TRACE("ignoring reply from %s in %s state\n", reply.from_tag.c_str(), callStatus2str(call_status));
391 393
     return;
392 394
   }
... ...
@@ -410,7 +412,7 @@ void CallLeg::onB2BConnect(ConnectLegEvent* co_ev)
410 412
   }
411 413
 
412 414
   MONITORING_LOG3(getLocalTag().c_str(), 
413
-		  "b2b_leg", other_id.c_str(),
415
+		  "b2b_leg", getOtherId().c_str(),
414 416
 		  "to", dlg->getRemoteParty().c_str(),
415 417
 		  "ruri", dlg->getRemoteUri().c_str());
416 418
 
... ...
@@ -475,7 +477,8 @@ void CallLeg::onB2BReconnect(ReconnectLegEvent* ev)
475 477
     ERROR("BUG: invalid argument given\n");
476 478
     return;
477 479
   }
478
-  TRACE("handling ReconnectLegEvent, other: %s, connect to %s\n", other_id.c_str(), ev->session_tag.c_str());
480
+  TRACE("handling ReconnectLegEvent, other: %s, connect to %s\n", 
481
+	getOtherId().c_str(), ev->session_tag.c_str());
479 482
 
480 483
   ev->markAsProcessed();
481 484
 
... ...
@@ -484,7 +487,7 @@ void CallLeg::onB2BReconnect(ReconnectLegEvent* ev)
484 487
   resumeHeld(false);
485 488
   clearRtpReceiverRelay();
486 489
 
487
-  other_id = ev->session_tag;
490
+  setOtherId(ev->session_tag);
488 491
   if (ev->role == ReconnectLegEvent::A) a_leg = true;
489 492
   else a_leg = false;
490 493
   // FIXME: What about calling SBC CC modules in this case? Original CC
... ...
@@ -503,7 +506,7 @@ void CallLeg::onB2BReconnect(ReconnectLegEvent* ev)
503 506
   else rtp_relay_mode = RTP_Direct;
504 507
 
505 508
   MONITORING_LOG3(getLocalTag().c_str(),
506
-		  "b2b_leg", other_id.c_str(),
509
+		  "b2b_leg", getOtherId().c_str(),
507 510
 		  "to", dlg->getRemoteParty().c_str(),
508 511
 		  "ruri", dlg->getRemoteUri().c_str());
509 512
 
... ...
@@ -563,9 +566,10 @@ void CallLeg::onB2BReplace(ReplaceLegEvent *e)
563 566
     return;
564 567
   }
565 568
 
566
-  TRACE("handling ReplaceLegEvent, other: %s, connect to %s\n", other_id.c_str(), reconnect->session_tag.c_str());
569
+  TRACE("handling ReplaceLegEvent, other: %s, connect to %s\n", 
570
+	getOtherId().c_str(), reconnect->session_tag.c_str());
567 571
 
568
-  string id(other_id);
572
+  string id(getOtherId());
569 573
   if (id.empty()) {
570 574
     // try it with the first B leg?
571 575
     if (other_legs.empty()) {
... ...
@@ -585,7 +589,7 @@ void CallLeg::onB2BReplace(ReplaceLegEvent *e)
585 589
   removeOtherLeg(id);
586 590
 
587 591
   // commit suicide if our last B leg is stolen
588
-  if (other_legs.empty() && other_id.empty()) stopCall();
592
+  if (other_legs.empty() && getOtherId().empty()) stopCall();
589 593
 }
590 594
 
591 595
 void CallLeg::onB2BReplaceInProgress(ReplaceInProgressEvent *e)
... ...
@@ -957,7 +961,7 @@ void CallLeg::updateCallStatus(CallStatus new_status)
957 961
         getLocalTag().c_str(),
958 962
         callStatus2str(call_status),
959 963
         callStatus2str(new_status),
960
-        other_id.c_str());
964
+        getOtherId().c_str());
961 965
   else
962 966
     TRACE("%s leg %s changing status from %s to %s\n",
963 967
         a_leg ? "A" : "B",
... ...
@@ -1059,7 +1063,7 @@ void CallLeg::replaceExistingLeg(const string &session_tag, const string &hdrs)
1059 1063
 
1060 1064
 void CallLeg::clear_other()
1061 1065
 {
1062
-  removeOtherLeg(other_id);
1066
+  removeOtherLeg(getOtherId());
1063 1067
   AmB2BSession::clear_other();
1064 1068
 }
1065 1069
 
... ...
@@ -279,7 +279,12 @@ class CallLeg: public AmB2BSession
279 279
     // functions offered to successors
280 280
 
281 281
     CallStatus getCallStatus() { return call_status; }
282
-    virtual void setOtherId(const AmSipReply& reply) { other_id = reply.from_tag; }
282
+    virtual void setOtherId(const string& n_other_id) { 
283
+      AmB2BSession::setOtherId(n_other_id);
284
+    }
285
+    virtual void setOtherId(const AmSipReply& reply) { 
286
+      AmB2BSession::setOtherId(reply.from_tag);
287
+    }
283 288
 
284 289
     // @see AmSession
285 290
     virtual void onInvite(const AmSipRequest& req);
... ...
@@ -481,7 +481,7 @@ void SBCCallLeg::onSipRequest(const AmSipRequest& req) {
481 481
 void SBCCallLeg::setOtherId(const AmSipReply& reply)
482 482
 {
483 483
   DBG("setting other_id to '%s'",reply.from_tag.c_str());
484
-  CallLeg::setOtherId(reply);
484
+  setOtherId(reply.from_tag);
485 485
   if(call_profile.transparent_dlg_id && !reply.to_tag.empty()) {
486 486
     dlg->setExtLocalTag(reply.to_tag);
487 487
   }
... ...
@@ -1103,7 +1103,7 @@ void SBCCallLeg::CCConnect(const AmSipReply& reply) {
1103 1103
     di_args.back().push((int)call_connect_ts.tv_usec);
1104 1104
     for (int i=0;i<2;i++)
1105 1105
       di_args.back().push((int)0);
1106
-    di_args.push(other_id);                      // other leg ltag
1106
+    di_args.push(getOtherId());                      // other leg ltag
1107 1107
 
1108 1108
 
1109 1109
     try {
... ...
@@ -1426,7 +1426,7 @@ void SBCCallLeg::changeRtpMode(RTPRelayMode new_mode)
1426 1426
       break;
1427 1427
   }
1428 1428
 
1429
-  if (!other_id.empty())
1429
+  if (!getOtherId().empty())
1430 1430
     relayEvent(new ChangeRtpModeEvent(new_mode, getMediaSession()));
1431 1431
   setRtpRelayMode(new_mode);
1432 1432
 }
... ...
@@ -147,7 +147,6 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
147 147
 
148 148
   SBCCallProfile &getCallProfile() { return call_profile; }
149 149
   CallStatus getCallStatus() { return CallLeg::getCallStatus(); }
150
-  const string &getOtherId() { return other_id; }
151 150
 
152 151
   // media interface must be accessible from CC modules
153 152
   AmB2BMedia *getMediaSession() { return media_session; }
... ...
@@ -167,6 +166,7 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
167 166
  protected:
168 167
 
169 168
   void setOtherId(const AmSipReply& reply);
169
+  void setOtherId(const string& n_other_id) { CallLeg::setOtherId(n_other_id); }
170 170
 
171 171
   void onSipReply(const AmSipRequest& req, const AmSipReply& reply, AmSipDialog::Status old_dlg_status);
172 172
   void onSendRequest(AmSipRequest& req, int &flags);
... ...
@@ -99,12 +99,7 @@ void AmB2BSession::set_sip_relay_only(bool r) {
99 99
 
100 100
 void AmB2BSession::clear_other()
101 101
 {
102
-#if __GNUC__ < 3
103
-  string cleared ("");
104
-  other_id.assign (cleared, 0, 0);
105
-#else
106
-  other_id.clear();
107
-#endif
102
+  setOtherId("");
108 103
 }
109 104
 
110 105
 void AmB2BSession::process(AmEvent* event)
... ...
@@ -912,7 +907,7 @@ void AmB2BCallerSession::onB2BEvent(B2BEvent* ev)
912 907
 
913 908
     AmSipReply& reply = ((B2BSipReplyEvent*)ev)->reply;
914 909
 
915
-    if(other_id.empty()){
910
+    if(getOtherId().empty()){
916 911
       //DBG("Discarding B2BSipReply from other leg (other_id empty)\n");
917 912
       DBG("B2BSipReply: other_id empty ("
918 913
 	  "reply code=%i; method=%s; callid=%s; from_tag=%s; "
... ...
@@ -921,9 +916,9 @@ void AmB2BCallerSession::onB2BEvent(B2BEvent* ev)
921 916
 	  reply.to_tag.c_str(),reply.cseq);
922 917
       //return;
923 918
     }
924
-    else if(other_id != reply.from_tag){// was: local_tag
919
+    else if(getOtherId() != reply.from_tag){// was: local_tag
925 920
       DBG("Dialog mismatch! (oi=%s;ft=%s)\n",
926
-	  other_id.c_str(),reply.from_tag.c_str());
921
+	  getOtherId().c_str(),reply.from_tag.c_str());
927 922
       return;
928 923
     }
929 924
 
... ...
@@ -985,7 +980,7 @@ void AmB2BCallerSession::onB2BEvent(B2BEvent* ev)
985 980
 
986 981
 int AmB2BCallerSession::relayEvent(AmEvent* ev)
987 982
 {
988
-  if(other_id.empty() && !getStopped()){
983
+  if(getOtherId().empty() && !getStopped()){
989 984
 
990 985
     bool create_callee = false;
991 986
     B2BSipEvent* sip_ev = dynamic_cast<B2BSipEvent*>(ev);
... ...
@@ -996,8 +991,8 @@ int AmB2BCallerSession::relayEvent(AmEvent* ev)
996 991
 
997 992
     if (create_callee) {
998 993
       createCalleeSession();
999
-      if (other_id.length()) {
1000
-	MONITORING_LOG(getLocalTag().c_str(), "b2b_leg", other_id.c_str());
994
+      if (getOtherId().length()) {
995
+	MONITORING_LOG(getLocalTag().c_str(), "b2b_leg", getOtherId().c_str());
1001 996
       }
1002 997
     }
1003 998
 
... ...
@@ -1091,9 +1086,9 @@ void AmB2BCallerSession::createCalleeSession() {
1091 1086
 
1092 1087
   AmSipDialog* callee_dlg = callee_session->dlg;
1093 1088
 
1094
-  other_id = AmSession::getNewId();
1089
+  setOtherId(AmSession::getNewId());
1095 1090
   
1096
-  callee_dlg->setLocalTag(other_id);
1091
+  callee_dlg->setLocalTag(getOtherId());
1097 1092
   callee_dlg->setCallid(AmSession::getNewId());
1098 1093
 
1099 1094
   callee_dlg->setLocalParty(dlg->getRemoteParty());
... ...
@@ -1105,7 +1100,7 @@ void AmB2BCallerSession::createCalleeSession() {
1105 1100
 	 callee_session->getLocalTag().c_str());
1106 1101
   }
1107 1102
 
1108
-  MONITORING_LOG4(other_id.c_str(), 
1103
+  MONITORING_LOG4(getOtherId().c_str(), 
1109 1104
 		  "dir",  "out",
1110 1105
 		  "from", callee_dlg->getLocalParty().c_str(),
1111 1106
 		  "to",   callee_dlg->getRemoteParty().c_str(),
... ...
@@ -1119,7 +1114,7 @@ void AmB2BCallerSession::createCalleeSession() {
1119 1114
   }
1120 1115
 
1121 1116
   AmSessionContainer* sess_cont = AmSessionContainer::instance();
1122
-  sess_cont->addSession(other_id,callee_session);
1117
+  sess_cont->addSession(getOtherId(),callee_session);
1123 1118
 
1124 1119
   callee_session->start();
1125 1120
 }
... ...
@@ -1180,7 +1175,7 @@ void AmB2BCalleeSession::onB2BEvent(B2BEvent* ev)
1180 1175
       return;
1181 1176
 
1182 1177
     MONITORING_LOG3(getLocalTag().c_str(), 
1183
-		    "b2b_leg", other_id.c_str(),
1178
+		    "b2b_leg", getOtherId().c_str(),
1184 1179
 		    "to", co_ev->remote_party.c_str(),
1185 1180
 		    "ruri", co_ev->remote_uri.c_str());
1186 1181
 
... ...
@@ -134,10 +134,11 @@ class AmB2BSession: public AmSession
134 134
     RTP_Transcoding
135 135
   };
136 136
 
137
- protected:
137
+private:
138 138
   /** local tag of the other leg */
139 139
   string other_id;
140 140
 
141
+ protected:
141 142
   /** Tell if the session should
142 143
    *  process SIP request itself
143 144
    * or only relay them (B2B mode).
... ...
@@ -267,6 +268,12 @@ class AmB2BSession: public AmSession
267 268
   virtual bool updateRemoteSdp(AmSdp &sdp);
268 269
 
269 270
  public:
271
+
272
+  virtual void setOtherId(const string& n_other_id) {
273
+    other_id = n_other_id;
274
+  }
275
+  virtual const string& getOtherId() const { return other_id; }
276
+
270 277
   void set_sip_relay_only(bool r);
271 278
 
272 279
   /** set RTP relay mode (possibly initiaze by given INVITE) */