mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
for #319, raw api support set the ff_log_dir
This commit is contained in:
parent
c8466c36bd
commit
8107e5f9a6
5 changed files with 65 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -345,6 +345,10 @@ public:
|
|||
* 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();
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue