summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-03-21 13:54:42 +0100
committerMartin Schanzenbach <schanzen@gnunet.org>2022-03-21 13:54:42 +0100
commit8b0ef87bd51442c30077b5f9d0590ec149bd1cd0 (patch)
tree9b06a963b0d97930fbb118772fa442abd89a816a
parent4e95b59a6f3cd35c9c1b5dcdc6320f0e0dfef79b (diff)
parent8d4192c47697d87373fd2886746a12e42d60d515 (diff)
Merge branch 'master' of git+ssh://git.gnunet.org/gnunet
-rw-r--r--src/include/gnunet_messenger_service.h23
-rw-r--r--src/messenger/plugin_gnsrecord_messenger.c59
2 files changed, 79 insertions, 3 deletions
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h
index 96d48b411..f8bbc7398 100644
--- a/src/include/gnunet_messenger_service.h
+++ b/src/include/gnunet_messenger_service.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2020--2021 GNUnet e.V.
+ Copyright (C) 2020--2022 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -96,6 +96,27 @@ struct GNUNET_MESSENGER_RoomEntryRecord
GNUNET_NETWORK_STRUCT_END
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * A room details record specifies a custom name for a given room and
+ * some additional space for flags.
+ */
+struct GNUNET_MESSENGER_RoomDetailsRecord
+{
+ /**
+ * The custom name for the room.
+ */
+ char name [256];
+
+ /**
+ * The flags of the room.
+ */
+ uint32_t flags;
+};
+
+GNUNET_NETWORK_STRUCT_END
+
/**
* Enum for the different supported kinds of messages
*/
diff --git a/src/messenger/plugin_gnsrecord_messenger.c b/src/messenger/plugin_gnsrecord_messenger.c
index 2219f0bde..e09a0330d 100644
--- a/src/messenger/plugin_gnsrecord_messenger.c
+++ b/src/messenger/plugin_gnsrecord_messenger.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021 GNUnet e.V.
+ Copyright (C) 2021--2022 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -63,12 +63,30 @@ messenger_value_to_string (void *cls,
char *key = GNUNET_STRINGS_data_to_string_alloc (&(record->key), sizeof(struct GNUNET_HashCode));
char *ret;
- GNUNET_asprintf (&ret, "%s-%s", door, key);
+ GNUNET_asprintf (&ret, "%s-%s", key, door);
GNUNET_free (key);
GNUNET_free (door);
return ret;
}
+ case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS:
+ {
+ if (data_size != sizeof(struct GNUNET_MESSENGER_RoomDetailsRecord))
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+
+ const struct GNUNET_MESSENGER_RoomDetailsRecord *record = data;
+ char *name = GNUNET_strndup(record->name, 256);
+ char *flags = GNUNET_STRINGS_data_to_string_alloc (&(record->flags), sizeof(uint32_t));
+
+ char *ret;
+ GNUNET_asprintf (&ret, "%s-%s", flags, name);
+ GNUNET_free (flags);
+ GNUNET_free (name);
+ return ret;
+ }
default:
return NULL;
}
@@ -141,7 +159,43 @@ messenger_string_to_value (void *cls,
*data_size = sizeof(struct GNUNET_MESSENGER_RoomEntryRecord);
return GNUNET_OK;
}
+ case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS:
+ {
+ char flags [7];
+ const char *dash;
+
+ if ((NULL == (dash = strchr (s, '-'))) ||
+ (1 != sscanf (s, "%7s-", flags)) ||
+ (strlen (dash + 1) > 256))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+
+ struct GNUNET_MESSENGER_RoomDetailsRecord *record = GNUNET_new (
+ struct GNUNET_MESSENGER_RoomDetailsRecord
+ );
+
+ if (GNUNET_OK != GNUNET_STRINGS_string_to_data (flags,
+ strlen (flags),
+ &(record->flags),
+ sizeof(uint32_t)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
+ s);
+ GNUNET_free (record);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_memcpy(record->name, dash + 1, strlen(dash + 1));
+
+ *data = record;
+ *data_size = sizeof(struct GNUNET_MESSENGER_RoomDetailsRecord);
+ return GNUNET_OK;
+ }
default:
return GNUNET_SYSERR;
}
@@ -158,6 +212,7 @@ static struct
uint32_t number;
} name_map[] = {
{ "MESSENGER_ROOM_ENTRY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY },
+ { "MESSENGER_ROOM_DETAILS", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS },
{ NULL, UINT32_MAX }
};