aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet_chat_handle.c')
-rw-r--r--src/gnunet_chat_handle.c74
1 files changed, 33 insertions, 41 deletions
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index d6f45fd..ec10351 100644
--- a/src/gnunet_chat_handle.c
+++ b/src/gnunet_chat_handle.c
@@ -25,9 +25,11 @@
25#include "gnunet_chat_handle.h" 25#include "gnunet_chat_handle.h"
26 26
27#include "gnunet_chat_handle_intern.c" 27#include "gnunet_chat_handle_intern.c"
28#include "gnunet_chat_message.h"
28#include <gnunet/gnunet_arm_service.h> 29#include <gnunet/gnunet_arm_service.h>
29#include <gnunet/gnunet_common.h> 30#include <gnunet/gnunet_common.h>
30#include <gnunet/gnunet_reclaim_service.h> 31#include <gnunet/gnunet_reclaim_service.h>
32#include <gnunet/gnunet_scheduler_lib.h>
31 33
32static const unsigned int initial_map_size_of_handle = 8; 34static const unsigned int initial_map_size_of_handle = 8;
33static const unsigned int minimum_amount_of_other_members_in_group = 2; 35static const unsigned int minimum_amount_of_other_members_in_group = 2;
@@ -188,6 +190,8 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle)
188 if (handle->disconnection) 190 if (handle->disconnection)
189 GNUNET_SCHEDULER_cancel(handle->disconnection); 191 GNUNET_SCHEDULER_cancel(handle->disconnection);
190 192
193 handle->disconnection = NULL;
194
191 if (handle->monitor) 195 if (handle->monitor)
192 GNUNET_NAMESTORE_zone_monitor_stop(handle->monitor); 196 GNUNET_NAMESTORE_zone_monitor_stop(handle->monitor);
193 197
@@ -209,22 +213,12 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle)
209 { 213 {
210 accounts = handle->accounts_head; 214 accounts = handle->accounts_head;
211 215
212 if (accounts->op) 216 internal_accounts_stop_method(accounts);
213 GNUNET_IDENTITY_cancel(accounts->op);
214 217
215 if (accounts->account) 218 if (accounts->account)
216 account_destroy(accounts->account); 219 account_destroy(accounts->account);
217 220
218 GNUNET_CONTAINER_DLL_remove( 221 internal_accounts_destroy(accounts);
219 handle->accounts_head,
220 handle->accounts_tail,
221 accounts
222 );
223
224 if (accounts->identifier)
225 GNUNET_free(accounts->identifier);
226
227 GNUNET_free(accounts);
228 } 222 }
229 223
230 if (handle->fs) 224 if (handle->fs)
@@ -525,7 +519,12 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle)
525 handle->contacts = NULL; 519 handle->contacts = NULL;
526 handle->groups = NULL; 520 handle->groups = NULL;
527 521
522 if (handle->disconnection)
523 GNUNET_SCHEDULER_cancel(handle->disconnection);
524
528 handle->current = NULL; 525 handle->current = NULL;
526 handle->disconnection = NULL;
527
529 handle_update_key(handle); 528 handle_update_key(handle);
530} 529}
531 530
@@ -556,39 +555,23 @@ static int
556update_accounts_operation (struct GNUNET_CHAT_InternalAccounts **out_accounts, 555update_accounts_operation (struct GNUNET_CHAT_InternalAccounts **out_accounts,
557 struct GNUNET_CHAT_Handle *handle, 556 struct GNUNET_CHAT_Handle *handle,
558 const char *name, 557 const char *name,
559 int wait_for_completion) 558 enum GNUNET_CHAT_AccountMethod method)
560{ 559{
561 GNUNET_assert(handle); 560 GNUNET_assert(handle);
562 561
563 struct GNUNET_CHAT_InternalAccounts *accounts = *out_accounts; 562 struct GNUNET_CHAT_InternalAccounts *accounts = *out_accounts;
564 563
565 if (!accounts) 564 if (accounts)
565 internal_accounts_stop_method(accounts);
566 else
566 { 567 {
567 accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts); 568 accounts = internal_accounts_create(handle, NULL);
568 569
569 if (!accounts) 570 if (!accounts)
570 return GNUNET_SYSERR; 571 return GNUNET_SYSERR;
571
572 accounts->account = NULL;
573 accounts->handle = handle;
574
575 GNUNET_CONTAINER_DLL_insert_tail(
576 handle->accounts_head,
577 handle->accounts_tail,
578 accounts
579 );
580 }
581 else
582 {
583 if (accounts->identifier)
584 GNUNET_free(accounts->identifier);
585
586 if (accounts->op)
587 GNUNET_IDENTITY_cancel(accounts->op);
588 } 572 }
589 573
590 accounts->identifier = name ? GNUNET_strdup(name) : NULL; 574 internal_accounts_start_method(accounts, method, name);
591 accounts->wait_for_completion = wait_for_completion;
592 575
593 *out_accounts = accounts; 576 *out_accounts = accounts;
594 577
@@ -605,13 +588,13 @@ handle_create_account (struct GNUNET_CHAT_Handle *handle,
605 accounts = find_accounts_by_name(handle, name); 588 accounts = find_accounts_by_name(handle, name);
606 589
607 if (accounts) 590 if (accounts)
608 return GNUNET_NO; 591 return GNUNET_SYSERR;
609 592
610 int result = update_accounts_operation( 593 int result = update_accounts_operation(
611 &accounts, 594 &accounts,
612 handle, 595 handle,
613 NULL, 596 name,
614 GNUNET_NO 597 GNUNET_CHAT_ACCOUNT_CREATION
615 ); 598 );
616 599
617 if (GNUNET_OK != result) 600 if (GNUNET_OK != result)
@@ -641,11 +624,14 @@ handle_delete_account (struct GNUNET_CHAT_Handle *handle,
641 struct GNUNET_CHAT_InternalAccounts *accounts; 624 struct GNUNET_CHAT_InternalAccounts *accounts;
642 accounts = find_accounts_by_name(handle, name); 625 accounts = find_accounts_by_name(handle, name);
643 626
627 if (!accounts)
628 return GNUNET_SYSERR;
629
644 int result = update_accounts_operation( 630 int result = update_accounts_operation(
645 &accounts, 631 &accounts,
646 handle, 632 handle,
647 NULL, 633 NULL,
648 GNUNET_YES 634 GNUNET_CHAT_ACCOUNT_DELETION
649 ); 635 );
650 636
651 if (GNUNET_OK != result) 637 if (GNUNET_OK != result)
@@ -674,11 +660,14 @@ handle_rename_account (struct GNUNET_CHAT_Handle *handle,
674 struct GNUNET_CHAT_InternalAccounts *accounts; 660 struct GNUNET_CHAT_InternalAccounts *accounts;
675 accounts = find_accounts_by_name(handle, old_name); 661 accounts = find_accounts_by_name(handle, old_name);
676 662
663 if (!accounts)
664 return GNUNET_SYSERR;
665
677 int result = update_accounts_operation( 666 int result = update_accounts_operation(
678 &accounts, 667 &accounts,
679 handle, 668 handle,
680 NULL, 669 NULL,
681 GNUNET_YES 670 GNUNET_CHAT_ACCOUNT_RENAMING
682 ); 671 );
683 672
684 if (GNUNET_OK != result) 673 if (GNUNET_OK != result)
@@ -744,11 +733,14 @@ handle_update (struct GNUNET_CHAT_Handle *handle)
744 struct GNUNET_CHAT_InternalAccounts *accounts; 733 struct GNUNET_CHAT_InternalAccounts *accounts;
745 accounts = find_accounts_by_name(handle, name); 734 accounts = find_accounts_by_name(handle, name);
746 735
736 if (!accounts)
737 return GNUNET_SYSERR;
738
747 int result = update_accounts_operation( 739 int result = update_accounts_operation(
748 &accounts, 740 &accounts,
749 handle, 741 handle,
750 name, 742 name,
751 GNUNET_YES 743 GNUNET_CHAT_ACCOUNT_UPDATING
752 ); 744 );
753 745
754 if (GNUNET_OK != result) 746 if (GNUNET_OK != result)
@@ -944,7 +936,7 @@ setup_group:
944 handle, 936 handle,
945 NULL, 937 NULL,
946 context, 938 context,
947 GNUNET_CHAT_FLAG_UPDATE, 939 GNUNET_CHAT_FLAG_UPDATE_CONTEXT,
948 NULL 940 NULL
949 ); 941 );
950 942