Module: sems
Branch: master
Commit: 3f8c2942adb9a0c81fd94bc29cae03f7ea75c981
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=3f8c2942adb9a0c81fd94bc29cae03f7ea75c981

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Wed Nov  3 18:44:17 2010 +0100

b2b mode SDPFilter: filter relayed message body

---

 core/AmB2BSession.cpp |   61 ++++++++++++++++++++++++++++++++++++++++++++++--
 core/AmB2BSession.h   |   18 +++++++++++++-
 core/AmSipHeaders.h   |    1 +
 3 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/core/AmB2BSession.cpp b/core/AmB2BSession.cpp
index 13112ac..029a4be 100644
--- a/core/AmB2BSession.cpp
+++ b/core/AmB2BSession.cpp
@@ -37,7 +37,8 @@
 //
 
 AmB2BSession::AmB2BSession()
-  : sip_relay_only(true)
+  : sip_relay_only(true),
+    b2b_mode(B2BMode_Transparent)
 {
 }
 
@@ -58,6 +59,10 @@ void AmB2BSession::set_sip_relay_only(bool r) {
   sip_relay_only = r; 
 }
 
+AmB2BSession::B2BMode AmB2BSession::getB2BMode() const {
+  return b2b_mode;
+}
+
 void AmB2BSession::clear_other()
 {
 #if __GNUC__ < 3
@@ -185,7 +190,18 @@ void AmB2BSession::onSipRequest(const AmSipRequest& req)
     recvd_req.insert(std::make_pair(req.cseq,req));
   }
 
-  relayEvent(new B2BSipRequestEvent(req,fwd));
+  B2BSipRequestEvent* r_ev = new B2BSipRequestEvent(req,fwd);
+  
+  // filter relayed INVITE/UPDATE body
+  if (fwd && b2b_mode != B2BMode_Transparent &&
+      (req.method == SIP_METH_INVITE || req.method == SIP_METH_UPDATE ||
+       req.method == SIP_METH_ACK)) {
+    DBG("filtering body for request '%s' (c/t '%s')\n",
+       req.method.c_str(), req.content_type.c_str());
+    filterBody(r_ev->req.content_type, r_ev->req.body, a_leg);
+  }
+
+  relayEvent(r_ev);
 }
 
 void AmB2BSession::onSipReply(const AmSipReply& reply,
@@ -203,6 +219,12 @@ void AmB2BSession::onSipReply(const AmSipReply& reply,
 
     AmSipReply n_reply = reply;
     n_reply.cseq = t->second.cseq;
+
+    // filter relayed INVITE/UPDATE body
+    if (b2b_mode != B2BMode_Transparent &&
+       (trans_method == SIP_METH_INVITE || trans_method == SIP_METH_UPDATE)) {
+      filterBody(n_reply.content_type, n_reply.body, a_leg);
+    }
     
     relayEvent(new B2BSipReplyEvent(n_reply, true, t->second.method));
 
@@ -410,6 +432,30 @@ void AmB2BSession::relaySip(const AmSipRequest& orig, 
const AmSipReply& reply)
 
 }
 
+int AmB2BSession::filterBody(string& content_type, string& body, bool is_a2b) {
+  if (body.empty())
+    return 0;
+
+  if (content_type == SIP_APPLICATION_SDP) {
+    AmSdp f_sdp;
+    f_sdp.setBody(body.c_str());
+    int res = f_sdp.parse();
+    if (0 != res) {
+      DBG("SDP parsing failed!\n");
+      return res;
+    }
+    filterBody(f_sdp, is_a2b);
+    f_sdp.print(body);
+  }
+
+  return 0;
+}
+
+int AmB2BSession::filterBody(AmSdp& sdp, bool is_a2b) {
+  // default: transparent
+  return 0;
+}
+
 // 
 // AmB2BCallerSession methods
 //
@@ -418,6 +464,7 @@ AmB2BCallerSession::AmB2BCallerSession()
   : AmB2BSession(),
     callee_status(None), sip_relay_early_media_sdp(false)
 {
+  a_leg = true;
 }
 
 AmB2BCallerSession::~AmB2BCallerSession()
@@ -550,6 +597,10 @@ void AmB2BCallerSession::connectCallee(const string& 
remote_party,
 
   B2BConnectEvent* ev = new B2BConnectEvent(remote_party,remote_uri);
 
+  if (b2b_mode == B2BMode_SDPFilter) {
+    filterBody(invite_req.content_type, invite_req.body, true);
+  }
+
   ev->content_type = invite_req.content_type;
   ev->body         = invite_req.body;
   ev->hdrs         = invite_req.hdrs;
@@ -606,14 +657,18 @@ AmB2BCalleeSession* AmB2BCallerSession::newCalleeSession()
   return new AmB2BCalleeSession(this);
 }
 
-AmB2BCalleeSession::AmB2BCalleeSession(const string& other_local_tag)
+/* AmB2BCalleeSession::AmB2BCalleeSession(const string& other_local_tag)
   : AmB2BSession(other_local_tag)
 {
+  a_leg = false;
 }
+*/
 
 AmB2BCalleeSession::AmB2BCalleeSession(const AmB2BCallerSession* caller)
   : AmB2BSession(caller->getLocalTag())
 {
+  a_leg = false;
+  b2b_mode = caller->getB2BMode();
 }
 
 AmB2BCalleeSession::~AmB2BCalleeSession() {
diff --git a/core/AmB2BSession.h b/core/AmB2BSession.h
index 0ebf089..ffde475 100644
--- a/core/AmB2BSession.h
+++ b/core/AmB2BSession.h
@@ -124,6 +124,12 @@ struct B2BConnectEvent: public B2BEvent
  */
 class AmB2BSession: public AmSession
 {
+ public:
+  enum B2BMode {
+    B2BMode_Transparent,  // relay message bodies
+    B2BMode_SDPFilter     // reconstruct SDP
+  };
+
  protected:
   /** local tag of the other leg */
   string other_id;
@@ -134,6 +140,9 @@ class AmB2BSession: public AmSession
    */
   bool sip_relay_only;
 
+  B2BMode b2b_mode;
+  bool a_leg;
+
   /** 
    * Requests which have been relayed 
    * from the other leg and sent as SIP
@@ -204,6 +213,12 @@ class AmB2BSession: public AmSession
    */
   virtual bool onOtherReply(const AmSipReply& reply);
 
+  /** filter body ( b2b_mode == SDPFilter */
+  virtual int filterBody(string& content_type, string& body, bool is_a2b);
+
+  /** filter SDP body ( b2b_mode == SDPFilter */
+  virtual int filterBody(AmSdp& sdp, bool is_a2b);
+
   AmB2BSession();
   AmB2BSession(const string& other_local_tag);
 
@@ -211,6 +226,7 @@ class AmB2BSession: public AmSession
 
  public:
   void set_sip_relay_only(bool r);
+  B2BMode getB2BMode() const;
 };
 
 class AmB2BCalleeSession;
@@ -274,7 +290,7 @@ class AmB2BCallerSession: public AmB2BSession
 class AmB2BCalleeSession: public AmB2BSession
 {
  public:
-  AmB2BCalleeSession(const string& other_local_tag);
+  /*  AmB2BCalleeSession(const string& other_local_tag); */
   AmB2BCalleeSession(const AmB2BCallerSession* caller);
 
   virtual ~AmB2BCalleeSession();
diff --git a/core/AmSipHeaders.h b/core/AmSipHeaders.h
index c13020d..c33eb05 100644
--- a/core/AmSipHeaders.h
+++ b/core/AmSipHeaders.h
@@ -8,6 +8,7 @@
 #define SIP_METH_PRACK          "PRACK"
 #define SIP_METH_UPDATE         "UPDATE"
 #define SIP_METH_BYE            "BYE"
+#define SIP_METH_ACK            "ACK"
 
 #define SIP_HDR_FROM            "From"
 #define SIP_HDR_TO              "To"

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to