diff --git a/v2alpha/cmd/goupnp2srvgen/main.go b/v2alpha/cmd/goupnp2srvgen/main.go index be9f427..fdd9c78 100644 --- a/v2alpha/cmd/goupnp2srvgen/main.go +++ b/v2alpha/cmd/goupnp2srvgen/main.go @@ -13,6 +13,7 @@ import ( "strings" "text/template" + "github.com/BurntSushi/toml" "github.com/huin/goupnp/v2alpha/cmd/goupnp2srvgen/tmplfuncs" "github.com/huin/goupnp/v2alpha/cmd/goupnp2srvgen/zipread" "github.com/huin/goupnp/v2alpha/description/srvdesc" @@ -23,6 +24,7 @@ import ( ) var ( + srvManifests = flag.String("srv_manifests", "", "Path to srvmanifests.toml") srvTemplate = flag.String("srv_template", "", "Path to srv.gotemplate.") upnpresourcesZip = flag.String("upnpresources_zip", "", "Path to upnpresources.zip.") ) @@ -41,6 +43,16 @@ func run() error { if len(flag.Args()) > 0 { 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 == "" { return errors.New("-srv_template is a required flag.") } @@ -72,7 +84,7 @@ func run() error { 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 { return fmt.Errorf("processing DCP %s: %w", m.Path, err) } @@ -80,24 +92,6 @@ func run() error { 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( upnpresources *zipread.ZipRead, manifest *DCPSpecManifest, @@ -158,6 +152,10 @@ func processService( return nil } +type DCPSpecManifests struct { + DCPS []*DCPSpecManifest +} + type DCPSpecManifest struct { // Path is the file path within upnpresources.zip to the DCP spec ZIP file. Path string diff --git a/v2alpha/go.mod b/v2alpha/go.mod index 130c55f..6bb1eaa 100644 --- a/v2alpha/go.mod +++ b/v2alpha/go.mod @@ -3,3 +3,5 @@ module github.com/huin/goupnp/v2alpha go 1.18 require github.com/google/go-cmp v0.5.7 + +require github.com/BurntSushi/toml v1.1.0 // indirect diff --git a/v2alpha/go.sum b/v2alpha/go.sum index a6ca3a4..b08ca62 100644 --- a/v2alpha/go.sum +++ b/v2alpha/go.sum @@ -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/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/v2alpha/srv/srvmanifests.toml b/v2alpha/srv/srvmanifests.toml new file mode 100644 index 0000000..dbc8e5b --- /dev/null +++ b/v2alpha/srv/srvmanifests.toml @@ -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"