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

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Mon Feb  6 20:34:09 2012 +0100

sbc: ctl cc module, to control sbc through headers

---

 apps/sbc/call_control/ctl/CCCtl.cpp         |  171 +++++++++++++++++++++++++++
 apps/sbc/call_control/ctl/CCCtl.h           |   52 ++++++++
 apps/sbc/call_control/ctl/Makefile          |    8 ++
 apps/sbc/call_control/ctl/Readme.cc_ctl.txt |   44 +++++++
 4 files changed, 275 insertions(+), 0 deletions(-)

diff --git a/apps/sbc/call_control/ctl/CCCtl.cpp 
b/apps/sbc/call_control/ctl/CCCtl.cpp
new file mode 100644
index 0000000..f8a2002
--- /dev/null
+++ b/apps/sbc/call_control/ctl/CCCtl.cpp
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2011 Stefan Sayer
+ *
+ * This file is part of SEMS, a free SIP media server.
+ *
+ * SEMS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * For a license to use the SEMS software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * SEMS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "AmPlugIn.h"
+#include "log.h"
+#include "AmArg.h"
+#include "SBC.h"
+
+#include "CCCtl.h"
+
+#include "ampi/SBCCallControlAPI.h"
+
+#include <string.h>
+
+class CCCtlFactory : public AmDynInvokeFactory
+{
+public:
+    CCCtlFactory(const string& name)
+       : AmDynInvokeFactory(name) {}
+
+    AmDynInvoke* getInstance(){
+       return CCCtl::instance();
+    }
+
+    int onLoad(){
+      if (CCCtl::instance()->onLoad())
+       return -1;
+
+      DBG("ctl call control loaded.\n");
+
+      return 0;
+    }
+};
+
+EXPORT_PLUGIN_CLASS_FACTORY(CCCtlFactory, "ctl");
+
+CCCtl* CCCtl::_instance=0;
+
+CCCtl* CCCtl::instance()
+{
+    if(!_instance)
+       _instance = new CCCtl();
+    return _instance;
+}
+
+CCCtl::CCCtl()
+{
+}
+
+CCCtl::~CCCtl() { }
+
+int CCCtl::onLoad() {
+  AmConfigReader cfg;
+
+  // if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) {
+  //   INFO(MOD_NAME "configuration  file (%s) not found, "
+  //    "assuming default configuration is fine\n",
+  //    (AmConfig::ModConfigPath + string(MOD_NAME ".conf")).c_str());
+  //   return 0;
+  // }
+
+  // syslog_prefix = cfg.hasParameter("cdr_prefix") ? 
+  //   cfg.getParameter("cdr_prefix") : syslog_prefix;
+
+  return 0;
+}
+
+void CCCtl::invoke(const string& method, const AmArg& args, AmArg& ret)
+{
+  DBG("CCCtl: %s(%s)\n", method.c_str(), AmArg::print(args).c_str());
+
+  if(method == "start"){
+    SBCCallProfile* call_profile =
+      
dynamic_cast<SBCCallProfile*>(args[CC_API_PARAMS_CALL_PROFILE].asObject());
+
+    start(args[CC_API_PARAMS_CC_NAMESPACE].asCStr(),
+         args[CC_API_PARAMS_LTAG].asCStr(),
+         call_profile,
+         args[CC_API_PARAMS_TIMESTAMPS][CC_API_TS_START_SEC].asInt(),
+         args[CC_API_PARAMS_TIMESTAMPS][CC_API_TS_START_USEC].asInt(),
+         args[CC_API_PARAMS_CFGVALUES],
+         args[CC_API_PARAMS_TIMERID].asInt(),  ret);
+
+  } else if(method == "connect"){
+    // dummy
+  } else if(method == "end"){
+    // dummy
+  } else if(method == "_list"){
+    ret.push("start");
+    ret.push("connect");
+    ret.push("end");
+  }
+  else
+    throw AmDynInvoke::NotImplemented(method);
+}
+
+void CCCtl::start(const string& cc_name, const string& ltag,
+                      SBCCallProfile* call_profile,
+                      int start_ts_sec, int start_ts_usec,
+                      const AmArg& values, int timer_id, AmArg& res) {
+  if (!call_profile) {
+    ERROR("internal - call profile not found\n");
+    return;
+  }
+
+#define SET_TO_CALL_PROFILE(cfgparam, member)          \
+  if (values.hasMember(cfgparam)) {                    \
+    DBG("setting '%s' to '%s'\n", cfgparam, values[cfgparam].asCStr());        
\
+    call_profile->member = values[cfgparam].asCStr();  \
+  }
+
+#define ADD_TO_CALL_PROFILE(cfgparam, member)          \
+  if (values.hasMember(cfgparam)) {                    \
+    DBG("adding '%s' to '%s'\n", values[cfgparam].asCStr(), cfgparam); \
+    call_profile->member += values[cfgparam].asCStr(); \
+  }
+
+#define ENABLE_IN_CALL_PROFILE(cfgparam, member)       \
+  if (values.hasMember(cfgparam)) {                    \
+    call_profile->member =                             \
+      string(values[cfgparam].asCStr()) == "yes";      \
+    DBG("%sabling '%s'\n", call_profile->member?"en":"dis", \
+       values[cfgparam].asCStr());                    \
+  }
+
+  SET_TO_CALL_PROFILE("RURI", ruri);
+  SET_TO_CALL_PROFILE("From", from);
+  SET_TO_CALL_PROFILE("To", to);
+  SET_TO_CALL_PROFILE("Contact", contact);
+  SET_TO_CALL_PROFILE("Call-ID", callid);
+  SET_TO_CALL_PROFILE("outbound_proxy", outbound_proxy);
+  ENABLE_IN_CALL_PROFILE("force_outbound_proxy", force_outbound_proxy);
+
+  SET_TO_CALL_PROFILE("next_hop_ip", next_hop_ip);
+  SET_TO_CALL_PROFILE("next_hop_port", next_hop_port);
+
+  SET_TO_CALL_PROFILE("sst_enabled", sst_enabled);
+  SET_TO_CALL_PROFILE("sst_aleg_enabled", sst_aleg_enabled);
+
+  assertEndCRLF(call_profile->append_headers);
+  ADD_TO_CALL_PROFILE("append_headers", append_headers);
+  assertEndCRLF(call_profile->append_headers);
+
+  ENABLE_IN_CALL_PROFILE("rtprelay_enabled", rtprelay_enabled);
+  SET_TO_CALL_PROFILE("rtprelay_interface", rtprelay_interface);
+  SET_TO_CALL_PROFILE("aleg_rtprelay_interface", aleg_rtprelay_interface);
+
+  SET_TO_CALL_PROFILE("outbound_interface", outbound_interface);
+}
diff --git a/apps/sbc/call_control/ctl/CCCtl.h 
b/apps/sbc/call_control/ctl/CCCtl.h
new file mode 100644
index 0000000..2019dbd
--- /dev/null
+++ b/apps/sbc/call_control/ctl/CCCtl.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 Stefan Sayer
+ *
+ * This file is part of SEMS, a free SIP media server.
+ *
+ * SEMS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * For a license to use the SEMS software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * SEMS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _CC_CTL_H
+#define _CC_CTL_H
+
+#include "AmApi.h"
+
+#include "SBCCallProfile.h"
+
+/**
+ * ctl call control module - control profile by headers
+ */
+class CCCtl : public AmDynInvoke
+{
+  static CCCtl* _instance;
+
+  void start(const string& cc_name, const string& ltag, SBCCallProfile* 
call_profile,
+            int start_ts_sec, int start_ts_usec, const AmArg& values,
+            int timer_id, AmArg& res);
+
+ public:
+  CCCtl();
+  ~CCCtl();
+  static CCCtl* instance();
+  void invoke(const string& method, const AmArg& args, AmArg& ret);
+  int onLoad();
+};
+
+#endif 
diff --git a/apps/sbc/call_control/ctl/Makefile 
b/apps/sbc/call_control/ctl/Makefile
new file mode 100644
index 0000000..462bcbb
--- /dev/null
+++ b/apps/sbc/call_control/ctl/Makefile
@@ -0,0 +1,8 @@
+plug_in_name = cc_ctl
+sbc_app_path = ../..
+
+module_ldflags =
+module_cflags  = -DMOD_NAME=\"$(plug_in_name)\"  -I$(sbc_app_path)
+
+COREPATH =../../../../core
+include $(COREPATH)/plug-in/Makefile.app_module
diff --git a/apps/sbc/call_control/ctl/Readme.cc_ctl.txt 
b/apps/sbc/call_control/ctl/Readme.cc_ctl.txt
new file mode 100644
index 0000000..7171f37
--- /dev/null
+++ b/apps/sbc/call_control/ctl/Readme.cc_ctl.txt
@@ -0,0 +1,44 @@
+CCCtl - control SBC through headers
+
+This call control module exports SBC profile options to be controlled
+completely through headers. The module cn be instantiated several times.
+
+Example:
+ hdr_ctl.sbcprofile.conf:
+  call_control=$H(P-Call-Control)
+
+ Invite incoming:
+  INVITE sip:[email protected] SIP/2.0
+  To: <sip:[email protected]>
+  From: "" <sip:[email protected]>;tag=64015874f26373e6
+  ...
+  P-Call-Control: ctl;RURI=sip:[email protected]
+  P-Call-Control: ctl;rtprelay_enabled=yes
+  P-Call-Control: ctl;append_headers=P-My-Caller: $fU
+
+ Invite outgoing: 
+  INVITE sip:[email protected]
+  To: <sip:[email protected]>
+  From: "" <sip:[email protected]>;tag=64015874f26373e6
+  ...
+  P-My-Caller: stefan
+  ...
+
+Exported parameters:
+    RURI
+    From
+    To
+    Contact
+    Call-ID
+    outbound_proxy
+    force_outbound_proxy  
+    next_hop_ip
+    next_hop_port
+    sst_enabled  ("yes" or "no")
+    sst_aleg_enabled  ("yes" or "no")
+    append_headers  (incremental)
+    rtprelay_enabled ("yes" or "no")
+    rtprelay_interface
+    aleg_rtprelay_interface
+    outbound_interface
+

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

Reply via email to