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