dict

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package dict provides a Diameter dictionary parser.

Index

Constants

View Source
const (
	// UndefinedVendorID specifies a non existing vendorID
	UndefinedVendorID = 4294967295
)

Variables

View Source
var ErrApplicationUnsupported = errors.New("application unsupported")

ErrApplicationUnsupported indicates that the application requested does not exist in the dictionary Parser object.

Functions

This section is empty.

Types

type AVP

type AVP struct {
	Name       string `xml:"name,attr"`
	Code       uint32 `xml:"code,attr"`
	Must       string `xml:"must,attr"`
	May        string `xml:"may,attr"`
	MustNot    string `xml:"must-not,attr"`
	MayEncrypt string `xml:"may-encrypt,attr"`
	VendorID   uint32 `xml:"vendor-id,attr"`
	Data       Data   `xml:"data"`
	App        *App   `xml:"none"` // Link back to diameter application
}

AVP represents a dictionary AVP that is loaded from XML.

func MakeUnknownAVP

func MakeUnknownAVP(appid, code, vendorID uint32) *AVP

type App

type App struct {
	ID      uint32     `xml:"id,attr"`   // Application Id
	Type    string     `xml:"type,attr"` // Application type
	Name    string     `xml:"name,attr"` // Application name
	Vendor  []*Vendor  `xml:"vendor"`    // Support for multiple vendors
	Command []*Command `xml:"command"`   // Diameter commands
	AVP     []*AVP     `xml:"avp"`       // Each application support multiple AVPs
}

App defines a diameter application in XML and its multiple AVPs.

type Command

type Command struct {
	Code    uint32      `xml:"code,attr"`
	Name    string      `xml:"name,attr"`
	Short   string      `xml:"short,attr"`
	Request CommandRule `xml:"request"`
	Answer  CommandRule `xml:"answer"`
}

Command defines a diameter command (CE, CC, etc)

func (*Command) String

func (cmd *Command) String() string

type CommandRule

type CommandRule struct {
	Rule []*Rule `xml:"rule"`
}

CommandRule contains rules for a given command.

type Data

type Data struct {
	Type     datatype.TypeID `xml:"-"`
	TypeName string          `xml:"type,attr"`
	Enum     []*Enum         `xml:"item"` // In case of Enumerated AVP data
	Rule     []*Rule         `xml:"rule"` // In case of Grouped AVPs
}

Data of an AVP can be EnumItem or a Parser of multiple AVPs.

type Enum

type Enum struct {
	// rfc6733 (section 4.3.1):
	// The Enumerated format is derived from the Integer32 Basic AVP Format.
	Code int32  `xml:"code,attr"`
	Name string `xml:"name,attr"`
}

Enum contains the code and name of Enumerated items.

type File

type File struct {
	XMLName xml.Name `xml:"diameter"`
	App     []*App   `xml:"application"` // Support for multiple applications
}

File is the dictionary root element of a XML file. See diam_base.xml.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser is the root element for dictionaries and supports multiple XML dictionary files loaded together. Diameter applications use dictionaries to parse messages received from peers as well as to encode crafted messages before sending them over the wire.

Parser can load multiple XML dictionary files, which in turn support multiple applications that are composed by multiple AVPs.

The Parser element has an index to make pre-loaded AVPs searcheable per App.

var Default *Parser

Default is a Parser object with pre-loaded Base Protocol and Credit Control dictionaries.

func NewParser

func NewParser(filename ...string) (*Parser, error)

NewParser allocates a new Parser optionally loading dictionary XML files.

func (*Parser) App

func (p *Parser) App(code uint32, typ ...string) (*App, error)

App returns a dictionary application for the given application code if exists. App must never be called concurrently with LoadFile or Load.

func (*Parser) Apps

func (p *Parser) Apps() []*App

Apps return a list of all applications loaded in the Parser object. Apps must never be called concurrently with LoadFile or Load.

func (*Parser) Enum

func (p *Parser) Enum(appid, code uint32, n int32) (*Enum, error)

Enum is a helper function that returns a pre-loaded Enum item for the given AVP appid, code and n. (n is the enum code in the dictionary)

Enum must never be called concurrently with LoadFile or Load.

func (*Parser) FindAVP

func (p *Parser) FindAVP(appid uint32, code interface{}) (*AVP, error)

FindAVP is a helper function that returns a pre-loaded AVP from the Parser. If the AVP code is not found for the given appid it tries with appid=0 before returning an error. Code can be either the AVP code (int, uint32) or name (string).

FindAVP must never be called concurrently with LoadFile or Load.

func (*Parser) FindAVPWithVendor

func (p *Parser) FindAVPWithVendor(appid uint32, code interface{}, vendorID uint32) (*AVP, error)

FindAVPWithVendor is a helper function that returns a pre-loaded AVP from the Parser, considering vendorID as filter. For no vendorID filter, use UndefinedVendorID constant If the AVP code is not found for the given appid it tries with appid=0 before returning an error. Code can be either the AVP code (int, uint32) or name (string).

FindAVPWithVendor must never be called concurrently with LoadFile or Load.

func (*Parser) FindCommand

func (p *Parser) FindCommand(appid, code uint32) (*Command, error)

FindCommand returns a pre-loaded Command from the Parser.

FindCommand must never be called concurrently with LoadFile or Load.

func (*Parser) Load

func (p *Parser) Load(r io.Reader) error

Load loads a dictionary from byte array. May be used multiple times.

func (*Parser) LoadFile

func (p *Parser) LoadFile(filename string) error

LoadFile loads a dictionary XML file. May be used multiple times.

func (*Parser) Rule

func (p *Parser) Rule(appid, code uint32, n string) (*Rule, error)

Rule is a helper function that returns a pre-loaded Rule item for the given AVP code and name.

Rule must never be called concurrently with LoadFile or Load.

func (*Parser) ScanAVP

func (p *Parser) ScanAVP(code interface{}) (*AVP, error)

ScanAVP is a helper function that returns a pre-loaded AVP from the Dict. It's similar to FindAPI except that it scans the list of available AVPs instead of looking into one specific appid.

ScanAVP is 20x or more slower than FindAVP. Use with care. Code can be either the AVP code (uint32) or name (string).

ScanAVP must never be called concurrently with LoadFile or Load.

func (*Parser) String

func (p *Parser) String() string

String returns the Parser represented in a human readable form.

type Rule

type Rule struct {
	AVP      string `xml:"avp,attr"` // AVP Name
	Required bool   `xml:"required,attr"`
	Min      int    `xml:"min,attr"`
	Max      int    `xml:"max,attr"`
}

Rule defines the usage rules of an AVP.

type Vendor

type Vendor struct {
	ID   uint32 `xml:"id,attr"`
	Name string `xml:"name,attr"`
}

Vendor defines diameter vendors in XML, that can be used to translate the VendorId AVP of incoming messages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL