mirror of
https://github.com/renorris/openfsd
synced 2026-03-22 14:35:36 +08:00
refactor query type validation, support SIMDATA type
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user