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);
92 static int lpc_cmd_video_window(LinphoneCore *lc, char *args);
93 static int lpc_cmd_states(LinphoneCore *lc, char *args);
95 /* Command handler helpers */
96 static void linphonec_proxy_add(LinphoneCore *lc);
97 static void linphonec_proxy_display(LinphoneProxyConfig *lc);
98 static void linphonec_proxy_list(LinphoneCore *lc);
99 static void linphonec_proxy_remove(LinphoneCore *lc, int index);
100 static int linphonec_proxy_use(LinphoneCore *lc, int index);
101 static void linphonec_proxy_show(LinphoneCore *lc,int index);
102 static void linphonec_friend_display(LinphoneFriend *fr);
103 static int linphonec_friend_list(LinphoneCore *lc, char *arg);
104 static void linphonec_display_command_help(LPC_COMMAND *cmd);
105 static int linphonec_friend_call(LinphoneCore *lc, unsigned int num);
107 static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
109 static int linphonec_friend_delete(LinphoneCore *lc, int num);
110 static int linphonec_friend_delete(LinphoneCore *lc, int num);
111 static void linphonec_codec_list(int type, LinphoneCore *lc);
112 static void linphonec_codec_enable(int type, LinphoneCore *lc, int index);
113 static void linphonec_codec_disable(int type, LinphoneCore *lc, int index);
117 /* Command table management */
118 static LPC_COMMAND *lpc_find_command(const char *name);
120 void linphonec_out(const char *fmt,...);
122 VideoParams lpc_video_params={-1,-1,-1,-1,TRUE};
125 /***************************************************************************
129 ***************************************************************************/
134 static LPC_COMMAND commands[] = {
135 { "help", lpc_cmd_help, "Print commands help.",
136 "'help <command>'\t: displays specific help for command.\n"
137 "'help advanced'\t: shows advanced commands.\n"
139 { "call", lpc_cmd_call, "Call a SIP uri",
140 "'call <sip-url>' \t: initiate a call to the specified destination.\n"
141 "'call show' \t: show all the current calls with their id and status.\n"
143 { "calls", lpc_cmd_calls, "Show all the current calls with their id and status.",
146 { "chat", lpc_cmd_chat, "Chat with a SIP uri",
147 "'chat <sip-url> \"message\"' "
148 ": send a chat message \"message\" to the specified destination."
150 { "terminate", lpc_cmd_terminate, "Terminate a call",
151 "'terminate' : Terminate the current call\n"
152 "'terminate <call id>' : Terminate the call with supplied id\n"
153 "'terminate <all>' : Terminate all the current calls\n"
155 { "answer", lpc_cmd_answer, "Answer a call",
156 "'answer' : Answer the current incoming call\n"
157 "'answer <call id>' : Answer the call with given id\n"
159 { "pause", lpc_cmd_pause, "pause a call",
160 "'pause' : pause the current call\n"},
161 { "resume", lpc_cmd_resume, "resume a call",
162 "'resume' : resume the unique call\n"
163 "'resume <call id>' : hold off the call with given id\n"},
164 { "mute", lpc_cmd_mute_mic,
165 "Mute microphone and suspend voice transmission."},
166 { "unmute", lpc_cmd_unmute_mic,
167 "Unmute microphone and resume voice transmission."},
168 { "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
170 { "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
171 "'autoanswer' \t: show current autoanswer mode\n"
172 "'autoanswer enable'\t: enable autoanswer mode\n"
173 "'autoanswer disable'\t: disable autoanswer modeĀ \n"},
174 { "proxy", lpc_cmd_proxy, "Manage proxies",
175 "'proxy list' : list all proxy setups.\n"
176 "'proxy add' : add a new proxy setup.\n"
177 "'proxy remove <index>' : remove proxy setup with number index.\n"
178 "'proxy use <index>' : use proxy with number index as default proxy.\n"
179 "'proxy unuse' : don't use a default proxy.\n"
180 "'proxy show <index>' : show configuration and status of the proxy numbered by index.\n"
181 "'proxy show default' : show configuration and status of the default proxy.\n"
183 { "soundcard", lpc_cmd_soundcard, "Manage soundcards",
184 "'soundcard list' : list all sound devices.\n"
185 "'soundcard show' : show current sound devices configuration.\n"
186 "'soundcard use <index>' : select a sound device.\n"
187 "'soundcard use files' : use .wav files instead of soundcard\n"
189 { "webcam", lpc_cmd_webcam, "Manage webcams",
190 "'webcam list' : list all known devices.\n"
191 "'webcam use <index>' : select a video device.\n"
193 { "ipv6", lpc_cmd_ipv6, "Use IPV6",
194 "'ipv6 status' : show ipv6 usage status.\n"
195 "'ipv6 enable' : enable the use of the ipv6 network.\n"
196 "'ipv6 disable' : do not use ipv6 network."
198 { "transfer", lpc_cmd_transfer,
199 "Transfer a call to a specified destination.",
200 "'transfer <sip-uri>' : transfers the current active call to the destination sip-uri"
201 "'transfer <call id> <sip-uri>': transfers the call with 'id' to the destination sip-uri"
203 { "nat", lpc_cmd_nat, "Set nat address",
204 "'nat' : show nat settings.\n"
205 "'nat <addr>' : set nat address.\n"
207 { "stun", lpc_cmd_stun, "Set stun server address",
208 "'stun' : show stun settings.\n"
209 "'stun <addr>' : set stun server address.\n"
211 { "firewall", lpc_cmd_firewall, "Set firewall policy",
212 "'firewall' : show current firewall policy.\n"
213 "'firewall none' : use direct connection.\n"
214 "'firewall nat' : use nat address given with the 'nat' command.\n"
215 "'firewall stun' : use stun server given with the 'stun' command.\n"
217 { "call-logs", lpc_cmd_call_logs, "Calls history", NULL },
218 { "friend", lpc_cmd_friend, "Manage friends",
219 "'friend list [<pattern>]' : list friends.\n"
220 "'friend call <index>' : call a friend.\n"
221 "'friend add <name> <addr>' : add friend, <name> must be quoted to include\n"
222 " spaces, <addr> has \"sip:\" added if it isn't\n"
223 " there. Don't use '<' '>' around <addr>.\n"
224 "'friend delete <index>' : remove friend, 'all' removes all\n"
226 { "play", lpc_cmd_play, "play a wav file",
227 "This command has two roles:\n"
228 "Plays a file instead of capturing from soundcard - only available in file mode (see 'help soundcard')\n"
229 "Specifies a wav file to be played to play music to far end when putting it on hold (pause)\n"
230 "'play <wav file>' : play a wav file."
232 { "record", lpc_cmd_record, "record to a wav file",
233 "This feature is available only in file mode (see 'help soundcard')\n"
234 "'record <wav file>' : record into wav file."
236 { "quit", lpc_cmd_quit, "Exit linphonec", NULL },
237 { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
241 static LPC_COMMAND advanced_commands[] = {
242 { "codec", lpc_cmd_acodec, "Audio codec configuration",
243 "'codec list' : list audio codecs\n"
244 "'codec enable <index>' : enable available audio codec\n"
245 "'codec disable <index>' : disable audio codec" },
246 { "vcodec", lpc_cmd_vcodec, "Video codec configuration",
247 "'vcodec list' : list video codecs\n"
248 "'vcodec enable <index>' : enable available video codec\n"
249 "'vcodec disable <index>' : disable video codec" },
250 { "ec", lpc_cmd_echocancellation, "Echo cancellation",
251 "'ec on [<delay>] [<tail>] [<framesize>]' : turn EC on with given delay, tail length and framesize\n"
252 "'ec off' : turn echo cancellation (EC) off\n"
253 "'ec show' : show EC status" },
254 { "nortp-on-audio-mute", lpc_cmd_rtp_no_xmit_on_audio_mute,
255 "Set the rtp_no_xmit_on_audio_mute configuration parameter",
256 " If set to 1 then rtp transmission will be muted when\n"
257 " audio is muted , otherwise rtp is always sent."},
258 { "vwindow", lpc_cmd_video_window, "Control video display window",
259 "'vwindow show': shows video window\n"
260 "'vwindow hide': hides video window\n"
261 "'vwindow pos <x> <y>': Moves video window to x,y pixel coordinates\n"
262 "'vwindow size <width> <height>': Resizes video window"
264 { "states", lpc_cmd_states, "Show internal states of liblinphone, registrations and calls, according to linphonecore.h definitions",
265 "'states global': shows global state of liblinphone \n"
266 "'states calls': shows state of calls\n"
267 "'states proxies': shows state of proxy configurations"
269 { "register", lpc_cmd_register, "Register in one line to a proxy" , "register <sip identity> <sip proxy> <password>"},
270 { "unregister", lpc_cmd_unregister, "Unregister from default proxy", NULL },
271 { "status", lpc_cmd_status, "Print various status information",
272 "'status register' \t: print status concerning registration\n"
273 "'status autoanswer'\t: tell whether autoanswer mode is enabled\n"
274 "'status hook' \t: print hook status\n" },
275 { "ports", lpc_cmd_ports, "Network ports configuration",
276 "'ports' \t: prints current used ports.\n"
277 "'ports sip <port number>'\t: Sets the sip port.\n" },
278 { "speak", lpc_cmd_speak, "Speak a sentence using espeak TTS engine",
279 "This feature is available only in file mode. (see 'help soundcard')\n"
280 "'speak <voice name> <sentence>' : speak a text using the specified espeak voice.\n"
281 "Example for english voice: 'speak default Hello my friend !'"
283 { "staticpic", lpc_cmd_staticpic, "Manage static pictures when nowebcam",
284 "'staticpic set' : Set path to picture that should be used.\n"
285 "'staticpic fps' : Get/set frames per seconds for picture emission.\n"
287 { NULL,NULL,NULL,NULL}
292 /***************************************************************************
296 ***************************************************************************/
299 * Main command dispatcher.
300 * WARNING: modifies second argument!
302 * Always return 1 currently.
305 linphonec_parse_command_line(LinphoneCore *lc, char *cl)
311 /* Isolate first word and args */
312 while(*ptr && !isspace(*ptr)) ++ptr;
316 /* set args to first nonblank */
318 while(*args && isspace(*args)) ++args;
322 if ( isdigit(*cl) || *cl == '#' || *cl == '*' )
324 while ( isdigit(*cl) || *cl == '#' || *cl == '*' )
326 linphone_core_send_dtmf(lc, *cl);
327 linphone_core_play_dtmf (lc,*cl,100);
328 ms_sleep(1); // be nice
332 // discard spurious trailing chars
336 /* Handle other kind of commands */
337 cmd=lpc_find_command(cl);
340 linphonec_out("'%s': Cannot understand this.\n", cl);
344 if ( ! cmd->func(lc, args) )
346 linphonec_out("Syntax error.\n");
347 linphonec_display_command_help(cmd);
354 * Generator function for command completion.
355 * STATE let us know whether to start from scratch;
356 * without any state (STATE==0), then we start at the
360 linphonec_command_generator(const char *text, int state)
362 static int index, len, adv;
372 * Return the next name which partially matches
373 * from the commands list
376 while ((name=commands[index].name))
378 ++index; /* so next call get next command */
380 if (strncmp(name, text, len) == 0)
382 return ortp_strdup(name);
389 while ((name=advanced_commands[index].name))
391 ++index; /* so next call get next command */
393 if (strncmp(name, text, len) == 0)
395 return ortp_strdup(name);
403 /***************************************************************************
407 ***************************************************************************/
410 lpc_cmd_help(LinphoneCore *lc, char *arg)
417 linphonec_out("Commands are:\n");
418 linphonec_out("---------------------------\n");
420 while (commands[i].help)
422 linphonec_out("%10.10s\t%s\n", commands[i].name,
427 linphonec_out("---------------------------\n");
428 linphonec_out("Type 'help <command>' for more details or 'help advanced' to list additional commands.\n");
433 if (strcmp(arg,"advanced")==0){
434 linphonec_out("Advanced commands are:\n");
435 linphonec_out("---------------------------\n");
437 while (advanced_commands[i].help)
439 linphonec_out("%10.10s\t%s\n", advanced_commands[i].name,
440 advanced_commands[i].help);
444 linphonec_out("---------------------------\n");
445 linphonec_out("Type 'help <command>' for more details.\n");
450 cmd=lpc_find_command(arg);
453 linphonec_out("No such command.\n");
457 linphonec_display_command_help(cmd);
462 static char callee_name[256]={0};
463 static char caller_name[256]={0};
465 static const char *get_call_status(LinphoneCall *call){
466 switch(linphone_call_get_state(call)){
467 case LinphoneCallPaused:
468 if (linphone_call_get_refer_to (call)!=NULL){
469 return "Paused (transfered)";
474 case LinphoneCallPausedByRemote:
475 return "Paused by remote";
477 case LinphoneCallIncomingReceived:
480 case LinphoneCallOutgoingInit:
481 case LinphoneCallOutgoingProgress:
482 return "Dialing out";
484 case LinphoneCallOutgoingEarlyMedia:
485 case LinphoneCallOutgoingRinging:
486 return "Remote ringing";
489 if (linphone_call_has_transfer_pending(call)){
490 return "Running (transfer pending)";
498 lpc_cmd_call(LinphoneCore *lc, char *args)
500 if ( ! args || ! *args )
506 if ( linphone_core_in_call(lc) )
508 linphonec_out("Terminate or hold on the current call first.\n");
511 if ( NULL == (call=linphone_core_invite(lc, args)) )
513 linphonec_out("Error from linphone_core_invite.\n");
517 snprintf(callee_name,sizeof(callee_name),"%s",args);
524 lpc_cmd_calls(LinphoneCore *lc, char *args){
525 const MSList *calls = linphone_core_get_calls(lc);
528 const MSList *p_calls = calls;
529 linphonec_out("ID\t\tDestination\t\t\t\tStatus\n---------------------------------------------------------------------\n");
530 while(p_calls != NULL)
532 LinphoneCall *call=(LinphoneCall*)p_calls->data;
533 char *tmp=linphone_call_get_remote_address_as_string(call);
534 linphonec_out("%li\t%s\t\t\t%s\r\n",
535 (long)linphone_call_get_user_pointer (call),
537 get_call_status(call));
538 p_calls = p_calls->next;
543 linphonec_out("No active call.\n");
550 lpc_cmd_chat(LinphoneCore *lc, char *args)
558 /* Isolate first and second arg */
559 while(*ptr && !isspace(*ptr)) ++ptr;
564 while(*arg2 && isspace(*arg2)) ++arg2;
568 /* missing one parameter */
571 LinphoneChatRoom *cr = linphone_core_create_chat_room(lc,arg1);
572 linphone_chat_room_send_message(cr,arg2);
573 linphone_chat_room_destroy(cr);
578 const char *linphonec_get_callee(){
582 const char *linphonec_get_caller(){
586 void linphonec_set_caller(const char *caller){
587 snprintf(caller_name,sizeof(caller_name)-1,"%s",caller);
591 lpc_cmd_transfer(LinphoneCore *lc, char *args)
595 const char *refer_to=NULL;
598 int n=sscanf(args,"%s %s",arg1,arg2);
599 if (n==1 || isalpha(*arg1)){
600 call=linphone_core_get_current_call(lc);
601 if (call==NULL && linphone_core_get_calls_nb (lc)==1){
602 call=(LinphoneCall*)linphone_core_get_calls(lc)->data;
606 linphonec_out("No active call, please specify a call id among the ones listed by 'calls' command.\n");
611 refer_to=args+strlen(arg1)+1;
612 call=linphonec_get_call(id);
613 if (call==NULL) return 0;
615 linphone_core_transfer_call(lc, call, refer_to);
617 linphonec_out("Transfer command requires at least one argument\n");
624 lpc_cmd_terminate(LinphoneCore *lc, char *args)
626 if (linphone_core_get_calls(lc)==NULL){
627 linphonec_out("No active calls");
632 if ( -1 == linphone_core_terminate_call(lc, NULL) ){
633 linphonec_out("Could not stop the active call.\n");
638 if(strcmp(args,"all")==0){
639 linphonec_out("We are going to stop all the calls.\n");
640 linphone_core_terminate_all_calls(lc);
643 /*the argument is a linphonec call id */
645 LinphoneCall *call=linphonec_get_call(id);
647 if (linphone_core_terminate_call(lc,call)==-1){
648 linphonec_out("Could not stop the call with id %li",id);
658 lpc_cmd_answer(LinphoneCore *lc, char *args){
661 int nb=ms_list_size(linphone_core_get_calls(lc));
663 //if just one call is present answer the only one in passing NULL to the linphone_core_accept_call ...
664 if ( -1 == linphone_core_accept_call(lc, NULL) )
666 linphonec_out("Fail to accept incoming call\n");
669 linphonec_out("There are no calls to answer.\n");
671 linphonec_out("Multiple calls in progress, please specify call id.\n");
677 if (sscanf(args,"%li",&id)==1){
678 LinphoneCall *call=linphonec_get_call (id);
679 if (linphone_core_accept_call (lc,call)==-1){
680 linphonec_out("Fail to accept call %i\n",id);
689 lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
693 if ( linphonec_get_autoanswer() ) {
694 linphonec_out("Auto answer is enabled. Use 'autoanswer disable' to disable.\n");
696 linphonec_out("Auto answer is disabled. Use 'autoanswer enable' to enable.\n");
701 if (strstr(args,"enable")){
702 linphonec_set_autoanswer(TRUE);
703 linphonec_out("Auto answer enabled.\n");
704 }else if (strstr(args,"disable")){
705 linphonec_set_autoanswer(FALSE);
706 linphonec_out("Auto answer disabled.\n");
712 lpc_cmd_quit(LinphoneCore *lc, char *args)
714 linphonec_main_loop_exit();
719 lpc_cmd_nat(LinphoneCore *lc, char *args)
724 if ( args ) args=lpc_strip_blanks(args);
728 linphone_core_set_nat_address(lc, args);
729 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS); */
732 nat = linphone_core_get_nat_address(lc);
733 use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress;
734 linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
740 lpc_cmd_stun(LinphoneCore *lc, char *args)
745 if ( args ) args=lpc_strip_blanks(args);
749 linphone_core_set_stun_server(lc, args);
750 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN); */
753 stun = linphone_core_get_stun_server(lc);
754 use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseStun;
755 linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
761 lpc_cmd_firewall(LinphoneCore *lc, char *args)
763 const char* setting=NULL;
765 if ( args ) args=lpc_strip_blanks(args);
769 if (strcmp(args,"none")==0)
771 linphone_core_set_firewall_policy(lc,LinphonePolicyNoFirewall);
773 else if (strcmp(args,"stun")==0)
775 setting = linphone_core_get_stun_server(lc);
778 linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
781 linphone_core_set_firewall_policy(lc,LinphonePolicyUseStun);
783 else if (strcmp(args,"nat")==0)
785 setting = linphone_core_get_nat_address(lc);
788 linphonec_out("No nat address is defined, use 'nat <address>' first");
791 linphone_core_set_firewall_policy(lc,LinphonePolicyUseNatAddress);
795 switch(linphone_core_get_firewall_policy(lc))
797 case LinphonePolicyNoFirewall:
798 linphonec_out("No firewall\n");
800 case LinphonePolicyUseStun:
801 linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
803 case LinphonePolicyUseNatAddress:
804 linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
811 /* Helper function for processing freind names */
813 lpc_friend_name(char **args, char **name)
815 /* Use space as a terminator unless quoted */
816 if (('"' == **args) || ('\'' == **args)){
821 while ((delim != *end) && ('\0' != *end)) end++;
823 fprintf(stderr, "Mismatched quotes\n");
830 *name = strsep(args, " ");
832 if (NULL == *args) { /* Means there was no separator */
833 fprintf(stderr, "Either name or address is missing\n");
836 if (NULL == *name) return 0;
843 lpc_cmd_friend(LinphoneCore *lc, char *args)
847 if ( args ) args=lpc_strip_blanks(args);
849 if ( ! args || ! *args ) return 0;
851 if ( !strncmp(args, "list", 4) )
853 return linphonec_friend_list(lc, args+4);
856 else if ( !strncmp(args, "call", 4) )
859 if ( ! *args ) return 0;
860 friend_num = strtol(args, NULL, 10);
862 if ( errno == ERANGE ) {
863 linphonec_out("Invalid friend number\n");
866 #endif /*_WIN32_WCE*/
867 linphonec_friend_call(lc, friend_num);
870 else if ( !strncmp(args, "delete", 6) )
873 if ( ! *args ) return 0;
874 while (*args == ' ') args++;
875 if ( ! *args ) return 0;
876 if (!strncmp(args, "all", 3))
882 friend_num = strtol(args, NULL, 10);
884 if ( errno == ERANGE ) {
885 linphonec_out("Invalid friend number\n");
888 #endif /*_WIN32_WCE*/
890 linphonec_friend_delete(lc, friend_num);
893 else if ( !strncmp(args, "add", 3) )
902 if ( ! *args ) return 0;
903 while (*args == ' ') args++;
904 if ( ! *args ) return 0;
906 if (!lpc_friend_name(&args, &name)) return 0;
908 while (*args == ' ') args++;
909 if ( ! *args ) return 0;
910 if (isdigit(*args)) {
911 strcpy (addr, "sip:");
912 addr_p = addr + strlen("sip:");
914 addr_orig = strsep(&args, " ");
915 if (1 >= strlen(addr_orig)) {
916 fprintf(stderr, "A single-digit address is not valid\n");
919 strcpy(addr_p, addr_orig);
920 linphonec_friend_add(lc, name, addr);
922 LinphoneFriend *new_friend;
923 new_friend = linphone_friend_new_with_addr(args);
924 linphone_core_add_friend(lc, new_friend);
931 static int lpc_cmd_play(LinphoneCore *lc, char *args){
932 if ( args ) args=lpc_strip_blanks(args);
933 if ( ! args || ! *args ) return 0;
934 linphone_core_set_play_file(lc,args);
938 static int lpc_cmd_record(LinphoneCore *lc, char *args){
939 if ( args ) args=lpc_strip_blanks(args);
940 if ( ! args || ! *args ) return 0;
941 linphone_core_set_record_file(lc,args);
949 lpc_cmd_proxy(LinphoneCore *lc, char *args)
956 if ( ! arg1 ) return 0;
958 /* Isolate first and second arg */
959 while(*ptr && !isspace(*ptr)) ++ptr;
964 while(*arg2 && isspace(*arg2)) ++arg2;
967 if (strcmp(arg1,"add")==0)
970 rl_inhibit_completion=1;
972 linphonec_proxy_add(lc);
974 rl_inhibit_completion=0;
977 else if (strcmp(arg1,"list")==0)
979 linphonec_proxy_list(lc);
981 else if (strcmp(arg1,"remove")==0)
983 linphonec_proxy_remove(lc,atoi(arg2));
985 else if (strcmp(arg1,"use")==0)
990 if ( linphonec_proxy_use(lc, proxynum) )
991 linphonec_out("Default proxy set to %d.\n", proxynum);
995 proxynum=linphone_core_get_default_proxy(lc, NULL);
996 if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
997 else linphonec_out("Current default proxy is %d.\n", proxynum);
999 }else if (strcmp(arg1, "unuse")==0){
1000 linphone_core_set_default_proxy(lc, NULL);
1001 linphonec_out("Use no proxy.\n");
1004 else if (strcmp(arg1, "show")==0)
1008 if (strstr(arg2,"default"))
1010 proxynum=linphone_core_get_default_proxy(lc, NULL);
1011 if ( proxynum < 0 ) {
1012 linphonec_out("No default proxy defined\n");
1015 linphonec_proxy_show(lc,proxynum);
1019 linphonec_proxy_show(lc, atoi(arg2));
1022 else return 0; /* syntax error */
1027 return 0; /* syntax error */
1034 lpc_cmd_call_logs(LinphoneCore *lc, char *args)
1036 const MSList *elem=linphone_core_get_call_logs(lc);
1037 for (;elem!=NULL;elem=ms_list_next(elem))
1039 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
1040 char *str=linphone_call_log_to_str(cl);
1041 linphonec_out("%s\n",str);
1048 lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
1052 return 0; /* syntax error */
1055 if (strcmp(arg1,"status")==0)
1057 linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
1059 else if (strcmp(arg1,"enable")==0)
1061 linphone_core_enable_ipv6(lc,TRUE);
1062 linphonec_out("ipv6 use enabled.\n");
1064 else if (strcmp(arg1,"disable")==0)
1066 linphone_core_enable_ipv6(lc,FALSE);
1067 linphonec_out("ipv6 use disabled.\n");
1071 return 0; /* syntax error */
1076 static int devname_to_index(LinphoneCore *lc, const char *devname){
1079 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1080 if (strcmp(devname,*p)==0) return i;
1085 static const char *index_to_devname(LinphoneCore *lc, int index){
1088 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1089 if (i==index) return *p;
1094 static int lpc_cmd_soundcard(LinphoneCore *lc, char *args)
1102 if (!args) return 0; /* syntax error */
1104 /* Isolate first and second arg */
1105 while(*ptr && !isspace(*ptr)) ++ptr;
1110 while(*arg2 && isspace(*arg2)) ++arg2;
1113 if (strcmp(arg1, "list")==0)
1115 dev=linphone_core_get_sound_devices(lc);
1116 for(i=0; dev[i]!=NULL; ++i){
1117 linphonec_out("%i: %s\n",i,dev[i]);
1122 if (strcmp(arg1, "show")==0)
1124 linphonec_out("Ringer device: %s\n",
1125 linphone_core_get_ringer_device(lc));
1126 linphonec_out("Playback device: %s\n",
1127 linphone_core_get_playback_device(lc));
1128 linphonec_out("Capture device: %s\n",
1129 linphone_core_get_capture_device(lc));
1133 if (strcmp(arg1, "use")==0 && arg2)
1135 if (strcmp(arg2, "files")==0)
1137 linphonec_out("Using wav files instead of soundcard.\n");
1138 linphone_core_use_files(lc,TRUE);
1142 dev=linphone_core_get_sound_devices(lc);
1143 index=atoi(arg2); /* FIXME: handle not-a-number */
1144 for(i=0;dev[i]!=NULL;i++)
1146 if (i!=index) continue;
1148 linphone_core_set_ringer_device(lc,dev[i]);
1149 linphone_core_set_playback_device(lc,dev[i]);
1150 linphone_core_set_capture_device(lc,dev[i]);
1151 linphonec_out("Using sound device %s\n",dev[i]);
1154 linphonec_out("No such sound device\n");
1157 if (strcmp(arg1, "capture")==0)
1159 const char *devname=linphone_core_get_capture_device(lc);
1161 linphonec_out("Using capture device #%i (%s)\n",
1162 devname_to_index(lc,devname),devname);
1164 index=atoi(arg2); /* FIXME: handle not-a-number */
1165 devname=index_to_devname(lc,index);
1167 linphone_core_set_capture_device(lc,devname);
1168 linphonec_out("Using capture sound device %s\n",devname);
1171 linphonec_out("No such sound device\n");
1175 if (strcmp(arg1, "playback")==0)
1177 const char *devname=linphone_core_get_playback_device(lc);
1179 linphonec_out("Using playback device #%i (%s)\n",
1180 devname_to_index(lc,devname),devname);
1182 index=atoi(arg2); /* FIXME: handle not-a-number */
1183 devname=index_to_devname(lc,index);
1185 linphone_core_set_playback_device(lc,devname);
1186 linphonec_out("Using playback sound device %s\n",devname);
1189 linphonec_out("No such sound device\n");
1193 if (strcmp(arg1, "ring")==0)
1195 const char *devname=linphone_core_get_ringer_device(lc);
1197 linphonec_out("Using ring device #%i (%s)\n",
1198 devname_to_index(lc,devname),devname);
1200 index=atoi(arg2); /* FIXME: handle not-a-number */
1201 devname=index_to_devname(lc,index);
1203 linphone_core_set_ringer_device(lc,devname);
1204 linphonec_out("Using ring sound device %s\n",devname);
1207 linphonec_out("No such sound device\n");
1211 return 0; /* syntax error */
1214 static int lpc_cmd_webcam(LinphoneCore *lc, char *args)
1222 if (!args) return 0; /* syntax error */
1224 /* Isolate first and second arg */
1225 while(*ptr && !isspace(*ptr)) ++ptr;
1230 while(*arg2 && isspace(*arg2)) ++arg2;
1233 if (strcmp(arg1, "list")==0)
1235 dev=linphone_core_get_video_devices(lc);
1236 for(i=0; dev[i]!=NULL; ++i){
1237 linphonec_out("%i: %s\n",i,dev[i]);
1242 if (strcmp(arg1, "use")==0 && arg2)
1244 dev=linphone_core_get_video_devices(lc);
1245 index=atoi(arg2); /* FIXME: handle not-a-number */
1246 for(i=0;dev[i]!=NULL;i++)
1248 if (i!=index) continue;
1250 linphone_core_set_video_device(lc, dev[i]);
1251 linphonec_out("Using video device %s\n",dev[i]);
1254 linphonec_out("No such video device\n");
1257 return 0; /* syntax error */
1261 lpc_cmd_staticpic(LinphoneCore *lc, char *args)
1267 if (!args) return 0; /* Syntax error */
1269 /* Isolate first and second arg */
1270 while(*ptr && !isspace(*ptr)) ++ptr;
1275 while(*arg2 && isspace(*arg2)) ++arg2;
1278 if (strcmp(arg1, "set")==0 && arg2) {
1279 linphone_core_set_static_picture(lc, arg2);
1283 if (strcmp(arg1, "fps")==0) {
1285 float fps = atof(arg2); /* FIXME: Handle not-a-float */
1286 linphone_core_set_static_picture_fps(lc, fps);
1290 fps = linphone_core_get_static_picture_fps(lc);
1291 linphonec_out("Current FPS %f\n", fps);
1296 return 0; /* Syntax error */
1299 static int lpc_cmd_pause(LinphoneCore *lc, char *args){
1301 if(linphone_core_in_call(lc))
1303 linphone_core_pause_call(lc,linphone_core_get_current_call(lc));
1306 linphonec_out("you can only pause when a call is in process\n");
1310 static int lpc_cmd_resume(LinphoneCore *lc, char *args){
1312 if(linphone_core_in_call(lc))
1314 linphonec_out("There is already a call in process pause or stop it first");
1320 int n = sscanf(args, "%li", &id);
1322 LinphoneCall *call=linphonec_get_call (id);
1324 if(linphone_core_resume_call(lc,call)==-1){
1325 linphonec_out("There was a problem to resume the call check the remote address you gave %s\n",args);
1333 const MSList *calls = linphone_core_get_calls(lc);
1334 int nbcalls=ms_list_size(calls);
1337 if(linphone_core_resume_call(lc,calls->data) < 0)
1339 linphonec_out("There was a problem to resume the unique call.\n");
1342 }else if (nbcalls==0){
1343 linphonec_out("There is no calls at this time.\n");
1346 linphonec_out("There are %i calls at this time, please specify call id as given with 'calls' command.\n");
1353 /***************************************************************************
1355 * Commands helper functions
1357 ***************************************************************************/
1361 linphonec_proxy_add(LinphoneCore *lc)
1363 bool_t enable_register=FALSE;
1364 LinphoneProxyConfig *cfg;
1366 linphonec_out("Adding new proxy setup. Hit ^D to abort.\n");
1373 char *input=linphonec_readline("Enter proxy sip address: ");
1377 linphonec_out("Aborted.\n");
1382 clean=lpc_strip_blanks(input);
1388 cfg=linphone_proxy_config_new();
1389 if (linphone_proxy_config_set_server_addr(cfg,clean)<0)
1391 linphonec_out("Invalid sip address (sip:sip.domain.tld).\n");
1393 linphone_proxy_config_destroy(cfg);
1401 * SIP Proxy identity
1405 char *input=linphonec_readline("Your identity for this proxy: ");
1409 linphonec_out("Aborted.\n");
1410 linphone_proxy_config_destroy(cfg);
1415 clean=lpc_strip_blanks(input);
1421 linphone_proxy_config_set_identity(cfg, clean);
1422 if ( ! cfg->reg_identity )
1424 linphonec_out("Invalid identity (sip:name@sip.domain.tld).\n");
1433 * SIP Proxy enable register
1437 char *input=linphonec_readline("Do you want to register on this proxy (yes/no): ");
1441 linphonec_out("Aborted.\n");
1442 linphone_proxy_config_destroy(cfg);
1447 clean=lpc_strip_blanks(input);
1453 if ( ! strcmp(clean, "yes") ) enable_register=TRUE;
1454 else if ( ! strcmp(clean, "no") ) enable_register=FALSE;
1456 linphonec_out("Please answer with 'yes' or 'no'\n");
1460 linphone_proxy_config_enableregister(cfg, enable_register);
1466 * SIP Proxy registration expiration
1468 if ( enable_register==TRUE )
1473 char *input=linphonec_readline("Specify register expiration time"
1474 " in seconds (default is 600): ");
1477 linphonec_out("Aborted.\n");
1478 linphone_proxy_config_destroy(cfg);
1482 expires=strtol(input, (char **)NULL, 10);
1483 if ( expires == LONG_MIN || expires == LONG_MAX )
1485 linphonec_out("Invalid value: %s\n", strerror(errno));
1490 linphone_proxy_config_expires(cfg, expires);
1491 linphonec_out("Expiration: %d seconds\n", cfg->expires);
1503 char *input=linphonec_readline("Specify route if needed: ");
1507 linphonec_out("Aborted.\n");
1508 linphone_proxy_config_destroy(cfg);
1513 clean=lpc_strip_blanks(input);
1516 linphonec_out("No route specified.\n");
1520 linphone_proxy_config_set_route(cfg, clean);
1521 if ( ! cfg->reg_route )
1523 linphonec_out("Invalid route.\n");
1533 * Final confirmation
1540 linphonec_out("--------------------------------------------\n");
1541 linphonec_proxy_display(cfg);
1542 linphonec_out("--------------------------------------------\n");
1543 input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: ");
1547 linphonec_out("Aborted.\n");
1548 linphone_proxy_config_destroy(cfg);
1553 clean=lpc_strip_blanks(input);
1559 if ( ! strcmp(clean, "yes") ) break;
1560 else if ( ! strcmp(clean, "no") )
1562 linphonec_out("Declined.\n");
1563 linphone_proxy_config_destroy(cfg);
1568 linphonec_out("Please answer with 'yes' or 'no'\n");
1574 linphone_core_add_proxy_config(lc,cfg);
1576 /* automatically set the last entered proxy as the default one */
1577 linphone_core_set_default_proxy(lc,cfg);
1579 linphonec_out("Proxy added.\n");
1583 linphonec_proxy_display(LinphoneProxyConfig *cfg)
1585 linphonec_out("sip address: %s\nroute: %s\nidentity: %s\nregister: %s\nexpires: %i\nregistered: %s\n",
1587 (cfg->reg_route!=NULL)?cfg->reg_route:"",
1588 (cfg->reg_identity!=NULL)?cfg->reg_identity:"",
1589 (cfg->reg_sendregister)?"yes":"no",
1591 linphone_proxy_config_is_registered(cfg) ? "yes" : "no");
1594 static void linphonec_proxy_show(LinphoneCore *lc, int index)
1598 for(elem=linphone_core_get_proxy_config_list(lc),i=0;elem!=NULL;elem=elem->next,++i){
1600 LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)elem->data;
1601 linphonec_proxy_display(cfg);
1605 linphonec_out("No proxy with index %i\n", index);
1609 linphonec_proxy_list(LinphoneCore *lc)
1611 const MSList *proxies;
1613 int def=linphone_core_get_default_proxy(lc,NULL);
1615 proxies=linphone_core_get_proxy_config_list(lc);
1616 for(n=0;proxies!=NULL;proxies=ms_list_next(proxies),n++){
1618 linphonec_out("****** Proxy %i - this is the default one - *******\n",n);
1620 linphonec_out("****** Proxy %i *******\n",n);
1621 linphonec_proxy_display((LinphoneProxyConfig*)proxies->data);
1623 if ( ! n ) linphonec_out("No proxies defined\n");
1627 linphonec_proxy_remove(LinphoneCore *lc, int index)
1629 const MSList *proxies;
1630 LinphoneProxyConfig *cfg;
1631 proxies=linphone_core_get_proxy_config_list(lc);
1632 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1634 linphonec_out("No such proxy.\n");
1637 linphone_core_remove_proxy_config(lc,cfg);
1638 linphonec_out("Proxy %s removed.\n", cfg->reg_proxy);
1639 linphone_proxy_config_destroy(cfg);
1643 linphonec_proxy_use(LinphoneCore *lc, int index)
1645 const MSList *proxies;
1646 LinphoneProxyConfig *cfg;
1647 proxies=linphone_core_get_proxy_config_list(lc);
1648 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1650 linphonec_out("No such proxy (try 'proxy list').");
1653 linphone_core_set_default_proxy(lc,cfg);
1658 linphonec_friend_display(LinphoneFriend *fr)
1660 LinphoneAddress *uri=linphone_address_clone(linphone_friend_get_address(fr));
1663 linphonec_out("name: %s\n", linphone_address_get_display_name(uri));
1664 linphone_address_set_display_name(uri,NULL);
1665 str=linphone_address_as_string(uri);
1666 linphonec_out("address: %s\n", str);
1670 linphonec_friend_list(LinphoneCore *lc, char *pat)
1672 const MSList *friend;
1676 pat=lpc_strip_blanks(pat);
1677 if (!*pat) pat = NULL;
1680 friend = linphone_core_get_friend_list(lc);
1681 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1684 const char *name = linphone_address_get_display_name(
1685 linphone_friend_get_address((LinphoneFriend*)friend->data));
1686 if (name && ! strstr(name, pat) ) continue;
1688 linphonec_out("****** Friend %i *******\n",n);
1689 linphonec_friend_display((LinphoneFriend*)friend->data);
1696 linphonec_friend_call(LinphoneCore *lc, unsigned int num)
1698 const MSList *friend = linphone_core_get_friend_list(lc);
1702 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1707 addr = linphone_address_as_string(linphone_friend_get_address((LinphoneFriend*)friend->data));
1708 ret=lpc_cmd_call(lc, addr);
1713 linphonec_out("No such friend %u\n", num);
1719 linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr)
1721 LinphoneFriend *newFriend;
1725 snprintf(url, PATH_MAX, "%s <%s>", name, addr);
1726 newFriend = linphone_friend_new_with_addr(url);
1727 linphone_core_add_friend(lc, newFriend);
1733 linphonec_friend_delete(LinphoneCore *lc, int num)
1735 const MSList *friend = linphone_core_get_friend_list(lc);
1738 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1742 linphone_core_remove_friend(lc, friend->data);
1750 for (i = 0 ; i < n ; i++)
1751 linphonec_friend_delete(lc, 0);
1755 linphonec_out("No such friend %u\n", num);
1760 linphonec_display_command_help(LPC_COMMAND *cmd)
1762 if ( cmd->doc ) linphonec_out ("%s\n", cmd->doc);
1763 else linphonec_out("%s\n", cmd->help);
1767 static int lpc_cmd_register(LinphoneCore *lc, char *args){
1771 LinphoneProxyConfig *cfg;
1776 /* it means that you want to register the default proxy */
1777 LinphoneProxyConfig *cfg=NULL;
1778 linphone_core_get_default_proxy(lc,&cfg);
1781 if(!linphone_proxy_config_is_registered(cfg)) {
1782 linphone_proxy_config_enable_register(cfg,TRUE);
1783 linphone_proxy_config_done(cfg);
1785 linphonec_out("default proxy already registered\n");
1788 linphonec_out("we do not have a default proxy\n");
1793 passwd[0]=proxy[0]=identity[0]='\0';
1794 sscanf(args,"%s %s %s",identity,proxy,passwd);
1795 if (proxy[0]=='\0' || identity[0]=='\0'){
1796 linphonec_out("Missing parameters, see help register\n");
1799 if (passwd[0]!='\0'){
1800 LinphoneAddress *from;
1801 LinphoneAuthInfo *info;
1802 if ((from=linphone_address_new(identity))!=NULL){
1804 snprintf(realm,sizeof(realm)-1,"\"%s\"",linphone_address_get_domain(from));
1805 info=linphone_auth_info_new(linphone_address_get_username(from),NULL,passwd,NULL,NULL);
1806 linphone_core_add_auth_info(lc,info);
1807 linphone_address_destroy(from);
1808 linphone_auth_info_destroy(info);
1811 elem=linphone_core_get_proxy_config_list(lc);
1813 cfg=(LinphoneProxyConfig*)elem->data;
1814 linphone_proxy_config_edit(cfg);
1816 else cfg=linphone_proxy_config_new();
1817 linphone_proxy_config_set_identity(cfg,identity);
1818 linphone_proxy_config_set_server_addr(cfg,proxy);
1819 linphone_proxy_config_enable_register(cfg,TRUE);
1820 if (elem) linphone_proxy_config_done(cfg);
1821 else linphone_core_add_proxy_config(lc,cfg);
1822 linphone_core_set_default_proxy(lc,cfg);
1826 static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
1827 LinphoneProxyConfig *cfg=NULL;
1828 linphone_core_get_default_proxy(lc,&cfg);
1829 if (cfg && linphone_proxy_config_is_registered(cfg)) {
1830 linphone_proxy_config_edit(cfg);
1831 linphone_proxy_config_enable_register(cfg,FALSE);
1832 linphone_proxy_config_done(cfg);
1834 linphonec_out("unregistered\n");
1839 static int lpc_cmd_duration(LinphoneCore *lc, char *args){
1840 LinphoneCallLog *cl;
1841 const MSList *elem=linphone_core_get_call_logs(lc);
1842 for(;elem!=NULL;elem=elem->next){
1843 if (elem->next==NULL){
1844 cl=(LinphoneCallLog*)elem->data;
1845 linphonec_out("%i seconds\n",cl->duration);
1851 static int lpc_cmd_status(LinphoneCore *lc, char *args)
1853 LinphoneProxyConfig *cfg;
1855 if ( ! args ) return 0;
1856 linphone_core_get_default_proxy(lc,&cfg);
1857 if (strstr(args,"register"))
1861 if (linphone_proxy_config_is_registered(cfg)){
1862 linphonec_out("registered, identity=%s duration=%i\n",
1863 linphone_proxy_config_get_identity(cfg),
1864 linphone_proxy_config_get_expires(cfg));
1865 }else if (linphone_proxy_config_register_enabled(cfg)){
1866 linphonec_out("registered=-1\n");
1867 }else linphonec_out("registered=0\n");
1869 else linphonec_out("registered=0\n");
1871 else if (strstr(args,"autoanswer"))
1873 if (cfg && linphone_proxy_config_is_registered(cfg))
1874 linphonec_out("autoanswer=%i\n",linphonec_get_autoanswer());
1875 else linphonec_out("unregistered\n");
1877 else if (strstr(args,"hook"))
1879 LinphoneCall *call=linphone_core_get_current_call (lc);
1880 LinphoneCallState call_state=LinphoneCallIdle;
1881 if (call) call_state=linphone_call_get_state(call);
1884 case LinphoneCallOutgoingInit:
1885 case LinphoneCallOutgoingProgress:
1886 linphonec_out("hook=dialing\n");
1888 case LinphoneCallIdle:
1889 linphonec_out("hook=offhook\n");
1891 case LinphoneCallStreamsRunning:
1892 case LinphoneCallConnected:
1893 if (linphone_call_get_dir(call)==LinphoneCallOutgoing){
1894 linphonec_out("Call out, hook=%s duration=%i, muted=%s rtp-xmit-muted=%s\n", linphonec_get_callee(),
1895 linphone_core_get_current_call_duration(lc),
1896 linphone_core_is_mic_muted (lc) ? "yes" : "no",
1897 linphone_core_is_rtp_muted(lc) ? "yes" : "no");
1899 linphonec_out("hook=answered duration=%i\n" ,
1900 linphone_core_get_current_call_duration(lc));
1903 case LinphoneCallIncomingReceived:
1904 linphonec_out("Incoming call from %s\n",linphonec_get_caller());
1916 static int lpc_cmd_ports(LinphoneCore *lc, char *args)
1920 linphonec_out("sip port = %i\naudio rtp port = %i\nvideo rtp port = %i\n",
1921 linphone_core_get_sip_port(lc),
1922 linphone_core_get_audio_port(lc),
1923 linphone_core_get_video_port(lc));
1926 if (sscanf(args,"sip %i",&port)==1){
1927 linphonec_out("Setting sip port to %i\n",port);
1928 linphone_core_set_sip_port(lc,port);
1934 static int lpc_cmd_speak(LinphoneCore *lc, char *args){
1943 if (!args) return 0;
1944 memset(voice,0,sizeof(voice));
1945 sscanf(args,"%s63",voice);
1946 sentence=args+strlen(voice);
1947 wavfile=tempnam("/tmp/","linphonec-espeak-");
1948 snprintf(cl,sizeof(cl),"espeak -v %s -s 100 -w %s --stdin",voice,wavfile);
1951 ms_error("Could not open pipe to espeak !");
1954 fprintf(file,"%s",sentence);
1955 status=pclose(file);
1956 if (WEXITSTATUS(status)==0){
1957 linphone_core_set_play_file(lc,wavfile);
1959 linphonec_out("espeak command failed.");
1962 linphonec_out("Sorry, this command is not implemented in windows version.");
1967 static int lpc_cmd_acodec(LinphoneCore *lc, char *args){
1968 return lpc_cmd_codec(AUDIO, lc, args);
1971 static int lpc_cmd_vcodec(LinphoneCore *lc, char *args){
1972 return lpc_cmd_codec(VIDEO, lc, args);
1975 static int lpc_cmd_codec(int type, LinphoneCore *lc, char *args){
1980 if (!args) return 0;
1982 /* Isolate first and second arg */
1983 while(*ptr && !isspace(*ptr)) ++ptr;
1988 while(*arg2 && isspace(*arg2)) ++arg2;
1991 if (strcmp(arg1,"enable")==0)
1993 #ifdef HAVE_READLINE
1994 rl_inhibit_completion=1;
1996 if (!strcmp(arg2,"all")) linphonec_codec_enable(type,lc,-1);
1997 else linphonec_codec_enable(type,lc,atoi(arg2));
1998 #ifdef HAVE_READLINE
1999 rl_inhibit_completion=0;
2002 else if (strcmp(arg1,"list")==0)
2004 linphonec_codec_list(type,lc);
2006 else if (strcmp(arg1,"disable")==0)
2008 if (!strcmp(arg2,"all")) linphonec_codec_disable(type,lc,-1);
2009 else linphonec_codec_disable(type,lc,atoi(arg2));
2013 return 0; /* syntax error */
2019 static void linphonec_codec_list(int type, LinphoneCore *lc){
2021 codecs_config_t *config=&lc->codecs_conf;
2025 if (type == AUDIO) {
2026 node=config->audio_codecs;
2027 } else if(type==VIDEO) {
2028 node=config->video_codecs;
2031 for(;node!=NULL;node=ms_list_next(node)){
2032 pt=(PayloadType*)(node->data);
2033 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate,
2034 linphone_core_payload_type_enabled(lc,pt) ? "enabled" : "disabled");
2039 static void linphonec_codec_enable(int type, LinphoneCore *lc, int sel_index){
2041 codecs_config_t *config=&lc->codecs_conf;
2045 if (type == AUDIO) {
2046 node=config->audio_codecs;
2047 } else if(type==VIDEO) {
2048 node=config->video_codecs;
2051 for(;node!=NULL;node=ms_list_next(node)){
2052 if (index == sel_index || sel_index == -1) {
2053 pt=(PayloadType*)(node->data);
2054 pt->flags|=PAYLOAD_TYPE_ENABLED;
2055 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "enabled");
2061 static void linphonec_codec_disable(int type, LinphoneCore *lc, int sel_index){
2063 codecs_config_t *config=&lc->codecs_conf;
2067 if (type == AUDIO) {
2068 node=config->audio_codecs;
2069 } else if(type==VIDEO) {
2070 node=config->video_codecs;
2073 for(;node!=NULL;node=ms_list_next(node)){
2074 if (index == sel_index || sel_index == -1) {
2075 pt=(PayloadType*)(node->data);
2076 pt->flags&=~PAYLOAD_TYPE_ENABLED;
2077 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "disabled");
2083 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){
2088 if (!args) return 0;
2090 /* Isolate first and second arg */
2091 while(*ptr && !isspace(*ptr)) ++ptr;
2096 while(*arg2 && isspace(*arg2)) ++arg2;
2099 if (strcmp(arg1,"on")==0){
2100 int delay, tail_len, frame_size;
2103 linphone_core_enable_echo_cancellation(lc,1);
2106 n = sscanf(arg2, "%d %d %d", &delay, &tail_len, &frame_size);
2109 lp_config_set_int(lc->config,"sound","ec_delay",delay);
2112 lp_config_set_int(lc->config,"sound","ec_delay",delay);
2113 lp_config_set_int(lc->config,"sound","ec_tail_len",tail_len);
2116 lp_config_set_int(lc->config,"sound","ec_delay",delay);
2117 lp_config_set_int(lc->config,"sound","ec_tail_len",tail_len);
2118 lp_config_set_int(lc->config,"sound","ec_framesize",frame_size);
2122 else if (strcmp(arg1,"off")==0){
2123 linphone_core_enable_echo_cancellation(lc,0);
2125 else if (strcmp(arg1,"show")==0){
2126 linphonec_out("echo cancellation is %s; delay %d, tail length %d, frame size %d\n",
2127 linphone_core_echo_cancellation_enabled(lc) ? "on" : "off",
2128 lp_config_get_int(lc->config,"sound","ec_delay",0),
2129 lp_config_get_int(lc->config,"sound","ec_tail_len",0),
2130 lp_config_get_int(lc->config,"sound","ec_framesize",0));
2139 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args)
2141 linphone_core_mute_mic(lc, 1);
2145 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args){
2146 linphone_core_mute_mic(lc, 0);
2150 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args)
2152 bool_t rtp_xmit_off=FALSE;
2156 if(strstr(args,"1"))rtp_xmit_off=TRUE;
2157 if(linphone_core_get_current_call (lc)==NULL)
2158 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_xmit_off);
2160 linphonec_out("nortp-on-audio-mute: call in progress - cannot change state\n");
2162 rtp_xmit_off=linphone_core_get_rtp_no_xmit_on_audio_mute(lc);
2163 if (rtp_xmit_off) status="off";
2165 linphonec_out("rtp transmit %s when audio muted\n",status);
2169 static int lpc_cmd_video_window(LinphoneCore *lc, char *args){
2170 char subcommand[64];
2173 #ifdef VIDEO_ENABLED
2174 err=sscanf(args,"%s %i %i",subcommand,&a,&b);
2176 if (strcmp(subcommand,"pos")==0){
2177 if (err<3) return 0;
2178 lpc_video_params.x=a;
2179 lpc_video_params.y=b;
2180 lpc_video_params.refresh=TRUE;
2181 }else if (strcmp(subcommand,"size")==0){
2182 if (err<3) return 0;
2183 lpc_video_params.w=a;
2184 lpc_video_params.h=b;
2185 lpc_video_params.refresh=TRUE;
2186 }else if (strcmp(subcommand,"show")==0){
2187 lpc_video_params.show=TRUE;
2188 lpc_video_params.refresh=TRUE;
2189 }else if (strcmp(subcommand,"hide")==0){
2190 lpc_video_params.show=FALSE;
2191 lpc_video_params.refresh=TRUE;
2195 linphonec_out("Sorry, this version of linphonec wasn't compiled with video support.");
2200 static void lpc_display_global_state(LinphoneCore *lc){
2201 linphonec_out("****************Global liblinphone state********************\n\t%s",
2202 linphone_global_state_to_string(linphone_core_get_global_state(lc)));
2205 static void lpc_display_call_states(LinphoneCore *lc){
2209 linphonec_out("****************Calls states*******************************\nId | Destination | State\n");
2211 for(elem=linphone_core_get_calls(lc);elem!=NULL;elem=elem->next){
2212 call=(LinphoneCall*)elem->data;
2213 tmp=linphone_call_get_remote_address_as_string (call);
2214 linphonec_out("%2.2i|%10.10s|%s",(int)(long)linphone_call_get_user_pointer(call),
2215 tmp,linphone_call_state_to_string(linphone_call_get_state(call)));
2220 static void lpc_display_proxy_states(LinphoneCore *lc){
2222 linphonec_out("****************Proxy registration states*****************\nIdentity | State\n");
2223 for(elem=linphone_core_get_proxy_config_list (lc);elem!=NULL;elem=elem->next){
2224 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2225 linphonec_out("%20.10s | %s",linphone_proxy_config_get_identity (cfg),
2226 linphone_registration_state_to_string(linphone_proxy_config_get_state(cfg)));
2230 static int lpc_cmd_states(LinphoneCore *lc, char *args){
2232 lpc_display_global_state(lc);
2233 lpc_display_call_states(lc);
2234 lpc_display_proxy_states(lc);
2237 if (strcmp(args,"global")==0){
2238 lpc_display_global_state(lc);
2241 if (strcmp(args,"proxies")==0){
2242 lpc_display_proxy_states(lc);
2245 if (strcmp(args,"calls")==0){
2246 lpc_display_call_states(lc);
2252 /***************************************************************************
2254 * Command table management funx
2256 ***************************************************************************/
2259 * Find a command given its name
2261 static LPC_COMMAND *
2262 lpc_find_command(const char *name)
2266 for (i=0; commands[i].name; ++i)
2268 if (strcmp(name, commands[i].name) == 0)
2269 return &commands[i];
2272 for (i=0; advanced_commands[i].name; ++i)
2274 if (strcmp(name, advanced_commands[i].name) == 0)
2275 return &advanced_commands[i];
2278 return (LPC_COMMAND *)NULL;
2282 /****************************************************************************
2284 * $Log: commands.c,v $
2285 * Revision 1.39 2008/07/03 15:08:34 smorlat
2286 * api cleanups, interface in progress.
2288 * Revision 1.38 2008/06/17 20:38:59 smorlat
2289 * added missing file.
2291 * Revision 1.37 2008/04/09 09:26:00 smorlat
2292 * merge various patches
2295 * Revision 1.36 2007/08/01 14:47:53 strk
2296 * * console/commands.c: Clean up commands 'nat', 'stun'
2297 * and 'firewall' to be more intuitive.
2299 * Revision 1.35 2007/06/27 09:01:25 smorlat
2300 * logging improvements.
2302 * Revision 1.34 2007/02/20 10:17:13 smorlat
2303 * linphonec friends patch2
2305 * Revision 1.31 2006/09/22 07:22:47 smorlat
2306 * linphonecore api changes.
2308 * Revision 1.30 2006/09/08 15:32:57 smorlat
2309 * support for using files instead of soundcard (used by linphonec only)
2311 * Revision 1.29 2006/08/28 14:29:07 smorlat
2314 * Revision 1.28 2006/08/21 12:49:59 smorlat
2315 * merged several little patches.
2317 * Revision 1.27 2006/07/17 18:45:00 smorlat
2318 * support for several event queues in ortp.
2319 * glib dependency removed from coreapi/ and console/
2321 * Revision 1.26 2006/04/14 15:16:36 smorlat
2322 * soundcard use did nothing !
2324 * Revision 1.25 2006/04/06 20:09:33 smorlat
2325 * add linphonec command to see and select sound devices.
2327 * Revision 1.24 2006/03/04 11:17:10 smorlat
2328 * mediastreamer2 in progress.
2330 * Revision 1.23 2006/02/20 21:14:01 strk
2331 * Handled syntax errors with 'friend' command
2333 * Revision 1.22 2006/02/20 10:20:29 strk
2334 * Added substring-based filter support for command 'friend list'
2336 * Revision 1.21 2006/02/02 15:39:18 strk
2337 * - Added 'friend list' and 'friend call' commands
2338 * - Allowed for multiple DTFM send in a single line
2339 * - Added status-specific callback (bare version)
2341 * Revision 1.20 2006/01/26 11:54:34 strk
2342 * More robust 'nat' command handler (strip blanks in args)
2344 * Revision 1.19 2006/01/26 09:48:05 strk
2345 * Added limits.h include
2347 * Revision 1.18 2006/01/26 02:18:05 strk
2348 * Added new commands 'nat use' and 'nat unuse'.
2349 * These will required a pending patch to linphonecore.c
2352 * Revision 1.17 2006/01/20 14:12:33 strk
2353 * Added linphonec_init() and linphonec_finish() functions.
2354 * Handled SIGINT and SIGTERM to invoke linphonec_finish().
2355 * Handling of auto-termination (-t) moved to linphonec_finish().
2356 * Reworked main (input read) loop to not rely on 'terminate'
2357 * and 'run' variable (dropped). configfile_name allocated on stack
2358 * using PATH_MAX limit. Changed print_usage signature to allow
2359 * for an exit_status specification.
2361 * Revision 1.16 2006/01/18 09:25:32 strk
2362 * Command completion inhibited in proxy addition and auth request prompts.
2363 * Avoided use of linphonec_readline's internal filename completion.
2365 * Revision 1.15 2006/01/14 13:29:32 strk
2366 * Reworked commands interface to use a table structure,
2367 * used by command line parser and help function.
2368 * Implemented first level of completion (commands).
2369 * Added notification of invalid "answer" and "terminate"
2370 * commands (no incoming call, no active call).
2371 * Forbidden "call" intialization when a call is already active.
2372 * Cleaned up all commands, adding more feedback and error checks.
2374 * Revision 1.14 2006/01/13 13:00:29 strk
2375 * Added linphonec.h. Code layout change (added comments, forward decl,
2376 * globals on top, copyright notices and Logs). Handled out-of-memory
2377 * condition on history management. Removed assumption on sizeof(char).
2378 * Fixed bug in authentication prompt (introduced by linphonec_readline).
2379 * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
2382 ****************************************************************************/