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