Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
cf8b6f6b
Commit
cf8b6f6b
authored
Feb 05, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
鉴权失败添加错误描述信息
parent
805a1a94
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
36 行增加
和
31 行删除
+36
-31
src/Common/config.h
+1
-1
src/Http/HttpSession.cpp
+6
-7
src/Rtmp/RtmpSession.cpp
+14
-14
src/Rtsp/RtspSession.cpp
+11
-7
tests/test_server.cpp
+4
-2
没有找到文件。
src/Common/config.h
查看文件 @
cf8b6f6b
...
...
@@ -86,7 +86,7 @@ extern const char kBroadcastOnRtspAuth[];
//鉴权结果回调对象
typedef
std
::
function
<
void
(
bool
success
)
>
AuthInvoker
;
typedef
std
::
function
<
void
(
bool
success
,
const
string
&
errMessage
)
>
AuthInvoker
;
//收到rtmp推流事件广播,通过该事件控制推流鉴权
extern
const
char
kBroadcastRtmpPublish
[];
...
...
src/Http/HttpSession.cpp
查看文件 @
cf8b6f6b
...
...
@@ -202,10 +202,9 @@ inline bool HttpSession::checkLiveFlvStream(){
return
true
;
}
auto
onRes
=
[
this
,
mediaSrc
](
bool
authSuccess
){
auto
onRes
=
[
this
,
mediaSrc
](
bool
authSuccess
,
const
string
&
err
){
if
(
!
authSuccess
){
string
status
=
"401 Unauthorized"
;
sendResponse
(
status
.
data
(),
makeHttpHeader
(
true
,
status
.
size
()),
status
);
sendResponse
(
"401 Unauthorized"
,
makeHttpHeader
(
true
,
err
.
size
()),
err
);
shutdown
();
return
;
}
...
...
@@ -276,23 +275,23 @@ inline bool HttpSession::checkLiveFlvStream(){
};
weak_ptr
<
HttpSession
>
weakSelf
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
authSuccess
){
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
authSuccess
,
const
string
&
err
){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
return
;
}
strongSelf
->
async
([
weakSelf
,
onRes
,
authSuccess
](){
strongSelf
->
async
([
weakSelf
,
onRes
,
authSuccess
,
err
](){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
return
;
}
onRes
(
authSuccess
);
onRes
(
authSuccess
,
err
);
});
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
info
,
invoker
);
if
(
!
flag
){
//该事件无人监听,默认不鉴权
onRes
(
true
);
onRes
(
true
,
""
);
}
return
true
;
}
...
...
src/Rtmp/RtmpSession.cpp
查看文件 @
cf8b6f6b
...
...
@@ -130,7 +130,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
dec
.
load
<
AMFValue
>
();
/* NULL */
m_mediaInfo
.
parse
(
m_strTcUrl
+
"/"
+
dec
.
load
<
std
::
string
>
());
auto
onRes
=
[
this
](
bool
authSuccess
){
auto
onRes
=
[
this
](
bool
authSuccess
,
const
string
&
err
){
auto
src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
MediaSource
::
find
(
RTMP_SCHEMA
,
m_mediaInfo
.
m_vhost
,
m_mediaInfo
.
m_app
,
...
...
@@ -140,12 +140,12 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
AMFValue
status
(
AMF_OBJECT
);
status
.
set
(
"level"
,
ok
?
"status"
:
"error"
);
status
.
set
(
"code"
,
ok
?
"NetStream.Publish.Start"
:
(
authSuccess
?
"NetStream.Publish.BadName"
:
"NetStream.Publish.BadAuth"
));
status
.
set
(
"description"
,
ok
?
"Started publishing stream."
:
(
authSuccess
?
"Already publishing."
:
"Auth failed"
));
status
.
set
(
"description"
,
ok
?
"Started publishing stream."
:
(
authSuccess
?
"Already publishing."
:
err
.
data
()
));
status
.
set
(
"clientid"
,
"0"
);
sendReply
(
"onStatus"
,
nullptr
,
status
);
if
(
!
ok
)
{
WarnL
<<
"onPublish:"
<<
(
authSuccess
?
"Already publishing:"
:
"Auth failed:"
)
<<
(
authSuccess
?
"Already publishing:"
:
err
.
data
()
)
<<
m_mediaInfo
.
m_vhost
<<
" "
<<
m_mediaInfo
.
m_app
<<
" "
<<
m_mediaInfo
.
m_streamid
<<
endl
;
...
...
@@ -157,17 +157,17 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
};
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
success
){
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
success
,
const
string
&
err
){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
return
;
}
strongSelf
->
async
([
weakSelf
,
onRes
,
success
](){
strongSelf
->
async
([
weakSelf
,
onRes
,
success
,
err
](){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
return
;
}
onRes
(
success
);
onRes
(
success
,
err
);
});
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Config
::
Broadcast
::
kBroadcastRtmpPublish
,
...
...
@@ -175,7 +175,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
invoker
);
if
(
!
flag
){
//该事件无人监听,默认鉴权成功
onRes
(
true
);
onRes
(
true
,
""
);
}
}
...
...
@@ -189,7 +189,7 @@ void RtmpSession::onCmd_deleteStream(AMFDecoder &dec) {
}
void
RtmpSession
::
doPlay
(
AMFDecoder
&
dec
){
auto
onRes
=
[
this
](
bool
authSuccess
)
{
auto
onRes
=
[
this
](
bool
authSuccess
,
const
string
&
err
)
{
auto
src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
MediaSource
::
find
(
RTMP_SCHEMA
,
m_mediaInfo
.
m_vhost
,
m_mediaInfo
.
m_app
,
...
...
@@ -207,13 +207,13 @@ void RtmpSession::doPlay(AMFDecoder &dec){
AMFValue
status
(
AMF_OBJECT
);
status
.
set
(
"level"
,
ok
?
"status"
:
"error"
);
status
.
set
(
"code"
,
ok
?
"NetStream.Play.Reset"
:
(
authSuccess
?
"NetStream.Play.StreamNotFound"
:
"NetStream.Play.BadAuth"
));
status
.
set
(
"description"
,
ok
?
"Resetting and playing."
:
(
authSuccess
?
"No such stream."
:
"Auth failed"
));
status
.
set
(
"description"
,
ok
?
"Resetting and playing."
:
(
authSuccess
?
"No such stream."
:
err
.
data
()
));
status
.
set
(
"details"
,
m_mediaInfo
.
m_streamid
);
status
.
set
(
"clientid"
,
"0"
);
sendReply
(
"onStatus"
,
nullptr
,
status
);
if
(
!
ok
)
{
WarnL
<<
"onPlayed:"
<<
(
authSuccess
?
"No such stream:"
:
"Auth failed:"
)
<<
(
authSuccess
?
"No such stream:"
:
err
.
data
()
)
<<
m_mediaInfo
.
m_vhost
<<
" "
<<
m_mediaInfo
.
m_app
<<
" "
<<
m_mediaInfo
.
m_streamid
...
...
@@ -292,23 +292,23 @@ void RtmpSession::doPlay(AMFDecoder &dec){
};
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
authSuccess
){
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
authSuccess
,
const
string
&
err
){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
return
;
}
strongSelf
->
async
([
weakSelf
,
onRes
,
authSuccess
](){
strongSelf
->
async
([
weakSelf
,
onRes
,
authSuccess
,
err
](){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
return
;
}
onRes
(
authSuccess
);
onRes
(
authSuccess
,
err
);
});
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
m_mediaInfo
,
invoker
);
if
(
!
flag
){
//该事件无人监听,默认不鉴权
onRes
(
true
);
onRes
(
true
,
""
);
}
}
void
RtmpSession
::
onCmd_play2
(
AMFDecoder
&
dec
)
{
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
cf8b6f6b
...
...
@@ -641,7 +641,7 @@ bool RtspSession::handleReq_Play() {
send_SessionNotFound
();
return
false
;
}
auto
onRes
=
[
this
](
bool
authSuccess
){
auto
onRes
=
[
this
](
bool
authSuccess
,
const
string
&
err
){
char
response
[
2
*
1024
];
m_pcBuf
=
response
;
if
(
!
authSuccess
&&
m_bFirstPlay
){
...
...
@@ -650,8 +650,12 @@ bool RtspSession::handleReq_Play() {
"RTSP/1.0 401 Unauthorized
\r\n
"
"CSeq: %d
\r\n
"
"Server: %s-%0.2f(build in %s)
\r\n
"
"%s
\r\n
"
,
m_iCseq
,
SERVER_NAME
,
RTSP_VERSION
,
RTSP_BUILDTIME
,
dateHeader
().
data
());
"%s"
"Content-Type: text/plain
\r\n
"
"Content-Length: %d
\r\n\r\n
%s"
,
m_iCseq
,
SERVER_NAME
,
RTSP_VERSION
,
RTSP_BUILDTIME
,
dateHeader
().
data
(),(
int
)
err
.
size
(),
err
.
data
());
send
(
m_pcBuf
,
n
);
shutdown
();
return
;
...
...
@@ -730,23 +734,23 @@ bool RtspSession::handleReq_Play() {
};
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
authSuccess
){
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
authSuccess
,
const
string
&
err
){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
return
;
}
strongSelf
->
async
([
weakSelf
,
onRes
,
authSuccess
](){
strongSelf
->
async
([
weakSelf
,
onRes
,
authSuccess
,
err
](){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
return
;
}
onRes
(
authSuccess
);
onRes
(
authSuccess
,
err
);
});
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
m_mediaInfo
,
invoker
);
if
(
!
flag
){
//该事件无人监听,默认不鉴权
onRes
(
true
);
onRes
(
true
,
""
);
}
return
true
;
}
...
...
tests/test_server.cpp
查看文件 @
cf8b6f6b
...
...
@@ -112,14 +112,16 @@ static onceToken s_token([](){
NoticeCenter
::
Instance
().
addListener
(
nullptr
,
Config
::
Broadcast
::
kBroadcastRtmpPublish
,[](
BroadcastRtmpPublishArgs
){
InfoL
<<
args
.
m_vhost
<<
" "
<<
args
.
m_app
<<
" "
<<
args
.
m_streamid
<<
" "
<<
args
.
m_param_strs
;
EventPoller
::
Instance
().
async
([
invoker
](){
invoker
(
true
);
//invoker(true,"");//鉴权成功
invoker
(
false
,
"this is auth failed message"
);
//鉴权失败
});
});
NoticeCenter
::
Instance
().
addListener
(
nullptr
,
Config
::
Broadcast
::
kBroadcastMediaPlayed
,[](
BroadcastMediaPlayedArgs
){
InfoL
<<
args
.
m_schema
<<
" "
<<
args
.
m_vhost
<<
" "
<<
args
.
m_app
<<
" "
<<
args
.
m_streamid
<<
" "
<<
args
.
m_param_strs
;
EventPoller
::
Instance
().
async
([
invoker
](){
invoker
(
true
);
//invoker(true,"");//鉴权成功
invoker
(
false
,
"this is auth failed message"
);
//鉴权失败
});
});
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论