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
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
52 changes: 33 additions & 19 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,35 +1014,49 @@ srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveTy
}

// build directive tree.
if (args[0] == "include") {
if (args.at(0) == "include") {
if (args.size() < 2) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: include is empty directive", buffer->line);
}
#if 0
winlinvip marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 1; i < (int)args.size(); i++) {
std::string file = args.at(i);

if (!srs_string_contains(file, "*", "?", "[")) {
srs_trace("config parse include %s", file.c_str());
srs_freep(err);
if ((err = conf->parse_include_file(file.c_str())) != srs_success) {
return srs_error_wrap(err, "parse file");
}
} else {
unsigned long i = 0;
glob_t glob_buf;

if (glob((char *) file.c_str(), 0, NULL, &glob_buf) != 0) {
winlinvip marked this conversation as resolved.
Show resolved Hide resolved
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: parse include %s failed", buffer->line, file.c_str());
}

while(i < glob_buf.gl_pathc) {
srs_trace("include %s", *(glob_buf.gl_pathv+i));
srs_freep(err);
if ((err = conf->parse_include_file(*(glob_buf.gl_pathv+i))) != srs_success) {
return srs_error_wrap(err, "parse file");
}
i ++;
}
}
}
#else
for (int i = 1; i < (int)args.size(); i++) {
std::string file = args.at(i);

std::string file = args[1];
if (!srs_string_contains(file, "*", "?", "[")) {
srs_trace("config parse include %s", file.c_str());
srs_freep(err);
if ((err = conf->parse_include_file(file.c_str())) != srs_success) {
return srs_error_wrap(err, "parse file");
}
} else {
unsigned long i = 0;
glob_t glob_buf;

if (glob((char *) file.c_str(), 0, NULL, &glob_buf) != 0) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: parse include %s failed", buffer->line, file.c_str());
}

while(i < glob_buf.gl_pathc) {
srs_trace("include %s", *(glob_buf.gl_pathv+i));
srs_freep(err);
if ((err = conf->parse_include_file(*(glob_buf.gl_pathv+i))) != srs_success) {
return srs_error_wrap(err, "parse file");
}
i ++;
}
}
#endif
} else {
SrsConfDirective* directive = new SrsConfDirective();

Expand Down