Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-06-29 11:45:31 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
051c9e6268b039ace3195207f4f7ddc4b0cfd482
051c9e62
1 parent
6a2f0a3d
refine the protocol utility, add utest, 0.9.140
隐藏空白字符变更
内嵌
并排对比
正在显示
9 个修改的文件
包含
203 行增加
和
45 行删除
trunk/configure
trunk/src/core/srs_core.hpp
trunk/src/rtmp/srs_protocol_rtmp.cpp
trunk/src/rtmp/srs_protocol_rtmp.hpp
trunk/src/rtmp/srs_protocol_utility.cpp
trunk/src/rtmp/srs_protocol_utility.hpp
trunk/src/srs/srs.upp
trunk/src/utest/srs_utest_protocol.cpp
trunk/src/utest/srs_utest_protocol.hpp
trunk/configure
查看文件 @
051c9e6
...
...
@@ -516,7 +516,8 @@ if [ $SRS_LIBRTMP = YES ]; then
fi
#
# utest, the unit-test cases of srs, base on gtest1.6
MODULE_FILES
=(
"srs_utest"
"srs_utest_amf0"
"srs_utest_handshake"
"srs_utest_buffer"
)
MODULE_FILES
=(
"srs_utest"
"srs_utest_amf0"
"srs_utest_handshake"
"srs_utest_buffer"
"srs_utest_protocol"
)
ModuleLibIncs
=(
${
SRS_OBJS
}
${
LibSTRoot
}
)
ModuleLibFiles
=(
${
LibSTfile
}
${
LibHttpParserfile
}
${
LibSSLfile
}
)
MODULE_DEPENDS
=(
"CORE"
"KERNEL"
"RTMP"
"APP"
)
...
...
trunk/src/core/srs_core.hpp
查看文件 @
051c9e6
...
...
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
#define VERSION_REVISION "1
39
"
#define VERSION_REVISION "1
40
"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
...
...
trunk/src/rtmp/srs_protocol_rtmp.cpp
查看文件 @
051c9e6
...
...
@@ -124,41 +124,6 @@ void SrsRequest::update_auth(SrsRequest* req)
srs_info
(
"update req of soruce for auth ok"
);
}
int
SrsRequest
::
discovery_app
()
{
int
ret
=
ERROR_SUCCESS
;
size_t
pos
=
std
::
string
::
npos
;
std
::
string
url
=
tcUrl
;
if
((
pos
=
url
.
find
(
"://"
))
!=
std
::
string
::
npos
)
{
schema
=
url
.
substr
(
0
,
pos
);
url
=
url
.
substr
(
schema
.
length
()
+
3
);
srs_verbose
(
"discovery schema=%s"
,
schema
.
c_str
());
}
if
((
pos
=
url
.
find
(
"/"
))
!=
std
::
string
::
npos
)
{
host
=
url
.
substr
(
0
,
pos
);
url
=
url
.
substr
(
host
.
length
()
+
1
);
srs_verbose
(
"discovery host=%s"
,
host
.
c_str
());
}
port
=
RTMP_DEFAULT_PORT
;
if
((
pos
=
host
.
find
(
":"
))
!=
std
::
string
::
npos
)
{
port
=
host
.
substr
(
pos
+
1
);
host
=
host
.
substr
(
0
,
pos
);
srs_verbose
(
"discovery host=%s, port=%s"
,
host
.
c_str
(),
port
.
c_str
());
}
app
=
url
;
vhost
=
host
;
srs_vhost_resolve
(
vhost
,
app
);
strip
();
return
ret
;
}
string
SrsRequest
::
get_stream_url
()
{
std
::
string
url
=
""
;
...
...
@@ -867,7 +832,10 @@ int SrsRtmpServer::connect_app(SrsRequest* req)
srs_info
(
"get connect app message params success."
);
return
req
->
discovery_app
();
srs_discovery_tc_url
(
req
->
tcUrl
,
req
->
schema
,
req
->
host
,
req
->
vhost
,
req
->
app
,
req
->
port
);
req
->
strip
();
return
ret
;
}
int
SrsRtmpServer
::
set_window_ack_size
(
int
ack_size
)
...
...
trunk/src/rtmp/srs_protocol_rtmp.hpp
查看文件 @
051c9e6
...
...
@@ -98,9 +98,8 @@ public:
virtual
void
update_auth
(
SrsRequest
*
req
);
/**
*
disconvery vhost/app from tcUrl
.
*
get the stream identify, vhost/app/stream
.
*/
virtual
int
discovery_app
();
virtual
std
::
string
get_stream_url
();
// strip url, user must strip when update the url.
...
...
trunk/src/rtmp/srs_protocol_utility.cpp
查看文件 @
051c9e6
...
...
@@ -29,9 +29,43 @@ using namespace std;
#include <srs_kernel_log.hpp>
#include <srs_kernel_utility.hpp>
void
srs_discovery_tc_url
(
string
tcUrl
,
string
&
schema
,
string
&
host
,
string
&
vhost
,
string
&
app
,
string
&
port
)
{
size_t
pos
=
std
::
string
::
npos
;
std
::
string
url
=
tcUrl
;
if
((
pos
=
url
.
find
(
"://"
))
!=
std
::
string
::
npos
)
{
schema
=
url
.
substr
(
0
,
pos
);
url
=
url
.
substr
(
schema
.
length
()
+
3
);
srs_info
(
"discovery schema=%s"
,
schema
.
c_str
());
}
if
((
pos
=
url
.
find
(
"/"
))
!=
std
::
string
::
npos
)
{
host
=
url
.
substr
(
0
,
pos
);
url
=
url
.
substr
(
host
.
length
()
+
1
);
srs_info
(
"discovery host=%s"
,
host
.
c_str
());
}
port
=
RTMP_DEFAULT_PORT
;
if
((
pos
=
host
.
find
(
":"
))
!=
std
::
string
::
npos
)
{
port
=
host
.
substr
(
pos
+
1
);
host
=
host
.
substr
(
0
,
pos
);
srs_info
(
"discovery host=%s, port=%s"
,
host
.
c_str
(),
port
.
c_str
());
}
app
=
url
;
vhost
=
host
;
srs_vhost_resolve
(
vhost
,
app
);
}
void
srs_vhost_resolve
(
string
&
vhost
,
string
&
app
)
{
app
=
srs_string_replace
(
app
,
"..."
,
"?"
);
app
=
srs_string_replace
(
app
,
"&&"
,
"?"
);
app
=
srs_string_replace
(
app
,
"="
,
"?"
);
size_t
pos
=
0
;
if
((
pos
=
app
.
find
(
"?"
))
==
std
::
string
::
npos
)
{
...
...
@@ -41,15 +75,14 @@ void srs_vhost_resolve(string& vhost, string& app)
std
::
string
query
=
app
.
substr
(
pos
+
1
);
app
=
app
.
substr
(
0
,
pos
);
if
((
pos
=
query
.
find
(
"vhost?"
))
!=
std
::
string
::
npos
||
(
pos
=
query
.
find
(
"vhost="
))
!=
std
::
string
::
npos
||
(
pos
=
query
.
find
(
"Vhost?"
))
!=
std
::
string
::
npos
||
(
pos
=
query
.
find
(
"Vhost="
))
!=
std
::
string
::
npos
)
{
if
((
pos
=
query
.
find
(
"vhost?"
))
!=
std
::
string
::
npos
)
{
query
=
query
.
substr
(
pos
+
6
);
if
(
!
query
.
empty
())
{
vhost
=
query
;
}
if
((
pos
=
vhost
.
find
(
"?"
))
!=
std
::
string
::
npos
)
{
vhost
=
vhost
.
substr
(
0
,
pos
);
}
}
}
...
...
trunk/src/rtmp/srs_protocol_utility.hpp
查看文件 @
051c9e6
...
...
@@ -39,6 +39,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// the default chunk size for system.
#define SRS_CONF_DEFAULT_CHUNK_SIZE 60000
// parse the tcUrl, output the schema, host, vhost, app and port.
extern
void
srs_discovery_tc_url
(
std
::
string
tcUrl
,
std
::
string
&
schema
,
std
::
string
&
host
,
std
::
string
&
vhost
,
std
::
string
&
app
,
std
::
string
&
port
);
// resolve the vhost in query string
// @param app, may contains the vhost in query string format:
// app?vhost=request_vhost
...
...
trunk/src/srs/srs.upp
查看文件 @
051c9e6
...
...
@@ -116,6 +116,8 @@ file
..\utest\srs_utest_buffer.cpp,
..\utest\srs_utest_handshake.hpp,
..\utest\srs_utest_handshake.cpp,
..\utest\srs_utest_protocol.hpp,
..\utest\srs_utest_protocol.cpp,
research readonly separator,
..\..\research\librtmp\srs_detect_rtmp.c,
..\..\research\librtmp\srs_flv_injecter.c,
...
...
trunk/src/utest/srs_utest_protocol.cpp
0 → 100644
查看文件 @
051c9e6
/*
The MIT License (MIT)
Copyright (c) 2013-2014 winlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_utest_protocol.hpp>
using
namespace
std
;
#include <srs_kernel_error.hpp>
#include <srs_kernel_utility.hpp>
VOID
TEST
(
ProtocolUtilityTest
,
VhostResolve
)
{
std
::
string
vhost
=
"vhost"
;
std
::
string
app
=
"app"
;
srs_vhost_resolve
(
vhost
,
app
);
EXPECT_STREQ
(
"vhost"
,
vhost
.
c_str
());
EXPECT_STREQ
(
"app"
,
app
.
c_str
());
app
=
"app?vhost=changed"
;
srs_vhost_resolve
(
vhost
,
app
);
EXPECT_STREQ
(
"changed"
,
vhost
.
c_str
());
EXPECT_STREQ
(
"app"
,
app
.
c_str
());
app
=
"app?vhost=changed1&&query=true"
;
srs_vhost_resolve
(
vhost
,
app
);
EXPECT_STREQ
(
"changed1"
,
vhost
.
c_str
());
EXPECT_STREQ
(
"app"
,
app
.
c_str
());
app
=
"app?other=true&&vhost=changed2&&query=true"
;
srs_vhost_resolve
(
vhost
,
app
);
EXPECT_STREQ
(
"changed2"
,
vhost
.
c_str
());
EXPECT_STREQ
(
"app"
,
app
.
c_str
());
app
=
"app...other...true...vhost...changed3...query...true"
;
srs_vhost_resolve
(
vhost
,
app
);
EXPECT_STREQ
(
"changed3"
,
vhost
.
c_str
());
EXPECT_STREQ
(
"app"
,
app
.
c_str
());
}
VOID
TEST
(
ProtocolUtilityTest
,
DiscoveryTcUrl
)
{
std
::
string
tcUrl
;
std
::
string
schema
;
std
::
string
host
;
std
::
string
vhost
;
std
::
string
app
;
std
::
string
port
;
tcUrl
=
"rtmp://127.0.0.1:1935/live"
;
srs_discovery_tc_url
(
tcUrl
,
schema
,
host
,
vhost
,
app
,
port
);
EXPECT_STREQ
(
"rtmp"
,
schema
.
c_str
());
EXPECT_STREQ
(
"127.0.0.1"
,
host
.
c_str
());
EXPECT_STREQ
(
"127.0.0.1"
,
vhost
.
c_str
());
EXPECT_STREQ
(
"live"
,
app
.
c_str
());
EXPECT_STREQ
(
"1935"
,
port
.
c_str
());
tcUrl
=
"rtmp://127.0.0.1:19351/live"
;
srs_discovery_tc_url
(
tcUrl
,
schema
,
host
,
vhost
,
app
,
port
);
EXPECT_STREQ
(
"rtmp"
,
schema
.
c_str
());
EXPECT_STREQ
(
"127.0.0.1"
,
host
.
c_str
());
EXPECT_STREQ
(
"127.0.0.1"
,
vhost
.
c_str
());
EXPECT_STREQ
(
"live"
,
app
.
c_str
());
EXPECT_STREQ
(
"19351"
,
port
.
c_str
());
tcUrl
=
"rtmp://127.0.0.1:19351/live?vhost=demo"
;
srs_discovery_tc_url
(
tcUrl
,
schema
,
host
,
vhost
,
app
,
port
);
EXPECT_STREQ
(
"rtmp"
,
schema
.
c_str
());
EXPECT_STREQ
(
"127.0.0.1"
,
host
.
c_str
());
EXPECT_STREQ
(
"demo"
,
vhost
.
c_str
());
EXPECT_STREQ
(
"live"
,
app
.
c_str
());
EXPECT_STREQ
(
"19351"
,
port
.
c_str
());
tcUrl
=
"rtmp://127.0.0.1:19351/live/show?vhost=demo"
;
srs_discovery_tc_url
(
tcUrl
,
schema
,
host
,
vhost
,
app
,
port
);
EXPECT_STREQ
(
"rtmp"
,
schema
.
c_str
());
EXPECT_STREQ
(
"127.0.0.1"
,
host
.
c_str
());
EXPECT_STREQ
(
"demo"
,
vhost
.
c_str
());
EXPECT_STREQ
(
"live/show"
,
app
.
c_str
());
EXPECT_STREQ
(
"19351"
,
port
.
c_str
());
}
VOID
TEST
(
ProtocolUtilityTest
,
GenerateTcUrl
)
{
string
ip
;
string
vhost
;
string
app
;
string
port
;
string
tcUrl
;
ip
=
"127.0.0.1"
;
vhost
=
"__defaultVhost__"
;
app
=
"live"
;
port
=
"1935"
;
tcUrl
=
srs_generate_tc_url
(
ip
,
vhost
,
app
,
port
);
EXPECT_STREQ
(
"rtmp://127.0.0.1/live"
,
tcUrl
.
c_str
());
ip
=
"127.0.0.1"
;
vhost
=
"demo"
;
app
=
"live"
;
port
=
"1935"
;
tcUrl
=
srs_generate_tc_url
(
ip
,
vhost
,
app
,
port
);
EXPECT_STREQ
(
"rtmp://demo/live"
,
tcUrl
.
c_str
());
ip
=
"127.0.0.1"
;
vhost
=
"demo"
;
app
=
"live"
;
port
=
"19351"
;
tcUrl
=
srs_generate_tc_url
(
ip
,
vhost
,
app
,
port
);
EXPECT_STREQ
(
"rtmp://demo:19351/live"
,
tcUrl
.
c_str
());
}
...
...
trunk/src/utest/srs_utest_protocol.hpp
0 → 100644
查看文件 @
051c9e6
/*
The MIT License (MIT)
Copyright (c) 2013-2014 winlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_UTEST_PROTOCOL_HPP
#define SRS_UTEST_PROTOCOL_HPP
/*
#include <srs_utest_protocol.hpp>
*/
#include <srs_utest.hpp>
#include <string>
#include <srs_protocol_utility.hpp>
#endif
...
...
请
注册
或
登录
后发表评论