package pkg import ( "errors" "strconv" "strings" ) // RTSPProfile : Virtual server RTSP traffic profile configuration type RTSPProfile struct { CheckSource string `json:"check_source"` // enabled IdleTimeout int `json:"idle_timeout"` // 300 LogProfile string `json:"log_profile"` // none LogPublisher string `json:"log_publisher"` // none MaxHeaderSize int `json:"max_header_size"` // 4096 MaxQueuedData int `json:"max_queued_data"` // 32768 MulticastRedirect string `json:"multicast_redirect"` // disabled Proxy string `json:"proxy"` // none ProxyHeader string `json:"proxy_header"` // none RealHTTPPersistence string `json:"real_http_persistence"` // enabled RTCPPort int `json:"rtcp_port"` //rtcp_port 0 RTPPort int `json:"rtp_port"` //rtp_port 0 SessionReconnect string `json:"session_reconnect"` // disabled UnicaseRedirect string `json:"unicast_redirect"` // disabled } func ParseRTSP(raw string) (*RTSPProfile, error) { p := new(RTSPProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile rtsp") { return nil, errors.New("not an rtsp profile") } for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "check-source": p.CheckSource = strings.Join(f[1:], " ") case "idle-timeout": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.IdleTimeout = i case "log-profile": p.LogProfile = strings.Join(f[1:], " ") case "log-publisher": p.LogPublisher = strings.Join(f[1:], " ") case "max-header-size": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.MaxHeaderSize = i case "max-queued-data": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.MaxQueuedData = i case "multicast-redirect": p.MulticastRedirect = strings.Join(f[1:], " ") case "proxy": p.Proxy = strings.Join(f[1:], " ") case "proxy-header": p.ProxyHeader = strings.Join(f[1:], " ") case "real-http-persistence": p.RealHTTPPersistence = strings.Join(f[1:], " ") case "rtcp-port": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.RTCPPort = i case "rtp-port": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.RTPPort = i case "session-reconnect": p.SessionReconnect = strings.Join(f[1:], " ") case "unicast-redirect": p.UnicaseRedirect = strings.Join(f[1:], " ") } } return p, nil }