add ignoring _definst_ at the end of app (#1261)

pull/1268/head
MakarovYaroslav 6 years ago committed by winlin
parent b2066cbf68
commit e62ac29f48

@ -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();

@ -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

@ -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);

@ -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"));

@ -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());
}
/**

Loading…
Cancel
Save