aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/messenger_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/messenger_api.c')
-rw-r--r--src/messenger/messenger_api.c417
1 files changed, 251 insertions, 166 deletions
diff --git a/src/messenger/messenger_api.c b/src/messenger/messenger_api.c
index 82fc0d1eb..fe99e0e8d 100644
--- a/src/messenger/messenger_api.c
+++ b/src/messenger/messenger_api.c
@@ -75,6 +75,7 @@ GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind)
75 } 75 }
76} 76}
77 77
78
78static enum GNUNET_GenericReturnValue 79static enum GNUNET_GenericReturnValue
79dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room); 80dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room);
80 81
@@ -86,7 +87,7 @@ handle_room_open (void *cls,
86 87
87 const struct GNUNET_HashCode *key = &(msg->key); 88 const struct GNUNET_HashCode *key = &(msg->key);
88 89
89 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key)); 90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key));
90 91
91 open_handle_room (handle, key); 92 open_handle_room (handle, key);
92 93
@@ -96,6 +97,7 @@ handle_room_open (void *cls,
96 dequeue_messages_from_room (room); 97 dequeue_messages_from_room (room);
97} 98}
98 99
100
99static void 101static void
100handle_room_entry (void *cls, 102handle_room_entry (void *cls,
101 const struct GNUNET_MESSENGER_RoomMessage *msg) 103 const struct GNUNET_MESSENGER_RoomMessage *msg)
@@ -115,6 +117,7 @@ handle_room_entry (void *cls,
115 dequeue_messages_from_room (room); 117 dequeue_messages_from_room (room);
116} 118}
117 119
120
118static void 121static void
119handle_room_close (void *cls, 122handle_room_close (void *cls,
120 const struct GNUNET_MESSENGER_RoomMessage *msg) 123 const struct GNUNET_MESSENGER_RoomMessage *msg)
@@ -133,6 +136,7 @@ handle_room_close (void *cls,
133 close_handle_room (handle, key); 136 close_handle_room (handle, key);
134} 137}
135 138
139
136static void 140static void
137enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, 141enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room,
138 struct GNUNET_MESSENGER_Message *message); 142 struct GNUNET_MESSENGER_Message *message);
@@ -147,13 +151,15 @@ handle_member_id (void *cls,
147 const struct GNUNET_ShortHashCode *id = &(msg->id); 151 const struct GNUNET_ShortHashCode *id = &(msg->id);
148 const uint32_t reset = msg->reset; 152 const uint32_t reset = msg->reset;
149 153
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Changed member id in room: %s\n", GNUNET_h2s (key)); 154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Changed member id in room: %s\n",
155 GNUNET_h2s (key));
151 156
152 struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key); 157 struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key);
153 158
154 if (!room) 159 if (! room)
155 { 160 {
156 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Room is unknown to handle: %s\n", GNUNET_h2s (key)); 161 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Room is unknown to handle: %s\n",
162 GNUNET_h2s (key));
157 return; 163 return;
158 } 164 }
159 165
@@ -161,7 +167,7 @@ handle_member_id (void *cls,
161 switch (reset) 167 switch (reset)
162 { 168 {
163 case GNUNET_YES: 169 case GNUNET_YES:
164 set_room_sender_id(room, id); 170 set_room_sender_id (room, id);
165 message = create_message_join (get_handle_key (handle)); 171 message = create_message_join (get_handle_key (handle));
166 break; 172 break;
167 case GNUNET_NO: 173 case GNUNET_NO:
@@ -171,13 +177,14 @@ handle_member_id (void *cls,
171 break; 177 break;
172 } 178 }
173 179
174 if (!message) 180 if (! message)
175 return; 181 return;
176 182
177 enqueue_message_to_room (room, message); 183 enqueue_message_to_room (room, message);
178 destroy_message (message); 184 destroy_message (message);
179} 185}
180 186
187
181static int 188static int
182check_recv_message (void *cls, 189check_recv_message (void *cls,
183 const struct GNUNET_MESSENGER_RecvMessage *msg) 190 const struct GNUNET_MESSENGER_RecvMessage *msg)
@@ -186,7 +193,8 @@ check_recv_message (void *cls,
186 193
187 if (full_length < sizeof(*msg)) 194 if (full_length < sizeof(*msg))
188 { 195 {
189 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Receiving failed: Message invalid!\n"); 196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 "Receiving failed: Message invalid!\n");
190 return GNUNET_NO; 198 return GNUNET_NO;
191 } 199 }
192 200
@@ -195,22 +203,26 @@ check_recv_message (void *cls,
195 203
196 struct GNUNET_MESSENGER_Message message; 204 struct GNUNET_MESSENGER_Message message;
197 205
198 if (length < get_message_kind_size(GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_YES)) 206 if (length < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN,
207 GNUNET_YES))
199 { 208 {
200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Receiving failed: Message too short!\n"); 209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
210 "Receiving failed: Message too short!\n");
201 return GNUNET_NO; 211 return GNUNET_NO;
202 } 212 }
203 213
204 if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL)) 214 if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL))
205 { 215 {
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Receiving failed: Message decoding failed!\n"); 216 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
217 "Receiving failed: Message decoding failed!\n");
207 return GNUNET_NO; 218 return GNUNET_NO;
208 } 219 }
209 220
210 cleanup_message(&message); 221 cleanup_message (&message);
211 return GNUNET_OK; 222 return GNUNET_OK;
212} 223}
213 224
225
214static void 226static void
215handle_recv_message (void *cls, 227handle_recv_message (void *cls,
216 const struct GNUNET_MESSENGER_RecvMessage *msg) 228 const struct GNUNET_MESSENGER_RecvMessage *msg)
@@ -223,8 +235,8 @@ handle_recv_message (void *cls,
223 const struct GNUNET_HashCode *hash = &(msg->hash); 235 const struct GNUNET_HashCode *hash = &(msg->hash);
224 236
225 enum GNUNET_MESSENGER_MessageFlags flags = ( 237 enum GNUNET_MESSENGER_MessageFlags flags = (
226 (enum GNUNET_MESSENGER_MessageFlags) (msg->flags) 238 (enum GNUNET_MESSENGER_MessageFlags) (msg->flags)
227 ); 239 );
228 240
229 const uint16_t length = ntohs (msg->header.size) - sizeof(*msg); 241 const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
230 const char *buffer = ((const char*) msg) + sizeof(*msg); 242 const char *buffer = ((const char*) msg) + sizeof(*msg);
@@ -235,11 +247,12 @@ handle_recv_message (void *cls,
235 struct GNUNET_MESSENGER_Message *private_message = NULL; 247 struct GNUNET_MESSENGER_Message *private_message = NULL;
236 if (GNUNET_MESSENGER_KIND_PRIVATE == message.header.kind) 248 if (GNUNET_MESSENGER_KIND_PRIVATE == message.header.kind)
237 { 249 {
238 private_message = copy_message(&message); 250 private_message = copy_message (&message);
239 251
240 if (GNUNET_YES != decrypt_message(private_message, get_handle_key(handle))) 252 if (GNUNET_YES != decrypt_message (private_message, get_handle_key (
253 handle)))
241 { 254 {
242 destroy_message(private_message); 255 destroy_message (private_message);
243 private_message = NULL; 256 private_message = NULL;
244 } 257 }
245 } 258 }
@@ -248,37 +261,46 @@ handle_recv_message (void *cls,
248 flags |= GNUNET_MESSENGER_FLAG_PRIVATE; 261 flags |= GNUNET_MESSENGER_FLAG_PRIVATE;
249 262
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n", 263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n",
251 GNUNET_MESSENGER_name_of_kind (private_message ? private_message->header.kind : message.header.kind)); 264 GNUNET_MESSENGER_name_of_kind (private_message ?
265 private_message->header.kind :
266 message.header.kind));
252 267
253 struct GNUNET_MESSENGER_Room *room = get_handle_room(handle, key); 268 struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key);
254 269
255 if (room) 270 if (room)
256 { 271 {
257 struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(handle); 272 struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store (
273 handle);
258 274
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Raw contact from sender and context: (%s : %s)\n", 275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 GNUNET_h2s(sender), GNUNET_h2s_full(context)); 276 "Raw contact from sender and context: (%s : %s)\n",
277 GNUNET_h2s (sender), GNUNET_h2s_full (context));
261 278
262 struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw( 279 struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw (
263 store, context, sender 280 store, context, sender
264 ); 281 );
265 282
266 contact = handle_room_message (room, contact, private_message ? private_message : &message, hash, flags); 283 contact = handle_room_message (room, contact, private_message ?
284 private_message : &message, hash, flags);
267 285
268 const struct GNUNET_MESSENGER_Message *stored_message = get_room_message(room, hash); 286 const struct GNUNET_MESSENGER_Message *stored_message = get_room_message (
287 room, hash);
269 288
270 if (handle->msg_callback) 289 if (handle->msg_callback)
271 handle->msg_callback (handle->msg_cls, room, contact, stored_message, hash, flags); 290 handle->msg_callback (handle->msg_cls, room, contact, stored_message,
291 hash, flags);
272 } 292 }
273 else 293 else
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n", GNUNET_h2s (key)); 294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n",
295 GNUNET_h2s (key));
275 296
276 cleanup_message(&message); 297 cleanup_message (&message);
277 298
278 if (private_message) 299 if (private_message)
279 destroy_message(private_message); 300 destroy_message (private_message);
280} 301}
281 302
303
282static void 304static void
283handle_miss_message (void *cls, 305handle_miss_message (void *cls,
284 const struct GNUNET_MESSENGER_GetMessage *msg) 306 const struct GNUNET_MESSENGER_GetMessage *msg)
@@ -288,27 +310,30 @@ handle_miss_message (void *cls,
288 const struct GNUNET_HashCode *key = &(msg->key); 310 const struct GNUNET_HashCode *key = &(msg->key);
289 const struct GNUNET_HashCode *hash = &(msg->hash); 311 const struct GNUNET_HashCode *hash = &(msg->hash);
290 312
291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Missing message in room: %s\n", GNUNET_h2s (hash)); 313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Missing message in room: %s\n",
314 GNUNET_h2s (hash));
292 315
293 struct GNUNET_MESSENGER_Room *room = get_handle_room(handle, key); 316 struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key);
294 317
295 if (!room) 318 if (! room)
296 { 319 {
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Miss in unknown room for this client: %s\n", GNUNET_h2s (key)); 320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
321 "Miss in unknown room for this client: %s\n", GNUNET_h2s (key));
298 return; 322 return;
299 } 323 }
300 324
301 if (!get_room_sender_id(room)) 325 if (! get_room_sender_id (room))
302 return; 326 return;
303 327
304 struct GNUNET_MESSENGER_Message *message = create_message_request (hash); 328 struct GNUNET_MESSENGER_Message *message = create_message_request (hash);
305 if (!message) 329 if (! message)
306 return; 330 return;
307 331
308 enqueue_message_to_room (room, message); 332 enqueue_message_to_room (room, message);
309 destroy_message (message); 333 destroy_message (message);
310} 334}
311 335
336
312static void 337static void
313reconnect (struct GNUNET_MESSENGER_Handle *handle); 338reconnect (struct GNUNET_MESSENGER_Handle *handle);
314 339
@@ -316,34 +341,37 @@ static void
316send_open_room (struct GNUNET_MESSENGER_Handle *handle, 341send_open_room (struct GNUNET_MESSENGER_Handle *handle,
317 struct GNUNET_MESSENGER_Room *room) 342 struct GNUNET_MESSENGER_Room *room)
318{ 343{
319 const struct GNUNET_IDENTITY_PublicKey *key = get_handle_pubkey(handle); 344 const struct GNUNET_IDENTITY_PublicKey *key = get_handle_pubkey (handle);
320 345
321 struct GNUNET_MESSENGER_RoomMessage *msg; 346 struct GNUNET_MESSENGER_RoomMessage *msg;
322 struct GNUNET_MQ_Envelope *env; 347 struct GNUNET_MQ_Envelope *env;
323 348
324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Open room (%s) by member using key: %s\n", 349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
350 "Open room (%s) by member using key: %s\n",
325 GNUNET_h2s (&(room->key)), 351 GNUNET_h2s (&(room->key)),
326 GNUNET_IDENTITY_public_key_to_string (key)); 352 GNUNET_IDENTITY_public_key_to_string (key));
327 353
328 const ssize_t len = GNUNET_IDENTITY_public_key_get_length(key); 354 const ssize_t len = GNUNET_IDENTITY_public_key_get_length (key);
329 355
330 env = GNUNET_MQ_msg_extra(msg, len > 0 ? len : 0, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN); 356 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
331 GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key)); 357 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN);
358 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
332 359
333 char *msg_buffer = ((char*) msg) + sizeof(*msg); 360 char *msg_buffer = ((char*) msg) + sizeof(*msg);
334 361
335 if (len > 0) 362 if (len > 0)
336 GNUNET_IDENTITY_write_public_key_to_buffer(key, msg_buffer, len); 363 GNUNET_IDENTITY_write_public_key_to_buffer (key, msg_buffer, len);
337 364
338 GNUNET_MQ_send (handle->mq, env); 365 GNUNET_MQ_send (handle->mq, env);
339} 366}
340 367
368
341static void 369static void
342send_enter_room (struct GNUNET_MESSENGER_Handle *handle, 370send_enter_room (struct GNUNET_MESSENGER_Handle *handle,
343 struct GNUNET_MESSENGER_Room *room, 371 struct GNUNET_MESSENGER_Room *room,
344 const struct GNUNET_PeerIdentity *door) 372 const struct GNUNET_PeerIdentity *door)
345{ 373{
346 const struct GNUNET_IDENTITY_PublicKey *key = get_handle_pubkey(handle); 374 const struct GNUNET_IDENTITY_PublicKey *key = get_handle_pubkey (handle);
347 375
348 struct GNUNET_MESSENGER_RoomMessage *msg; 376 struct GNUNET_MESSENGER_RoomMessage *msg;
349 struct GNUNET_MQ_Envelope *env; 377 struct GNUNET_MQ_Envelope *env;
@@ -353,20 +381,22 @@ send_enter_room (struct GNUNET_MESSENGER_Handle *handle,
353 GNUNET_i2s (door), 381 GNUNET_i2s (door),
354 GNUNET_IDENTITY_public_key_to_string (key)); 382 GNUNET_IDENTITY_public_key_to_string (key));
355 383
356 const ssize_t len = GNUNET_IDENTITY_public_key_get_length(key); 384 const ssize_t len = GNUNET_IDENTITY_public_key_get_length (key);
357 385
358 env = GNUNET_MQ_msg_extra(msg, len > 0 ? len : 0, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY); 386 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
359 GNUNET_memcpy(&(msg->door), door, sizeof(*door)); 387 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY);
360 GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key)); 388 GNUNET_memcpy (&(msg->door), door, sizeof(*door));
389 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
361 390
362 char *msg_buffer = ((char*) msg) + sizeof(*msg); 391 char *msg_buffer = ((char*) msg) + sizeof(*msg);
363 392
364 if (len > 0) 393 if (len > 0)
365 GNUNET_IDENTITY_write_public_key_to_buffer(key, msg_buffer, len); 394 GNUNET_IDENTITY_write_public_key_to_buffer (key, msg_buffer, len);
366 395
367 GNUNET_MQ_send (handle->mq, env); 396 GNUNET_MQ_send (handle->mq, env);
368} 397}
369 398
399
370static void 400static void
371send_close_room (struct GNUNET_MESSENGER_Handle *handle, 401send_close_room (struct GNUNET_MESSENGER_Handle *handle,
372 struct GNUNET_MESSENGER_Room *room) 402 struct GNUNET_MESSENGER_Room *room)
@@ -377,11 +407,12 @@ send_close_room (struct GNUNET_MESSENGER_Handle *handle,
377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Close room (%s)!\n", 407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Close room (%s)!\n",
378 GNUNET_h2s (&(room->key))); 408 GNUNET_h2s (&(room->key)));
379 409
380 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE); 410 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE);
381 GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key)); 411 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
382 GNUNET_MQ_send (handle->mq, env); 412 GNUNET_MQ_send (handle->mq, env);
383} 413}
384 414
415
385static int 416static int
386iterate_reset_room (void *cls, 417iterate_reset_room (void *cls,
387 const struct GNUNET_HashCode *key, 418 const struct GNUNET_HashCode *key,
@@ -409,21 +440,24 @@ iterate_reset_room (void *cls,
409 return GNUNET_YES; 440 return GNUNET_YES;
410} 441}
411 442
443
412static void 444static void
413callback_reconnect (void *cls) 445callback_reconnect (void *cls)
414{ 446{
415 struct GNUNET_MESSENGER_Handle *handle = cls; 447 struct GNUNET_MESSENGER_Handle *handle = cls;
416 448
417 handle->reconnect_task = NULL; 449 handle->reconnect_task = NULL;
418 handle->reconnect_time = GNUNET_TIME_STD_BACKOFF(handle->reconnect_time); 450 handle->reconnect_time = GNUNET_TIME_STD_BACKOFF (handle->reconnect_time);
419 451
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnect messenger!\n"); 452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnect messenger!\n");
421 453
422 reconnect (handle); 454 reconnect (handle);
423 455
424 GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_reset_room, handle); 456 GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_reset_room,
457 handle);
425} 458}
426 459
460
427static int 461static int
428iterate_close_room (void *cls, 462iterate_close_room (void *cls,
429 const struct GNUNET_HashCode *key, 463 const struct GNUNET_HashCode *key,
@@ -437,15 +471,17 @@ iterate_close_room (void *cls,
437 return GNUNET_YES; 471 return GNUNET_YES;
438} 472}
439 473
474
440static void 475static void
441callback_mq_error (void *cls, 476callback_mq_error (void *cls,
442 enum GNUNET_MQ_Error error) 477 enum GNUNET_MQ_Error error)
443{ 478{
444 struct GNUNET_MESSENGER_Handle *handle = cls; 479 struct GNUNET_MESSENGER_Handle *handle = cls;
445 480
446 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error); 481 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error);
447 482
448 GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_close_room, handle); 483 GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_close_room,
484 handle);
449 485
450 if (handle->mq) 486 if (handle->mq)
451 { 487 {
@@ -453,50 +489,55 @@ callback_mq_error (void *cls,
453 handle->mq = NULL; 489 handle->mq = NULL;
454 } 490 }
455 491
456 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_time, &callback_reconnect, handle); 492 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_time,
493 &callback_reconnect,
494 handle);
457} 495}
458 496
497
459static void 498static void
460reconnect (struct GNUNET_MESSENGER_Handle *handle) 499reconnect (struct GNUNET_MESSENGER_Handle *handle)
461{ 500{
462 const struct GNUNET_MQ_MessageHandler handlers[] = 501 const struct GNUNET_MQ_MessageHandler handlers[] = {
463 { 502 GNUNET_MQ_hd_fixed_size (
464 GNUNET_MQ_hd_fixed_size( 503 member_id,
465 member_id, 504 GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID,
466 GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID, 505 struct GNUNET_MESSENGER_MemberMessage, handle
467 struct GNUNET_MESSENGER_MemberMessage, handle 506 ),
468 ), 507 GNUNET_MQ_hd_fixed_size (
469 GNUNET_MQ_hd_fixed_size( 508 room_open,
470 room_open, 509 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN,
471 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, 510 struct GNUNET_MESSENGER_RoomMessage, handle
472 struct GNUNET_MESSENGER_RoomMessage, handle 511 ),
473 ), 512 GNUNET_MQ_hd_fixed_size (
474 GNUNET_MQ_hd_fixed_size( 513 room_entry,
475 room_entry, 514 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY,
476 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, 515 struct GNUNET_MESSENGER_RoomMessage, handle
477 struct GNUNET_MESSENGER_RoomMessage, handle 516 ),
478 ), 517 GNUNET_MQ_hd_fixed_size (
479 GNUNET_MQ_hd_fixed_size( 518 room_close,
480 room_close, 519 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE,
481 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, 520 struct GNUNET_MESSENGER_RoomMessage, handle
482 struct GNUNET_MESSENGER_RoomMessage, handle 521 ),
483 ), 522 GNUNET_MQ_hd_var_size (
484 GNUNET_MQ_hd_var_size( 523 recv_message,
485 recv_message, 524 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE,
486 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE, 525 struct GNUNET_MESSENGER_RecvMessage, handle
487 struct GNUNET_MESSENGER_RecvMessage, handle 526 ),
488 ), 527 GNUNET_MQ_hd_fixed_size (
489 GNUNET_MQ_hd_fixed_size( 528 miss_message,
490 miss_message, 529 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE,
491 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE, 530 struct GNUNET_MESSENGER_GetMessage, handle
492 struct GNUNET_MESSENGER_GetMessage, handle 531 ),
493 ), 532 GNUNET_MQ_handler_end ()
494 GNUNET_MQ_handler_end()
495 }; 533 };
496 534
497 handle->mq = GNUNET_CLIENT_connect (handle->cfg, GNUNET_MESSENGER_SERVICE_NAME, handlers, &callback_mq_error, handle); 535 handle->mq = GNUNET_CLIENT_connect (handle->cfg,
536 GNUNET_MESSENGER_SERVICE_NAME, handlers,
537 &callback_mq_error, handle);
498} 538}
499 539
540
500struct GNUNET_MESSENGER_Handle* 541struct GNUNET_MESSENGER_Handle*
501GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 542GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
502 const char *name, 543 const char *name,
@@ -504,7 +545,8 @@ GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
504 GNUNET_MESSENGER_MessageCallback msg_callback, 545 GNUNET_MESSENGER_MessageCallback msg_callback,
505 void *msg_cls) 546 void *msg_cls)
506{ 547{
507 struct GNUNET_MESSENGER_Handle *handle = create_handle (cfg, msg_callback, msg_cls); 548 struct GNUNET_MESSENGER_Handle *handle = create_handle (cfg, msg_callback,
549 msg_cls);
508 550
509 reconnect (handle); 551 reconnect (handle);
510 552
@@ -512,13 +554,13 @@ GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
512 { 554 {
513 set_handle_name (handle, name); 555 set_handle_name (handle, name);
514 556
515 if ((!key) || (0 < GNUNET_IDENTITY_private_key_get_length (key))) 557 if ((! key) || (0 < GNUNET_IDENTITY_private_key_get_length (key)))
516 set_handle_key (handle, key); 558 set_handle_key (handle, key);
517 559
518 struct GNUNET_MESSENGER_CreateMessage *msg; 560 struct GNUNET_MESSENGER_CreateMessage *msg;
519 struct GNUNET_MQ_Envelope *env; 561 struct GNUNET_MQ_Envelope *env;
520 562
521 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE); 563 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE);
522 GNUNET_MQ_send (handle->mq, env); 564 GNUNET_MQ_send (handle->mq, env);
523 return handle; 565 return handle;
524 } 566 }
@@ -529,21 +571,23 @@ GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
529 } 571 }
530} 572}
531 573
574
532void 575void
533GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle) 576GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle)
534{ 577{
535 if (!handle) 578 if (! handle)
536 return; 579 return;
537 580
538 struct GNUNET_MESSENGER_DestroyMessage *msg; 581 struct GNUNET_MESSENGER_DestroyMessage *msg;
539 struct GNUNET_MQ_Envelope *env; 582 struct GNUNET_MQ_Envelope *env;
540 583
541 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY); 584 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY);
542 GNUNET_MQ_send (handle->mq, env); 585 GNUNET_MQ_send (handle->mq, env);
543 586
544 destroy_handle (handle); 587 destroy_handle (handle);
545} 588}
546 589
590
547static void 591static void
548send_message_to_room (struct GNUNET_MESSENGER_Room *room, 592send_message_to_room (struct GNUNET_MESSENGER_Room *room,
549 struct GNUNET_MESSENGER_Message *message, 593 struct GNUNET_MESSENGER_Message *message,
@@ -551,10 +595,13 @@ send_message_to_room (struct GNUNET_MESSENGER_Room *room,
551{ 595{
552 const struct GNUNET_ShortHashCode *sender_id = get_room_sender_id (room); 596 const struct GNUNET_ShortHashCode *sender_id = get_room_sender_id (room);
553 597
554 message->header.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 598 message->header.timestamp = GNUNET_TIME_absolute_hton (
599 GNUNET_TIME_absolute_get ());
555 600
556 GNUNET_memcpy (&(message->header.sender_id), sender_id, sizeof(message->header.sender_id)); 601 GNUNET_memcpy (&(message->header.sender_id), sender_id,
557 GNUNET_memcpy (&(message->header.previous), &(room->last_message), sizeof(message->header.previous)); 602 sizeof(message->header.sender_id));
603 GNUNET_memcpy (&(message->header.previous), &(room->last_message),
604 sizeof(message->header.previous));
558 605
559 message->header.signature.type = key->type; 606 message->header.signature.type = key->type;
560 607
@@ -563,12 +610,12 @@ send_message_to_room (struct GNUNET_MESSENGER_Room *room,
563 struct GNUNET_MESSENGER_SendMessage *msg; 610 struct GNUNET_MESSENGER_SendMessage *msg;
564 struct GNUNET_MQ_Envelope *env; 611 struct GNUNET_MQ_Envelope *env;
565 612
566 env = GNUNET_MQ_msg_extra( 613 env = GNUNET_MQ_msg_extra (
567 msg, msg_length, 614 msg, msg_length,
568 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE 615 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE
569 ); 616 );
570 617
571 GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key)); 618 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
572 619
573 char *msg_buffer = ((char*) msg) + sizeof(*msg); 620 char *msg_buffer = ((char*) msg) + sizeof(*msg);
574 encode_message (message, msg_length, msg_buffer, GNUNET_YES); 621 encode_message (message, msg_length, msg_buffer, GNUNET_YES);
@@ -582,6 +629,7 @@ send_message_to_room (struct GNUNET_MESSENGER_Room *room,
582 GNUNET_MQ_send (room->handle->mq, env); 629 GNUNET_MQ_send (room->handle->mq, env);
583} 630}
584 631
632
585static void 633static void
586enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, 634enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room,
587 struct GNUNET_MESSENGER_Message *message) 635 struct GNUNET_MESSENGER_Message *message)
@@ -594,9 +642,10 @@ enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room,
594 send_message_to_room (room, message, key); 642 send_message_to_room (room, message, key);
595 } 643 }
596 else 644 else
597 enqueue_to_messages(&(room->queue), key, message); 645 enqueue_to_messages (&(room->queue), key, message);
598} 646}
599 647
648
600static enum GNUNET_GenericReturnValue 649static enum GNUNET_GenericReturnValue
601dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room) 650dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room)
602{ 651{
@@ -608,28 +657,30 @@ dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room)
608 657
609 do { 658 do {
610 if (message) 659 if (message)
611 destroy_message(message); 660 destroy_message (message);
612 661
613 message = dequeue_from_messages(&(room->queue), &key); 662 message = dequeue_from_messages (&(room->queue), &key);
614 663
615 if (message) 664 if (message)
616 send_message_to_room(room, message, &key); 665 send_message_to_room (room, message, &key);
617 } while (message); 666 } while (message);
618 667
619 return GNUNET_YES; 668 return GNUNET_YES;
620} 669}
621 670
671
622const char* 672const char*
623GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle) 673GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle)
624{ 674{
625 if (!handle) 675 if (! handle)
626 return NULL; 676 return NULL;
627 677
628 return get_handle_name (handle); 678 return get_handle_name (handle);
629} 679}
630 680
681
631static int 682static int
632iterate_send_name_to_room (void* cls, 683iterate_send_name_to_room (void *cls,
633 struct GNUNET_MESSENGER_Room *room, 684 struct GNUNET_MESSENGER_Room *room,
634 const struct GNUNET_MESSENGER_Contact *contact) 685 const struct GNUNET_MESSENGER_Contact *contact)
635{ 686{
@@ -638,14 +689,14 @@ iterate_send_name_to_room (void* cls,
638 if (GNUNET_YES != room->use_handle_name) 689 if (GNUNET_YES != room->use_handle_name)
639 return GNUNET_YES; 690 return GNUNET_YES;
640 691
641 const char *name = get_handle_name(handle); 692 const char *name = get_handle_name (handle);
642 693
643 if (!name) 694 if (! name)
644 return GNUNET_YES; 695 return GNUNET_YES;
645 696
646 struct GNUNET_MESSENGER_Message *message = create_message_name (name); 697 struct GNUNET_MESSENGER_Message *message = create_message_name (name);
647 698
648 if (!message) 699 if (! message)
649 return GNUNET_NO; 700 return GNUNET_NO;
650 701
651 enqueue_message_to_room (room, message); 702 enqueue_message_to_room (room, message);
@@ -653,11 +704,12 @@ iterate_send_name_to_room (void* cls,
653 return GNUNET_YES; 704 return GNUNET_YES;
654} 705}
655 706
707
656int 708int
657GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, 709GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle,
658 const char *name) 710 const char *name)
659{ 711{
660 if (!handle) 712 if (! handle)
661 return GNUNET_SYSERR; 713 return GNUNET_SYSERR;
662 714
663 set_handle_name (handle, strlen (name) > 0 ? name : NULL); 715 set_handle_name (handle, strlen (name) > 0 ? name : NULL);
@@ -665,26 +717,29 @@ GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle,
665 return GNUNET_YES; 717 return GNUNET_YES;
666} 718}
667 719
720
668static const struct GNUNET_IDENTITY_PublicKey* 721static const struct GNUNET_IDENTITY_PublicKey*
669get_non_anonymous_key (const struct GNUNET_IDENTITY_PublicKey* public_key) 722get_non_anonymous_key (const struct GNUNET_IDENTITY_PublicKey *public_key)
670{ 723{
671 if (0 == GNUNET_memcmp(public_key, get_anonymous_public_key ())) 724 if (0 == GNUNET_memcmp (public_key, get_anonymous_public_key ()))
672 return NULL; 725 return NULL;
673 726
674 return public_key; 727 return public_key;
675} 728}
676 729
730
677const struct GNUNET_IDENTITY_PublicKey* 731const struct GNUNET_IDENTITY_PublicKey*
678GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle) 732GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle)
679{ 733{
680 if (!handle) 734 if (! handle)
681 return NULL; 735 return NULL;
682 736
683 return get_non_anonymous_key (get_handle_pubkey (handle)); 737 return get_non_anonymous_key (get_handle_pubkey (handle));
684} 738}
685 739
740
686static int 741static int
687iterate_send_key_to_room (void* cls, 742iterate_send_key_to_room (void *cls,
688 struct GNUNET_MESSENGER_Room *room, 743 struct GNUNET_MESSENGER_Room *room,
689 const struct GNUNET_MESSENGER_Contact *contact) 744 const struct GNUNET_MESSENGER_Contact *contact)
690{ 745{
@@ -692,7 +747,7 @@ iterate_send_key_to_room (void* cls,
692 747
693 struct GNUNET_MESSENGER_Message *message = create_message_key (key); 748 struct GNUNET_MESSENGER_Message *message = create_message_key (key);
694 749
695 if (!message) 750 if (! message)
696 return GNUNET_NO; 751 return GNUNET_NO;
697 752
698 enqueue_message_to_room (room, message); 753 enqueue_message_to_room (room, message);
@@ -700,14 +755,15 @@ iterate_send_key_to_room (void* cls,
700 return GNUNET_YES; 755 return GNUNET_YES;
701} 756}
702 757
758
703int 759int
704GNUNET_MESSENGER_set_key (struct GNUNET_MESSENGER_Handle *handle, 760GNUNET_MESSENGER_set_key (struct GNUNET_MESSENGER_Handle *handle,
705 const struct GNUNET_IDENTITY_PrivateKey *key) 761 const struct GNUNET_IDENTITY_PrivateKey *key)
706{ 762{
707 if (!handle) 763 if (! handle)
708 return GNUNET_SYSERR; 764 return GNUNET_SYSERR;
709 765
710 if (!key) 766 if (! key)
711 { 767 {
712 GNUNET_MESSENGER_find_rooms (handle, NULL, iterate_send_key_to_room, NULL); 768 GNUNET_MESSENGER_find_rooms (handle, NULL, iterate_send_key_to_room, NULL);
713 set_handle_key (handle, NULL); 769 set_handle_key (handle, NULL);
@@ -725,20 +781,23 @@ GNUNET_MESSENGER_set_key (struct GNUNET_MESSENGER_Handle *handle,
725 return GNUNET_YES; 781 return GNUNET_YES;
726} 782}
727 783
784
728struct GNUNET_MESSENGER_Room* 785struct GNUNET_MESSENGER_Room*
729GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, 786GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle,
730 const struct GNUNET_HashCode *key) 787 const struct GNUNET_HashCode *key)
731{ 788{
732 if ((!handle) || (!key)) 789 if ((! handle) || (! key))
733 return NULL; 790 return NULL;
734 791
735 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); 792 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (
793 handle->rooms, key);
736 794
737 if (!room) 795 if (! room)
738 { 796 {
739 room = create_room (handle, key); 797 room = create_room (handle, key);
740 798
741 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room, 799 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key,
800 room,
742 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 801 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
743 { 802 {
744 destroy_room (room); 803 destroy_room (room);
@@ -750,21 +809,24 @@ GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle,
750 return room; 809 return room;
751} 810}
752 811
812
753struct GNUNET_MESSENGER_Room* 813struct GNUNET_MESSENGER_Room*
754GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle, 814GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle,
755 const struct GNUNET_PeerIdentity *door, 815 const struct GNUNET_PeerIdentity *door,
756 const struct GNUNET_HashCode *key) 816 const struct GNUNET_HashCode *key)
757{ 817{
758 if ((!handle) || (!door) || (!key)) 818 if ((! handle) || (! door) || (! key))
759 return NULL; 819 return NULL;
760 820
761 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); 821 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (
822 handle->rooms, key);
762 823
763 if (!room) 824 if (! room)
764 { 825 {
765 room = create_room (handle, key); 826 room = create_room (handle, key);
766 827
767 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room, 828 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key,
829 room,
768 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 830 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
769 { 831 {
770 destroy_room (room); 832 destroy_room (room);
@@ -776,13 +838,14 @@ GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle,
776 return room; 838 return room;
777} 839}
778 840
841
779void 842void
780GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room) 843GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room)
781{ 844{
782 if (!room) 845 if (! room)
783 return; 846 return;
784 847
785 struct GNUNET_MESSENGER_Message *message = create_message_leave(); 848 struct GNUNET_MESSENGER_Message *message = create_message_leave ();
786 849
787 if (message) 850 if (message)
788 { 851 {
@@ -793,6 +856,7 @@ GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room)
793 send_close_room (room->handle, room); 856 send_close_room (room->handle, room);
794} 857}
795 858
859
796struct GNUNET_MESSENGER_RoomFind 860struct GNUNET_MESSENGER_RoomFind
797{ 861{
798 const struct GNUNET_MESSENGER_Contact *contact; 862 const struct GNUNET_MESSENGER_Contact *contact;
@@ -802,33 +866,37 @@ struct GNUNET_MESSENGER_RoomFind
802}; 866};
803 867
804static int 868static int
805iterate_find_room (void* cls, 869iterate_find_room (void *cls,
806 const struct GNUNET_HashCode *key, 870 const struct GNUNET_HashCode *key,
807 void *value) 871 void *value)
808{ 872{
809 struct GNUNET_MESSENGER_RoomFind *find = cls; 873 struct GNUNET_MESSENGER_RoomFind *find = cls;
810 struct GNUNET_MESSENGER_Room *room = value; 874 struct GNUNET_MESSENGER_Room *room = value;
811 875
812 if ((find->counter > 0) && ((!find->contact) || (GNUNET_YES == find_room_member(room, find->contact)))) 876 if ((find->counter > 0) && ((! find->contact) || (GNUNET_YES ==
877 find_room_member (room,
878 find->
879 contact))))
813 { 880 {
814 find->counter--; 881 find->counter--;
815 882
816 if (!find->callback) 883 if (! find->callback)
817 return GNUNET_YES; 884 return GNUNET_YES;
818 885
819 return find->callback(find->cls, room, find->contact); 886 return find->callback (find->cls, room, find->contact);
820 } 887 }
821 else 888 else
822 return GNUNET_NO; 889 return GNUNET_NO;
823} 890}
824 891
892
825int 893int
826GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, 894GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle,
827 const struct GNUNET_MESSENGER_Contact *contact, 895 const struct GNUNET_MESSENGER_Contact *contact,
828 GNUNET_MESSENGER_MemberCallback callback, 896 GNUNET_MESSENGER_MemberCallback callback,
829 void *cls) 897 void *cls)
830{ 898{
831 if (!handle) 899 if (! handle)
832 return GNUNET_SYSERR; 900 return GNUNET_SYSERR;
833 901
834 struct GNUNET_MESSENGER_RoomFind find; 902 struct GNUNET_MESSENGER_RoomFind find;
@@ -838,79 +906,91 @@ GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle,
838 find.counter = (contact? contact->rc : SIZE_MAX); 906 find.counter = (contact? contact->rc : SIZE_MAX);
839 find.cls = cls; 907 find.cls = cls;
840 908
841 return GNUNET_CONTAINER_multihashmap_iterate(handle->rooms, iterate_find_room, &find); 909 return GNUNET_CONTAINER_multihashmap_iterate (handle->rooms,
910 iterate_find_room, &find);
842} 911}
843 912
913
844const struct GNUNET_HashCode* 914const struct GNUNET_HashCode*
845GNUNET_MESSENGER_room_get_key (const struct GNUNET_MESSENGER_Room *room) 915GNUNET_MESSENGER_room_get_key (const struct GNUNET_MESSENGER_Room *room)
846{ 916{
847 if (!room) 917 if (! room)
848 return NULL; 918 return NULL;
849 919
850 return &(room->key); 920 return &(room->key);
851} 921}
852 922
923
853const struct GNUNET_MESSENGER_Contact* 924const struct GNUNET_MESSENGER_Contact*
854GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, 925GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room,
855 const struct GNUNET_HashCode *hash) 926 const struct GNUNET_HashCode *hash)
856{ 927{
857 if ((!room) || (!hash)) 928 if ((! room) || (! hash))
858 return NULL; 929 return NULL;
859 930
860 return get_room_sender(room, hash); 931 return get_room_sender (room, hash);
861} 932}
862 933
934
863const char* 935const char*
864GNUNET_MESSENGER_contact_get_name (const struct GNUNET_MESSENGER_Contact *contact) 936GNUNET_MESSENGER_contact_get_name (const struct
937 GNUNET_MESSENGER_Contact *contact)
865{ 938{
866 if (!contact) 939 if (! contact)
867 return NULL; 940 return NULL;
868 941
869 return get_contact_name (contact); 942 return get_contact_name (contact);
870} 943}
871 944
945
872const struct GNUNET_IDENTITY_PublicKey* 946const struct GNUNET_IDENTITY_PublicKey*
873GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact) 947GNUNET_MESSENGER_contact_get_key (const struct
948 GNUNET_MESSENGER_Contact *contact)
874{ 949{
875 if (!contact) 950 if (! contact)
876 return NULL; 951 return NULL;
877 952
878 return get_non_anonymous_key (get_contact_key (contact)); 953 return get_non_anonymous_key (get_contact_key (contact));
879} 954}
880 955
956
881void 957void
882GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, 958GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room,
883 struct GNUNET_MESSENGER_Message *message, 959 struct GNUNET_MESSENGER_Message *message,
884 const struct GNUNET_MESSENGER_Contact *contact) 960 const struct GNUNET_MESSENGER_Contact *contact)
885{ 961{
886 if ((!room) || (!message)) 962 if ((! room) || (! message))
887 return; 963 return;
888 964
889 switch (filter_message_sending (message)) 965 switch (filter_message_sending (message))
890 { 966 {
891 case GNUNET_SYSERR: 967 case GNUNET_SYSERR:
892 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message aborted: This kind of message is reserved for the service!\n"); 968 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
969 "Sending message aborted: This kind of message is reserved for the service!\n");
893 return; 970 return;
894 case GNUNET_NO: 971 case GNUNET_NO:
895 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: This kind of message could cause issues!\n"); 972 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
973 "Sending message aborted: This kind of message could cause issues!\n");
896 return; 974 return;
897 default: 975 default:
898 break; 976 break;
899 } 977 }
900 978
901 char* original_name; 979 char *original_name;
902 char* changed_name = NULL; 980 char *changed_name = NULL;
903 981
904 if (GNUNET_MESSENGER_KIND_NAME != message->header.kind) 982 if (GNUNET_MESSENGER_KIND_NAME != message->header.kind)
905 goto skip_naming; 983 goto skip_naming;
906 984
907 original_name = message->body.name.name; 985 original_name = message->body.name.name;
908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Apply rule for using handle name in room: %s\n", GNUNET_h2s (&(room->key))); 986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
987 "Apply rule for using handle name in room: %s\n", GNUNET_h2s (
988 &(room->key)));
909 989
910 const char* handle_name = get_handle_name (room->handle); 990 const char *handle_name = get_handle_name (room->handle);
911 991
912 if ((handle_name) && (GNUNET_YES == room->use_handle_name) && 992 if ((handle_name) && (GNUNET_YES == room->use_handle_name) &&
913 ((!original_name) || (0 == strlen (original_name)))) 993 ((! original_name) || (0 == strlen (original_name))))
914 { 994 {
915 changed_name = GNUNET_strdup (handle_name); 995 changed_name = GNUNET_strdup (handle_name);
916 message->body.name.name = changed_name; 996 message->body.name.name = changed_name;
@@ -920,23 +1000,25 @@ skip_naming:
920 if (contact) 1000 if (contact)
921 { 1001 {
922 const struct GNUNET_IDENTITY_PublicKey *public_key = get_non_anonymous_key ( 1002 const struct GNUNET_IDENTITY_PublicKey *public_key = get_non_anonymous_key (
923 get_contact_key (contact) 1003 get_contact_key (contact)
924 ); 1004 );
925 1005
926 if (!public_key) 1006 if (! public_key)
927 { 1007 {
928 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: Invalid key!\n"); 1008 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1009 "Sending message aborted: Invalid key!\n");
929 goto reset_naming; 1010 goto reset_naming;
930 } 1011 }
931 1012
932 struct GNUNET_MESSENGER_Message *original = message; 1013 struct GNUNET_MESSENGER_Message *original = message;
933 message = copy_message(original); 1014 message = copy_message (original);
934 1015
935 if (GNUNET_YES != encrypt_message (message, public_key)) 1016 if (GNUNET_YES != encrypt_message (message, public_key))
936 { 1017 {
937 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message aborted: Encryption failed!\n"); 1018 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1019 "Sending message aborted: Encryption failed!\n");
938 1020
939 destroy_message(message); 1021 destroy_message (message);
940 message = original; 1022 message = original;
941 1023
942 goto reset_naming; 1024 goto reset_naming;
@@ -955,36 +1037,39 @@ reset_naming:
955 message->body.name.name = original_name; 1037 message->body.name.name = original_name;
956} 1038}
957 1039
1040
958const struct GNUNET_MESSENGER_Message* 1041const struct GNUNET_MESSENGER_Message*
959GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, 1042GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room,
960 const struct GNUNET_HashCode *hash) 1043 const struct GNUNET_HashCode *hash)
961{ 1044{
962 if ((!room) || (!hash)) 1045 if ((! room) || (! hash))
963 return NULL; 1046 return NULL;
964 1047
965 const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash); 1048 const struct GNUNET_MESSENGER_Message *message = get_room_message (room,
1049 hash);
966 1050
967 if (!message) 1051 if (! message)
968 { 1052 {
969 struct GNUNET_MESSENGER_GetMessage *msg; 1053 struct GNUNET_MESSENGER_GetMessage *msg;
970 struct GNUNET_MQ_Envelope *env; 1054 struct GNUNET_MQ_Envelope *env;
971 1055
972 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE); 1056 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE);
973 GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key)); 1057 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
974 GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash)); 1058 GNUNET_memcpy (&(msg->hash), hash, sizeof(*hash));
975 GNUNET_MQ_send (room->handle->mq, env); 1059 GNUNET_MQ_send (room->handle->mq, env);
976 } 1060 }
977 1061
978 return message; 1062 return message;
979} 1063}
980 1064
1065
981int 1066int
982GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, 1067GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room,
983 GNUNET_MESSENGER_MemberCallback callback, 1068 GNUNET_MESSENGER_MemberCallback callback,
984 void *cls) 1069 void *cls)
985{ 1070{
986 if (!room) 1071 if (! room)
987 return GNUNET_SYSERR; 1072 return GNUNET_SYSERR;
988 1073
989 return iterate_room_members(room, callback, cls); 1074 return iterate_room_members (room, callback, cls);
990} 1075}