feat: complete split camera credentials (#50)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -82,9 +83,32 @@ func (c *HTTPClient) Profiles(ctx context.Context, address string, credential Cr
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
profiles[i].StreamURI, err = normalizeStreamURI(deviceEndpoint, profiles[i].StreamURI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return profiles, nil
|
||||
}
|
||||
|
||||
func normalizeStreamURI(deviceEndpoint, streamURI string) (string, error) {
|
||||
device, err := url.Parse(deviceEndpoint)
|
||||
if err != nil || device.Hostname() == "" {
|
||||
return "", fmt.Errorf("invalid ONVIF address")
|
||||
}
|
||||
stream, err := url.Parse(streamURI)
|
||||
if err != nil || stream.Scheme != "rtsp" || stream.Host == "" || stream.User != nil {
|
||||
return "", fmt.Errorf("invalid RTSP stream URI")
|
||||
}
|
||||
if !strings.EqualFold(stream.Hostname(), device.Hostname()) {
|
||||
port := stream.Port()
|
||||
stream.Host = device.Hostname()
|
||||
if port != "" {
|
||||
stream.Host = net.JoinHostPort(device.Hostname(), port)
|
||||
}
|
||||
}
|
||||
return stream.String(), nil
|
||||
}
|
||||
func (c *HTTPClient) soap(ctx context.Context, endpoint string, credential Credential, body string) ([]byte, error) {
|
||||
return c.soapAttempt(ctx, endpoint, credential, body, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user