diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index eeae92ef1..a29c11895 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2514,15 +2514,57 @@ srs_error_t SrsConfig::check_normal_config() if (true) { string api = get_http_api_listen(); string server = get_http_stream_listen(); - if (api.empty()) { + vector api_vec = get_http_apis_listens(); + vector server_vec = get_http_streams_listens(); + if (api_vec.empty()) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "http_api.listen requires params"); } - if (server.empty()) { + if (server_vec.empty()) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "http_server.listen requires params"); } + std::sort(api_vec.begin(), api_vec.end()); + std::sort(server_vec.begin(), server_vec.end()); + + // 교집합 결과를 저장할 벡터 + std::vector intersection_result; + std::vector intersections_result; + + // set_intersection 사용 + std::set_intersection( + api_vec.begin(), api_vec.end(), + server_vec.begin(), server_vec.end(), + std::back_inserter(intersection_result) + ); + + if (intersection_result.size() != 0 && intersection_result != api_vec.size()) + { + return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "http api and server have a intersection, but http server did not include http api"); + } + + string apis = get_https_api_listen(); string servers = get_https_stream_listen(); + vector apis_vec = get_https_apis_listens(); + vector servers_vec = get_https_streams_listens(); + + std::sort(apis_vec.begin(), apis_vec.end()); + std::sort(servers_vec.begin(), servers_vec.end()); + + // 교집합 결과를 저장할 벡터 + + // set_intersection 사용 + std::set_intersection( + apis_vec.begin(), apis_vec.end(), + servers_vec.begin(), servers_vec.end(), + std::back_inserter(intersections_result) + ); + + if (intersections_result.size() != 0 && intersections_result != api_vec.size()) + { + return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "https api and server have a intersection, but https server did not include http api"); + } + if (api == server && apis != servers) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "for same http, https api(%s) != server(%s)", apis.c_str(), servers.c_str()); } @@ -7696,6 +7738,26 @@ string SrsConfig::get_http_api_listen() return conf->arg0(); } +std::vector SrsConfig::get_http_apis_listens() +{ + std::vector ports; + if (!srs_getenv("srs.http_api.listen").empty()) { // SRS_LISTEN + return srs_string_split(srs_getenv("srs.http_api.listen"), " "); + } + string DEFAULT = "1985"; + SrsConfDirective* conf = root->get("http_api"); + if (!conf) { + ports.push_back(DEFAULT); + return ports; + } + + for (int i = 0; i < (int)conf->args.size(); i++) { + ports.push_back(conf->args.at(i)); + } + + return ports; +} + bool SrsConfig::get_http_api_crossdomain() { SRS_OVERWRITE_BY_ENV_BOOL2("srs.http_api.crossdomain"); // SRS_HTTP_API_CROSSDOMAIN @@ -7900,6 +7962,31 @@ string SrsConfig::get_https_api_listen() return conf->arg0(); } +std::vector SrsConfig::get_https_apis_listens() +{ + std::vector ports; + if (!srs_getenv("srs.http_api.https.listen").empty()) { // SRS_LISTEN + return srs_string_split(srs_getenv("srs.http_api.https.listen"), " "); + } + static string DEFAULT = "1990"; + if (get_http_api_listen() == get_http_stream_listen()) { + DEFAULT = get_https_stream_listen(); + } + + SrsConfDirective* conf = get_https_api(); + if (!conf) { + ports.push_back(DEFAULT); + return ports; + } + + for (int i = 0; i < (int)conf->args.size(); i++) { + ports.push_back(conf->args.at(i)); + } + + return ports; +} + + string SrsConfig::get_https_api_ssl_key() { SRS_OVERWRITE_BY_ENV_STRING("srs.http_api.https.key"); // SRS_HTTP_API_HTTPS_KEY @@ -8315,6 +8402,25 @@ bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf) return SRS_CONF_PREFER_FALSE(conf->arg0()); } +std::vector SrsConfig::get_http_streams_listens() +{ + std::vector ports; + if (!srs_getenv("srs.http_server.listen").empty()) { // SRS_LISTEN + return srs_string_split(srs_getenv("srs.http_server.listen"), " "); + } + string DEFAULT = "8080"; + SrsConfDirective* conf = root->get("http_server"); + if (!conf) { + ports.push_back(DEFAULT); + return ports; + } + + for (int i = 0; i < (int)conf->args.size(); i++) { + ports.push_back(conf->args.at(i)); + } + + return ports; +} string SrsConfig::get_http_stream_listen() { @@ -8421,6 +8527,26 @@ string SrsConfig::get_https_stream_listen() return conf->arg0(); } +std::vector SrsConfig::get_https_streams_listens() +{ + std::vector ports; + if (!srs_getenv("srs.http_server.https.listen").empty()) { // SRS_LISTEN + return srs_string_split(srs_getenv("srs.http_server.https.listen"), " "); + } + static string DEFAULT = "8088"; + SrsConfDirective* conf = get_https_stream(); + if (!conf) { + ports.push_back(DEFAULT); + return ports; + } + + for (int i = 0; i < (int)conf->args.size(); i++) { + ports.push_back(conf->args.at(i)); + } + + return ports; +} + string SrsConfig::get_https_stream_ssl_key() { SRS_OVERWRITE_BY_ENV_STRING("srs.http_server.https.key"); // SRS_HTTP_SERVER_HTTPS_KEY diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index e7432d14c..9e159a48d 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -1031,6 +1031,10 @@ public: virtual bool get_http_api_enabled(); // Get the http api listen port. virtual std::string get_http_api_listen(); + // Get the http api listen port. + // user can specifies multiple listen ports, + // each args of directive is a listen port. + virtual std::vector get_http_apis_listens(); // Whether enable crossdomain for http api. virtual bool get_http_api_crossdomain(); // Whether enable the HTTP RAW API. @@ -1053,6 +1057,7 @@ private: public: virtual bool get_https_api_enabled(); virtual std::string get_https_api_listen(); + virtual std::vector get_https_apis_listens(); virtual std::string get_https_api_ssl_key(); virtual std::string get_https_api_ssl_cert(); // http stream section @@ -1065,6 +1070,10 @@ public: virtual bool get_http_stream_enabled(); // Get the http stream listen port. virtual std::string get_http_stream_listen(); + // Get the http stream listen port. + // user can specifies multiple listen ports, + // each args of directive is a listen port. + virtual std::vector get_http_streams_listens(); // Get the http stream root dir. virtual std::string get_http_stream_dir(); // Whether enable crossdomain for http static and stream server. @@ -1075,6 +1084,7 @@ private: public: virtual bool get_https_stream_enabled(); virtual std::string get_https_stream_listen(); + virtual std::vector get_https_streams_listens(); virtual std::string get_https_stream_ssl_key(); virtual std::string get_https_stream_ssl_cert(); public: diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 767429b24..e5d82e291 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -493,6 +493,13 @@ srs_error_t SrsServer::initialize() bool stream = _srs_config->get_http_stream_enabled(); string http_listen = _srs_config->get_http_stream_listen(); string https_listen = _srs_config->get_https_stream_listen(); + vector server_vec = get_http_streams_listens(); + vector servers_vec = get_https_streams_listens(); + std::sort(server_vec.begin(), server_vec.end()); + std::sort(servers_vec.begin(), servers_vec.end()); + + + #ifdef SRS_RTC bool rtc = _srs_config->get_rtc_server_enabled(); @@ -513,6 +520,36 @@ srs_error_t SrsServer::initialize() bool api = _srs_config->get_http_api_enabled(); string api_listen = _srs_config->get_http_api_listen(); string apis_listen = _srs_config->get_https_api_listen(); + vector api_vec = get_http_apis_listens(); + vector apis_vec = get_https_apis_listens(); + + std::sort(api_vec.begin(), api_vec.end()); + std::sort(apis_vec.begin(), apis_vec.end()); + + std::vector intersection_result; + std::vector intersections_result; + + std::set_intersection( + api_vec.begin(), api_vec.end(), + server_vec.begin(), server_vec.end(), + std::back_inserter(intersection_result) + ); + + if (intersection_result.size() == 0) + { + reuse_api_over_server_ = false; + } + else if (intersection_result.size() == api_vec.size()) + { + reuse_api_over_server_ = true; + } + else + { + return srs_error_wrap(err, "http api initialize"); + } + + + if (stream && api && api_listen == http_listen && apis_listen == https_listen) { srs_trace("API reuses http=%s and https=%s server", http_listen.c_str(), https_listen.c_str()); reuse_api_over_server_ = true; diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index 07fb52cc4..db5e49701 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -116,7 +116,7 @@ private: bool reuse_api_over_server_; // If reusing, WebRTC TCP use the same port of HTTP server. bool reuse_rtc_over_server_; - // RTMP stream listeners, over TCP. + // RTMP stream listeners, over TCP. SrsMultipleTcpListeners* rtmp_listener_; // HTTP API listener, over TCP. Please note that it might reuse with stream listener. SrsTcpListener* api_listener_;