mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +00:00 
			
		
		
		
	SRT: Compatible with previous auth querystring. #2908
This commit is contained in:
		
							parent
							
								
									210cdf04be
								
							
						
					
					
						commit
						41e35155f7
					
				
					 2 changed files with 29 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -11,6 +11,7 @@
 | 
			
		|||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include <srs_protocol_utility.hpp>
 | 
			
		||||
#include <srs_kernel_utility.hpp>
 | 
			
		||||
#include <srs_app_config.hpp>
 | 
			
		||||
 | 
			
		||||
bool is_streamid_valid(const std::string& streamid) {
 | 
			
		||||
| 
						 | 
				
			
			@ -93,16 +94,23 @@ bool get_streamid_info(const std::string& streamid, int& mode, std::string& vhos
 | 
			
		|||
    std::string real_streamid;
 | 
			
		||||
    real_streamid = streamid.substr(4);
 | 
			
		||||
 | 
			
		||||
    // Compatible with previous auth querystring, like this one:
 | 
			
		||||
    //      srt://127.0.0.1:10080?streamid=#!::h=live/livestream?secret=xxx,m=publish
 | 
			
		||||
    real_streamid = srs_string_replace(real_streamid, "?", ",");
 | 
			
		||||
 | 
			
		||||
    std::map<std::string, std::string> query;
 | 
			
		||||
    srs_parse_query_string(real_streamid, query);
 | 
			
		||||
    for (std::map<std::string, std::string>::iterator it = query.begin(); it != query.end(); ++it) {
 | 
			
		||||
        if (it->first == "h") {
 | 
			
		||||
            std::string host = it->second;
 | 
			
		||||
 | 
			
		||||
            // Compatible with previous style, see https://github.com/ossrs/srs/issues/2893#compatible
 | 
			
		||||
            size_t r0 = host.find("/");
 | 
			
		||||
            size_t r1 = host.rfind("/");
 | 
			
		||||
            if (r0 != std::string::npos && r0 != std::string::npos) {
 | 
			
		||||
                // Compatible with previous style, see https://github.com/ossrs/srs/issues/2893#compatible
 | 
			
		||||
                //      srt://127.0.0.1:10080?streamid=#!::h=live/livestream,m=publish
 | 
			
		||||
                //      srt://127.0.0.1:10080?streamid=#!::h=live/livestream,m=request
 | 
			
		||||
                //      srt://127.0.0.1:10080?streamid=#!::h=srs.srt.com.cn/live/livestream,m=publish
 | 
			
		||||
                if (r0 != r1) {
 | 
			
		||||
                    // We got vhost in host.
 | 
			
		||||
                    url_subpath = host.substr(r0 + 1);
 | 
			
		||||
| 
						 | 
				
			
			@ -117,7 +125,10 @@ bool get_streamid_info(const std::string& streamid, int& mode, std::string& vhos
 | 
			
		|||
                    url_subpath = host;
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                // Now we get the host as vhost.
 | 
			
		||||
                // New URL style, see https://github.com/ossrs/srs/issues/2893#solution
 | 
			
		||||
                //      srt://host.com:10080?streamid=#!::h=host.com,r=app/stream,key1=value1,key2=value2
 | 
			
		||||
                //      srt://1.2.3.4:10080?streamid=#!::h=host.com,r=app/stream,key1=value1,key2=value2
 | 
			
		||||
                //      srt://1.2.3.4:10080?streamid=#!::r=app/stream,key1=value1,key2=value2
 | 
			
		||||
                params.append("vhost=");
 | 
			
		||||
                params.append(host);
 | 
			
		||||
                params.append("&");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,9 +12,8 @@
 | 
			
		|||
using namespace std;
 | 
			
		||||
 | 
			
		||||
VOID TEST(ProtocolSrtTest, SrtGetStreamInfoNormal) {
 | 
			
		||||
    int mode; string vhost; string subpath;
 | 
			
		||||
 | 
			
		||||
    if (true) {
 | 
			
		||||
        int mode; string vhost; string subpath;
 | 
			
		||||
        EXPECT_TRUE(get_streamid_info("#!::r=live/livestream,key1=value1,key2=value2", mode, vhost, subpath));
 | 
			
		||||
        EXPECT_EQ(PULL_SRT_MODE, mode);
 | 
			
		||||
        EXPECT_STREQ("", vhost.c_str());
 | 
			
		||||
| 
						 | 
				
			
			@ -22,6 +21,7 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoNormal) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    if (true) {
 | 
			
		||||
        int mode; string vhost; string subpath;
 | 
			
		||||
        EXPECT_TRUE(get_streamid_info("#!::h=host.com,r=live/livestream,key1=value1,key2=value2", mode, vhost, subpath));
 | 
			
		||||
        EXPECT_EQ(PULL_SRT_MODE, mode);
 | 
			
		||||
        EXPECT_STREQ("host.com", vhost.c_str());
 | 
			
		||||
| 
						 | 
				
			
			@ -30,15 +30,15 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoNormal) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
VOID TEST(ProtocolSrtTest, SrtGetStreamInfoMethod) {
 | 
			
		||||
    int mode; string vhost; string subpath;
 | 
			
		||||
 | 
			
		||||
    if (true) {
 | 
			
		||||
        int mode; string vhost; string subpath;
 | 
			
		||||
        EXPECT_TRUE(get_streamid_info("#!::r=live/livestream,m=request", mode, vhost, subpath));
 | 
			
		||||
        EXPECT_EQ(PULL_SRT_MODE, mode);
 | 
			
		||||
        EXPECT_STREQ("live/livestream", subpath.c_str());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (true) {
 | 
			
		||||
        int mode; string vhost; string subpath;
 | 
			
		||||
        EXPECT_TRUE(get_streamid_info("#!::r=live/livestream,m=publish", mode, vhost, subpath));
 | 
			
		||||
        EXPECT_EQ(PUSH_SRT_MODE, mode);
 | 
			
		||||
        EXPECT_STREQ("live/livestream", subpath.c_str());
 | 
			
		||||
| 
						 | 
				
			
			@ -46,9 +46,8 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoMethod) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
VOID TEST(ProtocolSrtTest, SrtGetStreamInfoCompatible) {
 | 
			
		||||
    int mode; string vhost; string subpath;
 | 
			
		||||
 | 
			
		||||
    if (true) {
 | 
			
		||||
        int mode; string vhost; string subpath;
 | 
			
		||||
        EXPECT_TRUE(get_streamid_info("#!::h=live/livestream,m=request", mode, vhost, subpath));
 | 
			
		||||
        EXPECT_EQ(PULL_SRT_MODE, mode);
 | 
			
		||||
        EXPECT_STREQ("", vhost.c_str());
 | 
			
		||||
| 
						 | 
				
			
			@ -56,6 +55,7 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoCompatible) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    if (true) {
 | 
			
		||||
        int mode; string vhost; string subpath;
 | 
			
		||||
        EXPECT_TRUE(get_streamid_info("#!::h=live/livestream,m=publish", mode, vhost, subpath));
 | 
			
		||||
        EXPECT_EQ(PUSH_SRT_MODE, mode);
 | 
			
		||||
        EXPECT_STREQ("", vhost.c_str());
 | 
			
		||||
| 
						 | 
				
			
			@ -63,6 +63,7 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoCompatible) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    if (true) {
 | 
			
		||||
        int mode; string vhost; string subpath;
 | 
			
		||||
        EXPECT_TRUE(get_streamid_info("#!::h=srs.srt.com.cn/live/livestream,m=request", mode, vhost, subpath));
 | 
			
		||||
        EXPECT_EQ(PULL_SRT_MODE, mode);
 | 
			
		||||
        EXPECT_STREQ("srs.srt.com.cn", vhost.c_str());
 | 
			
		||||
| 
						 | 
				
			
			@ -70,10 +71,19 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoCompatible) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    if (true) {
 | 
			
		||||
        int mode; string vhost; string subpath;
 | 
			
		||||
        EXPECT_TRUE(get_streamid_info("#!::h=srs.srt.com.cn/live/livestream,m=publish", mode, vhost, subpath));
 | 
			
		||||
        EXPECT_EQ(PUSH_SRT_MODE, mode);
 | 
			
		||||
        EXPECT_STREQ("srs.srt.com.cn", vhost.c_str());
 | 
			
		||||
        EXPECT_STREQ("live/livestream?vhost=srs.srt.com.cn", subpath.c_str());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (true) {
 | 
			
		||||
        int mode; string vhost; string subpath;
 | 
			
		||||
        EXPECT_TRUE(get_streamid_info("#!::h=live/livestream?secret=d6d2be37,m=publish", mode, vhost, subpath));
 | 
			
		||||
        EXPECT_EQ(PUSH_SRT_MODE, mode);
 | 
			
		||||
        EXPECT_STREQ("", vhost.c_str());
 | 
			
		||||
        EXPECT_STREQ("live/livestream?secret=d6d2be37", subpath.c_str());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue