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"
47 /***************************************************************************
49 * Forward declarations
51 ***************************************************************************/
53 extern char *lpc_strip_blanks(char *input);
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);
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);
105 static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
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);
115 /* Command table management */
116 static LPC_COMMAND *lpc_find_command(const char *name);
118 void linphonec_out(const char *fmt,...);
122 /***************************************************************************
126 ***************************************************************************/
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"
137 { "calls", lpc_cmd_calls, "Show all the current calls with their id and status.\n",
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."
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"
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"
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"
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"
172 { "webcam", lpc_cmd_webcam, "Manage webcams",
173 "'webcam list' : list all known devices.\n"
174 "'webcam use <index>' : select a video device.\n"
176 { "staticpic", lpc_cmd_staticpic, "Manage static pictures when nowebcam",
177 "'staticpic set' : Set path to picture that should be used.\n"
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."
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"
189 { "nat", lpc_cmd_nat, "Set nat address",
190 "'nat' : show nat settings.\n"
191 "'nat <addr>' : set nat address.\n"
193 { "stun", lpc_cmd_stun, "Set stun server address",
194 "'stun' : show stun settings.\n"
195 "'stun <addr>' : set stun server address.\n"
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"
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"
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."
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."
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 !'"
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 }
264 /***************************************************************************
268 ***************************************************************************/
271 * Main command dispatcher.
272 * WARNING: modifies second argument!
274 * Always return 1 currently.
277 linphonec_parse_command_line(LinphoneCore *lc, char *cl)
283 /* Isolate first word and args */
284 while(*ptr && !isspace(*ptr)) ++ptr;
288 /* set args to first nonblank */
290 while(*args && isspace(*args)) ++args;
294 if ( isdigit(*cl) || *cl == '#' || *cl == '*' )
296 while ( isdigit(*cl) || *cl == '#' || *cl == '*' )
298 linphone_core_send_dtmf(lc, *cl);
299 linphone_core_play_dtmf (lc,*cl,100);
300 ms_sleep(1); // be nice
304 // discard spurious trailing chars
308 /* Handle other kind of commands */
309 cmd=lpc_find_command(cl);
312 linphonec_out("'%s': Cannot understand this.\n", cl);
316 if ( ! cmd->func(lc, args) )
318 linphonec_out("Syntax error.\n");
319 linphonec_display_command_help(cmd);
326 * Generator function for command completion.
327 * STATE let us know whether to start from scratch;
328 * without any state (STATE==0), then we start at the
332 linphonec_command_generator(const char *text, int state)
334 static int index, len;
344 * Return the next name which partially matches
345 * from the commands list
347 while ((name=commands[index].name))
349 ++index; /* so next call get next command */
351 if (strncmp(name, text, len) == 0)
353 return ortp_strdup(name);
361 /***************************************************************************
365 ***************************************************************************/
368 lpc_cmd_help(LinphoneCore *lc, char *arg)
375 linphonec_out("Commands are:\n");
376 linphonec_out("---------------------------\n");
378 while (commands[i].help)
380 linphonec_out("%10.10s\t%s\n", commands[i].name,
385 linphonec_out("---------------------------\n");
386 linphonec_out("Type 'help <command>' for more details.\n");
391 cmd=lpc_find_command(arg);
394 linphonec_out("No such command.\n");
398 linphonec_display_command_help(cmd);
403 static char callee_name[256]={0};
404 static char caller_name[256]={0};
406 static const char *get_call_status(LinphoneCall *call){
407 switch(linphone_call_get_state(call)){
408 case LinphoneCallPaused:
409 if (linphone_call_get_refer_to (call)!=NULL){
410 return "Paused (transfered)";
415 case LinphoneCallIncomingReceived:
418 case LinphoneCallOutgoingInit:
419 case LinphoneCallOutgoingProgress:
420 return "Dialing out";
422 case LinphoneCallOutgoingEarlyMedia:
423 case LinphoneCallOutgoingRinging:
424 return "Remote ringing";
427 if (linphone_call_has_transfer_pending(call)){
428 return "Running (transfer pending)";
436 lpc_cmd_call(LinphoneCore *lc, char *args)
438 if ( ! args || ! *args )
444 if ( linphone_core_in_call(lc) )
446 linphonec_out("Terminate or hold on the current call first.\n");
449 if ( NULL == (call=linphone_core_invite(lc, args)) )
451 linphonec_out("Error from linphone_core_invite.\n");
455 snprintf(callee_name,sizeof(callee_name),"%s",args);
462 lpc_cmd_calls(LinphoneCore *lc, char *args){
463 const MSList *calls = linphone_core_get_calls(lc);
466 const MSList *p_calls = calls;
467 linphonec_out("ID\t\tDestination\t\t\t\tStatus\n---------------------------------------------------------------------\n");
468 while(p_calls != NULL)
470 LinphoneCall *call=(LinphoneCall*)p_calls->data;
471 char *tmp=linphone_call_get_remote_address_as_string(call);
472 linphonec_out("%li\t%s\t\t\t%s\r\n",
473 (long)linphone_call_get_user_pointer (call),
475 get_call_status(call));
476 p_calls = p_calls->next;
481 linphonec_out("No active call.\n");
488 lpc_cmd_chat(LinphoneCore *lc, char *args)
496 /* Isolate first and second arg */
497 while(*ptr && !isspace(*ptr)) ++ptr;
502 while(*arg2 && isspace(*arg2)) ++arg2;
506 /* missing one parameter */
509 LinphoneChatRoom *cr = linphone_core_create_chat_room(lc,arg1);
510 linphone_chat_room_send_message(cr,arg2);
511 linphone_chat_room_destroy(cr);
516 const char *linphonec_get_callee(){
520 const char *linphonec_get_caller(){
524 void linphonec_set_caller(const char *caller){
525 snprintf(caller_name,sizeof(caller_name)-1,"%s",caller);
529 lpc_cmd_transfer(LinphoneCore *lc, char *args)
533 const char *refer_to=NULL;
536 int n=sscanf(args,"%s %s",arg1,arg2);
537 if (n==1 || isalpha(*arg1)){
538 call=linphone_core_get_current_call(lc);
539 if (call==NULL && linphone_core_get_calls_nb (lc)==1){
540 call=(LinphoneCall*)linphone_core_get_calls(lc)->data;
544 linphonec_out("No active call, please specify a call id among the ones listed by 'calls' command.\n");
549 refer_to=args+strlen(arg1)+1;
550 call=linphonec_get_call(id);
551 if (call==NULL) return 0;
553 linphone_core_transfer_call(lc, call, refer_to);
555 linphonec_out("Transfer command requires at least one argument\n");
562 lpc_cmd_terminate(LinphoneCore *lc, char *args)
564 if (linphone_core_get_calls(lc)==NULL){
565 linphonec_out("No active calls");
570 if ( -1 == linphone_core_terminate_call(lc, NULL) ){
571 linphonec_out("Could not stop the active call.\n");
576 if(strcmp(args,"all")==0){
577 linphonec_out("We are going to stop all the calls.\n");
578 linphone_core_terminate_all_calls(lc);
581 /*the argument is a linphonec call id */
583 LinphoneCall *call=linphonec_get_call(id);
585 if (linphone_core_terminate_call(lc,call)==-1){
586 linphonec_out("Could not stop the call with id %li",id);
596 lpc_cmd_answer(LinphoneCore *lc, char *args){
599 int nb=ms_list_size(linphone_core_get_calls(lc));
601 //if just one call is present answer the only one in passing NULL to the linphone_core_accept_call ...
602 if ( -1 == linphone_core_accept_call(lc, NULL) )
604 linphonec_out("Fail to accept incoming call\n");
607 linphonec_out("There are no calls to answer.\n");
609 linphonec_out("Multiple calls in progress, please specify call id.\n");
615 if (sscanf(args,"%li",&id)==1){
616 LinphoneCall *call=linphonec_get_call (id);
617 if (linphone_core_accept_call (lc,call)==-1){
618 linphonec_out("Fail to accept call %i\n",id);
627 lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
631 if ( linphonec_get_autoanswer() ) {
632 linphonec_out("Auto answer is enabled. Use 'autoanswer disable' to disable.\n");
634 linphonec_out("Auto answer is disabled. Use 'autoanswer enable' to enable.\n");
639 if (strstr(args,"enable")){
640 linphonec_set_autoanswer(TRUE);
641 linphonec_out("Auto answer enabled.\n");
642 }else if (strstr(args,"disable")){
643 linphonec_set_autoanswer(FALSE);
644 linphonec_out("Auto answer disabled.\n");
650 lpc_cmd_quit(LinphoneCore *lc, char *args)
652 linphonec_main_loop_exit();
657 lpc_cmd_nat(LinphoneCore *lc, char *args)
662 if ( args ) args=lpc_strip_blanks(args);
666 linphone_core_set_nat_address(lc, args);
667 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS); */
670 nat = linphone_core_get_nat_address(lc);
671 use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress;
672 linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
678 lpc_cmd_stun(LinphoneCore *lc, char *args)
683 if ( args ) args=lpc_strip_blanks(args);
687 linphone_core_set_stun_server(lc, args);
688 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN); */
691 stun = linphone_core_get_stun_server(lc);
692 use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseStun;
693 linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
699 lpc_cmd_firewall(LinphoneCore *lc, char *args)
701 const char* setting=NULL;
703 if ( args ) args=lpc_strip_blanks(args);
707 if (strcmp(args,"none")==0)
709 linphone_core_set_firewall_policy(lc,LinphonePolicyNoFirewall);
711 else if (strcmp(args,"stun")==0)
713 setting = linphone_core_get_stun_server(lc);
716 linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
719 linphone_core_set_firewall_policy(lc,LinphonePolicyUseStun);
721 else if (strcmp(args,"nat")==0)
723 setting = linphone_core_get_nat_address(lc);
726 linphonec_out("No nat address is defined, use 'nat <address>' first");
729 linphone_core_set_firewall_policy(lc,LinphonePolicyUseNatAddress);
733 switch(linphone_core_get_firewall_policy(lc))
735 case LinphonePolicyNoFirewall:
736 linphonec_out("No firewall\n");
738 case LinphonePolicyUseStun:
739 linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
741 case LinphonePolicyUseNatAddress:
742 linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
749 /* Helper function for processing freind names */
751 lpc_friend_name(char **args, char **name)
753 /* Use space as a terminator unless quoted */
754 if (('"' == **args) || ('\'' == **args)){
759 while ((delim != *end) && ('\0' != *end)) end++;
761 fprintf(stderr, "Mismatched quotes\n");
768 *name = strsep(args, " ");
770 if (NULL == *args) { /* Means there was no separator */
771 fprintf(stderr, "Either name or address is missing\n");
774 if (NULL == *name) return 0;
781 lpc_cmd_friend(LinphoneCore *lc, char *args)
785 if ( args ) args=lpc_strip_blanks(args);
787 if ( ! args || ! *args ) return 0;
789 if ( !strncmp(args, "list", 4) )
791 return linphonec_friend_list(lc, args+4);
794 else if ( !strncmp(args, "call", 4) )
797 if ( ! *args ) return 0;
798 friend_num = strtol(args, NULL, 10);
800 if ( errno == ERANGE ) {
801 linphonec_out("Invalid friend number\n");
804 #endif /*_WIN32_WCE*/
805 linphonec_friend_call(lc, friend_num);
808 else if ( !strncmp(args, "delete", 6) )
811 if ( ! *args ) return 0;
812 while (*args == ' ') args++;
813 if ( ! *args ) return 0;
814 if (!strncmp(args, "all", 3))
820 friend_num = strtol(args, NULL, 10);
822 if ( errno == ERANGE ) {
823 linphonec_out("Invalid friend number\n");
826 #endif /*_WIN32_WCE*/
828 linphonec_friend_delete(lc, friend_num);
831 else if ( !strncmp(args, "add", 3) )
840 if ( ! *args ) return 0;
841 while (*args == ' ') args++;
842 if ( ! *args ) return 0;
844 if (!lpc_friend_name(&args, &name)) return 0;
846 while (*args == ' ') args++;
847 if ( ! *args ) return 0;
848 if (isdigit(*args)) {
849 strcpy (addr, "sip:");
850 addr_p = addr + strlen("sip:");
852 addr_orig = strsep(&args, " ");
853 if (1 >= strlen(addr_orig)) {
854 fprintf(stderr, "A single-digit address is not valid\n");
857 strcpy(addr_p, addr_orig);
858 linphonec_friend_add(lc, name, addr);
860 LinphoneFriend *new_friend;
861 new_friend = linphone_friend_new_with_addr(args);
862 linphone_core_add_friend(lc, new_friend);
869 static int lpc_cmd_play(LinphoneCore *lc, char *args){
870 if ( args ) args=lpc_strip_blanks(args);
871 if ( ! args || ! *args ) return 0;
872 linphone_core_set_play_file(lc,args);
876 static int lpc_cmd_record(LinphoneCore *lc, char *args){
877 if ( args ) args=lpc_strip_blanks(args);
878 if ( ! args || ! *args ) return 0;
879 linphone_core_set_record_file(lc,args);
887 lpc_cmd_proxy(LinphoneCore *lc, char *args)
894 if ( ! arg1 ) return 0;
896 /* Isolate first and second arg */
897 while(*ptr && !isspace(*ptr)) ++ptr;
902 while(*arg2 && isspace(*arg2)) ++arg2;
905 if (strcmp(arg1,"add")==0)
908 rl_inhibit_completion=1;
910 linphonec_proxy_add(lc);
912 rl_inhibit_completion=0;
915 else if (strcmp(arg1,"list")==0)
917 linphonec_proxy_list(lc);
919 else if (strcmp(arg1,"remove")==0)
921 linphonec_proxy_remove(lc,atoi(arg2));
923 else if (strcmp(arg1,"use")==0)
928 if ( linphonec_proxy_use(lc, proxynum) )
929 linphonec_out("Default proxy set to %d.\n", proxynum);
933 proxynum=linphone_core_get_default_proxy(lc, NULL);
934 if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
935 else linphonec_out("Current default proxy is %d.\n", proxynum);
937 }else if (strcmp(arg1, "unuse")==0){
938 linphone_core_set_default_proxy(lc, NULL);
939 linphonec_out("Use no proxy.\n");
942 else if (strcmp(arg1, "show")==0)
946 if (strstr(arg2,"default"))
948 proxynum=linphone_core_get_default_proxy(lc, NULL);
949 if ( proxynum < 0 ) {
950 linphonec_out("No default proxy defined\n");
953 linphonec_proxy_show(lc,proxynum);
957 linphonec_proxy_show(lc, atoi(arg2));
960 else return 0; /* syntax error */
965 return 0; /* syntax error */
972 lpc_cmd_call_logs(LinphoneCore *lc, char *args)
974 const MSList *elem=linphone_core_get_call_logs(lc);
975 for (;elem!=NULL;elem=ms_list_next(elem))
977 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
978 char *str=linphone_call_log_to_str(cl);
979 linphonec_out("%s\n",str);
986 lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
990 return 0; /* syntax error */
993 if (strcmp(arg1,"status")==0)
995 linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
997 else if (strcmp(arg1,"enable")==0)
999 linphone_core_enable_ipv6(lc,TRUE);
1000 linphonec_out("ipv6 use enabled.\n");
1002 else if (strcmp(arg1,"disable")==0)
1004 linphone_core_enable_ipv6(lc,FALSE);
1005 linphonec_out("ipv6 use disabled.\n");
1009 return 0; /* syntax error */
1014 static int devname_to_index(LinphoneCore *lc, const char *devname){
1017 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1018 if (strcmp(devname,*p)==0) return i;
1023 static const char *index_to_devname(LinphoneCore *lc, int index){
1026 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1027 if (i==index) return *p;
1032 static int lpc_cmd_soundcard(LinphoneCore *lc, char *args)
1040 if (!args) return 0; /* syntax error */
1042 /* Isolate first and second arg */
1043 while(*ptr && !isspace(*ptr)) ++ptr;
1048 while(*arg2 && isspace(*arg2)) ++arg2;
1051 if (strcmp(arg1, "list")==0)
1053 dev=linphone_core_get_sound_devices(lc);
1054 for(i=0; dev[i]!=NULL; ++i){
1055 linphonec_out("%i: %s\n",i,dev[i]);
1060 if (strcmp(arg1, "show")==0)
1062 linphonec_out("Ringer device: %s\n",
1063 linphone_core_get_ringer_device(lc));
1064 linphonec_out("Playback device: %s\n",
1065 linphone_core_get_playback_device(lc));
1066 linphonec_out("Capture device: %s\n",
1067 linphone_core_get_capture_device(lc));
1071 if (strcmp(arg1, "use")==0 && arg2)
1073 if (strcmp(arg2, "files")==0)
1075 linphonec_out("Using wav files instead of soundcard.\n");
1076 linphone_core_use_files(lc,TRUE);
1080 dev=linphone_core_get_sound_devices(lc);
1081 index=atoi(arg2); /* FIXME: handle not-a-number */
1082 for(i=0;dev[i]!=NULL;i++)
1084 if (i!=index) continue;
1086 linphone_core_set_ringer_device(lc,dev[i]);
1087 linphone_core_set_playback_device(lc,dev[i]);
1088 linphone_core_set_capture_device(lc,dev[i]);
1089 linphonec_out("Using sound device %s\n",dev[i]);
1092 linphonec_out("No such sound device\n");
1095 if (strcmp(arg1, "capture")==0)
1097 const char *devname=linphone_core_get_capture_device(lc);
1099 linphonec_out("Using capture device #%i (%s)\n",
1100 devname_to_index(lc,devname),devname);
1102 index=atoi(arg2); /* FIXME: handle not-a-number */
1103 devname=index_to_devname(lc,index);
1105 linphone_core_set_capture_device(lc,devname);
1106 linphonec_out("Using capture sound device %s\n",devname);
1109 linphonec_out("No such sound device\n");
1113 if (strcmp(arg1, "playback")==0)
1115 const char *devname=linphone_core_get_playback_device(lc);
1117 linphonec_out("Using playback device #%i (%s)\n",
1118 devname_to_index(lc,devname),devname);
1120 index=atoi(arg2); /* FIXME: handle not-a-number */
1121 devname=index_to_devname(lc,index);
1123 linphone_core_set_playback_device(lc,devname);
1124 linphonec_out("Using playback sound device %s\n",devname);
1127 linphonec_out("No such sound device\n");
1131 if (strcmp(arg1, "ring")==0)
1133 const char *devname=linphone_core_get_ringer_device(lc);
1135 linphonec_out("Using ring device #%i (%s)\n",
1136 devname_to_index(lc,devname),devname);
1138 index=atoi(arg2); /* FIXME: handle not-a-number */
1139 devname=index_to_devname(lc,index);
1141 linphone_core_set_ringer_device(lc,devname);
1142 linphonec_out("Using ring sound device %s\n",devname);
1145 linphonec_out("No such sound device\n");
1149 return 0; /* syntax error */
1152 static int lpc_cmd_webcam(LinphoneCore *lc, char *args)
1160 if (!args) return 0; /* syntax error */
1162 /* Isolate first and second arg */
1163 while(*ptr && !isspace(*ptr)) ++ptr;
1168 while(*arg2 && isspace(*arg2)) ++arg2;
1171 if (strcmp(arg1, "list")==0)
1173 dev=linphone_core_get_video_devices(lc);
1174 for(i=0; dev[i]!=NULL; ++i){
1175 linphonec_out("%i: %s\n",i,dev[i]);
1180 if (strcmp(arg1, "use")==0 && arg2)
1182 dev=linphone_core_get_video_devices(lc);
1183 index=atoi(arg2); /* FIXME: handle not-a-number */
1184 for(i=0;dev[i]!=NULL;i++)
1186 if (i!=index) continue;
1188 linphone_core_set_video_device(lc, dev[i]);
1189 linphonec_out("Using video device %s\n",dev[i]);
1192 linphonec_out("No such video device\n");
1195 return 0; /* syntax error */
1199 lpc_cmd_staticpic(LinphoneCore *lc, char *args)
1205 if (!args) return 0; /* Syntax error */
1207 /* Isolate first and second arg */
1208 while(*ptr && !isspace(*ptr)) ++ptr;
1213 while(*arg2 && isspace(*arg2)) ++arg2;
1216 if (strcmp(arg1, "set")==0 && arg2) {
1217 linphone_core_set_static_picture(lc, arg2);
1221 return 0; /* Syntax error */
1224 static int lpc_cmd_pause(LinphoneCore *lc, char *args){
1226 if(linphone_core_in_call(lc))
1228 linphone_core_pause_call(lc,linphone_core_get_current_call(lc));
1231 linphonec_out("you can only pause when a call is in process\n");
1235 static int lpc_cmd_resume(LinphoneCore *lc, char *args){
1237 if(linphone_core_in_call(lc))
1239 linphonec_out("There is already a call in process pause or stop it first");
1245 int n = sscanf(args, "%li", &id);
1247 LinphoneCall *call=linphonec_get_call (id);
1249 if(linphone_core_resume_call(lc,call)==-1){
1250 linphonec_out("There was a problem to resume the call check the remote address you gave %s\n",args);
1258 const MSList *calls = linphone_core_get_calls(lc);
1259 int nbcalls=ms_list_size(calls);
1262 if(linphone_core_resume_call(lc,calls->data) < 0)
1264 linphonec_out("There was a problem to resume the unique call.\n");
1267 }else if (nbcalls==0){
1268 linphonec_out("There is no calls at this time.\n");
1271 linphonec_out("There are %i calls at this time, please specify call id as given with 'calls' command.\n");
1278 /***************************************************************************
1280 * Commands helper functions
1282 ***************************************************************************/
1286 linphonec_proxy_add(LinphoneCore *lc)
1288 bool_t enable_register=FALSE;
1289 LinphoneProxyConfig *cfg;
1291 linphonec_out("Adding new proxy setup. Hit ^D to abort.\n");
1298 char *input=linphonec_readline("Enter proxy sip address: ");
1302 linphonec_out("Aborted.\n");
1307 clean=lpc_strip_blanks(input);
1313 cfg=linphone_proxy_config_new();
1314 if (linphone_proxy_config_set_server_addr(cfg,clean)<0)
1316 linphonec_out("Invalid sip address (sip:sip.domain.tld).\n");
1318 linphone_proxy_config_destroy(cfg);
1326 * SIP Proxy identity
1330 char *input=linphonec_readline("Your identity for this proxy: ");
1334 linphonec_out("Aborted.\n");
1335 linphone_proxy_config_destroy(cfg);
1340 clean=lpc_strip_blanks(input);
1346 linphone_proxy_config_set_identity(cfg, clean);
1347 if ( ! cfg->reg_identity )
1349 linphonec_out("Invalid identity (sip:name@sip.domain.tld).\n");
1358 * SIP Proxy enable register
1362 char *input=linphonec_readline("Do you want to register on this proxy (yes/no): ");
1366 linphonec_out("Aborted.\n");
1367 linphone_proxy_config_destroy(cfg);
1372 clean=lpc_strip_blanks(input);
1378 if ( ! strcmp(clean, "yes") ) enable_register=TRUE;
1379 else if ( ! strcmp(clean, "no") ) enable_register=FALSE;
1381 linphonec_out("Please answer with 'yes' or 'no'\n");
1385 linphone_proxy_config_enableregister(cfg, enable_register);
1391 * SIP Proxy registration expiration
1393 if ( enable_register==TRUE )
1398 char *input=linphonec_readline("Specify register expiration time"
1399 " in seconds (default is 600): ");
1402 linphonec_out("Aborted.\n");
1403 linphone_proxy_config_destroy(cfg);
1407 expires=strtol(input, (char **)NULL, 10);
1408 if ( expires == LONG_MIN || expires == LONG_MAX )
1410 linphonec_out("Invalid value: %s\n", strerror(errno));
1415 linphone_proxy_config_expires(cfg, expires);
1416 linphonec_out("Expiration: %d seconds\n", cfg->expires);
1428 char *input=linphonec_readline("Specify route if needed: ");
1432 linphonec_out("Aborted.\n");
1433 linphone_proxy_config_destroy(cfg);
1438 clean=lpc_strip_blanks(input);
1441 linphonec_out("No route specified.\n");
1445 linphone_proxy_config_set_route(cfg, clean);
1446 if ( ! cfg->reg_route )
1448 linphonec_out("Invalid route.\n");
1458 * Final confirmation
1465 linphonec_out("--------------------------------------------\n");
1466 linphonec_proxy_display(cfg);
1467 linphonec_out("--------------------------------------------\n");
1468 input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: ");
1472 linphonec_out("Aborted.\n");
1473 linphone_proxy_config_destroy(cfg);
1478 clean=lpc_strip_blanks(input);
1484 if ( ! strcmp(clean, "yes") ) break;
1485 else if ( ! strcmp(clean, "no") )
1487 linphonec_out("Declined.\n");
1488 linphone_proxy_config_destroy(cfg);
1493 linphonec_out("Please answer with 'yes' or 'no'\n");
1499 linphone_core_add_proxy_config(lc,cfg);
1501 /* automatically set the last entered proxy as the default one */
1502 linphone_core_set_default_proxy(lc,cfg);
1504 linphonec_out("Proxy added.\n");
1508 linphonec_proxy_display(LinphoneProxyConfig *cfg)
1510 linphonec_out("sip address: %s\nroute: %s\nidentity: %s\nregister: %s\nexpires: %i\nregistered: %s\n",
1512 (cfg->reg_route!=NULL)?cfg->reg_route:"",
1513 (cfg->reg_identity!=NULL)?cfg->reg_identity:"",
1514 (cfg->reg_sendregister)?"yes":"no",
1516 linphone_proxy_config_is_registered(cfg) ? "yes" : "no");
1519 static void linphonec_proxy_show(LinphoneCore *lc, int index)
1523 for(elem=linphone_core_get_proxy_config_list(lc),i=0;elem!=NULL;elem=elem->next,++i){
1525 LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)elem->data;
1526 linphonec_proxy_display(cfg);
1530 linphonec_out("No proxy with index %i\n", index);
1534 linphonec_proxy_list(LinphoneCore *lc)
1536 const MSList *proxies;
1538 int def=linphone_core_get_default_proxy(lc,NULL);
1540 proxies=linphone_core_get_proxy_config_list(lc);
1541 for(n=0;proxies!=NULL;proxies=ms_list_next(proxies),n++){
1543 linphonec_out("****** Proxy %i - this is the default one - *******\n",n);
1545 linphonec_out("****** Proxy %i *******\n",n);
1546 linphonec_proxy_display((LinphoneProxyConfig*)proxies->data);
1548 if ( ! n ) linphonec_out("No proxies defined\n");
1552 linphonec_proxy_remove(LinphoneCore *lc, int index)
1554 const MSList *proxies;
1555 LinphoneProxyConfig *cfg;
1556 proxies=linphone_core_get_proxy_config_list(lc);
1557 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1559 linphonec_out("No such proxy.\n");
1562 linphone_core_remove_proxy_config(lc,cfg);
1563 linphonec_out("Proxy %s removed.\n", cfg->reg_proxy);
1564 linphone_proxy_config_destroy(cfg);
1568 linphonec_proxy_use(LinphoneCore *lc, int index)
1570 const MSList *proxies;
1571 LinphoneProxyConfig *cfg;
1572 proxies=linphone_core_get_proxy_config_list(lc);
1573 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1575 linphonec_out("No such proxy (try 'proxy list').");
1578 linphone_core_set_default_proxy(lc,cfg);
1583 linphonec_friend_display(LinphoneFriend *fr)
1585 LinphoneAddress *uri=linphone_address_clone(linphone_friend_get_address(fr));
1588 linphonec_out("name: %s\n", linphone_address_get_display_name(uri));
1589 linphone_address_set_display_name(uri,NULL);
1590 str=linphone_address_as_string(uri);
1591 linphonec_out("address: %s\n", str);
1595 linphonec_friend_list(LinphoneCore *lc, char *pat)
1597 const MSList *friend;
1601 pat=lpc_strip_blanks(pat);
1602 if (!*pat) pat = NULL;
1605 friend = linphone_core_get_friend_list(lc);
1606 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1609 const char *name = linphone_address_get_display_name(
1610 linphone_friend_get_address((LinphoneFriend*)friend->data));
1611 if (name && ! strstr(name, pat) ) continue;
1613 linphonec_out("****** Friend %i *******\n",n);
1614 linphonec_friend_display((LinphoneFriend*)friend->data);
1621 linphonec_friend_call(LinphoneCore *lc, unsigned int num)
1623 const MSList *friend = linphone_core_get_friend_list(lc);
1627 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1632 addr = linphone_address_as_string(linphone_friend_get_address((LinphoneFriend*)friend->data));
1633 ret=lpc_cmd_call(lc, addr);
1638 linphonec_out("No such friend %u\n", num);
1644 linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr)
1646 LinphoneFriend *newFriend;
1650 snprintf(url, PATH_MAX, "%s <%s>", name, addr);
1651 newFriend = linphone_friend_new_with_addr(url);
1652 linphone_core_add_friend(lc, newFriend);
1658 linphonec_friend_delete(LinphoneCore *lc, int num)
1660 const MSList *friend = linphone_core_get_friend_list(lc);
1663 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1667 linphone_core_remove_friend(lc, friend->data);
1675 for (i = 0 ; i < n ; i++)
1676 linphonec_friend_delete(lc, 0);
1680 linphonec_out("No such friend %u\n", num);
1685 linphonec_display_command_help(LPC_COMMAND *cmd)
1687 if ( cmd->doc ) linphonec_out ("%s\n", cmd->doc);
1688 else linphonec_out("%s\n", cmd->help);
1692 static int lpc_cmd_register(LinphoneCore *lc, char *args){
1696 LinphoneProxyConfig *cfg;
1701 /* it means that you want to register the default proxy */
1702 LinphoneProxyConfig *cfg=NULL;
1703 linphone_core_get_default_proxy(lc,&cfg);
1706 if(!linphone_proxy_config_is_registered(cfg)) {
1707 linphone_proxy_config_enable_register(cfg,TRUE);
1708 linphone_proxy_config_done(cfg);
1710 linphonec_out("default proxy already registered\n");
1713 linphonec_out("we do not have a default proxy\n");
1718 passwd[0]=proxy[0]=identity[0]='\0';
1719 sscanf(args,"%s %s %s",identity,proxy,passwd);
1720 if (proxy[0]=='\0' || identity[0]=='\0'){
1721 linphonec_out("Missing parameters, see help register\n");
1724 if (passwd[0]!='\0'){
1725 LinphoneAddress *from;
1726 LinphoneAuthInfo *info;
1727 if ((from=linphone_address_new(identity))!=NULL){
1729 snprintf(realm,sizeof(realm)-1,"\"%s\"",linphone_address_get_domain(from));
1730 info=linphone_auth_info_new(linphone_address_get_username(from),NULL,passwd,NULL,NULL);
1731 linphone_core_add_auth_info(lc,info);
1732 linphone_address_destroy(from);
1733 linphone_auth_info_destroy(info);
1736 elem=linphone_core_get_proxy_config_list(lc);
1738 cfg=(LinphoneProxyConfig*)elem->data;
1739 linphone_proxy_config_edit(cfg);
1741 else cfg=linphone_proxy_config_new();
1742 linphone_proxy_config_set_identity(cfg,identity);
1743 linphone_proxy_config_set_server_addr(cfg,proxy);
1744 linphone_proxy_config_enable_register(cfg,TRUE);
1745 if (elem) linphone_proxy_config_done(cfg);
1746 else linphone_core_add_proxy_config(lc,cfg);
1747 linphone_core_set_default_proxy(lc,cfg);
1751 static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
1752 LinphoneProxyConfig *cfg=NULL;
1753 linphone_core_get_default_proxy(lc,&cfg);
1754 if (cfg && linphone_proxy_config_is_registered(cfg)) {
1755 linphone_proxy_config_edit(cfg);
1756 linphone_proxy_config_enable_register(cfg,FALSE);
1757 linphone_proxy_config_done(cfg);
1759 linphonec_out("unregistered\n");
1764 static int lpc_cmd_duration(LinphoneCore *lc, char *args){
1765 LinphoneCallLog *cl;
1766 const MSList *elem=linphone_core_get_call_logs(lc);
1767 for(;elem!=NULL;elem=elem->next){
1768 if (elem->next==NULL){
1769 cl=(LinphoneCallLog*)elem->data;
1770 linphonec_out("%i seconds\n",cl->duration);
1776 static int lpc_cmd_status(LinphoneCore *lc, char *args)
1778 LinphoneProxyConfig *cfg;
1780 if ( ! args ) return 0;
1781 linphone_core_get_default_proxy(lc,&cfg);
1782 if (strstr(args,"register"))
1786 if (linphone_proxy_config_is_registered(cfg)){
1787 linphonec_out("registered, identity=%s duration=%i\n",
1788 linphone_proxy_config_get_identity(cfg),
1789 linphone_proxy_config_get_expires(cfg));
1790 }else if (linphone_proxy_config_register_enabled(cfg)){
1791 linphonec_out("registered=-1\n");
1792 }else linphonec_out("registered=0\n");
1794 else linphonec_out("registered=0\n");
1796 else if (strstr(args,"autoanswer"))
1798 if (cfg && linphone_proxy_config_is_registered(cfg))
1799 linphonec_out("autoanswer=%i\n",linphonec_get_autoanswer());
1800 else linphonec_out("unregistered\n");
1802 else if (strstr(args,"hook"))
1804 LinphoneCall *call=linphone_core_get_current_call (lc);
1805 LinphoneCallState call_state=LinphoneCallIdle;
1806 if (call) call_state=linphone_call_get_state(call);
1809 case LinphoneCallOutgoingInit:
1810 case LinphoneCallOutgoingProgress:
1811 linphonec_out("hook=dialing\n");
1813 case LinphoneCallIdle:
1814 linphonec_out("hook=offhook\n");
1816 case LinphoneCallStreamsRunning:
1817 case LinphoneCallConnected:
1818 if (linphone_call_get_dir(call)==LinphoneCallOutgoing){
1819 linphonec_out("Call out, hook=%s duration=%i, muted=%s rtp-xmit-muted=%s\n", linphonec_get_callee(),
1820 linphone_core_get_current_call_duration(lc),
1821 linphone_core_is_mic_muted (lc) ? "yes" : "no",
1822 linphone_core_is_rtp_muted(lc) ? "yes" : "no");
1824 linphonec_out("hook=answered duration=%i\n" ,
1825 linphone_core_get_current_call_duration(lc));
1828 case LinphoneCallIncomingReceived:
1829 linphonec_out("Incoming call from %s\n",linphonec_get_caller());
1841 static int lpc_cmd_ports(LinphoneCore *lc, char *args)
1845 linphonec_out("sip port = %i\naudio rtp port = %i\nvideo rtp port = %i\n",
1846 linphone_core_get_sip_port(lc),
1847 linphone_core_get_audio_port(lc),
1848 linphone_core_get_video_port(lc));
1851 if (sscanf(args,"sip %i",&port)==1){
1852 linphonec_out("Setting sip port to %i\n",port);
1853 linphone_core_set_sip_port(lc,port);
1859 static int lpc_cmd_speak(LinphoneCore *lc, char *args){
1868 if (!args) return 0;
1869 memset(voice,0,sizeof(voice));
1870 sscanf(args,"%s63",voice);
1871 sentence=args+strlen(voice);
1872 wavfile=tempnam("/tmp/","linphonec-espeak-");
1873 snprintf(cl,sizeof(cl),"espeak -v %s -s 100 -w %s --stdin",voice,wavfile);
1876 ms_error("Could not open pipe to espeak !");
1879 fprintf(file,"%s",sentence);
1880 status=pclose(file);
1881 if (WEXITSTATUS(status)==0){
1882 linphone_core_set_play_file(lc,wavfile);
1884 linphonec_out("espeak command failed.");
1887 linphonec_out("Sorry, this command is not implemented in windows version.");
1892 static int lpc_cmd_acodec(LinphoneCore *lc, char *args){
1893 return lpc_cmd_codec(AUDIO, lc, args);
1896 static int lpc_cmd_vcodec(LinphoneCore *lc, char *args){
1897 return lpc_cmd_codec(VIDEO, lc, args);
1900 static int lpc_cmd_codec(int type, LinphoneCore *lc, char *args){
1905 if (!args) return 0;
1907 /* Isolate first and second arg */
1908 while(*ptr && !isspace(*ptr)) ++ptr;
1913 while(*arg2 && isspace(*arg2)) ++arg2;
1916 if (strcmp(arg1,"enable")==0)
1918 #ifdef HAVE_READLINE
1919 rl_inhibit_completion=1;
1921 if (!strcmp(arg2,"all")) linphonec_codec_enable(type,lc,-1);
1922 else linphonec_codec_enable(type,lc,atoi(arg2));
1923 #ifdef HAVE_READLINE
1924 rl_inhibit_completion=0;
1927 else if (strcmp(arg1,"list")==0)
1929 linphonec_codec_list(type,lc);
1931 else if (strcmp(arg1,"disable")==0)
1933 if (!strcmp(arg2,"all")) linphonec_codec_disable(type,lc,-1);
1934 else linphonec_codec_disable(type,lc,atoi(arg2));
1938 return 0; /* syntax error */
1944 static void linphonec_codec_list(int type, LinphoneCore *lc){
1946 codecs_config_t *config=&lc->codecs_conf;
1950 if (type == AUDIO) {
1951 node=config->audio_codecs;
1952 } else if(type==VIDEO) {
1953 node=config->video_codecs;
1956 for(;node!=NULL;node=ms_list_next(node)){
1957 pt=(PayloadType*)(node->data);
1958 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate,
1959 linphone_core_payload_type_enabled(lc,pt) ? "enabled" : "disabled");
1964 static void linphonec_codec_enable(int type, LinphoneCore *lc, int sel_index){
1966 codecs_config_t *config=&lc->codecs_conf;
1970 if (type == AUDIO) {
1971 node=config->audio_codecs;
1972 } else if(type==VIDEO) {
1973 node=config->video_codecs;
1976 for(;node!=NULL;node=ms_list_next(node)){
1977 if (index == sel_index || sel_index == -1) {
1978 pt=(PayloadType*)(node->data);
1979 pt->flags|=PAYLOAD_TYPE_ENABLED;
1980 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "enabled");
1986 static void linphonec_codec_disable(int type, LinphoneCore *lc, int sel_index){
1988 codecs_config_t *config=&lc->codecs_conf;
1992 if (type == AUDIO) {
1993 node=config->audio_codecs;
1994 } else if(type==VIDEO) {
1995 node=config->video_codecs;
1998 for(;node!=NULL;node=ms_list_next(node)){
1999 if (index == sel_index || sel_index == -1) {
2000 pt=(PayloadType*)(node->data);
2001 pt->flags&=~PAYLOAD_TYPE_ENABLED;
2002 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "disabled");
2008 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){
2013 if (!args) return 0;
2015 /* Isolate first and second arg */
2016 while(*ptr && !isspace(*ptr)) ++ptr;
2021 while(*arg2 && isspace(*arg2)) ++arg2;
2024 if (strcmp(arg1,"on")==0){
2025 int delay, tail_len, frame_size;
2028 linphone_core_enable_echo_cancellation(lc,1);
2031 n = sscanf(arg2, "%d %d %d", &delay, &tail_len, &frame_size);
2034 lp_config_set_int(lc->config,"sound","ec_delay",delay);
2037 lp_config_set_int(lc->config,"sound","ec_delay",delay);
2038 lp_config_set_int(lc->config,"sound","ec_tail_len",tail_len);
2041 lp_config_set_int(lc->config,"sound","ec_delay",delay);
2042 lp_config_set_int(lc->config,"sound","ec_tail_len",tail_len);
2043 lp_config_set_int(lc->config,"sound","ec_framesize",frame_size);
2047 else if (strcmp(arg1,"off")==0){
2048 linphone_core_enable_echo_cancellation(lc,0);
2050 else if (strcmp(arg1,"show")==0){
2051 linphonec_out("echo cancellation is %s; delay %d, tail length %d, frame size %d\n",
2052 linphone_core_echo_cancellation_enabled(lc) ? "on" : "off",
2053 lp_config_get_int(lc->config,"sound","ec_delay",0),
2054 lp_config_get_int(lc->config,"sound","ec_tail_len",0),
2055 lp_config_get_int(lc->config,"sound","ec_framesize",0));
2064 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args)
2066 linphone_core_mute_mic(lc, 1);
2070 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args){
2071 linphone_core_mute_mic(lc, 0);
2075 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args)
2077 bool_t rtp_xmit_off=FALSE;
2081 if(strstr(args,"1"))rtp_xmit_off=TRUE;
2082 if(linphone_core_get_current_call (lc)==NULL)
2083 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_xmit_off);
2085 linphonec_out("nortp-on-audio-mute: call in progress - cannot change state\n");
2087 rtp_xmit_off=linphone_core_get_rtp_no_xmit_on_audio_mute(lc);
2088 if (rtp_xmit_off) status="off";
2090 linphonec_out("rtp transmit %s when audio muted\n",status);
2095 /***************************************************************************
2097 * Command table management funx
2099 ***************************************************************************/
2102 * Find a command given its name
2104 static LPC_COMMAND *
2105 lpc_find_command(const char *name)
2109 for (i=0; commands[i].name; ++i)
2111 if (strcmp(name, commands[i].name) == 0)
2112 return &commands[i];
2115 return (LPC_COMMAND *)NULL;
2119 /****************************************************************************
2121 * $Log: commands.c,v $
2122 * Revision 1.39 2008/07/03 15:08:34 smorlat
2123 * api cleanups, interface in progress.
2125 * Revision 1.38 2008/06/17 20:38:59 smorlat
2126 * added missing file.
2128 * Revision 1.37 2008/04/09 09:26:00 smorlat
2129 * merge various patches
2132 * Revision 1.36 2007/08/01 14:47:53 strk
2133 * * console/commands.c: Clean up commands 'nat', 'stun'
2134 * and 'firewall' to be more intuitive.
2136 * Revision 1.35 2007/06/27 09:01:25 smorlat
2137 * logging improvements.
2139 * Revision 1.34 2007/02/20 10:17:13 smorlat
2140 * linphonec friends patch2
2142 * Revision 1.31 2006/09/22 07:22:47 smorlat
2143 * linphonecore api changes.
2145 * Revision 1.30 2006/09/08 15:32:57 smorlat
2146 * support for using files instead of soundcard (used by linphonec only)
2148 * Revision 1.29 2006/08/28 14:29:07 smorlat
2151 * Revision 1.28 2006/08/21 12:49:59 smorlat
2152 * merged several little patches.
2154 * Revision 1.27 2006/07/17 18:45:00 smorlat
2155 * support for several event queues in ortp.
2156 * glib dependency removed from coreapi/ and console/
2158 * Revision 1.26 2006/04/14 15:16:36 smorlat
2159 * soundcard use did nothing !
2161 * Revision 1.25 2006/04/06 20:09:33 smorlat
2162 * add linphonec command to see and select sound devices.
2164 * Revision 1.24 2006/03/04 11:17:10 smorlat
2165 * mediastreamer2 in progress.
2167 * Revision 1.23 2006/02/20 21:14:01 strk
2168 * Handled syntax errors with 'friend' command
2170 * Revision 1.22 2006/02/20 10:20:29 strk
2171 * Added substring-based filter support for command 'friend list'
2173 * Revision 1.21 2006/02/02 15:39:18 strk
2174 * - Added 'friend list' and 'friend call' commands
2175 * - Allowed for multiple DTFM send in a single line
2176 * - Added status-specific callback (bare version)
2178 * Revision 1.20 2006/01/26 11:54:34 strk
2179 * More robust 'nat' command handler (strip blanks in args)
2181 * Revision 1.19 2006/01/26 09:48:05 strk
2182 * Added limits.h include
2184 * Revision 1.18 2006/01/26 02:18:05 strk
2185 * Added new commands 'nat use' and 'nat unuse'.
2186 * These will required a pending patch to linphonecore.c
2189 * Revision 1.17 2006/01/20 14:12:33 strk
2190 * Added linphonec_init() and linphonec_finish() functions.
2191 * Handled SIGINT and SIGTERM to invoke linphonec_finish().
2192 * Handling of auto-termination (-t) moved to linphonec_finish().
2193 * Reworked main (input read) loop to not rely on 'terminate'
2194 * and 'run' variable (dropped). configfile_name allocated on stack
2195 * using PATH_MAX limit. Changed print_usage signature to allow
2196 * for an exit_status specification.
2198 * Revision 1.16 2006/01/18 09:25:32 strk
2199 * Command completion inhibited in proxy addition and auth request prompts.
2200 * Avoided use of linphonec_readline's internal filename completion.
2202 * Revision 1.15 2006/01/14 13:29:32 strk
2203 * Reworked commands interface to use a table structure,
2204 * used by command line parser and help function.
2205 * Implemented first level of completion (commands).
2206 * Added notification of invalid "answer" and "terminate"
2207 * commands (no incoming call, no active call).
2208 * Forbidden "call" intialization when a call is already active.
2209 * Cleaned up all commands, adding more feedback and error checks.
2211 * Revision 1.14 2006/01/13 13:00:29 strk
2212 * Added linphonec.h. Code layout change (added comments, forward decl,
2213 * globals on top, copyright notices and Logs). Handled out-of-memory
2214 * condition on history management. Removed assumption on sizeof(char).
2215 * Fixed bug in authentication prompt (introduced by linphonec_readline).
2216 * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
2219 ****************************************************************************/