GNUnet  0.10.x
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
gnunet-conversation.c File Reference

conversation implementation More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_conversation_service.h"
#include "gnunet_namestore_service.h"
Include dependency graph for gnunet-conversation.c:

Go to the source code of this file.

Data Structures

struct  CallList
 List of incoming calls. More...
 
struct  VoipCommand
 Structure which defines a command. More...
 

Macros

#define MAX_MESSAGE_LENGTH   1024
 Maximum length allowed for the command line input. More...
 
#define XSTRINGIFY(x)   STRINGIFY(x)
 
#define STRINGIFY(x)   (#x)
 

Typedefs

typedef void(* ActionFunction) (const char *arguments)
 Function declareation for executing a action. More...
 

Enumerations

enum  PhoneState {
  PS_REGISTER = 0, PS_READY, PS_LOOKUP_EGO, PS_LISTEN,
  PS_ACCEPTED, PS_ERROR
}
 Possible states of the phone. More...
 
enum  CallState {
  CS_LOOKUP = 0, CS_RINGING, CS_ACTIVE, CS_SHUTDOWN,
  CS_SUSPENDED_CALLER, CS_SUSPENDED_CALLEE, CS_SUSPENDED_BOTH, CS_RESOLVING,
  CS_RINGING, CS_CONNECTED, CS_SUSPENDED
}
 States for current outgoing call. More...
 

Functions

static void phone_event_handler (void *cls, enum GNUNET_CONVERSATION_PhoneEventCode code, struct GNUNET_CONVERSATION_Caller *caller, const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
 Function called with an event emitted by a phone. More...
 
static void caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code)
 Function called with an event emitted by a caller. More...
 
static void start_phone ()
 Start our phone. More...
 
static void call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
 Function called with an event emitted by a call. More...
 
static void do_help (const char *args)
 Action function to print help for the command shell. More...
 
static void do_quit (const char *args)
 Terminate the client. More...
 
static void do_unknown (const char *msg)
 Handler for unknown command. More...
 
static void do_call (const char *arg)
 Initiating a new call. More...
 
static void do_accept (const char *args)
 Accepting an incoming call. More...
 
static void do_address (const char *args)
 Print address information for this phone. More...
 
static void do_status (const char *args)
 Accepting an incoming call. More...
 
static void do_suspend (const char *args)
 Suspending a call. More...
 
static void do_resume (const char *args)
 Resuming a call. More...
 
static void do_reject (const char *args)
 Rejecting a call. More...
 
static void do_stop_task (void *cls)
 Task run during shutdown. More...
 
static void handle_command_string (char *message, size_t str_len)
 Handle user command. More...
 
static void handle_command (void *cls)
 Task to handle commands from the terminal. More...
 
static void identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
 Function called by identity service with information about egos. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 The main function to conversation. More...
 

Variables

static struct GNUNET_CONVERSATION_Phonephone
 Phone handle. More...
 
static struct GNUNET_CONVERSATION_Callcall
 Call handle (for active outgoing call). More...
 
static struct CallListcl_active
 Caller handle (for active incoming call). More...
 
static struct CallListcl_head
 Head of calls waiting to be accepted. More...
 
static struct CallListcl_tail
 Tail of calls waiting to be accepted. More...
 
static char * line
 Desired phone line (string to be converted to a hash). More...
 
static struct GNUNET_SCHEDULER_Taskhandle_cmd_task
 Task which handles the commands. More...
 
static struct GNUNET_SPEAKER_Handlespeaker
 Our speaker. More...
 
static struct GNUNET_MICROPHONE_Handlemic
 Our microphone. More...
 
static struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 
static struct GNUNET_IDENTITY_Egomy_caller_id
 Our ego. More...
 
static struct GNUNET_IDENTITY_Handleid
 Handle to identity service. More...
 
static char * ego_name
 Name of our ego. More...
 
static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
 Public key of active conversation partner (if any). More...
 
static char * peer_name
 Name of active conversation partner (if any). More...
 
static struct GNUNET_DISK_FileHandlestdin_fh
 File handle for stdin. More...
 
static enum PhoneState phone_state
 Our phone's current state. More...
 
static enum CallState call_state
 Our call's current state. More...
 
static unsigned int caller_num_gen
 Counts the number of incoming calls we have had so far. More...
 
static char * address
 GNS address for this phone. More...
 
static int verbose
 Be verbose. More...
 
static struct VoipCommand commands []
 List of supported commands. More...
 

Detailed Description

conversation implementation

Author
Simon Dieterle
Andreas Fuchs

Definition in file gnunet-conversation.c.

Macro Definition Documentation

◆ MAX_MESSAGE_LENGTH

#define MAX_MESSAGE_LENGTH   1024

Maximum length allowed for the command line input.

Definition at line 39 of file gnunet-conversation.c.

Referenced by handle_command(), and run().

◆ XSTRINGIFY

#define XSTRINGIFY (   x)    STRINGIFY(x)

Definition at line 41 of file gnunet-conversation.c.

Referenced by run().

◆ STRINGIFY

#define STRINGIFY (   x)    (#x)

Definition at line 43 of file gnunet-conversation.c.

Typedef Documentation

◆ ActionFunction

typedef void(* ActionFunction) (const char *arguments)

Function declareation for executing a action.

Parameters
argumentsarguments given to the function

Definition at line 468 of file gnunet-conversation.c.

Enumeration Type Documentation

◆ PhoneState

enum PhoneState

Possible states of the phone.

Enumerator
PS_REGISTER 

We still need to register the phone.

PS_READY 

We are waiting for calls.

PS_LOOKUP_EGO 

We're waiting for our own idenitty.

PS_LISTEN 

We're listening for calls.

PS_ACCEPTED 

We accepted an incoming phone call.

PS_ERROR 

Internal error.

Definition at line 55 of file gnunet-conversation.c.

56 {
61 
65  PS_LISTEN,
66 
71 
75  PS_ERROR
76 };
Internal error.
We're waiting for our own idenitty.
We accepted an incoming phone call.
We're listening for calls.

◆ CallState

enum CallState

States for current outgoing call.

Enumerator
CS_LOOKUP 

We still need to lookup the callee.

CS_RINGING 

The call is ringing.

CS_ACTIVE 

The call is in an active conversation.

CS_SHUTDOWN 

The call is in termination.

CS_SUSPENDED_CALLER 

The call was suspended by the caller.

CS_SUSPENDED_CALLEE 

The call was suspended by the callee.

CS_SUSPENDED_BOTH 

The call was suspended by both caller and callee.

CS_RESOLVING 

We are looking up some other participant.

CS_RINGING 

We are now ringing the other participant.

CS_CONNECTED 

The other party accepted our call and we are now connected.

CS_SUSPENDED 

The call is currently suspended (by us).

Definition at line 82 of file gnunet-conversation.c.

83 {
88 
92  CS_RINGING,
93 
98 
103 
104 };
The other party accepted our call and we are now connected.
We are now ringing the other participant.
The call is currently suspended (by us).
We are looking up some other participant.

Function Documentation

◆ phone_event_handler()

static void phone_event_handler ( void *  cls,
enum GNUNET_CONVERSATION_PhoneEventCode  code,
struct GNUNET_CONVERSATION_Caller caller,
const struct GNUNET_CRYPTO_EcdsaPublicKey caller_id 
)
static

Function called with an event emitted by a phone.

Parameters
clsclosure
codetype of the event
callerhandle for the caller
caller_idpublic key of the caller (in GNS)

Definition at line 258 of file gnunet-conversation.c.

References _, CallList::caller, CallList::caller_id, CallList::caller_num, caller_num_gen, cl_active, FPRINTF, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, GNUNET_CONVERSATION_EC_PHONE_RING, GNUNET_free, GNUNET_GNSRECORD_pkey_to_zkey(), GNUNET_new, CallList::next, phone_state, and PS_LISTEN.

Referenced by start_phone().

262 {
263  struct CallList *cl;
264 
265  (void) cls;
266  switch (code)
267  {
269  /*
270  * FIXME: we should be playing our ringtones from contrib/sounds now!
271  *
272  ring_my_bell();
273  *
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
275  */
276  FPRINTF (stdout,
277  _("Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"),
278  GNUNET_GNSRECORD_pkey_to_zkey (caller_id),
281  cl = GNUNET_new (struct CallList);
282  cl->caller = caller;
283  cl->caller_id = *caller_id;
284  cl->caller_num = caller_num_gen++;
286  cl_tail,
287  cl);
288  break;
290  for (cl = cl_head; NULL != cl; cl = cl->next)
291  if (caller == cl->caller)
292  break;
293  if ( (NULL == cl) &&
294  (caller == cl_active->caller) )
295  cl = cl_active;
296  if (NULL == cl)
297  {
298  GNUNET_break (0);
299  return;
300  }
301  FPRINTF (stdout,
302  _("Call from `%s' terminated\n"),
304  if (cl == cl_active)
305  {
306  cl_active = NULL;
308  }
309  else
310  {
312  cl_tail,
313  cl);
314  }
315  GNUNET_free (cl);
316  break;
317  }
318 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct CallList * cl_tail
Tail of calls waiting to be accepted.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define FPRINTF
Definition: plibc.h:683
List of incoming calls.
unsigned int caller_num
Unique number of the call.
static enum PhoneState phone_state
Our phone's current state.
static struct CallList * cl_head
Head of calls waiting to be accepted.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct CallList * next
A DLL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
The conversation was terminated by the caller.
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
We're listening for calls.
We are the callee and the phone is ringing.
static struct CallList * cl_active
Caller handle (for active incoming call).
struct GNUNET_CONVERSATION_Caller * caller
Handle to hang up or activate.
static unsigned int caller_num_gen
Counts the number of incoming calls we have had so far.
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Public key identifying the caller.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ caller_event_handler()

static void caller_event_handler ( void *  cls,
enum GNUNET_CONVERSATION_CallerEventCode  code 
)
static

Function called with an event emitted by a caller.

Parameters
clsclosure with the struct CallList of the caller
codetype of the event issued by the caller

Definition at line 328 of file gnunet-conversation.c.

References _, CallList::caller_id, FPRINTF, GNUNET_CONVERSATION_EC_CALLER_RESUME, GNUNET_CONVERSATION_EC_CALLER_SUSPEND, and GNUNET_GNSRECORD_pkey_to_zkey().

Referenced by do_accept().

330 {
331  struct CallList *cl = cls;
332 
333  switch (code)
334  {
336  FPRINTF (stdout,
337  _("Call from `%s' suspended by other user\n"),
339  break;
341  FPRINTF (stdout,
342  _("Call from `%s' resumed by other user\n"),
344  break;
345  }
346 }
#define FPRINTF
Definition: plibc.h:683
List of incoming calls.
We are the callee and the caller resumed the call.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
We are the callee and the caller suspended the call.
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Public key identifying the caller.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_phone()

static void start_phone ( )
static

Start our phone.

Definition at line 353 of file gnunet-conversation.c.

References _, address, GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, ego_name, FPRINTF, GNUNET_assert, GNUNET_CONVERSATION_phone_create(), GNUNET_CONVERSATION_phone_get_record(), GNUNET_free_non_null, GNUNET_GNSRECORD_value_to_string(), phone_event_handler(), phone_state, PS_ERROR, PS_LISTEN, PS_LOOKUP_EGO, and GNUNET_GNSRECORD_Data::record_type.

Referenced by identity_cb().

354 {
355  struct GNUNET_GNSRECORD_Data rd;
356 
357  if (NULL == my_caller_id)
358  {
359  FPRINTF (stderr,
360  _("Ego `%s' no longer available, phone is now down.\n"),
361  ego_name);
363  return;
364  }
365  GNUNET_assert (NULL == phone);
367  my_caller_id,
369  NULL);
370  /* FIXME: get record and print full GNS record info later here... */
371  if (NULL == phone)
372  {
373  FPRINTF (stderr,
374  "%s",
375  _("Failed to setup phone (internal error)\n"));
377  }
378  else
379  {
381  &rd);
383  address = GNUNET_GNSRECORD_value_to_string (rd.record_type,
384  rd.data,
385  rd.data_size);
386  FPRINTF (stdout,
387  _("Phone active at `%s'. Type `/help' for a list of available commands\n"),
388  address);
390  }
391 }
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
Internal error.
We're waiting for our own idenitty.
#define FPRINTF
Definition: plibc.h:683
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static char * ego_name
Name of our ego.
static enum PhoneState phone_state
Our phone's current state.
void GNUNET_CONVERSATION_phone_get_record(struct GNUNET_CONVERSATION_Phone *phone, struct GNUNET_GNSRECORD_Data *rd)
Fill in a namestore record with the contact information for this phone.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_IDENTITY_Ego * my_caller_id
Our ego.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void phone_event_handler(void *cls, enum GNUNET_CONVERSATION_PhoneEventCode code, struct GNUNET_CONVERSATION_Caller *caller, const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
Function called with an event emitted by a phone.
We're listening for calls.
struct GNUNET_CONVERSATION_Phone * GNUNET_CONVERSATION_phone_create(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_IDENTITY_Ego *ego, GNUNET_CONVERSATION_PhoneEventHandler event_handler, void *event_handler_cls)
Create a new phone.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
Definition: gnsrecord.c:143
static char * address
GNS address for this phone.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ call_event_handler()

static void call_event_handler ( void *  cls,
enum GNUNET_CONVERSATION_CallEventCode  code 
)
static

Function called with an event emitted by a call.

Parameters
clsclosure, NULL
codetype of the event on the call

Definition at line 401 of file gnunet-conversation.c.

References _, call_state, CS_CONNECTED, CS_RESOLVING, CS_RINGING, FPRINTF, GNUNET_break, GNUNET_CONVERSATION_EC_CALL_ERROR, GNUNET_CONVERSATION_EC_CALL_GNS_FAIL, GNUNET_CONVERSATION_EC_CALL_HUNG_UP, GNUNET_CONVERSATION_EC_CALL_PICKED_UP, GNUNET_CONVERSATION_EC_CALL_RESUMED, GNUNET_CONVERSATION_EC_CALL_RINGING, GNUNET_CONVERSATION_EC_CALL_SUSPENDED, GNUNET_free, and peer_name.

Referenced by do_call().

403 {
404  (void) cls;
405 
406  switch (code)
407  {
410  FPRINTF (stdout,
411  _("Resolved address of `%s'. Now ringing other party.\n"),
412  peer_name);
414  break;
417  FPRINTF (stdout,
418  _("Connection established to `%s'\n"),
419  peer_name);
421  break;
424  FPRINTF (stdout,
425  _("Failed to resolve `%s'\n"),
426  peer_name);
428  peer_name = NULL;
429  call = NULL;
430  break;
432  FPRINTF (stdout,
433  _("Call to `%s' terminated\n"),
434  peer_name);
436  peer_name = NULL;
437  call = NULL;
438  break;
441  FPRINTF (stdout,
442  _("Connection to `%s' suspended (by other user)\n"),
443  peer_name);
444  break;
447  FPRINTF (stdout,
448  _("Connection to `%s' resumed (by other user)\n"),
449  peer_name);
450  break;
452  FPRINTF (stdout,
453  _("Error with the call, restarting it\n"));
455  peer_name = NULL;
456  call = NULL;
457  break;
458  }
459 }
#define FPRINTF
Definition: plibc.h:683
static enum CallState call_state
Our call's current state.
We are the caller and the callee suspended the call.
static char * peer_name
Name of active conversation partner (if any).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
We are the caller and are now ready to talk as the callee picked up.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
We are the caller and are now ringing the other party (GNS lookup succeeded).
We are the caller and the callee called GNUNET_CONVERSATION_caller_hang_up.
We are the caller and failed to locate a phone record in GNS.
The other party accepted our call and we are now connected.
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We are now ringing the other participant.
We are the caller and the callee suspended the call.
We had an error handing the call, and are now restarting it (back to lookup).
We are looking up some other participant.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ do_help()

static void do_help ( const char *  args)
static

Action function to print help for the command shell.

Parameters
argsarguments given to the command

Definition at line 995 of file gnunet-conversation.c.

References VoipCommand::Action, VoipCommand::command, FPRINTF, gettext, and VoipCommand::helptext.

Referenced by do_call().

996 {
997  unsigned int i;
998 
999  i = 0;
1000  while ( (NULL != args) &&
1001  (0 != strlen (args)) &&
1002  (commands[i].Action != &do_help))
1003  {
1004  if (0 ==
1005  strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
1006  {
1007  FPRINTF (stdout,
1008  "%s\n",
1009  gettext (commands[i].helptext));
1010  return;
1011  }
1012  i++;
1013  }
1014  i = 0;
1015  FPRINTF (stdout,
1016  "%s",
1017  "Available commands:\n");
1018  while (commands[i].Action != &do_help)
1019  {
1020  FPRINTF (stdout,
1021  "%s\n",
1022  gettext (commands[i].command));
1023  i++;
1024  }
1025  FPRINTF (stdout,
1026  "%s",
1027  "\n");
1028  FPRINTF (stdout,
1029  "%s\n",
1030  gettext (commands[i].helptext));
1031 }
#define FPRINTF
Definition: plibc.h:683
#define gettext(Msgid)
Definition: gettext.h:45
static struct VoipCommand commands[]
List of supported commands.
static void do_help(const char *args)
Action function to print help for the command shell.
Here is the caller graph for this function:

◆ do_quit()

static void do_quit ( const char *  args)
static

Terminate the client.

Parameters
argsarguments given to the command

Definition at line 508 of file gnunet-conversation.c.

References GNUNET_SCHEDULER_shutdown().

509 {
510  (void) args;
512 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
Here is the call graph for this function:

◆ do_unknown()

static void do_unknown ( const char *  msg)
static

Handler for unknown command.

Parameters
msgarguments given to the command

Definition at line 521 of file gnunet-conversation.c.

References _, and FPRINTF.

522 {
523  FPRINTF (stderr,
524  _("Unknown command `%s'\n"),
525  msg);
526 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define FPRINTF
Definition: plibc.h:683
#define _(String)
GNU gettext support macro.
Definition: platform.h:208

◆ do_call()

static void do_call ( const char *  arg)
static

Initiating a new call.

Parameters
argarguments given to the command

Definition at line 535 of file gnunet-conversation.c.

References _, call_event_handler(), call_state, CS_RESOLVING, do_help(), ego_name, FPRINTF, GNUNET_assert, GNUNET_CONVERSATION_call_start(), GNUNET_GNSRECORD_pkey_to_zkey(), GNUNET_strdup, peer_key, peer_name, phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

536 {
537  if (NULL == my_caller_id)
538  {
539  FPRINTF (stderr,
540  _("Ego `%s' not available\n"),
541  ego_name);
542  return;
543  }
544  if (NULL != call)
545  {
546  FPRINTF (stderr,
547  _("You are calling someone else already, hang up first!\n"));
548  return;
549  }
550  switch (phone_state)
551  {
552  case PS_LOOKUP_EGO:
553  FPRINTF (stderr,
554  _("Ego `%s' not available\n"),
555  ego_name);
556  return;
557  case PS_LISTEN:
558  /* ok to call! */
559  break;
560  case PS_ACCEPTED:
561  FPRINTF (stderr,
562  _("You are answering call from `%s', hang up or suspend that call first!\n"),
564  return;
565  case PS_ERROR:
566  /* ok to call */
567  break;
568  }
569  if (NULL == arg)
570  {
571  FPRINTF (stderr,
572  _("Call recipient missing.\n"));
573  do_help ("/call");
574  return;
575  }
578  GNUNET_assert (NULL == call);
580  my_caller_id,
581  arg,
582  speaker,
583  mic,
584  &call_event_handler, NULL);
585 }
Internal error.
We're waiting for our own idenitty.
#define FPRINTF
Definition: plibc.h:683
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static enum CallState call_state
Our call's current state.
static char * ego_name
Name of our ego.
static enum PhoneState phone_state
Our phone's current state.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * peer_name
Name of active conversation partner (if any).
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
We accepted an incoming phone call.
static struct GNUNET_IDENTITY_Ego * my_caller_id
Our ego.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_SPEAKER_Handle * speaker
Our speaker.
struct GNUNET_CONVERSATION_Call * GNUNET_CONVERSATION_call_start(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_IDENTITY_Ego *caller_id, const char *callee, struct GNUNET_SPEAKER_Handle *speaker, struct GNUNET_MICROPHONE_Handle *mic, GNUNET_CONVERSATION_CallEventHandler event_handler, void *event_handler_cls)
Call the phone of another user.
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
Public key of active conversation partner (if any).
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
static void call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
Function called with an event emitted by a call.
We are looking up some other participant.
static void do_help(const char *args)
Action function to print help for the command shell.
Here is the call graph for this function:

◆ do_accept()

static void do_accept ( const char *  args)
static

Accepting an incoming call.

Parameters
argsarguments given to the command

Definition at line 594 of file gnunet-conversation.c.

References _, buf, call_state, CallList::caller, caller_event_handler(), CallList::caller_id, CallList::caller_num, cl_head, CS_SUSPENDED, FPRINTF, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_CONVERSATION_caller_pick_up(), GNUNET_GNSRECORD_pkey_to_zkey(), GNUNET_snprintf(), CallList::next, peer_key, phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

595 {
596  struct CallList *cl;
597  char buf[32];
598 
599  if ( (NULL != call) &&
600  (CS_SUSPENDED != call_state) )
601  {
602  FPRINTF (stderr,
603  _("You are calling someone else already, hang up first!\n"));
604  return;
605  }
606  switch (phone_state)
607  {
608  case PS_LOOKUP_EGO:
609  GNUNET_break (0);
610  break;
611  case PS_LISTEN:
612  /* this is the expected state */
613  break;
614  case PS_ACCEPTED:
615  FPRINTF (stderr,
616  _("You are answering call from `%s', hang up or suspend that call first!\n"),
618  return;
619  case PS_ERROR:
620  GNUNET_break (0);
621  break;
622  }
623  cl = cl_head;
624  if (NULL == cl)
625  {
626  FPRINTF (stderr,
627  _("There is no incoming call to accept here!\n"));
628  return;
629  }
630  if ( (NULL != cl->next) || (NULL != args) )
631  {
632  for (cl = cl_head; NULL != cl; cl = cl->next)
633  {
634  GNUNET_snprintf (buf, sizeof (buf),
635  "%u",
636  cl->caller_num);
637  if (0 == strcmp (buf, args))
638  break;
639  }
640  }
641  if (NULL == cl)
642  {
643  FPRINTF (stderr,
644  _("There is no incoming call `%s' to accept right now!\n"),
645  args);
646  return;
647  }
649  cl_tail,
650  cl);
651  cl_active = cl;
652  peer_key = cl->caller_id;
656  cl,
657  speaker,
658  mic);
659 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct CallList * cl_tail
Tail of calls waiting to be accepted.
Internal error.
We're waiting for our own idenitty.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
#define FPRINTF
Definition: plibc.h:683
List of incoming calls.
unsigned int caller_num
Unique number of the call.
static enum CallState call_state
Our call's current state.
static enum PhoneState phone_state
Our phone's current state.
static struct CallList * cl_head
Head of calls waiting to be accepted.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct CallList * next
A DLL.
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
We accepted an incoming phone call.
static void caller_event_handler(void *cls, enum GNUNET_CONVERSATION_CallerEventCode code)
Function called with an event emitted by a caller.
static struct GNUNET_SPEAKER_Handle * speaker
Our speaker.
static char buf[2048]
void GNUNET_CONVERSATION_caller_pick_up(struct GNUNET_CONVERSATION_Caller *caller, GNUNET_CONVERSATION_CallerEventHandler event_handler, void *event_handler_cls, struct GNUNET_SPEAKER_Handle *speaker, struct GNUNET_MICROPHONE_Handle *mic)
Picks up a (ringing) phone.
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
Public key of active conversation partner (if any).
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
static struct CallList * cl_active
Caller handle (for active incoming call).
struct GNUNET_CONVERSATION_Caller * caller
Handle to hang up or activate.
The call is currently suspended (by us).
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Public key identifying the caller.
Here is the call graph for this function:

◆ do_address()

static void do_address ( const char *  args)
static

Print address information for this phone.

Parameters
argsarguments given to the command

Definition at line 668 of file gnunet-conversation.c.

References _, address, and FPRINTF.

669 {
670  (void) args;
671  if (NULL == address)
672  {
673  FPRINTF (stdout,
674  "%s",
675  _("We currently do not have an address.\n"));
676  return;
677  }
678  FPRINTF (stdout,
679  "%s\n",
680  address);
681 }
#define FPRINTF
Definition: plibc.h:683
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * address
GNS address for this phone.

◆ do_status()

static void do_status ( const char *  args)
static

Accepting an incoming call.

Parameters
argsarguments given to the command

Definition at line 690 of file gnunet-conversation.c.

References _, call_state, CallList::caller_id, CallList::caller_num, CS_CONNECTED, CS_RESOLVING, CS_RINGING, CS_SUSPENDED, ego_name, FPRINTF, GNUNET_GNSRECORD_pkey_to_zkey(), line, CallList::next, peer_key, peer_name, phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

691 {
692  struct CallList *cl;
693 
694  (void) args;
695  switch (phone_state)
696  {
697  case PS_LOOKUP_EGO:
698  FPRINTF (stdout,
699  _("We are currently trying to locate the private key for the ego `%s'.\n"),
700  ego_name);
701  break;
702  case PS_LISTEN:
703  FPRINTF (stdout,
704  _("We are listening for incoming calls for ego `%s' on line `%s'.\n"),
705  ego_name,
706  line);
707  break;
708  case PS_ACCEPTED:
709  FPRINTF (stdout,
710  _("You are having a conversation with `%s'.\n"),
712  break;
713  case PS_ERROR:
714  FPRINTF (stdout,
715  _("We had an internal error setting up our phone line. You can still make calls.\n"));
716  break;
717  }
718  if (NULL != call)
719  {
720  switch (call_state)
721  {
722  case CS_RESOLVING:
723  FPRINTF (stdout,
724  _("We are trying to find the network address to call `%s'.\n"),
725  peer_name);
726  break;
727  case CS_RINGING:
728  FPRINTF (stdout,
729  _("We are calling `%s', their phone should be ringing.\n"),
730  peer_name);
731  break;
732  case CS_CONNECTED:
733  FPRINTF (stdout,
734  _("You are having a conversation with `%s'.\n"),
735  peer_name);
736  break;
737  case CS_SUSPENDED:
738  /* ok to accept incoming call right now */
739  break;
740  }
741  }
742  if ( (NULL != cl_head) &&
743  ( (cl_head != cl_active) ||
744  (cl_head != cl_tail) ) )
745  {
746  FPRINTF (stdout,
747  "%s",
748  _("Calls waiting:\n"));
749  for (cl = cl_head; NULL != cl; cl = cl->next)
750  {
751  if (cl == cl_active)
752  continue;
753  FPRINTF (stdout,
754  _("#%u: `%s'\n"),
755  cl->caller_num,
757  }
758  FPRINTF (stdout,
759  "%s",
760  "\n");
761  }
762 }
static struct CallList * cl_tail
Tail of calls waiting to be accepted.
Internal error.
We're waiting for our own idenitty.
#define FPRINTF
Definition: plibc.h:683
List of incoming calls.
unsigned int caller_num
Unique number of the call.
static enum CallState call_state
Our call's current state.
static char * ego_name
Name of our ego.
static enum PhoneState phone_state
Our phone's current state.
static struct CallList * cl_head
Head of calls waiting to be accepted.
static char * peer_name
Name of active conversation partner (if any).
struct CallList * next
A DLL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * line
Desired phone line (string to be converted to a hash).
We accepted an incoming phone call.
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
Public key of active conversation partner (if any).
The other party accepted our call and we are now connected.
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
We are now ringing the other participant.
static struct CallList * cl_active
Caller handle (for active incoming call).
The call is currently suspended (by us).
We are looking up some other participant.
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Public key identifying the caller.
Here is the call graph for this function:

◆ do_suspend()

static void do_suspend ( const char *  args)
static

Suspending a call.

Parameters
argsarguments given to the command

Definition at line 771 of file gnunet-conversation.c.

References _, call_state, CallList::caller, CS_CONNECTED, CS_RESOLVING, CS_RINGING, CS_SUSPENDED, FPRINTF, GNUNET_assert, GNUNET_CONVERSATION_call_suspend(), GNUNET_CONVERSATION_caller_suspend(), phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

772 {
773  (void) args;
774  if (NULL != call)
775  {
776  switch (call_state)
777  {
778  case CS_RESOLVING:
779  case CS_RINGING:
780  case CS_SUSPENDED:
781  FPRINTF (stderr,
782  "%s",
783  _("There is no call that could be suspended right now.\n"));
784  return;
785  case CS_CONNECTED:
788  return;
789  }
790  }
791  switch (phone_state)
792  {
793  case PS_LOOKUP_EGO:
794  case PS_LISTEN:
795  case PS_ERROR:
796  FPRINTF (stderr,
797  "%s",
798  _("There is no call that could be suspended right now.\n"));
799  return;
800  case PS_ACCEPTED:
801  /* expected state, do rejection logic */
802  break;
803  }
804  GNUNET_assert (NULL != cl_active);
806  cl_active = NULL;
808 }
Internal error.
We're waiting for our own idenitty.
#define FPRINTF
Definition: plibc.h:683
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static enum CallState call_state
Our call's current state.
static enum PhoneState phone_state
Our phone's current state.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
We accepted an incoming phone call.
The other party accepted our call and we are now connected.
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
void GNUNET_CONVERSATION_caller_suspend(struct GNUNET_CONVERSATION_Caller *caller)
Pause conversation of an active call.
We are now ringing the other participant.
static struct CallList * cl_active
Caller handle (for active incoming call).
struct GNUNET_CONVERSATION_Caller * caller
Handle to hang up or activate.
The call is currently suspended (by us).
We are looking up some other participant.
void GNUNET_CONVERSATION_call_suspend(struct GNUNET_CONVERSATION_Call *call)
Pause a call.
Here is the call graph for this function:

◆ do_resume()

static void do_resume ( const char *  args)
static

Resuming a call.

Parameters
argsarguments given to the command

Definition at line 817 of file gnunet-conversation.c.

References _, buf, call_state, CallList::caller, CallList::caller_num, cl_head, CS_CONNECTED, CS_RESOLVING, CS_RINGING, CS_SUSPENDED, FPRINTF, GNUNET_assert, GNUNET_CONVERSATION_call_resume(), GNUNET_CONVERSATION_caller_resume(), GNUNET_GNSRECORD_pkey_to_zkey(), GNUNET_snprintf(), CallList::next, peer_key, phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

818 {
819  struct CallList *cl;
820  char buf[32];
821 
822  if (NULL != call)
823  {
824  switch (call_state)
825  {
826  case CS_RESOLVING:
827  case CS_RINGING:
828  case CS_CONNECTED:
829  FPRINTF (stderr,
830  "%s",
831  _("There is no call that could be resumed right now.\n"));
832  return;
833  case CS_SUSPENDED:
836  speaker,
837  mic);
838  return;
839  }
840  }
841  switch (phone_state)
842  {
843  case PS_LOOKUP_EGO:
844  case PS_ERROR:
845  FPRINTF (stderr,
846  "%s",
847  _("There is no call that could be resumed right now.\n"));
848  return;
849  case PS_LISTEN:
850  /* expected state, do resume logic */
851  break;
852  case PS_ACCEPTED:
853  FPRINTF (stderr,
854  _("Already talking with `%s', cannot resume a call right now.\n"),
856  return;
857  }
858  GNUNET_assert (NULL == cl_active);
859  cl = cl_head;
860  if (NULL == cl)
861  {
862  FPRINTF (stderr,
863  _("There is no incoming call to resume here!\n"));
864  return;
865  }
866  if ( (NULL != cl->next) || (NULL != args) )
867  {
868  for (cl = cl_head; NULL != cl; cl = cl->next)
869  {
870  GNUNET_snprintf (buf, sizeof (buf),
871  "%u",
872  cl->caller_num);
873  if (0 == strcmp (buf, args))
874  break;
875  }
876  }
877  if (NULL == cl)
878  {
879  FPRINTF (stderr,
880  _("There is no incoming call `%s' to resume right now!\n"),
881  args);
882  return;
883  }
884  cl_active = cl;
886  speaker,
887  mic);
889 }
Internal error.
We're waiting for our own idenitty.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
#define FPRINTF
Definition: plibc.h:683
List of incoming calls.
unsigned int caller_num
Unique number of the call.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static enum CallState call_state
Our call's current state.
static enum PhoneState phone_state
Our phone's current state.
static struct CallList * cl_head
Head of calls waiting to be accepted.
struct CallList * next
A DLL.
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
We accepted an incoming phone call.
static struct GNUNET_SPEAKER_Handle * speaker
Our speaker.
void GNUNET_CONVERSATION_call_resume(struct GNUNET_CONVERSATION_Call *call, struct GNUNET_SPEAKER_Handle *speaker, struct GNUNET_MICROPHONE_Handle *mic)
Resumes a call after GNUNET_CONVERSATION_call_suspend.
static char buf[2048]
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
Public key of active conversation partner (if any).
The other party accepted our call and we are now connected.
void GNUNET_CONVERSATION_caller_resume(struct GNUNET_CONVERSATION_Caller *caller, struct GNUNET_SPEAKER_Handle *speaker, struct GNUNET_MICROPHONE_Handle *mic)
Resume suspended conversation of a phone.
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
We are now ringing the other participant.
static struct CallList * cl_active
Caller handle (for active incoming call).
struct GNUNET_CONVERSATION_Caller * caller
Handle to hang up or activate.
The call is currently suspended (by us).
We are looking up some other participant.
Here is the call graph for this function:

◆ do_reject()

static void do_reject ( const char *  args)
static

Rejecting a call.

Parameters
argsarguments given to the command

Definition at line 898 of file gnunet-conversation.c.

References _, buf, CallList::caller, CallList::caller_num, cl_head, FPRINTF, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONVERSATION_call_stop(), GNUNET_CONVERSATION_caller_hang_up(), GNUNET_free, GNUNET_snprintf(), CallList::next, phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

899 {
900  struct CallList *cl;
901  char buf[32];
902 
903  if (NULL != call)
904  {
906  call = NULL;
907  return;
908  }
909  switch (phone_state)
910  {
911  case PS_LOOKUP_EGO:
912  case PS_ERROR:
913  FPRINTF (stderr,
914  "%s",
915  _("There is no call that could be cancelled right now.\n"));
916  return;
917  case PS_LISTEN:
918  /* look for active incoming calls to refuse */
919  cl = cl_head;
920  if (NULL == cl)
921  {
922  FPRINTF (stderr,
923  _("There is no incoming call to refuse here!\n"));
924  return;
925  }
926  if ( (NULL != cl->next) || (NULL != args) )
927  {
928  for (cl = cl_head; NULL != cl; cl = cl->next)
929  {
930  GNUNET_snprintf (buf, sizeof (buf),
931  "%u",
932  cl->caller_num);
933  if (0 == strcmp (buf, args))
934  break;
935  }
936  }
937  if (NULL == cl)
938  {
939  FPRINTF (stderr,
940  _("There is no incoming call `%s' to refuse right now!\n"),
941  args);
942  return;
943  }
946  cl_tail,
947  cl);
948  GNUNET_free (cl);
949  break;
950  case PS_ACCEPTED:
951  /* expected state, do rejection logic */
952  GNUNET_assert (NULL != cl_active);
954  cl_active = NULL;
956  break;
957  }
958 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct CallList * cl_tail
Tail of calls waiting to be accepted.
Internal error.
We're waiting for our own idenitty.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
#define FPRINTF
Definition: plibc.h:683
List of incoming calls.
unsigned int caller_num
Unique number of the call.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_CONVERSATION_caller_hang_up(struct GNUNET_CONVERSATION_Caller *caller)
Hang up up a (possibly ringing) phone.
static enum PhoneState phone_state
Our phone's current state.
static struct CallList * cl_head
Head of calls waiting to be accepted.
struct CallList * next
A DLL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
We accepted an incoming phone call.
static char buf[2048]
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
void GNUNET_CONVERSATION_call_stop(struct GNUNET_CONVERSATION_Call *call)
Terminate a call.
static struct CallList * cl_active
Caller handle (for active incoming call).
struct GNUNET_CONVERSATION_Caller * caller
Handle to hang up or activate.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ do_stop_task()

static void do_stop_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsNULL

Definition at line 1040 of file gnunet-conversation.c.

References ego_name, GNUNET_CONVERSATION_call_stop(), GNUNET_CONVERSATION_phone_destroy(), GNUNET_free, GNUNET_free_non_null, GNUNET_HELPER_stop(), GNUNET_IDENTITY_disconnect(), GNUNET_MICROPHONE_destroy(), GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_SPEAKER_destroy(), peer_name, phone_state, and PS_ERROR.

Referenced by run().

1041 {
1042  (void) cls;
1043 #ifdef WINDOWS
1044  if (NULL != stdin_hlp)
1045  {
1046  GNUNET_HELPER_stop (stdin_hlp, GNUNET_NO);
1047  stdin_hlp = NULL;
1048  }
1049 #endif
1050  if (NULL != call)
1051  {
1053  call = NULL;
1054  }
1055  if (NULL != phone)
1056  {
1058  phone = NULL;
1059  }
1060  if (NULL != handle_cmd_task)
1061  {
1063  handle_cmd_task = NULL;
1064  }
1065  if (NULL != id)
1066  {
1068  id = NULL;
1069  }
1071  speaker = NULL;
1073  mic = NULL;
1075  ego_name = NULL;
1077  peer_name = NULL;
1079 }
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
Internal error.
static struct GNUNET_SCHEDULER_Task * handle_cmd_task
Task which handles the commands.
static char * ego_name
Name of our ego.
void GNUNET_HELPER_stop(struct GNUNET_HELPER_Handle *h, int soft_kill)
Kills the helper, closes the pipe, frees the handle and calls wait() on the helper process...
Definition: helper.c:569
static enum PhoneState phone_state
Our phone's current state.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static char * peer_name
Name of active conversation partner (if any).
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
static struct GNUNET_SPEAKER_Handle * speaker
Our speaker.
void GNUNET_CONVERSATION_phone_destroy(struct GNUNET_CONVERSATION_Phone *phone)
Destroys a phone.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:838
void GNUNET_SPEAKER_destroy(struct GNUNET_SPEAKER_Handle *speaker)
Destroy a speaker.
Definition: speaker.c:183
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
void GNUNET_MICROPHONE_destroy(struct GNUNET_MICROPHONE_Handle *microphone)
Destroy a microphone.
Definition: microphone.c:195
void GNUNET_CONVERSATION_call_stop(struct GNUNET_CONVERSATION_Call *call)
Terminate a call.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_command_string()

static void handle_command_string ( char *  message,
size_t  str_len 
)
static

Handle user command.

Parameters
messagecommand the user typed in
str_lennumber of bytes to process in message

Definition at line 1089 of file gnunet-conversation.c.

References VoipCommand::Action, chars, VoipCommand::command, GNUNET_break, GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS, GNUNET_OK, GNUNET_SYSERR, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by handle_command().

1091 {
1092  size_t i;
1093  const char *ptr;
1094 
1095  if (0 == str_len)
1096  return;
1097  if (message[str_len - 1] == '\n')
1098  message[str_len - 1] = '\0';
1099  if (message[str_len - 2] == '\r')
1100  message[str_len - 2] = '\0';
1101  if (0 == strlen (message))
1102  return;
1103  i = 0;
1104  while ((NULL != commands[i].command) &&
1105  (0 != strncasecmp (commands[i].command, message,
1106  strlen (commands[i].command))))
1107  i++;
1108  ptr = &message[strlen (commands[i].command)];
1109  while (isspace ((unsigned char) *ptr))
1110  ptr++;
1111  if ('\0' == *ptr)
1112  ptr = NULL;
1113  commands[i].Action (ptr);
1114 }
static struct VoipCommand commands[]
List of supported commands.
ActionFunction Action
Function to call on command.
Here is the caller graph for this function:

◆ handle_command()

static void handle_command ( void *  cls)
static

Task to handle commands from the terminal.

Parameters
clsNULL

Definition at line 1154 of file gnunet-conversation.c.

References GNUNET_SCHEDULER_add_read_file(), GNUNET_TIME_UNIT_FOREVER_REL, handle_command_string(), and MAX_MESSAGE_LENGTH.

Referenced by run().

1155 {
1156  char message[MAX_MESSAGE_LENGTH + 1];
1157 
1158  (void) cls;
1159  handle_cmd_task =
1161  stdin_fh,
1162  &handle_command, NULL);
1163  /* read message from command line and handle it */
1164  memset (message,
1165  0,
1166  MAX_MESSAGE_LENGTH + 1);
1167  if (NULL == fgets (message,
1169  stdin))
1170  return;
1171  handle_command_string (message,
1172  strlen (message));
1173 }
static void handle_command(void *cls)
Task to handle commands from the terminal.
static struct GNUNET_SCHEDULER_Task * handle_cmd_task
Task which handles the commands.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1643
static void handle_command_string(char *message, size_t str_len)
Handle user command.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static struct GNUNET_DISK_FileHandle * stdin_fh
File handle for stdin.
#define MAX_MESSAGE_LENGTH
Maximum length allowed for the command line input.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ identity_cb()

static void identity_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego,
void **  ctx,
const char *  name 
)
static

Function called by identity service with information about egos.

Parameters
clsNULL
egoego handle
ctxunused
namename of the ego

Definition at line 1185 of file gnunet-conversation.c.

References _, ego_name, FPRINTF, GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_strdup, line, start_phone(), and verbose.

Referenced by run().

1189 {
1190  (void) cls;
1191  (void) ctx;
1192  if (NULL == name)
1193  return;
1194  if (ego == my_caller_id)
1195  {
1196  if (verbose)
1197  FPRINTF (stdout,
1198  _("Name of our ego changed to `%s'\n"),
1199  name);
1202  return;
1203  }
1204  if (0 != strcmp (name,
1205  ego_name))
1206  return;
1207  if (NULL == ego)
1208  {
1209  if (verbose)
1210  FPRINTF (stdout,
1211  _("Our ego `%s' was deleted!\n"),
1212  ego_name);
1213  my_caller_id = NULL;
1214  return;
1215  }
1216  my_caller_id = ego;
1218  "CONVERSATION",
1219  "LINE",
1220  line);
1221  start_phone ();
1222 }
#define FPRINTF
Definition: plibc.h:683
static char * ego_name
Name of our ego.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * line
Desired phone line (string to be converted to a hash).
static struct GNUNET_IDENTITY_Ego * my_caller_id
Our ego.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
static void start_phone()
Start our phone.
const char * name
static int verbose
Be verbose.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

Definition at line 1234 of file gnunet-conversation.c.

References _, cpid, do_stop_task(), ego_name, FPRINTF, GNUNET_CONFIGURATION_dup(), GNUNET_HELPER_start(), GNUNET_IDENTITY_connect(), GNUNET_MICROPHONE_create_from_hardware(), GNUNET_NO, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_UI, GNUNET_SPEAKER_create_from_hardware(), handle_command(), identity_cb(), MAX_MESSAGE_LENGTH, and XSTRINGIFY.

Referenced by main().

1238 {
1239  (void) cls;
1240  (void) args;
1241  (void) cfgfile;
1245  if (NULL == ego_name)
1246  {
1247  FPRINTF (stderr,
1248  "%s",
1249  _("You must specify the NAME of an ego to use\n"));
1250  return;
1251  }
1253  &identity_cb,
1254  NULL);
1255 #ifdef WINDOWS
1256  if (stdin_fh == NULL)
1257  {
1258  static char cpid[64];
1259  static char *args[] = {"gnunet-helper-w32-console.exe", "chars",
1261  snprintf (cpid, 64, "%d", GetCurrentProcessId ());
1262  stdin_hlp = GNUNET_HELPER_start (
1263  GNUNET_NO,
1264  "gnunet-helper-w32-console",
1265  args,
1266  console_reader_chars,
1267  NULL,
1268  NULL);
1269  if (NULL == stdin_hlp)
1270  {
1271  FPRINTF (stderr,
1272  "%s",
1273  _("Failed to start gnunet-helper-w32-console\n"));
1274  return;
1275  }
1276  }
1277  else
1278 #endif
1279  handle_cmd_task =
1281  &handle_command, NULL);
1283  NULL);
1284 }
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:528
static char * cpid
Which peer should we connect to?
static void handle_command(void *cls)
Task to handle commands from the terminal.
static struct GNUNET_SCHEDULER_Task * handle_cmd_task
Task which handles the commands.
#define FPRINTF
Definition: plibc.h:683
struct GNUNET_HELPER_Handle * GNUNET_HELPER_start(int with_control_pipe, const char *binary_name, char *const binary_argv[], GNUNET_MessageTokenizerCallback cb, GNUNET_HELPER_ExceptionCallback exp_cb, void *cb_cls)
Starts a helper and begins reading from it.
Definition: helper.c:491
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
struct GNUNET_SPEAKER_Handle * GNUNET_SPEAKER_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a speaker that corresponds to the speaker hardware of our system.
Definition: speaker.c:160
static char * ego_name
Name of our ego.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1200
Run with priority for interactive tasks.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_SPEAKER_Handle * speaker
Our speaker.
static struct GNUNET_DISK_FileHandle * stdin_fh
File handle for stdin.
#define XSTRINGIFY(x)
static void identity_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Function called by identity service with information about egos.
static void do_stop_task(void *cls)
Task run during shutdown.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
#define MAX_MESSAGE_LENGTH
Maximum length allowed for the command line input.
struct GNUNET_MICROPHONE_Handle * GNUNET_MICROPHONE_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a microphone that corresponds to the microphone hardware of our system.
Definition: microphone.c:173
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function to conversation.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 1295 of file gnunet-conversation.c.

References ego_name, gettext_noop, GNUNET_CONFIGURATION_destroy(), GNUNET_DISK_get_handle_from_int_fd(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_string(), GNUNET_log_strerror, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), line, ret, and run().

1297 {
1300  "ego",
1301  "NAME",
1302  gettext_noop ("sets the NAME of the ego to use for the caller ID"),
1303  &ego_name),
1305  "phone",
1306  "LINE",
1307  gettext_noop ("sets the LINE to use for the phone"),
1308  &line),
1310  };
1311  int ret;
1312 #ifndef WINDOWS
1313  int flags;
1314  flags = fcntl (0, F_GETFL, 0);
1315  flags |= O_NONBLOCK;
1316  if (0 != fcntl (0, F_SETFL, flags))
1318  "fcntl");
1320 #else
1321  if (FILE_TYPE_CHAR == GetFileType ((HANDLE) _get_osfhandle (0)))
1322  {
1323  stdin_fh = NULL;
1324  }
1325  else
1327 #endif
1328 
1329  if (GNUNET_OK !=
1330  GNUNET_STRINGS_get_utf8_args (argc, argv,
1331  &argc, &argv))
1332  return 2;
1333  ret = GNUNET_PROGRAM_run (argc,
1334  argv,
1335  "gnunet-conversation",
1336  gettext_noop ("Enables having a conversation with other GNUnet users."),
1337  options,
1338  &run, NULL);
1339  GNUNET_free ((void *) argv);
1340  if (NULL != cfg)
1341  {
1343  cfg = NULL;
1344  }
1345  return (GNUNET_OK == ret) ? 0 : 1;
1346 }
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run by the scheduler.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
static char * ego_name
Name of our ego.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
static char * line
Desired phone line (string to be converted to a hash).
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static struct GNUNET_DISK_FileHandle * stdin_fh
File handle for stdin.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd(int fno)
Get a handle from a native integer FD.
Definition: disk.c:1937
int GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:361
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ phone

struct GNUNET_CONVERSATION_Phone* phone
static

Phone handle.

Definition at line 145 of file gnunet-conversation.c.

◆ call

struct GNUNET_CONVERSATION_Call* call
static

◆ cl_active

struct CallList* cl_active
static

Caller handle (for active incoming call).

This call handler is NOT in the cl_head / cl_tail list.

Definition at line 156 of file gnunet-conversation.c.

Referenced by phone_event_handler().

◆ cl_head

struct CallList* cl_head
static

Head of calls waiting to be accepted.

Definition at line 161 of file gnunet-conversation.c.

Referenced by do_accept(), do_reject(), and do_resume().

◆ cl_tail

struct CallList* cl_tail
static

Tail of calls waiting to be accepted.

Definition at line 166 of file gnunet-conversation.c.

◆ line

char* line
static

◆ handle_cmd_task

struct GNUNET_SCHEDULER_Task* handle_cmd_task
static

Task which handles the commands.

Definition at line 176 of file gnunet-conversation.c.

◆ speaker

struct GNUNET_SPEAKER_Handle* speaker
static

Our speaker.

Definition at line 181 of file gnunet-conversation.c.

◆ mic

struct GNUNET_MICROPHONE_Handle* mic
static

◆ cfg

struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

Definition at line 191 of file gnunet-conversation.c.

◆ my_caller_id

struct GNUNET_IDENTITY_Ego* my_caller_id
static

Our ego.

Definition at line 196 of file gnunet-conversation.c.

◆ id

struct GNUNET_IDENTITY_Handle* id
static

◆ ego_name

char* ego_name
static

Name of our ego.

Definition at line 206 of file gnunet-conversation.c.

Referenced by do_call(), do_status(), do_stop_task(), identity_cb(), main(), run(), and start_phone().

◆ peer_key

struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
static

Public key of active conversation partner (if any).

Definition at line 211 of file gnunet-conversation.c.

Referenced by do_accept(), do_call(), do_resume(), and do_status().

◆ peer_name

char* peer_name
static

Name of active conversation partner (if any).

Definition at line 216 of file gnunet-conversation.c.

Referenced by call_event_handler(), do_call(), do_status(), and do_stop_task().

◆ stdin_fh

struct GNUNET_DISK_FileHandle* stdin_fh
static

File handle for stdin.

Definition at line 221 of file gnunet-conversation.c.

◆ phone_state

enum PhoneState phone_state
static

Our phone's current state.

Definition at line 226 of file gnunet-conversation.c.

Referenced by do_accept(), do_call(), do_reject(), do_resume(), do_status(), do_stop_task(), do_suspend(), phone_event_handler(), and start_phone().

◆ call_state

enum CallState call_state
static

Our call's current state.

Definition at line 231 of file gnunet-conversation.c.

Referenced by call_event_handler(), do_accept(), do_call(), do_resume(), do_status(), and do_suspend().

◆ caller_num_gen

unsigned int caller_num_gen
static

Counts the number of incoming calls we have had so far.

Definition at line 236 of file gnunet-conversation.c.

Referenced by phone_event_handler().

◆ address

char* address
static

GNS address for this phone.

Definition at line 241 of file gnunet-conversation.c.

Referenced by ack_proc(), add_address_to_hello(), address_notification(), broadcast_mst_cb(), check_address_add(), check_client_address_to_string(), check_reply(), client_lookup_session(), client_run(), copy_latest(), create_channel_to_destination(), delta_match(), do_address(), dump_pc(), find_matching(), find_validation_entry(), free_all_it(), GAS_handle_address_add(), GAS_proportional_address_add(), GAS_ril_address_add(), GNUNET_OS_network_interfaces_list(), GST_receive_callback(), handle_client_address_to_string(), handle_dummy(), handle_reply(), handle_response(), handle_session_add(), handle_tcp_welcome(), http_common_address_from_socket(), http_common_plugin_address_pretty_printer(), http_common_plugin_address_to_string(), http_common_plugin_address_to_url(), http_common_plugin_string_to_address(), LIBGNUNET_PLUGIN_TRANSPORT_DONE(), libgnunet_plugin_transport_unix_done(), lookup_session(), main(), mlp_create_problem_add_address_information(), mlp_propagate_results(), normalize_address(), notify_change(), process_data(), process_udp_message(), read_process_ack(), send_syn_ack_message(), server_add_address(), server_remove_address(), setup_sender(), start_address_validation(), start_phone(), tcp_nat_port_map_callback(), tcp_plugin_get_session(), tcp_plugin_string_to_address(), udp_nat_port_map_callback(), udp_plugin_lookup_session(), udp_string_to_address(), unix_demultiplexer(), unix_plugin_string_to_address(), and vpn_allocation_cb().

◆ verbose

int verbose
static

Be verbose.

Definition at line 246 of file gnunet-conversation.c.

Referenced by identity_cb().

◆ commands

struct VoipCommand commands[]
static
Initial value:
= {
{"/address", &do_address,
gettext_noop ("Use `/address' to find out which address this phone should have in GNS")},
{"/call", &do_call,
gettext_noop ("Use `/call USER.gnu' to call USER")},
{"/accept", &do_accept,
gettext_noop ("Use `/accept #NUM' to accept incoming call #NUM")},
{"/suspend", &do_suspend,
gettext_noop ("Use `/suspend' to suspend the active call")},
{"/resume", &do_resume,
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.")},
{"/cancel", &do_reject,
gettext_noop ("Use `/cancel' to reject or terminate a call")},
{"/status", &do_status,
gettext_noop ("Use `/status' to print status information")},
{"/quit", &do_quit,
gettext_noop ("Use `/quit' to terminate gnunet-conversation")},
{"/help", &do_help,
gettext_noop ("Use `/help command' to get help for a specific command")},
{"", &do_unknown,
NULL},
{NULL, NULL, NULL},
}
static void do_call(const char *arg)
Initiating a new call.
static void do_suspend(const char *args)
Suspending a call.
static void do_resume(const char *args)
Resuming a call.
static void do_reject(const char *args)
Rejecting a call.
static void do_status(const char *args)
Accepting an incoming call.
static void do_accept(const char *args)
Accepting an incoming call.
static void do_address(const char *args)
Print address information for this phone.
static void do_unknown(const char *msg)
Handler for unknown command.
static void do_help(const char *args)
Action function to print help for the command shell.
static void do_quit(const char *args)
Terminate the client.
#define gettext_noop(String)
Definition: gettext.h:69

List of supported commands.

Definition at line 964 of file gnunet-conversation.c.