1 Star 0 Fork 0

lwch / upnp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
desc.go 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
lwch 提交于 2019-02-26 18:01 . supported desc parse and service parse
package upnp
import (
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
)
// FROM: http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf
// Device description section, only include REQUIRED fields
type descResponse struct {
// configuration number to which the device description belongs
ConfigID string `xml:"configId,attr"`
// version templates
SpecVersion specVersionType `xml:"specVersion"`
// device object
Device deviceType `xml:"device"`
}
type specVersionType struct {
Major int `xml:"major"`
Minor int `xml:"minor"`
}
type deviceType struct {
// starts with "urn:schemas-upnp-org:device:"
DeviceType string `xml:"deviceType"`
// show name
FriendlyName string `xml:"friendlyName"`
// manufacturer name
Manufacturer string `xml:"manufacturer"`
// model name
ModelName string `xml:"modelName"`
// service list
ServiceList []serviceType `xml:"serviceList>service"`
// embedded devices
DeviceList []deviceType `xml:"deviceList>device"`
}
type serviceType struct {
// starts with "urn:schemas-upnp-org:service:"
ServiceType string `xml:"serviceType"`
// starts with "urn:upnp-org:serviceId:"
ServiceID string `xml:"serviceId"`
// url for service spec
SCPDURL string `xml:"SCPDURL"`
// url for control
ControlURL string `xml:"controlURL"`
// url for eventing
EventSubURL string `xml:"eventSubURL"`
}
func (d *Device) parse() error {
resp, err := http.Get(d.descLocation)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
data, _ := ioutil.ReadAll(resp.Body)
return fmt.Errorf("GET description info fail, http_code=%d\n%s", resp.StatusCode, string(data))
}
var desc descResponse
if err := xml.NewDecoder(resp.Body).Decode(&desc); err != nil {
return err
}
if err := d.loadService(desc.Device); err != nil {
return err
}
d.parsed = true
return nil
}
1
https://gitee.com/lwch/upnp.git
git@gitee.com:lwch/upnp.git
lwch
upnp
upnp
master

搜索帮助