-fix build system issues
[oweals/gnunet.git] / src / conversation / gnunet-conversation.c
index 5961046d18aa77702bc0e2e08ef1728accd62753..a042629cc86be1a29f176871376aa403eecbcd92 100644 (file)
@@ -249,7 +249,7 @@ phone_event_handler (void *cls,
   {
   case GNUNET_CONVERSATION_EC_PHONE_RING:
     FPRINTF (stdout,
-             _("Incoming call from `%s'.\nPlease /accept #%u or /cancel %u the call.\n"),
+             _("Incoming call from `%s'. Please /accept #%u or /cancel %u the call.\n"),
              caller_id,
              caller_num_gen,
              caller_num_gen);
@@ -332,6 +332,7 @@ start_phone ()
     phone_state = PS_LOOKUP_EGO;
     return;
   }
+  GNUNET_assert (NULL == phone);
   phone = GNUNET_CONVERSATION_phone_create (cfg,
                                             caller_id,
                                             &phone_event_handler, NULL);
@@ -351,10 +352,9 @@ start_phone ()
     address = GNUNET_GNSRECORD_value_to_string (rd.record_type,
                                                 rd.data,
                                                 rd.data_size);
-    if (verbose)
-      FPRINTF (stdout,
-               _("Phone active on line %u\n"),
-               (unsigned int) line);
+    FPRINTF (stdout,
+             _("Phone active on line %u.  Type `/help' for a list of available commands\n"),
+             (unsigned int) line);
     phone_state = PS_LISTEN;
   }
 }
@@ -374,10 +374,9 @@ call_event_handler (void *cls,
   {
   case GNUNET_CONVERSATION_EC_CALL_RINGING:
     GNUNET_break (CS_RESOLVING == call_state);
-    if (verbose)
-      FPRINTF (stdout,
-               "%s",
-               _("Resolved address. Now ringing other party.\n"));
+    FPRINTF (stdout,
+             _("Resolved address of `%s'. Now ringing other party.\n"),
+             peer_name);
     call_state = CS_RINGING;
     break;
   case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
@@ -412,6 +411,11 @@ call_event_handler (void *cls,
              _("Connection to `%s' resumed (by other user)\n"),
              peer_name);
     break;
+  case GNUNET_CONVERSATION_EC_CALL_ERROR:
+    FPRINTF (stdout,
+             _("Error with the call, restarting it\n"));
+    call_state = CS_RESOLVING;
+    break;
   }
 }
 
@@ -522,8 +526,16 @@ do_call (const char *arg)
     break;
   }
   GNUNET_free_non_null (peer_name);
+  if (NULL == arg)
+  {
+    FPRINTF (stderr,
+             _("Call recipient missing.\n"));
+    do_help ("/call");
+    return;
+  }
   peer_name = GNUNET_strdup (arg);
   call_state = CS_RESOLVING;
+  GNUNET_assert (NULL == call);
   call = GNUNET_CONVERSATION_call_start (cfg,
                                          caller_id,
                                          arg,
@@ -787,7 +799,7 @@ do_resume (const char *args)
   case PS_ERROR:
     FPRINTF (stderr,
              "%s",
-             _("There is no call that could be suspended right now.\n"));
+             _("There is no call that could be resumed right now.\n"));
     return;
   case PS_LISTEN:
     /* expected state, do resume logic */
@@ -840,6 +852,9 @@ do_resume (const char *args)
 static void
 do_reject (const char *args)
 {
+  struct CallList *cl;
+  char buf[32];
+
   if (NULL != call)
   {
     GNUNET_CONVERSATION_call_stop (call);
@@ -849,20 +864,53 @@ do_reject (const char *args)
   switch (phone_state)
   {
   case PS_LOOKUP_EGO:
-  case PS_LISTEN:
   case PS_ERROR:
     FPRINTF (stderr,
              "%s",
              _("There is no call that could be cancelled right now.\n"));
     return;
+  case PS_LISTEN:
+    /* look for active incoming calls to refuse */
+    cl = cl_head;
+    if (NULL == cl)
+    {
+      FPRINTF (stderr,
+               _("There is no incoming call to refuse here!\n"));
+      return;
+    }
+    if ( (NULL != cl->next) || (NULL != args) )
+    {
+      for (cl = cl_head; NULL != cl; cl = cl->next)
+      {
+        GNUNET_snprintf (buf, sizeof (buf),
+                         "%u",
+                         cl->caller_num);
+        if (0 == strcmp (buf, args))
+          break;
+      }
+    }
+    if (NULL == cl)
+    {
+      FPRINTF (stderr,
+               _("There is no incoming call `%s' to refuse right now!\n"),
+               args);
+      return;
+    }
+    GNUNET_CONVERSATION_caller_hang_up (cl->caller);
+    GNUNET_CONTAINER_DLL_remove (cl_head,
+                                 cl_tail,
+                                 cl);
+    GNUNET_free (cl->caller_id);
+    GNUNET_free (cl);
+    break;
   case PS_ACCEPTED:
     /* expected state, do rejection logic */
+    GNUNET_assert (NULL != cl_active);
+    GNUNET_CONVERSATION_caller_hang_up (cl_active->caller);
+    cl_active = NULL;
+    phone_state = PS_LISTEN;
     break;
   }
-  GNUNET_assert (NULL != cl_active);
-  GNUNET_CONVERSATION_caller_hang_up (cl_active->caller);
-  cl_active = NULL;
-  phone_state = PS_LISTEN;
 }
 
 
@@ -975,8 +1023,6 @@ do_stop_task (void *cls,
   mic = NULL;
   GNUNET_free (ego_name);
   ego_name = NULL;
-  GNUNET_CONFIGURATION_destroy (cfg);
-  cfg = NULL;
   GNUNET_free_non_null (peer_name);
   phone_state = PS_ERROR;
 }
@@ -1018,6 +1064,8 @@ handle_command (void *cls,
   ptr = &message[strlen (commands[i].command)];
   while (isspace ((int) *ptr))
     ptr++;
+  if ('\0' == *ptr)
+    ptr = NULL;
   commands[i].Action (ptr);
 }
 
@@ -1137,6 +1185,11 @@ main (int argc, char *const *argv)
                            gettext_noop ("Enables having a conversation with other GNUnet users."),
                            options, &run, NULL);
   GNUNET_free ((void *) argv);
+  if (NULL != cfg)
+  {
+    GNUNET_CONFIGURATION_destroy (cfg);
+    cfg = NULL;
+  }
   return (GNUNET_OK == ret) ? 0 : 1;
 }