From 167b9766e52022410644dfc64e8aadd57ee36858 Mon Sep 17 00:00:00 2001 From: John Beisley Date: Thu, 15 Mar 2018 19:11:26 +0000 Subject: [PATCH] Allow SSDP search results from inexact searches. Fixes #24. --- ssdp/ssdp.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ssdp/ssdp.go b/ssdp/ssdp.go index eb61bdb..4c03b25 100644 --- a/ssdp/ssdp.go +++ b/ssdp/ssdp.go @@ -20,6 +20,11 @@ const ( ssdpSearchPort = 1900 methodSearch = "M-SEARCH" 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 @@ -54,12 +59,15 @@ func SSDPRawSearch(httpu *httpu.HTTPUClient, searchTarget string, maxWaitSeconds if err != nil { return nil, err } + + isExactSearch := searchTarget != SSDPAll && searchTarget != UPNPRootDevice + for _, response := range allResponses { if response.StatusCode != 200 { log.Printf("ssdp: got response status code %q in search response", response.Status) continue } - if st := response.Header.Get("ST"); st != searchTarget { + if st := response.Header.Get("ST"); isExactSearch && st != searchTarget { continue } location, err := response.Location()