正在显示
5 个修改的文件
包含
65 行增加
和
11 行删除
| @@ -2293,6 +2293,29 @@ int SrsConfig::raw_set_chunk_size(string chunk_size, bool& applied) | @@ -2293,6 +2293,29 @@ int SrsConfig::raw_set_chunk_size(string chunk_size, bool& applied) | ||
| 2293 | return ret; | 2293 | return ret; |
| 2294 | } | 2294 | } |
| 2295 | 2295 | ||
| 2296 | +int SrsConfig::raw_set_ff_log_dir(string ff_log_dir, bool& applied) | ||
| 2297 | +{ | ||
| 2298 | + int ret = ERROR_SUCCESS; | ||
| 2299 | + | ||
| 2300 | + applied = false; | ||
| 2301 | + | ||
| 2302 | + | ||
| 2303 | + SrsConfDirective* conf = root->get_or_create("ff_log_dir"); | ||
| 2304 | + | ||
| 2305 | + if (conf->arg0() == ff_log_dir) { | ||
| 2306 | + return ret; | ||
| 2307 | + } | ||
| 2308 | + | ||
| 2309 | + conf->args.clear(); | ||
| 2310 | + conf->args.push_back(ff_log_dir); | ||
| 2311 | + | ||
| 2312 | + // directly supported reload for ff_log_dir change. | ||
| 2313 | + | ||
| 2314 | + applied = true; | ||
| 2315 | + | ||
| 2316 | + return ret; | ||
| 2317 | +} | ||
| 2318 | + | ||
| 2296 | int SrsConfig::do_reload_listen() | 2319 | int SrsConfig::do_reload_listen() |
| 2297 | { | 2320 | { |
| 2298 | int ret = ERROR_SUCCESS; | 2321 | int ret = ERROR_SUCCESS; |
| @@ -345,6 +345,10 @@ public: | @@ -345,6 +345,10 @@ public: | ||
| 345 | * raw set the global chunk size. | 345 | * raw set the global chunk size. |
| 346 | */ | 346 | */ |
| 347 | virtual int raw_set_chunk_size(std::string chunk_size, bool& applied); | 347 | virtual int raw_set_chunk_size(std::string chunk_size, bool& applied); |
| 348 | + /** | ||
| 349 | + * raw set the global ffmpeg log dir. | ||
| 350 | + */ | ||
| 351 | + virtual int raw_set_ff_log_dir(std::string ff_log_dir, bool& applied); | ||
| 348 | private: | 352 | private: |
| 349 | virtual int do_reload_listen(); | 353 | virtual int do_reload_listen(); |
| 350 | virtual int do_reload_pid(); | 354 | virtual int do_reload_pid(); |
| @@ -998,7 +998,14 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -998,7 +998,14 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 998 | 998 | ||
| 999 | std::string scope = r->query_get("scope"); | 999 | std::string scope = r->query_get("scope"); |
| 1000 | std::string value = r->query_get("value"); | 1000 | std::string value = r->query_get("value"); |
| 1001 | - if (scope.empty() || (scope != "listen" && scope != "pid" && scope != "chunk_size")) { | 1001 | + if (scope.empty()) { |
| 1002 | + ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; | ||
| 1003 | + srs_error("raw api query invalid empty scope. ret=%d", ret); | ||
| 1004 | + return srs_api_response_code(w, r, ret); | ||
| 1005 | + } | ||
| 1006 | + if (scope != "listen" && scope != "pid" && scope != "chunk_size" | ||
| 1007 | + && scope != "ff_log_dir" | ||
| 1008 | + ) { | ||
| 1002 | ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; | 1009 | ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; |
| 1003 | srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret); | 1010 | srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret); |
| 1004 | return srs_api_response_code(w, r, ret); | 1011 | return srs_api_response_code(w, r, ret); |
| @@ -1028,16 +1035,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -1028,16 +1035,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 1028 | return srs_api_response_code(w, r, ret); | 1035 | return srs_api_response_code(w, r, ret); |
| 1029 | } | 1036 | } |
| 1030 | } else if (scope == "pid") { | 1037 | } else if (scope == "pid") { |
| 1031 | - bool invalid = value.empty(); | ||
| 1032 | - if (!invalid) { | ||
| 1033 | - invalid = !srs_string_starts_with(value, "./") | ||
| 1034 | - && !srs_string_starts_with(value, "/tmp") | ||
| 1035 | - && !srs_string_starts_with(value, "/var"); | ||
| 1036 | - } | ||
| 1037 | - if (!invalid) { | ||
| 1038 | - invalid = !srs_string_ends_with(value, ".pid"); | ||
| 1039 | - } | ||
| 1040 | - if (invalid) { | 1038 | + if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".pid")) { |
| 1041 | ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; | 1039 | ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; |
| 1042 | srs_error("raw api update check pid=%s failed. ret=%d", value.c_str(), ret); | 1040 | srs_error("raw api update check pid=%s failed. ret=%d", value.c_str(), ret); |
| 1043 | return srs_api_response_code(w, r, ret); | 1041 | return srs_api_response_code(w, r, ret); |
| @@ -1059,6 +1057,17 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -1059,6 +1057,17 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 1059 | srs_error("raw api update chunk_size=%s/%d failed. ret=%d", value.c_str(), csv, ret); | 1057 | srs_error("raw api update chunk_size=%s/%d failed. ret=%d", value.c_str(), csv, ret); |
| 1060 | return srs_api_response_code(w, r, ret); | 1058 | return srs_api_response_code(w, r, ret); |
| 1061 | } | 1059 | } |
| 1060 | + } else if (scope == "ff_log_dir") { | ||
| 1061 | + if (value.empty() || (value != "/dev/null" && !srs_string_starts_with(value, "./", "/tmp/", "/var/"))) { | ||
| 1062 | + ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; | ||
| 1063 | + srs_error("raw api update check ff_log_dir=%s failed. ret=%d", value.c_str(), ret); | ||
| 1064 | + return srs_api_response_code(w, r, ret); | ||
| 1065 | + } | ||
| 1066 | + | ||
| 1067 | + if ((ret = _srs_config->raw_set_ff_log_dir(value, applied)) != ERROR_SUCCESS) { | ||
| 1068 | + srs_error("raw api update ff_log_dir=%s failed. ret=%d", value.c_str(), ret); | ||
| 1069 | + return srs_api_response_code(w, r, ret); | ||
| 1070 | + } | ||
| 1062 | } | 1071 | } |
| 1063 | 1072 | ||
| 1064 | // whether the config applied. | 1073 | // whether the config applied. |
| @@ -280,6 +280,21 @@ bool srs_string_starts_with(string str, string flag) | @@ -280,6 +280,21 @@ bool srs_string_starts_with(string str, string flag) | ||
| 280 | return str.find(flag) == 0; | 280 | return str.find(flag) == 0; |
| 281 | } | 281 | } |
| 282 | 282 | ||
| 283 | +bool srs_string_starts_with(string str, string flag0, string flag1) | ||
| 284 | +{ | ||
| 285 | + return srs_string_starts_with(str, flag0) || srs_string_starts_with(str, flag1); | ||
| 286 | +} | ||
| 287 | + | ||
| 288 | +bool srs_string_starts_with(string str, string flag0, string flag1, string flag2) | ||
| 289 | +{ | ||
| 290 | + return srs_string_starts_with(str, flag0, flag1) || srs_string_starts_with(str, flag2); | ||
| 291 | +} | ||
| 292 | + | ||
| 293 | +bool srs_string_starts_with(string str, string flag0, string flag1, string flag2, string flag3) | ||
| 294 | +{ | ||
| 295 | + return srs_string_starts_with(str, flag0, flag1, flag2) || srs_string_starts_with(str, flag3); | ||
| 296 | +} | ||
| 297 | + | ||
| 283 | bool srs_string_contains(string str, string flag) | 298 | bool srs_string_contains(string str, string flag) |
| 284 | { | 299 | { |
| 285 | return str.find(flag) != string::npos; | 300 | return str.find(flag) != string::npos; |
| @@ -68,6 +68,9 @@ extern std::string srs_string_remove(std::string str, std::string remove_chars); | @@ -68,6 +68,9 @@ extern std::string srs_string_remove(std::string str, std::string remove_chars); | ||
| 68 | extern bool srs_string_ends_with(std::string str, std::string flag); | 68 | extern bool srs_string_ends_with(std::string str, std::string flag); |
| 69 | // whether string starts with | 69 | // whether string starts with |
| 70 | extern bool srs_string_starts_with(std::string str, std::string flag); | 70 | extern bool srs_string_starts_with(std::string str, std::string flag); |
| 71 | +extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1); | ||
| 72 | +extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1, std::string flag2); | ||
| 73 | +extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1, std::string flag2, std::string flag3); | ||
| 71 | // whether string contains with | 74 | // whether string contains with |
| 72 | extern bool srs_string_contains(std::string str, std::string flag); | 75 | extern bool srs_string_contains(std::string str, std::string flag); |
| 73 | // split the string by flag to array. | 76 | // split the string by flag to array. |
-
请 注册 或 登录 后发表评论