For #1508, Refactor srs_is_digital, support all zeros.

pull/1568/head
winlin 5 years ago
parent cee4feda61
commit 4382ced3bf

@ -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.
* <strong>v3.0, 2019-12-19, [3.0 alpha5(3.0.75)][r3.0a5] released. 115362 lines.</strong>
* 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

@ -29,7 +29,6 @@
#include <arpa/inet.h>
#include <signal.h>
#include <sys/wait.h>
#include <math.h>
#include <netdb.h>
#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";

@ -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

@ -28,6 +28,8 @@
#include <net/if.h>
#include <ifaddrs.h>
#include <netdb.h>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sstream>
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.

@ -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<std::string>& srs_get_local_ips();

Loading…
Cancel
Save