diff --git a/trunk/src/app/srs_app_encoder.cpp b/trunk/src/app/srs_app_encoder.cpp index f418e02a3..826255742 100644 --- a/trunk/src/app/srs_app_encoder.cpp +++ b/trunk/src/app/srs_app_encoder.cpp @@ -111,11 +111,11 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine) // output stream, to other/self server // ie. rtmp://127.0.0.1:1935/live/livestream_sd - output = srs_replace(output, "[vhost]", req->vhost); - output = srs_replace(output, "[port]", req->port); - output = srs_replace(output, "[app]", req->app); - output = srs_replace(output, "[stream]", req->stream); - output = srs_replace(output, "[engine]", engine->arg0()); + output = srs_string_replace(output, "[vhost]", req->vhost); + output = srs_string_replace(output, "[port]", req->port); + output = srs_string_replace(output, "[app]", req->app); + output = srs_string_replace(output, "[stream]", req->stream); + output = srs_string_replace(output, "[engine]", engine->arg0()); // write ffmpeg info to log file. log_file = _srs_config->get_ffmpeg_log_dir(); diff --git a/trunk/src/app/srs_app_http.cpp b/trunk/src/app/srs_app_http.cpp index aa2691e2a..40bc3bb24 100644 --- a/trunk/src/app/srs_app_http.cpp +++ b/trunk/src/app/srs_app_http.cpp @@ -338,7 +338,20 @@ void SrsHttpMessage::reset() int SrsHttpMessage::parse_uri() { - return _uri->initialize(_url); + // filter url according to HTTP specification. + + // remove the duplicated slash. + std::string filtered_url = srs_string_replace(_url, "//", "/"); + + // remove the last / to match resource. + filtered_url = srs_string_trim_end(filtered_url, "/"); + + // if empty, use root. + if (filtered_url.empty()) { + filtered_url = "/"; + } + + return _uri->initialize(filtered_url); } bool SrsHttpMessage::is_complete() diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 147bf2f00..f2802af2b 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -239,7 +239,6 @@ int SrsRtmpConn::stream_service_cycle() srs_error("identify client failed. ret=%d", ret); return ret; } - req->strip(); srs_trace("identify client success. type=%s, stream_name=%s", srs_client_type_string(type).c_str(), req->stream.c_str()); diff --git a/trunk/src/core/srs_core.cpp b/trunk/src/core/srs_core.cpp index cfc9e8ada..bfa353dec 100644 --- a/trunk/src/core/srs_core.cpp +++ b/trunk/src/core/srs_core.cpp @@ -27,7 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -std::string srs_replace(std::string str, std::string old_str, std::string new_str) +using namespace std; + +string srs_string_replace(string str, string old_str, string new_str) { std::string ret = str; @@ -38,13 +40,52 @@ std::string srs_replace(std::string str, std::string old_str, std::string new_st size_t pos = 0; while ((pos = ret.find(old_str, pos)) != std::string::npos) { ret = ret.replace(pos, old_str.length(), new_str); - pos += new_str.length(); } return ret; } -std::string srs_dns_resolve(std::string host) +string srs_string_trim_end(string str, string trim_chars) +{ + std::string ret = str; + + for (int i = 0; i < (int)trim_chars.length(); i++) { + char ch = trim_chars.at(i); + + while (!ret.empty() && ret.at(ret.length() - 1) == ch) { + ret.erase(ret.end() - 1); + + // ok, matched, should reset the search + i = 0; + } + } + + return ret; +} + +string srs_string_remove(string str, string remove_chars) +{ + std::string ret = str; + + for (int i = 0; i < (int)remove_chars.length(); i++) { + char ch = remove_chars.at(i); + + for (std::string::iterator it = ret.begin(); it != ret.end();) { + if (ch == *it) { + it = ret.erase(it); + + // ok, matched, should reset the search + i = 0; + } else { + ++it; + } + } + } + + return ret; +} + +string srs_dns_resolve(string host) { if (inet_addr(host.c_str()) != INADDR_NONE) { return host; diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 604d30397..774151bf5 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR "0" #define VERSION_MINOR "9" -#define VERSION_REVISION "43" +#define VERSION_REVISION "44" #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION // server info. #define RTMP_SIG_SRS_KEY "srs" @@ -91,8 +91,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define SIGNAL_RELOAD SIGHUP #include -// replace utility -extern std::string srs_replace(std::string str, std::string old_str, std::string new_str); +// replace old_str to new_str of str +extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str); +// trim char in trim_chars of str +extern std::string srs_string_trim_end(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); + // dns resolve utility, return the resolved ip address. extern std::string srs_dns_resolve(std::string host); // whether system is little endian diff --git a/trunk/src/rtmp/srs_protocol_rtmp.cpp b/trunk/src/rtmp/srs_protocol_rtmp.cpp index 53d71183a..b8a4c7bde 100644 --- a/trunk/src/rtmp/srs_protocol_rtmp.cpp +++ b/trunk/src/rtmp/srs_protocol_rtmp.cpp @@ -127,7 +127,11 @@ int SrsRequest::discovery_app() app = url; vhost = host; srs_vhost_resolve(vhost, app); - strip(); + + // remove the unsupported chars in names. + vhost = srs_string_remove(vhost, "/ \n\r\t"); + app = srs_string_remove(app, " \n\r\t"); + stream = srs_string_remove(stream, "/ \n\r\t"); return ret; } @@ -145,30 +149,6 @@ string SrsRequest::get_stream_url() return url; } -void SrsRequest::strip() -{ - trim(vhost, "/ \n\r\t"); - trim(app, "/ \n\r\t"); - trim(stream, "/ \n\r\t"); -} - -string& SrsRequest::trim(string& str, string chs) -{ - for (int i = 0; i < (int)chs.length(); i++) { - char ch = chs.at(i); - - for (std::string::iterator it = str.begin(); it != str.end();) { - if (ch == *it) { - it = str.erase(it); - } else { - ++it; - } - } - } - - return str; -} - SrsResponse::SrsResponse() { stream_id = SRS_DEFAULT_SID; diff --git a/trunk/src/rtmp/srs_protocol_rtmp.hpp b/trunk/src/rtmp/srs_protocol_rtmp.hpp index bafdfcfe7..0e642a7d2 100644 --- a/trunk/src/rtmp/srs_protocol_rtmp.hpp +++ b/trunk/src/rtmp/srs_protocol_rtmp.hpp @@ -82,9 +82,6 @@ public: */ virtual int discovery_app(); virtual std::string get_stream_url(); - virtual void strip(); -private: - std::string& trim(std::string& str, std::string chs); }; /** diff --git a/trunk/src/rtmp/srs_protocol_utility.cpp b/trunk/src/rtmp/srs_protocol_utility.cpp index 6ff8ae5ea..7f600ead4 100644 --- a/trunk/src/rtmp/srs_protocol_utility.cpp +++ b/trunk/src/rtmp/srs_protocol_utility.cpp @@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. void srs_vhost_resolve(std::string& vhost, std::string& app) { - app = srs_replace(app, "...", "?"); + app = srs_string_replace(app, "...", "?"); size_t pos = 0; if ((pos = app.find("?")) == std::string::npos) {