diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-03-04 08:10:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-03-04 08:10:00 +0000 |
commit | fb199b4553100aa977d4d2f4a108bb0a27a705d2 (patch) | |
tree | 03f6fbb293c879d3015a599ce6da2419d55da92b /src/chat/chat.c | |
parent | e3445ef22cc8478bb6cdca2b35f20f7f3325c697 (diff) | |
download | gnunet-fb199b4553100aa977d4d2f4a108bb0a27a705d2.tar.gz gnunet-fb199b4553100aa977d4d2f4a108bb0a27a705d2.zip |
chat indent -- Mantis 1665
Diffstat (limited to 'src/chat/chat.c')
-rw-r--r-- | src/chat/chat.c | 398 |
1 files changed, 199 insertions, 199 deletions
diff --git a/src/chat/chat.c b/src/chat/chat.c index 5f4e121dc..3c8f9a862 100644 --- a/src/chat/chat.c +++ b/src/chat/chat.c | |||
@@ -162,8 +162,8 @@ rejoin_room (struct GNUNET_CHAT_Room *chat_room); | |||
162 | */ | 162 | */ |
163 | static size_t | 163 | static size_t |
164 | transmit_acknowledge_request (void *cls, | 164 | transmit_acknowledge_request (void *cls, |
165 | size_t size, | 165 | size_t size, |
166 | void *buf) | 166 | void *buf) |
167 | { | 167 | { |
168 | struct GNUNET_CHAT_SendReceiptContext *src = cls; | 168 | struct GNUNET_CHAT_SendReceiptContext *src = cls; |
169 | struct ConfirmationReceiptMessage *receipt; | 169 | struct ConfirmationReceiptMessage *receipt; |
@@ -174,12 +174,12 @@ transmit_acknowledge_request (void *cls, | |||
174 | if (NULL == buf) | 174 | if (NULL == buf) |
175 | { | 175 | { |
176 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 176 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
177 | _("Could not transmit confirmation receipt\n")); | 177 | _("Could not transmit confirmation receipt\n")); |
178 | return 0; | 178 | return 0; |
179 | } | 179 | } |
180 | #if DEBUG_CHAT | 180 | #if DEBUG_CHAT |
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
182 | "Transmitting confirmation receipt to the service\n"); | 182 | "Transmitting confirmation receipt to the service\n"); |
183 | #endif | 183 | #endif |
184 | msg_size = sizeof (struct ConfirmationReceiptMessage); | 184 | msg_size = sizeof (struct ConfirmationReceiptMessage); |
185 | GNUNET_assert (size >= msg_size); | 185 | GNUNET_assert (size >= msg_size); |
@@ -192,23 +192,23 @@ transmit_acknowledge_request (void *cls, | |||
192 | receipt->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 192 | receipt->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
193 | GNUNET_CRYPTO_rsa_key_get_public (src->chat_room->my_private_key, &pub_key); | 193 | GNUNET_CRYPTO_rsa_key_get_public (src->chat_room->my_private_key, &pub_key); |
194 | GNUNET_CRYPTO_hash (&pub_key, | 194 | GNUNET_CRYPTO_hash (&pub_key, |
195 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 195 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
196 | &receipt->target); | 196 | &receipt->target); |
197 | receipt->author = src->received_msg->sender; | 197 | receipt->author = src->received_msg->sender; |
198 | receipt->purpose.purpose = | 198 | receipt->purpose.purpose = |
199 | htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT); | 199 | htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT); |
200 | receipt->purpose.size = | 200 | receipt->purpose.size = |
201 | htonl (msg_size - | 201 | htonl (msg_size - |
202 | sizeof (struct GNUNET_MessageHeader) - | 202 | sizeof (struct GNUNET_MessageHeader) - |
203 | sizeof (uint32_t) - | 203 | sizeof (uint32_t) - |
204 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); | 204 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
205 | msg_len = ntohs (src->received_msg->header.size) - | 205 | msg_len = ntohs (src->received_msg->header.size) - |
206 | sizeof (struct ReceiveNotificationMessage); | 206 | sizeof (struct ReceiveNotificationMessage); |
207 | GNUNET_CRYPTO_hash (&src->received_msg[1], msg_len, &receipt->content); | 207 | GNUNET_CRYPTO_hash (&src->received_msg[1], msg_len, &receipt->content); |
208 | GNUNET_assert (GNUNET_OK == | 208 | GNUNET_assert (GNUNET_OK == |
209 | GNUNET_CRYPTO_rsa_sign (src->chat_room->my_private_key, | 209 | GNUNET_CRYPTO_rsa_sign (src->chat_room->my_private_key, |
210 | &receipt->purpose, | 210 | &receipt->purpose, |
211 | &receipt->signature)); | 211 | &receipt->signature)); |
212 | GNUNET_free (src->received_msg); | 212 | GNUNET_free (src->received_msg); |
213 | GNUNET_free (src); | 213 | GNUNET_free (src); |
214 | return msg_size; | 214 | return msg_size; |
@@ -221,7 +221,7 @@ transmit_acknowledge_request (void *cls, | |||
221 | */ | 221 | */ |
222 | static void | 222 | static void |
223 | process_result (struct GNUNET_CHAT_Room *room, | 223 | process_result (struct GNUNET_CHAT_Room *room, |
224 | const struct GNUNET_MessageHeader *reply) | 224 | const struct GNUNET_MessageHeader *reply) |
225 | { | 225 | { |
226 | struct LeaveNotificationMessage *leave_msg; | 226 | struct LeaveNotificationMessage *leave_msg; |
227 | struct JoinNotificationMessage *join_msg; | 227 | struct JoinNotificationMessage *join_msg; |
@@ -249,80 +249,80 @@ process_result (struct GNUNET_CHAT_Room *room, | |||
249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a join notification\n"); | 249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a join notification\n"); |
250 | #endif | 250 | #endif |
251 | if (size < sizeof (struct JoinNotificationMessage)) | 251 | if (size < sizeof (struct JoinNotificationMessage)) |
252 | { | 252 | { |
253 | GNUNET_break (0); | 253 | GNUNET_break (0); |
254 | return; | 254 | return; |
255 | } | 255 | } |
256 | join_msg = (struct JoinNotificationMessage *) reply; | 256 | join_msg = (struct JoinNotificationMessage *) reply; |
257 | meta_len = size - sizeof (struct JoinNotificationMessage); | 257 | meta_len = size - sizeof (struct JoinNotificationMessage); |
258 | meta = | 258 | meta = |
259 | GNUNET_CONTAINER_meta_data_deserialize ((const char *) &join_msg[1], | 259 | GNUNET_CONTAINER_meta_data_deserialize ((const char *) &join_msg[1], |
260 | meta_len); | 260 | meta_len); |
261 | if (NULL == meta) | 261 | if (NULL == meta) |
262 | { | 262 | { |
263 | GNUNET_break (0); | 263 | GNUNET_break (0); |
264 | return; | 264 | return; |
265 | } | 265 | } |
266 | pos = GNUNET_malloc (sizeof (struct MemberList)); | 266 | pos = GNUNET_malloc (sizeof (struct MemberList)); |
267 | pos->meta = meta; | 267 | pos->meta = meta; |
268 | GNUNET_CRYPTO_hash (&join_msg->public_key, | 268 | GNUNET_CRYPTO_hash (&join_msg->public_key, |
269 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 269 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
270 | &pos->id); | 270 | &pos->id); |
271 | GNUNET_PSEUDONYM_add (room->cfg, &pos->id, meta); | 271 | GNUNET_PSEUDONYM_add (room->cfg, &pos->id, meta); |
272 | pos->next = room->members; | 272 | pos->next = room->members; |
273 | room->members = pos; | 273 | room->members = pos; |
274 | if (GNUNET_NO == room->is_joined) | 274 | if (GNUNET_NO == room->is_joined) |
275 | { | 275 | { |
276 | GNUNET_CRYPTO_rsa_key_get_public (room->my_private_key, &pkey); | 276 | GNUNET_CRYPTO_rsa_key_get_public (room->my_private_key, &pkey); |
277 | if (0 == memcmp (&join_msg->public_key, | 277 | if (0 == memcmp (&join_msg->public_key, |
278 | &pkey, | 278 | &pkey, |
279 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) | 279 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) |
280 | { | 280 | { |
281 | room->join_callback (room->join_callback_cls); | 281 | room->join_callback (room->join_callback_cls); |
282 | room->is_joined = GNUNET_YES; | 282 | room->is_joined = GNUNET_YES; |
283 | } | 283 | } |
284 | else | 284 | else |
285 | { | 285 | { |
286 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 286 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
287 | _("The current user must be the the first one joined\n")); | 287 | _("The current user must be the the first one joined\n")); |
288 | GNUNET_break (0); | 288 | GNUNET_break (0); |
289 | return; | 289 | return; |
290 | } | 290 | } |
291 | } | 291 | } |
292 | else | 292 | else |
293 | room->member_list_callback (room->member_list_callback_cls, | 293 | room->member_list_callback (room->member_list_callback_cls, |
294 | meta, &join_msg->public_key, | 294 | meta, &join_msg->public_key, |
295 | ntohl (join_msg->msg_options)); | 295 | ntohl (join_msg->msg_options)); |
296 | break; | 296 | break; |
297 | case GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION: | 297 | case GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION: |
298 | #if DEBUG_CHAT | 298 | #if DEBUG_CHAT |
299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a leave notification\n"); | 299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a leave notification\n"); |
300 | #endif | 300 | #endif |
301 | if (size < sizeof (struct LeaveNotificationMessage)) | 301 | if (size < sizeof (struct LeaveNotificationMessage)) |
302 | { | 302 | { |
303 | GNUNET_break (0); | 303 | GNUNET_break (0); |
304 | return; | 304 | return; |
305 | } | 305 | } |
306 | leave_msg = (struct LeaveNotificationMessage *) reply; | 306 | leave_msg = (struct LeaveNotificationMessage *) reply; |
307 | room->member_list_callback (room->member_list_callback_cls, | 307 | room->member_list_callback (room->member_list_callback_cls, |
308 | NULL, &leave_msg->user, | 308 | NULL, &leave_msg->user, |
309 | GNUNET_CHAT_MSG_OPTION_NONE); | 309 | GNUNET_CHAT_MSG_OPTION_NONE); |
310 | GNUNET_CRYPTO_hash (&leave_msg->user, | 310 | GNUNET_CRYPTO_hash (&leave_msg->user, |
311 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 311 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
312 | &id); | 312 | &id); |
313 | prev = NULL; | 313 | prev = NULL; |
314 | pos = room->members; | 314 | pos = room->members; |
315 | while ((NULL != pos) && | 315 | while ((NULL != pos) && |
316 | (0 != memcmp (&pos->id, &id, sizeof (GNUNET_HashCode)))) | 316 | (0 != memcmp (&pos->id, &id, sizeof (GNUNET_HashCode)))) |
317 | { | 317 | { |
318 | prev = pos; | 318 | prev = pos; |
319 | pos = pos->next; | 319 | pos = pos->next; |
320 | } | 320 | } |
321 | GNUNET_assert (NULL != pos); | 321 | GNUNET_assert (NULL != pos); |
322 | if (NULL == prev) | 322 | if (NULL == prev) |
323 | room->members = pos->next; | 323 | room->members = pos->next; |
324 | else | 324 | else |
325 | prev->next = pos->next; | 325 | prev->next = pos->next; |
326 | GNUNET_CONTAINER_meta_data_destroy (pos->meta); | 326 | GNUNET_CONTAINER_meta_data_destroy (pos->meta); |
327 | GNUNET_free (pos); | 327 | GNUNET_free (pos); |
328 | break; | 328 | break; |
@@ -331,96 +331,96 @@ process_result (struct GNUNET_CHAT_Room *room, | |||
331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a message notification\n"); | 331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a message notification\n"); |
332 | #endif | 332 | #endif |
333 | if (size <= sizeof (struct ReceiveNotificationMessage)) | 333 | if (size <= sizeof (struct ReceiveNotificationMessage)) |
334 | { | 334 | { |
335 | GNUNET_break (0); | 335 | GNUNET_break (0); |
336 | return; | 336 | return; |
337 | } | 337 | } |
338 | received_msg = (struct ReceiveNotificationMessage *) reply; | 338 | received_msg = (struct ReceiveNotificationMessage *) reply; |
339 | if (0 != | 339 | if (0 != |
340 | (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ACKNOWLEDGED)) | 340 | (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ACKNOWLEDGED)) |
341 | { | 341 | { |
342 | src = GNUNET_malloc (sizeof (struct GNUNET_CHAT_SendReceiptContext)); | 342 | src = GNUNET_malloc (sizeof (struct GNUNET_CHAT_SendReceiptContext)); |
343 | src->chat_room = room; | 343 | src->chat_room = room; |
344 | src->received_msg = GNUNET_memdup (received_msg, size); | 344 | src->received_msg = GNUNET_memdup (received_msg, size); |
345 | GNUNET_CLIENT_notify_transmit_ready (room->client, | 345 | GNUNET_CLIENT_notify_transmit_ready (room->client, |
346 | sizeof (struct ConfirmationReceiptMessage), | 346 | sizeof (struct ConfirmationReceiptMessage), |
347 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 347 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
348 | GNUNET_YES, | 348 | GNUNET_YES, |
349 | &transmit_acknowledge_request, | 349 | &transmit_acknowledge_request, |
350 | src); | 350 | src); |
351 | } | 351 | } |
352 | msg_len = size - sizeof (struct ReceiveNotificationMessage); | 352 | msg_len = size - sizeof (struct ReceiveNotificationMessage); |
353 | if (0 != | 353 | if (0 != |
354 | (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_PRIVATE)) | 354 | (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_PRIVATE)) |
355 | { | 355 | { |
356 | if (-1 == GNUNET_CRYPTO_rsa_decrypt (room->my_private_key, | 356 | if (-1 == GNUNET_CRYPTO_rsa_decrypt (room->my_private_key, |
357 | &received_msg->encrypted_key, | 357 | &received_msg->encrypted_key, |
358 | &key, | 358 | &key, |
359 | sizeof (struct GNUNET_CRYPTO_AesSessionKey))) | 359 | sizeof (struct GNUNET_CRYPTO_AesSessionKey))) |
360 | { | 360 | { |
361 | GNUNET_break (0); | 361 | GNUNET_break (0); |
362 | return; | 362 | return; |
363 | } | 363 | } |
364 | msg_len = GNUNET_CRYPTO_aes_decrypt (&received_msg[1], | 364 | msg_len = GNUNET_CRYPTO_aes_decrypt (&received_msg[1], |
365 | msg_len, | 365 | msg_len, |
366 | &key, | 366 | &key, |
367 | (const struct GNUNET_CRYPTO_AesInitializationVector *) INITVALUE, | 367 | (const struct GNUNET_CRYPTO_AesInitializationVector *) INITVALUE, |
368 | decrypted_msg); | 368 | decrypted_msg); |
369 | message_content = decrypted_msg; | 369 | message_content = decrypted_msg; |
370 | } | 370 | } |
371 | else | 371 | else |
372 | { | 372 | { |
373 | message_content = GNUNET_malloc (msg_len + 1); | 373 | message_content = GNUNET_malloc (msg_len + 1); |
374 | memcpy (message_content, &received_msg[1], msg_len); | 374 | memcpy (message_content, &received_msg[1], msg_len); |
375 | } | 375 | } |
376 | message_content[msg_len] = '\0'; | 376 | message_content[msg_len] = '\0'; |
377 | if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)) | 377 | if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)) |
378 | { | 378 | { |
379 | sender = NULL; | 379 | sender = NULL; |
380 | meta = NULL; | 380 | meta = NULL; |
381 | } | 381 | } |
382 | else | 382 | else |
383 | { | 383 | { |
384 | pos = room->members; | 384 | pos = room->members; |
385 | while ((NULL != pos) && | 385 | while ((NULL != pos) && |
386 | (0 != memcmp (&pos->id, | 386 | (0 != memcmp (&pos->id, |
387 | &received_msg->sender, | 387 | &received_msg->sender, |
388 | sizeof (GNUNET_HashCode)))) | 388 | sizeof (GNUNET_HashCode)))) |
389 | pos = pos->next; | 389 | pos = pos->next; |
390 | GNUNET_assert (NULL != pos); | 390 | GNUNET_assert (NULL != pos); |
391 | sender = &received_msg->sender; | 391 | sender = &received_msg->sender; |
392 | meta = pos->meta; | 392 | meta = pos->meta; |
393 | } | 393 | } |
394 | room->message_callback (room->message_callback_cls, | 394 | room->message_callback (room->message_callback_cls, |
395 | room, | 395 | room, |
396 | sender, | 396 | sender, |
397 | meta, | 397 | meta, |
398 | message_content, | 398 | message_content, |
399 | GNUNET_TIME_absolute_ntoh (received_msg->timestamp), | 399 | GNUNET_TIME_absolute_ntoh (received_msg->timestamp), |
400 | ntohl (received_msg->msg_options)); | 400 | ntohl (received_msg->msg_options)); |
401 | if (message_content != decrypted_msg) | 401 | if (message_content != decrypted_msg) |
402 | GNUNET_free (message_content); | 402 | GNUNET_free (message_content); |
403 | break; | 403 | break; |
404 | case GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION: | 404 | case GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION: |
405 | #if DEBUG_CHAT | 405 | #if DEBUG_CHAT |
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a confirmation receipt\n"); | 406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a confirmation receipt\n"); |
407 | #endif | 407 | #endif |
408 | if (size < sizeof (struct ConfirmationReceiptMessage)) | 408 | if (size < sizeof (struct ConfirmationReceiptMessage)) |
409 | { | 409 | { |
410 | GNUNET_break (0); | 410 | GNUNET_break (0); |
411 | return; | 411 | return; |
412 | } | 412 | } |
413 | receipt = (struct ConfirmationReceiptMessage *) reply; | 413 | receipt = (struct ConfirmationReceiptMessage *) reply; |
414 | if (NULL != room->confirmation_callback) | 414 | if (NULL != room->confirmation_callback) |
415 | room->confirmation_callback (room->confirmation_cls, | 415 | room->confirmation_callback (room->confirmation_cls, |
416 | room, | 416 | room, |
417 | ntohl (receipt->sequence_number), | 417 | ntohl (receipt->sequence_number), |
418 | GNUNET_TIME_absolute_ntoh (receipt->timestamp), | 418 | GNUNET_TIME_absolute_ntoh (receipt->timestamp), |
419 | &receipt->target); | 419 | &receipt->target); |
420 | break; | 420 | break; |
421 | default: | 421 | default: |
422 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 422 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
423 | _("Unknown message type: '%u'\n"), ntohs (reply->type)); | 423 | _("Unknown message type: '%u'\n"), ntohs (reply->type)); |
424 | GNUNET_break_op (0); | 424 | GNUNET_break_op (0); |
425 | break; | 425 | break; |
426 | } | 426 | } |
@@ -436,7 +436,7 @@ process_result (struct GNUNET_CHAT_Room *room, | |||
436 | */ | 436 | */ |
437 | static void | 437 | static void |
438 | receive_results (void *cls, | 438 | receive_results (void *cls, |
439 | const struct GNUNET_MessageHeader *msg) | 439 | const struct GNUNET_MessageHeader *msg) |
440 | { | 440 | { |
441 | struct GNUNET_CHAT_Room *chat_room = cls; | 441 | struct GNUNET_CHAT_Room *chat_room = cls; |
442 | 442 | ||
@@ -456,9 +456,9 @@ receive_results (void *cls, | |||
456 | return; /* fatal error */ | 456 | return; /* fatal error */ |
457 | /* continue receiving */ | 457 | /* continue receiving */ |
458 | GNUNET_CLIENT_receive (chat_room->client, | 458 | GNUNET_CLIENT_receive (chat_room->client, |
459 | &receive_results, | 459 | &receive_results, |
460 | chat_room, | 460 | chat_room, |
461 | GNUNET_TIME_UNIT_FOREVER_REL); | 461 | GNUNET_TIME_UNIT_FOREVER_REL); |
462 | } | 462 | } |
463 | 463 | ||
464 | 464 | ||
@@ -469,7 +469,7 @@ receive_results (void *cls, | |||
469 | */ | 469 | */ |
470 | static struct GNUNET_CRYPTO_RsaPrivateKey * | 470 | static struct GNUNET_CRYPTO_RsaPrivateKey * |
471 | init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg, | 471 | init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg, |
472 | const char *nick_name) | 472 | const char *nick_name) |
473 | { | 473 | { |
474 | char *home; | 474 | char *home; |
475 | char *keyfile; | 475 | char *keyfile; |
@@ -480,29 +480,29 @@ init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
480 | #endif | 480 | #endif |
481 | if (GNUNET_OK != | 481 | if (GNUNET_OK != |
482 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 482 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
483 | "chat", | 483 | "chat", |
484 | "HOME", | 484 | "HOME", |
485 | &home)) | 485 | &home)) |
486 | { | 486 | { |
487 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 487 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
488 | _("Configuration option `%s' in section `%s' missing\n"), | 488 | _("Configuration option `%s' in section `%s' missing\n"), |
489 | "HOME", | 489 | "HOME", |
490 | "chat"); | 490 | "chat"); |
491 | return NULL; | 491 | return NULL; |
492 | } | 492 | } |
493 | GNUNET_DISK_directory_create (home); | 493 | GNUNET_DISK_directory_create (home); |
494 | if (GNUNET_OK != GNUNET_DISK_directory_test (home)) | 494 | if (GNUNET_OK != GNUNET_DISK_directory_test (home)) |
495 | { | 495 | { |
496 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 496 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
497 | _("Failed to access chat home directory `%s'\n"), | 497 | _("Failed to access chat home directory `%s'\n"), |
498 | home); | 498 | home); |
499 | GNUNET_free (home); | 499 | GNUNET_free (home); |
500 | return NULL; | 500 | return NULL; |
501 | } | 501 | } |
502 | /* read or create private key */ | 502 | /* read or create private key */ |
503 | keyfile = | 503 | keyfile = |
504 | GNUNET_malloc (strlen (home) + strlen (NICK_IDENTITY_PREFIX) + | 504 | GNUNET_malloc (strlen (home) + strlen (NICK_IDENTITY_PREFIX) + |
505 | strlen (nick_name) + 2); | 505 | strlen (nick_name) + 2); |
506 | strcpy (keyfile, home); | 506 | strcpy (keyfile, home); |
507 | GNUNET_free (home); | 507 | GNUNET_free (home); |
508 | if (keyfile[strlen (keyfile) - 1] != DIR_SEPARATOR) | 508 | if (keyfile[strlen (keyfile) - 1] != DIR_SEPARATOR) |
@@ -513,8 +513,8 @@ init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
513 | if (NULL == privKey) | 513 | if (NULL == privKey) |
514 | { | 514 | { |
515 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 515 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
516 | _("Failed to create/open key in file `%s'\n"), | 516 | _("Failed to create/open key in file `%s'\n"), |
517 | keyfile); | 517 | keyfile); |
518 | } | 518 | } |
519 | GNUNET_free (keyfile); | 519 | GNUNET_free (keyfile); |
520 | return privKey; | 520 | return privKey; |
@@ -531,8 +531,8 @@ init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
531 | */ | 531 | */ |
532 | static size_t | 532 | static size_t |
533 | transmit_join_request (void *cls, | 533 | transmit_join_request (void *cls, |
534 | size_t size, | 534 | size_t size, |
535 | void *buf) | 535 | void *buf) |
536 | { | 536 | { |
537 | struct GNUNET_CHAT_Room *chat_room = cls; | 537 | struct GNUNET_CHAT_Room *chat_room = cls; |
538 | struct JoinRequestMessage *join_msg; | 538 | struct JoinRequestMessage *join_msg; |
@@ -546,14 +546,14 @@ transmit_join_request (void *cls, | |||
546 | { | 546 | { |
547 | #if DEBUG_CHAT | 547 | #if DEBUG_CHAT |
548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
549 | "Could not transmit join request, retrying...\n"); | 549 | "Could not transmit join request, retrying...\n"); |
550 | #endif | 550 | #endif |
551 | rejoin_room (chat_room); | 551 | rejoin_room (chat_room); |
552 | return 0; | 552 | return 0; |
553 | } | 553 | } |
554 | #if DEBUG_CHAT | 554 | #if DEBUG_CHAT |
555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
556 | "Transmitting join request to the service\n"); | 556 | "Transmitting join request to the service\n"); |
557 | #endif | 557 | #endif |
558 | room_len = strlen (chat_room->room_name); | 558 | room_len = strlen (chat_room->room_name); |
559 | meta_len = GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info); | 559 | meta_len = GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info); |
@@ -571,18 +571,18 @@ transmit_join_request (void *cls, | |||
571 | meta = &room[room_len]; | 571 | meta = &room[room_len]; |
572 | if (GNUNET_SYSERR == | 572 | if (GNUNET_SYSERR == |
573 | GNUNET_CONTAINER_meta_data_serialize (chat_room->member_info, | 573 | GNUNET_CONTAINER_meta_data_serialize (chat_room->member_info, |
574 | &meta, | 574 | &meta, |
575 | meta_len, | 575 | meta_len, |
576 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) | 576 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) |
577 | { | 577 | { |
578 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 578 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
579 | _("Could not serialize metadata\n")); | 579 | _("Could not serialize metadata\n")); |
580 | return 0; | 580 | return 0; |
581 | } | 581 | } |
582 | GNUNET_CLIENT_receive (chat_room->client, | 582 | GNUNET_CLIENT_receive (chat_room->client, |
583 | &receive_results, | 583 | &receive_results, |
584 | chat_room, | 584 | chat_room, |
585 | GNUNET_TIME_UNIT_FOREVER_REL); | 585 | GNUNET_TIME_UNIT_FOREVER_REL); |
586 | return size_of_join; | 586 | return size_of_join; |
587 | } | 587 | } |
588 | 588 | ||
@@ -600,11 +600,11 @@ rejoin_room (struct GNUNET_CHAT_Room *chat_room) | |||
600 | strlen (chat_room->room_name); | 600 | strlen (chat_room->room_name); |
601 | if (NULL == | 601 | if (NULL == |
602 | GNUNET_CLIENT_notify_transmit_ready (chat_room->client, | 602 | GNUNET_CLIENT_notify_transmit_ready (chat_room->client, |
603 | size_of_join, | 603 | size_of_join, |
604 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 604 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
605 | GNUNET_YES, | 605 | GNUNET_YES, |
606 | &transmit_join_request, | 606 | &transmit_join_request, |
607 | chat_room)) | 607 | chat_room)) |
608 | return GNUNET_SYSERR; | 608 | return GNUNET_SYSERR; |
609 | return GNUNET_OK; | 609 | return GNUNET_OK; |
610 | } | 610 | } |
@@ -620,7 +620,7 @@ GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room) | |||
620 | 620 | ||
621 | #if DEBUG_CHAT | 621 | #if DEBUG_CHAT |
622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
623 | "Leaving the room '%s'\n", chat_room->room_name); | 623 | "Leaving the room '%s'\n", chat_room->room_name); |
624 | #endif | 624 | #endif |
625 | GNUNET_CLIENT_disconnect (chat_room->client, GNUNET_NO); | 625 | GNUNET_CLIENT_disconnect (chat_room->client, GNUNET_NO); |
626 | GNUNET_free (chat_room->room_name); | 626 | GNUNET_free (chat_room->room_name); |
@@ -660,19 +660,19 @@ GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room) | |||
660 | */ | 660 | */ |
661 | struct GNUNET_CHAT_Room * | 661 | struct GNUNET_CHAT_Room * |
662 | GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, | 662 | GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, |
663 | const char *nick_name, | 663 | const char *nick_name, |
664 | struct GNUNET_CONTAINER_MetaData *member_info, | 664 | struct GNUNET_CONTAINER_MetaData *member_info, |
665 | const char *room_name, | 665 | const char *room_name, |
666 | enum GNUNET_CHAT_MsgOptions msg_options, | 666 | enum GNUNET_CHAT_MsgOptions msg_options, |
667 | GNUNET_CHAT_JoinCallback joinCallback, | 667 | GNUNET_CHAT_JoinCallback joinCallback, |
668 | void *join_cls, | 668 | void *join_cls, |
669 | GNUNET_CHAT_MessageCallback messageCallback, | 669 | GNUNET_CHAT_MessageCallback messageCallback, |
670 | void *message_cls, | 670 | void *message_cls, |
671 | GNUNET_CHAT_MemberListCallback memberCallback, | 671 | GNUNET_CHAT_MemberListCallback memberCallback, |
672 | void *member_cls, | 672 | void *member_cls, |
673 | GNUNET_CHAT_MessageConfirmation confirmationCallback, | 673 | GNUNET_CHAT_MessageConfirmation confirmationCallback, |
674 | void *confirmation_cls, | 674 | void *confirmation_cls, |
675 | GNUNET_HashCode *me) | 675 | GNUNET_HashCode *me) |
676 | { | 676 | { |
677 | struct GNUNET_CHAT_Room *chat_room; | 677 | struct GNUNET_CHAT_Room *chat_room; |
678 | struct GNUNET_CRYPTO_RsaPrivateKey *priv_key; | 678 | struct GNUNET_CRYPTO_RsaPrivateKey *priv_key; |
@@ -687,32 +687,32 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
687 | return NULL; | 687 | return NULL; |
688 | GNUNET_CRYPTO_rsa_key_get_public (priv_key, &pub_key); | 688 | GNUNET_CRYPTO_rsa_key_get_public (priv_key, &pub_key); |
689 | GNUNET_CRYPTO_hash (&pub_key, | 689 | GNUNET_CRYPTO_hash (&pub_key, |
690 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 690 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
691 | me); | 691 | me); |
692 | GNUNET_PSEUDONYM_add (cfg, me, member_info); | 692 | GNUNET_PSEUDONYM_add (cfg, me, member_info); |
693 | client = GNUNET_CLIENT_connect ("chat", cfg); | 693 | client = GNUNET_CLIENT_connect ("chat", cfg); |
694 | if (NULL == client) | 694 | if (NULL == client) |
695 | { | 695 | { |
696 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 696 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
697 | _("Failed to connect to the chat service\n")); | 697 | _("Failed to connect to the chat service\n")); |
698 | return NULL; | 698 | return NULL; |
699 | } | 699 | } |
700 | if (NULL == joinCallback) | 700 | if (NULL == joinCallback) |
701 | { | 701 | { |
702 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 702 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
703 | _("Undefined mandatory parameter: joinCallback\n")); | 703 | _("Undefined mandatory parameter: joinCallback\n")); |
704 | return NULL; | 704 | return NULL; |
705 | } | 705 | } |
706 | if (NULL == messageCallback) | 706 | if (NULL == messageCallback) |
707 | { | 707 | { |
708 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 708 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
709 | _("Undefined mandatory parameter: messageCallback\n")); | 709 | _("Undefined mandatory parameter: messageCallback\n")); |
710 | return NULL; | 710 | return NULL; |
711 | } | 711 | } |
712 | if (NULL == memberCallback) | 712 | if (NULL == memberCallback) |
713 | { | 713 | { |
714 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 714 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
715 | _("Undefined mandatory parameter: memberCallback\n")); | 715 | _("Undefined mandatory parameter: memberCallback\n")); |
716 | return NULL; | 716 | return NULL; |
717 | } | 717 | } |
718 | chat_room = GNUNET_malloc (sizeof (struct GNUNET_CHAT_Room)); | 718 | chat_room = GNUNET_malloc (sizeof (struct GNUNET_CHAT_Room)); |
@@ -751,8 +751,8 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
751 | */ | 751 | */ |
752 | static size_t | 752 | static size_t |
753 | transmit_send_request (void *cls, | 753 | transmit_send_request (void *cls, |
754 | size_t size, | 754 | size_t size, |
755 | void *buf) | 755 | void *buf) |
756 | { | 756 | { |
757 | struct GNUNET_CHAT_SendMessageContext *smc = cls; | 757 | struct GNUNET_CHAT_SendMessageContext *smc = cls; |
758 | struct TransmitRequestMessage *msg_to_send; | 758 | struct TransmitRequestMessage *msg_to_send; |
@@ -762,13 +762,13 @@ transmit_send_request (void *cls, | |||
762 | { | 762 | { |
763 | #if DEBUG_CHAT | 763 | #if DEBUG_CHAT |
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
765 | "Could not transmit a chat message\n"); | 765 | "Could not transmit a chat message\n"); |
766 | #endif | 766 | #endif |
767 | return 0; | 767 | return 0; |
768 | } | 768 | } |
769 | #if DEBUG_CHAT | 769 | #if DEBUG_CHAT |
770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
771 | "Transmitting a chat message to the service\n"); | 771 | "Transmitting a chat message to the service\n"); |
772 | #endif | 772 | #endif |
773 | msg_size = strlen (smc->message) + sizeof (struct TransmitRequestMessage); | 773 | msg_size = strlen (smc->message) + sizeof (struct TransmitRequestMessage); |
774 | GNUNET_assert (size >= msg_size); | 774 | GNUNET_assert (size >= msg_size); |
@@ -784,8 +784,8 @@ transmit_send_request (void *cls, | |||
784 | memset (&msg_to_send->target, 0, sizeof (GNUNET_HashCode)); | 784 | memset (&msg_to_send->target, 0, sizeof (GNUNET_HashCode)); |
785 | else | 785 | else |
786 | GNUNET_CRYPTO_hash (smc->receiver, | 786 | GNUNET_CRYPTO_hash (smc->receiver, |
787 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 787 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
788 | &msg_to_send->target); | 788 | &msg_to_send->target); |
789 | memcpy (&msg_to_send[1], smc->message, strlen (smc->message)); | 789 | memcpy (&msg_to_send[1], smc->message, strlen (smc->message)); |
790 | /** | 790 | /** |
791 | * Client don't encode private messages since public keys of other members are | 791 | * Client don't encode private messages since public keys of other members are |
@@ -794,15 +794,15 @@ transmit_send_request (void *cls, | |||
794 | if (smc->options & GNUNET_CHAT_MSG_AUTHENTICATED) | 794 | if (smc->options & GNUNET_CHAT_MSG_AUTHENTICATED) |
795 | { | 795 | { |
796 | msg_to_send->purpose.purpose = | 796 | msg_to_send->purpose.purpose = |
797 | htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); | 797 | htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); |
798 | msg_to_send->purpose.size = | 798 | msg_to_send->purpose.size = |
799 | htonl (msg_size - | 799 | htonl (msg_size - |
800 | sizeof (struct GNUNET_MessageHeader) - | 800 | sizeof (struct GNUNET_MessageHeader) - |
801 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); | 801 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
802 | GNUNET_assert (GNUNET_OK == | 802 | GNUNET_assert (GNUNET_OK == |
803 | GNUNET_CRYPTO_rsa_sign (smc->chat_room->my_private_key, | 803 | GNUNET_CRYPTO_rsa_sign (smc->chat_room->my_private_key, |
804 | &msg_to_send->purpose, | 804 | &msg_to_send->purpose, |
805 | &msg_to_send->signature)); | 805 | &msg_to_send->signature)); |
806 | } | 806 | } |
807 | GNUNET_free (smc->message); | 807 | GNUNET_free (smc->message); |
808 | GNUNET_free (smc); | 808 | GNUNET_free (smc); |
@@ -821,10 +821,10 @@ transmit_send_request (void *cls, | |||
821 | */ | 821 | */ |
822 | void | 822 | void |
823 | GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, | 823 | GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, |
824 | const char *message, | 824 | const char *message, |
825 | enum GNUNET_CHAT_MsgOptions options, | 825 | enum GNUNET_CHAT_MsgOptions options, |
826 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *receiver, | 826 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *receiver, |
827 | uint32_t *sequence_number) | 827 | uint32_t *sequence_number) |
828 | { | 828 | { |
829 | size_t msg_size; | 829 | size_t msg_size; |
830 | struct GNUNET_CHAT_SendMessageContext *smc; | 830 | struct GNUNET_CHAT_SendMessageContext *smc; |
@@ -843,11 +843,11 @@ GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, | |||
843 | smc->sequence_number = room->sequence_number; | 843 | smc->sequence_number = room->sequence_number; |
844 | msg_size = strlen (message) + sizeof (struct TransmitRequestMessage); | 844 | msg_size = strlen (message) + sizeof (struct TransmitRequestMessage); |
845 | GNUNET_CLIENT_notify_transmit_ready (room->client, | 845 | GNUNET_CLIENT_notify_transmit_ready (room->client, |
846 | msg_size, | 846 | msg_size, |
847 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 847 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
848 | GNUNET_YES, | 848 | GNUNET_YES, |
849 | &transmit_send_request, | 849 | &transmit_send_request, |
850 | smc); | 850 | smc); |
851 | } | 851 | } |
852 | 852 | ||
853 | /* end of chat.c */ | 853 | /* end of chat.c */ |