-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to load additional diameter dictionary definition (#2)
* add dict_generator cli * add dict.load(dictionary)
- Loading branch information
Showing
6 changed files
with
918 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
"github.com/fiorix/go-diameter/v4/diam/dict" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func main() { | ||
var dictionary string | ||
var output string | ||
|
||
flag.StringVar(&dictionary, "dictionary", "dictionary.xml", "Dictionary") | ||
flag.StringVar(&output, "output", "const.js", "Output file") | ||
flag.Parse() | ||
|
||
file, err := os.Open(dictionary) | ||
if err != nil { | ||
log.Fatalf("Error opening dictioanry: %s\n", err) | ||
} | ||
defer file.Close() | ||
|
||
parser := dict.Default | ||
parser.Load(file) | ||
if err != nil { | ||
log.Fatalf("Error parsing dictioanry: %s\n", err) | ||
} | ||
|
||
w, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666) | ||
if err != nil { | ||
log.Fatalf("Error opening file: %s\n", err) | ||
} | ||
defer w.Close() | ||
|
||
PrintFlags(w) | ||
PrintAvpCode(w, parser) | ||
PrintVendorId(w, parser) | ||
} | ||
|
||
func PrintFlags(w io.Writer) { | ||
fmt.Fprintf(w, "export const flags = {\n") | ||
fmt.Fprintf(w, " Vbit: 0x80,\n") | ||
fmt.Fprintf(w, " Mbit: 0x40,\n") | ||
fmt.Fprintf(w, " Pbit: 0x20,\n") | ||
fmt.Fprintf(w, "}\n") | ||
fmt.Fprintf(w, "\n") | ||
} | ||
|
||
func PrintAvpCode(w io.Writer, parser *dict.Parser) { | ||
fmt.Fprintf(w, "export const avpCode = {\n") | ||
for _, app := range parser.Apps() { | ||
fmt.Fprintf(w, " // %s\n", app.Name) | ||
for _, avp := range app.AVP { | ||
name := strings.ReplaceAll(avp.Name, "-", "") | ||
fmt.Fprintf(w, " %s: %d,\n", name, avp.Code) | ||
} | ||
} | ||
fmt.Fprintf(w, "}\n") | ||
fmt.Fprintf(w, "\n") | ||
|
||
} | ||
|
||
func PrintVendorId(w io.Writer, parser *dict.Parser) { | ||
vendorIds := make(map[uint32]struct{}) | ||
exists := struct{}{} | ||
|
||
fmt.Fprintf(w, "export const vendorId = {\n") | ||
for _, app := range parser.Apps() { | ||
for _, vendor := range app.Vendor { | ||
// Remove duplicate vendorId | ||
_, found := vendorIds[vendor.ID] | ||
if found { | ||
continue | ||
} | ||
vendorIds[vendor.ID] = exists | ||
|
||
fmt.Fprintf(w, " %s: %d,\n", vendor.Name, vendor.ID) | ||
} | ||
} | ||
fmt.Fprintf(w, "}\n") | ||
fmt.Fprintf(w, "\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<diameter> | ||
<application id="4" type="auth" name="Extra"> | ||
<vendor name="Matrixxsoftware" id="35838"/> | ||
<avp name="Event-Name-Code" code="13001" vendor-id="35838"> | ||
<data type="UTF8String"/> | ||
</avp> | ||
</application> | ||
</diameter> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.