1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-14 12:21:55 +00:00

Replace hex to string to match MIT license. 3.0.33

This commit is contained in:
winlin 2018-07-22 18:47:38 +08:00
parent 84f81983aa
commit 41c6e833b9
6 changed files with 68 additions and 29 deletions

View file

@ -184,6 +184,7 @@ Please select according to languages:
### V3 changes
* v3.0, 2018-07-22, Replace hex to string to match MIT license. 3.0.33
* v3.0, 2018-07-22, Replace base64 to match MIT license. 3.0.32
* v3.0, 2018-07-22, Replace crc32 IEEE and MPEG by pycrc to match MIT license. 3.0.31
* v3.0, 2018-07-21, Replace crc32 IEEE by golang to match MIT license. 3.0.30

View file

@ -27,7 +27,7 @@
// current release version
#define VERSION_MAJOR 3
#define VERSION_MINOR 0
#define VERSION_REVISION 32
#define VERSION_REVISION 33
// generated by configure, only macros.
#include <srs_auto_headers.hpp>

View file

@ -948,33 +948,44 @@ int av_toupper(int c)
}
return c;
}
int ff_hex_to_data(uint8_t* data, const char* p)
{
int c, len, v;
len = 0;
v = 1;
for (;;) {
p += strspn(p, SPACE_CHARS);
if (*p == '\0')
break;
c = av_toupper((unsigned char) *p++);
if (c >= '0' && c <= '9')
c = c - '0';
else if (c >= 'A' && c <= 'F')
c = c - 'A' + 10;
else
break;
v = (v << 4) | c;
if (v & 0x100) {
if (data)
data[len] = v;
len++;
v = 1;
}
// fromHexChar converts a hex character into its value and a success flag.
uint8_t srs_from_hex_char(uint8_t c)
{
if ('0' <= c && c <= '9') {
return c - '0';
}
return len;
if ('a' <= c && c <= 'f') {
return c - 'a' + 10;
}
if ('A' <= c && c <= 'F') {
return c - 'A' + 10;
}
return -1;
}
int srs_hex_to_data(uint8_t* data, const char* p, int size)
{
if (size <= 0 || (size%2) == 1) {
return -1;
}
for (int i = 0; i < size / 2; i++) {
uint8_t a = srs_from_hex_char(p[i*2]);
if (a == (uint8_t)-1) {
return -1;
}
uint8_t b = srs_from_hex_char(p[i*2 + 1]);
if (b == (uint8_t)-1) {
return -1;
}
data[i] = (a << 4) | b;
}
return size / 2;
}
int srs_chunk_header_c0(int perfer_cid, uint32_t timestamp, int32_t payload_length, int8_t message_type, int32_t stream_id, char* cache, int nb_cache)

View file

@ -161,7 +161,7 @@ extern srs_error_t srs_av_base64_decode(std::string cipher, std::string& plainte
* for example, p=config='139056E5A0'
* output hex to data={0x13, 0x90, 0x56, 0xe5, 0xa0}
*/
extern int ff_hex_to_data(uint8_t* data, const char* p);
extern int srs_hex_to_data(uint8_t* data, const char* p, int size);
/**
* generate the c0 chunk header for msg.

View file

@ -537,8 +537,12 @@ srs_error_t SrsRtspSdp::parse_fmtp_attribute(string attr)
char* tmp_sh = new char[item_value.length()];
SrsAutoFreeA(char, tmp_sh);
int nb_tmp_sh = ff_hex_to_data((uint8_t*)tmp_sh, item_value.c_str());
srs_assert(nb_tmp_sh > 0);
int nb_tmp_sh = srs_hex_to_data((uint8_t*)tmp_sh, item_value.c_str(), item_value.length());
if (nb_tmp_sh <= 0) {
return srs_error_new(ERROR_RTSP_AUDIO_CONFIG, "audio config");
}
audio_sh.append(tmp_sh, nb_tmp_sh);
}
}

View file

@ -1684,5 +1684,28 @@ VOID TEST(KernelUtility, Base64Decode)
EXPECT_TRUE(expect == plaintext);
}
VOID TEST(KernelUtility, StringToHex)
{
if (true) {
uint8_t h[16];
EXPECT_EQ(-1, srs_hex_to_data(h, NULL, 0));
EXPECT_EQ(-1, srs_hex_to_data(h, "0", 1));
EXPECT_EQ(-1, srs_hex_to_data(h, "0g", 2));
}
if (true) {
string s = "139056E5A0";
uint8_t h[16];
int n = srs_hex_to_data(h, s.data(), s.length());
EXPECT_EQ(n, 5);
EXPECT_EQ(0x13, h[0]);
EXPECT_EQ(0x90, h[1]);
EXPECT_EQ(0x56, h[2]);
EXPECT_EQ(0xe5, h[3]);
EXPECT_EQ(0xa0, h[4]);
}
}
#endif