aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_handle_intern.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet_chat_handle_intern.c')
-rw-r--r--src/gnunet_chat_handle_intern.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index a6342a9..e2ea342 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -211,7 +211,7 @@ check_handle_room_members (void* cls,
211 return GNUNET_YES; 211 return GNUNET_YES;
212} 212}
213 213
214struct GNUNET_CHAT_Context* 214int
215request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle, 215request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle,
216 struct GNUNET_MESSENGER_Room *room) 216 struct GNUNET_MESSENGER_Room *room)
217{ 217{
@@ -222,7 +222,7 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle,
222 ); 222 );
223 223
224 if (context) 224 if (context)
225 return context; 225 return GNUNET_OK;
226 226
227 context = context_create_from_room(handle, room); 227 context = context_create_from_room(handle, room);
228 context_load_config(context); 228 context_load_config(context);
@@ -232,14 +232,16 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle,
232 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 232 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
233 { 233 {
234 context_destroy(context); 234 context_destroy(context);
235 return NULL; 235 return GNUNET_SYSERR;
236 } 236 }
237 237
238 struct GNUNET_CHAT_CheckHandleRoomMembers check; 238 struct GNUNET_CHAT_CheckHandleRoomMembers check;
239 check.ignore_key = GNUNET_MESSENGER_get_key(handle->messenger); 239 check.ignore_key = GNUNET_MESSENGER_get_key(handle->messenger);
240 check.contact = NULL; 240 check.contact = NULL;
241 241
242 GNUNET_MESSENGER_iterate_members(room, check_handle_room_members, &check); 242 const int checks = GNUNET_MESSENGER_iterate_members(
243 room, check_handle_room_members, &check
244 );
243 245
244 if (check.contact) 246 if (check.contact)
245 { 247 {
@@ -257,11 +259,11 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle,
257 if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put( 259 if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put(
258 handle->contacts, &shorthash, contact, 260 handle->contacts, &shorthash, contact,
259 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 261 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
260 return context; 262 return GNUNET_OK;
261 263
262 contact_destroy(contact); 264 contact_destroy(contact);
263 } 265 }
264 else 266 else if (checks >= 2)
265 { 267 {
266 context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; 268 context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP;
267 269
@@ -277,14 +279,20 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle,
277 if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( 279 if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(
278 handle->groups, key, group, 280 handle->groups, key, group,
279 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 281 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
280 return context; 282 return GNUNET_OK;
281 283
282 group_destroy(group); 284 group_destroy(group);
283 } 285 }
286 else
287 {
288 context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN;
289
290 // TODO: handle chats which only contain yourself currently!
291 }
284 292
285 GNUNET_CONTAINER_multihashmap_remove(handle->contexts, key, context); 293 GNUNET_CONTAINER_multihashmap_remove(handle->contexts, key, context);
286 context_destroy(context); 294 context_destroy(context);
287 return NULL; 295 return GNUNET_SYSERR;
288} 296}
289 297
290int 298int
@@ -293,9 +301,8 @@ find_handle_rooms (void *cls, struct GNUNET_MESSENGER_Room *room,
293{ 301{
294 struct GNUNET_CHAT_Handle *handle = cls; 302 struct GNUNET_CHAT_Handle *handle = cls;
295 303
296 request_handle_context_by_room( 304 if (GNUNET_OK != request_handle_context_by_room(handle, room))
297 handle, room 305 return GNUNET_NO;
298 );
299 306
300 return GNUNET_YES; 307 return GNUNET_YES;
301} 308}