mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #2424, use srandom/random to generate. 4.0.139
This commit is contained in:
parent
e802fe5bd6
commit
642359a50e
14 changed files with 28 additions and 34 deletions
|
@ -131,39 +131,38 @@ void srs_parse_query_string(string q, map<string,string>& query)
|
|||
}
|
||||
}
|
||||
|
||||
static bool _random_initialized = false;
|
||||
|
||||
void srs_random_generate(char* bytes, int size)
|
||||
{
|
||||
if (!_random_initialized) {
|
||||
_random_initialized = true;
|
||||
::srandom((unsigned long)(srs_update_system_time() | (::getpid()<<13)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
// the common value in [0x0f, 0xf0]
|
||||
bytes[i] = 0x0f + (random() % (256 - 0x0f - 0x0f));
|
||||
bytes[i] = 0x0f + (srs_random() % (256 - 0x0f - 0x0f));
|
||||
}
|
||||
}
|
||||
|
||||
std::string srs_random_str(int len)
|
||||
{
|
||||
if (!_random_initialized) {
|
||||
_random_initialized = true;
|
||||
::srandom((unsigned long)(srs_update_system_time() | (::getpid()<<13)));
|
||||
}
|
||||
|
||||
static string random_table = "01234567890123456789012345678901234567890123456789abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
string ret;
|
||||
ret.reserve(len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
ret.append(1, random_table[random() % random_table.size()]);
|
||||
ret.append(1, random_table[srs_random() % random_table.size()]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
long srs_random()
|
||||
{
|
||||
static bool _random_initialized = false;
|
||||
if (!_random_initialized) {
|
||||
_random_initialized = true;
|
||||
::srandom((unsigned long)(srs_update_system_time() | (::getpid()<<13)));
|
||||
}
|
||||
|
||||
return random();
|
||||
}
|
||||
|
||||
string srs_generate_tc_url(string host, string vhost, string app, int port)
|
||||
{
|
||||
string tcUrl = "rtmp://";
|
||||
|
|
|
@ -55,6 +55,9 @@ extern void srs_random_generate(char* bytes, int size);
|
|||
// Generate random string [0-9a-z] in size of len bytes.
|
||||
extern std::string srs_random_str(int len);
|
||||
|
||||
// Generate random value, use srandom(now_us) to init seed if not initialized.
|
||||
extern long srs_random();
|
||||
|
||||
/**
|
||||
* generate the tcUrl without param.
|
||||
* @remark Use host as tcUrl.vhost if vhost is default vhost.
|
||||
|
|
|
@ -341,7 +341,7 @@ namespace srs_internal
|
|||
|
||||
key_block::key_block()
|
||||
{
|
||||
offset = (int32_t)rand();
|
||||
offset = (int32_t)srs_random();
|
||||
random0 = NULL;
|
||||
random1 = NULL;
|
||||
|
||||
|
@ -423,7 +423,7 @@ namespace srs_internal
|
|||
|
||||
digest_block::digest_block()
|
||||
{
|
||||
offset = (int32_t)rand();
|
||||
offset = (int32_t)srs_random();
|
||||
random0 = NULL;
|
||||
random1 = NULL;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue