From ca36226491b6a50d44ff394cd4ff09303f11d59d Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Fri, 11 Aug 2023 15:21:49 +0500 Subject: [PATCH] Stream key not involved until publish stage, just check if proper command and app --- rtmp/amf/command.go | 31 ++++++++++++++++--------------- rtmp/chunk_wrap.go | 25 ++----------------------- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/rtmp/amf/command.go b/rtmp/amf/command.go index e9c2609..a1e3621 100644 --- a/rtmp/amf/command.go +++ b/rtmp/amf/command.go @@ -2,30 +2,31 @@ package amf import "errors" -func (amf_obj_root AMFObj) ProcessConnect() (string, error) { - err := errors.New("Bad AMF connect command") +func (amf_obj_root AMFObj) ProcessConnect() (err error) { + err = errors.New("Bad AMF connect command") if _, ok := amf_obj_root[0]; !ok { - return "", err + return } else if command_string, ok := amf_obj_root[0].(string); !ok || command_string != "connect" { - return "", err + return } if _, ok := amf_obj_root[1]; !ok { - return "", err + return } else if transac_id_float, ok := amf_obj_root[1].(float64); !ok || transac_id_float != 1.0 { - return "", err + return } if _, ok := amf_obj_root[2]; !ok { - return "", err + return } else if _, ok := amf_obj_root[2].(AMFObj); !ok { - return "", err - } else if _, ok := amf_obj_root[2].(AMFObj)["tcUrl"]; !ok { - return "", err - } else if tcUrl, ok := amf_obj_root[2].(AMFObj)["tcUrl"].(string); ok { - return tcUrl, nil - } else { - return "", err + return + } else if _, ok := amf_obj_root[2].(AMFObj)["app"]; !ok { + return + } else if _, ok := amf_obj_root[2].(AMFObj)["app"].(string); !ok { + return + } else if amf_obj_root[2].(AMFObj)["app"].(string) != "live" { + return } - + err = nil + return } diff --git a/rtmp/chunk_wrap.go b/rtmp/chunk_wrap.go index ff46e52..927adda 100644 --- a/rtmp/chunk_wrap.go +++ b/rtmp/chunk_wrap.go @@ -4,10 +4,6 @@ import ( "net" "encoding/binary" "stream_server/rtmp/amf" - "errors" - "strings" - "fmt" - "os" ) type ChunkWrapper struct { @@ -70,27 +66,10 @@ func (chnk_wrp_ptr *ChunkWrapper) ReadConnectCommand() (error) { if err != nil { return err } - tcUrl, err := amf_obj.ProcessConnect() + err = amf_obj.ProcessConnect() if err != nil { return err } - if chnk_wrp_ptr.params.stream_key, err = check_stream_key(tcUrl); err != nil { - return err - } - return nil -} + return err -func check_stream_key(tcUrl string) (string, error) { - err := errors.New("bad stream key") - tcUrl_split := strings.Split(tcUrl, "/") - if len(tcUrl_split) != 5 { - return "", err - } - base_dir, _ := os.UserHomeDir() - stream_dir := base_dir + "/live/" + tcUrl_split[4] - fileinfo, err := os.Stat(stream_dir) - if err == nil && fileinfo.IsDir() { - return tcUrl_split[4], nil - } - return "", err }