SMFS - Adding sip_req_user as destination due to special cases like transfer, couple of tests more for session manager connections

This commit is contained in:
DanB
2015-03-25 19:21:41 +01:00
parent 7480019833
commit 531b58e2ef
4 changed files with 88 additions and 4 deletions

View File

@@ -42,4 +42,12 @@
},
},
"sm_freeswitch": {
"enabled": true, // starts SessionManager service: <true|false>
"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},
],
},
}

View File

@@ -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)
}
}

55
config/smconfig_test.go Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>
*/
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)
}
}

View File

@@ -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