Author: sayer
Date: 2008-12-02 23:39:38 +0100 (Tue, 02 Dec 2008)
New Revision: 1156

Added:
   trunk/apps/examples/b2b_connect/etc/
   trunk/apps/examples/b2b_connect/etc/b2b_connect.conf
Modified:
   trunk/apps/examples/b2b_connect/b2b_connect.cpp
   trunk/apps/examples/b2b_connect/b2b_connect.h
Log:
optionally relay headers from first INVITE into callee leg


Modified: trunk/apps/examples/b2b_connect/b2b_connect.cpp
===================================================================
--- trunk/apps/examples/b2b_connect/b2b_connect.cpp     2008-12-02 21:42:39 UTC 
(rev 1155)
+++ trunk/apps/examples/b2b_connect/b2b_connect.cpp     2008-12-02 22:39:38 UTC 
(rev 1156)
@@ -30,9 +30,11 @@
 #include "AmAudio.h"
 #include "AmPlugIn.h"
 #include "AmMediaProcessor.h"
-//#include "AmConfigReader.h"
+#include "AmConfigReader.h"
 #include "AmSessionContainer.h"
 
+bool b2b_connectFactory::TransparentHeaders = true; // default
+
 EXPORT_SESSION_FACTORY(b2b_connectFactory,MOD_NAME);
 
 b2b_connectFactory::b2b_connectFactory(const string& _app_name)
@@ -44,10 +46,16 @@
 
 int b2b_connectFactory::onLoad()
 {
-//   AmConfigReader cfg;
-//   if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf")))
-//     return -1;
+  AmConfigReader cfg;
+  if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) {
+    INFO("configuration file '%s' not found. using defaults.\n",
+        (AmConfig::ModConfigPath + string(MOD_NAME ".conf")).c_str());
+    return 0;
+  }
 
+  if (cfg.getParameter("transparent_headers")=="false")
+    TransparentHeaders = false;
+  
 //   user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer");
 //   if(!user_timer_fact) {
 //     ERROR("could not load user_timer from session_timer plug-in\n");
@@ -66,13 +74,18 @@
 //     throw AmSession::Exception(500,"could not get a user timer reference");
 //   }
 
+  string app_param = getHeader(req.hdrs, PARAM_HDR);
+
+  if (!app_param.length()) {
+    throw  AmSession::Exception(500, "b2b_connect: parameters not found");
+  }
+
   return new b2b_connectDialog(); //user_timer);
 }
 
 
 b2b_connectDialog::b2b_connectDialog() // AmDynInvoke* user_timer)
-: m_state(BB_Init),
-  //m_user_timer(user_timer),
+: //m_user_timer(user_timer),
   AmB2ABCallerSession()
 
 {
@@ -88,17 +101,11 @@
   // TODO: do reinvites get here? if so, don't set a timer then
   // -> yes, they do.
 
-  // TODO: errors thrown as exception don't seem to trigger a reply?
-  // -> only in SessionFactory::onInvite they do. todo: move the logic to 
-  //    session factory 
 
-  //setReceiving(false);
-  //AmMediaProcessor::instance()->removeSession(this);
-
   string app_param = getHeader(req.hdrs, PARAM_HDR);
 
   if (!app_param.length()) {
-    AmSession::Exception(500, "b2b_connect: parameters not found");
+    throw AmSession::Exception(500, "b2b_connect: parameters not found");
   }
 
   domain = get_header_keyvalue(app_param,"d");
@@ -108,41 +115,23 @@
   from = "sip:"+user+"@"+domain;
   to = "sip:"+req.user+"@"+domain;
 
-//   
DBG("-----------------------------------------------------------------\n");
-//   DBG("domain = %s, user = %s, pwd = %s, from = %s, to = %s;",  
-//       domain.c_str(), user.c_str(), password.c_str(), from.c_str(), 
to.c_str());
-//   
DBG("-----------------------------------------------------------------\n");
-
-  m_state = BB_Dialing;
-
   if(dlg.reply(req, 100, "Connecting") != 0) {
     throw AmSession::Exception(500,"Failed to reply 100");
   }
 
   invite_req = req;
-  size_t pos1, pos2, hdr_start;
-
-  if (findHeader(invite_req.hdrs,PARAM_HDR, pos1, pos2, 
-                hdr_start)) {
-    while (invite_req.hdrs[pos2]=='\r' ||invite_req.hdrs[pos2]=='\n') 
-      pos2++;
-
-    hdr_start -= 11; //"P-App-Param"
-    invite_req.hdrs.erase(hdr_start, pos2-hdr_start);
+  if (b2b_connectFactory::TransparentHeaders) {
+    removeHeader(invite_req.hdrs, PARAM_HDR);
+    removeHeader(invite_req.hdrs, "P-App-Name");
+    removeHeader(invite_req.hdrs, "User-Agent");
+    removeHeader(invite_req.hdrs, "Max-Forwards");
   }
 
-  if (findHeader(invite_req.hdrs,"P-App-Name", pos1, pos2, 
-                hdr_start)) {
-    while (invite_req.hdrs[pos2]=='\r' ||invite_req.hdrs[pos2]=='\n') 
-      pos2++;
-    hdr_start -= 10; //"P-App-Name"
-    invite_req.hdrs.erase(hdr_start, pos2-hdr_start);
-  }
-
   dlg.updateStatus(req);
   recvd_req.insert(std::make_pair(req.cseq,req));
   
-  connectCallee("<" + to + ">", to, from, from);
+  connectCallee("<" + to + ">", to, from, from, 
+               b2b_connectFactory::TransparentHeaders ? invite_req.hdrs : "");
 }
 
 void b2b_connectDialog::onSessionStart(const AmSipRequest& req)
@@ -217,12 +206,8 @@
   
 }
 
-
 void b2b_connectDialog::onBye(const AmSipRequest& req)
 {
-  if (m_state == BB_Connected) {
-//     stopAccounting();
-  }
   terminateOtherLeg();
   setStopped();
 }

Modified: trunk/apps/examples/b2b_connect/b2b_connect.h
===================================================================
--- trunk/apps/examples/b2b_connect/b2b_connect.h       2008-12-02 21:42:39 UTC 
(rev 1155)
+++ trunk/apps/examples/b2b_connect/b2b_connect.h       2008-12-02 22:39:38 UTC 
(rev 1156)
@@ -44,24 +44,19 @@
   
   int onLoad();
   AmSession* onInvite(const AmSipRequest& req);
+
+  static bool TransparentHeaders; // default
+
 };
 
 class b2b_connectDialog : public AmB2ABCallerSession
 {
-  enum {
-    BB_Init = 0,
-    BB_Dialing,
-    BB_Connected,
-    BB_Teardown
-  } CallerState;
-
-  int m_state;
-
   string domain;
   string user;
   string password;
   string from;
   string to;
+
   AmSipRequest invite_req;
   
 /*   AmDynInvoke* m_user_timer; */

Added: trunk/apps/examples/b2b_connect/etc/b2b_connect.conf
===================================================================
--- trunk/apps/examples/b2b_connect/etc/b2b_connect.conf        2008-12-02 
21:42:39 UTC (rev 1155)
+++ trunk/apps/examples/b2b_connect/etc/b2b_connect.conf        2008-12-02 
22:39:38 UTC (rev 1156)
@@ -0,0 +1,7 @@
+#
+# transparent_headers = [true|false]
+#
+# relay headers from initial INVITE into callee leg?
+#
+# default:
+#  transparent_headers = true

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

Reply via email to