Ported strstr() from c to go for use in librtmp.go

This commit is contained in:
saxon 2018-08-10 23:22:53 +09:30
parent 85de75a4c6
commit e552384a42
1 changed files with 57 additions and 0 deletions

View File

@ -593,6 +593,27 @@ func C_RTMP_SetupURL(r *C.RTMP, u string) int32 {
return 1 return 1
} }
// int RTMP_ParseURL(const char *url, int *protocol, AVal *host, unsigned int *port,
// AVal *playpath, AVal *app);
// parseurl.c +33
func C_RTMP_ParseURL(url *byte, protocol *int32, host *C.AVal, port *uint32,
playpath *C.AVal, app *C.AVal) {
var p, end, col, ques, slash *byte
// RTMP_Log(RTMP_LOGDEBUG, "Parsing...");
*protocol = RTMP_PROTOCOL_RTMP
*port = 0
playpath.av_len = 0
playpath.av_val = nil
app.av_len = 0
app.av_val = nil
p = str
}
// void SocksSetup(RTMP *r, C.AVal* sockshost); // void SocksSetup(RTMP *r, C.AVal* sockshost);
// rtmp.c +410 // rtmp.c +410
func C_SocksSetup(r *C.RTMP, sockshost *C.AVal) { func C_SocksSetup(r *C.RTMP, sockshost *C.AVal) {
@ -2353,6 +2374,42 @@ func strchr(str *byte, val byte) *byte {
return nil return nil
} }
// Porting: http://www.ai.mit.edu/projects/im/cam8/cam8/working/CAMlib/tcl/compat/strstr.c
func strstr(str *byte, substring *byte) *byte {
var a, b *byte
/* First scan quickly through the two strings looking for a
* single-character match. When it's found, then compare the
* rest of the substring.
*/
b = substring
if *b == 0 {
return str
}
for *str != 0 {
str = (*byte)(incBytePtr(unsafe.Pointer(str), 1))
if *str != *b {
continue
}
a = str
for {
if *b == 0 {
return str
}
tmp1 := a
a = (*byte)(incBytePtr(unsafe.Pointer(a), 1))
tmp2 := b
b = (*byte)(incBytePtr(unsafe.Pointer(b), 1))
if *tmp1 != *tmp2 {
break
}
}
b = substring
}
return nil
}
// Creates mem of the size noOfBytes. returns as unsafe pointer // Creates mem of the size noOfBytes. returns as unsafe pointer
func allocate(nOfBytes uintptr) unsafe.Pointer { func allocate(nOfBytes uintptr) unsafe.Pointer {
mem := make([]byte, int(nOfBytes)) mem := make([]byte, int(nOfBytes))