mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
Support include empty config file. v5.0.173 v6.0.68 (#3768)
SRS supports including another configuration in the include package. When generating configurations, we can only generate the changed configurations, while the unchanged configurations are in the fixed files, for example: ```nginx listen 1935; include server.conf; ``` In `server.conf`, we can manage the changing configurations with the program: ```nginx http_api { enabled on; } ``` However, during system initialization, we often create an empty `server.conf`, and the content is generated only after the program starts, so `server.conf` might be an empty file. This also makes it convenient to use a script to confirm the existence of this file: ```bash touch server.conf ``` Currently, SRS does not support empty configurations and will report an error. This PR is to solve this problem, making it more convenient to use include. `TRANS_BY_GPT4` --------- Co-authored-by: Haibo Chen <495810242@qq.com>
This commit is contained in:
parent
b5347e19f7
commit
cf46dae80f
9 changed files with 124 additions and 22 deletions
27
README.md
27
README.md
|
@ -12,7 +12,7 @@
|
||||||
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fossrs%2Fsrs?ref=badge_small)
|
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fossrs%2Fsrs?ref=badge_small)
|
||||||
[](https://ossrs.net/lts/zh-cn/faq)
|
[](https://ossrs.net/lts/zh-cn/faq)
|
||||||
[](https://stackoverflow.com/questions/tagged/simple-realtime-server)
|
[](https://stackoverflow.com/questions/tagged/simple-realtime-server)
|
||||||
[](https://opencollective.com/srs-server/contribute)
|
[](https://opencollective.com/srs-server)
|
||||||
[](https://hub.docker.com/r/ossrs/srs/tags)
|
[](https://hub.docker.com/r/ossrs/srs/tags)
|
||||||
[](https://cloud.digitalocean.com/droplets/new?appId=133468816&size=s-1vcpu-512mb-10gb®ion=sgp1&image=ossrs-srs&type=applications)
|
[](https://cloud.digitalocean.com/droplets/new?appId=133468816&size=s-1vcpu-512mb-10gb®ion=sgp1&image=ossrs-srs&type=applications)
|
||||||
[](https://api.securityscorecards.dev/projects/github.com/ossrs/srs)
|
[](https://api.securityscorecards.dev/projects/github.com/ossrs/srs)
|
||||||
|
@ -104,16 +104,25 @@ Here are some other important wikis:
|
||||||
* Usage: What are the strategies for improving edge performance on multiple CPUs? ([CN](https://ossrs.net/lts/zh-cn/docs/v5/doc/reuse-port), [EN](https://ossrs.io/lts/en-us/docs/v5/doc/reuse-port))
|
* Usage: What are the strategies for improving edge performance on multiple CPUs? ([CN](https://ossrs.net/lts/zh-cn/docs/v5/doc/reuse-port), [EN](https://ossrs.io/lts/en-us/docs/v5/doc/reuse-port))
|
||||||
* Usage: How can bugs be reported or contact be made with us? ([CN](https://ossrs.net/lts/zh-cn/contact), [EN](https://ossrs.io/lts/en-us/contact))
|
* Usage: How can bugs be reported or contact be made with us? ([CN](https://ossrs.net/lts/zh-cn/contact), [EN](https://ossrs.io/lts/en-us/contact))
|
||||||
|
|
||||||
|
## Sponsor
|
||||||
|
|
||||||
|
Would you like additional assistance from us? By becoming a sponsor or backer of SRS, we can provide you
|
||||||
|
with the support you need:
|
||||||
|
|
||||||
|
* Backer: $5 per month, online text chat support through Discord.
|
||||||
|
* Sponsor: $100 per month, online meeting support, 1 meeting per month in 1 hour.
|
||||||
|
|
||||||
|
Please visit [OpenCollective](https://opencollective.com/srs-server) to become a backer or sponsor, and send
|
||||||
|
us a direct message on [Discord](https://discord.gg/yZ4BnPmHAd). We are currently providing support to the
|
||||||
|
developers listed below:
|
||||||
|
|
||||||
|
[](https://opencollective.com/srs-server)
|
||||||
|
|
||||||
|
We at SRS aim to establish a non-profit, open-source community that assists developers worldwide in creating
|
||||||
|
their own high-quality streaming and RTC platforms to support your businesses.
|
||||||
|
|
||||||
## AUTHORS
|
## AUTHORS
|
||||||
|
|
||||||
We highly appreciate all our contributors for their significant contributions that have made a remarkable difference.
|
|
||||||
Thank you! 🙏
|
|
||||||
|
|
||||||
If you wish to support this project financially, you can donate [through Open Collective](https://opencollective.com/srs-server).
|
|
||||||
We appreciate your contribution!
|
|
||||||
|
|
||||||
[](https://opencollective.com/srs-server/contribute/backer-34941/checkout?interval=month&amount=5)
|
|
||||||
|
|
||||||
The [TOC(Technical Oversight Committee)](trunk/AUTHORS.md#toc) and [contributors](trunk/AUTHORS.md#contributors):
|
The [TOC(Technical Oversight Committee)](trunk/AUTHORS.md#toc) and [contributors](trunk/AUTHORS.md#contributors):
|
||||||
|
|
||||||
* [Winlin](https://github.com/winlinvip): Founder of the project, focusing on ST and Issues/PR. Responsible for architecture and maintenance.
|
* [Winlin](https://github.com/winlinvip): Founder of the project, focusing on ST and Issues/PR. Responsible for architecture and maintenance.
|
||||||
|
|
2
trunk/configure
vendored
2
trunk/configure
vendored
|
@ -434,7 +434,7 @@ fi
|
||||||
if [[ $SRS_UTEST == YES ]]; then
|
if [[ $SRS_UTEST == YES ]]; then
|
||||||
MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_kernel" "srs_utest_core"
|
MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_kernel" "srs_utest_core"
|
||||||
"srs_utest_config" "srs_utest_rtmp" "srs_utest_http" "srs_utest_avc" "srs_utest_reload"
|
"srs_utest_config" "srs_utest_rtmp" "srs_utest_http" "srs_utest_avc" "srs_utest_reload"
|
||||||
"srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc"
|
"srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc" "srs_utest_config2"
|
||||||
"srs_utest_protocol" "srs_utest_protocol2" "srs_utest_kernel2")
|
"srs_utest_protocol" "srs_utest_protocol2" "srs_utest_kernel2")
|
||||||
if [[ $SRS_SRT == YES ]]; then
|
if [[ $SRS_SRT == YES ]]; then
|
||||||
MODULE_FILES+=("srs_utest_srt")
|
MODULE_FILES+=("srs_utest_srt")
|
||||||
|
|
|
@ -7,6 +7,7 @@ The changelog for SRS.
|
||||||
<a name="v6-changes"></a>
|
<a name="v6-changes"></a>
|
||||||
|
|
||||||
## SRS 6.0 Changelog
|
## SRS 6.0 Changelog
|
||||||
|
* v6.0, 2023-08-28, Merge [#3768](https://github.com/ossrs/srs/pull/3768): Support include empty config file. v6.0.68 (#3768)
|
||||||
* v6.0, 2023-08-25, Merge [#3782](https://github.com/ossrs/srs/pull/3782): HLS: Support reload HLS asynchronously. v6.0.67 (#3782)
|
* v6.0, 2023-08-25, Merge [#3782](https://github.com/ossrs/srs/pull/3782): HLS: Support reload HLS asynchronously. v6.0.67 (#3782)
|
||||||
* v6.0, 2023-08-22, Merge [#3775](https://github.com/ossrs/srs/pull/3775): Bugfix: Log format output type does not match. v6.0.66 (#3699)
|
* v6.0, 2023-08-22, Merge [#3775](https://github.com/ossrs/srs/pull/3775): Bugfix: Log format output type does not match. v6.0.66 (#3699)
|
||||||
* v6.0, 2023-08-02, Merge [#3750](https://github.com/ossrs/srs/pull/3750): HLS: Ignore empty NALU to avoid error. v6.0.64 (#3750)
|
* v6.0, 2023-08-02, Merge [#3750](https://github.com/ossrs/srs/pull/3750): HLS: Ignore empty NALU to avoid error. v6.0.64 (#3750)
|
||||||
|
@ -79,7 +80,8 @@ The changelog for SRS.
|
||||||
<a name="v5-changes"></a>
|
<a name="v5-changes"></a>
|
||||||
|
|
||||||
## SRS 5.0 Changelog
|
## SRS 5.0 Changelog
|
||||||
* v5.0, 2023-08-25, Merge [#3782](https://github.com/ossrs/srs/pull/3782): HLS: Support reload HLS asynchronously.. v5.0.171 (#3782)
|
* v5.0, 2023-08-28, Merge [#3768](https://github.com/ossrs/srs/pull/3768): Support include empty config file. v5.0.173 (#3768)
|
||||||
|
* v5.0, 2023-08-25, Merge [#3782](https://github.com/ossrs/srs/pull/3782): HLS: Support reload HLS asynchronously. v5.0.172 (#3782)
|
||||||
* v5.0, 2023-08-22, Merge [#3775](https://github.com/ossrs/srs/pull/3775): Bugfix: Log format output type does not match. v5.0.171 (#3699)
|
* v5.0, 2023-08-22, Merge [#3775](https://github.com/ossrs/srs/pull/3775): Bugfix: Log format output type does not match. v5.0.171 (#3699)
|
||||||
* v5.0, 2023-08-02, HLS: Ignore empty NALU to avoid error. v5.0.170
|
* v5.0, 2023-08-02, HLS: Ignore empty NALU to avoid error. v5.0.170
|
||||||
* v5.0, 2023-07-26, Merge [#3699](https://github.com/ossrs/srs/pull/3699): Bugfix: Eliminate the redundant declaration of the _srs_rtc_manager variable. v5.0.168 (#3699)
|
* v5.0, 2023-07-26, Merge [#3699](https://github.com/ossrs/srs/pull/3699): Bugfix: Eliminate the redundant declaration of the _srs_rtc_manager variable. v5.0.168 (#3699)
|
||||||
|
|
|
@ -123,6 +123,8 @@ namespace srs_internal
|
||||||
|
|
||||||
// read all.
|
// read all.
|
||||||
int filesize = (int)reader.filesize();
|
int filesize = (int)reader.filesize();
|
||||||
|
// Ignore if empty file.
|
||||||
|
if (filesize <= 0) return err;
|
||||||
|
|
||||||
// create buffer
|
// create buffer
|
||||||
srs_freepa(start);
|
srs_freepa(start);
|
||||||
|
@ -1069,6 +1071,9 @@ srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveCo
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
// Ignore empty config file.
|
||||||
|
if (ctx == SrsDirectiveContextFile && buffer->empty()) return err;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
std::vector<string> args;
|
std::vector<string> args;
|
||||||
int line_start = 0;
|
int line_start = 0;
|
||||||
|
@ -1127,7 +1132,7 @@ srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveCo
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = parse_conf(include_file_buffer, SrsDirectiveContextFile, conf)) != srs_success) {
|
if ((err = parse_conf(include_file_buffer, SrsDirectiveContextFile, conf)) != srs_success) {
|
||||||
return srs_error_wrap(err, "parse include buffer");
|
return srs_error_wrap(err, "parse include buffer %s", file.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2197,11 +2202,11 @@ srs_error_t SrsConfig::parse_file(const char* filename)
|
||||||
SrsConfigBuffer* buffer = NULL;
|
SrsConfigBuffer* buffer = NULL;
|
||||||
SrsAutoFree(SrsConfigBuffer, buffer);
|
SrsAutoFree(SrsConfigBuffer, buffer);
|
||||||
if ((err = build_buffer(config_file, &buffer)) != srs_success) {
|
if ((err = build_buffer(config_file, &buffer)) != srs_success) {
|
||||||
return srs_error_wrap(err, "buffer fullfill %s", config_file.c_str());
|
return srs_error_wrap(err, "buffer fullfill %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = parse_buffer(buffer)) != srs_success) {
|
if ((err = parse_buffer(buffer)) != srs_success) {
|
||||||
return srs_error_wrap(err, "parse buffer");
|
return srs_error_wrap(err, "parse buffer %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 5
|
#define VERSION_MAJOR 5
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 172
|
#define VERSION_REVISION 173
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 6
|
#define VERSION_MAJOR 6
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 67
|
#define VERSION_REVISION 68
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -85,11 +85,14 @@ srs_error_t MockSrsConfig::build_buffer(std::string src, srs_internal::SrsConfig
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
string content = included_files[src];
|
// No file, error.
|
||||||
if(content.empty()) {
|
if(included_files.find(src) == included_files.end()) {
|
||||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "file %s: no found", src.c_str());
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "file %s: no found", src.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string content = included_files[src];
|
||||||
|
|
||||||
|
// Empty file, ok.
|
||||||
*pbuffer = new MockSrsConfigBuffer(content);
|
*pbuffer = new MockSrsConfigBuffer(content);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -690,9 +693,29 @@ VOID TEST(ConfigDirectiveTest, ParseInvalidNoEndOfSubDirective)
|
||||||
{
|
{
|
||||||
srs_error_t err;
|
srs_error_t err;
|
||||||
|
|
||||||
MockSrsConfigBuffer buf("dir0 {");
|
if (true) {
|
||||||
SrsConfDirective conf;
|
MockSrsConfigBuffer buf("");
|
||||||
HELPER_ASSERT_FAILED(conf.parse(&buf));
|
SrsConfDirective conf;
|
||||||
|
HELPER_ASSERT_SUCCESS(conf.parse(&buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
MockSrsConfigBuffer buf("# OK");
|
||||||
|
SrsConfDirective conf;
|
||||||
|
HELPER_ASSERT_SUCCESS(conf.parse(&buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
MockSrsConfigBuffer buf("dir0 {");
|
||||||
|
SrsConfDirective conf;
|
||||||
|
HELPER_ASSERT_FAILED(conf.parse(&buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
MockSrsConfigBuffer buf("dir0 {} dir1 {");
|
||||||
|
SrsConfDirective conf;
|
||||||
|
HELPER_ASSERT_FAILED(conf.parse(&buf));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(ConfigDirectiveTest, ParseInvalidNoStartOfSubDirective)
|
VOID TEST(ConfigDirectiveTest, ParseInvalidNoStartOfSubDirective)
|
||||||
|
|
47
trunk/src/utest/srs_utest_config2.cpp
Normal file
47
trunk/src/utest/srs_utest_config2.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2013-2023 The SRS Authors
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT or MulanPSL-2.0
|
||||||
|
//
|
||||||
|
#include <srs_utest_config2.hpp>
|
||||||
|
|
||||||
|
#include <srs_kernel_error.hpp>
|
||||||
|
#include <srs_kernel_file.hpp>
|
||||||
|
#include <srs_utest_kernel.hpp>
|
||||||
|
|
||||||
|
VOID TEST(ConfigMainTest, CheckIncludeEmptyConfig)
|
||||||
|
{
|
||||||
|
srs_error_t err;
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
string filepath = _srs_tmp_file_prefix + "utest-main.conf";
|
||||||
|
MockFileRemover _mfr(filepath);
|
||||||
|
|
||||||
|
string included = _srs_tmp_file_prefix + "utest-included-empty.conf";
|
||||||
|
MockFileRemover _mfr2(included);
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsFileWriter fw;
|
||||||
|
fw.open(included);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsFileWriter fw;
|
||||||
|
fw.open(filepath);
|
||||||
|
string content = _MIN_OK_CONF "include " + included + ";";
|
||||||
|
fw.write((void*)content.data(), (int)content.length(), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
SrsConfig conf;
|
||||||
|
HELPER_ASSERT_SUCCESS(conf.parse_file(filepath.c_str()));
|
||||||
|
EXPECT_EQ(1, (int)conf.get_listens().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
MockSrsConfig conf;
|
||||||
|
conf.mock_include("test.conf", "");
|
||||||
|
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "include test.conf;"));
|
||||||
|
EXPECT_EQ(1, (int)conf.get_listens().size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
16
trunk/src/utest/srs_utest_config2.hpp
Normal file
16
trunk/src/utest/srs_utest_config2.hpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2013-2023 The SRS Authors
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT or MulanPSL-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SRS_UTEST_CONFIG2_HPP
|
||||||
|
#define SRS_UTEST_CONFIG2_HPP
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <srs_utest_config2.hpp>
|
||||||
|
*/
|
||||||
|
#include <srs_utest_config.hpp>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue