正在显示
3 个修改的文件
包含
29 行增加
和
50 行删除
| @@ -131,7 +131,7 @@ http_api { | @@ -131,7 +131,7 @@ http_api { | ||
| 131 | allow_reload off; | 131 | allow_reload off; |
| 132 | # whether enable rpc query. | 132 | # whether enable rpc query. |
| 133 | # default: off | 133 | # default: off |
| 134 | - allow_query off; | 134 | + allow_query off; |
| 135 | } | 135 | } |
| 136 | } | 136 | } |
| 137 | # embeded http server in srs. | 137 | # embeded http server in srs. |
| @@ -1806,38 +1806,16 @@ int SrsConfig::raw_to_json(SrsAmf0Object* obj) | @@ -1806,38 +1806,16 @@ int SrsConfig::raw_to_json(SrsAmf0Object* obj) | ||
| 1806 | SrsAmf0Object* sobj = SrsAmf0Any::object(); | 1806 | SrsAmf0Object* sobj = SrsAmf0Any::object(); |
| 1807 | obj->set("http_api", sobj); | 1807 | obj->set("http_api", sobj); |
| 1808 | 1808 | ||
| 1809 | - for (int i = 0; i < (int)root->directives.size(); i++) { | ||
| 1810 | - SrsConfDirective* dir = root->directives.at(i); | ||
| 1811 | - | ||
| 1812 | - if (dir->name != "http_api") { | ||
| 1813 | - continue; | ||
| 1814 | - } | ||
| 1815 | - | ||
| 1816 | - for (int j = 0; j < (int)dir->directives.size(); j++) { | ||
| 1817 | - SrsConfDirective* sdir = dir->directives.at(j); | ||
| 1818 | - if (sdir->name == "enabled") { | ||
| 1819 | - sobj->set(sdir->name, sdir->dumps_arg0_to_boolean()); | ||
| 1820 | - } else if (sdir->name == "listen") { | ||
| 1821 | - sobj->set(sdir->name, sdir->dumps_arg0_to_str()); | ||
| 1822 | - } else if (sdir->name == "crossdomain") { | ||
| 1823 | - sobj->set(sdir->name, sdir->dumps_arg0_to_boolean()); | ||
| 1824 | - } else if (sdir->name == "raw_api") { | ||
| 1825 | - SrsAmf0Object* ssobj = SrsAmf0Any::object(); | ||
| 1826 | - sobj->set(sdir->name, ssobj); | ||
| 1827 | - | ||
| 1828 | - for (int k = 0; k < (int)sdir->directives.size(); k++) { | ||
| 1829 | - SrsConfDirective* ssdir = sdir->directives.at(k); | ||
| 1830 | - if (ssdir->name == "enabled") { | ||
| 1831 | - ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean()); | ||
| 1832 | - } else if (ssdir->name == "allow_reload") { | ||
| 1833 | - ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean()); | ||
| 1834 | - } else if (ssdir->name == "allow_query") { | ||
| 1835 | - ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean()); | ||
| 1836 | - } | ||
| 1837 | - } | ||
| 1838 | - } | ||
| 1839 | - } | ||
| 1840 | - } | 1809 | + sobj->set("enabled", SrsAmf0Any::boolean(get_http_api_enabled())); |
| 1810 | + sobj->set("listen", SrsAmf0Any::str(get_http_api_listen().c_str())); | ||
| 1811 | + sobj->set("crossdomain", SrsAmf0Any::boolean(get_http_api_crossdomain())); | ||
| 1812 | + | ||
| 1813 | + SrsAmf0Object* ssobj = SrsAmf0Any::object(); | ||
| 1814 | + sobj->set("raw_api", ssobj); | ||
| 1815 | + | ||
| 1816 | + ssobj->set("enabled", SrsAmf0Any::boolean(get_raw_api())); | ||
| 1817 | + ssobj->set("allow_reload", SrsAmf0Any::boolean(get_raw_api_allow_reload())); | ||
| 1818 | + ssobj->set("allow_query", SrsAmf0Any::boolean(get_raw_api_allow_query())); | ||
| 1841 | 1819 | ||
| 1842 | return ret; | 1820 | return ret; |
| 1843 | } | 1821 | } |
| @@ -859,6 +859,24 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -859,6 +859,24 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 859 | { | 859 | { |
| 860 | int ret = ERROR_SUCCESS; | 860 | int ret = ERROR_SUCCESS; |
| 861 | 861 | ||
| 862 | + std::string rpc = r->query_get("rpc"); | ||
| 863 | + | ||
| 864 | + // the object to return for request. | ||
| 865 | + SrsAmf0Object* obj = SrsAmf0Any::object(); | ||
| 866 | + SrsAutoFree(SrsAmf0Object, obj); | ||
| 867 | + obj->set("code", SrsAmf0Any::number(ERROR_SUCCESS)); | ||
| 868 | + | ||
| 869 | + // for rpc=raw, to query the raw api config for http api. | ||
| 870 | + if (rpc == "raw") { | ||
| 871 | + // query global scope. | ||
| 872 | + if ((ret = _srs_config->raw_to_json(obj)) != ERROR_SUCCESS) { | ||
| 873 | + srs_error("raw api rpc raw failed. ret=%d", ret); | ||
| 874 | + return srs_api_response_code(w, r, ret); | ||
| 875 | + } | ||
| 876 | + | ||
| 877 | + return srs_api_response(w, r, obj->to_json()); | ||
| 878 | + } | ||
| 879 | + | ||
| 862 | // whether enabled the HTTP RAW API. | 880 | // whether enabled the HTTP RAW API. |
| 863 | if (!raw_api) { | 881 | if (!raw_api) { |
| 864 | ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; | 882 | ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; |
| @@ -867,7 +885,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -867,7 +885,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 867 | } | 885 | } |
| 868 | 886 | ||
| 869 | // the rpc is required. | 887 | // the rpc is required. |
| 870 | - std::string rpc = r->query_get("rpc"); | ||
| 871 | if (rpc.empty() || (rpc != "reload" && rpc != "query" && rpc != "raw")) { | 888 | if (rpc.empty() || (rpc != "reload" && rpc != "query" && rpc != "raw")) { |
| 872 | ret = ERROR_SYSTEM_CONFIG_RAW; | 889 | ret = ERROR_SYSTEM_CONFIG_RAW; |
| 873 | srs_error("raw api invalid rpc=%s. ret=%d", rpc.c_str(), ret); | 890 | 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) | @@ -886,22 +903,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 886 | server->on_signal(SRS_SIGNAL_RELOAD); | 903 | server->on_signal(SRS_SIGNAL_RELOAD); |
| 887 | return srs_api_response_code(w, r, ret); | 904 | return srs_api_response_code(w, r, ret); |
| 888 | } | 905 | } |
| 889 | - | ||
| 890 | - // the object to return for request. | ||
| 891 | - SrsAmf0Object* obj = SrsAmf0Any::object(); | ||
| 892 | - SrsAutoFree(SrsAmf0Object, obj); | ||
| 893 | - obj->set("code", SrsAmf0Any::number(ERROR_SUCCESS)); | ||
| 894 | - | ||
| 895 | - // for rpc=raw, to query the raw api config for http api. | ||
| 896 | - if (rpc == "raw") { | ||
| 897 | - // query global scope. | ||
| 898 | - if ((ret = _srs_config->raw_to_json(obj)) != ERROR_SUCCESS) { | ||
| 899 | - srs_error("raw api rpc raw failed. ret=%d", ret); | ||
| 900 | - return srs_api_response_code(w, r, ret); | ||
| 901 | - } | ||
| 902 | - | ||
| 903 | - return srs_api_response(w, r, obj->to_json()); | ||
| 904 | - } | ||
| 905 | 906 | ||
| 906 | // for rpc=query, to get the configs of server. | 907 | // for rpc=query, to get the configs of server. |
| 907 | // @param scope the scope to query for config, it can be: | 908 | // @param scope the scope to query for config, it can be: |
-
请 注册 或 登录 后发表评论