Add SCPD parsing.
This commit is contained in:
parent
58cc710720
commit
489c180de9
17
device.go
17
device.go
@ -4,14 +4,20 @@ package goupnp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: Do the sub-structures have to be pointers?
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DeviceXMLNamespace = "urn:schemas-upnp-org:device-1-0"
|
DeviceXMLNamespace = "urn:schemas-upnp-org:device-1-0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RootDevice is the device description as described by section 2.3 "Device
|
||||||
|
// description" in
|
||||||
|
// http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf
|
||||||
type RootDevice struct {
|
type RootDevice struct {
|
||||||
Name xml.Name `xml:"root`
|
Name xml.Name `xml:"root`
|
||||||
SpecVersion SpecVersion `xml:"specVersion"`
|
SpecVersion SpecVersion `xml:"specVersion"`
|
||||||
@ -100,6 +106,17 @@ func (srv *Service) String() string {
|
|||||||
return fmt.Sprintf("Service ID %s : %s", srv.ServiceId, srv.ServiceType)
|
return fmt.Sprintf("Service ID %s : %s", srv.ServiceId, srv.ServiceType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (srv *Service) RequestSCDP() (*SCPD, error) {
|
||||||
|
if !srv.SCPDURL.Ok {
|
||||||
|
return nil, errors.New("bad/missing SCPD URL, or no URLBase has been set")
|
||||||
|
}
|
||||||
|
scpd := new(SCPD)
|
||||||
|
if err := requestXml(srv.SCPDURL.URL.String(), SCPDXMLNamespace, scpd); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return scpd, nil
|
||||||
|
}
|
||||||
|
|
||||||
type URLField struct {
|
type URLField struct {
|
||||||
URL url.URL `xml:"-"`
|
URL url.URL `xml:"-"`
|
||||||
Ok bool `xml:"-"`
|
Ok bool `xml:"-"`
|
||||||
|
53
scpd.go
Normal file
53
scpd.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package goupnp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
SCPDXMLNamespace = "urn:schemas-upnp-org:service-1-0"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SCPD is the service description as described by section 2.5 "Service
|
||||||
|
// description" in
|
||||||
|
// http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf
|
||||||
|
type SCPD struct {
|
||||||
|
Name xml.Name `xml:"scpd"`
|
||||||
|
ConfigId string `xml:"configId,attr"`
|
||||||
|
SpecVersion SpecVersion `xml:"specVersion"`
|
||||||
|
Actions []Action `xml:"actionList>action"`
|
||||||
|
StateVariables []StateVariable `xml:"serviceStateTable>stateVariable"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Action struct {
|
||||||
|
Name string `xml:"name"`
|
||||||
|
Arguments []Argument `xml:"argumentList>argument"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Argument struct {
|
||||||
|
Name string `xml:"name"`
|
||||||
|
Direction string `xml:"direction"` // in|out
|
||||||
|
RelatedStateVariable string `xml:"relatedStateVariable"` // ?
|
||||||
|
Retval string `xml:"retval"` // ?
|
||||||
|
}
|
||||||
|
|
||||||
|
type StateVariable struct {
|
||||||
|
Name string `xml:"name"`
|
||||||
|
SendEvents string `xml:"sendEvents,attr"` // yes|no
|
||||||
|
Multicast string `xml:"multicast,attr"` // yes|no
|
||||||
|
DataType DataType `xml:"dataType"`
|
||||||
|
DefaultValue string `xml:"defaultValue"`
|
||||||
|
AllowedValueRange AllowedValueRange `xml:"allowedValueRange"`
|
||||||
|
AllowedValue []string `xml:"allowedValueList>allowedValue"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AllowedValueRange struct {
|
||||||
|
Minimum string `xml:"minimum"`
|
||||||
|
Maximum string `xml:"maximum"`
|
||||||
|
Step string `xml:"step"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DataType struct {
|
||||||
|
Name string `xml:",chardata"`
|
||||||
|
Type string `xml:"type,attr"`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user