From 531b58e2ef08161cd12b868079c372f7d092cedf Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 25 Mar 2015 19:21:41 +0100 Subject: [PATCH] SMFS - Adding sip_req_user as destination due to special cases like transfer, couple of tests more for session manager connections --- config/cfg_data.json | 8 ++++++ config/config_json_test.go | 20 ++++++++++++++ config/smconfig_test.go | 55 ++++++++++++++++++++++++++++++++++++++ sessionmanager/fsevent.go | 9 ++++--- 4 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 config/smconfig_test.go diff --git a/config/cfg_data.json b/config/cfg_data.json index 67d83ee7f..52aaa040b 100644 --- a/config/cfg_data.json +++ b/config/cfg_data.json @@ -42,4 +42,12 @@ }, }, +"sm_freeswitch": { + "enabled": true, // starts SessionManager service: + "connections":[ // instantiate connections to multiple FreeSWITCH servers + {"server": "1.2.3.4:8021", "password": "ClueCon", "reconnects": 5}, + {"server": "2.3.4.5:8021", "password": "ClueCon", "reconnects": 5}, + ], +}, + } \ No newline at end of file diff --git a/config/config_json_test.go b/config/config_json_test.go index 28f4f72dd..b9cd16808 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -503,4 +503,24 @@ func TestNewCgrJsonCfgFromFile(t *testing.T) { } else if cfg != nil { t.Error("Received: ", cfg) } + eCfgSmFs := &SmFsJsonCfg{ + Enabled: utils.BoolPointer(true), + Connections: &[]*FsConnJsonCfg{ + &FsConnJsonCfg{ + Server: utils.StringPointer("1.2.3.4:8021"), + Password: utils.StringPointer("ClueCon"), + Reconnects: utils.IntPointer(5), + }, + &FsConnJsonCfg{ + Server: utils.StringPointer("2.3.4.5:8021"), + Password: utils.StringPointer("ClueCon"), + Reconnects: utils.IntPointer(5), + }, + }, + } + if smFsCfg, err := cgrJsonCfg.SmFsJsonCfg(); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(eCfgSmFs, smFsCfg) { + t.Error("Received: ", smFsCfg) + } } diff --git a/config/smconfig_test.go b/config/smconfig_test.go new file mode 100644 index 000000000..0f11e6504 --- /dev/null +++ b/config/smconfig_test.go @@ -0,0 +1,55 @@ +/* +Real-time Charging System for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program 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 3 of the License, or +(at your option) any later version. + +This program 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, see +*/ + +package config + +import ( + "github.com/cgrates/cgrates/utils" + "reflect" + "testing" +) + +func TesSmFsConfigLoadFromJsonCfg(t *testing.T) { + smFsJsnCfg := &SmFsJsonCfg{ + Enabled: utils.BoolPointer(true), + Connections: &[]*FsConnJsonCfg{ + &FsConnJsonCfg{ + Server: utils.StringPointer("1.2.3.4:8021"), + Password: utils.StringPointer("ClueCon"), + Reconnects: utils.IntPointer(5), + }, + &FsConnJsonCfg{ + Server: utils.StringPointer("2.3.4.5:8021"), + Password: utils.StringPointer("ClueCon"), + Reconnects: utils.IntPointer(5), + }, + }, + } + eSmFsConfig := &SmFsConfig{Enabled: true, + Connections: []*FsConnConfig{ + &FsConnConfig{Server: "1.2.3.4:8021", Password: "ClueCon", Reconnects: 5}, + &FsConnConfig{Server: "1.2.3.4:8021", Password: "ClueCon", Reconnects: 5}, + }, + } + smFsCfg := new(SmFsConfig) + if err := smFsCfg.loadFromJsonCfg(smFsJsnCfg); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(eSmFsConfig, smFsCfg) { + t.Error("Received: ", smFsCfg) + } +} diff --git a/sessionmanager/fsevent.go b/sessionmanager/fsevent.go index 47afd52f8..3b6c656d3 100644 --- a/sessionmanager/fsevent.go +++ b/sessionmanager/fsevent.go @@ -46,6 +46,7 @@ const ( UUID = "Unique-ID" // -Unique ID for this call leg CSTMID = "variable_cgr_tenant" CALL_DEST_NR = "Caller-Destination-Number" + SIP_REQ_USER = "variable_sip_req_user" PARK_TIME = "Caller-Profile-Created-Time" SETUP_TIME = "Caller-Channel-Created-Time" ANSWER_TIME = "Caller-Channel-Answered-Time" @@ -115,9 +116,9 @@ func (fsev FSEvent) GetDestination(fieldName string) string { if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value return fieldName[len(utils.STATIC_VALUE_PREFIX):] } else if fieldName == utils.META_DEFAULT { - return utils.FirstNonEmpty(fsev[DESTINATION], fsev[CALL_DEST_NR]) + return utils.FirstNonEmpty(fsev[DESTINATION], fsev[CALL_DEST_NR], fsev[SIP_REQ_USER]) } - return utils.FirstNonEmpty(fsev[fieldName], fsev[DESTINATION], fsev[CALL_DEST_NR]) + return utils.FirstNonEmpty(fsev[fieldName], fsev[DESTINATION], fsev[CALL_DEST_NR], fsev[SIP_REQ_USER]) } // Original dialed destination number, useful in case of unpark @@ -125,9 +126,9 @@ func (fsev FSEvent) GetCallDestNr(fieldName string) string { if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value return fieldName[len(utils.STATIC_VALUE_PREFIX):] } else if fieldName == utils.META_DEFAULT { - return fsev[CALL_DEST_NR] + return utils.FirstNonEmpty(fsev[CALL_DEST_NR], fsev[SIP_REQ_USER]) } - return utils.FirstNonEmpty(fsev[fieldName], fsev[CALL_DEST_NR]) + return utils.FirstNonEmpty(fsev[fieldName], fsev[CALL_DEST_NR], fsev[SIP_REQ_USER]) } func (fsev FSEvent) GetCategory(fieldName string) string { if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value