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