1 /****************************************************************************
3 * $Id: commands.c,v 1.39 2008/07/03 15:08:34 smorlat Exp $
5 * Copyright (C) 2006-2009 Sandro Santilli <strk@keybit.net>
6 * Copyright (C) 2004 Simon MORLAT <simon.morlat@linphone.org>
8 ****************************************************************************
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.
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.
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.
24 ****************************************************************************/
35 #include <linphonecore.h>
36 #include "linphonec.h"
44 /***************************************************************************
46 * Forward declarations
48 ***************************************************************************/
50 extern char *lpc_strip_blanks(char *input);
52 /* Command handlers */
53 static int lpc_cmd_help(LinphoneCore *, char *);
54 static int lpc_cmd_proxy(LinphoneCore *, char *);
55 static int lpc_cmd_call(LinphoneCore *, char *);
56 static int lpc_cmd_chat(LinphoneCore *, char *);
57 static int lpc_cmd_answer(LinphoneCore *, char *);
58 static int lpc_cmd_autoanswer(LinphoneCore *, char *);
59 static int lpc_cmd_terminate(LinphoneCore *, char *);
60 static int lpc_cmd_call_logs(LinphoneCore *, char *);
61 static int lpc_cmd_ipv6(LinphoneCore *, char *);
62 static int lpc_cmd_refer(LinphoneCore *, char *);
63 static int lpc_cmd_quit(LinphoneCore *, char *);
64 static int lpc_cmd_nat(LinphoneCore *, char *);
65 static int lpc_cmd_stun(LinphoneCore *, char *);
66 static int lpc_cmd_firewall(LinphoneCore *, char *);
67 static int lpc_cmd_friend(LinphoneCore *, char*);
68 static int lpc_cmd_soundcard(LinphoneCore *, char *);
69 static int lpc_cmd_webcam(LinphoneCore *, char *);
70 static int lpc_cmd_staticpic(LinphoneCore *, char *);
71 static int lpc_cmd_play(LinphoneCore *, char *);
72 static int lpc_cmd_record(LinphoneCore *, char *);
73 static int lpc_cmd_register(LinphoneCore *, char *);
74 static int lpc_cmd_unregister(LinphoneCore *, char *);
75 static int lpc_cmd_duration(LinphoneCore *lc, char *args);
76 static int lpc_cmd_status(LinphoneCore *lc, char *args);
77 static int lpc_cmd_ports(LinphoneCore *lc, char *args);
78 static int lpc_cmd_speak(LinphoneCore *lc, char *args);
79 static int lpc_cmd_codec(LinphoneCore *lc, char *args);
80 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args);
81 static int lpc_cmd_pause(LinphoneCore *lc, char *args);
82 static int lpc_cmd_resume(LinphoneCore *lc, char *args);
83 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args);
84 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args);
85 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args);
87 /* Command handler helpers */
88 static void linphonec_proxy_add(LinphoneCore *lc);
89 static void linphonec_proxy_display(LinphoneProxyConfig *lc);
90 static void linphonec_proxy_list(LinphoneCore *lc);
91 static void linphonec_proxy_remove(LinphoneCore *lc, int index);
92 static int linphonec_proxy_use(LinphoneCore *lc, int index);
93 static void linphonec_proxy_show(LinphoneCore *lc,int index);
94 static void linphonec_friend_display(LinphoneFriend *fr);
95 static int linphonec_friend_list(LinphoneCore *lc, char *arg);
96 static void linphonec_display_command_help(LPC_COMMAND *cmd);
97 static int linphonec_friend_call(LinphoneCore *lc, unsigned int num);
99 static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
101 static int linphonec_friend_delete(LinphoneCore *lc, int num);
102 static int linphonec_friend_delete(LinphoneCore *lc, int num);
103 static void linphonec_codec_list(LinphoneCore *lc);
104 static void linphonec_codec_enable(LinphoneCore *lc, int index);
105 static void linphonec_codec_disable(LinphoneCore *lc, int index);
109 /* Command table management */
110 static LPC_COMMAND *lpc_find_command(const char *name);
112 void linphonec_out(const char *fmt,...);
116 /***************************************************************************
120 ***************************************************************************/
125 LPC_COMMAND commands[] = {
126 { "help", lpc_cmd_help, "Print commands help", NULL },
127 { "call", lpc_cmd_call, "Call a SIP uri",
128 "'call <sip-url>' \t: initiate a call to the specified destination.\n"
129 "'call show' \t: show all the current calls status.\n"
131 { "chat", lpc_cmd_chat, "Chat with a SIP uri",
132 "'chat <sip-url> \"message\"' "
133 ": send a chat message \"message\" to the specified destination."
135 { "terminate", lpc_cmd_terminate, "Terminate a call",
136 "'terminate' : Terminate the current call\n"
137 "'terminate <sip:XXX@XXX.XXX.XXX.XXX>' : Terminate the call with remote address\n"
138 "'terminate <all>' : Terminate all the current calls\n"
140 { "answer", lpc_cmd_answer, "Answer a call",
141 "'answer' : Answer the current incoming call\n"
142 "'answer <sip:XXX@XXX.XXX.XXX.XXX>' : Answer the call with remote address\n"
144 { "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
145 "'autoanswer' \t: show current autoanswer mode\n"
146 "'autoanswer enable'\t: enable autoanswer mode\n"
147 "'autoanswer disable'\t: disable autoanswer modeĀ \n"},
148 { "proxy", lpc_cmd_proxy, "Manage proxies",
149 "'proxy list' : list all proxy setups.\n"
150 "'proxy add' : add a new proxy setup.\n"
151 "'proxy remove <index>' : remove proxy setup with number index.\n"
152 "'proxy use <index>' : use proxy with number index as default proxy.\n"
153 "'proxy unuse' : don't use a default proxy.\n"
154 "'proxy show <index>' : show configuration and status of the proxy numbered by index.\n"
155 "'proxy show default' : show configuration and status of the default proxy.\n"
157 { "soundcard", lpc_cmd_soundcard, "Manage soundcards",
158 "'soundcard list' : list all sound devices.\n"
159 "'soundcard show' : show current sound devices configuration.\n"
160 "'soundcard use <index>' : select a sound device.\n"
161 "'soundcard use files' : use .wav files instead of soundcard\n"
163 { "webcam", lpc_cmd_webcam, "Manage webcams",
164 "'webcam list' : list all known devices.\n"
165 "'webcam use <index>' : select a video device.\n"
167 { "staticpic", lpc_cmd_staticpic, "Manage static pictures when nowebcam",
168 "'staticpic set' : Set path to picture that should be used.\n"
170 { "ipv6", lpc_cmd_ipv6, "Use IPV6",
171 "'ipv6 status' : show ipv6 usage status.\n"
172 "'ipv6 enable' : enable the use of the ipv6 network.\n"
173 "'ipv6 disable' : do not use ipv6 network."
175 { "refer", lpc_cmd_refer,
176 "Refer the current call to the specified destination.",
177 "'refer <sip-url>' or 'r <sip-url>' "
178 ": refer the current call to the specified destination."
180 { "nat", lpc_cmd_nat, "Set nat address",
181 "'nat' : show nat settings.\n"
182 "'nat <addr>' : set nat address.\n"
184 { "stun", lpc_cmd_stun, "Set stun server address",
185 "'stun' : show stun settings.\n"
186 "'stun <addr>' : set stun server address.\n"
188 { "firewall", lpc_cmd_firewall, "Set firewall policy",
189 "'firewall' : show current firewall policy.\n"
190 "'firewall none' : use direct connection.\n"
191 "'firewall nat' : use nat address given with the 'nat' command.\n"
192 "'firewall stun' : use stun server given with the 'stun' command.\n"
194 { "call-logs", lpc_cmd_call_logs, "Calls history", NULL },
195 { "friend", lpc_cmd_friend, "Manage friends",
196 "'friend list [<pattern>]' : list friends.\n"
197 "'friend call <index>' : call a friend.\n"
198 "'friend add <name> <addr>' : add friend, <name> must be quoted to include\n"
199 " spaces, <addr> has \"sip:\" added if it isn't\n"
200 " there. Don't use '<' '>' around <addr>.\n"
201 "'friend delete <index>' : remove friend, 'all' removes all\n"
203 { "play", lpc_cmd_play, "play from a wav file",
204 "This feature is available only in file mode (see 'help soundcard')\n"
205 "'play <wav file>' : play a wav file."
207 { "record", lpc_cmd_record, "record to a wav file",
208 "This feature is available only in file mode (see 'help soundcard')\n"
209 "'record <wav file>' : record into wav file."
211 { "quit", lpc_cmd_quit, "Exit linphonec", NULL },
212 { "register", lpc_cmd_register, "Register in one line to a proxy" , "register <sip identity> <sip proxy> <password>"},
213 { "unregister", lpc_cmd_unregister, "Unregister from default proxy", NULL },
214 { "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
215 { "status", lpc_cmd_status, "Print various status information",
216 "'status register' \t: print status concerning registration\n"
217 "'status autoanswer'\t: tell whether autoanswer mode is enabled\n"
218 "'status hook' \t: print hook status\n" },
219 { "ports", lpc_cmd_ports, "Network ports configuration",
220 "'ports' \t: prints current used ports.\n"
221 "'ports sip <port number>'\t: Sets the sip port.\n" },
222 { "speak", lpc_cmd_speak, "Speak a sentence using espeak TTS engine",
223 "This feature is available only in file mode. (see 'help soundcard')\n"
224 "'speak <voice name> <sentence>' : speak a text using the specified espeak voice.\n"
225 "Example for english voice: 'speak default Hello my friend !'"
227 { "codec", lpc_cmd_codec, "Codec configuration",
228 "'codec list' : list codecs\n"
229 "'codec enable <index>' : enable available codec\n"
230 "'codec disable <index>' : disable codecs" },
231 { "ec", lpc_cmd_echocancellation, "Echo cancellation",
232 "'ec on [<delay>] [<tail>] [<framesize>]' : turn EC on with given delay, tail length and framesize\n"
233 "'ec off' : turn echo cancellation (EC) off\n"
234 "'ec show' : show EC status" },
235 { "pause", lpc_cmd_pause, "pause a call",
236 "'pause' : pause the current call\n"},
237 { "resume", lpc_cmd_resume, "resume a call",
238 "'resume' : resume the unique call\n"
239 "'resume <sip:XXX@XXX.XXX.XXX.XXX>' : hold off the call with cid <cid>\n"},
240 { "mute", lpc_cmd_mute_mic,
241 "Mute microphone and suspend voice transmission."},
242 { "unmute", lpc_cmd_unmute_mic,
243 "Unmute microphone and resume voice transmission."},
244 { "nortp-on-audio-mute", lpc_cmd_rtp_no_xmit_on_audio_mute,
245 "Set the rtp_no_xmit_on_audio_mute configuration parameter",
246 " If set to 1 then rtp transmission will be muted when\n"
247 " audio is muted , otherwise rtp is always sent."},
248 { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
251 /***************************************************************************
255 ***************************************************************************/
258 * Main command dispatcher.
259 * WARNING: modifies second argument!
261 * Always return 1 currently.
264 linphonec_parse_command_line(LinphoneCore *lc, char *cl)
270 /* Isolate first word and args */
271 while(*ptr && !isspace(*ptr)) ++ptr;
275 /* set args to first nonblank */
277 while(*args && isspace(*args)) ++args;
281 if ( isdigit(*cl) || *cl == '#' || *cl == '*' )
283 while ( isdigit(*cl) || *cl == '#' || *cl == '*' )
285 linphone_core_send_dtmf(lc, *cl);
286 ms_sleep(1); // be nice
290 // discard spurious trailing chars
294 /* Handle other kind of commands */
295 cmd=lpc_find_command(cl);
298 linphonec_out("'%s': Cannot understand this.\n", cl);
302 if ( ! cmd->func(lc, args) )
304 linphonec_out("Syntax error.\n");
305 linphonec_display_command_help(cmd);
312 * Generator function for command completion.
313 * STATE let us know whether to start from scratch;
314 * without any state (STATE==0), then we start at the
318 linphonec_command_generator(const char *text, int state)
320 static int index, len;
330 * Return the next name which partially matches
331 * from the commands list
333 while ((name=commands[index].name))
335 ++index; /* so next call get next command */
337 if (strncmp(name, text, len) == 0)
339 return ortp_strdup(name);
347 /***************************************************************************
351 ***************************************************************************/
354 lpc_cmd_help(LinphoneCore *lc, char *arg)
361 linphonec_out("Commands are:\n");
362 linphonec_out("---------------------------\n");
364 while (commands[i].help)
366 linphonec_out("%10.10s\t%s\n", commands[i].name,
371 linphonec_out("---------------------------\n");
372 linphonec_out("Type 'help <command>' for more details.\n");
377 cmd=lpc_find_command(arg);
380 linphonec_out("No such command.\n");
384 linphonec_display_command_help(cmd);
389 static char callee_name[256]={0};
390 static char caller_name[256]={0};
393 lpc_cmd_call(LinphoneCore *lc, char *args)
395 if ( ! args || ! *args )
399 if(!strcmp(args,"show"))
401 MSList *calls = linphone_core_get_calls(lc);
404 MSList *p_calls = calls;
405 linphonec_out("<remote>\t\t\t\t<status>\r\n");
406 while(p_calls != NULL)
408 linphonec_out("%s\t\t\t%s\r\n",
409 linphone_call_get_remote_address_as_string(p_calls->data),
410 (((LinphoneCall *)p_calls->data)==linphone_core_get_current_call(lc))?"yes":"no");
411 p_calls = p_calls->next;
417 linphonec_out("No active call.\n");
422 if ( linphone_core_in_call(lc) )
424 linphonec_out("Terminate or hold on the current call first.\n");
427 if ( NULL == linphone_core_invite(lc, args) )
429 linphonec_out("Error from linphone_core_invite.\n");
433 snprintf(callee_name,sizeof(callee_name),"%s",args);
440 lpc_cmd_chat(LinphoneCore *lc, char *args)
448 /* Isolate first and second arg */
449 while(*ptr && !isspace(*ptr)) ++ptr;
454 while(*arg2 && isspace(*arg2)) ++arg2;
458 /* missing one parameter */
461 LinphoneChatRoom *cr = linphone_core_create_chat_room(lc,arg1);
462 linphone_chat_room_send_message(cr,arg2);
463 linphone_chat_room_destroy(cr);
468 const char *linphonec_get_callee(){
472 const char *linphonec_get_caller(){
476 void linphonec_set_caller(const char *caller){
477 snprintf(caller_name,sizeof(caller_name)-1,"%s",caller);
481 lpc_cmd_refer(LinphoneCore *lc, char *args)
484 linphone_core_refer(lc, linphone_core_get_current_call(lc), args);
486 linphonec_out("refer needs an argument\n");
492 lpc_cmd_terminate(LinphoneCore *lc, char *args)
500 if(linphone_core_in_call(lc))
502 if ( -1 == linphone_core_terminate_call(lc, linphone_core_get_current_call(lc)) )
504 linphonec_out("Could not stop the active call.\n");
509 linphonec_out("No active call.\n");
514 /* Isolate first and second arg */
515 while(*ptr && !isspace(*ptr)) ++ptr;
520 while(*arg2 && isspace(*arg2)) ++arg2;
524 if(strcmp(arg1,"all")==0)
526 linphonec_out("We are going to stop all the calls.\n");
527 return (linphone_core_terminate_all_calls(lc)==0)?1:0;
531 char the_remote_address[255];
532 int n = sscanf(arg1, "%s", the_remote_address);
535 if ( -1 == linphone_core_terminate_call(lc,linphone_core_get_call_by_remote_address(lc,the_remote_address)))
537 linphonec_out("Cannot stop the call with %s.\n",the_remote_address);
548 lpc_cmd_answer(LinphoneCore *lc, char *args)
556 //if just one call is present answer the only one in passing NULL to the linphone_core_accept_call ...
557 if ( -1 == linphone_core_accept_call(lc, NULL) )
559 linphonec_out("No incoming call.\n");
564 // Isolate first and second arg
565 while(*ptr && !isspace(*ptr)) ++ptr;
570 while(*arg2 && isspace(*arg2)) ++arg2;
574 char the_remote_address[256];
575 int n = sscanf(arg1, "%s", the_remote_address);
578 if ( -1 == linphone_core_accept_call(lc, linphone_core_get_call_by_remote_address(lc,the_remote_address)) )
580 linphonec_out("Cannot answer the call from %s.\n",the_remote_address);
589 lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
593 if ( linphonec_get_autoanswer() ) {
594 linphonec_out("Auto answer is enabled. Use 'autoanswer disable' to disable.\n");
596 linphonec_out("Auto answer is disabled. Use 'autoanswer enable' to enable.\n");
601 if (strstr(args,"enable")){
602 linphonec_set_autoanswer(TRUE);
603 linphonec_out("Auto answer enabled.\n");
604 }else if (strstr(args,"disable")){
605 linphonec_set_autoanswer(FALSE);
606 linphonec_out("Auto answer disabled.\n");
612 lpc_cmd_quit(LinphoneCore *lc, char *args)
614 linphonec_main_loop_exit();
619 lpc_cmd_nat(LinphoneCore *lc, char *args)
624 if ( args ) args=lpc_strip_blanks(args);
628 linphone_core_set_nat_address(lc, args);
629 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS); */
632 nat = linphone_core_get_nat_address(lc);
633 use = linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS;
634 linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
640 lpc_cmd_stun(LinphoneCore *lc, char *args)
645 if ( args ) args=lpc_strip_blanks(args);
649 linphone_core_set_stun_server(lc, args);
650 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN); */
653 stun = linphone_core_get_stun_server(lc);
654 use = linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_STUN;
655 linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
661 lpc_cmd_firewall(LinphoneCore *lc, char *args)
663 const char* setting=NULL;
665 if ( args ) args=lpc_strip_blanks(args);
669 if (strcmp(args,"none")==0)
671 linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_NO_FIREWALL);
673 else if (strcmp(args,"stun")==0)
675 setting = linphone_core_get_stun_server(lc);
678 linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
681 linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN);
683 else if (strcmp(args,"nat")==0)
685 setting = linphone_core_get_nat_address(lc);
688 linphonec_out("No nat address is defined, use 'nat <address>' first");
691 linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS);
695 switch(linphone_core_get_firewall_policy(lc))
697 case LINPHONE_POLICY_NO_FIREWALL:
698 linphonec_out("No firewall\n");
700 case LINPHONE_POLICY_USE_STUN:
701 linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
703 case LINPHONE_POLICY_USE_NAT_ADDRESS:
704 linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
711 /* Helper function for processing freind names */
713 lpc_friend_name(char **args, char **name)
715 /* Use space as a terminator unless quoted */
716 if (('"' == **args) || ('\'' == **args)){
721 while ((delim != *end) && ('\0' != *end)) end++;
723 fprintf(stderr, "Mismatched quotes\n");
730 *name = strsep(args, " ");
732 if (NULL == *args) { /* Means there was no separator */
733 fprintf(stderr, "Either name or address is missing\n");
736 if (NULL == *name) return 0;
743 lpc_cmd_friend(LinphoneCore *lc, char *args)
747 if ( args ) args=lpc_strip_blanks(args);
749 if ( ! args || ! *args ) return 0;
751 if ( !strncmp(args, "list", 4) )
753 return linphonec_friend_list(lc, args+4);
756 else if ( !strncmp(args, "call", 4) )
759 if ( ! *args ) return 0;
760 friend_num = strtol(args, NULL, 10);
762 if ( errno == ERANGE ) {
763 linphonec_out("Invalid friend number\n");
766 #endif /*_WIN32_WCE*/
767 linphonec_friend_call(lc, friend_num);
770 else if ( !strncmp(args, "delete", 6) )
773 if ( ! *args ) return 0;
774 while (*args == ' ') args++;
775 if ( ! *args ) return 0;
776 if (!strncmp(args, "all", 3))
782 friend_num = strtol(args, NULL, 10);
784 if ( errno == ERANGE ) {
785 linphonec_out("Invalid friend number\n");
788 #endif /*_WIN32_WCE*/
790 linphonec_friend_delete(lc, friend_num);
793 else if ( !strncmp(args, "add", 3) )
802 if ( ! *args ) return 0;
803 while (*args == ' ') args++;
804 if ( ! *args ) return 0;
806 if (!lpc_friend_name(&args, &name)) return 0;
808 while (*args == ' ') args++;
809 if ( ! *args ) return 0;
810 if (isdigit(*args)) {
811 strcpy (addr, "sip:");
812 addr_p = addr + strlen("sip:");
814 addr_orig = strsep(&args, " ");
815 if (1 >= strlen(addr_orig)) {
816 fprintf(stderr, "A single-digit address is not valid\n");
819 strcpy(addr_p, addr_orig);
820 linphonec_friend_add(lc, name, addr);
822 LinphoneFriend *new_friend;
823 new_friend = linphone_friend_new_with_addr(args);
824 linphone_core_add_friend(lc, new_friend);
831 static int lpc_cmd_play(LinphoneCore *lc, char *args){
832 if ( args ) args=lpc_strip_blanks(args);
833 if ( ! args || ! *args ) return 0;
834 linphone_core_set_play_file(lc,args);
838 static int lpc_cmd_record(LinphoneCore *lc, char *args){
839 if ( args ) args=lpc_strip_blanks(args);
840 if ( ! args || ! *args ) return 0;
841 linphone_core_set_record_file(lc,args);
849 lpc_cmd_proxy(LinphoneCore *lc, char *args)
856 if ( ! arg1 ) return 0;
858 /* Isolate first and second arg */
859 while(*ptr && !isspace(*ptr)) ++ptr;
864 while(*arg2 && isspace(*arg2)) ++arg2;
867 if (strcmp(arg1,"add")==0)
870 rl_inhibit_completion=1;
872 linphonec_proxy_add(lc);
874 rl_inhibit_completion=0;
877 else if (strcmp(arg1,"list")==0)
879 linphonec_proxy_list(lc);
881 else if (strcmp(arg1,"remove")==0)
883 linphonec_proxy_remove(lc,atoi(arg2));
885 else if (strcmp(arg1,"use")==0)
890 if ( linphonec_proxy_use(lc, proxynum) )
891 linphonec_out("Default proxy set to %d.\n", proxynum);
895 proxynum=linphone_core_get_default_proxy(lc, NULL);
896 if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
897 else linphonec_out("Current default proxy is %d.\n", proxynum);
899 }else if (strcmp(arg1, "unuse")==0){
900 linphone_core_set_default_proxy(lc, NULL);
901 linphonec_out("Use no proxy.\n");
904 else if (strcmp(arg1, "show")==0)
908 if (strstr(arg2,"default"))
910 proxynum=linphone_core_get_default_proxy(lc, NULL);
911 if ( proxynum < 0 ) {
912 linphonec_out("No default proxy defined\n");
915 linphonec_proxy_show(lc,proxynum);
919 linphonec_proxy_show(lc, atoi(arg2));
922 else return 0; /* syntax error */
927 return 0; /* syntax error */
934 lpc_cmd_call_logs(LinphoneCore *lc, char *args)
936 const MSList *elem=linphone_core_get_call_logs(lc);
937 for (;elem!=NULL;elem=ms_list_next(elem))
939 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
940 char *str=linphone_call_log_to_str(cl);
941 linphonec_out("%s\n",str);
948 lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
952 return 0; /* syntax error */
955 if (strcmp(arg1,"status")==0)
957 linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
959 else if (strcmp(arg1,"enable")==0)
961 linphone_core_enable_ipv6(lc,TRUE);
962 linphonec_out("ipv6 use enabled.\n");
964 else if (strcmp(arg1,"disable")==0)
966 linphone_core_enable_ipv6(lc,FALSE);
967 linphonec_out("ipv6 use disabled.\n");
971 return 0; /* syntax error */
976 static int devname_to_index(LinphoneCore *lc, const char *devname){
979 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
980 if (strcmp(devname,*p)==0) return i;
985 static const char *index_to_devname(LinphoneCore *lc, int index){
988 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
989 if (i==index) return *p;
994 static int lpc_cmd_soundcard(LinphoneCore *lc, char *args)
1002 if (!args) return 0; /* syntax error */
1004 /* Isolate first and second arg */
1005 while(*ptr && !isspace(*ptr)) ++ptr;
1010 while(*arg2 && isspace(*arg2)) ++arg2;
1013 if (strcmp(arg1, "list")==0)
1015 dev=linphone_core_get_sound_devices(lc);
1016 for(i=0; dev[i]!=NULL; ++i){
1017 linphonec_out("%i: %s\n",i,dev[i]);
1022 if (strcmp(arg1, "show")==0)
1024 linphonec_out("Ringer device: %s\n",
1025 linphone_core_get_ringer_device(lc));
1026 linphonec_out("Playback device: %s\n",
1027 linphone_core_get_playback_device(lc));
1028 linphonec_out("Capture device: %s\n",
1029 linphone_core_get_capture_device(lc));
1033 if (strcmp(arg1, "use")==0 && arg2)
1035 if (strcmp(arg2, "files")==0)
1037 linphonec_out("Using wav files instead of soundcard.\n");
1038 linphone_core_use_files(lc,TRUE);
1042 dev=linphone_core_get_sound_devices(lc);
1043 index=atoi(arg2); /* FIXME: handle not-a-number */
1044 for(i=0;dev[i]!=NULL;i++)
1046 if (i!=index) continue;
1048 linphone_core_set_ringer_device(lc,dev[i]);
1049 linphone_core_set_playback_device(lc,dev[i]);
1050 linphone_core_set_capture_device(lc,dev[i]);
1051 linphonec_out("Using sound device %s\n",dev[i]);
1054 linphonec_out("No such sound device\n");
1057 if (strcmp(arg1, "capture")==0)
1059 const char *devname=linphone_core_get_capture_device(lc);
1061 linphonec_out("Using capture device #%i (%s)\n",
1062 devname_to_index(lc,devname),devname);
1064 index=atoi(arg2); /* FIXME: handle not-a-number */
1065 devname=index_to_devname(lc,index);
1067 linphone_core_set_capture_device(lc,devname);
1068 linphonec_out("Using capture sound device %s\n",devname);
1071 linphonec_out("No such sound device\n");
1075 if (strcmp(arg1, "playback")==0)
1077 const char *devname=linphone_core_get_playback_device(lc);
1079 linphonec_out("Using playback device #%i (%s)\n",
1080 devname_to_index(lc,devname),devname);
1082 index=atoi(arg2); /* FIXME: handle not-a-number */
1083 devname=index_to_devname(lc,index);
1085 linphone_core_set_playback_device(lc,devname);
1086 linphonec_out("Using playback sound device %s\n",devname);
1089 linphonec_out("No such sound device\n");
1093 if (strcmp(arg1, "ring")==0)
1095 const char *devname=linphone_core_get_ringer_device(lc);
1097 linphonec_out("Using ring device #%i (%s)\n",
1098 devname_to_index(lc,devname),devname);
1100 index=atoi(arg2); /* FIXME: handle not-a-number */
1101 devname=index_to_devname(lc,index);
1103 linphone_core_set_ringer_device(lc,devname);
1104 linphonec_out("Using ring sound device %s\n",devname);
1107 linphonec_out("No such sound device\n");
1111 return 0; /* syntax error */
1114 static int lpc_cmd_webcam(LinphoneCore *lc, char *args)
1122 if (!args) return 0; /* syntax error */
1124 /* Isolate first and second arg */
1125 while(*ptr && !isspace(*ptr)) ++ptr;
1130 while(*arg2 && isspace(*arg2)) ++arg2;
1133 if (strcmp(arg1, "list")==0)
1135 dev=linphone_core_get_video_devices(lc);
1136 for(i=0; dev[i]!=NULL; ++i){
1137 linphonec_out("%i: %s\n",i,dev[i]);
1142 if (strcmp(arg1, "use")==0 && arg2)
1144 dev=linphone_core_get_video_devices(lc);
1145 index=atoi(arg2); /* FIXME: handle not-a-number */
1146 for(i=0;dev[i]!=NULL;i++)
1148 if (i!=index) continue;
1150 linphone_core_set_video_device(lc, dev[i]);
1151 linphonec_out("Using video device %s\n",dev[i]);
1154 linphonec_out("No such video device\n");
1157 return 0; /* syntax error */
1161 lpc_cmd_staticpic(LinphoneCore *lc, char *args)
1167 if (!args) return 0; /* Syntax error */
1169 /* Isolate first and second arg */
1170 while(*ptr && !isspace(*ptr)) ++ptr;
1175 while(*arg2 && isspace(*arg2)) ++arg2;
1178 if (strcmp(arg1, "set")==0 && arg2) {
1179 linphone_core_set_static_picture(lc, arg2);
1183 return 0; /* Syntax error */
1186 static int lpc_cmd_pause(LinphoneCore *lc, char *args){
1188 if(linphone_core_in_call(lc))
1190 linphone_core_pause_call(lc,linphone_core_get_current_call(lc));
1193 linphonec_out("you can only pause when a call is in process\n");
1197 static int lpc_cmd_resume(LinphoneCore *lc, char *args){
1199 if(linphone_core_in_call(lc))
1201 linphonec_out("There is already a call in process pause or stop it first");
1205 char the_remote_address[255];
1206 int n = sscanf(args, "%s", the_remote_address);
1209 if(linphone_core_resume_call(lc,linphone_core_get_call_by_remote_address(lc,the_remote_address)) < 0)
1211 linphonec_out("There was a problem to resume the call check the remote address you gave %s\n",args);
1223 MSList *calls = linphone_core_get_calls(lc);
1224 if(ms_list_size(calls) == 1)
1226 if(linphone_core_resume_call(lc,calls->data) < 0)
1228 linphonec_out("There was a problem to resume the unique call \n");
1235 ms_list_free(calls);
1243 /***************************************************************************
1245 * Commands helper functions
1247 ***************************************************************************/
1251 linphonec_proxy_add(LinphoneCore *lc)
1253 bool_t enable_register=FALSE;
1254 LinphoneProxyConfig *cfg;
1256 linphonec_out("Adding new proxy setup. Hit ^D to abort.\n");
1263 char *input=linphonec_readline("Enter proxy sip address: ");
1267 linphonec_out("Aborted.\n");
1272 clean=lpc_strip_blanks(input);
1278 cfg=linphone_proxy_config_new();
1279 if (linphone_proxy_config_set_server_addr(cfg,clean)<0)
1281 linphonec_out("Invalid sip address (sip:sip.domain.tld).\n");
1283 linphone_proxy_config_destroy(cfg);
1291 * SIP Proxy identity
1295 char *input=linphonec_readline("Your identity for this proxy: ");
1299 linphonec_out("Aborted.\n");
1300 linphone_proxy_config_destroy(cfg);
1305 clean=lpc_strip_blanks(input);
1311 linphone_proxy_config_set_identity(cfg, clean);
1312 if ( ! cfg->reg_identity )
1314 linphonec_out("Invalid identity (sip:name@sip.domain.tld).\n");
1323 * SIP Proxy enable register
1327 char *input=linphonec_readline("Do you want to register on this proxy (yes/no): ");
1331 linphonec_out("Aborted.\n");
1332 linphone_proxy_config_destroy(cfg);
1337 clean=lpc_strip_blanks(input);
1343 if ( ! strcmp(clean, "yes") ) enable_register=TRUE;
1344 else if ( ! strcmp(clean, "no") ) enable_register=FALSE;
1346 linphonec_out("Please answer with 'yes' or 'no'\n");
1350 linphone_proxy_config_enableregister(cfg, enable_register);
1356 * SIP Proxy registration expiration
1358 if ( enable_register==TRUE )
1363 char *input=linphonec_readline("Specify register expiration time"
1364 " in seconds (default is 600): ");
1367 linphonec_out("Aborted.\n");
1368 linphone_proxy_config_destroy(cfg);
1372 expires=strtol(input, (char **)NULL, 10);
1373 if ( expires == LONG_MIN || expires == LONG_MAX )
1375 linphonec_out("Invalid value: %s\n", strerror(errno));
1380 linphone_proxy_config_expires(cfg, expires);
1381 linphonec_out("Expiration: %d seconds\n", cfg->expires);
1393 char *input=linphonec_readline("Specify route if needed: ");
1397 linphonec_out("Aborted.\n");
1398 linphone_proxy_config_destroy(cfg);
1403 clean=lpc_strip_blanks(input);
1406 linphonec_out("No route specified.\n");
1410 linphone_proxy_config_set_route(cfg, clean);
1411 if ( ! cfg->reg_route )
1413 linphonec_out("Invalid route.\n");
1423 * Final confirmation
1430 linphonec_out("--------------------------------------------\n");
1431 linphonec_proxy_display(cfg);
1432 linphonec_out("--------------------------------------------\n");
1433 input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: ");
1437 linphonec_out("Aborted.\n");
1438 linphone_proxy_config_destroy(cfg);
1443 clean=lpc_strip_blanks(input);
1449 if ( ! strcmp(clean, "yes") ) break;
1450 else if ( ! strcmp(clean, "no") )
1452 linphonec_out("Declined.\n");
1453 linphone_proxy_config_destroy(cfg);
1458 linphonec_out("Please answer with 'yes' or 'no'\n");
1464 linphone_core_add_proxy_config(lc,cfg);
1466 /* automatically set the last entered proxy as the default one */
1467 linphone_core_set_default_proxy(lc,cfg);
1469 linphonec_out("Proxy added.\n");
1473 linphonec_proxy_display(LinphoneProxyConfig *cfg)
1475 linphonec_out("sip address: %s\nroute: %s\nidentity: %s\nregister: %s\nexpires: %i\nregistered: %s\n",
1477 (cfg->reg_route!=NULL)?cfg->reg_route:"",
1478 (cfg->reg_identity!=NULL)?cfg->reg_identity:"",
1479 (cfg->reg_sendregister)?"yes":"no",
1481 linphone_proxy_config_is_registered(cfg) ? "yes" : "no");
1484 static void linphonec_proxy_show(LinphoneCore *lc, int index)
1488 for(elem=linphone_core_get_proxy_config_list(lc),i=0;elem!=NULL;elem=elem->next,++i){
1490 LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)elem->data;
1491 linphonec_proxy_display(cfg);
1495 linphonec_out("No proxy with index %i\n", index);
1499 linphonec_proxy_list(LinphoneCore *lc)
1501 const MSList *proxies;
1503 int def=linphone_core_get_default_proxy(lc,NULL);
1505 proxies=linphone_core_get_proxy_config_list(lc);
1506 for(n=0;proxies!=NULL;proxies=ms_list_next(proxies),n++){
1508 linphonec_out("****** Proxy %i - this is the default one - *******\n",n);
1510 linphonec_out("****** Proxy %i *******\n",n);
1511 linphonec_proxy_display((LinphoneProxyConfig*)proxies->data);
1513 if ( ! n ) linphonec_out("No proxies defined\n");
1517 linphonec_proxy_remove(LinphoneCore *lc, int index)
1519 const MSList *proxies;
1520 LinphoneProxyConfig *cfg;
1521 proxies=linphone_core_get_proxy_config_list(lc);
1522 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1524 linphonec_out("No such proxy.\n");
1527 linphone_core_remove_proxy_config(lc,cfg);
1528 linphonec_out("Proxy %s removed.\n", cfg->reg_proxy);
1529 linphone_proxy_config_destroy(cfg);
1533 linphonec_proxy_use(LinphoneCore *lc, int index)
1535 const MSList *proxies;
1536 LinphoneProxyConfig *cfg;
1537 proxies=linphone_core_get_proxy_config_list(lc);
1538 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1540 linphonec_out("No such proxy (try 'proxy list').");
1543 linphone_core_set_default_proxy(lc,cfg);
1548 linphonec_friend_display(LinphoneFriend *fr)
1550 LinphoneAddress *uri=linphone_address_clone(linphone_friend_get_address(fr));
1553 linphonec_out("name: %s\n", linphone_address_get_display_name(uri));
1554 linphone_address_set_display_name(uri,NULL);
1555 str=linphone_address_as_string(uri);
1556 linphonec_out("address: %s\n", str);
1560 linphonec_friend_list(LinphoneCore *lc, char *pat)
1562 const MSList *friend;
1566 pat=lpc_strip_blanks(pat);
1567 if (!*pat) pat = NULL;
1570 friend = linphone_core_get_friend_list(lc);
1571 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1574 const char *name = linphone_address_get_display_name(
1575 linphone_friend_get_address((LinphoneFriend*)friend->data));
1576 if (name && ! strstr(name, pat) ) continue;
1578 linphonec_out("****** Friend %i *******\n",n);
1579 linphonec_friend_display((LinphoneFriend*)friend->data);
1586 linphonec_friend_call(LinphoneCore *lc, unsigned int num)
1588 const MSList *friend = linphone_core_get_friend_list(lc);
1592 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1597 addr = linphone_address_as_string(linphone_friend_get_address((LinphoneFriend*)friend->data));
1598 ret=lpc_cmd_call(lc, addr);
1603 linphonec_out("No such friend %u\n", num);
1609 linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr)
1611 LinphoneFriend *newFriend;
1615 snprintf(url, PATH_MAX, "%s <%s>", name, addr);
1616 newFriend = linphone_friend_new_with_addr(url);
1617 linphone_core_add_friend(lc, newFriend);
1623 linphonec_friend_delete(LinphoneCore *lc, int num)
1625 const MSList *friend = linphone_core_get_friend_list(lc);
1628 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1632 linphone_core_remove_friend(lc, friend->data);
1640 for (i = 0 ; i < n ; i++)
1641 linphonec_friend_delete(lc, 0);
1645 linphonec_out("No such friend %u\n", num);
1650 linphonec_display_command_help(LPC_COMMAND *cmd)
1652 if ( cmd->doc ) linphonec_out ("%s\n", cmd->doc);
1653 else linphonec_out("%s\n", cmd->help);
1657 static int lpc_cmd_register(LinphoneCore *lc, char *args){
1661 LinphoneProxyConfig *cfg;
1666 /* it means that you want to register the default proxy */
1667 LinphoneProxyConfig *cfg=NULL;
1668 linphone_core_get_default_proxy(lc,&cfg);
1671 if(!linphone_proxy_config_is_registered(cfg)) {
1672 linphone_proxy_config_enable_register(cfg,TRUE);
1673 linphone_proxy_config_done(cfg);
1675 linphonec_out("default proxy already registered\n");
1678 linphonec_out("we do not have a default proxy\n");
1683 passwd[0]=proxy[0]=identity[0]='\0';
1684 sscanf(args,"%s %s %s",identity,proxy,passwd);
1685 if (proxy[0]=='\0' || identity[0]=='\0'){
1686 linphonec_out("Missing parameters, see help register\n");
1689 if (passwd[0]!='\0'){
1690 LinphoneAddress *from;
1691 LinphoneAuthInfo *info;
1692 if ((from=linphone_address_new(identity))!=NULL){
1694 snprintf(realm,sizeof(realm)-1,"\"%s\"",linphone_address_get_domain(from));
1695 info=linphone_auth_info_new(linphone_address_get_username(from),NULL,passwd,NULL,NULL);
1696 linphone_core_add_auth_info(lc,info);
1697 linphone_address_destroy(from);
1698 linphone_auth_info_destroy(info);
1701 elem=linphone_core_get_proxy_config_list(lc);
1703 cfg=(LinphoneProxyConfig*)elem->data;
1704 linphone_proxy_config_edit(cfg);
1706 else cfg=linphone_proxy_config_new();
1707 linphone_proxy_config_set_identity(cfg,identity);
1708 linphone_proxy_config_set_server_addr(cfg,proxy);
1709 linphone_proxy_config_enable_register(cfg,TRUE);
1710 if (elem) linphone_proxy_config_done(cfg);
1711 else linphone_core_add_proxy_config(lc,cfg);
1712 linphone_core_set_default_proxy(lc,cfg);
1716 static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
1717 LinphoneProxyConfig *cfg=NULL;
1718 linphone_core_get_default_proxy(lc,&cfg);
1719 if (cfg && linphone_proxy_config_is_registered(cfg)) {
1720 linphone_proxy_config_edit(cfg);
1721 linphone_proxy_config_enable_register(cfg,FALSE);
1722 linphone_proxy_config_done(cfg);
1724 linphonec_out("unregistered\n");
1729 static int lpc_cmd_duration(LinphoneCore *lc, char *args){
1730 LinphoneCallLog *cl;
1731 const MSList *elem=linphone_core_get_call_logs(lc);
1732 for(;elem!=NULL;elem=elem->next){
1733 if (elem->next==NULL){
1734 cl=(LinphoneCallLog*)elem->data;
1735 linphonec_out("%i seconds\n",cl->duration);
1741 static int lpc_cmd_status(LinphoneCore *lc, char *args)
1743 LinphoneProxyConfig *cfg;
1745 if ( ! args ) return 0;
1746 linphone_core_get_default_proxy(lc,&cfg);
1747 if (strstr(args,"register"))
1751 if (linphone_proxy_config_is_registered(cfg)){
1752 linphonec_out("registered, identity=%s duration=%i\n",
1753 linphone_proxy_config_get_identity(cfg),
1754 linphone_proxy_config_get_expires(cfg));
1755 }else if (linphone_proxy_config_register_enabled(cfg)){
1756 linphonec_out("registered=-1\n");
1757 }else linphonec_out("registered=0\n");
1759 else linphonec_out("registered=0\n");
1761 else if (strstr(args,"autoanswer"))
1763 if (cfg && linphone_proxy_config_is_registered(cfg))
1764 linphonec_out("autoanswer=%i\n",linphonec_get_autoanswer());
1765 else linphonec_out("unregistered\n");
1767 else if (strstr(args,"hook"))
1769 gstate_t call_state=linphone_core_get_state(lc,GSTATE_GROUP_CALL);
1771 if (!cfg || !linphone_proxy_config_is_registered(cfg)){
1772 linphonec_out("unregistered\n");
1777 case GSTATE_CALL_OUT_INVITE:
1778 linphonec_out("hook=dialing\n");
1780 case GSTATE_CALL_IDLE:
1781 linphonec_out("hook=offhook\n");
1783 case GSTATE_CALL_OUT_CONNECTED:
1784 linphonec_out("Call out, hook=%s duration=%i, muted=%s rtp-xmit-muted=%s\n", linphonec_get_callee(),
1785 linphone_core_get_current_call_duration(lc),
1786 lc->audio_muted ? "yes" : "no",
1787 linphone_core_is_rtp_muted(lc) ? "yes" : "no");
1789 case GSTATE_CALL_IN_CONNECTED:
1790 linphonec_out("hook=answered duration=%i\n" ,
1791 linphone_core_get_current_call_duration(lc));
1793 case GSTATE_CALL_IN_INVITE:
1794 linphonec_out("Incoming call from %s\n",linphonec_get_caller());
1806 static int lpc_cmd_ports(LinphoneCore *lc, char *args)
1810 linphonec_out("sip port = %i\naudio rtp port = %i\nvideo rtp port = %i\n",
1811 linphone_core_get_sip_port(lc),
1812 linphone_core_get_audio_port(lc),
1813 linphone_core_get_video_port(lc));
1816 if (sscanf(args,"sip %i",&port)==1){
1817 linphonec_out("Setting sip port to %i\n",port);
1818 linphone_core_set_sip_port(lc,port);
1824 static int lpc_cmd_speak(LinphoneCore *lc, char *args){
1833 if (!args) return 0;
1834 memset(voice,0,sizeof(voice));
1835 sscanf(args,"%s63",voice);
1836 sentence=args+strlen(voice);
1837 wavfile=tempnam("/tmp/","linphonec-espeak-");
1838 snprintf(cl,sizeof(cl),"espeak -v %s -s 100 -w %s --stdin",voice,wavfile);
1841 ms_error("Could not open pipe to espeak !");
1844 fprintf(file,"%s",sentence);
1845 status=pclose(file);
1846 if (WEXITSTATUS(status)==0){
1847 linphone_core_set_play_file(lc,wavfile);
1849 linphonec_out("espeak command failed.");
1852 linphonec_out("Sorry, this command is not implemented in windows version.");
1857 static int lpc_cmd_codec(LinphoneCore *lc, char *args){
1862 if (!args) return 0;
1864 /* Isolate first and second arg */
1865 while(*ptr && !isspace(*ptr)) ++ptr;
1870 while(*arg2 && isspace(*arg2)) ++arg2;
1873 if (strcmp(arg1,"enable")==0)
1875 #ifdef HAVE_READLINE
1876 rl_inhibit_completion=1;
1878 if (!strcmp(arg2,"all")) linphonec_codec_enable(lc,-1);
1879 else linphonec_codec_enable(lc,atoi(arg2));
1880 #ifdef HAVE_READLINE
1881 rl_inhibit_completion=0;
1884 else if (strcmp(arg1,"list")==0)
1886 linphonec_codec_list(lc);
1888 else if (strcmp(arg1,"disable")==0)
1890 if (!strcmp(arg2,"all")) linphonec_codec_disable(lc,-1);
1891 else linphonec_codec_disable(lc,atoi(arg2));
1895 return 0; /* syntax error */
1901 static void linphonec_codec_list(LinphoneCore *lc){
1903 codecs_config_t *config=&lc->codecs_conf;
1906 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
1907 pt=(PayloadType*)(node->data);
1908 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate,
1909 linphone_core_payload_type_enabled(lc,pt) ? "enabled" : "disabled");
1914 static void linphonec_codec_enable(LinphoneCore *lc, int sel_index){
1916 codecs_config_t *config=&lc->codecs_conf;
1919 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
1920 if (index == sel_index || sel_index == -1) {
1921 pt=(PayloadType*)(node->data);
1922 pt->flags|=PAYLOAD_TYPE_ENABLED;
1923 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "enabled");
1929 static void linphonec_codec_disable(LinphoneCore *lc, int sel_index){
1931 codecs_config_t *config=&lc->codecs_conf;
1934 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
1935 if (index == sel_index || sel_index == -1) {
1936 pt=(PayloadType*)(node->data);
1937 pt->flags&=~PAYLOAD_TYPE_ENABLED;
1938 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "disabled");
1944 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){
1949 if (!args) return 0;
1951 /* Isolate first and second arg */
1952 while(*ptr && !isspace(*ptr)) ++ptr;
1957 while(*arg2 && isspace(*arg2)) ++arg2;
1960 if (strcmp(arg1,"on")==0){
1961 int delay, tail_len, frame_size;
1964 linphone_core_enable_echo_cancellation(lc,1);
1967 n = sscanf(arg2, "%d %d %d", &delay, &tail_len, &frame_size);
1970 lp_config_set_int(lc->config,"sound","ec_delay",delay);
1973 lp_config_set_int(lc->config,"sound","ec_delay",delay);
1974 lp_config_set_int(lc->config,"sound","ec_tail_len",tail_len);
1977 lp_config_set_int(lc->config,"sound","ec_delay",delay);
1978 lp_config_set_int(lc->config,"sound","ec_tail_len",tail_len);
1979 lp_config_set_int(lc->config,"sound","ec_framesize",frame_size);
1983 else if (strcmp(arg1,"off")==0){
1984 linphone_core_enable_echo_cancellation(lc,0);
1986 else if (strcmp(arg1,"show")==0){
1987 linphonec_out("echo cancellation is %s; delay %d, tail length %d, frame size %d\n",
1988 linphone_core_echo_cancellation_enabled(lc) ? "on" : "off",
1989 lp_config_get_int(lc->config,"sound","ec_delay",0),
1990 lp_config_get_int(lc->config,"sound","ec_tail_len",0),
1991 lp_config_get_int(lc->config,"sound","ec_framesize",0));
2000 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args)
2002 linphone_core_mute_mic(lc, 1);
2006 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args){
2007 linphone_core_mute_mic(lc, 0);
2011 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args)
2013 bool_t rtp_xmit_off=FALSE;
2015 gstate_t call_state=linphone_core_get_state(lc,GSTATE_GROUP_CALL);
2018 if(strstr(args,"1"))rtp_xmit_off=TRUE;
2019 if(call_state == GSTATE_CALL_IDLE)
2020 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_xmit_off);
2022 linphonec_out("nortp-on-audio-mute: call in progress - cannot change state\n");
2024 rtp_xmit_off=linphone_core_get_rtp_no_xmit_on_audio_mute(lc);
2025 if(rtp_xmit_off)status="off";
2027 linphonec_out("rtp transmit %s when audio muted\n",status);
2032 /***************************************************************************
2034 * Command table management funx
2036 ***************************************************************************/
2039 * Find a command given its name
2041 static LPC_COMMAND *
2042 lpc_find_command(const char *name)
2046 for (i=0; commands[i].name; ++i)
2048 if (strcmp(name, commands[i].name) == 0)
2049 return &commands[i];
2052 return (LPC_COMMAND *)NULL;
2056 /****************************************************************************
2058 * $Log: commands.c,v $
2059 * Revision 1.39 2008/07/03 15:08:34 smorlat
2060 * api cleanups, interface in progress.
2062 * Revision 1.38 2008/06/17 20:38:59 smorlat
2063 * added missing file.
2065 * Revision 1.37 2008/04/09 09:26:00 smorlat
2066 * merge various patches
2069 * Revision 1.36 2007/08/01 14:47:53 strk
2070 * * console/commands.c: Clean up commands 'nat', 'stun'
2071 * and 'firewall' to be more intuitive.
2073 * Revision 1.35 2007/06/27 09:01:25 smorlat
2074 * logging improvements.
2076 * Revision 1.34 2007/02/20 10:17:13 smorlat
2077 * linphonec friends patch2
2079 * Revision 1.31 2006/09/22 07:22:47 smorlat
2080 * linphonecore api changes.
2082 * Revision 1.30 2006/09/08 15:32:57 smorlat
2083 * support for using files instead of soundcard (used by linphonec only)
2085 * Revision 1.29 2006/08/28 14:29:07 smorlat
2088 * Revision 1.28 2006/08/21 12:49:59 smorlat
2089 * merged several little patches.
2091 * Revision 1.27 2006/07/17 18:45:00 smorlat
2092 * support for several event queues in ortp.
2093 * glib dependency removed from coreapi/ and console/
2095 * Revision 1.26 2006/04/14 15:16:36 smorlat
2096 * soundcard use did nothing !
2098 * Revision 1.25 2006/04/06 20:09:33 smorlat
2099 * add linphonec command to see and select sound devices.
2101 * Revision 1.24 2006/03/04 11:17:10 smorlat
2102 * mediastreamer2 in progress.
2104 * Revision 1.23 2006/02/20 21:14:01 strk
2105 * Handled syntax errors with 'friend' command
2107 * Revision 1.22 2006/02/20 10:20:29 strk
2108 * Added substring-based filter support for command 'friend list'
2110 * Revision 1.21 2006/02/02 15:39:18 strk
2111 * - Added 'friend list' and 'friend call' commands
2112 * - Allowed for multiple DTFM send in a single line
2113 * - Added status-specific callback (bare version)
2115 * Revision 1.20 2006/01/26 11:54:34 strk
2116 * More robust 'nat' command handler (strip blanks in args)
2118 * Revision 1.19 2006/01/26 09:48:05 strk
2119 * Added limits.h include
2121 * Revision 1.18 2006/01/26 02:18:05 strk
2122 * Added new commands 'nat use' and 'nat unuse'.
2123 * These will required a pending patch to linphonecore.c
2126 * Revision 1.17 2006/01/20 14:12:33 strk
2127 * Added linphonec_init() and linphonec_finish() functions.
2128 * Handled SIGINT and SIGTERM to invoke linphonec_finish().
2129 * Handling of auto-termination (-t) moved to linphonec_finish().
2130 * Reworked main (input read) loop to not rely on 'terminate'
2131 * and 'run' variable (dropped). configfile_name allocated on stack
2132 * using PATH_MAX limit. Changed print_usage signature to allow
2133 * for an exit_status specification.
2135 * Revision 1.16 2006/01/18 09:25:32 strk
2136 * Command completion inhibited in proxy addition and auth request prompts.
2137 * Avoided use of linphonec_readline's internal filename completion.
2139 * Revision 1.15 2006/01/14 13:29:32 strk
2140 * Reworked commands interface to use a table structure,
2141 * used by command line parser and help function.
2142 * Implemented first level of completion (commands).
2143 * Added notification of invalid "answer" and "terminate"
2144 * commands (no incoming call, no active call).
2145 * Forbidden "call" intialization when a call is already active.
2146 * Cleaned up all commands, adding more feedback and error checks.
2148 * Revision 1.14 2006/01/13 13:00:29 strk
2149 * Added linphonec.h. Code layout change (added comments, forward decl,
2150 * globals on top, copyright notices and Logs). Handled out-of-memory
2151 * condition on history management. Removed assumption on sizeof(char).
2152 * Fixed bug in authentication prompt (introduced by linphonec_readline).
2153 * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
2156 ****************************************************************************/