libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 4df66ae0839555369313675df5391146083827e8
parent 66c08d87a9785e4725a401aff69501d7b72be8f9
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Mon, 21 Mar 2022 13:37:46 +0100

Updated to use new room details record

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Msrc/gnunet_chat_context.c | 71+++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/gnunet_chat_context.h | 5+----
Msrc/gnunet_chat_handle.c | 11+++++++++--
Msrc/gnunet_chat_lib.c | 16+++++++++++-----
4 files changed, 58 insertions(+), 45 deletions(-)

diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c @@ -40,7 +40,7 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle, context->handle = handle; context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; - context->nick = NULL; + context->nick[0] = '\0'; context->topic = NULL; context->deleted = GNUNET_NO; @@ -74,7 +74,7 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle, context->handle = handle; context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; - context->nick = NULL; + context->nick[0] = '\0'; context->topic = NULL; context->deleted = GNUNET_NO; @@ -131,9 +131,6 @@ context_destroy (struct GNUNET_CHAT_Context *context) if (context->topic) GNUNET_free(context->topic); - if (context->nick) - GNUNET_free(context->nick); - GNUNET_free(context); } @@ -179,7 +176,12 @@ context_update_nick (struct GNUNET_CHAT_Context *context, { GNUNET_assert(context); - util_set_name_field(nick, &(context->nick)); + size_t len = nick? strlen(nick) : 0; + if (len >= sizeof(context->nick)) + len = sizeof(context->nick) - 1; + + GNUNET_memcpy(context->nick, nick, len); + context->nick[len] = '\0'; if (!(context->handle)) return; @@ -203,24 +205,28 @@ context_read_records (struct GNUNET_CHAT_Context *context, char *nick = NULL; char *topic = NULL; + uint32_t flags = 0; for (unsigned int i = 0; i < count; i++) { if (!(GNUNET_GNSRECORD_RF_SUPPLEMENTAL & data[i].flags)) continue; - if (GNUNET_GNSRECORD_TYPE_NICK == data[i].record_type) + if (GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS == data[i].record_type) { if (nick) - continue; + continue; + + const struct GNUNET_MESSENGER_RoomDetailsRecord *record = data[i].data; - nick = GNUNET_strndup(data[i].data, data[i].data_size); + nick = GNUNET_strndup(record->name, sizeof(record->name)); + flags = record->flags; } if (GNUNET_DNSPARSER_TYPE_TXT == data[i].record_type) { if (topic) - continue; + continue; topic = GNUNET_strndup(data[i].data, data[i].data_size); } @@ -280,16 +286,16 @@ context_write_records (struct GNUNET_CHAT_Context *context) struct GNUNET_TIME_Absolute expiration = GNUNET_TIME_absolute_get_forever_(); - struct GNUNET_MESSENGER_RoomEntryRecord room; - GNUNET_CRYPTO_get_peer_identity(context->handle->cfg, &(room.door)); + struct GNUNET_MESSENGER_RoomEntryRecord room_entry; + GNUNET_CRYPTO_get_peer_identity(context->handle->cfg, &(room_entry.door)); GNUNET_memcpy( - &(room.key), + &(room_entry.key), hash, - sizeof(room.key) + sizeof(room_entry.key) ); - const char *nick = context->nick; + struct GNUNET_MESSENGER_RoomDetailsRecord room_details; const char *topic = context->topic; if (topic) @@ -310,18 +316,21 @@ context_write_records (struct GNUNET_CHAT_Context *context) if (GNUNET_YES == context->deleted) goto skip_record_data; - data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY; - data[0].data = &room; - data[0].data_size = sizeof(room); - data[0].expiration_time = expiration.abs_value_us; - data[0].flags = GNUNET_GNSRECORD_RF_PRIVATE; + data[count].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY; + data[count].data = &room_entry; + data[count].data_size = sizeof(room_entry); + data[count].expiration_time = expiration.abs_value_us; + data[count].flags = GNUNET_GNSRECORD_RF_PRIVATE; count++; - if (nick) + if (context->nick) { - data[count].record_type = GNUNET_GNSRECORD_TYPE_NICK; - data[count].data = nick; - data[count].data_size = strlen(nick); + GNUNET_memcpy(room_details.name, context->nick, sizeof(room_details.name)); + room_details.flags = 0; + + data[count].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS; + data[count].data = &room_details; + data[count].data_size = sizeof(room_details); data[count].expiration_time = expiration.abs_value_us; data[count].flags = ( GNUNET_GNSRECORD_RF_PRIVATE | @@ -346,7 +355,10 @@ context_write_records (struct GNUNET_CHAT_Context *context) } skip_record_data: - GNUNET_NAMESTORE_records_store( + if (context->query) + GNUNET_NAMESTORE_cancel(context->query); + + context->query = GNUNET_NAMESTORE_records_store( context->handle->namestore, zone, label, @@ -358,12 +370,3 @@ skip_record_data: GNUNET_free(label); } - -void -context_delete_records (struct GNUNET_CHAT_Context *context) -{ - GNUNET_assert(context); - - context->deleted = GNUNET_YES; - context_write_records(context); -} diff --git a/src/gnunet_chat_context.h b/src/gnunet_chat_context.h @@ -42,7 +42,7 @@ struct GNUNET_CHAT_Context struct GNUNET_CHAT_Handle *handle; enum GNUNET_CHAT_ContextType type; - char *nick; + char nick [256 + 1]; char *topic; int deleted; @@ -89,7 +89,4 @@ context_read_records (struct GNUNET_CHAT_Context *context, void context_write_records (struct GNUNET_CHAT_Context *context); -void -context_delete_records (struct GNUNET_CHAT_Context *context); - #endif /* GNUNET_CHAT_CONTEXT_H_ */ diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -473,14 +473,21 @@ check_type: check.contact, context))) { - context_delete_records(context); + context->deleted = GNUNET_YES; + context_write_records(context); + context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; + context->deleted = GNUNET_NO; + context_write_records(context); } else if (checks >= 2) { - context_delete_records(context); + context->deleted = GNUNET_YES; + context_write_records(context); + context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; + context->deleted = GNUNET_NO; if (context->contact) { diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -553,7 +553,9 @@ GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact) ); GNUNET_MESSENGER_close_room(contact->context->room); - context_delete_records(contact->context); + + contact->context->deleted = GNUNET_YES; + context_write_records(contact->context); context_destroy(contact->context); contact_destroy(contact); @@ -581,7 +583,7 @@ GNUNET_CHAT_contact_get_name (const struct GNUNET_CHAT_Contact *contact) if (!contact) return NULL; - if ((contact->context) && (contact->context->nick)) + if ((contact->context) && (contact->context->nick[0])) return contact->context->nick; return GNUNET_MESSENGER_contact_get_name(contact->member); @@ -671,7 +673,9 @@ GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) ); GNUNET_MESSENGER_close_room(group->context->room); - context_delete_records(group->context); + + group->context->deleted = GNUNET_YES; + context_write_records(group->context); context_destroy(group->context); group_destroy(group); @@ -687,7 +691,9 @@ GNUNET_CHAT_group_set_name (struct GNUNET_CHAT_Group *group, return; context_update_nick(group->context, name); - context_write_records(group->context); + + if (group->context->room) + context_write_records(group->context); } @@ -697,7 +703,7 @@ GNUNET_CHAT_group_get_name (const struct GNUNET_CHAT_Group *group) if ((!group) || (!(group->context))) return NULL; - if (group->context->nick) + if (group->context->nick[0]) return group->context->nick; return group->context->topic;