Skip to content

Commit

Permalink
for #319, raw api support set the ff_log_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Sep 9, 2015
1 parent c8466c3 commit 8107e5f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 11 deletions.
23 changes: 23 additions & 0 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
31 changes: 20 additions & 11 deletions trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions trunk/src/kernel/srs_kernel_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/kernel/srs_kernel_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8107e5f

Please sign in to comment.