Include allowed string values in generated services.

This commit is contained in:
John Beisley 2023-03-09 18:23:18 +00:00
parent 1270e56d5f
commit e5bb4e5154
7 changed files with 251 additions and 72 deletions

View File

@ -23,7 +23,9 @@ import (
"github.com/huin/goupnp/v2alpha/description/typedesc" "github.com/huin/goupnp/v2alpha/description/typedesc"
"github.com/huin/goupnp/v2alpha/description/xmlsrvdesc" "github.com/huin/goupnp/v2alpha/description/xmlsrvdesc"
"github.com/huin/goupnp/v2alpha/soap" "github.com/huin/goupnp/v2alpha/soap"
"github.com/huin/goupnp/v2alpha/soap/types" "golang.org/x/exp/maps"
soaptypes "github.com/huin/goupnp/v2alpha/soap/types"
) )
var ( var (
@ -93,7 +95,7 @@ func run() error {
// Use default type map for now. Addtional types could be use instead or // Use default type map for now. Addtional types could be use instead or
// as well as necessary for extended types. // as well as necessary for extended types.
typeMap := types.TypeMap().Clone() typeMap := soaptypes.TypeMap().Clone()
typeMap[soapActionInterface] = typedesc.TypeDesc{ typeMap[soapActionInterface] = typedesc.TypeDesc{
GoType: reflect.TypeOf((*soap.Action)(nil)).Elem(), GoType: reflect.TypeOf((*soap.Action)(nil)).Elem(),
} }
@ -160,7 +162,8 @@ func processService(
return fmt.Errorf("transforming service description: %w", err) return fmt.Errorf("transforming service description: %w", err)
} }
imps, err := accumulateImports(sd, typeMap) imps := newImports()
types, err := accumulateTypes(sd, typeMap, imps)
if err != nil { if err != nil {
return err return err
} }
@ -169,6 +172,7 @@ func processService(
err = tmpl.ExecuteTemplate(buf, "service", tmplArgs{ err = tmpl.ExecuteTemplate(buf, "service", tmplArgs{
Manifest: srvManifest, Manifest: srvManifest,
Imps: imps, Imps: imps,
Types: types,
SCPD: sd, SCPD: sd,
}) })
if err != nil { if err != nil {
@ -221,14 +225,44 @@ type ServiceManifest struct {
type tmplArgs struct { type tmplArgs struct {
Manifest *ServiceManifest Manifest *ServiceManifest
Imps *imports Imps *imports
Types *types
SCPD *srvdesc.SCPD SCPD *srvdesc.SCPD
} }
type imports struct { type imports struct {
// Maps from a type name like "ui4" to the `alias.name` for the import.
TypeByName map[string]typeDesc
// Each required import line, ordered by path. // Each required import line, ordered by path.
ImportLines []importItem ImportLines []importItem
// aliasByPath maps from import path to its imported alias.
aliasByPath map[string]string
// nextAlias is the number for the next import alias.
nextAlias int
}
func newImports() *imports {
return &imports{
aliasByPath: make(map[string]string),
nextAlias: 1,
}
}
func (imps *imports) getAliasForPath(path string) string {
if alias, ok := imps.aliasByPath[path]; ok {
return alias
}
alias := fmt.Sprintf("pkg%d", imps.nextAlias)
imps.nextAlias++
imps.ImportLines = append(imps.ImportLines, importItem{
Alias: alias,
Path: path,
})
imps.aliasByPath[path] = alias
return alias
}
type types struct {
// Maps from a type name like "ui4" to the `alias.name` for the import.
TypeByName map[string]typeDesc
StringVarDefs []stringVarDef
} }
type typeDesc struct { type typeDesc struct {
@ -241,17 +275,41 @@ type typeDesc struct {
Name string Name string
} }
type stringVarDef struct {
Name string
AllowedValues []string
}
type importItem struct { type importItem struct {
Alias string Alias string
Path string Path string
} }
func accumulateImports(srvDesc *srvdesc.SCPD, typeMap typedesc.TypeMap) (*imports, error) { // accumulateTypes creates type information, and adds any required imports for
typeNames := make(map[string]bool) // them.
typeNames[soapActionInterface] = true func accumulateTypes(
srvDesc *srvdesc.SCPD,
typeMap typedesc.TypeMap,
imps *imports,
) (*types, error) {
typeNames := make(map[string]struct{})
typeNames[soapActionInterface] = struct{}{}
err := visitTypesSCPD(srvDesc, func(typeName string) { var stringVarDefs []stringVarDef
typeNames[typeName] = true sortedVarNames := maps.Keys(srvDesc.VariableByName)
sort.Strings(sortedVarNames)
for _, svName := range sortedVarNames {
sv := srvDesc.VariableByName[svName]
if sv.DataType == "string" && len(sv.AllowedValues) > 0 {
stringVarDefs = append(stringVarDefs, stringVarDef{
Name: svName,
AllowedValues: srvDesc.VariableByName[svName].AllowedValues,
})
}
}
err := visitTypesSCPD(srvDesc, func(sv *srvdesc.StateVariable) {
typeNames[sv.DataType] = struct{}{}
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -259,7 +317,7 @@ func accumulateImports(srvDesc *srvdesc.SCPD, typeMap typedesc.TypeMap) (*import
// Have sorted list of import package paths. Partly for aesthetics of generated code, but also // Have sorted list of import package paths. Partly for aesthetics of generated code, but also
// to have stable-generated aliases. // to have stable-generated aliases.
paths := make(map[string]bool) paths := make(map[string]struct{})
for typeName := range typeNames { for typeName := range typeNames {
t, ok := typeMap[typeName] t, ok := typeMap[typeName]
if !ok { if !ok {
@ -267,29 +325,17 @@ func accumulateImports(srvDesc *srvdesc.SCPD, typeMap typedesc.TypeMap) (*import
} }
pkgPath := t.GoType.PkgPath() pkgPath := t.GoType.PkgPath()
if pkgPath == "" { if pkgPath == "" {
// Builtin type, ignore. // Builtin type, no import needed.
continue continue
} }
paths[pkgPath] = true paths[pkgPath] = struct{}{}
}
sortedPaths := make([]string, 0, len(paths))
for path := range paths {
sortedPaths = append(sortedPaths, path)
} }
sortedPaths := maps.Keys(paths)
sort.Strings(sortedPaths) sort.Strings(sortedPaths)
// Generate import aliases. // Generate import aliases in deterministic order.
index := 1
aliasByPath := make(map[string]string, len(paths))
importLines := make([]importItem, 0, len(paths))
for _, path := range sortedPaths { for _, path := range sortedPaths {
alias := fmt.Sprintf("pkg%d", index) imps.getAliasForPath(path)
index++
importLines = append(importLines, importItem{
Alias: alias,
Path: path,
})
aliasByPath[path] = alias
} }
// Populate typeByName. // Populate typeByName.
@ -297,28 +343,27 @@ func accumulateImports(srvDesc *srvdesc.SCPD, typeMap typedesc.TypeMap) (*import
for typeName := range typeNames { for typeName := range typeNames {
goType := typeMap[typeName] goType := typeMap[typeName]
pkgPath := goType.GoType.PkgPath() pkgPath := goType.GoType.PkgPath()
alias := aliasByPath[pkgPath]
td := typeDesc{ td := typeDesc{
Name: goType.GoType.Name(), Name: goType.GoType.Name(),
} }
if alias == "" { if pkgPath == "" {
// Builtin type. // Builtin type.
td.AbsRef = td.Name td.AbsRef = td.Name
td.Ref = td.Name td.Ref = td.Name
} else { } else {
td.AbsRef = strconv.Quote(pkgPath) + "." + td.Name td.AbsRef = strconv.Quote(pkgPath) + "." + td.Name
td.Ref = alias + "." + td.Name td.Ref = imps.getAliasForPath(pkgPath) + "." + td.Name
} }
typeByName[typeName] = td typeByName[typeName] = td
} }
return &imports{ return &types{
TypeByName: typeByName, TypeByName: typeByName,
ImportLines: importLines, StringVarDefs: stringVarDefs,
}, nil }, nil
} }
type typeVisitor func(typeName string) type typeVisitor func(sv *srvdesc.StateVariable)
// visitTypesSCPD calls `visitor` with each data type name (e.g. "ui4") referenced // visitTypesSCPD calls `visitor` with each data type name (e.g. "ui4") referenced
// by action arguments.` // by action arguments.`
@ -337,14 +382,14 @@ func visitTypesAction(action *srvdesc.Action, visitor typeVisitor) error {
if err != nil { if err != nil {
return err return err
} }
visitor(sv.DataType) visitor(sv)
} }
for _, arg := range action.OutArgs { for _, arg := range action.OutArgs {
sv, err := arg.RelatedStateVariable() sv, err := arg.RelatedStateVariable()
if err != nil { if err != nil {
return err return err
} }
visitor(sv.DataType) visitor(sv)
} }
return nil return nil
} }

View File

@ -140,6 +140,8 @@ func (arg *Argument) RelatedStateVariable() (*StateVariable, error) {
type StateVariable struct { type StateVariable struct {
Name string Name string
DataType string DataType string
AllowedValues []string
} }
func stateVariableFromXML(xmlSV *xmlsrvdesc.StateVariable) (*StateVariable, error) { func stateVariableFromXML(xmlSV *xmlsrvdesc.StateVariable) (*StateVariable, error) {
@ -150,8 +152,13 @@ func stateVariableFromXML(xmlSV *xmlsrvdesc.StateVariable) (*StateVariable, erro
return nil, fmt.Errorf("%w: unsupported data type %q", return nil, fmt.Errorf("%w: unsupported data type %q",
ErrUnsupportedDescription, xmlSV.DataType.Type) ErrUnsupportedDescription, xmlSV.DataType.Type)
} }
if xmlSV.DataType.Name != "string" && len(xmlSV.AllowedValues) > 0 {
return nil, fmt.Errorf("%w: allowedValueList is currently unsupported for type %q",
ErrUnsupportedDescription, xmlSV.DataType.Name)
}
return &StateVariable{ return &StateVariable{
Name: xmlSV.Name, Name: xmlSV.Name,
DataType: xmlSV.DataType.Name, DataType: xmlSV.DataType.Name,
AllowedValues: xmlSV.AllowedValues,
}, nil }, nil
} }

View File

@ -2,6 +2,8 @@ module github.com/huin/goupnp/v2alpha
go 1.18 go 1.18
require github.com/google/go-cmp v0.5.7 require github.com/google/go-cmp v0.5.8
require github.com/BurntSushi/toml v1.1.0 require github.com/BurntSushi/toml v1.1.0
require golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect

View File

@ -2,5 +2,9 @@ github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/exp v0.0.0-20230307190834-24139beb5833 h1:SChBja7BCQewoTAU7IgvucQKMIXrEpFxNMs0spT3/5s=
golang.org/x/exp v0.0.0-20230307190834-24139beb5833/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -34,6 +34,7 @@ func (a *DeleteDNSServer) RefResponse() any { return &a.Response }
// DeleteDNSServerRequest contains the "in" args for the "DeleteDNSServer" action. // DeleteDNSServerRequest contains the "in" args for the "DeleteDNSServer" action.
type DeleteDNSServerRequest struct { type DeleteDNSServerRequest struct {
// NewDNSServers relates to state variable DNSServers.
NewDNSServers string NewDNSServers string
} }
@ -64,6 +65,7 @@ func (a *DeleteIPRouter) RefResponse() any { return &a.Response }
// DeleteIPRouterRequest contains the "in" args for the "DeleteIPRouter" action. // DeleteIPRouterRequest contains the "in" args for the "DeleteIPRouter" action.
type DeleteIPRouterRequest struct { type DeleteIPRouterRequest struct {
// NewIPRouters relates to state variable IPRouters.
NewIPRouters string NewIPRouters string
} }
@ -94,6 +96,7 @@ func (a *DeleteReservedAddress) RefResponse() any { return &a.Response }
// DeleteReservedAddressRequest contains the "in" args for the "DeleteReservedAddress" action. // DeleteReservedAddressRequest contains the "in" args for the "DeleteReservedAddress" action.
type DeleteReservedAddressRequest struct { type DeleteReservedAddressRequest struct {
// NewReservedAddresses relates to state variable ReservedAddresses.
NewReservedAddresses string NewReservedAddresses string
} }
@ -127,7 +130,9 @@ type GetAddressRangeRequest struct{}
// GetAddressRangeResponse contains the "out" args for the "GetAddressRange" action. // GetAddressRangeResponse contains the "out" args for the "GetAddressRange" action.
type GetAddressRangeResponse struct { type GetAddressRangeResponse struct {
// NewMinAddress relates to state variable MinAddress.
NewMinAddress string NewMinAddress string
// NewMaxAddress relates to state variable MaxAddress.
NewMaxAddress string NewMaxAddress string
} }
@ -158,6 +163,7 @@ type GetDHCPRelayRequest struct{}
// GetDHCPRelayResponse contains the "out" args for the "GetDHCPRelay" action. // GetDHCPRelayResponse contains the "out" args for the "GetDHCPRelay" action.
type GetDHCPRelayResponse struct { type GetDHCPRelayResponse struct {
// NewDHCPRelay relates to state variable DHCPRelay.
NewDHCPRelay pkg2.Boolean NewDHCPRelay pkg2.Boolean
} }
@ -188,6 +194,7 @@ type GetDHCPServerConfigurableRequest struct{}
// GetDHCPServerConfigurableResponse contains the "out" args for the "GetDHCPServerConfigurable" action. // GetDHCPServerConfigurableResponse contains the "out" args for the "GetDHCPServerConfigurable" action.
type GetDHCPServerConfigurableResponse struct { type GetDHCPServerConfigurableResponse struct {
// NewDHCPServerConfigurable relates to state variable DHCPServerConfigurable.
NewDHCPServerConfigurable pkg2.Boolean NewDHCPServerConfigurable pkg2.Boolean
} }
@ -218,6 +225,7 @@ type GetDNSServersRequest struct{}
// GetDNSServersResponse contains the "out" args for the "GetDNSServers" action. // GetDNSServersResponse contains the "out" args for the "GetDNSServers" action.
type GetDNSServersResponse struct { type GetDNSServersResponse struct {
// NewDNSServers relates to state variable DNSServers.
NewDNSServers string NewDNSServers string
} }
@ -248,6 +256,7 @@ type GetDomainNameRequest struct{}
// GetDomainNameResponse contains the "out" args for the "GetDomainName" action. // GetDomainNameResponse contains the "out" args for the "GetDomainName" action.
type GetDomainNameResponse struct { type GetDomainNameResponse struct {
// NewDomainName relates to state variable DomainName.
NewDomainName string NewDomainName string
} }
@ -278,6 +287,7 @@ type GetIPRoutersListRequest struct{}
// GetIPRoutersListResponse contains the "out" args for the "GetIPRoutersList" action. // GetIPRoutersListResponse contains the "out" args for the "GetIPRoutersList" action.
type GetIPRoutersListResponse struct { type GetIPRoutersListResponse struct {
// NewIPRouters relates to state variable IPRouters.
NewIPRouters string NewIPRouters string
} }
@ -308,6 +318,7 @@ type GetReservedAddressesRequest struct{}
// GetReservedAddressesResponse contains the "out" args for the "GetReservedAddresses" action. // GetReservedAddressesResponse contains the "out" args for the "GetReservedAddresses" action.
type GetReservedAddressesResponse struct { type GetReservedAddressesResponse struct {
// NewReservedAddresses relates to state variable ReservedAddresses.
NewReservedAddresses string NewReservedAddresses string
} }
@ -338,6 +349,7 @@ type GetSubnetMaskRequest struct{}
// GetSubnetMaskResponse contains the "out" args for the "GetSubnetMask" action. // GetSubnetMaskResponse contains the "out" args for the "GetSubnetMask" action.
type GetSubnetMaskResponse struct { type GetSubnetMaskResponse struct {
// NewSubnetMask relates to state variable SubnetMask.
NewSubnetMask string NewSubnetMask string
} }
@ -365,7 +377,9 @@ func (a *SetAddressRange) RefResponse() any { return &a.Response }
// SetAddressRangeRequest contains the "in" args for the "SetAddressRange" action. // SetAddressRangeRequest contains the "in" args for the "SetAddressRange" action.
type SetAddressRangeRequest struct { type SetAddressRangeRequest struct {
// NewMinAddress relates to state variable MinAddress.
NewMinAddress string NewMinAddress string
// NewMaxAddress relates to state variable MaxAddress.
NewMaxAddress string NewMaxAddress string
} }
@ -396,6 +410,7 @@ func (a *SetDHCPRelay) RefResponse() any { return &a.Response }
// SetDHCPRelayRequest contains the "in" args for the "SetDHCPRelay" action. // SetDHCPRelayRequest contains the "in" args for the "SetDHCPRelay" action.
type SetDHCPRelayRequest struct { type SetDHCPRelayRequest struct {
// NewDHCPRelay relates to state variable DHCPRelay.
NewDHCPRelay pkg2.Boolean NewDHCPRelay pkg2.Boolean
} }
@ -426,6 +441,7 @@ func (a *SetDHCPServerConfigurable) RefResponse() any { return &a.Response }
// SetDHCPServerConfigurableRequest contains the "in" args for the "SetDHCPServerConfigurable" action. // SetDHCPServerConfigurableRequest contains the "in" args for the "SetDHCPServerConfigurable" action.
type SetDHCPServerConfigurableRequest struct { type SetDHCPServerConfigurableRequest struct {
// NewDHCPServerConfigurable relates to state variable DHCPServerConfigurable.
NewDHCPServerConfigurable pkg2.Boolean NewDHCPServerConfigurable pkg2.Boolean
} }
@ -456,6 +472,7 @@ func (a *SetDNSServer) RefResponse() any { return &a.Response }
// SetDNSServerRequest contains the "in" args for the "SetDNSServer" action. // SetDNSServerRequest contains the "in" args for the "SetDNSServer" action.
type SetDNSServerRequest struct { type SetDNSServerRequest struct {
// NewDNSServers relates to state variable DNSServers.
NewDNSServers string NewDNSServers string
} }
@ -486,6 +503,7 @@ func (a *SetDomainName) RefResponse() any { return &a.Response }
// SetDomainNameRequest contains the "in" args for the "SetDomainName" action. // SetDomainNameRequest contains the "in" args for the "SetDomainName" action.
type SetDomainNameRequest struct { type SetDomainNameRequest struct {
// NewDomainName relates to state variable DomainName.
NewDomainName string NewDomainName string
} }
@ -516,6 +534,7 @@ func (a *SetIPRouter) RefResponse() any { return &a.Response }
// SetIPRouterRequest contains the "in" args for the "SetIPRouter" action. // SetIPRouterRequest contains the "in" args for the "SetIPRouter" action.
type SetIPRouterRequest struct { type SetIPRouterRequest struct {
// NewIPRouters relates to state variable IPRouters.
NewIPRouters string NewIPRouters string
} }
@ -546,6 +565,7 @@ func (a *SetReservedAddress) RefResponse() any { return &a.Response }
// SetReservedAddressRequest contains the "in" args for the "SetReservedAddress" action. // SetReservedAddressRequest contains the "in" args for the "SetReservedAddress" action.
type SetReservedAddressRequest struct { type SetReservedAddressRequest struct {
// NewReservedAddresses relates to state variable ReservedAddresses.
NewReservedAddresses string NewReservedAddresses string
} }
@ -576,6 +596,7 @@ func (a *SetSubnetMask) RefResponse() any { return &a.Response }
// SetSubnetMaskRequest contains the "in" args for the "SetSubnetMask" action. // SetSubnetMaskRequest contains the "in" args for the "SetSubnetMask" action.
type SetSubnetMaskRequest struct { type SetSubnetMaskRequest struct {
// NewSubnetMask relates to state variable SubnetMask.
NewSubnetMask string NewSubnetMask string
} }

View File

@ -8,6 +8,35 @@ import (
pkg2 "github.com/huin/goupnp/v2alpha/soap/types" pkg2 "github.com/huin/goupnp/v2alpha/soap/types"
) )
// Allowed values for state variable ConnectionStatus.
const (
ConnectionStatus_Unconfigured = "Unconfigured"
ConnectionStatus_Connected = "Connected"
ConnectionStatus_Disconnected = "Disconnected"
)
// Allowed values for state variable LastConnectionError.
const (
LastConnectionError_ERROR_NONE = "ERROR_NONE"
)
// Allowed values for state variable PortMappingProtocol.
const (
PortMappingProtocol_TCP = "TCP"
PortMappingProtocol_UDP = "UDP"
)
// Allowed values for state variable PossibleConnectionTypes.
const (
PossibleConnectionTypes_Unconfigured = "Unconfigured"
PossibleConnectionTypes_IP_Routed = "IP_Routed"
PossibleConnectionTypes_DHCP_Spoofed = "DHCP_Spoofed"
PossibleConnectionTypes_PPPoE_Bridged = "PPPoE_Bridged"
PossibleConnectionTypes_PPTP_Relay = "PPTP_Relay"
PossibleConnectionTypes_L2TP_Relay = "L2TP_Relay"
PossibleConnectionTypes_PPPoE_Relay = "PPPoE_Relay"
)
const ServiceType = "urn:schemas-upnp-org:service:WANPPPConnection:1" const ServiceType = "urn:schemas-upnp-org:service:WANPPPConnection:1"
// AddPortMapping provides request and response for the action. // AddPortMapping provides request and response for the action.
@ -34,14 +63,22 @@ func (a *AddPortMapping) RefResponse() any { return &a.Response }
// AddPortMappingRequest contains the "in" args for the "AddPortMapping" action. // AddPortMappingRequest contains the "in" args for the "AddPortMapping" action.
type AddPortMappingRequest struct { type AddPortMappingRequest struct {
NewRemoteHost string // NewRemoteHost relates to state variable RemoteHost.
NewExternalPort pkg2.UI2 NewRemoteHost string
NewProtocol string // NewExternalPort relates to state variable ExternalPort.
NewInternalPort pkg2.UI2 NewExternalPort pkg2.UI2
NewInternalClient string // NewProtocol relates to state variable PortMappingProtocol (2 standard allowed values).
NewEnabled pkg2.Boolean NewProtocol string
// NewInternalPort relates to state variable InternalPort.
NewInternalPort pkg2.UI2
// NewInternalClient relates to state variable InternalClient.
NewInternalClient string
// NewEnabled relates to state variable PortMappingEnabled.
NewEnabled pkg2.Boolean
// NewPortMappingDescription relates to state variable PortMappingDescription.
NewPortMappingDescription string NewPortMappingDescription string
NewLeaseDuration pkg2.UI4 // NewLeaseDuration relates to state variable PortMappingLeaseDuration.
NewLeaseDuration pkg2.UI4
} }
// AddPortMappingResponse contains the "out" args for the "AddPortMapping" action. // AddPortMappingResponse contains the "out" args for the "AddPortMapping" action.
@ -71,7 +108,9 @@ func (a *ConfigureConnection) RefResponse() any { return &a.Response }
// ConfigureConnectionRequest contains the "in" args for the "ConfigureConnection" action. // ConfigureConnectionRequest contains the "in" args for the "ConfigureConnection" action.
type ConfigureConnectionRequest struct { type ConfigureConnectionRequest struct {
// NewUserName relates to state variable UserName.
NewUserName string NewUserName string
// NewPassword relates to state variable Password.
NewPassword string NewPassword string
} }
@ -102,9 +141,12 @@ func (a *DeletePortMapping) RefResponse() any { return &a.Response }
// DeletePortMappingRequest contains the "in" args for the "DeletePortMapping" action. // DeletePortMappingRequest contains the "in" args for the "DeletePortMapping" action.
type DeletePortMappingRequest struct { type DeletePortMappingRequest struct {
NewRemoteHost string // NewRemoteHost relates to state variable RemoteHost.
NewRemoteHost string
// NewExternalPort relates to state variable ExternalPort.
NewExternalPort pkg2.UI2 NewExternalPort pkg2.UI2
NewProtocol string // NewProtocol relates to state variable PortMappingProtocol (2 standard allowed values).
NewProtocol string
} }
// DeletePortMappingResponse contains the "out" args for the "DeletePortMapping" action. // DeletePortMappingResponse contains the "out" args for the "DeletePortMapping" action.
@ -165,6 +207,7 @@ type GetAutoDisconnectTimeRequest struct{}
// GetAutoDisconnectTimeResponse contains the "out" args for the "GetAutoDisconnectTime" action. // GetAutoDisconnectTimeResponse contains the "out" args for the "GetAutoDisconnectTime" action.
type GetAutoDisconnectTimeResponse struct { type GetAutoDisconnectTimeResponse struct {
// NewAutoDisconnectTime relates to state variable AutoDisconnectTime.
NewAutoDisconnectTime pkg2.UI4 NewAutoDisconnectTime pkg2.UI4
} }
@ -195,7 +238,9 @@ type GetConnectionTypeInfoRequest struct{}
// GetConnectionTypeInfoResponse contains the "out" args for the "GetConnectionTypeInfo" action. // GetConnectionTypeInfoResponse contains the "out" args for the "GetConnectionTypeInfo" action.
type GetConnectionTypeInfoResponse struct { type GetConnectionTypeInfoResponse struct {
NewConnectionType string // NewConnectionType relates to state variable ConnectionType.
NewConnectionType string
// NewPossibleConnectionTypes relates to state variable PossibleConnectionTypes (7 standard allowed values).
NewPossibleConnectionTypes string NewPossibleConnectionTypes string
} }
@ -226,6 +271,7 @@ type GetExternalIPAddressRequest struct{}
// GetExternalIPAddressResponse contains the "out" args for the "GetExternalIPAddress" action. // GetExternalIPAddressResponse contains the "out" args for the "GetExternalIPAddress" action.
type GetExternalIPAddressResponse struct { type GetExternalIPAddressResponse struct {
// NewExternalIPAddress relates to state variable ExternalIPAddress.
NewExternalIPAddress string NewExternalIPAddress string
} }
@ -253,19 +299,28 @@ func (a *GetGenericPortMappingEntry) RefResponse() any { return &a.Response }
// GetGenericPortMappingEntryRequest contains the "in" args for the "GetGenericPortMappingEntry" action. // GetGenericPortMappingEntryRequest contains the "in" args for the "GetGenericPortMappingEntry" action.
type GetGenericPortMappingEntryRequest struct { type GetGenericPortMappingEntryRequest struct {
// NewPortMappingIndex relates to state variable PortMappingNumberOfEntries.
NewPortMappingIndex pkg2.UI2 NewPortMappingIndex pkg2.UI2
} }
// GetGenericPortMappingEntryResponse contains the "out" args for the "GetGenericPortMappingEntry" action. // GetGenericPortMappingEntryResponse contains the "out" args for the "GetGenericPortMappingEntry" action.
type GetGenericPortMappingEntryResponse struct { type GetGenericPortMappingEntryResponse struct {
NewRemoteHost string // NewRemoteHost relates to state variable RemoteHost.
NewExternalPort pkg2.UI2 NewRemoteHost string
NewProtocol string // NewExternalPort relates to state variable ExternalPort.
NewInternalPort pkg2.UI2 NewExternalPort pkg2.UI2
NewInternalClient string // NewProtocol relates to state variable PortMappingProtocol (2 standard allowed values).
NewEnabled pkg2.Boolean NewProtocol string
// NewInternalPort relates to state variable InternalPort.
NewInternalPort pkg2.UI2
// NewInternalClient relates to state variable InternalClient.
NewInternalClient string
// NewEnabled relates to state variable PortMappingEnabled.
NewEnabled pkg2.Boolean
// NewPortMappingDescription relates to state variable PortMappingDescription.
NewPortMappingDescription string NewPortMappingDescription string
NewLeaseDuration pkg2.UI4 // NewLeaseDuration relates to state variable PortMappingLeaseDuration.
NewLeaseDuration pkg2.UI4
} }
// GetIdleDisconnectTime provides request and response for the action. // GetIdleDisconnectTime provides request and response for the action.
@ -295,6 +350,7 @@ type GetIdleDisconnectTimeRequest struct{}
// GetIdleDisconnectTimeResponse contains the "out" args for the "GetIdleDisconnectTime" action. // GetIdleDisconnectTimeResponse contains the "out" args for the "GetIdleDisconnectTime" action.
type GetIdleDisconnectTimeResponse struct { type GetIdleDisconnectTimeResponse struct {
// NewIdleDisconnectTime relates to state variable IdleDisconnectTime.
NewIdleDisconnectTime pkg2.UI4 NewIdleDisconnectTime pkg2.UI4
} }
@ -325,7 +381,9 @@ type GetLinkLayerMaxBitRatesRequest struct{}
// GetLinkLayerMaxBitRatesResponse contains the "out" args for the "GetLinkLayerMaxBitRates" action. // GetLinkLayerMaxBitRatesResponse contains the "out" args for the "GetLinkLayerMaxBitRates" action.
type GetLinkLayerMaxBitRatesResponse struct { type GetLinkLayerMaxBitRatesResponse struct {
NewUpstreamMaxBitRate pkg2.UI4 // NewUpstreamMaxBitRate relates to state variable UpstreamMaxBitRate.
NewUpstreamMaxBitRate pkg2.UI4
// NewDownstreamMaxBitRate relates to state variable DownstreamMaxBitRate.
NewDownstreamMaxBitRate pkg2.UI4 NewDownstreamMaxBitRate pkg2.UI4
} }
@ -356,8 +414,10 @@ type GetNATRSIPStatusRequest struct{}
// GetNATRSIPStatusResponse contains the "out" args for the "GetNATRSIPStatus" action. // GetNATRSIPStatusResponse contains the "out" args for the "GetNATRSIPStatus" action.
type GetNATRSIPStatusResponse struct { type GetNATRSIPStatusResponse struct {
// NewRSIPAvailable relates to state variable RSIPAvailable.
NewRSIPAvailable pkg2.Boolean NewRSIPAvailable pkg2.Boolean
NewNATEnabled pkg2.Boolean // NewNATEnabled relates to state variable NATEnabled.
NewNATEnabled pkg2.Boolean
} }
// GetPPPAuthenticationProtocol provides request and response for the action. // GetPPPAuthenticationProtocol provides request and response for the action.
@ -387,6 +447,7 @@ type GetPPPAuthenticationProtocolRequest struct{}
// GetPPPAuthenticationProtocolResponse contains the "out" args for the "GetPPPAuthenticationProtocol" action. // GetPPPAuthenticationProtocolResponse contains the "out" args for the "GetPPPAuthenticationProtocol" action.
type GetPPPAuthenticationProtocolResponse struct { type GetPPPAuthenticationProtocolResponse struct {
// NewPPPAuthenticationProtocol relates to state variable PPPAuthenticationProtocol.
NewPPPAuthenticationProtocol string NewPPPAuthenticationProtocol string
} }
@ -417,6 +478,7 @@ type GetPPPCompressionProtocolRequest struct{}
// GetPPPCompressionProtocolResponse contains the "out" args for the "GetPPPCompressionProtocol" action. // GetPPPCompressionProtocolResponse contains the "out" args for the "GetPPPCompressionProtocol" action.
type GetPPPCompressionProtocolResponse struct { type GetPPPCompressionProtocolResponse struct {
// NewPPPCompressionProtocol relates to state variable PPPCompressionProtocol.
NewPPPCompressionProtocol string NewPPPCompressionProtocol string
} }
@ -447,6 +509,7 @@ type GetPPPEncryptionProtocolRequest struct{}
// GetPPPEncryptionProtocolResponse contains the "out" args for the "GetPPPEncryptionProtocol" action. // GetPPPEncryptionProtocolResponse contains the "out" args for the "GetPPPEncryptionProtocol" action.
type GetPPPEncryptionProtocolResponse struct { type GetPPPEncryptionProtocolResponse struct {
// NewPPPEncryptionProtocol relates to state variable PPPEncryptionProtocol.
NewPPPEncryptionProtocol string NewPPPEncryptionProtocol string
} }
@ -477,6 +540,7 @@ type GetPasswordRequest struct{}
// GetPasswordResponse contains the "out" args for the "GetPassword" action. // GetPasswordResponse contains the "out" args for the "GetPassword" action.
type GetPasswordResponse struct { type GetPasswordResponse struct {
// NewPassword relates to state variable Password.
NewPassword string NewPassword string
} }
@ -504,18 +568,26 @@ func (a *GetSpecificPortMappingEntry) RefResponse() any { return &a.Response }
// GetSpecificPortMappingEntryRequest contains the "in" args for the "GetSpecificPortMappingEntry" action. // GetSpecificPortMappingEntryRequest contains the "in" args for the "GetSpecificPortMappingEntry" action.
type GetSpecificPortMappingEntryRequest struct { type GetSpecificPortMappingEntryRequest struct {
NewRemoteHost string // NewRemoteHost relates to state variable RemoteHost.
NewRemoteHost string
// NewExternalPort relates to state variable ExternalPort.
NewExternalPort pkg2.UI2 NewExternalPort pkg2.UI2
NewProtocol string // NewProtocol relates to state variable PortMappingProtocol (2 standard allowed values).
NewProtocol string
} }
// GetSpecificPortMappingEntryResponse contains the "out" args for the "GetSpecificPortMappingEntry" action. // GetSpecificPortMappingEntryResponse contains the "out" args for the "GetSpecificPortMappingEntry" action.
type GetSpecificPortMappingEntryResponse struct { type GetSpecificPortMappingEntryResponse struct {
NewInternalPort pkg2.UI2 // NewInternalPort relates to state variable InternalPort.
NewInternalClient string NewInternalPort pkg2.UI2
NewEnabled pkg2.Boolean // NewInternalClient relates to state variable InternalClient.
NewInternalClient string
// NewEnabled relates to state variable PortMappingEnabled.
NewEnabled pkg2.Boolean
// NewPortMappingDescription relates to state variable PortMappingDescription.
NewPortMappingDescription string NewPortMappingDescription string
NewLeaseDuration pkg2.UI4 // NewLeaseDuration relates to state variable PortMappingLeaseDuration.
NewLeaseDuration pkg2.UI4
} }
// GetStatusInfo provides request and response for the action. // GetStatusInfo provides request and response for the action.
@ -545,9 +617,12 @@ type GetStatusInfoRequest struct{}
// GetStatusInfoResponse contains the "out" args for the "GetStatusInfo" action. // GetStatusInfoResponse contains the "out" args for the "GetStatusInfo" action.
type GetStatusInfoResponse struct { type GetStatusInfoResponse struct {
NewConnectionStatus string // NewConnectionStatus relates to state variable ConnectionStatus (3 standard allowed values).
NewConnectionStatus string
// NewLastConnectionError relates to state variable LastConnectionError (1 standard allowed values).
NewLastConnectionError string NewLastConnectionError string
NewUptime pkg2.UI4 // NewUptime relates to state variable Uptime.
NewUptime pkg2.UI4
} }
// GetUserName provides request and response for the action. // GetUserName provides request and response for the action.
@ -577,6 +652,7 @@ type GetUserNameRequest struct{}
// GetUserNameResponse contains the "out" args for the "GetUserName" action. // GetUserNameResponse contains the "out" args for the "GetUserName" action.
type GetUserNameResponse struct { type GetUserNameResponse struct {
// NewUserName relates to state variable UserName.
NewUserName string NewUserName string
} }
@ -607,6 +683,7 @@ type GetWarnDisconnectDelayRequest struct{}
// GetWarnDisconnectDelayResponse contains the "out" args for the "GetWarnDisconnectDelay" action. // GetWarnDisconnectDelayResponse contains the "out" args for the "GetWarnDisconnectDelay" action.
type GetWarnDisconnectDelayResponse struct { type GetWarnDisconnectDelayResponse struct {
// NewWarnDisconnectDelay relates to state variable WarnDisconnectDelay.
NewWarnDisconnectDelay pkg2.UI4 NewWarnDisconnectDelay pkg2.UI4
} }
@ -690,6 +767,7 @@ func (a *SetAutoDisconnectTime) RefResponse() any { return &a.Response }
// SetAutoDisconnectTimeRequest contains the "in" args for the "SetAutoDisconnectTime" action. // SetAutoDisconnectTimeRequest contains the "in" args for the "SetAutoDisconnectTime" action.
type SetAutoDisconnectTimeRequest struct { type SetAutoDisconnectTimeRequest struct {
// NewAutoDisconnectTime relates to state variable AutoDisconnectTime.
NewAutoDisconnectTime pkg2.UI4 NewAutoDisconnectTime pkg2.UI4
} }
@ -720,6 +798,7 @@ func (a *SetConnectionType) RefResponse() any { return &a.Response }
// SetConnectionTypeRequest contains the "in" args for the "SetConnectionType" action. // SetConnectionTypeRequest contains the "in" args for the "SetConnectionType" action.
type SetConnectionTypeRequest struct { type SetConnectionTypeRequest struct {
// NewConnectionType relates to state variable ConnectionType.
NewConnectionType string NewConnectionType string
} }
@ -750,6 +829,7 @@ func (a *SetIdleDisconnectTime) RefResponse() any { return &a.Response }
// SetIdleDisconnectTimeRequest contains the "in" args for the "SetIdleDisconnectTime" action. // SetIdleDisconnectTimeRequest contains the "in" args for the "SetIdleDisconnectTime" action.
type SetIdleDisconnectTimeRequest struct { type SetIdleDisconnectTimeRequest struct {
// NewIdleDisconnectTime relates to state variable IdleDisconnectTime.
NewIdleDisconnectTime pkg2.UI4 NewIdleDisconnectTime pkg2.UI4
} }
@ -780,6 +860,7 @@ func (a *SetWarnDisconnectDelay) RefResponse() any { return &a.Response }
// SetWarnDisconnectDelayRequest contains the "in" args for the "SetWarnDisconnectDelay" action. // SetWarnDisconnectDelayRequest contains the "in" args for the "SetWarnDisconnectDelay" action.
type SetWarnDisconnectDelayRequest struct { type SetWarnDisconnectDelayRequest struct {
// NewWarnDisconnectDelay relates to state variable WarnDisconnectDelay.
NewWarnDisconnectDelay pkg2.UI4 NewWarnDisconnectDelay pkg2.UI4
} }

View File

@ -1,5 +1,6 @@
{{define "service"}} {{define "service"}}
{{- $Imps := .Imps -}} {{- $Imps := .Imps -}}
{{- $Types := .Types -}}
// Package {{.Manifest.Package}} provides types for the {{quote .Manifest.ServiceType}} service. // Package {{.Manifest.Package}} provides types for the {{quote .Manifest.ServiceType}} service.
{{- with .Manifest.DocumentURL}} {{- with .Manifest.DocumentURL}}
// //
@ -13,15 +14,28 @@ import (
{{- end}} {{- end}}
) )
{{range .Types.StringVarDefs}}
{{- $Name := .Name}}
{{- with .AllowedValues}}
// Allowed values for state variable {{$Name}}.
const (
{{- range .}}
{{$Name}}_{{.}} = "{{.}}"
{{- end}}
)
{{- end}}
{{- end}}
const ServiceType = {{quote .Manifest.ServiceType}} const ServiceType = {{quote .Manifest.ServiceType}}
{{range .SCPD.SortedActions}} {{range .SCPD.SortedActions}}
{{- template "action" args "Action" . "Imps" $Imps}} {{- template "action" args "Action" . "Imps" $Imps "Types" $Types}}
{{end}} {{end}}
{{- end}} {{- end}}
{{define "action"}} {{define "action"}}
{{- $Imps := .Imps}} {{- $Imps := .Imps}}
{{- $soapActionType := index $Imps.TypeByName "SOAPActionInterface"}} {{- $Types := .Types}}
{{- $soapActionType := index $Types.TypeByName "SOAPActionInterface"}}
// {{.Action.Name}} provides request and response for the action. // {{.Action.Name}} provides request and response for the action.
// //
// ServiceType implements {{$soapActionType.AbsRef}}, self-describing the SOAP action. // ServiceType implements {{$soapActionType.AbsRef}}, self-describing the SOAP action.
@ -43,18 +57,23 @@ func (a *{{.Action.Name}}) RefResponse() any { return &a.Response }
// {{.Action.Name}}Request contains the "in" args for the {{quote .Action.Name}} action. // {{.Action.Name}}Request contains the "in" args for the {{quote .Action.Name}} action.
type {{.Action.Name}}Request struct type {{.Action.Name}}Request struct
{{- template "args" args "Args" .Action.InArgs "Imps" $Imps}} {{- template "args" args "Args" .Action.InArgs "Imps" $Imps "Types" $Types}}
// {{.Action.Name}}Response contains the "out" args for the {{quote .Action.Name}} action. // {{.Action.Name}}Response contains the "out" args for the {{quote .Action.Name}} action.
type {{.Action.Name}}Response struct type {{.Action.Name}}Response struct
{{- template "args" args "Args" .Action.OutArgs "Imps" $Imps}} {{- template "args" args "Args" .Action.OutArgs "Imps" $Imps "Types" $Types}}
{{- end}} {{- end}}
{{define "args"}} {{define "args"}}
{{- $Imps := .Imps -}} {{- $Imps := .Imps -}}
{{- $Types := .Types -}}
{ {{- with .Args}} { {{- with .Args}}
{{- range .}} {{- range .}}
{{- $fieldType := index $Imps.TypeByName .RelatedStateVariable.DataType}} {{- $fieldType := index $Types.TypeByName .RelatedStateVariable.DataType}}
// {{.Name}} relates to state variable {{.RelatedStateVariable.Name}}
{{- with .RelatedStateVariable.AllowedValues}}
{{- ""}} ({{len .}} standard allowed values)
{{- end }}.
{{.Name}} {{$fieldType.Ref}} {{.Name}} {{$fieldType.Ref}}
{{- end}} {{- end}}
{{end -}} } {{end -}} }