/work/toxcore/friend_requests.h
Line | Count | Source |
1 | | /* SPDX-License-Identifier: GPL-3.0-or-later |
2 | | * Copyright © 2016-2025 The TokTok team. |
3 | | * Copyright © 2014 Tox project. |
4 | | */ |
5 | | |
6 | | /** |
7 | | * Handle friend requests. |
8 | | */ |
9 | | #ifndef C_TOXCORE_TOXCORE_FRIEND_REQUESTS_H |
10 | | #define C_TOXCORE_TOXCORE_FRIEND_REQUESTS_H |
11 | | |
12 | | #include <stddef.h> |
13 | | |
14 | | #include "attributes.h" |
15 | | #include "friend_connection.h" |
16 | | #include "mem.h" |
17 | | |
18 | | // TODO(Jfreegman): This should be the maximum size that an onion client can handle. |
19 | 310 | #define MAX_FRIEND_REQUEST_DATA_SIZE (ONION_CLIENT_MAX_DATA_SIZE - 100) |
20 | | |
21 | | typedef struct Friend_Requests Friend_Requests; |
22 | | |
23 | | /** Set and get the nospam variable used to prevent one type of friend request spam. */ |
24 | | void set_nospam(Friend_Requests *_Nonnull fr, uint32_t num); |
25 | | uint32_t get_nospam(const Friend_Requests *_Nonnull fr); |
26 | | |
27 | | /** @brief Remove real_pk from received_requests list. |
28 | | * |
29 | | * @retval 0 if it removed it successfully. |
30 | | * @retval -1 if it didn't find it. |
31 | | */ |
32 | | int remove_request_received(Friend_Requests *_Nonnull fr, const uint8_t *_Nonnull real_pk); |
33 | | |
34 | | typedef void fr_friend_request_cb(void *_Nonnull object, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull message, size_t length, |
35 | | void *_Nullable user_data); |
36 | | |
37 | | /** Set the function that will be executed when a friend request for us is received. */ |
38 | | void callback_friendrequest(Friend_Requests *_Nonnull fr, fr_friend_request_cb *_Nonnull function, void *_Nonnull object); |
39 | | |
40 | | typedef int filter_function_cb(void *_Nonnull object, const uint8_t *_Nonnull public_key); |
41 | | |
42 | | /** @brief Set the function used to check if a friend request should be displayed to the user or not. |
43 | | * It must return 0 if the request is ok (anything else if it is bad). |
44 | | */ |
45 | | void set_filter_function(Friend_Requests *_Nonnull fr, filter_function_cb *_Nonnull function, void *_Nonnull userdata); |
46 | | |
47 | | /** Sets up friendreq packet handlers. */ |
48 | | void friendreq_init(Friend_Requests *_Nonnull fr, Friend_Connections *_Nonnull fr_c); |
49 | | |
50 | | Friend_Requests *_Nullable friendreq_new(const Memory *_Nonnull mem); |
51 | | |
52 | | void friendreq_kill(Friend_Requests *_Nullable fr); |
53 | | #endif /* C_TOXCORE_TOXCORE_FRIEND_REQUESTS_H */ |