From 310b5a14cb7896af1525977b36a3c0815e363cc1 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 1 Sep 2015 13:33:49 +0800 Subject: [PATCH] for #319, support minimal query api --- trunk/src/app/srs_app_config.cpp | 18 ++++++++++++++++++ trunk/src/app/srs_app_config.hpp | 4 ++++ trunk/src/app/srs_app_http_api.cpp | 12 +++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 76ebe50ab..04aace1b1 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -1468,6 +1468,24 @@ int SrsConfig::persistence() return ret; } +int SrsConfig::minimal_to_json(SrsAmf0Object* obj) +{ + int ret = ERROR_SUCCESS; + + for (int i = 0; i < (int)root->directives.size(); i++) { + SrsConfDirective* dir = root->directives.at(i); + if (dir->is_vhost()) { + continue; + } + + if (dir->name == "listen") { + obj->set(dir->name, dir->dumps_args()); + } + } + + return ret; +} + int SrsConfig::global_to_json(SrsAmf0Object* obj) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 1f066a003..8a6308135 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -321,6 +321,10 @@ public: * dumps the global sections to json. */ virtual int global_to_json(SrsAmf0Object* obj); + /** + * dumps the minimal sections to json. + */ + virtual int minimal_to_json(SrsAmf0Object* obj); /** * dumps the vhost section to json. */ diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 162218e3e..953958c46 100755 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -917,6 +917,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) // for rpc=query, to get the configs of server. // @param scope the scope to query for config, it can be: // global, the configs belongs to the root, donot includes any sub directives. + // minimal, the minimal summary of server, for preview stream to got the port serving. // vhost, the configs for specified vhost by @param vhost. // @param vhost the vhost name for @param scope is vhost to query config. // for the default vhost, must be __defaultVhost__ @@ -929,7 +930,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) std::string scope = r->query_get("scope"); std::string vhost = r->query_get("vhost"); - if (scope.empty() || (scope != "global" && scope != "vhost")) { + if (scope.empty() || (scope != "global" && scope != "vhost" && scope != "minimal")) { 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); @@ -957,6 +958,15 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) srs_error("raw api query vhost failed. ret=%d", ret); return srs_api_response_code(w, r, ret); } + } else if (scope == "minimal") { + SrsAmf0Object* data = SrsAmf0Any::object(); + obj->set("minimal", data); + + // query minimal scope. + if ((ret = _srs_config->minimal_to_json(data)) != ERROR_SUCCESS) { + srs_error("raw api query global failed. ret=%d", ret); + return srs_api_response_code(w, r, ret); + } } else { SrsAmf0Object* data = SrsAmf0Any::object(); obj->set("global", data);