Allow SSDP search results from inexact searches.

Fixes #24.
This commit is contained in:
John Beisley 2018-03-15 19:11:26 +00:00
parent e25a5cc217
commit 167b9766e5

View File

@ -20,6 +20,11 @@ const (
ssdpSearchPort = 1900 ssdpSearchPort = 1900
methodSearch = "M-SEARCH" methodSearch = "M-SEARCH"
methodNotify = "NOTIFY" methodNotify = "NOTIFY"
// SSDPAll is a value for searchTarget that searches for all devices and services.
SSDPAll = "ssdp:all"
// UPNPRootDevice is a value for searchTarget that searches for all root devices.
UPNPRootDevice = "upnp:rootdevice"
) )
// SSDPRawSearch performs a fairly raw SSDP search request, and returns the // SSDPRawSearch performs a fairly raw SSDP search request, and returns the
@ -54,12 +59,15 @@ func SSDPRawSearch(httpu *httpu.HTTPUClient, searchTarget string, maxWaitSeconds
if err != nil { if err != nil {
return nil, err return nil, err
} }
isExactSearch := searchTarget != SSDPAll && searchTarget != UPNPRootDevice
for _, response := range allResponses { for _, response := range allResponses {
if response.StatusCode != 200 { if response.StatusCode != 200 {
log.Printf("ssdp: got response status code %q in search response", response.Status) log.Printf("ssdp: got response status code %q in search response", response.Status)
continue continue
} }
if st := response.Header.Get("ST"); st != searchTarget { if st := response.Header.Get("ST"); isExactSearch && st != searchTarget {
continue continue
} }
location, err := response.Location() location, err := response.Location()