aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-04-28 18:21:59 +0200
committerJacki <jacki@thejackimonster.de>2024-04-28 18:21:59 +0200
commit10bdc736a489383d5cee691f60ad5b1d19f8c39f (patch)
tree9d4d001692a494141c77512cd036799b01af808e
parent0b6678f50cbed14b5ff6159845f6ee1289cb8f90 (diff)
downloadlibgnunetchat-10bdc736a489383d5cee691f60ad5b1d19f8c39f.tar.gz
libgnunetchat-10bdc736a489383d5cee691f60ad5b1d19f8c39f.zip
Adjust account operations to implement new separate message kinds
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r--include/gnunet/gnunet_chat_lib.h43
-rw-r--r--src/gnunet_chat_account.c68
-rw-r--r--src/gnunet_chat_account.h26
-rw-r--r--src/gnunet_chat_context.c2
-rw-r--r--src/gnunet_chat_handle.c74
-rw-r--r--src/gnunet_chat_handle.h16
-rw-r--r--src/gnunet_chat_handle_intern.c188
-rw-r--r--src/gnunet_chat_lib.c12
-rw-r--r--src/gnunet_chat_lib_intern.c6
-rw-r--r--src/gnunet_chat_message.h9
-rw-r--r--src/internal/gnunet_chat_accounts.c114
-rw-r--r--src/internal/gnunet_chat_accounts.h71
-rw-r--r--src/internal/meson.build23
-rw-r--r--src/meson.build4
-rw-r--r--tests/test_gnunet_chat_handle.c436
-rw-r--r--tools/gnunet_chat_lib_uml.c19
16 files changed, 693 insertions, 418 deletions
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
index 66c2b73..af50d9b 100644
--- a/include/gnunet/gnunet_chat_lib.h
+++ b/include/gnunet/gnunet_chat_lib.h
@@ -90,73 +90,88 @@ enum GNUNET_CHAT_MessageKind
90 /** 90 /**
91 * The kind to inform that the application can be used. 91 * The kind to inform that the application can be used.
92 */ 92 */
93 GNUNET_CHAT_KIND_LOGIN = 3, /**< GNUNET_CHAT_KIND_LOGIN */ 93 GNUNET_CHAT_KIND_LOGIN = 3, /**< GNUNET_CHAT_KIND_LOGIN */
94 94
95 /** 95 /**
96 * The kind to inform that the application needs to cleanup 96 * The kind to inform that the application needs to cleanup
97 * resources related to the currently connected account. 97 * resources related to the currently connected account.
98 */ 98 */
99 GNUNET_CHAT_KIND_LOGOUT = 4, /**< GNUNET_CHAT_KIND_LOGOUT */ 99 GNUNET_CHAT_KIND_LOGOUT = 4, /**< GNUNET_CHAT_KIND_LOGOUT */
100
101 /**
102 * The kind to inform that an account was successfully created.
103 */
104 GNUNET_CHAT_KIND_CREATED_ACCOUNT = 5, /**< GNUNET_CHAT_KIND_CREATED_ACCOUNT */
105
106 /**
107 * The kind to inform that an account was successfully deleted.
108 */
109 GNUNET_CHAT_KIND_DELETED_ACCOUNT = 6, /**< GNUNET_CHAT_KIND_DELETED_ACCOUNT */
110
111 /**
112 * The kind to inform that an account was updated.
113 */
114 GNUNET_CHAT_KIND_UPDATE_ACCOUNT = 7, /**< GNUNET_CHAT_KIND_UPDATE_ACCOUNT */
100 115
101 /** 116 /**
102 * The kind to inform that a context was updated. 117 * The kind to inform that a context was updated.
103 */ 118 */
104 GNUNET_CHAT_KIND_UPDATE = 5, /**< GNUNET_CHAT_KIND_UPDATE */ 119 GNUNET_CHAT_KIND_UPDATE_CONTEXT = 8, /**< GNUNET_CHAT_KIND_UPDATE_CONTEXT */
105 120
106 /** 121 /**
107 * The kind to inform that a contact has joined a chat. 122 * The kind to inform that a contact has joined a chat.
108 */ 123 */
109 GNUNET_CHAT_KIND_JOIN = 6, /**< GNUNET_CHAT_KIND_JOIN */ 124 GNUNET_CHAT_KIND_JOIN = 9, /**< GNUNET_CHAT_KIND_JOIN */
110 125
111 /** 126 /**
112 * The kind to inform that a contact has left a chat. 127 * The kind to inform that a contact has left a chat.
113 */ 128 */
114 GNUNET_CHAT_KIND_LEAVE = 7, /**< GNUNET_CHAT_KIND_LEAVE */ 129 GNUNET_CHAT_KIND_LEAVE = 10, /**< GNUNET_CHAT_KIND_LEAVE */
115 130
116 /** 131 /**
117 * The kind to inform that a contact has changed. 132 * The kind to inform that a contact has changed.
118 */ 133 */
119 GNUNET_CHAT_KIND_CONTACT = 8, /**< GNUNET_CHAT_KIND_CONTACT */ 134 GNUNET_CHAT_KIND_CONTACT = 11, /**< GNUNET_CHAT_KIND_CONTACT */
120 135
121 /** 136 /**
122 * The kind to describe an invitation to a different chat. 137 * The kind to describe an invitation to a different chat.
123 */ 138 */
124 GNUNET_CHAT_KIND_INVITATION = 9, /**< GNUNET_CHAT_KIND_INVITATION */ 139 GNUNET_CHAT_KIND_INVITATION = 12, /**< GNUNET_CHAT_KIND_INVITATION */
125 140
126 /** 141 /**
127 * The kind to describe a text message. 142 * The kind to describe a text message.
128 */ 143 */
129 GNUNET_CHAT_KIND_TEXT = 10, /**< GNUNET_CHAT_KIND_TEXT */ 144 GNUNET_CHAT_KIND_TEXT = 13, /**< GNUNET_CHAT_KIND_TEXT */
130 145
131 /** 146 /**
132 * The kind to describe a shared file. 147 * The kind to describe a shared file.
133 */ 148 */
134 GNUNET_CHAT_KIND_FILE = 11, /**< GNUNET_CHAT_KIND_FILE */ 149 GNUNET_CHAT_KIND_FILE = 14, /**< GNUNET_CHAT_KIND_FILE */
135 150
136 /** 151 /**
137 * The kind to inform about a deletion of a previous message. 152 * The kind to inform about a deletion of a previous message.
138 */ 153 */
139 GNUNET_CHAT_KIND_DELETION = 12, /**< GNUNET_CHAT_KIND_DELETION */ 154 GNUNET_CHAT_KIND_DELETION = 15, /**< GNUNET_CHAT_KIND_DELETION */
140 155
141 /** 156 /**
142 * The kind to tag a previous message. 157 * The kind to tag a previous message.
143 */ 158 */
144 GNUNET_CHAT_KIND_TAG = 13, /**< GNUNET_CHAT_KIND_TAG */ 159 GNUNET_CHAT_KIND_TAG = 16, /**< GNUNET_CHAT_KIND_TAG */
145 160
146 /** 161 /**
147 * The kind to inform that attributes were updated. 162 * The kind to inform that attributes were updated.
148 */ 163 */
149 GNUNET_CHAT_KIND_ATTRIBUTES = 14, 164 GNUNET_CHAT_KIND_ATTRIBUTES = 17, /**< GNUNET_CHAT_KIND_ATTRIBUTES */
150 165
151 /** 166 /**
152 * The kind to inform that attributes were shared. 167 * The kind to inform that attributes were shared.
153 */ 168 */
154 GNUNET_CHAT_KIND_SHARED_ATTRIBUTES = 15, 169 GNUNET_CHAT_KIND_SHARED_ATTRIBUTES = 18, /**< GNUNET_CHAT_KIND_SHARED_ATTRIBUTES */
155 170
156 /** 171 /**
157 * An unknown kind of message. 172 * An unknown kind of message.
158 */ 173 */
159 GNUNET_CHAT_KIND_UNKNOWN = 0 /**< GNUNET_CHAT_KIND_UNKNOWN */ 174 GNUNET_CHAT_KIND_UNKNOWN = 0 /**< GNUNET_CHAT_KIND_UNKNOWN */
160}; 175};
161 176
162/** 177/**
diff --git a/src/gnunet_chat_account.c b/src/gnunet_chat_account.c
index 95418cc..016128b 100644
--- a/src/gnunet_chat_account.c
+++ b/src/gnunet_chat_account.c
@@ -23,17 +23,21 @@
23 */ 23 */
24 24
25#include "gnunet_chat_account.h" 25#include "gnunet_chat_account.h"
26#include "gnunet_chat_handle.h"
26#include "gnunet_chat_util.h" 27#include "gnunet_chat_util.h"
27 28
29#include <gnunet/gnunet_common.h>
30#include <gnunet/gnunet_identity_service.h>
31#include <gnunet/gnunet_messenger_service.h>
32
28struct GNUNET_CHAT_Account* 33struct GNUNET_CHAT_Account*
29account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego, 34account_create(const char *name)
30 const char *name)
31{ 35{
32 GNUNET_assert((ego) && (name)); 36 GNUNET_assert(name);
33 37
34 struct GNUNET_CHAT_Account *account = GNUNET_new(struct GNUNET_CHAT_Account); 38 struct GNUNET_CHAT_Account *account = GNUNET_new(struct GNUNET_CHAT_Account);
35 39
36 account->ego = ego; 40 account->ego = NULL;
37 account->directory = NULL; 41 account->directory = NULL;
38 account->name = NULL; 42 account->name = NULL;
39 43
@@ -44,6 +48,19 @@ account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego,
44 return account; 48 return account;
45} 49}
46 50
51struct GNUNET_CHAT_Account*
52account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego,
53 const char *name)
54{
55 GNUNET_assert((ego) && (name));
56
57 struct GNUNET_CHAT_Account *account = account_create(name);
58
59 account->ego = ego;
60
61 return account;
62}
63
47void 64void
48account_update_directory (struct GNUNET_CHAT_Account *account, 65account_update_directory (struct GNUNET_CHAT_Account *account,
49 const char *base_directory) 66 const char *base_directory)
@@ -53,6 +70,12 @@ account_update_directory (struct GNUNET_CHAT_Account *account,
53 if (account->directory) 70 if (account->directory)
54 GNUNET_free(account->directory); 71 GNUNET_free(account->directory);
55 72
73 if (!(account->ego))
74 {
75 account->directory = NULL;
76 return;
77 }
78
56 struct GNUNET_CRYPTO_PublicKey key; 79 struct GNUNET_CRYPTO_PublicKey key;
57 GNUNET_IDENTITY_ego_get_public_key(account->ego, &key); 80 GNUNET_IDENTITY_ego_get_public_key(account->ego, &key);
58 81
@@ -82,6 +105,43 @@ account_get_key (const struct GNUNET_CHAT_Account *account)
82} 105}
83 106
84void 107void
108account_update_ego(struct GNUNET_CHAT_Account *account,
109 struct GNUNET_CHAT_Handle *handle,
110 struct GNUNET_IDENTITY_Ego *ego)
111{
112 GNUNET_assert((account) && (handle) && (ego) && (account->ego != ego));
113
114 enum GNUNET_CHAT_MessageFlag flag;
115 if ((!(account->ego)) && (handle->current != account))
116 flag = GNUNET_CHAT_FLAG_CREATE_ACCOUNT;
117 else
118 flag = GNUNET_CHAT_FLAG_UPDATE_ACCOUNT;
119
120 account->ego = ego;
121
122 if (handle->directory)
123 account_update_directory(account, handle->directory);
124
125 if ((handle->current == account) && (handle->messenger))
126 {
127 GNUNET_MESSENGER_set_key(
128 handle->messenger,
129 GNUNET_IDENTITY_ego_get_private_key(account->ego)
130 );
131
132 handle_update_key(handle);
133 }
134
135 handle_send_internal_message(
136 handle,
137 account,
138 NULL,
139 flag,
140 NULL
141 );
142}
143
144void
85account_destroy(struct GNUNET_CHAT_Account *account) 145account_destroy(struct GNUNET_CHAT_Account *account)
86{ 146{
87 GNUNET_assert(account); 147 GNUNET_assert(account);
diff --git a/src/gnunet_chat_account.h b/src/gnunet_chat_account.h
index f81b85e..228f775 100644
--- a/src/gnunet_chat_account.h
+++ b/src/gnunet_chat_account.h
@@ -25,9 +25,12 @@
25#ifndef GNUNET_CHAT_ACCOUNT_H_ 25#ifndef GNUNET_CHAT_ACCOUNT_H_
26#define GNUNET_CHAT_ACCOUNT_H_ 26#define GNUNET_CHAT_ACCOUNT_H_
27 27
28#include <gnunet/gnunet_common.h>
28#include <gnunet/gnunet_identity_service.h> 29#include <gnunet/gnunet_identity_service.h>
29#include <gnunet/gnunet_util_lib.h> 30#include <gnunet/gnunet_util_lib.h>
30 31
32struct GNUNET_CHAT_Handle;
33
31struct GNUNET_CHAT_Account 34struct GNUNET_CHAT_Account
32{ 35{
33 struct GNUNET_IDENTITY_Ego *ego; 36 struct GNUNET_IDENTITY_Ego *ego;
@@ -38,6 +41,15 @@ struct GNUNET_CHAT_Account
38}; 41};
39 42
40/** 43/**
44 * Creates a chat account using a given <i>name</i>.
45 *
46 * @param[in] name Name
47 * @return New chat account
48 */
49struct GNUNET_CHAT_Account*
50account_create(const char *name);
51
52/**
41 * Creates a chat account using a given <i>ego</i> and 53 * Creates a chat account using a given <i>ego</i> and
42 * a matching <i>name</i>. 54 * a matching <i>name</i>.
43 * 55 *
@@ -71,6 +83,20 @@ const struct GNUNET_CRYPTO_PrivateKey*
71account_get_key (const struct GNUNET_CHAT_Account *account); 83account_get_key (const struct GNUNET_CHAT_Account *account);
72 84
73/** 85/**
86 * Updates the key from a given chat <i>account</i> using
87 * the chat <i>handle</i> and a specific <i>ego</i> matching
88 * the accounts name.
89 *
90 * @param[in,out] account Chat account
91 * @param[in,out] handle Chat handle
92 * @param[in] ego EGO
93 */
94void
95account_update_ego(struct GNUNET_CHAT_Account *account,
96 struct GNUNET_CHAT_Handle *handle,
97 struct GNUNET_IDENTITY_Ego *ego);
98
99/**
74 * Destroys a chat <i>account</i> and frees its memory. 100 * Destroys a chat <i>account</i> and frees its memory.
75 * 101 *
76 * @param[in,out] account Chat account 102 * @param[in,out] account Chat account
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
index e2c7827..3e6ab4d 100644
--- a/src/gnunet_chat_context.c
+++ b/src/gnunet_chat_context.c
@@ -243,7 +243,7 @@ context_update_nick (struct GNUNET_CHAT_Context *context,
243 context->handle, 243 context->handle,
244 NULL, 244 NULL,
245 context, 245 context,
246 GNUNET_CHAT_FLAG_UPDATE, 246 GNUNET_CHAT_FLAG_UPDATE_CONTEXT,
247 NULL 247 NULL
248 ); 248 );
249} 249}
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
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index 18ac62c..bca7790 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -43,6 +43,8 @@
43#include "gnunet_chat_message.h" 43#include "gnunet_chat_message.h"
44#include "gnunet_chat_uri.h" 44#include "gnunet_chat_uri.h"
45 45
46#include "internal/gnunet_chat_accounts.h"
47
46struct GNUNET_CHAT_Handle; 48struct GNUNET_CHAT_Handle;
47 49
48struct GNUNET_CHAT_InternalServices 50struct GNUNET_CHAT_InternalServices
@@ -60,20 +62,6 @@ struct GNUNET_CHAT_InternalMessages
60 struct GNUNET_CHAT_InternalMessages *prev; 62 struct GNUNET_CHAT_InternalMessages *prev;
61}; 63};
62 64
63struct GNUNET_CHAT_InternalAccounts
64{
65 struct GNUNET_CHAT_Account *account;
66 char *identifier;
67
68 struct GNUNET_CHAT_Handle *handle;
69 struct GNUNET_IDENTITY_Operation *op;
70
71 int wait_for_completion;
72
73 struct GNUNET_CHAT_InternalAccounts *next;
74 struct GNUNET_CHAT_InternalAccounts *prev;
75};
76
77struct GNUNET_CHAT_InternalLobbies 65struct GNUNET_CHAT_InternalLobbies
78{ 66{
79 struct GNUNET_CHAT_Lobby *lobby; 67 struct GNUNET_CHAT_Lobby *lobby;
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index e05a2d9..f11312a 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -32,6 +32,7 @@
32#include "gnunet_chat_tagging.h" 32#include "gnunet_chat_tagging.h"
33#include "gnunet_chat_ticket.h" 33#include "gnunet_chat_ticket.h"
34#include "gnunet_chat_util.h" 34#include "gnunet_chat_util.h"
35#include "internal/gnunet_chat_accounts.h"
35 36
36#include <gnunet/gnunet_arm_service.h> 37#include <gnunet/gnunet_arm_service.h>
37#include <gnunet/gnunet_common.h> 38#include <gnunet/gnunet_common.h>
@@ -284,10 +285,7 @@ on_handle_gnunet_identity (void *cls,
284 285
285 struct GNUNET_CHAT_Handle* handle = cls; 286 struct GNUNET_CHAT_Handle* handle = cls;
286 287
287 if (!ctx) 288 if ((!ctx) || (!ego))
288 return;
289
290 if (!ego)
291 goto send_refresh; 289 goto send_refresh;
292 290
293 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; 291 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head;
@@ -304,47 +302,30 @@ on_handle_gnunet_identity (void *cls,
304 { 302 {
305 util_set_name_field(name, &(accounts->account->name)); 303 util_set_name_field(name, &(accounts->account->name));
306 304
307 if (handle->current == accounts->account) 305 handle_send_internal_message(
308 handle_send_internal_message( 306 handle,
309 handle, 307 accounts->account,
310 accounts->account, 308 NULL,
311 NULL, 309 GNUNET_CHAT_FLAG_UPDATE_ACCOUNT,
312 GNUNET_CHAT_FLAG_LOGIN, 310 NULL
313 NULL 311 );
314 );
315 } 312 }
316 else 313 else if (!(accounts->op))
317 { 314 {
318 if (handle->current == accounts->account) 315 if (handle->current == accounts->account)
319 handle_disconnect(handle); 316 handle_disconnect(handle);
320 317
321 account_destroy(accounts->account); 318 account_destroy(accounts->account);
322 319 internal_accounts_destroy(accounts);
323 if (accounts->op)
324 {
325 accounts->account = NULL;
326 goto send_refresh;
327 }
328
329 GNUNET_CONTAINER_DLL_remove(
330 handle->accounts_head,
331 handle->accounts_tail,
332 accounts
333 );
334
335 if (accounts->identifier)
336 GNUNET_free(accounts->identifier);
337
338 GNUNET_free(accounts);
339 } 320 }
340 321
341 goto send_refresh; 322 goto send_refresh;
342 323
343check_matching_name: 324check_matching_name:
344 if ((name) && (accounts->account->name) && 325 if ((name) && (accounts->account->name) && (ego) &&
345 (0 == strcmp(accounts->account->name, name))) 326 (0 == strcmp(accounts->account->name, name)))
346 { 327 {
347 accounts->account->ego = ego; 328 account_update_ego(accounts->account, handle, ego);
348 goto send_refresh; 329 goto send_refresh;
349 } 330 }
350 331
@@ -355,23 +336,14 @@ skip_account:
355 if (!name) 336 if (!name)
356 return; 337 return;
357 338
358 accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts); 339 accounts = internal_accounts_create(
359 accounts->account = account_create_from_ego(ego, name); 340 handle,
360 341 account_create_from_ego(ego, name)
361 accounts->handle = handle; 342 );
362 accounts->op = NULL;
363
364 accounts->wait_for_completion = GNUNET_NO;
365 343
366 if (handle->directory) 344 if (handle->directory)
367 account_update_directory(accounts->account, handle->directory); 345 account_update_directory(accounts->account, handle->directory);
368 346
369 GNUNET_CONTAINER_DLL_insert_tail(
370 handle->accounts_head,
371 handle->accounts_tail,
372 accounts
373 );
374
375send_refresh: 347send_refresh:
376 handle_send_internal_message( 348 handle_send_internal_message(
377 handle, 349 handle,
@@ -393,40 +365,25 @@ cb_account_creation (void *cls,
393 (struct GNUNET_CHAT_InternalAccounts*) cls 365 (struct GNUNET_CHAT_InternalAccounts*) cls
394 ); 366 );
395 367
396 struct GNUNET_CHAT_Handle *handle = accounts->handle; 368 accounts->op = NULL;
397 struct GNUNET_CHAT_Account *account = accounts->account;
398
399 GNUNET_CONTAINER_DLL_remove(
400 handle->accounts_head,
401 handle->accounts_tail,
402 accounts
403 );
404
405 if (accounts->identifier)
406 GNUNET_free(accounts->identifier);
407
408 GNUNET_free(accounts);
409 369
410 if (GNUNET_EC_NONE != ec) 370 if ((!(accounts->account)) && (accounts->identifier))
411 { 371 accounts->account = account_create(
412 handle_send_internal_message( 372 accounts->identifier
413 handle,
414 account,
415 NULL,
416 GNUNET_CHAT_FLAG_WARNING,
417 GNUNET_ErrorCode_get_hint(ec)
418 ); 373 );
419 374
375 internal_accounts_stop_method(accounts);
376
377 if (GNUNET_EC_NONE == ec)
420 return; 378 return;
421 } 379
422 else if (key) 380 handle_send_internal_message(
423 handle_send_internal_message( 381 accounts->handle,
424 handle, 382 accounts->account,
425 NULL, 383 NULL,
426 NULL, 384 GNUNET_CHAT_FLAG_WARNING,
427 GNUNET_CHAT_FLAG_REFRESH, 385 GNUNET_ErrorCode_get_hint(ec)
428 NULL 386 );
429 );
430} 387}
431 388
432void 389void
@@ -439,32 +396,32 @@ cb_account_deletion (void *cls,
439 (struct GNUNET_CHAT_InternalAccounts*) cls 396 (struct GNUNET_CHAT_InternalAccounts*) cls
440 ); 397 );
441 398
442 struct GNUNET_CHAT_Handle *handle = accounts->handle; 399 accounts->op = NULL;
443 struct GNUNET_CHAT_Account *account = accounts->account;
444
445 GNUNET_CONTAINER_DLL_remove(
446 handle->accounts_head,
447 handle->accounts_tail,
448 accounts
449 );
450 400
451 if (accounts->identifier) 401 internal_accounts_stop_method(accounts);
452 GNUNET_free(accounts->identifier);
453 402
454 GNUNET_free(accounts); 403 if (accounts->handle->current == accounts->account)
404 handle_disconnect(accounts->handle);
455 405
456 if (GNUNET_EC_NONE != ec) 406 if (GNUNET_EC_NONE != ec)
457 {
458 handle_send_internal_message( 407 handle_send_internal_message(
459 handle, 408 accounts->handle,
460 account, 409 accounts->account,
461 NULL, 410 NULL,
462 GNUNET_CHAT_FLAG_WARNING, 411 GNUNET_CHAT_FLAG_WARNING,
463 GNUNET_ErrorCode_get_hint(ec) 412 GNUNET_ErrorCode_get_hint(ec)
464 ); 413 );
414 else
415 handle_send_internal_message(
416 accounts->handle,
417 accounts->account,
418 NULL,
419 GNUNET_CHAT_FLAG_DELETE_ACCOUNT,
420 NULL
421 );
465 422
466 return; 423 account_destroy(accounts->account);
467 } 424 internal_accounts_destroy(accounts);
468} 425}
469 426
470void 427void
@@ -477,32 +434,20 @@ cb_account_rename (void *cls,
477 (struct GNUNET_CHAT_InternalAccounts*) cls 434 (struct GNUNET_CHAT_InternalAccounts*) cls
478 ); 435 );
479 436
480 struct GNUNET_CHAT_Handle *handle = accounts->handle; 437 accounts->op = NULL;
481 struct GNUNET_CHAT_Account *account = accounts->account;
482
483 GNUNET_CONTAINER_DLL_remove(
484 handle->accounts_head,
485 handle->accounts_tail,
486 accounts
487 );
488
489 if (accounts->identifier)
490 GNUNET_free(accounts->identifier);
491
492 GNUNET_free(accounts);
493 438
494 if (GNUNET_EC_NONE != ec) 439 internal_accounts_stop_method(accounts);
495 {
496 handle_send_internal_message(
497 handle,
498 account,
499 NULL,
500 GNUNET_CHAT_FLAG_WARNING,
501 GNUNET_ErrorCode_get_hint(ec)
502 );
503 440
441 if (GNUNET_EC_NONE == ec)
504 return; 442 return;
505 } 443
444 handle_send_internal_message(
445 accounts->handle,
446 accounts->account,
447 NULL,
448 GNUNET_CHAT_FLAG_WARNING,
449 GNUNET_ErrorCode_get_hint(ec)
450 );
506} 451}
507 452
508static void 453static void
@@ -516,10 +461,7 @@ cb_account_update_completion (void *cls,
516 (struct GNUNET_CHAT_InternalAccounts*) cls 461 (struct GNUNET_CHAT_InternalAccounts*) cls
517 ); 462 );
518 463
519 struct GNUNET_CHAT_Handle *handle = accounts->handle; 464 accounts->op = NULL;
520
521 if ((GNUNET_EC_NONE == ec) && (key))
522 GNUNET_MESSENGER_set_key(handle->messenger, key);
523 465
524 cb_account_creation(cls, key, ec); 466 cb_account_creation(cls, key, ec);
525} 467}
@@ -534,16 +476,14 @@ cb_account_update (void *cls,
534 (struct GNUNET_CHAT_InternalAccounts*) cls 476 (struct GNUNET_CHAT_InternalAccounts*) cls
535 ); 477 );
536 478
537 struct GNUNET_CHAT_Handle *handle = accounts->handle; 479 if ((GNUNET_EC_NONE != ec) || (!(accounts->identifier)))
538
539 if ((GNUNET_EC_NONE != ec) || (!accounts->identifier))
540 { 480 {
541 cb_account_deletion(cls, ec); 481 cb_account_deletion(cls, ec);
542 return; 482 return;
543 } 483 }
544 484
545 accounts->op = GNUNET_IDENTITY_create( 485 accounts->op = GNUNET_IDENTITY_create(
546 handle->identity, 486 accounts->handle->identity,
547 accounts->identifier, 487 accounts->identifier,
548 NULL, 488 NULL,
549 GNUNET_PUBLIC_KEY_TYPE_ECDSA, 489 GNUNET_PUBLIC_KEY_TYPE_ECDSA,
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index c6e81dc..2014458 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -2036,11 +2036,17 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message)
2036 return GNUNET_CHAT_KIND_LOGIN; 2036 return GNUNET_CHAT_KIND_LOGIN;
2037 case GNUNET_CHAT_FLAG_LOGOUT: 2037 case GNUNET_CHAT_FLAG_LOGOUT:
2038 return GNUNET_CHAT_KIND_LOGOUT; 2038 return GNUNET_CHAT_KIND_LOGOUT;
2039 case GNUNET_CHAT_FLAG_UPDATE: 2039 case GNUNET_CHAT_FLAG_CREATE_ACCOUNT:
2040 return GNUNET_CHAT_KIND_UPDATE; 2040 return GNUNET_CHAT_KIND_CREATED_ACCOUNT;
2041 case GNUNET_CHAT_FLAG_DELETE_ACCOUNT:
2042 return GNUNET_CHAT_KIND_DELETED_ACCOUNT;
2043 case GNUNET_CHAT_FLAG_UPDATE_ACCOUNT:
2044 return GNUNET_CHAT_KIND_UPDATE_ACCOUNT;
2045 case GNUNET_CHAT_FLAG_UPDATE_CONTEXT:
2046 return GNUNET_CHAT_KIND_UPDATE_CONTEXT;
2041 case GNUNET_CHAT_FLAG_ATTRIBUTES: 2047 case GNUNET_CHAT_FLAG_ATTRIBUTES:
2042 return GNUNET_CHAT_KIND_ATTRIBUTES; 2048 return GNUNET_CHAT_KIND_ATTRIBUTES;
2043 case GNUNET_CHAT_FLAG_SHARED_ATTRIBUTES: 2049 case GNUNET_CHAT_FLAG_SHARE_ATTRIBUTES:
2044 return GNUNET_CHAT_KIND_SHARED_ATTRIBUTES; 2050 return GNUNET_CHAT_KIND_SHARED_ATTRIBUTES;
2045 default: 2051 default:
2046 break; 2052 break;
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
index c17f24b..797294a 100644
--- a/src/gnunet_chat_lib_intern.c
+++ b/src/gnunet_chat_lib_intern.c
@@ -45,7 +45,7 @@ task_handle_destruction (void *cls)
45 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; 45 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head;
46 while (accounts) 46 while (accounts)
47 { 47 {
48 if ((accounts->op) && (GNUNET_YES == accounts->wait_for_completion)) 48 if ((accounts->op) && (GNUNET_CHAT_ACCOUNT_NONE != accounts->method))
49 break; 49 break;
50 50
51 accounts = accounts->next; 51 accounts = accounts->next;
@@ -77,8 +77,8 @@ task_handle_disconnection (void *cls)
77 77
78 struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; 78 struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls;
79 79
80 handle_disconnect(handle);
81 handle->disconnection = NULL; 80 handle->disconnection = NULL;
81 handle_disconnect(handle);
82 82
83 if (! handle->next) 83 if (! handle->next)
84 return; 84 return;
@@ -936,7 +936,7 @@ cont_revoke_ticket (void *cls,
936 handle, 936 handle,
937 NULL, 937 NULL,
938 NULL, 938 NULL,
939 GNUNET_CHAT_FLAG_SHARED_ATTRIBUTES, 939 GNUNET_CHAT_FLAG_SHARE_ATTRIBUTES,
940 NULL 940 NULL
941 ); 941 );
942 942
diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h
index dd568ef..bba251c 100644
--- a/src/gnunet_chat_message.h
+++ b/src/gnunet_chat_message.h
@@ -47,9 +47,12 @@ enum GNUNET_CHAT_MessageFlag
47 GNUNET_CHAT_FLAG_REFRESH = 2, 47 GNUNET_CHAT_FLAG_REFRESH = 2,
48 GNUNET_CHAT_FLAG_LOGIN = 3, 48 GNUNET_CHAT_FLAG_LOGIN = 3,
49 GNUNET_CHAT_FLAG_LOGOUT = 4, 49 GNUNET_CHAT_FLAG_LOGOUT = 4,
50 GNUNET_CHAT_FLAG_UPDATE = 5, 50 GNUNET_CHAT_FLAG_CREATE_ACCOUNT = 5,
51 GNUNET_CHAT_FLAG_ATTRIBUTES = 6, 51 GNUNET_CHAT_FLAG_DELETE_ACCOUNT = 6,
52 GNUNET_CHAT_FLAG_SHARED_ATTRIBUTES = 7 52 GNUNET_CHAT_FLAG_UPDATE_ACCOUNT = 7,
53 GNUNET_CHAT_FLAG_UPDATE_CONTEXT = 8,
54 GNUNET_CHAT_FLAG_ATTRIBUTES = 9,
55 GNUNET_CHAT_FLAG_SHARE_ATTRIBUTES = 10
53}; 56};
54 57
55struct GNUNET_CHAT_Message 58struct GNUNET_CHAT_Message
diff --git a/src/internal/gnunet_chat_accounts.c b/src/internal/gnunet_chat_accounts.c
new file mode 100644
index 0000000..9d055e1
--- /dev/null
+++ b/src/internal/gnunet_chat_accounts.c
@@ -0,0 +1,114 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2024 GNUnet e.V.
4
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
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file gnunet_chat_accounts.c
23 */
24
25#include "gnunet_chat_accounts.h"
26
27#include "../gnunet_chat_handle.h"
28
29#include <gnunet/gnunet_common.h>
30
31struct GNUNET_CHAT_InternalAccounts*
32internal_accounts_create(struct GNUNET_CHAT_Handle *handle,
33 struct GNUNET_CHAT_Account *account)
34{
35 GNUNET_assert(handle);
36
37 struct GNUNET_CHAT_InternalAccounts *accounts = GNUNET_new(
38 struct GNUNET_CHAT_InternalAccounts
39 );
40
41 if (!accounts)
42 return NULL;
43
44 accounts->handle = handle;
45 accounts->account = account;
46
47 accounts->identifier = NULL;
48 accounts->op = NULL;
49 accounts->method = GNUNET_CHAT_ACCOUNT_NONE;
50
51 GNUNET_CONTAINER_DLL_insert(
52 accounts->handle->accounts_head,
53 accounts->handle->accounts_tail,
54 accounts
55 );
56
57 return accounts;
58}
59
60void
61internal_accounts_destroy(struct GNUNET_CHAT_InternalAccounts *accounts)
62{
63 GNUNET_assert((accounts) && (accounts->handle));
64
65 GNUNET_CONTAINER_DLL_remove(
66 accounts->handle->accounts_head,
67 accounts->handle->accounts_tail,
68 accounts
69 );
70
71 if (accounts->identifier)
72 GNUNET_free(accounts->identifier);
73
74 if (accounts->op)
75 GNUNET_IDENTITY_cancel(accounts->op);
76
77 GNUNET_free(accounts);
78}
79
80void
81internal_accounts_start_method(struct GNUNET_CHAT_InternalAccounts *accounts,
82 enum GNUNET_CHAT_AccountMethod method,
83 const char *identifier)
84{
85 GNUNET_assert(
86 (accounts) &&
87 (GNUNET_CHAT_ACCOUNT_NONE == accounts->method) &&
88 (!(accounts->identifier)) &&
89 (!(accounts->op))
90 );
91
92 accounts->identifier = identifier ? GNUNET_strdup(identifier) : NULL;
93 accounts->method = method;
94}
95
96void
97internal_accounts_stop_method(struct GNUNET_CHAT_InternalAccounts *accounts)
98{
99 GNUNET_assert(accounts);
100
101 if (accounts->identifier)
102 {
103 GNUNET_free(accounts->identifier);
104 accounts->identifier = NULL;
105 }
106
107 if (accounts->op)
108 {
109 GNUNET_IDENTITY_cancel(accounts->op);
110 accounts->op = NULL;
111 }
112
113 accounts->method = GNUNET_CHAT_ACCOUNT_NONE;
114}
diff --git a/src/internal/gnunet_chat_accounts.h b/src/internal/gnunet_chat_accounts.h
new file mode 100644
index 0000000..65f877a
--- /dev/null
+++ b/src/internal/gnunet_chat_accounts.h
@@ -0,0 +1,71 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2024 GNUnet e.V.
4
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
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file gnunet_chat_accounts.h
23 */
24
25#ifndef GNUNET_CHAT_INTERNAL_ACCOUNTS_H_
26#define GNUNET_CHAT_INTERNAL_ACCOUNTS_H_
27
28#include <gnunet/gnunet_identity_service.h>
29
30enum GNUNET_CHAT_AccountMethod
31{
32 GNUNET_CHAT_ACCOUNT_CREATION = 1,
33 GNUNET_CHAT_ACCOUNT_DELETION = 2,
34 GNUNET_CHAT_ACCOUNT_RENAMING = 3,
35 GNUNET_CHAT_ACCOUNT_UPDATING = 4,
36
37 GNUNET_CHAT_ACCOUNT_NONE = 0
38};
39
40struct GNUNET_CHAT_Handle;
41struct GNUNET_CHAT_Account;
42
43struct GNUNET_CHAT_InternalAccounts
44{
45 struct GNUNET_CHAT_Handle *handle;
46 struct GNUNET_CHAT_Account *account;
47
48 char *identifier;
49 struct GNUNET_IDENTITY_Operation *op;
50 enum GNUNET_CHAT_AccountMethod method;
51
52 struct GNUNET_CHAT_InternalAccounts *next;
53 struct GNUNET_CHAT_InternalAccounts *prev;
54};
55
56struct GNUNET_CHAT_InternalAccounts*
57internal_accounts_create(struct GNUNET_CHAT_Handle *handle,
58 struct GNUNET_CHAT_Account *account);
59
60void
61internal_accounts_destroy(struct GNUNET_CHAT_InternalAccounts *accounts);
62
63void
64internal_accounts_start_method(struct GNUNET_CHAT_InternalAccounts *accounts,
65 enum GNUNET_CHAT_AccountMethod method,
66 const char *identifier);
67
68void
69internal_accounts_stop_method(struct GNUNET_CHAT_InternalAccounts *accounts);
70
71#endif /* GNUNET_CHAT_ACCOUNTS_H_ */
diff --git a/src/internal/meson.build b/src/internal/meson.build
new file mode 100644
index 0000000..510590c
--- /dev/null
+++ b/src/internal/meson.build
@@ -0,0 +1,23 @@
1#
2# This file is part of GNUnet.
3# Copyright (C) 2024 GNUnet e.V.
4#
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
7# by the Free Software Foundation, either version 3 of the License,
8# or (at your option) any later version.
9#
10# GNUnet is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17#
18# SPDX-License-Identifier: AGPL3.0-or-later
19#
20
21gnunetchat_internal_sources = files([
22 'gnunet_chat_accounts.c', 'gnunet_chat_accounts.h'
23])
diff --git a/src/meson.build b/src/meson.build
index 858391c..061e4d3 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -18,6 +18,8 @@
18# SPDX-License-Identifier: AGPL3.0-or-later 18# SPDX-License-Identifier: AGPL3.0-or-later
19# 19#
20 20
21subdir('internal')
22
21gnunetchat_sources = files([ 23gnunetchat_sources = files([
22 'gnunet_chat_account.c', 'gnunet_chat_account.h', 24 'gnunet_chat_account.c', 'gnunet_chat_account.h',
23 'gnunet_chat_contact.c', 'gnunet_chat_contact.h', 25 'gnunet_chat_contact.c', 'gnunet_chat_contact.h',
@@ -33,7 +35,7 @@ gnunetchat_sources = files([
33 'gnunet_chat_uri.c', 'gnunet_chat_uri.h', 35 'gnunet_chat_uri.c', 'gnunet_chat_uri.h',
34 'gnunet_chat_util.c', 'gnunet_chat_util.h', 36 'gnunet_chat_util.c', 'gnunet_chat_util.h',
35 'gnunet_chat_lib.c', 37 'gnunet_chat_lib.c',
36]) 38]) + gnunetchat_internal_sources
37 39
38gnunetchat_internal = files([ 40gnunetchat_internal = files([
39 'gnunet_chat_contact_intern.c', 41 'gnunet_chat_contact_intern.c',
diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c
index 2be8445..8763391 100644
--- a/tests/test_gnunet_chat_handle.c
+++ b/tests/test_gnunet_chat_handle.c
@@ -23,7 +23,15 @@
23 */ 23 */
24 24
25#include "test_gnunet_chat.h" 25#include "test_gnunet_chat.h"
26#include <check.h>
26#include <gnunet/gnunet_chat_lib.h> 27#include <gnunet/gnunet_chat_lib.h>
28#include <string.h>
29
30#define TEST_ACCOUNTS_ID "gnunet_chat_handle_accounts"
31#define TEST_CONNECTION_ID "gnunet_chat_handle_connection"
32#define TEST_UPDATE_ID "gnunet_chat_handle_update"
33#define TEST_RENAME_ID_A "gnunet_chat_handle_rename_a"
34#define TEST_RENAME_ID_B "gnunet_chat_handle_rename_b"
27 35
28void 36void
29call_gnunet_chat_handle_init(const struct GNUNET_CONFIGURATION_Handle *cfg) 37call_gnunet_chat_handle_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -47,18 +55,22 @@ on_gnunet_chat_handle_accounts_it(void *cls,
47 55
48 ck_assert_ptr_ne(handle, NULL); 56 ck_assert_ptr_ne(handle, NULL);
49 ck_assert_ptr_ne(account, NULL); 57 ck_assert_ptr_ne(account, NULL);
58 ck_assert_int_eq(*accounts_stage, 2);
50 59
51 const char *name = GNUNET_CHAT_account_get_name(account); 60 const char *name = GNUNET_CHAT_account_get_name(account);
52 61
53 ck_assert_ptr_ne(name, NULL); 62 ck_assert_ptr_ne(name, NULL);
54 63
55 if (0 == strcmp(name, "gnunet_chat_handle_accounts")) 64 if (0 == strcmp(name, TEST_ACCOUNTS_ID))
56 *accounts_stage |= 2; 65 {
66 *accounts_stage = 3;
67 return GNUNET_NO;
68 }
57 69
58 return GNUNET_YES; 70 return GNUNET_YES;
59} 71}
60 72
61int 73enum GNUNET_GenericReturnValue
62on_gnunet_chat_handle_accounts_msg(void *cls, 74on_gnunet_chat_handle_accounts_msg(void *cls,
63 struct GNUNET_CHAT_Context *context, 75 struct GNUNET_CHAT_Context *context,
64 const struct GNUNET_CHAT_Message *message) 76 const struct GNUNET_CHAT_Message *message)
@@ -69,38 +81,63 @@ on_gnunet_chat_handle_accounts_msg(void *cls,
69 (struct GNUNET_CHAT_Handle**) cls 81 (struct GNUNET_CHAT_Handle**) cls
70 ); 82 );
71 83
72 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
73
74 ck_assert(kind == GNUNET_CHAT_KIND_REFRESH);
75 ck_assert_ptr_ne(handle, NULL); 84 ck_assert_ptr_ne(handle, NULL);
76 ck_assert_ptr_eq(context, NULL); 85 ck_assert_ptr_eq(context, NULL);
77 86
78 GNUNET_CHAT_iterate_accounts( 87 const struct GNUNET_CHAT_Account *account;
79 handle, 88 account = GNUNET_CHAT_message_get_account(message);
80 on_gnunet_chat_handle_accounts_it,
81 &accounts_stage
82 );
83 89
84 if (2 & accounts_stage) 90 switch (GNUNET_CHAT_message_get_kind(message))
85 { 91 {
86 if (3 == accounts_stage) 92 case GNUNET_CHAT_KIND_REFRESH:
87 ck_assert_int_eq(GNUNET_CHAT_account_delete( 93 if (0 == accounts_stage)
88 handle, 94 {
89 "gnunet_chat_handle_accounts" 95 ck_assert_int_eq(GNUNET_CHAT_account_create(
90 ), GNUNET_OK); 96 handle,
91 97 TEST_ACCOUNTS_ID
92 accounts_stage = 4; 98 ), GNUNET_OK);
93 } 99
94 else if (4 == accounts_stage) 100 accounts_stage = 1;
95 GNUNET_CHAT_stop(handle); 101 } else
96 else if (0 == accounts_stage) 102 if (2 == accounts_stage)
97 { 103 {
98 ck_assert_int_eq(GNUNET_CHAT_account_create( 104 ck_assert_int_ge(GNUNET_CHAT_iterate_accounts(
99 handle, 105 handle,
100 "gnunet_chat_handle_accounts" 106 on_gnunet_chat_handle_accounts_it,
101 ), GNUNET_OK); 107 &accounts_stage
102 108 ), 1);
103 accounts_stage = 1; 109 }
110
111 if (3 == accounts_stage)
112 {
113 ck_assert_int_eq(GNUNET_CHAT_account_delete(
114 handle,
115 TEST_ACCOUNTS_ID
116 ), GNUNET_OK);
117
118 accounts_stage = 4;
119 }
120
121 break;
122 case GNUNET_CHAT_KIND_CREATED_ACCOUNT:
123 ck_assert_ptr_ne(account, NULL);
124
125 if (0 == strcmp(GNUNET_CHAT_account_get_name(account),
126 TEST_ACCOUNTS_ID))
127 accounts_stage = 2;
128
129 break;
130 case GNUNET_CHAT_KIND_DELETED_ACCOUNT:
131 ck_assert_int_eq(accounts_stage, 4);
132
133 if (0 == strcmp(GNUNET_CHAT_account_get_name(account),
134 TEST_ACCOUNTS_ID))
135 GNUNET_CHAT_stop(handle);
136
137 break;
138 default:
139 ck_abort();
140 break;
104 } 141 }
105 142
106 return GNUNET_YES; 143 return GNUNET_YES;
@@ -118,31 +155,6 @@ call_gnunet_chat_handle_accounts(const struct GNUNET_CONFIGURATION_Handle *cfg)
118CREATE_GNUNET_TEST(test_gnunet_chat_handle_accounts, call_gnunet_chat_handle_accounts) 155CREATE_GNUNET_TEST(test_gnunet_chat_handle_accounts, call_gnunet_chat_handle_accounts)
119 156
120int 157int
121on_gnunet_chat_handle_connection_it(void *cls,
122 const struct GNUNET_CHAT_Handle *handle,
123 struct GNUNET_CHAT_Account *account)
124{
125 struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls;
126
127 ck_assert_ptr_ne(chat, NULL);
128 ck_assert_ptr_eq(handle, chat);
129 ck_assert_ptr_ne(account, NULL);
130
131 const char *name = GNUNET_CHAT_account_get_name(account);
132
133 ck_assert_ptr_ne(name, NULL);
134 ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL);
135
136 if (0 == strcmp(name, "gnunet_chat_handle_connection"))
137 {
138 GNUNET_CHAT_connect(chat, account);
139 return GNUNET_NO;
140 }
141
142 return GNUNET_YES;
143}
144
145int
146on_gnunet_chat_handle_connection_msg(void *cls, 158on_gnunet_chat_handle_connection_msg(void *cls,
147 struct GNUNET_CHAT_Context *context, 159 struct GNUNET_CHAT_Context *context,
148 const struct GNUNET_CHAT_Message *message) 160 const struct GNUNET_CHAT_Message *message)
@@ -155,27 +167,31 @@ on_gnunet_chat_handle_connection_msg(void *cls,
155 ck_assert_ptr_eq(context, NULL); 167 ck_assert_ptr_eq(context, NULL);
156 ck_assert_ptr_ne(message, NULL); 168 ck_assert_ptr_ne(message, NULL);
157 169
158 if (GNUNET_CHAT_KIND_LOGOUT == GNUNET_CHAT_message_get_kind(message)) 170 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
171
172 if (GNUNET_CHAT_KIND_LOGOUT == kind)
159 { 173 {
160 ck_assert_int_eq(GNUNET_CHAT_account_delete( 174 ck_assert_int_eq(GNUNET_CHAT_account_delete(
161 handle, 175 handle,
162 "gnunet_chat_handle_connection" 176 TEST_CONNECTION_ID
163 ), GNUNET_OK); 177 ), GNUNET_OK);
164 178
165 GNUNET_CHAT_stop(handle); 179 GNUNET_CHAT_stop(handle);
166 return GNUNET_YES; 180 return GNUNET_YES;
167 } 181 }
168 182
169 if (GNUNET_CHAT_KIND_LOGIN == GNUNET_CHAT_message_get_kind(message)) 183 if (GNUNET_CHAT_KIND_CREATED_ACCOUNT == kind)
170 goto skip_iteration; 184 {
185 const struct GNUNET_CHAT_Account *account;
186 account = GNUNET_CHAT_message_get_account(message);
171 187
172 GNUNET_CHAT_iterate_accounts( 188 ck_assert_ptr_ne(account, NULL);
173 handle, 189
174 on_gnunet_chat_handle_connection_it, 190 if (0 == strcmp(GNUNET_CHAT_account_get_name(account),
175 handle 191 TEST_CONNECTION_ID))
176 ); 192 GNUNET_CHAT_connect(handle, account);
193 }
177 194
178skip_iteration:
179 if (!GNUNET_CHAT_get_connected(handle)) 195 if (!GNUNET_CHAT_get_connected(handle))
180 return GNUNET_YES; 196 return GNUNET_YES;
181 197
@@ -192,38 +208,13 @@ call_gnunet_chat_handle_connection(const struct GNUNET_CONFIGURATION_Handle *cfg
192 ck_assert_ptr_ne(handle, NULL); 208 ck_assert_ptr_ne(handle, NULL);
193 ck_assert_int_eq(GNUNET_CHAT_account_create( 209 ck_assert_int_eq(GNUNET_CHAT_account_create(
194 handle, 210 handle,
195 "gnunet_chat_handle_connection" 211 TEST_CONNECTION_ID
196 ), GNUNET_OK); 212 ), GNUNET_OK);
197} 213}
198 214
199CREATE_GNUNET_TEST(test_gnunet_chat_handle_connection, call_gnunet_chat_handle_connection) 215CREATE_GNUNET_TEST(test_gnunet_chat_handle_connection, call_gnunet_chat_handle_connection)
200 216
201int 217int
202on_gnunet_chat_handle_update_it(void *cls,
203 const struct GNUNET_CHAT_Handle *handle,
204 struct GNUNET_CHAT_Account *account)
205{
206 struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls;
207
208 ck_assert_ptr_ne(chat, NULL);
209 ck_assert_ptr_eq(handle, chat);
210 ck_assert_ptr_ne(account, NULL);
211
212 const char *name = GNUNET_CHAT_account_get_name(account);
213
214 ck_assert_ptr_ne(name, NULL);
215 ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL);
216
217 if (0 == strcmp(name, "gnunet_chat_handle_update"))
218 {
219 GNUNET_CHAT_connect(chat, account);
220 return GNUNET_NO;
221 }
222
223 return GNUNET_YES;
224}
225
226int
227on_gnunet_chat_handle_update_msg(void *cls, 218on_gnunet_chat_handle_update_msg(void *cls,
228 struct GNUNET_CHAT_Context *context, 219 struct GNUNET_CHAT_Context *context,
229 const struct GNUNET_CHAT_Message *message) 220 const struct GNUNET_CHAT_Message *message)
@@ -238,65 +229,113 @@ on_gnunet_chat_handle_update_msg(void *cls,
238 ck_assert_ptr_eq(context, NULL); 229 ck_assert_ptr_eq(context, NULL);
239 ck_assert_ptr_ne(message, NULL); 230 ck_assert_ptr_ne(message, NULL);
240 231
241 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); 232 const struct GNUNET_CHAT_Account *account;
233 account = GNUNET_CHAT_message_get_account(message);
242 234
243 if (GNUNET_CHAT_get_connected(handle)) 235 const char *key;
244 goto skip_search_account; 236 char *dup;
245 237
246 GNUNET_CHAT_iterate_accounts( 238 switch (GNUNET_CHAT_message_get_kind(message))
247 handle, 239 {
248 on_gnunet_chat_handle_update_it, 240 case GNUNET_CHAT_KIND_REFRESH:
249 handle 241 break;
250 ); 242 case GNUNET_CHAT_KIND_LOGIN:
243 account = GNUNET_CHAT_get_connected(handle);
251 244
252 if (!GNUNET_CHAT_get_connected(handle)) 245 ck_assert_ptr_ne(account, NULL);
253 return GNUNET_YES; 246 ck_assert_str_eq(
247 GNUNET_CHAT_account_get_name(account),
248 TEST_UPDATE_ID
249 );
254 250
255skip_search_account: 251 key = GNUNET_CHAT_get_key(handle);
256 if (GNUNET_CHAT_KIND_LOGOUT == kind) 252 ck_assert_ptr_ne(key, NULL);
257 {
258 if (update_stage < 2)
259 return GNUNET_YES;
260 253
261 ck_assert_int_eq(GNUNET_CHAT_account_delete( 254 dup = (char*) GNUNET_CHAT_get_user_pointer(handle);
262 handle,
263 "gnunet_chat_handle_update"
264 ), GNUNET_OK);
265 255
266 GNUNET_CHAT_stop(handle); 256 ck_assert_int_eq(update_stage, 1);
267 return GNUNET_YES;
268 }
269 257
270 if (GNUNET_CHAT_KIND_LOGIN != kind) 258 dup = GNUNET_strdup(key);
271 return GNUNET_YES;
272 259
273 const char *key = GNUNET_CHAT_get_key(handle); 260 ck_assert_ptr_ne(dup, NULL);
274 ck_assert_ptr_ne(key, NULL); 261 ck_assert_str_eq(key, dup);
275 262
276 char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle); 263 GNUNET_CHAT_set_user_pointer(handle, (void*) dup);
264 GNUNET_CHAT_update(handle);
277 265
278 if (!dup) 266 update_stage = 2;
279 { 267 break;
280 dup = GNUNET_strdup(key); 268 case GNUNET_CHAT_KIND_LOGOUT:
269 account = GNUNET_CHAT_get_connected(handle);
281 270
282 ck_assert_ptr_ne(dup, NULL); 271 ck_assert_int_ge(update_stage, 2);
283 ck_assert_str_eq(key, dup); 272 ck_assert_int_le(update_stage, 3);
284 273
285 GNUNET_CHAT_set_user_pointer(handle, (void*) dup); 274 ck_assert_ptr_ne(account, NULL);
286 GNUNET_CHAT_update(handle); 275 ck_assert_str_eq(
276 GNUNET_CHAT_account_get_name(account),
277 TEST_UPDATE_ID
278 );
287 279
288 update_stage = 1; 280 if (update_stage == 3)
289 } 281 {
290 else 282 ck_assert_int_eq(GNUNET_CHAT_account_delete(
291 { 283 handle,
292 ck_assert_ptr_ne(dup, NULL); 284 TEST_UPDATE_ID
293 ck_assert_str_ne(key, dup); 285 ), GNUNET_OK);
286
287 update_stage = 4;
288 }
289
290 break;
291 case GNUNET_CHAT_KIND_CREATED_ACCOUNT:
292 ck_assert_ptr_ne(account, NULL);
293
294 if ((0 != strcmp(GNUNET_CHAT_account_get_name(account),
295 TEST_UPDATE_ID)))
296 break;
297
298 ck_assert_int_eq(update_stage, 0);
299
300 update_stage = 1;
301 GNUNET_CHAT_connect(handle, account);
302 break;
303 case GNUNET_CHAT_KIND_DELETED_ACCOUNT:
304 ck_assert_ptr_ne(account, NULL);
305
306 if ((0 != strcmp(GNUNET_CHAT_account_get_name(account),
307 TEST_UPDATE_ID)))
308 break;
309
310 ck_assert_int_eq(update_stage, 4);
311
312 GNUNET_CHAT_stop(handle);
313 break;
314 case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
315 ck_assert_ptr_ne(account, NULL);
294 316
295 GNUNET_free(dup); 317 if ((0 != strcmp(GNUNET_CHAT_account_get_name(account),
318 TEST_UPDATE_ID)))
319 break;
320
321 key = GNUNET_CHAT_get_key(handle);
322 ck_assert_ptr_ne(key, NULL);
296 323
297 GNUNET_CHAT_disconnect(handle); 324 dup = (char*) GNUNET_CHAT_get_user_pointer(handle);
298 325
299 update_stage = 2; 326 ck_assert_int_eq(update_stage, 2);
327 ck_assert_ptr_ne(dup, NULL);
328 ck_assert_str_ne(key, dup);
329
330 GNUNET_free(dup);
331
332 GNUNET_CHAT_disconnect(handle);
333
334 update_stage = 3;
335 break;
336 default:
337 ck_abort();
338 break;
300 } 339 }
301 340
302 return GNUNET_YES; 341 return GNUNET_YES;
@@ -311,38 +350,13 @@ call_gnunet_chat_handle_update(const struct GNUNET_CONFIGURATION_Handle *cfg)
311 ck_assert_ptr_ne(handle, NULL); 350 ck_assert_ptr_ne(handle, NULL);
312 ck_assert_int_eq(GNUNET_CHAT_account_create( 351 ck_assert_int_eq(GNUNET_CHAT_account_create(
313 handle, 352 handle,
314 "gnunet_chat_handle_update" 353 TEST_UPDATE_ID
315 ), GNUNET_OK); 354 ), GNUNET_OK);
316} 355}
317 356
318CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_update) 357CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_update)
319 358
320int 359int
321on_gnunet_chat_handle_rename_it(void *cls,
322 const struct GNUNET_CHAT_Handle *handle,
323 struct GNUNET_CHAT_Account *account)
324{
325 struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls;
326
327 ck_assert_ptr_ne(chat, NULL);
328 ck_assert_ptr_eq(handle, chat);
329 ck_assert_ptr_ne(account, NULL);
330
331 const char *name = GNUNET_CHAT_account_get_name(account);
332
333 ck_assert_ptr_ne(name, NULL);
334 ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL);
335
336 if (0 == strcmp(name, "gnunet_chat_handle_rename_a"))
337 {
338 GNUNET_CHAT_connect(chat, account);
339 return GNUNET_NO;
340 }
341
342 return GNUNET_YES;
343}
344
345int
346on_gnunet_chat_handle_rename_msg(void *cls, 360on_gnunet_chat_handle_rename_msg(void *cls,
347 struct GNUNET_CHAT_Context *context, 361 struct GNUNET_CHAT_Context *context,
348 const struct GNUNET_CHAT_Message *message) 362 const struct GNUNET_CHAT_Message *message)
@@ -355,62 +369,68 @@ on_gnunet_chat_handle_rename_msg(void *cls,
355 ck_assert_ptr_eq(context, NULL); 369 ck_assert_ptr_eq(context, NULL);
356 ck_assert_ptr_ne(message, NULL); 370 ck_assert_ptr_ne(message, NULL);
357 371
358 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); 372 const struct GNUNET_CHAT_Account *account;
359 373 account = GNUNET_CHAT_message_get_account(message);
360 if (GNUNET_CHAT_get_connected(handle))
361 goto skip_search_account;
362
363 GNUNET_CHAT_iterate_accounts(
364 handle,
365 on_gnunet_chat_handle_rename_it,
366 handle
367 );
368
369 if (!GNUNET_CHAT_get_connected(handle))
370 return GNUNET_YES;
371
372skip_search_account:
373 if (GNUNET_CHAT_KIND_LOGOUT == kind)
374 {
375 ck_assert_int_eq(GNUNET_CHAT_account_delete(
376 handle,
377 "gnunet_chat_handle_rename_b"
378 ), GNUNET_OK);
379
380 GNUNET_CHAT_stop(handle);
381 return GNUNET_YES;
382 }
383
384 if (GNUNET_CHAT_KIND_LOGIN != kind)
385 return GNUNET_YES;
386 374
387 const char *name = GNUNET_CHAT_get_name(handle); 375 const char *name = GNUNET_CHAT_get_name(handle);
388 ck_assert_ptr_ne(name, NULL);
389
390 char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle); 376 char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle);
391 377
392 if (!dup) 378 printf("%d\n", (int) GNUNET_CHAT_message_get_kind(message));
393 {
394 dup = GNUNET_strdup(name);
395 379
396 ck_assert_ptr_ne(dup, NULL); 380 switch (GNUNET_CHAT_message_get_kind(message))
397 ck_assert_str_eq(name, dup); 381 {
382 case GNUNET_CHAT_KIND_REFRESH:
383 break;
384 case GNUNET_CHAT_KIND_LOGIN:
385 ck_assert_ptr_ne(account, NULL);
386 ck_assert_ptr_ne(name, NULL);
387 ck_assert_ptr_eq(dup, NULL);
388 ck_assert_str_eq(name, TEST_RENAME_ID_A);
398 389
399 GNUNET_CHAT_set_user_pointer(handle, (void*) dup); 390 dup = GNUNET_strdup(name);
400 391
401 ck_assert_int_eq(GNUNET_CHAT_set_name( 392 ck_assert_ptr_ne(dup, NULL);
402 handle, 393 ck_assert_str_eq(name, dup);
403 "gnunet_chat_handle_rename_b"
404 ), GNUNET_YES);
405 }
406 else if (0 != strcmp(name, dup))
407 {
408 ck_assert_ptr_ne(dup, NULL);
409 ck_assert_str_ne(name, dup);
410 394
411 GNUNET_free(dup); 395 GNUNET_CHAT_set_user_pointer(handle, (void*) dup);
412 396
413 GNUNET_CHAT_disconnect(handle); 397 ck_assert_int_eq(GNUNET_CHAT_set_name(
398 handle,
399 TEST_RENAME_ID_B
400 ), GNUNET_YES);
401 break;
402 case GNUNET_CHAT_KIND_LOGOUT:
403 ck_assert_ptr_ne(account, NULL);
404 ck_assert_int_eq(GNUNET_CHAT_account_delete(
405 handle,
406 TEST_RENAME_ID_B
407 ), GNUNET_OK);
408 break;
409 case GNUNET_CHAT_KIND_CREATED_ACCOUNT:
410 ck_assert_ptr_ne(account, NULL);
411
412 GNUNET_CHAT_connect(handle, account);
413 break;
414 case GNUNET_CHAT_KIND_DELETED_ACCOUNT:
415 ck_assert_ptr_ne(account, NULL);
416
417 GNUNET_CHAT_stop(handle);
418 break;
419 case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
420 ck_assert_ptr_ne(account, NULL);
421 ck_assert_ptr_ne(name, NULL);
422 ck_assert_ptr_ne(dup, NULL);
423 ck_assert_str_ne(name, dup);
424 ck_assert_str_eq(name, TEST_RENAME_ID_B);
425 ck_assert_str_eq(dup, TEST_RENAME_ID_A);
426
427 GNUNET_free(dup);
428
429 GNUNET_CHAT_disconnect(handle);
430 break;
431 default:
432 ck_abort();
433 break;
414 } 434 }
415 435
416 return GNUNET_YES; 436 return GNUNET_YES;
@@ -425,7 +445,7 @@ call_gnunet_chat_handle_rename(const struct GNUNET_CONFIGURATION_Handle *cfg)
425 ck_assert_ptr_ne(handle, NULL); 445 ck_assert_ptr_ne(handle, NULL);
426 ck_assert_int_eq(GNUNET_CHAT_account_create( 446 ck_assert_int_eq(GNUNET_CHAT_account_create(
427 handle, 447 handle,
428 "gnunet_chat_handle_rename_a" 448 TEST_RENAME_ID_A
429 ), GNUNET_OK); 449 ), GNUNET_OK);
430} 450}
431 451
diff --git a/tools/gnunet_chat_lib_uml.c b/tools/gnunet_chat_lib_uml.c
index 3459e5b..4e64a71 100644
--- a/tools/gnunet_chat_lib_uml.c
+++ b/tools/gnunet_chat_lib_uml.c
@@ -99,8 +99,17 @@ chat_message (void *cls,
99 case GNUNET_CHAT_KIND_LOGOUT: 99 case GNUNET_CHAT_KIND_LOGOUT:
100 kind_name = "LOGOUT"; 100 kind_name = "LOGOUT";
101 break; 101 break;
102 case GNUNET_CHAT_KIND_UPDATE: 102 case GNUNET_CHAT_KIND_CREATED_ACCOUNT:
103 kind_name = "UPDATE"; 103 kind_name = "CREATED_ACCOUNT";
104 break;
105 case GNUNET_CHAT_KIND_DELETED_ACCOUNT:
106 kind_name = "DELETED_ACCOUNT";
107 break;
108 case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
109 kind_name = "UPDATE_ACCOUNT";
110 break;
111 case GNUNET_CHAT_KIND_UPDATE_CONTEXT:
112 kind_name = "UPDATE_CONTEXT";
104 break; 113 break;
105 case GNUNET_CHAT_KIND_JOIN: 114 case GNUNET_CHAT_KIND_JOIN:
106 kind_name = "JOIN"; 115 kind_name = "JOIN";
@@ -126,6 +135,12 @@ chat_message (void *cls,
126 case GNUNET_CHAT_KIND_TAG: 135 case GNUNET_CHAT_KIND_TAG:
127 kind_name = "TAG"; 136 kind_name = "TAG";
128 break; 137 break;
138 case GNUNET_CHAT_KIND_ATTRIBUTES:
139 kind_name = "ATTRIBUTES";
140 break;
141 case GNUNET_CHAT_KIND_SHARED_ATTRIBUTES:
142 kind_name = "SHARED_ATTRIBUTES";
143 break;
129 default: 144 default:
130 break; 145 break;
131 } 146 }