mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #319, support update and delete the disabled vhost
This commit is contained in:
parent
95979674f9
commit
631e76cd32
3 changed files with 110 additions and 21 deletions
|
@ -228,6 +228,14 @@ SrsConfDirective* SrsConfDirective::set_arg0(string a0)
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SrsConfDirective::remove(SrsConfDirective* v)
|
||||||
|
{
|
||||||
|
std::vector<SrsConfDirective*>::iterator it;
|
||||||
|
if ((it = ::find(directives.begin(), directives.end(), v)) != directives.end()) {
|
||||||
|
directives.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool SrsConfDirective::is_vhost()
|
bool SrsConfDirective::is_vhost()
|
||||||
{
|
{
|
||||||
return name == "vhost";
|
return name == "vhost";
|
||||||
|
@ -2472,6 +2480,40 @@ int SrsConfig::raw_create_vhost(string vhost, bool& applied)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SrsConfig::raw_update_vhost(string vhost, string name, bool& applied)
|
||||||
|
{
|
||||||
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
applied = false;
|
||||||
|
|
||||||
|
// the vhost must be disabled, so we donot need to reload.
|
||||||
|
SrsConfDirective* conf = root->get_or_create("vhost", vhost);
|
||||||
|
conf->set_arg0(name);
|
||||||
|
|
||||||
|
applied = true;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SrsConfig::raw_delete_vhost(string vhost, bool& applied)
|
||||||
|
{
|
||||||
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
applied = false;
|
||||||
|
|
||||||
|
// the vhost must be disabled, so we donot need to reload.
|
||||||
|
SrsConfDirective* conf = root->get("vhost", vhost);
|
||||||
|
srs_assert(conf);
|
||||||
|
|
||||||
|
// remove the directive.
|
||||||
|
root->remove(conf);
|
||||||
|
srs_freep(conf);
|
||||||
|
|
||||||
|
applied = true;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int SrsConfig::do_reload_listen()
|
int SrsConfig::do_reload_listen()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
|
@ -131,6 +131,10 @@ public:
|
||||||
virtual SrsConfDirective* get_or_create(std::string n);
|
virtual SrsConfDirective* get_or_create(std::string n);
|
||||||
virtual SrsConfDirective* get_or_create(std::string n, std::string a0);
|
virtual SrsConfDirective* get_or_create(std::string n, std::string a0);
|
||||||
virtual SrsConfDirective* set_arg0(std::string a0);
|
virtual SrsConfDirective* set_arg0(std::string a0);
|
||||||
|
/**
|
||||||
|
* remove the v from sub directives, user must free the v.
|
||||||
|
*/
|
||||||
|
virtual void remove(SrsConfDirective* v);
|
||||||
// help utilities
|
// help utilities
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -378,6 +382,14 @@ public:
|
||||||
* raw create the new vhost.
|
* raw create the new vhost.
|
||||||
*/
|
*/
|
||||||
virtual int raw_create_vhost(std::string vhost, bool& applied);
|
virtual int raw_create_vhost(std::string vhost, bool& applied);
|
||||||
|
/**
|
||||||
|
* raw update the disabled vhost name.
|
||||||
|
*/
|
||||||
|
virtual int raw_update_vhost(std::string vhost, std::string name, bool& applied);
|
||||||
|
/**
|
||||||
|
* raw delete the disabled vhost.
|
||||||
|
*/
|
||||||
|
virtual int raw_delete_vhost(std::string vhost, bool& applied);
|
||||||
private:
|
private:
|
||||||
virtual int do_reload_listen();
|
virtual int do_reload_listen();
|
||||||
virtual int do_reload_pid();
|
virtual int do_reload_pid();
|
||||||
|
|
|
@ -985,6 +985,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
// @scope the scope to update for config.
|
// @scope the scope to update for config.
|
||||||
// @value the updated value for scope.
|
// @value the updated value for scope.
|
||||||
// @param the extra param for scope.
|
// @param the extra param for scope.
|
||||||
|
// @data the extra data for scope.
|
||||||
// possible updates:
|
// possible updates:
|
||||||
// @scope @value value-description
|
// @scope @value value-description
|
||||||
// listen 1935,1936 the port list.
|
// listen 1935,1936 the port list.
|
||||||
|
@ -998,8 +999,9 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
// utc_time false whether enable utc time.
|
// utc_time false whether enable utc time.
|
||||||
// pithy_print_ms 10000 the pithy print interval in ms.
|
// pithy_print_ms 10000 the pithy print interval in ms.
|
||||||
// vhost specified updates:
|
// vhost specified updates:
|
||||||
// @scope @value @param description
|
// @scope @value @param @data description
|
||||||
// vhost ossrs.net create create vhost ossrs.net
|
// vhost ossrs.net create - create vhost ossrs.net
|
||||||
|
// vhost ossrs.net update new.ossrs.net the new name to update vhost
|
||||||
if (rpc == "update") {
|
if (rpc == "update") {
|
||||||
if (!allow_update) {
|
if (!allow_update) {
|
||||||
ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED;
|
ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED;
|
||||||
|
@ -1009,7 +1011,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
|
|
||||||
std::string scope = r->query_get("scope");
|
std::string scope = r->query_get("scope");
|
||||||
std::string value = r->query_get("value");
|
std::string value = r->query_get("value");
|
||||||
std::string param = r->query_get("param");
|
|
||||||
if (scope.empty()) {
|
if (scope.empty()) {
|
||||||
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED;
|
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED;
|
||||||
srs_error("raw api query invalid empty scope. ret=%d", ret);
|
srs_error("raw api query invalid empty scope. ret=%d", ret);
|
||||||
|
@ -1024,13 +1025,9 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret);
|
srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret);
|
||||||
return srs_api_response_code(w, r, ret);
|
return srs_api_response_code(w, r, ret);
|
||||||
}
|
}
|
||||||
if (scope == "vhost" && param != "create") {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool applied = false;
|
bool applied = false;
|
||||||
|
string extra = "";
|
||||||
if (scope == "listen") {
|
if (scope == "listen") {
|
||||||
vector<string> eps = srs_string_split(value, ",");
|
vector<string> eps = srs_string_split(value, ",");
|
||||||
|
|
||||||
|
@ -1156,6 +1153,15 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
return srs_api_response_code(w, r, ret);
|
return srs_api_response_code(w, r, ret);
|
||||||
}
|
}
|
||||||
} else if (scope == "vhost") {
|
} 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") {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
extra += " " + param;
|
||||||
|
|
||||||
if (param == "create") {
|
if (param == "create") {
|
||||||
// when create, the vhost must not exists.
|
// when create, the vhost must not exists.
|
||||||
if (param.empty() || _srs_config->get_vhost(value, false)) {
|
if (param.empty() || _srs_config->get_vhost(value, false)) {
|
||||||
|
@ -1168,15 +1174,44 @@ 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);
|
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);
|
return srs_api_response_code(w, r, ret);
|
||||||
}
|
}
|
||||||
|
} else if (param == "update") {
|
||||||
|
extra += " to " + data;
|
||||||
|
|
||||||
|
// when update, the vhost must exists and disabled.
|
||||||
|
SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
|
||||||
|
if (data.empty() || data == value || 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, data=%s failed. ret=%d", value.c_str(), param.c_str(), data.c_str(), ret);
|
||||||
|
return srs_api_response_code(w, r, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ret = _srs_config->raw_update_vhost(value, data, applied)) != ERROR_SUCCESS) {
|
||||||
|
srs_error("raw api update vhost=%s, param=%s, data=%s failed. ret=%d", value.c_str(), param.c_str(), data.c_str(), ret);
|
||||||
|
return srs_api_response_code(w, r, ret);
|
||||||
|
}
|
||||||
|
} else if (param == "delete") {
|
||||||
|
// when delete, 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_delete_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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// whether the config applied.
|
// whether the config applied.
|
||||||
if (applied) {
|
if (applied) {
|
||||||
server->on_signal(SRS_SIGNAL_PERSISTENCE_CONFIG);
|
server->on_signal(SRS_SIGNAL_PERSISTENCE_CONFIG);
|
||||||
srs_trace("raw api update %s=%s ok.", scope.c_str(), value.c_str());
|
srs_trace("raw api update %s=%s%s ok.", scope.c_str(), value.c_str(), extra.c_str());
|
||||||
} else {
|
} else {
|
||||||
srs_warn("raw api update not applied %s=%s.", scope.c_str(), value.c_str());
|
srs_warn("raw api update not applied %s=%s%s.", scope.c_str(), value.c_str(), extra.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return srs_api_response(w, r, obj->to_json());
|
return srs_api_response(w, r, obj->to_json());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue