aboutsummaryrefslogtreecommitdiff
path: root/src/conversation
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
committerng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
commit6e599264ad13e8fc105493d74d7c11d46f8739ed (patch)
tree169bef1ecbade5a659831fb169f3ae6943af127f /src/conversation
parent4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff)
downloadgnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz
gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip
first step to remove plibc
Diffstat (limited to 'src/conversation')
-rw-r--r--src/conversation/gnunet-conversation.c487
1 files changed, 213 insertions, 274 deletions
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c
index 6c3db2184..4c5407cd7 100644
--- a/src/conversation/gnunet-conversation.c
+++ b/src/conversation/gnunet-conversation.c
@@ -38,7 +38,7 @@
38 */ 38 */
39#define MAX_MESSAGE_LENGTH 1024 39#define MAX_MESSAGE_LENGTH 1024
40 40
41#define XSTRINGIFY(x) STRINGIFY(x) 41#define XSTRINGIFY(x) STRINGIFY (x)
42 42
43#define STRINGIFY(x) (#x) 43#define STRINGIFY(x) (#x)
44 44
@@ -134,11 +134,9 @@ struct CallList
134 * Unique number of the call. 134 * Unique number of the call.
135 */ 135 */
136 unsigned int caller_num; 136 unsigned int caller_num;
137
138}; 137};
139 138
140 139
141
142/** 140/**
143 * Phone handle 141 * Phone handle
144 */ 142 */
@@ -173,7 +171,7 @@ static char *line;
173/** 171/**
174 * Task which handles the commands 172 * Task which handles the commands
175 */ 173 */
176static struct GNUNET_SCHEDULER_Task * handle_cmd_task; 174static struct GNUNET_SCHEDULER_Task *handle_cmd_task;
177 175
178/** 176/**
179 * Our speaker. 177 * Our speaker.
@@ -273,33 +271,32 @@ phone_event_handler (void *cls,
273 * 271 *
274 * see https://gstreamer.freedesktop.org/documentation/application-development/highlevel/playback-components.html on how to play a wav using the gst framework being used here 272 * see https://gstreamer.freedesktop.org/documentation/application-development/highlevel/playback-components.html on how to play a wav using the gst framework being used here
275 */ 273 */
276 FPRINTF (stdout, 274 fprintf (
277 _("Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"), 275 stdout,
278 GNUNET_GNSRECORD_pkey_to_zkey (caller_id), 276 _ (
279 caller_num_gen, 277 "Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"),
280 caller_num_gen); 278 GNUNET_GNSRECORD_pkey_to_zkey (caller_id),
279 caller_num_gen,
280 caller_num_gen);
281 cl = GNUNET_new (struct CallList); 281 cl = GNUNET_new (struct CallList);
282 cl->caller = caller; 282 cl->caller = caller;
283 cl->caller_id = *caller_id; 283 cl->caller_id = *caller_id;
284 cl->caller_num = caller_num_gen++; 284 cl->caller_num = caller_num_gen++;
285 GNUNET_CONTAINER_DLL_insert (cl_head, 285 GNUNET_CONTAINER_DLL_insert (cl_head, cl_tail, cl);
286 cl_tail,
287 cl);
288 break; 286 break;
289 case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: 287 case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP:
290 for (cl = cl_head; NULL != cl; cl = cl->next) 288 for (cl = cl_head; NULL != cl; cl = cl->next)
291 if (caller == cl->caller) 289 if (caller == cl->caller)
292 break; 290 break;
293 if ( (NULL == cl) && 291 if ((NULL == cl) && (caller == cl_active->caller))
294 (caller == cl_active->caller) )
295 cl = cl_active; 292 cl = cl_active;
296 if (NULL == cl) 293 if (NULL == cl)
297 { 294 {
298 GNUNET_break (0); 295 GNUNET_break (0);
299 return; 296 return;
300 } 297 }
301 FPRINTF (stdout, 298 fprintf (stdout,
302 _("Call from `%s' terminated\n"), 299 _ ("Call from `%s' terminated\n"),
303 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); 300 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
304 if (cl == cl_active) 301 if (cl == cl_active)
305 { 302 {
@@ -308,9 +305,7 @@ phone_event_handler (void *cls,
308 } 305 }
309 else 306 else
310 { 307 {
311 GNUNET_CONTAINER_DLL_remove (cl_head, 308 GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl);
312 cl_tail,
313 cl);
314 } 309 }
315 GNUNET_free (cl); 310 GNUNET_free (cl);
316 break; 311 break;
@@ -325,21 +320,20 @@ phone_event_handler (void *cls,
325 * @param code type of the event issued by the caller 320 * @param code type of the event issued by the caller
326 */ 321 */
327static void 322static void
328caller_event_handler (void *cls, 323caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code)
329 enum GNUNET_CONVERSATION_CallerEventCode code)
330{ 324{
331 struct CallList *cl = cls; 325 struct CallList *cl = cls;
332 326
333 switch (code) 327 switch (code)
334 { 328 {
335 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: 329 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
336 FPRINTF (stdout, 330 fprintf (stdout,
337 _("Call from `%s' suspended by other user\n"), 331 _ ("Call from `%s' suspended by other user\n"),
338 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); 332 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
339 break; 333 break;
340 case GNUNET_CONVERSATION_EC_CALLER_RESUME: 334 case GNUNET_CONVERSATION_EC_CALLER_RESUME:
341 FPRINTF (stdout, 335 fprintf (stdout,
342 _("Call from `%s' resumed by other user\n"), 336 _ ("Call from `%s' resumed by other user\n"),
343 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); 337 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
344 break; 338 break;
345 } 339 }
@@ -356,8 +350,8 @@ start_phone ()
356 350
357 if (NULL == my_caller_id) 351 if (NULL == my_caller_id)
358 { 352 {
359 FPRINTF (stderr, 353 fprintf (stderr,
360 _("Ego `%s' no longer available, phone is now down.\n"), 354 _ ("Ego `%s' no longer available, phone is now down.\n"),
361 ego_name); 355 ego_name);
362 phone_state = PS_LOOKUP_EGO; 356 phone_state = PS_LOOKUP_EGO;
363 return; 357 return;
@@ -370,22 +364,20 @@ start_phone ()
370 /* FIXME: get record and print full GNS record info later here... */ 364 /* FIXME: get record and print full GNS record info later here... */
371 if (NULL == phone) 365 if (NULL == phone)
372 { 366 {
373 FPRINTF (stderr, 367 fprintf (stderr, "%s", _ ("Failed to setup phone (internal error)\n"));
374 "%s",
375 _("Failed to setup phone (internal error)\n"));
376 phone_state = PS_ERROR; 368 phone_state = PS_ERROR;
377 } 369 }
378 else 370 else
379 { 371 {
380 GNUNET_CONVERSATION_phone_get_record (phone, 372 GNUNET_CONVERSATION_phone_get_record (phone, &rd);
381 &rd);
382 GNUNET_free_non_null (address); 373 GNUNET_free_non_null (address);
383 address = GNUNET_GNSRECORD_value_to_string (rd.record_type, 374 address =
384 rd.data, 375 GNUNET_GNSRECORD_value_to_string (rd.record_type, rd.data, rd.data_size);
385 rd.data_size); 376 fprintf (
386 FPRINTF (stdout, 377 stdout,
387 _("Phone active at `%s'. Type `/help' for a list of available commands\n"), 378 _ (
388 address); 379 "Phone active at `%s'. Type `/help' for a list of available commands\n"),
380 address);
389 phone_state = PS_LISTEN; 381 phone_state = PS_LISTEN;
390 } 382 }
391} 383}
@@ -398,59 +390,51 @@ start_phone ()
398 * @param code type of the event on the call 390 * @param code type of the event on the call
399 */ 391 */
400static void 392static void
401call_event_handler (void *cls, 393call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
402 enum GNUNET_CONVERSATION_CallEventCode code)
403{ 394{
404 (void) cls; 395 (void) cls;
405 396
406 switch (code) 397 switch (code)
407 { 398 {
408 case GNUNET_CONVERSATION_EC_CALL_RINGING: 399 case GNUNET_CONVERSATION_EC_CALL_RINGING:
409 GNUNET_break (CS_RESOLVING == call_state); 400 GNUNET_break (CS_RESOLVING == call_state);
410 FPRINTF (stdout, 401 fprintf (stdout,
411 _("Resolved address of `%s'. Now ringing other party.\n"), 402 _ ("Resolved address of `%s'. Now ringing other party.\n"),
412 peer_name); 403 peer_name);
413 call_state = CS_RINGING; 404 call_state = CS_RINGING;
414 break; 405 break;
415 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: 406 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
416 GNUNET_break (CS_RINGING == call_state); 407 GNUNET_break (CS_RINGING == call_state);
417 FPRINTF (stdout, 408 fprintf (stdout, _ ("Connection established to `%s'\n"), peer_name);
418 _("Connection established to `%s'\n"),
419 peer_name);
420 call_state = CS_CONNECTED; 409 call_state = CS_CONNECTED;
421 break; 410 break;
422 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: 411 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
423 GNUNET_break (CS_RESOLVING == call_state); 412 GNUNET_break (CS_RESOLVING == call_state);
424 FPRINTF (stdout, 413 fprintf (stdout, _ ("Failed to resolve `%s'\n"), peer_name);
425 _("Failed to resolve `%s'\n"),
426 peer_name);
427 GNUNET_free (peer_name); 414 GNUNET_free (peer_name);
428 peer_name = NULL; 415 peer_name = NULL;
429 call = NULL; 416 call = NULL;
430 break; 417 break;
431 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: 418 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
432 FPRINTF (stdout, 419 fprintf (stdout, _ ("Call to `%s' terminated\n"), peer_name);
433 _("Call to `%s' terminated\n"),
434 peer_name);
435 GNUNET_free (peer_name); 420 GNUNET_free (peer_name);
436 peer_name = NULL; 421 peer_name = NULL;
437 call = NULL; 422 call = NULL;
438 break; 423 break;
439 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: 424 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
440 GNUNET_break (CS_CONNECTED == call_state); 425 GNUNET_break (CS_CONNECTED == call_state);
441 FPRINTF (stdout, 426 fprintf (stdout,
442 _("Connection to `%s' suspended (by other user)\n"), 427 _ ("Connection to `%s' suspended (by other user)\n"),
443 peer_name); 428 peer_name);
444 break; 429 break;
445 case GNUNET_CONVERSATION_EC_CALL_RESUMED: 430 case GNUNET_CONVERSATION_EC_CALL_RESUMED:
446 GNUNET_break (CS_CONNECTED == call_state); 431 GNUNET_break (CS_CONNECTED == call_state);
447 FPRINTF (stdout, 432 fprintf (stdout,
448 _("Connection to `%s' resumed (by other user)\n"), 433 _ ("Connection to `%s' resumed (by other user)\n"),
449 peer_name); 434 peer_name);
450 break; 435 break;
451 case GNUNET_CONVERSATION_EC_CALL_ERROR: 436 case GNUNET_CONVERSATION_EC_CALL_ERROR:
452 FPRINTF (stdout, 437 fprintf (stdout, _ ("Error with the call, restarting it\n"));
453 _("Error with the call, restarting it\n"));
454 GNUNET_free (peer_name); 438 GNUNET_free (peer_name);
455 peer_name = NULL; 439 peer_name = NULL;
456 call = NULL; 440 call = NULL;
@@ -464,8 +448,7 @@ call_event_handler (void *cls,
464 * 448 *
465 * @param arguments arguments given to the function 449 * @param arguments arguments given to the function
466 */ 450 */
467typedef void 451typedef void (*ActionFunction) (const char *arguments);
468(*ActionFunction) (const char *arguments);
469 452
470 453
471/** 454/**
@@ -520,9 +503,7 @@ do_quit (const char *args)
520static void 503static void
521do_unknown (const char *msg) 504do_unknown (const char *msg)
522{ 505{
523 FPRINTF (stderr, 506 fprintf (stderr, _ ("Unknown command `%s'\n"), msg);
524 _("Unknown command `%s'\n"),
525 msg);
526} 507}
527 508
528 509
@@ -536,31 +517,29 @@ do_call (const char *arg)
536{ 517{
537 if (NULL == my_caller_id) 518 if (NULL == my_caller_id)
538 { 519 {
539 FPRINTF (stderr, 520 fprintf (stderr, _ ("Ego `%s' not available\n"), ego_name);
540 _("Ego `%s' not available\n"),
541 ego_name);
542 return; 521 return;
543 } 522 }
544 if (NULL != call) 523 if (NULL != call)
545 { 524 {
546 FPRINTF (stderr, 525 fprintf (stderr,
547 _("You are calling someone else already, hang up first!\n")); 526 _ ("You are calling someone else already, hang up first!\n"));
548 return; 527 return;
549 } 528 }
550 switch (phone_state) 529 switch (phone_state)
551 { 530 {
552 case PS_LOOKUP_EGO: 531 case PS_LOOKUP_EGO:
553 FPRINTF (stderr, 532 fprintf (stderr, _ ("Ego `%s' not available\n"), ego_name);
554 _("Ego `%s' not available\n"),
555 ego_name);
556 return; 533 return;
557 case PS_LISTEN: 534 case PS_LISTEN:
558 /* ok to call! */ 535 /* ok to call! */
559 break; 536 break;
560 case PS_ACCEPTED: 537 case PS_ACCEPTED:
561 FPRINTF (stderr, 538 fprintf (
562 _("You are answering call from `%s', hang up or suspend that call first!\n"), 539 stderr,
563 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); 540 _ (
541 "You are answering call from `%s', hang up or suspend that call first!\n"),
542 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
564 return; 543 return;
565 case PS_ERROR: 544 case PS_ERROR:
566 /* ok to call */ 545 /* ok to call */
@@ -568,8 +547,7 @@ do_call (const char *arg)
568 } 547 }
569 if (NULL == arg) 548 if (NULL == arg)
570 { 549 {
571 FPRINTF (stderr, 550 fprintf (stderr, _ ("Call recipient missing.\n"));
572 _("Call recipient missing.\n"));
573 do_help ("/call"); 551 do_help ("/call");
574 return; 552 return;
575 } 553 }
@@ -581,7 +559,8 @@ do_call (const char *arg)
581 arg, 559 arg,
582 speaker, 560 speaker,
583 mic, 561 mic,
584 &call_event_handler, NULL); 562 &call_event_handler,
563 NULL);
585} 564}
586 565
587 566
@@ -596,11 +575,10 @@ do_accept (const char *args)
596 struct CallList *cl; 575 struct CallList *cl;
597 char buf[32]; 576 char buf[32];
598 577
599 if ( (NULL != call) && 578 if ((NULL != call) && (CS_SUSPENDED != call_state))
600 (CS_SUSPENDED != call_state) )
601 { 579 {
602 FPRINTF (stderr, 580 fprintf (stderr,
603 _("You are calling someone else already, hang up first!\n")); 581 _ ("You are calling someone else already, hang up first!\n"));
604 return; 582 return;
605 } 583 }
606 switch (phone_state) 584 switch (phone_state)
@@ -612,9 +590,11 @@ do_accept (const char *args)
612 /* this is the expected state */ 590 /* this is the expected state */
613 break; 591 break;
614 case PS_ACCEPTED: 592 case PS_ACCEPTED:
615 FPRINTF (stderr, 593 fprintf (
616 _("You are answering call from `%s', hang up or suspend that call first!\n"), 594 stderr,
617 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); 595 _ (
596 "You are answering call from `%s', hang up or suspend that call first!\n"),
597 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
618 return; 598 return;
619 case PS_ERROR: 599 case PS_ERROR:
620 GNUNET_break (0); 600 GNUNET_break (0);
@@ -623,31 +603,26 @@ do_accept (const char *args)
623 cl = cl_head; 603 cl = cl_head;
624 if (NULL == cl) 604 if (NULL == cl)
625 { 605 {
626 FPRINTF (stderr, 606 fprintf (stderr, _ ("There is no incoming call to accept here!\n"));
627 _("There is no incoming call to accept here!\n"));
628 return; 607 return;
629 } 608 }
630 if ( (NULL != cl->next) || (NULL != args) ) 609 if ((NULL != cl->next) || (NULL != args))
631 { 610 {
632 for (cl = cl_head; NULL != cl; cl = cl->next) 611 for (cl = cl_head; NULL != cl; cl = cl->next)
633 { 612 {
634 GNUNET_snprintf (buf, sizeof (buf), 613 GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num);
635 "%u",
636 cl->caller_num);
637 if (0 == strcmp (buf, args)) 614 if (0 == strcmp (buf, args))
638 break; 615 break;
639 } 616 }
640 } 617 }
641 if (NULL == cl) 618 if (NULL == cl)
642 { 619 {
643 FPRINTF (stderr, 620 fprintf (stderr,
644 _("There is no incoming call `%s' to accept right now!\n"), 621 _ ("There is no incoming call `%s' to accept right now!\n"),
645 args); 622 args);
646 return; 623 return;
647 } 624 }
648 GNUNET_CONTAINER_DLL_remove (cl_head, 625 GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl);
649 cl_tail,
650 cl);
651 cl_active = cl; 626 cl_active = cl;
652 peer_key = cl->caller_id; 627 peer_key = cl->caller_id;
653 phone_state = PS_ACCEPTED; 628 phone_state = PS_ACCEPTED;
@@ -670,14 +645,10 @@ do_address (const char *args)
670 (void) args; 645 (void) args;
671 if (NULL == address) 646 if (NULL == address)
672 { 647 {
673 FPRINTF (stdout, 648 fprintf (stdout, "%s", _ ("We currently do not have an address.\n"));
674 "%s",
675 _("We currently do not have an address.\n"));
676 return; 649 return;
677 } 650 }
678 FPRINTF (stdout, 651 fprintf (stdout, "%s\n", address);
679 "%s\n",
680 address);
681} 652}
682 653
683 654
@@ -695,24 +666,30 @@ do_status (const char *args)
695 switch (phone_state) 666 switch (phone_state)
696 { 667 {
697 case PS_LOOKUP_EGO: 668 case PS_LOOKUP_EGO:
698 FPRINTF (stdout, 669 fprintf (
699 _("We are currently trying to locate the private key for the ego `%s'.\n"), 670 stdout,
700 ego_name); 671 _ (
672 "We are currently trying to locate the private key for the ego `%s'.\n"),
673 ego_name);
701 break; 674 break;
702 case PS_LISTEN: 675 case PS_LISTEN:
703 FPRINTF (stdout, 676 fprintf (stdout,
704 _("We are listening for incoming calls for ego `%s' on line `%s'.\n"), 677 _ (
678 "We are listening for incoming calls for ego `%s' on line `%s'.\n"),
705 ego_name, 679 ego_name,
706 line); 680 line);
707 break; 681 break;
708 case PS_ACCEPTED: 682 case PS_ACCEPTED:
709 FPRINTF (stdout, 683 fprintf (stdout,
710 _("You are having a conversation with `%s'.\n"), 684 _ ("You are having a conversation with `%s'.\n"),
711 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));; 685 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
686 ;
712 break; 687 break;
713 case PS_ERROR: 688 case PS_ERROR:
714 FPRINTF (stdout, 689 fprintf (
715 _("We had an internal error setting up our phone line. You can still make calls.\n")); 690 stdout,
691 _ (
692 "We had an internal error setting up our phone line. You can still make calls.\n"));
716 break; 693 break;
717 } 694 }
718 if (NULL != call) 695 if (NULL != call)
@@ -720,18 +697,18 @@ do_status (const char *args)
720 switch (call_state) 697 switch (call_state)
721 { 698 {
722 case CS_RESOLVING: 699 case CS_RESOLVING:
723 FPRINTF (stdout, 700 fprintf (stdout,
724 _("We are trying to find the network address to call `%s'.\n"), 701 _ ("We are trying to find the network address to call `%s'.\n"),
725 peer_name); 702 peer_name);
726 break; 703 break;
727 case CS_RINGING: 704 case CS_RINGING:
728 FPRINTF (stdout, 705 fprintf (stdout,
729 _("We are calling `%s', their phone should be ringing.\n"), 706 _ ("We are calling `%s', their phone should be ringing.\n"),
730 peer_name); 707 peer_name);
731 break; 708 break;
732 case CS_CONNECTED: 709 case CS_CONNECTED:
733 FPRINTF (stdout, 710 fprintf (stdout,
734 _("You are having a conversation with `%s'.\n"), 711 _ ("You are having a conversation with `%s'.\n"),
735 peer_name); 712 peer_name);
736 break; 713 break;
737 case CS_SUSPENDED: 714 case CS_SUSPENDED:
@@ -739,25 +716,19 @@ do_status (const char *args)
739 break; 716 break;
740 } 717 }
741 } 718 }
742 if ( (NULL != cl_head) && 719 if ((NULL != cl_head) && ((cl_head != cl_active) || (cl_head != cl_tail)))
743 ( (cl_head != cl_active) ||
744 (cl_head != cl_tail) ) )
745 { 720 {
746 FPRINTF (stdout, 721 fprintf (stdout, "%s", _ ("Calls waiting:\n"));
747 "%s",
748 _("Calls waiting:\n"));
749 for (cl = cl_head; NULL != cl; cl = cl->next) 722 for (cl = cl_head; NULL != cl; cl = cl->next)
750 { 723 {
751 if (cl == cl_active) 724 if (cl == cl_active)
752 continue; 725 continue;
753 FPRINTF (stdout, 726 fprintf (stdout,
754 _("#%u: `%s'\n"), 727 _ ("#%u: `%s'\n"),
755 cl->caller_num, 728 cl->caller_num,
756 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); 729 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
757 } 730 }
758 FPRINTF (stdout, 731 fprintf (stdout, "%s", "\n");
759 "%s",
760 "\n");
761 } 732 }
762} 733}
763 734
@@ -778,9 +749,9 @@ do_suspend (const char *args)
778 case CS_RESOLVING: 749 case CS_RESOLVING:
779 case CS_RINGING: 750 case CS_RINGING:
780 case CS_SUSPENDED: 751 case CS_SUSPENDED:
781 FPRINTF (stderr, 752 fprintf (stderr,
782 "%s", 753 "%s",
783 _("There is no call that could be suspended right now.\n")); 754 _ ("There is no call that could be suspended right now.\n"));
784 return; 755 return;
785 case CS_CONNECTED: 756 case CS_CONNECTED:
786 call_state = CS_SUSPENDED; 757 call_state = CS_SUSPENDED;
@@ -793,9 +764,9 @@ do_suspend (const char *args)
793 case PS_LOOKUP_EGO: 764 case PS_LOOKUP_EGO:
794 case PS_LISTEN: 765 case PS_LISTEN:
795 case PS_ERROR: 766 case PS_ERROR:
796 FPRINTF (stderr, 767 fprintf (stderr,
797 "%s", 768 "%s",
798 _("There is no call that could be suspended right now.\n")); 769 _ ("There is no call that could be suspended right now.\n"));
799 return; 770 return;
800 case PS_ACCEPTED: 771 case PS_ACCEPTED:
801 /* expected state, do rejection logic */ 772 /* expected state, do rejection logic */
@@ -826,15 +797,13 @@ do_resume (const char *args)
826 case CS_RESOLVING: 797 case CS_RESOLVING:
827 case CS_RINGING: 798 case CS_RINGING:
828 case CS_CONNECTED: 799 case CS_CONNECTED:
829 FPRINTF (stderr, 800 fprintf (stderr,
830 "%s", 801 "%s",
831 _("There is no call that could be resumed right now.\n")); 802 _ ("There is no call that could be resumed right now.\n"));
832 return; 803 return;
833 case CS_SUSPENDED: 804 case CS_SUSPENDED:
834 call_state = CS_CONNECTED; 805 call_state = CS_CONNECTED;
835 GNUNET_CONVERSATION_call_resume (call, 806 GNUNET_CONVERSATION_call_resume (call, speaker, mic);
836 speaker,
837 mic);
838 return; 807 return;
839 } 808 }
840 } 809 }
@@ -842,16 +811,16 @@ do_resume (const char *args)
842 { 811 {
843 case PS_LOOKUP_EGO: 812 case PS_LOOKUP_EGO:
844 case PS_ERROR: 813 case PS_ERROR:
845 FPRINTF (stderr, 814 fprintf (stderr,
846 "%s", 815 "%s",
847 _("There is no call that could be resumed right now.\n")); 816 _ ("There is no call that could be resumed right now.\n"));
848 return; 817 return;
849 case PS_LISTEN: 818 case PS_LISTEN:
850 /* expected state, do resume logic */ 819 /* expected state, do resume logic */
851 break; 820 break;
852 case PS_ACCEPTED: 821 case PS_ACCEPTED:
853 FPRINTF (stderr, 822 fprintf (stderr,
854 _("Already talking with `%s', cannot resume a call right now.\n"), 823 _ ("Already talking with `%s', cannot resume a call right now.\n"),
855 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); 824 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
856 return; 825 return;
857 } 826 }
@@ -859,32 +828,27 @@ do_resume (const char *args)
859 cl = cl_head; 828 cl = cl_head;
860 if (NULL == cl) 829 if (NULL == cl)
861 { 830 {
862 FPRINTF (stderr, 831 fprintf (stderr, _ ("There is no incoming call to resume here!\n"));
863 _("There is no incoming call to resume here!\n"));
864 return; 832 return;
865 } 833 }
866 if ( (NULL != cl->next) || (NULL != args) ) 834 if ((NULL != cl->next) || (NULL != args))
867 { 835 {
868 for (cl = cl_head; NULL != cl; cl = cl->next) 836 for (cl = cl_head; NULL != cl; cl = cl->next)
869 { 837 {
870 GNUNET_snprintf (buf, sizeof (buf), 838 GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num);
871 "%u",
872 cl->caller_num);
873 if (0 == strcmp (buf, args)) 839 if (0 == strcmp (buf, args))
874 break; 840 break;
875 } 841 }
876 } 842 }
877 if (NULL == cl) 843 if (NULL == cl)
878 { 844 {
879 FPRINTF (stderr, 845 fprintf (stderr,
880 _("There is no incoming call `%s' to resume right now!\n"), 846 _ ("There is no incoming call `%s' to resume right now!\n"),
881 args); 847 args);
882 return; 848 return;
883 } 849 }
884 cl_active = cl; 850 cl_active = cl;
885 GNUNET_CONVERSATION_caller_resume (cl_active->caller, 851 GNUNET_CONVERSATION_caller_resume (cl_active->caller, speaker, mic);
886 speaker,
887 mic);
888 phone_state = PS_ACCEPTED; 852 phone_state = PS_ACCEPTED;
889} 853}
890 854
@@ -910,41 +874,36 @@ do_reject (const char *args)
910 { 874 {
911 case PS_LOOKUP_EGO: 875 case PS_LOOKUP_EGO:
912 case PS_ERROR: 876 case PS_ERROR:
913 FPRINTF (stderr, 877 fprintf (stderr,
914 "%s", 878 "%s",
915 _("There is no call that could be cancelled right now.\n")); 879 _ ("There is no call that could be cancelled right now.\n"));
916 return; 880 return;
917 case PS_LISTEN: 881 case PS_LISTEN:
918 /* look for active incoming calls to refuse */ 882 /* look for active incoming calls to refuse */
919 cl = cl_head; 883 cl = cl_head;
920 if (NULL == cl) 884 if (NULL == cl)
921 { 885 {
922 FPRINTF (stderr, 886 fprintf (stderr, _ ("There is no incoming call to refuse here!\n"));
923 _("There is no incoming call to refuse here!\n"));
924 return; 887 return;
925 } 888 }
926 if ( (NULL != cl->next) || (NULL != args) ) 889 if ((NULL != cl->next) || (NULL != args))
927 { 890 {
928 for (cl = cl_head; NULL != cl; cl = cl->next) 891 for (cl = cl_head; NULL != cl; cl = cl->next)
929 { 892 {
930 GNUNET_snprintf (buf, sizeof (buf), 893 GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num);
931 "%u",
932 cl->caller_num);
933 if (0 == strcmp (buf, args)) 894 if (0 == strcmp (buf, args))
934 break; 895 break;
935 } 896 }
936 } 897 }
937 if (NULL == cl) 898 if (NULL == cl)
938 { 899 {
939 FPRINTF (stderr, 900 fprintf (stderr,
940 _("There is no incoming call `%s' to refuse right now!\n"), 901 _ ("There is no incoming call `%s' to refuse right now!\n"),
941 args); 902 args);
942 return; 903 return;
943 } 904 }
944 GNUNET_CONVERSATION_caller_hang_up (cl->caller); 905 GNUNET_CONVERSATION_caller_hang_up (cl->caller);
945 GNUNET_CONTAINER_DLL_remove (cl_head, 906 GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl);
946 cl_tail,
947 cl);
948 GNUNET_free (cl); 907 GNUNET_free (cl);
949 break; 908 break;
950 case PS_ACCEPTED: 909 case PS_ACCEPTED:
@@ -962,26 +921,34 @@ do_reject (const char *args)
962 * List of supported commands. 921 * List of supported commands.
963 */ 922 */
964static struct VoipCommand commands[] = { 923static struct VoipCommand commands[] = {
965 {"/address", &do_address, 924 {"/address",
966 gettext_noop ("Use `/address' to find out which address this phone should have in GNS")}, 925 &do_address,
967 {"/call", &do_call, 926 gettext_noop (
968 gettext_noop ("Use `/call USER.gnu' to call USER")}, 927 "Use `/address' to find out which address this phone should have in GNS")},
969 {"/accept", &do_accept, 928 {"/call", &do_call, gettext_noop ("Use `/call USER.gnu' to call USER")},
929 {"/accept",
930 &do_accept,
970 gettext_noop ("Use `/accept #NUM' to accept incoming call #NUM")}, 931 gettext_noop ("Use `/accept #NUM' to accept incoming call #NUM")},
971 {"/suspend", &do_suspend, 932 {"/suspend",
933 &do_suspend,
972 gettext_noop ("Use `/suspend' to suspend the active call")}, 934 gettext_noop ("Use `/suspend' to suspend the active call")},
973 {"/resume", &do_resume, 935 {"/resume",
974 gettext_noop ("Use `/resume [#NUM]' to resume a call, #NUM is needed to resume incoming calls, no argument is needed to resume the current outgoing call.")}, 936 &do_resume,
975 {"/cancel", &do_reject, 937 gettext_noop (
938 "Use `/resume [#NUM]' to resume a call, #NUM is needed to resume incoming calls, no argument is needed to resume the current outgoing call.")},
939 {"/cancel",
940 &do_reject,
976 gettext_noop ("Use `/cancel' to reject or terminate a call")}, 941 gettext_noop ("Use `/cancel' to reject or terminate a call")},
977 {"/status", &do_status, 942 {"/status",
943 &do_status,
978 gettext_noop ("Use `/status' to print status information")}, 944 gettext_noop ("Use `/status' to print status information")},
979 {"/quit", &do_quit, 945 {"/quit",
946 &do_quit,
980 gettext_noop ("Use `/quit' to terminate gnunet-conversation")}, 947 gettext_noop ("Use `/quit' to terminate gnunet-conversation")},
981 {"/help", &do_help, 948 {"/help",
949 &do_help,
982 gettext_noop ("Use `/help command' to get help for a specific command")}, 950 gettext_noop ("Use `/help command' to get help for a specific command")},
983 {"", &do_unknown, 951 {"", &do_unknown, NULL},
984 NULL},
985 {NULL, NULL, NULL}, 952 {NULL, NULL, NULL},
986}; 953};
987 954
@@ -997,37 +964,25 @@ do_help (const char *args)
997 unsigned int i; 964 unsigned int i;
998 965
999 i = 0; 966 i = 0;
1000 while ( (NULL != args) && 967 while ((NULL != args) && (0 != strlen (args)) &&
1001 (0 != strlen (args)) && 968 (commands[i].Action != &do_help))
1002 (commands[i].Action != &do_help))
1003 { 969 {
1004 if (0 == 970 if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
1005 strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
1006 { 971 {
1007 FPRINTF (stdout, 972 fprintf (stdout, "%s\n", gettext (commands[i].helptext));
1008 "%s\n",
1009 gettext (commands[i].helptext));
1010 return; 973 return;
1011 } 974 }
1012 i++; 975 i++;
1013 } 976 }
1014 i = 0; 977 i = 0;
1015 FPRINTF (stdout, 978 fprintf (stdout, "%s", "Available commands:\n");
1016 "%s",
1017 "Available commands:\n");
1018 while (commands[i].Action != &do_help) 979 while (commands[i].Action != &do_help)
1019 { 980 {
1020 FPRINTF (stdout, 981 fprintf (stdout, "%s\n", gettext (commands[i].command));
1021 "%s\n",
1022 gettext (commands[i].command));
1023 i++; 982 i++;
1024 } 983 }
1025 FPRINTF (stdout, 984 fprintf (stdout, "%s", "\n");
1026 "%s", 985 fprintf (stdout, "%s\n", gettext (commands[i].helptext));
1027 "\n");
1028 FPRINTF (stdout,
1029 "%s\n",
1030 gettext (commands[i].helptext));
1031} 986}
1032 987
1033 988
@@ -1086,8 +1041,7 @@ do_stop_task (void *cls)
1086 * @param str_len number of bytes to process in @a message 1041 * @param str_len number of bytes to process in @a message
1087 */ 1042 */
1088static void 1043static void
1089handle_command_string (char *message, 1044handle_command_string (char *message, size_t str_len)
1090 size_t str_len)
1091{ 1045{
1092 size_t i; 1046 size_t i;
1093 const char *ptr; 1047 const char *ptr;
@@ -1101,9 +1055,10 @@ handle_command_string (char *message,
1101 if (0 == strlen (message)) 1055 if (0 == strlen (message))
1102 return; 1056 return;
1103 i = 0; 1057 i = 0;
1104 while ((NULL != commands[i].command) && 1058 while (
1105 (0 != strncasecmp (commands[i].command, message, 1059 (NULL != commands[i].command) &&
1106 strlen (commands[i].command)))) 1060 (0 !=
1061 strncasecmp (commands[i].command, message, strlen (commands[i].command))))
1107 i++; 1062 i++;
1108 ptr = &message[strlen (commands[i].command)]; 1063 ptr = &message[strlen (commands[i].command)];
1109 while (isspace ((unsigned char) *ptr)) 1064 while (isspace ((unsigned char) *ptr))
@@ -1159,17 +1114,13 @@ handle_command (void *cls)
1159 handle_cmd_task = 1114 handle_cmd_task =
1160 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 1115 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1161 stdin_fh, 1116 stdin_fh,
1162 &handle_command, NULL); 1117 &handle_command,
1118 NULL);
1163 /* read message from command line and handle it */ 1119 /* read message from command line and handle it */
1164 memset (message, 1120 memset (message, 0, MAX_MESSAGE_LENGTH + 1);
1165 0, 1121 if (NULL == fgets (message, MAX_MESSAGE_LENGTH, stdin))
1166 MAX_MESSAGE_LENGTH + 1);
1167 if (NULL == fgets (message,
1168 MAX_MESSAGE_LENGTH,
1169 stdin))
1170 return; 1122 return;
1171 handle_command_string (message, 1123 handle_command_string (message, strlen (message));
1172 strlen (message));
1173} 1124}
1174 1125
1175 1126
@@ -1194,30 +1145,22 @@ identity_cb (void *cls,
1194 if (ego == my_caller_id) 1145 if (ego == my_caller_id)
1195 { 1146 {
1196 if (verbose) 1147 if (verbose)
1197 FPRINTF (stdout, 1148 fprintf (stdout, _ ("Name of our ego changed to `%s'\n"), name);
1198 _("Name of our ego changed to `%s'\n"),
1199 name);
1200 GNUNET_free (ego_name); 1149 GNUNET_free (ego_name);
1201 ego_name = GNUNET_strdup (name); 1150 ego_name = GNUNET_strdup (name);
1202 return; 1151 return;
1203 } 1152 }
1204 if (0 != strcmp (name, 1153 if (0 != strcmp (name, ego_name))
1205 ego_name))
1206 return; 1154 return;
1207 if (NULL == ego) 1155 if (NULL == ego)
1208 { 1156 {
1209 if (verbose) 1157 if (verbose)
1210 FPRINTF (stdout, 1158 fprintf (stdout, _ ("Our ego `%s' was deleted!\n"), ego_name);
1211 _("Our ego `%s' was deleted!\n"),
1212 ego_name);
1213 my_caller_id = NULL; 1159 my_caller_id = NULL;
1214 return; 1160 return;
1215 } 1161 }
1216 my_caller_id = ego; 1162 my_caller_id = ego;
1217 GNUNET_CONFIGURATION_set_value_string (cfg, 1163 GNUNET_CONFIGURATION_set_value_string (cfg, "CONVERSATION", "LINE", line);
1218 "CONVERSATION",
1219 "LINE",
1220 line);
1221 start_phone (); 1164 start_phone ();
1222} 1165}
1223 1166
@@ -1244,43 +1187,39 @@ run (void *cls,
1244 mic = GNUNET_MICROPHONE_create_from_hardware (cfg); 1187 mic = GNUNET_MICROPHONE_create_from_hardware (cfg);
1245 if (NULL == ego_name) 1188 if (NULL == ego_name)
1246 { 1189 {
1247 FPRINTF (stderr, 1190 fprintf (stderr, "%s", _ ("You must specify the NAME of an ego to use\n"));
1248 "%s",
1249 _("You must specify the NAME of an ego to use\n"));
1250 return; 1191 return;
1251 } 1192 }
1252 id = GNUNET_IDENTITY_connect (cfg, 1193 id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
1253 &identity_cb,
1254 NULL);
1255#ifdef WINDOWS 1194#ifdef WINDOWS
1256 if (stdin_fh == NULL) 1195 if (stdin_fh == NULL)
1257 { 1196 {
1258 static char cpid[64]; 1197 static char cpid[64];
1259 static char *args[] = {"gnunet-helper-w32-console.exe", "chars", 1198 static char *args[] = {"gnunet-helper-w32-console.exe",
1260 XSTRINGIFY (MAX_MESSAGE_LENGTH), cpid, NULL}; 1199 "chars",
1200 XSTRINGIFY (MAX_MESSAGE_LENGTH),
1201 cpid,
1202 NULL};
1261 snprintf (cpid, 64, "%d", GetCurrentProcessId ()); 1203 snprintf (cpid, 64, "%d", GetCurrentProcessId ());
1262 stdin_hlp = GNUNET_HELPER_start ( 1204 stdin_hlp = GNUNET_HELPER_start (GNUNET_NO,
1263 GNUNET_NO, 1205 "gnunet-helper-w32-console",
1264 "gnunet-helper-w32-console", 1206 args,
1265 args, 1207 console_reader_chars,
1266 console_reader_chars, 1208 NULL,
1267 NULL, 1209 NULL);
1268 NULL);
1269 if (NULL == stdin_hlp) 1210 if (NULL == stdin_hlp)
1270 { 1211 {
1271 FPRINTF (stderr, 1212 fprintf (stderr, "%s", _ ("Failed to start gnunet-helper-w32-console\n"));
1272 "%s",
1273 _("Failed to start gnunet-helper-w32-console\n"));
1274 return; 1213 return;
1275 } 1214 }
1276 } 1215 }
1277 else 1216 else
1278#endif 1217#endif
1279 handle_cmd_task = 1218 handle_cmd_task =
1280 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, 1219 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
1281 &handle_command, NULL); 1220 &handle_command,
1282 GNUNET_SCHEDULER_add_shutdown (&do_stop_task, 1221 NULL);
1283 NULL); 1222 GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL);
1284} 1223}
1285 1224
1286 1225
@@ -1292,30 +1231,29 @@ run (void *cls,
1292 * @return 0 ok, 1 on error 1231 * @return 0 ok, 1 on error
1293 */ 1232 */
1294int 1233int
1295main (int argc, 1234main (int argc, char *const *argv)
1296 char *const *argv)
1297{ 1235{
1298 struct GNUNET_GETOPT_CommandLineOption options[] = { 1236 struct GNUNET_GETOPT_CommandLineOption options[] =
1299 GNUNET_GETOPT_option_string ('e', 1237 {GNUNET_GETOPT_option_string (
1300 "ego", 1238 'e',
1301 "NAME", 1239 "ego",
1302 gettext_noop ("sets the NAME of the ego to use for the caller ID"), 1240 "NAME",
1303 &ego_name), 1241 gettext_noop ("sets the NAME of the ego to use for the caller ID"),
1304 GNUNET_GETOPT_option_string ('p', 1242 &ego_name),
1305 "phone", 1243 GNUNET_GETOPT_option_string ('p',
1306 "LINE", 1244 "phone",
1307 gettext_noop ("sets the LINE to use for the phone"), 1245 "LINE",
1308 &line), 1246 gettext_noop (
1309 GNUNET_GETOPT_OPTION_END 1247 "sets the LINE to use for the phone"),
1310 }; 1248 &line),
1249 GNUNET_GETOPT_OPTION_END};
1311 int ret; 1250 int ret;
1312#ifndef WINDOWS 1251#ifndef WINDOWS
1313 int flags; 1252 int flags;
1314 flags = fcntl (0, F_GETFL, 0); 1253 flags = fcntl (0, F_GETFL, 0);
1315 flags |= O_NONBLOCK; 1254 flags |= O_NONBLOCK;
1316 if (0 != fcntl (0, F_SETFL, flags)) 1255 if (0 != fcntl (0, F_SETFL, flags))
1317 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 1256 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
1318 "fcntl");
1319 stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0); 1257 stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0);
1320#else 1258#else
1321 if (FILE_TYPE_CHAR == GetFileType ((HANDLE) _get_osfhandle (0))) 1259 if (FILE_TYPE_CHAR == GetFileType ((HANDLE) _get_osfhandle (0)))
@@ -1326,16 +1264,17 @@ main (int argc,
1326 stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0); 1264 stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0);
1327#endif 1265#endif
1328 1266
1329 if (GNUNET_OK != 1267 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1330 GNUNET_STRINGS_get_utf8_args (argc, argv,
1331 &argc, &argv))
1332 return 2; 1268 return 2;
1333 ret = GNUNET_PROGRAM_run (argc, 1269 ret =
1334 argv, 1270 GNUNET_PROGRAM_run (argc,
1335 "gnunet-conversation", 1271 argv,
1336 gettext_noop ("Enables having a conversation with other GNUnet users."), 1272 "gnunet-conversation",
1337 options, 1273 gettext_noop (
1338 &run, NULL); 1274 "Enables having a conversation with other GNUnet users."),
1275 options,
1276 &run,
1277 NULL);
1339 GNUNET_free ((void *) argv); 1278 GNUNET_free ((void *) argv);
1340 if (NULL != cfg) 1279 if (NULL != cfg)
1341 { 1280 {