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-07-20 16:16:29 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c65a6b5d631009c94fc0bbdfb11e2185b4feb635
c65a6b5d
1 parent
86ad39f0
fix the conf_line bug of parse config directive.
隐藏空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
132 行增加
和
13 行删除
trunk/src/app/srs_app_config.cpp
trunk/src/app/srs_app_config.hpp
trunk/src/utest/srs_utest_config.cpp
trunk/src/app/srs_app_config.cpp
查看文件 @
c65a6b5
...
...
@@ -154,8 +154,8 @@ int SrsConfDirective::parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDire
while
(
true
)
{
std
::
vector
<
string
>
args
;
ret
=
read_token
(
buffer
,
args
);
int
line_start
=
0
;
ret
=
read_token
(
buffer
,
args
,
line_start
);
/**
* ret maybe:
...
...
@@ -170,14 +170,14 @@ int SrsConfDirective::parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDire
}
if
(
ret
==
ERROR_SYSTEM_CONFIG_BLOCK_END
)
{
if
(
type
!=
parse_block
)
{
srs_error
(
"line %d: unexpected
\"
}
\"
, ret=%d"
,
buffer
->
line
+
1
,
ret
);
srs_error
(
"line %d: unexpected
\"
}
\"
, ret=%d"
,
buffer
->
line
,
ret
);
return
ret
;
}
return
ERROR_SUCCESS
;
}
if
(
ret
==
ERROR_SYSTEM_CONFIG_EOF
)
{
if
(
type
==
parse_block
)
{
srs_error
(
"line %d: unexpected end of file, expecting
\"
}
\"
, ret=%d"
,
conf_line
+
1
,
ret
);
srs_error
(
"line %d: unexpected end of file, expecting
\"
}
\"
, ret=%d"
,
conf_line
,
ret
);
return
ret
;
}
return
ERROR_SUCCESS
;
...
...
@@ -185,14 +185,14 @@ int SrsConfDirective::parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDire
if
(
args
.
empty
())
{
ret
=
ERROR_SYSTEM_CONFIG_INVALID
;
srs_error
(
"line %d: empty directive. ret=%d"
,
conf_line
+
1
,
ret
);
srs_error
(
"line %d: empty directive. ret=%d"
,
conf_line
,
ret
);
return
ret
;
}
// build directive tree.
SrsConfDirective
*
directive
=
new
SrsConfDirective
();
directive
->
conf_line
=
buffer
->
line
;
directive
->
conf_line
=
line_start
;
directive
->
name
=
args
[
0
];
args
.
erase
(
args
.
begin
());
directive
->
args
.
swap
(
args
);
...
...
@@ -210,7 +210,7 @@ int SrsConfDirective::parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDire
}
// see: ngx_conf_read_token
int
SrsConfDirective
::
read_token
(
_srs_internal
::
SrsConfigBuffer
*
buffer
,
vector
<
string
>&
args
)
int
SrsConfDirective
::
read_token
(
_srs_internal
::
SrsConfigBuffer
*
buffer
,
vector
<
string
>&
args
,
int
&
line_start
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -260,7 +260,7 @@ int SrsConfDirective::read_token(_srs_internal::SrsConfigBuffer* buffer, vector<
if
(
ch
==
'{'
)
{
return
ERROR_SYSTEM_CONFIG_BLOCK_START
;
}
srs_error
(
"line %d: unexpected '%c'"
,
buffer
->
line
+
1
,
ch
);
srs_error
(
"line %d: unexpected '%c'"
,
buffer
->
line
,
ch
);
return
ERROR_SYSTEM_CONFIG_INVALID
;
}
...
...
@@ -273,19 +273,19 @@ int SrsConfDirective::read_token(_srs_internal::SrsConfigBuffer* buffer, vector<
switch
(
ch
)
{
case
';'
:
if
(
args
.
size
()
==
0
)
{
srs_error
(
"line %d: unexpected ';'"
,
buffer
->
line
+
1
);
srs_error
(
"line %d: unexpected ';'"
,
buffer
->
line
);
return
ERROR_SYSTEM_CONFIG_INVALID
;
}
return
ERROR_SYSTEM_CONFIG_DIRECTIVE
;
case
'{'
:
if
(
args
.
size
()
==
0
)
{
srs_error
(
"line %d: unexpected '{'"
,
buffer
->
line
+
1
);
srs_error
(
"line %d: unexpected '{'"
,
buffer
->
line
);
return
ERROR_SYSTEM_CONFIG_INVALID
;
}
return
ERROR_SYSTEM_CONFIG_BLOCK_START
;
case
'}'
:
if
(
args
.
size
()
!=
0
)
{
srs_error
(
"line %d: unexpected '}'"
,
buffer
->
line
+
1
);
srs_error
(
"line %d: unexpected '}'"
,
buffer
->
line
);
return
ERROR_SYSTEM_CONFIG_INVALID
;
}
return
ERROR_SYSTEM_CONFIG_BLOCK_END
;
...
...
@@ -308,6 +308,10 @@ int SrsConfDirective::read_token(_srs_internal::SrsConfigBuffer* buffer, vector<
}
}
else
{
// last charecter is not space
if
(
line_start
==
0
)
{
line_start
=
buffer
->
line
;
}
bool
found
=
false
;
if
(
d_quoted
)
{
if
(
ch
==
'"'
)
{
...
...
@@ -2847,7 +2851,7 @@ namespace _srs_internal
{
SrsConfigBuffer
::
SrsConfigBuffer
()
{
line
=
0
;
line
=
1
;
pos
=
last
=
start
=
NULL
;
end
=
start
;
...
...
trunk/src/app/srs_app_config.hpp
查看文件 @
c65a6b5
...
...
@@ -215,9 +215,10 @@ private:
* read a token from buffer.
* a token, is the directive args and a flag indicates whether has child-directives.
* @param args, the output directive args, the first is the directive name, left is the args.
* @param line_start, the actual start line of directive.
* @return, an error code indicates error or has child-directives.
*/
virtual
int
read_token
(
_srs_internal
::
SrsConfigBuffer
*
buffer
,
std
::
vector
<
std
::
string
>&
args
);
virtual
int
read_token
(
_srs_internal
::
SrsConfigBuffer
*
buffer
,
std
::
vector
<
std
::
string
>&
args
,
int
&
line_start
);
};
/**
...
...
trunk/src/utest/srs_utest_config.cpp
查看文件 @
c65a6b5
...
...
@@ -663,3 +663,117 @@ VOID TEST(ConfigDirectiveTest, ParseInvalidEmptyDirective)
EXPECT_EQ
(
0
,
(
int
)
dir0
.
args
.
size
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
directives
.
size
());
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseLine
)
{
MockSrsConfigBuffer
buf
(
"dir0 {}"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir0
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir0"
,
dir0
.
name
.
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
args
.
size
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
directives
.
size
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
conf_line
);
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseLine2
)
{
MockSrsConfigBuffer
buf
(
"
\n\n
dir0 {}"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir0
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir0"
,
dir0
.
name
.
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
args
.
size
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
directives
.
size
());
EXPECT_EQ
(
3
,
(
int
)
dir0
.
conf_line
);
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseLine3
)
{
MockSrsConfigBuffer
buf
(
"dir0 {
\n\n
dir1 arg0;}"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir0
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir0"
,
dir0
.
name
.
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
directives
.
size
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
conf_line
);
SrsConfDirective
&
dir1
=
*
dir0
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir1"
,
dir1
.
name
.
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir1
.
args
.
size
());
EXPECT_STREQ
(
"arg0"
,
dir1
.
arg0
().
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir1
.
directives
.
size
());
EXPECT_EQ
(
3
,
(
int
)
dir1
.
conf_line
);
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseLine4
)
{
MockSrsConfigBuffer
buf
(
"dir0 {
\n\n
dir1
\n\n
arg0;dir2 arg1;}"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir0
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir0"
,
dir0
.
name
.
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
args
.
size
());
EXPECT_EQ
(
2
,
(
int
)
dir0
.
directives
.
size
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
conf_line
);
SrsConfDirective
&
dir1
=
*
dir0
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir1"
,
dir1
.
name
.
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir1
.
args
.
size
());
EXPECT_STREQ
(
"arg0"
,
dir1
.
arg0
().
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir1
.
directives
.
size
());
EXPECT_EQ
(
3
,
(
int
)
dir1
.
conf_line
);
SrsConfDirective
&
dir2
=
*
dir0
.
directives
.
at
(
1
);
EXPECT_STREQ
(
"dir2"
,
dir2
.
name
.
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir2
.
args
.
size
());
EXPECT_STREQ
(
"arg1"
,
dir2
.
arg0
().
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir2
.
directives
.
size
());
EXPECT_EQ
(
5
,
(
int
)
dir2
.
conf_line
);
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseLineNormal
)
{
MockSrsConfigBuffer
buf
(
"dir0 {
\n
dir1 {
\n
dir2 arg2;
\n
}
\n
}"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir0
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir0"
,
dir0
.
name
.
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
directives
.
size
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
conf_line
);
SrsConfDirective
&
dir1
=
*
dir0
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir1"
,
dir1
.
name
.
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir1
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
dir1
.
directives
.
size
());
EXPECT_EQ
(
2
,
(
int
)
dir1
.
conf_line
);
SrsConfDirective
&
dir2
=
*
dir1
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir2"
,
dir2
.
name
.
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir2
.
args
.
size
());
EXPECT_STREQ
(
"arg2"
,
dir2
.
arg0
().
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir2
.
directives
.
size
());
EXPECT_EQ
(
3
,
(
int
)
dir2
.
conf_line
);
}
...
...
请
注册
或
登录
后发表评论