aboutsummaryrefslogtreecommitdiff
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)
downloadgnunet-8b0ef87bd51442c30077b5f9d0590ec149bd1cd0.tar.gz
gnunet-8b0ef87bd51442c30077b5f9d0590ec149bd1cd0.zip
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 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2020--2021 GNUnet e.V. 3 Copyright (C) 2020--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -96,6 +96,27 @@ struct GNUNET_MESSENGER_RoomEntryRecord
96 96
97GNUNET_NETWORK_STRUCT_END 97GNUNET_NETWORK_STRUCT_END
98 98
99GNUNET_NETWORK_STRUCT_BEGIN
100
101/**
102 * A room details record specifies a custom name for a given room and
103 * some additional space for flags.
104 */
105struct GNUNET_MESSENGER_RoomDetailsRecord
106{
107 /**
108 * The custom name for the room.
109 */
110 char name [256];
111
112 /**
113 * The flags of the room.
114 */
115 uint32_t flags;
116};
117
118GNUNET_NETWORK_STRUCT_END
119
99/** 120/**
100 * Enum for the different supported kinds of messages 121 * Enum for the different supported kinds of messages
101 */ 122 */
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 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -63,12 +63,30 @@ messenger_value_to_string (void *cls,
63 char *key = GNUNET_STRINGS_data_to_string_alloc (&(record->key), sizeof(struct GNUNET_HashCode)); 63 char *key = GNUNET_STRINGS_data_to_string_alloc (&(record->key), sizeof(struct GNUNET_HashCode));
64 64
65 char *ret; 65 char *ret;
66 GNUNET_asprintf (&ret, "%s-%s", door, key); 66 GNUNET_asprintf (&ret, "%s-%s", key, door);
67 GNUNET_free (key); 67 GNUNET_free (key);
68 GNUNET_free (door); 68 GNUNET_free (door);
69 return ret; 69 return ret;
70 } 70 }
71 case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS:
72 {
73 if (data_size != sizeof(struct GNUNET_MESSENGER_RoomDetailsRecord))
74 {
75 GNUNET_break_op (0);
76 return NULL;
77 }
78
79 const struct GNUNET_MESSENGER_RoomDetailsRecord *record = data;
71 80
81 char *name = GNUNET_strndup(record->name, 256);
82 char *flags = GNUNET_STRINGS_data_to_string_alloc (&(record->flags), sizeof(uint32_t));
83
84 char *ret;
85 GNUNET_asprintf (&ret, "%s-%s", flags, name);
86 GNUNET_free (flags);
87 GNUNET_free (name);
88 return ret;
89 }
72 default: 90 default:
73 return NULL; 91 return NULL;
74 } 92 }
@@ -141,7 +159,43 @@ messenger_string_to_value (void *cls,
141 *data_size = sizeof(struct GNUNET_MESSENGER_RoomEntryRecord); 159 *data_size = sizeof(struct GNUNET_MESSENGER_RoomEntryRecord);
142 return GNUNET_OK; 160 return GNUNET_OK;
143 } 161 }
162 case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS:
163 {
164 char flags [7];
165 const char *dash;
166
167 if ((NULL == (dash = strchr (s, '-'))) ||
168 (1 != sscanf (s, "%7s-", flags)) ||
169 (strlen (dash + 1) > 256))
170 {
171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
172 _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
173 s);
174 return GNUNET_SYSERR;
175 }
176
177 struct GNUNET_MESSENGER_RoomDetailsRecord *record = GNUNET_new (
178 struct GNUNET_MESSENGER_RoomDetailsRecord
179 );
180
181 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (flags,
182 strlen (flags),
183 &(record->flags),
184 sizeof(uint32_t)))
185 {
186 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
187 _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
188 s);
189 GNUNET_free (record);
190 return GNUNET_SYSERR;
191 }
144 192
193 GNUNET_memcpy(record->name, dash + 1, strlen(dash + 1));
194
195 *data = record;
196 *data_size = sizeof(struct GNUNET_MESSENGER_RoomDetailsRecord);
197 return GNUNET_OK;
198 }
145 default: 199 default:
146 return GNUNET_SYSERR; 200 return GNUNET_SYSERR;
147 } 201 }
@@ -158,6 +212,7 @@ static struct
158 uint32_t number; 212 uint32_t number;
159} name_map[] = { 213} name_map[] = {
160 { "MESSENGER_ROOM_ENTRY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY }, 214 { "MESSENGER_ROOM_ENTRY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY },
215 { "MESSENGER_ROOM_DETAILS", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS },
161 { NULL, UINT32_MAX } 216 { NULL, UINT32_MAX }
162}; 217};
163 218