winlin

fix the empty config error

... ... @@ -1182,6 +1182,13 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer)
if ((ret = root->parse(buffer)) != ERROR_SUCCESS) {
return ret;
}
// check empty
if (root->directives.size() == 0) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("conf is empty, ret=%d", ret);
return ret;
}
// check root directives.
for (int i = 0; i < (int)root->directives.size(); i++) {
... ... @@ -1200,7 +1207,7 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer)
}
// check rtmp port specified by directive listen.
if (_srs_config->get_listen().size() <= 0) {
if (get_listen().size() <= 0) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive \"listen\" is empty, ret=%d", ret);
return ret;
... ...
... ... @@ -53,6 +53,20 @@ int MockSrsConfigBuffer::fullfill(const char* /*filename*/)
return ERROR_SUCCESS;
}
MockSrsConfig::MockSrsConfig()
{
}
MockSrsConfig::~MockSrsConfig()
{
}
int MockSrsConfig::parse(string buf)
{
MockSrsConfigBuffer buffer(buf);
return parse_buffer(&buffer);
}
VOID TEST(ConfigTest, CheckMacros)
{
#ifndef SRS_CONSTS_LOCALHOST
... ... @@ -777,3 +791,9 @@ VOID TEST(ConfigDirectiveTest, ParseLineNormal)
EXPECT_EQ(0, (int)dir2.directives.size());
EXPECT_EQ(3, (int)dir2.conf_line);
}
VOID TEST(ConfigMainTest, ParseEmpty)
{
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse(""));
}
... ...
... ... @@ -42,4 +42,13 @@ public:
virtual int fullfill(const char* filename);
};
class MockSrsConfig : public SrsConfig
{
public:
MockSrsConfig();
virtual ~MockSrsConfig();
public:
virtual int parse(std::string buf);
};
#endif
... ...