diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 2a7381ff..e1b29b7f 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 2a7381ff6dbe5a2f419957734425d5423f3850c6 +Subproject commit e1b29b7fa22e18bb0976a281268c0431a411e7ce diff --git a/src/Common/config.cpp b/src/Common/config.cpp index d4f08373..5cc44dd9 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -68,6 +68,7 @@ const string kBroadcastReloadConfig = "kBroadcastReloadConfig"; const string kBroadcastShellLogin = "kBroadcastShellLogin"; const string kBroadcastNotFoundStream = "kBroadcastNotFoundStream"; const string kBroadcastStreamNoneReader = "kBroadcastStreamNoneReader"; +const string kBroadcastHttpBeforeAccess = "kBroadcastHttpBeforeAccess"; } //namespace Broadcast //通用配置项目 diff --git a/src/Common/config.h b/src/Common/config.h index 8eb447b3..9e9b3c1e 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -83,10 +83,15 @@ extern const string kBroadcastRecordMP4; extern const string kBroadcastHttpRequest; #define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,TcpSession &sender -//收到http 访问文件或目录的广播,通过该事件控制访问http目录的权限 +//在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限 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 +//在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.如果该事件不监听则不认证 extern const string kBroadcastOnGetRtspRealm; #define BroadcastOnGetRtspRealmArgs const MediaInfo &args,const RtspSession::onGetRealm &invoker,TcpSession &sender diff --git a/src/Http/HttpFileManager.cpp b/src/Http/HttpFileManager.cpp index d44f736d..70fd75df 100644 --- a/src/Http/HttpFileManager.cpp +++ b/src/Http/HttpFileManager.cpp @@ -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 事件触发者 @@ -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) { auto fullUrl = string(HTTP_SCHEMA) + "://" + parser["Host"] + parser.FullUrl(); MediaInfo mediaInfo(fullUrl); - - GET_CONFIG(bool, enableVhost, General::kEnableVhost); - GET_CONFIG(string, rootPath, Http::kRootPath); - auto strFile = File::absolutePath(enableVhost ? mediaInfo._vhost + parser.Url() : parser.Url(), rootPath); - + auto strFile = getFilePath(parser, mediaInfo, sender); //访问的是文件夹 if (File::is_dir(strFile.data())) { auto indexFile = searchIndexFile(strFile);