Skip to content

Commit

Permalink
for #319, always allow raw query.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 28, 2015
1 parent f167616 commit 66ffcad
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 50 deletions.
2 changes: 1 addition & 1 deletion trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 10 additions & 32 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
35 changes: 18 additions & 17 deletions trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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:
Expand Down

0 comments on commit 66ffcad

Please sign in to comment.