@@ -60,6 +60,7 @@ struct Tox {
6060 Mono_Time * mono_time ;
6161 pthread_mutex_t * mutex ;
6262
63+ tox_log_cb * log_callback ;
6364 tox_self_connection_status_cb * self_connection_status_callback ;
6465 tox_friend_name_cb * friend_name_callback ;
6566 tox_friend_status_message_cb * friend_status_message_callback ;
@@ -107,6 +108,17 @@ struct Tox_Userdata {
107108 void * user_data ;
108109};
109110
111+ static logger_cb tox_log_handler ;
112+ non_null (1 , 3 , 5 , 6 ) nullable (7 )
113+ static void tox_log_handler (void * context , Logger_Level level , const char * file , int line , const char * func ,
114+ const char * message , void * userdata )
115+ {
116+ Tox * tox = (Tox * )context ;
117+ assert (tox != nullptr );
118+ tox -> log_callback (tox , (Tox_Log_Level )level , file , line , func , message , userdata );
119+ }
120+
121+ static m_self_connection_status_cb tox_self_connection_status_handler ;
110122non_null (1 ) nullable (3 )
111123static void tox_self_connection_status_handler (Messenger * m , Onion_Connection_Status connection_status , void * user_data )
112124{
@@ -117,6 +129,7 @@ static void tox_self_connection_status_handler(Messenger *m, Onion_Connection_St
117129 }
118130}
119131
132+ static m_friend_name_cb tox_friend_name_handler ;
120133non_null (1 , 3 ) nullable (5 )
121134static void tox_friend_name_handler (Messenger * m , uint32_t friend_number , const uint8_t * name , size_t length ,
122135 void * user_data )
@@ -128,6 +141,7 @@ static void tox_friend_name_handler(Messenger *m, uint32_t friend_number, const
128141 }
129142}
130143
144+ static m_friend_status_message_cb tox_friend_status_message_handler ;
131145non_null (1 , 3 ) nullable (5 )
132146static void tox_friend_status_message_handler (Messenger * m , uint32_t friend_number , const uint8_t * message ,
133147 size_t length , void * user_data )
@@ -139,6 +153,7 @@ static void tox_friend_status_message_handler(Messenger *m, uint32_t friend_numb
139153 }
140154}
141155
156+ static m_friend_status_cb tox_friend_status_handler ;
142157non_null (1 ) nullable (4 )
143158static void tox_friend_status_handler (Messenger * m , uint32_t friend_number , unsigned int status , void * user_data )
144159{
@@ -149,6 +164,7 @@ static void tox_friend_status_handler(Messenger *m, uint32_t friend_number, unsi
149164 }
150165}
151166
167+ static m_friend_connection_status_cb tox_friend_connection_status_handler ;
152168non_null (1 ) nullable (4 )
153169static void tox_friend_connection_status_handler (Messenger * m , uint32_t friend_number , unsigned int connection_status ,
154170 void * user_data )
@@ -161,6 +177,7 @@ static void tox_friend_connection_status_handler(Messenger *m, uint32_t friend_n
161177 }
162178}
163179
180+ static m_friend_typing_cb tox_friend_typing_handler ;
164181non_null (1 ) nullable (4 )
165182static void tox_friend_typing_handler (Messenger * m , uint32_t friend_number , bool is_typing , void * user_data )
166183{
@@ -171,6 +188,7 @@ static void tox_friend_typing_handler(Messenger *m, uint32_t friend_number, bool
171188 }
172189}
173190
191+ static m_friend_read_receipt_cb tox_friend_read_receipt_handler ;
174192non_null (1 ) nullable (4 )
175193static void tox_friend_read_receipt_handler (Messenger * m , uint32_t friend_number , uint32_t message_id , void * user_data )
176194{
@@ -181,6 +199,7 @@ static void tox_friend_read_receipt_handler(Messenger *m, uint32_t friend_number
181199 }
182200}
183201
202+ static m_friend_request_cb tox_friend_request_handler ;
184203non_null (1 , 2 , 3 ) nullable (5 )
185204static void tox_friend_request_handler (Messenger * m , const uint8_t * public_key , const uint8_t * message , size_t length ,
186205 void * user_data )
@@ -192,18 +211,20 @@ static void tox_friend_request_handler(Messenger *m, const uint8_t *public_key,
192211 }
193212}
194213
214+ static m_friend_message_cb tox_friend_message_handler ;
195215non_null (1 , 4 ) nullable (6 )
196- static void tox_friend_message_handler (Messenger * m , uint32_t friend_number , unsigned int type , const uint8_t * message ,
197- size_t length , void * user_data )
216+ static void tox_friend_message_handler (Messenger * m , uint32_t friend_number , unsigned int message_type ,
217+ const uint8_t * message , size_t length , void * user_data )
198218{
199219 struct Tox_Userdata * tox_data = (struct Tox_Userdata * )user_data ;
200220
201221 if (tox_data -> tox -> friend_message_callback != nullptr ) {
202- tox_data -> tox -> friend_message_callback (tox_data -> tox , friend_number , (Tox_Message_Type )type , message , length ,
222+ tox_data -> tox -> friend_message_callback (tox_data -> tox , friend_number , (Tox_Message_Type )message_type , message , length ,
203223 tox_data -> user_data );
204224 }
205225}
206226
227+ static m_file_recv_control_cb tox_file_recv_control_handler ;
207228non_null (1 ) nullable (5 )
208229static void tox_file_recv_control_handler (Messenger * m , uint32_t friend_number , uint32_t file_number ,
209230 unsigned int control , void * user_data )
@@ -216,6 +237,7 @@ static void tox_file_recv_control_handler(Messenger *m, uint32_t friend_number,
216237 }
217238}
218239
240+ static m_file_chunk_request_cb tox_file_chunk_request_handler ;
219241non_null (1 ) nullable (6 )
220242static void tox_file_chunk_request_handler (Messenger * m , uint32_t friend_number , uint32_t file_number ,
221243 uint64_t position , size_t length , void * user_data )
@@ -228,6 +250,7 @@ static void tox_file_chunk_request_handler(Messenger *m, uint32_t friend_number,
228250 }
229251}
230252
253+ static m_file_recv_cb tox_file_recv_handler ;
231254non_null (1 , 6 ) nullable (8 )
232255static void tox_file_recv_handler (Messenger * m , uint32_t friend_number , uint32_t file_number , uint32_t kind ,
233256 uint64_t file_size , const uint8_t * filename , size_t filename_length , void * user_data )
@@ -240,6 +263,7 @@ static void tox_file_recv_handler(Messenger *m, uint32_t friend_number, uint32_t
240263 }
241264}
242265
266+ static m_file_recv_chunk_cb tox_file_recv_chunk_handler ;
243267non_null (1 , 5 ) nullable (7 )
244268static void tox_file_recv_chunk_handler (Messenger * m , uint32_t friend_number , uint32_t file_number , uint64_t position ,
245269 const uint8_t * data , size_t length , void * user_data )
@@ -252,6 +276,7 @@ static void tox_file_recv_chunk_handler(Messenger *m, uint32_t friend_number, ui
252276 }
253277}
254278
279+ static g_conference_invite_cb tox_conference_invite_handler ;
255280non_null (1 , 4 ) nullable (6 )
256281static void tox_conference_invite_handler (Messenger * m , uint32_t friend_number , int type , const uint8_t * cookie ,
257282 size_t length , void * user_data )
@@ -264,6 +289,7 @@ static void tox_conference_invite_handler(Messenger *m, uint32_t friend_number,
264289 }
265290}
266291
292+ static g_conference_connected_cb tox_conference_connected_handler ;
267293non_null (1 ) nullable (3 )
268294static void tox_conference_connected_handler (Messenger * m , uint32_t conference_number , void * user_data )
269295{
@@ -274,6 +300,7 @@ static void tox_conference_connected_handler(Messenger *m, uint32_t conference_n
274300 }
275301}
276302
303+ static g_conference_message_cb tox_conference_message_handler ;
277304non_null (1 , 5 ) nullable (7 )
278305static void tox_conference_message_handler (Messenger * m , uint32_t conference_number , uint32_t peer_number , int type ,
279306 const uint8_t * message , size_t length , void * user_data )
@@ -286,6 +313,7 @@ static void tox_conference_message_handler(Messenger *m, uint32_t conference_num
286313 }
287314}
288315
316+ static title_cb tox_conference_title_handler ;
289317non_null (1 , 4 ) nullable (6 )
290318static void tox_conference_title_handler (Messenger * m , uint32_t conference_number , uint32_t peer_number ,
291319 const uint8_t * title , size_t length , void * user_data )
@@ -298,6 +326,7 @@ static void tox_conference_title_handler(Messenger *m, uint32_t conference_numbe
298326 }
299327}
300328
329+ static peer_name_cb tox_conference_peer_name_handler ;
301330non_null (1 , 4 ) nullable (6 )
302331static void tox_conference_peer_name_handler (Messenger * m , uint32_t conference_number , uint32_t peer_number ,
303332 const uint8_t * name , size_t length , void * user_data )
@@ -310,6 +339,7 @@ static void tox_conference_peer_name_handler(Messenger *m, uint32_t conference_n
310339 }
311340}
312341
342+ static peer_list_changed_cb tox_conference_peer_list_changed_handler ;
313343non_null (1 ) nullable (3 )
314344static void tox_conference_peer_list_changed_handler (Messenger * m , uint32_t conference_number , void * user_data )
315345{
@@ -320,6 +350,7 @@ static void tox_conference_peer_list_changed_handler(Messenger *m, uint32_t conf
320350 }
321351}
322352
353+ static dht_get_nodes_response_cb tox_dht_get_nodes_response_handler ;
323354non_null (1 , 2 ) nullable (3 )
324355static void tox_dht_get_nodes_response_handler (const DHT * dht , const Node_format * node , void * user_data )
325356{
@@ -336,6 +367,7 @@ static void tox_dht_get_nodes_response_handler(const DHT *dht, const Node_format
336367 tox_data -> user_data );
337368}
338369
370+ static m_friend_lossy_packet_cb tox_friend_lossy_packet_handler ;
339371non_null (1 , 4 ) nullable (6 )
340372static void tox_friend_lossy_packet_handler (Messenger * m , uint32_t friend_number , uint8_t packet_id ,
341373 const uint8_t * data , size_t length , void * user_data )
@@ -351,6 +383,7 @@ static void tox_friend_lossy_packet_handler(Messenger *m, uint32_t friend_number
351383 }
352384}
353385
386+ static m_friend_lossless_packet_cb tox_friend_lossless_packet_handler ;
354387non_null (1 , 4 ) nullable (6 )
355388static void tox_friend_lossless_packet_handler (Messenger * m , uint32_t friend_number , uint8_t packet_id ,
356389 const uint8_t * data , size_t length , void * user_data )
@@ -499,10 +532,8 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
499532 m_options .hole_punching_enabled = tox_options_get_hole_punching_enabled (opts );
500533 m_options .local_discovery_enabled = tox_options_get_local_discovery_enabled (opts );
501534
502- // TODO(iphydf): Don't cast function pointers.
503- //!TOKSTYLE-
504- m_options .log_callback = (logger_cb * )tox_options_get_log_callback (opts );
505- //!TOKSTYLE+
535+ tox -> log_callback = tox_options_get_log_callback (opts );
536+ m_options .log_callback = tox_log_handler ;
506537 m_options .log_context = tox ;
507538 m_options .log_user_data = tox_options_get_log_user_data (opts );
508539
0 commit comments