Skip to content

Commit

Permalink
add ignoring _definst_ at the end of app (#1261)
Browse files Browse the repository at this point in the history
  • Loading branch information
MakarovYaroslav authored and winlinvip committed Nov 11, 2018
1 parent b2066cb commit e62ac29
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
26 changes: 26 additions & 0 deletions trunk/src/kernel/srs_kernel_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,32 @@ string srs_string_remove(string str, string remove_chars)
return ret;
}

string srs_erase_first_substr(string str, string erase_string)
{
std::string ret = str;

size_t pos = ret.find(erase_string);

if (pos != std::string::npos)
{
ret.erase(pos, erase_string.length());
}
return ret;
}

string srs_erase_last_substr(string str, string erase_string)
{
std::string ret = str;

size_t pos = ret.rfind(erase_string);

if (pos != std::string::npos)
{
ret.erase(pos, erase_string.length());
}
return ret;
}

bool srs_string_ends_with(string str, string flag)
{
return str.rfind(flag) == str.length() - flag.length();
Expand Down
4 changes: 4 additions & 0 deletions trunk/src/kernel/srs_kernel_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ extern std::string srs_string_trim_end(std::string str, std::string trim_chars);
extern std::string srs_string_trim_start(std::string str, std::string trim_chars);
// remove char in remove_chars of str
extern std::string srs_string_remove(std::string str, std::string remove_chars);
// remove first substring from str
extern std::string srs_erase_first_substr(std::string str, std::string erase_string);
// remove last substring from str
extern std::string srs_erase_last_substr(std::string str, std::string erase_string);
// whether string end with
extern bool srs_string_ends_with(std::string str, std::string flag);
// whether string starts with
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/protocol/srs_rtmp_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ void srs_vhost_resolve(string& vhost, string& app, string& param)
app = srs_string_replace(app, "...", "?");
app = srs_string_replace(app, "&&", "?");
app = srs_string_replace(app, "=", "?");
if (srs_string_ends_with(app, "/_definst_")){
app = srs_erase_last_substr(app, "/_definst_");
}

if ((pos = app.find("?")) != std::string::npos) {
std::string query = app.substr(pos + 1);
Expand Down
12 changes: 12 additions & 0 deletions trunk/src/utest/srs_utest_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,18 @@ VOID TEST(KernelUtilityTest, UtilityString)

str1 = srs_string_remove(str, "ol");
EXPECT_STREQ("He, Wrd! He, SRS!", str1.c_str());

str1 = srs_erase_first_substr(str, "Hello");
EXPECT_STREQ(", World! Hello, SRS!", str1.c_str());

str1 = srs_erase_first_substr(str, "XX");
EXPECT_STREQ("Hello, World! Hello, SRS!", str1.c_str());

str1 = srs_erase_last_substr(str, "Hello");
EXPECT_STREQ("Hello, World! , SRS!", str1.c_str());

str1 = srs_erase_last_substr(str, "XX");
EXPECT_STREQ("Hello, World! Hello, SRS!", str1.c_str());

EXPECT_FALSE(srs_string_ends_with("Hello", "x"));
EXPECT_TRUE(srs_string_ends_with("Hello", "o"));
Expand Down
10 changes: 10 additions & 0 deletions trunk/src/utest/srs_utest_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,16 @@ VOID TEST(ProtocolUtilityTest, DiscoveryTcUrl)
EXPECT_STREQ("live", app.c_str());
EXPECT_STREQ("show", stream.c_str());
EXPECT_STREQ("19351", port.c_str());

// _definst_ at the end of app
tcUrl = "rtmp://winlin.cn/live/_definst_"; stream= "show";
srs_discovery_tc_url(tcUrl, schema, ip, vhost, app, stream, port, param);
EXPECT_STREQ("rtmp", schema.c_str());
EXPECT_STREQ("winlin.cn", ip.c_str());
EXPECT_STREQ("winlin.cn", vhost.c_str());
EXPECT_STREQ("live", app.c_str());
EXPECT_STREQ("show", stream.c_str());
EXPECT_STREQ("1935", port.c_str());
}

/**
Expand Down

0 comments on commit e62ac29

Please sign in to comment.