]> sjero.net Git - linphone/blob - console/commands.c
audio conferencing is working. Not all cases are tested yet.
[linphone] / console / commands.c
1 /****************************************************************************
2  *
3  *  $Id: commands.c,v 1.39 2008/07/03 15:08:34 smorlat Exp $
4  *
5  *  Copyright (C) 2006-2009  Sandro Santilli <strk@keybit.net>
6  *  Copyright (C) 2004  Simon MORLAT <simon.morlat@linphone.org>
7  *
8 ****************************************************************************
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  *
24  ****************************************************************************/
25
26 #include <string.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #ifndef _WIN32_WCE
30 #include <errno.h>
31 #include <unistd.h>
32 #endif /*_WIN32_WCE*/
33 #include <limits.h>
34 #include <ctype.h>
35 #include <linphonecore.h>
36 #include "linphonec.h"
37 #include "lpconfig.h"
38
39 #ifndef WIN32
40 #include <sys/wait.h>
41 #endif
42
43 #define AUDIO 0
44 #define VIDEO 1
45
46 /***************************************************************************
47  *
48  *  Forward declarations 
49  *
50  ***************************************************************************/
51
52 extern char *lpc_strip_blanks(char *input);
53
54 /* Command handlers */
55 static int lpc_cmd_help(LinphoneCore *, char *);
56 static int lpc_cmd_proxy(LinphoneCore *, char *);
57 static int lpc_cmd_call(LinphoneCore *, char *);
58 static int lpc_cmd_calls(LinphoneCore *, char *);
59 static int lpc_cmd_chat(LinphoneCore *, char *);
60 static int lpc_cmd_answer(LinphoneCore *, char *);
61 static int lpc_cmd_autoanswer(LinphoneCore *, char *);
62 static int lpc_cmd_terminate(LinphoneCore *, char *);
63 static int lpc_cmd_redirect(LinphoneCore *, char *);
64 static int lpc_cmd_call_logs(LinphoneCore *, char *);
65 static int lpc_cmd_ipv6(LinphoneCore *, char *);
66 static int lpc_cmd_transfer(LinphoneCore *, char *);
67 static int lpc_cmd_quit(LinphoneCore *, char *);
68 static int lpc_cmd_nat(LinphoneCore *, char *);
69 static int lpc_cmd_stun(LinphoneCore *, char *);
70 static int lpc_cmd_firewall(LinphoneCore *, char *);
71 static int lpc_cmd_friend(LinphoneCore *, char*);
72 static int lpc_cmd_soundcard(LinphoneCore *, char *);
73 static int lpc_cmd_webcam(LinphoneCore *, char *);
74 static int lpc_cmd_staticpic(LinphoneCore *, char *);
75 static int lpc_cmd_play(LinphoneCore *, char *);
76 static int lpc_cmd_record(LinphoneCore *, char *);
77 static int lpc_cmd_register(LinphoneCore *, char *);
78 static int lpc_cmd_unregister(LinphoneCore *, char *);
79 static int lpc_cmd_duration(LinphoneCore *lc, char *args);
80 static int lpc_cmd_status(LinphoneCore *lc, char *args);
81 static int lpc_cmd_ports(LinphoneCore *lc, char *args);
82 static int lpc_cmd_param(LinphoneCore *lc, char *args);
83 static int lpc_cmd_speak(LinphoneCore *lc, char *args);
84 static int lpc_cmd_acodec(LinphoneCore *lc, char *args);
85 static int lpc_cmd_vcodec(LinphoneCore *lc, char *args);
86 static int lpc_cmd_codec(int type, LinphoneCore *lc, char *args);
87 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args);
88 static int lpc_cmd_echolimiter(LinphoneCore *lc, char *args);
89 static int lpc_cmd_pause(LinphoneCore *lc, char *args);
90 static int lpc_cmd_resume(LinphoneCore *lc, char *args);
91 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args);
92 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args);
93 static int lpc_cmd_playback_gain(LinphoneCore *lc, char *args);
94 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args);
95 #ifdef VIDEO_ENABLED
96 static int lpc_cmd_camera(LinphoneCore *lc, char *args);
97 static int lpc_cmd_video_window(LinphoneCore *lc, char *args);
98 static int lpc_cmd_preview_window(LinphoneCore *lc, char *args);
99 static int lpc_cmd_snapshot(LinphoneCore *lc, char *args);
100 static int lpc_cmd_vfureq(LinphoneCore *lc, char *arg);
101 #endif
102 static int lpc_cmd_states(LinphoneCore *lc, char *args);
103 static int lpc_cmd_identify(LinphoneCore *lc, char *args);
104 static int lpc_cmd_ringback(LinphoneCore *lc, char *args);
105 static int lpc_cmd_conference(LinphoneCore *lc, char *args);
106
107 /* Command handler helpers */
108 static void linphonec_proxy_add(LinphoneCore *lc);
109 static void linphonec_proxy_display(LinphoneProxyConfig *lc);
110 static void linphonec_proxy_list(LinphoneCore *lc);
111 static void linphonec_proxy_remove(LinphoneCore *lc, int index);
112 static  int linphonec_proxy_use(LinphoneCore *lc, int index);
113 static void linphonec_proxy_show(LinphoneCore *lc,int index);
114 static void linphonec_friend_display(LinphoneFriend *fr);
115 static int linphonec_friend_list(LinphoneCore *lc, char *arg);
116 static void linphonec_display_command_help(LPC_COMMAND *cmd);
117 static int linphonec_friend_call(LinphoneCore *lc, unsigned int num);
118 #ifndef WIN32
119 static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
120 #endif
121 static int linphonec_friend_delete(LinphoneCore *lc, int num);
122 static int linphonec_friend_delete(LinphoneCore *lc, int num);
123 static void linphonec_codec_list(int type, LinphoneCore *lc);
124 static void linphonec_codec_enable(int type, LinphoneCore *lc, int index);
125 static void linphonec_codec_disable(int type, LinphoneCore *lc, int index);
126 static void lpc_display_call_states(LinphoneCore *lc);
127
128 /* Command table management */
129 static LPC_COMMAND *lpc_find_command(const char *name);
130
131 void linphonec_out(const char *fmt,...);
132
133 VideoParams lpc_video_params={-1,-1,-1,-1,0,TRUE};
134 VideoParams lpc_preview_params={-1,-1,-1,-1,0,TRUE};
135
136 /***************************************************************************
137  *
138  *  Global variables
139  *
140  ***************************************************************************/
141
142 /*
143  * Commands table.
144  */
145 static LPC_COMMAND commands[] = {
146         { "help", lpc_cmd_help, "Print commands help.",
147                 "'help <command>'\t: displays specific help for command.\n"
148                 "'help advanced'\t: shows advanced commands.\n"
149         },
150         { "call", lpc_cmd_call, "Call a SIP uri or number",
151 #ifdef VIDEO_ENABLED
152                 "'call <sip-url or number>  [options]' \t: initiate a call to the specified destination.\n"
153                 "Options can be:\n"
154                 "--audio-only : initiate the call without video.\n"
155                 "--early-media : sends audio and video stream immediately when remote proposes early media.\n"
156 #else
157                 "'call <sip-url or number>' \t: initiate a call to the specified destination.\n"
158 #endif
159                 },
160         { "calls", lpc_cmd_calls, "Show all the current calls with their id and status.",
161                 NULL
162                 },
163         { "chat", lpc_cmd_chat, "Chat with a SIP uri",
164                 "'chat <sip-url> \"message\"' "
165                 ": send a chat message \"message\" to the specified destination."
166                 },
167         { "terminate", lpc_cmd_terminate, "Terminate a call",
168                 "'terminate' : Terminate the current call\n"
169                 "'terminate <call id>' : Terminate the call with supplied id\n"
170                 "'terminate <all>' : Terminate all the current calls\n"
171                 },
172         { "answer", lpc_cmd_answer, "Answer a call",
173                 "'answer' : Answer the current incoming call\n"
174                 "'answer <call id>' : Answer the call with given id\n"
175         },
176         { "pause", lpc_cmd_pause, "pause a call",
177                 "'pause' : pause the current call\n"},
178         { "resume", lpc_cmd_resume, "resume a call",
179                 "'resume' : resume the unique call\n"
180                 "'resume <call id>' : hold off the call with given id\n"},
181         { "transfer", lpc_cmd_transfer,
182                 "Transfer a call to a specified destination.",
183                 "'transfer <sip-uri>' : transfers the current active call to the destination sip-uri\n"
184                 "'transfer <call id> <sip-uri>': transfers the call with 'id' to the destination sip-uri\n"
185                 "'transfer <call id1> --to-call <call id2>': transfers the call with 'id1' to the destination of call 'id2' (attended transfer)\n"
186         },
187         { "conference", lpc_cmd_conference, "Create and manage an audio conference.",
188                 "'conference add <call id> : join the call with id 'call id' into the audio conference."
189                 "'conference rm <call id> : remove the call with id 'call id' from the audio conference."
190         },
191         { "mute", lpc_cmd_mute_mic, 
192           "Mute microphone and suspend voice transmission."},
193 #ifdef VIDEO_ENABLED
194         { "camera", lpc_cmd_camera, "Send camera output for current call.",
195                 "'camera on'\t: allow sending of local camera video to remote end.\n"
196                 "'camera off'\t: disable sending of local camera's video to remote end.\n"},
197 #endif
198         { "unmute", lpc_cmd_unmute_mic, 
199                   "Unmute microphone and resume voice transmission."},
200         { "playbackgain", lpc_cmd_playback_gain, 
201                   "Adjust playback gain."},
202         { "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
203         
204         { "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
205                 "'autoanswer'       \t: show current autoanswer mode\n"
206                 "'autoanswer enable'\t: enable autoanswer mode\n"
207                 "'autoanswer disable'\t: disable autoanswer modeĀ \n"},
208         { "proxy", lpc_cmd_proxy, "Manage proxies",
209                 "'proxy list' : list all proxy setups.\n"
210                 "'proxy add' : add a new proxy setup.\n"
211                 "'proxy remove <index>' : remove proxy setup with number index.\n"
212                 "'proxy use <index>' : use proxy with number index as default proxy.\n"
213                 "'proxy unuse' : don't use a default proxy.\n"
214                 "'proxy show <index>' : show configuration and status of the proxy numbered by index.\n"
215                 "'proxy show default' : show configuration and status of the default proxy.\n"
216         },
217         { "soundcard", lpc_cmd_soundcard, "Manage soundcards",
218                 "'soundcard list' : list all sound devices.\n"
219                 "'soundcard show' : show current sound devices configuration.\n"
220                 "'soundcard use <index>' : select a sound device.\n"
221                 "'soundcard use files' : use .wav files instead of soundcard\n"
222         },
223         { "webcam", lpc_cmd_webcam, "Manage webcams",
224                 "'webcam list' : list all known devices.\n"
225                 "'webcam use <index>' : select a video device.\n"
226         },
227         { "ipv6", lpc_cmd_ipv6, "Use IPV6",
228                 "'ipv6 status' : show ipv6 usage status.\n"
229                 "'ipv6 enable' : enable the use of the ipv6 network.\n"
230                 "'ipv6 disable' : do not use ipv6 network."
231         },
232         { "nat", lpc_cmd_nat, "Set nat address",
233                 "'nat'        : show nat settings.\n"
234                 "'nat <addr>' : set nat address.\n"
235         },
236         { "stun", lpc_cmd_stun, "Set stun server address",
237                 "'stun'        : show stun settings.\n"
238                 "'stun <addr>' : set stun server address.\n"
239         },
240         { "firewall", lpc_cmd_firewall, "Set firewall policy",
241                 "'firewall'        : show current firewall policy.\n"
242                 "'firewall none'   : use direct connection.\n"
243                 "'firewall nat'    : use nat address given with the 'nat' command.\n"
244                 "'firewall stun'   : use stun server given with the 'stun' command.\n"
245         },
246         { "call-logs", lpc_cmd_call_logs, "Calls history", NULL },
247         { "friend", lpc_cmd_friend, "Manage friends",
248                 "'friend list [<pattern>]'    : list friends.\n"
249                 "'friend call <index>'        : call a friend.\n"
250                 "'friend add <name> <addr>'   : add friend, <name> must be quoted to include\n"
251             "                               spaces, <addr> has \"sip:\" added if it isn't\n"
252             "                               there.  Don't use '<' '>' around <addr>.\n"
253                 "'friend delete <index>'      : remove friend, 'all' removes all\n"
254         },
255         { "play", lpc_cmd_play, "play a wav file",
256                 "This command has two roles:\n"
257                 "Plays a file instead of capturing from soundcard - only available in file mode (see 'help soundcard')\n"
258                 "Specifies a wav file to be played to play music to far end when putting it on hold (pause)\n"
259                 "'play <wav file>'    : play a wav file."
260         },
261         { "record", lpc_cmd_record, "record to a wav file",
262                 "This feature is available only in file mode (see 'help soundcard')\n"
263                 "'record <wav file>'    : record into wav file."
264         },
265         { "quit", lpc_cmd_quit, "Exit linphonec", NULL },
266         { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
267 };
268
269
270 static LPC_COMMAND advanced_commands[] = {
271          { "codec", lpc_cmd_acodec, "Audio codec configuration",
272             "'codec list' : list audio codecs\n"
273             "'codec enable <index>' : enable available audio codec\n"
274             "'codec disable <index>' : disable audio codec" },
275     { "vcodec", lpc_cmd_vcodec, "Video codec configuration",
276             "'vcodec list' : list video codecs\n"
277             "'vcodec enable <index>' : enable available video codec\n"
278             "'vcodec disable <index>' : disable video codec" },
279         { "ec", lpc_cmd_echocancellation, "Echo cancellation",
280             "'ec on [<delay>] [<tail>] [<framesize>]' : turn EC on with given delay, tail length and framesize\n"
281             "'ec off' : turn echo cancellation (EC) off\n"
282             "'ec show' : show EC status" },
283         { "el", lpc_cmd_echolimiter, "Echo limiter",
284             "'el on turns on echo limiter (automatic half duplex, for cases where echo canceller cannot work)\n"
285             "'el off' : turn echo limiter off\n"
286             "'el show' : show echo limiter status" },
287         { "nortp-on-audio-mute", lpc_cmd_rtp_no_xmit_on_audio_mute,
288                   "Set the rtp_no_xmit_on_audio_mute configuration parameter",
289                   "   If set to 1 then rtp transmission will be muted when\n"
290                   "   audio is muted , otherwise rtp is always sent."}, 
291 #ifdef VIDEO_ENABLED
292         { "vwindow", lpc_cmd_video_window, "Control video display window",
293                 "'vwindow show': shows video window\n"
294                 "'vwindow hide': hides video window\n"
295                 "'vwindow pos <x> <y>': Moves video window to x,y pixel coordinates\n"
296                 "'vwindow size <width> <height>': Resizes video window\n"
297                 "'vwindow id <window id>': embeds video display into supplied window id."
298         },
299         { "pwindow", lpc_cmd_preview_window, "Control local camera video display (preview window)",
300                 "'pwindow show': shows the local camera video display\n"
301                 "'pwindow hide': hides the local camera video display\n"
302                 "'pwindow pos <x> <y>': Moves preview window to x,y pixel coordinates\n"
303                 "'pwindow size <width> <height>': Resizes preview window\n"
304                 "'pwindow id <window id>': embeds preview display into supplied window id.\n"
305                 "'pwindow integrated': integrate preview display within the video window of current call.\n"
306                 "'pwindow standalone': use standalone window for preview display."
307         },
308         { "snapshot", lpc_cmd_snapshot, "Take a snapshot of currently received video stream",
309                 "'snapshot <file path>': take a snapshot and records it in jpeg format into the supplied path\n"
310         },
311         { "vfureq", lpc_cmd_vfureq, "Request the other side to send VFU for the current call"},
312 #endif
313         { "states", lpc_cmd_states, "Show internal states of liblinphone, registrations and calls, according to linphonecore.h definitions",
314                 "'states global': shows global state of liblinphone \n"
315                 "'states calls': shows state of calls\n"
316                 "'states proxies': shows state of proxy configurations"
317         },
318         { "register", lpc_cmd_register, "Register in one line to a proxy" , "register <sip identity> <sip proxy> <password>"},
319         { "unregister", lpc_cmd_unregister, "Unregister from default proxy", NULL       },
320         { "status", lpc_cmd_status, "Print various status information", 
321                         "'status register'  \t: print status concerning registration\n"
322                         "'status autoanswer'\t: tell whether autoanswer mode is enabled\n"
323                         "'status hook'      \t: print hook status\n" },
324         { "ports", lpc_cmd_ports, "Network ports configuration", 
325                         "'ports'  \t: prints current used ports.\n"
326                         "'ports sip <port number>'\t: Sets the sip port.\n" },
327         { "param", lpc_cmd_param, "parameter set or read as normally given in .linphonerc",
328                         "'param <section> <parameter> [<value>]'  \t: reads [sets] given parameter.\n"
329                         "NOTES: - changes may become effective after (re)establishing a sip connection.\n"
330                         "       - upon exit, .linphonerc will reflect the updated state.\n" },
331         { "speak", lpc_cmd_speak, "Speak a sentence using espeak TTS engine",
332                         "This feature is available only in file mode. (see 'help soundcard')\n"
333                         "'speak <voice name> <sentence>'        : speak a text using the specified espeak voice.\n"
334                         "Example for english voice: 'speak default Hello my friend !'"
335         },
336         { "staticpic", lpc_cmd_staticpic, "Manage static pictures when nowebcam",
337                 "'staticpic set' : Set path to picture that should be used.\n"
338                 "'staticpic fps' : Get/set frames per seconds for picture emission.\n"
339         },
340         { "identify", lpc_cmd_identify, "Returns the user-agent string of far end",
341                 "'identify' \t: returns remote user-agent string for current call.\n"
342                 "'identify <id>' \t: returns remote user-agent string for call with supplied id.\n"
343         },
344         { "ringback", lpc_cmd_ringback, "Specifies a ringback tone to be played to remote end during incoming calls",
345                 "'ringback <path of mono .wav file>'\t: Specifies a ringback tone to be played to remote end during incoming calls\n"
346                 "'ringback disable'\t: Disable playing of ringback tone to callers\n"
347         },
348         { "redirect", lpc_cmd_redirect, "Redirect an incoming call",
349                 "'redirect <redirect-uri>'\t: Redirect all pending incoming calls to the <redirect-uri>\n"
350         },
351         {       NULL,NULL,NULL,NULL}
352 };
353
354
355
356 /***************************************************************************
357  *
358  *  Public interface 
359  *
360  ***************************************************************************/
361
362 /*
363  * Main command dispatcher.
364  * WARNING: modifies second argument!
365  *
366  * Always return 1 currently.
367  */
368 int
369 linphonec_parse_command_line(LinphoneCore *lc, char *cl)
370 {
371         char *ptr=cl;
372         char *args=NULL;
373         LPC_COMMAND *cmd;
374
375         /* Isolate first word and args */
376         while(*ptr && !isspace(*ptr)) ++ptr;
377         if (*ptr)
378         {
379                 *ptr='\0';
380                 /* set args to first nonblank */
381                 args=ptr+1;
382                 while(*args && isspace(*args)) ++args;
383         }
384
385         /* Handle DTMF */
386         if ( isdigit(*cl) || *cl == '#' || *cl == '*' )
387         {
388                 while ( isdigit(*cl) || *cl == '#' || *cl == '*' )
389                 {
390                         linphone_core_send_dtmf(lc, *cl);
391                         linphone_core_play_dtmf (lc,*cl,100);
392                         ms_sleep(1); // be nice
393                         ++cl;
394                 }
395
396                 // discard spurious trailing chars
397                 return 1;
398         }
399
400         /* Handle other kind of commands */
401         cmd=lpc_find_command(cl);
402         if ( !cmd )
403         {
404                 linphonec_out("'%s': Cannot understand this.\n", cl);
405                 return 1;
406         }
407
408         if ( ! cmd->func(lc, args) )
409         {
410                 linphonec_out("Syntax error.\n");
411                 linphonec_display_command_help(cmd);
412         }
413
414         return 1;
415 }
416
417 /*
418  * Generator function for command completion.
419  * STATE let us know whether to start from scratch;
420  * without any state (STATE==0), then we start at the
421  * top of the list.
422  */
423 char *
424 linphonec_command_generator(const char *text, int state)
425 {
426         static int index, len, adv;
427         char *name;
428
429         if ( ! state )
430         {
431                 index=0;
432                 adv=0;
433                 len=strlen(text);
434         }
435         /*
436          * Return the next name which partially matches
437          * from the commands list
438          */
439         if (adv==0){
440                 while ((name=commands[index].name))
441                 {
442                         ++index; /* so next call get next command */
443
444                         if (strncmp(name, text, len) == 0)
445                         {
446                                 return ortp_strdup(name);
447                         }
448                 }
449                 adv=1;
450                 index=0;
451         }
452         if (adv==1){
453                 while ((name=advanced_commands[index].name))
454                 {
455                         ++index; /* so next call get next command */
456
457                         if (strncmp(name, text, len) == 0)
458                         {
459                                 return ortp_strdup(name);
460                         }
461                 }
462         }
463         return NULL;
464 }
465
466
467 /***************************************************************************
468  *
469  *  Command handlers 
470  *
471  ***************************************************************************/
472
473 static int
474 lpc_cmd_help(LinphoneCore *lc, char *arg)
475 {
476         int i=0;
477         LPC_COMMAND *cmd;
478
479         if (!arg || !*arg)
480         {
481                 linphonec_out("Commands are:\n");
482                 linphonec_out("---------------------------\n");
483
484                 while (commands[i].help)
485                 {
486                         linphonec_out("%10.10s\t%s\n", commands[i].name,
487                                 commands[i].help);
488                         i++;
489                 }
490                 
491                 linphonec_out("---------------------------\n");
492                 linphonec_out("Type 'help <command>' for more details or\n");
493                 linphonec_out("     'help advanced' to list additional commands.\n");
494
495                 return 1;
496         }
497
498         if (strcmp(arg,"advanced")==0){
499                 linphonec_out("Advanced commands are:\n");
500                 linphonec_out("---------------------------\n");
501                 i=0;
502                 while (advanced_commands[i].help)
503                 {
504                         linphonec_out("%10.10s\t%s\n", advanced_commands[i].name,
505                                 advanced_commands[i].help);
506                         i++;
507                 }
508                 
509                 linphonec_out("---------------------------\n");
510                 linphonec_out("Type 'help <command>' for more details.\n");
511
512                 return 1;
513         }
514         
515         cmd=lpc_find_command(arg);
516         if ( !cmd )
517         {
518                 linphonec_out("No such command.\n");
519                 return 1;
520         }
521
522         linphonec_display_command_help(cmd);
523         return 1;
524
525 }
526
527 static char callee_name[256]={0};
528 static char caller_name[256]={0};
529
530
531 static int
532 lpc_cmd_call(LinphoneCore *lc, char *args)
533 {
534         if ( ! args || ! *args )
535         {
536                 return 0;
537         }
538         {
539                 LinphoneCall *call;
540                 LinphoneCallParams *cp=linphone_core_create_default_call_parameters (lc);
541                 char *opt1,*opt2;
542                 if ( linphone_core_in_call(lc) )
543                 {
544                         linphonec_out("Terminate or hold on the current call first.\n");
545                         return 1;
546                 }
547                 opt1=strstr(args,"--audio-only");
548                 opt2=strstr(args,"--early-media");
549                 if (opt1){
550                         opt1[0]='\0';
551                         linphone_call_params_enable_video (cp,FALSE);
552                 }
553                 if (opt2){
554                         opt2[0]='\0';
555                         linphone_call_params_enable_early_media_sending(cp,TRUE);
556                 }
557                 if ( NULL == (call=linphone_core_invite_with_params(lc, args,cp)) )
558                 {
559                         linphonec_out("Error from linphone_core_invite.\n");
560                 }
561                 else
562                 {
563                         snprintf(callee_name,sizeof(callee_name),"%s",args);
564                 }
565                 linphone_call_params_destroy(cp);
566         }
567         return 1;
568 }
569
570 static int 
571 lpc_cmd_calls(LinphoneCore *lc, char *args){
572         const MSList *calls = linphone_core_get_calls(lc);
573         if(calls)
574         {
575                 lpc_display_call_states(lc);
576         }else
577         {
578                 linphonec_out("No active call.\n");
579         }
580         return 1;
581 }
582
583
584 static int
585 lpc_cmd_chat(LinphoneCore *lc, char *args)
586 {
587         char *arg1 = args;
588         char *arg2 = NULL;
589         char *ptr = args;
590
591         if (!args) return 0;
592
593         /* Isolate first and second arg */
594         while(*ptr && !isspace(*ptr)) ++ptr;
595         if ( *ptr )
596         {
597                 *ptr='\0';
598                 arg2=ptr+1;
599                 while(*arg2 && isspace(*arg2)) ++arg2;
600         }
601         else
602         {
603                 /* missing one parameter */
604                 return 0;
605         }
606         LinphoneChatRoom *cr = linphone_core_create_chat_room(lc,arg1);
607         linphone_chat_room_send_message(cr,arg2);
608         linphone_chat_room_destroy(cr);
609
610         return 1;
611 }
612
613 const char *linphonec_get_callee(){
614         return callee_name;
615 }
616
617 const char *linphonec_get_caller(){
618         return caller_name;
619 }
620
621 void linphonec_set_caller(const char *caller){
622         snprintf(caller_name,sizeof(caller_name)-1,"%s",caller);
623 }
624
625 static int
626 lpc_cmd_transfer(LinphoneCore *lc, char *args)
627 {
628         if (args){
629                 LinphoneCall *call;
630                 LinphoneCall *call2;
631                 const char *refer_to=NULL;
632                 char arg1[256]={0};
633                 char arg2[266]={0};
634                 long id2=0;
635                 int n=sscanf(args,"%s %s %li",arg1,arg2,&id2);
636                 if (n==1 || isalpha(*arg1)){
637                         call=linphone_core_get_current_call(lc);
638                         if (call==NULL && ms_list_size(linphone_core_get_calls(lc))==1){
639                                 call=(LinphoneCall*)linphone_core_get_calls(lc)->data;
640                         }
641                         refer_to=args;
642                         if (call==NULL){
643                                 linphonec_out("No active call, please specify a call id among the ones listed by 'calls' command.\n");
644                                 return 0;
645                         }
646                         linphone_core_transfer_call(lc, call, refer_to);
647                 }else if (n==2){
648                         long id=atoi(arg1);
649                         refer_to=args+strlen(arg1)+1;
650                         call=linphonec_get_call(id);
651                         if (call==NULL) return 0;
652                         linphone_core_transfer_call(lc, call, refer_to);
653                 }else if (n==3){
654                         long id=atoi(arg1);
655                         call=linphonec_get_call(id);
656                         call2=linphonec_get_call(id2);
657                         if (call==NULL || call2==NULL) return 0;
658                         if (strcmp(arg2,"--to-call")!=0){
659                                 return 0;
660                         }
661                         linphonec_out("Performing attended transfer of call %i to call %i",id,id2);
662                         linphone_core_transfer_call_to_another (lc,call,call2);
663                 }else return 0;
664         }else{
665                 linphonec_out("Transfer command requires at least one argument\n");
666                 return 0;
667         }
668         return 1;
669 }
670
671 static int
672 lpc_cmd_terminate(LinphoneCore *lc, char *args)
673 {
674         if (linphone_core_get_calls(lc)==NULL){
675                 linphonec_out("No active calls\n");
676                 return 1;
677         }
678         if (!args)
679         {
680                 if ( -1 == linphone_core_terminate_call(lc, NULL) ){
681                         linphonec_out("Could not stop the active call.\n");
682                 }
683                 return 1;
684         }
685         
686         if(strcmp(args,"all")==0){
687                 linphonec_out("We are going to stop all the calls.\n");
688                 linphone_core_terminate_all_calls(lc);
689                 return 1;
690         }else{
691                 /*the argument is a linphonec call id */
692                 long id=atoi(args);
693                 LinphoneCall *call=linphonec_get_call(id);
694                 if (call){
695                         if (linphone_core_terminate_call(lc,call)==-1){
696                                 linphonec_out("Could not stop the call with id %li\n",id);
697                         }
698                 }else return 0;
699                 return 1;
700         }
701         return 0;
702         
703 }
704
705 static int
706 lpc_cmd_redirect(LinphoneCore *lc, char *args){
707         const MSList *elem;
708         int didit=0;
709         if (!args) return 0;
710         if ((elem=linphone_core_get_calls(lc))==NULL){
711                 linphonec_out("No active calls.\n");
712                 return 1;
713         }
714         while(elem!=NULL){
715                 LinphoneCall *call=(LinphoneCall*)elem->data;
716                 if (linphone_call_get_state(call)==LinphoneCallIncomingReceived){
717                         linphone_core_redirect_call(lc,call,args);
718                         didit=1;
719                         /*as the redirection closes the call, we need to re-check the call list that is invalidated.*/
720                         elem=linphone_core_get_calls(lc);
721                 }else elem=elem->next;
722         }
723         if (didit==0){
724                 linphonec_out("There is no pending incoming call to redirect.");
725         }
726         return 1;
727 }
728
729 static int
730 lpc_cmd_answer(LinphoneCore *lc, char *args){
731         if (!args)
732         {
733                 int nb=ms_list_size(linphone_core_get_calls(lc));
734                 if (nb==1){
735                         //if just one call is present answer the only one in passing NULL to the linphone_core_accept_call ...
736                         if ( -1 == linphone_core_accept_call(lc, NULL) )
737                         {
738                                 linphonec_out("Fail to accept incoming call\n");
739                         }
740                 }else if (nb==0){
741                         linphonec_out("There are no calls to answer.\n");
742                 }else{
743                         linphonec_out("Multiple calls in progress, please specify call id.\n");
744                         return 0;
745                 }
746                 return 1;
747         }else{
748                 long id;
749                 if (sscanf(args,"%li",&id)==1){
750                         LinphoneCall *call=linphonec_get_call (id);
751                         if (linphone_core_accept_call (lc,call)==-1){
752                                 linphonec_out("Fail to accept call %i\n",id);
753                         }
754                 }else return 0;
755                 return 1;
756         }
757         return 0;
758 }
759
760 static int
761 lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
762 {
763         if ( ! args )
764         {
765                 if ( linphonec_get_autoanswer() ) {
766                         linphonec_out("Auto answer is enabled. Use 'autoanswer disable' to disable.\n");
767                 } else {
768                         linphonec_out("Auto answer is disabled. Use 'autoanswer enable' to enable.\n");
769                 }
770                 return 1;
771         }
772
773         if (strstr(args,"enable")){
774                 linphonec_set_autoanswer(TRUE);
775                 linphonec_out("Auto answer enabled.\n");
776         }else if (strstr(args,"disable")){
777                 linphonec_set_autoanswer(FALSE);
778                 linphonec_out("Auto answer disabled.\n");
779         }else return 0;
780         return 1;
781 }
782
783 static int
784 lpc_cmd_quit(LinphoneCore *lc, char *args)
785 {
786         linphonec_main_loop_exit();
787         return 1;
788 }
789
790 static int
791 lpc_cmd_nat(LinphoneCore *lc, char *args)
792 {
793         bool_t use;
794         const char *nat;
795
796         if ( args ) args=lpc_strip_blanks(args);
797
798         if ( args && *args )
799         {
800                 linphone_core_set_nat_address(lc, args);
801                 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS); */
802         }
803
804         nat = linphone_core_get_nat_address(lc);
805         use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress;
806         linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
807
808         return 1;
809 }
810
811 static int
812 lpc_cmd_stun(LinphoneCore *lc, char *args)
813 {
814         bool_t use;
815         const char *stun;
816
817         if ( args ) args=lpc_strip_blanks(args);
818
819         if ( args && *args )
820         {
821                 linphone_core_set_stun_server(lc, args);
822                 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN); */
823         }
824
825         stun = linphone_core_get_stun_server(lc);
826         use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseStun;
827         linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
828
829         return 1;
830 }
831
832 static int
833 lpc_cmd_firewall(LinphoneCore *lc, char *args)
834 {
835         const char* setting=NULL;
836
837         if ( args ) args=lpc_strip_blanks(args);
838
839         if ( args && *args )
840         {
841                 if (strcmp(args,"none")==0)
842                 {
843                         linphone_core_set_firewall_policy(lc,LinphonePolicyNoFirewall);
844                 }
845                 else if (strcmp(args,"stun")==0)
846                 {
847                         setting = linphone_core_get_stun_server(lc);
848                         if ( ! setting )
849                         {
850                                 linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
851                                 return 1;
852                         }
853                         linphone_core_set_firewall_policy(lc,LinphonePolicyUseStun);
854                 }
855                 else if (strcmp(args,"nat")==0)
856                 {
857                         setting = linphone_core_get_nat_address(lc);
858                         if ( ! setting )
859                         {
860                                 linphonec_out("No nat address is defined, use 'nat <address>' first");
861                                 return 1;
862                         }
863                         linphone_core_set_firewall_policy(lc,LinphonePolicyUseNatAddress);
864                 }
865         }
866
867         switch(linphone_core_get_firewall_policy(lc))
868         {
869                 case LinphonePolicyNoFirewall:
870                         linphonec_out("No firewall\n");
871                         break;
872                 case LinphonePolicyUseStun:
873                         linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
874                         break;
875                 case LinphonePolicyUseNatAddress:
876                         linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
877                         break;
878         }
879         return 1;
880 }
881
882 #ifndef WIN32
883 /* Helper function for processing freind names */
884 static int
885 lpc_friend_name(char **args, char **name)
886 {
887         /* Use space as a terminator unless quoted */
888         if (('"' == **args) || ('\'' == **args)){
889                 char *end;
890                 char delim = **args;
891                 (*args)++;
892                 end = (*args);
893                 while ((delim != *end) && ('\0' != *end)) end++;
894                 if ('\0' == *end) {
895                         fprintf(stderr, "Mismatched quotes\n");
896                         return 0;
897                 }
898                 *name = *args;
899                 *end = '\0';
900                 *args = ++end;
901         } else {
902                 *name = strsep(args, " ");
903                 
904                 if (NULL == *args) { /* Means there was no separator */
905                         fprintf(stderr, "Either name or address is missing\n");
906                         return 0;
907                 }
908                 if (NULL == *name) return 0;
909         }
910         return 1;
911 }
912 #endif
913
914 static int
915 lpc_cmd_friend(LinphoneCore *lc, char *args)
916 {
917         int friend_num;
918
919         if ( args ) args=lpc_strip_blanks(args);
920
921         if ( ! args || ! *args ) return 0;
922
923         if ( !strncmp(args, "list", 4) )
924         {
925                 return linphonec_friend_list(lc, args+4);
926                 return 1;
927         }
928         else if ( !strncmp(args, "call", 4) )
929         {
930                 args+=4;
931                 if ( ! *args ) return 0;
932                 friend_num = strtol(args, NULL, 10);
933 #ifndef _WIN32_WCE              
934                 if ( errno == ERANGE ) {
935                         linphonec_out("Invalid friend number\n");
936                         return 0;
937                 }
938 #endif /*_WIN32_WCE*/
939                 linphonec_friend_call(lc, friend_num);
940                 return 1;
941         }
942         else if ( !strncmp(args, "delete", 6) )
943         {
944                 args+=6;
945                 if ( ! *args ) return 0;
946                 while (*args == ' ') args++;
947                 if ( ! *args ) return 0;
948                 if (!strncmp(args, "all", 3))
949                 {
950                         friend_num = -1;
951                 } 
952                 else
953                 {
954                         friend_num = strtol(args, NULL, 10);
955 #ifndef _WIN32_WCE              
956                         if ( errno == ERANGE ) {
957                                 linphonec_out("Invalid friend number\n");
958                                 return 0;
959                         }
960 #endif /*_WIN32_WCE*/
961                 }
962                 linphonec_friend_delete(lc, friend_num);
963                 return 1;
964         }
965         else if ( !strncmp(args, "add", 3) )
966         {
967 #ifndef WIN32
968                 char  *name;
969                 char  addr[80];
970                 char *addr_p = addr;
971                 char *addr_orig;
972
973                 args+=3;
974                 if ( ! *args ) return 0;
975                 while (*args == ' ') args++;
976                 if ( ! *args ) return 0;
977
978                 if (!lpc_friend_name(&args,  &name)) return 0;
979
980                 while (*args == ' ') args++;
981                 if ( ! *args ) return 0;
982                 if (isdigit(*args)) {
983                         strcpy (addr, "sip:");
984                         addr_p = addr + strlen("sip:");
985                 }
986                 addr_orig = strsep(&args, " ");
987                 if (1 >= strlen(addr_orig)) {
988                         fprintf(stderr, "A single-digit address is not valid\n");
989                         return 0;
990                 }
991                 strcpy(addr_p, addr_orig);
992                 linphonec_friend_add(lc, name, addr);
993 #else
994                 LinphoneFriend *new_friend;
995                 new_friend = linphone_friend_new_with_addr(args);
996                 linphone_core_add_friend(lc, new_friend);
997 #endif
998                 return 1;
999         }
1000         return 0;
1001 }
1002
1003 static int lpc_cmd_play(LinphoneCore *lc, char *args){
1004         if ( args ) args=lpc_strip_blanks(args);
1005         if ( ! args || ! *args ) return 0;
1006         linphone_core_set_play_file(lc,args);
1007         return 1;
1008 }
1009
1010 static int lpc_cmd_record(LinphoneCore *lc, char *args){
1011         if ( args ) args=lpc_strip_blanks(args);
1012         if ( ! args || ! *args ) return 0;
1013         linphone_core_set_record_file(lc,args);
1014         return 1;
1015 }
1016
1017 /*
1018  * Modified input
1019  */
1020 static int
1021 lpc_cmd_proxy(LinphoneCore *lc, char *args)
1022 {
1023         char *arg1 = args;
1024         char *arg2 = NULL;
1025         char *ptr = args;
1026         int proxynum;
1027
1028         if ( ! arg1 ) return 0;
1029
1030         /* Isolate first and second arg */
1031         while(*ptr && !isspace(*ptr)) ++ptr;
1032         if ( *ptr )
1033         {
1034                 *ptr='\0';
1035                 arg2=ptr+1;
1036                 while(*arg2 && isspace(*arg2)) ++arg2;
1037         }
1038
1039         if (strcmp(arg1,"add")==0)
1040         {
1041 #ifdef HAVE_READLINE
1042                 rl_inhibit_completion=1;
1043 #endif
1044                 linphonec_proxy_add(lc);
1045 #ifdef HAVE_READLINE
1046                 rl_inhibit_completion=0;
1047 #endif
1048         }
1049         else if (strcmp(arg1,"list")==0)
1050         {
1051                 linphonec_proxy_list(lc);
1052         }
1053         else if (strcmp(arg1,"remove")==0)
1054         {
1055                 linphonec_proxy_remove(lc,atoi(arg2));
1056         }
1057         else if (strcmp(arg1,"use")==0)
1058         {
1059                 if ( arg2 && *arg2 )
1060                 {
1061                         proxynum=atoi(arg2);
1062                         if ( linphonec_proxy_use(lc, proxynum) )
1063                                 linphonec_out("Default proxy set to %d.\n", proxynum);
1064                 }
1065                 else
1066                 {
1067                         proxynum=linphone_core_get_default_proxy(lc, NULL);
1068                         if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
1069                         else linphonec_out("Current default proxy is %d.\n", proxynum);
1070                 }
1071         }else if (strcmp(arg1, "unuse")==0){
1072                 linphone_core_set_default_proxy(lc, NULL);
1073                 linphonec_out("Use no proxy.\n");
1074         }
1075
1076         else if (strcmp(arg1, "show")==0)
1077         {
1078                 if (arg2 && *arg2)
1079                 {
1080                         if (strstr(arg2,"default"))
1081                         {
1082                 proxynum=linphone_core_get_default_proxy(lc, NULL);
1083                 if ( proxynum < 0 ) {
1084                         linphonec_out("No default proxy defined\n");
1085                         return 1;
1086                 }
1087                 linphonec_proxy_show(lc,proxynum);
1088                         }
1089                         else
1090                         {
1091                 linphonec_proxy_show(lc, atoi(arg2));
1092                         }
1093                 }
1094                 else return 0; /* syntax error */
1095         }
1096
1097         else
1098         {
1099                 return 0; /* syntax error */
1100         }
1101
1102         return 1;
1103 }
1104
1105 static int
1106 lpc_cmd_call_logs(LinphoneCore *lc, char *args)
1107 {
1108         const MSList *elem=linphone_core_get_call_logs(lc);
1109         for (;elem!=NULL;elem=ms_list_next(elem))
1110         {
1111                 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
1112                 char *str=linphone_call_log_to_str(cl);
1113                 linphonec_out("%s\n",str);
1114                 ms_free(str);
1115         }
1116         return 1;
1117 }
1118
1119 static int
1120 lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
1121 {
1122         if ( ! arg1 )
1123         {
1124                 return 0; /* syntax error */
1125         }
1126
1127         if (strcmp(arg1,"status")==0)
1128         {
1129                 linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
1130         }
1131         else if (strcmp(arg1,"enable")==0)
1132         {
1133                 linphone_core_enable_ipv6(lc,TRUE);
1134                 linphonec_out("ipv6 use enabled.\n");
1135         }
1136         else if (strcmp(arg1,"disable")==0)
1137         {
1138                 linphone_core_enable_ipv6(lc,FALSE);
1139                 linphonec_out("ipv6 use disabled.\n");
1140         }
1141         else
1142         {
1143                 return 0; /* syntax error */
1144         }
1145         return 1;
1146 }
1147
1148 static int devname_to_index(LinphoneCore *lc, const char *devname){
1149         const char **p;
1150         int i;
1151         for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1152                 if (strcmp(devname,*p)==0) return i;
1153         }
1154         return -1;
1155 }
1156
1157 static const char *index_to_devname(LinphoneCore *lc, int index){
1158         const char **p;
1159         int i;
1160         for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1161                 if (i==index) return *p;
1162         }
1163         return NULL;
1164 }
1165
1166 static int lpc_cmd_soundcard(LinphoneCore *lc, char *args)
1167 {
1168         int i, index;
1169         const char **dev;
1170         char *arg1 = args;
1171         char *arg2 = NULL;
1172         char *ptr = args;
1173
1174         if (!args) return 0; /* syntax error */
1175
1176         /* Isolate first and second arg */
1177         while(*ptr && !isspace(*ptr)) ++ptr;
1178         if ( *ptr )
1179         {
1180                 *ptr='\0';
1181                 arg2=ptr+1;
1182                 while(*arg2 && isspace(*arg2)) ++arg2;
1183         }
1184
1185         if (strcmp(arg1, "list")==0)
1186         {
1187                 dev=linphone_core_get_sound_devices(lc);
1188                 for(i=0; dev[i]!=NULL; ++i){
1189                         linphonec_out("%i: %s\n",i,dev[i]);
1190                 }
1191                 return 1;
1192         }
1193
1194         if (strcmp(arg1, "show")==0)
1195         {
1196                 linphonec_out("Ringer device: %s\n",
1197                         linphone_core_get_ringer_device(lc));
1198                 linphonec_out("Playback device: %s\n",
1199                         linphone_core_get_playback_device(lc));
1200                 linphonec_out("Capture device: %s\n",
1201                         linphone_core_get_capture_device(lc));
1202                 return 1;
1203         }
1204
1205         if (strcmp(arg1, "use")==0 && arg2)
1206         {
1207                 if (strcmp(arg2, "files")==0)
1208                 {
1209                         linphonec_out("Using wav files instead of soundcard.\n");
1210                         linphone_core_use_files(lc,TRUE);
1211                         return 1;
1212                 }
1213
1214                 dev=linphone_core_get_sound_devices(lc);
1215                 index=atoi(arg2); /* FIXME: handle not-a-number */
1216                 for(i=0;dev[i]!=NULL;i++)
1217                 {
1218                         if (i!=index) continue;
1219
1220                         linphone_core_set_ringer_device(lc,dev[i]);
1221                         linphone_core_set_playback_device(lc,dev[i]);
1222                         linphone_core_set_capture_device(lc,dev[i]);
1223                         linphonec_out("Using sound device %s\n",dev[i]);
1224                         return 1;
1225                 }
1226                 linphonec_out("No such sound device\n");
1227                 return 1;
1228         }
1229         if (strcmp(arg1, "capture")==0)
1230         {
1231                 const char *devname=linphone_core_get_capture_device(lc);
1232                 if (!arg2){
1233                         linphonec_out("Using capture device #%i (%s)\n",
1234                                         devname_to_index(lc,devname),devname);
1235                 }else{
1236                         index=atoi(arg2); /* FIXME: handle not-a-number */
1237                         devname=index_to_devname(lc,index);
1238                         if (devname!=NULL){
1239                                 linphone_core_set_capture_device(lc,devname);
1240                                 linphonec_out("Using capture sound device %s\n",devname);
1241                                 return 1;
1242                         }
1243                         linphonec_out("No such sound device\n");
1244                 }
1245                 return 1;
1246         }
1247         if (strcmp(arg1, "playback")==0)
1248         {
1249                 const char *devname=linphone_core_get_playback_device(lc);
1250                 if (!arg2){
1251                         linphonec_out("Using playback device #%i (%s)\n",
1252                                         devname_to_index(lc,devname),devname);
1253                 }else{
1254                         index=atoi(arg2); /* FIXME: handle not-a-number */
1255                         devname=index_to_devname(lc,index);
1256                         if (devname!=NULL){
1257                                 linphone_core_set_playback_device(lc,devname);
1258                                 linphonec_out("Using playback sound device %s\n",devname);
1259                                 return 1;
1260                         }
1261                         linphonec_out("No such sound device\n");
1262                 }
1263                 return 1;
1264         }
1265         if (strcmp(arg1, "ring")==0)
1266         {
1267                 const char *devname=linphone_core_get_ringer_device(lc);
1268                 if (!arg2){
1269                         linphonec_out("Using ring device #%i (%s)\n",
1270                                         devname_to_index(lc,devname),devname);
1271                 }else{
1272                         index=atoi(arg2); /* FIXME: handle not-a-number */
1273                         devname=index_to_devname(lc,index);
1274                         if (devname!=NULL){
1275                                 linphone_core_set_ringer_device(lc,devname);
1276                                 linphonec_out("Using ring sound device %s\n",devname);
1277                                 return 1;
1278                         }
1279                         linphonec_out("No such sound device\n");
1280                 }
1281                 return 1;
1282         }
1283         return 0; /* syntax error */
1284 }
1285
1286 static int lpc_cmd_webcam(LinphoneCore *lc, char *args)
1287 {
1288         int i, index;
1289         const char **dev;
1290         char *arg1 = args;
1291         char *arg2 = NULL;
1292         char *ptr = args;
1293
1294         if (!args) return 0; /* syntax error */
1295
1296         /* Isolate first and second arg */
1297         while(*ptr && !isspace(*ptr)) ++ptr;
1298         if ( *ptr )
1299         {
1300                 *ptr='\0';
1301                 arg2=ptr+1;
1302                 while(*arg2 && isspace(*arg2)) ++arg2;
1303         }
1304
1305         if (strcmp(arg1, "list")==0)
1306         {
1307                 dev=linphone_core_get_video_devices(lc);
1308                 for(i=0; dev[i]!=NULL; ++i){
1309                         linphonec_out("%i: %s\n",i,dev[i]);
1310                 }
1311                 return 1;
1312         }
1313
1314         if (strcmp(arg1, "use")==0 && arg2)
1315         {
1316                 dev=linphone_core_get_video_devices(lc);
1317                 index=atoi(arg2); /* FIXME: handle not-a-number */
1318                 for(i=0;dev[i]!=NULL;i++)
1319                 {
1320                         if (i!=index) continue;
1321
1322                         linphone_core_set_video_device(lc, dev[i]);
1323                         linphonec_out("Using video device %s\n",dev[i]);
1324                         return 1;
1325                 }
1326                 linphonec_out("No such video device\n");
1327                 return 1;
1328         }
1329         return 0; /* syntax error */
1330 }
1331
1332 static int
1333 lpc_cmd_staticpic(LinphoneCore *lc, char *args)
1334 {
1335         char *arg1 = args;
1336         char *arg2 = NULL;
1337         char *ptr = args;
1338
1339         if (!args) return 0;  /* Syntax error */
1340
1341         /* Isolate first and second arg */
1342         while(*ptr && !isspace(*ptr)) ++ptr;
1343         if ( *ptr )
1344         {
1345                 *ptr='\0';
1346                 arg2=ptr+1;
1347                 while(*arg2 && isspace(*arg2)) ++arg2;
1348         }
1349
1350         if (strcmp(arg1, "set")==0 && arg2) {
1351                 linphone_core_set_static_picture(lc, arg2);
1352                 return 1;
1353         }
1354
1355         if (strcmp(arg1, "fps")==0) {
1356           if (arg2) {
1357                 float fps = atof(arg2); /* FIXME: Handle not-a-float */
1358                 linphone_core_set_static_picture_fps(lc, fps);
1359                 return 1;
1360           } else {
1361                 float fps;
1362                 fps = linphone_core_get_static_picture_fps(lc);
1363                 linphonec_out("Current FPS %f\n", fps);
1364                 return 1;
1365           }
1366         }
1367
1368         return 0; /* Syntax error */
1369 }
1370
1371 static int lpc_cmd_pause(LinphoneCore *lc, char *args){
1372
1373         if(linphone_core_in_call(lc))
1374         {
1375                 linphone_core_pause_call(lc,linphone_core_get_current_call(lc));
1376                 return 1;
1377         }
1378         linphonec_out("you can only pause when a call is in process\n");
1379     return 0;
1380 }
1381
1382 static int lpc_cmd_resume(LinphoneCore *lc, char *args){
1383         
1384         if(linphone_core_in_call(lc))
1385         {
1386                 linphonec_out("There is already a call in process pause or stop it first");
1387                 return 1;
1388         }
1389         if (args)
1390         {
1391                 long id;
1392                 int n = sscanf(args, "%li", &id);
1393                 if (n == 1){
1394                         LinphoneCall *call=linphonec_get_call (id);
1395                         if (call){
1396                                 if(linphone_core_resume_call(lc,call)==-1){
1397                                         linphonec_out("There was a problem to resume the call check the remote address you gave %s\n",args);
1398                                 }
1399                         }
1400                         return 1;
1401                 }else return 0;
1402         }
1403         else
1404         {
1405                 const MSList *calls = linphone_core_get_calls(lc);
1406                 int nbcalls=ms_list_size(calls);
1407                 if( nbcalls == 1)
1408                 {
1409                         if(linphone_core_resume_call(lc,calls->data) < 0)
1410                         {
1411                                 linphonec_out("There was a problem to resume the unique call.\n");
1412                         }
1413                         return 1;
1414                 }else if (nbcalls==0){
1415                         linphonec_out("There is no calls at this time.\n");
1416                         return 1;
1417                 }else{
1418                         linphonec_out("There are %i calls at this time, please specify call id as given with 'calls' command.\n");
1419                 }
1420         }
1421         return 0;
1422     
1423 }
1424
1425 static int lpc_cmd_conference(LinphoneCore *lc, char *args){
1426         long id;
1427         char subcommand[32]={0};
1428         int n;
1429         if (args==NULL) return 0;
1430         n=sscanf(args, "%31s %li", subcommand,&id);
1431         if (n == 2){
1432                 LinphoneCall *call=linphonec_get_call(id);
1433                 if (call==NULL) return 1;
1434                 if (strcmp(subcommand,"add")==0){
1435                         linphone_core_add_to_conference(lc,call);
1436                         return 1;
1437                 }else if (strcmp(subcommand,"rm")==0){
1438                         linphone_core_remove_from_conference(lc,call);
1439                         return 1;
1440                 }else if (strcmp(subcommand,"enter")==0){
1441                         linphone_core_enter_conference(lc);
1442                         return 1;
1443                 }else if (strcmp(subcommand,"leave")==0){
1444                         linphone_core_leave_conference(lc);
1445                         return 1;
1446                 }
1447         }
1448         return 0;
1449 }
1450
1451 /***************************************************************************
1452  *
1453  *  Commands helper functions
1454  *
1455  ***************************************************************************/
1456
1457
1458 static void
1459 linphonec_proxy_add(LinphoneCore *lc)
1460 {
1461         bool_t enable_register=FALSE;
1462         LinphoneProxyConfig *cfg;
1463
1464         linphonec_out("Adding new proxy setup. Hit ^D to abort.\n");
1465
1466         /*
1467          * SIP Proxy address
1468          */
1469         while (1)
1470         {
1471                 char *input=linphonec_readline("Enter proxy sip address: ");
1472                 char *clean;
1473
1474                 if ( ! input ) {
1475                         linphonec_out("Aborted.\n");
1476                         return;
1477                 }
1478
1479                 /* Strip blanks */
1480                 clean=lpc_strip_blanks(input);
1481                 if ( ! *clean ) {
1482                         free(input);
1483                         continue;
1484                 }
1485
1486                 cfg=linphone_proxy_config_new();
1487                 if (linphone_proxy_config_set_server_addr(cfg,clean)<0)
1488                 {
1489                         linphonec_out("Invalid sip address (sip:sip.domain.tld).\n");
1490                         free(input);
1491                         linphone_proxy_config_destroy(cfg);
1492                         continue;
1493                 }
1494                 free(input);
1495                 break;
1496         }
1497
1498         /*
1499          * SIP Proxy identity
1500          */
1501         while (1)
1502         {
1503                 char *input=linphonec_readline("Your identity for this proxy: ");
1504                 char *clean;
1505
1506                 if ( ! input ) {
1507                         linphonec_out("Aborted.\n");
1508                         linphone_proxy_config_destroy(cfg);
1509                         return;
1510                 }
1511
1512                 /* Strip blanks */
1513                 clean=lpc_strip_blanks(input);
1514                 if ( ! *clean ) {
1515                         free(input);
1516                         continue;
1517                 }
1518
1519                 linphone_proxy_config_set_identity(cfg, clean);
1520                 if ( ! linphone_proxy_config_get_identity (cfg))
1521                 {
1522                         linphonec_out("Invalid identity (sip:name@sip.domain.tld).\n");
1523                         free(input);
1524                         continue;
1525                 }
1526                 free(input);
1527                 break;
1528         }
1529
1530         /*
1531          * SIP Proxy enable register
1532          */
1533         while (1)
1534         {
1535                 char *input=linphonec_readline("Do you want to register on this proxy (yes/no): ");
1536                 char *clean;
1537
1538                 if ( ! input ) {
1539                         linphonec_out("Aborted.\n");
1540                         linphone_proxy_config_destroy(cfg);
1541                         return;
1542                 }
1543
1544                 /* Strip blanks */
1545                 clean=lpc_strip_blanks(input);
1546                 if ( ! *clean ) {
1547                         free(input);
1548                         continue;
1549                 }
1550
1551                 if ( ! strcmp(clean, "yes") ) enable_register=TRUE;
1552                 else if ( ! strcmp(clean, "no") ) enable_register=FALSE;
1553                 else {
1554                         linphonec_out("Please answer with 'yes' or 'no'\n");
1555                         free(input);
1556                         continue;
1557                 }
1558                 linphone_proxy_config_enableregister(cfg, enable_register);
1559                 free(input);
1560                 break;
1561         }
1562
1563         /*
1564          * SIP Proxy registration expiration
1565          */
1566         if ( enable_register==TRUE )
1567         {
1568                 long int expires=0;
1569                 while (1)
1570                 {
1571                         char *input=linphonec_readline("Specify register expiration time"
1572                                 " in seconds (default is 600): ");
1573
1574                         if ( ! input ) {
1575                                 linphonec_out("Aborted.\n");
1576                                 linphone_proxy_config_destroy(cfg);
1577                                 return;
1578                         }
1579
1580                         expires=strtol(input, (char **)NULL, 10);
1581                         if ( expires == LONG_MIN || expires == LONG_MAX )
1582                         {
1583                                 linphonec_out("Invalid value: %s\n", strerror(errno));
1584                                 free(input);
1585                                 continue;
1586                         }
1587
1588                         linphone_proxy_config_expires(cfg, expires);
1589                         linphonec_out("Expiration: %d seconds\n", linphone_proxy_config_get_expires (cfg));
1590
1591                         free(input);
1592                         break;
1593                 }
1594         }
1595
1596         /*
1597          * SIP proxy route
1598          */
1599         while (1)
1600         {
1601                 char *input=linphonec_readline("Specify route if needed: ");
1602                 char *clean;
1603
1604                 if ( ! input ) {
1605                         linphonec_out("Aborted.\n");
1606                         linphone_proxy_config_destroy(cfg);
1607                         return;
1608                 }
1609
1610                 /* Strip blanks */
1611                 clean=lpc_strip_blanks(input);
1612                 if ( ! *clean ) {
1613                         free(input);
1614                         linphonec_out("No route specified.\n");
1615                         break;
1616                 }
1617
1618                 linphone_proxy_config_set_route(cfg, clean);
1619                 if ( ! linphone_proxy_config_get_route(cfg) )
1620                 {
1621                         linphonec_out("Invalid route.\n");
1622                         free(input);
1623                         continue;
1624                 }
1625
1626                 free(input);
1627                 break;
1628         }
1629
1630         /*
1631          * Final confirmation 
1632          */
1633         while (1)
1634         {
1635                 char *input;
1636                 char *clean;
1637
1638                 linphonec_out("--------------------------------------------\n");
1639                 linphonec_proxy_display(cfg);
1640                 linphonec_out("--------------------------------------------\n");
1641                 input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: ");
1642
1643
1644                 if ( ! input ) {
1645                         linphonec_out("Aborted.\n");
1646                         linphone_proxy_config_destroy(cfg);
1647                         return;
1648                 }
1649
1650                 /* Strip blanks */
1651                 clean=lpc_strip_blanks(input);
1652                 if ( ! *clean ) {
1653                         free(input);
1654                         continue;
1655                 }
1656
1657                 if ( ! strcmp(clean, "yes") ) break;
1658                 else if ( ! strcmp(clean, "no") )
1659                 {
1660                         linphonec_out("Declined.\n");
1661                         linphone_proxy_config_destroy(cfg);
1662                         free(input);
1663                         return;
1664                 }
1665
1666                 linphonec_out("Please answer with 'yes' or 'no'\n");
1667                 free(input);
1668                 continue;
1669         }
1670
1671
1672         linphone_core_add_proxy_config(lc,cfg);
1673
1674         /* automatically set the last entered proxy as the default one */
1675         linphone_core_set_default_proxy(lc,cfg);
1676
1677         linphonec_out("Proxy added.\n");
1678 }
1679
1680 static void
1681 linphonec_proxy_display(LinphoneProxyConfig *cfg)
1682 {
1683         const char *route=linphone_proxy_config_get_route(cfg);
1684         const char *identity=linphone_proxy_config_get_identity(cfg);
1685         linphonec_out("sip address: %s\nroute: %s\nidentity: %s\nregister: %s\nexpires: %i\nregistered: %s\n",
1686                         linphone_proxy_config_get_addr(cfg),
1687                         (route!=NULL)? route:"",
1688                         (identity!=NULL)?identity:"",
1689                         linphone_proxy_config_register_enabled (cfg)?"yes":"no",
1690                         linphone_proxy_config_get_expires (cfg),
1691                         linphone_proxy_config_is_registered(cfg) ? "yes" : "no");
1692 }
1693
1694 static void linphonec_proxy_show(LinphoneCore *lc, int index)
1695 {
1696         const MSList *elem;
1697         int i;
1698         for(elem=linphone_core_get_proxy_config_list(lc),i=0;elem!=NULL;elem=elem->next,++i){
1699                 if (index==i){
1700                         LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)elem->data;
1701                         linphonec_proxy_display(cfg);
1702                         return;
1703                 }
1704         }
1705         linphonec_out("No proxy with index %i\n", index);
1706 }
1707
1708 static void
1709 linphonec_proxy_list(LinphoneCore *lc)
1710 {
1711         const MSList *proxies;
1712         int n;
1713         int def=linphone_core_get_default_proxy(lc,NULL);
1714         
1715         proxies=linphone_core_get_proxy_config_list(lc);
1716         for(n=0;proxies!=NULL;proxies=ms_list_next(proxies),n++){
1717                 if (n==def)
1718                         linphonec_out("****** Proxy %i - this is the default one - *******\n",n);
1719                 else 
1720                         linphonec_out("****** Proxy %i *******\n",n);
1721                 linphonec_proxy_display((LinphoneProxyConfig*)proxies->data);
1722         }
1723         if ( ! n ) linphonec_out("No proxies defined\n");
1724 }
1725
1726 static void
1727 linphonec_proxy_remove(LinphoneCore *lc, int index)
1728 {
1729         const MSList *proxies;
1730         LinphoneProxyConfig *cfg;
1731         proxies=linphone_core_get_proxy_config_list(lc);
1732         cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1733         if (cfg==NULL){
1734                 linphonec_out("No such proxy.\n");
1735                 return;
1736         }
1737         linphone_core_remove_proxy_config(lc,cfg);
1738         linphonec_out("Proxy %s removed.\n", linphone_proxy_config_get_addr(cfg));
1739 }
1740
1741 static int
1742 linphonec_proxy_use(LinphoneCore *lc, int index)
1743 {
1744         const MSList *proxies;
1745         LinphoneProxyConfig *cfg;
1746         proxies=linphone_core_get_proxy_config_list(lc);
1747         cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1748         if (cfg==NULL){
1749                 linphonec_out("No such proxy (try 'proxy list').");
1750                 return 0;
1751         }
1752         linphone_core_set_default_proxy(lc,cfg);
1753         return 1;
1754 }
1755
1756 static void
1757 linphonec_friend_display(LinphoneFriend *fr)
1758 {
1759         LinphoneAddress *uri=linphone_address_clone(linphone_friend_get_address(fr));
1760         char *str;
1761         
1762         linphonec_out("name: %s\n", linphone_address_get_display_name(uri));
1763         linphone_address_set_display_name(uri,NULL);
1764         str=linphone_address_as_string(uri);
1765         linphonec_out("address: %s\n", str);
1766 }
1767
1768 static int
1769 linphonec_friend_list(LinphoneCore *lc, char *pat)
1770 {
1771         const MSList *friend;
1772         int n;
1773
1774         if (pat) {
1775                 pat=lpc_strip_blanks(pat);
1776                 if (!*pat) pat = NULL;
1777         }
1778
1779         friend = linphone_core_get_friend_list(lc);
1780         for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1781         {
1782                 if ( pat ) {
1783                         const char *name = linphone_address_get_display_name(
1784                             linphone_friend_get_address((LinphoneFriend*)friend->data));
1785                         if (name && ! strstr(name, pat) ) continue;
1786                 }
1787                 linphonec_out("****** Friend %i *******\n",n);
1788                 linphonec_friend_display((LinphoneFriend*)friend->data);
1789         }
1790
1791         return 1;
1792 }
1793
1794 static int
1795 linphonec_friend_call(LinphoneCore *lc, unsigned int num)
1796 {
1797         const MSList *friend = linphone_core_get_friend_list(lc);
1798         unsigned int n;
1799         char *addr;
1800
1801         for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1802         {
1803                 if ( n == num )
1804                 {
1805                         int ret;
1806                         addr = linphone_address_as_string(linphone_friend_get_address((LinphoneFriend*)friend->data));
1807                         ret=lpc_cmd_call(lc, addr);
1808                         ms_free(addr);
1809                         return ret;
1810                 }
1811         }
1812         linphonec_out("No such friend %u\n", num);
1813         return 1;
1814 }
1815
1816 #ifndef WIN32
1817 static int
1818 linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr)
1819 {
1820         LinphoneFriend *newFriend;
1821
1822         char url[PATH_MAX];
1823
1824         snprintf(url, PATH_MAX, "%s <%s>", name, addr);
1825         newFriend = linphone_friend_new_with_addr(url);
1826         linphone_core_add_friend(lc, newFriend);
1827         return 0;
1828 }
1829 #endif
1830
1831 static int
1832 linphonec_friend_delete(LinphoneCore *lc, int num)
1833 {
1834         const MSList *friend = linphone_core_get_friend_list(lc);
1835         unsigned int n;
1836
1837         for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1838         {
1839                 if ( n == num )
1840                 {
1841                         linphone_core_remove_friend(lc, friend->data);
1842                         return 0;
1843                 }
1844         }
1845
1846         if (-1 == num) 
1847         {
1848                 unsigned int i;
1849                 for (i = 0 ; i < n ; i++)
1850                         linphonec_friend_delete(lc, 0);
1851                 return 0;
1852         }
1853
1854         linphonec_out("No such friend %u\n", num);
1855         return 1;
1856 }
1857
1858 static void
1859 linphonec_display_command_help(LPC_COMMAND *cmd)
1860 {
1861         if ( cmd->doc ) linphonec_out ("%s\n", cmd->doc);
1862         else linphonec_out("%s\n", cmd->help);
1863 }
1864
1865
1866 static int lpc_cmd_register(LinphoneCore *lc, char *args){
1867         char identity[512];
1868         char proxy[512];
1869         char passwd[512];
1870         LinphoneProxyConfig *cfg;
1871         const MSList *elem;
1872     
1873         if (!args)
1874         {
1875                 /* it means that you want to register the default proxy */
1876                 LinphoneProxyConfig *cfg=NULL;
1877                 linphone_core_get_default_proxy(lc,&cfg);
1878                 if (cfg)
1879                 {
1880                         if(!linphone_proxy_config_is_registered(cfg)) {
1881                                 linphone_proxy_config_enable_register(cfg,TRUE);
1882                                 linphone_proxy_config_done(cfg);
1883                         }else{
1884                                 linphonec_out("default proxy already registered\n");
1885                         }
1886                 }else{
1887                         linphonec_out("we do not have a default proxy\n");
1888                         return 0;
1889                 }
1890                 return 1;
1891         }
1892         passwd[0]=proxy[0]=identity[0]='\0';
1893         sscanf(args,"%s %s %s",identity,proxy,passwd);
1894         if (proxy[0]=='\0' || identity[0]=='\0'){
1895                 linphonec_out("Missing parameters, see help register\n");
1896                 return 1;
1897         }
1898         if (passwd[0]!='\0'){
1899                 LinphoneAddress *from;
1900                 LinphoneAuthInfo *info;
1901                 if ((from=linphone_address_new(identity))!=NULL){
1902                         char realm[128];
1903                         snprintf(realm,sizeof(realm)-1,"\"%s\"",linphone_address_get_domain(from));
1904                         info=linphone_auth_info_new(linphone_address_get_username(from),NULL,passwd,NULL,NULL);
1905                         linphone_core_add_auth_info(lc,info);
1906                         linphone_address_destroy(from);
1907                         linphone_auth_info_destroy(info);
1908                 }
1909         }
1910         elem=linphone_core_get_proxy_config_list(lc);
1911         if (elem) {
1912                 cfg=(LinphoneProxyConfig*)elem->data;
1913                 linphone_proxy_config_edit(cfg);
1914         }
1915         else cfg=linphone_proxy_config_new();
1916         linphone_proxy_config_set_identity(cfg,identity);
1917         linphone_proxy_config_set_server_addr(cfg,proxy);
1918         linphone_proxy_config_enable_register(cfg,TRUE);
1919         if (elem) linphone_proxy_config_done(cfg);
1920         else linphone_core_add_proxy_config(lc,cfg);
1921         linphone_core_set_default_proxy(lc,cfg);
1922         return 1;
1923 }
1924
1925 static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
1926         LinphoneProxyConfig *cfg=NULL;
1927         linphone_core_get_default_proxy(lc,&cfg);
1928         if (cfg && linphone_proxy_config_is_registered(cfg)) {
1929                 linphone_proxy_config_edit(cfg);
1930                 linphone_proxy_config_enable_register(cfg,FALSE);
1931                 linphone_proxy_config_done(cfg);
1932         }else{
1933                 linphonec_out("unregistered\n");
1934         }
1935         return 1;
1936 }
1937
1938 static int lpc_cmd_duration(LinphoneCore *lc, char *args){
1939         LinphoneCallLog *cl;
1940         const MSList *elem=linphone_core_get_call_logs(lc);
1941         for(;elem!=NULL;elem=elem->next){
1942                 if (elem->next==NULL){
1943                         cl=(LinphoneCallLog*)elem->data;
1944                         linphonec_out("%i seconds\n",cl->duration);
1945                 }
1946         }
1947         return 1;
1948 }
1949
1950 static int lpc_cmd_status(LinphoneCore *lc, char *args)
1951 {
1952         LinphoneProxyConfig *cfg;
1953         
1954         if ( ! args ) return 0;
1955         linphone_core_get_default_proxy(lc,&cfg);
1956         if (strstr(args,"register"))
1957         {
1958                 if (cfg)
1959                 {
1960                         if (linphone_proxy_config_is_registered(cfg)){
1961                                 linphonec_out("registered, identity=%s duration=%i\n",
1962                                         linphone_proxy_config_get_identity(cfg),
1963                                         linphone_proxy_config_get_expires(cfg));
1964                         }else if (linphone_proxy_config_register_enabled(cfg)){
1965                                 linphonec_out("registered=-1\n");
1966                         }else linphonec_out("registered=0\n");
1967                 }
1968                 else linphonec_out("registered=0\n");
1969         }
1970         else if (strstr(args,"autoanswer"))
1971         {
1972                 if (cfg && linphone_proxy_config_is_registered(cfg))
1973                         linphonec_out("autoanswer=%i\n",linphonec_get_autoanswer());
1974                 else linphonec_out("unregistered\n");
1975         }
1976         else if (strstr(args,"hook"))
1977         {
1978                 LinphoneCall *call=linphone_core_get_current_call (lc);
1979                 LinphoneCallState call_state=LinphoneCallIdle;
1980                 if (call) call_state=linphone_call_get_state(call);
1981
1982                 switch(call_state){
1983                         case LinphoneCallOutgoingInit:
1984                                 linphonec_out("hook=outgoing_init sip:%s\n",linphonec_get_callee());
1985                         break;
1986                         case LinphoneCallOutgoingProgress:
1987                                 linphonec_out("hook=dialing sip:%s\n",linphonec_get_callee());
1988                         break;
1989                         case LinphoneCallOutgoingRinging:
1990                                 linphonec_out("hook=ringing sip:%s\n",linphonec_get_callee());
1991                         break;
1992                         case LinphoneCallPaused:
1993                                 linphonec_out("hook=paused sip:%s\n",linphonec_get_callee());
1994                         break;
1995                         case LinphoneCallIdle:
1996                                 linphonec_out("hook=offhook\n");
1997                         break;
1998                         case LinphoneCallStreamsRunning:
1999                         case LinphoneCallConnected:
2000                                 if (linphone_call_get_dir(call)==LinphoneCallOutgoing){
2001                                         linphonec_out("Call out, hook=%s duration=%i, muted=%s rtp-xmit-muted=%s\n", linphonec_get_callee(),
2002                                               linphone_core_get_current_call_duration(lc),
2003                                               linphone_core_is_mic_muted (lc) ? "yes" : "no",
2004                                               linphone_core_is_rtp_muted(lc) ? "yes"  : "no");
2005                                 }else{
2006                                         linphonec_out("hook=answered duration=%i %s\n" ,
2007                                                 linphone_core_get_current_call_duration(lc), linphonec_get_caller());
2008                                 }
2009                                 break;
2010                         case LinphoneCallIncomingReceived:
2011                                 linphonec_out("Incoming call from %s\n",linphonec_get_caller());
2012                                 break;
2013                         default:
2014                                 break;
2015                 }
2016                 
2017         }
2018         else return 0;
2019
2020         return 1;
2021 }
2022
2023 static int lpc_cmd_ports(LinphoneCore *lc, char *args)
2024 {
2025         int port;
2026         if ( ! args ){
2027                 linphonec_out("sip port = %i\naudio rtp port = %i\nvideo rtp port = %i\n",
2028                         linphone_core_get_sip_port(lc),
2029                         linphone_core_get_audio_port(lc),
2030                         linphone_core_get_video_port(lc));
2031                 return 1;
2032         }
2033         if (sscanf(args,"sip %i",&port)==1){
2034                 linphonec_out("Setting sip port to %i\n",port);
2035                 linphone_core_set_sip_port(lc,port);
2036         }else return 0;
2037
2038         return 1;
2039 }
2040
2041 static int lpc_cmd_param(LinphoneCore *lc, char *args)
2042 {
2043         char section[20], param[20], value[50];
2044         const char *string;
2045
2046         if (args == NULL) {
2047                 return 0;
2048         }
2049         switch (sscanf(args,"%s %s %s",section,param,value)) {
2050                 // case 1 might show all current settings under a section
2051                 case 2:
2052                         string = lp_config_get_string(linphone_core_get_config(lc), section, param, "(undef)");
2053                         linphonec_out("current value: %s\n", string);
2054                         break;
2055                 case 3:
2056                         if (lp_config_get_string(linphone_core_get_config(lc), section, param, NULL) != NULL) {
2057                                 lp_config_set_string(linphone_core_get_config(lc), section, param, value);
2058                         // no indication of existence
2059                                 linphonec_out("updated value: %s\n", value);
2060                         } else {
2061                                 linphonec_out("only update of existing variables are allowed\n");
2062                         }
2063                         break;
2064                 default:
2065                         return 0;
2066     }
2067         return 1;
2068 }
2069
2070 static int lpc_cmd_speak(LinphoneCore *lc, char *args){
2071 #ifndef WIN32
2072         char voice[64];
2073         char *sentence;
2074         char cl[128];
2075         char *wavfile;
2076         int status;
2077         FILE *file;
2078         
2079     if (!args) return 0;
2080         memset(voice,0,sizeof(voice));
2081         sscanf(args,"%s63",voice);
2082         sentence=args+strlen(voice);
2083         wavfile=tempnam("/tmp/","linphonec-espeak-");
2084         snprintf(cl,sizeof(cl),"espeak -v %s -s 100 -w %s --stdin",voice,wavfile);
2085         file=popen(cl,"w");
2086         if (file==NULL){
2087                 ms_error("Could not open pipe to espeak !");
2088                 return 1;
2089         }
2090         fprintf(file,"%s",sentence);
2091         status=pclose(file);
2092         if (WEXITSTATUS(status)==0){
2093                 linphone_core_set_play_file(lc,wavfile);
2094         }else{
2095                 linphonec_out("espeak command failed.");
2096         }
2097 #else
2098         linphonec_out("Sorry, this command is not implemented in windows version.");
2099 #endif
2100         return 1;
2101 }
2102
2103 static int lpc_cmd_acodec(LinphoneCore *lc, char *args){
2104     return lpc_cmd_codec(AUDIO, lc, args);
2105 }
2106
2107 static int lpc_cmd_vcodec(LinphoneCore *lc, char *args){
2108     return lpc_cmd_codec(VIDEO, lc, args);
2109 }
2110
2111 static int lpc_cmd_codec(int type, LinphoneCore *lc, char *args){
2112         char *arg1 = args;
2113         char *arg2 = NULL;
2114         char *ptr = args;
2115
2116         if (!args) return 0;
2117
2118         /* Isolate first and second arg */
2119         while(*ptr && !isspace(*ptr)) ++ptr;
2120         if ( *ptr )
2121         {
2122                 *ptr='\0';
2123                 arg2=ptr+1;
2124                 while(*arg2 && isspace(*arg2)) ++arg2;
2125         }
2126
2127         if (strcmp(arg1,"enable")==0)
2128         {
2129 #ifdef HAVE_READLINE
2130                 rl_inhibit_completion=1;
2131 #endif
2132         if (!strcmp(arg2,"all")) linphonec_codec_enable(type,lc,-1);
2133         else linphonec_codec_enable(type,lc,atoi(arg2));
2134 #ifdef HAVE_READLINE
2135                 rl_inhibit_completion=0;
2136 #endif
2137         }
2138         else if (strcmp(arg1,"list")==0)
2139         {
2140                 linphonec_codec_list(type,lc);
2141         }
2142         else if (strcmp(arg1,"disable")==0)
2143         {
2144         if (!strcmp(arg2,"all")) linphonec_codec_disable(type,lc,-1);
2145         else linphonec_codec_disable(type,lc,atoi(arg2));
2146         }
2147         else
2148         {
2149                 return 0; /* syntax error */
2150         }
2151
2152         return 1;
2153 }
2154
2155 static void linphonec_codec_list(int type, LinphoneCore *lc){
2156         PayloadType *pt;
2157         int index=0;
2158         const MSList *node=NULL;
2159
2160     if (type == AUDIO) {
2161       node=linphone_core_get_audio_codecs(lc);
2162     } else if(type==VIDEO) {
2163       node=linphone_core_get_video_codecs(lc);
2164     }
2165
2166         for(;node!=NULL;node=ms_list_next(node)){
2167                 pt=(PayloadType*)(node->data);
2168         linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, 
2169                     linphone_core_payload_type_enabled(lc,pt) ? "enabled" : "disabled");
2170                 index++;
2171         }
2172 }
2173
2174 static void linphonec_codec_enable(int type, LinphoneCore *lc, int sel_index){
2175         PayloadType *pt;
2176         int index=0;
2177         const MSList *node=NULL;
2178
2179         if (type == AUDIO) {
2180                 node=linphone_core_get_audio_codecs(lc);
2181         } else if(type==VIDEO) {
2182                 node=linphone_core_get_video_codecs(lc);
2183         }
2184
2185     for(;node!=NULL;node=ms_list_next(node)){
2186         if (index == sel_index || sel_index == -1) {
2187                     pt=(PayloadType*)(node->data);
2188             linphone_core_enable_payload_type (lc,pt,TRUE);
2189             linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "enabled");
2190         }
2191                 index++;
2192         }
2193 }
2194
2195 static void linphonec_codec_disable(int type, LinphoneCore *lc, int sel_index){
2196         PayloadType *pt;
2197         int index=0;
2198         const MSList *node=NULL;
2199
2200         if (type == AUDIO) {
2201                 node=linphone_core_get_audio_codecs(lc);
2202         } else if(type==VIDEO) {
2203                 node=linphone_core_get_video_codecs(lc);
2204         }
2205
2206         for(;node!=NULL;node=ms_list_next(node)){
2207                 if (index == sel_index || sel_index == -1) {
2208                         pt=(PayloadType*)(node->data);
2209                         linphone_core_enable_payload_type (lc,pt,FALSE);
2210                         linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "disabled");
2211                 }
2212                 index++;
2213         }
2214 }
2215
2216 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){
2217         char *arg1 = args;
2218         char *arg2 = NULL;
2219         char *ptr = args;
2220         LpConfig *config=linphone_core_get_config(lc);
2221
2222         if (!args) return 0;
2223
2224         /* Isolate first and second arg */
2225         while(*ptr && !isspace(*ptr)) ++ptr;
2226         if ( *ptr )
2227         {
2228                 *ptr='\0';
2229                 arg2=ptr+1;
2230                 while(*arg2 && isspace(*arg2)) ++arg2;
2231         }
2232
2233         if (strcmp(arg1,"on")==0){
2234         int delay, tail_len, frame_size;
2235         int n;
2236
2237         linphone_core_enable_echo_cancellation(lc,1);
2238
2239         if (arg2 != 0) {
2240             n = sscanf(arg2, "%d %d %d", &delay, &tail_len, &frame_size);
2241
2242             if (n == 1) {   
2243                 lp_config_set_int(config,"sound","ec_delay",delay);
2244             }
2245             else if (n == 2) {
2246                 lp_config_set_int(config,"sound","ec_delay",delay);
2247                 lp_config_set_int(config,"sound","ec_tail_len",tail_len);
2248             }
2249             else if (n == 3) {
2250                 lp_config_set_int(config,"sound","ec_delay",delay);
2251                 lp_config_set_int(config,"sound","ec_tail_len",tail_len);
2252                 lp_config_set_int(config,"sound","ec_framesize",frame_size);
2253             }
2254         }
2255     }
2256     else if (strcmp(arg1,"off")==0){
2257         linphone_core_enable_echo_cancellation(lc,0);
2258     }
2259     else if (strcmp(arg1,"show")==0){
2260         linphonec_out("echo cancellation is %s; delay %d, tail length %d, frame size %d\n", 
2261             linphone_core_echo_cancellation_enabled(lc) ? "on" : "off",
2262             lp_config_get_int(config,"sound","ec_delay",0),
2263             lp_config_get_int(config,"sound","ec_tail_len",0),
2264             lp_config_get_int(config,"sound","ec_framesize",0));        
2265     }
2266     else {
2267         return 0;
2268     }
2269
2270     return 1;
2271 }
2272
2273 static int lpc_cmd_echolimiter(LinphoneCore *lc, char *args){
2274         if (args){
2275                 if (strcmp(args,"on")==0){
2276                         linphone_core_enable_echo_limiter (lc,TRUE);
2277                 }else if (strcmp(args,"off")==0){
2278                         linphone_core_enable_echo_limiter (lc,FALSE);
2279                 }
2280         }
2281         linphonec_out("Echo limiter is now %s.\n",linphone_core_echo_limiter_enabled (lc) ? "on":"off");
2282         return 1;
2283 }
2284
2285 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args)
2286 {
2287         linphone_core_mute_mic(lc, 1);
2288         return 1;
2289 }
2290
2291 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args){
2292         linphone_core_mute_mic(lc, 0);
2293         return 1;
2294 }
2295
2296 static int lpc_cmd_playback_gain(LinphoneCore *lc, char *args)
2297 {
2298         if (args){
2299                 linphone_core_set_playback_gain_db(lc, atof(args));
2300                 return 1;
2301         }
2302         return 0;
2303 }
2304
2305 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args)
2306 {
2307         bool_t rtp_xmit_off=FALSE;
2308         char *status;
2309
2310         if(args){
2311                 if(strstr(args,"1"))rtp_xmit_off=TRUE;
2312                 if(linphone_core_get_current_call (lc)==NULL)
2313                         linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_xmit_off);
2314                 else 
2315                         linphonec_out("nortp-on-audio-mute: call in progress - cannot change state\n");
2316         }
2317         rtp_xmit_off=linphone_core_get_rtp_no_xmit_on_audio_mute(lc);
2318         if (rtp_xmit_off) status="off";
2319         else status="on";
2320         linphonec_out("rtp transmit %s when audio muted\n",status);
2321         return 1;
2322 }
2323
2324 #ifdef VIDEO_ENABLED
2325 static int _lpc_cmd_video_window(LinphoneCore *lc, char *args, bool_t is_preview){
2326         char subcommand[64];
2327         int a,b;
2328         int err;
2329         VideoParams *params=is_preview ? &lpc_preview_params : &lpc_video_params;
2330
2331         if (!args) return 0;
2332         err=sscanf(args,"%s %i %i",subcommand,&a,&b);
2333         if (err>=1){
2334                 if (strcmp(subcommand,"pos")==0){
2335                         if (err<3) return 0;
2336                         params->x=a;
2337                         params->y=b;
2338                         params->refresh=TRUE;
2339                 }else if (strcmp(subcommand,"size")==0){
2340                         if (err<3) return 0;
2341                         params->w=a;
2342                         params->h=b;
2343                         params->refresh=TRUE;
2344                 }else if (strcmp(subcommand,"show")==0){
2345                         params->show=TRUE;
2346                         params->refresh=TRUE;
2347                         if (is_preview) linphone_core_enable_video_preview (lc,TRUE);
2348                 }else if (strcmp(subcommand,"hide")==0){
2349                         params->show=FALSE;
2350                         params->refresh=TRUE;
2351                         if (is_preview) linphone_core_enable_video_preview (lc,FALSE);
2352                 }else if (strcmp(subcommand,"id")==0){
2353                         if (err == 1){
2354                                 linphonec_out("vwindow id: 0x%x\n",is_preview ? linphone_core_get_native_preview_window_id (lc) :
2355                                               linphone_core_get_native_video_window_id (lc));
2356                                 return 1;
2357                         } else if (err != 2) return 0;
2358                         params->wid=a;
2359                         if (is_preview)
2360                                 linphone_core_set_native_preview_window_id (lc,a);
2361                         else
2362                                 linphone_core_set_native_video_window_id(lc,a);
2363                 }else if (is_preview==TRUE){
2364                         if (strcmp(subcommand,"integrated")==0){
2365                                 linphone_core_use_preview_window (lc,FALSE);
2366                         }else if (strcmp(subcommand,"standalone")==0){
2367                                 linphone_core_use_preview_window(lc,TRUE);
2368                         }else return 0;
2369                 }else return 0;
2370         }
2371         return 1;
2372 }
2373
2374 static int lpc_cmd_video_window(LinphoneCore *lc, char *args){
2375         return _lpc_cmd_video_window(lc, args, FALSE);
2376 }
2377
2378 static int lpc_cmd_preview_window(LinphoneCore *lc, char *args){
2379         return _lpc_cmd_video_window(lc, args, TRUE);
2380 }
2381 #endif
2382
2383 static void lpc_display_global_state(LinphoneCore *lc){
2384         linphonec_out("Global liblinphone state\n%s\n",
2385                       linphone_global_state_to_string(linphone_core_get_global_state(lc)));
2386 }
2387
2388 static void lpc_display_call_states(LinphoneCore *lc){
2389         LinphoneCall *call;
2390         const MSList *elem;
2391         char *tmp;
2392         linphonec_out("Call states\n"
2393                       "Id |            Destination              |      State      |    Flags   |\n"
2394                       "------------------------------------------------------------------------\n");
2395         elem=linphone_core_get_calls(lc);
2396         if (elem==NULL){
2397                 linphonec_out("(empty)\n");
2398         }else{
2399                 for(;elem!=NULL;elem=elem->next){
2400                         const char *flag;
2401                         call=(LinphoneCall*)elem->data;
2402                         bool_t in_conference=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
2403                         tmp=linphone_call_get_remote_address_as_string (call);
2404                         flag=in_conference ? "conferencing" : "";
2405                         flag=linphone_call_has_transfer_pending(call) ? "transfer pending" : flag;
2406                         linphonec_out("%-2i | %-35s | %-15s | %s\n",(int)(long)linphone_call_get_user_pointer(call),
2407                                                   tmp,linphone_call_state_to_string(linphone_call_get_state(call))+strlen("LinphoneCall"),flag);
2408                         ms_free(tmp);
2409                 }
2410         }
2411 }
2412
2413 static void lpc_display_proxy_states(LinphoneCore *lc){
2414         const MSList *elem;
2415         linphonec_out("Proxy registration states\n"
2416                       "           Identity                      |      State\n"
2417                       "------------------------------------------------------------\n");
2418         elem=linphone_core_get_proxy_config_list (lc);
2419         if (elem==NULL) linphonec_out("(empty)\n");
2420         else {
2421                 for(;elem!=NULL;elem=elem->next){
2422                         LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2423                         linphonec_out("%-40s | %s\n",linphone_proxy_config_get_identity (cfg),
2424                                                   linphone_registration_state_to_string(linphone_proxy_config_get_state(cfg)));
2425                 }
2426         }
2427 }
2428
2429 static int lpc_cmd_states(LinphoneCore *lc, char *args){
2430         if (args==NULL) {
2431                 lpc_display_global_state(lc);
2432                 lpc_display_call_states(lc);
2433                 lpc_display_proxy_states(lc);
2434                 return 1;
2435         }
2436         if (strcmp(args,"global")==0){
2437                 lpc_display_global_state(lc);
2438                 return 1;
2439         }
2440         if (strcmp(args,"proxies")==0){
2441                 lpc_display_proxy_states(lc);
2442                 return 1;
2443         }
2444         if (strcmp(args,"calls")==0){
2445                 lpc_display_call_states(lc);
2446                 return 1;
2447         }
2448         return 0;
2449 }
2450
2451 #ifdef VIDEO_ENABLED
2452 static int lpc_cmd_camera(LinphoneCore *lc, char *args){
2453         LinphoneCall *call=linphone_core_get_current_call(lc);
2454         bool_t activated=FALSE;
2455         
2456         if (linphone_core_video_enabled (lc)==FALSE){
2457                 linphonec_out("Video is disabled, re-run linphonec with -V option.");
2458                 return 1;
2459         }
2460
2461         if (args){
2462                 if (strcmp(args,"on")==0)
2463                         activated=TRUE;
2464                 else if (strcmp(args,"off")==0)
2465                         activated=FALSE;
2466                 else
2467                         return 0;
2468         }
2469
2470         if (call==NULL){
2471                 if (args){
2472                         linphonec_camera_enabled=activated;
2473                 }
2474                 if (linphonec_camera_enabled){
2475                         linphonec_out("Camera is enabled. Video stream will be setup immediately for outgoing and incoming calls.\n");
2476                 }else{
2477                         linphonec_out("Camera is disabled. Calls will be established with audio-only, with the possibility to later add video using 'camera on'.\n");
2478                 }
2479         }else{
2480                 const LinphoneCallParams *cp=linphone_call_get_current_params (call);
2481                 if (args){
2482                         linphone_call_enable_camera(call,activated);
2483                         if ((activated && !linphone_call_params_video_enabled (cp))){
2484                                 /*update the call to add the video stream*/
2485                                 LinphoneCallParams *ncp=linphone_call_params_copy(cp);
2486                                 linphone_call_params_enable_video(ncp,TRUE);
2487                                 linphone_core_update_call(lc,call,ncp);
2488                                 linphone_call_params_destroy (ncp);
2489                                 linphonec_out("Trying to bring up video stream...\n");
2490                         }
2491                 }
2492                 if (linphone_call_camera_enabled (call))
2493                                 linphonec_out("Camera is allowed for current call.\n");
2494                 else linphonec_out("Camera is dis-allowed for current call.\n");
2495         }
2496         return 1;
2497 }
2498
2499 static int lpc_cmd_snapshot(LinphoneCore *lc, char *args){
2500         LinphoneCall *call;
2501         if (!args) return 0;
2502         call=linphone_core_get_current_call(lc);
2503         if (call!=NULL){
2504                 linphone_call_take_video_snapshot(call,args);
2505                 linphonec_out("Taking video snapshot in file %s\n", args);
2506         }else linphonec_out("There is no active call.\n");
2507         return 1;
2508 }
2509
2510 static int lpc_cmd_vfureq(LinphoneCore *lc, char *arg){
2511         LinphoneCall *call;
2512         call=linphone_core_get_current_call(lc);
2513         if (call!=NULL){
2514                 linphone_call_send_vfu_request(call);
2515                 linphonec_out("VFU request sent\n");
2516         }else linphonec_out("There is no active call.\n");
2517         return 1;
2518 }
2519 #endif
2520
2521 static int lpc_cmd_identify(LinphoneCore *lc, char *args){
2522         LinphoneCall *call;
2523         const char *remote_ua;
2524         if (args==NULL){
2525                 call=linphone_core_get_current_call(lc);
2526                 if (call==NULL) {
2527                         linphonec_out("There is currently running call. Specify call id.\n");
2528                         return 0;
2529                 }
2530         }else{
2531                 call=linphonec_get_call(atoi(args));
2532                 if (call==NULL){
2533                         return 0;
2534                 }
2535         }
2536         remote_ua=linphone_call_get_remote_user_agent(call);
2537         if (remote_ua){
2538                 linphonec_out("Remote user agent string is: %s\n",remote_ua);
2539         }
2540         return 1;
2541 }
2542
2543 static int lpc_cmd_ringback(LinphoneCore *lc, char *args){
2544         if (!args) return 0;
2545         if (strcmp(args,"disable")==0){
2546                 linphone_core_set_remote_ringback_tone(lc,NULL);
2547                 linphonec_out("Disabling ringback tone.\n");
2548                 return 1;
2549         }
2550         linphone_core_set_remote_ringback_tone (lc,args);
2551         linphonec_out("Using %s as ringback tone to be played to callers.",args);
2552         return 1;
2553 }
2554
2555 /***************************************************************************
2556  *
2557  *  Command table management funx
2558  *
2559  ***************************************************************************/
2560
2561 /*
2562  * Find a command given its name
2563  */
2564 static LPC_COMMAND *
2565 lpc_find_command(const char *name)
2566 {
2567         int i;
2568
2569         for (i=0; commands[i].name; ++i)
2570         {
2571                 if (strcmp(name, commands[i].name) == 0)
2572                         return &commands[i];
2573         }
2574
2575         for (i=0; advanced_commands[i].name; ++i)
2576         {
2577                 if (strcmp(name, advanced_commands[i].name) == 0)
2578                         return &advanced_commands[i];
2579         }
2580
2581         return (LPC_COMMAND *)NULL;
2582 }
2583
2584
2585 /****************************************************************************
2586  *
2587  * $Log: commands.c,v $
2588  * Revision 1.39  2008/07/03 15:08:34  smorlat
2589  * api cleanups, interface in progress.
2590  *
2591  * Revision 1.38  2008/06/17 20:38:59  smorlat
2592  * added missing file.
2593  *
2594  * Revision 1.37  2008/04/09 09:26:00  smorlat
2595  * merge various patches
2596  * H264 support.
2597  *
2598  * Revision 1.36  2007/08/01 14:47:53  strk
2599  *         * console/commands.c: Clean up commands 'nat', 'stun'
2600  *           and 'firewall' to be more intuitive.
2601  *
2602  * Revision 1.35  2007/06/27 09:01:25  smorlat
2603  * logging improvements.
2604  *
2605  * Revision 1.34  2007/02/20 10:17:13  smorlat
2606  * linphonec friends patch2
2607  *
2608  * Revision 1.31  2006/09/22 07:22:47  smorlat
2609  * linphonecore api changes.
2610  *
2611  * Revision 1.30  2006/09/08 15:32:57  smorlat
2612  * support for using files instead of soundcard (used by linphonec only)
2613  *
2614  * Revision 1.29  2006/08/28 14:29:07  smorlat
2615  * fix bug.
2616  *
2617  * Revision 1.28  2006/08/21 12:49:59  smorlat
2618  * merged several little patches.
2619  *
2620  * Revision 1.27  2006/07/17 18:45:00  smorlat
2621  * support for several event queues in ortp.
2622  * glib dependency removed from coreapi/ and console/
2623  *
2624  * Revision 1.26  2006/04/14 15:16:36  smorlat
2625  * soundcard use did nothing !
2626  *
2627  * Revision 1.25  2006/04/06 20:09:33  smorlat
2628  * add linphonec command to see and select sound devices.
2629  *
2630  * Revision 1.24  2006/03/04 11:17:10  smorlat
2631  * mediastreamer2 in progress.
2632  *
2633  * Revision 1.23  2006/02/20 21:14:01  strk
2634  * Handled syntax errors with 'friend' command
2635  *
2636  * Revision 1.22  2006/02/20 10:20:29  strk
2637  * Added substring-based filter support for command 'friend list'
2638  *
2639  * Revision 1.21  2006/02/02 15:39:18  strk
2640  * - Added 'friend list' and 'friend call' commands
2641  * - Allowed for multiple DTFM send in a single line
2642  * - Added status-specific callback (bare version)
2643  *
2644  * Revision 1.20  2006/01/26 11:54:34  strk
2645  * More robust 'nat' command handler (strip blanks in args)
2646  *
2647  * Revision 1.19  2006/01/26 09:48:05  strk
2648  * Added limits.h include
2649  *
2650  * Revision 1.18  2006/01/26 02:18:05  strk
2651  * Added new commands 'nat use' and 'nat unuse'.
2652  * These will required a pending patch to linphonecore.c
2653  * in order to work.
2654  *
2655  * Revision 1.17  2006/01/20 14:12:33  strk
2656  * Added linphonec_init() and linphonec_finish() functions.
2657  * Handled SIGINT and SIGTERM to invoke linphonec_finish().
2658  * Handling of auto-termination (-t) moved to linphonec_finish().
2659  * Reworked main (input read) loop to not rely on 'terminate'
2660  * and 'run' variable (dropped). configfile_name allocated on stack
2661  * using PATH_MAX limit. Changed print_usage signature to allow
2662  * for an exit_status specification.
2663  *
2664  * Revision 1.16  2006/01/18 09:25:32  strk
2665  * Command completion inhibited in proxy addition and auth request prompts.
2666  * Avoided use of linphonec_readline's internal filename completion.
2667  *
2668  * Revision 1.15  2006/01/14 13:29:32  strk
2669  * Reworked commands interface to use a table structure,
2670  * used by command line parser and help function.
2671  * Implemented first level of completion (commands).
2672  * Added notification of invalid "answer" and "terminate"
2673  * commands (no incoming call, no active call).
2674  * Forbidden "call" intialization when a call is already active.
2675  * Cleaned up all commands, adding more feedback and error checks.
2676  *
2677  * Revision 1.14  2006/01/13 13:00:29  strk
2678  * Added linphonec.h. Code layout change (added comments, forward decl,
2679  * globals on top, copyright notices and Logs). Handled out-of-memory
2680  * condition on history management. Removed assumption on sizeof(char).
2681  * Fixed bug in authentication prompt (introduced by linphonec_readline).
2682  * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
2683  *
2684  *
2685  ****************************************************************************/