diff --git a/README.md b/README.md index 09989d4b5..16eaf0437 100755 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2019-12-20, For [#1508][bug #1508], Refactor srs_is_digital, support all zeros. * v3.0, 2019-12-19, [3.0 alpha5(3.0.75)][r3.0a5] released. 115362 lines. * v3.0, 2019-12-19, Refine the RTMP iovs cache increasing to much faster. * v3.0, 2019-12-19, Fix [#1524][bug #1524], memory leak for amf0 strict array. 3.0.75 @@ -1541,6 +1542,7 @@ Winlin [bug #1506]: https://github.com/ossrs/srs/issues/1506 [bug #1520]: https://github.com/ossrs/srs/issues/1520 [bug #1223]: https://github.com/ossrs/srs/issues/1223 +[bug #1508]: https://github.com/ossrs/srs/issues/1508 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index 6ea2ba0f8..9c6343860 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #ifdef SRS_OSX @@ -1158,17 +1157,6 @@ string srs_get_peer_ip(int fd) return std::string(saddr); } -bool srs_is_digit_number(const string& str) -{ - if (str.empty()) { - return false; - } - - int v = ::atoi(str.c_str()); - int powv = (int)pow(10, str.length() - 1); - return v / powv >= 1 && v / powv <= 9; -} - bool srs_is_boolean(const string& str) { return str == "true" || str == "false"; diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index e058e0a93..5e4d09afe 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -640,12 +640,6 @@ extern int srs_get_local_port(int fd); // Where peer ip is the client public ip which connected to server. extern std::string srs_get_peer_ip(int fd); -// Whether string is digit number -// is_digit("1234567890") === true -// is_digit("0123456789") === false -// is_digit("1234567890a") === false -// is_digit("a1234567890") === false -extern bool srs_is_digit_number(const std::string& str); // Whether string is boolean // is_bool("true") == true // is_bool("false") == true diff --git a/trunk/src/service/srs_service_utility.cpp b/trunk/src/service/srs_service_utility.cpp index 434cd9d4d..e6312d272 100644 --- a/trunk/src/service/srs_service_utility.cpp +++ b/trunk/src/service/srs_service_utility.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include using namespace std; @@ -48,6 +50,28 @@ bool srs_string_is_rtmp(string url) return srs_string_starts_with(url, "rtmp://"); } +bool srs_is_digit_number(const 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. diff --git a/trunk/src/service/srs_service_utility.hpp b/trunk/src/service/srs_service_utility.hpp index 86a8e85e8..d9896c13d 100644 --- a/trunk/src/service/srs_service_utility.hpp +++ b/trunk/src/service/srs_service_utility.hpp @@ -36,6 +36,18 @@ 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(const std::string& str); + // Get local ip, fill to @param ips extern std::vector& srs_get_local_ips();