[prev in list] [next in list] [prev in thread] [next in thread] 

List:       semsdev
Subject:    Re: [Semsdev] DSM B2BUA: callflow and SDP originator session id
From:       Emil Kroymann <emil.kroymann () isaco ! de>
Date:       2012-02-28 10:07:51
Message-ID: 20120228110751.31c994db () descartes
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Re-Hi,

Am Mon, 27 Feb 2012 15:29:29 +0100
schrieb Emil Kroymann <emil.kroymann@isaco.de>:

> > Also, after a small look at the patch I think replacing the o-line
> > can be done at a more generic place - actually i think everywhere
> > usually the SDP filter is called. can you possibly split out this 
> > functionality into a separate patch?
> 
> I will split this functionality out, but I think it is placed pretty
> generically everywhere where also the replaceConnectionAddress
> function for rtp relay mode would be called. 
> 
> I'll send the split-up patches.

Attached is the patch for replacing the o-line. The replacing function
is invoked every time a SDP body is sent out. I think that's as generic
as it can get. You cannot do it on receipt of a SIP message as
the SDP filter function because, that would be in the wrong dialog. The
o-line can only be saved in the dialog where the SDP is sent out, to
cope with the case where the SDP is generated by SEMS itself.

The other part of the patch - the optional new call flow - I prefer to
do once this patch is applied.

Regards,
Emil

-- 
Emil Kroymann
VoIP Services Engineer

Email: emil.kroymann@isaco.de
Tel: +49-30-203899885
Mobile: +49-176-38389303

ISACO GmbH
Kurfürstenstraße 79
10787 Berlin
Germany

Amtsgericht Charlottenburg, HRB 112464B
Geschäftsführer: Daniel Frommherz


[Attachment #7 (text/x-patch)]

diff --git a/core/AmB2BSession.cpp b/core/AmB2BSession.cpp
index 06be6cd..3000cee 100644
--- a/core/AmB2BSession.cpp
+++ b/core/AmB2BSession.cpp
@@ -572,6 +572,10 @@ void AmB2BSession::onInvite2xx(const AmSipReply& reply)
 int AmB2BSession::onSdpCompleted(const AmSdp& local_sdp, const AmSdp& remote_sdp)
 {
   if(!sip_relay_only){
+    if (saved_origin.get() == NULL) {
+      saved_origin.reset(new SdpOrigin(local_sdp.origin));
+      
+    }
     return AmSession::onSdpCompleted(local_sdp,remote_sdp);
   }
   
@@ -725,6 +729,14 @@ int AmB2BSession::sendEstablishedReInvite() {
       body = &r_body; // should we keep the old one intact???
     }
 
+    AmMimeBody r2_body;
+    if (saved_origin.get() != NULL) {
+      if (replaceOrigin(*body, r2_body))
+	body = &r2_body;
+    } else {
+      saveOrigin(*body);
+    }
+
     return dlg.reinvite("", body,
 			SIP_FLAGS_VERBATIM);
   } catch (const string& s) {
@@ -795,6 +807,14 @@ int AmB2BSession::relaySip(const AmSipRequest& req)
       }
     }
 
+    AmMimeBody r2_body;
+    if (saved_origin.get() != NULL) {
+      if (replaceOrigin(*body, r2_body))
+	body = &r2_body;
+    } else if (!body->empty()) {
+      saveOrigin(*body);
+    }
+
     int err = dlg.sendRequest(req.method, body, *hdrs, SIP_FLAGS_VERBATIM);
     if(err < 0){
       ERROR("dlg.sendRequest() failed\n");
@@ -869,6 +889,14 @@ int AmB2BSession::relaySip(const AmSipRequest& orig, const AmSipReply& reply)
     }
   }
 
+  AmMimeBody r2_body;
+  if (saved_origin.get() != NULL) {
+    if (replaceOrigin(*body, r2_body))
+      body = &r2_body;
+  } else if (!body->empty()) {
+    saveOrigin(*body);
+  }
+
   int err = dlg.reply(orig,reply.code,reply.reason,
 		      body, *hdrs, SIP_FLAGS_VERBATIM);
   if(err < 0){
@@ -886,6 +914,38 @@ int AmB2BSession::relaySip(const AmSipRequest& orig, const AmSipReply& reply)
   return 0;
 }
 
+bool AmB2BSession::replaceOrigin(const AmMimeBody& body, AmMimeBody& replaced_body)
+{
+  AmSdp sdp;
+  if (sdp.parse((const char *)body.getPayload()) != 0) {
+    ERROR("SDP parsing failed!\n");
+    return false;
+  }
+  
+  if (saved_origin.get() == NULL) {
+    return false;
+  }
+  
+  sdp.origin.sessId = saved_origin.get()->sessId;
+  sdp.origin.sessV = ++(saved_origin.get()->sessV);
+  sdp.origin.user = saved_origin.get()->user;
+  
+  string contents;
+  sdp.print(contents);
+  replaced_body.parse(body.getCTStr(), (const unsigned char*) contents.c_str(), contents.length());
+  return true;
+}
+
+void AmB2BSession::saveOrigin(const AmMimeBody& body)
+{
+  AmSdp sdp;
+  if ((sdp.parse((const char *)body.getPayload())) != 0) {
+      ERROR("SDP parsing failed!\n");
+      return;
+  }
+  saved_origin.reset(new SdpOrigin(sdp.origin));
+}
+
 int AmB2BSession::filterBody(AmMimeBody& body, AmSdp& filter_sdp,
 			     bool is_a2b) {
   if (body.empty())
@@ -1217,8 +1277,17 @@ void AmB2BCallerSession::connectCallee(const string& remote_party,
 
 int AmB2BCallerSession::reinviteCaller(const AmSipReply& callee_reply)
 {
+  const AmMimeBody* body = &callee_reply.body;
+  AmMimeBody r_body;
+  if (saved_origin.get() != NULL) {
+    replaceOrigin(*body, r_body);
+    body = &r_body;
+  } else {
+    saveOrigin(*body);
+  }
+
   return dlg.sendRequest(SIP_METH_INVITE,
-			 &callee_reply.body,
+			 body,
 			 "" /* hdrs */, SIP_FLAGS_VERBATIM);
 }
 
@@ -1341,6 +1410,15 @@ void AmB2BCalleeSession::onB2BEvent(B2BEvent* ev)
       }
     }
 
+    AmMimeBody r2_body;
+    if (saved_origin.get() != NULL) {
+      if (replaceOrigin(*body, r2_body)) {
+	body = &r2_body;
+      }
+    } else if (!body->empty()) {
+      saveOrigin(*body);
+    }
+
     int res = dlg.sendRequest(SIP_METH_INVITE, body,
 			co_ev->hdrs, SIP_FLAGS_VERBATIM);
     if (res < 0) {
diff --git a/core/AmB2BSession.h b/core/AmB2BSession.h
index c45bff3..555a4f5 100644
--- a/core/AmB2BSession.h
+++ b/core/AmB2BSession.h
@@ -138,6 +138,11 @@ class AmB2BSession: public AmSession
    */
   TransMap relayed_req;
 
+  /* SDP originator line which was first sent
+   * in local SDP
+   */
+  auto_ptr<SdpOrigin> saved_origin;
+
   /** Requests received for relaying */
   std::map<int,AmSipRequest> recvd_req;
 
@@ -154,7 +159,10 @@ class AmB2BSession: public AmSession
   virtual void saveSessionDescription(const AmMimeBody& body);
   /** @return whether session description (SDP) has changed */
   virtual bool updateSessionDescription(const AmMimeBody& body);
-
+  /** save origin line from SDP body to saved_origin **/
+  void saveOrigin(const AmMimeBody& body);
+  /** replace origin line in given body with saved origin line (at least session id and user name) */
+  bool replaceOrigin(const AmMimeBody& body, AmMimeBody& replaced_body);
   /** reset relation with other leg */
   virtual void clear_other();
 

["signature.asc" (application/pgp-signature)]

_______________________________________________
Semsdev mailing list
Semsdev@lists.iptel.org
http://lists.iptel.org/mailman/listinfo/semsdev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic