diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index 494a50193..05cac25ef 100755 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -1049,6 +1049,18 @@ srs_error_t SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandle return err; } } + + // For HTTP-FLV stream, the template must have the same schema with upath. + // The template is defined in config, the mout of http stream. The upath is specified by http request path. + // If template is "[vhost]/[app]/[stream].flv", the upath should be: + // matched for "/live/livestream.flv" + // matched for "ossrs.net/live/livestream.flv" + // not-matched for "/livestream.flv", which is actually "/__defaultApp__/livestream.flv", HTTP not support default app. + // not-matched for "/live/show/livestream.flv" + string upath = request->path(); + if (srs_string_count(upath, "/") != srs_string_count(entry->mount, "/")) { + return err; + } // convert to concreate class. SrsHttpMessage* hreq = dynamic_cast(request); diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index 9a2b7c46c..b1f8a0cdd 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -37,6 +37,7 @@ #include #include +#include using namespace std; #include @@ -451,6 +452,16 @@ bool srs_string_contains(string str, string flag0, string flag1, string flag2) return str.find(flag0) != string::npos || str.find(flag1) != string::npos || str.find(flag2) != string::npos; } +int srs_string_count(string str, string flag) +{ + int nn = 0; + for (int i = 0; i < (int)flag.length(); i++) { + char ch = flag.at(i); + nn += std::count(str.begin(), str.end(), ch); + } + return nn; +} + vector srs_string_split(string str, string flag) { vector arr; diff --git a/trunk/src/kernel/srs_kernel_utility.hpp b/trunk/src/kernel/srs_kernel_utility.hpp index 3b55a520f..30a8b5568 100644 --- a/trunk/src/kernel/srs_kernel_utility.hpp +++ b/trunk/src/kernel/srs_kernel_utility.hpp @@ -98,6 +98,8 @@ extern bool srs_string_starts_with(std::string str, std::string flag0, std::stri extern bool srs_string_contains(std::string str, std::string flag); extern bool srs_string_contains(std::string str, std::string flag0, std::string flag1); extern bool srs_string_contains(std::string str, std::string flag0, std::string flag1, std::string flag2); +// Count each char of flag in string +extern int srs_string_count(std::string str, std::string flag); // Find the min match in str for flags. extern std::string srs_string_min_match(std::string str, std::vector flags); // Split the string by flag to array. diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index 7f0479ddb..2843c304e 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -2318,6 +2318,14 @@ VOID TEST(KernelUtility, StringUtils) EXPECT_TRUE(srs_string_contains("srs", "s", "sr")); EXPECT_TRUE(srs_string_contains("srs", "s", "sr", "srs")); } + + if (true) { + EXPECT_EQ(0, srs_string_count("srs", "y")); + EXPECT_EQ(0, srs_string_count("srs", "")); + EXPECT_EQ(1, srs_string_count("srs", "r")); + EXPECT_EQ(2, srs_string_count("srs", "s")); + EXPECT_EQ(3, srs_string_count("srs", "sr")); + } if (true) { vector flags;