aboutsummaryrefslogtreecommitdiff
path: root/src/service/messenger/messenger_api_contact.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/messenger/messenger_api_contact.c')
-rw-r--r--src/service/messenger/messenger_api_contact.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/src/service/messenger/messenger_api_contact.c b/src/service/messenger/messenger_api_contact.c
new file mode 100644
index 000000000..848a27b8f
--- /dev/null
+++ b/src/service/messenger/messenger_api_contact.c
@@ -0,0 +1,119 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2023 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Tobias Frisch
22 * @file src/messenger/messenger_api_contact.c
23 * @brief messenger api: client implementation of GNUnet MESSENGER service
24 */
25
26#include "platform.h"
27#include "messenger_api_contact.h"
28
29struct GNUNET_MESSENGER_Contact*
30create_contact (const struct GNUNET_CRYPTO_PublicKey *key)
31{
32 GNUNET_assert (key);
33
34 struct GNUNET_MESSENGER_Contact *contact = GNUNET_new (struct
35 GNUNET_MESSENGER_Contact);
36
37 contact->name = NULL;
38 contact->rc = 0;
39
40 GNUNET_memcpy (&(contact->public_key), key, sizeof(contact->public_key));
41
42 return contact;
43}
44
45
46void
47destroy_contact (struct GNUNET_MESSENGER_Contact *contact)
48{
49 GNUNET_assert (contact);
50
51 if (contact->name)
52 GNUNET_free (contact->name);
53
54 GNUNET_free (contact);
55}
56
57
58const char*
59get_contact_name (const struct GNUNET_MESSENGER_Contact *contact)
60{
61 GNUNET_assert (contact);
62
63 return contact->name;
64}
65
66
67void
68set_contact_name (struct GNUNET_MESSENGER_Contact *contact,
69 const char *name)
70{
71 GNUNET_assert (contact);
72
73 if (contact->name)
74 GNUNET_free (contact->name);
75
76 contact->name = name ? GNUNET_strdup (name) : NULL;
77}
78
79
80const struct GNUNET_CRYPTO_PublicKey*
81get_contact_key (const struct GNUNET_MESSENGER_Contact *contact)
82{
83 GNUNET_assert (contact);
84
85 return &(contact->public_key);
86}
87
88
89void
90increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact)
91{
92 GNUNET_assert (contact);
93
94 contact->rc++;
95}
96
97
98int
99decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact)
100{
101 GNUNET_assert (contact);
102
103 if (contact->rc > 0)
104 contact->rc--;
105
106 return contact->rc ? GNUNET_NO : GNUNET_YES;
107}
108
109
110void
111get_context_from_member (const struct GNUNET_HashCode *key,
112 const struct GNUNET_ShortHashCode *id,
113 struct GNUNET_HashCode *context)
114{
115 GNUNET_assert ((key) && (id) && (context));
116
117 GNUNET_CRYPTO_hash (id, sizeof(*id), context);
118 GNUNET_CRYPTO_hash_xor (key, context, context);
119}