support more splash in http url. remove the strip of SrsRequest, use srs_string_…
…remove instead, change to 0.9.44
正在显示
8 个修改的文件
包含
77 行增加
和
42 行删除
| @@ -111,11 +111,11 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine) | @@ -111,11 +111,11 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine) | ||
| 111 | 111 | ||
| 112 | // output stream, to other/self server | 112 | // output stream, to other/self server |
| 113 | // ie. rtmp://127.0.0.1:1935/live/livestream_sd | 113 | // ie. rtmp://127.0.0.1:1935/live/livestream_sd |
| 114 | - output = srs_replace(output, "[vhost]", req->vhost); | ||
| 115 | - output = srs_replace(output, "[port]", req->port); | ||
| 116 | - output = srs_replace(output, "[app]", req->app); | ||
| 117 | - output = srs_replace(output, "[stream]", req->stream); | ||
| 118 | - output = srs_replace(output, "[engine]", engine->arg0()); | 114 | + output = srs_string_replace(output, "[vhost]", req->vhost); |
| 115 | + output = srs_string_replace(output, "[port]", req->port); | ||
| 116 | + output = srs_string_replace(output, "[app]", req->app); | ||
| 117 | + output = srs_string_replace(output, "[stream]", req->stream); | ||
| 118 | + output = srs_string_replace(output, "[engine]", engine->arg0()); | ||
| 119 | 119 | ||
| 120 | // write ffmpeg info to log file. | 120 | // write ffmpeg info to log file. |
| 121 | log_file = _srs_config->get_ffmpeg_log_dir(); | 121 | log_file = _srs_config->get_ffmpeg_log_dir(); |
| @@ -338,7 +338,20 @@ void SrsHttpMessage::reset() | @@ -338,7 +338,20 @@ void SrsHttpMessage::reset() | ||
| 338 | 338 | ||
| 339 | int SrsHttpMessage::parse_uri() | 339 | int SrsHttpMessage::parse_uri() |
| 340 | { | 340 | { |
| 341 | - return _uri->initialize(_url); | 341 | + // filter url according to HTTP specification. |
| 342 | + | ||
| 343 | + // remove the duplicated slash. | ||
| 344 | + std::string filtered_url = srs_string_replace(_url, "//", "/"); | ||
| 345 | + | ||
| 346 | + // remove the last / to match resource. | ||
| 347 | + filtered_url = srs_string_trim_end(filtered_url, "/"); | ||
| 348 | + | ||
| 349 | + // if empty, use root. | ||
| 350 | + if (filtered_url.empty()) { | ||
| 351 | + filtered_url = "/"; | ||
| 352 | + } | ||
| 353 | + | ||
| 354 | + return _uri->initialize(filtered_url); | ||
| 342 | } | 355 | } |
| 343 | 356 | ||
| 344 | bool SrsHttpMessage::is_complete() | 357 | bool SrsHttpMessage::is_complete() |
| @@ -239,7 +239,6 @@ int SrsRtmpConn::stream_service_cycle() | @@ -239,7 +239,6 @@ int SrsRtmpConn::stream_service_cycle() | ||
| 239 | srs_error("identify client failed. ret=%d", ret); | 239 | srs_error("identify client failed. ret=%d", ret); |
| 240 | return ret; | 240 | return ret; |
| 241 | } | 241 | } |
| 242 | - req->strip(); | ||
| 243 | srs_trace("identify client success. type=%s, stream_name=%s", | 242 | srs_trace("identify client success. type=%s, stream_name=%s", |
| 244 | srs_client_type_string(type).c_str(), req->stream.c_str()); | 243 | srs_client_type_string(type).c_str(), req->stream.c_str()); |
| 245 | 244 |
| @@ -27,7 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -27,7 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 27 | #include <netdb.h> | 27 | #include <netdb.h> |
| 28 | #include <arpa/inet.h> | 28 | #include <arpa/inet.h> |
| 29 | 29 | ||
| 30 | -std::string srs_replace(std::string str, std::string old_str, std::string new_str) | 30 | +using namespace std; |
| 31 | + | ||
| 32 | +string srs_string_replace(string str, string old_str, string new_str) | ||
| 31 | { | 33 | { |
| 32 | std::string ret = str; | 34 | std::string ret = str; |
| 33 | 35 | ||
| @@ -38,13 +40,52 @@ std::string srs_replace(std::string str, std::string old_str, std::string new_st | @@ -38,13 +40,52 @@ std::string srs_replace(std::string str, std::string old_str, std::string new_st | ||
| 38 | size_t pos = 0; | 40 | size_t pos = 0; |
| 39 | while ((pos = ret.find(old_str, pos)) != std::string::npos) { | 41 | while ((pos = ret.find(old_str, pos)) != std::string::npos) { |
| 40 | ret = ret.replace(pos, old_str.length(), new_str); | 42 | ret = ret.replace(pos, old_str.length(), new_str); |
| 41 | - pos += new_str.length(); | ||
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | return ret; | 45 | return ret; |
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | -std::string srs_dns_resolve(std::string host) | 48 | +string srs_string_trim_end(string str, string trim_chars) |
| 49 | +{ | ||
| 50 | + std::string ret = str; | ||
| 51 | + | ||
| 52 | + for (int i = 0; i < (int)trim_chars.length(); i++) { | ||
| 53 | + char ch = trim_chars.at(i); | ||
| 54 | + | ||
| 55 | + while (!ret.empty() && ret.at(ret.length() - 1) == ch) { | ||
| 56 | + ret.erase(ret.end() - 1); | ||
| 57 | + | ||
| 58 | + // ok, matched, should reset the search | ||
| 59 | + i = 0; | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + return ret; | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +string srs_string_remove(string str, string remove_chars) | ||
| 67 | +{ | ||
| 68 | + std::string ret = str; | ||
| 69 | + | ||
| 70 | + for (int i = 0; i < (int)remove_chars.length(); i++) { | ||
| 71 | + char ch = remove_chars.at(i); | ||
| 72 | + | ||
| 73 | + for (std::string::iterator it = ret.begin(); it != ret.end();) { | ||
| 74 | + if (ch == *it) { | ||
| 75 | + it = ret.erase(it); | ||
| 76 | + | ||
| 77 | + // ok, matched, should reset the search | ||
| 78 | + i = 0; | ||
| 79 | + } else { | ||
| 80 | + ++it; | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + return ret; | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +string srs_dns_resolve(string host) | ||
| 48 | { | 89 | { |
| 49 | if (inet_addr(host.c_str()) != INADDR_NONE) { | 90 | if (inet_addr(host.c_str()) != INADDR_NONE) { |
| 50 | return host; | 91 | return host; |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
| 33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
| 34 | -#define VERSION_REVISION "43" | 34 | +#define VERSION_REVISION "44" |
| 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "srs" | 37 | #define RTMP_SIG_SRS_KEY "srs" |
| @@ -91,8 +91,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -91,8 +91,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 91 | #define SIGNAL_RELOAD SIGHUP | 91 | #define SIGNAL_RELOAD SIGHUP |
| 92 | 92 | ||
| 93 | #include <string> | 93 | #include <string> |
| 94 | -// replace utility | ||
| 95 | -extern std::string srs_replace(std::string str, std::string old_str, std::string new_str); | 94 | +// replace old_str to new_str of str |
| 95 | +extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str); | ||
| 96 | +// trim char in trim_chars of str | ||
| 97 | +extern std::string srs_string_trim_end(std::string str, std::string trim_chars); | ||
| 98 | +// remove char in remove_chars of str | ||
| 99 | +extern std::string srs_string_remove(std::string str, std::string remove_chars); | ||
| 100 | + | ||
| 96 | // dns resolve utility, return the resolved ip address. | 101 | // dns resolve utility, return the resolved ip address. |
| 97 | extern std::string srs_dns_resolve(std::string host); | 102 | extern std::string srs_dns_resolve(std::string host); |
| 98 | // whether system is little endian | 103 | // whether system is little endian |
| @@ -127,7 +127,11 @@ int SrsRequest::discovery_app() | @@ -127,7 +127,11 @@ int SrsRequest::discovery_app() | ||
| 127 | app = url; | 127 | app = url; |
| 128 | vhost = host; | 128 | vhost = host; |
| 129 | srs_vhost_resolve(vhost, app); | 129 | srs_vhost_resolve(vhost, app); |
| 130 | - strip(); | 130 | + |
| 131 | + // remove the unsupported chars in names. | ||
| 132 | + vhost = srs_string_remove(vhost, "/ \n\r\t"); | ||
| 133 | + app = srs_string_remove(app, " \n\r\t"); | ||
| 134 | + stream = srs_string_remove(stream, "/ \n\r\t"); | ||
| 131 | 135 | ||
| 132 | return ret; | 136 | return ret; |
| 133 | } | 137 | } |
| @@ -145,30 +149,6 @@ string SrsRequest::get_stream_url() | @@ -145,30 +149,6 @@ string SrsRequest::get_stream_url() | ||
| 145 | return url; | 149 | return url; |
| 146 | } | 150 | } |
| 147 | 151 | ||
| 148 | -void SrsRequest::strip() | ||
| 149 | -{ | ||
| 150 | - trim(vhost, "/ \n\r\t"); | ||
| 151 | - trim(app, "/ \n\r\t"); | ||
| 152 | - trim(stream, "/ \n\r\t"); | ||
| 153 | -} | ||
| 154 | - | ||
| 155 | -string& SrsRequest::trim(string& str, string chs) | ||
| 156 | -{ | ||
| 157 | - for (int i = 0; i < (int)chs.length(); i++) { | ||
| 158 | - char ch = chs.at(i); | ||
| 159 | - | ||
| 160 | - for (std::string::iterator it = str.begin(); it != str.end();) { | ||
| 161 | - if (ch == *it) { | ||
| 162 | - it = str.erase(it); | ||
| 163 | - } else { | ||
| 164 | - ++it; | ||
| 165 | - } | ||
| 166 | - } | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | - return str; | ||
| 170 | -} | ||
| 171 | - | ||
| 172 | SrsResponse::SrsResponse() | 152 | SrsResponse::SrsResponse() |
| 173 | { | 153 | { |
| 174 | stream_id = SRS_DEFAULT_SID; | 154 | stream_id = SRS_DEFAULT_SID; |
| @@ -82,9 +82,6 @@ public: | @@ -82,9 +82,6 @@ public: | ||
| 82 | */ | 82 | */ |
| 83 | virtual int discovery_app(); | 83 | virtual int discovery_app(); |
| 84 | virtual std::string get_stream_url(); | 84 | virtual std::string get_stream_url(); |
| 85 | - virtual void strip(); | ||
| 86 | -private: | ||
| 87 | - std::string& trim(std::string& str, std::string chs); | ||
| 88 | }; | 85 | }; |
| 89 | 86 | ||
| 90 | /** | 87 | /** |
| @@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 29 | 29 | ||
| 30 | void srs_vhost_resolve(std::string& vhost, std::string& app) | 30 | void srs_vhost_resolve(std::string& vhost, std::string& app) |
| 31 | { | 31 | { |
| 32 | - app = srs_replace(app, "...", "?"); | 32 | + app = srs_string_replace(app, "...", "?"); |
| 33 | 33 | ||
| 34 | size_t pos = 0; | 34 | size_t pos = 0; |
| 35 | if ((pos = app.find("?")) == std::string::npos) { | 35 | if ((pos = app.find("?")) == std::string::npos) { |
-
请 注册 或 登录 后发表评论