Fix DiscoverDevices to work with absent root.URLBaseStr.
This is particularly important as URLBaseStr should never be present in UPnP/1.1.
This commit is contained in:
parent
980f9c9dcc
commit
8a169ca3f7
13
goupnp.go
13
goupnp.go
@ -17,6 +17,7 @@ package goupnp
|
|||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
@ -59,9 +60,11 @@ func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error) {
|
|||||||
|
|
||||||
results := make([]MaybeRootDevice, len(responses))
|
results := make([]MaybeRootDevice, len(responses))
|
||||||
for i, response := range responses {
|
for i, response := range responses {
|
||||||
|
log.Print(response)
|
||||||
maybe := &results[i]
|
maybe := &results[i]
|
||||||
loc, err := response.Location()
|
loc, err := response.Location()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
maybe.Err = ContextError{"unexpected bad location from search", err}
|
maybe.Err = ContextError{"unexpected bad location from search", err}
|
||||||
continue
|
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}
|
maybe.Err = ContextError{fmt.Sprintf("error requesting root device details from %q", locStr), err}
|
||||||
continue
|
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 {
|
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
|
continue
|
||||||
}
|
}
|
||||||
root.SetURLBase(urlBase)
|
root.SetURLBase(urlBase)
|
||||||
|
Loading…
Reference in New Issue
Block a user