aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-12-16 00:58:44 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-12-16 00:58:44 +0100
commit98852b955cacf792adc9a02682e3d23b5e6ee979 (patch)
tree8b6b5f3825046a31c5d1739eae1945df37fd106e
parentbf0bb934cc4c62c4aefedaab205ba0035747bdd4 (diff)
downloadlibgnunetchat-98852b955cacf792adc9a02682e3d23b5e6ee979.tar.gz
libgnunetchat-98852b955cacf792adc9a02682e3d23b5e6ee979.zip
Added function to check if a contact is owned by the account
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--include/gnunet_chat_lib.h11
-rw-r--r--src/gnunet_chat_contact.c2
-rw-r--r--src/gnunet_chat_contact.h2
-rw-r--r--src/gnunet_chat_contact_intern.c2
-rw-r--r--src/gnunet_chat_handle_intern.c11
-rw-r--r--src/gnunet_chat_lib.c10
6 files changed, 34 insertions, 4 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h
index b4a8075..2eec1d6 100644
--- a/include/gnunet_chat_lib.h
+++ b/include/gnunet_chat_lib.h
@@ -443,6 +443,17 @@ void*
443GNUNET_CHAT_contact_get_user_pointer (const struct GNUNET_CHAT_Contact *contact); 443GNUNET_CHAT_contact_get_user_pointer (const struct GNUNET_CHAT_Contact *contact);
444 444
445/** 445/**
446 * Returns if a given <i>contact</i> is owned as account and whether it has
447 * sent messages with.
448 *
449 * @param[in] contact Contact
450 * @return GNUNET_YES if the contact is owned, otherwise GNUNET_NO
451 * and GNUNET_SYSERR on failure
452 */
453int
454GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact);
455
456/**
446 * Leaves a specific <i>group</i> chat and frees its memory if it is not shared 457 * Leaves a specific <i>group</i> chat and frees its memory if it is not shared
447 * with other groups or contacts. 458 * with other groups or contacts.
448 * 459 *
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
index c7004d3..273f917 100644
--- a/src/gnunet_chat_contact.c
+++ b/src/gnunet_chat_contact.c
@@ -44,6 +44,8 @@ contact_create_from_member (struct GNUNET_CHAT_Handle *handle,
44 contact->public_key = NULL; 44 contact->public_key = NULL;
45 contact->user_pointer = NULL; 45 contact->user_pointer = NULL;
46 46
47 contact->is_owned = GNUNET_NO;
48
47 contact_update_key (contact); 49 contact_update_key (contact);
48 return contact; 50 return contact;
49} 51}
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h
index 68078e0..cf0dded 100644
--- a/src/gnunet_chat_contact.h
+++ b/src/gnunet_chat_contact.h
@@ -42,6 +42,8 @@ struct GNUNET_CHAT_Contact
42 42
43 char *public_key; 43 char *public_key;
44 void *user_pointer; 44 void *user_pointer;
45
46 int is_owned;
45}; 47};
46 48
47struct GNUNET_CHAT_Contact* 49struct GNUNET_CHAT_Contact*
diff --git a/src/gnunet_chat_contact_intern.c b/src/gnunet_chat_contact_intern.c
index 5005651..4ecdf51 100644
--- a/src/gnunet_chat_contact_intern.c
+++ b/src/gnunet_chat_contact_intern.c
@@ -22,6 +22,8 @@
22 * @file gnunet_chat_contact_intern.c 22 * @file gnunet_chat_contact_intern.c
23 */ 23 */
24 24
25#include <stdlib.h>
26
25#define GNUNET_UNUSED __attribute__ ((unused)) 27#define GNUNET_UNUSED __attribute__ ((unused))
26 28
27struct GNUNET_CHAT_ContactFindRoom 29struct GNUNET_CHAT_ContactFindRoom
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index 9f69611..d804545 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -464,6 +464,13 @@ on_handle_message (void *cls,
464 struct GNUNET_ShortHashCode shorthash; 464 struct GNUNET_ShortHashCode shorthash;
465 util_shorthash_from_member(sender, &shorthash); 465 util_shorthash_from_member(sender, &shorthash);
466 466
467 struct GNUNET_CHAT_Contact *contact = GNUNET_CONTAINER_multishortmap_get(
468 handle->contacts, &shorthash
469 );
470
471 if (flags & GNUNET_MESSENGER_FLAG_SENT)
472 contact->is_owned = GNUNET_YES;
473
467 struct GNUNET_TIME_Absolute *time = GNUNET_CONTAINER_multishortmap_get( 474 struct GNUNET_TIME_Absolute *time = GNUNET_CONTAINER_multishortmap_get(
468 context->timestamps, &shorthash 475 context->timestamps, &shorthash
469 ); 476 );
@@ -501,10 +508,6 @@ on_handle_message (void *cls,
501 { 508 {
502 case GNUNET_MESSENGER_KIND_KEY: 509 case GNUNET_MESSENGER_KIND_KEY:
503 { 510 {
504 struct GNUNET_CHAT_Contact *contact = GNUNET_CONTAINER_multishortmap_get(
505 handle->contacts, &shorthash
506 );
507
508 contact_update_key(contact); 511 contact_update_key(contact);
509 break; 512 break;
510 } 513 }
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index fae83d2..f1421af 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -332,6 +332,16 @@ GNUNET_CHAT_contact_get_user_pointer (const struct GNUNET_CHAT_Contact *contact)
332 332
333 333
334int 334int
335GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact)
336{
337 if (!contact)
338 return GNUNET_SYSERR;
339
340 return contact->is_owned;
341}
342
343
344int
335GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) 345GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group)
336{ 346{
337 if (!group) 347 if (!group)