mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-13 02:56:24 +05:00
Add pathIdx for diameter in case of group items with the same path
This commit is contained in:
committed by
Dan Christian Bogos
parent
3f12b8470c
commit
d7f736d25f
@@ -21,6 +21,7 @@ package agents
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
@@ -151,6 +152,7 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) {
|
||||
}
|
||||
a := m.Answer(diam.Success)
|
||||
// write reply into message
|
||||
pathIdx := make(map[string]int) // group items for same path
|
||||
for _, val := range rply.Values() {
|
||||
nmItms, isNMItems := val.([]*config.NMItem)
|
||||
if !isNMItems {
|
||||
@@ -162,24 +164,33 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) {
|
||||
}
|
||||
// find out the first itm which is not an attribute
|
||||
var itm *config.NMItem
|
||||
var itmStr string
|
||||
for _, cfgItm := range nmItms {
|
||||
if cfgItm.Config == nil || cfgItm.Config.AttributeID == "" {
|
||||
itm = cfgItm
|
||||
break
|
||||
itmStr, err = utils.IfaceAsString(cfgItm.Data)
|
||||
if err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> error: %s processing reply item: %s for message: %s",
|
||||
utils.DiameterAgent, err.Error(), utils.ToJSON(cfgItm), m))
|
||||
writeOnConn(c, m.Answer(diam.UnableToComply))
|
||||
return
|
||||
}
|
||||
// uniquePath is path contatenated with data (must be something unique)
|
||||
uniquePath := utils.ConcatenatedKey(strings.Join(cfgItm.Path, "."), itmStr)
|
||||
if _, has := pathIdx[uniquePath]; !has {
|
||||
pathIdx[uniquePath] += 1
|
||||
itm = cfgItm
|
||||
break
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if itm == nil {
|
||||
continue // all attributes, not writable to diameter packet
|
||||
}
|
||||
itmStr, err := utils.IfaceAsString(itm.Data)
|
||||
if err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> error: %s processing reply item: %s for message: %s",
|
||||
utils.DiameterAgent, err.Error(), utils.ToJSON(itm), m))
|
||||
writeOnConn(c, m.Answer(diam.UnableToComply))
|
||||
return
|
||||
}
|
||||
|
||||
var newBranch bool
|
||||
if itm.Config != nil && itm.Config.NewBranch {
|
||||
newBranch = true
|
||||
|
||||
Reference in New Issue
Block a user