diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2023-11-23 22:08:16 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2023-11-23 22:08:16 +0100 |
commit | 8439235ac35c86983e50bf8cc86d854019ab932b (patch) | |
tree | 4fbbed539ab795553df28eb59b5359ff1d032d47 | |
parent | 02c6e842ce9b1232b9538a7da1d702d6e681ac1b (diff) | |
download | libgnunetchat-8439235ac35c86983e50bf8cc86d854019ab932b.tar.gz libgnunetchat-8439235ac35c86983e50bf8cc86d854019ab932b.zip |
Define magic numbers and prefixes as constants
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/gnunet_chat_context.c | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c index a24dd36..bb348ed 100644 --- a/src/gnunet_chat_context.c +++ b/src/gnunet_chat_context.c | |||
@@ -29,6 +29,12 @@ | |||
29 | 29 | ||
30 | #include "gnunet_chat_context_intern.c" | 30 | #include "gnunet_chat_context_intern.c" |
31 | 31 | ||
32 | static const unsigned int initial_map_size_of_room = 8; | ||
33 | static const unsigned int initial_map_size_of_contact = 4; | ||
34 | |||
35 | static const char label_prefix_of_contact [] = "contact_"; | ||
36 | static const char label_prefix_of_group [] = "group_"; | ||
37 | |||
32 | struct GNUNET_CHAT_Context* | 38 | struct GNUNET_CHAT_Context* |
33 | context_create_from_room (struct GNUNET_CHAT_Handle *handle, | 39 | context_create_from_room (struct GNUNET_CHAT_Handle *handle, |
34 | struct GNUNET_MESSENGER_Room *room) | 40 | struct GNUNET_MESSENGER_Room *room) |
@@ -44,10 +50,14 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle, | |||
44 | context->topic = NULL; | 50 | context->topic = NULL; |
45 | context->deleted = GNUNET_NO; | 51 | context->deleted = GNUNET_NO; |
46 | 52 | ||
47 | context->timestamps = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); | 53 | context->timestamps = GNUNET_CONTAINER_multishortmap_create( |
48 | context->messages = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 54 | initial_map_size_of_room, GNUNET_NO); |
49 | context->invites = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 55 | context->messages = GNUNET_CONTAINER_multihashmap_create( |
50 | context->files = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 56 | initial_map_size_of_room, GNUNET_NO); |
57 | context->invites = GNUNET_CONTAINER_multihashmap_create( | ||
58 | initial_map_size_of_room, GNUNET_NO); | ||
59 | context->files = GNUNET_CONTAINER_multihashmap_create( | ||
60 | initial_map_size_of_room, GNUNET_NO); | ||
51 | 61 | ||
52 | context->room = room; | 62 | context->room = room; |
53 | context->contact = NULL; | 63 | context->contact = NULL; |
@@ -55,8 +65,7 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle, | |||
55 | context->user_pointer = NULL; | 65 | context->user_pointer = NULL; |
56 | 66 | ||
57 | context->member_pointers = GNUNET_CONTAINER_multishortmap_create( | 67 | context->member_pointers = GNUNET_CONTAINER_multishortmap_create( |
58 | 8, GNUNET_NO | 68 | initial_map_size_of_room, GNUNET_NO); |
59 | ); | ||
60 | 69 | ||
61 | context->query = NULL; | 70 | context->query = NULL; |
62 | 71 | ||
@@ -78,10 +87,14 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle, | |||
78 | context->topic = NULL; | 87 | context->topic = NULL; |
79 | context->deleted = GNUNET_NO; | 88 | context->deleted = GNUNET_NO; |
80 | 89 | ||
81 | context->timestamps = GNUNET_CONTAINER_multishortmap_create(4, GNUNET_NO); | 90 | context->timestamps = GNUNET_CONTAINER_multishortmap_create( |
82 | context->messages = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); | 91 | initial_map_size_of_contact, GNUNET_NO); |
83 | context->invites = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); | 92 | context->messages = GNUNET_CONTAINER_multihashmap_create( |
84 | context->files = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); | 93 | initial_map_size_of_contact, GNUNET_NO); |
94 | context->invites = GNUNET_CONTAINER_multihashmap_create( | ||
95 | initial_map_size_of_contact, GNUNET_NO); | ||
96 | context->files = GNUNET_CONTAINER_multihashmap_create( | ||
97 | initial_map_size_of_contact, GNUNET_NO); | ||
85 | 98 | ||
86 | context->room = NULL; | 99 | context->room = NULL; |
87 | context->contact = contact; | 100 | context->contact = contact; |
@@ -89,8 +102,7 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle, | |||
89 | context->user_pointer = NULL; | 102 | context->user_pointer = NULL; |
90 | 103 | ||
91 | context->member_pointers = GNUNET_CONTAINER_multishortmap_create( | 104 | context->member_pointers = GNUNET_CONTAINER_multishortmap_create( |
92 | 8, GNUNET_NO | 105 | initial_map_size_of_contact, GNUNET_NO); |
93 | ); | ||
94 | 106 | ||
95 | context->query = NULL; | 107 | context->query = NULL; |
96 | 108 | ||
@@ -156,7 +168,8 @@ context_update_room (struct GNUNET_CHAT_Context *context, | |||
156 | ); | 168 | ); |
157 | 169 | ||
158 | GNUNET_CONTAINER_multishortmap_destroy(context->timestamps); | 170 | GNUNET_CONTAINER_multishortmap_destroy(context->timestamps); |
159 | context->timestamps = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); | 171 | context->timestamps = GNUNET_CONTAINER_multishortmap_create( |
172 | initial_map_size_of_room, GNUNET_NO); | ||
160 | 173 | ||
161 | GNUNET_CONTAINER_multihashmap_clear(context->messages); | 174 | GNUNET_CONTAINER_multihashmap_clear(context->messages); |
162 | GNUNET_CONTAINER_multihashmap_clear(context->invites); | 175 | GNUNET_CONTAINER_multihashmap_clear(context->invites); |
@@ -258,9 +271,11 @@ context_read_records (struct GNUNET_CHAT_Context *context, | |||
258 | if (topic) | 271 | if (topic) |
259 | GNUNET_free(topic); | 272 | GNUNET_free(topic); |
260 | 273 | ||
261 | if (0 == strncmp(label, "group_", 6)) | 274 | if (0 == strncmp(label, label_prefix_of_group, |
275 | sizeof(label_prefix_of_group) - 1)) | ||
262 | context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; | 276 | context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; |
263 | else if (0 == strncmp(label, "contact_", 8)) | 277 | else if (0 == strncmp(label, label_prefix_of_contact, |
278 | sizeof(label_prefix_of_contact) - 1)) | ||
264 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; | 279 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; |
265 | else | 280 | else |
266 | context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; | 281 | context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; |