添加用户追踪事件

This commit is contained in:
xiongziliang 2019-06-12 18:55:23 +08:00
parent 080f2af4b4
commit 20e62b103a
3 changed files with 18 additions and 3 deletions

View File

@ -58,6 +58,7 @@ const string kBroadcastMediaChanged = "kBroadcastMediaChanged";
const string kBroadcastRecordMP4 = "kBroadcastRecordMP4"; const string kBroadcastRecordMP4 = "kBroadcastRecordMP4";
const string kBroadcastHttpRequest = "kBroadcastHttpRequest"; const string kBroadcastHttpRequest = "kBroadcastHttpRequest";
const string kBroadcastHttpAccess = "kBroadcastHttpAccess"; const string kBroadcastHttpAccess = "kBroadcastHttpAccess";
const string kBroadcastTrackHttpClient = "kBroadcastTrackHttpClient";
const string kBroadcastOnGetRtspRealm = "kBroadcastOnGetRtspRealm"; const string kBroadcastOnGetRtspRealm = "kBroadcastOnGetRtspRealm";
const string kBroadcastOnRtspAuth = "kBroadcastOnRtspAuth"; const string kBroadcastOnRtspAuth = "kBroadcastOnRtspAuth";
const string kBroadcastMediaPlayed = "kBroadcastMediaPlayed"; const string kBroadcastMediaPlayed = "kBroadcastMediaPlayed";

View File

@ -79,10 +79,16 @@ 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目录的权限
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客户端不支持cookieip端口又一直变那么可以根据url参数来追踪用户
//从而减少kBroadcastHttpAccess事件触发的次数。
extern const string kBroadcastTrackHttpClient;
#define BroadcastTrackHttpClientArgs const Parser &parser,string &uid,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

View File

@ -325,10 +325,18 @@ inline string HttpSession::getClientUid(){
//该ip端口只能有一个cookie不能重复获取cookie //该ip端口只能有一个cookie不能重复获取cookie
//目的是为了防止我们让客户端设置cookie但是客户端不支持cookie导致一直重复生成cookie //目的是为了防止我们让客户端设置cookie但是客户端不支持cookie导致一直重复生成cookie
//判断是否为同一个用户还可以根据url相关字段但是这个跟具体业务逻辑相关在这里不便实现 //判断是否为同一个用户还可以根据url相关字段但是这个跟具体业务逻辑相关在这里不便实现
//如果一个http客户端不支持cookie并且一直变换端口号那么会导致服务器无法追踪该用户从而导致一直触发事件并且一直生成cookie //如果一个http客户端不支持cookie并且一直变换端口号那么可能会导致服务器无法追踪该用户从而导致一直触发事件并且一直生成cookie
return StrPrinter << get_peer_ip() << ":" << get_peer_port(); string uid = StrPrinter << get_peer_ip() << ":" << get_peer_port();
//所以我们通过kBroadcastTrackHttpClient事件来让业务逻辑自行决定根据url参数追踪用户
NoticeCenter::Instance().emitEventNoCopy(Broadcast::kBroadcastTrackHttpClient,_parser,uid,*this);
return uid;
} }
inline void HttpSession::canAccessPath(const string &path_in,bool is_dir,const function<void(bool canAccess,const CookieData::Ptr &cookie)> &callback_in){ inline void HttpSession::canAccessPath(const string &path_in,bool is_dir,const function<void(bool canAccess,const CookieData::Ptr &cookie)> &callback_in){
if(NoticeCenter::Instance().listenerSize(Broadcast::kBroadcastHttpAccess) == 0){
//该事件无人监听那么就不做cookie查找这样费时的操作
callback_in(true, nullptr);
return;
}
auto path = path_in; auto path = path_in;
replace(const_cast<string &>(path),"//","/"); replace(const_cast<string &>(path),"//","/");