diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-04-06 02:30:45 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-04-06 02:30:45 +0200 |
commit | 4423dd264ef99fe9617e5d871857d15e88639f51 (patch) | |
tree | b242b1ad2fb5d433000dd6d5c1f1d6d5b9c665dd | |
parent | de5dccb421f01bb09764ae1da40cb226c30b8d45 (diff) | |
download | libgnunetchat-4423dd264ef99fe9617e5d871857d15e88639f51.tar.gz libgnunetchat-4423dd264ef99fe9617e5d871857d15e88639f51.zip |
Added some safety for stopping chat handle
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | include/gnunet_chat_lib.h | 5 | ||||
-rw-r--r-- | src/gnunet_chat_handle.c | 114 | ||||
-rw-r--r-- | src/gnunet_chat_handle.h | 24 | ||||
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 76 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 74 | ||||
-rw-r--r-- | src/gnunet_chat_lib_intern.c | 60 | ||||
-rw-r--r-- | src/gnunet_chat_lobby.c | 17 | ||||
-rw-r--r-- | src/gnunet_chat_lobby.h | 4 | ||||
-rw-r--r-- | src/gnunet_chat_lobby_intern.c | 30 | ||||
-rw-r--r-- | src/gnunet_chat_message.c | 5 | ||||
-rw-r--r-- | src/gnunet_chat_message.h | 1 | ||||
-rw-r--r-- | tests/test_gnunet_chat_lobby.c | 8 |
12 files changed, 257 insertions, 161 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index 6d3a581..2590dd2 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h | |||
@@ -365,12 +365,9 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle, | |||
365 | * Deletes an existing chat account of a given chat <i>handle</i> under a | 365 | * Deletes an existing chat account of a given chat <i>handle</i> under a |
366 | * unique <i>name</i>. | 366 | * unique <i>name</i>. |
367 | * | 367 | * |
368 | * If there is no account known to this chat handle under the provided name, the | ||
369 | * function will fail and return #GNUNET_NO. | ||
370 | * | ||
371 | * @param[in,out] handle Chat handle | 368 | * @param[in,out] handle Chat handle |
372 | * @param[in] name Account name | 369 | * @param[in] name Account name |
373 | * @return #GNUNET_OK on success, #GNUNET_NO on failure and otherwise #GNUNET_SYSERR | 370 | * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR |
374 | */ | 371 | */ |
375 | int | 372 | int |
376 | GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle, | 373 | GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle, |
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c index c5d70a8..05c0054 100644 --- a/src/gnunet_chat_handle.c +++ b/src/gnunet_chat_handle.c | |||
@@ -377,6 +377,115 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle) | |||
377 | handle_update_key(handle); | 377 | handle_update_key(handle); |
378 | } | 378 | } |
379 | 379 | ||
380 | int | ||
381 | handle_create_account (struct GNUNET_CHAT_Handle *handle, | ||
382 | const char *name) | ||
383 | { | ||
384 | GNUNET_assert((handle) && (name)); | ||
385 | |||
386 | struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; | ||
387 | while (accounts) | ||
388 | { | ||
389 | if (!(accounts->account)) | ||
390 | goto skip_account; | ||
391 | |||
392 | if ((accounts->account->name) && | ||
393 | (0 == strcmp(accounts->account->name, name))) | ||
394 | return GNUNET_NO; | ||
395 | |||
396 | skip_account: | ||
397 | accounts = accounts->next; | ||
398 | } | ||
399 | |||
400 | accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts); | ||
401 | accounts->account = NULL; | ||
402 | accounts->handle = handle; | ||
403 | |||
404 | accounts->op = GNUNET_IDENTITY_create( | ||
405 | handle->identity, | ||
406 | name, | ||
407 | NULL, | ||
408 | GNUNET_IDENTITY_TYPE_ECDSA, | ||
409 | cb_account_creation, | ||
410 | accounts | ||
411 | ); | ||
412 | |||
413 | if (!(accounts->op)) | ||
414 | { | ||
415 | GNUNET_free(accounts); | ||
416 | return GNUNET_SYSERR; | ||
417 | } | ||
418 | |||
419 | GNUNET_CONTAINER_DLL_insert_tail( | ||
420 | handle->accounts_head, | ||
421 | handle->accounts_tail, | ||
422 | accounts | ||
423 | ); | ||
424 | |||
425 | return GNUNET_OK; | ||
426 | } | ||
427 | |||
428 | int | ||
429 | handle_delete_account (struct GNUNET_CHAT_Handle *handle, | ||
430 | const char *name) | ||
431 | { | ||
432 | GNUNET_assert((handle) && (name)); | ||
433 | |||
434 | struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; | ||
435 | while (accounts) | ||
436 | { | ||
437 | if (!(accounts->account)) | ||
438 | goto skip_account; | ||
439 | |||
440 | if ((accounts->account->name) && | ||
441 | (0 == strcmp(accounts->account->name, name))) | ||
442 | break; | ||
443 | |||
444 | skip_account: | ||
445 | accounts = accounts->next; | ||
446 | } | ||
447 | |||
448 | if (!accounts) | ||
449 | { | ||
450 | accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts); | ||
451 | accounts->account = NULL; | ||
452 | accounts->handle = handle; | ||
453 | |||
454 | accounts->op = GNUNET_IDENTITY_delete( | ||
455 | handle->identity, | ||
456 | name, | ||
457 | cb_account_deletion, | ||
458 | accounts | ||
459 | ); | ||
460 | |||
461 | if (!(accounts->op)) | ||
462 | { | ||
463 | GNUNET_free(accounts); | ||
464 | return GNUNET_SYSERR; | ||
465 | } | ||
466 | |||
467 | GNUNET_CONTAINER_DLL_insert_tail( | ||
468 | handle->accounts_head, | ||
469 | handle->accounts_tail, | ||
470 | accounts | ||
471 | ); | ||
472 | |||
473 | return GNUNET_OK; | ||
474 | } | ||
475 | |||
476 | if (accounts->op) | ||
477 | GNUNET_IDENTITY_cancel(accounts->op); | ||
478 | |||
479 | accounts->op = GNUNET_IDENTITY_delete( | ||
480 | handle->identity, | ||
481 | name, | ||
482 | cb_account_deletion, | ||
483 | accounts | ||
484 | ); | ||
485 | |||
486 | return (accounts->op? GNUNET_OK : GNUNET_SYSERR); | ||
487 | } | ||
488 | |||
380 | const char* | 489 | const char* |
381 | handle_get_directory (const struct GNUNET_CHAT_Handle *handle) | 490 | handle_get_directory (const struct GNUNET_CHAT_Handle *handle) |
382 | { | 491 | { |
@@ -412,7 +521,7 @@ handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, | |||
412 | { | 521 | { |
413 | GNUNET_assert((handle) && (GNUNET_CHAT_FLAG_NONE != flag)); | 522 | GNUNET_assert((handle) && (GNUNET_CHAT_FLAG_NONE != flag)); |
414 | 523 | ||
415 | if (!(handle->msg_cb)) | 524 | if ((handle->destruction) || (!(handle->msg_cb))) |
416 | return; | 525 | return; |
417 | 526 | ||
418 | struct GNUNET_CHAT_InternalMessages *internal = GNUNET_new( | 527 | struct GNUNET_CHAT_InternalMessages *internal = GNUNET_new( |
@@ -444,6 +553,9 @@ handle_send_room_name (struct GNUNET_CHAT_Handle *handle, | |||
444 | { | 553 | { |
445 | GNUNET_assert((handle) && (handle->messenger) && (room)); | 554 | GNUNET_assert((handle) && (handle->messenger) && (room)); |
446 | 555 | ||
556 | if (handle->destruction) | ||
557 | return; | ||
558 | |||
447 | const char *name = GNUNET_MESSENGER_get_name(handle->messenger); | 559 | const char *name = GNUNET_MESSENGER_get_name(handle->messenger); |
448 | 560 | ||
449 | if (!name) | 561 | if (!name) |
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h index 3028186..37a6faf 100644 --- a/src/gnunet_chat_handle.h +++ b/src/gnunet_chat_handle.h | |||
@@ -177,6 +177,30 @@ void | |||
177 | handle_disconnect (struct GNUNET_CHAT_Handle *handle); | 177 | handle_disconnect (struct GNUNET_CHAT_Handle *handle); |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * Enqueues a creation for a chat account with a specific | ||
181 | * <i>name</i> as identifier for a given chat <i>handle</i>. | ||
182 | * | ||
183 | * @param[in,out] handle Chat handle | ||
184 | * @param[in] name Chat account name | ||
185 | * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR | ||
186 | */ | ||
187 | int | ||
188 | handle_create_account (struct GNUNET_CHAT_Handle *handle, | ||
189 | const char *name); | ||
190 | |||
191 | /** | ||
192 | * Enqueues a deletion for a chat account with a specific | ||
193 | * <i>name</i> as identifier for a given chat <i>handle</i>. | ||
194 | * | ||
195 | * @param[in,out] handle Chat handle | ||
196 | * @param[in] name Chat account name | ||
197 | * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR | ||
198 | */ | ||
199 | int | ||
200 | handle_delete_account (struct GNUNET_CHAT_Handle *handle, | ||
201 | const char *name); | ||
202 | |||
203 | /** | ||
180 | * Returns the main directory path to store information | 204 | * Returns the main directory path to store information |
181 | * of a given chat <i>handle</i>. | 205 | * of a given chat <i>handle</i>. |
182 | * | 206 | * |
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index e278eaf..08b7cfd 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -259,6 +259,12 @@ on_handle_gnunet_identity(void *cls, | |||
259 | 259 | ||
260 | account_destroy(accounts->account); | 260 | account_destroy(accounts->account); |
261 | 261 | ||
262 | if (accounts->op) | ||
263 | { | ||
264 | accounts->account = NULL; | ||
265 | goto send_refresh; | ||
266 | } | ||
267 | |||
262 | GNUNET_CONTAINER_DLL_remove( | 268 | GNUNET_CONTAINER_DLL_remove( |
263 | handle->accounts_head, | 269 | handle->accounts_head, |
264 | handle->accounts_tail, | 270 | handle->accounts_tail, |
@@ -271,7 +277,7 @@ on_handle_gnunet_identity(void *cls, | |||
271 | goto send_refresh; | 277 | goto send_refresh; |
272 | 278 | ||
273 | check_matching_name: | 279 | check_matching_name: |
274 | if ((accounts->account->name) && (name) && | 280 | if ((name) && (accounts->account->name) && |
275 | (0 == strcmp(accounts->account->name, name))) | 281 | (0 == strcmp(accounts->account->name, name))) |
276 | { | 282 | { |
277 | accounts->account->ego = ego; | 283 | accounts->account->ego = ego; |
@@ -304,6 +310,60 @@ send_refresh: | |||
304 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_REFRESH, NULL); | 310 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_REFRESH, NULL); |
305 | } | 311 | } |
306 | 312 | ||
313 | void | ||
314 | cb_account_creation (void *cls, | ||
315 | const struct GNUNET_IDENTITY_PrivateKey *key, | ||
316 | const char *emsg) | ||
317 | { | ||
318 | GNUNET_assert(cls); | ||
319 | |||
320 | struct GNUNET_CHAT_InternalAccounts *accounts = ( | ||
321 | (struct GNUNET_CHAT_InternalAccounts*) cls | ||
322 | ); | ||
323 | |||
324 | struct GNUNET_CHAT_Handle *handle = accounts->handle; | ||
325 | |||
326 | GNUNET_CONTAINER_DLL_remove( | ||
327 | handle->accounts_head, | ||
328 | handle->accounts_tail, | ||
329 | accounts | ||
330 | ); | ||
331 | |||
332 | GNUNET_free(accounts); | ||
333 | |||
334 | if (emsg) | ||
335 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_WARNING, emsg); | ||
336 | else if (key) | ||
337 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_REFRESH, NULL); | ||
338 | } | ||
339 | |||
340 | void | ||
341 | cb_account_deletion (void *cls, | ||
342 | const char *emsg) | ||
343 | { | ||
344 | GNUNET_assert(cls); | ||
345 | |||
346 | struct GNUNET_CHAT_InternalAccounts *accounts = ( | ||
347 | (struct GNUNET_CHAT_InternalAccounts*) cls | ||
348 | ); | ||
349 | |||
350 | struct GNUNET_CHAT_Handle *handle = accounts->handle; | ||
351 | |||
352 | GNUNET_CONTAINER_DLL_remove( | ||
353 | handle->accounts_head, | ||
354 | handle->accounts_tail, | ||
355 | accounts | ||
356 | ); | ||
357 | |||
358 | GNUNET_free(accounts); | ||
359 | |||
360 | if (emsg) | ||
361 | { | ||
362 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_WARNING, emsg); | ||
363 | return; | ||
364 | } | ||
365 | } | ||
366 | |||
307 | int | 367 | int |
308 | intern_provide_contact_for_member(struct GNUNET_CHAT_Handle *handle, | 368 | intern_provide_contact_for_member(struct GNUNET_CHAT_Handle *handle, |
309 | const struct GNUNET_MESSENGER_Contact *member, | 369 | const struct GNUNET_MESSENGER_Contact *member, |
@@ -410,6 +470,13 @@ on_monitor_namestore_record(void *cls, | |||
410 | { | 470 | { |
411 | struct GNUNET_CHAT_Handle *chat = cls; | 471 | struct GNUNET_CHAT_Handle *chat = cls; |
412 | 472 | ||
473 | if (chat->destruction) | ||
474 | { | ||
475 | GNUNET_NAMESTORE_zone_monitor_stop(chat->monitor); | ||
476 | chat->monitor = NULL; | ||
477 | return; | ||
478 | } | ||
479 | |||
413 | handle_process_records(chat, label, count, data); | 480 | handle_process_records(chat, label, count, data); |
414 | 481 | ||
415 | if (chat->monitor) | 482 | if (chat->monitor) |
@@ -471,6 +538,8 @@ on_handle_message_callback(void *cls) | |||
471 | (message->context) && | 538 | (message->context) && |
472 | (message->context->handle)); | 539 | (message->context->handle)); |
473 | 540 | ||
541 | message->task = NULL; | ||
542 | |||
474 | struct GNUNET_CHAT_Context *context = message->context; | 543 | struct GNUNET_CHAT_Context *context = message->context; |
475 | 544 | ||
476 | switch (message->msg->header.kind) | 545 | switch (message->msg->header.kind) |
@@ -512,7 +581,8 @@ on_handle_message (void *cls, | |||
512 | (msg) && | 581 | (msg) && |
513 | (hash)); | 582 | (hash)); |
514 | 583 | ||
515 | if ((GNUNET_OK != handle_request_context_by_room(handle, room)) || | 584 | if ((handle->destruction) || |
585 | (GNUNET_OK != handle_request_context_by_room(handle, room)) || | ||
516 | (GNUNET_OK != intern_provide_contact_for_member(handle, sender, NULL))) | 586 | (GNUNET_OK != intern_provide_contact_for_member(handle, sender, NULL))) |
517 | return; | 587 | return; |
518 | 588 | ||
@@ -647,6 +717,8 @@ on_handle_message (void *cls, | |||
647 | 717 | ||
648 | if (!task) | 718 | if (!task) |
649 | on_handle_message_callback(message); | 719 | on_handle_message_callback(message); |
720 | else | ||
721 | message->task = task; | ||
650 | } | 722 | } |
651 | 723 | ||
652 | int | 724 | int |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index c52ddf4..8c7558d 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -88,46 +88,7 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle, | |||
88 | if ((!handle) || (handle->destruction) || (!name)) | 88 | if ((!handle) || (handle->destruction) || (!name)) |
89 | return GNUNET_SYSERR; | 89 | return GNUNET_SYSERR; |
90 | 90 | ||
91 | struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; | 91 | return handle_create_account(handle, name); |
92 | while (accounts) | ||
93 | { | ||
94 | if (!(accounts->account)) | ||
95 | goto skip_account; | ||
96 | |||
97 | if ((accounts->account->name) && | ||
98 | (0 == strcmp(accounts->account->name, name))) | ||
99 | return GNUNET_NO; | ||
100 | |||
101 | skip_account: | ||
102 | accounts = accounts->next; | ||
103 | } | ||
104 | |||
105 | accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts); | ||
106 | accounts->account = NULL; | ||
107 | accounts->handle = handle; | ||
108 | |||
109 | accounts->op = GNUNET_IDENTITY_create( | ||
110 | handle->identity, | ||
111 | name, | ||
112 | NULL, | ||
113 | GNUNET_IDENTITY_TYPE_ECDSA, | ||
114 | cb_account_creation, | ||
115 | accounts | ||
116 | ); | ||
117 | |||
118 | if (!(accounts->op)) | ||
119 | { | ||
120 | GNUNET_free(accounts); | ||
121 | return GNUNET_SYSERR; | ||
122 | } | ||
123 | |||
124 | GNUNET_CONTAINER_DLL_insert_tail( | ||
125 | handle->accounts_head, | ||
126 | handle->accounts_tail, | ||
127 | accounts | ||
128 | ); | ||
129 | |||
130 | return GNUNET_OK; | ||
131 | } | 92 | } |
132 | 93 | ||
133 | 94 | ||
@@ -140,34 +101,7 @@ GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle, | |||
140 | if ((!handle) || (handle->destruction) || (!name)) | 101 | if ((!handle) || (handle->destruction) || (!name)) |
141 | return GNUNET_SYSERR; | 102 | return GNUNET_SYSERR; |
142 | 103 | ||
143 | struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; | 104 | return handle_delete_account(handle, name); |
144 | while (accounts) | ||
145 | { | ||
146 | if (!(accounts->account)) | ||
147 | goto skip_account; | ||
148 | |||
149 | if ((accounts->account->name) && | ||
150 | (0 == strcmp(accounts->account->name, name))) | ||
151 | break; | ||
152 | |||
153 | skip_account: | ||
154 | accounts = accounts->next; | ||
155 | } | ||
156 | |||
157 | if (!accounts) | ||
158 | return GNUNET_NO; | ||
159 | |||
160 | if (accounts->op) | ||
161 | GNUNET_IDENTITY_cancel(accounts->op); | ||
162 | |||
163 | accounts->op = GNUNET_IDENTITY_delete( | ||
164 | handle->identity, | ||
165 | name, | ||
166 | cb_account_deletion, | ||
167 | handle | ||
168 | ); | ||
169 | |||
170 | return (accounts->op? GNUNET_OK : GNUNET_SYSERR); | ||
171 | } | 105 | } |
172 | 106 | ||
173 | 107 | ||
@@ -186,7 +120,7 @@ GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle, | |||
186 | struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; | 120 | struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; |
187 | while (accounts) | 121 | while (accounts) |
188 | { | 122 | { |
189 | if (!(accounts->account)) | 123 | if ((!(accounts->account)) || (accounts->op)) |
190 | goto skip_account; | 124 | goto skip_account; |
191 | 125 | ||
192 | result++; | 126 | result++; |
@@ -361,7 +295,7 @@ GNUNET_CHAT_uri_to_string (const struct GNUNET_CHAT_Uri *uri) | |||
361 | char *key_string = GNUNET_IDENTITY_public_key_to_string(&(uri->zone)); | 295 | char *key_string = GNUNET_IDENTITY_public_key_to_string(&(uri->zone)); |
362 | 296 | ||
363 | char *string; | 297 | char *string; |
364 | GNUNET_asprintf( | 298 | GNUNET_asprintf ( |
365 | &string, | 299 | &string, |
366 | "gnunet://chat/%s.%s", | 300 | "gnunet://chat/%s.%s", |
367 | key_string, | 301 | key_string, |
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c index c4f570b..b9806a9 100644 --- a/src/gnunet_chat_lib_intern.c +++ b/src/gnunet_chat_lib_intern.c | |||
@@ -31,50 +31,32 @@ task_handle_destruction (void *cls) | |||
31 | 31 | ||
32 | struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; | 32 | struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; |
33 | 33 | ||
34 | handle->destruction = NULL; | 34 | struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; |
35 | handle_destroy(handle); | 35 | while (accounts) |
36 | } | 36 | { |
37 | 37 | if ((accounts->op) && (accounts->account)) | |
38 | void | 38 | break; |
39 | cb_account_creation (void *cls, | ||
40 | const struct GNUNET_IDENTITY_PrivateKey *key, | ||
41 | const char *emsg) | ||
42 | { | ||
43 | GNUNET_assert(cls); | ||
44 | |||
45 | struct GNUNET_CHAT_InternalAccounts *accounts = ( | ||
46 | (struct GNUNET_CHAT_InternalAccounts*) cls | ||
47 | ); | ||
48 | |||
49 | struct GNUNET_CHAT_Handle *handle = accounts->handle; | ||
50 | |||
51 | GNUNET_CONTAINER_DLL_remove( | ||
52 | handle->accounts_head, | ||
53 | handle->accounts_tail, | ||
54 | accounts | ||
55 | ); | ||
56 | |||
57 | GNUNET_free(accounts); | ||
58 | |||
59 | if (emsg) | ||
60 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_WARNING, emsg); | ||
61 | else if (key) | ||
62 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_REFRESH, NULL); | ||
63 | } | ||
64 | |||
65 | void | ||
66 | cb_account_deletion (void *cls, | ||
67 | const char *emsg) | ||
68 | { | ||
69 | GNUNET_assert(cls); | ||
70 | 39 | ||
71 | struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; | 40 | accounts = accounts->next; |
41 | } | ||
72 | 42 | ||
73 | if (emsg) | 43 | if (accounts) |
74 | { | 44 | { |
75 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_WARNING, emsg); | 45 | handle->destruction = GNUNET_SCHEDULER_add_at_with_priority( |
46 | GNUNET_TIME_absolute_add( | ||
47 | GNUNET_TIME_absolute_get(), | ||
48 | GNUNET_TIME_relative_get_second_() | ||
49 | ), | ||
50 | GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
51 | task_handle_destruction, | ||
52 | handle | ||
53 | ); | ||
54 | |||
76 | return; | 55 | return; |
77 | } | 56 | } |
57 | |||
58 | handle->destruction = NULL; | ||
59 | handle_destroy(handle); | ||
78 | } | 60 | } |
79 | 61 | ||
80 | void | 62 | void |
diff --git a/src/gnunet_chat_lobby.c b/src/gnunet_chat_lobby.c index dcc33bb..c6d0327 100644 --- a/src/gnunet_chat_lobby.c +++ b/src/gnunet_chat_lobby.c | |||
@@ -38,9 +38,7 @@ lobby_create (struct GNUNET_CHAT_Handle *handle) | |||
38 | lobby->context = NULL; | 38 | lobby->context = NULL; |
39 | lobby->uri = NULL; | 39 | lobby->uri = NULL; |
40 | 40 | ||
41 | lobby->op_create = NULL; | 41 | lobby->op = NULL; |
42 | lobby->op_delete = NULL; | ||
43 | |||
44 | lobby->query = NULL; | 42 | lobby->query = NULL; |
45 | 43 | ||
46 | lobby->expiration = GNUNET_TIME_absolute_get_forever_(); | 44 | lobby->expiration = GNUNET_TIME_absolute_get_forever_(); |
@@ -55,11 +53,8 @@ lobby_destroy (struct GNUNET_CHAT_Lobby *lobby) | |||
55 | { | 53 | { |
56 | GNUNET_assert(lobby); | 54 | GNUNET_assert(lobby); |
57 | 55 | ||
58 | if (lobby->op_create) | 56 | if (lobby->op) |
59 | GNUNET_IDENTITY_cancel(lobby->op_create); | 57 | GNUNET_IDENTITY_cancel(lobby->op); |
60 | |||
61 | if (lobby->op_delete) | ||
62 | GNUNET_IDENTITY_cancel(lobby->op_delete); | ||
63 | 58 | ||
64 | if (lobby->query) | 59 | if (lobby->query) |
65 | GNUNET_NAMESTORE_cancel(lobby->query); | 60 | GNUNET_NAMESTORE_cancel(lobby->query); |
@@ -84,9 +79,9 @@ lobby_open (struct GNUNET_CHAT_Lobby *lobby, | |||
84 | lobby->callback = callback; | 79 | lobby->callback = callback; |
85 | lobby->cls = cls; | 80 | lobby->cls = cls; |
86 | 81 | ||
87 | if (lobby->op_create) | 82 | if (lobby->op) |
88 | { | 83 | { |
89 | GNUNET_IDENTITY_cancel(lobby->op_create); | 84 | GNUNET_IDENTITY_cancel(lobby->op); |
90 | goto open_zone; | 85 | goto open_zone; |
91 | } | 86 | } |
92 | 87 | ||
@@ -119,7 +114,7 @@ lobby_open (struct GNUNET_CHAT_Lobby *lobby, | |||
119 | open_zone: | 114 | open_zone: |
120 | util_lobby_name(&key, &name); | 115 | util_lobby_name(&key, &name); |
121 | 116 | ||
122 | lobby->op_create = GNUNET_IDENTITY_create( | 117 | lobby->op = GNUNET_IDENTITY_create( |
123 | lobby->handle->identity, | 118 | lobby->handle->identity, |
124 | name, | 119 | name, |
125 | NULL, | 120 | NULL, |
diff --git a/src/gnunet_chat_lobby.h b/src/gnunet_chat_lobby.h index c77fbae..3a55b42 100644 --- a/src/gnunet_chat_lobby.h +++ b/src/gnunet_chat_lobby.h | |||
@@ -43,9 +43,7 @@ struct GNUNET_CHAT_Lobby | |||
43 | struct GNUNET_CHAT_Context *context; | 43 | struct GNUNET_CHAT_Context *context; |
44 | struct GNUNET_CHAT_Uri *uri; | 44 | struct GNUNET_CHAT_Uri *uri; |
45 | 45 | ||
46 | struct GNUNET_IDENTITY_Operation *op_create; | 46 | struct GNUNET_IDENTITY_Operation *op; |
47 | struct GNUNET_IDENTITY_Operation *op_delete; | ||
48 | |||
49 | struct GNUNET_NAMESTORE_QueueEntry *query; | 47 | struct GNUNET_NAMESTORE_QueueEntry *query; |
50 | 48 | ||
51 | struct GNUNET_TIME_Absolute expiration; | 49 | struct GNUNET_TIME_Absolute expiration; |
diff --git a/src/gnunet_chat_lobby_intern.c b/src/gnunet_chat_lobby_intern.c index 0c5a647..135dfe5 100644 --- a/src/gnunet_chat_lobby_intern.c +++ b/src/gnunet_chat_lobby_intern.c | |||
@@ -25,27 +25,6 @@ | |||
25 | #include "gnunet_chat_context.h" | 25 | #include "gnunet_chat_context.h" |
26 | 26 | ||
27 | void | 27 | void |
28 | cont_lobby_identity_delete (void *cls, | ||
29 | const char *emsg) | ||
30 | { | ||
31 | struct GNUNET_CHAT_Lobby *lobby = cls; | ||
32 | |||
33 | GNUNET_assert(lobby); | ||
34 | |||
35 | lobby->op_delete = NULL; | ||
36 | |||
37 | if (!emsg) | ||
38 | return; | ||
39 | |||
40 | handle_send_internal_message( | ||
41 | lobby->handle, | ||
42 | lobby->context, | ||
43 | GNUNET_CHAT_FLAG_WARNING, | ||
44 | emsg | ||
45 | ); | ||
46 | } | ||
47 | |||
48 | void | ||
49 | cont_lobby_write_records (void *cls, | 28 | cont_lobby_write_records (void *cls, |
50 | GNUNET_UNUSED int32_t success, | 29 | GNUNET_UNUSED int32_t success, |
51 | const char *emsg) | 30 | const char *emsg) |
@@ -63,12 +42,7 @@ cont_lobby_write_records (void *cls, | |||
63 | char *name; | 42 | char *name; |
64 | util_lobby_name(key, &name); | 43 | util_lobby_name(key, &name); |
65 | 44 | ||
66 | lobby->op_delete = GNUNET_IDENTITY_delete( | 45 | handle_delete_account(lobby->handle, name); |
67 | lobby->handle->identity, | ||
68 | name, | ||
69 | cont_lobby_identity_delete, | ||
70 | lobby | ||
71 | ); | ||
72 | 46 | ||
73 | GNUNET_free(name); | 47 | GNUNET_free(name); |
74 | 48 | ||
@@ -104,7 +78,7 @@ cont_lobby_identity_create (void *cls, | |||
104 | 78 | ||
105 | GNUNET_assert(lobby); | 79 | GNUNET_assert(lobby); |
106 | 80 | ||
107 | lobby->op_create = NULL; | 81 | lobby->op = NULL; |
108 | 82 | ||
109 | if (emsg) | 83 | if (emsg) |
110 | { | 84 | { |
diff --git a/src/gnunet_chat_message.c b/src/gnunet_chat_message.c index e044415..d3c1385 100644 --- a/src/gnunet_chat_message.c +++ b/src/gnunet_chat_message.c | |||
@@ -37,6 +37,7 @@ message_create_from_msg (struct GNUNET_CHAT_Context *context, | |||
37 | struct GNUNET_CHAT_Message *message = GNUNET_new(struct GNUNET_CHAT_Message); | 37 | struct GNUNET_CHAT_Message *message = GNUNET_new(struct GNUNET_CHAT_Message); |
38 | 38 | ||
39 | message->context = context; | 39 | message->context = context; |
40 | message->task = NULL; | ||
40 | 41 | ||
41 | GNUNET_memcpy(&(message->hash), hash, sizeof(message->hash)); | 42 | GNUNET_memcpy(&(message->hash), hash, sizeof(message->hash)); |
42 | message->flags = flags; | 43 | message->flags = flags; |
@@ -55,6 +56,7 @@ message_create_internally (struct GNUNET_CHAT_Context *context, | |||
55 | struct GNUNET_CHAT_Message *message = GNUNET_new(struct GNUNET_CHAT_Message); | 56 | struct GNUNET_CHAT_Message *message = GNUNET_new(struct GNUNET_CHAT_Message); |
56 | 57 | ||
57 | message->context = context; | 58 | message->context = context; |
59 | message->task = NULL; | ||
58 | 60 | ||
59 | memset(&(message->hash), 0, sizeof(message->hash)); | 61 | memset(&(message->hash), 0, sizeof(message->hash)); |
60 | message->flags = GNUNET_MESSENGER_FLAG_PRIVATE; | 62 | message->flags = GNUNET_MESSENGER_FLAG_PRIVATE; |
@@ -70,5 +72,8 @@ message_destroy (struct GNUNET_CHAT_Message* message) | |||
70 | { | 72 | { |
71 | GNUNET_assert(message); | 73 | GNUNET_assert(message); |
72 | 74 | ||
75 | if (message->task) | ||
76 | GNUNET_SCHEDULER_cancel(message->task); | ||
77 | |||
73 | GNUNET_free(message); | 78 | GNUNET_free(message); |
74 | } | 79 | } |
diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h index e39cc9c..3ea7283 100644 --- a/src/gnunet_chat_message.h +++ b/src/gnunet_chat_message.h | |||
@@ -53,6 +53,7 @@ enum GNUNET_CHAT_MessageFlag | |||
53 | struct GNUNET_CHAT_Message | 53 | struct GNUNET_CHAT_Message |
54 | { | 54 | { |
55 | struct GNUNET_CHAT_Context *context; | 55 | struct GNUNET_CHAT_Context *context; |
56 | struct GNUNET_SCHEDULER_Task *task; | ||
56 | 57 | ||
57 | union { | 58 | union { |
58 | const struct GNUNET_MESSENGER_Message *msg; | 59 | const struct GNUNET_MESSENGER_Message *msg; |
diff --git a/tests/test_gnunet_chat_lobby.c b/tests/test_gnunet_chat_lobby.c index 8f079ed..53ef9e7 100644 --- a/tests/test_gnunet_chat_lobby.c +++ b/tests/test_gnunet_chat_lobby.c | |||
@@ -175,7 +175,9 @@ on_gnunet_chat_lobby_join_open(void *cls, | |||
175 | 175 | ||
176 | GNUNET_CHAT_lobby_join(chat, uri); | 176 | GNUNET_CHAT_lobby_join(chat, uri); |
177 | 177 | ||
178 | GNUNET_SCHEDULER_add_now( | 178 | GNUNET_SCHEDULER_add_at_with_priority( |
179 | GNUNET_TIME_absolute_get(), | ||
180 | GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
179 | on_gnunet_chat_lobby_join_task, | 181 | on_gnunet_chat_lobby_join_task, |
180 | chat | 182 | chat |
181 | ); | 183 | ); |
@@ -244,9 +246,9 @@ call_gnunet_chat_lobby_join(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
244 | 246 | ||
245 | CREATE_GNUNET_TEST(test_gnunet_chat_lobby_join, call_gnunet_chat_lobby_join) | 247 | CREATE_GNUNET_TEST(test_gnunet_chat_lobby_join, call_gnunet_chat_lobby_join) |
246 | 248 | ||
247 | START_SUITE(handle_suite, "Lobby") | 249 | START_SUITE(lobby_suite, "Lobby") |
248 | ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_base, "Open/Close") | 250 | ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_base, "Open/Close") |
249 | ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_join, "Join") | 251 | ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_join, "Join") |
250 | END_SUITE | 252 | END_SUITE |
251 | 253 | ||
252 | MAIN_SUITE(handle_suite, CK_NORMAL) | 254 | MAIN_SUITE(lobby_suite, CK_NORMAL) |