aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/messenger_api_contact.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/messenger_api_contact.c')
-rw-r--r--src/messenger/messenger_api_contact.c38
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 @@
29struct GNUNET_MESSENGER_Contact* 29struct GNUNET_MESSENGER_Contact*
30create_contact (const struct GNUNET_IDENTITY_PublicKey *key) 30create_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
44void 46void
45destroy_contact (struct GNUNET_MESSENGER_Contact *contact) 47destroy_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
55const char* 58const char*
56get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) 59get_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
63void 67void
64set_contact_name (struct GNUNET_MESSENGER_Contact *contact, 68set_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
75const struct GNUNET_IDENTITY_PublicKey* 80const struct GNUNET_IDENTITY_PublicKey*
76get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) 81get_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
83void 89void
84increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact) 90increase_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
91int 98int
92decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) 99decrease_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
102void 110void
103get_context_from_member (const struct GNUNET_HashCode *key, 111get_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);