mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #319, support enable or disable vhost.
This commit is contained in:
parent
631e76cd32
commit
e8a00de4a3
3 changed files with 93 additions and 10 deletions
|
@ -721,16 +721,9 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
|
|||
|
||||
// ENABLED => DISABLED
|
||||
if (get_vhost_enabled(old_vhost) && !get_vhost_enabled(new_vhost)) {
|
||||
srs_trace("vhost %s removed, reload it.", vhost.c_str());
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_vhost_removed(vhost)) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes removed "
|
||||
"vhost %s failed. ret=%d", vhost.c_str(), ret);
|
||||
if ((ret = do_reload_vhost_removed(vhost)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload removed vhost %s success.", vhost.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2514,6 +2507,42 @@ int SrsConfig::raw_delete_vhost(string vhost, bool& applied)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::raw_disable_vhost(string vhost, bool& applied)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
applied = false;
|
||||
|
||||
SrsConfDirective* conf = root->get("vhost", vhost);
|
||||
conf->get_or_create("enabled")->set_arg0("off");
|
||||
|
||||
if ((ret = do_reload_vhost_removed(vhost)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
applied = true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::raw_enable_vhost(string vhost, bool& applied)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
applied = false;
|
||||
|
||||
SrsConfDirective* conf = root->get("vhost", vhost);
|
||||
conf->get_or_create("enabled")->set_arg0("on");
|
||||
|
||||
if ((ret = do_reload_vhost_added(vhost)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
applied = true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::do_reload_listen()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
@ -2670,6 +2699,26 @@ int SrsConfig::do_reload_vhost_added(string vhost)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::do_reload_vhost_removed(string vhost)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_trace("vhost %s removed, reload it.", vhost.c_str());
|
||||
|
||||
vector<ISrsReloadHandler*>::iterator it;
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_vhost_removed(vhost)) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes removed "
|
||||
"vhost %s failed. ret=%d", vhost.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload removed vhost %s success.", vhost.c_str());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
string SrsConfig::config()
|
||||
{
|
||||
return config_file;
|
||||
|
|
|
@ -390,6 +390,14 @@ public:
|
|||
* raw delete the disabled vhost.
|
||||
*/
|
||||
virtual int raw_delete_vhost(std::string vhost, bool& applied);
|
||||
/**
|
||||
* raw disable the enabled vhost.
|
||||
*/
|
||||
virtual int raw_disable_vhost(std::string vhost, bool& applied);
|
||||
/**
|
||||
* raw enable the disabled vhost.
|
||||
*/
|
||||
virtual int raw_enable_vhost(std::string vhost, bool& applied);
|
||||
private:
|
||||
virtual int do_reload_listen();
|
||||
virtual int do_reload_pid();
|
||||
|
@ -400,6 +408,7 @@ private:
|
|||
virtual int do_reload_utc_time();
|
||||
virtual int do_reload_pithy_print_ms();
|
||||
virtual int do_reload_vhost_added(std::string vhost);
|
||||
virtual int do_reload_vhost_removed(std::string vhost);
|
||||
public:
|
||||
/**
|
||||
* get the config file path.
|
||||
|
|
|
@ -1155,7 +1155,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
|||
} else if (scope == "vhost") {
|
||||
std::string param = r->query_get("param");
|
||||
std::string data = r->query_get("data");
|
||||
if (param != "create" && param != "update" && param != "delete") {
|
||||
if (param != "create" && param != "update" && param != "delete" && param != "disable" && param != "enable") {
|
||||
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED;
|
||||
srs_error("raw api query invalid scope=%s, param=%s. ret=%d", scope.c_str(), param.c_str(), ret);
|
||||
return srs_api_response_code(w, r, ret);
|
||||
|
@ -1202,7 +1202,32 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
|||
srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret);
|
||||
return srs_api_response_code(w, r, ret);
|
||||
}
|
||||
} else if (param == "disable") {
|
||||
// when disable, the vhost must exists and enabled.
|
||||
SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
|
||||
if (param.empty() || !vhost || !_srs_config->get_vhost_enabled(vhost)) {
|
||||
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS;
|
||||
srs_error("raw api update check vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret);
|
||||
return srs_api_response_code(w, r, ret);
|
||||
}
|
||||
|
||||
if ((ret = _srs_config->raw_disable_vhost(value, applied)) != ERROR_SUCCESS) {
|
||||
srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret);
|
||||
return srs_api_response_code(w, r, ret);
|
||||
}
|
||||
} else if (param == "enable") {
|
||||
// when enable, the vhost must exists and disabled.
|
||||
SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
|
||||
if (param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) {
|
||||
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS;
|
||||
srs_error("raw api update check vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret);
|
||||
return srs_api_response_code(w, r, ret);
|
||||
}
|
||||
|
||||
if ((ret = _srs_config->raw_enable_vhost(value, applied)) != ERROR_SUCCESS) {
|
||||
srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret);
|
||||
return srs_api_response_code(w, r, ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue