From eb8cd30559b97a5ee9c76ea7dc7ea1441905abe8 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 8 Jul 2018 15:30:19 +0000 Subject: [PATCH] Use named function types for friend_requests callbacks. Also: * `#define` must be scoped. If it's used outside a scope, it must be defined outside that scope (global `#define` does not need a matching `#undef`). --- toxcore/friend_requests.c | 13 ++++++------- toxcore/friend_requests.h | 4 +++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c index 3123e4ff90c..d09df1874bb 100644 --- a/toxcore/friend_requests.c +++ b/toxcore/friend_requests.c @@ -32,20 +32,20 @@ #include "util.h" +#define MAX_RECEIVED_STORED 32 + struct Friend_Requests { uint32_t nospam; - void (*handle_friendrequest)(void *, const uint8_t *, const uint8_t *, size_t, void *); + fr_friend_request_cb *handle_friendrequest; uint8_t handle_friendrequest_isset; void *handle_friendrequest_object; - int (*filter_function)(const uint8_t *, void *); + filter_function_cb *filter_function; void *filter_function_userdata; /* NOTE: The following is just a temporary fix for the multiple friend requests received at the same time problem. * TODO(irungentoo): Make this better (This will most likely tie in with the way we will handle spam.) */ -#define MAX_RECEIVED_STORED 32 - uint8_t received_requests[MAX_RECEIVED_STORED][CRYPTO_PUBLIC_KEY_SIZE]; uint16_t received_requests_index; }; @@ -63,8 +63,7 @@ uint32_t get_nospam(const Friend_Requests *fr) /* Set the function that will be executed when a friend request is received. */ -void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, size_t, - void *), void *object) +void callback_friendrequest(Friend_Requests *fr, fr_friend_request_cb *function, void *object) { fr->handle_friendrequest = function; fr->handle_friendrequest_isset = 1; @@ -72,7 +71,7 @@ void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const } /* Set the function used to check if a friend request should be displayed to the user or not. */ -void set_filter_function(Friend_Requests *fr, int (*function)(const uint8_t *, void *), void *userdata) +void set_filter_function(Friend_Requests *fr, filter_function_cb *function, void *userdata) { fr->filter_function = function; fr->filter_function_userdata = userdata; diff --git a/toxcore/friend_requests.h b/toxcore/friend_requests.h index 91571775d44..97cd316462e 100644 --- a/toxcore/friend_requests.h +++ b/toxcore/friend_requests.h @@ -48,11 +48,13 @@ typedef void fr_friend_request_cb(void *, const uint8_t *, const uint8_t *, size */ void callback_friendrequest(Friend_Requests *fr, fr_friend_request_cb *function, void *object); +typedef int filter_function_cb(const uint8_t *, void *); + /* Set the function used to check if a friend request should be displayed to the user or not. * Function format is int function(uint8_t * public_key, void * userdata) * It must return 0 if the request is ok (anything else if it is bad.) */ -void set_filter_function(Friend_Requests *fr, int (*function)(const uint8_t *, void *), void *userdata); +void set_filter_function(Friend_Requests *fr, filter_function_cb *function, void *userdata); /* Sets up friendreq packet handlers. */ void friendreq_init(Friend_Requests *fr, Friend_Connections *fr_c);