[SEN] 分离ONVIF/RTSP凭据并持久化Profile (#50) #52

Open
ila wants to merge 21 commits from agent/codex/50-sense-split-camera-credentials into agent/codex/48-sense-onvif-digest
Showing only changes of commit d0e947ca02 - Show all commits
@@ -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, "")
}