Skip to content

Commit d2de910

Browse files
Support include empty config file. v5.0.172 v6.0.67 (#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 <[email protected]>
1 parent b5347e1 commit d2de910

9 files changed

+122
-20
lines changed

README.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[![](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fossrs%2Fsrs.svg?type=small)](https://app.fossa.com/projects/git%2Bgithub.com%2Fossrs%2Fsrs?ref=badge_small)
1313
[![](https://ossrs.net/wiki/images/srs-faq.svg)](https://ossrs.net/lts/zh-cn/faq)
1414
[![](https://badgen.net/badge/srs/stackoverflow/orange?icon=terminal)](https://stackoverflow.com/questions/tagged/simple-realtime-server)
15-
[![](https://opencollective.com/srs-server/tiers/badge.svg)](https://opencollective.com/srs-server/contribute)
15+
[![](https://opencollective.com/srs-server/tiers/badge.svg)](https://opencollective.com/srs-server)
1616
[![](https://img.shields.io/docker/pulls/ossrs/srs)](https://hub.docker.com/r/ossrs/srs/tags)
1717
[![](https://ossrs.net/wiki/images/do-btn-srs-125x20.svg)](https://cloud.digitalocean.com/droplets/new?appId=133468816&size=s-1vcpu-512mb-10gb&region=sgp1&image=ossrs-srs&type=applications)
1818
[![](https://api.securityscorecards.dev/projects/github.com/ossrs/srs/badge)](https://api.securityscorecards.dev/projects/github.com/ossrs/srs)
@@ -104,15 +104,24 @@ Here are some other important wikis:
104104
* 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))
105105
* 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))
106106

107-
## AUTHORS
107+
## Sponsor
108+
109+
Would you like additional assistance from us? By becoming a sponsor or backer of SRS, we can provide you
110+
with the support you need:
111+
112+
* Backer: $5 per month, online text chat support through Discord.
113+
* Sponsor: $100 per month, online meeting support, 1 meeting per month in 1 hour.
108114

109-
We highly appreciate all our contributors for their significant contributions that have made a remarkable difference.
110-
Thank you! 🙏
115+
Please visit [OpenCollective](https://opencollective.com/srs-server) to become a backer or sponsor, and send
116+
us a direct message on [Discord](https://discord.gg/yZ4BnPmHAd). We are currently providing support to the
117+
developers listed below:
111118

112-
If you wish to support this project financially, you can donate [through Open Collective](https://opencollective.com/srs-server).
113-
We appreciate your contribution!
119+
[![](https://opencollective.com/srs-server/backers.svg?width=800&button=false)](https://opencollective.com/srs-server)
114120

115-
[![](https://opencollective.com/srs-server/backers.svg?width=800&button=true)](https://opencollective.com/srs-server/contribute/backer-34941/checkout?interval=month&amount=5)
121+
We at SRS aim to establish a non-profit, open-source community that assists developers worldwide in creating
122+
their own high-quality streaming and RTC platforms to support your businesses.
123+
124+
## AUTHORS
116125

117126
The [TOC(Technical Oversight Committee)](trunk/AUTHORS.md#toc) and [contributors](trunk/AUTHORS.md#contributors):
118127

trunk/configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ fi
434434
if [[ $SRS_UTEST == YES ]]; then
435435
MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_kernel" "srs_utest_core"
436436
"srs_utest_config" "srs_utest_rtmp" "srs_utest_http" "srs_utest_avc" "srs_utest_reload"
437-
"srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc"
437+
"srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc" "srs_utest_config2"
438438
"srs_utest_protocol" "srs_utest_protocol2" "srs_utest_kernel2")
439439
if [[ $SRS_SRT == YES ]]; then
440440
MODULE_FILES+=("srs_utest_srt")

trunk/doc/CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The changelog for SRS.
77
<a name="v6-changes"></a>
88

99
## SRS 6.0 Changelog
10+
* v6.0, 2023-08-28, Merge [#3768](https://github.com/ossrs/srs/pull/3768): Support include empty config file. v6.0.67 (#3768)
1011
* v6.0, 2023-08-25, Merge [#3782](https://github.com/ossrs/srs/pull/3782): HLS: Support reload HLS asynchronously. v6.0.67 (#3782)
1112
* 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)
1213
* 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.
7980
<a name="v5-changes"></a>
8081

8182
## SRS 5.0 Changelog
82-
* v5.0, 2023-08-25, Merge [#3782](https://github.com/ossrs/srs/pull/3782): HLS: Support reload HLS asynchronously.. v5.0.171 (#3782)
83+
* v5.0, 2023-08-28, Merge [#3768](https://github.com/ossrs/srs/pull/3768): Support include empty config file. v5.0.172 (#3768)
84+
* v5.0, 2023-08-25, Merge [#3782](https://github.com/ossrs/srs/pull/3782): HLS: Support reload HLS asynchronously. v5.0.171 (#3782)
8385
* 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)
8486
* v5.0, 2023-08-02, HLS: Ignore empty NALU to avoid error. v5.0.170
8587
* 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)

trunk/src/app/srs_app_config.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ namespace srs_internal
123123

124124
// read all.
125125
int filesize = (int)reader.filesize();
126+
// Ignore if empty file.
127+
if (filesize <= 0) return err;
126128

127129
// create buffer
128130
srs_freepa(start);
@@ -1068,6 +1070,9 @@ SrsJsonAny* SrsConfDirective::dumps_arg0_to_boolean()
10681070
srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveContext ctx, SrsConfig* conf)
10691071
{
10701072
srs_error_t err = srs_success;
1073+
1074+
// Ignore empty config file.
1075+
if (ctx == SrsDirectiveContextFile && buffer->empty()) return err;
10711076

10721077
while (true) {
10731078
std::vector<string> args;
@@ -1127,7 +1132,7 @@ srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveCo
11271132
}
11281133

11291134
if ((err = parse_conf(include_file_buffer, SrsDirectiveContextFile, conf)) != srs_success) {
1130-
return srs_error_wrap(err, "parse include buffer");
1135+
return srs_error_wrap(err, "parse include buffer %s", file.c_str());
11311136
}
11321137
}
11331138
}
@@ -2197,11 +2202,11 @@ srs_error_t SrsConfig::parse_file(const char* filename)
21972202
SrsConfigBuffer* buffer = NULL;
21982203
SrsAutoFree(SrsConfigBuffer, buffer);
21992204
if ((err = build_buffer(config_file, &buffer)) != srs_success) {
2200-
return srs_error_wrap(err, "buffer fullfill %s", config_file.c_str());
2205+
return srs_error_wrap(err, "buffer fullfill %s", filename);
22012206
}
22022207

22032208
if ((err = parse_buffer(buffer)) != srs_success) {
2204-
return srs_error_wrap(err, "parse buffer");
2209+
return srs_error_wrap(err, "parse buffer %s", filename);
22052210
}
22062211

22072212
return err;

trunk/src/core/srs_core_version5.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 5
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 172
12+
#define VERSION_REVISION 173
1313

1414
#endif

trunk/src/core/srs_core_version6.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 6
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 67
12+
#define VERSION_REVISION 68
1313

1414
#endif

trunk/src/utest/srs_utest_config.cpp

+29-6
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,14 @@ srs_error_t MockSrsConfig::build_buffer(std::string src, srs_internal::SrsConfig
8585
{
8686
srs_error_t err = srs_success;
8787

88-
string content = included_files[src];
89-
if(content.empty()) {
88+
// No file, error.
89+
if(included_files.find(src) == included_files.end()) {
9090
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "file %s: no found", src.c_str());
9191
}
9292

93+
string content = included_files[src];
94+
95+
// Empty file, ok.
9396
*pbuffer = new MockSrsConfigBuffer(content);
9497

9598
return err;
@@ -689,10 +692,30 @@ VOID TEST(ConfigDirectiveTest, ParseInvalidNoEndOfDirective)
689692
VOID TEST(ConfigDirectiveTest, ParseInvalidNoEndOfSubDirective)
690693
{
691694
srs_error_t err;
692-
693-
MockSrsConfigBuffer buf("dir0 {");
694-
SrsConfDirective conf;
695-
HELPER_ASSERT_FAILED(conf.parse(&buf));
695+
696+
if (true) {
697+
MockSrsConfigBuffer buf("");
698+
SrsConfDirective conf;
699+
HELPER_ASSERT_SUCCESS(conf.parse(&buf));
700+
}
701+
702+
if (true) {
703+
MockSrsConfigBuffer buf("# OK");
704+
SrsConfDirective conf;
705+
HELPER_ASSERT_SUCCESS(conf.parse(&buf));
706+
}
707+
708+
if (true) {
709+
MockSrsConfigBuffer buf("dir0 {");
710+
SrsConfDirective conf;
711+
HELPER_ASSERT_FAILED(conf.parse(&buf));
712+
}
713+
714+
if (true) {
715+
MockSrsConfigBuffer buf("dir0 {} dir1 {");
716+
SrsConfDirective conf;
717+
HELPER_ASSERT_FAILED(conf.parse(&buf));
718+
}
696719
}
697720

698721
VOID TEST(ConfigDirectiveTest, ParseInvalidNoStartOfSubDirective)

trunk/src/utest/srs_utest_config2.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Copyright (c) 2013-2023 The SRS Authors
3+
//
4+
// SPDX-License-Identifier: MIT or MulanPSL-2.0
5+
//
6+
#include <srs_utest_config2.hpp>
7+
8+
#include <srs_kernel_error.hpp>
9+
#include <srs_kernel_file.hpp>
10+
#include <srs_utest_kernel.hpp>
11+
12+
VOID TEST(ConfigMainTest, CheckIncludeEmptyConfig)
13+
{
14+
srs_error_t err;
15+
16+
if (true) {
17+
string filepath = _srs_tmp_file_prefix + "utest-main.conf";
18+
MockFileRemover _mfr(filepath);
19+
20+
string included = _srs_tmp_file_prefix + "utest-included-empty.conf";
21+
MockFileRemover _mfr2(included);
22+
23+
if (true) {
24+
SrsFileWriter fw;
25+
fw.open(included);
26+
}
27+
28+
if (true) {
29+
SrsFileWriter fw;
30+
fw.open(filepath);
31+
string content = _MIN_OK_CONF "include " + included + ";";
32+
fw.write((void*)content.data(), (int)content.length(), NULL);
33+
}
34+
35+
SrsConfig conf;
36+
HELPER_ASSERT_SUCCESS(conf.parse_file(filepath.c_str()));
37+
EXPECT_EQ(1, (int)conf.get_listens().size());
38+
}
39+
40+
if (true) {
41+
MockSrsConfig conf;
42+
conf.mock_include("test.conf", "");
43+
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "include test.conf;"));
44+
EXPECT_EQ(1, (int)conf.get_listens().size());
45+
}
46+
}
47+

trunk/src/utest/srs_utest_config2.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Copyright (c) 2013-2023 The SRS Authors
3+
//
4+
// SPDX-License-Identifier: MIT or MulanPSL-2.0
5+
//
6+
7+
#ifndef SRS_UTEST_CONFIG2_HPP
8+
#define SRS_UTEST_CONFIG2_HPP
9+
10+
/*
11+
#include <srs_utest_config2.hpp>
12+
*/
13+
#include <srs_utest_config.hpp>
14+
15+
#endif
16+

0 commit comments

Comments
 (0)