From 8a169ca3f7bd938872a5d5f551c7230b1645116b Mon Sep 17 00:00:00 2001 From: John Beisley Date: Sun, 5 Jan 2014 19:39:24 +0000 Subject: [PATCH] Fix DiscoverDevices to work with absent root.URLBaseStr. This is particularly important as URLBaseStr should never be present in UPnP/1.1. --- goupnp.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/goupnp.go b/goupnp.go index 5a64001..a1a45d4 100644 --- a/goupnp.go +++ b/goupnp.go @@ -17,6 +17,7 @@ package goupnp import ( "encoding/xml" "fmt" + "log" "net/http" "net/url" @@ -59,9 +60,11 @@ func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error) { results := make([]MaybeRootDevice, len(responses)) for i, response := range responses { + log.Print(response) maybe := &results[i] loc, err := response.Location() if err != nil { + maybe.Err = ContextError{"unexpected bad location from search", err} continue } @@ -71,9 +74,15 @@ func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error) { maybe.Err = ContextError{fmt.Sprintf("error requesting root device details from %q", locStr), err} continue } - urlBase, err := url.Parse(root.URLBaseStr) + var urlBaseStr string + if root.URLBaseStr != "" { + urlBaseStr = root.URLBaseStr + } else { + urlBaseStr = locStr + } + urlBase, err := url.Parse(urlBaseStr) if err != nil { - maybe.Err = ContextError{fmt.Sprintf("error parsing URLBase %q from %q: %v", root.URLBaseStr, locStr), err} + maybe.Err = ContextError{fmt.Sprintf("error parsing location URL %q", locStr), err} continue } root.SetURLBase(urlBase)