winlin

for #319, support rpc raw api to query the HTTP RAW API configs.

@@ -121,10 +121,18 @@ http_api { @@ -121,10 +121,18 @@ http_api {
121 # whether enable crossdomain request. 121 # whether enable crossdomain request.
122 # default: on 122 # default: on
123 crossdomain on; 123 crossdomain on;
124 - # whether enable the HTTP RAW API,  
125 - # which is more powerful api to change srs state and reload.  
126 - # default: off  
127 - raw_api off; 124 + # the HTTP RAW API is more powerful api to change srs state and reload.
  125 + raw_api {
  126 + # whether enable the HTTP RAW API.
  127 + # default: off
  128 + enabled off;
  129 + # whether enable rpc reload.
  130 + # default: off
  131 + allow_reload off;
  132 + # whether enable rpc config_query.
  133 + # default: off
  134 + allow_config_query off;
  135 + }
128 } 136 }
129 # embeded http server in srs. 137 # embeded http server in srs.
130 # the http streaming config, for HLS/HDS/DASH/HTTPProgressive 138 # the http streaming config, for HLS/HDS/DASH/HTTPProgressive
@@ -1143,9 +1143,6 @@ int SrsConfig::reload_http_api(SrsConfDirective* old_root) @@ -1143,9 +1143,6 @@ int SrsConfig::reload_http_api(SrsConfDirective* old_root)
1143 { 1143 {
1144 int ret = ERROR_SUCCESS; 1144 int ret = ERROR_SUCCESS;
1145 1145
1146 - // always support reload without additional code:  
1147 - // crossdomain, raw_api  
1148 -  
1149 // merge config. 1146 // merge config.
1150 std::vector<ISrsReloadHandler*>::iterator it; 1147 std::vector<ISrsReloadHandler*>::iterator it;
1151 1148
@@ -1199,6 +1196,24 @@ int SrsConfig::reload_http_api(SrsConfDirective* old_root) @@ -1199,6 +1196,24 @@ int SrsConfig::reload_http_api(SrsConfDirective* old_root)
1199 } 1196 }
1200 srs_trace("reload enabled modified http_api success."); 1197 srs_trace("reload enabled modified http_api success.");
1201 1198
  1199 + if (!srs_directive_equals(old_http_api->get("crossdomain"), new_http_api->get("crossdomain"))) {
  1200 + ISrsReloadHandler* subscribe = *it;
  1201 + if ((ret = subscribe->on_reload_http_api_crossdomain()) != ERROR_SUCCESS) {
  1202 + srs_error("notify subscribes http_api crossdomain modified failed. ret=%d", ret);
  1203 + return ret;
  1204 + }
  1205 + }
  1206 + srs_trace("reload crossdomain modified http_api success.");
  1207 +
  1208 + if (!srs_directive_equals(old_http_api->get("raw_api"), new_http_api->get("raw_api"))) {
  1209 + ISrsReloadHandler* subscribe = *it;
  1210 + if ((ret = subscribe->on_reload_http_api_raw_api()) != ERROR_SUCCESS) {
  1211 + srs_error("notify subscribes http_api raw_api modified failed. ret=%d", ret);
  1212 + return ret;
  1213 + }
  1214 + }
  1215 + srs_trace("reload raw_api modified http_api success.");
  1216 +
1202 return ret; 1217 return ret;
1203 } 1218 }
1204 1219
@@ -1645,7 +1660,7 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj) @@ -1645,7 +1660,7 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj)
1645 } else if (sdir->name == "crossdomain") { 1660 } else if (sdir->name == "crossdomain") {
1646 sobj->set(sdir->name, sdir->dumps_arg0_to_boolean()); 1661 sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
1647 } else if (sdir->name == "raw_api") { 1662 } else if (sdir->name == "raw_api") {
1648 - sobj->set(sdir->name, sdir->dumps_arg0_to_boolean()); 1663 + sobj->set(sdir->name, SrsAmf0Any::boolean(get_raw_api()));
1649 } 1664 }
1650 } 1665 }
1651 obj->set(dir->name, sobj); 1666 obj->set(dir->name, sobj);
@@ -1780,6 +1795,49 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) @@ -1780,6 +1795,49 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
1780 return ret; 1795 return ret;
1781 } 1796 }
1782 1797
  1798 +int SrsConfig::raw_to_json(SrsAmf0Object* obj)
  1799 +{
  1800 + int ret = ERROR_SUCCESS;
  1801 +
  1802 + SrsAmf0Object* sobj = SrsAmf0Any::object();
  1803 + obj->set("http_api", sobj);
  1804 +
  1805 + for (int i = 0; i < (int)root->directives.size(); i++) {
  1806 + SrsConfDirective* dir = root->directives.at(i);
  1807 +
  1808 + if (dir->name != "http_api") {
  1809 + continue;
  1810 + }
  1811 +
  1812 + for (int j = 0; j < (int)dir->directives.size(); j++) {
  1813 + SrsConfDirective* sdir = dir->directives.at(j);
  1814 + if (sdir->name == "enabled") {
  1815 + sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
  1816 + } else if (sdir->name == "listen") {
  1817 + sobj->set(sdir->name, sdir->dumps_arg0_to_str());
  1818 + } else if (sdir->name == "crossdomain") {
  1819 + sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
  1820 + } else if (sdir->name == "raw_api") {
  1821 + SrsAmf0Object* ssobj = SrsAmf0Any::object();
  1822 + sobj->set(sdir->name, ssobj);
  1823 +
  1824 + for (int k = 0; k < (int)sdir->directives.size(); k++) {
  1825 + SrsConfDirective* ssdir = sdir->directives.at(k);
  1826 + if (ssdir->name == "enabled") {
  1827 + ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean());
  1828 + } else if (ssdir->name == "allow_reload") {
  1829 + ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean());
  1830 + } else if (ssdir->name == "allow_config_query") {
  1831 + ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean());
  1832 + }
  1833 + }
  1834 + }
  1835 + }
  1836 + }
  1837 +
  1838 + return ret;
  1839 +}
  1840 +
1783 string SrsConfig::config() 1841 string SrsConfig::config()
1784 { 1842 {
1785 return config_file; 1843 return config_file;
@@ -1946,12 +2004,24 @@ int SrsConfig::check_config() @@ -1946,12 +2004,24 @@ int SrsConfig::check_config()
1946 if (true) { 2004 if (true) {
1947 SrsConfDirective* conf = get_http_api(); 2005 SrsConfDirective* conf = get_http_api();
1948 for (int i = 0; conf && i < (int)conf->directives.size(); i++) { 2006 for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
1949 - string n = conf->at(i)->name; 2007 + SrsConfDirective* obj = conf->at(i);
  2008 + string n = obj->name;
1950 if (n != "enabled" && n != "listen" && n != "crossdomain" && n != "raw_api") { 2009 if (n != "enabled" && n != "listen" && n != "crossdomain" && n != "raw_api") {
1951 ret = ERROR_SYSTEM_CONFIG_INVALID; 2010 ret = ERROR_SYSTEM_CONFIG_INVALID;
1952 srs_error("unsupported http_api directive %s, ret=%d", n.c_str(), ret); 2011 srs_error("unsupported http_api directive %s, ret=%d", n.c_str(), ret);
1953 return ret; 2012 return ret;
1954 } 2013 }
  2014 +
  2015 + if (n == "raw_api") {
  2016 + for (int j = 0; j < (int)obj->directives.size(); j++) {
  2017 + string m = obj->at(j)->name;
  2018 + if (m != "enabled" && m != "allow_reload" && m != "allow_config_query") {
  2019 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  2020 + srs_error("unsupported http_api.raw_api directive %s, ret=%d", m.c_str(), ret);
  2021 + return ret;
  2022 + }
  2023 + }
  2024 + }
1955 } 2025 }
1956 } 2026 }
1957 if (true) { 2027 if (true) {
@@ -4529,7 +4599,29 @@ bool SrsConfig::get_http_api_crossdomain() @@ -4529,7 +4599,29 @@ bool SrsConfig::get_http_api_crossdomain()
4529 return SRS_CONF_PERFER_TRUE(conf->arg0()); 4599 return SRS_CONF_PERFER_TRUE(conf->arg0());
4530 } 4600 }
4531 4601
4532 -bool SrsConfig::get_http_api_raw_api() 4602 +bool SrsConfig::get_raw_api()
  4603 +{
  4604 + static bool DEFAULT = false;
  4605 +
  4606 + SrsConfDirective* conf = get_http_api();
  4607 + if (!conf) {
  4608 + return DEFAULT;
  4609 + }
  4610 +
  4611 + conf = conf->get("raw_api");
  4612 + if (!conf) {
  4613 + return DEFAULT;
  4614 + }
  4615 +
  4616 + conf = conf->get("enabled");
  4617 + if (!conf || conf->arg0().empty()) {
  4618 + return DEFAULT;
  4619 + }
  4620 +
  4621 + return SRS_CONF_PERFER_FALSE(conf->arg0());
  4622 +}
  4623 +
  4624 +bool SrsConfig::get_raw_api_allow_reload()
4533 { 4625 {
4534 static bool DEFAULT = false; 4626 static bool DEFAULT = false;
4535 4627
@@ -4539,6 +4631,33 @@ bool SrsConfig::get_http_api_raw_api() @@ -4539,6 +4631,33 @@ bool SrsConfig::get_http_api_raw_api()
4539 } 4631 }
4540 4632
4541 conf = conf->get("raw_api"); 4633 conf = conf->get("raw_api");
  4634 + if (!conf) {
  4635 + return DEFAULT;
  4636 + }
  4637 +
  4638 + conf = conf->get("allow_reload");
  4639 + if (!conf || conf->arg0().empty()) {
  4640 + return DEFAULT;
  4641 + }
  4642 +
  4643 + return SRS_CONF_PERFER_FALSE(conf->arg0());
  4644 +}
  4645 +
  4646 +bool SrsConfig::get_raw_api_allow_config_query()
  4647 +{
  4648 + static bool DEFAULT = false;
  4649 +
  4650 + SrsConfDirective* conf = get_http_api();
  4651 + if (!conf) {
  4652 + return DEFAULT;
  4653 + }
  4654 +
  4655 + conf = conf->get("raw_api");
  4656 + if (!conf) {
  4657 + return DEFAULT;
  4658 + }
  4659 +
  4660 + conf = conf->get("allow_config_query");
4542 if (!conf || conf->arg0().empty()) { 4661 if (!conf || conf->arg0().empty()) {
4543 return DEFAULT; 4662 return DEFAULT;
4544 } 4663 }
@@ -321,6 +321,10 @@ public: @@ -321,6 +321,10 @@ public:
321 */ 321 */
322 virtual int vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj); 322 virtual int vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj);
323 /** 323 /**
  324 + * dumps the http_api sections to json for raw api info.
  325 + */
  326 + virtual int raw_to_json(SrsAmf0Object* obj);
  327 + /**
324 * get the config file path. 328 * get the config file path.
325 */ 329 */
326 virtual std::string config(); 330 virtual std::string config();
@@ -1061,7 +1065,15 @@ public: @@ -1061,7 +1065,15 @@ public:
1061 /** 1065 /**
1062 * whether enable the HTTP RAW API. 1066 * whether enable the HTTP RAW API.
1063 */ 1067 */
1064 - virtual bool get_http_api_raw_api(); 1068 + virtual bool get_raw_api();
  1069 + /**
  1070 + * whether allow rpc reload.
  1071 + */
  1072 + virtual bool get_raw_api_allow_reload();
  1073 + /**
  1074 + * whether allow rpc config_query.
  1075 + */
  1076 + virtual bool get_raw_api_allow_config_query();
1065 // http stream section 1077 // http stream section
1066 private: 1078 private:
1067 /** 1079 /**
@@ -842,10 +842,17 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -842,10 +842,17 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
842 SrsGoApiRaw::SrsGoApiRaw(SrsServer* svr) 842 SrsGoApiRaw::SrsGoApiRaw(SrsServer* svr)
843 { 843 {
844 server = svr; 844 server = svr;
  845 +
  846 + raw_api = _srs_config->get_raw_api();
  847 + allow_reload = _srs_config->get_raw_api_allow_reload();
  848 + allow_config_query = _srs_config->get_raw_api_allow_config_query();
  849 +
  850 + _srs_config->subscribe(this);
845 } 851 }
846 852
847 SrsGoApiRaw::~SrsGoApiRaw() 853 SrsGoApiRaw::~SrsGoApiRaw()
848 { 854 {
  855 + _srs_config->unsubscribe(this);
849 } 856 }
850 857
851 int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) 858 int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
@@ -853,7 +860,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -853,7 +860,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
853 int ret = ERROR_SUCCESS; 860 int ret = ERROR_SUCCESS;
854 861
855 // whether enabled the HTTP RAW API. 862 // whether enabled the HTTP RAW API.
856 - if (!_srs_config->get_http_api_raw_api()) { 863 + if (!raw_api) {
857 ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; 864 ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED;
858 srs_warn("raw api disabled. ret=%d", ret); 865 srs_warn("raw api disabled. ret=%d", ret);
859 return srs_api_response_code(w, r, ret); 866 return srs_api_response_code(w, r, ret);
@@ -861,7 +868,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -861,7 +868,7 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
861 868
862 // the rpc is required. 869 // the rpc is required.
863 std::string rpc = r->query_get("rpc"); 870 std::string rpc = r->query_get("rpc");
864 - if (rpc.empty() || (rpc != "reload" && rpc != "config_query")) { 871 + if (rpc.empty() || (rpc != "reload" && rpc != "config_query" && rpc != "raw")) {
865 ret = ERROR_SYSTEM_CONFIG_RAW; 872 ret = ERROR_SYSTEM_CONFIG_RAW;
866 srs_error("raw api invalid rpc=%s. ret=%d", rpc.c_str(), ret); 873 srs_error("raw api invalid rpc=%s. ret=%d", rpc.c_str(), ret);
867 return srs_api_response_code(w, r, ret); 874 return srs_api_response_code(w, r, ret);
@@ -869,11 +876,33 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -869,11 +876,33 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
869 876
870 // for rpc=reload, trigger the server to reload the config. 877 // for rpc=reload, trigger the server to reload the config.
871 if (rpc == "reload") { 878 if (rpc == "reload") {
  879 + if (!allow_reload) {
  880 + ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED;
  881 + srs_error("raw api reload disabled rpc=%s. ret=%d", rpc.c_str(), ret);
  882 + return srs_api_response_code(w, r, ret);
  883 + }
  884 +
872 srs_trace("raw api trigger reload. ret=%d", ret); 885 srs_trace("raw api trigger reload. ret=%d", ret);
873 server->on_signal(SRS_SIGNAL_RELOAD); 886 server->on_signal(SRS_SIGNAL_RELOAD);
874 return srs_api_response_code(w, r, ret); 887 return srs_api_response_code(w, r, ret);
875 } 888 }
876 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 +
877 // for rpc=config_query, to get the configs of server. 906 // for rpc=config_query, to get the configs of server.
878 // @param scope the scope to query for config, it can be: 907 // @param scope the scope to query for config, it can be:
879 // global, the configs belongs to the root, donot includes any sub directives. 908 // global, the configs belongs to the root, donot includes any sub directives.
@@ -881,6 +910,12 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -881,6 +910,12 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
881 // @param vhost the vhost name for @param scope is vhost to query config. 910 // @param vhost the vhost name for @param scope is vhost to query config.
882 // for the default vhost, must be __defaultVhost__ 911 // for the default vhost, must be __defaultVhost__
883 if (rpc == "config_query") { 912 if (rpc == "config_query") {
  913 + if (!allow_config_query) {
  914 + ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED;
  915 + srs_error("raw api allow_config_query disabled rpc=%s. ret=%d", rpc.c_str(), ret);
  916 + return srs_api_response_code(w, r, ret);
  917 + }
  918 +
884 std::string scope = r->query_get("scope"); 919 std::string scope = r->query_get("scope");
885 std::string vhost = r->query_get("vhost"); 920 std::string vhost = r->query_get("vhost");
886 if (scope.empty() || (scope != "global" && scope != "vhost")) { 921 if (scope.empty() || (scope != "global" && scope != "vhost")) {
@@ -889,12 +924,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -889,12 +924,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
889 return srs_api_response_code(w, r, ret); 924 return srs_api_response_code(w, r, ret);
890 } 925 }
891 926
892 - // config query.  
893 - SrsAmf0Object* obj = SrsAmf0Any::object();  
894 - SrsAutoFree(SrsAmf0Object, obj);  
895 -  
896 - obj->set("code", SrsAmf0Any::number(ERROR_SUCCESS));  
897 -  
898 if (scope == "vhost") { 927 if (scope == "vhost") {
899 // query vhost scope. 928 // query vhost scope.
900 if (vhost.empty()) { 929 if (vhost.empty()) {
@@ -934,6 +963,15 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -934,6 +963,15 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
934 return ret; 963 return ret;
935 } 964 }
936 965
  966 +int SrsGoApiRaw::on_reload_http_api_raw_api()
  967 +{
  968 + raw_api = _srs_config->get_raw_api();
  969 + allow_reload = _srs_config->get_raw_api_allow_reload();
  970 + allow_config_query = _srs_config->get_raw_api_allow_config_query();
  971 +
  972 + return ERROR_SUCCESS;
  973 +}
  974 +
937 SrsGoApiError::SrsGoApiError() 975 SrsGoApiError::SrsGoApiError()
938 { 976 {
939 } 977 }
@@ -954,11 +992,15 @@ SrsHttpApi::SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m @@ -954,11 +992,15 @@ SrsHttpApi::SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m
954 mux = m; 992 mux = m;
955 parser = new SrsHttpParser(); 993 parser = new SrsHttpParser();
956 crossdomain_required = false; 994 crossdomain_required = false;
  995 +
  996 + _srs_config->subscribe(this);
957 } 997 }
958 998
959 SrsHttpApi::~SrsHttpApi() 999 SrsHttpApi::~SrsHttpApi()
960 { 1000 {
961 srs_freep(parser); 1001 srs_freep(parser);
  1002 +
  1003 + _srs_config->unsubscribe(this);
962 } 1004 }
963 1005
964 void SrsHttpApi::resample() 1006 void SrsHttpApi::resample()
@@ -1002,6 +1044,9 @@ int SrsHttpApi::do_cycle() @@ -1002,6 +1044,9 @@ int SrsHttpApi::do_cycle()
1002 // @see https://github.com/simple-rtmp-server/srs/issues/398 1044 // @see https://github.com/simple-rtmp-server/srs/issues/398
1003 skt.set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US); 1045 skt.set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US);
1004 1046
  1047 + // initialize the crossdomain
  1048 + crossdomain_enabled = _srs_config->get_http_api_crossdomain();
  1049 +
1005 // process http messages. 1050 // process http messages.
1006 while(!disposed) { 1051 while(!disposed) {
1007 ISrsHttpMessage* req = NULL; 1052 ISrsHttpMessage* req = NULL;
@@ -1083,5 +1128,12 @@ int SrsHttpApi::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -1083,5 +1128,12 @@ int SrsHttpApi::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
1083 return ret; 1128 return ret;
1084 } 1129 }
1085 1130
  1131 +int SrsHttpApi::on_reload_http_api_crossdomain()
  1132 +{
  1133 + crossdomain_enabled = _srs_config->get_http_api_crossdomain();
  1134 +
  1135 + return ERROR_SUCCESS;
  1136 +}
  1137 +
1086 #endif 1138 #endif
1087 1139
@@ -41,6 +41,7 @@ class SrsServer; @@ -41,6 +41,7 @@ class SrsServer;
41 #include <srs_app_st.hpp> 41 #include <srs_app_st.hpp>
42 #include <srs_app_conn.hpp> 42 #include <srs_app_conn.hpp>
43 #include <srs_http_stack.hpp> 43 #include <srs_http_stack.hpp>
  44 +#include <srs_app_reload.hpp>
44 45
45 // for http root. 46 // for http root.
46 class SrsGoApiRoot : public ISrsHttpHandler 47 class SrsGoApiRoot : public ISrsHttpHandler
@@ -178,15 +179,22 @@ public: @@ -178,15 +179,22 @@ public:
178 virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); 179 virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
179 }; 180 };
180 181
181 -class SrsGoApiRaw : public ISrsHttpHandler 182 +class SrsGoApiRaw : virtual public ISrsHttpHandler, virtual public ISrsReloadHandler
182 { 183 {
183 private: 184 private:
184 SrsServer* server; 185 SrsServer* server;
  186 +private:
  187 + bool raw_api;
  188 + bool allow_reload;
  189 + bool allow_config_query;
185 public: 190 public:
186 SrsGoApiRaw(SrsServer* svr); 191 SrsGoApiRaw(SrsServer* svr);
187 virtual ~SrsGoApiRaw(); 192 virtual ~SrsGoApiRaw();
188 public: 193 public:
189 virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); 194 virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
  195 +// interface ISrsReloadHandler
  196 +public:
  197 + virtual int on_reload_http_api_raw_api();
190 }; 198 };
191 199
192 class SrsGoApiError : public ISrsHttpHandler 200 class SrsGoApiError : public ISrsHttpHandler
@@ -198,12 +206,13 @@ public: @@ -198,12 +206,13 @@ public:
198 virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); 206 virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
199 }; 207 };
200 208
201 -class SrsHttpApi : public SrsConnection 209 +class SrsHttpApi : virtual public SrsConnection, virtual public ISrsReloadHandler
202 { 210 {
203 private: 211 private:
204 SrsHttpParser* parser; 212 SrsHttpParser* parser;
205 SrsHttpServeMux* mux; 213 SrsHttpServeMux* mux;
206 bool crossdomain_required; 214 bool crossdomain_required;
  215 + bool crossdomain_enabled;
207 public: 216 public:
208 SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m); 217 SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m);
209 virtual ~SrsHttpApi(); 218 virtual ~SrsHttpApi();
@@ -217,6 +226,9 @@ protected: @@ -217,6 +226,9 @@ protected:
217 virtual int do_cycle(); 226 virtual int do_cycle();
218 private: 227 private:
219 virtual int process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); 228 virtual int process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
  229 +// interface ISrsReloadHandler
  230 +public:
  231 + virtual int on_reload_http_api_crossdomain();
220 }; 232 };
221 233
222 #endif 234 #endif
@@ -80,6 +80,16 @@ int ISrsReloadHandler::on_reload_http_api_disabled() @@ -80,6 +80,16 @@ int ISrsReloadHandler::on_reload_http_api_disabled()
80 return ERROR_SUCCESS; 80 return ERROR_SUCCESS;
81 } 81 }
82 82
  83 +int ISrsReloadHandler::on_reload_http_api_crossdomain()
  84 +{
  85 + return ERROR_SUCCESS;
  86 +}
  87 +
  88 +int ISrsReloadHandler::on_reload_http_api_raw_api()
  89 +{
  90 + return ERROR_SUCCESS;
  91 +}
  92 +
83 int ISrsReloadHandler::on_reload_http_stream_enabled() 93 int ISrsReloadHandler::on_reload_http_stream_enabled()
84 { 94 {
85 return ERROR_SUCCESS; 95 return ERROR_SUCCESS;
@@ -53,6 +53,8 @@ public: @@ -53,6 +53,8 @@ public:
53 virtual int on_reload_pithy_print(); 53 virtual int on_reload_pithy_print();
54 virtual int on_reload_http_api_enabled(); 54 virtual int on_reload_http_api_enabled();
55 virtual int on_reload_http_api_disabled(); 55 virtual int on_reload_http_api_disabled();
  56 + virtual int on_reload_http_api_crossdomain();
  57 + virtual int on_reload_http_api_raw_api();
56 virtual int on_reload_http_stream_enabled(); 58 virtual int on_reload_http_stream_enabled();
57 virtual int on_reload_http_stream_disabled(); 59 virtual int on_reload_http_stream_disabled();
58 virtual int on_reload_http_stream_updated(); 60 virtual int on_reload_http_stream_updated();