From 66ffcad635ab706ac9804b1415c49913a14dedf6 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 28 Aug 2015 13:17:46 +0800 Subject: [PATCH] for #319, always allow raw query. --- trunk/conf/full.conf | 2 +- trunk/src/app/srs_app_config.cpp | 42 +++++++----------------------- trunk/src/app/srs_app_http_api.cpp | 35 +++++++++++++------------ 3 files changed, 29 insertions(+), 50 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 5db2e7586a..2c367e33a6 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -131,7 +131,7 @@ http_api { allow_reload off; # whether enable rpc query. # default: off - allow_query off; + allow_query off; } } # embeded http server in srs. diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 9a375adef7..e3602ac2ed 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -1806,38 +1806,16 @@ int SrsConfig::raw_to_json(SrsAmf0Object* obj) SrsAmf0Object* sobj = SrsAmf0Any::object(); obj->set("http_api", sobj); - for (int i = 0; i < (int)root->directives.size(); i++) { - SrsConfDirective* dir = root->directives.at(i); - - if (dir->name != "http_api") { - continue; - } - - for (int j = 0; j < (int)dir->directives.size(); j++) { - SrsConfDirective* sdir = dir->directives.at(j); - if (sdir->name == "enabled") { - sobj->set(sdir->name, sdir->dumps_arg0_to_boolean()); - } else if (sdir->name == "listen") { - sobj->set(sdir->name, sdir->dumps_arg0_to_str()); - } else if (sdir->name == "crossdomain") { - sobj->set(sdir->name, sdir->dumps_arg0_to_boolean()); - } else if (sdir->name == "raw_api") { - SrsAmf0Object* ssobj = SrsAmf0Any::object(); - sobj->set(sdir->name, ssobj); - - for (int k = 0; k < (int)sdir->directives.size(); k++) { - SrsConfDirective* ssdir = sdir->directives.at(k); - if (ssdir->name == "enabled") { - ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean()); - } else if (ssdir->name == "allow_reload") { - ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean()); - } else if (ssdir->name == "allow_query") { - ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean()); - } - } - } - } - } + sobj->set("enabled", SrsAmf0Any::boolean(get_http_api_enabled())); + sobj->set("listen", SrsAmf0Any::str(get_http_api_listen().c_str())); + sobj->set("crossdomain", SrsAmf0Any::boolean(get_http_api_crossdomain())); + + SrsAmf0Object* ssobj = SrsAmf0Any::object(); + sobj->set("raw_api", ssobj); + + ssobj->set("enabled", SrsAmf0Any::boolean(get_raw_api())); + ssobj->set("allow_reload", SrsAmf0Any::boolean(get_raw_api_allow_reload())); + ssobj->set("allow_query", SrsAmf0Any::boolean(get_raw_api_allow_query())); return ret; } diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index f42813eeaa..c85ef2847b 100755 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -859,6 +859,24 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) { int ret = ERROR_SUCCESS; + std::string rpc = r->query_get("rpc"); + + // the object to return for request. + SrsAmf0Object* obj = SrsAmf0Any::object(); + SrsAutoFree(SrsAmf0Object, obj); + obj->set("code", SrsAmf0Any::number(ERROR_SUCCESS)); + + // for rpc=raw, to query the raw api config for http api. + if (rpc == "raw") { + // query global scope. + if ((ret = _srs_config->raw_to_json(obj)) != ERROR_SUCCESS) { + srs_error("raw api rpc raw failed. ret=%d", ret); + return srs_api_response_code(w, r, ret); + } + + return srs_api_response(w, r, obj->to_json()); + } + // whether enabled the HTTP RAW API. if (!raw_api) { ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; @@ -867,7 +885,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) } // the rpc is required. - std::string rpc = r->query_get("rpc"); if (rpc.empty() || (rpc != "reload" && rpc != "query" && rpc != "raw")) { ret = ERROR_SYSTEM_CONFIG_RAW; srs_error("raw api invalid rpc=%s. ret=%d", rpc.c_str(), ret); @@ -886,22 +903,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) server->on_signal(SRS_SIGNAL_RELOAD); return srs_api_response_code(w, r, ret); } - - // the object to return for request. - SrsAmf0Object* obj = SrsAmf0Any::object(); - SrsAutoFree(SrsAmf0Object, obj); - obj->set("code", SrsAmf0Any::number(ERROR_SUCCESS)); - - // for rpc=raw, to query the raw api config for http api. - if (rpc == "raw") { - // query global scope. - if ((ret = _srs_config->raw_to_json(obj)) != ERROR_SUCCESS) { - srs_error("raw api rpc raw failed. ret=%d", ret); - return srs_api_response_code(w, r, ret); - } - - return srs_api_response(w, r, obj->to_json()); - } // for rpc=query, to get the configs of server. // @param scope the scope to query for config, it can be: