goupnp

package
v0.9.30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2015 License: BSD-2-Clause, LGPL-2.1-or-later Imports: 11 Imported by: 0

README

goupnp is a UPnP client library for Go

Installation

Run go get -u github.com/huin/goupnp.

Regenerating dcps generated source code:

  1. Install gotasks: go get -u github.com/jingweno/gotask
  2. Change to the gotasks directory: cd gotasks
  3. Download UPnP specification data (if not done already): wget http://upnp.org/resources/upnpresources.zip
  4. Regenerate source code: gotask specgen -s upnpresources.zip -o ../dcps

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

View Source
const (
	DeviceXMLNamespace = "urn:schemas-upnp-org:device-1-0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextError

type ContextError struct {
	Context string
	Err     error
}

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"`
	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

func (device *Device) FindService(serviceType string) []*Service

FindService finds all (if any) Services under the device and its descendents that have the given ServiceType.

func (*Device) SetURLBase

func (device *Device) SetURLBase(urlBase *url.URL)

SetURLBase sets the URLBase for the Device and its underlying components.

func (*Device) String

func (device *Device) String() string

func (*Device) VisitDevices

func (device *Device) VisitDevices(visitor func(*Device))

VisitDevices calls visitor for the device, and all its descendent devices.

func (*Device) VisitServices

func (device *Device) VisitServices(visitor func(*Service))

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

func (icon *Icon) SetURLBase(url *url.URL)

SetURLBase sets the URLBase for the Icon.

type MaybeRootDevice

type MaybeRootDevice struct {
	Root *RootDevice
	Err  error
}

MaybeRootDevice contains either a RootDevice or an error.

func DiscoverDevices

func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error)

DiscoverDevices 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 (*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

func (srv *Service) RequestSCDP() (*scpd.SCPD, error)

RequestSCDP requests the SCPD (soap actions and state variables description) for the service.

func (*Service) SetURLBase

func (srv *Service) SetURLBase(urlBase *url.URL)

SetURLBase sets the URLBase for the Service.

func (*Service) String

func (srv *Service) String() string

type ServiceClient

type ServiceClient struct {
	SOAPClient *soap.SOAPClient
	RootDevice *RootDevice
	Service    *Service
}

ServiceClient is a SOAP client, root device and the service for the SOAP client rolled into one value. The root device and service are intended to be informational.

func NewServiceClients

func NewServiceClients(searchTarget string) (clients []ServiceClient, errors []error, err error)

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.

type SpecVersion

type SpecVersion struct {
	Major int32 `xml:"major"`
	Minor int32 `xml:"minor"`
}

SpecVersion is part of a RootDevice, describes the version of the specification that the data adheres to.

type URLField

type URLField struct {
	URL url.URL `xml:"-"`
	Ok  bool    `xml:"-"`
	Str string  `xml:",chardata"`
}

URLField is a URL that is part of a device description.

func (*URLField) SetURLBase

func (uf *URLField) SetURLBase(urlBase *url.URL)

Directories

Path Synopsis
cmd
dcps
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.
Serves as examples of using the goupnp library.
Serves as examples of using the goupnp library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL