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