Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to loosen message parsing to allow AVPs with empty/invalid payloads while defaulting to strict parsing #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Yoone
Copy link
Contributor

@Yoone Yoone commented Nov 20, 2020

I am working with equipments that can occasionally send slightly invalid messages, containing empty AVPs (the length is valid, but the "data" is empty).

This change aims to address this issue by adding an optional parameter in dictionaries to set whether the parsing of incoming messages should be strict or not (it is strict by default).

TODO

Example usage

dictionary, err := dict.NewParserFromLibrary(
    library.Base,
    library.CreditControl,
    library.TgppRoRf,
)
if err != nil {
    panic(err)
}
dictionary.Strict = false // Does not return an error when one or more incoming AVPs are invalid or empty

// declare stateMachine

if err := diam.ListenAndServeNetwork("tcp", "127.0.0.1", stateMachine, dictionary); err != nil {
    panic(err)
}

How to get the parsing error?

When Parser.Strict is set to false, the parsing error is accessible like so:

func myHandler(conn diam.Conn, msg *diam.Message) {
    if msg.DecodeErr != nil {
        // some custom logic, like logging the error
    }
}

Example error (shows the AVP stack, down the actual error, and it contains all the invalid AVPs, not just the first one):

Failed to decode one or more AVPs: {Service-Information(873): Grouped{SMS-Information(2000): Grouped{Recipient-SCCP-Address(2010): Not enough data to make an Address from byte[0] = []}}}

…id payloads while defaulting to strict parsing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant