Skip to content

Commit

Permalink
Fix #1059, support vhost in stream parameters. 2.0.246
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 13, 2018
1 parent 366309c commit 1721e4e
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 68 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ Remark:

## History

* v2.0, 2018-02-13, Fix [#1059][bug #1059], support vhost in stream parameters. 2.0.246
* v2.0, 2018-01-07, Merge [#1045][bug #1045], fix [#1044][bug #1044], TCP connection alive detection. 2.0.245
* v2.0, 2018-01-04, Merge [#1039][bug #1039], fix bug of init.d script.
* v2.0, 2018-01-01, Merge [#1033][bug #1033], allow user to add some specific flags. 2.0.244
Expand Down Expand Up @@ -1303,6 +1304,7 @@ Winlin
[bug #1039]: https://github.com/ossrs/srs/issues/1039
[bug #1044]: https://github.com/ossrs/srs/issues/1044
[bug #1045]: https://github.com/ossrs/srs/issues/1045
[bug #1059]: https://github.com/ossrs/srs/issues/1059
[bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx

[exo #828]: https://github.com/google/ExoPlayer/pull/828
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_caster_flv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ int SrsDynamicHttpConn::connect()
}

srs_discovery_tc_url(req->tcUrl,
req->schema, req->host, req->vhost, req->app, req->port,
req->schema, req->host, req->vhost, req->app, req->stream, req->port,
req->param);
}

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ SrsRequest* SrsHttpMessage::to_request(string vhost)
req->objectEncoding = 0;

srs_discovery_tc_url(req->tcUrl,
req->schema, req->host, req->vhost, req->app, req->port,
req->schema, req->host, req->vhost, req->app, req->stream, req->port,
req->param);
req->strip();

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_mpegts_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ int SrsMpegtsOverUdp::connect()
}

srs_discovery_tc_url(req->tcUrl,
req->schema, req->host, req->vhost, req->app, req->port,
req->schema, req->host, req->vhost, req->app, req->stream, req->port,
req->param);
}

Expand Down
77 changes: 40 additions & 37 deletions trunk/src/app/srs_app_rtmp_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ using namespace std;
#include <srs_kernel_utility.hpp>
#include <srs_app_security.hpp>
#include <srs_app_statistic.hpp>
#include <srs_rtmp_utility.hpp>

// when stream is busy, for example, streaming is already
// publishing, when a new client to request to publish,
Expand Down Expand Up @@ -149,30 +150,6 @@ int SrsRtmpConn::do_cycle()
// set client ip to request.
req->ip = ip;

// discovery vhost, resolve the vhost from config
SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req->vhost);
if (parsed_vhost) {
req->vhost = parsed_vhost->arg0();
}

srs_info("discovery app success. schema=%s, vhost=%s, port=%s, app=%s",
req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str());

if (req->schema.empty() || req->vhost.empty() || req->port.empty() || req->app.empty()) {
ret = ERROR_RTMP_REQ_TCURL;
srs_error("discovery tcUrl failed. "
"tcUrl=%s, schema=%s, vhost=%s, port=%s, app=%s, ret=%d",
req->tcUrl.c_str(), req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str(), ret);
return ret;
}

// check vhost
if ((ret = check_vhost()) != ERROR_SUCCESS) {
srs_error("check vhost failed. ret=%d", ret);
return ret;
}
srs_verbose("check vhost success.");

srs_trace("connect app, "
"tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%s, app=%s, args=%s",
req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(),
Expand Down Expand Up @@ -376,19 +353,6 @@ int SrsRtmpConn::service_cycle()
return bandwidth->bandwidth_check(rtmp, skt, req, local_ip);
}

// do token traverse before serve it.
// @see https://github.com/ossrs/srs/pull/239
if (true) {
bool vhost_is_edge = _srs_config->get_vhost_is_edge(req->vhost);
bool edge_traverse = _srs_config->get_vhost_edge_token_traverse(req->vhost);
if (vhost_is_edge && edge_traverse) {
if ((ret = check_edge_token_traverse_auth()) != ERROR_SUCCESS) {
srs_warn("token auth failed, ret=%d", ret);
return ret;
}
}
}

// set chunk size to larger.
// set the chunk size before any larger response greater than 128,
// to make OBS happy, @see https://github.com/ossrs/srs/issues/454
Expand Down Expand Up @@ -471,10 +435,49 @@ int SrsRtmpConn::stream_service_cycle()
}
return ret;
}

srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param);
req->strip();
srs_trace("client identified, type=%s, stream_name=%s, duration=%.2f",
srs_client_type_string(type).c_str(), req->stream.c_str(), req->duration);

// discovery vhost, resolve the vhost from config
SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req->vhost);
if (parsed_vhost) {
req->vhost = parsed_vhost->arg0();
}

if (req->schema.empty() || req->vhost.empty() || req->port.empty() || req->app.empty()) {
ret = ERROR_RTMP_REQ_TCURL;
srs_error("discovery tcUrl failed. "
"tcUrl=%s, schema=%s, vhost=%s, port=%s, app=%s, ret=%d",
req->tcUrl.c_str(), req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str(), ret);
return ret;
}

if ((ret = check_vhost()) != ERROR_SUCCESS) {
srs_error("check vhost failed. ret=%d", ret);
return ret;
}

srs_trace("connected stream, tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%s, app=%s, stream=%s, args=%s",
req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(),
req->schema.c_str(), req->vhost.c_str(), req->port.c_str(),
req->app.c_str(), req->stream.c_str(), (req->args? "(obj)":"null"));

// do token traverse before serve it.
// @see https://github.com/ossrs/srs/pull/239
if (true) {
bool vhost_is_edge = _srs_config->get_vhost_is_edge(req->vhost);
bool edge_traverse = _srs_config->get_vhost_edge_token_traverse(req->vhost);
if (vhost_is_edge && edge_traverse) {
if ((ret = check_edge_token_traverse_auth()) != ERROR_SUCCESS) {
srs_warn("token auth failed, ret=%d", ret);
return ret;
}
}
}

// security check
if ((ret = security->check(type, ip, req)) != ERROR_SUCCESS) {
srs_error("security check failed. ret=%d", ret);
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_rtsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ int SrsRtspConn::connect()
req = new SrsRequest();

std::string schema, host, vhost, app, port, param;
srs_discovery_tc_url(rtsp_tcUrl, schema, host, vhost, app, port, param);
srs_discovery_tc_url(rtsp_tcUrl, schema, host, vhost, app, rtsp_stream, port, param);

// generate output by template.
std::string output = output_template;
Expand All @@ -671,7 +671,7 @@ int SrsRtspConn::connect()
}

srs_discovery_tc_url(req->tcUrl,
req->schema, req->host, req->vhost, req->app, req->port,
req->schema, req->host, req->vhost, req->app, req->stream, req->port,
req->param);
}

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_REVISION 245
#define VERSION_REVISION 246

// generated by configure, only macros.
#include <srs_auto_headers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/libs/srs_librtmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ int srs_librtmp_context_parse_uri(Context* context)

std::string schema;
srs_discovery_tc_url(context->tcUrl,
schema, context->host, context->vhost, context->app, context->port,
schema, context->host, context->vhost, context->app, context->stream, context->port,
context->param);

return ret;
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/main/srs_main_ingest_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ int SrsIngestSrsOutput::connect()
}

srs_discovery_tc_url(req->tcUrl,
req->schema, req->host, req->vhost, req->app, req->port,
req->schema, req->host, req->vhost, req->app, req->stream, req->port,
req->param);
}

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/protocol/srs_rtmp_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2515,7 +2515,7 @@ int SrsRtmpServer::connect_app(SrsRequest* req)
srs_info("get connect app message params success.");

srs_discovery_tc_url(req->tcUrl,
req->schema, req->host, req->vhost, req->app, req->port,
req->schema, req->host, req->vhost, req->app, req->stream, req->port,
req->param);
req->strip();

Expand Down
3 changes: 2 additions & 1 deletion trunk/src/protocol/srs_rtmp_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using namespace std;
void srs_discovery_tc_url(
string tcUrl,
string& schema, string& host, string& vhost,
string& app, string& port, std::string& param
string& app, string& stream, string& port, std::string& param
) {
size_t pos = std::string::npos;
std::string url = tcUrl;
Expand All @@ -70,6 +70,7 @@ void srs_discovery_tc_url(
app = url;
vhost = host;
srs_vhost_resolve(vhost, app, param);
srs_vhost_resolve(vhost, stream, param);
}

void srs_vhost_resolve(string& vhost, string& app, string& param)
Expand Down
5 changes: 4 additions & 1 deletion trunk/src/protocol/srs_rtmp_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ class ISrsProtocolReaderWriter;
* @param port, for example, 19350
* default to 1935 if not specified.
* param param, for example, vhost=vhost.ossrs.net
* @remark The param stream is input and output param, that is:
* input: tcUrl+stream
* output: schema, host, vhost, app, stream, port, param
*/
extern void srs_discovery_tc_url(
std::string tcUrl,
std::string& schema, std::string& host, std::string& vhost,
std::string& app, std::string& port, std::string& param
std::string& app, std::string& stream, std::string& port, std::string& param
);

/**
Expand Down
Loading

0 comments on commit 1721e4e

Please sign in to comment.