int SrsHandshakeBytes::create_s0s1s2(const char* c1) { int ret = ERROR_SUCCESS; if (s0s1s2) { return ret; } s0s1s2 = new char[3073]; srs_random_generate(s0s1s2, 3073); // plain text required. SrsStream stream; if ((ret = stream.initialize(s0s1s2, 9)) != ERROR_SUCCESS) { return ret; } stream.write_1bytes(0x03); stream.write_4bytes(::time(NULL)); // s2 time2 copy from c1 if (c0c1) { stream.write_bytes(c0c1 + 1, 4); } // if c1 specified, copy c1 to s2. // @see: https://github.com/winlinvip/simple-rtmp-server/issues/46 if (c1) { memcpy(s0s1s2 + 1537, c1, 1536); } return ret; }
// read/write stream using SrsStream. void __srs_stream_write_4bytes(char* pp, int32_t value) { static SrsStream stream; int ret = stream.initialize(pp, 4); srs_assert(ret == ERROR_SUCCESS); stream.write_4bytes(value); }
/** * test the stream utility, write 34bytes */ VOID TEST(KernelStreamTest, StreamWrite4Bytes) { SrsStream s; char data[1024]; EXPECT_TRUE(ERROR_SUCCESS == s.initialize(data, 1024)); s.write_4bytes(0x10111213); s.write_4bytes(0x14151617); s.write_4bytes(0x18192021); s.skip(-1 * s.pos()); EXPECT_EQ(0x10, s.read_1bytes()); s.skip(2); EXPECT_EQ(0x13, s.read_1bytes()); s.skip(5); EXPECT_EQ(0x19, s.read_1bytes()); }
int SrsHandshakeBytes::create_c0c1() { int ret = ERROR_SUCCESS; if (c0c1) { return ret; } c0c1 = new char[1537]; srs_random_generate(c0c1, 1537); // plain text required. static SrsStream stream; if ((ret = stream.initialize(c0c1, 9)) != ERROR_SUCCESS) { return ret; } stream.write_1bytes(0x03); stream.write_4bytes(::time(NULL)); stream.write_4bytes(0x00); return ret; }
int SrsHandshakeBytes::create_c2() { int ret = ERROR_SUCCESS; if (c2) { return ret; } c2 = new char[1536]; srs_random_generate(c2, 1536); // time SrsStream stream; if ((ret = stream.initialize(c2, 8)) != ERROR_SUCCESS) { return ret; } stream.write_4bytes(::time(NULL)); // c2 time2 copy from s1 if (s0s1s2) { stream.write_bytes(s0s1s2 + 1, 4); } return ret; }