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
af0ebf46
Commit
af0ebf46
authored
Jun 10, 2023
by
xia-chu
Committed by
夏楚
Jun 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化Parser代码命名
parent
52c7bc1d
隐藏空白字符变更
内嵌
并排
正在显示
24 个修改的文件
包含
156 行增加
和
147 行删除
+156
-147
api/source/mk_events_objects.cpp
+6
-6
api/source/mk_httpclient.cpp
+3
-3
player/test_player.cpp
+1
-2
server/WebApi.cpp
+9
-9
server/WebHook.cpp
+5
-5
server/main.cpp
+2
-2
src/Common/Parser.cpp
+17
-9
src/Common/Parser.h
+38
-36
src/Http/HlsParser.cpp
+1
-1
src/Http/HttpClient.cpp
+5
-5
src/Http/HttpFileManager.cpp
+8
-8
src/Http/HttpSession.cpp
+8
-8
src/Rtmp/RtmpPlayer.cpp
+1
-1
src/Rtmp/RtmpPlayerImp.h
+1
-1
src/Rtmp/RtmpPusher.cpp
+1
-1
src/Rtsp/RtspPlayer.cpp
+14
-14
src/Rtsp/RtspPlayerImp.h
+1
-1
src/Rtsp/RtspPusher.cpp
+8
-8
src/Rtsp/RtspSession.cpp
+11
-11
src/Rtsp/RtspSplitter.cpp
+2
-2
tests/test_httpApi.cpp
+6
-6
tests/test_httpClient.cpp
+6
-6
tests/test_wsServer.cpp
+1
-1
webrtc/WebRtcTransport.cpp
+1
-1
没有找到文件。
api/source/mk_events_objects.cpp
查看文件 @
af0ebf46
...
...
@@ -86,17 +86,17 @@ API_EXPORT const char* API_CALL mk_mp4_info_get_stream(const mk_mp4_info ctx){
API_EXPORT
const
char
*
API_CALL
mk_parser_get_method
(
const
mk_parser
ctx
){
assert
(
ctx
);
Parser
*
parser
=
(
Parser
*
)
ctx
;
return
parser
->
M
ethod
().
c_str
();
return
parser
->
m
ethod
().
c_str
();
}
API_EXPORT
const
char
*
API_CALL
mk_parser_get_url
(
const
mk_parser
ctx
){
assert
(
ctx
);
Parser
*
parser
=
(
Parser
*
)
ctx
;
return
parser
->
U
rl
().
c_str
();
return
parser
->
u
rl
().
c_str
();
}
API_EXPORT
const
char
*
API_CALL
mk_parser_get_url_params
(
const
mk_parser
ctx
){
assert
(
ctx
);
Parser
*
parser
=
(
Parser
*
)
ctx
;
return
parser
->
P
arams
().
c_str
();
return
parser
->
p
arams
().
c_str
();
}
API_EXPORT
const
char
*
API_CALL
mk_parser_get_url_param
(
const
mk_parser
ctx
,
const
char
*
key
){
assert
(
ctx
&&
key
);
...
...
@@ -106,7 +106,7 @@ API_EXPORT const char* API_CALL mk_parser_get_url_param(const mk_parser ctx,cons
API_EXPORT
const
char
*
API_CALL
mk_parser_get_tail
(
const
mk_parser
ctx
){
assert
(
ctx
);
Parser
*
parser
=
(
Parser
*
)
ctx
;
return
parser
->
Tai
l
().
c_str
();
return
parser
->
protoco
l
().
c_str
();
}
API_EXPORT
const
char
*
API_CALL
mk_parser_get_header
(
const
mk_parser
ctx
,
const
char
*
key
){
assert
(
ctx
&&
key
);
...
...
@@ -117,9 +117,9 @@ API_EXPORT const char* API_CALL mk_parser_get_content(const mk_parser ctx, size_
assert
(
ctx
);
Parser
*
parser
=
(
Parser
*
)
ctx
;
if
(
length
){
*
length
=
parser
->
C
ontent
().
size
();
*
length
=
parser
->
c
ontent
().
size
();
}
return
parser
->
C
ontent
().
c_str
();
return
parser
->
c
ontent
().
c_str
();
}
///////////////////////////////////////////MediaInfo/////////////////////////////////////////////
...
...
api/source/mk_httpclient.cpp
查看文件 @
af0ebf46
...
...
@@ -108,7 +108,7 @@ API_EXPORT void API_CALL mk_http_requester_add_header(mk_http_requester ctx,cons
API_EXPORT
const
char
*
API_CALL
mk_http_requester_get_response_status
(
mk_http_requester
ctx
){
assert
(
ctx
);
HttpRequester
::
Ptr
*
obj
=
(
HttpRequester
::
Ptr
*
)
ctx
;
return
(
*
obj
)
->
response
().
Url
().
c_str
();
return
(
*
obj
)
->
response
().
status
().
c_str
();
}
API_EXPORT
const
char
*
API_CALL
mk_http_requester_get_response_header
(
mk_http_requester
ctx
,
const
char
*
key
){
...
...
@@ -121,9 +121,9 @@ API_EXPORT const char* API_CALL mk_http_requester_get_response_body(mk_http_requ
assert
(
ctx
);
HttpRequester
::
Ptr
*
obj
=
(
HttpRequester
::
Ptr
*
)
ctx
;
if
(
length
){
*
length
=
(
*
obj
)
->
response
().
C
ontent
().
size
();
*
length
=
(
*
obj
)
->
response
().
c
ontent
().
size
();
}
return
(
*
obj
)
->
response
().
C
ontent
().
c_str
();
return
(
*
obj
)
->
response
().
c
ontent
().
c_str
();
}
API_EXPORT
mk_parser
API_CALL
mk_http_requester_get_response
(
mk_http_requester
ctx
){
...
...
player/test_player.cpp
查看文件 @
af0ebf46
...
...
@@ -56,8 +56,7 @@ int main(int argc, char *argv[]) {
if
(
argc
<
3
)
{
ErrorL
<<
"
\r\n
测试方法:./test_player rtxp_url rtp_type
\r\n
"
<<
"例如:./test_player rtsp://admin:123456@127.0.0.1/live/0 0
\r\n
"
<<
endl
;
<<
"例如:./test_player rtsp://admin:123456@127.0.0.1/live/0 0
\r\n
"
;
return
0
;
}
...
...
server/WebApi.cpp
查看文件 @
af0ebf46
...
...
@@ -130,7 +130,7 @@ static HttpApi toApi(const function<void(API_ARGS_JSON_ASYNC)> &cb) {
//参数解析成json对象然后处理
Json
::
Value
args
;
Json
::
Reader
reader
;
reader
.
parse
(
parser
.
C
ontent
(),
args
);
reader
.
parse
(
parser
.
c
ontent
(),
args
);
cb
(
sender
,
headerOut
,
HttpAllArgs
<
decltype
(
args
)
>
(
parser
,
args
),
val
,
invoker
);
};
...
...
@@ -152,7 +152,7 @@ static HttpApi toApi(const function<void(API_ARGS_STRING_ASYNC)> &cb) {
Json
::
Value
val
;
val
[
"code"
]
=
API
::
Success
;
cb
(
sender
,
headerOut
,
HttpAllArgs
<
string
>
(
parser
,
(
string
&
)
parser
.
C
ontent
()),
val
,
invoker
);
cb
(
sender
,
headerOut
,
HttpAllArgs
<
string
>
(
parser
,
(
string
&
)
parser
.
c
ontent
()),
val
,
invoker
);
};
}
...
...
@@ -191,13 +191,13 @@ void api_regist(const string &api_path, const function<void(API_ARGS_STRING_ASYN
static
ApiArgsType
getAllArgs
(
const
Parser
&
parser
)
{
ApiArgsType
allArgs
;
if
(
parser
[
"Content-Type"
].
find
(
"application/x-www-form-urlencoded"
)
==
0
)
{
auto
contentArgs
=
parser
.
parseArgs
(
parser
.
C
ontent
());
auto
contentArgs
=
parser
.
parseArgs
(
parser
.
c
ontent
());
for
(
auto
&
pr
:
contentArgs
)
{
allArgs
[
pr
.
first
]
=
HttpSession
::
urlDecode
(
pr
.
second
);
}
}
else
if
(
parser
[
"Content-Type"
].
find
(
"application/json"
)
==
0
)
{
try
{
stringstream
ss
(
parser
.
C
ontent
());
stringstream
ss
(
parser
.
c
ontent
());
Value
jsonArgs
;
ss
>>
jsonArgs
;
auto
keys
=
jsonArgs
.
getMemberNames
();
...
...
@@ -231,7 +231,7 @@ static inline void addHttpListener(){
GET_CONFIG
(
bool
,
api_debug
,
API
::
kApiDebug
);
//注册监听kBroadcastHttpRequest事件
NoticeCenter
::
Instance
().
addListener
(
&
web_api_tag
,
Broadcast
::
kBroadcastHttpRequest
,
[](
BroadcastHttpRequestArgs
)
{
auto
it
=
s_map_api
.
find
(
parser
.
U
rl
());
auto
it
=
s_map_api
.
find
(
parser
.
u
rl
());
if
(
it
==
s_map_api
.
end
())
{
return
;
}
...
...
@@ -248,14 +248,14 @@ static inline void addHttpListener(){
}
LogContextCapture
log
(
getLogger
(),
toolkit
::
LTrace
,
__FILE__
,
"http api debug"
,
__LINE__
);
log
<<
"
\r\n
# request:
\r\n
"
<<
parser
.
Method
()
<<
" "
<<
parser
.
F
ullUrl
()
<<
"
\r\n
"
;
log
<<
"
\r\n
# request:
\r\n
"
<<
parser
.
method
()
<<
" "
<<
parser
.
f
ullUrl
()
<<
"
\r\n
"
;
log
<<
"# header:
\r\n
"
;
for
(
auto
&
pr
:
parser
.
getHeader
())
{
log
<<
pr
.
first
<<
" : "
<<
pr
.
second
<<
"
\r\n
"
;
}
auto
&
content
=
parser
.
C
ontent
();
auto
&
content
=
parser
.
c
ontent
();
log
<<
"# content:
\r\n
"
<<
(
content
.
size
()
>
4
*
1024
?
content
.
substr
(
0
,
4
*
1024
)
:
content
)
<<
"
\r\n
"
;
if
(
size
>
0
&&
size
<
4
*
1024
)
{
...
...
@@ -1637,7 +1637,7 @@ void installWebApi() {
CHECK_ARGS
(
"app"
,
"stream"
);
return
StrPrinter
<<
RTC_SCHEMA
<<
"://"
<<
_args
[
"Host"
]
<<
"/"
<<
_args
[
"app"
]
<<
"/"
<<
_args
[
"stream"
]
<<
"?"
<<
_args
.
getParser
().
P
arams
()
+
"&session="
+
_session_id
;
<<
_args
[
"stream"
]
<<
"?"
<<
_args
.
getParser
().
p
arams
()
+
"&session="
+
_session_id
;
}
private
:
...
...
@@ -1700,7 +1700,7 @@ void installWebApi() {
api_regist
(
delete_webrtc_url
,
[](
API_ARGS_MAP_ASYNC
)
{
CHECK_ARGS
(
"id"
,
"token"
);
CHECK
(
allArgs
.
getParser
().
Method
()
==
"DELETE"
,
"http method is not DELETE: "
+
allArgs
.
getParser
().
M
ethod
());
CHECK
(
allArgs
.
getParser
().
method
()
==
"DELETE"
,
"http method is not DELETE: "
+
allArgs
.
getParser
().
m
ethod
());
auto
obj
=
WebRtcTransportManager
::
Instance
().
getItem
(
allArgs
[
"id"
]);
if
(
!
obj
)
{
invoker
(
404
,
headerOut
,
"id not found"
);
...
...
server/WebHook.cpp
查看文件 @
af0ebf46
...
...
@@ -100,14 +100,14 @@ static void parse_http_response(const SockException &ex, const Parser &res, cons
fun
(
Json
::
nullValue
,
errStr
,
should_retry
);
return
;
}
if
(
res
.
Url
()
!=
"200"
)
{
auto
errStr
=
StrPrinter
<<
"[bad http status code]:"
<<
res
.
Url
()
<<
endl
;
if
(
res
.
status
()
!=
"200"
)
{
auto
errStr
=
StrPrinter
<<
"[bad http status code]:"
<<
res
.
status
()
<<
endl
;
fun
(
Json
::
nullValue
,
errStr
,
should_retry
);
return
;
}
Value
result
;
try
{
stringstream
ss
(
res
.
C
ontent
());
stringstream
ss
(
res
.
c
ontent
());
ss
>>
result
;
}
catch
(
std
::
exception
&
ex
)
{
auto
errStr
=
StrPrinter
<<
"[parse json failed]:"
<<
ex
.
what
()
<<
endl
;
...
...
@@ -614,7 +614,7 @@ void installWebHook() {
// 追踪用户的目的是为了缓存上次鉴权结果,减少鉴权次数,提高性能
NoticeCenter
::
Instance
().
addListener
(
&
web_hook_tag
,
Broadcast
::
kBroadcastHttpAccess
,
[](
BroadcastHttpAccessArgs
)
{
GET_CONFIG
(
string
,
hook_http_access
,
Hook
::
kOnHttpAccess
);
if
(
sender
.
get_peer_ip
()
==
"127.0.0.1"
||
parser
.
P
arams
()
==
hook_adminparams
)
{
if
(
sender
.
get_peer_ip
()
==
"127.0.0.1"
||
parser
.
p
arams
()
==
hook_adminparams
)
{
// 如果是本机或超级管理员访问,那么不做访问鉴权;权限有效期1个小时
invoker
(
""
,
""
,
60
*
60
);
return
;
...
...
@@ -632,7 +632,7 @@ void installWebHook() {
body
[
"id"
]
=
sender
.
getIdentifier
();
body
[
"path"
]
=
path
;
body
[
"is_dir"
]
=
is_dir
;
body
[
"params"
]
=
parser
.
P
arams
();
body
[
"params"
]
=
parser
.
p
arams
();
for
(
auto
&
pr
:
parser
.
getHeader
())
{
body
[
string
(
"header."
)
+
pr
.
first
]
=
pr
.
second
;
}
...
...
server/main.cpp
查看文件 @
af0ebf46
...
...
@@ -363,8 +363,8 @@ int start_main(int argc,char *argv[]) {
#endif//defined(ENABLE_SRT)
}
catch
(
std
::
exception
&
ex
)
{
WarnL
<<
"端口占用或无权限:"
<<
ex
.
what
()
<<
endl
;
ErrorL
<<
"程序启动失败,请修改配置文件中端口号后重试!"
<<
endl
;
WarnL
<<
"端口占用或无权限:"
<<
ex
.
what
();
ErrorL
<<
"程序启动失败,请修改配置文件中端口号后重试!"
;
sleep
(
1
);
#if !defined(_WIN32)
if
(
pid
!=
getpid
()
&&
kill_parent_if_failed
)
{
...
...
src/Common/Parser.cpp
查看文件 @
af0ebf46
...
...
@@ -44,7 +44,7 @@ string FindField(const char* buf, const char* start, const char *end ,size_t buf
void
Parser
::
Parse
(
const
char
*
buf
)
{
//解析
const
char
*
start
=
buf
;
C
lear
();
c
lear
();
while
(
true
)
{
auto
line
=
FindField
(
start
,
NULL
,
"
\r\n
"
);
if
(
line
.
size
()
==
0
)
{
...
...
@@ -77,25 +77,33 @@ void Parser::Parse(const char *buf) {
}
}
const
string
&
Parser
::
M
ethod
()
const
{
const
string
&
Parser
::
m
ethod
()
const
{
return
_strMethod
;
}
const
string
&
Parser
::
U
rl
()
const
{
const
string
&
Parser
::
u
rl
()
const
{
return
_strUrl
;
}
string
Parser
::
FullUrl
()
const
{
const
std
::
string
&
Parser
::
status
()
const
{
return
url
();
}
string
Parser
::
fullUrl
()
const
{
if
(
_params
.
empty
())
{
return
_strUrl
;
}
return
_strUrl
+
"?"
+
_params
;
}
const
string
&
Parser
::
Tai
l
()
const
{
const
string
&
Parser
::
protoco
l
()
const
{
return
_strTail
;
}
const
std
::
string
&
Parser
::
statusStr
()
const
{
return
protocol
();
}
const
string
&
Parser
::
operator
[](
const
char
*
name
)
const
{
auto
it
=
_mapHeaders
.
find
(
name
);
if
(
it
==
_mapHeaders
.
end
())
{
...
...
@@ -104,11 +112,11 @@ const string &Parser::operator[](const char *name) const {
return
it
->
second
;
}
const
string
&
Parser
::
C
ontent
()
const
{
const
string
&
Parser
::
c
ontent
()
const
{
return
_strContent
;
}
void
Parser
::
C
lear
()
{
void
Parser
::
c
lear
()
{
_strMethod
.
clear
();
_strUrl
.
clear
();
_params
.
clear
();
...
...
@@ -118,7 +126,7 @@ void Parser::Clear() {
_mapUrlArgs
.
clear
();
}
const
string
&
Parser
::
P
arams
()
const
{
const
string
&
Parser
::
p
arams
()
const
{
return
_params
;
}
...
...
@@ -159,7 +167,7 @@ StrCaseMap Parser::parseArgs(const string &str, const char *pair_delim, const ch
}
return
ret
;
}
std
::
string
Parser
::
merge
_u
rl
(
const
string
&
base_url
,
const
string
&
path
)
{
std
::
string
Parser
::
merge
U
rl
(
const
string
&
base_url
,
const
string
&
path
)
{
//以base_url为基础, 合并path路径生成新的url, path支持相对路径和绝对路径
if
(
base_url
.
empty
())
{
return
path
;
...
...
src/Common/Parser.h
查看文件 @
af0ebf46
...
...
@@ -17,15 +17,13 @@
namespace
mediakit
{
//从字符串中提取子字符串
//
从字符串中提取子字符串
std
::
string
FindField
(
const
char
*
buf
,
const
char
*
start
,
const
char
*
end
,
size_t
bufSize
=
0
);
//把url解析为主机地址和端口号,兼容ipv4/ipv6/dns
void
splitUrl
(
const
std
::
string
&
url
,
std
::
string
&
host
,
uint16_t
&
port
);
//
把url解析为主机地址和端口号,兼容ipv4/ipv6/dns
void
splitUrl
(
const
std
::
string
&
url
,
std
::
string
&
host
,
uint16_t
&
port
);
struct
StrCaseCompare
{
bool
operator
()(
const
std
::
string
&
__x
,
const
std
::
string
&
__y
)
const
{
return
strcasecmp
(
__x
.
data
(),
__y
.
data
())
<
0
;
}
bool
operator
()(
const
std
::
string
&
__x
,
const
std
::
string
&
__y
)
const
{
return
strcasecmp
(
__x
.
data
(),
__y
.
data
())
<
0
;
}
};
class
StrCaseMap
:
public
std
::
multimap
<
std
::
string
,
std
::
string
,
StrCaseCompare
>
{
...
...
@@ -42,7 +40,7 @@ public:
return
it
->
second
;
}
template
<
typename
V
>
template
<
typename
V
>
void
emplace
(
const
std
::
string
&
k
,
V
&&
v
)
{
auto
it
=
find
(
k
);
if
(
it
!=
end
())
{
...
...
@@ -51,61 +49,65 @@ public:
Super
::
emplace
(
k
,
std
::
forward
<
V
>
(
v
));
}
template
<
typename
V
>
template
<
typename
V
>
void
emplace_force
(
const
std
::
string
k
,
V
&&
v
)
{
Super
::
emplace
(
k
,
std
::
forward
<
V
>
(
v
));
}
};
//rtsp/http/sip解析类
//
rtsp/http/sip解析类
class
Parser
{
public
:
Parser
()
=
default
;
~
Parser
()
=
default
;
//解析信令
//
解析信令
void
Parse
(
const
char
*
buf
);
//获取命令字
const
std
::
string
&
M
ethod
()
const
;
//
获取命令字
const
std
::
string
&
m
ethod
()
const
;
//获取中间url,不包含?后面的参数
const
std
::
string
&
Url
()
const
;
// 请求时,获取中间url,不包含?后面的参数
const
std
::
string
&
url
()
const
;
// 回复时,获取状态码
const
std
::
string
&
status
()
const
;
//获取中间url,包含?后面的参数
std
::
string
F
ullUrl
()
const
;
//
获取中间url,包含?后面的参数
std
::
string
f
ullUrl
()
const
;
//获取命令协议名
const
std
::
string
&
Tail
()
const
;
// 请求时,获取协议名
const
std
::
string
&
protocol
()
const
;
// 回复时,获取状态字符串
const
std
::
string
&
statusStr
()
const
;
//根据header key名,获取请求header value值
//
根据header key名,获取请求header value值
const
std
::
string
&
operator
[](
const
char
*
name
)
const
;
//获取http body或sdp
const
std
::
string
&
C
ontent
()
const
;
//
获取http body或sdp
const
std
::
string
&
c
ontent
()
const
;
//清空,为了重用
void
C
lear
();
//
清空,为了重用
void
c
lear
();
//获取?后面的参数
const
std
::
string
&
P
arams
()
const
;
//
获取?后面的参数
const
std
::
string
&
p
arams
()
const
;
//重新设置url
//
重新设置url
void
setUrl
(
std
::
string
url
);
//重新设置content
//
重新设置content
void
setContent
(
std
::
string
content
);
//获取header列表
//
获取header列表
StrCaseMap
&
getHeader
()
const
;
//获取url参数列表
//
获取url参数列表
StrCaseMap
&
getUrlArgs
()
const
;
//解析?后面的参数
//
解析?后面的参数
static
StrCaseMap
parseArgs
(
const
std
::
string
&
str
,
const
char
*
pair_delim
=
"&"
,
const
char
*
key_delim
=
"="
);
static
std
::
string
merge
_u
rl
(
const
std
::
string
&
base_url
,
const
std
::
string
&
path
);
static
std
::
string
merge
U
rl
(
const
std
::
string
&
base_url
,
const
std
::
string
&
path
);
private
:
std
::
string
_strMethod
;
...
...
@@ -118,8 +120,8 @@ private:
mutable
StrCaseMap
_mapUrlArgs
;
};
//解析rtsp url的工具类
class
RtspUrl
{
//
解析rtsp url的工具类
class
RtspUrl
{
public
:
bool
_is_ssl
;
uint16_t
_port
;
...
...
@@ -134,9 +136,9 @@ public:
void
parse
(
const
std
::
string
&
url
);
private
:
void
setup
(
bool
,
const
std
::
string
&
,
const
std
::
string
&
,
const
std
::
string
&
);
void
setup
(
bool
,
const
std
::
string
&
,
const
std
::
string
&
,
const
std
::
string
&
);
};
}
//
namespace mediakit
}
//
namespace mediakit
#endif //ZLMEDIAKIT_PARSER_H
#endif //
ZLMEDIAKIT_PARSER_H
src/Http/HlsParser.cpp
查看文件 @
af0ebf46
...
...
@@ -37,7 +37,7 @@ bool HlsParser::parse(const string &http_url, const string &m3u8) {
if
((
_is_m3u8_inner
||
extinf_dur
!=
0
)
&&
line
[
0
]
!=
'#'
)
{
segment
.
duration
=
extinf_dur
;
segment
.
url
=
Parser
::
merge
_u
rl
(
http_url
,
line
);
segment
.
url
=
Parser
::
merge
U
rl
(
http_url
,
line
);
if
(
!
_is_m3u8_inner
)
{
//ts按照先后顺序排序
ts_map
.
emplace
(
index
++
,
segment
);
...
...
src/Http/HttpClient.cpp
查看文件 @
af0ebf46
...
...
@@ -100,7 +100,7 @@ void HttpClient::clearResponse() {
_header_recved
=
false
;
_recved_body_size
=
0
;
_total_body_size
=
0
;
_parser
.
C
lear
();
_parser
.
c
lear
();
_chunked_splitter
=
nullptr
;
_wait_header
.
resetTime
();
_wait_body
.
resetTime
();
...
...
@@ -182,19 +182,19 @@ void HttpClient::onError(const SockException &ex) {
ssize_t
HttpClient
::
onRecvHeader
(
const
char
*
data
,
size_t
len
)
{
_parser
.
Parse
(
data
);
if
(
_parser
.
Url
()
==
"302"
||
_parser
.
Url
()
==
"301"
||
_parser
.
Url
()
==
"303"
)
{
auto
new_url
=
Parser
::
merge
_u
rl
(
_url
,
_parser
[
"Location"
]);
if
(
_parser
.
status
()
==
"302"
||
_parser
.
status
()
==
"301"
||
_parser
.
status
()
==
"303"
)
{
auto
new_url
=
Parser
::
merge
U
rl
(
_url
,
_parser
[
"Location"
]);
if
(
new_url
.
empty
())
{
throw
invalid_argument
(
"未找到Location字段(跳转url)"
);
}
if
(
onRedirectUrl
(
new_url
,
_parser
.
Url
()
==
"302"
))
{
if
(
onRedirectUrl
(
new_url
,
_parser
.
status
()
==
"302"
))
{
HttpClient
::
sendRequest
(
new_url
);
return
0
;
}
}
checkCookie
(
_parser
.
getHeader
());
onResponseHeader
(
_parser
.
Url
(),
_parser
.
getHeader
());
onResponseHeader
(
_parser
.
status
(),
_parser
.
getHeader
());
_header_recved
=
true
;
if
(
_parser
[
"Transfer-Encoding"
]
==
"chunked"
)
{
...
...
src/Http/HttpFileManager.cpp
查看文件 @
af0ebf46
...
...
@@ -240,8 +240,8 @@ public:
static
void
canAccessPath
(
Session
&
sender
,
const
Parser
&
parser
,
const
MediaInfo
&
media_info
,
bool
is_dir
,
const
function
<
void
(
const
string
&
err_msg
,
const
HttpServerCookie
::
Ptr
&
cookie
)
>
&
callback
)
{
//获取用户唯一id
auto
uid
=
parser
.
P
arams
();
auto
path
=
parser
.
U
rl
();
auto
uid
=
parser
.
p
arams
();
auto
path
=
parser
.
u
rl
();
//先根据http头中的cookie字段获取cookie
HttpServerCookie
::
Ptr
cookie
=
HttpCookieManager
::
Instance
().
getCookie
(
kCookieName
,
parser
.
getHeader
());
...
...
@@ -268,7 +268,7 @@ static void canAccessPath(Session &sender, const Parser &parser, const MediaInfo
return
;
}
//上次鉴权失败,但是如果url参数发生变更,那么也重新鉴权下
if
(
parser
.
Params
().
empty
()
||
parser
.
P
arams
()
==
cookie
->
getUid
())
{
if
(
parser
.
params
().
empty
()
||
parser
.
p
arams
()
==
cookie
->
getUid
())
{
//url参数未变,或者本来就没有url参数,那么判断本次请求为重复请求,无访问权限
callback
(
attach
.
_err_msg
,
update_cookie
?
cookie
:
nullptr
);
return
;
...
...
@@ -469,11 +469,11 @@ static string getFilePath(const Parser &parser,const MediaInfo &media_info, Sess
if
(
it
!=
virtualPathMap
.
end
())
{
//访问的是virtualPath
path
=
it
->
second
;
url
=
parser
.
U
rl
().
substr
(
1
+
media_info
.
app
.
size
());
url
=
parser
.
u
rl
().
substr
(
1
+
media_info
.
app
.
size
());
}
else
{
//访问的是rootPath
path
=
rootPath
;
url
=
parser
.
U
rl
();
url
=
parser
.
u
rl
();
}
for
(
auto
&
ch
:
url
)
{
if
(
ch
==
'\\'
)
{
...
...
@@ -493,7 +493,7 @@ static string getFilePath(const Parser &parser,const MediaInfo &media_info, Sess
* @param cb 回调对象
*/
void
HttpFileManager
::
onAccessPath
(
Session
&
sender
,
Parser
&
parser
,
const
HttpFileManager
::
invoker
&
cb
)
{
auto
fullUrl
=
string
(
HTTP_SCHEMA
)
+
"://"
+
parser
[
"Host"
]
+
parser
.
F
ullUrl
();
auto
fullUrl
=
string
(
HTTP_SCHEMA
)
+
"://"
+
parser
[
"Host"
]
+
parser
.
f
ullUrl
();
MediaInfo
media_info
(
fullUrl
);
auto
file_path
=
getFilePath
(
parser
,
media_info
,
sender
);
if
(
file_path
.
size
()
==
0
)
{
...
...
@@ -506,13 +506,13 @@ void HttpFileManager::onAccessPath(Session &sender, Parser &parser, const HttpFi
if
(
!
indexFile
.
empty
())
{
//发现该文件夹下有index文件
file_path
=
pathCat
(
file_path
,
indexFile
);
parser
.
setUrl
(
pathCat
(
parser
.
U
rl
(),
indexFile
));
parser
.
setUrl
(
pathCat
(
parser
.
u
rl
(),
indexFile
));
accessFile
(
sender
,
parser
,
media_info
,
file_path
,
cb
);
return
;
}
string
strMenu
;
//生成文件夹菜单索引
if
(
!
makeFolderMenu
(
parser
.
U
rl
(),
file_path
,
strMenu
))
{
if
(
!
makeFolderMenu
(
parser
.
u
rl
(),
file_path
,
strMenu
))
{
//文件夹不存在
sendNotFound
(
cb
);
return
;
...
...
src/Http/HttpSession.cpp
查看文件 @
af0ebf46
...
...
@@ -64,10 +64,10 @@ ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
});
_parser
.
Parse
(
header
);
CHECK
(
_parser
.
U
rl
()[
0
]
==
'/'
);
CHECK
(
_parser
.
u
rl
()[
0
]
==
'/'
);
urlDecode
(
_parser
);
string
cmd
=
_parser
.
M
ethod
();
string
cmd
=
_parser
.
m
ethod
();
auto
it
=
s_func_map
.
find
(
cmd
);
if
(
it
==
s_func_map
.
end
())
{
WarnP
(
this
)
<<
"不支持该命令:"
<<
cmd
;
...
...
@@ -80,7 +80,7 @@ ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
(
this
->*
(
it
->
second
))(
content_len
);
// 清空解析器节省内存
_parser
.
C
lear
();
_parser
.
c
lear
();
// 返回content长度
return
content_len
;
}
...
...
@@ -173,7 +173,7 @@ bool HttpSession::checkWebSocket() {
}
bool
HttpSession
::
checkLiveStream
(
const
string
&
schema
,
const
string
&
url_suffix
,
const
function
<
void
(
const
MediaSource
::
Ptr
&
src
)
>
&
cb
)
{
std
::
string
url
=
_parser
.
U
rl
();
std
::
string
url
=
_parser
.
u
rl
();
auto
it
=
_parser
.
getUrlArgs
().
find
(
"schema"
);
if
(
it
!=
_parser
.
getUrlArgs
().
end
())
{
if
(
strcasecmp
(
it
->
second
.
c_str
(),
schema
.
c_str
()))
{
...
...
@@ -191,9 +191,9 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffix
}
// 带参数的url
if
(
!
_parser
.
P
arams
().
empty
())
{
if
(
!
_parser
.
p
arams
().
empty
())
{
url
+=
"?"
;
url
+=
_parser
.
P
arams
();
url
+=
_parser
.
p
arams
();
}
// 解析带上协议+参数完整的url
...
...
@@ -616,7 +616,7 @@ string HttpSession::urlDecode(const string &str) {
}
void
HttpSession
::
urlDecode
(
Parser
&
parser
)
{
parser
.
setUrl
(
urlDecode
(
parser
.
U
rl
()));
parser
.
setUrl
(
urlDecode
(
parser
.
u
rl
()));
for
(
auto
&
pr
:
_parser
.
getUrlArgs
())
{
const_cast
<
string
&>
(
pr
.
second
)
=
urlDecode
(
pr
.
second
);
}
...
...
@@ -682,7 +682,7 @@ void HttpSession::Handle_Req_POST(ssize_t &content_len) {
// 触发http事件,emitHttpEvent内部会选择是否关闭连接
emitHttpEvent
(
true
);
// 清空数据,节省内存
_parser
.
C
lear
();
_parser
.
c
lear
();
// content已经接收完毕
return
false
;
};
...
...
src/Rtmp/RtmpPlayer.cpp
查看文件 @
af0ebf46
...
...
@@ -27,7 +27,7 @@ namespace mediakit {
RtmpPlayer
::
RtmpPlayer
(
const
EventPoller
::
Ptr
&
poller
)
:
TcpClient
(
poller
)
{}
RtmpPlayer
::~
RtmpPlayer
()
{
DebugL
<<
endl
;
DebugL
;
}
void
RtmpPlayer
::
teardown
()
{
...
...
src/Rtmp/RtmpPlayerImp.h
查看文件 @
af0ebf46
...
...
@@ -27,7 +27,7 @@ public:
RtmpPlayerImp
(
const
toolkit
::
EventPoller
::
Ptr
&
poller
)
:
Super
(
poller
)
{};
~
RtmpPlayerImp
()
override
{
DebugL
<<
std
::
endl
;
DebugL
;
}
float
getProgress
()
const
override
{
...
...
src/Rtmp/RtmpPusher.cpp
查看文件 @
af0ebf46
...
...
@@ -27,7 +27,7 @@ RtmpPusher::RtmpPusher(const EventPoller::Ptr &poller, const RtmpMediaSource::Pt
RtmpPusher
::~
RtmpPusher
()
{
teardown
();
DebugL
<<
endl
;
DebugL
;
}
void
RtmpPusher
::
teardown
()
{
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
af0ebf46
...
...
@@ -33,7 +33,7 @@ RtspPlayer::RtspPlayer(const EventPoller::Ptr &poller)
:
TcpClient
(
poller
)
{}
RtspPlayer
::~
RtspPlayer
(
void
)
{
DebugL
<<
endl
;
DebugL
;
}
void
RtspPlayer
::
sendTeardown
()
{
...
...
@@ -170,11 +170,11 @@ bool RtspPlayer::handleAuthenticationFailure(const string ¶msStr) {
bool
RtspPlayer
::
handleResponse
(
const
string
&
cmd
,
const
Parser
&
parser
)
{
string
authInfo
=
parser
[
"WWW-Authenticate"
];
// 发送DESCRIBE命令后的回复
if
((
parser
.
Url
()
==
"401"
)
&&
handleAuthenticationFailure
(
authInfo
))
{
if
((
parser
.
status
()
==
"401"
)
&&
handleAuthenticationFailure
(
authInfo
))
{
sendOptions
();
return
false
;
}
if
(
parser
.
Url
()
==
"302"
||
parser
.
Url
()
==
"301"
)
{
if
(
parser
.
status
()
==
"302"
||
parser
.
status
()
==
"301"
)
{
auto
newUrl
=
parser
[
"Location"
];
if
(
newUrl
.
empty
())
{
throw
std
::
runtime_error
(
"未找到Location字段(跳转url)"
);
...
...
@@ -182,8 +182,8 @@ bool RtspPlayer::handleResponse(const string &cmd, const Parser &parser) {
play
(
newUrl
);
return
false
;
}
if
(
parser
.
Url
()
!=
"200"
)
{
throw
std
::
runtime_error
(
StrPrinter
<<
cmd
<<
":"
<<
parser
.
Url
()
<<
" "
<<
parser
.
Tail
()
<<
endl
);
if
(
parser
.
status
()
!=
"200"
)
{
throw
std
::
runtime_error
(
StrPrinter
<<
cmd
<<
":"
<<
parser
.
status
()
<<
" "
<<
parser
.
statusStr
()
<<
endl
);
}
return
true
;
}
...
...
@@ -201,7 +201,7 @@ void RtspPlayer::handleResDESCRIBE(const Parser &parser) {
}
// 解析sdp
SdpParser
sdpParser
(
parser
.
C
ontent
());
SdpParser
sdpParser
(
parser
.
c
ontent
());
string
sdp
;
auto
play_track
=
(
TrackType
)((
int
)(
*
this
)[
Client
::
kPlayTrack
]
-
1
);
...
...
@@ -267,8 +267,8 @@ void RtspPlayer::sendSetup(unsigned int track_idx) {
}
void
RtspPlayer
::
handleResSETUP
(
const
Parser
&
parser
,
unsigned
int
track_idx
)
{
if
(
parser
.
Url
()
!=
"200"
)
{
throw
std
::
runtime_error
(
StrPrinter
<<
"SETUP:"
<<
parser
.
Url
()
<<
" "
<<
parser
.
Tail
()
<<
endl
);
if
(
parser
.
status
()
!=
"200"
)
{
throw
std
::
runtime_error
(
StrPrinter
<<
"SETUP:"
<<
parser
.
status
()
<<
" "
<<
parser
.
statusStr
()
<<
endl
);
}
if
(
track_idx
==
0
)
{
_session_id
=
parser
[
"Session"
];
...
...
@@ -446,14 +446,14 @@ void RtspPlayer::speed(float speed) {
}
void
RtspPlayer
::
handleResPAUSE
(
const
Parser
&
parser
,
int
type
)
{
if
(
parser
.
Url
()
!=
"200"
)
{
if
(
parser
.
status
()
!=
"200"
)
{
switch
(
type
)
{
case
type_pause
:
WarnL
<<
"Pause failed:"
<<
parser
.
Url
()
<<
" "
<<
parser
.
Tail
()
<<
endl
;
break
;
case
type_pause
:
WarnL
<<
"Pause failed:"
<<
parser
.
status
()
<<
" "
<<
parser
.
statusStr
()
;
break
;
case
type_play
:
WarnL
<<
"Play failed:"
<<
parser
.
Url
()
<<
" "
<<
parser
.
Tail
()
<<
endl
;
onPlayResult_l
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"rtsp play failed:"
<<
parser
.
Url
()
<<
" "
<<
parser
.
Tail
()),
!
_play_check_timer
);
WarnL
<<
"Play failed:"
<<
parser
.
status
()
<<
" "
<<
parser
.
statusStr
()
;
onPlayResult_l
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"rtsp play failed:"
<<
parser
.
status
()
<<
" "
<<
parser
.
statusStr
()),
!
_play_check_timer
);
break
;
case
type_seek
:
WarnL
<<
"Seek failed:"
<<
parser
.
Url
()
<<
" "
<<
parser
.
Tail
()
<<
endl
;
break
;
case
type_seek
:
WarnL
<<
"Seek failed:"
<<
parser
.
status
()
<<
" "
<<
parser
.
statusStr
()
;
break
;
}
return
;
}
...
...
@@ -487,7 +487,7 @@ void RtspPlayer::onWholeRtspPacket(Parser &parser) {
if
(
func
)
{
func
(
parser
);
}
parser
.
C
lear
();
parser
.
c
lear
();
}
catch
(
std
::
exception
&
err
)
{
// 定时器_pPlayTimer为空后表明握手结束了
onPlayResult_l
(
SockException
(
Err_other
,
err
.
what
()),
!
_play_check_timer
);
...
...
src/Rtsp/RtspPlayerImp.h
查看文件 @
af0ebf46
...
...
@@ -28,7 +28,7 @@ public:
RtspPlayerImp
(
const
toolkit
::
EventPoller
::
Ptr
&
poller
)
:
Super
(
poller
)
{}
~
RtspPlayerImp
()
override
{
DebugL
<<
std
::
endl
;
DebugL
;
}
float
getProgress
()
const
override
{
...
...
src/Rtsp/RtspPusher.cpp
查看文件 @
af0ebf46
...
...
@@ -26,7 +26,7 @@ RtspPusher::RtspPusher(const EventPoller::Ptr &poller, const RtspMediaSource::Pt
RtspPusher
::~
RtspPusher
()
{
teardown
();
DebugL
<<
endl
;
DebugL
;
}
void
RtspPusher
::
sendTeardown
(){
...
...
@@ -147,7 +147,7 @@ void RtspPusher::onWholeRtspPacket(Parser &parser) {
if
(
func
)
{
func
(
parser
);
}
parser
.
C
lear
();
parser
.
c
lear
();
}
void
RtspPusher
::
onRtpPacket
(
const
char
*
data
,
size_t
len
)
{
...
...
@@ -188,11 +188,11 @@ void RtspPusher::sendAnnounce() {
void
RtspPusher
::
handleResAnnounce
(
const
Parser
&
parser
)
{
string
authInfo
=
parser
[
"WWW-Authenticate"
];
//发送DESCRIBE命令后的回复
if
((
parser
.
Url
()
==
"401"
)
&&
handleAuthenticationFailure
(
authInfo
))
{
if
((
parser
.
status
()
==
"401"
)
&&
handleAuthenticationFailure
(
authInfo
))
{
sendAnnounce
();
return
;
}
if
(
parser
.
Url
()
==
"302"
)
{
if
(
parser
.
status
()
==
"302"
)
{
auto
newUrl
=
parser
[
"Location"
];
if
(
newUrl
.
empty
())
{
throw
std
::
runtime_error
(
"未找到Location字段(跳转url)"
);
...
...
@@ -200,8 +200,8 @@ void RtspPusher::handleResAnnounce(const Parser &parser) {
publish
(
newUrl
);
return
;
}
if
(
parser
.
Url
()
!=
"200"
)
{
throw
std
::
runtime_error
(
StrPrinter
<<
"ANNOUNCE:"
<<
parser
.
Url
()
<<
" "
<<
parser
.
Tail
());
if
(
parser
.
status
()
!=
"200"
)
{
throw
std
::
runtime_error
(
StrPrinter
<<
"ANNOUNCE:"
<<
parser
.
status
()
<<
" "
<<
parser
.
statusStr
());
}
_content_base
=
parser
[
"Content-Base"
];
...
...
@@ -285,8 +285,8 @@ void RtspPusher::sendSetup(unsigned int track_idx) {
}
void
RtspPusher
::
handleResSetup
(
const
Parser
&
parser
,
unsigned
int
track_idx
)
{
if
(
parser
.
Url
()
!=
"200"
)
{
throw
std
::
runtime_error
(
StrPrinter
<<
"SETUP:"
<<
parser
.
Url
()
<<
" "
<<
parser
.
Tail
()
<<
endl
);
if
(
parser
.
status
()
!=
"200"
)
{
throw
std
::
runtime_error
(
StrPrinter
<<
"SETUP:"
<<
parser
.
status
()
<<
" "
<<
parser
.
statusStr
()
<<
endl
);
}
if
(
track_idx
==
0
)
{
_session_id
=
parser
[
"Session"
];
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
af0ebf46
...
...
@@ -128,11 +128,11 @@ void RtspSession::onRecv(const Buffer::Ptr &buf) {
}
void
RtspSession
::
onWholeRtspPacket
(
Parser
&
parser
)
{
string
method
=
parser
.
M
ethod
();
//提取出请求命令字
string
method
=
parser
.
m
ethod
();
//提取出请求命令字
_cseq
=
atoi
(
parser
[
"CSeq"
].
data
());
if
(
_content_base
.
empty
()
&&
method
!=
"GET"
)
{
_content_base
=
parser
.
U
rl
();
_media_info
.
parse
(
parser
.
F
ullUrl
());
_content_base
=
parser
.
u
rl
();
_media_info
.
parse
(
parser
.
f
ullUrl
());
_media_info
.
schema
=
RTSP_SCHEMA
;
}
...
...
@@ -160,7 +160,7 @@ void RtspSession::onWholeRtspPacket(Parser &parser) {
}
(
this
->*
(
it
->
second
))(
parser
);
parser
.
C
lear
();
parser
.
c
lear
();
}
void
RtspSession
::
onRtpPacket
(
const
char
*
data
,
size_t
len
)
{
...
...
@@ -187,7 +187,7 @@ void RtspSession::onRtcpPacket(int track_idx, SdpTrack::Ptr &track, const char *
}
ssize_t
RtspSession
::
getContentLength
(
Parser
&
parser
)
{
if
(
parser
.
M
ethod
()
==
"POST"
){
if
(
parser
.
m
ethod
()
==
"POST"
){
//http post请求的content数据部分是base64编码后的rtsp请求信令包
return
remainDataSize
();
}
...
...
@@ -200,7 +200,7 @@ void RtspSession::handleReq_Options(const Parser &parser) {
}
void
RtspSession
::
handleReq_ANNOUNCE
(
const
Parser
&
parser
)
{
auto
full_url
=
parser
.
F
ullUrl
();
auto
full_url
=
parser
.
f
ullUrl
();
_content_base
=
full_url
;
if
(
end_with
(
full_url
,
".sdp"
))
{
//去除.sdp后缀,防止EasyDarwin推流器强制添加.sdp后缀
...
...
@@ -250,7 +250,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
throw
SockException
(
Err_shutdown
,
err
);
}
SdpParser
sdpParser
(
parser
.
C
ontent
());
SdpParser
sdpParser
(
parser
.
c
ontent
());
_sessionid
=
makeRandStr
(
12
);
_sdp_track
=
sdpParser
.
getAvailableTrack
();
if
(
_sdp_track
.
empty
())
{
...
...
@@ -270,7 +270,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
//获取所有权
_push_src_ownership
=
_push_src
->
getOwnership
();
_push_src
->
setProtocolOption
(
option
);
_push_src
->
setSdp
(
parser
.
C
ontent
());
_push_src
->
setSdp
(
parser
.
c
ontent
());
}
_push_src
->
setListener
(
static_pointer_cast
<
RtspSession
>
(
shared_from_this
()));
...
...
@@ -628,7 +628,7 @@ void RtspSession::send_SessionNotFound() {
void
RtspSession
::
handleReq_Setup
(
const
Parser
&
parser
)
{
//处理setup命令,该函数可能进入多次
int
trackIdx
=
getTrackIndexByControlUrl
(
parser
.
F
ullUrl
());
int
trackIdx
=
getTrackIndexByControlUrl
(
parser
.
f
ullUrl
());
SdpTrack
::
Ptr
&
trackRef
=
_sdp_track
[
trackIdx
];
if
(
trackRef
->
_inited
)
{
//已经初始化过该Track
...
...
@@ -915,9 +915,9 @@ void RtspSession::handleReq_Post(const Parser &parser) {
});
};
if
(
!
parser
.
C
ontent
().
empty
()){
if
(
!
parser
.
c
ontent
().
empty
()){
//http poster后面的粘包
_on_recv
(
std
::
make_shared
<
BufferString
>
(
parser
.
C
ontent
()));
_on_recv
(
std
::
make_shared
<
BufferString
>
(
parser
.
c
ontent
()));
}
sendRtspResponse
(
"200 OK"
,
...
...
src/Rtsp/RtspSplitter.cpp
查看文件 @
af0ebf46
...
...
@@ -65,7 +65,7 @@ ssize_t RtspSplitter::onRecvHeader(const char *data, size_t len) {
auto
ret
=
getContentLength
(
_parser
);
if
(
ret
==
0
){
onWholeRtspPacket
(
_parser
);
_parser
.
C
lear
();
_parser
.
c
lear
();
}
return
ret
;
}
...
...
@@ -73,7 +73,7 @@ ssize_t RtspSplitter::onRecvHeader(const char *data, size_t len) {
void
RtspSplitter
::
onRecvContent
(
const
char
*
data
,
size_t
len
)
{
_parser
.
setContent
(
string
(
data
,
len
));
onWholeRtspPacket
(
_parser
);
_parser
.
C
lear
();
_parser
.
c
lear
();
}
void
RtspSplitter
::
enableRecvRtp
(
bool
enable
)
{
...
...
tests/test_httpApi.cpp
查看文件 @
af0ebf46
...
...
@@ -43,7 +43,7 @@ void initEventListener(){
static
onceToken
s_token
([](){
NoticeCenter
::
Instance
().
addListener
(
nullptr
,
Broadcast
::
kBroadcastHttpRequest
,[](
BroadcastHttpRequestArgs
){
//const Parser &parser,HttpSession::HttpResponseInvoker &invoker,bool &consumed
if
(
strstr
(
parser
.
Url
().
data
(),
"/api/"
)
!=
parser
.
U
rl
().
data
()){
if
(
strstr
(
parser
.
url
().
data
(),
"/api/"
)
!=
parser
.
u
rl
().
data
()){
return
;
}
//url以"/api/起始,说明是http api"
...
...
@@ -51,11 +51,11 @@ void initEventListener(){
_StrPrinter
printer
;
////////////////method////////////////////
printer
<<
"
\r\n
method:
\r\n\t
"
<<
parser
.
M
ethod
();
printer
<<
"
\r\n
method:
\r\n\t
"
<<
parser
.
m
ethod
();
////////////////url/////////////////
printer
<<
"
\r\n
url:
\r\n\t
"
<<
parser
.
U
rl
();
printer
<<
"
\r\n
url:
\r\n\t
"
<<
parser
.
u
rl
();
////////////////protocol/////////////////
printer
<<
"
\r\n
protocol:
\r\n\t
"
<<
parser
.
Tai
l
();
printer
<<
"
\r\n
protocol:
\r\n\t
"
<<
parser
.
protoco
l
();
///////////////args//////////////////
printer
<<
"
\r\n
args:
\r\n
"
;
for
(
auto
&
pr
:
parser
.
getUrlArgs
()){
...
...
@@ -67,7 +67,7 @@ void initEventListener(){
printer
<<
"
\t
"
<<
pr
.
first
<<
" : "
<<
pr
.
second
<<
"
\r\n
"
;
}
////////////////content/////////////////
printer
<<
"
\r\n
content:
\r\n
"
<<
parser
.
C
ontent
();
printer
<<
"
\r\n
content:
\r\n
"
<<
parser
.
c
ontent
();
auto
contentOut
=
printer
<<
endl
;
////////////////我们测算异步回复,当然你也可以同步回复/////////////////
...
...
@@ -113,7 +113,7 @@ int main(int argc,char *argv[]){
TcpServer
::
Ptr
httpsSrv
(
new
TcpServer
());
httpsSrv
->
start
<
HttpsSession
>
(
mINI
::
Instance
()[
Http
::
kSSLPort
]);
//默认443
InfoL
<<
"你可以在浏览器输入:http://127.0.0.1/api/my_api?key0=val0&key1=参数1"
<<
endl
;
InfoL
<<
"你可以在浏览器输入:http://127.0.0.1/api/my_api?key0=val0&key1=参数1"
;
sem
.
wait
();
return
0
;
...
...
tests/test_httpClient.cpp
查看文件 @
af0ebf46
...
...
@@ -86,9 +86,9 @@ int main(int argc, char *argv[]) {
for
(
auto
&
pr
:
parser
.
getHeader
())
{
printer
<<
pr
.
first
<<
":"
<<
pr
.
second
<<
"
\r\n
"
;
}
InfoL
<<
"status:"
<<
parser
.
Url
()
<<
"
\r\n
"
InfoL
<<
"status:"
<<
parser
.
status
()
<<
"
\r\n
"
<<
"header:
\r\n
"
<<
(
printer
<<
endl
)
<<
"
\r\n
body:"
<<
parser
.
C
ontent
();
<<
"
\r\n
body:"
<<
parser
.
c
ontent
();
}
});
...
...
@@ -122,9 +122,9 @@ int main(int argc, char *argv[]) {
for
(
auto
&
pr
:
parser
.
getHeader
())
{
printer
<<
pr
.
first
<<
":"
<<
pr
.
second
<<
"
\r\n
"
;
}
InfoL
<<
"status:"
<<
parser
.
Url
()
<<
"
\r\n
"
InfoL
<<
"status:"
<<
parser
.
status
()
<<
"
\r\n
"
<<
"header:
\r\n
"
<<
(
printer
<<
endl
)
<<
"
\r\n
body:"
<<
parser
.
C
ontent
();
<<
"
\r\n
body:"
<<
parser
.
c
ontent
();
}
});
...
...
@@ -159,9 +159,9 @@ int main(int argc, char *argv[]) {
for
(
auto
&
pr
:
parser
.
getHeader
())
{
printer
<<
pr
.
first
<<
":"
<<
pr
.
second
<<
"
\r\n
"
;
}
InfoL
<<
"status:"
<<
parser
.
Url
()
<<
"
\r\n
"
InfoL
<<
"status:"
<<
parser
.
status
()
<<
"
\r\n
"
<<
"header:
\r\n
"
<<
(
printer
<<
endl
)
<<
"
\r\n
body:"
<<
parser
.
C
ontent
();
<<
"
\r\n
body:"
<<
parser
.
c
ontent
();
}
});
...
...
tests/test_wsServer.cpp
查看文件 @
af0ebf46
...
...
@@ -83,7 +83,7 @@ struct EchoSessionCreator {
//返回的Session必须派生于SendInterceptor,可以返回null(拒绝连接)
Session
::
Ptr
operator
()(
const
Parser
&
header
,
const
HttpSession
&
parent
,
const
Socket
::
Ptr
&
pSock
)
{
// return nullptr;
if
(
header
.
U
rl
()
==
"/"
)
{
if
(
header
.
u
rl
()
==
"/"
)
{
return
std
::
make_shared
<
SessionTypeImp
<
EchoSession
>
>
(
header
,
parent
,
pSock
);
}
return
std
::
make_shared
<
SessionTypeImp
<
EchoSessionWithUrl
>
>
(
header
,
parent
,
pSock
);
...
...
webrtc/WebRtcTransport.cpp
查看文件 @
af0ebf46
...
...
@@ -323,7 +323,7 @@ void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tup
if
(
RTC
::
StunPacket
::
IsStun
((
const
uint8_t
*
)
buf
,
len
))
{
std
::
unique_ptr
<
RTC
::
StunPacket
>
packet
(
RTC
::
StunPacket
::
Parse
((
const
uint8_t
*
)
buf
,
len
));
if
(
!
packet
)
{
WarnL
<<
"parse stun error"
<<
std
::
endl
;
WarnL
<<
"parse stun error"
;
return
;
}
_ice_server
->
ProcessStunPacket
(
packet
.
get
(),
tuple
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论