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

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Thu Sep 29 14:23:33 2011 +0200

sbc: cc: adds call_timer call control module

---

 apps/sbc/call_control/call_timer/CallTimer.cpp     |  163 ++++++++++++++++++++
 apps/sbc/call_control/call_timer/CallTimer.h       |   52 ++++++
 apps/sbc/call_control/call_timer/Makefile          |    8 +
 .../call_control/call_timer/etc/cc_call_timer.conf |    4 +
 apps/sbc/etc/call_timer.sbcprofile.conf            |   31 +---
 5 files changed, 234 insertions(+), 24 deletions(-)

diff --git a/apps/sbc/call_control/call_timer/CallTimer.cpp 
b/apps/sbc/call_control/call_timer/CallTimer.cpp
new file mode 100644
index 0000000..e710c1e
--- /dev/null
+++ b/apps/sbc/call_control/call_timer/CallTimer.cpp
@@ -0,0 +1,163 @@
+/*
+ * 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 "CallTimer.h"
+
+#include "ampi/SBCCallControlAPI.h"
+#include "AmSipHeaders.h"
+
+#include <string.h>
+
+class CallTimerFactory : public AmDynInvokeFactory
+{
+public:
+    CallTimerFactory(const string& name)
+       : AmDynInvokeFactory(name) {}
+
+    AmDynInvoke* getInstance(){
+       return CallTimer::instance();
+    }
+
+    int onLoad(){
+      if (CallTimer::instance()->onLoad())
+       return -1;
+
+      DBG("call timer call control loaded.\n");
+
+      return 0;
+    }
+};
+
+EXPORT_PLUGIN_CLASS_FACTORY(CallTimerFactory, MOD_NAME);
+
+CallTimer* CallTimer::_instance=0;
+
+CallTimer* CallTimer::instance()
+{
+    if(!_instance)
+       _instance = new CallTimer();
+    return _instance;
+}
+
+CallTimer::CallTimer()
+  : default_timer(-1)
+{
+}
+
+CallTimer::~CallTimer() { }
+
+int CallTimer::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;
+  }
+
+  if (cfg.hasParameter("default_timer")) {
+    if (!str2int(cfg.getParameter("default_timer"), default_timer)) {
+      ERROR("default_timer '%s' not understood\n", 
cfg.getParameter("default_timer").c_str());
+      return -1;
+    }
+  }
+
+  DBG("default call timer set to '%i'\n", default_timer);
+
+  return 0;
+}
+
+void CallTimer::invoke(const string& method, const AmArg& args, AmArg& ret)
+{
+  DBG("CallTimer: %s(%s)\n", method.c_str(), AmArg::print(args).c_str());
+
+    if(method == "start"){
+
+      // 
INFO("--------------------------------------------------------------\n");
+      // INFO("Got call control start ltag '%s' start_ts %i.%i\n",
+      //          args.get(0).asCStr(), args[2][0].asInt(), 
args[2][1].asInt());
+      // INFO("---- dumping CC values ----\n");
+      // for (AmArg::ValueStruct::const_iterator it =
+      //            args.get(CC_API_PARAMS_CFGVALUES).begin();
+      //               it != args.get(CC_API_PARAMS_CFGVALUES).end(); it++) {
+      //       INFO("    CDR value '%s' = '%s'\n", it->first.c_str(), 
it->second.asCStr());
+      // }
+      // 
INFO("--------------------------------------------------------------\n");
+
+      // ltag, call profile, timestamps, [[key: val], ...], timer_id
+      args.assertArrayFmt("soaui");
+
+      start(args[CC_API_PARAMS_CFGVALUES],
+           args[CC_API_PARAMS_TIMERID].asInt(),  ret);
+
+    } else if(method == "connect"){
+      // unused
+    } else if(method == "end"){
+      // unused
+    } else if(method == "_list"){
+      ret.push("start");
+      ret.push("connect");
+      ret.push("end");
+    }
+    else
+       throw AmDynInvoke::NotImplemented(method);
+}
+
+void CallTimer::start(const AmArg& values, int timer_id, AmArg& res) {
+
+  int timer = default_timer;
+
+  if (values.hasMember("timer")) {
+    if (isArgCStr(values["timer"])) {
+      if (strlen(values["timer"].asCStr()))
+       str2int(values["timer"].asCStr(), timer);
+    } else if (isArgInt(values["timer"])) {
+      timer = values["timer"].asInt();
+    }
+  }
+  DBG("got timer value '%i'\n", timer);
+
+  if (timer<0) {
+    ERROR("configuration error: timer missing for call timer call control!\n");
+    res.push(AmArg());
+    AmArg& res_cmd = res.back();
+    res_cmd[SBC_CC_ACTION] = SBC_CC_REFUSE_ACTION;
+    res_cmd[SBC_CC_REFUSE_CODE] = 500;
+    res_cmd[SBC_CC_REFUSE_REASON] = SIP_REPLY_SERVER_INTERNAL_ERROR;
+    return;
+  }
+  res.push(AmArg());
+  AmArg& res_cmd = res.back();
+
+  // Set Timer:
+  DBG("setting timer ID %i, timeout %i\n", timer_id, timer);
+  res_cmd[SBC_CC_ACTION] = SBC_CC_SET_CALL_TIMER_ACTION;
+  res_cmd[SBC_CC_TIMER_TIMEOUT] = timer;
+}
diff --git a/apps/sbc/call_control/call_timer/CallTimer.h 
b/apps/sbc/call_control/call_timer/CallTimer.h
new file mode 100644
index 0000000..86febaa
--- /dev/null
+++ b/apps/sbc/call_control/call_timer/CallTimer.h
@@ -0,0 +1,52 @@
+/*
+ * 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
+ */
+
+#ifndef _CC_TEMPLATE_H
+#define _CC_TEMPLATE_H
+
+#include "AmApi.h"
+
+#include "SBCCallProfile.h"
+
+/**
+ * sample call control module
+ */
+class CallTimer : public AmDynInvoke
+{
+  static CallTimer* _instance;
+
+  int default_timer;
+
+  void start(const AmArg& values, int timer_id, AmArg& res);
+
+ public:
+  CallTimer();
+  ~CallTimer();
+  static CallTimer* instance();
+  void invoke(const string& method, const AmArg& args, AmArg& ret);
+  int onLoad();
+};
+
+#endif 
diff --git a/apps/sbc/call_control/call_timer/Makefile 
b/apps/sbc/call_control/call_timer/Makefile
new file mode 100644
index 0000000..5462517
--- /dev/null
+++ b/apps/sbc/call_control/call_timer/Makefile
@@ -0,0 +1,8 @@
+plug_in_name = cc_call_timer
+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/call_timer/etc/cc_call_timer.conf 
b/apps/sbc/call_control/call_timer/etc/cc_call_timer.conf
new file mode 100644
index 0000000..e6bb249
--- /dev/null
+++ b/apps/sbc/call_control/call_timer/etc/cc_call_timer.conf
@@ -0,0 +1,4 @@
+#the value of default_timer is used if no 'timer' 
+#is configured in the SBC profile, or the value is empty
+#
+#default_timer=60
\ No newline at end of file
diff --git a/apps/sbc/etc/call_timer.sbcprofile.conf 
b/apps/sbc/etc/call_timer.sbcprofile.conf
index ba6e63a..72b4a21 100644
--- a/apps/sbc/etc/call_timer.sbcprofile.conf
+++ b/apps/sbc/etc/call_timer.sbcprofile.conf
@@ -29,11 +29,15 @@
 #message_list=
 
 ## call timer
-enable_call_timer=yes
+call_control=call_timer
+
+# module cc_call_timer
+call_timer_module=cc_call_timer
 # maximum call time in seconds.
 # take the timer value from "t" parameter of P-App-Param,
 # e.g. P-App-Param: t=120
-call_timer=$P(t)
+call_timer_timer=$P(t)
+
 #
 # Kamailio/sip-router script: 
 #  remove_hf("P-App-Param");
@@ -41,25 +45,4 @@ call_timer=$P(t)
 #  t_relay_to_udp("10.0.0.3","5070");
 #
 #For a static value, set it like this
-#call_timer=120
-
-## prepaid
-#enable_prepaid=yes
-#prepaid_accmodule=cc_acc
-#prepaid_uuid=$H(P-Caller-Uuid)
-#prepaid_acc_dest=$H(P-Acc-Dest)
-
-## authentication:
-#enable_auth=yes
-#auth_user=$P(u)
-#auth_pwd=$P(p)
-
-## session timer:
-#enable_session_timer=yes
-# if session_expires is not configured here,
-# the values from sbc.conf are used, or the
-# default values
-#session_expires=120
-#minimum_timer=90
-#session_refresh_method=UPDATE_FALLBACK_INVITE
-#accept_501_reply=yes
+#call_timer=120
\ No newline at end of file

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

Reply via email to