mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
for #319, support minimal query api
This commit is contained in:
parent
06c7ae62ee
commit
310b5a14cb
3 changed files with 33 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue