Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support include directive for config file #2878

Merged
merged 20 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Config: Refine code, parsing recursively.
  • Loading branch information
winlinvip committed Feb 13, 2022
commit fd7092367a96f1d9cd567fe594d5e150f1039378
39 changes: 8 additions & 31 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,23 +1021,15 @@ srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveCo
for (int i = 0; i < (int)files.size(); i++) {
std::string file = files.at(i);
srs_assert(!file.empty());

srs_trace("config parse include %s", file.c_str());
if (ctx != SrsDirectiveContextBlock) {
if ((err = conf->parse_include_file(file.c_str())) != srs_success) {
return srs_error_wrap(err, "parse file");
}
} else {
SrsConfigBuffer* config_buffer = conf->get_buffer_from_include_file(file.c_str());
SrsAutoFree(SrsConfigBuffer, config_buffer);

if(config_buffer == NULL) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "empty include buffer, file=%s", file.c_str());
} else {
if ((err = parse_conf(config_buffer, SrsDirectiveContextFile, conf)) != srs_success) {
return srs_error_wrap(err, "parse include buffer");
}
}

SrsConfigBuffer include_file_buffer;
if ((err = include_file_buffer.fullfill(file.c_str())) != srs_success) {
return srs_error_wrap(err, "buffer fullfill %s", file.c_str());
}

if ((err = parse_conf(&include_file_buffer, SrsDirectiveContextFile, conf)) != srs_success) {
return srs_error_wrap(err, "parse include buffer");
}
}
}
Expand Down Expand Up @@ -2458,21 +2450,6 @@ srs_error_t SrsConfig::parse_include_file(const char *filename)

return err;
}

SrsConfigBuffer* SrsConfig::get_buffer_from_include_file(const char* filename)
{
srs_error_t err = srs_success;

SrsConfigBuffer* buffer = new SrsConfigBuffer();

if ((err = buffer->fullfill(filename)) != srs_success) {
srs_freep(buffer);

return NULL;
}

return buffer;
}
// LCOV_EXCL_STOP

srs_error_t SrsConfig::check_config()
Expand Down
2 changes: 0 additions & 2 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,6 @@ class SrsConfig
virtual srs_error_t parse_file(const char* filename);
// Parse the include config file.
virtual srs_error_t parse_include_file(const char* filename);
// Get buffer from include config file.
virtual srs_internal::SrsConfigBuffer* get_buffer_from_include_file(const char* filename);
// Check the parsed config.
virtual srs_error_t check_config();
protected:
Expand Down
16 changes: 0 additions & 16 deletions trunk/src/utest/srs_utest_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,6 @@ SrsConfDirective* MockSrsConfig::get_mock_directive(const string file_name)
return mock_directive;
}

MockSrsConfigBuffer* MockSrsConfig::get_buffer_from_include_file(const char* filename)
{
MockSrsConfigBuffer* buffer = NULL;

std::string file = filename;
SrsConfDirective* mock_directive = get_mock_directive(file);

if(!mock_directive) {
return NULL;
} else {
buffer = new MockSrsConfigBuffer(mock_directive->arg0());
}

return buffer;
}

srs_error_t MockSrsConfig::parse(string buf)
{
srs_error_t err = srs_success;
Expand Down
1 change: 0 additions & 1 deletion trunk/src/utest/srs_utest_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class MockSrsConfig : public SrsConfig
public:
SrsConfDirective* get_mock_directive(const std::string file_name);
public:
virtual MockSrsConfigBuffer* get_buffer_from_include_file(const char* filename);
virtual srs_error_t parse(std::string buf);
virtual srs_error_t parse_include_file(const char* filename);
virtual srs_error_t mock_include(const std::string file_name, const std::string content);
Expand Down