From 665ad564fb5712e0c0fc9a9d3e29af8a0476225c Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 9 Jun 2022 19:59:51 +0800 Subject: [PATCH] Rename service to protocol files. --- trunk/configure | 4 +- trunk/src/app/srs_app_conn.cpp | 2 +- trunk/src/app/srs_app_conn.hpp | 2 +- trunk/src/app/srs_app_coworkers.cpp | 2 +- trunk/src/app/srs_app_edge.cpp | 2 +- trunk/src/app/srs_app_http_client.hpp | 2 +- trunk/src/app/srs_app_http_conn.hpp | 2 +- trunk/src/app/srs_app_http_static.cpp | 4 +- trunk/src/app/srs_app_hybrid.cpp | 2 +- trunk/src/app/srs_app_log.hpp | 2 +- trunk/src/app/srs_app_rtc_conn.cpp | 6 +- trunk/src/app/srs_app_rtc_conn.hpp | 4 +- trunk/src/app/srs_app_rtc_server.cpp | 4 +- trunk/src/app/srs_app_rtc_source.hpp | 2 +- trunk/src/app/srs_app_rtmp_conn.hpp | 2 +- trunk/src/app/srs_app_server.cpp | 2 +- trunk/src/app/srs_app_server.hpp | 2 +- trunk/src/app/srs_app_source.hpp | 2 +- trunk/src/app/srs_app_st.hpp | 2 +- trunk/src/app/srs_app_utility.hpp | 2 +- trunk/src/main/srs_main_ingest_hls.cpp | 12 +- trunk/src/main/srs_main_mp4_parser.cpp | 2 +- ...service_conn.cpp => srs_protocol_conn.cpp} | 2 +- ...service_conn.hpp => srs_protocol_conn.hpp} | 4 +- ...lient.cpp => srs_protocol_http_client.cpp} | 4 +- ...lient.hpp => srs_protocol_http_client.hpp} | 6 +- ...tp_conn.cpp => srs_protocol_http_conn.cpp} | 6 +- ...tp_conn.hpp => srs_protocol_http_conn.hpp} | 4 +- ...s_service_log.cpp => srs_protocol_log.cpp} | 2 +- ...s_service_log.hpp => srs_protocol_log.hpp} | 6 +- ...mp_conn.cpp => srs_protocol_rtmp_conn.cpp} | 6 +- ...mp_conn.hpp => srs_protocol_rtmp_conn.hpp} | 4 +- ...srs_service_st.cpp => srs_protocol_st.cpp} | 4 +- ...srs_service_st.hpp => srs_protocol_st.hpp} | 4 +- trunk/src/protocol/srs_protocol_utility.cpp | 378 +++++++++++++++++ trunk/src/protocol/srs_protocol_utility.hpp | 53 +++ trunk/src/protocol/srs_service_utility.cpp | 385 ------------------ trunk/src/protocol/srs_service_utility.hpp | 66 --- trunk/src/utest/srs_utest_app.cpp | 2 +- trunk/src/utest/srs_utest_config.cpp | 2 +- trunk/src/utest/srs_utest_http.cpp | 4 +- trunk/src/utest/srs_utest_http.hpp | 2 +- trunk/src/utest/srs_utest_protocol.cpp | 2 +- trunk/src/utest/srs_utest_rtmp.cpp | 2 +- trunk/src/utest/srs_utest_service.cpp | 16 +- trunk/src/utest/srs_utest_service.hpp | 2 +- 46 files changed, 506 insertions(+), 526 deletions(-) rename trunk/src/protocol/{srs_service_conn.cpp => srs_protocol_conn.cpp} (91%) rename trunk/src/protocol/{srs_service_conn.hpp => srs_protocol_conn.hpp} (94%) rename trunk/src/protocol/{srs_service_http_client.cpp => srs_protocol_http_client.cpp} (99%) rename trunk/src/protocol/{srs_service_http_client.hpp => srs_protocol_http_client.hpp} (97%) rename trunk/src/protocol/{srs_service_http_conn.cpp => srs_protocol_http_conn.cpp} (99%) rename trunk/src/protocol/{srs_service_http_conn.hpp => srs_protocol_http_conn.hpp} (99%) rename trunk/src/protocol/{srs_service_log.cpp => srs_protocol_log.cpp} (99%) rename trunk/src/protocol/{srs_service_log.hpp => srs_protocol_log.hpp} (96%) rename trunk/src/protocol/{srs_service_rtmp_conn.cpp => srs_protocol_rtmp_conn.cpp} (98%) rename trunk/src/protocol/{srs_service_rtmp_conn.hpp => srs_protocol_rtmp_conn.hpp} (97%) rename trunk/src/protocol/{srs_service_st.cpp => srs_protocol_st.cpp} (99%) rename trunk/src/protocol/{srs_service_st.hpp => srs_protocol_st.hpp} (99%) delete mode 100644 trunk/src/protocol/srs_service_utility.cpp delete mode 100644 trunk/src/protocol/srs_service_utility.hpp diff --git a/trunk/configure b/trunk/configure index aa812011a0..2ade18f4b9 100755 --- a/trunk/configure +++ b/trunk/configure @@ -226,8 +226,8 @@ ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot}) MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_rtmp_stack" "srs_rtmp_handshake" "srs_protocol_utility" "srs_rtmp_msg_array" "srs_protocol_stream" "srs_raw_avc" "srs_rtsp_stack" "srs_http_stack" "srs_protocol_kbps" "srs_protocol_json" - "srs_protocol_format" "srs_service_log" "srs_service_st" "srs_service_http_client" "srs_service_http_conn" - "srs_service_rtmp_conn" "srs_service_utility" "srs_service_conn") + "srs_protocol_format" "srs_protocol_log" "srs_protocol_st" "srs_protocol_http_client" + "srs_protocol_http_conn" "srs_protocol_rtmp_conn" "srs_protocol_conn") if [[ $SRS_RTC == YES ]]; then MODULE_FILES+=("srs_rtc_stun_stack") ModuleLibIncs+=(${LibSrtpRoot}) diff --git a/trunk/src/app/srs_app_conn.cpp b/trunk/src/app/srs_app_conn.cpp index d3114e642e..1517bdf3e0 100644 --- a/trunk/src/app/srs_app_conn.cpp +++ b/trunk/src/app/srs_app_conn.cpp @@ -14,7 +14,7 @@ using namespace std; #include #include #include -#include +#include #include #include #include diff --git a/trunk/src/app/srs_app_conn.hpp b/trunk/src/app/srs_app_conn.hpp index 2b2a245b73..33c817a3cd 100644 --- a/trunk/src/app/srs_app_conn.hpp +++ b/trunk/src/app/srs_app_conn.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include class SrsWallClock; diff --git a/trunk/src/app/srs_app_coworkers.cpp b/trunk/src/app/srs_app_coworkers.cpp index 7e7376090a..c932626198 100644 --- a/trunk/src/app/srs_app_coworkers.cpp +++ b/trunk/src/app/srs_app_coworkers.cpp @@ -14,7 +14,7 @@ using namespace std; #include #include #include -#include +#include #include SrsCoWorkers* SrsCoWorkers::_instance = NULL; diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index 146c2269b6..4e3e6e02d3 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -29,7 +29,7 @@ using namespace std; #include #include #include -#include +#include #include #include #include diff --git a/trunk/src/app/srs_app_http_client.hpp b/trunk/src/app/srs_app_http_client.hpp index 9c1408618b..22869f33ef 100644 --- a/trunk/src/app/srs_app_http_client.hpp +++ b/trunk/src/app/srs_app_http_client.hpp @@ -9,7 +9,7 @@ #include -#include +#include #endif diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp index e093992f2d..337816063f 100644 --- a/trunk/src/app/srs_app_http_conn.hpp +++ b/trunk/src/app/srs_app_http_conn.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include diff --git a/trunk/src/app/srs_app_http_static.cpp b/trunk/src/app/srs_app_http_static.cpp index c091f91b76..c475bd7841 100644 --- a/trunk/src/app/srs_app_http_static.cpp +++ b/trunk/src/app/srs_app_http_static.cpp @@ -33,11 +33,11 @@ using namespace std; #include #include #include -#include +#include #include #include #include -#include +#include #define SRS_CONTEXT_IN_HLS "hls_ctx" diff --git a/trunk/src/app/srs_app_hybrid.cpp b/trunk/src/app/srs_app_hybrid.cpp index d1828e4f0e..b703fa7bfa 100644 --- a/trunk/src/app/srs_app_hybrid.cpp +++ b/trunk/src/app/srs_app_hybrid.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include using namespace std; diff --git a/trunk/src/app/srs_app_log.hpp b/trunk/src/app/srs_app_log.hpp index f1f409ac3d..a186628342 100644 --- a/trunk/src/app/srs_app_log.hpp +++ b/trunk/src/app/srs_app_log.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include // For log TAGs. #define TAG_MAIN "MAIN" diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index a4e2c2cff5..d1e8c451dd 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -32,17 +32,17 @@ using namespace std; #include #include #include -#include +#include #include #include #include #include -#include +#include #include #include #include #include -#include +#include #include #include #include diff --git a/trunk/src/app/srs_app_rtc_conn.hpp b/trunk/src/app/srs_app_rtc_conn.hpp index 34a9a98aed..f61a6dadaf 100644 --- a/trunk/src/app/srs_app_rtc_conn.hpp +++ b/trunk/src/app/srs_app_rtc_conn.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include diff --git a/trunk/src/app/srs_app_rtc_server.cpp b/trunk/src/app/srs_app_rtc_server.cpp index 76703730d8..780650468b 100644 --- a/trunk/src/app/srs_app_rtc_server.cpp +++ b/trunk/src/app/srs_app_rtc_server.cpp @@ -23,12 +23,12 @@ using namespace std; #include #include #include -#include +#include #include #include #include #include -#include +#include extern SrsPps* _srs_pps_rpkts; SrsPps* _srs_pps_rstuns = NULL; diff --git a/trunk/src/app/srs_app_rtc_source.hpp b/trunk/src/app/srs_app_rtc_source.hpp index 7bb28b5bcc..f261ed4104 100644 --- a/trunk/src/app/srs_app_rtc_source.hpp +++ b/trunk/src/app/srs_app_rtc_source.hpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp index 99dddccb30..cc02125bce 100644 --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include class SrsServer; class SrsRtmpServer; diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index f8d1de30d5..bdf877ccbf 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -34,7 +34,7 @@ using namespace std; #include #include #include -#include +#include #include std::string srs_listener_type2string(SrsListenerType type) diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index aae93b3082..a823dec290 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index 80618a9de1..5ebdb46142 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include class SrsFormat; diff --git a/trunk/src/app/srs_app_st.hpp b/trunk/src/app/srs_app_st.hpp index 6b7eb701e7..dfa442f5f3 100644 --- a/trunk/src/app/srs_app_st.hpp +++ b/trunk/src/app/srs_app_st.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include class SrsFastCoroutine; diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index 86566cc0a4..cd400ab33a 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include class SrsKbps; class SrsBuffer; diff --git a/trunk/src/main/srs_main_ingest_hls.cpp b/trunk/src/main/srs_main_ingest_hls.cpp index 024edc3d8b..eb7a3cc5b3 100644 --- a/trunk/src/main/srs_main_ingest_hls.cpp +++ b/trunk/src/main/srs_main_ingest_hls.cpp @@ -23,12 +23,12 @@ using namespace std; #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include // pre-declare diff --git a/trunk/src/main/srs_main_mp4_parser.cpp b/trunk/src/main/srs_main_mp4_parser.cpp index 6f278d0d57..2466561bc6 100644 --- a/trunk/src/main/srs_main_mp4_parser.cpp +++ b/trunk/src/main/srs_main_mp4_parser.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/trunk/src/protocol/srs_service_conn.cpp b/trunk/src/protocol/srs_protocol_conn.cpp similarity index 91% rename from trunk/src/protocol/srs_service_conn.cpp rename to trunk/src/protocol/srs_protocol_conn.cpp index 1d79456808..ea299e43d3 100644 --- a/trunk/src/protocol/srs_service_conn.cpp +++ b/trunk/src/protocol/srs_protocol_conn.cpp @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#include +#include ISrsResource::ISrsResource() { diff --git a/trunk/src/protocol/srs_service_conn.hpp b/trunk/src/protocol/srs_protocol_conn.hpp similarity index 94% rename from trunk/src/protocol/srs_service_conn.hpp rename to trunk/src/protocol/srs_protocol_conn.hpp index cff04334af..c3d8f52c13 100644 --- a/trunk/src/protocol/srs_service_conn.hpp +++ b/trunk/src/protocol/srs_protocol_conn.hpp @@ -4,8 +4,8 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#ifndef SRS_SERVICE_CONN_HPP -#define SRS_SERVICE_CONN_HPP +#ifndef SRS_PROTOCOL_CONN_HPP +#define SRS_PROTOCOL_CONN_HPP #include diff --git a/trunk/src/protocol/srs_service_http_client.cpp b/trunk/src/protocol/srs_protocol_http_client.cpp similarity index 99% rename from trunk/src/protocol/srs_service_http_client.cpp rename to trunk/src/protocol/srs_protocol_http_client.cpp index 4196e88797..d15984824f 100644 --- a/trunk/src/protocol/srs_service_http_client.cpp +++ b/trunk/src/protocol/srs_protocol_http_client.cpp @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#include +#include #include #include @@ -16,7 +16,7 @@ using namespace std; #include #include #include -#include +#include // The return value of verify_callback controls the strategy of the further verification process. If verify_callback // returns 0, the verification process is immediately stopped with "verification failed" state. If SSL_VERIFY_PEER is diff --git a/trunk/src/protocol/srs_service_http_client.hpp b/trunk/src/protocol/srs_protocol_http_client.hpp similarity index 97% rename from trunk/src/protocol/srs_service_http_client.hpp rename to trunk/src/protocol/srs_protocol_http_client.hpp index 7cfa56f198..ed160c6ff4 100644 --- a/trunk/src/protocol/srs_service_http_client.hpp +++ b/trunk/src/protocol/srs_protocol_http_client.hpp @@ -4,8 +4,8 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#ifndef SRS_SERVICE_HTTP_CLIENT_HPP -#define SRS_SERVICE_HTTP_CLIENT_HPP +#ifndef SRS_PROTOCOL_HTTP_CLIENT_HPP +#define SRS_PROTOCOL_HTTP_CLIENT_HPP #include @@ -14,7 +14,7 @@ #include -#include +#include #include class SrsHttpUri; diff --git a/trunk/src/protocol/srs_service_http_conn.cpp b/trunk/src/protocol/srs_protocol_http_conn.cpp similarity index 99% rename from trunk/src/protocol/srs_service_http_conn.cpp rename to trunk/src/protocol/srs_protocol_http_conn.cpp index f5fd10fd7d..77afe94bb3 100644 --- a/trunk/src/protocol/srs_service_http_conn.cpp +++ b/trunk/src/protocol/srs_protocol_http_conn.cpp @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#include +#include #include #include @@ -13,12 +13,12 @@ using namespace std; #include #include #include -#include +#include #include #include #include #include -#include +#include SrsHttpParser::SrsHttpParser() { diff --git a/trunk/src/protocol/srs_service_http_conn.hpp b/trunk/src/protocol/srs_protocol_http_conn.hpp similarity index 99% rename from trunk/src/protocol/srs_service_http_conn.hpp rename to trunk/src/protocol/srs_protocol_http_conn.hpp index 968cc60862..cd9b687341 100644 --- a/trunk/src/protocol/srs_service_http_conn.hpp +++ b/trunk/src/protocol/srs_protocol_http_conn.hpp @@ -4,8 +4,8 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#ifndef SRS_SERVICE_HTTP_CONN_HPP -#define SRS_SERVICE_HTTP_CONN_HPP +#ifndef SRS_PROTOCOL_HTTP_CONN_HPP +#define SRS_PROTOCOL_HTTP_CONN_HPP #include diff --git a/trunk/src/protocol/srs_service_log.cpp b/trunk/src/protocol/srs_protocol_log.cpp similarity index 99% rename from trunk/src/protocol/srs_service_log.cpp rename to trunk/src/protocol/srs_protocol_log.cpp index 1f40fe36ec..d031ed97bd 100644 --- a/trunk/src/protocol/srs_service_log.cpp +++ b/trunk/src/protocol/srs_protocol_log.cpp @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#include +#include #include #include diff --git a/trunk/src/protocol/srs_service_log.hpp b/trunk/src/protocol/srs_protocol_log.hpp similarity index 96% rename from trunk/src/protocol/srs_service_log.hpp rename to trunk/src/protocol/srs_protocol_log.hpp index 08d504ffa1..ad8855c20e 100644 --- a/trunk/src/protocol/srs_service_log.hpp +++ b/trunk/src/protocol/srs_protocol_log.hpp @@ -4,15 +4,15 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#ifndef SRS_SERVICE_LOG_HPP -#define SRS_SERVICE_LOG_HPP +#ifndef SRS_PROTOCOL_LOG_HPP +#define SRS_PROTOCOL_LOG_HPP #include #include #include -#include +#include #include // The st thread context, get_id will get the st-thread id, diff --git a/trunk/src/protocol/srs_service_rtmp_conn.cpp b/trunk/src/protocol/srs_protocol_rtmp_conn.cpp similarity index 98% rename from trunk/src/protocol/srs_service_rtmp_conn.cpp rename to trunk/src/protocol/srs_protocol_rtmp_conn.cpp index 3ea549b67e..3f76fdc298 100644 --- a/trunk/src/protocol/srs_service_rtmp_conn.cpp +++ b/trunk/src/protocol/srs_protocol_rtmp_conn.cpp @@ -4,17 +4,17 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#include +#include #include using namespace std; #include #include -#include +#include #include #include -#include +#include SrsBasicRtmpClient::SrsBasicRtmpClient(string r, srs_utime_t ctm, srs_utime_t stm) { diff --git a/trunk/src/protocol/srs_service_rtmp_conn.hpp b/trunk/src/protocol/srs_protocol_rtmp_conn.hpp similarity index 97% rename from trunk/src/protocol/srs_service_rtmp_conn.hpp rename to trunk/src/protocol/srs_protocol_rtmp_conn.hpp index ce35f9de34..8a2396413f 100644 --- a/trunk/src/protocol/srs_service_rtmp_conn.hpp +++ b/trunk/src/protocol/srs_protocol_rtmp_conn.hpp @@ -4,8 +4,8 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#ifndef SRS_SERVICE_RTMP_CONN_HPP -#define SRS_SERVICE_RTMP_CONN_HPP +#ifndef SRS_PROTOCOL_RTMP_CONN_HPP +#define SRS_PROTOCOL_RTMP_CONN_HPP #include diff --git a/trunk/src/protocol/srs_service_st.cpp b/trunk/src/protocol/srs_protocol_st.cpp similarity index 99% rename from trunk/src/protocol/srs_service_st.cpp rename to trunk/src/protocol/srs_protocol_st.cpp index a3510662f2..a923fcce7d 100644 --- a/trunk/src/protocol/srs_service_st.cpp +++ b/trunk/src/protocol/srs_protocol_st.cpp @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#include +#include #include #include @@ -15,7 +15,7 @@ using namespace std; #include #include #include -#include +#include #include // nginx also set to 512 diff --git a/trunk/src/protocol/srs_service_st.hpp b/trunk/src/protocol/srs_protocol_st.hpp similarity index 99% rename from trunk/src/protocol/srs_service_st.hpp rename to trunk/src/protocol/srs_protocol_st.hpp index 6bb9254643..dad9fb6032 100644 --- a/trunk/src/protocol/srs_service_st.hpp +++ b/trunk/src/protocol/srs_protocol_st.hpp @@ -4,8 +4,8 @@ // SPDX-License-Identifier: MIT or MulanPSL-2.0 // -#ifndef SRS_SERVICE_ST_HPP -#define SRS_SERVICE_ST_HPP +#ifndef SRS_PROTOCOL_ST_HPP +#define SRS_PROTOCOL_ST_HPP #include diff --git a/trunk/src/protocol/srs_protocol_utility.cpp b/trunk/src/protocol/srs_protocol_utility.cpp index 88af17e7c7..6535ca1c23 100644 --- a/trunk/src/protocol/srs_protocol_utility.cpp +++ b/trunk/src/protocol/srs_protocol_utility.cpp @@ -24,6 +24,24 @@ using namespace std; #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#include +#include +#include +#include +#include +#include + /** * resolve the vhost in query string * @pram vhost, update the vhost if query contains the vhost. @@ -533,3 +551,363 @@ string srs_get_cidr_ipv4(string network_address) { return ipv4_address; } + +bool srs_string_is_http(string url) +{ + return srs_string_starts_with(url, "http://", "https://"); +} + +bool srs_string_is_rtmp(string url) +{ + return srs_string_starts_with(url, "rtmp://"); +} + +bool srs_is_digit_number(string str) +{ + if (str.empty()) { + return false; + } + + const char* p = str.c_str(); + const char* p_end = str.data() + str.length(); + for (; p < p_end; p++) { + if (*p != '0') { + break; + } + } + if (p == p_end) { + return true; + } + + int64_t v = ::atoll(p); + int64_t powv = (int64_t)pow(10, p_end - p - 1); + return v / powv >= 1 && v / powv <= 9; +} + +// we detect all network device as internet or intranet device, by its ip address. +// key is device name, for instance, eth0 +// value is whether internet, for instance, true. +static std::map _srs_device_ifs; + +bool srs_net_device_is_internet(string ifname) +{ + srs_info("check ifname=%s", ifname.c_str()); + + if (_srs_device_ifs.find(ifname) == _srs_device_ifs.end()) { + return false; + } + return _srs_device_ifs[ifname]; +} + +bool srs_net_device_is_internet(const sockaddr* addr) +{ + if(addr->sa_family == AF_INET) { + const in_addr inaddr = ((sockaddr_in*)addr)->sin_addr; + const uint32_t addr_h = ntohl(inaddr.s_addr); + + // lo, 127.0.0.0-127.0.0.1 + if (addr_h >= 0x7f000000 && addr_h <= 0x7f000001) { + return false; + } + + // Class A 10.0.0.0-10.255.255.255 + if (addr_h >= 0x0a000000 && addr_h <= 0x0affffff) { + return false; + } + + // Class B 172.16.0.0-172.31.255.255 + if (addr_h >= 0xac100000 && addr_h <= 0xac1fffff) { + return false; + } + + // Class C 192.168.0.0-192.168.255.255 + if (addr_h >= 0xc0a80000 && addr_h <= 0xc0a8ffff) { + return false; + } + } else if(addr->sa_family == AF_INET6) { + const sockaddr_in6* a6 = (const sockaddr_in6*)addr; + + // IPv6 loopback is ::1 + if (IN6_IS_ADDR_LOOPBACK(&a6->sin6_addr)) { + return false; + } + + // IPv6 unspecified is :: + if (IN6_IS_ADDR_UNSPECIFIED(&a6->sin6_addr)) { + return false; + } + + // From IPv4, you might know APIPA (Automatic Private IP Addressing) or AutoNet. + // Whenever automatic IP configuration through DHCP fails. + // The prefix of a site-local address is FE80::/10. + if (IN6_IS_ADDR_LINKLOCAL(&a6->sin6_addr)) { + return false; + } + + // Site-local addresses are equivalent to private IP addresses in IPv4. + // The prefix of a site-local address is FEC0::/10. + // https://4sysops.com/archives/ipv6-tutorial-part-6-site-local-addresses-and-link-local-addresses/ + if (IN6_IS_ADDR_SITELOCAL(&a6->sin6_addr)) { + return false; + } + + // Others. + if (IN6_IS_ADDR_MULTICAST(&a6->sin6_addr)) { + return false; + } + if (IN6_IS_ADDR_MC_NODELOCAL(&a6->sin6_addr)) { + return false; + } + if (IN6_IS_ADDR_MC_LINKLOCAL(&a6->sin6_addr)) { + return false; + } + if (IN6_IS_ADDR_MC_SITELOCAL(&a6->sin6_addr)) { + return false; + } + if (IN6_IS_ADDR_MC_ORGLOCAL(&a6->sin6_addr)) { + return false; + } + if (IN6_IS_ADDR_MC_GLOBAL(&a6->sin6_addr)) { + return false; + } + } + + return true; +} + +vector _srs_system_ips; + +void discover_network_iface(ifaddrs* cur, vector& ips, stringstream& ss0, stringstream& ss1, bool ipv6, bool loopback) +{ + char saddr[64]; + char* h = (char*)saddr; + socklen_t nbh = (socklen_t)sizeof(saddr); + const int r0 = getnameinfo(cur->ifa_addr, sizeof(sockaddr_storage), h, nbh, NULL, 0, NI_NUMERICHOST); + if(r0) { + srs_warn("convert local ip failed: %s", gai_strerror(r0)); + return; + } + + std::string ip(saddr, strlen(saddr)); + ss0 << ", iface[" << (int)ips.size() << "] " << cur->ifa_name << " " << (ipv6? "ipv6":"ipv4") + << " 0x" << std::hex << cur->ifa_flags << std::dec << " " << ip; + + SrsIPAddress* ip_address = new SrsIPAddress(); + ip_address->ip = ip; + ip_address->is_ipv4 = !ipv6; + ip_address->is_loopback = loopback; + ip_address->ifname = cur->ifa_name; + ip_address->is_internet = srs_net_device_is_internet(cur->ifa_addr); + ips.push_back(ip_address); + + // set the device internet status. + if (!ip_address->is_internet) { + ss1 << ", intranet "; + _srs_device_ifs[cur->ifa_name] = false; + } else { + ss1 << ", internet "; + _srs_device_ifs[cur->ifa_name] = true; + } + ss1 << cur->ifa_name << " " << ip; +} + +void retrieve_local_ips() +{ + vector& ips = _srs_system_ips; + + // Release previous IPs. + for (int i = 0; i < (int)ips.size(); i++) { + SrsIPAddress* ip = ips[i]; + srs_freep(ip); + } + ips.clear(); + + // Get the addresses. + ifaddrs* ifap; + if (getifaddrs(&ifap) == -1) { + srs_warn("retrieve local ips, getifaddrs failed."); + return; + } + + stringstream ss0; + ss0 << "ips"; + + stringstream ss1; + ss1 << "devices"; + + // Discover IPv4 first. + for (ifaddrs* p = ifap; p ; p = p->ifa_next) { + ifaddrs* cur = p; + + // Ignore if no address for this interface. + // @see https://github.com/ossrs/srs/issues/1087#issuecomment-408847115 + if (!cur->ifa_addr) { + continue; + } + + // retrieve IP address, ignore the tun0 network device, whose addr is NULL. + // @see: https://github.com/ossrs/srs/issues/141 + bool ipv4 = (cur->ifa_addr->sa_family == AF_INET); + bool ready = (cur->ifa_flags & IFF_UP) && (cur->ifa_flags & IFF_RUNNING); + // Ignore IFF_PROMISC(Interface is in promiscuous mode), which may be set by Wireshark. + bool ignored = (!cur->ifa_addr) || (cur->ifa_flags & IFF_LOOPBACK) || (cur->ifa_flags & IFF_POINTOPOINT); + bool loopback = (cur->ifa_flags & IFF_LOOPBACK); + if (ipv4 && ready && !ignored) { + discover_network_iface(cur, ips, ss0, ss1, false, loopback); + } + } + + // Then, discover IPv6 addresses. + for (ifaddrs* p = ifap; p ; p = p->ifa_next) { + ifaddrs* cur = p; + + // Ignore if no address for this interface. + // @see https://github.com/ossrs/srs/issues/1087#issuecomment-408847115 + if (!cur->ifa_addr) { + continue; + } + + // retrieve IP address, ignore the tun0 network device, whose addr is NULL. + // @see: https://github.com/ossrs/srs/issues/141 + bool ipv6 = (cur->ifa_addr->sa_family == AF_INET6); + bool ready = (cur->ifa_flags & IFF_UP) && (cur->ifa_flags & IFF_RUNNING); + bool ignored = (!cur->ifa_addr) || (cur->ifa_flags & IFF_POINTOPOINT) || (cur->ifa_flags & IFF_PROMISC) || (cur->ifa_flags & IFF_LOOPBACK); + bool loopback = (cur->ifa_flags & IFF_LOOPBACK); + if (ipv6 && ready && !ignored) { + discover_network_iface(cur, ips, ss0, ss1, true, loopback); + } + } + + // If empty, disover IPv4 loopback. + if (ips.empty()) { + for (ifaddrs* p = ifap; p ; p = p->ifa_next) { + ifaddrs* cur = p; + + // Ignore if no address for this interface. + // @see https://github.com/ossrs/srs/issues/1087#issuecomment-408847115 + if (!cur->ifa_addr) { + continue; + } + + // retrieve IP address, ignore the tun0 network device, whose addr is NULL. + // @see: https://github.com/ossrs/srs/issues/141 + bool ipv4 = (cur->ifa_addr->sa_family == AF_INET); + bool ready = (cur->ifa_flags & IFF_UP) && (cur->ifa_flags & IFF_RUNNING); + bool ignored = (!cur->ifa_addr) || (cur->ifa_flags & IFF_POINTOPOINT) || (cur->ifa_flags & IFF_PROMISC); + bool loopback = (cur->ifa_flags & IFF_LOOPBACK); + if (ipv4 && ready && !ignored) { + discover_network_iface(cur, ips, ss0, ss1, false, loopback); + } + } + } + + srs_trace("%s", ss0.str().c_str()); + srs_trace("%s", ss1.str().c_str()); + + freeifaddrs(ifap); +} + +vector& srs_get_local_ips() +{ + if (_srs_system_ips.empty()) { + retrieve_local_ips(); + } + + return _srs_system_ips; +} + +std::string _public_internet_address; + +string srs_get_public_internet_address(bool ipv4_only) +{ + if (!_public_internet_address.empty()) { + return _public_internet_address; + } + + std::vector& ips = srs_get_local_ips(); + + // find the best match public address. + for (int i = 0; i < (int)ips.size(); i++) { + SrsIPAddress* ip = ips[i]; + if (!ip->is_internet) { + continue; + } + if (ipv4_only && !ip->is_ipv4) { + continue; + } + + srs_warn("use public address as ip: %s, ifname=%s", ip->ip.c_str(), ip->ifname.c_str()); + _public_internet_address = ip->ip; + return ip->ip; + } + + // no public address, use private address. + for (int i = 0; i < (int)ips.size(); i++) { + SrsIPAddress* ip = ips[i]; + if (ip->is_loopback) { + continue; + } + if (ipv4_only && !ip->is_ipv4) { + continue; + } + + srs_warn("use private address as ip: %s, ifname=%s", ip->ip.c_str(), ip->ifname.c_str()); + _public_internet_address = ip->ip; + return ip->ip; + } + + // Finally, use first whatever kind of address. + if (!ips.empty() && _public_internet_address.empty()) { + SrsIPAddress* ip = ips[0]; + + srs_warn("use first address as ip: %s, ifname=%s", ip->ip.c_str(), ip->ifname.c_str()); + _public_internet_address = ip->ip; + return ip->ip; + } + + return ""; +} + +string srs_get_original_ip(ISrsHttpMessage* r) +{ + SrsHttpHeader* h = r->header(); + + string x_forwarded_for = h->get("X-Forwarded-For"); + if (!x_forwarded_for.empty()) { + size_t pos = string::npos; + if ((pos = x_forwarded_for.find(",")) == string::npos) { + return x_forwarded_for; + } + return x_forwarded_for.substr(0, pos); + } + + string x_real_ip = h->get("X-Real-IP"); + if (!x_real_ip.empty()) { + size_t pos = string::npos; + if ((pos = x_real_ip.find(":")) == string::npos) { + return x_real_ip; + } + return x_real_ip.substr(0, pos); + } + + return ""; +} + +std::string _srs_system_hostname; + +string srs_get_system_hostname() +{ + if (!_srs_system_hostname.empty()) { + return _srs_system_hostname; + } + + char buf[256]; + if (-1 == gethostname(buf, sizeof(buf))) { + srs_warn("gethostbyname fail"); + return ""; + } + + _srs_system_hostname = std::string(buf); + return _srs_system_hostname; +} + diff --git a/trunk/src/protocol/srs_protocol_utility.hpp b/trunk/src/protocol/srs_protocol_utility.hpp index 6f7173697a..9cecd70d2f 100644 --- a/trunk/src/protocol/srs_protocol_utility.hpp +++ b/trunk/src/protocol/srs_protocol_utility.hpp @@ -20,6 +20,14 @@ #include +#include +#include +#include + +#include + +class ISrsHttpMessage; + class SrsMessageHeader; class SrsSharedPtrMessage; class SrsCommonMessage; @@ -124,5 +132,50 @@ extern std::string srs_get_cidr_mask(std::string network_address); // Get the CIDR (Classless Inter-Domain Routing) IPv4 for a network address. extern std::string srs_get_cidr_ipv4(std::string network_address); +// Whether the url is starts with http:// or https:// +extern bool srs_string_is_http(std::string url); +extern bool srs_string_is_rtmp(std::string url); + +// Whether string is digit number +// is_digit("0") === true +// is_digit("0000000000") === true +// is_digit("1234567890") === true +// is_digit("0123456789") === true +// is_digit("1234567890a") === false +// is_digit("a1234567890") === false +// is_digit("10e3") === false +// is_digit("!1234567890") === false +// is_digit("") === false +extern bool srs_is_digit_number(std::string str); + +// Get local ip, fill to @param ips +struct SrsIPAddress +{ + // The network interface name, such as eth0, en0, eth1. + std::string ifname; + // The IP v4 or v6 address. + std::string ip; + // Whether the ip is IPv4 address. + bool is_ipv4; + // Whether the ip is internet public IP address. + bool is_internet; + // Whether the ip is loopback, such as 127.0.0.1 + bool is_loopback; +}; +extern std::vector& srs_get_local_ips(); + +// Get local public ip, empty string if no public internet address found. +extern std::string srs_get_public_internet_address(bool ipv4_only = false); + +// Detect whether specified device is internet public address. +extern bool srs_net_device_is_internet(std::string ifname); +extern bool srs_net_device_is_internet(const sockaddr* addr); + +// Get the original ip from query and header by proxy. +extern std::string srs_get_original_ip(ISrsHttpMessage* r); + +// Get hostname +extern std::string srs_get_system_hostname(void); + #endif diff --git a/trunk/src/protocol/srs_service_utility.cpp b/trunk/src/protocol/srs_service_utility.cpp deleted file mode 100644 index 53f7a1a5d9..0000000000 --- a/trunk/src/protocol/srs_service_utility.cpp +++ /dev/null @@ -1,385 +0,0 @@ -// -// Copyright (c) 2013-2021 The SRS Authors -// -// SPDX-License-Identifier: MIT or MulanPSL-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -#include -#include -#include -#include -#include -#include - -bool srs_string_is_http(string url) -{ - return srs_string_starts_with(url, "http://", "https://"); -} - -bool srs_string_is_rtmp(string url) -{ - return srs_string_starts_with(url, "rtmp://"); -} - -bool srs_is_digit_number(string str) -{ - if (str.empty()) { - return false; - } - - const char* p = str.c_str(); - const char* p_end = str.data() + str.length(); - for (; p < p_end; p++) { - if (*p != '0') { - break; - } - } - if (p == p_end) { - return true; - } - - int64_t v = ::atoll(p); - int64_t powv = (int64_t)pow(10, p_end - p - 1); - return v / powv >= 1 && v / powv <= 9; -} - -// we detect all network device as internet or intranet device, by its ip address. -// key is device name, for instance, eth0 -// value is whether internet, for instance, true. -static std::map _srs_device_ifs; - -bool srs_net_device_is_internet(string ifname) -{ - srs_info("check ifname=%s", ifname.c_str()); - - if (_srs_device_ifs.find(ifname) == _srs_device_ifs.end()) { - return false; - } - return _srs_device_ifs[ifname]; -} - -bool srs_net_device_is_internet(const sockaddr* addr) -{ - if(addr->sa_family == AF_INET) { - const in_addr inaddr = ((sockaddr_in*)addr)->sin_addr; - const uint32_t addr_h = ntohl(inaddr.s_addr); - - // lo, 127.0.0.0-127.0.0.1 - if (addr_h >= 0x7f000000 && addr_h <= 0x7f000001) { - return false; - } - - // Class A 10.0.0.0-10.255.255.255 - if (addr_h >= 0x0a000000 && addr_h <= 0x0affffff) { - return false; - } - - // Class B 172.16.0.0-172.31.255.255 - if (addr_h >= 0xac100000 && addr_h <= 0xac1fffff) { - return false; - } - - // Class C 192.168.0.0-192.168.255.255 - if (addr_h >= 0xc0a80000 && addr_h <= 0xc0a8ffff) { - return false; - } - } else if(addr->sa_family == AF_INET6) { - const sockaddr_in6* a6 = (const sockaddr_in6*)addr; - - // IPv6 loopback is ::1 - if (IN6_IS_ADDR_LOOPBACK(&a6->sin6_addr)) { - return false; - } - - // IPv6 unspecified is :: - if (IN6_IS_ADDR_UNSPECIFIED(&a6->sin6_addr)) { - return false; - } - - // From IPv4, you might know APIPA (Automatic Private IP Addressing) or AutoNet. - // Whenever automatic IP configuration through DHCP fails. - // The prefix of a site-local address is FE80::/10. - if (IN6_IS_ADDR_LINKLOCAL(&a6->sin6_addr)) { - return false; - } - - // Site-local addresses are equivalent to private IP addresses in IPv4. - // The prefix of a site-local address is FEC0::/10. - // https://4sysops.com/archives/ipv6-tutorial-part-6-site-local-addresses-and-link-local-addresses/ - if (IN6_IS_ADDR_SITELOCAL(&a6->sin6_addr)) { - return false; - } - - // Others. - if (IN6_IS_ADDR_MULTICAST(&a6->sin6_addr)) { - return false; - } - if (IN6_IS_ADDR_MC_NODELOCAL(&a6->sin6_addr)) { - return false; - } - if (IN6_IS_ADDR_MC_LINKLOCAL(&a6->sin6_addr)) { - return false; - } - if (IN6_IS_ADDR_MC_SITELOCAL(&a6->sin6_addr)) { - return false; - } - if (IN6_IS_ADDR_MC_ORGLOCAL(&a6->sin6_addr)) { - return false; - } - if (IN6_IS_ADDR_MC_GLOBAL(&a6->sin6_addr)) { - return false; - } - } - - return true; -} - -vector _srs_system_ips; - -void discover_network_iface(ifaddrs* cur, vector& ips, stringstream& ss0, stringstream& ss1, bool ipv6, bool loopback) -{ - char saddr[64]; - char* h = (char*)saddr; - socklen_t nbh = (socklen_t)sizeof(saddr); - const int r0 = getnameinfo(cur->ifa_addr, sizeof(sockaddr_storage), h, nbh, NULL, 0, NI_NUMERICHOST); - if(r0) { - srs_warn("convert local ip failed: %s", gai_strerror(r0)); - return; - } - - std::string ip(saddr, strlen(saddr)); - ss0 << ", iface[" << (int)ips.size() << "] " << cur->ifa_name << " " << (ipv6? "ipv6":"ipv4") - << " 0x" << std::hex << cur->ifa_flags << std::dec << " " << ip; - - SrsIPAddress* ip_address = new SrsIPAddress(); - ip_address->ip = ip; - ip_address->is_ipv4 = !ipv6; - ip_address->is_loopback = loopback; - ip_address->ifname = cur->ifa_name; - ip_address->is_internet = srs_net_device_is_internet(cur->ifa_addr); - ips.push_back(ip_address); - - // set the device internet status. - if (!ip_address->is_internet) { - ss1 << ", intranet "; - _srs_device_ifs[cur->ifa_name] = false; - } else { - ss1 << ", internet "; - _srs_device_ifs[cur->ifa_name] = true; - } - ss1 << cur->ifa_name << " " << ip; -} - -void retrieve_local_ips() -{ - vector& ips = _srs_system_ips; - - // Release previous IPs. - for (int i = 0; i < (int)ips.size(); i++) { - SrsIPAddress* ip = ips[i]; - srs_freep(ip); - } - ips.clear(); - - // Get the addresses. - ifaddrs* ifap; - if (getifaddrs(&ifap) == -1) { - srs_warn("retrieve local ips, getifaddrs failed."); - return; - } - - stringstream ss0; - ss0 << "ips"; - - stringstream ss1; - ss1 << "devices"; - - // Discover IPv4 first. - for (ifaddrs* p = ifap; p ; p = p->ifa_next) { - ifaddrs* cur = p; - - // Ignore if no address for this interface. - // @see https://github.com/ossrs/srs/issues/1087#issuecomment-408847115 - if (!cur->ifa_addr) { - continue; - } - - // retrieve IP address, ignore the tun0 network device, whose addr is NULL. - // @see: https://github.com/ossrs/srs/issues/141 - bool ipv4 = (cur->ifa_addr->sa_family == AF_INET); - bool ready = (cur->ifa_flags & IFF_UP) && (cur->ifa_flags & IFF_RUNNING); - // Ignore IFF_PROMISC(Interface is in promiscuous mode), which may be set by Wireshark. - bool ignored = (!cur->ifa_addr) || (cur->ifa_flags & IFF_LOOPBACK) || (cur->ifa_flags & IFF_POINTOPOINT); - bool loopback = (cur->ifa_flags & IFF_LOOPBACK); - if (ipv4 && ready && !ignored) { - discover_network_iface(cur, ips, ss0, ss1, false, loopback); - } - } - - // Then, discover IPv6 addresses. - for (ifaddrs* p = ifap; p ; p = p->ifa_next) { - ifaddrs* cur = p; - - // Ignore if no address for this interface. - // @see https://github.com/ossrs/srs/issues/1087#issuecomment-408847115 - if (!cur->ifa_addr) { - continue; - } - - // retrieve IP address, ignore the tun0 network device, whose addr is NULL. - // @see: https://github.com/ossrs/srs/issues/141 - bool ipv6 = (cur->ifa_addr->sa_family == AF_INET6); - bool ready = (cur->ifa_flags & IFF_UP) && (cur->ifa_flags & IFF_RUNNING); - bool ignored = (!cur->ifa_addr) || (cur->ifa_flags & IFF_POINTOPOINT) || (cur->ifa_flags & IFF_PROMISC) || (cur->ifa_flags & IFF_LOOPBACK); - bool loopback = (cur->ifa_flags & IFF_LOOPBACK); - if (ipv6 && ready && !ignored) { - discover_network_iface(cur, ips, ss0, ss1, true, loopback); - } - } - - // If empty, disover IPv4 loopback. - if (ips.empty()) { - for (ifaddrs* p = ifap; p ; p = p->ifa_next) { - ifaddrs* cur = p; - - // Ignore if no address for this interface. - // @see https://github.com/ossrs/srs/issues/1087#issuecomment-408847115 - if (!cur->ifa_addr) { - continue; - } - - // retrieve IP address, ignore the tun0 network device, whose addr is NULL. - // @see: https://github.com/ossrs/srs/issues/141 - bool ipv4 = (cur->ifa_addr->sa_family == AF_INET); - bool ready = (cur->ifa_flags & IFF_UP) && (cur->ifa_flags & IFF_RUNNING); - bool ignored = (!cur->ifa_addr) || (cur->ifa_flags & IFF_POINTOPOINT) || (cur->ifa_flags & IFF_PROMISC); - bool loopback = (cur->ifa_flags & IFF_LOOPBACK); - if (ipv4 && ready && !ignored) { - discover_network_iface(cur, ips, ss0, ss1, false, loopback); - } - } - } - - srs_trace("%s", ss0.str().c_str()); - srs_trace("%s", ss1.str().c_str()); - - freeifaddrs(ifap); -} - -vector& srs_get_local_ips() -{ - if (_srs_system_ips.empty()) { - retrieve_local_ips(); - } - - return _srs_system_ips; -} - -std::string _public_internet_address; - -string srs_get_public_internet_address(bool ipv4_only) -{ - if (!_public_internet_address.empty()) { - return _public_internet_address; - } - - std::vector& ips = srs_get_local_ips(); - - // find the best match public address. - for (int i = 0; i < (int)ips.size(); i++) { - SrsIPAddress* ip = ips[i]; - if (!ip->is_internet) { - continue; - } - if (ipv4_only && !ip->is_ipv4) { - continue; - } - - srs_warn("use public address as ip: %s, ifname=%s", ip->ip.c_str(), ip->ifname.c_str()); - _public_internet_address = ip->ip; - return ip->ip; - } - - // no public address, use private address. - for (int i = 0; i < (int)ips.size(); i++) { - SrsIPAddress* ip = ips[i]; - if (ip->is_loopback) { - continue; - } - if (ipv4_only && !ip->is_ipv4) { - continue; - } - - srs_warn("use private address as ip: %s, ifname=%s", ip->ip.c_str(), ip->ifname.c_str()); - _public_internet_address = ip->ip; - return ip->ip; - } - - // Finally, use first whatever kind of address. - if (!ips.empty() && _public_internet_address.empty()) { - SrsIPAddress* ip = ips[0]; - - srs_warn("use first address as ip: %s, ifname=%s", ip->ip.c_str(), ip->ifname.c_str()); - _public_internet_address = ip->ip; - return ip->ip; - } - - return ""; -} - -string srs_get_original_ip(ISrsHttpMessage* r) -{ - SrsHttpHeader* h = r->header(); - - string x_forwarded_for = h->get("X-Forwarded-For"); - if (!x_forwarded_for.empty()) { - size_t pos = string::npos; - if ((pos = x_forwarded_for.find(",")) == string::npos) { - return x_forwarded_for; - } - return x_forwarded_for.substr(0, pos); - } - - string x_real_ip = h->get("X-Real-IP"); - if (!x_real_ip.empty()) { - size_t pos = string::npos; - if ((pos = x_real_ip.find(":")) == string::npos) { - return x_real_ip; - } - return x_real_ip.substr(0, pos); - } - - return ""; -} - - -std::string _srs_system_hostname; - -string srs_get_system_hostname() -{ - if (!_srs_system_hostname.empty()) { - return _srs_system_hostname; - } - - char buf[256]; - if (-1 == gethostname(buf, sizeof(buf))) { - srs_warn("gethostbyname fail"); - return ""; - } - - _srs_system_hostname = std::string(buf); - return _srs_system_hostname; -} diff --git a/trunk/src/protocol/srs_service_utility.hpp b/trunk/src/protocol/srs_service_utility.hpp deleted file mode 100644 index d6b130e7f3..0000000000 --- a/trunk/src/protocol/srs_service_utility.hpp +++ /dev/null @@ -1,66 +0,0 @@ -// -// Copyright (c) 2013-2021 The SRS Authors -// -// SPDX-License-Identifier: MIT or MulanPSL-2.0 -// - -#ifndef SRS_SERVICE_UTILITY_HPP -#define SRS_SERVICE_UTILITY_HPP - -#include - -#include -#include -#include - -#include - -class ISrsHttpMessage; - -// Whether the url is starts with http:// or https:// -extern bool srs_string_is_http(std::string url); -extern bool srs_string_is_rtmp(std::string url); - -// Whether string is digit number -// is_digit("0") === true -// is_digit("0000000000") === true -// is_digit("1234567890") === true -// is_digit("0123456789") === true -// is_digit("1234567890a") === false -// is_digit("a1234567890") === false -// is_digit("10e3") === false -// is_digit("!1234567890") === false -// is_digit("") === false -extern bool srs_is_digit_number(std::string str); - -// Get local ip, fill to @param ips -struct SrsIPAddress -{ - // The network interface name, such as eth0, en0, eth1. - std::string ifname; - // The IP v4 or v6 address. - std::string ip; - // Whether the ip is IPv4 address. - bool is_ipv4; - // Whether the ip is internet public IP address. - bool is_internet; - // Whether the ip is loopback, such as 127.0.0.1 - bool is_loopback; -}; -extern std::vector& srs_get_local_ips(); - -// Get local public ip, empty string if no public internet address found. -extern std::string srs_get_public_internet_address(bool ipv4_only = false); - -// Detect whether specified device is internet public address. -extern bool srs_net_device_is_internet(std::string ifname); -extern bool srs_net_device_is_internet(const sockaddr* addr); - -// Get the original ip from query and header by proxy. -extern std::string srs_get_original_ip(ISrsHttpMessage* r); - -// Get hostname -extern std::string srs_get_system_hostname(void); - -#endif - diff --git a/trunk/src/utest/srs_utest_app.cpp b/trunk/src/utest/srs_utest_app.cpp index 728f87ff9e..55c5bdc750 100644 --- a/trunk/src/utest/srs_utest_app.cpp +++ b/trunk/src/utest/srs_utest_app.cpp @@ -13,7 +13,7 @@ using namespace std; #include #include -#include +#include #include class MockIDResource : public ISrsResource diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index b36700b69b..87551e3342 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -13,7 +13,7 @@ using namespace std; #include #include #include -#include +#include #include #include diff --git a/trunk/src/utest/srs_utest_http.cpp b/trunk/src/utest/srs_utest_http.cpp index c32fa77ac7..b8d3700f0b 100644 --- a/trunk/src/utest/srs_utest_http.cpp +++ b/trunk/src/utest/srs_utest_http.cpp @@ -9,14 +9,14 @@ using namespace std; #include -#include +#include #include #include #include #include #include #include -#include +#include #include class MockMSegmentsReader : public ISrsReader diff --git a/trunk/src/utest/srs_utest_http.hpp b/trunk/src/utest/srs_utest_http.hpp index 2f701c2515..1f0dec8378 100644 --- a/trunk/src/utest/srs_utest_http.hpp +++ b/trunk/src/utest/srs_utest_http.hpp @@ -14,7 +14,7 @@ #include #include -#include +#include #include using namespace std; diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index 8a3347c35c..2be8a1a79c 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -16,7 +16,7 @@ using namespace std; #include #include #include -#include +#include MockEmptyIO::MockEmptyIO() { diff --git a/trunk/src/utest/srs_utest_rtmp.cpp b/trunk/src/utest/srs_utest_rtmp.cpp index df453df5f3..bc6ea69394 100644 --- a/trunk/src/utest/srs_utest_rtmp.cpp +++ b/trunk/src/utest/srs_utest_rtmp.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/trunk/src/utest/srs_utest_service.cpp b/trunk/src/utest/srs_utest_service.cpp index ed77da08a8..6113f83917 100644 --- a/trunk/src/utest/srs_utest_service.cpp +++ b/trunk/src/utest/srs_utest_service.cpp @@ -9,19 +9,19 @@ using namespace std; #include #include -#include -#include +#include +#include -#include -#include +#include +#include #include #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/trunk/src/utest/srs_utest_service.hpp b/trunk/src/utest/srs_utest_service.hpp index 7929982ba4..1f2b6b787c 100644 --- a/trunk/src/utest/srs_utest_service.hpp +++ b/trunk/src/utest/srs_utest_service.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include class MockSrsConnection : public ISrsConnection {