Skip to content

Commit

Permalink
Use named function types for friend_requests callbacks.
Browse files Browse the repository at this point in the history
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`).
  • Loading branch information
iphydf committed Jul 8, 2018
1 parent b3889f0 commit 0c7fc77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 6 additions & 7 deletions toxcore/friend_requests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -63,16 +63,15 @@ 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;
fr->handle_friendrequest_object = object;
}

/* 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;
Expand Down
4 changes: 3 additions & 1 deletion toxcore/friend_requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0c7fc77

Please sign in to comment.