diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2020-11-12 20:58:07 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2020-11-12 20:58:07 +0100 |
commit | ca912f85dae6b61dd80ab02d0e3f0b20a556da7c (patch) | |
tree | 788ebaf2ce0870bad875a7d910b6cd1b536a99c7 /src/messenger/gnunet-service-messenger_contact.c | |
parent | 5bdfe2001fbc68b06293b79dd6426156719d33c0 (diff) | |
download | gnunet-ca912f85dae6b61dd80ab02d0e3f0b20a556da7c.tar.gz gnunet-ca912f85dae6b61dd80ab02d0e3f0b20a556da7c.zip |
-remerge branch 'jacki/messenger'
This reverts commit e11d1e59e4ae5f7d89c33df3ae9ca8f1ece990cf.
Diffstat (limited to 'src/messenger/gnunet-service-messenger_contact.c')
-rw-r--r-- | src/messenger/gnunet-service-messenger_contact.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/messenger/gnunet-service-messenger_contact.c b/src/messenger/gnunet-service-messenger_contact.c new file mode 100644 index 000000000..1ec125402 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_contact.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_contact.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_contact.h" | ||
27 | |||
28 | struct GNUNET_MESSENGER_SrvContact* | ||
29 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key) | ||
30 | { | ||
31 | struct GNUNET_MESSENGER_SrvContact *contact = GNUNET_new(struct GNUNET_MESSENGER_SrvContact); | ||
32 | |||
33 | contact->name = NULL; | ||
34 | contact->rc = 0; | ||
35 | |||
36 | GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key)); | ||
37 | |||
38 | return contact; | ||
39 | } | ||
40 | |||
41 | void | ||
42 | destroy_contact (struct GNUNET_MESSENGER_SrvContact *contact) | ||
43 | { | ||
44 | if (contact->name) | ||
45 | GNUNET_free(contact->name); | ||
46 | |||
47 | GNUNET_free(contact); | ||
48 | } | ||
49 | |||
50 | const char* | ||
51 | get_contact_name (const struct GNUNET_MESSENGER_SrvContact *contact) | ||
52 | { | ||
53 | return contact->name; | ||
54 | } | ||
55 | |||
56 | void | ||
57 | set_contact_name (struct GNUNET_MESSENGER_SrvContact *contact, const char *name) | ||
58 | { | ||
59 | GNUNET_assert(name); | ||
60 | |||
61 | if (contact->name) | ||
62 | GNUNET_free(contact->name); | ||
63 | |||
64 | contact->name = GNUNET_strdup(name); | ||
65 | } | ||
66 | |||
67 | const struct GNUNET_IDENTITY_PublicKey* | ||
68 | get_contact_key (const struct GNUNET_MESSENGER_SrvContact *contact) | ||
69 | { | ||
70 | return &(contact->public_key); | ||
71 | } | ||
72 | |||
73 | void | ||
74 | increase_contact_rc (struct GNUNET_MESSENGER_SrvContact *contact) | ||
75 | { | ||
76 | contact->rc++; | ||
77 | } | ||
78 | |||
79 | int | ||
80 | decrease_contact_rc (struct GNUNET_MESSENGER_SrvContact *contact) | ||
81 | { | ||
82 | if (contact->rc > 0) | ||
83 | contact->rc--; | ||
84 | |||
85 | return contact->rc ? GNUNET_NO : GNUNET_YES; | ||
86 | } | ||
87 | |||
88 | const struct GNUNET_HashCode* | ||
89 | get_contact_id_from_key (const struct GNUNET_MESSENGER_SrvContact *contact) | ||
90 | { | ||
91 | static struct GNUNET_HashCode id; | ||
92 | |||
93 | GNUNET_CRYPTO_hash (&(contact->public_key), sizeof(contact->public_key), &id); | ||
94 | |||
95 | return &id; | ||
96 | } | ||