/* 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 ( "strings" "github.com/cgrates/cgrates/utils" ) type SIPAgentCfg struct { Enabled bool Listen string ListenNet string // udp or tcp SessionSConns []string Timezone string RequestProcessors []*RequestProcessor } func (da *SIPAgentCfg) loadFromJsonCfg(jsnCfg *SIPAgentJsonCfg, sep string) (err error) { if jsnCfg == nil { return nil } if jsnCfg.Enabled != nil { da.Enabled = *jsnCfg.Enabled } if jsnCfg.Listen_net != nil { da.ListenNet = *jsnCfg.Listen_net } if jsnCfg.Listen != nil { da.Listen = *jsnCfg.Listen } if jsnCfg.Timezone != nil { da.Timezone = *jsnCfg.Timezone } if jsnCfg.Sessions_conns != nil { da.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 if connID == utils.MetaInternal { da.SessionSConns[idx] = utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS) } else { da.SessionSConns[idx] = connID } } } 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, sep); err != nil { return } if !haveID { da.RequestProcessors = append(da.RequestProcessors, rp) } } } return } func (da *SIPAgentCfg) AsMapInterface(separator string) map[string]interface{} { requestProcessors := make([]map[string]interface{}, len(da.RequestProcessors)) for i, item := range da.RequestProcessors { requestProcessors[i] = item.AsMapInterface(separator) } sessionSConns := make([]string, len(da.SessionSConns)) for i, item := range da.SessionSConns { buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS) if item == buf { sessionSConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaSessionS, utils.EmptyString) } else { sessionSConns[i] = item } } return map[string]interface{}{ utils.EnabledCfg: da.Enabled, utils.ListenCfg: da.Listen, utils.ListenNetCfg: da.ListenNet, utils.SessionSConnsCfg: sessionSConns, utils.TimezoneCfg: da.Timezone, utils.RequestProcessorsCfg: requestProcessors, } }