mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
server: do not allow a client to change path name during PLAY or RECORD
This commit is contained in:
@@ -238,3 +238,14 @@ type ErrServerInvalidSession struct{}
|
|||||||
func (e ErrServerInvalidSession) Error() string {
|
func (e ErrServerInvalidSession) Error() string {
|
||||||
return "invalid session"
|
return "invalid session"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrServerPathHasChanged is an error that can be returned by a server.
|
||||||
|
type ErrServerPathHasChanged struct {
|
||||||
|
Prev string
|
||||||
|
Cur string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ErrServerPathHasChanged) Error() string {
|
||||||
|
return fmt.Sprintf("path has changed, was '%s', now is '%s'", e.Prev, e.Cur)
|
||||||
|
}
|
||||||
|
@@ -769,6 +769,13 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
|
|
||||||
path, query := base.PathSplitQuery(pathAndQuery)
|
path, query := base.PathSplitQuery(pathAndQuery)
|
||||||
|
|
||||||
|
if ss.State() == ServerSessionStatePrePlay &&
|
||||||
|
path != *ss.setuppedPath {
|
||||||
|
return &base.Response{
|
||||||
|
StatusCode: base.StatusBadRequest,
|
||||||
|
}, liberrors.ErrServerPathHasChanged{Prev: *ss.setuppedPath, Cur: path}
|
||||||
|
}
|
||||||
|
|
||||||
res, err := sc.s.Handler.(ServerHandlerOnPlay).OnPlay(&ServerHandlerOnPlayCtx{
|
res, err := sc.s.Handler.(ServerHandlerOnPlay).OnPlay(&ServerHandlerOnPlayCtx{
|
||||||
Session: ss,
|
Session: ss,
|
||||||
Conn: sc,
|
Conn: sc,
|
||||||
@@ -884,6 +891,12 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
ss.tcpConn = sc
|
ss.tcpConn = sc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if path != *ss.setuppedPath {
|
||||||
|
return &base.Response{
|
||||||
|
StatusCode: base.StatusBadRequest,
|
||||||
|
}, liberrors.ErrServerPathHasChanged{Prev: *ss.setuppedPath, Cur: path}
|
||||||
|
}
|
||||||
|
|
||||||
res, err := ss.s.Handler.(ServerHandlerOnRecord).OnRecord(&ServerHandlerOnRecordCtx{
|
res, err := ss.s.Handler.(ServerHandlerOnRecord).OnRecord(&ServerHandlerOnRecordCtx{
|
||||||
Session: ss,
|
Session: ss,
|
||||||
Conn: sc,
|
Conn: sc,
|
||||||
|
Reference in New Issue
Block a user