aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-service-messenger_handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/gnunet-service-messenger_handle.c')
-rw-r--r--src/messenger/gnunet-service-messenger_handle.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/messenger/gnunet-service-messenger_handle.c b/src/messenger/gnunet-service-messenger_handle.c
index 341bb7251..218482e45 100644
--- a/src/messenger/gnunet-service-messenger_handle.c
+++ b/src/messenger/gnunet-service-messenger_handle.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--2022 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
@@ -68,7 +68,13 @@ destroy_handle (struct GNUNET_MESSENGER_SrvHandle *handle)
68 save_handle_configuration (handle); 68 save_handle_configuration (handle);
69 69
70 if (handle->name) 70 if (handle->name)
71 {
72 struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
73
74 unbind_store_ego(store, handle->name, handle);
75
71 GNUNET_free(handle->name); 76 GNUNET_free(handle->name);
77 }
72 78
73 GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_free_member_ids, NULL); 79 GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_free_member_ids, NULL);
74 GNUNET_CONTAINER_multihashmap_destroy (handle->member_ids); 80 GNUNET_CONTAINER_multihashmap_destroy (handle->member_ids);
@@ -317,24 +323,26 @@ callback_update_handle (void *cls,
317{ 323{
318 struct GNUNET_MESSENGER_SrvHandle *handle = cls; 324 struct GNUNET_MESSENGER_SrvHandle *handle = cls;
319 325
320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating handle...\n"); 326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating handle...\n");
321 327
322 struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service); 328 struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
323 329
330 bind_store_ego(store, handle->name, handle);
331
324 if (!ego) 332 if (!ego)
325 create_store_ego(store, handle->name, handle); 333 create_store_ego (store, handle->name);
326 else 334 else
327 change_handle_ego (handle, ego); 335 renew_store_ego (store, handle->name);
328} 336}
329 337
330void 338void
331update_handle (struct GNUNET_MESSENGER_SrvHandle *handle) 339update_handle (struct GNUNET_MESSENGER_SrvHandle *handle)
332{ 340{
333 GNUNET_assert(handle); 341 GNUNET_assert (handle);
334 342
335 if (!handle->name) 343 if (!handle->name)
336 { 344 {
337 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating handle failed: Name is required!\n"); 345 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Updating handle failed: Name is required!\n");
338 return; 346 return;
339 } 347 }
340 348
@@ -360,46 +368,38 @@ callback_set_handle_name (void *cls,
360 368
361 struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service); 369 struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
362 370
363 int rename_ego_in_store = handle->ego? GNUNET_YES : GNUNET_NO;
364
365 char *old_dir; 371 char *old_dir;
366 get_handle_data_subdir (handle, handle->name, &old_dir); 372 get_handle_data_subdir (handle, handle->name, &old_dir);
367 373
368 char *new_dir; 374 char *new_dir;
369 get_handle_data_subdir (handle, name, &new_dir); 375 get_handle_data_subdir (handle, name, &new_dir);
370 376
371 int result = 0; 377 if ((GNUNET_YES == GNUNET_DISK_directory_test (new_dir, GNUNET_NO)) &&
378 (GNUNET_OK != GNUNET_DISK_directory_remove(new_dir)))
379 goto free_dirs;
372 380
373 if (GNUNET_YES == GNUNET_DISK_directory_test (old_dir, GNUNET_YES)) 381 if (GNUNET_YES == GNUNET_DISK_directory_test (old_dir, GNUNET_YES))
374 { 382 {
375 GNUNET_DISK_directory_create_for_file (new_dir); 383 GNUNET_DISK_directory_create_for_file (new_dir);
376 384
377 result = rename (old_dir, new_dir); 385 if (0 != rename (old_dir, new_dir))
386 goto free_dirs;
378 } 387 }
379 else if (GNUNET_YES == GNUNET_DISK_directory_test (new_dir, GNUNET_NO))
380 result = -1;
381
382 if (0 == result)
383 {
384 struct GNUNET_MESSENGER_MessageHandle msg_handle;
385 388
386 msg_handle.handle = handle; 389 if (handle->ego)
387 msg_handle.message = create_message_name (name); 390 rename_store_ego(store, handle->name, name);
388
389 GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_send_message, &msg_handle);
390 391
391 destroy_message (msg_handle.message); 392 struct GNUNET_MESSENGER_MessageHandle msg_handle;
393 msg_handle.handle = handle;
394 msg_handle.message = create_message_name (name);
392 395
393 change_handle_name (handle, name); 396 GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_send_message, &msg_handle);
394 } 397 destroy_message (msg_handle.message);
395 else 398 change_handle_name (handle, name);
396 rename_ego_in_store = GNUNET_NO;
397 399
400free_dirs:
398 GNUNET_free(old_dir); 401 GNUNET_free(old_dir);
399 GNUNET_free(new_dir); 402 GNUNET_free(new_dir);
400
401 if (GNUNET_YES == rename_ego_in_store)
402 rename_store_ego(store, handle->name, name);
403} 403}
404 404
405void 405void