Commit b6946a59 by xiongziliang

事件广播触发者改成SockInfo对象

parent 4d84661a
ZLToolKit @ 07d21ac6
Subproject commit fac78b63701ce6febd9ac6acefb637886c651873 Subproject commit 07d21ac61be6c7a4eba90a5d2d26b15daa882cf7
...@@ -36,7 +36,7 @@ typedef struct { ...@@ -36,7 +36,7 @@ typedef struct {
*/ */
void (API_CALL *on_mk_media_publish)(const mk_media_info url_info, void (API_CALL *on_mk_media_publish)(const mk_media_info url_info,
const mk_publish_auth_invoker invoker, const mk_publish_auth_invoker invoker,
const mk_tcp_session sender); const mk_sock_info sender);
/** /**
* 播放rtsp/rtmp/http-flv/hls事件广播,通过该事件控制播放鉴权 * 播放rtsp/rtmp/http-flv/hls事件广播,通过该事件控制播放鉴权
...@@ -47,7 +47,7 @@ typedef struct { ...@@ -47,7 +47,7 @@ typedef struct {
*/ */
void (API_CALL *on_mk_media_play)(const mk_media_info url_info, void (API_CALL *on_mk_media_play)(const mk_media_info url_info,
const mk_auth_invoker invoker, const mk_auth_invoker invoker,
const mk_tcp_session sender); const mk_sock_info sender);
/** /**
* 未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了 * 未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
...@@ -55,7 +55,7 @@ typedef struct { ...@@ -55,7 +55,7 @@ typedef struct {
* @param sender 播放客户端相关信息 * @param sender 播放客户端相关信息
*/ */
void (API_CALL *on_mk_media_not_found)(const mk_media_info url_info, void (API_CALL *on_mk_media_not_found)(const mk_media_info url_info,
const mk_tcp_session sender); const mk_sock_info sender);
/** /**
* 某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑 * 某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑
...@@ -73,7 +73,7 @@ typedef struct { ...@@ -73,7 +73,7 @@ typedef struct {
void (API_CALL *on_mk_http_request)(const mk_parser parser, void (API_CALL *on_mk_http_request)(const mk_parser parser,
const mk_http_response_invoker invoker, const mk_http_response_invoker invoker,
int *consumed, int *consumed,
const mk_tcp_session sender); const mk_sock_info sender);
/** /**
* 在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限 * 在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
...@@ -87,7 +87,7 @@ typedef struct { ...@@ -87,7 +87,7 @@ typedef struct {
const char *path, const char *path,
int is_dir, int is_dir,
const mk_http_access_path_invoker invoker, const mk_http_access_path_invoker invoker,
mk_tcp_session sender); const mk_sock_info sender);
/** /**
* 在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射 * 在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
...@@ -98,7 +98,7 @@ typedef struct { ...@@ -98,7 +98,7 @@ typedef struct {
*/ */
void (API_CALL *on_mk_http_before_access)(const mk_parser parser, void (API_CALL *on_mk_http_before_access)(const mk_parser parser,
char *path, char *path,
const mk_tcp_session sender); const mk_sock_info sender);
/** /**
* 该rtsp流是否需要认证?是的话调用invoker并传入realm,否则传入空的realm * 该rtsp流是否需要认证?是的话调用invoker并传入realm,否则传入空的realm
...@@ -108,7 +108,7 @@ typedef struct { ...@@ -108,7 +108,7 @@ typedef struct {
*/ */
void (API_CALL *on_mk_rtsp_get_realm)(const mk_media_info url_info, void (API_CALL *on_mk_rtsp_get_realm)(const mk_media_info url_info,
const mk_rtsp_get_realm_invoker invoker, const mk_rtsp_get_realm_invoker invoker,
const mk_tcp_session sender); const mk_sock_info sender);
/** /**
* 请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败 * 请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败
...@@ -125,7 +125,7 @@ typedef struct { ...@@ -125,7 +125,7 @@ typedef struct {
const char *user_name, const char *user_name,
int must_no_encrypt, int must_no_encrypt,
const mk_rtsp_auth_invoker invoker, const mk_rtsp_auth_invoker invoker,
const mk_tcp_session sender); const mk_sock_info sender);
/** /**
* 录制mp4分片文件成功后广播 * 录制mp4分片文件成功后广播
...@@ -138,7 +138,7 @@ typedef struct { ...@@ -138,7 +138,7 @@ typedef struct {
void (API_CALL *on_mk_shell_login)(const char *user_name, void (API_CALL *on_mk_shell_login)(const char *user_name,
const char *passwd, const char *passwd,
const mk_auth_invoker invoker, const mk_auth_invoker invoker,
const mk_tcp_session sender); const mk_sock_info sender);
/** /**
* 停止rtsp/rtmp/http-flv会话后流量汇报事件广播 * 停止rtsp/rtmp/http-flv会话后流量汇报事件广播
......
...@@ -17,19 +17,41 @@ ...@@ -17,19 +17,41 @@
extern "C" { extern "C" {
#endif #endif
///////////////////////////////////////////SockInfo/////////////////////////////////////////////
//SockInfo对象的C映射
typedef void* mk_sock_info;
//SockInfo::get_peer_ip()
API_EXPORT const char* API_CALL mk_sock_info_peer_ip(const mk_sock_info ctx);
//SockInfo::get_local_ip()
API_EXPORT const char* API_CALL mk_sock_info_local_ip(const mk_sock_info ctx);
//SockInfo::get_peer_port()
API_EXPORT uint16_t API_CALL mk_sock_info_peer_port(const mk_sock_info ctx);
//SockInfo::get_local_port()
API_EXPORT uint16_t API_CALL mk_sock_info_local_port(const mk_sock_info ctx);
#ifndef SOCK_INFO_API_RENAME
#define SOCK_INFO_API_RENAME
//mk_tcp_session对象转换成mk_sock_info对象后再获取网络相关信息
#define mk_tcp_session_peer_ip(x) mk_sock_info_peer_ip(mk_tcp_session_get_sock_info(x))
#define mk_tcp_session_local_ip(x) mk_sock_info_local_ip(mk_tcp_session_get_sock_info(x))
#define mk_tcp_session_peer_port(x) mk_sock_info_peer_port(mk_tcp_session_get_sock_info(x))
#define mk_tcp_session_local_port(x) mk_sock_info_local_port(mk_tcp_session_get_sock_info(x))
//mk_tcp_client对象转换成mk_sock_info对象后再获取网络相关信息
#define mk_tcp_client_peer_ip(x) mk_sock_info_peer_ip(mk_tcp_client_get_sock_info(x))
#define mk_tcp_client_local_ip(x) mk_sock_info_local_ip(mk_tcp_client_get_sock_info(x))
#define mk_tcp_client_peer_port(x) mk_sock_info_peer_port(mk_tcp_client_get_sock_info(x))
#define mk_tcp_client_local_port(x) mk_sock_info_local_port(mk_tcp_client_get_sock_info(x))
#endif
///////////////////////////////////////////TcpSession///////////////////////////////////////////// ///////////////////////////////////////////TcpSession/////////////////////////////////////////////
//TcpSession对象的C映射 //TcpSession对象的C映射
typedef void* mk_tcp_session; typedef void* mk_tcp_session;
//获取基类指针以便获取其网络相关信息
API_EXPORT mk_sock_info API_CALL mk_tcp_session_get_sock_info(const mk_tcp_session ctx);
//TcpSession::safeShutdown() //TcpSession::safeShutdown()
API_EXPORT void API_CALL mk_tcp_session_shutdown(const mk_tcp_session ctx,int err,const char *err_msg); API_EXPORT void API_CALL mk_tcp_session_shutdown(const mk_tcp_session ctx,int err,const char *err_msg);
//TcpSession::get_peer_ip()
API_EXPORT const char* API_CALL mk_tcp_session_peer_ip(const mk_tcp_session ctx);
//TcpSession::get_local_ip()
API_EXPORT const char* API_CALL mk_tcp_session_local_ip(const mk_tcp_session ctx);
//TcpSession::get_peer_port()
API_EXPORT uint16_t API_CALL mk_tcp_session_peer_port(const mk_tcp_session ctx);
//TcpSession::get_local_port()
API_EXPORT uint16_t API_CALL mk_tcp_session_local_port(const mk_tcp_session ctx);
//TcpSession::send() //TcpSession::send()
API_EXPORT void API_CALL mk_tcp_session_send(const mk_tcp_session ctx,const char *data,int len); API_EXPORT void API_CALL mk_tcp_session_send(const mk_tcp_session ctx,const char *data,int len);
//切换到该对象所在线程后再TcpSession::send() //切换到该对象所在线程后再TcpSession::send()
...@@ -115,6 +137,8 @@ API_EXPORT void API_CALL mk_tcp_server_events_listen(const mk_tcp_session_events ...@@ -115,6 +137,8 @@ API_EXPORT void API_CALL mk_tcp_server_events_listen(const mk_tcp_session_events
///////////////////////////////////////////自定义tcp客户端///////////////////////////////////////////// ///////////////////////////////////////////自定义tcp客户端/////////////////////////////////////////////
typedef void* mk_tcp_client; typedef void* mk_tcp_client;
//获取基类指针以便获取其网络相关信息
API_EXPORT mk_sock_info API_CALL mk_tcp_client_get_sock_info(const mk_tcp_client ctx);
typedef struct { typedef struct {
/** /**
......
...@@ -14,38 +14,46 @@ ...@@ -14,38 +14,46 @@
#include "Http/WebSocketSession.h" #include "Http/WebSocketSession.h"
using namespace mediakit; using namespace mediakit;
//////////////////////////////////////////////////////////////////////////////////////// API_EXPORT const char* API_CALL mk_sock_info_peer_ip(const mk_sock_info ctx){
API_EXPORT void API_CALL mk_tcp_session_shutdown(const mk_tcp_session ctx,int err,const char *err_msg){
assert(ctx); assert(ctx);
TcpSession *session = (TcpSession *)ctx; SockInfo *sock = (SockInfo *)ctx;
session->safeShutdown(SockException((ErrCode)err,err_msg)); return sock->get_peer_ip().c_str();
}
API_EXPORT const char* API_CALL mk_sock_info_local_ip(const mk_sock_info ctx){
assert(ctx);
SockInfo *sock = (SockInfo *)ctx;
return sock->get_local_ip().c_str();
} }
API_EXPORT const char* API_CALL mk_tcp_session_peer_ip(const mk_tcp_session ctx){ API_EXPORT uint16_t API_CALL mk_sock_info_peer_port(const mk_sock_info ctx){
assert(ctx); assert(ctx);
TcpSession *session = (TcpSession *)ctx; SockInfo *sock = (SockInfo *)ctx;
return session->get_peer_ip().c_str(); return sock->get_peer_port();
} }
API_EXPORT const char* API_CALL mk_tcp_session_local_ip(const mk_tcp_session ctx){ API_EXPORT uint16_t API_CALL mk_sock_info_local_port(const mk_sock_info ctx){
assert(ctx); assert(ctx);
TcpSession *session = (TcpSession *)ctx; SockInfo *sock = (SockInfo *)ctx;
return session->get_local_ip().c_str(); return sock->get_local_port();
} }
API_EXPORT uint16_t API_CALL mk_tcp_session_peer_port(const mk_tcp_session ctx){
////////////////////////////////////////////////////////////////////////////////////////
API_EXPORT mk_sock_info API_CALL mk_tcp_session_get_sock_info(const mk_tcp_session ctx){
assert(ctx); assert(ctx);
TcpSession *session = (TcpSession *)ctx; TcpSessionForC *session = (TcpSessionForC *)ctx;
return session->get_peer_port(); return (SockInfo *)session;
} }
API_EXPORT uint16_t API_CALL mk_tcp_session_local_port(const mk_tcp_session ctx){
API_EXPORT void API_CALL mk_tcp_session_shutdown(const mk_tcp_session ctx,int err,const char *err_msg){
assert(ctx); assert(ctx);
TcpSession *session = (TcpSession *)ctx; TcpSessionForC *session = (TcpSessionForC *)ctx;
return session->get_local_port(); session->safeShutdown(SockException((ErrCode)err,err_msg));
} }
API_EXPORT void API_CALL mk_tcp_session_send(const mk_tcp_session ctx,const char *data,int len){ API_EXPORT void API_CALL mk_tcp_session_send(const mk_tcp_session ctx,const char *data,int len){
assert(ctx && data); assert(ctx && data);
if(!len){ if(!len){
len = strlen(data); len = strlen(data);
} }
TcpSession *session = (TcpSession *)ctx; TcpSessionForC *session = (TcpSessionForC *)ctx;
session->SockSender::send(data,len); session->SockSender::send(data,len);
} }
...@@ -55,9 +63,9 @@ API_EXPORT void API_CALL mk_tcp_session_send_safe(const mk_tcp_session ctx,const ...@@ -55,9 +63,9 @@ API_EXPORT void API_CALL mk_tcp_session_send_safe(const mk_tcp_session ctx,const
len = strlen(data); len = strlen(data);
} }
try { try {
weak_ptr<TcpSession> weak_session = ((TcpSession *)ctx)->shared_from_this(); weak_ptr<TcpSession> weak_session = ((TcpSessionForC *)ctx)->shared_from_this();
string str = string(data,len); string str = string(data,len);
((TcpSession *)ctx)->async([weak_session,str](){ ((TcpSessionForC *)ctx)->async([weak_session,str](){
auto session_session = weak_session.lock(); auto session_session = weak_session.lock();
if(session_session){ if(session_session){
session_session->SockSender::send(str); session_session->SockSender::send(str);
...@@ -205,6 +213,12 @@ TcpClientForC::Ptr *mk_tcp_client_create_l(mk_tcp_client_events *events, mk_tcp_ ...@@ -205,6 +213,12 @@ TcpClientForC::Ptr *mk_tcp_client_create_l(mk_tcp_client_events *events, mk_tcp_
} }
} }
API_EXPORT mk_sock_info API_CALL mk_tcp_client_get_sock_info(const mk_tcp_client ctx){
assert(ctx);
TcpClientForC::Ptr *client = (TcpClientForC::Ptr *)ctx;
return (SockInfo *)client->get();
}
API_EXPORT mk_tcp_client API_CALL mk_tcp_client_create(mk_tcp_client_events *events, mk_tcp_type type){ API_EXPORT mk_tcp_client API_CALL mk_tcp_client_create(mk_tcp_client_events *events, mk_tcp_type type){
auto ret = mk_tcp_client_create_l(events,type); auto ret = mk_tcp_client_create_l(events,type);
(*ret)->setClient(ret); (*ret)->setClient(ret);
...@@ -213,25 +227,25 @@ API_EXPORT mk_tcp_client API_CALL mk_tcp_client_create(mk_tcp_client_events *eve ...@@ -213,25 +227,25 @@ API_EXPORT mk_tcp_client API_CALL mk_tcp_client_create(mk_tcp_client_events *eve
API_EXPORT void API_CALL mk_tcp_client_release(mk_tcp_client ctx){ API_EXPORT void API_CALL mk_tcp_client_release(mk_tcp_client ctx){
assert(ctx); assert(ctx);
TcpClient::Ptr *client = (TcpClient::Ptr *)ctx; TcpClientForC::Ptr *client = (TcpClientForC::Ptr *)ctx;
delete client; delete client;
} }
API_EXPORT void API_CALL mk_tcp_client_connect(mk_tcp_client ctx, const char *host, uint16_t port, float time_out_sec){ API_EXPORT void API_CALL mk_tcp_client_connect(mk_tcp_client ctx, const char *host, uint16_t port, float time_out_sec){
assert(ctx); assert(ctx);
TcpClient::Ptr *client = (TcpClient::Ptr *)ctx; TcpClientForC::Ptr *client = (TcpClientForC::Ptr *)ctx;
(*client)->startConnect(host,port); (*client)->startConnect(host,port);
} }
API_EXPORT void API_CALL mk_tcp_client_send(mk_tcp_client ctx, const char *data, int len){ API_EXPORT void API_CALL mk_tcp_client_send(mk_tcp_client ctx, const char *data, int len){
assert(ctx && data); assert(ctx && data);
TcpClient::Ptr *client = (TcpClient::Ptr *)ctx; TcpClientForC::Ptr *client = (TcpClientForC::Ptr *)ctx;
(*client)->SockSender::send(data,len); (*client)->SockSender::send(data,len);
} }
API_EXPORT void API_CALL mk_tcp_client_send_safe(mk_tcp_client ctx, const char *data, int len){ API_EXPORT void API_CALL mk_tcp_client_send_safe(mk_tcp_client ctx, const char *data, int len){
assert(ctx && data); assert(ctx && data);
TcpClient::Ptr *client = (TcpClient::Ptr *)ctx; TcpClientForC::Ptr *client = (TcpClientForC::Ptr *)ctx;
weak_ptr<TcpClient> weakClient = *client; weak_ptr<TcpClient> weakClient = *client;
Buffer::Ptr buf = (*client)->obtainBuffer(data,len); Buffer::Ptr buf = (*client)->obtainBuffer(data,len);
(*client)->async([weakClient,buf](){ (*client)->async([weakClient,buf](){
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
using namespace toolkit; using namespace toolkit;
class TcpClientForC : public TcpClient { class TcpClientForC : public TcpClient {
public: public:
typedef std::shared_ptr<TcpClientForC> Ptr; typedef std::shared_ptr<TcpClientForC> Ptr;
TcpClientForC(mk_tcp_client_events *events) ; TcpClientForC(mk_tcp_client_events *events) ;
~TcpClientForC() override ; ~TcpClientForC() override ;
...@@ -27,13 +27,13 @@ class TcpClientForC : public TcpClient { ...@@ -27,13 +27,13 @@ class TcpClientForC : public TcpClient {
void onConnect(const SockException &ex) override; void onConnect(const SockException &ex) override;
void setClient(mk_tcp_client client); void setClient(mk_tcp_client client);
void *_user_data; void *_user_data;
private: private:
mk_tcp_client_events _events; mk_tcp_client_events _events;
mk_tcp_client _client; mk_tcp_client _client;
}; };
class TcpSessionForC : public TcpSession { class TcpSessionForC : public TcpSession {
public: public:
TcpSessionForC(const Socket::Ptr &pSock) ; TcpSessionForC(const Socket::Ptr &pSock) ;
~TcpSessionForC() override = default; ~TcpSessionForC() override = default;
void onRecv(const Buffer::Ptr &buffer) override ; void onRecv(const Buffer::Ptr &buffer) override ;
......
...@@ -46,14 +46,14 @@ void API_CALL on_mk_media_changed(int regist, ...@@ -46,14 +46,14 @@ void API_CALL on_mk_media_changed(int regist,
*/ */
void API_CALL on_mk_media_publish(const mk_media_info url_info, void API_CALL on_mk_media_publish(const mk_media_info url_info,
const mk_publish_auth_invoker invoker, const mk_publish_auth_invoker invoker,
const mk_tcp_session sender) { const mk_sock_info sender) {
log_printf(LOG_LEV, log_printf(LOG_LEV,
"client info, local: %s:%d, peer: %s:%d\n" "client info, local: %s:%d, peer: %s:%d\n"
"%s/%s/%s/%s, url params: %s", "%s/%s/%s/%s, url params: %s",
mk_tcp_session_local_ip(sender), mk_sock_info_local_ip(sender),
mk_tcp_session_local_port(sender), mk_sock_info_local_port(sender),
mk_tcp_session_peer_ip(sender), mk_sock_info_peer_ip(sender),
mk_tcp_session_peer_port(sender), mk_sock_info_peer_port(sender),
mk_media_info_get_schema(url_info), mk_media_info_get_schema(url_info),
mk_media_info_get_vhost(url_info), mk_media_info_get_vhost(url_info),
mk_media_info_get_app(url_info), mk_media_info_get_app(url_info),
...@@ -73,15 +73,15 @@ void API_CALL on_mk_media_publish(const mk_media_info url_info, ...@@ -73,15 +73,15 @@ void API_CALL on_mk_media_publish(const mk_media_info url_info,
*/ */
void API_CALL on_mk_media_play(const mk_media_info url_info, void API_CALL on_mk_media_play(const mk_media_info url_info,
const mk_auth_invoker invoker, const mk_auth_invoker invoker,
const mk_tcp_session sender) { const mk_sock_info sender) {
log_printf(LOG_LEV, log_printf(LOG_LEV,
"client info, local: %s:%d, peer: %s:%d\n" "client info, local: %s:%d, peer: %s:%d\n"
"%s/%s/%s/%s, url params: %s", "%s/%s/%s/%s, url params: %s",
mk_tcp_session_local_ip(sender), mk_sock_info_local_ip(sender),
mk_tcp_session_local_port(sender), mk_sock_info_local_port(sender),
mk_tcp_session_peer_ip(sender), mk_sock_info_peer_ip(sender),
mk_tcp_session_peer_port(sender), mk_sock_info_peer_port(sender),
mk_media_info_get_schema(url_info), mk_media_info_get_schema(url_info),
mk_media_info_get_vhost(url_info), mk_media_info_get_vhost(url_info),
mk_media_info_get_app(url_info), mk_media_info_get_app(url_info),
...@@ -98,14 +98,14 @@ void API_CALL on_mk_media_play(const mk_media_info url_info, ...@@ -98,14 +98,14 @@ void API_CALL on_mk_media_play(const mk_media_info url_info,
* @param sender 播放客户端相关信息 * @param sender 播放客户端相关信息
*/ */
void API_CALL on_mk_media_not_found(const mk_media_info url_info, void API_CALL on_mk_media_not_found(const mk_media_info url_info,
const mk_tcp_session sender) { const mk_sock_info sender) {
log_printf(LOG_LEV, log_printf(LOG_LEV,
"client info, local: %s:%d, peer: %s:%d\n" "client info, local: %s:%d, peer: %s:%d\n"
"%s/%s/%s/%s, url params: %s", "%s/%s/%s/%s, url params: %s",
mk_tcp_session_local_ip(sender), mk_sock_info_local_ip(sender),
mk_tcp_session_local_port(sender), mk_sock_info_local_port(sender),
mk_tcp_session_peer_ip(sender), mk_sock_info_peer_ip(sender),
mk_tcp_session_peer_port(sender), mk_sock_info_peer_port(sender),
mk_media_info_get_schema(url_info), mk_media_info_get_schema(url_info),
mk_media_info_get_vhost(url_info), mk_media_info_get_vhost(url_info),
mk_media_info_get_app(url_info), mk_media_info_get_app(url_info),
...@@ -137,17 +137,17 @@ void API_CALL on_mk_media_no_reader(const mk_media_source sender) { ...@@ -137,17 +137,17 @@ void API_CALL on_mk_media_no_reader(const mk_media_source sender) {
void API_CALL on_mk_http_request(const mk_parser parser, void API_CALL on_mk_http_request(const mk_parser parser,
const mk_http_response_invoker invoker, const mk_http_response_invoker invoker,
int *consumed, int *consumed,
const mk_tcp_session sender) { const mk_sock_info sender) {
log_printf(LOG_LEV, log_printf(LOG_LEV,
"client info, local: %s:%d, peer: %s:%d\n" "client info, local: %s:%d, peer: %s:%d\n"
"%s %s?%s %s\n" "%s %s?%s %s\n"
"User-Agent: %s\n" "User-Agent: %s\n"
"%s", "%s",
mk_tcp_session_local_ip(sender), mk_sock_info_local_ip(sender),
mk_tcp_session_local_port(sender), mk_sock_info_local_port(sender),
mk_tcp_session_peer_ip(sender), mk_sock_info_peer_ip(sender),
mk_tcp_session_peer_port(sender), mk_sock_info_peer_port(sender),
mk_parser_get_method(parser), mk_parser_get_method(parser),
mk_parser_get_url(parser), mk_parser_get_url(parser),
mk_parser_get_url_params(parser), mk_parser_get_url_params(parser),
...@@ -191,17 +191,17 @@ void API_CALL on_mk_http_access(const mk_parser parser, ...@@ -191,17 +191,17 @@ void API_CALL on_mk_http_access(const mk_parser parser,
const char *path, const char *path,
int is_dir, int is_dir,
const mk_http_access_path_invoker invoker, const mk_http_access_path_invoker invoker,
mk_tcp_session sender) { const mk_sock_info sender) {
log_printf(LOG_LEV, log_printf(LOG_LEV,
"client info, local: %s:%d, peer: %s:%d, path: %s ,is_dir: %d\n" "client info, local: %s:%d, peer: %s:%d, path: %s ,is_dir: %d\n"
"%s %s?%s %s\n" "%s %s?%s %s\n"
"User-Agent: %s\n" "User-Agent: %s\n"
"%s", "%s",
mk_tcp_session_local_ip(sender), mk_sock_info_local_ip(sender),
mk_tcp_session_local_port(sender), mk_sock_info_local_port(sender),
mk_tcp_session_peer_ip(sender), mk_sock_info_peer_ip(sender),
mk_tcp_session_peer_port(sender), mk_sock_info_peer_port(sender),
path,(int)is_dir, path,(int)is_dir,
mk_parser_get_method(parser), mk_parser_get_method(parser),
mk_parser_get_url(parser), mk_parser_get_url(parser),
...@@ -223,16 +223,16 @@ void API_CALL on_mk_http_access(const mk_parser parser, ...@@ -223,16 +223,16 @@ void API_CALL on_mk_http_access(const mk_parser parser,
*/ */
void API_CALL on_mk_http_before_access(const mk_parser parser, void API_CALL on_mk_http_before_access(const mk_parser parser,
char *path, char *path,
const mk_tcp_session sender) { const mk_sock_info sender) {
log_printf(LOG_LEV, log_printf(LOG_LEV,
"client info, local: %s:%d, peer: %s:%d, path: %s\n" "client info, local: %s:%d, peer: %s:%d, path: %s\n"
"%s %s?%s %s\n" "%s %s?%s %s\n"
"User-Agent: %s\n" "User-Agent: %s\n"
"%s", "%s",
mk_tcp_session_local_ip(sender), mk_sock_info_local_ip(sender),
mk_tcp_session_local_port(sender), mk_sock_info_local_port(sender),
mk_tcp_session_peer_ip(sender), mk_sock_info_peer_ip(sender),
mk_tcp_session_peer_port(sender), mk_sock_info_peer_port(sender),
path, path,
mk_parser_get_method(parser), mk_parser_get_method(parser),
mk_parser_get_url(parser), mk_parser_get_url(parser),
...@@ -251,14 +251,14 @@ void API_CALL on_mk_http_before_access(const mk_parser parser, ...@@ -251,14 +251,14 @@ void API_CALL on_mk_http_before_access(const mk_parser parser,
*/ */
void API_CALL on_mk_rtsp_get_realm(const mk_media_info url_info, void API_CALL on_mk_rtsp_get_realm(const mk_media_info url_info,
const mk_rtsp_get_realm_invoker invoker, const mk_rtsp_get_realm_invoker invoker,
const mk_tcp_session sender) { const mk_sock_info sender) {
log_printf(LOG_LEV, log_printf(LOG_LEV,
"client info, local: %s:%d, peer: %s:%d\n" "client info, local: %s:%d, peer: %s:%d\n"
"%s/%s/%s/%s, url params: %s", "%s/%s/%s/%s, url params: %s",
mk_tcp_session_local_ip(sender), mk_sock_info_local_ip(sender),
mk_tcp_session_local_port(sender), mk_sock_info_local_port(sender),
mk_tcp_session_peer_ip(sender), mk_sock_info_peer_ip(sender),
mk_tcp_session_peer_port(sender), mk_sock_info_peer_port(sender),
mk_media_info_get_schema(url_info), mk_media_info_get_schema(url_info),
mk_media_info_get_vhost(url_info), mk_media_info_get_vhost(url_info),
mk_media_info_get_app(url_info), mk_media_info_get_app(url_info),
...@@ -284,16 +284,16 @@ void API_CALL on_mk_rtsp_auth(const mk_media_info url_info, ...@@ -284,16 +284,16 @@ void API_CALL on_mk_rtsp_auth(const mk_media_info url_info,
const char *user_name, const char *user_name,
int must_no_encrypt, int must_no_encrypt,
const mk_rtsp_auth_invoker invoker, const mk_rtsp_auth_invoker invoker,
const mk_tcp_session sender) { const mk_sock_info sender) {
log_printf(LOG_LEV, log_printf(LOG_LEV,
"client info, local: %s:%d, peer: %s:%d\n" "client info, local: %s:%d, peer: %s:%d\n"
"%s/%s/%s/%s, url params: %s\n" "%s/%s/%s/%s, url params: %s\n"
"realm: %s, user_name: %s, must_no_encrypt: %d", "realm: %s, user_name: %s, must_no_encrypt: %d",
mk_tcp_session_local_ip(sender), mk_sock_info_local_ip(sender),
mk_tcp_session_local_port(sender), mk_sock_info_local_port(sender),
mk_tcp_session_peer_ip(sender), mk_sock_info_peer_ip(sender),
mk_tcp_session_peer_port(sender), mk_sock_info_peer_port(sender),
mk_media_info_get_schema(url_info), mk_media_info_get_schema(url_info),
mk_media_info_get_vhost(url_info), mk_media_info_get_vhost(url_info),
mk_media_info_get_app(url_info), mk_media_info_get_app(url_info),
...@@ -338,13 +338,13 @@ void API_CALL on_mk_record_mp4(const mk_mp4_info mp4) { ...@@ -338,13 +338,13 @@ void API_CALL on_mk_record_mp4(const mk_mp4_info mp4) {
void API_CALL on_mk_shell_login(const char *user_name, void API_CALL on_mk_shell_login(const char *user_name,
const char *passwd, const char *passwd,
const mk_auth_invoker invoker, const mk_auth_invoker invoker,
const mk_tcp_session sender) { const mk_sock_info sender) {
log_printf(LOG_LEV,"client info, local: %s:%d, peer: %s:%d\n" log_printf(LOG_LEV,"client info, local: %s:%d, peer: %s:%d\n"
"user_name: %s, passwd: %s", "user_name: %s, passwd: %s",
mk_tcp_session_local_ip(sender), mk_sock_info_local_ip(sender),
mk_tcp_session_local_port(sender), mk_sock_info_local_port(sender),
mk_tcp_session_peer_ip(sender), mk_sock_info_peer_ip(sender),
mk_tcp_session_peer_port(sender), mk_sock_info_peer_port(sender),
user_name, passwd); user_name, passwd);
//允许登录shell //允许登录shell
mk_auth_invoker_do(invoker, NULL); mk_auth_invoker_do(invoker, NULL);
......
...@@ -86,7 +86,7 @@ public: ...@@ -86,7 +86,7 @@ public:
~SuccessException() = default; ~SuccessException() = default;
}; };
#define API_ARGS1 TcpSession &sender,HttpSession::KeyValue &headerIn, HttpSession::KeyValue &headerOut, ApiArgsType &allArgs, Json::Value &val #define API_ARGS1 SockInfo &sender,HttpSession::KeyValue &headerIn, HttpSession::KeyValue &headerOut, ApiArgsType &allArgs, Json::Value &val
#define API_ARGS2 API_ARGS1, const HttpSession::HttpResponseInvoker &invoker #define API_ARGS2 API_ARGS1, const HttpSession::HttpResponseInvoker &invoker
#define API_ARGS_VALUE1 sender,headerIn,headerOut,allArgs,val #define API_ARGS_VALUE1 sender,headerIn,headerOut,allArgs,val
#define API_ARGS_VALUE2 API_ARGS_VALUE1, invoker #define API_ARGS_VALUE2 API_ARGS_VALUE1, invoker
......
...@@ -190,7 +190,7 @@ void findAsync_l(const MediaInfo &info, const std::shared_ptr<TcpSession> &sessi ...@@ -190,7 +190,7 @@ void findAsync_l(const MediaInfo &info, const std::shared_ptr<TcpSession> &sessi
void *listener_tag = session.get(); void *listener_tag = session.get();
weak_ptr<TcpSession> weakSession = session; weak_ptr<TcpSession> weakSession = session;
//广播未找到流,此时可以立即去拉流,这样还来得及 //广播未找到流,此时可以立即去拉流,这样还来得及
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastNotFoundStream,info,*session); NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastNotFoundStream,info, static_cast<SockInfo &>(*session));
//最多等待一定时间,如果这个时间内,流未注册上,那么返回未找到流 //最多等待一定时间,如果这个时间内,流未注册上,那么返回未找到流
GET_CONFIG(int,maxWaitMS,General::kMaxStreamWaitTimeMS); GET_CONFIG(int,maxWaitMS,General::kMaxStreamWaitTimeMS);
......
...@@ -62,25 +62,25 @@ extern const string kBroadcastRecordMP4; ...@@ -62,25 +62,25 @@ extern const string kBroadcastRecordMP4;
//收到http api请求广播 //收到http api请求广播
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,SockInfo &sender
//在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限 //在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
extern const string kBroadcastHttpAccess; extern const string kBroadcastHttpAccess;
#define BroadcastHttpAccessArgs const Parser &parser,const string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,TcpSession &sender #define BroadcastHttpAccessArgs const Parser &parser,const string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,SockInfo &sender
//在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射 //在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
//在该事件中通过自行覆盖path参数,可以做到譬如根据虚拟主机或者app选择不同http根目录的目的 //在该事件中通过自行覆盖path参数,可以做到譬如根据虚拟主机或者app选择不同http根目录的目的
extern const string kBroadcastHttpBeforeAccess; extern const string kBroadcastHttpBeforeAccess;
#define BroadcastHttpBeforeAccessArgs const Parser &parser,string &path,TcpSession &sender #define BroadcastHttpBeforeAccessArgs const Parser &parser,string &path,SockInfo &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,SockInfo &sender
//请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败 //请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败
//获取到密码后请调用invoker并输入对应类型的密码和密码类型,invoker执行时会匹配密码 //获取到密码后请调用invoker并输入对应类型的密码和密码类型,invoker执行时会匹配密码
extern const string kBroadcastOnRtspAuth; extern const string kBroadcastOnRtspAuth;
#define BroadcastOnRtspAuthArgs const MediaInfo &args,const string &realm,const string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker,TcpSession &sender #define BroadcastOnRtspAuthArgs const MediaInfo &args,const string &realm,const string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker,SockInfo &sender
//推流鉴权结果回调对象 //推流鉴权结果回调对象
//如果errMessage为空则代表鉴权成功 //如果errMessage为空则代表鉴权成功
...@@ -91,7 +91,7 @@ typedef std::function<void(const string &errMessage,bool enableRtxp,bool enableH ...@@ -91,7 +91,7 @@ typedef std::function<void(const string &errMessage,bool enableRtxp,bool enableH
//收到rtsp/rtmp推流事件广播,通过该事件控制推流鉴权 //收到rtsp/rtmp推流事件广播,通过该事件控制推流鉴权
extern const string kBroadcastMediaPublish; extern const string kBroadcastMediaPublish;
#define BroadcastMediaPublishArgs const MediaInfo &args,const Broadcast::PublishAuthInvoker &invoker,TcpSession &sender #define BroadcastMediaPublishArgs const MediaInfo &args,const Broadcast::PublishAuthInvoker &invoker,SockInfo &sender
//播放鉴权结果回调对象 //播放鉴权结果回调对象
//如果errMessage为空则代表鉴权成功 //如果errMessage为空则代表鉴权成功
...@@ -99,11 +99,11 @@ typedef std::function<void(const string &errMessage)> AuthInvoker; ...@@ -99,11 +99,11 @@ typedef std::function<void(const string &errMessage)> AuthInvoker;
//播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权 //播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权
extern const string kBroadcastMediaPlayed; extern const string kBroadcastMediaPlayed;
#define BroadcastMediaPlayedArgs const MediaInfo &args,const Broadcast::AuthInvoker &invoker,TcpSession &sender #define BroadcastMediaPlayedArgs const MediaInfo &args,const Broadcast::AuthInvoker &invoker,SockInfo &sender
//shell登录鉴权 //shell登录鉴权
extern const string kBroadcastShellLogin; extern const string kBroadcastShellLogin;
#define BroadcastShellLoginArgs const string &user_name,const string &passwd,const Broadcast::AuthInvoker &invoker,TcpSession &sender #define BroadcastShellLoginArgs const string &user_name,const string &passwd,const Broadcast::AuthInvoker &invoker,SockInfo &sender
//停止rtsp/rtmp/http-flv会话后流量汇报事件广播 //停止rtsp/rtmp/http-flv会话后流量汇报事件广播
extern const string kBroadcastFlowReport; extern const string kBroadcastFlowReport;
...@@ -111,7 +111,7 @@ extern const string kBroadcastFlowReport; ...@@ -111,7 +111,7 @@ extern const string kBroadcastFlowReport;
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了 //未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
extern const string kBroadcastNotFoundStream; extern const string kBroadcastNotFoundStream;
#define BroadcastNotFoundStreamArgs const MediaInfo &args,TcpSession &sender #define BroadcastNotFoundStreamArgs const MediaInfo &args,SockInfo &sender
//某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑 //某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑
extern const string kBroadcastStreamNoneReader; extern const string kBroadcastStreamNoneReader;
......
...@@ -306,7 +306,7 @@ static bool emitHlsPlayed(const Parser &parser, const MediaInfo &mediaInfo, cons ...@@ -306,7 +306,7 @@ static bool emitHlsPlayed(const Parser &parser, const MediaInfo &mediaInfo, cons
//cookie有效期为kHlsCookieSecond //cookie有效期为kHlsCookieSecond
invoker(err,"",kHlsCookieSecond); invoker(err,"",kHlsCookieSecond);
}; };
return NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,mediaInfo,mediaAuthInvoker,sender); return NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,mediaInfo,mediaAuthInvoker,static_cast<SockInfo &>(sender));
} }
...@@ -407,7 +407,7 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI ...@@ -407,7 +407,7 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
} }
//事件未被拦截,则认为是http下载请求 //事件未被拦截,则认为是http下载请求
bool flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpAccess, parser, path, is_dir, accessPathInvoker, sender); bool flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpAccess, parser, path, is_dir, accessPathInvoker, static_cast<SockInfo &>(sender));
if (!flag) { if (!flag) {
//此事件无人监听,我们默认都有权限访问 //此事件无人监听,我们默认都有权限访问
callback("", nullptr); callback("", nullptr);
...@@ -521,7 +521,7 @@ static string getFilePath(const Parser &parser,const MediaInfo &mediaInfo, TcpSe ...@@ -521,7 +521,7 @@ static string getFilePath(const Parser &parser,const MediaInfo &mediaInfo, TcpSe
GET_CONFIG(bool, enableVhost, General::kEnableVhost); GET_CONFIG(bool, enableVhost, General::kEnableVhost);
GET_CONFIG(string, rootPath, Http::kRootPath); GET_CONFIG(string, rootPath, Http::kRootPath);
auto ret = File::absolutePath(enableVhost ? mediaInfo._vhost + parser.Url() : parser.Url(), rootPath); auto ret = File::absolutePath(enableVhost ? mediaInfo._vhost + parser.Url() : parser.Url(), rootPath);
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpBeforeAccess, parser, ret, sender); NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpBeforeAccess, parser, ret, static_cast<SockInfo &>(sender));
return std::move(ret); return std::move(ret);
} }
......
...@@ -241,7 +241,7 @@ bool HttpSession::checkLiveFlvStream(const function<void()> &cb){ ...@@ -241,7 +241,7 @@ bool HttpSession::checkLiveFlvStream(const function<void()> &cb){
onRes(err); onRes(err);
}); });
}; };
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,_mediaInfo,invoker,*this); auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,_mediaInfo,invoker,static_cast<SockInfo &>(*this));
if(!flag){ if(!flag){
//该事件无人监听,默认不鉴权 //该事件无人监听,默认不鉴权
onRes(""); onRes("");
...@@ -520,7 +520,8 @@ bool HttpSession::emitHttpEvent(bool doInvoke){ ...@@ -520,7 +520,8 @@ bool HttpSession::emitHttpEvent(bool doInvoke){
}; };
///////////////////广播HTTP事件/////////////////////////// ///////////////////广播HTTP事件///////////////////////////
bool consumed = false;//该事件是否被消费 bool consumed = false;//该事件是否被消费
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpRequest,_parser,invoker,consumed,*this); TcpSession &session = static_cast<TcpSession &>(*this);
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpRequest,_parser,invoker,consumed,static_cast<SockInfo &>(*this));
if(!consumed && doInvoke){ if(!consumed && doInvoke){
//该事件无人消费,所以返回404 //该事件无人消费,所以返回404
invoker("404 Not Found",KeyValue(), HttpBody::Ptr()); invoker("404 Not Found",KeyValue(), HttpBody::Ptr());
......
...@@ -171,10 +171,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) { ...@@ -171,10 +171,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
onRes(err,enableRtxp,enableHls,enableMP4); onRes(err,enableRtxp,enableHls,enableMP4);
}); });
}; };
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish, auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish,_mediaInfo,invoker,static_cast<SockInfo &>(*this));
_mediaInfo,
invoker,
*this);
if(!flag){ if(!flag){
//该事件无人监听,默认鉴权成功 //该事件无人监听,默认鉴权成功
GET_CONFIG(bool,toRtxp,General::kPublishToRtxp); GET_CONFIG(bool,toRtxp,General::kPublishToRtxp);
...@@ -346,7 +343,8 @@ void RtmpSession::doPlay(AMFDecoder &dec){ ...@@ -346,7 +343,8 @@ void RtmpSession::doPlay(AMFDecoder &dec){
strongSelf->doPlayResponse(err,[pToken](bool){}); strongSelf->doPlayResponse(err,[pToken](bool){});
}); });
}; };
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,_mediaInfo,invoker,*this);
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,_mediaInfo,invoker,static_cast<SockInfo &>(*this));
if(!flag){ if(!flag){
//该事件无人监听,默认不鉴权 //该事件无人监听,默认不鉴权
doPlayResponse("",[pToken](bool){}); doPlayResponse("",[pToken](bool){});
......
...@@ -302,7 +302,7 @@ void RtspSession::handleReq_RECORD(const Parser &parser){ ...@@ -302,7 +302,7 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
}; };
//rtsp推流需要鉴权 //rtsp推流需要鉴权
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish,_mediaInfo,invoker,*this); auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish,_mediaInfo,invoker,static_cast<SockInfo &>(*this));
if(!flag){ if(!flag){
//该事件无人监听,默认不鉴权 //该事件无人监听,默认不鉴权
GET_CONFIG(bool,toRtxp,General::kPublishToRtxp); GET_CONFIG(bool,toRtxp,General::kPublishToRtxp);
...@@ -341,10 +341,7 @@ void RtspSession::handleReq_Describe(const Parser &parser) { ...@@ -341,10 +341,7 @@ void RtspSession::handleReq_Describe(const Parser &parser) {
}; };
//广播是否需要认证事件 //广播是否需要认证事件
if(!NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastOnGetRtspRealm, if(!NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastOnGetRtspRealm,_mediaInfo,invoker,static_cast<SockInfo &>(*this))){
_mediaInfo,
invoker,
*this)){
//无人监听此事件,说明无需认证 //无人监听此事件,说明无需认证
invoker(""); invoker("");
} }
...@@ -446,7 +443,7 @@ void RtspSession::onAuthBasic(const string &realm,const string &strBase64){ ...@@ -446,7 +443,7 @@ void RtspSession::onAuthBasic(const string &realm,const string &strBase64){
}; };
//此时必须提供明文密码 //此时必须提供明文密码
if(!NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastOnRtspAuth,_mediaInfo,realm,user, true,invoker,*this)){ if(!NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastOnRtspAuth,_mediaInfo,realm,user, true,invoker,static_cast<SockInfo &>(*this))){
//表明该流需要认证却没监听请求密码事件,这一般是大意的程序所为,警告之 //表明该流需要认证却没监听请求密码事件,这一般是大意的程序所为,警告之
WarnP(this) << "请监听kBroadcastOnRtspAuth事件!"; WarnP(this) << "请监听kBroadcastOnRtspAuth事件!";
//但是我们还是忽略认证以便完成播放 //但是我们还是忽略认证以便完成播放
...@@ -530,7 +527,7 @@ void RtspSession::onAuthDigest(const string &realm,const string &strMd5){ ...@@ -530,7 +527,7 @@ void RtspSession::onAuthDigest(const string &realm,const string &strMd5){
}; };
//此时可以提供明文或md5加密的密码 //此时可以提供明文或md5加密的密码
if(!NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastOnRtspAuth,_mediaInfo,realm,username, false,invoker,*this)){ if(!NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastOnRtspAuth,_mediaInfo,realm,username, false,invoker,static_cast<SockInfo &>(*this))){
//表明该流需要认证却没监听请求密码事件,这一般是大意的程序所为,警告之 //表明该流需要认证却没监听请求密码事件,这一般是大意的程序所为,警告之
WarnP(this) << "请监听kBroadcastOnRtspAuth事件!"; WarnP(this) << "请监听kBroadcastOnRtspAuth事件!";
//但是我们还是忽略认证以便完成播放 //但是我们还是忽略认证以便完成播放
...@@ -824,7 +821,7 @@ void RtspSession::handleReq_Play(const Parser &parser) { ...@@ -824,7 +821,7 @@ void RtspSession::handleReq_Play(const Parser &parser) {
}; };
if(_bFirstPlay){ if(_bFirstPlay){
//第一次收到play命令,需要鉴权 //第一次收到play命令,需要鉴权
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,_mediaInfo,invoker,*this); auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,_mediaInfo,invoker,static_cast<SockInfo &>(*this));
if(!flag){ if(!flag){
//该事件无人监听,默认不鉴权 //该事件无人监听,默认不鉴权
onRes(""); onRes("");
......
...@@ -136,7 +136,7 @@ inline void ShellSession::pleaseInputPasswd() { ...@@ -136,7 +136,7 @@ inline void ShellSession::pleaseInputPasswd() {
}); });
}; };
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastShellLogin,_strUserName,passwd,invoker,*this); auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastShellLogin,_strUserName,passwd,invoker,static_cast<SockInfo &>(*this));
if(!flag){ if(!flag){
//如果无人监听shell登录事件,那么默认shell无法登录 //如果无人监听shell登录事件,那么默认shell无法登录
onAuth("please listen kBroadcastShellLogin event"); onAuth("please listen kBroadcastShellLogin event");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论