diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-21 12:57:42 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-21 12:57:42 +0100 |
commit | 8d4192c47697d87373fd2886746a12e42d60d515 (patch) | |
tree | 5ee812e37b20e1379c5796abf63d3de8f52a4e8e /src/messenger | |
parent | ec8a825b0e56c692c4879db10c6b25cd26bb42e4 (diff) | |
download | gnunet-8d4192c47697d87373fd2886746a12e42d60d515.tar.gz gnunet-8d4192c47697d87373fd2886746a12e42d60d515.zip |
-add gns record type handling for messenger room details
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/messenger')
-rw-r--r-- | src/messenger/plugin_gnsrecord_messenger.c | 59 |
1 files changed, 57 insertions, 2 deletions
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 | ||