Merge branch 'add_schema_query_string' of github.com:mtdxc/ZLMediaKit

This commit is contained in:
xiongziliang 2022-03-12 09:53:07 +08:00
commit 81c0635bf2

View File

@ -178,16 +178,28 @@ bool HttpSession::checkWebSocket(){
} }
bool HttpSession::checkLiveStream(const string &schema, const string &url_suffix, const function<void(const MediaSource::Ptr &src)> &cb){ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffix, const function<void(const MediaSource::Ptr &src)> &cb){
auto pos = strcasestr(_parser.Url().data(), url_suffix.data()); std::string url = _parser.Url();
if (!pos || pos + url_suffix.size() != 1 + &_parser.Url().back()) { auto it = _parser.getUrlArgs().find("schema");
if (it != _parser.getUrlArgs().end()) {
if (strcasecmp(it->second.c_str(), schema.c_str())) {
// unsupported schema
return false;
}
}
else {
int prefix_len = url_suffix.length();
if(url.length() < prefix_len || strcasecmp(url.substr(url.length() - prefix_len).c_str(), url_suffix.c_str())) {
//未找到后缀 //未找到后缀
return false; return false;
} }
//url去除特殊后缀 //url去除特殊后缀
auto url = _parser.Url().substr(0, _parser.Url().size() - url_suffix.size()); url = url.substr(0, url.size() - prefix_len);
}
//带参数的url //带参数的url
url = _parser.Params().empty() ? url : (url + "?" + _parser.Params()); if(!_parser.Params().empty())
url += "?" + _parser.Params();
//解析带上协议+参数完整的url //解析带上协议+参数完整的url
_mediaInfo.parse(schema + "://" + _parser["Host"] + url); _mediaInfo.parse(schema + "://" + _parser["Host"] + url);
@ -223,22 +235,19 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffi
if (!src) { if (!src) {
//未找到该流 //未找到该流
strong_self->sendNotFound(close_flag); strong_self->sendNotFound(close_flag);
return;
} }
else {
strong_self->_is_live_stream = true; strong_self->_is_live_stream = true;
//触发回调 //触发回调
cb(src); cb(src);
}
}); });
}; };
Broadcast::AuthInvoker invoker = [weak_self, onRes](const string &err) { Broadcast::AuthInvoker invoker = [weak_self, onRes](const string &err) {
auto strongSelf = weak_self.lock(); if (auto strongSelf = weak_self.lock()) {
if (!strongSelf) { strongSelf->async([onRes, err]() { onRes(err); });
return;
} }
strongSelf->async([onRes, err]() {
onRes(err);
});
}; };
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, _mediaInfo, invoker, static_cast<SockInfo &>(*this)); auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, _mediaInfo, invoker, static_cast<SockInfo &>(*this));