From d7437834d416e35a9031a7dd39ca09776e7966c6 Mon Sep 17 00:00:00 2001 From: runner365 Date: Thu, 23 Jan 2020 16:12:22 +0800 Subject: [PATCH] update is_streamid_valid --- trunk/src/srt/srt_conn.hpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/trunk/src/srt/srt_conn.hpp b/trunk/src/srt/srt_conn.hpp index 6801a1c84..9c46d05bd 100644 --- a/trunk/src/srt/srt_conn.hpp +++ b/trunk/src/srt/srt_conn.hpp @@ -20,12 +20,29 @@ inline bool is_streamid_valid(const std::string& streamid) { if (streamid.empty()) { return ret; } + //check whether subpath is valid, eg. live/test or srs.srt.com.cn/live/test std::vector ret_vec; string_split(streamid, "/", ret_vec); - if (ret_vec.size() < 2) { return ret; } + + //check whether mode is valid, eg. live/test?m=push or live/test?m=pull + size_t pos = streamid.find("?"); + if (pos == streamid.npos) { + return ret; + } + + std::string mode = streamid.substr(pos+1); + string_split(mode, "=", ret_vec); + if (ret_vec.size() != 2) { + return ret; + } + //it must be m=push or m=pull + std::string mode_oper = string_lower(ret_vec[1]); + if ((ret_vec[0] != "m") || ((mode_oper != "push") && (mode_oper != "pull"))) { + return ret; + } ret = true; return ret; } @@ -35,7 +52,7 @@ inline void get_streamid_info(const std::string& streamid, int& mode, std::strin size_t pos = streamid.find("?"); if (pos == std::string::npos) { - mode = PULL_SRT_MODE; + mode = ERR_SRT_MODE; url_subpash = streamid; } else { std::string mode_str = streamid.substr(pos+1);