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