1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

support more splash in http url. remove the strip of SrsRequest, use srs_string_remove instead, change to 0.9.44

This commit is contained in:
winlin 2014-04-03 15:53:56 +08:00
parent f2216691f9
commit b71eb0d49a
8 changed files with 77 additions and 42 deletions

View file

@ -111,11 +111,11 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine)
// output stream, to other/self server // output stream, to other/self server
// ie. rtmp://127.0.0.1:1935/live/livestream_sd // ie. rtmp://127.0.0.1:1935/live/livestream_sd
output = srs_replace(output, "[vhost]", req->vhost); output = srs_string_replace(output, "[vhost]", req->vhost);
output = srs_replace(output, "[port]", req->port); output = srs_string_replace(output, "[port]", req->port);
output = srs_replace(output, "[app]", req->app); output = srs_string_replace(output, "[app]", req->app);
output = srs_replace(output, "[stream]", req->stream); output = srs_string_replace(output, "[stream]", req->stream);
output = srs_replace(output, "[engine]", engine->arg0()); output = srs_string_replace(output, "[engine]", engine->arg0());
// write ffmpeg info to log file. // write ffmpeg info to log file.
log_file = _srs_config->get_ffmpeg_log_dir(); log_file = _srs_config->get_ffmpeg_log_dir();

View file

@ -338,7 +338,20 @@ void SrsHttpMessage::reset()
int SrsHttpMessage::parse_uri() 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() bool SrsHttpMessage::is_complete()

View file

@ -239,7 +239,6 @@ int SrsRtmpConn::stream_service_cycle()
srs_error("identify client failed. ret=%d", ret); srs_error("identify client failed. ret=%d", ret);
return ret; return ret;
} }
req->strip();
srs_trace("identify client success. type=%s, stream_name=%s", srs_trace("identify client success. type=%s, stream_name=%s",
srs_client_type_string(type).c_str(), req->stream.c_str()); srs_client_type_string(type).c_str(), req->stream.c_str());

View file

@ -27,7 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <netdb.h> #include <netdb.h>
#include <arpa/inet.h> #include <arpa/inet.h>
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; 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; size_t pos = 0;
while ((pos = ret.find(old_str, pos)) != std::string::npos) { while ((pos = ret.find(old_str, pos)) != std::string::npos) {
ret = ret.replace(pos, old_str.length(), new_str); ret = ret.replace(pos, old_str.length(), new_str);
pos += new_str.length();
} }
return ret; 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) { if (inet_addr(host.c_str()) != INADDR_NONE) {
return host; return host;

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version // current release version
#define VERSION_MAJOR "0" #define VERSION_MAJOR "0"
#define VERSION_MINOR "9" #define VERSION_MINOR "9"
#define VERSION_REVISION "43" #define VERSION_REVISION "44"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info. // server info.
#define RTMP_SIG_SRS_KEY "srs" #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 #define SIGNAL_RELOAD SIGHUP
#include <string> #include <string>
// replace utility // replace old_str to new_str of str
extern std::string srs_replace(std::string str, std::string old_str, std::string new_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. // dns resolve utility, return the resolved ip address.
extern std::string srs_dns_resolve(std::string host); extern std::string srs_dns_resolve(std::string host);
// whether system is little endian // whether system is little endian

View file

@ -127,7 +127,11 @@ int SrsRequest::discovery_app()
app = url; app = url;
vhost = host; vhost = host;
srs_vhost_resolve(vhost, app); 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; return ret;
} }
@ -145,30 +149,6 @@ string SrsRequest::get_stream_url()
return 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() SrsResponse::SrsResponse()
{ {
stream_id = SRS_DEFAULT_SID; stream_id = SRS_DEFAULT_SID;

View file

@ -82,9 +82,6 @@ public:
*/ */
virtual int discovery_app(); virtual int discovery_app();
virtual std::string get_stream_url(); virtual std::string get_stream_url();
virtual void strip();
private:
std::string& trim(std::string& str, std::string chs);
}; };
/** /**

View file

@ -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) void srs_vhost_resolve(std::string& vhost, std::string& app)
{ {
app = srs_replace(app, "...", "?"); app = srs_string_replace(app, "...", "?");
size_t pos = 0; size_t pos = 0;
if ((pos = app.find("?")) == std::string::npos) { if ((pos = app.find("?")) == std::string::npos) {