Documentation ¶
Overview ¶
goupnp is an implementation of a client for various UPnP services.
For most uses, it is recommended to use the code-generated packages under github.com/huin/goupnp/dcps. Example use is shown at http://godoc.org/github.com/huin/goupnp/example
A commonly used client is internetgateway1.WANPPPConnection1: http://godoc.org/github.com/huin/goupnp/dcps/internetgateway1#WANPPPConnection1
Currently only a couple of schemas have code generated for them from the UPnP example XML specifications. Not all methods will work on these clients, because the generated stubs contain the full set of specified methods from the XML specifications, and the discovered services will likely support a subset of those methods.
Index ¶
- Constants
- Variables
- type ContextError
- type Device
- type Icon
- type MaybeRootDevice
- type RootDevice
- type Service
- func (srv *Service) NewSOAPClient() *soap.SOAPClient
- func (srv *Service) RequestSCDP() (*scpd.SCPD, error)
- func (srv *Service) RequestSCPD() (*scpd.SCPD, error)
- func (srv *Service) RequestSCPDCtx(ctx context.Context) (*scpd.SCPD, error)
- func (srv *Service) SetURLBase(urlBase *url.URL)
- func (srv *Service) String() string
- type ServiceClient
- func NewServiceClients(searchTarget string) (clients []ServiceClient, errors []error, err error)
- func NewServiceClientsByURL(loc *url.URL, searchTarget string) ([]ServiceClient, error)
- func NewServiceClientsByURLCtx(ctx context.Context, loc *url.URL, searchTarget string) ([]ServiceClient, error)
- func NewServiceClientsCtx(ctx context.Context, searchTarget string) (clients []ServiceClient, errors []error, err error)
- func NewServiceClientsFromRootDevice(rootDevice *RootDevice, loc *url.URL, searchTarget string) ([]ServiceClient, error)
- type SpecVersion
- type URLField
Constants ¶
const (
DeviceXMLNamespace = "urn:schemas-upnp-org:device-1-0"
)
Variables ¶
CharsetReaderDefault specifies the charset reader used while decoding the output from a UPnP server. It can be modified in an init function to allow for non-utf8 encodings, but should not be changed after requesting clients.
var HTTPClientDefault = http.DefaultClient
HTTPClient specifies the http.Client object used when fetching the XML from the UPnP server. HTTPClient defaults the http.DefaultClient. This may be overridden by the importing application.
Functions ¶
This section is empty.
Types ¶
type ContextError ¶
ContextError is an error that wraps an error with some context information.
func (ContextError) Error ¶
func (err ContextError) Error() string
type Device ¶
type Device struct { DeviceType string `xml:"deviceType"` FriendlyName string `xml:"friendlyName"` Manufacturer string `xml:"manufacturer"` ManufacturerURL URLField `xml:"manufacturerURL"` ModelDescription string `xml:"modelDescription"` ModelName string `xml:"modelName"` ModelNumber string `xml:"modelNumber"` ModelType string `xml:"modelType"` ModelURL URLField `xml:"modelURL"` SerialNumber string `xml:"serialNumber"` UDN string `xml:"UDN"` UPC string `xml:"UPC,omitempty"` Icons []Icon `xml:"iconList>icon,omitempty"` Services []Service `xml:"serviceList>service,omitempty"` Devices []Device `xml:"deviceList>device,omitempty"` // Extra observed elements: PresentationURL URLField `xml:"presentationURL"` }
Device is a UPnP device. It can have child devices.
func (*Device) FindService ¶
FindService finds all (if any) Services under the device and its descendents that have the given ServiceType.
func (*Device) SetURLBase ¶
SetURLBase sets the URLBase for the Device and its underlying components.
func (*Device) VisitDevices ¶
VisitDevices calls visitor for the device, and all its descendent devices.
func (*Device) VisitServices ¶
VisitServices calls visitor for all Services under the device and all its descendent devices.
type Icon ¶
type Icon struct { Mimetype string `xml:"mimetype"` Width int32 `xml:"width"` Height int32 `xml:"height"` Depth int32 `xml:"depth"` URL URLField `xml:"url"` }
Icon is a representative image that a device might include in its description.
func (*Icon) SetURLBase ¶
SetURLBase sets the URLBase for the Icon.
type MaybeRootDevice ¶
type MaybeRootDevice struct { // Identifier of the device. Note that this in combination with Location // uniquely identifies a result from DiscoverDevices. USN string // Set iff Err == nil. Root *RootDevice // The location the device was discovered at. This can be used with // DeviceByURL, assuming the device is still present. A location represents // the discovery of a device, regardless of if there was an error probing it. Location *url.URL // The address from which the device was discovered (if known - otherwise nil). LocalAddr net.IP // Any error encountered probing a discovered device. Err error }
MaybeRootDevice contains either a RootDevice or an error.
func DiscoverDevices ¶
func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error)
DiscoverDevices is the legacy version of DiscoverDevicesCtx, but uses context.Background() as the context.
func DiscoverDevicesCtx ¶ added in v1.1.0
func DiscoverDevicesCtx(ctx context.Context, searchTarget string) ([]MaybeRootDevice, error)
DiscoverDevicesCtx attempts to find targets of the given type. This is typically the entry-point for this package. searchTarget is typically a URN in the form "urn:schemas-upnp-org:device:..." or "urn:schemas-upnp-org:service:...". A single error is returned for errors while attempting to send the query. An error or RootDevice is returned for each discovered RootDevice.
type RootDevice ¶
type RootDevice struct { XMLName xml.Name `xml:"root"` SpecVersion SpecVersion `xml:"specVersion"` URLBase url.URL `xml:"-"` URLBaseStr string `xml:"URLBase"` Device Device `xml:"device"` }
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
func DeviceByURL ¶
func DeviceByURL(loc *url.URL) (*RootDevice, error)
func DeviceByURLCtx ¶ added in v1.1.0
func (*RootDevice) SetURLBase ¶
func (root *RootDevice) SetURLBase(urlBase *url.URL)
SetURLBase sets the URLBase for the RootDevice and its underlying components.
type Service ¶
type Service struct { ServiceType string `xml:"serviceType"` ServiceId string `xml:"serviceId"` SCPDURL URLField `xml:"SCPDURL"` ControlURL URLField `xml:"controlURL"` EventSubURL URLField `xml:"eventSubURL"` }
Service is a service provided by a UPnP Device.
func (*Service) NewSOAPClient ¶
func (srv *Service) NewSOAPClient() *soap.SOAPClient
func (*Service) RequestSCDP ¶
RequestSCDP is for compatibility only, prefer RequestSCPD. This was a misspelling of RequestSCDP.
func (*Service) RequestSCPD ¶
RequestSCPD is the legacy version of RequestSCPDCtx, but uses context.Background() as the context.
func (*Service) RequestSCPDCtx ¶ added in v1.1.0
RequestSCPDCtx requests the SCPD (soap actions and state variables description) for the service.
func (*Service) SetURLBase ¶
SetURLBase sets the URLBase for the Service.
type ServiceClient ¶
type ServiceClient struct { SOAPClient *soap.SOAPClient RootDevice *RootDevice Location *url.URL Service *Service // contains filtered or unexported fields }
ServiceClient is a SOAP client, root device and the service for the SOAP client rolled into one value. The root device, location, and service are intended to be informational. Location can be used to later recreate a ServiceClient with NewServiceClientByURL if the service is still present; bypassing the discovery process.
func NewServiceClients ¶
func NewServiceClients(searchTarget string) (clients []ServiceClient, errors []error, err error)
NewServiceClients is the legacy version of NewServiceClientsCtx, but uses context.Background() as the context.
func NewServiceClientsByURL ¶
func NewServiceClientsByURL(loc *url.URL, searchTarget string) ([]ServiceClient, error)
NewServiceClientsByURL is the legacy version of NewServiceClientsByURLCtx, but uses context.Background() as the context.
func NewServiceClientsByURLCtx ¶ added in v1.1.0
func NewServiceClientsByURLCtx(ctx context.Context, loc *url.URL, searchTarget string) ([]ServiceClient, error)
NewServiceClientsByURLCtx creates client(s) for the given service URN, for a root device at the given URL.
func NewServiceClientsCtx ¶ added in v1.1.0
func NewServiceClientsCtx(ctx context.Context, searchTarget string) (clients []ServiceClient, errors []error, err error)
NewServiceClientsCtx discovers services, and returns clients for them. err will report any error with the discovery process (blocking any device/service discovery), errors reports errors on a per-root-device basis.
func NewServiceClientsFromRootDevice ¶
func NewServiceClientsFromRootDevice(rootDevice *RootDevice, loc *url.URL, searchTarget string) ([]ServiceClient, error)
NewServiceClientsFromDevice creates client(s) for the given service URN, in a given root device. The loc parameter is simply assigned to the Location attribute of the returned ServiceClient(s).
func (*ServiceClient) GetServiceClient ¶
func (client *ServiceClient) GetServiceClient() *ServiceClient
GetServiceClient returns the ServiceClient itself. This is provided so that the service client attributes can be accessed via an interface method on a wrapping type.
func (*ServiceClient) LocalAddr ¶ added in v1.0.3
func (client *ServiceClient) LocalAddr() net.IP
LocalAddr returns the address from which the device was discovered (if known - otherwise empty).
type SpecVersion ¶
SpecVersion is part of a RootDevice, describes the version of the specification that the data adheres to.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
discoverall
Example program to display all devices discovered on the local network.
|
Example program to display all devices discovered on the local network. |
goupnpdcpgen
Command to generate DCP package source from the XML specification.
|
Command to generate DCP package source from the XML specification. |
dcps
|
|
av1
Client for UPnP Device Control Protocol MediaServer v1 and MediaRenderer v1.
|
Client for UPnP Device Control Protocol MediaServer v1 and MediaRenderer v1. |
internetgateway1
Client for UPnP Device Control Protocol Internet Gateway Device v1.
|
Client for UPnP Device Control Protocol Internet Gateway Device v1. |
internetgateway2
Client for UPnP Device Control Protocol Internet Gateway Device v2.
|
Client for UPnP Device Control Protocol Internet Gateway Device v2. |
ocf/internetgateway2
Client for UPnP Device Control Protocol Internet Gateway Device v2 - Open Connectivity Foundation.
|
Client for UPnP Device Control Protocol Internet Gateway Device v2 - Open Connectivity Foundation. |
Serves as examples of using the goupnp library.
|
Serves as examples of using the goupnp library. |
v2alpha
module
|