1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #1657, Support HTTPS API

This commit is contained in:
winlin 2020-11-06 15:05:01 +08:00
parent 7916214e27
commit 272ca9d0f6
20 changed files with 647 additions and 11 deletions

View file

@ -1538,6 +1538,11 @@ srs_error_t SrsConfig::reload_conf(SrsConfig* conf)
if ((err = reload_http_api(old_root)) != srs_success) {
return srs_error_wrap(err, "http api");;
}
// merge config: http_api.https
if ((err = reload_https_api(old_root)) != srs_success) {
return srs_error_wrap(err, "https api");;
}
// merge config: http_stream
if ((err = reload_http_stream(old_root)) != srs_success) {
@ -1637,6 +1642,67 @@ srs_error_t SrsConfig::reload_http_api(SrsConfDirective* old_root)
return err;
}
srs_error_t SrsConfig::reload_https_api(SrsConfDirective* old_root)
{
srs_error_t err = srs_success;
// merge config.
std::vector<ISrsReloadHandler*>::iterator it;
// state graph
// old_https_api new_https_api
// DISABLED => ENABLED
// ENABLED => DISABLED
// ENABLED => ENABLED (modified)
SrsConfDirective* new_http_api = root->get("http_api");
SrsConfDirective* old_http_api = old_root->get("http_api");
SrsConfDirective* new_https_api = (new_http_api? new_http_api->get("https") : NULL);
SrsConfDirective* old_https_api = (old_http_api? old_http_api->get("https") : NULL);
// DISABLED => ENABLED
if (!get_https_api_enabled(old_https_api) && get_https_api_enabled(new_https_api)) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((err = subscribe->on_reload_https_api_enabled()) != srs_success) {
return srs_error_wrap(err, "https api off=>on");
}
}
srs_trace("reload off=>on https_api success.");
return err;
}
// ENABLED => DISABLED
if (get_https_api_enabled(old_https_api) && !get_https_api_enabled(new_https_api)) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((err = subscribe->on_reload_https_api_disabled()) != srs_success) {
return srs_error_wrap(err, "https api on=>off");
}
}
srs_trace("reload https_api on=>off success.");
return err;
}
// ENABLED => ENABLED (modified)
if (get_https_api_enabled(old_https_api) && get_https_api_enabled(new_https_api)
&& !srs_directive_equals(old_https_api, new_https_api)
) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((err = subscribe->on_reload_https_api_enabled()) != srs_success) {
return srs_error_wrap(err, "https api enabled");
}
}
srs_trace("reload https api enabled success.");
return err;
}
srs_trace("reload https_api success, nothing changed.");
return err;
}
srs_error_t SrsConfig::reload_http_stream(SrsConfDirective* old_root)
{
srs_error_t err = srs_success;
@ -3584,7 +3650,7 @@ srs_error_t SrsConfig::check_normal_config()
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
SrsConfDirective* obj = conf->at(i);
string n = obj->name;
if (n != "enabled" && n != "listen" && n != "crossdomain" && n != "raw_api") {
if (n != "enabled" && n != "listen" && n != "crossdomain" && n != "raw_api" && n != "https") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal http_api.%s", n.c_str());
}
@ -7661,6 +7727,84 @@ bool SrsConfig::get_raw_api_allow_update()
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
SrsConfDirective* SrsConfig::get_https_api()
{
SrsConfDirective* conf = root->get("http_api");
if (!conf) {
return NULL;
}
return conf->get("https");
}
bool SrsConfig::get_https_api_enabled(SrsConfDirective* conf)
{
static bool DEFAULT = false;
conf = conf->get("enabled");
if (!conf) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_https_api_enabled()
{
SrsConfDirective* conf = get_https_api();
return get_https_api_enabled(conf);
}
string SrsConfig::get_https_api_listen()
{
static string DEFAULT = "1986";
SrsConfDirective* conf = get_https_api();
if (!conf) {
return DEFAULT;
}
conf = conf->get("listen");
if (!conf) {
return DEFAULT;
}
return conf->arg0();
}
string SrsConfig::get_https_api_ssl_key()
{
static string DEFAULT = "./conf/server.key";
SrsConfDirective* conf = get_https_api();
if (!conf) {
return DEFAULT;
}
conf = conf->get("key");
if (!conf) {
return DEFAULT;
}
return conf->arg0();
}
string SrsConfig::get_https_api_ssl_cert()
{
static string DEFAULT = "./conf/server.crt";
SrsConfDirective* conf = get_https_api();
if (!conf) {
return DEFAULT;
}
conf = conf->get("cert");
if (!conf) {
return DEFAULT;
}
return conf->arg0();
}
bool SrsConfig::get_srt_enabled()
{