aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_context.c
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-01-04 18:14:46 +0100
committerJacki <jacki@thejackimonster.de>2024-01-04 18:14:46 +0100
commit2ee30f372acad534246beaf579b7bbfefab0b246 (patch)
treef17d4ac1675ab0465fd772d59157fc7d10127c94 /src/gnunet_chat_context.c
parentfa50b6878fa0c8aef70bc2d879e2e0dffdc65f88 (diff)
downloadlibgnunetchat-2ee30f372acad534246beaf579b7bbfefab0b246.tar.gz
libgnunetchat-2ee30f372acad534246beaf579b7bbfefab0b246.zip
Format more code
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat (limited to 'src/gnunet_chat_context.c')
-rw-r--r--src/gnunet_chat_context.c110
1 files changed, 54 insertions, 56 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
index c016fa3..ea188e7 100644
--- a/src/gnunet_chat_context.c
+++ b/src/gnunet_chat_context.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021--2023 GNUnet e.V. 3 Copyright (C) 2021--2024 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
@@ -23,7 +23,6 @@
23 */ 23 */
24 24
25#include "gnunet_chat_context.h" 25#include "gnunet_chat_context.h"
26#include "gnunet_chat_group.h"
27#include "gnunet_chat_handle.h" 26#include "gnunet_chat_handle.h"
28#include "gnunet_chat_util.h" 27#include "gnunet_chat_util.h"
29 28
@@ -35,7 +34,7 @@ static const unsigned int initial_map_size_of_contact = 4;
35 34
36struct GNUNET_CHAT_Context* 35struct GNUNET_CHAT_Context*
37context_create_from_room (struct GNUNET_CHAT_Handle *handle, 36context_create_from_room (struct GNUNET_CHAT_Handle *handle,
38 struct GNUNET_MESSENGER_Room *room) 37 struct GNUNET_MESSENGER_Room *room)
39{ 38{
40 GNUNET_assert((handle) && (room)); 39 GNUNET_assert((handle) && (room));
41 40
@@ -49,13 +48,13 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle,
49 context->deleted = GNUNET_NO; 48 context->deleted = GNUNET_NO;
50 49
51 context->timestamps = GNUNET_CONTAINER_multishortmap_create( 50 context->timestamps = GNUNET_CONTAINER_multishortmap_create(
52 initial_map_size_of_room, GNUNET_NO); 51 initial_map_size_of_room, GNUNET_NO);
53 context->messages = GNUNET_CONTAINER_multihashmap_create( 52 context->messages = GNUNET_CONTAINER_multihashmap_create(
54 initial_map_size_of_room, GNUNET_NO); 53 initial_map_size_of_room, GNUNET_NO);
55 context->invites = GNUNET_CONTAINER_multihashmap_create( 54 context->invites = GNUNET_CONTAINER_multihashmap_create(
56 initial_map_size_of_room, GNUNET_NO); 55 initial_map_size_of_room, GNUNET_NO);
57 context->files = GNUNET_CONTAINER_multihashmap_create( 56 context->files = GNUNET_CONTAINER_multihashmap_create(
58 initial_map_size_of_room, GNUNET_NO); 57 initial_map_size_of_room, GNUNET_NO);
59 58
60 context->room = room; 59 context->room = room;
61 context->contact = NULL; 60 context->contact = NULL;
@@ -63,7 +62,7 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle,
63 context->user_pointer = NULL; 62 context->user_pointer = NULL;
64 63
65 context->member_pointers = GNUNET_CONTAINER_multishortmap_create( 64 context->member_pointers = GNUNET_CONTAINER_multishortmap_create(
66 initial_map_size_of_room, GNUNET_NO); 65 initial_map_size_of_room, GNUNET_NO);
67 66
68 context->query = NULL; 67 context->query = NULL;
69 68
@@ -72,7 +71,7 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle,
72 71
73struct GNUNET_CHAT_Context* 72struct GNUNET_CHAT_Context*
74context_create_from_contact (struct GNUNET_CHAT_Handle *handle, 73context_create_from_contact (struct GNUNET_CHAT_Handle *handle,
75 const struct GNUNET_MESSENGER_Contact *contact) 74 const struct GNUNET_MESSENGER_Contact *contact)
76{ 75{
77 GNUNET_assert((handle) && (contact)); 76 GNUNET_assert((handle) && (contact));
78 77
@@ -86,13 +85,13 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle,
86 context->deleted = GNUNET_NO; 85 context->deleted = GNUNET_NO;
87 86
88 context->timestamps = GNUNET_CONTAINER_multishortmap_create( 87 context->timestamps = GNUNET_CONTAINER_multishortmap_create(
89 initial_map_size_of_contact, GNUNET_NO); 88 initial_map_size_of_contact, GNUNET_NO);
90 context->messages = GNUNET_CONTAINER_multihashmap_create( 89 context->messages = GNUNET_CONTAINER_multihashmap_create(
91 initial_map_size_of_contact, GNUNET_NO); 90 initial_map_size_of_contact, GNUNET_NO);
92 context->invites = GNUNET_CONTAINER_multihashmap_create( 91 context->invites = GNUNET_CONTAINER_multihashmap_create(
93 initial_map_size_of_contact, GNUNET_NO); 92 initial_map_size_of_contact, GNUNET_NO);
94 context->files = GNUNET_CONTAINER_multihashmap_create( 93 context->files = GNUNET_CONTAINER_multihashmap_create(
95 initial_map_size_of_contact, GNUNET_NO); 94 initial_map_size_of_contact, GNUNET_NO);
96 95
97 context->room = NULL; 96 context->room = NULL;
98 context->contact = contact; 97 context->contact = contact;
@@ -100,7 +99,7 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle,
100 context->user_pointer = NULL; 99 context->user_pointer = NULL;
101 100
102 context->member_pointers = GNUNET_CONTAINER_multishortmap_create( 101 context->member_pointers = GNUNET_CONTAINER_multishortmap_create(
103 initial_map_size_of_contact, GNUNET_NO); 102 initial_map_size_of_contact, GNUNET_NO);
104 103
105 context->query = NULL; 104 context->query = NULL;
106 105
@@ -110,25 +109,27 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle,
110void 109void
111context_destroy (struct GNUNET_CHAT_Context *context) 110context_destroy (struct GNUNET_CHAT_Context *context)
112{ 111{
113 GNUNET_assert((context) && 112 GNUNET_assert(
113 (context) &&
114 (context->timestamps) && 114 (context->timestamps) &&
115 (context->messages) && 115 (context->messages) &&
116 (context->invites) && 116 (context->invites) &&
117 (context->files)); 117 (context->files)
118 );
118 119
119 if (context->query) 120 if (context->query)
120 GNUNET_NAMESTORE_cancel(context->query); 121 GNUNET_NAMESTORE_cancel(context->query);
121 122
122 GNUNET_CONTAINER_multishortmap_iterate( 123 GNUNET_CONTAINER_multishortmap_iterate(
123 context->timestamps, it_destroy_context_timestamps, NULL 124 context->timestamps, it_destroy_context_timestamps, NULL
124 ); 125 );
125 126
126 GNUNET_CONTAINER_multihashmap_iterate( 127 GNUNET_CONTAINER_multihashmap_iterate(
127 context->messages, it_destroy_context_messages, NULL 128 context->messages, it_destroy_context_messages, NULL
128 ); 129 );
129 130
130 GNUNET_CONTAINER_multihashmap_iterate( 131 GNUNET_CONTAINER_multihashmap_iterate(
131 context->invites, it_destroy_context_invites, NULL 132 context->invites, it_destroy_context_invites, NULL
132 ); 133 );
133 134
134 GNUNET_CONTAINER_multishortmap_destroy(context->member_pointers); 135 GNUNET_CONTAINER_multishortmap_destroy(context->member_pointers);
@@ -146,7 +147,7 @@ context_destroy (struct GNUNET_CHAT_Context *context)
146 147
147void 148void
148context_update_room (struct GNUNET_CHAT_Context *context, 149context_update_room (struct GNUNET_CHAT_Context *context,
149 struct GNUNET_MESSENGER_Room *room) 150 struct GNUNET_MESSENGER_Room *room)
150{ 151{
151 GNUNET_assert(context); 152 GNUNET_assert(context);
152 153
@@ -154,20 +155,20 @@ context_update_room (struct GNUNET_CHAT_Context *context,
154 return; 155 return;
155 156
156 GNUNET_CONTAINER_multishortmap_iterate( 157 GNUNET_CONTAINER_multishortmap_iterate(
157 context->timestamps, it_destroy_context_timestamps, NULL 158 context->timestamps, it_destroy_context_timestamps, NULL
158 ); 159 );
159 160
160 GNUNET_CONTAINER_multihashmap_iterate( 161 GNUNET_CONTAINER_multihashmap_iterate(
161 context->messages, it_destroy_context_messages, NULL 162 context->messages, it_destroy_context_messages, NULL
162 ); 163 );
163 164
164 GNUNET_CONTAINER_multihashmap_iterate( 165 GNUNET_CONTAINER_multihashmap_iterate(
165 context->invites, it_destroy_context_invites, NULL 166 context->invites, it_destroy_context_invites, NULL
166 ); 167 );
167 168
168 GNUNET_CONTAINER_multishortmap_destroy(context->timestamps); 169 GNUNET_CONTAINER_multishortmap_destroy(context->timestamps);
169 context->timestamps = GNUNET_CONTAINER_multishortmap_create( 170 context->timestamps = GNUNET_CONTAINER_multishortmap_create(
170 initial_map_size_of_room, GNUNET_NO); 171 initial_map_size_of_room, GNUNET_NO);
171 172
172 GNUNET_CONTAINER_multihashmap_clear(context->messages); 173 GNUNET_CONTAINER_multihashmap_clear(context->messages);
173 GNUNET_CONTAINER_multihashmap_clear(context->invites); 174 GNUNET_CONTAINER_multihashmap_clear(context->invites);
@@ -183,7 +184,7 @@ context_update_room (struct GNUNET_CHAT_Context *context,
183 184
184void 185void
185context_update_nick (struct GNUNET_CHAT_Context *context, 186context_update_nick (struct GNUNET_CHAT_Context *context,
186 const char *nick) 187 const char *nick)
187{ 188{
188 GNUNET_assert(context); 189 GNUNET_assert(context);
189 190
@@ -198,21 +199,20 @@ context_update_nick (struct GNUNET_CHAT_Context *context,
198 return; 199 return;
199 200
200 handle_send_internal_message( 201 handle_send_internal_message(
201 context->handle, 202 context->handle,
202 context, 203 context,
203 GNUNET_CHAT_FLAG_UPDATE, 204 GNUNET_CHAT_FLAG_UPDATE,
204 NULL 205 NULL
205 ); 206 );
206} 207}
207 208
208void 209void
209context_read_records (struct GNUNET_CHAT_Context *context, 210context_read_records (struct GNUNET_CHAT_Context *context,
210 const char *label, 211 const char *label,
211 unsigned int count, 212 unsigned int count,
212 const struct GNUNET_GNSRECORD_Data *data) 213 const struct GNUNET_GNSRECORD_Data *data)
213{ 214{
214 GNUNET_assert((context) && 215 GNUNET_assert((context) && (context->room));
215 (context->room));
216 216
217 char *nick = NULL; 217 char *nick = NULL;
218 char *topic = NULL; 218 char *topic = NULL;
@@ -226,7 +226,7 @@ context_read_records (struct GNUNET_CHAT_Context *context,
226 if (GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS == data[i].record_type) 226 if (GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS == data[i].record_type)
227 { 227 {
228 if (nick) 228 if (nick)
229 continue; 229 continue;
230 230
231 const struct GNUNET_MESSENGER_RoomDetailsRecord *record = data[i].data; 231 const struct GNUNET_MESSENGER_RoomDetailsRecord *record = data[i].data;
232 232
@@ -237,7 +237,7 @@ context_read_records (struct GNUNET_CHAT_Context *context,
237 if (GNUNET_DNSPARSER_TYPE_TXT == data[i].record_type) 237 if (GNUNET_DNSPARSER_TYPE_TXT == data[i].record_type)
238 { 238 {
239 if (topic) 239 if (topic)
240 continue; 240 continue;
241 241
242 topic = GNUNET_strndup(data[i].data, data[i].data_size); 242 topic = GNUNET_strndup(data[i].data, data[i].data_size);
243 } 243 }
@@ -249,7 +249,7 @@ context_read_records (struct GNUNET_CHAT_Context *context,
249 GNUNET_free(nick); 249 GNUNET_free(nick);
250 250
251 const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( 251 const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key(
252 context->room 252 context->room
253 ); 253 );
254 254
255 if (topic) 255 if (topic)
@@ -275,19 +275,17 @@ context_read_records (struct GNUNET_CHAT_Context *context,
275void 275void
276context_write_records (struct GNUNET_CHAT_Context *context) 276context_write_records (struct GNUNET_CHAT_Context *context)
277{ 277{
278 GNUNET_assert((context) && 278 GNUNET_assert((context) && (context->handle) && (context->room));
279 (context->handle) &&
280 (context->room));
281 279
282 const struct GNUNET_CRYPTO_PrivateKey *zone = handle_get_key( 280 const struct GNUNET_CRYPTO_PrivateKey *zone = handle_get_key(
283 context->handle 281 context->handle
284 ); 282 );
285 283
286 if (!zone) 284 if (!zone)
287 return; 285 return;
288 286
289 const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( 287 const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key(
290 context->room 288 context->room
291 ); 289 );
292 290
293 struct GNUNET_TIME_Absolute expiration = GNUNET_TIME_absolute_get_forever_(); 291 struct GNUNET_TIME_Absolute expiration = GNUNET_TIME_absolute_get_forever_();
@@ -296,9 +294,9 @@ context_write_records (struct GNUNET_CHAT_Context *context)
296 GNUNET_CRYPTO_get_peer_identity(context->handle->cfg, &(room_entry.door)); 294 GNUNET_CRYPTO_get_peer_identity(context->handle->cfg, &(room_entry.door));
297 295
298 GNUNET_memcpy( 296 GNUNET_memcpy(
299 &(room_entry.key), 297 &(room_entry.key),
300 hash, 298 hash,
301 sizeof(room_entry.key) 299 sizeof(room_entry.key)
302 ); 300 );
303 301
304 struct GNUNET_MESSENGER_RoomDetailsRecord room_details; 302 struct GNUNET_MESSENGER_RoomDetailsRecord room_details;
@@ -339,8 +337,8 @@ context_write_records (struct GNUNET_CHAT_Context *context)
339 data[count].data_size = sizeof(room_details); 337 data[count].data_size = sizeof(room_details);
340 data[count].expiration_time = expiration.abs_value_us; 338 data[count].expiration_time = expiration.abs_value_us;
341 data[count].flags = ( 339 data[count].flags = (
342 GNUNET_GNSRECORD_RF_PRIVATE | 340 GNUNET_GNSRECORD_RF_PRIVATE |
343 GNUNET_GNSRECORD_RF_SUPPLEMENTAL 341 GNUNET_GNSRECORD_RF_SUPPLEMENTAL
344 ); 342 );
345 343
346 count++; 344 count++;
@@ -353,8 +351,8 @@ context_write_records (struct GNUNET_CHAT_Context *context)
353 data[count].data_size = strlen(topic); 351 data[count].data_size = strlen(topic);
354 data[count].expiration_time = expiration.abs_value_us; 352 data[count].expiration_time = expiration.abs_value_us;
355 data[count].flags = ( 353 data[count].flags = (
356 GNUNET_GNSRECORD_RF_PRIVATE | 354 GNUNET_GNSRECORD_RF_PRIVATE |
357 GNUNET_GNSRECORD_RF_SUPPLEMENTAL 355 GNUNET_GNSRECORD_RF_SUPPLEMENTAL
358 ); 356 );
359 357
360 count++; 358 count++;
@@ -365,13 +363,13 @@ skip_record_data:
365 GNUNET_NAMESTORE_cancel(context->query); 363 GNUNET_NAMESTORE_cancel(context->query);
366 364
367 context->query = GNUNET_NAMESTORE_record_set_store( 365 context->query = GNUNET_NAMESTORE_record_set_store(
368 context->handle->namestore, 366 context->handle->namestore,
369 zone, 367 zone,
370 label, 368 label,
371 count, 369 count,
372 data, 370 data,
373 cont_context_write_records, 371 cont_context_write_records,
374 context 372 context
375 ); 373 );
376 374
377 GNUNET_free(label); 375 GNUNET_free(label);