Coverage Report

Created: 2026-10-24 08:16

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