@@ -2,7 +2,9 @@ package gotox
2
2
3
3
//#include <tox/tox.h>
4
4
import "C"
5
+ import "encoding/hex"
5
6
import "unsafe"
7
+ import "unicode/utf8"
6
8
7
9
//export hook_callback_self_connection_status
8
10
func hook_callback_self_connection_status (t unsafe.Pointer , status C.enum_TOX_CONNECTION , tox unsafe.Pointer ) {
@@ -11,12 +13,12 @@ func hook_callback_self_connection_status(t unsafe.Pointer, status C.enum_TOX_CO
11
13
12
14
//export hook_callback_friend_name
13
15
func hook_callback_friend_name (t unsafe.Pointer , friendnumber C.uint32_t , name * C.uint8_t , length C.size_t , tox unsafe.Pointer ) {
14
- (* Tox )(tox ).onFriendNameChanges ((* Tox )(tox ), uint32 (friendnumber ), string (C .GoBytes (( unsafe .Pointer ) (name ), ( C .int ) (length ))))
16
+ (* Tox )(tox ).onFriendNameChanges ((* Tox )(tox ), uint32 (friendnumber ), string (C .GoBytes (unsafe .Pointer (name ), C .int (length ))))
15
17
}
16
18
17
19
//export hook_callback_friend_status_message
18
- func hook_callback_friend_status_message (t unsafe.Pointer , friendnumber C.uint32_t , message * C.uint8_t , length C.uint16_t , tox unsafe.Pointer ) {
19
- (* Tox )(tox ).onFriendStatusMessageChanges ((* Tox )(tox ), uint32 (friendnumber ), string (C .GoBytes (( unsafe .Pointer ) (message ), ( C .int ) (length ))))
20
+ func hook_callback_friend_status_message (t unsafe.Pointer , friendnumber C.uint32_t , message * C.uint8_t , length C.size_t , tox unsafe.Pointer ) {
21
+ (* Tox )(tox ).onFriendStatusMessageChanges ((* Tox )(tox ), uint32 (friendnumber ), string (C .GoBytes (unsafe .Pointer (message ), C .int (length ))))
20
22
}
21
23
22
24
//export hook_callback_friend_status
@@ -41,12 +43,12 @@ func hook_callback_friend_read_receipt(t unsafe.Pointer, friendnumber C.uint32_t
41
43
42
44
//export hook_callback_friend_request
43
45
func hook_callback_friend_request (t unsafe.Pointer , publicKey * C.uint8_t , message * C.uint8_t , length C.size_t , tox unsafe.Pointer ) {
44
- (* Tox )(tox ).onFriendRequest ((* Tox )(tox ), C .GoBytes ((unsafe .Pointer )(publicKey ), TOX_PUBLIC_KEY_SIZE ), string (C .GoBytes (( unsafe .Pointer ) (message ), ( C .int ) (length ))))
46
+ (* Tox )(tox ).onFriendRequest ((* Tox )(tox ), C .GoBytes ((unsafe .Pointer )(publicKey ), TOX_PUBLIC_KEY_SIZE ), string (C .GoBytes (unsafe .Pointer (message ), C .int (length ))))
45
47
}
46
48
47
49
//export hook_callback_friend_message
48
50
func hook_callback_friend_message (t unsafe.Pointer , friendnumber C.uint32_t , messagetype C.enum_TOX_MESSAGE_TYPE , message * C.uint8_t , length C.size_t , tox unsafe.Pointer ) {
49
- (* Tox )(tox ).onFriendMessage ((* Tox )(tox ), uint32 (friendnumber ), ToxMessageType (messagetype ), string (C .GoBytes (( unsafe .Pointer ) (message ), ( C .int ) (length ))))
51
+ (* Tox )(tox ).onFriendMessage ((* Tox )(tox ), uint32 (friendnumber ), ToxMessageType (messagetype ), string (C .GoBytes (unsafe .Pointer (message ), C .int (length ))))
50
52
}
51
53
52
54
//export hook_callback_file_recv_control
@@ -60,18 +62,26 @@ func hook_callback_file_chunk_request(t unsafe.Pointer, friendnumber C.uint32_t,
60
62
}
61
63
62
64
//export hook_callback_file_recv
63
- func hook_callback_file_recv (t unsafe.Pointer , friendnumber C.uint32_t , filenumber C.uint32_t , kind C.uint32_t , filesize C.uint64_t , filename * C.uint8_t , filenamelength C.size_t , tox unsafe.Pointer ) {
64
- (* Tox )(tox ).onFileRecv ((* Tox )(tox ), uint32 (friendnumber ), uint32 (filenumber ), ToxFileKind (kind ), uint64 (filesize ), string (C .GoBytes ((unsafe .Pointer )(filename ), (C .int )(filenamelength ))))
65
+ func hook_callback_file_recv (t unsafe.Pointer , friendnumber C.uint32_t , filenumber C.uint32_t , kind C.uint32_t , filesize C.uint64_t , filename * C.uint8_t , filenameLength C.size_t , tox unsafe.Pointer ) {
66
+ // convert the filename from CString to a GoString and encode hexadecimal if needed
67
+ goFilenameBytes := C .GoBytes (unsafe .Pointer (filename ), C .int (filenameLength ))
68
+ goFilename := string (goFilenameBytes )
69
+
70
+ if ! utf8 .ValidString (goFilename ) {
71
+ goFilename = hex .EncodeToString (goFilenameBytes )
72
+ }
73
+
74
+ (* Tox )(tox ).onFileRecv ((* Tox )(tox ), uint32 (friendnumber ), uint32 (filenumber ), ToxFileKind (kind ), uint64 (filesize ), goFilename )
65
75
}
66
76
67
77
//export hook_callback_file_recv_chunk
68
78
func hook_callback_file_recv_chunk (t unsafe.Pointer , friendnumber C.uint32_t , filenumber C.uint32_t , position C.uint64_t , data * C.uint8_t , length C.size_t , tox unsafe.Pointer ) {
69
- (* Tox )(tox ).onFileRecvChunk ((* Tox )(tox ), uint32 (friendnumber ), uint32 (filenumber ), uint64 (position ), C .GoBytes ((unsafe .Pointer )(data ), ( C .int ) (length )))
79
+ (* Tox )(tox ).onFileRecvChunk ((* Tox )(tox ), uint32 (friendnumber ), uint32 (filenumber ), uint64 (position ), C .GoBytes ((unsafe .Pointer )(data ), C .int (length )))
70
80
}
71
81
72
82
//export hook_callback_friend_lossy_packet
73
83
func hook_callback_friend_lossy_packet (t unsafe.Pointer , friendnumber C.uint32_t , data * C.uint8_t , length C.size_t , tox unsafe.Pointer ) {
74
- (* Tox )(tox ).onFriendLossyPacket ((* Tox )(tox ), uint32 (friendnumber ), C .GoBytes ((unsafe .Pointer )(data ), ( C .int ) (length )))
84
+ (* Tox )(tox ).onFriendLossyPacket ((* Tox )(tox ), uint32 (friendnumber ), C .GoBytes ((unsafe .Pointer )(data ), C .int (length )))
75
85
}
76
86
77
87
//export hook_callback_friend_lossless_packet
0 commit comments