aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet_chat_lib.c')
-rw-r--r--src/gnunet_chat_lib.c74
1 files changed, 65 insertions, 9 deletions
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index 72db7cd..6739d15 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -67,10 +67,12 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle)
67{ 67{
68 GNUNET_CHAT_VERSION_ASSERT(); 68 GNUNET_CHAT_VERSION_ASSERT();
69 69
70 if (!handle) 70 if ((!handle) || (handle->destruction))
71 return; 71 return;
72 72
73 handle_destroy(handle); 73 handle->destruction = GNUNET_SCHEDULER_add_now(
74 task_handle_destruction, handle
75 );
74} 76}
75 77
76 78
@@ -93,23 +95,76 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle,
93 (0 == strcmp(accounts->account->name, name))) 95 (0 == strcmp(accounts->account->name, name)))
94 return GNUNET_NO; 96 return GNUNET_NO;
95 97
96skip_account: 98 skip_account:
97 accounts = accounts->next; 99 accounts = accounts->next;
98 } 100 }
99 101
100 if (handle->creation_op) 102 accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts);
101 GNUNET_IDENTITY_cancel(handle->creation_op); 103 accounts->account = NULL;
104 accounts->handle = handle;
102 105
103 handle->creation_op = GNUNET_IDENTITY_create( 106 accounts->op = GNUNET_IDENTITY_create(
104 handle->identity, 107 handle->identity,
105 name, 108 name,
106 NULL, 109 NULL,
107 GNUNET_IDENTITY_TYPE_ECDSA, 110 GNUNET_IDENTITY_TYPE_ECDSA,
108 cb_account_creation, 111 cb_account_creation,
109 handle 112 accounts
113 );
114
115 if (!(accounts->op))
116 {
117 GNUNET_free(accounts);
118 return GNUNET_SYSERR;
119 }
120
121 GNUNET_CONTAINER_DLL_insert_tail(
122 handle->accounts_head,
123 handle->accounts_tail,
124 accounts
125 );
126
127 return GNUNET_OK;
128}
129
130
131int
132GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle,
133 const char* name)
134{
135 GNUNET_CHAT_VERSION_ASSERT();
136
137 if ((!handle) || (!name))
138 return GNUNET_SYSERR;
139
140 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head;
141 while (accounts)
142 {
143 if (!(accounts->account))
144 goto skip_account;
145
146 if ((accounts->account->name) &&
147 (0 == strcmp(accounts->account->name, name)))
148 break;
149
150 skip_account:
151 accounts = accounts->next;
152 }
153
154 if (!accounts)
155 return GNUNET_NO;
156
157 if (accounts->op)
158 GNUNET_IDENTITY_cancel(accounts->op);
159
160 accounts->op = GNUNET_IDENTITY_delete(
161 handle->identity,
162 name,
163 cb_account_deletion,
164 accounts
110 ); 165 );
111 166
112 return (handle->creation_op? GNUNET_OK : GNUNET_SYSERR); 167 return (accounts->op? GNUNET_OK : GNUNET_SYSERR);
113} 168}
114 169
115 170
@@ -129,13 +184,14 @@ GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle,
129 while (accounts) 184 while (accounts)
130 { 185 {
131 if (!(accounts->account)) 186 if (!(accounts->account))
132 return GNUNET_SYSERR; 187 goto skip_account;
133 188
134 result++; 189 result++;
135 190
136 if ((callback) && (GNUNET_YES != callback(cls, handle, accounts->account))) 191 if ((callback) && (GNUNET_YES != callback(cls, handle, accounts->account)))
137 break; 192 break;
138 193
194 skip_account:
139 accounts = accounts->next; 195 accounts = accounts->next;
140 } 196 }
141 197