diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 461fe6f6b4..9c3b9afee8 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2293,6 +2293,29 @@ int SrsConfig::raw_set_chunk_size(string chunk_size, bool& applied) return ret; } +int SrsConfig::raw_set_ff_log_dir(string ff_log_dir, bool& applied) +{ + int ret = ERROR_SUCCESS; + + applied = false; + + + SrsConfDirective* conf = root->get_or_create("ff_log_dir"); + + if (conf->arg0() == ff_log_dir) { + return ret; + } + + conf->args.clear(); + conf->args.push_back(ff_log_dir); + + // directly supported reload for ff_log_dir change. + + applied = true; + + return ret; +} + int SrsConfig::do_reload_listen() { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 8b716f6b14..d531ef0a83 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -345,6 +345,10 @@ class SrsConfig * raw set the global chunk size. */ virtual int raw_set_chunk_size(std::string chunk_size, bool& applied); + /** + * raw set the global ffmpeg log dir. + */ + virtual int raw_set_ff_log_dir(std::string ff_log_dir, bool& applied); private: virtual int do_reload_listen(); virtual int do_reload_pid(); diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 741d966fca..16a16ddc5c 100755 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -998,7 +998,14 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) std::string scope = r->query_get("scope"); std::string value = r->query_get("value"); - if (scope.empty() || (scope != "listen" && scope != "pid" && scope != "chunk_size")) { + if (scope.empty()) { + ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; + srs_error("raw api query invalid empty scope. ret=%d", ret); + return srs_api_response_code(w, r, ret); + } + if (scope != "listen" && scope != "pid" && scope != "chunk_size" + && scope != "ff_log_dir" + ) { ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret); return srs_api_response_code(w, r, ret); @@ -1028,16 +1035,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) return srs_api_response_code(w, r, ret); } } else if (scope == "pid") { - bool invalid = value.empty(); - if (!invalid) { - invalid = !srs_string_starts_with(value, "./") - && !srs_string_starts_with(value, "/tmp") - && !srs_string_starts_with(value, "/var"); - } - if (!invalid) { - invalid = !srs_string_ends_with(value, ".pid"); - } - if (invalid) { + if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".pid")) { ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; srs_error("raw api update check pid=%s failed. ret=%d", value.c_str(), ret); return srs_api_response_code(w, r, ret); @@ -1059,6 +1057,17 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) srs_error("raw api update chunk_size=%s/%d failed. ret=%d", value.c_str(), csv, ret); return srs_api_response_code(w, r, ret); } + } else if (scope == "ff_log_dir") { + if (value.empty() || (value != "/dev/null" && !srs_string_starts_with(value, "./", "/tmp/", "/var/"))) { + ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; + srs_error("raw api update check ff_log_dir=%s failed. ret=%d", value.c_str(), ret); + return srs_api_response_code(w, r, ret); + } + + if ((ret = _srs_config->raw_set_ff_log_dir(value, applied)) != ERROR_SUCCESS) { + srs_error("raw api update ff_log_dir=%s failed. ret=%d", value.c_str(), ret); + return srs_api_response_code(w, r, ret); + } } // whether the config applied. diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index c341e0c8e0..6db8205d72 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -280,6 +280,21 @@ bool srs_string_starts_with(string str, string flag) return str.find(flag) == 0; } +bool srs_string_starts_with(string str, string flag0, string flag1) +{ + return srs_string_starts_with(str, flag0) || srs_string_starts_with(str, flag1); +} + +bool srs_string_starts_with(string str, string flag0, string flag1, string flag2) +{ + return srs_string_starts_with(str, flag0, flag1) || srs_string_starts_with(str, flag2); +} + +bool srs_string_starts_with(string str, string flag0, string flag1, string flag2, string flag3) +{ + return srs_string_starts_with(str, flag0, flag1, flag2) || srs_string_starts_with(str, flag3); +} + bool srs_string_contains(string str, string flag) { return str.find(flag) != string::npos; diff --git a/trunk/src/kernel/srs_kernel_utility.hpp b/trunk/src/kernel/srs_kernel_utility.hpp index 6688679362..a5c7bfad69 100644 --- a/trunk/src/kernel/srs_kernel_utility.hpp +++ b/trunk/src/kernel/srs_kernel_utility.hpp @@ -68,6 +68,9 @@ extern std::string srs_string_remove(std::string str, std::string remove_chars); extern bool srs_string_ends_with(std::string str, std::string flag); // whether string starts with extern bool srs_string_starts_with(std::string str, std::string flag); +extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1); +extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1, std::string flag2); +extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1, std::string flag2, std::string flag3); // whether string contains with extern bool srs_string_contains(std::string str, std::string flag); // split the string by flag to array.