From aaa7cdbdabca3f813de1a0857637481a1fec5736 Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 22 Jul 2018 23:31:19 +0930 Subject: [PATCH] Ported SocksSetup and tested --- rtmp/rtmp.go | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 752b8beb..69b78689 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -354,7 +354,7 @@ func (s *session) Write(data []byte) (int, error) { if s.rtmp == nil { return 0, Err(3) } - // TODO: port this + if rtmpIsConnected(s.rtmp) == 0 { return 0, Err(1) } @@ -472,8 +472,8 @@ func rtmpSetupUrl(r *C.RTMP, u string) int32 { r.Link.tcUrl.av_len = C.int(strlen(url)) } } - // TODO: port this - C.SocksSetup(r, &r.Link.sockshost) + + socksSetup(r, &r.Link.sockshost) if r.Link.port == 0 { switch { @@ -488,6 +488,32 @@ func rtmpSetupUrl(r *C.RTMP, u string) int32 { return 1 } +func socksSetup(r *C.RTMP, sockshost *C.AVal) { + if sockshost.av_len != 0 { + socksport := strchr((*byte)(unsafe.Pointer(sockshost.av_val)), ':') + hostname := strdup((*byte)(unsafe.Pointer(sockshost.av_val))) + + if uintptr(unsafe.Pointer(socksport)) != 0 { + *indxBytePtr(unsafe.Pointer(hostname), + int(uintptr(decBytePtr(unsafe.Pointer(socksport), + int(uintptr(unsafe.Pointer(sockshost.av_val))))))) = '\000' + r.Link.sockshost.av_val = (*C.char)(unsafe.Pointer(hostname)) + r.Link.sockshost.av_len = C.int(strlen(hostname)) + + value, err := strconv.Atoi(string(ptrToSlice(unsafe.Pointer(uintptr( + unsafe.Pointer(socksport))+uintptr(1)), int(strlen((*byte)(unsafe.Pointer( + uintptr(unsafe.Pointer(socksport))+uintptr(1)))))+1))) + if err != nil { + log.Println("socksSetup: bad string conversion!") + } + if uintptr(unsafe.Pointer(socksport)) == 0 { + value = 1080 + } + r.Link.socksport = C.ushort(value) + } + } +} + /* func rtmpClose(r *C.RTMP) { closeInternal(r, 0) @@ -679,15 +705,6 @@ func rtmpConnect1(r *C.RTMP, cp *C.RTMPPacket) int { return 1 } -/* -func socksSetup(r *RTMP, sockshost *AVal) { - if sockshost.av_len != 0 { - socksport := strchr((*byte)(unsafe.Pointer(sockshost.av_val)), ':') - hostname := strdup((*byte)(unsafe.Pointer(sockshost.av_val))) - } -} -*/ - func rtmpConnectStream(r *C.RTMP, seekTime int32) int { var packet C.RTMPPacket