mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
198 lines
6.2 KiB
Go
198 lines
6.2 KiB
Go
/*
|
|
Real-time Online/Offline Charging System (OCS) 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"
|
|
"github.com/cgrates/rpcclient"
|
|
)
|
|
|
|
// DiameterAgentCfg the config section that describes the Diameter Agent
|
|
type DiameterAgentCfg struct {
|
|
Enabled bool // enables the diameter agent: <true|false>
|
|
ListenNet string // sctp or tcp
|
|
Listen string // address where to listen for diameter requests <x.y.z.y:1234>
|
|
DictionariesPath string
|
|
CeApplications []string
|
|
SessionSConns []string
|
|
OriginHost string
|
|
OriginRealm string
|
|
VendorID int
|
|
ProductName string
|
|
SyncedConnReqs bool
|
|
ASRTemplate string
|
|
RARTemplate string
|
|
ForcedDisconnect string
|
|
RequestProcessors []*RequestProcessor
|
|
}
|
|
|
|
func (da *DiameterAgentCfg) loadFromJSONCfg(jsnCfg *DiameterAgentJsonCfg, separator string) (err error) {
|
|
if jsnCfg == nil {
|
|
return nil
|
|
}
|
|
if jsnCfg.Enabled != nil {
|
|
da.Enabled = *jsnCfg.Enabled
|
|
}
|
|
if jsnCfg.Listen != nil {
|
|
da.Listen = *jsnCfg.Listen
|
|
}
|
|
if jsnCfg.Listen_net != nil {
|
|
da.ListenNet = *jsnCfg.Listen_net
|
|
}
|
|
if jsnCfg.Dictionaries_path != nil {
|
|
da.DictionariesPath = *jsnCfg.Dictionaries_path
|
|
}
|
|
if jsnCfg.Ce_applications != nil {
|
|
da.CeApplications = make([]string, len(*jsnCfg.Ce_applications))
|
|
copy(da.CeApplications, *jsnCfg.Ce_applications)
|
|
}
|
|
if jsnCfg.Sessions_conns != nil {
|
|
da.SessionSConns = make([]string, len(*jsnCfg.Sessions_conns))
|
|
for idx, attrConn := range *jsnCfg.Sessions_conns {
|
|
// if we have the connection internal we change the name so we can have internal rpc for each subsystem
|
|
da.SessionSConns[idx] = attrConn
|
|
if attrConn == utils.MetaInternal ||
|
|
attrConn == rpcclient.BiRPCInternal {
|
|
da.SessionSConns[idx] = utils.ConcatenatedKey(attrConn, utils.MetaSessionS)
|
|
}
|
|
}
|
|
}
|
|
if jsnCfg.Origin_host != nil {
|
|
da.OriginHost = *jsnCfg.Origin_host
|
|
}
|
|
if jsnCfg.Origin_realm != nil {
|
|
da.OriginRealm = *jsnCfg.Origin_realm
|
|
}
|
|
if jsnCfg.Vendor_id != nil {
|
|
da.VendorID = *jsnCfg.Vendor_id
|
|
}
|
|
if jsnCfg.Product_name != nil {
|
|
da.ProductName = *jsnCfg.Product_name
|
|
}
|
|
if jsnCfg.Synced_conn_requests != nil {
|
|
da.SyncedConnReqs = *jsnCfg.Synced_conn_requests
|
|
}
|
|
if jsnCfg.Asr_template != nil {
|
|
da.ASRTemplate = *jsnCfg.Asr_template
|
|
}
|
|
if jsnCfg.Rar_template != nil {
|
|
da.RARTemplate = *jsnCfg.Rar_template
|
|
}
|
|
if jsnCfg.Forced_disconnect != nil {
|
|
da.ForcedDisconnect = *jsnCfg.Forced_disconnect
|
|
}
|
|
if jsnCfg.Request_processors != nil {
|
|
for _, reqProcJsn := range *jsnCfg.Request_processors {
|
|
rp := new(RequestProcessor)
|
|
var haveID bool
|
|
for _, rpSet := range da.RequestProcessors {
|
|
if reqProcJsn.ID != nil && rpSet.ID == *reqProcJsn.ID {
|
|
rp = rpSet // Will load data into the one set
|
|
haveID = true
|
|
break
|
|
}
|
|
}
|
|
if err = rp.loadFromJSONCfg(reqProcJsn, separator); err != nil {
|
|
return
|
|
}
|
|
if !haveID {
|
|
da.RequestProcessors = append(da.RequestProcessors, rp)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// AsMapInterface returns the config as a map[string]any
|
|
func (da *DiameterAgentCfg) AsMapInterface(separator string) (initialMP map[string]any) {
|
|
initialMP = map[string]any{
|
|
utils.EnabledCfg: da.Enabled,
|
|
utils.ListenNetCfg: da.ListenNet,
|
|
utils.ListenCfg: da.Listen,
|
|
utils.DictionariesPathCfg: da.DictionariesPath,
|
|
utils.OriginHostCfg: da.OriginHost,
|
|
utils.OriginRealmCfg: da.OriginRealm,
|
|
utils.VendorIDCfg: da.VendorID,
|
|
utils.ProductNameCfg: da.ProductName,
|
|
utils.SyncedConnReqsCfg: da.SyncedConnReqs,
|
|
utils.ASRTemplateCfg: da.ASRTemplate,
|
|
utils.RARTemplateCfg: da.RARTemplate,
|
|
utils.ForcedDisconnectCfg: da.ForcedDisconnect,
|
|
}
|
|
|
|
if da.CeApplications != nil {
|
|
apps := make([]string, len(da.CeApplications))
|
|
copy(apps, da.CeApplications)
|
|
initialMP[utils.CeApplicationsCfg] = apps
|
|
}
|
|
|
|
requestProcessors := make([]map[string]any, len(da.RequestProcessors))
|
|
for i, item := range da.RequestProcessors {
|
|
requestProcessors[i] = item.AsMapInterface(separator)
|
|
}
|
|
initialMP[utils.RequestProcessorsCfg] = requestProcessors
|
|
|
|
if da.SessionSConns != nil {
|
|
sessionSConns := make([]string, len(da.SessionSConns))
|
|
for i, item := range da.SessionSConns {
|
|
sessionSConns[i] = item
|
|
if item == utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS) {
|
|
sessionSConns[i] = utils.MetaInternal
|
|
} else if item == utils.ConcatenatedKey(rpcclient.BiRPCInternal, utils.MetaSessionS) {
|
|
sessionSConns[i] = rpcclient.BiRPCInternal
|
|
}
|
|
}
|
|
initialMP[utils.SessionSConnsCfg] = sessionSConns
|
|
}
|
|
return
|
|
}
|
|
|
|
// Clone returns a deep copy of DiameterAgentCfg
|
|
func (da DiameterAgentCfg) Clone() (cln *DiameterAgentCfg) {
|
|
cln = &DiameterAgentCfg{
|
|
Enabled: da.Enabled,
|
|
ListenNet: da.ListenNet,
|
|
Listen: da.Listen,
|
|
DictionariesPath: da.DictionariesPath,
|
|
OriginHost: da.OriginHost,
|
|
OriginRealm: da.OriginRealm,
|
|
VendorID: da.VendorID,
|
|
ProductName: da.ProductName,
|
|
SyncedConnReqs: da.SyncedConnReqs,
|
|
ASRTemplate: da.ASRTemplate,
|
|
RARTemplate: da.RARTemplate,
|
|
ForcedDisconnect: da.ForcedDisconnect,
|
|
}
|
|
if da.CeApplications != nil {
|
|
cln.CeApplications = make([]string, len(da.CeApplications))
|
|
copy(cln.CeApplications, da.CeApplications)
|
|
}
|
|
if da.SessionSConns != nil {
|
|
cln.SessionSConns = make([]string, len(da.SessionSConns))
|
|
copy(cln.SessionSConns, da.SessionSConns)
|
|
}
|
|
if da.RequestProcessors != nil {
|
|
cln.RequestProcessors = make([]*RequestProcessor, len(da.RequestProcessors))
|
|
for i, req := range da.RequestProcessors {
|
|
cln.RequestProcessors[i] = req.Clone()
|
|
}
|
|
}
|
|
return
|
|
}
|