]> sjero.net Git - linphone/blob - console/commands.c
uPnP in progress
[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                 case LinphonePolicyUseUpnp:
900                         linphonec_out("Using uPnP IGD protocol\n");
901                         break;
902         }
903         return 1;
904 }
905
906 #ifndef WIN32
907 /* Helper function for processing freind names */
908 static int
909 lpc_friend_name(char **args, char **name)
910 {
911         /* Use space as a terminator unless quoted */
912         if (('"' == **args) || ('\'' == **args)){
913                 char *end;
914                 char delim = **args;
915                 (*args)++;
916                 end = (*args);
917                 while ((delim != *end) && ('\0' != *end)) end++;
918                 if ('\0' == *end) {
919                         fprintf(stderr, "Mismatched quotes\n");
920                         return 0;
921                 }
922                 *name = *args;
923                 *end = '\0';
924                 *args = ++end;
925         } else {
926                 *name = strsep(args, " ");
927                 
928                 if (NULL == *args) { /* Means there was no separator */
929                         fprintf(stderr, "Either name or address is missing\n");
930                         return 0;
931                 }
932                 if (NULL == *name) return 0;
933         }
934         return 1;
935 }
936 #endif
937
938 static int
939 lpc_cmd_friend(LinphoneCore *lc, char *args)
940 {
941         int friend_num;
942
943         if ( args ) args=lpc_strip_blanks(args);
944
945         if ( ! args || ! *args ) return 0;
946
947         if ( !strncmp(args, "list", 4) )
948         {
949                 return linphonec_friend_list(lc, args+4);
950                 return 1;
951         }
952         else if ( !strncmp(args, "call", 4) )
953         {
954                 args+=4;
955                 if ( ! *args ) return 0;
956                 friend_num = strtol(args, NULL, 10);
957 #ifndef _WIN32_WCE              
958                 if ( errno == ERANGE ) {
959                         linphonec_out("Invalid friend number\n");
960                         return 0;
961                 }
962 #endif /*_WIN32_WCE*/
963                 linphonec_friend_call(lc, friend_num);
964                 return 1;
965         }
966         else if ( !strncmp(args, "delete", 6) )
967         {
968                 args+=6;
969                 if ( ! *args ) return 0;
970                 while (*args == ' ') args++;
971                 if ( ! *args ) return 0;
972                 if (!strncmp(args, "all", 3))
973                 {
974                         friend_num = -1;
975                 } 
976                 else
977                 {
978                         friend_num = strtol(args, NULL, 10);
979 #ifndef _WIN32_WCE              
980                         if ( errno == ERANGE ) {
981                                 linphonec_out("Invalid friend number\n");
982                                 return 0;
983                         }
984 #endif /*_WIN32_WCE*/
985                 }
986                 linphonec_friend_delete(lc, friend_num);
987                 return 1;
988         }
989         else if ( !strncmp(args, "add", 3) )
990         {
991 #ifndef WIN32
992                 char  *name;
993                 char  addr[80];
994                 char *addr_p = addr;
995                 char *addr_orig;
996
997                 args+=3;
998                 if ( ! *args ) return 0;
999                 while (*args == ' ') args++;
1000                 if ( ! *args ) return 0;
1001
1002                 if (!lpc_friend_name(&args,  &name)) return 0;
1003
1004                 while (*args == ' ') args++;
1005                 if ( ! *args ) return 0;
1006                 if (isdigit(*args)) {
1007                         strcpy (addr, "sip:");
1008                         addr_p = addr + strlen("sip:");
1009                 }
1010                 addr_orig = strsep(&args, " ");
1011                 if (1 >= strlen(addr_orig)) {
1012                         fprintf(stderr, "A single-digit address is not valid\n");
1013                         return 0;
1014                 }
1015                 strcpy(addr_p, addr_orig);
1016                 linphonec_friend_add(lc, name, addr);
1017 #else
1018                 LinphoneFriend *new_friend;
1019                 new_friend = linphone_friend_new_with_addr(args);
1020                 linphone_core_add_friend(lc, new_friend);
1021 #endif
1022                 return 1;
1023         }
1024         return 0;
1025 }
1026
1027 static int lpc_cmd_play(LinphoneCore *lc, char *args){
1028         if ( args ) args=lpc_strip_blanks(args);
1029         if ( ! args || ! *args ) return 0;
1030         linphone_core_set_play_file(lc,args);
1031         return 1;
1032 }
1033
1034 static int lpc_cmd_record(LinphoneCore *lc, char *args){
1035         if ( args ) args=lpc_strip_blanks(args);
1036         if ( ! args || ! *args ) return 0;
1037         linphone_core_set_record_file(lc,args);
1038         return 1;
1039 }
1040
1041 /*
1042  * Modified input
1043  */
1044 static int
1045 lpc_cmd_proxy(LinphoneCore *lc, char *args)
1046 {
1047         char *arg1 = args;
1048         char *arg2 = NULL;
1049         char *ptr = args;
1050         int proxynum;
1051
1052         if ( ! arg1 ) return 0;
1053
1054         /* Isolate first and second arg */
1055         while(*ptr && !isspace(*ptr)) ++ptr;
1056         if ( *ptr )
1057         {
1058                 *ptr='\0';
1059                 arg2=ptr+1;
1060                 while(*arg2 && isspace(*arg2)) ++arg2;
1061         }
1062
1063         if (strcmp(arg1,"add")==0)
1064         {
1065 #ifdef HAVE_READLINE
1066                 rl_inhibit_completion=1;
1067 #endif
1068                 linphonec_proxy_add(lc);
1069 #ifdef HAVE_READLINE
1070                 rl_inhibit_completion=0;
1071 #endif
1072         }
1073         else if (strcmp(arg1,"list")==0)
1074         {
1075                 linphonec_proxy_list(lc);
1076         }
1077         else if (strcmp(arg1,"remove")==0)
1078         {
1079                 linphonec_proxy_remove(lc,atoi(arg2));
1080         }
1081         else if (strcmp(arg1,"use")==0)
1082         {
1083                 if ( arg2 && *arg2 )
1084                 {
1085                         proxynum=atoi(arg2);
1086                         if ( linphonec_proxy_use(lc, proxynum) )
1087                                 linphonec_out("Default proxy set to %d.\n", proxynum);
1088                 }
1089                 else
1090                 {
1091                         proxynum=linphone_core_get_default_proxy(lc, NULL);
1092                         if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
1093                         else linphonec_out("Current default proxy is %d.\n", proxynum);
1094                 }
1095         }else if (strcmp(arg1, "unuse")==0){
1096                 linphone_core_set_default_proxy(lc, NULL);
1097                 linphonec_out("Use no proxy.\n");
1098         }
1099
1100         else if (strcmp(arg1, "show")==0)
1101         {
1102                 if (arg2 && *arg2)
1103                 {
1104                         if (strstr(arg2,"default"))
1105                         {
1106                 proxynum=linphone_core_get_default_proxy(lc, NULL);
1107                 if ( proxynum < 0 ) {
1108                         linphonec_out("No default proxy defined\n");
1109                         return 1;
1110                 }
1111                 linphonec_proxy_show(lc,proxynum);
1112                         }
1113                         else
1114                         {
1115                 linphonec_proxy_show(lc, atoi(arg2));
1116                         }
1117                 }
1118                 else return 0; /* syntax error */
1119         }
1120
1121         else
1122         {
1123                 return 0; /* syntax error */
1124         }
1125
1126         return 1;
1127 }
1128
1129 static int
1130 lpc_cmd_call_logs(LinphoneCore *lc, char *args)
1131 {
1132         const MSList *elem=linphone_core_get_call_logs(lc);
1133         for (;elem!=NULL;elem=ms_list_next(elem))
1134         {
1135                 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
1136                 char *str=linphone_call_log_to_str(cl);
1137                 linphonec_out("%s\n",str);
1138                 ms_free(str);
1139         }
1140         return 1;
1141 }
1142
1143 static int
1144 lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
1145 {
1146         if ( ! arg1 )
1147         {
1148                 return 0; /* syntax error */
1149         }
1150
1151         if (strcmp(arg1,"status")==0)
1152         {
1153                 linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
1154         }
1155         else if (strcmp(arg1,"enable")==0)
1156         {
1157                 linphone_core_enable_ipv6(lc,TRUE);
1158                 linphonec_out("ipv6 use enabled.\n");
1159         }
1160         else if (strcmp(arg1,"disable")==0)
1161         {
1162                 linphone_core_enable_ipv6(lc,FALSE);
1163                 linphonec_out("ipv6 use disabled.\n");
1164         }
1165         else
1166         {
1167                 return 0; /* syntax error */
1168         }
1169         return 1;
1170 }
1171
1172 static int devname_to_index(LinphoneCore *lc, const char *devname){
1173         const char **p;
1174         int i;
1175         for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1176                 if (strcmp(devname,*p)==0) return i;
1177         }
1178         return -1;
1179 }
1180
1181 static const char *index_to_devname(LinphoneCore *lc, int index){
1182         const char **p;
1183         int i;
1184         for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1185                 if (i==index) return *p;
1186         }
1187         return NULL;
1188 }
1189
1190 static int lpc_cmd_soundcard(LinphoneCore *lc, char *args)
1191 {
1192         int i, index;
1193         const char **dev;
1194         char *arg1 = args;
1195         char *arg2 = NULL;
1196         char *ptr = args;
1197
1198         if (!args) return 0; /* syntax error */
1199
1200         /* Isolate first and second arg */
1201         while(*ptr && !isspace(*ptr)) ++ptr;
1202         if ( *ptr )
1203         {
1204                 *ptr='\0';
1205                 arg2=ptr+1;
1206                 while(*arg2 && isspace(*arg2)) ++arg2;
1207         }
1208
1209         if (strcmp(arg1, "list")==0)
1210         {
1211                 dev=linphone_core_get_sound_devices(lc);
1212                 for(i=0; dev[i]!=NULL; ++i){
1213                         linphonec_out("%i: %s\n",i,dev[i]);
1214                 }
1215                 return 1;
1216         }
1217
1218         if (strcmp(arg1, "show")==0)
1219         {
1220                 linphonec_out("Ringer device: %s\n",
1221                         linphone_core_get_ringer_device(lc));
1222                 linphonec_out("Playback device: %s\n",
1223                         linphone_core_get_playback_device(lc));
1224                 linphonec_out("Capture device: %s\n",
1225                         linphone_core_get_capture_device(lc));
1226                 return 1;
1227         }
1228
1229         if (strcmp(arg1, "use")==0 && arg2)
1230         {
1231                 if (strcmp(arg2, "files")==0)
1232                 {
1233                         linphonec_out("Using wav files instead of soundcard.\n");
1234                         linphone_core_use_files(lc,TRUE);
1235                         return 1;
1236                 }
1237
1238                 dev=linphone_core_get_sound_devices(lc);
1239                 index=atoi(arg2); /* FIXME: handle not-a-number */
1240                 for(i=0;dev[i]!=NULL;i++)
1241                 {
1242                         if (i!=index) continue;
1243
1244                         linphone_core_set_ringer_device(lc,dev[i]);
1245                         linphone_core_set_playback_device(lc,dev[i]);
1246                         linphone_core_set_capture_device(lc,dev[i]);
1247                         linphonec_out("Using sound device %s\n",dev[i]);
1248                         return 1;
1249                 }
1250                 linphonec_out("No such sound device\n");
1251                 return 1;
1252         }
1253         if (strcmp(arg1, "capture")==0)
1254         {
1255                 const char *devname=linphone_core_get_capture_device(lc);
1256                 if (!arg2){
1257                         linphonec_out("Using capture device #%i (%s)\n",
1258                                         devname_to_index(lc,devname),devname);
1259                 }else{
1260                         index=atoi(arg2); /* FIXME: handle not-a-number */
1261                         devname=index_to_devname(lc,index);
1262                         if (devname!=NULL){
1263                                 linphone_core_set_capture_device(lc,devname);
1264                                 linphonec_out("Using capture sound device %s\n",devname);
1265                                 return 1;
1266                         }
1267                         linphonec_out("No such sound device\n");
1268                 }
1269                 return 1;
1270         }
1271         if (strcmp(arg1, "playback")==0)
1272         {
1273                 const char *devname=linphone_core_get_playback_device(lc);
1274                 if (!arg2){
1275                         linphonec_out("Using playback device #%i (%s)\n",
1276                                         devname_to_index(lc,devname),devname);
1277                 }else{
1278                         index=atoi(arg2); /* FIXME: handle not-a-number */
1279                         devname=index_to_devname(lc,index);
1280                         if (devname!=NULL){
1281                                 linphone_core_set_playback_device(lc,devname);
1282                                 linphonec_out("Using playback sound device %s\n",devname);
1283                                 return 1;
1284                         }
1285                         linphonec_out("No such sound device\n");
1286                 }
1287                 return 1;
1288         }
1289         if (strcmp(arg1, "ring")==0)
1290         {
1291                 const char *devname=linphone_core_get_ringer_device(lc);
1292                 if (!arg2){
1293                         linphonec_out("Using ring device #%i (%s)\n",
1294                                         devname_to_index(lc,devname),devname);
1295                 }else{
1296                         index=atoi(arg2); /* FIXME: handle not-a-number */
1297                         devname=index_to_devname(lc,index);
1298                         if (devname!=NULL){
1299                                 linphone_core_set_ringer_device(lc,devname);
1300                                 linphonec_out("Using ring sound device %s\n",devname);
1301                                 return 1;
1302                         }
1303                         linphonec_out("No such sound device\n");
1304                 }
1305                 return 1;
1306         }
1307         return 0; /* syntax error */
1308 }
1309
1310 static int lpc_cmd_webcam(LinphoneCore *lc, char *args)
1311 {
1312         int i, index;
1313         const char **dev;
1314         char *arg1 = args;
1315         char *arg2 = NULL;
1316         char *ptr = args;
1317
1318         if (!args) return 0; /* syntax error */
1319
1320         /* Isolate first and second arg */
1321         while(*ptr && !isspace(*ptr)) ++ptr;
1322         if ( *ptr )
1323         {
1324                 *ptr='\0';
1325                 arg2=ptr+1;
1326                 while(*arg2 && isspace(*arg2)) ++arg2;
1327         }
1328
1329         if (strcmp(arg1, "list")==0)
1330         {
1331                 dev=linphone_core_get_video_devices(lc);
1332                 for(i=0; dev[i]!=NULL; ++i){
1333                         linphonec_out("%i: %s\n",i,dev[i]);
1334                 }
1335                 return 1;
1336         }
1337
1338         if (strcmp(arg1, "use")==0 && arg2)
1339         {
1340                 dev=linphone_core_get_video_devices(lc);
1341                 index=atoi(arg2); /* FIXME: handle not-a-number */
1342                 for(i=0;dev[i]!=NULL;i++)
1343                 {
1344                         if (i!=index) continue;
1345
1346                         linphone_core_set_video_device(lc, dev[i]);
1347                         linphonec_out("Using video device %s\n",dev[i]);
1348                         return 1;
1349                 }
1350                 linphonec_out("No such video device\n");
1351                 return 1;
1352         }
1353         return 0; /* syntax error */
1354 }
1355
1356 static int
1357 lpc_cmd_staticpic(LinphoneCore *lc, char *args)
1358 {
1359         char *arg1 = args;
1360         char *arg2 = NULL;
1361         char *ptr = args;
1362
1363         if (!args) return 0;  /* Syntax error */
1364
1365         /* Isolate first and second arg */
1366         while(*ptr && !isspace(*ptr)) ++ptr;
1367         if ( *ptr )
1368         {
1369                 *ptr='\0';
1370                 arg2=ptr+1;
1371                 while(*arg2 && isspace(*arg2)) ++arg2;
1372         }
1373
1374         if (strcmp(arg1, "set")==0 && arg2) {
1375                 linphone_core_set_static_picture(lc, arg2);
1376                 return 1;
1377         }
1378
1379         if (strcmp(arg1, "fps")==0) {
1380           if (arg2) {
1381                 float fps = atof(arg2); /* FIXME: Handle not-a-float */
1382                 linphone_core_set_static_picture_fps(lc, fps);
1383                 return 1;
1384           } else {
1385                 float fps;
1386                 fps = linphone_core_get_static_picture_fps(lc);
1387                 linphonec_out("Current FPS %f\n", fps);
1388                 return 1;
1389           }
1390         }
1391
1392         return 0; /* Syntax error */
1393 }
1394
1395 static int lpc_cmd_pause(LinphoneCore *lc, char *args){
1396
1397         if(linphone_core_in_call(lc))
1398         {
1399                 linphone_core_pause_call(lc,linphone_core_get_current_call(lc));
1400                 return 1;
1401         }
1402         linphonec_out("you can only pause when a call is in process\n");
1403     return 0;
1404 }
1405
1406 static int lpc_cmd_resume(LinphoneCore *lc, char *args){
1407         
1408         if(linphone_core_in_call(lc))
1409         {
1410                 linphonec_out("There is already a call in process pause or stop it first");
1411                 return 1;
1412         }
1413         if (args)
1414         {
1415                 long id;
1416                 int n = sscanf(args, "%li", &id);
1417                 if (n == 1){
1418                         LinphoneCall *call=linphonec_get_call (id);
1419                         if (call){
1420                                 if(linphone_core_resume_call(lc,call)==-1){
1421                                         linphonec_out("There was a problem to resume the call check the remote address you gave %s\n",args);
1422                                 }
1423                         }
1424                         return 1;
1425                 }else return 0;
1426         }
1427         else
1428         {
1429                 const MSList *calls = linphone_core_get_calls(lc);
1430                 int nbcalls=ms_list_size(calls);
1431                 if( nbcalls == 1)
1432                 {
1433                         if(linphone_core_resume_call(lc,calls->data) < 0)
1434                         {
1435                                 linphonec_out("There was a problem to resume the unique call.\n");
1436                         }
1437                         return 1;
1438                 }else if (nbcalls==0){
1439                         linphonec_out("There is no calls at this time.\n");
1440                         return 1;
1441                 }else{
1442                         linphonec_out("There are %i calls at this time, please specify call id as given with 'calls' command.\n");
1443                 }
1444         }
1445         return 0;
1446     
1447 }
1448
1449 static int lpc_cmd_conference(LinphoneCore *lc, char *args){
1450         long id;
1451         char subcommand[32]={0};
1452         int n;
1453         if (args==NULL) return 0;
1454         n=sscanf(args, "%31s %li", subcommand,&id);
1455         if (n == 2){
1456                 LinphoneCall *call=linphonec_get_call(id);
1457                 if (call==NULL) return 1;
1458                 if (strcmp(subcommand,"add")==0){
1459                         linphone_core_add_to_conference(lc,call);
1460                         return 1;
1461                 }else if (strcmp(subcommand,"rm")==0){
1462                         linphone_core_remove_from_conference(lc,call);
1463                         return 1;
1464                 }else if (strcmp(subcommand,"enter")==0){
1465                         linphone_core_enter_conference(lc);
1466                         return 1;
1467                 }else if (strcmp(subcommand,"leave")==0){
1468                         linphone_core_leave_conference(lc);
1469                         return 1;
1470                 }
1471         }
1472         return 0;
1473 }
1474
1475 /***************************************************************************
1476  *
1477  *  Commands helper functions
1478  *
1479  ***************************************************************************/
1480
1481
1482 static void
1483 linphonec_proxy_add(LinphoneCore *lc)
1484 {
1485         bool_t enable_register=FALSE;
1486         LinphoneProxyConfig *cfg;
1487
1488         linphonec_out("Adding new proxy setup. Hit ^D to abort.\n");
1489
1490         /*
1491          * SIP Proxy address
1492          */
1493         while (1)
1494         {
1495                 char *input=linphonec_readline("Enter proxy sip address: ");
1496                 char *clean;
1497
1498                 if ( ! input ) {
1499                         linphonec_out("Aborted.\n");
1500                         return;
1501                 }
1502
1503                 /* Strip blanks */
1504                 clean=lpc_strip_blanks(input);
1505                 if ( ! *clean ) {
1506                         free(input);
1507                         continue;
1508                 }
1509
1510                 cfg=linphone_proxy_config_new();
1511                 if (linphone_proxy_config_set_server_addr(cfg,clean)<0)
1512                 {
1513                         linphonec_out("Invalid sip address (sip:sip.domain.tld).\n");
1514                         free(input);
1515                         linphone_proxy_config_destroy(cfg);
1516                         continue;
1517                 }
1518                 free(input);
1519                 break;
1520         }
1521
1522         /*
1523          * SIP Proxy identity
1524          */
1525         while (1)
1526         {
1527                 char *input=linphonec_readline("Your identity for this proxy: ");
1528                 char *clean;
1529
1530                 if ( ! input ) {
1531                         linphonec_out("Aborted.\n");
1532                         linphone_proxy_config_destroy(cfg);
1533                         return;
1534                 }
1535
1536                 /* Strip blanks */
1537                 clean=lpc_strip_blanks(input);
1538                 if ( ! *clean ) {
1539                         free(input);
1540                         continue;
1541                 }
1542
1543                 linphone_proxy_config_set_identity(cfg, clean);
1544                 if ( ! linphone_proxy_config_get_identity (cfg))
1545                 {
1546                         linphonec_out("Invalid identity (sip:name@sip.domain.tld).\n");
1547                         free(input);
1548                         continue;
1549                 }
1550                 free(input);
1551                 break;
1552         }
1553
1554         /*
1555          * SIP Proxy enable register
1556          */
1557         while (1)
1558         {
1559                 char *input=linphonec_readline("Do you want to register on this proxy (yes/no): ");
1560                 char *clean;
1561
1562                 if ( ! input ) {
1563                         linphonec_out("Aborted.\n");
1564                         linphone_proxy_config_destroy(cfg);
1565                         return;
1566                 }
1567
1568                 /* Strip blanks */
1569                 clean=lpc_strip_blanks(input);
1570                 if ( ! *clean ) {
1571                         free(input);
1572                         continue;
1573                 }
1574
1575                 if ( ! strcmp(clean, "yes") ) enable_register=TRUE;
1576                 else if ( ! strcmp(clean, "no") ) enable_register=FALSE;
1577                 else {
1578                         linphonec_out("Please answer with 'yes' or 'no'\n");
1579                         free(input);
1580                         continue;
1581                 }
1582                 linphone_proxy_config_enableregister(cfg, enable_register);
1583                 free(input);
1584                 break;
1585         }
1586
1587         /*
1588          * SIP Proxy registration expiration
1589          */
1590         if ( enable_register==TRUE )
1591         {
1592                 long int expires=0;
1593                 while (1)
1594                 {
1595                         char *input=linphonec_readline("Specify register expiration time"
1596                                 " in seconds (default is 600): ");
1597
1598                         if ( ! input ) {
1599                                 linphonec_out("Aborted.\n");
1600                                 linphone_proxy_config_destroy(cfg);
1601                                 return;
1602                         }
1603
1604                         expires=strtol(input, (char **)NULL, 10);
1605                         if ( expires == LONG_MIN || expires == LONG_MAX )
1606                         {
1607                                 linphonec_out("Invalid value: %s\n", strerror(errno));
1608                                 free(input);
1609                                 continue;
1610                         }
1611
1612                         linphone_proxy_config_expires(cfg, expires);
1613                         linphonec_out("Expiration: %d seconds\n", linphone_proxy_config_get_expires (cfg));
1614
1615                         free(input);
1616                         break;
1617                 }
1618         }
1619
1620         /*
1621          * SIP proxy route
1622          */
1623         while (1)
1624         {
1625                 char *input=linphonec_readline("Specify route if needed: ");
1626                 char *clean;
1627
1628                 if ( ! input ) {
1629                         linphonec_out("Aborted.\n");
1630                         linphone_proxy_config_destroy(cfg);
1631                         return;
1632                 }
1633
1634                 /* Strip blanks */
1635                 clean=lpc_strip_blanks(input);
1636                 if ( ! *clean ) {
1637                         free(input);
1638                         linphonec_out("No route specified.\n");
1639                         break;
1640                 }
1641
1642                 linphone_proxy_config_set_route(cfg, clean);
1643                 if ( ! linphone_proxy_config_get_route(cfg) )
1644                 {
1645                         linphonec_out("Invalid route.\n");
1646                         free(input);
1647                         continue;
1648                 }
1649
1650                 free(input);
1651                 break;
1652         }
1653
1654         /*
1655          * Final confirmation 
1656          */
1657         while (1)
1658         {
1659                 char *input;
1660                 char *clean;
1661
1662                 linphonec_out("--------------------------------------------\n");
1663                 linphonec_proxy_display(cfg);
1664                 linphonec_out("--------------------------------------------\n");
1665                 input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: ");
1666
1667
1668                 if ( ! input ) {
1669                         linphonec_out("Aborted.\n");
1670                         linphone_proxy_config_destroy(cfg);
1671                         return;
1672                 }
1673
1674                 /* Strip blanks */
1675                 clean=lpc_strip_blanks(input);
1676                 if ( ! *clean ) {
1677                         free(input);
1678                         continue;
1679                 }
1680
1681                 if ( ! strcmp(clean, "yes") ) break;
1682                 else if ( ! strcmp(clean, "no") )
1683                 {
1684                         linphonec_out("Declined.\n");
1685                         linphone_proxy_config_destroy(cfg);
1686                         free(input);
1687                         return;
1688                 }
1689
1690                 linphonec_out("Please answer with 'yes' or 'no'\n");
1691                 free(input);
1692                 continue;
1693         }
1694
1695
1696         linphone_core_add_proxy_config(lc,cfg);
1697
1698         /* automatically set the last entered proxy as the default one */
1699         linphone_core_set_default_proxy(lc,cfg);
1700
1701         linphonec_out("Proxy added.\n");
1702 }
1703
1704 static void
1705 linphonec_proxy_display(LinphoneProxyConfig *cfg)
1706 {
1707         const char *route=linphone_proxy_config_get_route(cfg);
1708         const char *identity=linphone_proxy_config_get_identity(cfg);
1709         linphonec_out("sip address: %s\nroute: %s\nidentity: %s\nregister: %s\nexpires: %i\nregistered: %s\n",
1710                         linphone_proxy_config_get_addr(cfg),
1711                         (route!=NULL)? route:"",
1712                         (identity!=NULL)?identity:"",
1713                         linphone_proxy_config_register_enabled (cfg)?"yes":"no",
1714                         linphone_proxy_config_get_expires (cfg),
1715                         linphone_proxy_config_is_registered(cfg) ? "yes" : "no");
1716 }
1717
1718 static void linphonec_proxy_show(LinphoneCore *lc, int index)
1719 {
1720         const MSList *elem;
1721         int i;
1722         for(elem=linphone_core_get_proxy_config_list(lc),i=0;elem!=NULL;elem=elem->next,++i){
1723                 if (index==i){
1724                         LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)elem->data;
1725                         linphonec_proxy_display(cfg);
1726                         return;
1727                 }
1728         }
1729         linphonec_out("No proxy with index %i\n", index);
1730 }
1731
1732 static void
1733 linphonec_proxy_list(LinphoneCore *lc)
1734 {
1735         const MSList *proxies;
1736         int n;
1737         int def=linphone_core_get_default_proxy(lc,NULL);
1738         
1739         proxies=linphone_core_get_proxy_config_list(lc);
1740         for(n=0;proxies!=NULL;proxies=ms_list_next(proxies),n++){
1741                 if (n==def)
1742                         linphonec_out("****** Proxy %i - this is the default one - *******\n",n);
1743                 else 
1744                         linphonec_out("****** Proxy %i *******\n",n);
1745                 linphonec_proxy_display((LinphoneProxyConfig*)proxies->data);
1746         }
1747         if ( ! n ) linphonec_out("No proxies defined\n");
1748 }
1749
1750 static void
1751 linphonec_proxy_remove(LinphoneCore *lc, int index)
1752 {
1753         const MSList *proxies;
1754         LinphoneProxyConfig *cfg;
1755         proxies=linphone_core_get_proxy_config_list(lc);
1756         cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1757         if (cfg==NULL){
1758                 linphonec_out("No such proxy.\n");
1759                 return;
1760         }
1761         linphone_core_remove_proxy_config(lc,cfg);
1762         linphonec_out("Proxy %s removed.\n", linphone_proxy_config_get_addr(cfg));
1763 }
1764
1765 static int
1766 linphonec_proxy_use(LinphoneCore *lc, int index)
1767 {
1768         const MSList *proxies;
1769         LinphoneProxyConfig *cfg;
1770         proxies=linphone_core_get_proxy_config_list(lc);
1771         cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1772         if (cfg==NULL){
1773                 linphonec_out("No such proxy (try 'proxy list').");
1774                 return 0;
1775         }
1776         linphone_core_set_default_proxy(lc,cfg);
1777         return 1;
1778 }
1779
1780 static void
1781 linphonec_friend_display(LinphoneFriend *fr)
1782 {
1783         LinphoneAddress *uri=linphone_address_clone(linphone_friend_get_address(fr));
1784         char *str;
1785         
1786         linphonec_out("name: %s\n", linphone_address_get_display_name(uri));
1787         linphone_address_set_display_name(uri,NULL);
1788         str=linphone_address_as_string(uri);
1789         linphonec_out("address: %s\n", str);
1790 }
1791
1792 static int
1793 linphonec_friend_list(LinphoneCore *lc, char *pat)
1794 {
1795         const MSList *friend;
1796         int n;
1797
1798         if (pat) {
1799                 pat=lpc_strip_blanks(pat);
1800                 if (!*pat) pat = NULL;
1801         }
1802
1803         friend = linphone_core_get_friend_list(lc);
1804         for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1805         {
1806                 if ( pat ) {
1807                         const char *name = linphone_address_get_display_name(
1808                             linphone_friend_get_address((LinphoneFriend*)friend->data));
1809                         if (name && ! strstr(name, pat) ) continue;
1810                 }
1811                 linphonec_out("****** Friend %i *******\n",n);
1812                 linphonec_friend_display((LinphoneFriend*)friend->data);
1813         }
1814
1815         return 1;
1816 }
1817
1818 static int
1819 linphonec_friend_call(LinphoneCore *lc, unsigned int num)
1820 {
1821         const MSList *friend = linphone_core_get_friend_list(lc);
1822         unsigned int n;
1823         char *addr;
1824
1825         for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1826         {
1827                 if ( n == num )
1828                 {
1829                         int ret;
1830                         addr = linphone_address_as_string(linphone_friend_get_address((LinphoneFriend*)friend->data));
1831                         ret=lpc_cmd_call(lc, addr);
1832                         ms_free(addr);
1833                         return ret;
1834                 }
1835         }
1836         linphonec_out("No such friend %u\n", num);
1837         return 1;
1838 }
1839
1840 #ifndef WIN32
1841 static int
1842 linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr)
1843 {
1844         LinphoneFriend *newFriend;
1845
1846         char url[PATH_MAX];
1847
1848         snprintf(url, PATH_MAX, "%s <%s>", name, addr);
1849         newFriend = linphone_friend_new_with_addr(url);
1850         linphone_core_add_friend(lc, newFriend);
1851         return 0;
1852 }
1853 #endif
1854
1855 static int
1856 linphonec_friend_delete(LinphoneCore *lc, int num)
1857 {
1858         const MSList *friend = linphone_core_get_friend_list(lc);
1859         unsigned int n;
1860
1861         for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1862         {
1863                 if ( n == num )
1864                 {
1865                         linphone_core_remove_friend(lc, friend->data);
1866                         return 0;
1867                 }
1868         }
1869
1870         if (-1 == num) 
1871         {
1872                 unsigned int i;
1873                 for (i = 0 ; i < n ; i++)
1874                         linphonec_friend_delete(lc, 0);
1875                 return 0;
1876         }
1877
1878         linphonec_out("No such friend %u\n", num);
1879         return 1;
1880 }
1881
1882 static void
1883 linphonec_display_command_help(LPC_COMMAND *cmd)
1884 {
1885         if ( cmd->doc ) linphonec_out ("%s\n", cmd->doc);
1886         else linphonec_out("%s\n", cmd->help);
1887 }
1888
1889
1890 static int lpc_cmd_register(LinphoneCore *lc, char *args){
1891         char identity[512];
1892         char proxy[512];
1893         char passwd[512];
1894         LinphoneProxyConfig *cfg;
1895         const MSList *elem;
1896     
1897         if (!args)
1898         {
1899                 /* it means that you want to register the default proxy */
1900                 LinphoneProxyConfig *cfg=NULL;
1901                 linphone_core_get_default_proxy(lc,&cfg);
1902                 if (cfg)
1903                 {
1904                         if(!linphone_proxy_config_is_registered(cfg)) {
1905                                 linphone_proxy_config_enable_register(cfg,TRUE);
1906                                 linphone_proxy_config_done(cfg);
1907                         }else{
1908                                 linphonec_out("default proxy already registered\n");
1909                         }
1910                 }else{
1911                         linphonec_out("we do not have a default proxy\n");
1912                         return 0;
1913                 }
1914                 return 1;
1915         }
1916         passwd[0]=proxy[0]=identity[0]='\0';
1917         sscanf(args,"%511s %511s %511s",identity,proxy,passwd);
1918         if (proxy[0]=='\0' || identity[0]=='\0'){
1919                 linphonec_out("Missing parameters, see help register\n");
1920                 return 1;
1921         }
1922         if (passwd[0]!='\0'){
1923                 LinphoneAddress *from;
1924                 LinphoneAuthInfo *info;
1925                 if ((from=linphone_address_new(identity))!=NULL){
1926                         char realm[128];
1927                         snprintf(realm,sizeof(realm)-1,"\"%s\"",linphone_address_get_domain(from));
1928                         info=linphone_auth_info_new(linphone_address_get_username(from),NULL,passwd,NULL,NULL);
1929                         linphone_core_add_auth_info(lc,info);
1930                         linphone_address_destroy(from);
1931                         linphone_auth_info_destroy(info);
1932                 }
1933         }
1934         elem=linphone_core_get_proxy_config_list(lc);
1935         if (elem) {
1936                 cfg=(LinphoneProxyConfig*)elem->data;
1937                 linphone_proxy_config_edit(cfg);
1938         }
1939         else cfg=linphone_proxy_config_new();
1940         linphone_proxy_config_set_identity(cfg,identity);
1941         linphone_proxy_config_set_server_addr(cfg,proxy);
1942         linphone_proxy_config_enable_register(cfg,TRUE);
1943         if (elem) linphone_proxy_config_done(cfg);
1944         else linphone_core_add_proxy_config(lc,cfg);
1945         linphone_core_set_default_proxy(lc,cfg);
1946         return 1;
1947 }
1948
1949 static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
1950         LinphoneProxyConfig *cfg=NULL;
1951         linphone_core_get_default_proxy(lc,&cfg);
1952         if (cfg && linphone_proxy_config_is_registered(cfg)) {
1953                 linphone_proxy_config_edit(cfg);
1954                 linphone_proxy_config_enable_register(cfg,FALSE);
1955                 linphone_proxy_config_done(cfg);
1956         }else{
1957                 linphonec_out("unregistered\n");
1958         }
1959         return 1;
1960 }
1961
1962 static int lpc_cmd_duration(LinphoneCore *lc, char *args){
1963         LinphoneCallLog *cl;
1964         const MSList *elem=linphone_core_get_call_logs(lc);
1965         for(;elem!=NULL;elem=elem->next){
1966                 if (elem->next==NULL){
1967                         cl=(LinphoneCallLog*)elem->data;
1968                         linphonec_out("%i seconds\n",cl->duration);
1969                 }
1970         }
1971         return 1;
1972 }
1973
1974 static int lpc_cmd_status(LinphoneCore *lc, char *args)
1975 {
1976         LinphoneProxyConfig *cfg;
1977         
1978         if ( ! args ) return 0;
1979         linphone_core_get_default_proxy(lc,&cfg);
1980         if (strstr(args,"register"))
1981         {
1982                 if (cfg)
1983                 {
1984                         if (linphone_proxy_config_is_registered(cfg)){
1985                                 linphonec_out("registered, identity=%s duration=%i\n",
1986                                         linphone_proxy_config_get_identity(cfg),
1987                                         linphone_proxy_config_get_expires(cfg));
1988                         }else if (linphone_proxy_config_register_enabled(cfg)){
1989                                 linphonec_out("registered=-1\n");
1990                         }else linphonec_out("registered=0\n");
1991                 }
1992                 else linphonec_out("registered=0\n");
1993         }
1994         else if (strstr(args,"autoanswer"))
1995         {
1996                 if (cfg && linphone_proxy_config_is_registered(cfg))
1997                         linphonec_out("autoanswer=%i\n",linphonec_get_autoanswer());
1998                 else linphonec_out("unregistered\n");
1999         }
2000         else if (strstr(args,"hook"))
2001         {
2002                 LinphoneCall *call=linphone_core_get_current_call (lc);
2003                 LinphoneCallState call_state=LinphoneCallIdle;
2004                 if (call) call_state=linphone_call_get_state(call);
2005
2006                 switch(call_state){
2007                         case LinphoneCallOutgoingInit:
2008                                 linphonec_out("hook=outgoing_init sip:%s\n",linphonec_get_callee());
2009                         break;
2010                         case LinphoneCallOutgoingProgress:
2011                                 linphonec_out("hook=dialing sip:%s\n",linphonec_get_callee());
2012                         break;
2013                         case LinphoneCallOutgoingRinging:
2014                                 linphonec_out("hook=ringing sip:%s\n",linphonec_get_callee());
2015                         break;
2016                         case LinphoneCallPaused:
2017                                 linphonec_out("hook=paused sip:%s\n",linphonec_get_callee());
2018                         break;
2019                         case LinphoneCallIdle:
2020                                 linphonec_out("hook=offhook\n");
2021                         break;
2022                         case LinphoneCallStreamsRunning:
2023                         case LinphoneCallConnected:
2024                                 if (linphone_call_get_dir(call)==LinphoneCallOutgoing){
2025                                         linphonec_out("Call out, hook=%s duration=%i, muted=%s rtp-xmit-muted=%s\n", linphonec_get_callee(),
2026                                               linphone_core_get_current_call_duration(lc),
2027                                               linphone_core_is_mic_muted (lc) ? "yes" : "no",
2028                                               linphone_core_is_rtp_muted(lc) ? "yes"  : "no");
2029                                 }else{
2030                                         linphonec_out("hook=answered duration=%i %s\n" ,
2031                                                 linphone_core_get_current_call_duration(lc), linphonec_get_caller());
2032                                 }
2033                                 break;
2034                         case LinphoneCallIncomingReceived:
2035                                 linphonec_out("Incoming call from %s\n",linphonec_get_caller());
2036                                 break;
2037                         default:
2038                                 break;
2039                 }
2040                 
2041         }
2042         else return 0;
2043
2044         return 1;
2045 }
2046
2047 static int lpc_cmd_ports(LinphoneCore *lc, char *args)
2048 {
2049         int port;
2050         if ( ! args ){
2051                 linphonec_out("sip port = %i\naudio rtp port = %i\nvideo rtp port = %i\n",
2052                         linphone_core_get_sip_port(lc),
2053                         linphone_core_get_audio_port(lc),
2054                         linphone_core_get_video_port(lc));
2055                 return 1;
2056         }
2057         if (sscanf(args,"sip %i",&port)==1){
2058                 linphonec_out("Setting sip port to %i\n",port);
2059                 linphone_core_set_sip_port(lc,port);
2060         }else return 0;
2061
2062         return 1;
2063 }
2064
2065 static int lpc_cmd_param(LinphoneCore *lc, char *args)
2066 {
2067         char section[20], param[20], value[50];
2068         const char *string;
2069
2070         if (args == NULL) {
2071                 return 0;
2072         }
2073         switch (sscanf(args,"%19s %19s %49s",section,param,value)) {
2074                 // case 1 might show all current settings under a section
2075                 case 2:
2076                         string = lp_config_get_string(linphone_core_get_config(lc), section, param, "(undef)");
2077                         linphonec_out("current value: %s\n", string);
2078                         break;
2079                 case 3:
2080                         if (lp_config_get_string(linphone_core_get_config(lc), section, param, NULL) != NULL) {
2081                                 lp_config_set_string(linphone_core_get_config(lc), section, param, value);
2082                         // no indication of existence
2083                                 linphonec_out("updated value: %s\n", value);
2084                         } else {
2085                                 linphonec_out("only update of existing variables are allowed\n");
2086                         }
2087                         break;
2088                 default:
2089                         return 0;
2090     }
2091         return 1;
2092 }
2093
2094 static int lpc_cmd_speak(LinphoneCore *lc, char *args){
2095 #ifndef WIN32
2096         char voice[64];
2097         char *sentence;
2098         char cl[128];
2099         char *wavfile;
2100         int status;
2101         FILE *file;
2102         
2103     if (!args) return 0;
2104         memset(voice,0,sizeof(voice));
2105         sscanf(args,"%63s",voice);
2106         sentence=args+strlen(voice);
2107         wavfile=tempnam("/tmp/","linphonec-espeak-");
2108         snprintf(cl,sizeof(cl),"espeak -v %s -s 100 -w %s --stdin",voice,wavfile);
2109         file=popen(cl,"w");
2110         if (file==NULL){
2111                 ms_error("Could not open pipe to espeak !");
2112                 return 1;
2113         }
2114         fprintf(file,"%s",sentence);
2115         status=pclose(file);
2116         if (WEXITSTATUS(status)==0){
2117                 linphone_core_set_play_file(lc,wavfile);
2118         }else{
2119                 linphonec_out("espeak command failed.");
2120         }
2121 #else
2122         linphonec_out("Sorry, this command is not implemented in windows version.");
2123 #endif
2124         return 1;
2125 }
2126
2127 static int lpc_cmd_acodec(LinphoneCore *lc, char *args){
2128     return lpc_cmd_codec(AUDIO, lc, args);
2129 }
2130
2131 static int lpc_cmd_vcodec(LinphoneCore *lc, char *args){
2132     return lpc_cmd_codec(VIDEO, lc, args);
2133 }
2134
2135 static int lpc_cmd_codec(int type, LinphoneCore *lc, char *args){
2136         char *arg1 = args;
2137         char *arg2 = NULL;
2138         char *ptr = args;
2139
2140         if (!args) return 0;
2141
2142         /* Isolate first and second arg */
2143         while(*ptr && !isspace(*ptr)) ++ptr;
2144         if ( *ptr )
2145         {
2146                 *ptr='\0';
2147                 arg2=ptr+1;
2148                 while(*arg2 && isspace(*arg2)) ++arg2;
2149         }
2150
2151         if (strcmp(arg1,"enable")==0)
2152         {
2153 #ifdef HAVE_READLINE
2154                 rl_inhibit_completion=1;
2155 #endif
2156         if (!strcmp(arg2,"all")) linphonec_codec_enable(type,lc,-1);
2157         else linphonec_codec_enable(type,lc,atoi(arg2));
2158 #ifdef HAVE_READLINE
2159                 rl_inhibit_completion=0;
2160 #endif
2161         }
2162         else if (strcmp(arg1,"list")==0)
2163         {
2164                 linphonec_codec_list(type,lc);
2165         }
2166         else if (strcmp(arg1,"disable")==0)
2167         {
2168         if (!strcmp(arg2,"all")) linphonec_codec_disable(type,lc,-1);
2169         else linphonec_codec_disable(type,lc,atoi(arg2));
2170         }
2171         else
2172         {
2173                 return 0; /* syntax error */
2174         }
2175
2176         return 1;
2177 }
2178
2179 static void linphonec_codec_list(int type, LinphoneCore *lc){
2180         PayloadType *pt;
2181         int index=0;
2182         const MSList *node=NULL;
2183
2184     if (type == AUDIO) {
2185       node=linphone_core_get_audio_codecs(lc);
2186     } else if(type==VIDEO) {
2187       node=linphone_core_get_video_codecs(lc);
2188     }
2189
2190         for(;node!=NULL;node=ms_list_next(node)){
2191                 pt=(PayloadType*)(node->data);
2192         linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, 
2193                     linphone_core_payload_type_enabled(lc,pt) ? "enabled" : "disabled");
2194                 index++;
2195         }
2196 }
2197
2198 static void linphonec_codec_enable(int type, LinphoneCore *lc, int sel_index){
2199         PayloadType *pt;
2200         int index=0;
2201         const MSList *node=NULL;
2202
2203         if (type == AUDIO) {
2204                 node=linphone_core_get_audio_codecs(lc);
2205         } else if(type==VIDEO) {
2206                 node=linphone_core_get_video_codecs(lc);
2207         }
2208
2209     for(;node!=NULL;node=ms_list_next(node)){
2210         if (index == sel_index || sel_index == -1) {
2211                     pt=(PayloadType*)(node->data);
2212             linphone_core_enable_payload_type (lc,pt,TRUE);
2213             linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "enabled");
2214         }
2215                 index++;
2216         }
2217 }
2218
2219 static void linphonec_codec_disable(int type, LinphoneCore *lc, int sel_index){
2220         PayloadType *pt;
2221         int index=0;
2222         const MSList *node=NULL;
2223
2224         if (type == AUDIO) {
2225                 node=linphone_core_get_audio_codecs(lc);
2226         } else if(type==VIDEO) {
2227                 node=linphone_core_get_video_codecs(lc);
2228         }
2229
2230         for(;node!=NULL;node=ms_list_next(node)){
2231                 if (index == sel_index || sel_index == -1) {
2232                         pt=(PayloadType*)(node->data);
2233                         linphone_core_enable_payload_type (lc,pt,FALSE);
2234                         linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "disabled");
2235                 }
2236                 index++;
2237         }
2238 }
2239
2240 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){
2241         char *arg1 = args;
2242         char *arg2 = NULL;
2243         char *ptr = args;
2244         LpConfig *config=linphone_core_get_config(lc);
2245
2246         if (!args) return 0;
2247
2248         /* Isolate first and second arg */
2249         while(*ptr && !isspace(*ptr)) ++ptr;
2250         if ( *ptr )
2251         {
2252                 *ptr='\0';
2253                 arg2=ptr+1;
2254                 while(*arg2 && isspace(*arg2)) ++arg2;
2255         }
2256
2257         if (strcmp(arg1,"on")==0){
2258         int delay, tail_len, frame_size;
2259         int n;
2260
2261         linphone_core_enable_echo_cancellation(lc,1);
2262
2263         if (arg2 != 0) {
2264             n = sscanf(arg2, "%d %d %d", &delay, &tail_len, &frame_size);
2265
2266             if (n == 1) {   
2267                 lp_config_set_int(config,"sound","ec_delay",delay);
2268             }
2269             else if (n == 2) {
2270                 lp_config_set_int(config,"sound","ec_delay",delay);
2271                 lp_config_set_int(config,"sound","ec_tail_len",tail_len);
2272             }
2273             else if (n == 3) {
2274                 lp_config_set_int(config,"sound","ec_delay",delay);
2275                 lp_config_set_int(config,"sound","ec_tail_len",tail_len);
2276                 lp_config_set_int(config,"sound","ec_framesize",frame_size);
2277             }
2278         }
2279     }
2280     else if (strcmp(arg1,"off")==0){
2281         linphone_core_enable_echo_cancellation(lc,0);
2282     }
2283     else if (strcmp(arg1,"show")==0){
2284         linphonec_out("echo cancellation is %s; delay %d, tail length %d, frame size %d\n", 
2285             linphone_core_echo_cancellation_enabled(lc) ? "on" : "off",
2286             lp_config_get_int(config,"sound","ec_delay",0),
2287             lp_config_get_int(config,"sound","ec_tail_len",0),
2288             lp_config_get_int(config,"sound","ec_framesize",0));        
2289     }
2290     else {
2291         return 0;
2292     }
2293
2294     return 1;
2295 }
2296
2297 static int lpc_cmd_echolimiter(LinphoneCore *lc, char *args){
2298         if (args){
2299                 if (strcmp(args,"on")==0){
2300                         linphone_core_enable_echo_limiter (lc,TRUE);
2301                 }else if (strcmp(args,"off")==0){
2302                         linphone_core_enable_echo_limiter (lc,FALSE);
2303                 }
2304         }
2305         linphonec_out("Echo limiter is now %s.\n",linphone_core_echo_limiter_enabled (lc) ? "on":"off");
2306         return 1;
2307 }
2308
2309 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args)
2310 {
2311         linphone_core_mute_mic(lc, 1);
2312         return 1;
2313 }
2314
2315 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args){
2316         linphone_core_mute_mic(lc, 0);
2317         return 1;
2318 }
2319
2320 static int lpc_cmd_playback_gain(LinphoneCore *lc, char *args)
2321 {
2322         if (args){
2323                 linphone_core_set_playback_gain_db(lc, atof(args));
2324                 return 1;
2325         }
2326         return 0;
2327 }
2328
2329 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args)
2330 {
2331         bool_t rtp_xmit_off=FALSE;
2332         char *status;
2333
2334         if(args){
2335                 if(strstr(args,"1"))rtp_xmit_off=TRUE;
2336                 if(linphone_core_get_current_call (lc)==NULL)
2337                         linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_xmit_off);
2338                 else 
2339                         linphonec_out("nortp-on-audio-mute: call in progress - cannot change state\n");
2340         }
2341         rtp_xmit_off=linphone_core_get_rtp_no_xmit_on_audio_mute(lc);
2342         if (rtp_xmit_off) status="off";
2343         else status="on";
2344         linphonec_out("rtp transmit %s when audio muted\n",status);
2345         return 1;
2346 }
2347
2348 #ifdef VIDEO_ENABLED
2349 static int _lpc_cmd_video_window(LinphoneCore *lc, char *args, bool_t is_preview){
2350         char subcommand[64];
2351         int a,b;
2352         int err;
2353         VideoParams *params=is_preview ? &lpc_preview_params : &lpc_video_params;
2354
2355         if (!args) return 0;
2356         err=sscanf(args,"%63s %i %i",subcommand,&a,&b);
2357         if (err>=1){
2358                 if (strcmp(subcommand,"pos")==0){
2359                         if (err<3) return 0;
2360                         params->x=a;
2361                         params->y=b;
2362                         params->refresh=TRUE;
2363                 }else if (strcmp(subcommand,"size")==0){
2364                         if (err<3) return 0;
2365                         params->w=a;
2366                         params->h=b;
2367                         params->refresh=TRUE;
2368                 }else if (strcmp(subcommand,"show")==0){
2369                         params->show=TRUE;
2370                         params->refresh=TRUE;
2371                         if (is_preview) linphone_core_enable_video_preview (lc,TRUE);
2372                 }else if (strcmp(subcommand,"hide")==0){
2373                         params->show=FALSE;
2374                         params->refresh=TRUE;
2375                         if (is_preview) linphone_core_enable_video_preview (lc,FALSE);
2376                 }else if (strcmp(subcommand,"id")==0){
2377                         if (err == 1){
2378                                 linphonec_out("vwindow id: 0x%x\n",is_preview ? linphone_core_get_native_preview_window_id (lc) :
2379                                               linphone_core_get_native_video_window_id (lc));
2380                                 return 1;
2381                         } else if (err != 2) return 0;
2382                         params->wid=a;
2383                         if (is_preview)
2384                                 linphone_core_set_native_preview_window_id (lc,a);
2385                         else
2386                                 linphone_core_set_native_video_window_id(lc,a);
2387                 }else if (is_preview==TRUE){
2388                         if (strcmp(subcommand,"integrated")==0){
2389                                 linphone_core_use_preview_window (lc,FALSE);
2390                         }else if (strcmp(subcommand,"standalone")==0){
2391                                 linphone_core_use_preview_window(lc,TRUE);
2392                         }else return 0;
2393                 }else return 0;
2394         }
2395         return 1;
2396 }
2397
2398 static int lpc_cmd_video_window(LinphoneCore *lc, char *args){
2399         return _lpc_cmd_video_window(lc, args, FALSE);
2400 }
2401
2402 static int lpc_cmd_preview_window(LinphoneCore *lc, char *args){
2403         return _lpc_cmd_video_window(lc, args, TRUE);
2404 }
2405 #endif
2406
2407 static void lpc_display_global_state(LinphoneCore *lc){
2408         linphonec_out("Global liblinphone state\n%s\n",
2409                       linphone_global_state_to_string(linphone_core_get_global_state(lc)));
2410 }
2411
2412 static void lpc_display_call_states(LinphoneCore *lc){
2413         LinphoneCall *call;
2414         const MSList *elem;
2415         char *tmp;
2416         linphonec_out("Call states\n"
2417                       "Id |            Destination              |      State      |    Flags   |\n"
2418                       "------------------------------------------------------------------------\n");
2419         elem=linphone_core_get_calls(lc);
2420         if (elem==NULL){
2421                 linphonec_out("(empty)\n");
2422         }else{
2423                 for(;elem!=NULL;elem=elem->next){
2424                         const char *flag;
2425                         call=(LinphoneCall*)elem->data;
2426                         bool_t in_conference=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
2427                         tmp=linphone_call_get_remote_address_as_string (call);
2428                         flag=in_conference ? "conferencing" : "";
2429                         flag=linphone_call_has_transfer_pending(call) ? "transfer pending" : flag;
2430                         linphonec_out("%-2i | %-35s | %-15s | %s\n",(int)(long)linphone_call_get_user_pointer(call),
2431                                                   tmp,linphone_call_state_to_string(linphone_call_get_state(call))+strlen("LinphoneCall"),flag);
2432                         ms_free(tmp);
2433                 }
2434         }
2435 }
2436
2437 static void lpc_display_proxy_states(LinphoneCore *lc){
2438         const MSList *elem;
2439         linphonec_out("Proxy registration states\n"
2440                       "           Identity                      |      State\n"
2441                       "------------------------------------------------------------\n");
2442         elem=linphone_core_get_proxy_config_list (lc);
2443         if (elem==NULL) linphonec_out("(empty)\n");
2444         else {
2445                 for(;elem!=NULL;elem=elem->next){
2446                         LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2447                         linphonec_out("%-40s | %s\n",linphone_proxy_config_get_identity (cfg),
2448                                                   linphone_registration_state_to_string(linphone_proxy_config_get_state(cfg)));
2449                 }
2450         }
2451 }
2452
2453 static int lpc_cmd_states(LinphoneCore *lc, char *args){
2454         if (args==NULL) {
2455                 lpc_display_global_state(lc);
2456                 lpc_display_call_states(lc);
2457                 lpc_display_proxy_states(lc);
2458                 return 1;
2459         }
2460         if (strcmp(args,"global")==0){
2461                 lpc_display_global_state(lc);
2462                 return 1;
2463         }
2464         if (strcmp(args,"proxies")==0){
2465                 lpc_display_proxy_states(lc);
2466                 return 1;
2467         }
2468         if (strcmp(args,"calls")==0){
2469                 lpc_display_call_states(lc);
2470                 return 1;
2471         }
2472         return 0;
2473 }
2474
2475 #ifdef VIDEO_ENABLED
2476 static int lpc_cmd_camera(LinphoneCore *lc, char *args){
2477         LinphoneCall *call=linphone_core_get_current_call(lc);
2478         bool_t activated=FALSE;
2479         
2480         if (linphone_core_video_enabled (lc)==FALSE){
2481                 linphonec_out("Video is disabled, re-run linphonec with -V option.");
2482                 return 1;
2483         }
2484
2485         if (args){
2486                 if (strcmp(args,"on")==0)
2487                         activated=TRUE;
2488                 else if (strcmp(args,"off")==0)
2489                         activated=FALSE;
2490                 else
2491                         return 0;
2492         }
2493
2494         if (call==NULL){
2495                 if (args){
2496                         linphonec_camera_enabled=activated;
2497                 }
2498                 if (linphonec_camera_enabled){
2499                         linphonec_out("Camera is enabled. Video stream will be setup immediately for outgoing and incoming calls.\n");
2500                 }else{
2501                         linphonec_out("Camera is disabled. Calls will be established with audio-only, with the possibility to later add video using 'camera on'.\n");
2502                 }
2503         }else{
2504                 const LinphoneCallParams *cp=linphone_call_get_current_params (call);
2505                 if (args){
2506                         linphone_call_enable_camera(call,activated);
2507                         if ((activated && !linphone_call_params_video_enabled (cp))){
2508                                 /*update the call to add the video stream*/
2509                                 LinphoneCallParams *ncp=linphone_call_params_copy(cp);
2510                                 linphone_call_params_enable_video(ncp,TRUE);
2511                                 linphone_core_update_call(lc,call,ncp);
2512                                 linphone_call_params_destroy (ncp);
2513                                 linphonec_out("Trying to bring up video stream...\n");
2514                         }
2515                 }
2516                 if (linphone_call_camera_enabled (call))
2517                                 linphonec_out("Camera is allowed for current call.\n");
2518                 else linphonec_out("Camera is dis-allowed for current call.\n");
2519         }
2520         return 1;
2521 }
2522
2523 static int lpc_cmd_snapshot(LinphoneCore *lc, char *args){
2524         LinphoneCall *call;
2525         if (!args) return 0;
2526         call=linphone_core_get_current_call(lc);
2527         if (call!=NULL){
2528                 linphone_call_take_video_snapshot(call,args);
2529                 linphonec_out("Taking video snapshot in file %s\n", args);
2530         }else linphonec_out("There is no active call.\n");
2531         return 1;
2532 }
2533
2534 static int lpc_cmd_vfureq(LinphoneCore *lc, char *arg){
2535         LinphoneCall *call;
2536         call=linphone_core_get_current_call(lc);
2537         if (call!=NULL){
2538                 linphone_call_send_vfu_request(call);
2539                 linphonec_out("VFU request sent\n");
2540         }else linphonec_out("There is no active call.\n");
2541         return 1;
2542 }
2543 #endif
2544
2545 static int lpc_cmd_identify(LinphoneCore *lc, char *args){
2546         LinphoneCall *call;
2547         const char *remote_ua;
2548         if (args==NULL){
2549                 call=linphone_core_get_current_call(lc);
2550                 if (call==NULL) {
2551                         linphonec_out("There is currently running call. Specify call id.\n");
2552                         return 0;
2553                 }
2554         }else{
2555                 call=linphonec_get_call(atoi(args));
2556                 if (call==NULL){
2557                         return 0;
2558                 }
2559         }
2560         remote_ua=linphone_call_get_remote_user_agent(call);
2561         if (remote_ua){
2562                 linphonec_out("Remote user agent string is: %s\n",remote_ua);
2563         }
2564         return 1;
2565 }
2566
2567 static int lpc_cmd_ringback(LinphoneCore *lc, char *args){
2568         if (!args) return 0;
2569         if (strcmp(args,"disable")==0){
2570                 linphone_core_set_remote_ringback_tone(lc,NULL);
2571                 linphonec_out("Disabling ringback tone.\n");
2572                 return 1;
2573         }
2574         linphone_core_set_remote_ringback_tone (lc,args);
2575         linphonec_out("Using %s as ringback tone to be played to callers.",args);
2576         return 1;
2577 }
2578
2579 static int zrtp_set_verified(LinphoneCore *lc, char *args, bool_t verified){
2580         LinphoneCall *call=linphone_core_get_current_call(lc);
2581         if (linphone_call_params_get_media_encryption(linphone_call_get_current_params(call))==LinphoneMediaEncryptionZRTP){
2582                 linphone_call_set_authentication_token_verified(call,verified);
2583         }
2584         return 1;
2585 }
2586 static int lpc_cmd_zrtp_verified(LinphoneCore *lc, char *args){
2587         return zrtp_set_verified(lc,args,TRUE);
2588 }
2589 static int lpc_cmd_zrtp_unverified(LinphoneCore *lc, char *args){
2590         return zrtp_set_verified(lc,args,FALSE);
2591 }
2592
2593 /***************************************************************************
2594  *
2595  *  Command table management funx
2596  *
2597  ***************************************************************************/
2598
2599 /*
2600  * Find a command given its name
2601  */
2602 static LPC_COMMAND *
2603 lpc_find_command(const char *name)
2604 {
2605         int i;
2606
2607         for (i=0; commands[i].name; ++i)
2608         {
2609                 if (strcmp(name, commands[i].name) == 0)
2610                         return &commands[i];
2611         }
2612
2613         for (i=0; advanced_commands[i].name; ++i)
2614         {
2615                 if (strcmp(name, advanced_commands[i].name) == 0)
2616                         return &advanced_commands[i];
2617         }
2618
2619         return (LPC_COMMAND *)NULL;
2620 }
2621
2622
2623 /****************************************************************************
2624  *
2625  * $Log: commands.c,v $
2626  * Revision 1.39  2008/07/03 15:08:34  smorlat
2627  * api cleanups, interface in progress.
2628  *
2629  * Revision 1.38  2008/06/17 20:38:59  smorlat
2630  * added missing file.
2631  *
2632  * Revision 1.37  2008/04/09 09:26:00  smorlat
2633  * merge various patches
2634  * H264 support.
2635  *
2636  * Revision 1.36  2007/08/01 14:47:53  strk
2637  *         * console/commands.c: Clean up commands 'nat', 'stun'
2638  *           and 'firewall' to be more intuitive.
2639  *
2640  * Revision 1.35  2007/06/27 09:01:25  smorlat
2641  * logging improvements.
2642  *
2643  * Revision 1.34  2007/02/20 10:17:13  smorlat
2644  * linphonec friends patch2
2645  *
2646  * Revision 1.31  2006/09/22 07:22:47  smorlat
2647  * linphonecore api changes.
2648  *
2649  * Revision 1.30  2006/09/08 15:32:57  smorlat
2650  * support for using files instead of soundcard (used by linphonec only)
2651  *
2652  * Revision 1.29  2006/08/28 14:29:07  smorlat
2653  * fix bug.
2654  *
2655  * Revision 1.28  2006/08/21 12:49:59  smorlat
2656  * merged several little patches.
2657  *
2658  * Revision 1.27  2006/07/17 18:45:00  smorlat
2659  * support for several event queues in ortp.
2660  * glib dependency removed from coreapi/ and console/
2661  *
2662  * Revision 1.26  2006/04/14 15:16:36  smorlat
2663  * soundcard use did nothing !
2664  *
2665  * Revision 1.25  2006/04/06 20:09:33  smorlat
2666  * add linphonec command to see and select sound devices.
2667  *
2668  * Revision 1.24  2006/03/04 11:17:10  smorlat
2669  * mediastreamer2 in progress.
2670  *
2671  * Revision 1.23  2006/02/20 21:14:01  strk
2672  * Handled syntax errors with 'friend' command
2673  *
2674  * Revision 1.22  2006/02/20 10:20:29  strk
2675  * Added substring-based filter support for command 'friend list'
2676  *
2677  * Revision 1.21  2006/02/02 15:39:18  strk
2678  * - Added 'friend list' and 'friend call' commands
2679  * - Allowed for multiple DTFM send in a single line
2680  * - Added status-specific callback (bare version)
2681  *
2682  * Revision 1.20  2006/01/26 11:54:34  strk
2683  * More robust 'nat' command handler (strip blanks in args)
2684  *
2685  * Revision 1.19  2006/01/26 09:48:05  strk
2686  * Added limits.h include
2687  *
2688  * Revision 1.18  2006/01/26 02:18:05  strk
2689  * Added new commands 'nat use' and 'nat unuse'.
2690  * These will required a pending patch to linphonecore.c
2691  * in order to work.
2692  *
2693  * Revision 1.17  2006/01/20 14:12:33  strk
2694  * Added linphonec_init() and linphonec_finish() functions.
2695  * Handled SIGINT and SIGTERM to invoke linphonec_finish().
2696  * Handling of auto-termination (-t) moved to linphonec_finish().
2697  * Reworked main (input read) loop to not rely on 'terminate'
2698  * and 'run' variable (dropped). configfile_name allocated on stack
2699  * using PATH_MAX limit. Changed print_usage signature to allow
2700  * for an exit_status specification.
2701  *
2702  * Revision 1.16  2006/01/18 09:25:32  strk
2703  * Command completion inhibited in proxy addition and auth request prompts.
2704  * Avoided use of linphonec_readline's internal filename completion.
2705  *
2706  * Revision 1.15  2006/01/14 13:29:32  strk
2707  * Reworked commands interface to use a table structure,
2708  * used by command line parser and help function.
2709  * Implemented first level of completion (commands).
2710  * Added notification of invalid "answer" and "terminate"
2711  * commands (no incoming call, no active call).
2712  * Forbidden "call" intialization when a call is already active.
2713  * Cleaned up all commands, adding more feedback and error checks.
2714  *
2715  * Revision 1.14  2006/01/13 13:00:29  strk
2716  * Added linphonec.h. Code layout change (added comments, forward decl,
2717  * globals on top, copyright notices and Logs). Handled out-of-memory
2718  * condition on history management. Removed assumption on sizeof(char).
2719  * Fixed bug in authentication prompt (introduced by linphonec_readline).
2720  * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
2721  *
2722  *
2723  ****************************************************************************/