mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Config: Improve env config to support multi values. v7.0.2 (#4092)
1. add on_connect & on_close directives to conf/full.conf; 2. let http_hooks env overwrite support multi values; e.g. SRS_VHOST_HTTP_HOOKS_ON_CONNECT="http://127.0.0.1/api/connect http://localhost/api/connect" related to https://github.com/ossrs/srs/issues/1222#issuecomment-2170424703 Above comments said `http_hook` env may not works as expected, as I found there are still has some issue in `http_hooks` env configuration, but this PR may not target above problem. --------- Co-authored-by: winlin <winlinvip@gmail.com>
This commit is contained in:
parent
2e211f6abe
commit
16e569d823
4 changed files with 47 additions and 14 deletions
|
@ -7,6 +7,7 @@ The changelog for SRS.
|
||||||
<a name="v7-changes"></a>
|
<a name="v7-changes"></a>
|
||||||
|
|
||||||
## SRS 7.0 Changelog
|
## SRS 7.0 Changelog
|
||||||
|
* v7.0, 2024-08-13, Merge [#4092](https://github.com/ossrs/srs/pull/4092): Config: Improve env config to support multi values. v7.0.2 (#4092)
|
||||||
* v7.0, 2024-08-12, Merge [#4131](https://github.com/ossrs/srs/pull/4131): Transcode: More generic h264/h265 codec support. v7.0.1 (#4131)
|
* v7.0, 2024-08-12, Merge [#4131](https://github.com/ossrs/srs/pull/4131): Transcode: More generic h264/h265 codec support. v7.0.1 (#4131)
|
||||||
* v7.0, 2024-08-12, Init SRS 7 branch. v7.0.0
|
* v7.0, 2024-08-12, Init SRS 7 branch. v7.0.0
|
||||||
|
|
||||||
|
|
|
@ -68,15 +68,17 @@ const char* _srs_version = "XCORE-" RTMP_SIG_SRS_SERVER;
|
||||||
#define SRS_OVERWRITE_BY_ENV_MILLISECONDS(key) if (!srs_getenv(key).empty()) return (srs_utime_t)(::atoi(srs_getenv(key).c_str()) * SRS_UTIME_MILLISECONDS)
|
#define SRS_OVERWRITE_BY_ENV_MILLISECONDS(key) if (!srs_getenv(key).empty()) return (srs_utime_t)(::atoi(srs_getenv(key).c_str()) * SRS_UTIME_MILLISECONDS)
|
||||||
#define SRS_OVERWRITE_BY_ENV_FLOAT_SECONDS(key) if (!srs_getenv(key).empty()) return srs_utime_t(::atof(srs_getenv(key).c_str()) * SRS_UTIME_SECONDS)
|
#define SRS_OVERWRITE_BY_ENV_FLOAT_SECONDS(key) if (!srs_getenv(key).empty()) return srs_utime_t(::atof(srs_getenv(key).c_str()) * SRS_UTIME_SECONDS)
|
||||||
#define SRS_OVERWRITE_BY_ENV_FLOAT_MILLISECONDS(key) if (!srs_getenv(key).empty()) return srs_utime_t(::atof(srs_getenv(key).c_str()) * SRS_UTIME_MILLISECONDS)
|
#define SRS_OVERWRITE_BY_ENV_FLOAT_MILLISECONDS(key) if (!srs_getenv(key).empty()) return srs_utime_t(::atof(srs_getenv(key).c_str()) * SRS_UTIME_MILLISECONDS)
|
||||||
#define SRS_OVERWRITE_BY_ENV_DIRECTIVE(key) { \
|
#define SRS_OVERWRITE_BY_ENV_DIRECTIVE(key) { \
|
||||||
static SrsConfDirective* dir = NULL; \
|
static SrsConfDirective* dir = NULL; \
|
||||||
if (!dir && !srs_getenv(key).empty()) { \
|
if (!dir && !srs_getenv(key).empty()) { \
|
||||||
string v = srs_getenv(key); \
|
std::vector<string> vec = srs_string_split(srs_getenv(key), " "); \
|
||||||
dir = new SrsConfDirective(); \
|
dir = new SrsConfDirective(); \
|
||||||
dir->name = key; \
|
dir->name = key; \
|
||||||
dir->args.push_back(v); \
|
for (size_t i = 0; i < vec.size(); ++i) { \
|
||||||
} \
|
dir->args.push_back(vec[i]); \
|
||||||
if (dir) return dir; \
|
} \
|
||||||
|
} \
|
||||||
|
if (dir) return dir; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 7
|
#define VERSION_MAJOR 7
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 1
|
#define VERSION_REVISION 2
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -3369,7 +3369,20 @@ VOID TEST(ConfigMainTest, CheckVhostConfig3)
|
||||||
if (true) {
|
if (true) {
|
||||||
MockSrsConfig conf;
|
MockSrsConfig conf;
|
||||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_connect xxx;}}"));
|
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_connect xxx;}}"));
|
||||||
EXPECT_TRUE(conf.get_vhost_on_connect("ossrs.net") != NULL);
|
SrsConfDirective* dir = conf.get_vhost_on_connect("ossrs.net");
|
||||||
|
ASSERT_TRUE(dir != NULL);
|
||||||
|
ASSERT_EQ((int)dir->args.size(), 1);
|
||||||
|
ASSERT_STREQ("xxx", dir->arg0().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
MockSrsConfig conf;
|
||||||
|
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_connect xxx yyy;}}"));
|
||||||
|
SrsConfDirective* dir = conf.get_vhost_on_connect("ossrs.net");
|
||||||
|
ASSERT_TRUE(dir != NULL);
|
||||||
|
ASSERT_EQ((int)dir->args.size(), 2);
|
||||||
|
ASSERT_STREQ("xxx", dir->arg0().c_str());
|
||||||
|
ASSERT_STREQ("yyy", dir->arg1().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -5046,11 +5059,29 @@ VOID TEST(ConfigEnvTest, CheckEnvValuesHooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsSetEnvConfig(hooks, "SRS_VHOST_HTTP_HOOKS_ON_PUBLISH", "http://server/api/publish");
|
SrsSetEnvConfig(hooks, "SRS_VHOST_HTTP_HOOKS_ON_CONNECT", "http://server/api/connect https://server2/api/connect2");
|
||||||
SrsConfDirective* dir = conf.get_vhost_on_publish("__defaultVhost__");
|
SrsConfDirective* dir = conf.get_vhost_on_connect("__defaultVhost__");
|
||||||
|
ASSERT_TRUE(dir != NULL);
|
||||||
|
ASSERT_EQ((int)dir->args.size(), 2);
|
||||||
|
ASSERT_STREQ("http://server/api/connect", dir->arg0().c_str());
|
||||||
|
ASSERT_STREQ("https://server2/api/connect2", dir->arg1().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsSetEnvConfig(hooks, "SRS_VHOST_HTTP_HOOKS_ON_CLOSE", "http://server/api/close");
|
||||||
|
SrsConfDirective* dir = conf.get_vhost_on_close("__defaultVhost__");
|
||||||
ASSERT_TRUE(dir != NULL);
|
ASSERT_TRUE(dir != NULL);
|
||||||
ASSERT_TRUE((int)dir->args.size() == 1);
|
ASSERT_TRUE((int)dir->args.size() == 1);
|
||||||
|
ASSERT_STREQ("http://server/api/close", dir->arg0().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsSetEnvConfig(hooks, "SRS_VHOST_HTTP_HOOKS_ON_PUBLISH", "http://server/api/publish http://server/api/publish2");
|
||||||
|
SrsConfDirective* dir = conf.get_vhost_on_publish("__defaultVhost__");
|
||||||
|
ASSERT_TRUE(dir != NULL);
|
||||||
|
ASSERT_EQ((int)dir->args.size(), 2);
|
||||||
ASSERT_STREQ("http://server/api/publish", dir->arg0().c_str());
|
ASSERT_STREQ("http://server/api/publish", dir->arg0().c_str());
|
||||||
|
ASSERT_STREQ("http://server/api/publish2", dir->arg1().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -5101,4 +5132,3 @@ VOID TEST(ConfigEnvTest, CheckEnvValuesHooks)
|
||||||
ASSERT_STREQ("http://server/api/hls_notify", dir->arg0().c_str());
|
ASSERT_STREQ("http://server/api/hls_notify", dir->arg0().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue