diff options
Diffstat (limited to 'src/gnunet_chat_context.c')
-rw-r--r-- | src/gnunet_chat_context.c | 71 |
1 files changed, 37 insertions, 34 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c index c1e792c..961de47 100644 --- 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, | |||
40 | context->handle = handle; | 40 | context->handle = handle; |
41 | 41 | ||
42 | context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; | 42 | context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; |
43 | context->nick = NULL; | 43 | context->nick[0] = '\0'; |
44 | context->topic = NULL; | 44 | context->topic = NULL; |
45 | context->deleted = GNUNET_NO; | 45 | context->deleted = GNUNET_NO; |
46 | 46 | ||
@@ -74,7 +74,7 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle, | |||
74 | context->handle = handle; | 74 | context->handle = handle; |
75 | 75 | ||
76 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; | 76 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; |
77 | context->nick = NULL; | 77 | context->nick[0] = '\0'; |
78 | context->topic = NULL; | 78 | context->topic = NULL; |
79 | context->deleted = GNUNET_NO; | 79 | context->deleted = GNUNET_NO; |
80 | 80 | ||
@@ -131,9 +131,6 @@ context_destroy (struct GNUNET_CHAT_Context *context) | |||
131 | if (context->topic) | 131 | if (context->topic) |
132 | GNUNET_free(context->topic); | 132 | GNUNET_free(context->topic); |
133 | 133 | ||
134 | if (context->nick) | ||
135 | GNUNET_free(context->nick); | ||
136 | |||
137 | GNUNET_free(context); | 134 | GNUNET_free(context); |
138 | } | 135 | } |
139 | 136 | ||
@@ -179,7 +176,12 @@ context_update_nick (struct GNUNET_CHAT_Context *context, | |||
179 | { | 176 | { |
180 | GNUNET_assert(context); | 177 | GNUNET_assert(context); |
181 | 178 | ||
182 | util_set_name_field(nick, &(context->nick)); | 179 | size_t len = nick? strlen(nick) : 0; |
180 | if (len >= sizeof(context->nick)) | ||
181 | len = sizeof(context->nick) - 1; | ||
182 | |||
183 | GNUNET_memcpy(context->nick, nick, len); | ||
184 | context->nick[len] = '\0'; | ||
183 | 185 | ||
184 | if (!(context->handle)) | 186 | if (!(context->handle)) |
185 | return; | 187 | return; |
@@ -203,24 +205,28 @@ context_read_records (struct GNUNET_CHAT_Context *context, | |||
203 | 205 | ||
204 | char *nick = NULL; | 206 | char *nick = NULL; |
205 | char *topic = NULL; | 207 | char *topic = NULL; |
208 | uint32_t flags = 0; | ||
206 | 209 | ||
207 | for (unsigned int i = 0; i < count; i++) | 210 | for (unsigned int i = 0; i < count; i++) |
208 | { | 211 | { |
209 | if (!(GNUNET_GNSRECORD_RF_SUPPLEMENTAL & data[i].flags)) | 212 | if (!(GNUNET_GNSRECORD_RF_SUPPLEMENTAL & data[i].flags)) |
210 | continue; | 213 | continue; |
211 | 214 | ||
212 | if (GNUNET_GNSRECORD_TYPE_NICK == data[i].record_type) | 215 | if (GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS == data[i].record_type) |
213 | { | 216 | { |
214 | if (nick) | 217 | if (nick) |
215 | continue; | 218 | continue; |
219 | |||
220 | const struct GNUNET_MESSENGER_RoomDetailsRecord *record = data[i].data; | ||
216 | 221 | ||
217 | nick = GNUNET_strndup(data[i].data, data[i].data_size); | 222 | nick = GNUNET_strndup(record->name, sizeof(record->name)); |
223 | flags = record->flags; | ||
218 | } | 224 | } |
219 | 225 | ||
220 | if (GNUNET_DNSPARSER_TYPE_TXT == data[i].record_type) | 226 | if (GNUNET_DNSPARSER_TYPE_TXT == data[i].record_type) |
221 | { | 227 | { |
222 | if (topic) | 228 | if (topic) |
223 | continue; | 229 | continue; |
224 | 230 | ||
225 | topic = GNUNET_strndup(data[i].data, data[i].data_size); | 231 | topic = GNUNET_strndup(data[i].data, data[i].data_size); |
226 | } | 232 | } |
@@ -280,16 +286,16 @@ context_write_records (struct GNUNET_CHAT_Context *context) | |||
280 | 286 | ||
281 | struct GNUNET_TIME_Absolute expiration = GNUNET_TIME_absolute_get_forever_(); | 287 | struct GNUNET_TIME_Absolute expiration = GNUNET_TIME_absolute_get_forever_(); |
282 | 288 | ||
283 | struct GNUNET_MESSENGER_RoomEntryRecord room; | 289 | struct GNUNET_MESSENGER_RoomEntryRecord room_entry; |
284 | GNUNET_CRYPTO_get_peer_identity(context->handle->cfg, &(room.door)); | 290 | GNUNET_CRYPTO_get_peer_identity(context->handle->cfg, &(room_entry.door)); |
285 | 291 | ||
286 | GNUNET_memcpy( | 292 | GNUNET_memcpy( |
287 | &(room.key), | 293 | &(room_entry.key), |
288 | hash, | 294 | hash, |
289 | sizeof(room.key) | 295 | sizeof(room_entry.key) |
290 | ); | 296 | ); |
291 | 297 | ||
292 | const char *nick = context->nick; | 298 | struct GNUNET_MESSENGER_RoomDetailsRecord room_details; |
293 | const char *topic = context->topic; | 299 | const char *topic = context->topic; |
294 | 300 | ||
295 | if (topic) | 301 | if (topic) |
@@ -310,18 +316,21 @@ context_write_records (struct GNUNET_CHAT_Context *context) | |||
310 | if (GNUNET_YES == context->deleted) | 316 | if (GNUNET_YES == context->deleted) |
311 | goto skip_record_data; | 317 | goto skip_record_data; |
312 | 318 | ||
313 | data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY; | 319 | data[count].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY; |
314 | data[0].data = &room; | 320 | data[count].data = &room_entry; |
315 | data[0].data_size = sizeof(room); | 321 | data[count].data_size = sizeof(room_entry); |
316 | data[0].expiration_time = expiration.abs_value_us; | 322 | data[count].expiration_time = expiration.abs_value_us; |
317 | data[0].flags = GNUNET_GNSRECORD_RF_PRIVATE; | 323 | data[count].flags = GNUNET_GNSRECORD_RF_PRIVATE; |
318 | count++; | 324 | count++; |
319 | 325 | ||
320 | if (nick) | 326 | if (context->nick) |
321 | { | 327 | { |
322 | data[count].record_type = GNUNET_GNSRECORD_TYPE_NICK; | 328 | GNUNET_memcpy(room_details.name, context->nick, sizeof(room_details.name)); |
323 | data[count].data = nick; | 329 | room_details.flags = 0; |
324 | data[count].data_size = strlen(nick); | 330 | |
331 | data[count].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS; | ||
332 | data[count].data = &room_details; | ||
333 | data[count].data_size = sizeof(room_details); | ||
325 | data[count].expiration_time = expiration.abs_value_us; | 334 | data[count].expiration_time = expiration.abs_value_us; |
326 | data[count].flags = ( | 335 | data[count].flags = ( |
327 | GNUNET_GNSRECORD_RF_PRIVATE | | 336 | GNUNET_GNSRECORD_RF_PRIVATE | |
@@ -346,7 +355,10 @@ context_write_records (struct GNUNET_CHAT_Context *context) | |||
346 | } | 355 | } |
347 | 356 | ||
348 | skip_record_data: | 357 | skip_record_data: |
349 | GNUNET_NAMESTORE_records_store( | 358 | if (context->query) |
359 | GNUNET_NAMESTORE_cancel(context->query); | ||
360 | |||
361 | context->query = GNUNET_NAMESTORE_records_store( | ||
350 | context->handle->namestore, | 362 | context->handle->namestore, |
351 | zone, | 363 | zone, |
352 | label, | 364 | label, |
@@ -358,12 +370,3 @@ skip_record_data: | |||
358 | 370 | ||
359 | GNUNET_free(label); | 371 | GNUNET_free(label); |
360 | } | 372 | } |
361 | |||
362 | void | ||
363 | context_delete_records (struct GNUNET_CHAT_Context *context) | ||
364 | { | ||
365 | GNUNET_assert(context); | ||
366 | |||
367 | context->deleted = GNUNET_YES; | ||
368 | context_write_records(context); | ||
369 | } | ||