/* 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 */ package config import ( "time" "github.com/cgrates/cgrates/utils" ) // SIPAgentCfg the config for the SIPAgent type SIPAgentCfg struct { Enabled bool Listen string ListenNet string // udp or tcp SessionSConns []string Timezone string RetransmissionTimer time.Duration // timeout replies if not reaching back RequestProcessors []*RequestProcessor } func (sa *SIPAgentCfg) loadFromJSONCfg(jsnCfg *SIPAgentJsonCfg, sep string) (err error) { if jsnCfg == nil { return nil } if jsnCfg.Enabled != nil { sa.Enabled = *jsnCfg.Enabled } if jsnCfg.Listen_net != nil { sa.ListenNet = *jsnCfg.Listen_net } if jsnCfg.Listen != nil { sa.Listen = *jsnCfg.Listen } if jsnCfg.Timezone != nil { sa.Timezone = *jsnCfg.Timezone } if jsnCfg.Sessions_conns != nil { sa.SessionSConns = make([]string, len(*jsnCfg.Sessions_conns)) for idx, connID := range *jsnCfg.Sessions_conns { // if we have the connection internal we change the name so we can have internal rpc for each subsystem sa.SessionSConns[idx] = connID if connID == utils.MetaInternal { sa.SessionSConns[idx] = utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS) } } } if jsnCfg.Retransmission_timer != nil { if sa.RetransmissionTimer, err = utils.ParseDurationWithNanosecs(*jsnCfg.Retransmission_timer); err != nil { return err } } if jsnCfg.Request_processors != nil { for _, reqProcJsn := range *jsnCfg.Request_processors { rp := new(RequestProcessor) var haveID bool for _, rpSet := range sa.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, sep); err != nil { return } if !haveID { sa.RequestProcessors = append(sa.RequestProcessors, rp) } } } return } // AsMapInterface returns the config as a map[string]any func (sa *SIPAgentCfg) AsMapInterface(separator string) (initialMP map[string]any) { initialMP = map[string]any{ utils.EnabledCfg: sa.Enabled, utils.ListenCfg: sa.Listen, utils.ListenNetCfg: sa.ListenNet, utils.TimezoneCfg: sa.Timezone, utils.RetransmissionTimerCfg: sa.RetransmissionTimer, } requestProcessors := make([]map[string]any, len(sa.RequestProcessors)) for i, item := range sa.RequestProcessors { requestProcessors[i] = item.AsMapInterface(separator) } initialMP[utils.RequestProcessorsCfg] = requestProcessors if sa.SessionSConns != nil { sessionSConns := make([]string, len(sa.SessionSConns)) for i, item := range sa.SessionSConns { sessionSConns[i] = item if item == utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS) { sessionSConns[i] = utils.MetaInternal } } initialMP[utils.SessionSConnsCfg] = sessionSConns } return } // Clone returns a deep copy of SIPAgentCfg func (sa SIPAgentCfg) Clone() (cln *SIPAgentCfg) { cln = &SIPAgentCfg{ Enabled: sa.Enabled, Listen: sa.Listen, ListenNet: sa.ListenNet, Timezone: sa.Timezone, RetransmissionTimer: sa.RetransmissionTimer, } if sa.SessionSConns != nil { cln.SessionSConns = make([]string, len(sa.SessionSConns)) copy(cln.SessionSConns, sa.SessionSConns) } if sa.RequestProcessors != nil { cln.RequestProcessors = make([]*RequestProcessor, len(sa.RequestProcessors)) for i, rp := range sa.RequestProcessors { cln.RequestProcessors[i] = rp.Clone() } } return }