diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index aebee90c59..4e75b06f24 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -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(); diff --git a/trunk/src/kernel/srs_kernel_utility.hpp b/trunk/src/kernel/srs_kernel_utility.hpp index ad5dd5765b..0850748482 100644 --- a/trunk/src/kernel/srs_kernel_utility.hpp +++ b/trunk/src/kernel/srs_kernel_utility.hpp @@ -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 diff --git a/trunk/src/protocol/srs_rtmp_utility.cpp b/trunk/src/protocol/srs_rtmp_utility.cpp index c322a97968..b050488f02 100644 --- a/trunk/src/protocol/srs_rtmp_utility.cpp +++ b/trunk/src/protocol/srs_rtmp_utility.cpp @@ -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); diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index 46e82bcda3..5fd07a9bd1 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -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")); diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index 9bd2cc3f71..119acfd3ba 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -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()); } /**