mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
添加kBroadcastHttpBeforeAccess事件,拦截http文件下载事件
This commit is contained in:
parent
0b8c4e75e1
commit
2da0c884a1
@ -1 +1 @@
|
|||||||
Subproject commit 2a7381ff6dbe5a2f419957734425d5423f3850c6
|
Subproject commit e1b29b7fa22e18bb0976a281268c0431a411e7ce
|
@ -68,6 +68,7 @@ const string kBroadcastReloadConfig = "kBroadcastReloadConfig";
|
|||||||
const string kBroadcastShellLogin = "kBroadcastShellLogin";
|
const string kBroadcastShellLogin = "kBroadcastShellLogin";
|
||||||
const string kBroadcastNotFoundStream = "kBroadcastNotFoundStream";
|
const string kBroadcastNotFoundStream = "kBroadcastNotFoundStream";
|
||||||
const string kBroadcastStreamNoneReader = "kBroadcastStreamNoneReader";
|
const string kBroadcastStreamNoneReader = "kBroadcastStreamNoneReader";
|
||||||
|
const string kBroadcastHttpBeforeAccess = "kBroadcastHttpBeforeAccess";
|
||||||
} //namespace Broadcast
|
} //namespace Broadcast
|
||||||
|
|
||||||
//通用配置项目
|
//通用配置项目
|
||||||
|
@ -83,10 +83,15 @@ extern const string kBroadcastRecordMP4;
|
|||||||
extern const string kBroadcastHttpRequest;
|
extern const string kBroadcastHttpRequest;
|
||||||
#define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,TcpSession &sender
|
#define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,TcpSession &sender
|
||||||
|
|
||||||
//收到http 访问文件或目录的广播,通过该事件控制访问http目录的权限
|
//在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
|
||||||
extern const string kBroadcastHttpAccess;
|
extern const string kBroadcastHttpAccess;
|
||||||
#define BroadcastHttpAccessArgs const Parser &parser,const MediaInfo &args,const string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,TcpSession &sender
|
#define BroadcastHttpAccessArgs const Parser &parser,const MediaInfo &args,const string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,TcpSession &sender
|
||||||
|
|
||||||
|
//在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
|
||||||
|
//在该事件中通过自行覆盖path参数,可以做到譬如根据虚拟主机或者app选择不同http根目录的目的
|
||||||
|
extern const string kBroadcastHttpBeforeAccess;
|
||||||
|
#define BroadcastHttpBeforeAccessArgs const Parser &parser,const MediaInfo &args,string &path,TcpSession &sender
|
||||||
|
|
||||||
//该流是否需要认证?是的话调用invoker并传入realm,否则传入空的realm.如果该事件不监听则不认证
|
//该流是否需要认证?是的话调用invoker并传入realm,否则传入空的realm.如果该事件不监听则不认证
|
||||||
extern const string kBroadcastOnGetRtspRealm;
|
extern const string kBroadcastOnGetRtspRealm;
|
||||||
#define BroadcastOnGetRtspRealmArgs const MediaInfo &args,const RtspSession::onGetRealm &invoker,TcpSession &sender
|
#define BroadcastOnGetRtspRealmArgs const MediaInfo &args,const RtspSession::onGetRealm &invoker,TcpSession &sender
|
||||||
|
@ -375,6 +375,14 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static string getFilePath(const Parser &parser,const MediaInfo &mediaInfo, TcpSession &sender){
|
||||||
|
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
|
||||||
|
GET_CONFIG(string, rootPath, Http::kRootPath);
|
||||||
|
auto ret = File::absolutePath(enableVhost ? mediaInfo._vhost + parser.Url() : parser.Url(), rootPath);
|
||||||
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpBeforeAccess, parser, mediaInfo, ret, sender);
|
||||||
|
return std::move(ret);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 访问文件或文件夹
|
* 访问文件或文件夹
|
||||||
* @param sender 事件触发者
|
* @param sender 事件触发者
|
||||||
@ -384,11 +392,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
|||||||
void HttpFileManager::onAccessPath(TcpSession &sender, Parser &parser, const HttpFileManager::invoker &cb) {
|
void HttpFileManager::onAccessPath(TcpSession &sender, Parser &parser, const HttpFileManager::invoker &cb) {
|
||||||
auto fullUrl = string(HTTP_SCHEMA) + "://" + parser["Host"] + parser.FullUrl();
|
auto fullUrl = string(HTTP_SCHEMA) + "://" + parser["Host"] + parser.FullUrl();
|
||||||
MediaInfo mediaInfo(fullUrl);
|
MediaInfo mediaInfo(fullUrl);
|
||||||
|
auto strFile = getFilePath(parser, mediaInfo, sender);
|
||||||
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
|
|
||||||
GET_CONFIG(string, rootPath, Http::kRootPath);
|
|
||||||
auto strFile = File::absolutePath(enableVhost ? mediaInfo._vhost + parser.Url() : parser.Url(), rootPath);
|
|
||||||
|
|
||||||
//访问的是文件夹
|
//访问的是文件夹
|
||||||
if (File::is_dir(strFile.data())) {
|
if (File::is_dir(strFile.data())) {
|
||||||
auto indexFile = searchIndexFile(strFile);
|
auto indexFile = searchIndexFile(strFile);
|
||||||
|
Loading…
Reference in New Issue
Block a user