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:
parent
f2216691f9
commit
b71eb0d49a
8 changed files with 77 additions and 42 deletions
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -27,7 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <netdb.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;
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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 <string>
|
||||
// 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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue