protocol/rtsp: simplified ReadResponse further by using only one sscanf

This commit is contained in:
Saxon 2019-04-28 13:23:35 +09:30
parent 9abcfb138b
commit fa7c3044f3
1 changed files with 4 additions and 13 deletions

View File

@ -135,21 +135,12 @@ func ReadResponse(r io.Reader) (*Response, error) {
return nil, errSmallResponse
}
// Check that it was terminated by CRLF.
if s[len(s)-2] != '\r' {
return nil, errors.New("line not terminated by CRLF")
if s[:5] != "RTSP/" {
return nil, errors.New("not a valid RTSP response")
}
resp.Proto = "RTSP"
var proto string
_, err = fmt.Sscanf(s, "%s %d %s", &proto, &resp.StatusCode, &resp.Status)
if err != nil {
return nil, err
}
s1 := strings.Split(proto, "/")
resp.Proto = s1[0]
_, err = fmt.Sscanf(s1[1], "%d.%d", &resp.ProtoMajor, &resp.ProtoMinor)
_, err = fmt.Sscanf(s[5:12], "%d.%d %d %s", &resp.ProtoMajor, &resp.ProtoMinor, &resp.StatusCode)
if err != nil {
return nil, err
}