正在显示
3 个修改的文件
包含
110 行增加
和
21 行删除
| @@ -228,6 +228,14 @@ SrsConfDirective* SrsConfDirective::set_arg0(string a0) | @@ -228,6 +228,14 @@ SrsConfDirective* SrsConfDirective::set_arg0(string a0) | ||
| 228 | return this; | 228 | return this; |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | +void SrsConfDirective::remove(SrsConfDirective* v) | ||
| 232 | +{ | ||
| 233 | + std::vector<SrsConfDirective*>::iterator it; | ||
| 234 | + if ((it = ::find(directives.begin(), directives.end(), v)) != directives.end()) { | ||
| 235 | + directives.erase(it); | ||
| 236 | + } | ||
| 237 | +} | ||
| 238 | + | ||
| 231 | bool SrsConfDirective::is_vhost() | 239 | bool SrsConfDirective::is_vhost() |
| 232 | { | 240 | { |
| 233 | return name == "vhost"; | 241 | return name == "vhost"; |
| @@ -2472,6 +2480,40 @@ int SrsConfig::raw_create_vhost(string vhost, bool& applied) | @@ -2472,6 +2480,40 @@ int SrsConfig::raw_create_vhost(string vhost, bool& applied) | ||
| 2472 | return ret; | 2480 | return ret; |
| 2473 | } | 2481 | } |
| 2474 | 2482 | ||
| 2483 | +int SrsConfig::raw_update_vhost(string vhost, string name, bool& applied) | ||
| 2484 | +{ | ||
| 2485 | + int ret = ERROR_SUCCESS; | ||
| 2486 | + | ||
| 2487 | + applied = false; | ||
| 2488 | + | ||
| 2489 | + // the vhost must be disabled, so we donot need to reload. | ||
| 2490 | + SrsConfDirective* conf = root->get_or_create("vhost", vhost); | ||
| 2491 | + conf->set_arg0(name); | ||
| 2492 | + | ||
| 2493 | + applied = true; | ||
| 2494 | + | ||
| 2495 | + return ret; | ||
| 2496 | +} | ||
| 2497 | + | ||
| 2498 | +int SrsConfig::raw_delete_vhost(string vhost, bool& applied) | ||
| 2499 | +{ | ||
| 2500 | + int ret = ERROR_SUCCESS; | ||
| 2501 | + | ||
| 2502 | + applied = false; | ||
| 2503 | + | ||
| 2504 | + // the vhost must be disabled, so we donot need to reload. | ||
| 2505 | + SrsConfDirective* conf = root->get("vhost", vhost); | ||
| 2506 | + srs_assert(conf); | ||
| 2507 | + | ||
| 2508 | + // remove the directive. | ||
| 2509 | + root->remove(conf); | ||
| 2510 | + srs_freep(conf); | ||
| 2511 | + | ||
| 2512 | + applied = true; | ||
| 2513 | + | ||
| 2514 | + return ret; | ||
| 2515 | +} | ||
| 2516 | + | ||
| 2475 | int SrsConfig::do_reload_listen() | 2517 | int SrsConfig::do_reload_listen() |
| 2476 | { | 2518 | { |
| 2477 | int ret = ERROR_SUCCESS; | 2519 | int ret = ERROR_SUCCESS; |
| @@ -131,6 +131,10 @@ public: | @@ -131,6 +131,10 @@ public: | ||
| 131 | virtual SrsConfDirective* get_or_create(std::string n); | 131 | virtual SrsConfDirective* get_or_create(std::string n); |
| 132 | virtual SrsConfDirective* get_or_create(std::string n, std::string a0); | 132 | virtual SrsConfDirective* get_or_create(std::string n, std::string a0); |
| 133 | virtual SrsConfDirective* set_arg0(std::string a0); | 133 | virtual SrsConfDirective* set_arg0(std::string a0); |
| 134 | + /** | ||
| 135 | + * remove the v from sub directives, user must free the v. | ||
| 136 | + */ | ||
| 137 | + virtual void remove(SrsConfDirective* v); | ||
| 134 | // help utilities | 138 | // help utilities |
| 135 | public: | 139 | public: |
| 136 | /** | 140 | /** |
| @@ -378,6 +382,14 @@ public: | @@ -378,6 +382,14 @@ public: | ||
| 378 | * raw create the new vhost. | 382 | * raw create the new vhost. |
| 379 | */ | 383 | */ |
| 380 | virtual int raw_create_vhost(std::string vhost, bool& applied); | 384 | virtual int raw_create_vhost(std::string vhost, bool& applied); |
| 385 | + /** | ||
| 386 | + * raw update the disabled vhost name. | ||
| 387 | + */ | ||
| 388 | + virtual int raw_update_vhost(std::string vhost, std::string name, bool& applied); | ||
| 389 | + /** | ||
| 390 | + * raw delete the disabled vhost. | ||
| 391 | + */ | ||
| 392 | + virtual int raw_delete_vhost(std::string vhost, bool& applied); | ||
| 381 | private: | 393 | private: |
| 382 | virtual int do_reload_listen(); | 394 | virtual int do_reload_listen(); |
| 383 | virtual int do_reload_pid(); | 395 | virtual int do_reload_pid(); |
| @@ -985,21 +985,23 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -985,21 +985,23 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 985 | // @scope the scope to update for config. | 985 | // @scope the scope to update for config. |
| 986 | // @value the updated value for scope. | 986 | // @value the updated value for scope. |
| 987 | // @param the extra param for scope. | 987 | // @param the extra param for scope. |
| 988 | + // @data the extra data for scope. | ||
| 988 | // possible updates: | 989 | // possible updates: |
| 989 | - // @scope @value value-description | ||
| 990 | - // listen 1935,1936 the port list. | ||
| 991 | - // pid ./objs/srs.pid the pid file of srs. | ||
| 992 | - // chunk_size 60000 the global RTMP chunk_size. | ||
| 993 | - // ff_log_dir ./objs the dir for ffmpeg log. | ||
| 994 | - // srs_log_tank file the tank to log, file or console. | ||
| 995 | - // srs_log_level trace the level of log, verbose, info, trace, warn, error. | ||
| 996 | - // srs_log_file ./objs/srs.log the log file when tank is file. | ||
| 997 | - // max_connections 1000 the max connections of srs. | ||
| 998 | - // utc_time false whether enable utc time. | ||
| 999 | - // pithy_print_ms 10000 the pithy print interval in ms. | 990 | + // @scope @value value-description |
| 991 | + // listen 1935,1936 the port list. | ||
| 992 | + // pid ./objs/srs.pid the pid file of srs. | ||
| 993 | + // chunk_size 60000 the global RTMP chunk_size. | ||
| 994 | + // ff_log_dir ./objs the dir for ffmpeg log. | ||
| 995 | + // srs_log_tank file the tank to log, file or console. | ||
| 996 | + // srs_log_level trace the level of log, verbose, info, trace, warn, error. | ||
| 997 | + // srs_log_file ./objs/srs.log the log file when tank is file. | ||
| 998 | + // max_connections 1000 the max connections of srs. | ||
| 999 | + // utc_time false whether enable utc time. | ||
| 1000 | + // pithy_print_ms 10000 the pithy print interval in ms. | ||
| 1000 | // vhost specified updates: | 1001 | // vhost specified updates: |
| 1001 | - // @scope @value @param description | ||
| 1002 | - // vhost ossrs.net create create vhost ossrs.net | 1002 | + // @scope @value @param @data description |
| 1003 | + // vhost ossrs.net create - create vhost ossrs.net | ||
| 1004 | + // vhost ossrs.net update new.ossrs.net the new name to update vhost | ||
| 1003 | if (rpc == "update") { | 1005 | if (rpc == "update") { |
| 1004 | if (!allow_update) { | 1006 | if (!allow_update) { |
| 1005 | ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; | 1007 | ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; |
| @@ -1009,7 +1011,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -1009,7 +1011,6 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 1009 | 1011 | ||
| 1010 | std::string scope = r->query_get("scope"); | 1012 | std::string scope = r->query_get("scope"); |
| 1011 | std::string value = r->query_get("value"); | 1013 | std::string value = r->query_get("value"); |
| 1012 | - std::string param = r->query_get("param"); | ||
| 1013 | if (scope.empty()) { | 1014 | if (scope.empty()) { |
| 1014 | ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; | 1015 | ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; |
| 1015 | srs_error("raw api query invalid empty scope. ret=%d", ret); | 1016 | srs_error("raw api query invalid empty scope. ret=%d", ret); |
| @@ -1024,13 +1025,9 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -1024,13 +1025,9 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 1024 | srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret); | 1025 | srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret); |
| 1025 | return srs_api_response_code(w, r, ret); | 1026 | return srs_api_response_code(w, r, ret); |
| 1026 | } | 1027 | } |
| 1027 | - if (scope == "vhost" && param != "create") { | ||
| 1028 | - ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; | ||
| 1029 | - srs_error("raw api query invalid scope=%s, param=%s. ret=%d", scope.c_str(), param.c_str(), ret); | ||
| 1030 | - return srs_api_response_code(w, r, ret); | ||
| 1031 | - } | ||
| 1032 | 1028 | ||
| 1033 | bool applied = false; | 1029 | bool applied = false; |
| 1030 | + string extra = ""; | ||
| 1034 | if (scope == "listen") { | 1031 | if (scope == "listen") { |
| 1035 | vector<string> eps = srs_string_split(value, ","); | 1032 | vector<string> eps = srs_string_split(value, ","); |
| 1036 | 1033 | ||
| @@ -1156,6 +1153,15 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -1156,6 +1153,15 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 1156 | return srs_api_response_code(w, r, ret); | 1153 | return srs_api_response_code(w, r, ret); |
| 1157 | } | 1154 | } |
| 1158 | } else if (scope == "vhost") { | 1155 | } else if (scope == "vhost") { |
| 1156 | + std::string param = r->query_get("param"); | ||
| 1157 | + std::string data = r->query_get("data"); | ||
| 1158 | + if (param != "create" && param != "update" && param != "delete") { | ||
| 1159 | + ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; | ||
| 1160 | + srs_error("raw api query invalid scope=%s, param=%s. ret=%d", scope.c_str(), param.c_str(), ret); | ||
| 1161 | + return srs_api_response_code(w, r, ret); | ||
| 1162 | + } | ||
| 1163 | + extra += " " + param; | ||
| 1164 | + | ||
| 1159 | if (param == "create") { | 1165 | if (param == "create") { |
| 1160 | // when create, the vhost must not exists. | 1166 | // when create, the vhost must not exists. |
| 1161 | if (param.empty() || _srs_config->get_vhost(value, false)) { | 1167 | if (param.empty() || _srs_config->get_vhost(value, false)) { |
| @@ -1168,15 +1174,44 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -1168,15 +1174,44 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 1168 | srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); | 1174 | srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); |
| 1169 | return srs_api_response_code(w, r, ret); | 1175 | return srs_api_response_code(w, r, ret); |
| 1170 | } | 1176 | } |
| 1177 | + } else if (param == "update") { | ||
| 1178 | + extra += " to " + data; | ||
| 1179 | + | ||
| 1180 | + // when update, the vhost must exists and disabled. | ||
| 1181 | + SrsConfDirective* vhost = _srs_config->get_vhost(value, false); | ||
| 1182 | + if (data.empty() || data == value || param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) { | ||
| 1183 | + ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; | ||
| 1184 | + srs_error("raw api update check vhost=%s, param=%s, data=%s failed. ret=%d", value.c_str(), param.c_str(), data.c_str(), ret); | ||
| 1185 | + return srs_api_response_code(w, r, ret); | ||
| 1186 | + } | ||
| 1187 | + | ||
| 1188 | + if ((ret = _srs_config->raw_update_vhost(value, data, applied)) != ERROR_SUCCESS) { | ||
| 1189 | + srs_error("raw api update vhost=%s, param=%s, data=%s failed. ret=%d", value.c_str(), param.c_str(), data.c_str(), ret); | ||
| 1190 | + return srs_api_response_code(w, r, ret); | ||
| 1191 | + } | ||
| 1192 | + } else if (param == "delete") { | ||
| 1193 | + // when delete, the vhost must exists and disabled. | ||
| 1194 | + SrsConfDirective* vhost = _srs_config->get_vhost(value, false); | ||
| 1195 | + if (param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) { | ||
| 1196 | + ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; | ||
| 1197 | + srs_error("raw api update check vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); | ||
| 1198 | + return srs_api_response_code(w, r, ret); | ||
| 1199 | + } | ||
| 1200 | + | ||
| 1201 | + if ((ret = _srs_config->raw_delete_vhost(value, applied)) != ERROR_SUCCESS) { | ||
| 1202 | + srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); | ||
| 1203 | + return srs_api_response_code(w, r, ret); | ||
| 1204 | + } | ||
| 1205 | + | ||
| 1171 | } | 1206 | } |
| 1172 | } | 1207 | } |
| 1173 | 1208 | ||
| 1174 | // whether the config applied. | 1209 | // whether the config applied. |
| 1175 | if (applied) { | 1210 | if (applied) { |
| 1176 | server->on_signal(SRS_SIGNAL_PERSISTENCE_CONFIG); | 1211 | server->on_signal(SRS_SIGNAL_PERSISTENCE_CONFIG); |
| 1177 | - srs_trace("raw api update %s=%s ok.", scope.c_str(), value.c_str()); | 1212 | + srs_trace("raw api update %s=%s%s ok.", scope.c_str(), value.c_str(), extra.c_str()); |
| 1178 | } else { | 1213 | } else { |
| 1179 | - srs_warn("raw api update not applied %s=%s.", scope.c_str(), value.c_str()); | 1214 | + srs_warn("raw api update not applied %s=%s%s.", scope.c_str(), value.c_str(), extra.c_str()); |
| 1180 | } | 1215 | } |
| 1181 | 1216 | ||
| 1182 | return srs_api_response(w, r, obj->to_json()); | 1217 | return srs_api_response(w, r, obj->to_json()); |
-
请 注册 或 登录 后发表评论