feat: complete split camera credentials (#50)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -82,9 +83,32 @@ func (c *HTTPClient) Profiles(ctx context.Context, address string, credential Cr
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
profiles[i].StreamURI, err = normalizeStreamURI(deviceEndpoint, profiles[i].StreamURI)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return profiles, nil
|
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) {
|
func (c *HTTPClient) soap(ctx context.Context, endpoint string, credential Credential, body string) ([]byte, error) {
|
||||||
return c.soapAttempt(ctx, endpoint, credential, body, "")
|
return c.soapAttempt(ctx, endpoint, credential, body, "")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user