diff options
Diffstat (limited to 'src/messenger/messenger_api_contact.c')
-rw-r--r-- | src/messenger/messenger_api_contact.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/messenger/messenger_api_contact.c b/src/messenger/messenger_api_contact.c new file mode 100644 index 000000000..9a242aa00 --- /dev/null +++ b/src/messenger/messenger_api_contact.c | |||
@@ -0,0 +1,78 @@ | |||
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/messenger_api_contact.c | ||
23 | * @brief messenger api: client implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "messenger_api_contact.h" | ||
27 | |||
28 | struct GNUNET_MESSENGER_Contact* | ||
29 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key) | ||
30 | { | ||
31 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_new(struct GNUNET_MESSENGER_Contact); | ||
32 | |||
33 | contact->name = NULL; | ||
34 | |||
35 | GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key)); | ||
36 | |||
37 | return contact; | ||
38 | } | ||
39 | |||
40 | void | ||
41 | destroy_contact (struct GNUNET_MESSENGER_Contact *contact) | ||
42 | { | ||
43 | if (contact->name) | ||
44 | GNUNET_free(contact->name); | ||
45 | |||
46 | GNUNET_free(contact); | ||
47 | } | ||
48 | |||
49 | const char* | ||
50 | get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) | ||
51 | { | ||
52 | return contact->name; | ||
53 | } | ||
54 | |||
55 | void | ||
56 | set_contact_name (struct GNUNET_MESSENGER_Contact *contact, const char *name) | ||
57 | { | ||
58 | if (contact->name) | ||
59 | GNUNET_free(contact->name); | ||
60 | |||
61 | contact->name = name? GNUNET_strdup(name) : NULL; | ||
62 | } | ||
63 | |||
64 | const struct GNUNET_IDENTITY_PublicKey* | ||
65 | get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) | ||
66 | { | ||
67 | return &(contact->public_key); | ||
68 | } | ||
69 | |||
70 | const struct GNUNET_HashCode* | ||
71 | get_contact_id_from_key (const struct GNUNET_MESSENGER_Contact *contact) | ||
72 | { | ||
73 | static struct GNUNET_HashCode id; | ||
74 | |||
75 | GNUNET_CRYPTO_hash (&(contact->public_key), sizeof(contact->public_key), &id); | ||
76 | |||
77 | return &id; | ||
78 | } | ||