diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-18 22:32:59 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-18 22:32:59 +0100 |
commit | 6bbc30ef71cf23267937a73e34e185410ed73a10 (patch) | |
tree | fc562e55a9a46f5de081be70a6a78e6c2aabb482 /src/gnunet_chat_handle_intern.c | |
parent | ea39819757f6888ed983d0c327286e6a7bac8523 (diff) | |
download | libgnunetchat-6bbc30ef71cf23267937a73e34e185410ed73a10.tar.gz libgnunetchat-6bbc30ef71cf23267937a73e34e185410ed73a10.zip |
Fixed problems loading configurations but still inconsistencies
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/gnunet_chat_handle_intern.c')
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 134 |
1 files changed, 12 insertions, 122 deletions
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index d804545..70e4da4 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -217,7 +217,10 @@ intern_provide_contact_for_member(struct GNUNET_CHAT_Handle *handle, | |||
217 | if (contact) | 217 | if (contact) |
218 | { | 218 | { |
219 | if ((context) && (NULL == contact->context)) | 219 | if ((context) && (NULL == contact->context)) |
220 | { | ||
220 | contact->context = context; | 221 | contact->context = context; |
222 | context->contact = member; | ||
223 | } | ||
221 | 224 | ||
222 | return GNUNET_OK; | 225 | return GNUNET_OK; |
223 | } | 226 | } |
@@ -227,13 +230,19 @@ intern_provide_contact_for_member(struct GNUNET_CHAT_Handle *handle, | |||
227 | ); | 230 | ); |
228 | 231 | ||
229 | if (context) | 232 | if (context) |
233 | { | ||
230 | contact->context = context; | 234 | contact->context = context; |
235 | context->contact = member; | ||
236 | } | ||
231 | 237 | ||
232 | if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put( | 238 | if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put( |
233 | handle->contacts, &shorthash, contact, | 239 | handle->contacts, &shorthash, contact, |
234 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 240 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
235 | return GNUNET_OK; | 241 | return GNUNET_OK; |
236 | 242 | ||
243 | if (context) | ||
244 | context->contact = NULL; | ||
245 | |||
237 | contact_destroy(contact); | 246 | contact_destroy(contact); |
238 | return GNUNET_SYSERR; | 247 | return GNUNET_SYSERR; |
239 | } | 248 | } |
@@ -257,7 +266,7 @@ check_handle_room_members (void* cls, | |||
257 | GNUNET_MESSENGER_contact_get_key(member) | 266 | GNUNET_MESSENGER_contact_get_key(member) |
258 | ); | 267 | ); |
259 | 268 | ||
260 | if (0 == GNUNET_memcmp(member_key, check->ignore_key)) | 269 | if ((member_key) && (0 == GNUNET_memcmp(member_key, check->ignore_key))) |
261 | return GNUNET_YES; | 270 | return GNUNET_YES; |
262 | 271 | ||
263 | if (check->contact) | 272 | if (check->contact) |
@@ -271,94 +280,6 @@ check_handle_room_members (void* cls, | |||
271 | } | 280 | } |
272 | 281 | ||
273 | int | 282 | int |
274 | request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle, | ||
275 | struct GNUNET_MESSENGER_Room *room) | ||
276 | { | ||
277 | GNUNET_assert((handle) && | ||
278 | (handle->contexts) && | ||
279 | (room)); | ||
280 | |||
281 | const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(room); | ||
282 | |||
283 | struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get( | ||
284 | handle->contexts, key | ||
285 | ); | ||
286 | |||
287 | struct GNUNET_CHAT_CheckHandleRoomMembers check; | ||
288 | |||
289 | if ((context) && (GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN == context->type)) | ||
290 | goto check_context_type; | ||
291 | else if (context) | ||
292 | return GNUNET_OK; | ||
293 | |||
294 | context = context_create_from_room(handle, room); | ||
295 | context_load_config(context); | ||
296 | |||
297 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | ||
298 | handle->contexts, key, context, | ||
299 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
300 | { | ||
301 | context_destroy(context); | ||
302 | return GNUNET_SYSERR; | ||
303 | } | ||
304 | |||
305 | check_context_type: | ||
306 | check.ignore_key = GNUNET_MESSENGER_get_key(handle->messenger); | ||
307 | check.contact = NULL; | ||
308 | |||
309 | const int checks = GNUNET_MESSENGER_iterate_members( | ||
310 | room, check_handle_room_members, &check | ||
311 | ); | ||
312 | |||
313 | if ((check.contact) && | ||
314 | (GNUNET_OK == intern_provide_contact_for_member(handle, | ||
315 | check.contact, | ||
316 | context))) | ||
317 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; | ||
318 | else if (checks >= 2) | ||
319 | { | ||
320 | context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; | ||
321 | |||
322 | struct GNUNET_CHAT_Group *group = group_create_from_context( | ||
323 | handle, context | ||
324 | ); | ||
325 | |||
326 | group_load_config(group); | ||
327 | |||
328 | if (group->topic) | ||
329 | group_publish(group); | ||
330 | |||
331 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( | ||
332 | handle->groups, key, group, | ||
333 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
334 | return GNUNET_OK; | ||
335 | |||
336 | group_destroy(group); | ||
337 | |||
338 | GNUNET_CONTAINER_multihashmap_remove(handle->contexts, key, context); | ||
339 | context_destroy(context); | ||
340 | return GNUNET_SYSERR; | ||
341 | } | ||
342 | |||
343 | return GNUNET_OK; | ||
344 | } | ||
345 | |||
346 | int | ||
347 | find_handle_rooms (void *cls, | ||
348 | struct GNUNET_MESSENGER_Room *room, | ||
349 | GNUNET_UNUSED const struct GNUNET_MESSENGER_Contact *member) | ||
350 | { | ||
351 | struct GNUNET_CHAT_Handle *handle = cls; | ||
352 | |||
353 | GNUNET_assert((handle) && (room)); | ||
354 | |||
355 | if (GNUNET_OK != request_handle_context_by_room(handle, room)) | ||
356 | return GNUNET_NO; | ||
357 | |||
358 | return GNUNET_YES; | ||
359 | } | ||
360 | |||
361 | int | ||
362 | scan_handle_room_members (void* cls, | 283 | scan_handle_room_members (void* cls, |
363 | GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, | 284 | GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, |
364 | const struct GNUNET_MESSENGER_Contact *member) | 285 | const struct GNUNET_MESSENGER_Contact *member) |
@@ -371,30 +292,6 @@ scan_handle_room_members (void* cls, | |||
371 | return GNUNET_NO; | 292 | return GNUNET_NO; |
372 | } | 293 | } |
373 | 294 | ||
374 | int | ||
375 | scan_handle_rooms (void *cls, | ||
376 | struct GNUNET_MESSENGER_Room *room, | ||
377 | GNUNET_UNUSED const struct GNUNET_MESSENGER_Contact *member) | ||
378 | { | ||
379 | struct GNUNET_CHAT_Handle *handle = cls; | ||
380 | |||
381 | GNUNET_assert((handle) && | ||
382 | (handle->groups) && | ||
383 | (room)); | ||
384 | |||
385 | const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(room); | ||
386 | |||
387 | struct GNUNET_CHAT_Group *group = GNUNET_CONTAINER_multihashmap_get( | ||
388 | handle->groups, key | ||
389 | ); | ||
390 | |||
391 | if (!group) | ||
392 | return GNUNET_YES; | ||
393 | |||
394 | GNUNET_MESSENGER_iterate_members(room, scan_handle_room_members, handle); | ||
395 | return GNUNET_YES; | ||
396 | } | ||
397 | |||
398 | void | 295 | void |
399 | on_handle_identity(void *cls, | 296 | on_handle_identity(void *cls, |
400 | GNUNET_UNUSED struct GNUNET_MESSENGER_Handle *messenger) | 297 | GNUNET_UNUSED struct GNUNET_MESSENGER_Handle *messenger) |
@@ -414,14 +311,7 @@ on_handle_identity(void *cls, | |||
414 | return; | 311 | return; |
415 | 312 | ||
416 | GNUNET_assert(handle->messenger); | 313 | GNUNET_assert(handle->messenger); |
417 | 314 | context_scan_configs(handle); | |
418 | GNUNET_MESSENGER_find_rooms( | ||
419 | handle->messenger, NULL, find_handle_rooms, handle | ||
420 | ); | ||
421 | |||
422 | GNUNET_MESSENGER_find_rooms( | ||
423 | handle->messenger, NULL, scan_handle_rooms, handle | ||
424 | ); | ||
425 | 315 | ||
426 | if (!handle->msg_cb) | 316 | if (!handle->msg_cb) |
427 | return; | 317 | return; |
@@ -449,7 +339,7 @@ on_handle_message (void *cls, | |||
449 | (msg) && | 339 | (msg) && |
450 | (hash)); | 340 | (hash)); |
451 | 341 | ||
452 | if ((GNUNET_OK != request_handle_context_by_room(handle, room)) || | 342 | if ((GNUNET_OK != handle_request_context_by_room(handle, room)) || |
453 | (GNUNET_OK != intern_provide_contact_for_member(handle, sender, NULL))) | 343 | (GNUNET_OK != intern_provide_contact_for_member(handle, sender, NULL))) |
454 | return; | 344 | return; |
455 | 345 | ||