Move DCP spec manifests out to a TOML file.

This commit is contained in:
John Beisley 2022-06-10 07:20:09 +01:00
parent 3db7296aeb
commit 9d4879e3c6
4 changed files with 31 additions and 19 deletions

View File

@ -13,6 +13,7 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/BurntSushi/toml"
"github.com/huin/goupnp/v2alpha/cmd/goupnp2srvgen/tmplfuncs" "github.com/huin/goupnp/v2alpha/cmd/goupnp2srvgen/tmplfuncs"
"github.com/huin/goupnp/v2alpha/cmd/goupnp2srvgen/zipread" "github.com/huin/goupnp/v2alpha/cmd/goupnp2srvgen/zipread"
"github.com/huin/goupnp/v2alpha/description/srvdesc" "github.com/huin/goupnp/v2alpha/description/srvdesc"
@ -23,6 +24,7 @@ import (
) )
var ( var (
srvManifests = flag.String("srv_manifests", "", "Path to srvmanifests.toml")
srvTemplate = flag.String("srv_template", "", "Path to srv.gotemplate.") srvTemplate = flag.String("srv_template", "", "Path to srv.gotemplate.")
upnpresourcesZip = flag.String("upnpresources_zip", "", "Path to upnpresources.zip.") upnpresourcesZip = flag.String("upnpresources_zip", "", "Path to upnpresources.zip.")
) )
@ -41,6 +43,16 @@ func run() error {
if len(flag.Args()) > 0 { if len(flag.Args()) > 0 {
return fmt.Errorf("unused arguments: %s", strings.Join(flag.Args(), " ")) return fmt.Errorf("unused arguments: %s", strings.Join(flag.Args(), " "))
} }
if *srvManifests == "" {
return errors.New("-srv_manifests is a required flag.")
}
var manifests DCPSpecManifests
_, err := toml.DecodeFile(*srvManifests, &manifests)
if err != nil {
return fmt.Errorf("loading srv_manifests %q: %w", *srvManifests, err)
}
if *srvTemplate == "" { if *srvTemplate == "" {
return errors.New("-srv_template is a required flag.") return errors.New("-srv_template is a required flag.")
} }
@ -72,7 +84,7 @@ func run() error {
GoType: reflect.TypeOf((*soap.SOAPAction)(nil)).Elem(), GoType: reflect.TypeOf((*soap.SOAPAction)(nil)).Elem(),
} }
for _, m := range manifests { for _, m := range manifests.DCPS {
if err := processDCP(upnpresources, m, typeMap, tmpl); err != nil { if err := processDCP(upnpresources, m, typeMap, tmpl); err != nil {
return fmt.Errorf("processing DCP %s: %w", m.Path, err) return fmt.Errorf("processing DCP %s: %w", m.Path, err)
} }
@ -80,24 +92,6 @@ func run() error {
return nil return nil
} }
var manifests = []*DCPSpecManifest{
{
Path: "standardizeddcps/Internet Gateway_2/UPnP-gw-IGD-TestFiles-20101210.zip",
Services: []*ServiceManifest{
{
Package: "lanhostconfigmanagement1",
ServiceType: "urn:schemas-upnp-org:service:LANHostConfigManagement:1",
Path: "xml data files/service/LANHostConfigManagement1.xml",
},
{
Package: "wanpppconnection1",
ServiceType: "urn:schemas-upnp-org:service:WANPPPConnection:1",
Path: "xml data files/service/WANPPPConnection1.xml",
},
},
},
}
func processDCP( func processDCP(
upnpresources *zipread.ZipRead, upnpresources *zipread.ZipRead,
manifest *DCPSpecManifest, manifest *DCPSpecManifest,
@ -158,6 +152,10 @@ func processService(
return nil return nil
} }
type DCPSpecManifests struct {
DCPS []*DCPSpecManifest
}
type DCPSpecManifest struct { type DCPSpecManifest struct {
// Path is the file path within upnpresources.zip to the DCP spec ZIP file. // Path is the file path within upnpresources.zip to the DCP spec ZIP file.
Path string Path string

View File

@ -3,3 +3,5 @@ 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.7
require github.com/BurntSushi/toml v1.1.0 // indirect

View File

@ -1,3 +1,5 @@
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
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=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=

View File

@ -0,0 +1,10 @@
[[DCPS]]
Path = "standardizeddcps/Internet Gateway_2/UPnP-gw-IGD-TestFiles-20101210.zip"
[[DCPS.Services]]
Package = "lanhostconfigmanagement1"
ServiceType = "urn:schemas-upnp-org:service:LANHostConfigManagement:1"
Path = "xml data files/service/LANHostConfigManagement1.xml"
[[DCPS.Services]]
Package = "wanpppconnection1"
ServiceType = "urn:schemas-upnp-org:service:WANPPPConnection:1"
Path = "xml data files/service/WANPPPConnection1.xml"