refactor query type validation, support SIMDATA type

This commit is contained in:
Reese Norris
2024-10-22 18:34:37 -07:00
parent 1857df46f0
commit 71a4b40001
2 changed files with 23 additions and 24 deletions

View File

@@ -2,9 +2,29 @@ package protocol
import (
"fmt"
"slices"
"strings"
)
var supportedClientQueryTypes = buildSupportedClientQueryTypes()
func buildSupportedClientQueryTypes() []string {
typesList := []string{
"ATC", "CAPS", "C?",
"RN", "SV", "ATIS",
"IP", "INF", "FP",
"IPC", "BY", "HI",
"HLP", "NOHLP", "WH",
"IT", "HT", "DR",
"FA", "TA", "BC",
"SC", "VT", "ACC",
"NEWINFO", "NEWATIS", "EST",
"GD", "SIMDATA"}
slices.Sort(typesList)
return typesList
}
type ClientQueryPDU struct {
From string `validate:"required,alphanum,max=16"`
To string `validate:"required,max=7"`
@@ -49,18 +69,7 @@ func (p *ClientQueryPDU) Parse(packet string) error {
return err
}
switch pdu.QueryType {
case "ATC", "CAPS", "C?",
"RN", "SV", "ATIS",
"IP", "INF", "FP",
"IPC", "BY", "HI",
"HLP", "NOHLP", "WH",
"IT", "HT", "DR",
"FA", "TA", "BC",
"SC", "VT", "ACC",
"NEWINFO", "NEWATIS", "EST",
"GD":
default:
if _, exists := slices.BinarySearch(supportedClientQueryTypes, pdu.QueryType); !exists {
return NewGenericFSDError(SyntaxError, fields[2], "invalid query type")
}

View File

@@ -2,6 +2,7 @@ package protocol
import (
"fmt"
"slices"
"strings"
)
@@ -50,18 +51,7 @@ func (p *ClientQueryResponsePDU) Parse(packet string) error {
return err
}
switch pdu.QueryType {
case "ATC", "CAPS", "C?",
"RN", "SV", "ATIS",
"IP", "INF", "FP",
"IPC", "BY", "HI",
"HLP", "NOHLP", "WH",
"IT", "HT", "DR",
"FA", "TA", "BC",
"SC", "VT", "ACC",
"NEWINFO", "NEWATIS", "EST",
"GD":
default:
if _, exists := slices.BinarySearch(supportedClientQueryTypes, pdu.QueryType); !exists {
return NewGenericFSDError(SyntaxError, fields[2], "invalid query type")
}