From b545364ac1768f67812abb1cbaf5fd589d97424f Mon Sep 17 00:00:00 2001 From: q191201771 <191201771@qq.com> Date: Fri, 27 May 2022 20:31:24 +0800 Subject: [PATCH] [patch] prev pr patch --- pkg/logic/server_manager.go | 2 +- pkg/rtsp/server.go | 6 +++--- pkg/rtsp/server_command_session.go | 17 +++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/logic/server_manager.go b/pkg/logic/server_manager.go index 579e3af..dd5e8ad 100644 --- a/pkg/logic/server_manager.go +++ b/pkg/logic/server_manager.go @@ -126,7 +126,7 @@ Doc: %s sm.rtmpServer = rtmp.NewServer(sm.config.RtmpConfig.Addr, sm) } if sm.config.RtspConfig.Enable { - sm.rtspServer = rtsp.NewServer(sm.config.RtspConfig.Addr, sm, sm.config.RtspConfig.RtspServerAuthConfig) + sm.rtspServer = rtsp.NewServer(sm.config.RtspConfig.Addr, sm, sm.config.RtspConfig.ServerAuthConfig) } if sm.config.HttpApiConfig.Enable { sm.httpApiServer = NewHttpApiServer(sm.config.HttpApiConfig.Addr, sm) diff --git a/pkg/rtsp/server.go b/pkg/rtsp/server.go index 42b2156..fa0a117 100644 --- a/pkg/rtsp/server.go +++ b/pkg/rtsp/server.go @@ -49,7 +49,7 @@ type IServerObserver interface { OnDelRtspSubSession(session *SubSession) } -type RtspServerAuthConfig struct { +type ServerAuthConfig struct { AuthEnable bool `json:"auth_enable"` AuthMethod int `json:"auth_method"` UserName string `json:"username"` @@ -61,10 +61,10 @@ type Server struct { observer IServerObserver ln net.Listener - auth RtspServerAuthConfig + auth ServerAuthConfig } -func NewServer(addr string, observer IServerObserver, auth RtspServerAuthConfig) *Server { +func NewServer(addr string, observer IServerObserver, auth ServerAuthConfig) *Server { return &Server{ addr: addr, observer: observer, diff --git a/pkg/rtsp/server_command_session.go b/pkg/rtsp/server_command_session.go index 4f67a6c..e5b9882 100644 --- a/pkg/rtsp/server_command_session.go +++ b/pkg/rtsp/server_command_session.go @@ -55,13 +55,13 @@ type ServerCommandSession struct { prevConnStat connection.Stat staleStat *connection.Stat stat base.StatSession - auth RtspServerAuthConfig + auth ServerAuthConfig pubSession *PubSession subSession *SubSession } -func NewServerCommandSession(observer IServerCommandSessionObserver, conn net.Conn, auth RtspServerAuthConfig) *ServerCommandSession { +func NewServerCommandSession(observer IServerCommandSessionObserver, conn net.Conn, auth ServerAuthConfig) *ServerCommandSession { uk := base.GenUkRtspServerCommandSession() s := &ServerCommandSession{ uniqueKey: uk, @@ -291,17 +291,18 @@ func (session *ServerCommandSession) handleDescribe(requestCtx nazahttp.HttpReqM func (session *ServerCommandSession) handleAuthorized(requestCtx nazahttp.HttpReqMsgCtx) (string, error) { if requestCtx.Headers.Get(HeaderAuthorization) != "" { - auth_str := requestCtx.Headers.Get(HeaderAuthorization) - if strings.Contains(auth_str, AuthTypeBasic) { + authStr := requestCtx.Headers.Get(HeaderAuthorization) + if strings.Contains(authStr, AuthTypeBasic) { // Basic 鉴权 - auth_base64_client := strings.TrimLeft(auth_str, "Basic ") + authBase64Client := strings.TrimLeft(authStr, "Basic ") authstr := fmt.Sprintf("%s:%s", session.auth.UserName, session.auth.PassWord) - auth_base64_server := base64.StdEncoding.EncodeToString([]byte(authstr)) - if auth_base64_server == auth_base64_client { + authBase64Server := base64.StdEncoding.EncodeToString([]byte(authstr)) + if authBase64Server == authBase64Client { Log.Infof("[%s] Rtsp Basic auth success. uri=%s", session.uniqueKey, requestCtx.Uri) } else { - err := fmt.Errorf("Rtsp Basic auth failed, auth:%s", auth_base64_client) + // TODO(chef): [refactor] 错误放入base/error.go中 202205 + err := fmt.Errorf("rtsp basic auth failed, auth:%s", authBase64Client) return "", err } } else {