diff options
Diffstat (limited to 'src/gnunet_chat_handle.c')
-rw-r--r-- | src/gnunet_chat_handle.c | 114 |
1 files changed, 113 insertions, 1 deletions
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) |