diff options
Diffstat (limited to 'src/messenger/messenger_api_contact.c')
-rw-r--r-- | src/messenger/messenger_api_contact.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/messenger/messenger_api_contact.c b/src/messenger/messenger_api_contact.c index a284c3b08..6f5dc7ead 100644 --- a/src/messenger/messenger_api_contact.c +++ b/src/messenger/messenger_api_contact.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 GNUnet e.V. | 3 | Copyright (C) 2020--2023 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -29,69 +29,76 @@ | |||
29 | struct GNUNET_MESSENGER_Contact* | 29 | struct GNUNET_MESSENGER_Contact* |
30 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key) | 30 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key) |
31 | { | 31 | { |
32 | GNUNET_assert(key); | 32 | GNUNET_assert (key); |
33 | 33 | ||
34 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_new(struct GNUNET_MESSENGER_Contact); | 34 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_new (struct |
35 | GNUNET_MESSENGER_Contact); | ||
35 | 36 | ||
36 | contact->name = NULL; | 37 | contact->name = NULL; |
37 | contact->rc = 0; | 38 | contact->rc = 0; |
38 | 39 | ||
39 | GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key)); | 40 | GNUNET_memcpy (&(contact->public_key), key, sizeof(contact->public_key)); |
40 | 41 | ||
41 | return contact; | 42 | return contact; |
42 | } | 43 | } |
43 | 44 | ||
45 | |||
44 | void | 46 | void |
45 | destroy_contact (struct GNUNET_MESSENGER_Contact *contact) | 47 | destroy_contact (struct GNUNET_MESSENGER_Contact *contact) |
46 | { | 48 | { |
47 | GNUNET_assert(contact); | 49 | GNUNET_assert (contact); |
48 | 50 | ||
49 | if (contact->name) | 51 | if (contact->name) |
50 | GNUNET_free(contact->name); | 52 | GNUNET_free (contact->name); |
51 | 53 | ||
52 | GNUNET_free(contact); | 54 | GNUNET_free (contact); |
53 | } | 55 | } |
54 | 56 | ||
57 | |||
55 | const char* | 58 | const char* |
56 | get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) | 59 | get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) |
57 | { | 60 | { |
58 | GNUNET_assert(contact); | 61 | GNUNET_assert (contact); |
59 | 62 | ||
60 | return contact->name; | 63 | return contact->name; |
61 | } | 64 | } |
62 | 65 | ||
66 | |||
63 | void | 67 | void |
64 | set_contact_name (struct GNUNET_MESSENGER_Contact *contact, | 68 | set_contact_name (struct GNUNET_MESSENGER_Contact *contact, |
65 | const char *name) | 69 | const char *name) |
66 | { | 70 | { |
67 | GNUNET_assert(contact); | 71 | GNUNET_assert (contact); |
68 | 72 | ||
69 | if (contact->name) | 73 | if (contact->name) |
70 | GNUNET_free(contact->name); | 74 | GNUNET_free (contact->name); |
71 | 75 | ||
72 | contact->name = name ? GNUNET_strdup(name) : NULL; | 76 | contact->name = name ? GNUNET_strdup (name) : NULL; |
73 | } | 77 | } |
74 | 78 | ||
79 | |||
75 | const struct GNUNET_IDENTITY_PublicKey* | 80 | const struct GNUNET_IDENTITY_PublicKey* |
76 | get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) | 81 | get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) |
77 | { | 82 | { |
78 | GNUNET_assert(contact); | 83 | GNUNET_assert (contact); |
79 | 84 | ||
80 | return &(contact->public_key); | 85 | return &(contact->public_key); |
81 | } | 86 | } |
82 | 87 | ||
88 | |||
83 | void | 89 | void |
84 | increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact) | 90 | increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact) |
85 | { | 91 | { |
86 | GNUNET_assert(contact); | 92 | GNUNET_assert (contact); |
87 | 93 | ||
88 | contact->rc++; | 94 | contact->rc++; |
89 | } | 95 | } |
90 | 96 | ||
97 | |||
91 | int | 98 | int |
92 | decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) | 99 | decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) |
93 | { | 100 | { |
94 | GNUNET_assert(contact); | 101 | GNUNET_assert (contact); |
95 | 102 | ||
96 | if (contact->rc > 0) | 103 | if (contact->rc > 0) |
97 | contact->rc--; | 104 | contact->rc--; |
@@ -99,12 +106,13 @@ decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) | |||
99 | return contact->rc ? GNUNET_NO : GNUNET_YES; | 106 | return contact->rc ? GNUNET_NO : GNUNET_YES; |
100 | } | 107 | } |
101 | 108 | ||
109 | |||
102 | void | 110 | void |
103 | get_context_from_member (const struct GNUNET_HashCode *key, | 111 | get_context_from_member (const struct GNUNET_HashCode *key, |
104 | const struct GNUNET_ShortHashCode *id, | 112 | const struct GNUNET_ShortHashCode *id, |
105 | struct GNUNET_HashCode *context) | 113 | struct GNUNET_HashCode *context) |
106 | { | 114 | { |
107 | GNUNET_assert((key) && (id) && (context)); | 115 | GNUNET_assert ((key) && (id) && (context)); |
108 | 116 | ||
109 | GNUNET_CRYPTO_hash (id, sizeof(*id), context); | 117 | GNUNET_CRYPTO_hash (id, sizeof(*id), context); |
110 | GNUNET_CRYPTO_hash_xor (key, context, context); | 118 | GNUNET_CRYPTO_hash_xor (key, context, context); |