diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index a802576bc1..aa931908e7 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -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); - return 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::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; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index ad3a9f9731..dcfb5a766b 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -390,6 +390,14 @@ class SrsConfig * 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 @@ class SrsConfig 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. diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index d23056e566..ce2ce52455 100755 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -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); + } } }