mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine the protocol utility, add utest, 0.9.140
This commit is contained in:
parent
6a2f0a3dc9
commit
051c9e6268
9 changed files with 203 additions and 45 deletions
|
@ -124,41 +124,6 @@ void SrsRequest::update_auth(SrsRequest* req)
|
|||
srs_info("update req of soruce for auth ok");
|
||||
}
|
||||
|
||||
int SrsRequest::discovery_app()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
size_t pos = std::string::npos;
|
||||
std::string url = tcUrl;
|
||||
|
||||
if ((pos = url.find("://")) != std::string::npos) {
|
||||
schema = url.substr(0, pos);
|
||||
url = url.substr(schema.length() + 3);
|
||||
srs_verbose("discovery schema=%s", schema.c_str());
|
||||
}
|
||||
|
||||
if ((pos = url.find("/")) != std::string::npos) {
|
||||
host = url.substr(0, pos);
|
||||
url = url.substr(host.length() + 1);
|
||||
srs_verbose("discovery host=%s", host.c_str());
|
||||
}
|
||||
|
||||
port = RTMP_DEFAULT_PORT;
|
||||
if ((pos = host.find(":")) != std::string::npos) {
|
||||
port = host.substr(pos + 1);
|
||||
host = host.substr(0, pos);
|
||||
srs_verbose("discovery host=%s, port=%s", host.c_str(), port.c_str());
|
||||
}
|
||||
|
||||
app = url;
|
||||
vhost = host;
|
||||
srs_vhost_resolve(vhost, app);
|
||||
|
||||
strip();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
string SrsRequest::get_stream_url()
|
||||
{
|
||||
std::string url = "";
|
||||
|
@ -867,7 +832,10 @@ int SrsRtmpServer::connect_app(SrsRequest* req)
|
|||
|
||||
srs_info("get connect app message params success.");
|
||||
|
||||
return req->discovery_app();
|
||||
srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->port);
|
||||
req->strip();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsRtmpServer::set_window_ack_size(int ack_size)
|
||||
|
|
|
@ -98,9 +98,8 @@ public:
|
|||
virtual void update_auth(SrsRequest* req);
|
||||
|
||||
/**
|
||||
* disconvery vhost/app from tcUrl.
|
||||
* get the stream identify, vhost/app/stream.
|
||||
*/
|
||||
virtual int discovery_app();
|
||||
virtual std::string get_stream_url();
|
||||
|
||||
// strip url, user must strip when update the url.
|
||||
|
|
|
@ -29,9 +29,43 @@ using namespace std;
|
|||
#include <srs_kernel_log.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
|
||||
void srs_discovery_tc_url(
|
||||
string tcUrl,
|
||||
string& schema, string& host, string& vhost,
|
||||
string& app, string& port
|
||||
) {
|
||||
size_t pos = std::string::npos;
|
||||
std::string url = tcUrl;
|
||||
|
||||
if ((pos = url.find("://")) != std::string::npos) {
|
||||
schema = url.substr(0, pos);
|
||||
url = url.substr(schema.length() + 3);
|
||||
srs_info("discovery schema=%s", schema.c_str());
|
||||
}
|
||||
|
||||
if ((pos = url.find("/")) != std::string::npos) {
|
||||
host = url.substr(0, pos);
|
||||
url = url.substr(host.length() + 1);
|
||||
srs_info("discovery host=%s", host.c_str());
|
||||
}
|
||||
|
||||
port = RTMP_DEFAULT_PORT;
|
||||
if ((pos = host.find(":")) != std::string::npos) {
|
||||
port = host.substr(pos + 1);
|
||||
host = host.substr(0, pos);
|
||||
srs_info("discovery host=%s, port=%s", host.c_str(), port.c_str());
|
||||
}
|
||||
|
||||
app = url;
|
||||
vhost = host;
|
||||
srs_vhost_resolve(vhost, app);
|
||||
}
|
||||
|
||||
void srs_vhost_resolve(string& vhost, string& app)
|
||||
{
|
||||
app = srs_string_replace(app, "...", "?");
|
||||
app = srs_string_replace(app, "&&", "?");
|
||||
app = srs_string_replace(app, "=", "?");
|
||||
|
||||
size_t pos = 0;
|
||||
if ((pos = app.find("?")) == std::string::npos) {
|
||||
|
@ -41,15 +75,14 @@ void srs_vhost_resolve(string& vhost, string& app)
|
|||
std::string query = app.substr(pos + 1);
|
||||
app = app.substr(0, pos);
|
||||
|
||||
if ((pos = query.find("vhost?")) != std::string::npos
|
||||
|| (pos = query.find("vhost=")) != std::string::npos
|
||||
|| (pos = query.find("Vhost?")) != std::string::npos
|
||||
|| (pos = query.find("Vhost=")) != std::string::npos
|
||||
) {
|
||||
if ((pos = query.find("vhost?")) != std::string::npos) {
|
||||
query = query.substr(pos + 6);
|
||||
if (!query.empty()) {
|
||||
vhost = query;
|
||||
}
|
||||
if ((pos = vhost.find("?")) != std::string::npos) {
|
||||
vhost = vhost.substr(0, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
// the default chunk size for system.
|
||||
#define SRS_CONF_DEFAULT_CHUNK_SIZE 60000
|
||||
|
||||
// parse the tcUrl, output the schema, host, vhost, app and port.
|
||||
extern void srs_discovery_tc_url(
|
||||
std::string tcUrl,
|
||||
std::string& schema, std::string& host, std::string& vhost,
|
||||
std::string& app, std::string& port
|
||||
);
|
||||
|
||||
// resolve the vhost in query string
|
||||
// @param app, may contains the vhost in query string format:
|
||||
// app?vhost=request_vhost
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue