]> sjero.net Git - linphone/blob - console/commands.c
minor fixes and improvement in dtmf notifications
[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 "private.h"
38 #include "lpconfig.h"
39
40 #ifndef WIN32
41 #include <sys/wait.h>
42 #endif
43
44 /***************************************************************************
45  *
46  *  Forward declarations 
47  *
48  ***************************************************************************/
49
50 extern char *lpc_strip_blanks(char *input);
51
52 /* Command handlers */
53 static int lpc_cmd_help(LinphoneCore *, char *);
54 static int lpc_cmd_proxy(LinphoneCore *, char *);
55 static int lpc_cmd_call(LinphoneCore *, char *);
56 static int lpc_cmd_chat(LinphoneCore *, char *);
57 static int lpc_cmd_answer(LinphoneCore *, char *);
58 static int lpc_cmd_autoanswer(LinphoneCore *, char *);
59 static int lpc_cmd_terminate(LinphoneCore *, char *);
60 static int lpc_cmd_call_logs(LinphoneCore *, char *);
61 static int lpc_cmd_ipv6(LinphoneCore *, char *);
62 static int lpc_cmd_refer(LinphoneCore *, char *);
63 static int lpc_cmd_quit(LinphoneCore *, char *);
64 static int lpc_cmd_nat(LinphoneCore *, char *);
65 static int lpc_cmd_stun(LinphoneCore *, char *);
66 static int lpc_cmd_firewall(LinphoneCore *, char *);
67 static int lpc_cmd_friend(LinphoneCore *, char*);
68 static int lpc_cmd_soundcard(LinphoneCore *, char *);
69 static int lpc_cmd_webcam(LinphoneCore *, char *);
70 static int lpc_cmd_staticpic(LinphoneCore *, char *);
71 static int lpc_cmd_play(LinphoneCore *, char *);
72 static int lpc_cmd_record(LinphoneCore *, char *);
73 static int lpc_cmd_register(LinphoneCore *, char *);
74 static int lpc_cmd_unregister(LinphoneCore *, char *);
75 static int lpc_cmd_duration(LinphoneCore *lc, char *args);
76 static int lpc_cmd_status(LinphoneCore *lc, char *args);
77 static int lpc_cmd_ports(LinphoneCore *lc, char *args);
78 static int lpc_cmd_speak(LinphoneCore *lc, char *args);
79 static int lpc_cmd_codec(LinphoneCore *lc, char *args);
80 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args);
81 static int lpc_cmd_pause(LinphoneCore *lc, char *args);
82 static int lpc_cmd_resume(LinphoneCore *lc, char *args);
83 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args);
84 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args);
85 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args);
86
87 /* Command handler helpers */
88 static void linphonec_proxy_add(LinphoneCore *lc);
89 static void linphonec_proxy_display(LinphoneProxyConfig *lc);
90 static void linphonec_proxy_list(LinphoneCore *lc);
91 static void linphonec_proxy_remove(LinphoneCore *lc, int index);
92 static  int linphonec_proxy_use(LinphoneCore *lc, int index);
93 static void linphonec_proxy_show(LinphoneCore *lc,int index);
94 static void linphonec_friend_display(LinphoneFriend *fr);
95 static int linphonec_friend_list(LinphoneCore *lc, char *arg);
96 static void linphonec_display_command_help(LPC_COMMAND *cmd);
97 static int linphonec_friend_call(LinphoneCore *lc, unsigned int num);
98 #ifndef WIN32
99 static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
100 #endif
101 static int linphonec_friend_delete(LinphoneCore *lc, int num);
102 static int linphonec_friend_delete(LinphoneCore *lc, int num);
103 static void linphonec_codec_list(LinphoneCore *lc);
104 static void linphonec_codec_enable(LinphoneCore *lc, int index);
105 static void linphonec_codec_disable(LinphoneCore *lc, int index);
106
107
108
109 /* Command table management */
110 static LPC_COMMAND *lpc_find_command(const char *name);
111
112 void linphonec_out(const char *fmt,...);
113
114
115
116 /***************************************************************************
117  *
118  *  Global variables
119  *
120  ***************************************************************************/
121
122 /*
123  * Commands table.
124  */
125 LPC_COMMAND commands[] = {
126         { "help", lpc_cmd_help, "Print commands help", NULL },
127         { "call", lpc_cmd_call, "Call a SIP uri",
128                 "'call <sip-url>' \t: initiate a call to the specified destination.\n"
129                 "'call show' \t: show all the current calls status.\n"
130                 },
131         { "chat", lpc_cmd_chat, "Chat with a SIP uri",
132                 "'chat <sip-url> \"message\"' "
133                 ": send a chat message \"message\" to the specified destination."
134                 },
135         { "terminate", lpc_cmd_terminate, "Terminate a call",
136                 "'terminate' : Terminate the current call\n"
137                 "'terminate <sip:XXX@XXX.XXX.XXX.XXX>' : Terminate the call with remote address\n"
138                 "'terminate <all>' : Terminate all the current calls\n"
139                 },
140         { "answer", lpc_cmd_answer, "Answer a call",
141                 "'answer' : Answer the current incoming call\n"
142                 "'answer <sip:XXX@XXX.XXX.XXX.XXX>' : Answer the call with remote address\n"
143         },
144         { "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
145                 "'autoanswer'       \t: show current autoanswer mode\n"
146                 "'autoanswer enable'\t: enable autoanswer mode\n"
147                 "'autoanswer disable'\t: disable autoanswer modeĀ \n"},
148         { "proxy", lpc_cmd_proxy, "Manage proxies",
149                 "'proxy list' : list all proxy setups.\n"
150                 "'proxy add' : add a new proxy setup.\n"
151                 "'proxy remove <index>' : remove proxy setup with number index.\n"
152                 "'proxy use <index>' : use proxy with number index as default proxy.\n"
153                 "'proxy unuse' : don't use a default proxy.\n"
154                 "'proxy show <index>' : show configuration and status of the proxy numbered by index.\n"
155                 "'proxy show default' : show configuration and status of the default proxy.\n"
156         },
157         { "soundcard", lpc_cmd_soundcard, "Manage soundcards",
158                 "'soundcard list' : list all sound devices.\n"
159                 "'soundcard show' : show current sound devices configuration.\n"
160                 "'soundcard use <index>' : select a sound device.\n"
161                 "'soundcard use files' : use .wav files instead of soundcard\n"
162         },
163         { "webcam", lpc_cmd_webcam, "Manage webcams",
164                 "'webcam list' : list all known devices.\n"
165                 "'webcam use <index>' : select a video device.\n"
166         },
167         { "staticpic", lpc_cmd_staticpic, "Manage static pictures when nowebcam",
168                 "'staticpic set' : Set path to picture that should be used.\n"
169         },
170         { "ipv6", lpc_cmd_ipv6, "Use IPV6",
171                 "'ipv6 status' : show ipv6 usage status.\n"
172                 "'ipv6 enable' : enable the use of the ipv6 network.\n"
173                 "'ipv6 disable' : do not use ipv6 network."
174         },
175         { "refer", lpc_cmd_refer,
176                 "Refer the current call to the specified destination.",
177                 "'refer <sip-url>' or 'r <sip-url>' "
178                 ": refer the current call to the specified destination."
179         },
180         { "nat", lpc_cmd_nat, "Set nat address",
181                 "'nat'        : show nat settings.\n"
182                 "'nat <addr>' : set nat address.\n"
183         },
184         { "stun", lpc_cmd_stun, "Set stun server address",
185                 "'stun'        : show stun settings.\n"
186                 "'stun <addr>' : set stun server address.\n"
187         },
188         { "firewall", lpc_cmd_firewall, "Set firewall policy",
189                 "'firewall'        : show current firewall policy.\n"
190                 "'firewall none'   : use direct connection.\n"
191                 "'firewall nat'    : use nat address given with the 'nat' command.\n"
192                 "'firewall stun'   : use stun server given with the 'stun' command.\n"
193         },
194         { "call-logs", lpc_cmd_call_logs, "Calls history", NULL },
195         { "friend", lpc_cmd_friend, "Manage friends",
196                 "'friend list [<pattern>]'    : list friends.\n"
197                 "'friend call <index>'        : call a friend.\n"
198                 "'friend add <name> <addr>'   : add friend, <name> must be quoted to include\n"
199             "                               spaces, <addr> has \"sip:\" added if it isn't\n"
200             "                               there.  Don't use '<' '>' around <addr>.\n"
201                 "'friend delete <index>'      : remove friend, 'all' removes all\n"
202         },
203         { "play", lpc_cmd_play, "play from a wav file",
204                 "This feature is available only in file mode (see 'help soundcard')\n"
205                 "'play <wav file>'    : play a wav file."
206         },
207         { "record", lpc_cmd_record, "record to a wav file",
208                 "This feature is available only in file mode (see 'help soundcard')\n"
209                 "'record <wav file>'    : record into wav file."
210         },
211         { "quit", lpc_cmd_quit, "Exit linphonec", NULL },
212         { "register", lpc_cmd_register, "Register in one line to a proxy" , "register <sip identity> <sip proxy> <password>"},
213         { "unregister", lpc_cmd_unregister, "Unregister from default proxy", NULL       },
214         { "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
215         { "status", lpc_cmd_status, "Print various status information", 
216                         "'status register'  \t: print status concerning registration\n"
217                         "'status autoanswer'\t: tell whether autoanswer mode is enabled\n"
218                         "'status hook'      \t: print hook status\n" },
219         { "ports", lpc_cmd_ports, "Network ports configuration", 
220                         "'ports'  \t: prints current used ports.\n"
221                         "'ports sip <port number>'\t: Sets the sip port.\n" },
222         { "speak", lpc_cmd_speak, "Speak a sentence using espeak TTS engine",
223                         "This feature is available only in file mode. (see 'help soundcard')\n"
224                         "'speak <voice name> <sentence>'        : speak a text using the specified espeak voice.\n"
225                         "Example for english voice: 'speak default Hello my friend !'"
226         },
227         { "codec", lpc_cmd_codec, "Codec configuration",
228             "'codec list' : list codecs\n"  
229             "'codec enable <index>' : enable available codec\n"  
230             "'codec disable <index>' : disable codecs" }, 
231         { "ec", lpc_cmd_echocancellation, "Echo cancellation",
232             "'ec on [<delay>] [<tail>] [<framesize>]' : turn EC on with given delay, tail length and framesize\n"
233             "'ec off' : turn echo cancellation (EC) off\n"
234             "'ec show' : show EC status" },
235         { "pause", lpc_cmd_pause, "pause a call",
236                 "'pause' : pause the current call\n"},
237         { "resume", lpc_cmd_resume, "resume a call",
238                 "'resume' : resume the unique call\n"
239                 "'resume <sip:XXX@XXX.XXX.XXX.XXX>' : hold off the call with cid <cid>\n"},
240         { "mute", lpc_cmd_mute_mic, 
241           "Mute microphone and suspend voice transmission."},
242         { "unmute", lpc_cmd_unmute_mic, 
243                   "Unmute microphone and resume voice transmission."},
244         { "nortp-on-audio-mute", lpc_cmd_rtp_no_xmit_on_audio_mute,
245                   "Set the rtp_no_xmit_on_audio_mute configuration parameter",
246                   "   If set to 1 then rtp transmission will be muted when\n"
247                   "   audio is muted , otherwise rtp is always sent."}, 
248     { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
249 };
250
251 /***************************************************************************
252  *
253  *  Public interface 
254  *
255  ***************************************************************************/
256
257 /*
258  * Main command dispatcher.
259  * WARNING: modifies second argument!
260  *
261  * Always return 1 currently.
262  */
263 int
264 linphonec_parse_command_line(LinphoneCore *lc, char *cl)
265 {
266         char *ptr=cl;
267         char *args=NULL;
268         LPC_COMMAND *cmd;
269
270         /* Isolate first word and args */
271         while(*ptr && !isspace(*ptr)) ++ptr;
272         if (*ptr)
273         {
274                 *ptr='\0';
275                 /* set args to first nonblank */
276                 args=ptr+1;
277                 while(*args && isspace(*args)) ++args;
278         }
279
280         /* Handle DTMF */
281         if ( isdigit(*cl) || *cl == '#' || *cl == '*' )
282         {
283                 while ( isdigit(*cl) || *cl == '#' || *cl == '*' )
284                 {
285                         linphone_core_send_dtmf(lc, *cl);
286                         ms_sleep(1); // be nice
287                         ++cl;
288                 }
289
290                 // discard spurious trailing chars
291                 return 1;
292         }
293
294         /* Handle other kind of commands */
295         cmd=lpc_find_command(cl);
296         if ( !cmd )
297         {
298                 linphonec_out("'%s': Cannot understand this.\n", cl);
299                 return 1;
300         }
301
302         if ( ! cmd->func(lc, args) )
303         {
304                 linphonec_out("Syntax error.\n");
305                 linphonec_display_command_help(cmd);
306         }
307
308         return 1;
309 }
310
311 /*
312  * Generator function for command completion.
313  * STATE let us know whether to start from scratch;
314  * without any state (STATE==0), then we start at the
315  * top of the list.
316  */
317 char *
318 linphonec_command_generator(const char *text, int state)
319 {
320         static int index, len;
321         char *name;
322
323         if ( ! state )
324         {
325                 index=0;
326                 len=strlen(text);
327         }
328
329         /*
330          * Return the next name which partially matches
331          * from the commands list
332          */
333         while ((name=commands[index].name))
334         {
335                 ++index; /* so next call get next command */
336
337                 if (strncmp(name, text, len) == 0)
338                 {
339                         return ortp_strdup(name);
340                 }
341         }
342
343         return NULL;
344 }
345
346
347 /***************************************************************************
348  *
349  *  Command handlers 
350  *
351  ***************************************************************************/
352
353 static int
354 lpc_cmd_help(LinphoneCore *lc, char *arg)
355 {
356         int i=0;
357         LPC_COMMAND *cmd;
358
359         if (!arg || !*arg)
360         {
361                 linphonec_out("Commands are:\n");
362                 linphonec_out("---------------------------\n");
363
364                 while (commands[i].help)
365                 {
366                         linphonec_out("%10.10s\t%s\n", commands[i].name,
367                                 commands[i].help);
368                         i++;
369                 }
370                 
371                 linphonec_out("---------------------------\n");
372                 linphonec_out("Type 'help <command>' for more details.\n");
373
374                 return 1;
375         }
376
377         cmd=lpc_find_command(arg);
378         if ( !cmd )
379         {
380                 linphonec_out("No such command.\n");
381                 return 1;
382         }
383
384         linphonec_display_command_help(cmd);
385         return 1;
386
387 }
388
389 static char callee_name[256]={0};
390 static char caller_name[256]={0};
391
392 static int
393 lpc_cmd_call(LinphoneCore *lc, char *args)
394 {
395         if ( ! args || ! *args )
396         {
397                 return 0;
398         }
399         if(!strcmp(args,"show"))
400         {
401                 MSList *calls = linphone_core_get_calls(lc);
402                 if(calls)
403                 {
404                         MSList *p_calls = calls;
405                         linphonec_out("<remote>\t\t\t\t<status>\r\n");
406                         while(p_calls != NULL)                  
407                         {
408                                 linphonec_out("%s\t\t\t%s\r\n",
409                                                 linphone_call_get_remote_address_as_string(p_calls->data),
410                                                 (((LinphoneCall *)p_calls->data)==linphone_core_get_current_call(lc))?"yes":"no");
411                                 p_calls = p_calls->next;
412                         }
413                         ms_list_free(calls);
414                 }
415                 else
416                 {
417                         linphonec_out("No active call.\n");
418                 }
419         }
420         else
421         {
422                 if ( linphone_core_in_call(lc) )
423                 {
424                         linphonec_out("Terminate or hold on the current call first.\n");
425                         return 1;
426                 }
427                 if ( NULL == linphone_core_invite(lc, args) )
428                 {
429                         linphonec_out("Error from linphone_core_invite.\n");
430                 }
431                 else
432                 {
433                         snprintf(callee_name,sizeof(callee_name),"%s",args);
434                 }
435         }
436         return 1;
437 }
438
439 static int
440 lpc_cmd_chat(LinphoneCore *lc, char *args)
441 {
442         char *arg1 = args;
443         char *arg2 = NULL;
444         char *ptr = args;
445
446         if (!args) return 0;
447
448         /* Isolate first and second arg */
449         while(*ptr && !isspace(*ptr)) ++ptr;
450         if ( *ptr )
451         {
452                 *ptr='\0';
453                 arg2=ptr+1;
454                 while(*arg2 && isspace(*arg2)) ++arg2;
455         }
456         else
457         {
458                 /* missing one parameter */
459                 return 0;
460         }
461         LinphoneChatRoom *cr = linphone_core_create_chat_room(lc,arg1);
462         linphone_chat_room_send_message(cr,arg2);
463         linphone_chat_room_destroy(cr);
464
465         return 1;
466 }
467
468 const char *linphonec_get_callee(){
469         return callee_name;
470 }
471
472 const char *linphonec_get_caller(){
473         return caller_name;
474 }
475
476 void linphonec_set_caller(const char *caller){
477         snprintf(caller_name,sizeof(caller_name)-1,"%s",caller);
478 }
479
480 static int
481 lpc_cmd_refer(LinphoneCore *lc, char *args)
482 {
483         if (args)
484                 linphone_core_refer(lc, linphone_core_get_current_call(lc), args);
485         else{
486                 linphonec_out("refer needs an argument\n");
487         }
488         return 1;
489 }
490
491 static int
492 lpc_cmd_terminate(LinphoneCore *lc, char *args)
493 {
494         char *arg1 = args;
495         char *arg2 = NULL;
496         char *ptr = args;
497
498         if (!args)
499         {
500                 if(linphone_core_in_call(lc))
501                 {
502                         if ( -1 == linphone_core_terminate_call(lc, linphone_core_get_current_call(lc)) )
503                         {
504                                 linphonec_out("Could not stop the active call.\n");
505                         }
506                 }
507                 else
508                 {
509                         linphonec_out("No active call.\n");
510                 }
511                 return 1;
512         }
513         
514         /* Isolate first and second arg */
515         while(*ptr && !isspace(*ptr)) ++ptr;
516         if ( *ptr )
517         {
518                 *ptr='\0';
519                 arg2=ptr+1;
520                 while(*arg2 && isspace(*arg2)) ++arg2;
521         }
522         if (arg1 != 0)
523         {
524                 if(strcmp(arg1,"all")==0)
525                 {
526                         linphonec_out("We are going to stop all the calls.\n");
527                         return (linphone_core_terminate_all_calls(lc)==0)?1:0;
528                 }
529                 else
530                 {
531                         char the_remote_address[255];
532                         int n = sscanf(arg1, "%s", the_remote_address);
533                         if (n == 1)
534                         {
535                                 if ( -1 == linphone_core_terminate_call(lc,linphone_core_get_call_by_remote_address(lc,the_remote_address)))
536                                 {
537                                         linphonec_out("Cannot stop the call with %s.\n",the_remote_address);
538                                 }
539                                 return 1;
540                         }
541                 }
542         }
543         return 0;
544         
545 }
546
547 static int
548 lpc_cmd_answer(LinphoneCore *lc, char *args)
549 {
550         char *arg1 = args;
551         char *arg2 = NULL;
552         char *ptr = args;
553
554         if (!args)
555         {
556                 //if just one call is present answer the only one in passing NULL to the linphone_core_accept_call ...
557                 if ( -1 == linphone_core_accept_call(lc, NULL) )
558                 {
559                         linphonec_out("No incoming call.\n");
560                 }
561                 return 1;
562         }
563
564         // Isolate first and second arg
565         while(*ptr && !isspace(*ptr)) ++ptr;
566         if ( *ptr )
567         {
568                 *ptr='\0';
569                 arg2=ptr+1;
570                 while(*arg2 && isspace(*arg2)) ++arg2;
571         }
572         if (arg1 != 0)
573         {
574                 char the_remote_address[256];
575                 int n = sscanf(arg1, "%s", the_remote_address);
576                 if (n == 1)
577                 {
578                         if ( -1 == linphone_core_accept_call(lc, linphone_core_get_call_by_remote_address(lc,the_remote_address)) )
579                         {
580                                 linphonec_out("Cannot answer the call from %s.\n",the_remote_address);
581                         }
582                         return 1;
583                 }
584         }
585         return 0;
586 }
587
588 static int
589 lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
590 {
591         if ( ! args )
592         {
593                 if ( linphonec_get_autoanswer() ) {
594                         linphonec_out("Auto answer is enabled. Use 'autoanswer disable' to disable.\n");
595                 } else {
596                         linphonec_out("Auto answer is disabled. Use 'autoanswer enable' to enable.\n");
597                 }
598                 return 1;
599         }
600
601         if (strstr(args,"enable")){
602                 linphonec_set_autoanswer(TRUE);
603                 linphonec_out("Auto answer enabled.\n");
604         }else if (strstr(args,"disable")){
605                 linphonec_set_autoanswer(FALSE);
606                 linphonec_out("Auto answer disabled.\n");
607         }else return 0;
608         return 1;
609 }
610
611 static int
612 lpc_cmd_quit(LinphoneCore *lc, char *args)
613 {
614         linphonec_main_loop_exit();
615         return 1;
616 }
617
618 static int
619 lpc_cmd_nat(LinphoneCore *lc, char *args)
620 {
621         bool_t use;
622         const char *nat;
623
624         if ( args ) args=lpc_strip_blanks(args);
625
626         if ( args && *args )
627         {
628                 linphone_core_set_nat_address(lc, args);
629                 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS); */
630         }
631
632         nat = linphone_core_get_nat_address(lc);
633         use = linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS;
634         linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
635
636         return 1;
637 }
638
639 static int
640 lpc_cmd_stun(LinphoneCore *lc, char *args)
641 {
642         bool_t use;
643         const char *stun;
644
645         if ( args ) args=lpc_strip_blanks(args);
646
647         if ( args && *args )
648         {
649                 linphone_core_set_stun_server(lc, args);
650                 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN); */
651         }
652
653         stun = linphone_core_get_stun_server(lc);
654         use = linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_STUN;
655         linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
656
657         return 1;
658 }
659
660 static int
661 lpc_cmd_firewall(LinphoneCore *lc, char *args)
662 {
663         const char* setting=NULL;
664
665         if ( args ) args=lpc_strip_blanks(args);
666
667         if ( args && *args )
668         {
669                 if (strcmp(args,"none")==0)
670                 {
671                         linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_NO_FIREWALL);
672                 }
673                 else if (strcmp(args,"stun")==0)
674                 {
675                         setting = linphone_core_get_stun_server(lc);
676                         if ( ! setting )
677                         {
678                                 linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
679                                 return 1;
680                         }
681                         linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN);
682                 }
683                 else if (strcmp(args,"nat")==0)
684                 {
685                         setting = linphone_core_get_nat_address(lc);
686                         if ( ! setting )
687                         {
688                                 linphonec_out("No nat address is defined, use 'nat <address>' first");
689                                 return 1;
690                         }
691                         linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS);
692                 }
693         }
694
695         switch(linphone_core_get_firewall_policy(lc))
696         {
697                 case LINPHONE_POLICY_NO_FIREWALL:
698                         linphonec_out("No firewall\n");
699                         break;
700                 case LINPHONE_POLICY_USE_STUN:
701                         linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
702                         break;
703                 case LINPHONE_POLICY_USE_NAT_ADDRESS:
704                         linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
705                         break;
706         }
707         return 1;
708 }
709
710 #ifndef WIN32
711 /* Helper function for processing freind names */
712 static int
713 lpc_friend_name(char **args, char **name)
714 {
715         /* Use space as a terminator unless quoted */
716         if (('"' == **args) || ('\'' == **args)){
717                 char *end;
718                 char delim = **args;
719                 (*args)++;
720                 end = (*args);
721                 while ((delim != *end) && ('\0' != *end)) end++;
722                 if ('\0' == *end) {
723                         fprintf(stderr, "Mismatched quotes\n");
724                         return 0;
725                 }
726                 *name = *args;
727                 *end = '\0';
728                 *args = ++end;
729         } else {
730                 *name = strsep(args, " ");
731                 
732                 if (NULL == *args) { /* Means there was no separator */
733                         fprintf(stderr, "Either name or address is missing\n");
734                         return 0;
735                 }
736                 if (NULL == *name) return 0;
737         }
738         return 1;
739 }
740 #endif
741
742 static int
743 lpc_cmd_friend(LinphoneCore *lc, char *args)
744 {
745         int friend_num;
746
747         if ( args ) args=lpc_strip_blanks(args);
748
749         if ( ! args || ! *args ) return 0;
750
751         if ( !strncmp(args, "list", 4) )
752         {
753                 return linphonec_friend_list(lc, args+4);
754                 return 1;
755         }
756         else if ( !strncmp(args, "call", 4) )
757         {
758                 args+=4;
759                 if ( ! *args ) return 0;
760                 friend_num = strtol(args, NULL, 10);
761 #ifndef _WIN32_WCE              
762                 if ( errno == ERANGE ) {
763                         linphonec_out("Invalid friend number\n");
764                         return 0;
765                 }
766 #endif /*_WIN32_WCE*/
767                 linphonec_friend_call(lc, friend_num);
768                 return 1;
769         }
770         else if ( !strncmp(args, "delete", 6) )
771         {
772                 args+=6;
773                 if ( ! *args ) return 0;
774                 while (*args == ' ') args++;
775                 if ( ! *args ) return 0;
776                 if (!strncmp(args, "all", 3))
777                 {
778                         friend_num = -1;
779                 } 
780                 else
781                 {
782                         friend_num = strtol(args, NULL, 10);
783 #ifndef _WIN32_WCE              
784                         if ( errno == ERANGE ) {
785                                 linphonec_out("Invalid friend number\n");
786                                 return 0;
787                         }
788 #endif /*_WIN32_WCE*/
789                 }
790                 linphonec_friend_delete(lc, friend_num);
791                 return 1;
792         }
793         else if ( !strncmp(args, "add", 3) )
794         {
795 #ifndef WIN32
796                 char  *name;
797                 char  addr[80];
798                 char *addr_p = addr;
799                 char *addr_orig;
800
801                 args+=3;
802                 if ( ! *args ) return 0;
803                 while (*args == ' ') args++;
804                 if ( ! *args ) return 0;
805
806                 if (!lpc_friend_name(&args,  &name)) return 0;
807
808                 while (*args == ' ') args++;
809                 if ( ! *args ) return 0;
810                 if (isdigit(*args)) {
811                         strcpy (addr, "sip:");
812                         addr_p = addr + strlen("sip:");
813                 }
814                 addr_orig = strsep(&args, " ");
815                 if (1 >= strlen(addr_orig)) {
816                         fprintf(stderr, "A single-digit address is not valid\n");
817                         return 0;
818                 }
819                 strcpy(addr_p, addr_orig);
820                 linphonec_friend_add(lc, name, addr);
821 #else
822                 LinphoneFriend *new_friend;
823                 new_friend = linphone_friend_new_with_addr(args);
824                 linphone_core_add_friend(lc, new_friend);
825 #endif
826                 return 1;
827         }
828         return 0;
829 }
830
831 static int lpc_cmd_play(LinphoneCore *lc, char *args){
832         if ( args ) args=lpc_strip_blanks(args);
833         if ( ! args || ! *args ) return 0;
834         linphone_core_set_play_file(lc,args);
835         return 1;
836 }
837
838 static int lpc_cmd_record(LinphoneCore *lc, char *args){
839         if ( args ) args=lpc_strip_blanks(args);
840         if ( ! args || ! *args ) return 0;
841         linphone_core_set_record_file(lc,args);
842         return 1;
843 }
844
845 /*
846  * Modified input
847  */
848 static int
849 lpc_cmd_proxy(LinphoneCore *lc, char *args)
850 {
851         char *arg1 = args;
852         char *arg2 = NULL;
853         char *ptr = args;
854         int proxynum;
855
856         if ( ! arg1 ) return 0;
857
858         /* Isolate first and second arg */
859         while(*ptr && !isspace(*ptr)) ++ptr;
860         if ( *ptr )
861         {
862                 *ptr='\0';
863                 arg2=ptr+1;
864                 while(*arg2 && isspace(*arg2)) ++arg2;
865         }
866
867         if (strcmp(arg1,"add")==0)
868         {
869 #ifdef HAVE_READLINE
870                 rl_inhibit_completion=1;
871 #endif
872                 linphonec_proxy_add(lc);
873 #ifdef HAVE_READLINE
874                 rl_inhibit_completion=0;
875 #endif
876         }
877         else if (strcmp(arg1,"list")==0)
878         {
879                 linphonec_proxy_list(lc);
880         }
881         else if (strcmp(arg1,"remove")==0)
882         {
883                 linphonec_proxy_remove(lc,atoi(arg2));
884         }
885         else if (strcmp(arg1,"use")==0)
886         {
887                 if ( arg2 && *arg2 )
888                 {
889                         proxynum=atoi(arg2);
890                         if ( linphonec_proxy_use(lc, proxynum) )
891                                 linphonec_out("Default proxy set to %d.\n", proxynum);
892                 }
893                 else
894                 {
895                         proxynum=linphone_core_get_default_proxy(lc, NULL);
896                         if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
897                         else linphonec_out("Current default proxy is %d.\n", proxynum);
898                 }
899         }else if (strcmp(arg1, "unuse")==0){
900                 linphone_core_set_default_proxy(lc, NULL);
901                 linphonec_out("Use no proxy.\n");
902         }
903
904         else if (strcmp(arg1, "show")==0)
905         {
906                 if (arg2 && *arg2)
907                 {
908                         if (strstr(arg2,"default"))
909                         {
910                 proxynum=linphone_core_get_default_proxy(lc, NULL);
911                 if ( proxynum < 0 ) {
912                         linphonec_out("No default proxy defined\n");
913                         return 1;
914                 }
915                 linphonec_proxy_show(lc,proxynum);
916                         }
917                         else
918                         {
919                 linphonec_proxy_show(lc, atoi(arg2));
920                         }
921                 }
922                 else return 0; /* syntax error */
923         }
924
925         else
926         {
927                 return 0; /* syntax error */
928         }
929
930         return 1;
931 }
932
933 static int
934 lpc_cmd_call_logs(LinphoneCore *lc, char *args)
935 {
936         const MSList *elem=linphone_core_get_call_logs(lc);
937         for (;elem!=NULL;elem=ms_list_next(elem))
938         {
939                 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
940                 char *str=linphone_call_log_to_str(cl);
941                 linphonec_out("%s\n",str);
942                 ms_free(str);
943         }
944         return 1;
945 }
946
947 static int
948 lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
949 {
950         if ( ! arg1 )
951         {
952                 return 0; /* syntax error */
953         }
954
955         if (strcmp(arg1,"status")==0)
956         {
957                 linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
958         }
959         else if (strcmp(arg1,"enable")==0)
960         {
961                 linphone_core_enable_ipv6(lc,TRUE);
962                 linphonec_out("ipv6 use enabled.\n");
963         }
964         else if (strcmp(arg1,"disable")==0)
965         {
966                 linphone_core_enable_ipv6(lc,FALSE);
967                 linphonec_out("ipv6 use disabled.\n");
968         }
969         else
970         {
971                 return 0; /* syntax error */
972         }
973         return 1;
974 }
975
976 static int devname_to_index(LinphoneCore *lc, const char *devname){
977         const char **p;
978         int i;
979         for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
980                 if (strcmp(devname,*p)==0) return i;
981         }
982         return -1;
983 }
984
985 static const char *index_to_devname(LinphoneCore *lc, int index){
986         const char **p;
987         int i;
988         for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
989                 if (i==index) return *p;
990         }
991         return NULL;
992 }
993
994 static int lpc_cmd_soundcard(LinphoneCore *lc, char *args)
995 {
996         int i, index;
997         const char **dev;
998         char *arg1 = args;
999         char *arg2 = NULL;
1000         char *ptr = args;
1001
1002         if (!args) return 0; /* syntax error */
1003
1004         /* Isolate first and second arg */
1005         while(*ptr && !isspace(*ptr)) ++ptr;
1006         if ( *ptr )
1007         {
1008                 *ptr='\0';
1009                 arg2=ptr+1;
1010                 while(*arg2 && isspace(*arg2)) ++arg2;
1011         }
1012
1013         if (strcmp(arg1, "list")==0)
1014         {
1015                 dev=linphone_core_get_sound_devices(lc);
1016                 for(i=0; dev[i]!=NULL; ++i){
1017                         linphonec_out("%i: %s\n",i,dev[i]);
1018                 }
1019                 return 1;
1020         }
1021
1022         if (strcmp(arg1, "show")==0)
1023         {
1024                 linphonec_out("Ringer device: %s\n",
1025                         linphone_core_get_ringer_device(lc));
1026                 linphonec_out("Playback device: %s\n",
1027                         linphone_core_get_playback_device(lc));
1028                 linphonec_out("Capture device: %s\n",
1029                         linphone_core_get_capture_device(lc));
1030                 return 1;
1031         }
1032
1033         if (strcmp(arg1, "use")==0 && arg2)
1034         {
1035                 if (strcmp(arg2, "files")==0)
1036                 {
1037                         linphonec_out("Using wav files instead of soundcard.\n");
1038                         linphone_core_use_files(lc,TRUE);
1039                         return 1;
1040                 }
1041
1042                 dev=linphone_core_get_sound_devices(lc);
1043                 index=atoi(arg2); /* FIXME: handle not-a-number */
1044                 for(i=0;dev[i]!=NULL;i++)
1045                 {
1046                         if (i!=index) continue;
1047
1048                         linphone_core_set_ringer_device(lc,dev[i]);
1049                         linphone_core_set_playback_device(lc,dev[i]);
1050                         linphone_core_set_capture_device(lc,dev[i]);
1051                         linphonec_out("Using sound device %s\n",dev[i]);
1052                         return 1;
1053                 }
1054                 linphonec_out("No such sound device\n");
1055                 return 1;
1056         }
1057         if (strcmp(arg1, "capture")==0)
1058         {
1059                 const char *devname=linphone_core_get_capture_device(lc);
1060                 if (!arg2){
1061                         linphonec_out("Using capture device #%i (%s)\n",
1062                                         devname_to_index(lc,devname),devname);
1063                 }else{
1064                         index=atoi(arg2); /* FIXME: handle not-a-number */
1065                         devname=index_to_devname(lc,index);
1066                         if (devname!=NULL){
1067                                 linphone_core_set_capture_device(lc,devname);
1068                                 linphonec_out("Using capture sound device %s\n",devname);
1069                                 return 1;
1070                         }
1071                         linphonec_out("No such sound device\n");
1072                 }
1073                 return 1;
1074         }
1075         if (strcmp(arg1, "playback")==0)
1076         {
1077                 const char *devname=linphone_core_get_playback_device(lc);
1078                 if (!arg2){
1079                         linphonec_out("Using playback device #%i (%s)\n",
1080                                         devname_to_index(lc,devname),devname);
1081                 }else{
1082                         index=atoi(arg2); /* FIXME: handle not-a-number */
1083                         devname=index_to_devname(lc,index);
1084                         if (devname!=NULL){
1085                                 linphone_core_set_playback_device(lc,devname);
1086                                 linphonec_out("Using playback sound device %s\n",devname);
1087                                 return 1;
1088                         }
1089                         linphonec_out("No such sound device\n");
1090                 }
1091                 return 1;
1092         }
1093         if (strcmp(arg1, "ring")==0)
1094         {
1095                 const char *devname=linphone_core_get_ringer_device(lc);
1096                 if (!arg2){
1097                         linphonec_out("Using ring device #%i (%s)\n",
1098                                         devname_to_index(lc,devname),devname);
1099                 }else{
1100                         index=atoi(arg2); /* FIXME: handle not-a-number */
1101                         devname=index_to_devname(lc,index);
1102                         if (devname!=NULL){
1103                                 linphone_core_set_ringer_device(lc,devname);
1104                                 linphonec_out("Using ring sound device %s\n",devname);
1105                                 return 1;
1106                         }
1107                         linphonec_out("No such sound device\n");
1108                 }
1109                 return 1;
1110         }
1111         return 0; /* syntax error */
1112 }
1113
1114 static int lpc_cmd_webcam(LinphoneCore *lc, char *args)
1115 {
1116         int i, index;
1117         const char **dev;
1118         char *arg1 = args;
1119         char *arg2 = NULL;
1120         char *ptr = args;
1121
1122         if (!args) return 0; /* syntax error */
1123
1124         /* Isolate first and second arg */
1125         while(*ptr && !isspace(*ptr)) ++ptr;
1126         if ( *ptr )
1127         {
1128                 *ptr='\0';
1129                 arg2=ptr+1;
1130                 while(*arg2 && isspace(*arg2)) ++arg2;
1131         }
1132
1133         if (strcmp(arg1, "list")==0)
1134         {
1135                 dev=linphone_core_get_video_devices(lc);
1136                 for(i=0; dev[i]!=NULL; ++i){
1137                         linphonec_out("%i: %s\n",i,dev[i]);
1138                 }
1139                 return 1;
1140         }
1141
1142         if (strcmp(arg1, "use")==0 && arg2)
1143         {
1144                 dev=linphone_core_get_video_devices(lc);
1145                 index=atoi(arg2); /* FIXME: handle not-a-number */
1146                 for(i=0;dev[i]!=NULL;i++)
1147                 {
1148                         if (i!=index) continue;
1149
1150                         linphone_core_set_video_device(lc, dev[i]);
1151                         linphonec_out("Using video device %s\n",dev[i]);
1152                         return 1;
1153                 }
1154                 linphonec_out("No such video device\n");
1155                 return 1;
1156         }
1157         return 0; /* syntax error */
1158 }
1159
1160 static int
1161 lpc_cmd_staticpic(LinphoneCore *lc, char *args)
1162 {
1163         char *arg1 = args;
1164         char *arg2 = NULL;
1165         char *ptr = args;
1166
1167         if (!args) return 0;  /* Syntax error */
1168
1169         /* Isolate first and second arg */
1170         while(*ptr && !isspace(*ptr)) ++ptr;
1171         if ( *ptr )
1172         {
1173                 *ptr='\0';
1174                 arg2=ptr+1;
1175                 while(*arg2 && isspace(*arg2)) ++arg2;
1176         }
1177
1178         if (strcmp(arg1, "set")==0 && arg2) {
1179                 linphone_core_set_static_picture(lc, arg2);
1180                 return 1;
1181         }
1182
1183         return 0; /* Syntax error */
1184 }
1185
1186 static int lpc_cmd_pause(LinphoneCore *lc, char *args){
1187
1188         if(linphone_core_in_call(lc))
1189         {
1190                 linphone_core_pause_call(lc,linphone_core_get_current_call(lc));
1191                 return 1;
1192         }
1193         linphonec_out("you can only pause when a call is in process\n");
1194     return 0;
1195 }
1196
1197 static int lpc_cmd_resume(LinphoneCore *lc, char *args){
1198         
1199         if(linphone_core_in_call(lc))
1200         {
1201                 linphonec_out("There is already a call in process pause or stop it first");
1202         }
1203         if (args)
1204         {
1205                 char the_remote_address[255];
1206                 int n = sscanf(args, "%s", the_remote_address);
1207                 if (n == 1)
1208                 {
1209                         if(linphone_core_resume_call(lc,linphone_core_get_call_by_remote_address(lc,the_remote_address)) < 0)
1210                         {
1211                                 linphonec_out("There was a problem to resume the call check the remote address you gave %s\n",args);
1212                                 return 0;
1213                         }
1214                         else
1215                         {
1216                                 return 1;
1217                         }
1218                 }
1219         }
1220         else
1221         {
1222                 int returned = 0;
1223                 MSList *calls = linphone_core_get_calls(lc);
1224                 if(ms_list_size(calls) == 1)
1225                 {
1226                         if(linphone_core_resume_call(lc,calls->data) < 0)
1227                         {
1228                                 linphonec_out("There was a problem to resume the unique call \n");
1229                                 returned = 0;
1230                         }
1231                         else
1232                         {
1233                                 returned = 1;
1234                         }
1235                         ms_list_free(calls);
1236                         return returned;
1237                 }
1238         }
1239         return 0;
1240     
1241 }
1242
1243 /***************************************************************************
1244  *
1245  *  Commands helper functions
1246  *
1247  ***************************************************************************/
1248
1249
1250 static void
1251 linphonec_proxy_add(LinphoneCore *lc)
1252 {
1253         bool_t enable_register=FALSE;
1254         LinphoneProxyConfig *cfg;
1255
1256         linphonec_out("Adding new proxy setup. Hit ^D to abort.\n");
1257
1258         /*
1259          * SIP Proxy address
1260          */
1261         while (1)
1262         {
1263                 char *input=linphonec_readline("Enter proxy sip address: ");
1264                 char *clean;
1265
1266                 if ( ! input ) {
1267                         linphonec_out("Aborted.\n");
1268                         return;
1269                 }
1270
1271                 /* Strip blanks */
1272                 clean=lpc_strip_blanks(input);
1273                 if ( ! *clean ) {
1274                         free(input);
1275                         continue;
1276                 }
1277
1278                 cfg=linphone_proxy_config_new();
1279                 if (linphone_proxy_config_set_server_addr(cfg,clean)<0)
1280                 {
1281                         linphonec_out("Invalid sip address (sip:sip.domain.tld).\n");
1282                         free(input);
1283                         linphone_proxy_config_destroy(cfg);
1284                         continue;
1285                 }
1286                 free(input);
1287                 break;
1288         }
1289
1290         /*
1291          * SIP Proxy identity
1292          */
1293         while (1)
1294         {
1295                 char *input=linphonec_readline("Your identity for this proxy: ");
1296                 char *clean;
1297
1298                 if ( ! input ) {
1299                         linphonec_out("Aborted.\n");
1300                         linphone_proxy_config_destroy(cfg);
1301                         return;
1302                 }
1303
1304                 /* Strip blanks */
1305                 clean=lpc_strip_blanks(input);
1306                 if ( ! *clean ) {
1307                         free(input);
1308                         continue;
1309                 }
1310
1311                 linphone_proxy_config_set_identity(cfg, clean);
1312                 if ( ! cfg->reg_identity )
1313                 {
1314                         linphonec_out("Invalid identity (sip:name@sip.domain.tld).\n");
1315                         free(input);
1316                         continue;
1317                 }
1318                 free(input);
1319                 break;
1320         }
1321
1322         /*
1323          * SIP Proxy enable register
1324          */
1325         while (1)
1326         {
1327                 char *input=linphonec_readline("Do you want to register on this proxy (yes/no): ");
1328                 char *clean;
1329
1330                 if ( ! input ) {
1331                         linphonec_out("Aborted.\n");
1332                         linphone_proxy_config_destroy(cfg);
1333                         return;
1334                 }
1335
1336                 /* Strip blanks */
1337                 clean=lpc_strip_blanks(input);
1338                 if ( ! *clean ) {
1339                         free(input);
1340                         continue;
1341                 }
1342
1343                 if ( ! strcmp(clean, "yes") ) enable_register=TRUE;
1344                 else if ( ! strcmp(clean, "no") ) enable_register=FALSE;
1345                 else {
1346                         linphonec_out("Please answer with 'yes' or 'no'\n");
1347                         free(input);
1348                         continue;
1349                 }
1350                 linphone_proxy_config_enableregister(cfg, enable_register);
1351                 free(input);
1352                 break;
1353         }
1354
1355         /*
1356          * SIP Proxy registration expiration
1357          */
1358         if ( enable_register==TRUE )
1359         {
1360                 long int expires=0;
1361                 while (1)
1362                 {
1363                         char *input=linphonec_readline("Specify register expiration time"
1364                                 " in seconds (default is 600): ");
1365
1366                         if ( ! input ) {
1367                                 linphonec_out("Aborted.\n");
1368                                 linphone_proxy_config_destroy(cfg);
1369                                 return;
1370                         }
1371
1372                         expires=strtol(input, (char **)NULL, 10);
1373                         if ( expires == LONG_MIN || expires == LONG_MAX )
1374                         {
1375                                 linphonec_out("Invalid value: %s\n", strerror(errno));
1376                                 free(input);
1377                                 continue;
1378                         }
1379
1380                         linphone_proxy_config_expires(cfg, expires);
1381                         linphonec_out("Expiration: %d seconds\n", cfg->expires);
1382
1383                         free(input);
1384                         break;
1385                 }
1386         }
1387
1388         /*
1389          * SIP proxy route
1390          */
1391         while (1)
1392         {
1393                 char *input=linphonec_readline("Specify route if needed: ");
1394                 char *clean;
1395
1396                 if ( ! input ) {
1397                         linphonec_out("Aborted.\n");
1398                         linphone_proxy_config_destroy(cfg);
1399                         return;
1400                 }
1401
1402                 /* Strip blanks */
1403                 clean=lpc_strip_blanks(input);
1404                 if ( ! *clean ) {
1405                         free(input);
1406                         linphonec_out("No route specified.\n");
1407                         break;
1408                 }
1409
1410                 linphone_proxy_config_set_route(cfg, clean);
1411                 if ( ! cfg->reg_route )
1412                 {
1413                         linphonec_out("Invalid route.\n");
1414                         free(input);
1415                         continue;
1416                 }
1417
1418                 free(input);
1419                 break;
1420         }
1421
1422         /*
1423          * Final confirmation 
1424          */
1425         while (1)
1426         {
1427                 char *input;
1428                 char *clean;
1429
1430                 linphonec_out("--------------------------------------------\n");
1431                 linphonec_proxy_display(cfg);
1432                 linphonec_out("--------------------------------------------\n");
1433                 input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: ");
1434
1435
1436                 if ( ! input ) {
1437                         linphonec_out("Aborted.\n");
1438                         linphone_proxy_config_destroy(cfg);
1439                         return;
1440                 }
1441
1442                 /* Strip blanks */
1443                 clean=lpc_strip_blanks(input);
1444                 if ( ! *clean ) {
1445                         free(input);
1446                         continue;
1447                 }
1448
1449                 if ( ! strcmp(clean, "yes") ) break;
1450                 else if ( ! strcmp(clean, "no") )
1451                 {
1452                         linphonec_out("Declined.\n");
1453                         linphone_proxy_config_destroy(cfg);
1454                         free(input);
1455                         return;
1456                 }
1457
1458                 linphonec_out("Please answer with 'yes' or 'no'\n");
1459                 free(input);
1460                 continue;
1461         }
1462
1463
1464         linphone_core_add_proxy_config(lc,cfg);
1465
1466         /* automatically set the last entered proxy as the default one */
1467         linphone_core_set_default_proxy(lc,cfg);
1468
1469         linphonec_out("Proxy added.\n");
1470 }
1471
1472 static void
1473 linphonec_proxy_display(LinphoneProxyConfig *cfg)
1474 {
1475         linphonec_out("sip address: %s\nroute: %s\nidentity: %s\nregister: %s\nexpires: %i\nregistered: %s\n",
1476                         cfg->reg_proxy,
1477                         (cfg->reg_route!=NULL)?cfg->reg_route:"",
1478                         (cfg->reg_identity!=NULL)?cfg->reg_identity:"",
1479                         (cfg->reg_sendregister)?"yes":"no",
1480                         cfg->expires,
1481                         linphone_proxy_config_is_registered(cfg) ? "yes" : "no");
1482 }
1483
1484 static void linphonec_proxy_show(LinphoneCore *lc, int index)
1485 {
1486         const MSList *elem;
1487         int i;
1488         for(elem=linphone_core_get_proxy_config_list(lc),i=0;elem!=NULL;elem=elem->next,++i){
1489                 if (index==i){
1490                         LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)elem->data;
1491                         linphonec_proxy_display(cfg);
1492                         return;
1493                 }
1494         }
1495         linphonec_out("No proxy with index %i\n", index);
1496 }
1497
1498 static void
1499 linphonec_proxy_list(LinphoneCore *lc)
1500 {
1501         const MSList *proxies;
1502         int n;
1503         int def=linphone_core_get_default_proxy(lc,NULL);
1504         
1505         proxies=linphone_core_get_proxy_config_list(lc);
1506         for(n=0;proxies!=NULL;proxies=ms_list_next(proxies),n++){
1507                 if (n==def)
1508                         linphonec_out("****** Proxy %i - this is the default one - *******\n",n);
1509                 else 
1510                         linphonec_out("****** Proxy %i *******\n",n);
1511                 linphonec_proxy_display((LinphoneProxyConfig*)proxies->data);
1512         }
1513         if ( ! n ) linphonec_out("No proxies defined\n");
1514 }
1515
1516 static void
1517 linphonec_proxy_remove(LinphoneCore *lc, int index)
1518 {
1519         const MSList *proxies;
1520         LinphoneProxyConfig *cfg;
1521         proxies=linphone_core_get_proxy_config_list(lc);
1522         cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1523         if (cfg==NULL){
1524                 linphonec_out("No such proxy.\n");
1525                 return;
1526         }
1527         linphone_core_remove_proxy_config(lc,cfg);
1528         linphonec_out("Proxy %s removed.\n", cfg->reg_proxy);
1529         linphone_proxy_config_destroy(cfg);
1530 }
1531
1532 static int
1533 linphonec_proxy_use(LinphoneCore *lc, int index)
1534 {
1535         const MSList *proxies;
1536         LinphoneProxyConfig *cfg;
1537         proxies=linphone_core_get_proxy_config_list(lc);
1538         cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1539         if (cfg==NULL){
1540                 linphonec_out("No such proxy (try 'proxy list').");
1541                 return 0;
1542         }
1543         linphone_core_set_default_proxy(lc,cfg);
1544         return 1;
1545 }
1546
1547 static void
1548 linphonec_friend_display(LinphoneFriend *fr)
1549 {
1550         LinphoneAddress *uri=linphone_address_clone(linphone_friend_get_address(fr));
1551         char *str;
1552         
1553         linphonec_out("name: %s\n", linphone_address_get_display_name(uri));
1554         linphone_address_set_display_name(uri,NULL);
1555         str=linphone_address_as_string(uri);
1556         linphonec_out("address: %s\n", str);
1557 }
1558
1559 static int
1560 linphonec_friend_list(LinphoneCore *lc, char *pat)
1561 {
1562         const MSList *friend;
1563         int n;
1564
1565         if (pat) {
1566                 pat=lpc_strip_blanks(pat);
1567                 if (!*pat) pat = NULL;
1568         }
1569
1570         friend = linphone_core_get_friend_list(lc);
1571         for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1572         {
1573                 if ( pat ) {
1574                         const char *name = linphone_address_get_display_name(
1575                             linphone_friend_get_address((LinphoneFriend*)friend->data));
1576                         if (name && ! strstr(name, pat) ) continue;
1577                 }
1578                 linphonec_out("****** Friend %i *******\n",n);
1579                 linphonec_friend_display((LinphoneFriend*)friend->data);
1580         }
1581
1582         return 1;
1583 }
1584
1585 static int
1586 linphonec_friend_call(LinphoneCore *lc, unsigned int num)
1587 {
1588         const MSList *friend = linphone_core_get_friend_list(lc);
1589         unsigned int n;
1590         char *addr;
1591
1592         for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1593         {
1594                 if ( n == num )
1595                 {
1596                         int ret;
1597                         addr = linphone_address_as_string(linphone_friend_get_address((LinphoneFriend*)friend->data));
1598                         ret=lpc_cmd_call(lc, addr);
1599                         ms_free(addr);
1600                         return ret;
1601                 }
1602         }
1603         linphonec_out("No such friend %u\n", num);
1604         return 1;
1605 }
1606
1607 #ifndef WIN32
1608 static int
1609 linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr)
1610 {
1611         LinphoneFriend *newFriend;
1612
1613         char url[PATH_MAX];
1614
1615         snprintf(url, PATH_MAX, "%s <%s>", name, addr);
1616         newFriend = linphone_friend_new_with_addr(url);
1617         linphone_core_add_friend(lc, newFriend);
1618         return 0;
1619 }
1620 #endif
1621
1622 static int
1623 linphonec_friend_delete(LinphoneCore *lc, int num)
1624 {
1625         const MSList *friend = linphone_core_get_friend_list(lc);
1626         unsigned int n;
1627
1628         for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1629         {
1630                 if ( n == num )
1631                 {
1632                         linphone_core_remove_friend(lc, friend->data);
1633                         return 0;
1634                 }
1635         }
1636
1637         if (-1 == num) 
1638         {
1639                 unsigned int i;
1640                 for (i = 0 ; i < n ; i++)
1641                         linphonec_friend_delete(lc, 0);
1642                 return 0;
1643         }
1644
1645         linphonec_out("No such friend %u\n", num);
1646         return 1;
1647 }
1648
1649 static void
1650 linphonec_display_command_help(LPC_COMMAND *cmd)
1651 {
1652         if ( cmd->doc ) linphonec_out ("%s\n", cmd->doc);
1653         else linphonec_out("%s\n", cmd->help);
1654 }
1655
1656
1657 static int lpc_cmd_register(LinphoneCore *lc, char *args){
1658         char identity[512];
1659         char proxy[512];
1660         char passwd[512];
1661         LinphoneProxyConfig *cfg;
1662         const MSList *elem;
1663     
1664         if (!args)
1665         {
1666                 /* it means that you want to register the default proxy */
1667                 LinphoneProxyConfig *cfg=NULL;
1668                 linphone_core_get_default_proxy(lc,&cfg);
1669                 if (cfg)
1670                 {
1671                         if(!linphone_proxy_config_is_registered(cfg)) {
1672                                 linphone_proxy_config_enable_register(cfg,TRUE);
1673                                 linphone_proxy_config_done(cfg);
1674                         }else{
1675                                 linphonec_out("default proxy already registered\n");
1676                         }
1677                 }else{
1678                         linphonec_out("we do not have a default proxy\n");
1679                         return 0;
1680                 }
1681                 return 1;
1682         }
1683         passwd[0]=proxy[0]=identity[0]='\0';
1684         sscanf(args,"%s %s %s",identity,proxy,passwd);
1685         if (proxy[0]=='\0' || identity[0]=='\0'){
1686                 linphonec_out("Missing parameters, see help register\n");
1687                 return 1;
1688         }
1689         if (passwd[0]!='\0'){
1690                 LinphoneAddress *from;
1691                 LinphoneAuthInfo *info;
1692                 if ((from=linphone_address_new(identity))!=NULL){
1693                         char realm[128];
1694                         snprintf(realm,sizeof(realm)-1,"\"%s\"",linphone_address_get_domain(from));
1695                         info=linphone_auth_info_new(linphone_address_get_username(from),NULL,passwd,NULL,NULL);
1696                         linphone_core_add_auth_info(lc,info);
1697                         linphone_address_destroy(from);
1698                         linphone_auth_info_destroy(info);
1699                 }
1700         }
1701         elem=linphone_core_get_proxy_config_list(lc);
1702         if (elem) {
1703                 cfg=(LinphoneProxyConfig*)elem->data;
1704                 linphone_proxy_config_edit(cfg);
1705         }
1706         else cfg=linphone_proxy_config_new();
1707         linphone_proxy_config_set_identity(cfg,identity);
1708         linphone_proxy_config_set_server_addr(cfg,proxy);
1709         linphone_proxy_config_enable_register(cfg,TRUE);
1710         if (elem) linphone_proxy_config_done(cfg);
1711         else linphone_core_add_proxy_config(lc,cfg);
1712         linphone_core_set_default_proxy(lc,cfg);
1713         return 1;
1714 }
1715
1716 static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
1717         LinphoneProxyConfig *cfg=NULL;
1718         linphone_core_get_default_proxy(lc,&cfg);
1719         if (cfg && linphone_proxy_config_is_registered(cfg)) {
1720                 linphone_proxy_config_edit(cfg);
1721                 linphone_proxy_config_enable_register(cfg,FALSE);
1722                 linphone_proxy_config_done(cfg);
1723         }else{
1724                 linphonec_out("unregistered\n");
1725         }
1726         return 1;
1727 }
1728
1729 static int lpc_cmd_duration(LinphoneCore *lc, char *args){
1730         LinphoneCallLog *cl;
1731         const MSList *elem=linphone_core_get_call_logs(lc);
1732         for(;elem!=NULL;elem=elem->next){
1733                 if (elem->next==NULL){
1734                         cl=(LinphoneCallLog*)elem->data;
1735                         linphonec_out("%i seconds\n",cl->duration);
1736                 }
1737         }
1738         return 1;
1739 }
1740
1741 static int lpc_cmd_status(LinphoneCore *lc, char *args)
1742 {
1743         LinphoneProxyConfig *cfg;
1744         
1745         if ( ! args ) return 0;
1746         linphone_core_get_default_proxy(lc,&cfg);
1747         if (strstr(args,"register"))
1748         {
1749                 if (cfg)
1750                 {
1751                         if (linphone_proxy_config_is_registered(cfg)){
1752                                 linphonec_out("registered, identity=%s duration=%i\n",
1753                                         linphone_proxy_config_get_identity(cfg),
1754                                         linphone_proxy_config_get_expires(cfg));
1755                         }else if (linphone_proxy_config_register_enabled(cfg)){
1756                                 linphonec_out("registered=-1\n");
1757                         }else linphonec_out("registered=0\n");
1758                 }
1759                 else linphonec_out("registered=0\n");
1760         }
1761         else if (strstr(args,"autoanswer"))
1762         {
1763                 if (cfg && linphone_proxy_config_is_registered(cfg))
1764                         linphonec_out("autoanswer=%i\n",linphonec_get_autoanswer());
1765                 else linphonec_out("unregistered\n");
1766         }
1767         else if (strstr(args,"hook"))
1768         {
1769                 gstate_t call_state=linphone_core_get_state(lc,GSTATE_GROUP_CALL);
1770 /*
1771                 if (!cfg || !linphone_proxy_config_is_registered(cfg)){
1772                         linphonec_out("unregistered\n");
1773                         return 1;
1774                 }
1775  */
1776                 switch(call_state){
1777                         case GSTATE_CALL_OUT_INVITE:
1778                                 linphonec_out("hook=dialing\n");
1779                         break;
1780                         case GSTATE_CALL_IDLE:
1781                                 linphonec_out("hook=offhook\n");
1782                         break;
1783                         case GSTATE_CALL_OUT_CONNECTED:
1784                                 linphonec_out("Call out, hook=%s duration=%i, muted=%s rtp-xmit-muted=%s\n", linphonec_get_callee(),
1785                                               linphone_core_get_current_call_duration(lc),
1786                                               lc->audio_muted ? "yes" : "no",
1787                                               linphone_core_is_rtp_muted(lc) ? "yes"  : "no");
1788                         break;
1789                         case GSTATE_CALL_IN_CONNECTED:
1790                                 linphonec_out("hook=answered duration=%i\n" ,
1791                                         linphone_core_get_current_call_duration(lc));
1792                                 break;
1793                         case GSTATE_CALL_IN_INVITE:
1794                                 linphonec_out("Incoming call from %s\n",linphonec_get_caller());
1795                                 break;
1796                         default:
1797                                 break;
1798                 }
1799                 
1800         }
1801         else return 0;
1802
1803         return 1;
1804 }
1805
1806 static int lpc_cmd_ports(LinphoneCore *lc, char *args)
1807 {
1808         int port;
1809         if ( ! args ){
1810                 linphonec_out("sip port = %i\naudio rtp port = %i\nvideo rtp port = %i\n",
1811                         linphone_core_get_sip_port(lc),
1812                         linphone_core_get_audio_port(lc),
1813                         linphone_core_get_video_port(lc));
1814                 return 1;
1815         }
1816         if (sscanf(args,"sip %i",&port)==1){
1817                 linphonec_out("Setting sip port to %i\n",port);
1818                 linphone_core_set_sip_port(lc,port);
1819         }else return 0;
1820
1821         return 1;
1822 }
1823
1824 static int lpc_cmd_speak(LinphoneCore *lc, char *args){
1825 #ifndef WIN32
1826         char voice[64];
1827         char *sentence;
1828         char cl[128];
1829         char *wavfile;
1830         int status;
1831         FILE *file;
1832         
1833     if (!args) return 0;
1834         memset(voice,0,sizeof(voice));
1835         sscanf(args,"%s63",voice);
1836         sentence=args+strlen(voice);
1837         wavfile=tempnam("/tmp/","linphonec-espeak-");
1838         snprintf(cl,sizeof(cl),"espeak -v %s -s 100 -w %s --stdin",voice,wavfile);
1839         file=popen(cl,"w");
1840         if (file==NULL){
1841                 ms_error("Could not open pipe to espeak !");
1842                 return 1;
1843         }
1844         fprintf(file,"%s",sentence);
1845         status=pclose(file);
1846         if (WEXITSTATUS(status)==0){
1847                 linphone_core_set_play_file(lc,wavfile);
1848         }else{
1849                 linphonec_out("espeak command failed.");
1850         }
1851 #else
1852         linphonec_out("Sorry, this command is not implemented in windows version.");
1853 #endif
1854         return 1;
1855 }
1856
1857 static int lpc_cmd_codec(LinphoneCore *lc, char *args){
1858         char *arg1 = args;
1859         char *arg2 = NULL;
1860         char *ptr = args;
1861
1862         if (!args) return 0;
1863
1864         /* Isolate first and second arg */
1865         while(*ptr && !isspace(*ptr)) ++ptr;
1866         if ( *ptr )
1867         {
1868                 *ptr='\0';
1869                 arg2=ptr+1;
1870                 while(*arg2 && isspace(*arg2)) ++arg2;
1871         }
1872
1873         if (strcmp(arg1,"enable")==0)
1874         {
1875 #ifdef HAVE_READLINE
1876                 rl_inhibit_completion=1;
1877 #endif
1878         if (!strcmp(arg2,"all")) linphonec_codec_enable(lc,-1);
1879         else linphonec_codec_enable(lc,atoi(arg2));
1880 #ifdef HAVE_READLINE
1881                 rl_inhibit_completion=0;
1882 #endif
1883         }
1884         else if (strcmp(arg1,"list")==0)
1885         {
1886                 linphonec_codec_list(lc);
1887         }
1888         else if (strcmp(arg1,"disable")==0)
1889         {
1890         if (!strcmp(arg2,"all")) linphonec_codec_disable(lc,-1);
1891         else linphonec_codec_disable(lc,atoi(arg2));
1892         }
1893         else
1894         {
1895                 return 0; /* syntax error */
1896         }
1897
1898         return 1;
1899 }
1900
1901 static void linphonec_codec_list(LinphoneCore *lc){
1902         PayloadType *pt;
1903     codecs_config_t *config=&lc->codecs_conf;
1904         int index=0;
1905         MSList *node;
1906         for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
1907                 pt=(PayloadType*)(node->data);
1908         linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, 
1909                     linphone_core_payload_type_enabled(lc,pt) ? "enabled" : "disabled");
1910                 index++;
1911         }
1912 }
1913
1914 static void linphonec_codec_enable(LinphoneCore *lc, int sel_index){
1915         PayloadType *pt;
1916     codecs_config_t *config=&lc->codecs_conf;
1917         int index=0;
1918         MSList *node;
1919     for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
1920         if (index == sel_index || sel_index == -1) {
1921                     pt=(PayloadType*)(node->data);
1922             pt->flags|=PAYLOAD_TYPE_ENABLED;
1923             linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "enabled");
1924         }
1925                 index++;
1926         }
1927 }
1928
1929 static void linphonec_codec_disable(LinphoneCore *lc, int sel_index){
1930         PayloadType *pt;
1931     codecs_config_t *config=&lc->codecs_conf;
1932         int index=0;
1933         MSList *node;
1934         for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
1935         if (index == sel_index || sel_index == -1) {
1936                 pt=(PayloadType*)(node->data);
1937             pt->flags&=~PAYLOAD_TYPE_ENABLED;
1938             linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "disabled");
1939         }
1940                 index++;
1941         }
1942 }
1943
1944 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){
1945         char *arg1 = args;
1946         char *arg2 = NULL;
1947         char *ptr = args;
1948
1949         if (!args) return 0;
1950
1951         /* Isolate first and second arg */
1952         while(*ptr && !isspace(*ptr)) ++ptr;
1953         if ( *ptr )
1954         {
1955                 *ptr='\0';
1956                 arg2=ptr+1;
1957                 while(*arg2 && isspace(*arg2)) ++arg2;
1958         }
1959
1960         if (strcmp(arg1,"on")==0){
1961         int delay, tail_len, frame_size;
1962         int n;
1963
1964         linphone_core_enable_echo_cancellation(lc,1);
1965
1966         if (arg2 != 0) {
1967             n = sscanf(arg2, "%d %d %d", &delay, &tail_len, &frame_size);
1968
1969             if (n == 1) {   
1970                 lp_config_set_int(lc->config,"sound","ec_delay",delay);
1971             }
1972             else if (n == 2) {
1973                 lp_config_set_int(lc->config,"sound","ec_delay",delay);
1974                 lp_config_set_int(lc->config,"sound","ec_tail_len",tail_len);
1975             }
1976             else if (n == 3) {
1977                 lp_config_set_int(lc->config,"sound","ec_delay",delay);
1978                 lp_config_set_int(lc->config,"sound","ec_tail_len",tail_len);
1979                 lp_config_set_int(lc->config,"sound","ec_framesize",frame_size);
1980             }
1981         }
1982     }
1983     else if (strcmp(arg1,"off")==0){
1984         linphone_core_enable_echo_cancellation(lc,0);
1985     }
1986     else if (strcmp(arg1,"show")==0){
1987         linphonec_out("echo cancellation is %s; delay %d, tail length %d, frame size %d\n", 
1988             linphone_core_echo_cancellation_enabled(lc) ? "on" : "off",
1989             lp_config_get_int(lc->config,"sound","ec_delay",0),
1990             lp_config_get_int(lc->config,"sound","ec_tail_len",0),
1991             lp_config_get_int(lc->config,"sound","ec_framesize",0));        
1992     }
1993     else {
1994         return 0;
1995     }
1996
1997     return 1;
1998 }
1999
2000 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args)
2001 {
2002         linphone_core_mute_mic(lc, 1);
2003         return 1;
2004 }
2005
2006 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args){
2007         linphone_core_mute_mic(lc, 0);
2008         return 1;
2009 }
2010
2011 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args)
2012 {
2013   bool_t rtp_xmit_off=FALSE;
2014   char *status;
2015   gstate_t call_state=linphone_core_get_state(lc,GSTATE_GROUP_CALL);
2016
2017   if(args){
2018     if(strstr(args,"1"))rtp_xmit_off=TRUE;
2019     if(call_state == GSTATE_CALL_IDLE)
2020       linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_xmit_off);
2021     else 
2022       linphonec_out("nortp-on-audio-mute: call in progress - cannot change state\n");
2023   }
2024   rtp_xmit_off=linphone_core_get_rtp_no_xmit_on_audio_mute(lc);
2025   if(rtp_xmit_off)status="off";
2026   else status="on";
2027   linphonec_out("rtp transmit %s when audio muted\n",status);
2028   return 1;
2029 }
2030
2031
2032 /***************************************************************************
2033  *
2034  *  Command table management funx
2035  *
2036  ***************************************************************************/
2037
2038 /*
2039  * Find a command given its name
2040  */
2041 static LPC_COMMAND *
2042 lpc_find_command(const char *name)
2043 {
2044         int i;
2045
2046         for (i=0; commands[i].name; ++i)
2047         {
2048                 if (strcmp(name, commands[i].name) == 0)
2049                         return &commands[i];
2050         }
2051
2052         return (LPC_COMMAND *)NULL;
2053 }
2054
2055
2056 /****************************************************************************
2057  *
2058  * $Log: commands.c,v $
2059  * Revision 1.39  2008/07/03 15:08:34  smorlat
2060  * api cleanups, interface in progress.
2061  *
2062  * Revision 1.38  2008/06/17 20:38:59  smorlat
2063  * added missing file.
2064  *
2065  * Revision 1.37  2008/04/09 09:26:00  smorlat
2066  * merge various patches
2067  * H264 support.
2068  *
2069  * Revision 1.36  2007/08/01 14:47:53  strk
2070  *         * console/commands.c: Clean up commands 'nat', 'stun'
2071  *           and 'firewall' to be more intuitive.
2072  *
2073  * Revision 1.35  2007/06/27 09:01:25  smorlat
2074  * logging improvements.
2075  *
2076  * Revision 1.34  2007/02/20 10:17:13  smorlat
2077  * linphonec friends patch2
2078  *
2079  * Revision 1.31  2006/09/22 07:22:47  smorlat
2080  * linphonecore api changes.
2081  *
2082  * Revision 1.30  2006/09/08 15:32:57  smorlat
2083  * support for using files instead of soundcard (used by linphonec only)
2084  *
2085  * Revision 1.29  2006/08/28 14:29:07  smorlat
2086  * fix bug.
2087  *
2088  * Revision 1.28  2006/08/21 12:49:59  smorlat
2089  * merged several little patches.
2090  *
2091  * Revision 1.27  2006/07/17 18:45:00  smorlat
2092  * support for several event queues in ortp.
2093  * glib dependency removed from coreapi/ and console/
2094  *
2095  * Revision 1.26  2006/04/14 15:16:36  smorlat
2096  * soundcard use did nothing !
2097  *
2098  * Revision 1.25  2006/04/06 20:09:33  smorlat
2099  * add linphonec command to see and select sound devices.
2100  *
2101  * Revision 1.24  2006/03/04 11:17:10  smorlat
2102  * mediastreamer2 in progress.
2103  *
2104  * Revision 1.23  2006/02/20 21:14:01  strk
2105  * Handled syntax errors with 'friend' command
2106  *
2107  * Revision 1.22  2006/02/20 10:20:29  strk
2108  * Added substring-based filter support for command 'friend list'
2109  *
2110  * Revision 1.21  2006/02/02 15:39:18  strk
2111  * - Added 'friend list' and 'friend call' commands
2112  * - Allowed for multiple DTFM send in a single line
2113  * - Added status-specific callback (bare version)
2114  *
2115  * Revision 1.20  2006/01/26 11:54:34  strk
2116  * More robust 'nat' command handler (strip blanks in args)
2117  *
2118  * Revision 1.19  2006/01/26 09:48:05  strk
2119  * Added limits.h include
2120  *
2121  * Revision 1.18  2006/01/26 02:18:05  strk
2122  * Added new commands 'nat use' and 'nat unuse'.
2123  * These will required a pending patch to linphonecore.c
2124  * in order to work.
2125  *
2126  * Revision 1.17  2006/01/20 14:12:33  strk
2127  * Added linphonec_init() and linphonec_finish() functions.
2128  * Handled SIGINT and SIGTERM to invoke linphonec_finish().
2129  * Handling of auto-termination (-t) moved to linphonec_finish().
2130  * Reworked main (input read) loop to not rely on 'terminate'
2131  * and 'run' variable (dropped). configfile_name allocated on stack
2132  * using PATH_MAX limit. Changed print_usage signature to allow
2133  * for an exit_status specification.
2134  *
2135  * Revision 1.16  2006/01/18 09:25:32  strk
2136  * Command completion inhibited in proxy addition and auth request prompts.
2137  * Avoided use of linphonec_readline's internal filename completion.
2138  *
2139  * Revision 1.15  2006/01/14 13:29:32  strk
2140  * Reworked commands interface to use a table structure,
2141  * used by command line parser and help function.
2142  * Implemented first level of completion (commands).
2143  * Added notification of invalid "answer" and "terminate"
2144  * commands (no incoming call, no active call).
2145  * Forbidden "call" intialization when a call is already active.
2146  * Cleaned up all commands, adding more feedback and error checks.
2147  *
2148  * Revision 1.14  2006/01/13 13:00:29  strk
2149  * Added linphonec.h. Code layout change (added comments, forward decl,
2150  * globals on top, copyright notices and Logs). Handled out-of-memory
2151  * condition on history management. Removed assumption on sizeof(char).
2152  * Fixed bug in authentication prompt (introduced by linphonec_readline).
2153  * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
2154  *
2155  *
2156  ****************************************************************************/