diff options
Diffstat (limited to 'src/gnunet_chat_lib.c')
-rw-r--r-- | src/gnunet_chat_lib.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index 294a735..32e7082 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -171,6 +171,9 @@ GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle, | |||
171 | handle->messenger, &key | 171 | handle->messenger, &key |
172 | ); | 172 | ); |
173 | 173 | ||
174 | if (!room) | ||
175 | return NULL; | ||
176 | |||
174 | struct GNUNET_CHAT_Context *context = context_create_from_room(handle, room); | 177 | struct GNUNET_CHAT_Context *context = context_create_from_room(handle, room); |
175 | 178 | ||
176 | context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; | 179 | context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; |
@@ -290,6 +293,57 @@ GNUNET_CHAT_contact_get_context (struct GNUNET_CHAT_Contact *contact) | |||
290 | if (!contact) | 293 | if (!contact) |
291 | return NULL; | 294 | return NULL; |
292 | 295 | ||
296 | if (contact->context) | ||
297 | return contact->context; | ||
298 | |||
299 | struct GNUNET_CHAT_ContactFindRoom find; | ||
300 | find.room = NULL; | ||
301 | GNUNET_MESSENGER_find_rooms( | ||
302 | contact->handle->messenger, | ||
303 | contact->member, | ||
304 | it_contact_find_room, | ||
305 | &find | ||
306 | ); | ||
307 | |||
308 | // TODO: Check if the found room is a group or not | ||
309 | |||
310 | if (!(find.room)) | ||
311 | return NULL; | ||
312 | |||
313 | struct GNUNET_HashCode key; | ||
314 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &key, sizeof(key)); | ||
315 | |||
316 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains( | ||
317 | contact->handle->contexts, &key)) | ||
318 | return NULL; | ||
319 | |||
320 | struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room( | ||
321 | contact->handle->messenger, &key | ||
322 | ); | ||
323 | |||
324 | if (!room) | ||
325 | return NULL; | ||
326 | |||
327 | struct GNUNET_CHAT_Context *context = context_create_from_room( | ||
328 | contact->handle, room | ||
329 | ); | ||
330 | |||
331 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | ||
332 | contact->handle->contexts, &key, context, | ||
333 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
334 | { | ||
335 | context_destroy(context); | ||
336 | return NULL; | ||
337 | } | ||
338 | |||
339 | struct GNUNET_MESSENGER_Message msg; | ||
340 | msg.header.kind = GNUNET_MESSENGER_KIND_INVITE; | ||
341 | GNUNET_CRYPTO_get_peer_identity(contact->handle->cfg, &(msg.body.invite.door)); | ||
342 | GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key)); | ||
343 | |||
344 | GNUNET_MESSENGER_send_message(find.room, &msg, contact->member); | ||
345 | |||
346 | contact->context = context; | ||
293 | return contact->context; | 347 | return contact->context; |
294 | } | 348 | } |
295 | 349 | ||