mirror of https://bitbucket.org/ausocean/av.git
Still writing handShake func and also created new memcmp func
This commit is contained in:
parent
4eff566a73
commit
3e0d1a01d2
68
rtmp/rtmp.go
68
rtmp/rtmp.go
|
@ -52,7 +52,7 @@ RTMP* start_session(RTMP* rtmp, char* url, uint connect_timeout);
|
|||
int write_frame(RTMP* rtmp, char* data, uint data_length);
|
||||
int end_session(RTMP* rtmp);
|
||||
void AV_queue(RTMP_METHOD **vals, int *num, AVal *av, int txn);
|
||||
int WriteN(RTMP *r, const char *buffer, int n);
|
||||
int writeN(RTMP *r, const char *buffer, int n);
|
||||
int EncodeInt32LE(char *output, int nVal);
|
||||
int HTTP_Post(RTMP *r, RTMPTCmd cmd, const char *buf, int len);
|
||||
*/
|
||||
|
@ -709,7 +709,7 @@ func rtmpConnect1(r *C.RTMP, cp *C.RTMPPacket) int {
|
|||
|
||||
// TODO: complete this
|
||||
|
||||
/*
|
||||
|
||||
func handShake(r *C.RTMP, FP9HandShake int32) int {
|
||||
var i, bMatch int
|
||||
var uptime, suptime uint32
|
||||
|
@ -732,9 +732,51 @@ func handShake(r *C.RTMP, FP9HandShake int32) int {
|
|||
*indxBytePtr(unsafe.Pointer(clientsig), i) = byte(rand.Intn(256))
|
||||
}
|
||||
|
||||
}
|
||||
if writeN(r, clientbuf, RTMP_SIG_SIZE+1) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
*/
|
||||
// TODO: port this
|
||||
if ReadN(r, &type, 1) != 1 {
|
||||
return 0
|
||||
}
|
||||
|
||||
if debugMode {
|
||||
log.Println("handShake: Type answer: %v", t)
|
||||
}
|
||||
if t != clientbuf[0] {
|
||||
log.Println("handShake: type mismatch: client sent %v, server sent: %v",
|
||||
clientbuf[0], t)
|
||||
}
|
||||
|
||||
if ReadN(r, serversig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE {
|
||||
return 0
|
||||
}
|
||||
|
||||
// decode server response
|
||||
memmove(unsafe.Pointer(&suptime), serversig, 4)
|
||||
suptime = inet.Ntohl(suptime)
|
||||
|
||||
// 2nd part of handshake
|
||||
if writeN(r, serversig, RTMP_SIG_SIZE) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
if ReadN(r, serversig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE {
|
||||
return 0
|
||||
}
|
||||
|
||||
// TODO: find golang memcmp
|
||||
bMatch = 0
|
||||
if memcmp(serversig,clientsig,RTMP_SIG_SIZE) == 0 {
|
||||
bMatch = 1
|
||||
}
|
||||
|
||||
if bMatch != 0 {
|
||||
log.Println("Client signature does not match!")
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
func rtmpConnectStream(r *C.RTMP, seekTime int32) int {
|
||||
var packet C.RTMPPacket
|
||||
|
@ -1290,7 +1332,7 @@ func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int {
|
|||
|
||||
if nBytes < 0 {
|
||||
if debugMode {
|
||||
log.Println("WriteN, RTMP send error")
|
||||
log.Println("writeN, RTMP send error")
|
||||
}
|
||||
|
||||
// TODO: port this
|
||||
|
@ -1345,6 +1387,22 @@ func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int) {
|
|||
int(unsafe.Sizeof(rtmpMethodPtr))))).name.av_val = (*C.char)(tmp)
|
||||
}
|
||||
|
||||
// TODO: write test for this func
|
||||
func memcmp(a,b unsafe.Pointer, size int) int {
|
||||
for i := 0; i < size; i++ {
|
||||
aValue := *indxBytePtr(a,i)
|
||||
bValue := *indxBytePtr(b,i)
|
||||
if aValue != bValue {
|
||||
if aValue < bValue {
|
||||
return -1
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func memset(ptr *byte, val byte, num int) {
|
||||
for i := 0; i < num; i++ {
|
||||
*indxBytePtr(unsafe.Pointer(ptr), int(i)) = val
|
||||
|
|
Loading…
Reference in New Issue