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"
46 /***************************************************************************
48 * Forward declarations
50 ***************************************************************************/
52 extern char *lpc_strip_blanks(char *input);
54 /* Command handlers */
55 static int lpc_cmd_help(LinphoneCore *, char *);
56 static int lpc_cmd_proxy(LinphoneCore *, char *);
57 static int lpc_cmd_call(LinphoneCore *, char *);
58 static int lpc_cmd_calls(LinphoneCore *, char *);
59 static int lpc_cmd_chat(LinphoneCore *, char *);
60 static int lpc_cmd_answer(LinphoneCore *, char *);
61 static int lpc_cmd_autoanswer(LinphoneCore *, char *);
62 static int lpc_cmd_terminate(LinphoneCore *, char *);
63 static int lpc_cmd_call_logs(LinphoneCore *, char *);
64 static int lpc_cmd_ipv6(LinphoneCore *, char *);
65 static int lpc_cmd_transfer(LinphoneCore *, char *);
66 static int lpc_cmd_quit(LinphoneCore *, char *);
67 static int lpc_cmd_nat(LinphoneCore *, char *);
68 static int lpc_cmd_stun(LinphoneCore *, char *);
69 static int lpc_cmd_firewall(LinphoneCore *, char *);
70 static int lpc_cmd_friend(LinphoneCore *, char*);
71 static int lpc_cmd_soundcard(LinphoneCore *, char *);
72 static int lpc_cmd_webcam(LinphoneCore *, char *);
73 static int lpc_cmd_staticpic(LinphoneCore *, char *);
74 static int lpc_cmd_play(LinphoneCore *, char *);
75 static int lpc_cmd_record(LinphoneCore *, char *);
76 static int lpc_cmd_register(LinphoneCore *, char *);
77 static int lpc_cmd_unregister(LinphoneCore *, char *);
78 static int lpc_cmd_duration(LinphoneCore *lc, char *args);
79 static int lpc_cmd_status(LinphoneCore *lc, char *args);
80 static int lpc_cmd_ports(LinphoneCore *lc, char *args);
81 static int lpc_cmd_speak(LinphoneCore *lc, char *args);
82 static int lpc_cmd_acodec(LinphoneCore *lc, char *args);
83 static int lpc_cmd_vcodec(LinphoneCore *lc, char *args);
84 static int lpc_cmd_codec(int type, LinphoneCore *lc, char *args);
85 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args);
86 static int lpc_cmd_echolimiter(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 static int lpc_cmd_camera(LinphoneCore *lc, char *args);
94 static int lpc_cmd_video_window(LinphoneCore *lc, char *args);
95 static int lpc_cmd_preview_window(LinphoneCore *lc, char *args);
96 static int lpc_cmd_snapshot(LinphoneCore *lc, char *args);
98 static int lpc_cmd_states(LinphoneCore *lc, char *args);
99 static int lpc_cmd_identify(LinphoneCore *lc, char *args);
100 static int lpc_cmd_ringback(LinphoneCore *lc, char *args);
102 /* Command handler helpers */
103 static void linphonec_proxy_add(LinphoneCore *lc);
104 static void linphonec_proxy_display(LinphoneProxyConfig *lc);
105 static void linphonec_proxy_list(LinphoneCore *lc);
106 static void linphonec_proxy_remove(LinphoneCore *lc, int index);
107 static int linphonec_proxy_use(LinphoneCore *lc, int index);
108 static void linphonec_proxy_show(LinphoneCore *lc,int index);
109 static void linphonec_friend_display(LinphoneFriend *fr);
110 static int linphonec_friend_list(LinphoneCore *lc, char *arg);
111 static void linphonec_display_command_help(LPC_COMMAND *cmd);
112 static int linphonec_friend_call(LinphoneCore *lc, unsigned int num);
114 static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
116 static int linphonec_friend_delete(LinphoneCore *lc, int num);
117 static int linphonec_friend_delete(LinphoneCore *lc, int num);
118 static void linphonec_codec_list(int type, LinphoneCore *lc);
119 static void linphonec_codec_enable(int type, LinphoneCore *lc, int index);
120 static void linphonec_codec_disable(int type, LinphoneCore *lc, int index);
124 /* Command table management */
125 static LPC_COMMAND *lpc_find_command(const char *name);
127 void linphonec_out(const char *fmt,...);
129 VideoParams lpc_video_params={-1,-1,-1,-1,0,TRUE};
130 VideoParams lpc_preview_params={-1,-1,-1,-1,0,TRUE};
132 /***************************************************************************
136 ***************************************************************************/
141 static LPC_COMMAND commands[] = {
142 { "help", lpc_cmd_help, "Print commands help.",
143 "'help <command>'\t: displays specific help for command.\n"
144 "'help advanced'\t: shows advanced commands.\n"
146 { "call", lpc_cmd_call, "Call a SIP uri or number",
148 "'call <sip-url or number> [options]' \t: initiate a call to the specified destination.\n"
150 "--audio-only : initiate the call without video.\n"
151 "--early-media : sends audio and video stream immediately when remote proposes early media.\n"
153 "'call <sip-url or number>' \t: initiate a call to the specified destination.\n"
156 { "calls", lpc_cmd_calls, "Show all the current calls with their id and status.",
159 { "chat", lpc_cmd_chat, "Chat with a SIP uri",
160 "'chat <sip-url> \"message\"' "
161 ": send a chat message \"message\" to the specified destination."
163 { "terminate", lpc_cmd_terminate, "Terminate a call",
164 "'terminate' : Terminate the current call\n"
165 "'terminate <call id>' : Terminate the call with supplied id\n"
166 "'terminate <all>' : Terminate all the current calls\n"
168 { "answer", lpc_cmd_answer, "Answer a call",
169 "'answer' : Answer the current incoming call\n"
170 "'answer <call id>' : Answer the call with given id\n"
172 { "pause", lpc_cmd_pause, "pause a call",
173 "'pause' : pause the current call\n"},
174 { "resume", lpc_cmd_resume, "resume a call",
175 "'resume' : resume the unique call\n"
176 "'resume <call id>' : hold off the call with given id\n"},
177 { "transfer", lpc_cmd_transfer,
178 "Transfer a call to a specified destination.",
179 "'transfer <sip-uri>' : transfers the current active call to the destination sip-uri\n"
180 "'transfer <call id> <sip-uri>': transfers the call with 'id' to the destination sip-uri\n"
181 "'transfer <call id1> --to-call <call id2>': transfers the call with 'id1' to the destination of call 'id2' (attended transfer)\n"
183 { "mute", lpc_cmd_mute_mic,
184 "Mute microphone and suspend voice transmission."},
186 { "camera", lpc_cmd_camera, "Send camera output for current call.",
187 "'camera on'\t: allow sending of local camera video to remote end.\n"
188 "'camera off'\t: disable sending of local camera's video to remote end.\n"},
190 { "unmute", lpc_cmd_unmute_mic,
191 "Unmute microphone and resume voice transmission."},
192 { "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
194 { "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
195 "'autoanswer' \t: show current autoanswer mode\n"
196 "'autoanswer enable'\t: enable autoanswer mode\n"
197 "'autoanswer disable'\t: disable autoanswer modeĀ \n"},
198 { "proxy", lpc_cmd_proxy, "Manage proxies",
199 "'proxy list' : list all proxy setups.\n"
200 "'proxy add' : add a new proxy setup.\n"
201 "'proxy remove <index>' : remove proxy setup with number index.\n"
202 "'proxy use <index>' : use proxy with number index as default proxy.\n"
203 "'proxy unuse' : don't use a default proxy.\n"
204 "'proxy show <index>' : show configuration and status of the proxy numbered by index.\n"
205 "'proxy show default' : show configuration and status of the default proxy.\n"
207 { "soundcard", lpc_cmd_soundcard, "Manage soundcards",
208 "'soundcard list' : list all sound devices.\n"
209 "'soundcard show' : show current sound devices configuration.\n"
210 "'soundcard use <index>' : select a sound device.\n"
211 "'soundcard use files' : use .wav files instead of soundcard\n"
213 { "webcam", lpc_cmd_webcam, "Manage webcams",
214 "'webcam list' : list all known devices.\n"
215 "'webcam use <index>' : select a video device.\n"
217 { "ipv6", lpc_cmd_ipv6, "Use IPV6",
218 "'ipv6 status' : show ipv6 usage status.\n"
219 "'ipv6 enable' : enable the use of the ipv6 network.\n"
220 "'ipv6 disable' : do not use ipv6 network."
222 { "nat", lpc_cmd_nat, "Set nat address",
223 "'nat' : show nat settings.\n"
224 "'nat <addr>' : set nat address.\n"
226 { "stun", lpc_cmd_stun, "Set stun server address",
227 "'stun' : show stun settings.\n"
228 "'stun <addr>' : set stun server address.\n"
230 { "firewall", lpc_cmd_firewall, "Set firewall policy",
231 "'firewall' : show current firewall policy.\n"
232 "'firewall none' : use direct connection.\n"
233 "'firewall nat' : use nat address given with the 'nat' command.\n"
234 "'firewall stun' : use stun server given with the 'stun' command.\n"
236 { "call-logs", lpc_cmd_call_logs, "Calls history", NULL },
237 { "friend", lpc_cmd_friend, "Manage friends",
238 "'friend list [<pattern>]' : list friends.\n"
239 "'friend call <index>' : call a friend.\n"
240 "'friend add <name> <addr>' : add friend, <name> must be quoted to include\n"
241 " spaces, <addr> has \"sip:\" added if it isn't\n"
242 " there. Don't use '<' '>' around <addr>.\n"
243 "'friend delete <index>' : remove friend, 'all' removes all\n"
245 { "play", lpc_cmd_play, "play a wav file",
246 "This command has two roles:\n"
247 "Plays a file instead of capturing from soundcard - only available in file mode (see 'help soundcard')\n"
248 "Specifies a wav file to be played to play music to far end when putting it on hold (pause)\n"
249 "'play <wav file>' : play a wav file."
251 { "record", lpc_cmd_record, "record to a wav file",
252 "This feature is available only in file mode (see 'help soundcard')\n"
253 "'record <wav file>' : record into wav file."
255 { "quit", lpc_cmd_quit, "Exit linphonec", NULL },
256 { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
260 static LPC_COMMAND advanced_commands[] = {
261 { "codec", lpc_cmd_acodec, "Audio codec configuration",
262 "'codec list' : list audio codecs\n"
263 "'codec enable <index>' : enable available audio codec\n"
264 "'codec disable <index>' : disable audio codec" },
265 { "vcodec", lpc_cmd_vcodec, "Video codec configuration",
266 "'vcodec list' : list video codecs\n"
267 "'vcodec enable <index>' : enable available video codec\n"
268 "'vcodec disable <index>' : disable video codec" },
269 { "ec", lpc_cmd_echocancellation, "Echo cancellation",
270 "'ec on [<delay>] [<tail>] [<framesize>]' : turn EC on with given delay, tail length and framesize\n"
271 "'ec off' : turn echo cancellation (EC) off\n"
272 "'ec show' : show EC status" },
273 { "el", lpc_cmd_echolimiter, "Echo limiter",
274 "'el on turns on echo limiter (automatic half duplex, for cases where echo canceller cannot work)\n"
275 "'el off' : turn echo limiter off\n"
276 "'el show' : show echo limiter status" },
277 { "nortp-on-audio-mute", lpc_cmd_rtp_no_xmit_on_audio_mute,
278 "Set the rtp_no_xmit_on_audio_mute configuration parameter",
279 " If set to 1 then rtp transmission will be muted when\n"
280 " audio is muted , otherwise rtp is always sent."},
282 { "vwindow", lpc_cmd_video_window, "Control video display window",
283 "'vwindow show': shows video window\n"
284 "'vwindow hide': hides video window\n"
285 "'vwindow pos <x> <y>': Moves video window to x,y pixel coordinates\n"
286 "'vwindow size <width> <height>': Resizes video window\n"
287 "'vwindow id <window id>': embeds video display into supplied window id."
289 { "pwindow", lpc_cmd_preview_window, "Control local camera video display (preview window)",
290 "'pwindow show': shows the local camera video display\n"
291 "'pwindow hide': hides the local camera video display\n"
292 "'pwindow pos <x> <y>': Moves preview window to x,y pixel coordinates\n"
293 "'pwindow size <width> <height>': Resizes preview window\n"
294 "'pwindow id <window id>': embeds preview display into supplied window id.\n"
295 "'pwindow integrated': integrate preview display within the video window of current call.\n"
296 "'pwindow standalone': use standalone window for preview display."
298 { "snapshot", lpc_cmd_snapshot, "Take a snapshot of currently received video stream",
299 "'snapshot <file path>': take a snapshot and records it in jpeg format into the supplied path\n"
302 { "states", lpc_cmd_states, "Show internal states of liblinphone, registrations and calls, according to linphonecore.h definitions",
303 "'states global': shows global state of liblinphone \n"
304 "'states calls': shows state of calls\n"
305 "'states proxies': shows state of proxy configurations"
307 { "register", lpc_cmd_register, "Register in one line to a proxy" , "register <sip identity> <sip proxy> <password>"},
308 { "unregister", lpc_cmd_unregister, "Unregister from default proxy", NULL },
309 { "status", lpc_cmd_status, "Print various status information",
310 "'status register' \t: print status concerning registration\n"
311 "'status autoanswer'\t: tell whether autoanswer mode is enabled\n"
312 "'status hook' \t: print hook status\n" },
313 { "ports", lpc_cmd_ports, "Network ports configuration",
314 "'ports' \t: prints current used ports.\n"
315 "'ports sip <port number>'\t: Sets the sip port.\n" },
316 { "speak", lpc_cmd_speak, "Speak a sentence using espeak TTS engine",
317 "This feature is available only in file mode. (see 'help soundcard')\n"
318 "'speak <voice name> <sentence>' : speak a text using the specified espeak voice.\n"
319 "Example for english voice: 'speak default Hello my friend !'"
321 { "staticpic", lpc_cmd_staticpic, "Manage static pictures when nowebcam",
322 "'staticpic set' : Set path to picture that should be used.\n"
323 "'staticpic fps' : Get/set frames per seconds for picture emission.\n"
325 { "identify", lpc_cmd_identify, "Returns the user-agent string of far end",
326 "'identify' \t: returns remote user-agent string for current call.\n"
327 "'identify <id>' \t: returns remote user-agent string for call with supplied id.\n"
329 { "ringback", lpc_cmd_ringback, "Specifies a ringback tone to be played to remote end during incoming calls",
330 "'ringback <path of mono .wav file>'\t: Specifies a ringback tone to be played to remote end during incoming calls\n"
331 "'ringback disable'\t: Disable playing of ringback tone to callers\n"
333 { NULL,NULL,NULL,NULL}
338 /***************************************************************************
342 ***************************************************************************/
345 * Main command dispatcher.
346 * WARNING: modifies second argument!
348 * Always return 1 currently.
351 linphonec_parse_command_line(LinphoneCore *lc, char *cl)
357 /* Isolate first word and args */
358 while(*ptr && !isspace(*ptr)) ++ptr;
362 /* set args to first nonblank */
364 while(*args && isspace(*args)) ++args;
368 if ( isdigit(*cl) || *cl == '#' || *cl == '*' )
370 while ( isdigit(*cl) || *cl == '#' || *cl == '*' )
372 linphone_core_send_dtmf(lc, *cl);
373 linphone_core_play_dtmf (lc,*cl,100);
374 ms_sleep(1); // be nice
378 // discard spurious trailing chars
382 /* Handle other kind of commands */
383 cmd=lpc_find_command(cl);
386 linphonec_out("'%s': Cannot understand this.\n", cl);
390 if ( ! cmd->func(lc, args) )
392 linphonec_out("Syntax error.\n");
393 linphonec_display_command_help(cmd);
400 * Generator function for command completion.
401 * STATE let us know whether to start from scratch;
402 * without any state (STATE==0), then we start at the
406 linphonec_command_generator(const char *text, int state)
408 static int index, len, adv;
418 * Return the next name which partially matches
419 * from the commands list
422 while ((name=commands[index].name))
424 ++index; /* so next call get next command */
426 if (strncmp(name, text, len) == 0)
428 return ortp_strdup(name);
435 while ((name=advanced_commands[index].name))
437 ++index; /* so next call get next command */
439 if (strncmp(name, text, len) == 0)
441 return ortp_strdup(name);
449 /***************************************************************************
453 ***************************************************************************/
456 lpc_cmd_help(LinphoneCore *lc, char *arg)
463 linphonec_out("Commands are:\n");
464 linphonec_out("---------------------------\n");
466 while (commands[i].help)
468 linphonec_out("%10.10s\t%s\n", commands[i].name,
473 linphonec_out("---------------------------\n");
474 linphonec_out("Type 'help <command>' for more details or 'help advanced' to list additional commands.\n");
479 if (strcmp(arg,"advanced")==0){
480 linphonec_out("Advanced commands are:\n");
481 linphonec_out("---------------------------\n");
483 while (advanced_commands[i].help)
485 linphonec_out("%10.10s\t%s\n", advanced_commands[i].name,
486 advanced_commands[i].help);
490 linphonec_out("---------------------------\n");
491 linphonec_out("Type 'help <command>' for more details.\n");
496 cmd=lpc_find_command(arg);
499 linphonec_out("No such command.\n");
503 linphonec_display_command_help(cmd);
508 static char callee_name[256]={0};
509 static char caller_name[256]={0};
511 static const char *get_call_status(LinphoneCall *call){
512 switch(linphone_call_get_state(call)){
513 case LinphoneCallPaused:
514 if (linphone_call_get_refer_to (call)!=NULL){
515 return "Paused (transfered)";
520 case LinphoneCallPausedByRemote:
521 return "Paused by remote";
523 case LinphoneCallIncomingReceived:
526 case LinphoneCallOutgoingInit:
527 case LinphoneCallOutgoingProgress:
528 return "Dialing out";
530 case LinphoneCallOutgoingEarlyMedia:
531 case LinphoneCallOutgoingRinging:
532 return "Remote ringing";
535 if (linphone_call_has_transfer_pending(call)){
536 return "Running (transfer pending)";
544 lpc_cmd_call(LinphoneCore *lc, char *args)
546 if ( ! args || ! *args )
552 LinphoneCallParams *cp=linphone_core_create_default_call_parameters (lc);
554 if ( linphone_core_in_call(lc) )
556 linphonec_out("Terminate or hold on the current call first.\n");
559 opt1=strstr(args,"--audio-only");
560 opt2=strstr(args,"--early-media");
563 linphone_call_params_enable_video (cp,FALSE);
567 linphone_call_params_enable_early_media_sending(cp,TRUE);
569 if ( NULL == (call=linphone_core_invite_with_params(lc, args,cp)) )
571 linphonec_out("Error from linphone_core_invite.\n");
575 snprintf(callee_name,sizeof(callee_name),"%s",args);
577 linphone_call_params_destroy(cp);
583 lpc_cmd_calls(LinphoneCore *lc, char *args){
584 const MSList *calls = linphone_core_get_calls(lc);
587 const MSList *p_calls = calls;
588 linphonec_out("ID\t\tDestination\t\t\t\tStatus\n---------------------------------------------------------------------\n");
589 while(p_calls != NULL)
591 LinphoneCall *call=(LinphoneCall*)p_calls->data;
592 char *tmp=linphone_call_get_remote_address_as_string(call);
593 linphonec_out("%li\t%s\t\t\t%s\r\n",
594 (long)linphone_call_get_user_pointer (call),
596 get_call_status(call));
597 p_calls = p_calls->next;
602 linphonec_out("No active call.\n");
609 lpc_cmd_chat(LinphoneCore *lc, char *args)
617 /* Isolate first and second arg */
618 while(*ptr && !isspace(*ptr)) ++ptr;
623 while(*arg2 && isspace(*arg2)) ++arg2;
627 /* missing one parameter */
630 LinphoneChatRoom *cr = linphone_core_create_chat_room(lc,arg1);
631 linphone_chat_room_send_message(cr,arg2);
632 linphone_chat_room_destroy(cr);
637 const char *linphonec_get_callee(){
641 const char *linphonec_get_caller(){
645 void linphonec_set_caller(const char *caller){
646 snprintf(caller_name,sizeof(caller_name)-1,"%s",caller);
650 lpc_cmd_transfer(LinphoneCore *lc, char *args)
655 const char *refer_to=NULL;
659 int n=sscanf(args,"%s %s %li",arg1,arg2,&id2);
660 if (n==1 || isalpha(*arg1)){
661 call=linphone_core_get_current_call(lc);
662 if (call==NULL && ms_list_size(linphone_core_get_calls(lc))==1){
663 call=(LinphoneCall*)linphone_core_get_calls(lc)->data;
667 linphonec_out("No active call, please specify a call id among the ones listed by 'calls' command.\n");
670 linphone_core_transfer_call(lc, call, refer_to);
673 refer_to=args+strlen(arg1)+1;
674 call=linphonec_get_call(id);
675 if (call==NULL) return 0;
676 linphone_core_transfer_call(lc, call, refer_to);
679 call=linphonec_get_call(id);
680 call2=linphonec_get_call(id2);
681 if (call==NULL || call2==NULL) return 0;
682 if (strcmp(arg2,"--to-call")!=0){
685 linphonec_out("Performing attended transfer of call %i to call %i",id,id2);
686 linphone_core_transfer_call_to_another (lc,call,call2);
689 linphonec_out("Transfer command requires at least one argument\n");
696 lpc_cmd_terminate(LinphoneCore *lc, char *args)
698 if (linphone_core_get_calls(lc)==NULL){
699 linphonec_out("No active calls\n");
704 if ( -1 == linphone_core_terminate_call(lc, NULL) ){
705 linphonec_out("Could not stop the active call.\n");
710 if(strcmp(args,"all")==0){
711 linphonec_out("We are going to stop all the calls.\n");
712 linphone_core_terminate_all_calls(lc);
715 /*the argument is a linphonec call id */
717 LinphoneCall *call=linphonec_get_call(id);
719 if (linphone_core_terminate_call(lc,call)==-1){
720 linphonec_out("Could not stop the call with id %li\n",id);
730 lpc_cmd_answer(LinphoneCore *lc, char *args){
733 int nb=ms_list_size(linphone_core_get_calls(lc));
735 //if just one call is present answer the only one in passing NULL to the linphone_core_accept_call ...
736 if ( -1 == linphone_core_accept_call(lc, NULL) )
738 linphonec_out("Fail to accept incoming call\n");
741 linphonec_out("There are no calls to answer.\n");
743 linphonec_out("Multiple calls in progress, please specify call id.\n");
749 if (sscanf(args,"%li",&id)==1){
750 LinphoneCall *call=linphonec_get_call (id);
751 if (linphone_core_accept_call (lc,call)==-1){
752 linphonec_out("Fail to accept call %i\n",id);
761 lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
765 if ( linphonec_get_autoanswer() ) {
766 linphonec_out("Auto answer is enabled. Use 'autoanswer disable' to disable.\n");
768 linphonec_out("Auto answer is disabled. Use 'autoanswer enable' to enable.\n");
773 if (strstr(args,"enable")){
774 linphonec_set_autoanswer(TRUE);
775 linphonec_out("Auto answer enabled.\n");
776 }else if (strstr(args,"disable")){
777 linphonec_set_autoanswer(FALSE);
778 linphonec_out("Auto answer disabled.\n");
784 lpc_cmd_quit(LinphoneCore *lc, char *args)
786 linphonec_main_loop_exit();
791 lpc_cmd_nat(LinphoneCore *lc, char *args)
796 if ( args ) args=lpc_strip_blanks(args);
800 linphone_core_set_nat_address(lc, args);
801 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS); */
804 nat = linphone_core_get_nat_address(lc);
805 use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress;
806 linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
812 lpc_cmd_stun(LinphoneCore *lc, char *args)
817 if ( args ) args=lpc_strip_blanks(args);
821 linphone_core_set_stun_server(lc, args);
822 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN); */
825 stun = linphone_core_get_stun_server(lc);
826 use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseStun;
827 linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
833 lpc_cmd_firewall(LinphoneCore *lc, char *args)
835 const char* setting=NULL;
837 if ( args ) args=lpc_strip_blanks(args);
841 if (strcmp(args,"none")==0)
843 linphone_core_set_firewall_policy(lc,LinphonePolicyNoFirewall);
845 else if (strcmp(args,"stun")==0)
847 setting = linphone_core_get_stun_server(lc);
850 linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
853 linphone_core_set_firewall_policy(lc,LinphonePolicyUseStun);
855 else if (strcmp(args,"nat")==0)
857 setting = linphone_core_get_nat_address(lc);
860 linphonec_out("No nat address is defined, use 'nat <address>' first");
863 linphone_core_set_firewall_policy(lc,LinphonePolicyUseNatAddress);
867 switch(linphone_core_get_firewall_policy(lc))
869 case LinphonePolicyNoFirewall:
870 linphonec_out("No firewall\n");
872 case LinphonePolicyUseStun:
873 linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
875 case LinphonePolicyUseNatAddress:
876 linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
883 /* Helper function for processing freind names */
885 lpc_friend_name(char **args, char **name)
887 /* Use space as a terminator unless quoted */
888 if (('"' == **args) || ('\'' == **args)){
893 while ((delim != *end) && ('\0' != *end)) end++;
895 fprintf(stderr, "Mismatched quotes\n");
902 *name = strsep(args, " ");
904 if (NULL == *args) { /* Means there was no separator */
905 fprintf(stderr, "Either name or address is missing\n");
908 if (NULL == *name) return 0;
915 lpc_cmd_friend(LinphoneCore *lc, char *args)
919 if ( args ) args=lpc_strip_blanks(args);
921 if ( ! args || ! *args ) return 0;
923 if ( !strncmp(args, "list", 4) )
925 return linphonec_friend_list(lc, args+4);
928 else if ( !strncmp(args, "call", 4) )
931 if ( ! *args ) return 0;
932 friend_num = strtol(args, NULL, 10);
934 if ( errno == ERANGE ) {
935 linphonec_out("Invalid friend number\n");
938 #endif /*_WIN32_WCE*/
939 linphonec_friend_call(lc, friend_num);
942 else if ( !strncmp(args, "delete", 6) )
945 if ( ! *args ) return 0;
946 while (*args == ' ') args++;
947 if ( ! *args ) return 0;
948 if (!strncmp(args, "all", 3))
954 friend_num = strtol(args, NULL, 10);
956 if ( errno == ERANGE ) {
957 linphonec_out("Invalid friend number\n");
960 #endif /*_WIN32_WCE*/
962 linphonec_friend_delete(lc, friend_num);
965 else if ( !strncmp(args, "add", 3) )
974 if ( ! *args ) return 0;
975 while (*args == ' ') args++;
976 if ( ! *args ) return 0;
978 if (!lpc_friend_name(&args, &name)) return 0;
980 while (*args == ' ') args++;
981 if ( ! *args ) return 0;
982 if (isdigit(*args)) {
983 strcpy (addr, "sip:");
984 addr_p = addr + strlen("sip:");
986 addr_orig = strsep(&args, " ");
987 if (1 >= strlen(addr_orig)) {
988 fprintf(stderr, "A single-digit address is not valid\n");
991 strcpy(addr_p, addr_orig);
992 linphonec_friend_add(lc, name, addr);
994 LinphoneFriend *new_friend;
995 new_friend = linphone_friend_new_with_addr(args);
996 linphone_core_add_friend(lc, new_friend);
1003 static int lpc_cmd_play(LinphoneCore *lc, char *args){
1004 if ( args ) args=lpc_strip_blanks(args);
1005 if ( ! args || ! *args ) return 0;
1006 linphone_core_set_play_file(lc,args);
1010 static int lpc_cmd_record(LinphoneCore *lc, char *args){
1011 if ( args ) args=lpc_strip_blanks(args);
1012 if ( ! args || ! *args ) return 0;
1013 linphone_core_set_record_file(lc,args);
1021 lpc_cmd_proxy(LinphoneCore *lc, char *args)
1028 if ( ! arg1 ) return 0;
1030 /* Isolate first and second arg */
1031 while(*ptr && !isspace(*ptr)) ++ptr;
1036 while(*arg2 && isspace(*arg2)) ++arg2;
1039 if (strcmp(arg1,"add")==0)
1041 #ifdef HAVE_READLINE
1042 rl_inhibit_completion=1;
1044 linphonec_proxy_add(lc);
1045 #ifdef HAVE_READLINE
1046 rl_inhibit_completion=0;
1049 else if (strcmp(arg1,"list")==0)
1051 linphonec_proxy_list(lc);
1053 else if (strcmp(arg1,"remove")==0)
1055 linphonec_proxy_remove(lc,atoi(arg2));
1057 else if (strcmp(arg1,"use")==0)
1059 if ( arg2 && *arg2 )
1061 proxynum=atoi(arg2);
1062 if ( linphonec_proxy_use(lc, proxynum) )
1063 linphonec_out("Default proxy set to %d.\n", proxynum);
1067 proxynum=linphone_core_get_default_proxy(lc, NULL);
1068 if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
1069 else linphonec_out("Current default proxy is %d.\n", proxynum);
1071 }else if (strcmp(arg1, "unuse")==0){
1072 linphone_core_set_default_proxy(lc, NULL);
1073 linphonec_out("Use no proxy.\n");
1076 else if (strcmp(arg1, "show")==0)
1080 if (strstr(arg2,"default"))
1082 proxynum=linphone_core_get_default_proxy(lc, NULL);
1083 if ( proxynum < 0 ) {
1084 linphonec_out("No default proxy defined\n");
1087 linphonec_proxy_show(lc,proxynum);
1091 linphonec_proxy_show(lc, atoi(arg2));
1094 else return 0; /* syntax error */
1099 return 0; /* syntax error */
1106 lpc_cmd_call_logs(LinphoneCore *lc, char *args)
1108 const MSList *elem=linphone_core_get_call_logs(lc);
1109 for (;elem!=NULL;elem=ms_list_next(elem))
1111 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
1112 char *str=linphone_call_log_to_str(cl);
1113 linphonec_out("%s\n",str);
1120 lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
1124 return 0; /* syntax error */
1127 if (strcmp(arg1,"status")==0)
1129 linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
1131 else if (strcmp(arg1,"enable")==0)
1133 linphone_core_enable_ipv6(lc,TRUE);
1134 linphonec_out("ipv6 use enabled.\n");
1136 else if (strcmp(arg1,"disable")==0)
1138 linphone_core_enable_ipv6(lc,FALSE);
1139 linphonec_out("ipv6 use disabled.\n");
1143 return 0; /* syntax error */
1148 static int devname_to_index(LinphoneCore *lc, const char *devname){
1151 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1152 if (strcmp(devname,*p)==0) return i;
1157 static const char *index_to_devname(LinphoneCore *lc, int index){
1160 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1161 if (i==index) return *p;
1166 static int lpc_cmd_soundcard(LinphoneCore *lc, char *args)
1174 if (!args) return 0; /* syntax error */
1176 /* Isolate first and second arg */
1177 while(*ptr && !isspace(*ptr)) ++ptr;
1182 while(*arg2 && isspace(*arg2)) ++arg2;
1185 if (strcmp(arg1, "list")==0)
1187 dev=linphone_core_get_sound_devices(lc);
1188 for(i=0; dev[i]!=NULL; ++i){
1189 linphonec_out("%i: %s\n",i,dev[i]);
1194 if (strcmp(arg1, "show")==0)
1196 linphonec_out("Ringer device: %s\n",
1197 linphone_core_get_ringer_device(lc));
1198 linphonec_out("Playback device: %s\n",
1199 linphone_core_get_playback_device(lc));
1200 linphonec_out("Capture device: %s\n",
1201 linphone_core_get_capture_device(lc));
1205 if (strcmp(arg1, "use")==0 && arg2)
1207 if (strcmp(arg2, "files")==0)
1209 linphonec_out("Using wav files instead of soundcard.\n");
1210 linphone_core_use_files(lc,TRUE);
1214 dev=linphone_core_get_sound_devices(lc);
1215 index=atoi(arg2); /* FIXME: handle not-a-number */
1216 for(i=0;dev[i]!=NULL;i++)
1218 if (i!=index) continue;
1220 linphone_core_set_ringer_device(lc,dev[i]);
1221 linphone_core_set_playback_device(lc,dev[i]);
1222 linphone_core_set_capture_device(lc,dev[i]);
1223 linphonec_out("Using sound device %s\n",dev[i]);
1226 linphonec_out("No such sound device\n");
1229 if (strcmp(arg1, "capture")==0)
1231 const char *devname=linphone_core_get_capture_device(lc);
1233 linphonec_out("Using capture device #%i (%s)\n",
1234 devname_to_index(lc,devname),devname);
1236 index=atoi(arg2); /* FIXME: handle not-a-number */
1237 devname=index_to_devname(lc,index);
1239 linphone_core_set_capture_device(lc,devname);
1240 linphonec_out("Using capture sound device %s\n",devname);
1243 linphonec_out("No such sound device\n");
1247 if (strcmp(arg1, "playback")==0)
1249 const char *devname=linphone_core_get_playback_device(lc);
1251 linphonec_out("Using playback device #%i (%s)\n",
1252 devname_to_index(lc,devname),devname);
1254 index=atoi(arg2); /* FIXME: handle not-a-number */
1255 devname=index_to_devname(lc,index);
1257 linphone_core_set_playback_device(lc,devname);
1258 linphonec_out("Using playback sound device %s\n",devname);
1261 linphonec_out("No such sound device\n");
1265 if (strcmp(arg1, "ring")==0)
1267 const char *devname=linphone_core_get_ringer_device(lc);
1269 linphonec_out("Using ring device #%i (%s)\n",
1270 devname_to_index(lc,devname),devname);
1272 index=atoi(arg2); /* FIXME: handle not-a-number */
1273 devname=index_to_devname(lc,index);
1275 linphone_core_set_ringer_device(lc,devname);
1276 linphonec_out("Using ring sound device %s\n",devname);
1279 linphonec_out("No such sound device\n");
1283 return 0; /* syntax error */
1286 static int lpc_cmd_webcam(LinphoneCore *lc, char *args)
1294 if (!args) return 0; /* syntax error */
1296 /* Isolate first and second arg */
1297 while(*ptr && !isspace(*ptr)) ++ptr;
1302 while(*arg2 && isspace(*arg2)) ++arg2;
1305 if (strcmp(arg1, "list")==0)
1307 dev=linphone_core_get_video_devices(lc);
1308 for(i=0; dev[i]!=NULL; ++i){
1309 linphonec_out("%i: %s\n",i,dev[i]);
1314 if (strcmp(arg1, "use")==0 && arg2)
1316 dev=linphone_core_get_video_devices(lc);
1317 index=atoi(arg2); /* FIXME: handle not-a-number */
1318 for(i=0;dev[i]!=NULL;i++)
1320 if (i!=index) continue;
1322 linphone_core_set_video_device(lc, dev[i]);
1323 linphonec_out("Using video device %s\n",dev[i]);
1326 linphonec_out("No such video device\n");
1329 return 0; /* syntax error */
1333 lpc_cmd_staticpic(LinphoneCore *lc, char *args)
1339 if (!args) return 0; /* Syntax error */
1341 /* Isolate first and second arg */
1342 while(*ptr && !isspace(*ptr)) ++ptr;
1347 while(*arg2 && isspace(*arg2)) ++arg2;
1350 if (strcmp(arg1, "set")==0 && arg2) {
1351 linphone_core_set_static_picture(lc, arg2);
1355 if (strcmp(arg1, "fps")==0) {
1357 float fps = atof(arg2); /* FIXME: Handle not-a-float */
1358 linphone_core_set_static_picture_fps(lc, fps);
1362 fps = linphone_core_get_static_picture_fps(lc);
1363 linphonec_out("Current FPS %f\n", fps);
1368 return 0; /* Syntax error */
1371 static int lpc_cmd_pause(LinphoneCore *lc, char *args){
1373 if(linphone_core_in_call(lc))
1375 linphone_core_pause_call(lc,linphone_core_get_current_call(lc));
1378 linphonec_out("you can only pause when a call is in process\n");
1382 static int lpc_cmd_resume(LinphoneCore *lc, char *args){
1384 if(linphone_core_in_call(lc))
1386 linphonec_out("There is already a call in process pause or stop it first");
1392 int n = sscanf(args, "%li", &id);
1394 LinphoneCall *call=linphonec_get_call (id);
1396 if(linphone_core_resume_call(lc,call)==-1){
1397 linphonec_out("There was a problem to resume the call check the remote address you gave %s\n",args);
1405 const MSList *calls = linphone_core_get_calls(lc);
1406 int nbcalls=ms_list_size(calls);
1409 if(linphone_core_resume_call(lc,calls->data) < 0)
1411 linphonec_out("There was a problem to resume the unique call.\n");
1414 }else if (nbcalls==0){
1415 linphonec_out("There is no calls at this time.\n");
1418 linphonec_out("There are %i calls at this time, please specify call id as given with 'calls' command.\n");
1425 /***************************************************************************
1427 * Commands helper functions
1429 ***************************************************************************/
1433 linphonec_proxy_add(LinphoneCore *lc)
1435 bool_t enable_register=FALSE;
1436 LinphoneProxyConfig *cfg;
1438 linphonec_out("Adding new proxy setup. Hit ^D to abort.\n");
1445 char *input=linphonec_readline("Enter proxy sip address: ");
1449 linphonec_out("Aborted.\n");
1454 clean=lpc_strip_blanks(input);
1460 cfg=linphone_proxy_config_new();
1461 if (linphone_proxy_config_set_server_addr(cfg,clean)<0)
1463 linphonec_out("Invalid sip address (sip:sip.domain.tld).\n");
1465 linphone_proxy_config_destroy(cfg);
1473 * SIP Proxy identity
1477 char *input=linphonec_readline("Your identity for this proxy: ");
1481 linphonec_out("Aborted.\n");
1482 linphone_proxy_config_destroy(cfg);
1487 clean=lpc_strip_blanks(input);
1493 linphone_proxy_config_set_identity(cfg, clean);
1494 if ( ! linphone_proxy_config_get_identity (cfg))
1496 linphonec_out("Invalid identity (sip:name@sip.domain.tld).\n");
1505 * SIP Proxy enable register
1509 char *input=linphonec_readline("Do you want to register on this proxy (yes/no): ");
1513 linphonec_out("Aborted.\n");
1514 linphone_proxy_config_destroy(cfg);
1519 clean=lpc_strip_blanks(input);
1525 if ( ! strcmp(clean, "yes") ) enable_register=TRUE;
1526 else if ( ! strcmp(clean, "no") ) enable_register=FALSE;
1528 linphonec_out("Please answer with 'yes' or 'no'\n");
1532 linphone_proxy_config_enableregister(cfg, enable_register);
1538 * SIP Proxy registration expiration
1540 if ( enable_register==TRUE )
1545 char *input=linphonec_readline("Specify register expiration time"
1546 " in seconds (default is 600): ");
1549 linphonec_out("Aborted.\n");
1550 linphone_proxy_config_destroy(cfg);
1554 expires=strtol(input, (char **)NULL, 10);
1555 if ( expires == LONG_MIN || expires == LONG_MAX )
1557 linphonec_out("Invalid value: %s\n", strerror(errno));
1562 linphone_proxy_config_expires(cfg, expires);
1563 linphonec_out("Expiration: %d seconds\n", linphone_proxy_config_get_expires (cfg));
1575 char *input=linphonec_readline("Specify route if needed: ");
1579 linphonec_out("Aborted.\n");
1580 linphone_proxy_config_destroy(cfg);
1585 clean=lpc_strip_blanks(input);
1588 linphonec_out("No route specified.\n");
1592 linphone_proxy_config_set_route(cfg, clean);
1593 if ( ! linphone_proxy_config_get_route(cfg) )
1595 linphonec_out("Invalid route.\n");
1605 * Final confirmation
1612 linphonec_out("--------------------------------------------\n");
1613 linphonec_proxy_display(cfg);
1614 linphonec_out("--------------------------------------------\n");
1615 input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: ");
1619 linphonec_out("Aborted.\n");
1620 linphone_proxy_config_destroy(cfg);
1625 clean=lpc_strip_blanks(input);
1631 if ( ! strcmp(clean, "yes") ) break;
1632 else if ( ! strcmp(clean, "no") )
1634 linphonec_out("Declined.\n");
1635 linphone_proxy_config_destroy(cfg);
1640 linphonec_out("Please answer with 'yes' or 'no'\n");
1646 linphone_core_add_proxy_config(lc,cfg);
1648 /* automatically set the last entered proxy as the default one */
1649 linphone_core_set_default_proxy(lc,cfg);
1651 linphonec_out("Proxy added.\n");
1655 linphonec_proxy_display(LinphoneProxyConfig *cfg)
1657 const char *route=linphone_proxy_config_get_route(cfg);
1658 const char *identity=linphone_proxy_config_get_identity(cfg);
1659 linphonec_out("sip address: %s\nroute: %s\nidentity: %s\nregister: %s\nexpires: %i\nregistered: %s\n",
1660 linphone_proxy_config_get_addr(cfg),
1661 (route!=NULL)? route:"",
1662 (identity!=NULL)?identity:"",
1663 linphone_proxy_config_register_enabled (cfg)?"yes":"no",
1664 linphone_proxy_config_get_expires (cfg),
1665 linphone_proxy_config_is_registered(cfg) ? "yes" : "no");
1668 static void linphonec_proxy_show(LinphoneCore *lc, int index)
1672 for(elem=linphone_core_get_proxy_config_list(lc),i=0;elem!=NULL;elem=elem->next,++i){
1674 LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)elem->data;
1675 linphonec_proxy_display(cfg);
1679 linphonec_out("No proxy with index %i\n", index);
1683 linphonec_proxy_list(LinphoneCore *lc)
1685 const MSList *proxies;
1687 int def=linphone_core_get_default_proxy(lc,NULL);
1689 proxies=linphone_core_get_proxy_config_list(lc);
1690 for(n=0;proxies!=NULL;proxies=ms_list_next(proxies),n++){
1692 linphonec_out("****** Proxy %i - this is the default one - *******\n",n);
1694 linphonec_out("****** Proxy %i *******\n",n);
1695 linphonec_proxy_display((LinphoneProxyConfig*)proxies->data);
1697 if ( ! n ) linphonec_out("No proxies defined\n");
1701 linphonec_proxy_remove(LinphoneCore *lc, int index)
1703 const MSList *proxies;
1704 LinphoneProxyConfig *cfg;
1705 proxies=linphone_core_get_proxy_config_list(lc);
1706 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1708 linphonec_out("No such proxy.\n");
1711 linphone_core_remove_proxy_config(lc,cfg);
1712 linphonec_out("Proxy %s removed.\n", linphone_proxy_config_get_addr(cfg));
1716 linphonec_proxy_use(LinphoneCore *lc, int index)
1718 const MSList *proxies;
1719 LinphoneProxyConfig *cfg;
1720 proxies=linphone_core_get_proxy_config_list(lc);
1721 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1723 linphonec_out("No such proxy (try 'proxy list').");
1726 linphone_core_set_default_proxy(lc,cfg);
1731 linphonec_friend_display(LinphoneFriend *fr)
1733 LinphoneAddress *uri=linphone_address_clone(linphone_friend_get_address(fr));
1736 linphonec_out("name: %s\n", linphone_address_get_display_name(uri));
1737 linphone_address_set_display_name(uri,NULL);
1738 str=linphone_address_as_string(uri);
1739 linphonec_out("address: %s\n", str);
1743 linphonec_friend_list(LinphoneCore *lc, char *pat)
1745 const MSList *friend;
1749 pat=lpc_strip_blanks(pat);
1750 if (!*pat) pat = NULL;
1753 friend = linphone_core_get_friend_list(lc);
1754 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1757 const char *name = linphone_address_get_display_name(
1758 linphone_friend_get_address((LinphoneFriend*)friend->data));
1759 if (name && ! strstr(name, pat) ) continue;
1761 linphonec_out("****** Friend %i *******\n",n);
1762 linphonec_friend_display((LinphoneFriend*)friend->data);
1769 linphonec_friend_call(LinphoneCore *lc, unsigned int num)
1771 const MSList *friend = linphone_core_get_friend_list(lc);
1775 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1780 addr = linphone_address_as_string(linphone_friend_get_address((LinphoneFriend*)friend->data));
1781 ret=lpc_cmd_call(lc, addr);
1786 linphonec_out("No such friend %u\n", num);
1792 linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr)
1794 LinphoneFriend *newFriend;
1798 snprintf(url, PATH_MAX, "%s <%s>", name, addr);
1799 newFriend = linphone_friend_new_with_addr(url);
1800 linphone_core_add_friend(lc, newFriend);
1806 linphonec_friend_delete(LinphoneCore *lc, int num)
1808 const MSList *friend = linphone_core_get_friend_list(lc);
1811 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1815 linphone_core_remove_friend(lc, friend->data);
1823 for (i = 0 ; i < n ; i++)
1824 linphonec_friend_delete(lc, 0);
1828 linphonec_out("No such friend %u\n", num);
1833 linphonec_display_command_help(LPC_COMMAND *cmd)
1835 if ( cmd->doc ) linphonec_out ("%s\n", cmd->doc);
1836 else linphonec_out("%s\n", cmd->help);
1840 static int lpc_cmd_register(LinphoneCore *lc, char *args){
1844 LinphoneProxyConfig *cfg;
1849 /* it means that you want to register the default proxy */
1850 LinphoneProxyConfig *cfg=NULL;
1851 linphone_core_get_default_proxy(lc,&cfg);
1854 if(!linphone_proxy_config_is_registered(cfg)) {
1855 linphone_proxy_config_enable_register(cfg,TRUE);
1856 linphone_proxy_config_done(cfg);
1858 linphonec_out("default proxy already registered\n");
1861 linphonec_out("we do not have a default proxy\n");
1866 passwd[0]=proxy[0]=identity[0]='\0';
1867 sscanf(args,"%s %s %s",identity,proxy,passwd);
1868 if (proxy[0]=='\0' || identity[0]=='\0'){
1869 linphonec_out("Missing parameters, see help register\n");
1872 if (passwd[0]!='\0'){
1873 LinphoneAddress *from;
1874 LinphoneAuthInfo *info;
1875 if ((from=linphone_address_new(identity))!=NULL){
1877 snprintf(realm,sizeof(realm)-1,"\"%s\"",linphone_address_get_domain(from));
1878 info=linphone_auth_info_new(linphone_address_get_username(from),NULL,passwd,NULL,NULL);
1879 linphone_core_add_auth_info(lc,info);
1880 linphone_address_destroy(from);
1881 linphone_auth_info_destroy(info);
1884 elem=linphone_core_get_proxy_config_list(lc);
1886 cfg=(LinphoneProxyConfig*)elem->data;
1887 linphone_proxy_config_edit(cfg);
1889 else cfg=linphone_proxy_config_new();
1890 linphone_proxy_config_set_identity(cfg,identity);
1891 linphone_proxy_config_set_server_addr(cfg,proxy);
1892 linphone_proxy_config_enable_register(cfg,TRUE);
1893 if (elem) linphone_proxy_config_done(cfg);
1894 else linphone_core_add_proxy_config(lc,cfg);
1895 linphone_core_set_default_proxy(lc,cfg);
1899 static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
1900 LinphoneProxyConfig *cfg=NULL;
1901 linphone_core_get_default_proxy(lc,&cfg);
1902 if (cfg && linphone_proxy_config_is_registered(cfg)) {
1903 linphone_proxy_config_edit(cfg);
1904 linphone_proxy_config_enable_register(cfg,FALSE);
1905 linphone_proxy_config_done(cfg);
1907 linphonec_out("unregistered\n");
1912 static int lpc_cmd_duration(LinphoneCore *lc, char *args){
1913 LinphoneCallLog *cl;
1914 const MSList *elem=linphone_core_get_call_logs(lc);
1915 for(;elem!=NULL;elem=elem->next){
1916 if (elem->next==NULL){
1917 cl=(LinphoneCallLog*)elem->data;
1918 linphonec_out("%i seconds\n",cl->duration);
1924 static int lpc_cmd_status(LinphoneCore *lc, char *args)
1926 LinphoneProxyConfig *cfg;
1928 if ( ! args ) return 0;
1929 linphone_core_get_default_proxy(lc,&cfg);
1930 if (strstr(args,"register"))
1934 if (linphone_proxy_config_is_registered(cfg)){
1935 linphonec_out("registered, identity=%s duration=%i\n",
1936 linphone_proxy_config_get_identity(cfg),
1937 linphone_proxy_config_get_expires(cfg));
1938 }else if (linphone_proxy_config_register_enabled(cfg)){
1939 linphonec_out("registered=-1\n");
1940 }else linphonec_out("registered=0\n");
1942 else linphonec_out("registered=0\n");
1944 else if (strstr(args,"autoanswer"))
1946 if (cfg && linphone_proxy_config_is_registered(cfg))
1947 linphonec_out("autoanswer=%i\n",linphonec_get_autoanswer());
1948 else linphonec_out("unregistered\n");
1950 else if (strstr(args,"hook"))
1952 LinphoneCall *call=linphone_core_get_current_call (lc);
1953 LinphoneCallState call_state=LinphoneCallIdle;
1954 if (call) call_state=linphone_call_get_state(call);
1957 case LinphoneCallOutgoingInit:
1958 linphonec_out("hook=outgoing_init sip:%s\n",linphonec_get_callee());
1960 case LinphoneCallOutgoingProgress:
1961 linphonec_out("hook=dialing sip:%s\n",linphonec_get_callee());
1963 case LinphoneCallOutgoingRinging:
1964 linphonec_out("hook=ringing sip:%s\n",linphonec_get_callee());
1966 case LinphoneCallPaused:
1967 linphonec_out("hook=paused sip:%s\n",linphonec_get_callee());
1969 case LinphoneCallIdle:
1970 linphonec_out("hook=offhook\n");
1972 case LinphoneCallStreamsRunning:
1973 case LinphoneCallConnected:
1974 if (linphone_call_get_dir(call)==LinphoneCallOutgoing){
1975 linphonec_out("Call out, hook=%s duration=%i, muted=%s rtp-xmit-muted=%s\n", linphonec_get_callee(),
1976 linphone_core_get_current_call_duration(lc),
1977 linphone_core_is_mic_muted (lc) ? "yes" : "no",
1978 linphone_core_is_rtp_muted(lc) ? "yes" : "no");
1980 linphonec_out("hook=answered duration=%i %s\n" ,
1981 linphone_core_get_current_call_duration(lc), linphonec_get_caller());
1984 case LinphoneCallIncomingReceived:
1985 linphonec_out("Incoming call from %s\n",linphonec_get_caller());
1997 static int lpc_cmd_ports(LinphoneCore *lc, char *args)
2001 linphonec_out("sip port = %i\naudio rtp port = %i\nvideo rtp port = %i\n",
2002 linphone_core_get_sip_port(lc),
2003 linphone_core_get_audio_port(lc),
2004 linphone_core_get_video_port(lc));
2007 if (sscanf(args,"sip %i",&port)==1){
2008 linphonec_out("Setting sip port to %i\n",port);
2009 linphone_core_set_sip_port(lc,port);
2015 static int lpc_cmd_speak(LinphoneCore *lc, char *args){
2024 if (!args) return 0;
2025 memset(voice,0,sizeof(voice));
2026 sscanf(args,"%s63",voice);
2027 sentence=args+strlen(voice);
2028 wavfile=tempnam("/tmp/","linphonec-espeak-");
2029 snprintf(cl,sizeof(cl),"espeak -v %s -s 100 -w %s --stdin",voice,wavfile);
2032 ms_error("Could not open pipe to espeak !");
2035 fprintf(file,"%s",sentence);
2036 status=pclose(file);
2037 if (WEXITSTATUS(status)==0){
2038 linphone_core_set_play_file(lc,wavfile);
2040 linphonec_out("espeak command failed.");
2043 linphonec_out("Sorry, this command is not implemented in windows version.");
2048 static int lpc_cmd_acodec(LinphoneCore *lc, char *args){
2049 return lpc_cmd_codec(AUDIO, lc, args);
2052 static int lpc_cmd_vcodec(LinphoneCore *lc, char *args){
2053 return lpc_cmd_codec(VIDEO, lc, args);
2056 static int lpc_cmd_codec(int type, LinphoneCore *lc, char *args){
2061 if (!args) return 0;
2063 /* Isolate first and second arg */
2064 while(*ptr && !isspace(*ptr)) ++ptr;
2069 while(*arg2 && isspace(*arg2)) ++arg2;
2072 if (strcmp(arg1,"enable")==0)
2074 #ifdef HAVE_READLINE
2075 rl_inhibit_completion=1;
2077 if (!strcmp(arg2,"all")) linphonec_codec_enable(type,lc,-1);
2078 else linphonec_codec_enable(type,lc,atoi(arg2));
2079 #ifdef HAVE_READLINE
2080 rl_inhibit_completion=0;
2083 else if (strcmp(arg1,"list")==0)
2085 linphonec_codec_list(type,lc);
2087 else if (strcmp(arg1,"disable")==0)
2089 if (!strcmp(arg2,"all")) linphonec_codec_disable(type,lc,-1);
2090 else linphonec_codec_disable(type,lc,atoi(arg2));
2094 return 0; /* syntax error */
2100 static void linphonec_codec_list(int type, LinphoneCore *lc){
2103 const MSList *node=NULL;
2105 if (type == AUDIO) {
2106 node=linphone_core_get_audio_codecs(lc);
2107 } else if(type==VIDEO) {
2108 node=linphone_core_get_video_codecs(lc);
2111 for(;node!=NULL;node=ms_list_next(node)){
2112 pt=(PayloadType*)(node->data);
2113 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate,
2114 linphone_core_payload_type_enabled(lc,pt) ? "enabled" : "disabled");
2119 static void linphonec_codec_enable(int type, LinphoneCore *lc, int sel_index){
2122 const MSList *node=NULL;
2124 if (type == AUDIO) {
2125 node=linphone_core_get_audio_codecs(lc);
2126 } else if(type==VIDEO) {
2127 node=linphone_core_get_video_codecs(lc);
2130 for(;node!=NULL;node=ms_list_next(node)){
2131 if (index == sel_index || sel_index == -1) {
2132 pt=(PayloadType*)(node->data);
2133 linphone_core_enable_payload_type (lc,pt,TRUE);
2134 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "enabled");
2140 static void linphonec_codec_disable(int type, LinphoneCore *lc, int sel_index){
2143 const MSList *node=NULL;
2145 if (type == AUDIO) {
2146 node=linphone_core_get_audio_codecs(lc);
2147 } else if(type==VIDEO) {
2148 node=linphone_core_get_video_codecs(lc);
2151 for(;node!=NULL;node=ms_list_next(node)){
2152 if (index == sel_index || sel_index == -1) {
2153 pt=(PayloadType*)(node->data);
2154 linphone_core_enable_payload_type (lc,pt,FALSE);
2155 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "disabled");
2161 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){
2165 LpConfig *config=linphone_core_get_config(lc);
2167 if (!args) return 0;
2169 /* Isolate first and second arg */
2170 while(*ptr && !isspace(*ptr)) ++ptr;
2175 while(*arg2 && isspace(*arg2)) ++arg2;
2178 if (strcmp(arg1,"on")==0){
2179 int delay, tail_len, frame_size;
2182 linphone_core_enable_echo_cancellation(lc,1);
2185 n = sscanf(arg2, "%d %d %d", &delay, &tail_len, &frame_size);
2188 lp_config_set_int(config,"sound","ec_delay",delay);
2191 lp_config_set_int(config,"sound","ec_delay",delay);
2192 lp_config_set_int(config,"sound","ec_tail_len",tail_len);
2195 lp_config_set_int(config,"sound","ec_delay",delay);
2196 lp_config_set_int(config,"sound","ec_tail_len",tail_len);
2197 lp_config_set_int(config,"sound","ec_framesize",frame_size);
2201 else if (strcmp(arg1,"off")==0){
2202 linphone_core_enable_echo_cancellation(lc,0);
2204 else if (strcmp(arg1,"show")==0){
2205 linphonec_out("echo cancellation is %s; delay %d, tail length %d, frame size %d\n",
2206 linphone_core_echo_cancellation_enabled(lc) ? "on" : "off",
2207 lp_config_get_int(config,"sound","ec_delay",0),
2208 lp_config_get_int(config,"sound","ec_tail_len",0),
2209 lp_config_get_int(config,"sound","ec_framesize",0));
2218 static int lpc_cmd_echolimiter(LinphoneCore *lc, char *args){
2220 if (strcmp(args,"on")==0){
2221 linphone_core_enable_echo_limiter (lc,TRUE);
2222 }else if (strcmp(args,"off")==0){
2223 linphone_core_enable_echo_limiter (lc,FALSE);
2226 linphonec_out("Echo limiter is now %s.\n",linphone_core_echo_limiter_enabled (lc) ? "on":"off");
2230 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args)
2232 linphone_core_mute_mic(lc, 1);
2236 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args){
2237 linphone_core_mute_mic(lc, 0);
2241 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args)
2243 bool_t rtp_xmit_off=FALSE;
2247 if(strstr(args,"1"))rtp_xmit_off=TRUE;
2248 if(linphone_core_get_current_call (lc)==NULL)
2249 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_xmit_off);
2251 linphonec_out("nortp-on-audio-mute: call in progress - cannot change state\n");
2253 rtp_xmit_off=linphone_core_get_rtp_no_xmit_on_audio_mute(lc);
2254 if (rtp_xmit_off) status="off";
2256 linphonec_out("rtp transmit %s when audio muted\n",status);
2260 #ifdef VIDEO_ENABLED
2261 static int _lpc_cmd_video_window(LinphoneCore *lc, char *args, bool_t is_preview){
2262 char subcommand[64];
2265 VideoParams *params=is_preview ? &lpc_preview_params : &lpc_video_params;
2267 if (!args) return 0;
2268 err=sscanf(args,"%s %i %i",subcommand,&a,&b);
2270 if (strcmp(subcommand,"pos")==0){
2271 if (err<3) return 0;
2274 params->refresh=TRUE;
2275 }else if (strcmp(subcommand,"size")==0){
2276 if (err<3) return 0;
2279 params->refresh=TRUE;
2280 }else if (strcmp(subcommand,"show")==0){
2282 params->refresh=TRUE;
2283 if (is_preview) linphone_core_enable_video_preview (lc,TRUE);
2284 }else if (strcmp(subcommand,"hide")==0){
2286 params->refresh=TRUE;
2287 if (is_preview) linphone_core_enable_video_preview (lc,FALSE);
2288 }else if (strcmp(subcommand,"id")==0){
2290 linphonec_out("vwindow id: 0x%x\n",is_preview ? linphone_core_get_native_preview_window_id (lc) :
2291 linphone_core_get_native_video_window_id (lc));
2293 } else if (err != 2) return 0;
2296 linphone_core_set_native_preview_window_id (lc,a);
2298 linphone_core_set_native_video_window_id(lc,a);
2299 }else if (is_preview==TRUE){
2300 if (strcmp(subcommand,"integrated")==0){
2301 linphone_core_use_preview_window (lc,FALSE);
2302 }else if (strcmp(subcommand,"standalone")==0){
2303 linphone_core_use_preview_window(lc,TRUE);
2310 static int lpc_cmd_video_window(LinphoneCore *lc, char *args){
2311 return _lpc_cmd_video_window(lc, args, FALSE);
2314 static int lpc_cmd_preview_window(LinphoneCore *lc, char *args){
2315 return _lpc_cmd_video_window(lc, args, TRUE);
2319 static void lpc_display_global_state(LinphoneCore *lc){
2320 linphonec_out("Global liblinphone state\n%s\n",
2321 linphone_global_state_to_string(linphone_core_get_global_state(lc)));
2324 static void lpc_display_call_states(LinphoneCore *lc){
2328 linphonec_out("Call states\n"
2329 "Id | Destination | State\n"
2330 "---------------------------------------------------------------\n");
2331 elem=linphone_core_get_calls(lc);
2333 linphonec_out("(empty)\n");
2335 for(;elem!=NULL;elem=elem->next){
2336 call=(LinphoneCall*)elem->data;
2337 tmp=linphone_call_get_remote_address_as_string (call);
2338 linphonec_out("%-2i | %-35s | %s\n",(int)(long)linphone_call_get_user_pointer(call),
2339 tmp,linphone_call_state_to_string(linphone_call_get_state(call)));
2345 static void lpc_display_proxy_states(LinphoneCore *lc){
2347 linphonec_out("Proxy registration states\n"
2348 " Identity | State\n"
2349 "------------------------------------------------------------\n");
2350 elem=linphone_core_get_proxy_config_list (lc);
2351 if (elem==NULL) linphonec_out("(empty)\n");
2353 for(;elem!=NULL;elem=elem->next){
2354 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2355 linphonec_out("%-40s | %s\n",linphone_proxy_config_get_identity (cfg),
2356 linphone_registration_state_to_string(linphone_proxy_config_get_state(cfg)));
2361 static int lpc_cmd_states(LinphoneCore *lc, char *args){
2363 lpc_display_global_state(lc);
2364 lpc_display_call_states(lc);
2365 lpc_display_proxy_states(lc);
2368 if (strcmp(args,"global")==0){
2369 lpc_display_global_state(lc);
2372 if (strcmp(args,"proxies")==0){
2373 lpc_display_proxy_states(lc);
2376 if (strcmp(args,"calls")==0){
2377 lpc_display_call_states(lc);
2383 #ifdef VIDEO_ENABLED
2384 static int lpc_cmd_camera(LinphoneCore *lc, char *args){
2385 LinphoneCall *call=linphone_core_get_current_call(lc);
2386 bool_t activated=FALSE;
2388 if (linphone_core_video_enabled (lc)==FALSE){
2389 linphonec_out("Video is disabled, re-run linphonec with -V option.");
2394 if (strcmp(args,"on")==0)
2396 else if (strcmp(args,"off")==0)
2404 linphonec_camera_enabled=activated;
2406 if (linphonec_camera_enabled){
2407 linphonec_out("Camera is enabled. Video stream will be setup immediately for outgoing and incoming calls.\n");
2409 linphonec_out("Camera is disabled. Calls will be established with audio-only, with the possibility to later add video using 'camera on'.\n");
2412 const LinphoneCallParams *cp=linphone_call_get_current_params (call);
2414 linphone_call_enable_camera(call,activated);
2415 if ((activated && !linphone_call_params_video_enabled (cp))){
2416 /*update the call to add the video stream*/
2417 LinphoneCallParams *ncp=linphone_call_params_copy(cp);
2418 linphone_call_params_enable_video(ncp,TRUE);
2419 linphone_core_update_call(lc,call,ncp);
2420 linphone_call_params_destroy (ncp);
2421 linphonec_out("Trying to bring up video stream...\n");
2424 if (linphone_call_camera_enabled (call))
2425 linphonec_out("Camera is allowed for current call.\n");
2426 else linphonec_out("Camera is dis-allowed for current call.\n");
2431 static int lpc_cmd_snapshot(LinphoneCore *lc, char *args){
2433 if (!args) return 0;
2434 call=linphone_core_get_current_call(lc);
2436 linphone_call_take_video_snapshot (call,args);
2437 linphonec_out("Taking video snaphot in file %s\n", args);
2438 }else linphonec_out("There is no active call.\n");
2444 static int lpc_cmd_identify(LinphoneCore *lc, char *args){
2446 const char *remote_ua;
2448 call=linphone_core_get_current_call(lc);
2450 linphonec_out("There is currently running call. Specify call id.\n");
2454 call=linphonec_get_call(atoi(args));
2459 remote_ua=linphone_call_get_remote_user_agent(call);
2461 linphonec_out("Remote user agent string is: %s\n",remote_ua);
2466 static int lpc_cmd_ringback(LinphoneCore *lc, char *args){
2467 if (!args) return 0;
2468 if (strcmp(args,"disable")==0){
2469 linphone_core_set_remote_ringback_tone(lc,NULL);
2470 linphonec_out("Disabling ringback tone.\n");
2473 linphone_core_set_remote_ringback_tone (lc,args);
2474 linphonec_out("Using %s as ringback tone to be played to callers.",args);
2478 /***************************************************************************
2480 * Command table management funx
2482 ***************************************************************************/
2485 * Find a command given its name
2487 static LPC_COMMAND *
2488 lpc_find_command(const char *name)
2492 for (i=0; commands[i].name; ++i)
2494 if (strcmp(name, commands[i].name) == 0)
2495 return &commands[i];
2498 for (i=0; advanced_commands[i].name; ++i)
2500 if (strcmp(name, advanced_commands[i].name) == 0)
2501 return &advanced_commands[i];
2504 return (LPC_COMMAND *)NULL;
2508 /****************************************************************************
2510 * $Log: commands.c,v $
2511 * Revision 1.39 2008/07/03 15:08:34 smorlat
2512 * api cleanups, interface in progress.
2514 * Revision 1.38 2008/06/17 20:38:59 smorlat
2515 * added missing file.
2517 * Revision 1.37 2008/04/09 09:26:00 smorlat
2518 * merge various patches
2521 * Revision 1.36 2007/08/01 14:47:53 strk
2522 * * console/commands.c: Clean up commands 'nat', 'stun'
2523 * and 'firewall' to be more intuitive.
2525 * Revision 1.35 2007/06/27 09:01:25 smorlat
2526 * logging improvements.
2528 * Revision 1.34 2007/02/20 10:17:13 smorlat
2529 * linphonec friends patch2
2531 * Revision 1.31 2006/09/22 07:22:47 smorlat
2532 * linphonecore api changes.
2534 * Revision 1.30 2006/09/08 15:32:57 smorlat
2535 * support for using files instead of soundcard (used by linphonec only)
2537 * Revision 1.29 2006/08/28 14:29:07 smorlat
2540 * Revision 1.28 2006/08/21 12:49:59 smorlat
2541 * merged several little patches.
2543 * Revision 1.27 2006/07/17 18:45:00 smorlat
2544 * support for several event queues in ortp.
2545 * glib dependency removed from coreapi/ and console/
2547 * Revision 1.26 2006/04/14 15:16:36 smorlat
2548 * soundcard use did nothing !
2550 * Revision 1.25 2006/04/06 20:09:33 smorlat
2551 * add linphonec command to see and select sound devices.
2553 * Revision 1.24 2006/03/04 11:17:10 smorlat
2554 * mediastreamer2 in progress.
2556 * Revision 1.23 2006/02/20 21:14:01 strk
2557 * Handled syntax errors with 'friend' command
2559 * Revision 1.22 2006/02/20 10:20:29 strk
2560 * Added substring-based filter support for command 'friend list'
2562 * Revision 1.21 2006/02/02 15:39:18 strk
2563 * - Added 'friend list' and 'friend call' commands
2564 * - Allowed for multiple DTFM send in a single line
2565 * - Added status-specific callback (bare version)
2567 * Revision 1.20 2006/01/26 11:54:34 strk
2568 * More robust 'nat' command handler (strip blanks in args)
2570 * Revision 1.19 2006/01/26 09:48:05 strk
2571 * Added limits.h include
2573 * Revision 1.18 2006/01/26 02:18:05 strk
2574 * Added new commands 'nat use' and 'nat unuse'.
2575 * These will required a pending patch to linphonecore.c
2578 * Revision 1.17 2006/01/20 14:12:33 strk
2579 * Added linphonec_init() and linphonec_finish() functions.
2580 * Handled SIGINT and SIGTERM to invoke linphonec_finish().
2581 * Handling of auto-termination (-t) moved to linphonec_finish().
2582 * Reworked main (input read) loop to not rely on 'terminate'
2583 * and 'run' variable (dropped). configfile_name allocated on stack
2584 * using PATH_MAX limit. Changed print_usage signature to allow
2585 * for an exit_status specification.
2587 * Revision 1.16 2006/01/18 09:25:32 strk
2588 * Command completion inhibited in proxy addition and auth request prompts.
2589 * Avoided use of linphonec_readline's internal filename completion.
2591 * Revision 1.15 2006/01/14 13:29:32 strk
2592 * Reworked commands interface to use a table structure,
2593 * used by command line parser and help function.
2594 * Implemented first level of completion (commands).
2595 * Added notification of invalid "answer" and "terminate"
2596 * commands (no incoming call, no active call).
2597 * Forbidden "call" intialization when a call is already active.
2598 * Cleaned up all commands, adding more feedback and error checks.
2600 * Revision 1.14 2006/01/13 13:00:29 strk
2601 * Added linphonec.h. Code layout change (added comments, forward decl,
2602 * globals on top, copyright notices and Logs). Handled out-of-memory
2603 * condition on history management. Removed assumption on sizeof(char).
2604 * Fixed bug in authentication prompt (introduced by linphonec_readline).
2605 * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
2608 ****************************************************************************/