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);
97 static int lpc_cmd_vfureq(LinphoneCore *lc, char *arg);
99 static int lpc_cmd_states(LinphoneCore *lc, char *args);
100 static int lpc_cmd_identify(LinphoneCore *lc, char *args);
101 static int lpc_cmd_ringback(LinphoneCore *lc, char *args);
103 /* Command handler helpers */
104 static void linphonec_proxy_add(LinphoneCore *lc);
105 static void linphonec_proxy_display(LinphoneProxyConfig *lc);
106 static void linphonec_proxy_list(LinphoneCore *lc);
107 static void linphonec_proxy_remove(LinphoneCore *lc, int index);
108 static int linphonec_proxy_use(LinphoneCore *lc, int index);
109 static void linphonec_proxy_show(LinphoneCore *lc,int index);
110 static void linphonec_friend_display(LinphoneFriend *fr);
111 static int linphonec_friend_list(LinphoneCore *lc, char *arg);
112 static void linphonec_display_command_help(LPC_COMMAND *cmd);
113 static int linphonec_friend_call(LinphoneCore *lc, unsigned int num);
115 static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
117 static int linphonec_friend_delete(LinphoneCore *lc, int num);
118 static int linphonec_friend_delete(LinphoneCore *lc, int num);
119 static void linphonec_codec_list(int type, LinphoneCore *lc);
120 static void linphonec_codec_enable(int type, LinphoneCore *lc, int index);
121 static void linphonec_codec_disable(int type, LinphoneCore *lc, int index);
125 /* Command table management */
126 static LPC_COMMAND *lpc_find_command(const char *name);
128 void linphonec_out(const char *fmt,...);
130 VideoParams lpc_video_params={-1,-1,-1,-1,0,TRUE};
131 VideoParams lpc_preview_params={-1,-1,-1,-1,0,TRUE};
133 /***************************************************************************
137 ***************************************************************************/
142 static LPC_COMMAND commands[] = {
143 { "help", lpc_cmd_help, "Print commands help.",
144 "'help <command>'\t: displays specific help for command.\n"
145 "'help advanced'\t: shows advanced commands.\n"
147 { "call", lpc_cmd_call, "Call a SIP uri or number",
149 "'call <sip-url or number> [options]' \t: initiate a call to the specified destination.\n"
151 "--audio-only : initiate the call without video.\n"
152 "--early-media : sends audio and video stream immediately when remote proposes early media.\n"
154 "'call <sip-url or number>' \t: initiate a call to the specified destination.\n"
157 { "calls", lpc_cmd_calls, "Show all the current calls with their id and status.",
160 { "chat", lpc_cmd_chat, "Chat with a SIP uri",
161 "'chat <sip-url> \"message\"' "
162 ": send a chat message \"message\" to the specified destination."
164 { "terminate", lpc_cmd_terminate, "Terminate a call",
165 "'terminate' : Terminate the current call\n"
166 "'terminate <call id>' : Terminate the call with supplied id\n"
167 "'terminate <all>' : Terminate all the current calls\n"
169 { "answer", lpc_cmd_answer, "Answer a call",
170 "'answer' : Answer the current incoming call\n"
171 "'answer <call id>' : Answer the call with given id\n"
173 { "pause", lpc_cmd_pause, "pause a call",
174 "'pause' : pause the current call\n"},
175 { "resume", lpc_cmd_resume, "resume a call",
176 "'resume' : resume the unique call\n"
177 "'resume <call id>' : hold off the call with given id\n"},
178 { "transfer", lpc_cmd_transfer,
179 "Transfer a call to a specified destination.",
180 "'transfer <sip-uri>' : transfers the current active call to the destination sip-uri\n"
181 "'transfer <call id> <sip-uri>': transfers the call with 'id' to the destination sip-uri\n"
182 "'transfer <call id1> --to-call <call id2>': transfers the call with 'id1' to the destination of call 'id2' (attended transfer)\n"
184 { "mute", lpc_cmd_mute_mic,
185 "Mute microphone and suspend voice transmission."},
187 { "camera", lpc_cmd_camera, "Send camera output for current call.",
188 "'camera on'\t: allow sending of local camera video to remote end.\n"
189 "'camera off'\t: disable sending of local camera's video to remote end.\n"},
191 { "unmute", lpc_cmd_unmute_mic,
192 "Unmute microphone and resume voice transmission."},
193 { "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
195 { "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
196 "'autoanswer' \t: show current autoanswer mode\n"
197 "'autoanswer enable'\t: enable autoanswer mode\n"
198 "'autoanswer disable'\t: disable autoanswer modeĀ \n"},
199 { "proxy", lpc_cmd_proxy, "Manage proxies",
200 "'proxy list' : list all proxy setups.\n"
201 "'proxy add' : add a new proxy setup.\n"
202 "'proxy remove <index>' : remove proxy setup with number index.\n"
203 "'proxy use <index>' : use proxy with number index as default proxy.\n"
204 "'proxy unuse' : don't use a default proxy.\n"
205 "'proxy show <index>' : show configuration and status of the proxy numbered by index.\n"
206 "'proxy show default' : show configuration and status of the default proxy.\n"
208 { "soundcard", lpc_cmd_soundcard, "Manage soundcards",
209 "'soundcard list' : list all sound devices.\n"
210 "'soundcard show' : show current sound devices configuration.\n"
211 "'soundcard use <index>' : select a sound device.\n"
212 "'soundcard use files' : use .wav files instead of soundcard\n"
214 { "webcam", lpc_cmd_webcam, "Manage webcams",
215 "'webcam list' : list all known devices.\n"
216 "'webcam use <index>' : select a video device.\n"
218 { "ipv6", lpc_cmd_ipv6, "Use IPV6",
219 "'ipv6 status' : show ipv6 usage status.\n"
220 "'ipv6 enable' : enable the use of the ipv6 network.\n"
221 "'ipv6 disable' : do not use ipv6 network."
223 { "nat", lpc_cmd_nat, "Set nat address",
224 "'nat' : show nat settings.\n"
225 "'nat <addr>' : set nat address.\n"
227 { "stun", lpc_cmd_stun, "Set stun server address",
228 "'stun' : show stun settings.\n"
229 "'stun <addr>' : set stun server address.\n"
231 { "firewall", lpc_cmd_firewall, "Set firewall policy",
232 "'firewall' : show current firewall policy.\n"
233 "'firewall none' : use direct connection.\n"
234 "'firewall nat' : use nat address given with the 'nat' command.\n"
235 "'firewall stun' : use stun server given with the 'stun' command.\n"
237 { "call-logs", lpc_cmd_call_logs, "Calls history", NULL },
238 { "friend", lpc_cmd_friend, "Manage friends",
239 "'friend list [<pattern>]' : list friends.\n"
240 "'friend call <index>' : call a friend.\n"
241 "'friend add <name> <addr>' : add friend, <name> must be quoted to include\n"
242 " spaces, <addr> has \"sip:\" added if it isn't\n"
243 " there. Don't use '<' '>' around <addr>.\n"
244 "'friend delete <index>' : remove friend, 'all' removes all\n"
246 { "play", lpc_cmd_play, "play a wav file",
247 "This command has two roles:\n"
248 "Plays a file instead of capturing from soundcard - only available in file mode (see 'help soundcard')\n"
249 "Specifies a wav file to be played to play music to far end when putting it on hold (pause)\n"
250 "'play <wav file>' : play a wav file."
252 { "record", lpc_cmd_record, "record to a wav file",
253 "This feature is available only in file mode (see 'help soundcard')\n"
254 "'record <wav file>' : record into wav file."
256 { "quit", lpc_cmd_quit, "Exit linphonec", NULL },
257 { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
261 static LPC_COMMAND advanced_commands[] = {
262 { "codec", lpc_cmd_acodec, "Audio codec configuration",
263 "'codec list' : list audio codecs\n"
264 "'codec enable <index>' : enable available audio codec\n"
265 "'codec disable <index>' : disable audio codec" },
266 { "vcodec", lpc_cmd_vcodec, "Video codec configuration",
267 "'vcodec list' : list video codecs\n"
268 "'vcodec enable <index>' : enable available video codec\n"
269 "'vcodec disable <index>' : disable video codec" },
270 { "ec", lpc_cmd_echocancellation, "Echo cancellation",
271 "'ec on [<delay>] [<tail>] [<framesize>]' : turn EC on with given delay, tail length and framesize\n"
272 "'ec off' : turn echo cancellation (EC) off\n"
273 "'ec show' : show EC status" },
274 { "el", lpc_cmd_echolimiter, "Echo limiter",
275 "'el on turns on echo limiter (automatic half duplex, for cases where echo canceller cannot work)\n"
276 "'el off' : turn echo limiter off\n"
277 "'el show' : show echo limiter status" },
278 { "nortp-on-audio-mute", lpc_cmd_rtp_no_xmit_on_audio_mute,
279 "Set the rtp_no_xmit_on_audio_mute configuration parameter",
280 " If set to 1 then rtp transmission will be muted when\n"
281 " audio is muted , otherwise rtp is always sent."},
283 { "vwindow", lpc_cmd_video_window, "Control video display window",
284 "'vwindow show': shows video window\n"
285 "'vwindow hide': hides video window\n"
286 "'vwindow pos <x> <y>': Moves video window to x,y pixel coordinates\n"
287 "'vwindow size <width> <height>': Resizes video window\n"
288 "'vwindow id <window id>': embeds video display into supplied window id."
290 { "pwindow", lpc_cmd_preview_window, "Control local camera video display (preview window)",
291 "'pwindow show': shows the local camera video display\n"
292 "'pwindow hide': hides the local camera video display\n"
293 "'pwindow pos <x> <y>': Moves preview window to x,y pixel coordinates\n"
294 "'pwindow size <width> <height>': Resizes preview window\n"
295 "'pwindow id <window id>': embeds preview display into supplied window id.\n"
296 "'pwindow integrated': integrate preview display within the video window of current call.\n"
297 "'pwindow standalone': use standalone window for preview display."
299 { "snapshot", lpc_cmd_snapshot, "Take a snapshot of currently received video stream",
300 "'snapshot <file path>': take a snapshot and records it in jpeg format into the supplied path\n"
302 { "vfureq", lpc_cmd_vfureq, "Request the other side to send VFU for the current call"},
304 { "states", lpc_cmd_states, "Show internal states of liblinphone, registrations and calls, according to linphonecore.h definitions",
305 "'states global': shows global state of liblinphone \n"
306 "'states calls': shows state of calls\n"
307 "'states proxies': shows state of proxy configurations"
309 { "register", lpc_cmd_register, "Register in one line to a proxy" , "register <sip identity> <sip proxy> <password>"},
310 { "unregister", lpc_cmd_unregister, "Unregister from default proxy", NULL },
311 { "status", lpc_cmd_status, "Print various status information",
312 "'status register' \t: print status concerning registration\n"
313 "'status autoanswer'\t: tell whether autoanswer mode is enabled\n"
314 "'status hook' \t: print hook status\n" },
315 { "ports", lpc_cmd_ports, "Network ports configuration",
316 "'ports' \t: prints current used ports.\n"
317 "'ports sip <port number>'\t: Sets the sip port.\n" },
318 { "speak", lpc_cmd_speak, "Speak a sentence using espeak TTS engine",
319 "This feature is available only in file mode. (see 'help soundcard')\n"
320 "'speak <voice name> <sentence>' : speak a text using the specified espeak voice.\n"
321 "Example for english voice: 'speak default Hello my friend !'"
323 { "staticpic", lpc_cmd_staticpic, "Manage static pictures when nowebcam",
324 "'staticpic set' : Set path to picture that should be used.\n"
325 "'staticpic fps' : Get/set frames per seconds for picture emission.\n"
327 { "identify", lpc_cmd_identify, "Returns the user-agent string of far end",
328 "'identify' \t: returns remote user-agent string for current call.\n"
329 "'identify <id>' \t: returns remote user-agent string for call with supplied id.\n"
331 { "ringback", lpc_cmd_ringback, "Specifies a ringback tone to be played to remote end during incoming calls",
332 "'ringback <path of mono .wav file>'\t: Specifies a ringback tone to be played to remote end during incoming calls\n"
333 "'ringback disable'\t: Disable playing of ringback tone to callers\n"
335 { NULL,NULL,NULL,NULL}
340 /***************************************************************************
344 ***************************************************************************/
347 * Main command dispatcher.
348 * WARNING: modifies second argument!
350 * Always return 1 currently.
353 linphonec_parse_command_line(LinphoneCore *lc, char *cl)
359 /* Isolate first word and args */
360 while(*ptr && !isspace(*ptr)) ++ptr;
364 /* set args to first nonblank */
366 while(*args && isspace(*args)) ++args;
370 if ( isdigit(*cl) || *cl == '#' || *cl == '*' )
372 while ( isdigit(*cl) || *cl == '#' || *cl == '*' )
374 linphone_core_send_dtmf(lc, *cl);
375 linphone_core_play_dtmf (lc,*cl,100);
376 ms_sleep(1); // be nice
380 // discard spurious trailing chars
384 /* Handle other kind of commands */
385 cmd=lpc_find_command(cl);
388 linphonec_out("'%s': Cannot understand this.\n", cl);
392 if ( ! cmd->func(lc, args) )
394 linphonec_out("Syntax error.\n");
395 linphonec_display_command_help(cmd);
402 * Generator function for command completion.
403 * STATE let us know whether to start from scratch;
404 * without any state (STATE==0), then we start at the
408 linphonec_command_generator(const char *text, int state)
410 static int index, len, adv;
420 * Return the next name which partially matches
421 * from the commands list
424 while ((name=commands[index].name))
426 ++index; /* so next call get next command */
428 if (strncmp(name, text, len) == 0)
430 return ortp_strdup(name);
437 while ((name=advanced_commands[index].name))
439 ++index; /* so next call get next command */
441 if (strncmp(name, text, len) == 0)
443 return ortp_strdup(name);
451 /***************************************************************************
455 ***************************************************************************/
458 lpc_cmd_help(LinphoneCore *lc, char *arg)
465 linphonec_out("Commands are:\n");
466 linphonec_out("---------------------------\n");
468 while (commands[i].help)
470 linphonec_out("%10.10s\t%s\n", commands[i].name,
475 linphonec_out("---------------------------\n");
476 linphonec_out("Type 'help <command>' for more details or 'help advanced' to list additional commands.\n");
481 if (strcmp(arg,"advanced")==0){
482 linphonec_out("Advanced commands are:\n");
483 linphonec_out("---------------------------\n");
485 while (advanced_commands[i].help)
487 linphonec_out("%10.10s\t%s\n", advanced_commands[i].name,
488 advanced_commands[i].help);
492 linphonec_out("---------------------------\n");
493 linphonec_out("Type 'help <command>' for more details.\n");
498 cmd=lpc_find_command(arg);
501 linphonec_out("No such command.\n");
505 linphonec_display_command_help(cmd);
510 static char callee_name[256]={0};
511 static char caller_name[256]={0};
513 static const char *get_call_status(LinphoneCall *call){
514 switch(linphone_call_get_state(call)){
515 case LinphoneCallPaused:
516 if (linphone_call_get_refer_to (call)!=NULL){
517 return "Paused (transfered)";
522 case LinphoneCallPausedByRemote:
523 return "Paused by remote";
525 case LinphoneCallIncomingReceived:
528 case LinphoneCallOutgoingInit:
529 case LinphoneCallOutgoingProgress:
530 return "Dialing out";
532 case LinphoneCallOutgoingEarlyMedia:
533 case LinphoneCallOutgoingRinging:
534 return "Remote ringing";
537 if (linphone_call_has_transfer_pending(call)){
538 return "Running (transfer pending)";
546 lpc_cmd_call(LinphoneCore *lc, char *args)
548 if ( ! args || ! *args )
554 LinphoneCallParams *cp=linphone_core_create_default_call_parameters (lc);
556 if ( linphone_core_in_call(lc) )
558 linphonec_out("Terminate or hold on the current call first.\n");
561 opt1=strstr(args,"--audio-only");
562 opt2=strstr(args,"--early-media");
565 linphone_call_params_enable_video (cp,FALSE);
569 linphone_call_params_enable_early_media_sending(cp,TRUE);
571 if ( NULL == (call=linphone_core_invite_with_params(lc, args,cp)) )
573 linphonec_out("Error from linphone_core_invite.\n");
577 snprintf(callee_name,sizeof(callee_name),"%s",args);
579 linphone_call_params_destroy(cp);
585 lpc_cmd_calls(LinphoneCore *lc, char *args){
586 const MSList *calls = linphone_core_get_calls(lc);
589 const MSList *p_calls = calls;
590 linphonec_out("ID\t\tDestination\t\t\t\tStatus\n---------------------------------------------------------------------\n");
591 while(p_calls != NULL)
593 LinphoneCall *call=(LinphoneCall*)p_calls->data;
594 char *tmp=linphone_call_get_remote_address_as_string(call);
595 linphonec_out("%li\t%s\t\t\t%s\r\n",
596 (long)linphone_call_get_user_pointer (call),
598 get_call_status(call));
599 p_calls = p_calls->next;
604 linphonec_out("No active call.\n");
611 lpc_cmd_chat(LinphoneCore *lc, char *args)
619 /* Isolate first and second arg */
620 while(*ptr && !isspace(*ptr)) ++ptr;
625 while(*arg2 && isspace(*arg2)) ++arg2;
629 /* missing one parameter */
632 LinphoneChatRoom *cr = linphone_core_create_chat_room(lc,arg1);
633 linphone_chat_room_send_message(cr,arg2);
634 linphone_chat_room_destroy(cr);
639 const char *linphonec_get_callee(){
643 const char *linphonec_get_caller(){
647 void linphonec_set_caller(const char *caller){
648 snprintf(caller_name,sizeof(caller_name)-1,"%s",caller);
652 lpc_cmd_transfer(LinphoneCore *lc, char *args)
657 const char *refer_to=NULL;
661 int n=sscanf(args,"%s %s %li",arg1,arg2,&id2);
662 if (n==1 || isalpha(*arg1)){
663 call=linphone_core_get_current_call(lc);
664 if (call==NULL && ms_list_size(linphone_core_get_calls(lc))==1){
665 call=(LinphoneCall*)linphone_core_get_calls(lc)->data;
669 linphonec_out("No active call, please specify a call id among the ones listed by 'calls' command.\n");
672 linphone_core_transfer_call(lc, call, refer_to);
675 refer_to=args+strlen(arg1)+1;
676 call=linphonec_get_call(id);
677 if (call==NULL) return 0;
678 linphone_core_transfer_call(lc, call, refer_to);
681 call=linphonec_get_call(id);
682 call2=linphonec_get_call(id2);
683 if (call==NULL || call2==NULL) return 0;
684 if (strcmp(arg2,"--to-call")!=0){
687 linphonec_out("Performing attended transfer of call %i to call %i",id,id2);
688 linphone_core_transfer_call_to_another (lc,call,call2);
691 linphonec_out("Transfer command requires at least one argument\n");
698 lpc_cmd_terminate(LinphoneCore *lc, char *args)
700 if (linphone_core_get_calls(lc)==NULL){
701 linphonec_out("No active calls\n");
706 if ( -1 == linphone_core_terminate_call(lc, NULL) ){
707 linphonec_out("Could not stop the active call.\n");
712 if(strcmp(args,"all")==0){
713 linphonec_out("We are going to stop all the calls.\n");
714 linphone_core_terminate_all_calls(lc);
717 /*the argument is a linphonec call id */
719 LinphoneCall *call=linphonec_get_call(id);
721 if (linphone_core_terminate_call(lc,call)==-1){
722 linphonec_out("Could not stop the call with id %li\n",id);
732 lpc_cmd_answer(LinphoneCore *lc, char *args){
735 int nb=ms_list_size(linphone_core_get_calls(lc));
737 //if just one call is present answer the only one in passing NULL to the linphone_core_accept_call ...
738 if ( -1 == linphone_core_accept_call(lc, NULL) )
740 linphonec_out("Fail to accept incoming call\n");
743 linphonec_out("There are no calls to answer.\n");
745 linphonec_out("Multiple calls in progress, please specify call id.\n");
751 if (sscanf(args,"%li",&id)==1){
752 LinphoneCall *call=linphonec_get_call (id);
753 if (linphone_core_accept_call (lc,call)==-1){
754 linphonec_out("Fail to accept call %i\n",id);
763 lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
767 if ( linphonec_get_autoanswer() ) {
768 linphonec_out("Auto answer is enabled. Use 'autoanswer disable' to disable.\n");
770 linphonec_out("Auto answer is disabled. Use 'autoanswer enable' to enable.\n");
775 if (strstr(args,"enable")){
776 linphonec_set_autoanswer(TRUE);
777 linphonec_out("Auto answer enabled.\n");
778 }else if (strstr(args,"disable")){
779 linphonec_set_autoanswer(FALSE);
780 linphonec_out("Auto answer disabled.\n");
786 lpc_cmd_quit(LinphoneCore *lc, char *args)
788 linphonec_main_loop_exit();
793 lpc_cmd_nat(LinphoneCore *lc, char *args)
798 if ( args ) args=lpc_strip_blanks(args);
802 linphone_core_set_nat_address(lc, args);
803 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS); */
806 nat = linphone_core_get_nat_address(lc);
807 use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress;
808 linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
814 lpc_cmd_stun(LinphoneCore *lc, char *args)
819 if ( args ) args=lpc_strip_blanks(args);
823 linphone_core_set_stun_server(lc, args);
824 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN); */
827 stun = linphone_core_get_stun_server(lc);
828 use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseStun;
829 linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
835 lpc_cmd_firewall(LinphoneCore *lc, char *args)
837 const char* setting=NULL;
839 if ( args ) args=lpc_strip_blanks(args);
843 if (strcmp(args,"none")==0)
845 linphone_core_set_firewall_policy(lc,LinphonePolicyNoFirewall);
847 else if (strcmp(args,"stun")==0)
849 setting = linphone_core_get_stun_server(lc);
852 linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
855 linphone_core_set_firewall_policy(lc,LinphonePolicyUseStun);
857 else if (strcmp(args,"nat")==0)
859 setting = linphone_core_get_nat_address(lc);
862 linphonec_out("No nat address is defined, use 'nat <address>' first");
865 linphone_core_set_firewall_policy(lc,LinphonePolicyUseNatAddress);
869 switch(linphone_core_get_firewall_policy(lc))
871 case LinphonePolicyNoFirewall:
872 linphonec_out("No firewall\n");
874 case LinphonePolicyUseStun:
875 linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
877 case LinphonePolicyUseNatAddress:
878 linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
885 /* Helper function for processing freind names */
887 lpc_friend_name(char **args, char **name)
889 /* Use space as a terminator unless quoted */
890 if (('"' == **args) || ('\'' == **args)){
895 while ((delim != *end) && ('\0' != *end)) end++;
897 fprintf(stderr, "Mismatched quotes\n");
904 *name = strsep(args, " ");
906 if (NULL == *args) { /* Means there was no separator */
907 fprintf(stderr, "Either name or address is missing\n");
910 if (NULL == *name) return 0;
917 lpc_cmd_friend(LinphoneCore *lc, char *args)
921 if ( args ) args=lpc_strip_blanks(args);
923 if ( ! args || ! *args ) return 0;
925 if ( !strncmp(args, "list", 4) )
927 return linphonec_friend_list(lc, args+4);
930 else if ( !strncmp(args, "call", 4) )
933 if ( ! *args ) return 0;
934 friend_num = strtol(args, NULL, 10);
936 if ( errno == ERANGE ) {
937 linphonec_out("Invalid friend number\n");
940 #endif /*_WIN32_WCE*/
941 linphonec_friend_call(lc, friend_num);
944 else if ( !strncmp(args, "delete", 6) )
947 if ( ! *args ) return 0;
948 while (*args == ' ') args++;
949 if ( ! *args ) return 0;
950 if (!strncmp(args, "all", 3))
956 friend_num = strtol(args, NULL, 10);
958 if ( errno == ERANGE ) {
959 linphonec_out("Invalid friend number\n");
962 #endif /*_WIN32_WCE*/
964 linphonec_friend_delete(lc, friend_num);
967 else if ( !strncmp(args, "add", 3) )
976 if ( ! *args ) return 0;
977 while (*args == ' ') args++;
978 if ( ! *args ) return 0;
980 if (!lpc_friend_name(&args, &name)) return 0;
982 while (*args == ' ') args++;
983 if ( ! *args ) return 0;
984 if (isdigit(*args)) {
985 strcpy (addr, "sip:");
986 addr_p = addr + strlen("sip:");
988 addr_orig = strsep(&args, " ");
989 if (1 >= strlen(addr_orig)) {
990 fprintf(stderr, "A single-digit address is not valid\n");
993 strcpy(addr_p, addr_orig);
994 linphonec_friend_add(lc, name, addr);
996 LinphoneFriend *new_friend;
997 new_friend = linphone_friend_new_with_addr(args);
998 linphone_core_add_friend(lc, new_friend);
1005 static int lpc_cmd_play(LinphoneCore *lc, char *args){
1006 if ( args ) args=lpc_strip_blanks(args);
1007 if ( ! args || ! *args ) return 0;
1008 linphone_core_set_play_file(lc,args);
1012 static int lpc_cmd_record(LinphoneCore *lc, char *args){
1013 if ( args ) args=lpc_strip_blanks(args);
1014 if ( ! args || ! *args ) return 0;
1015 linphone_core_set_record_file(lc,args);
1023 lpc_cmd_proxy(LinphoneCore *lc, char *args)
1030 if ( ! arg1 ) return 0;
1032 /* Isolate first and second arg */
1033 while(*ptr && !isspace(*ptr)) ++ptr;
1038 while(*arg2 && isspace(*arg2)) ++arg2;
1041 if (strcmp(arg1,"add")==0)
1043 #ifdef HAVE_READLINE
1044 rl_inhibit_completion=1;
1046 linphonec_proxy_add(lc);
1047 #ifdef HAVE_READLINE
1048 rl_inhibit_completion=0;
1051 else if (strcmp(arg1,"list")==0)
1053 linphonec_proxy_list(lc);
1055 else if (strcmp(arg1,"remove")==0)
1057 linphonec_proxy_remove(lc,atoi(arg2));
1059 else if (strcmp(arg1,"use")==0)
1061 if ( arg2 && *arg2 )
1063 proxynum=atoi(arg2);
1064 if ( linphonec_proxy_use(lc, proxynum) )
1065 linphonec_out("Default proxy set to %d.\n", proxynum);
1069 proxynum=linphone_core_get_default_proxy(lc, NULL);
1070 if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
1071 else linphonec_out("Current default proxy is %d.\n", proxynum);
1073 }else if (strcmp(arg1, "unuse")==0){
1074 linphone_core_set_default_proxy(lc, NULL);
1075 linphonec_out("Use no proxy.\n");
1078 else if (strcmp(arg1, "show")==0)
1082 if (strstr(arg2,"default"))
1084 proxynum=linphone_core_get_default_proxy(lc, NULL);
1085 if ( proxynum < 0 ) {
1086 linphonec_out("No default proxy defined\n");
1089 linphonec_proxy_show(lc,proxynum);
1093 linphonec_proxy_show(lc, atoi(arg2));
1096 else return 0; /* syntax error */
1101 return 0; /* syntax error */
1108 lpc_cmd_call_logs(LinphoneCore *lc, char *args)
1110 const MSList *elem=linphone_core_get_call_logs(lc);
1111 for (;elem!=NULL;elem=ms_list_next(elem))
1113 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
1114 char *str=linphone_call_log_to_str(cl);
1115 linphonec_out("%s\n",str);
1122 lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
1126 return 0; /* syntax error */
1129 if (strcmp(arg1,"status")==0)
1131 linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
1133 else if (strcmp(arg1,"enable")==0)
1135 linphone_core_enable_ipv6(lc,TRUE);
1136 linphonec_out("ipv6 use enabled.\n");
1138 else if (strcmp(arg1,"disable")==0)
1140 linphone_core_enable_ipv6(lc,FALSE);
1141 linphonec_out("ipv6 use disabled.\n");
1145 return 0; /* syntax error */
1150 static int devname_to_index(LinphoneCore *lc, const char *devname){
1153 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1154 if (strcmp(devname,*p)==0) return i;
1159 static const char *index_to_devname(LinphoneCore *lc, int index){
1162 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1163 if (i==index) return *p;
1168 static int lpc_cmd_soundcard(LinphoneCore *lc, char *args)
1176 if (!args) return 0; /* syntax error */
1178 /* Isolate first and second arg */
1179 while(*ptr && !isspace(*ptr)) ++ptr;
1184 while(*arg2 && isspace(*arg2)) ++arg2;
1187 if (strcmp(arg1, "list")==0)
1189 dev=linphone_core_get_sound_devices(lc);
1190 for(i=0; dev[i]!=NULL; ++i){
1191 linphonec_out("%i: %s\n",i,dev[i]);
1196 if (strcmp(arg1, "show")==0)
1198 linphonec_out("Ringer device: %s\n",
1199 linphone_core_get_ringer_device(lc));
1200 linphonec_out("Playback device: %s\n",
1201 linphone_core_get_playback_device(lc));
1202 linphonec_out("Capture device: %s\n",
1203 linphone_core_get_capture_device(lc));
1207 if (strcmp(arg1, "use")==0 && arg2)
1209 if (strcmp(arg2, "files")==0)
1211 linphonec_out("Using wav files instead of soundcard.\n");
1212 linphone_core_use_files(lc,TRUE);
1216 dev=linphone_core_get_sound_devices(lc);
1217 index=atoi(arg2); /* FIXME: handle not-a-number */
1218 for(i=0;dev[i]!=NULL;i++)
1220 if (i!=index) continue;
1222 linphone_core_set_ringer_device(lc,dev[i]);
1223 linphone_core_set_playback_device(lc,dev[i]);
1224 linphone_core_set_capture_device(lc,dev[i]);
1225 linphonec_out("Using sound device %s\n",dev[i]);
1228 linphonec_out("No such sound device\n");
1231 if (strcmp(arg1, "capture")==0)
1233 const char *devname=linphone_core_get_capture_device(lc);
1235 linphonec_out("Using capture device #%i (%s)\n",
1236 devname_to_index(lc,devname),devname);
1238 index=atoi(arg2); /* FIXME: handle not-a-number */
1239 devname=index_to_devname(lc,index);
1241 linphone_core_set_capture_device(lc,devname);
1242 linphonec_out("Using capture sound device %s\n",devname);
1245 linphonec_out("No such sound device\n");
1249 if (strcmp(arg1, "playback")==0)
1251 const char *devname=linphone_core_get_playback_device(lc);
1253 linphonec_out("Using playback device #%i (%s)\n",
1254 devname_to_index(lc,devname),devname);
1256 index=atoi(arg2); /* FIXME: handle not-a-number */
1257 devname=index_to_devname(lc,index);
1259 linphone_core_set_playback_device(lc,devname);
1260 linphonec_out("Using playback sound device %s\n",devname);
1263 linphonec_out("No such sound device\n");
1267 if (strcmp(arg1, "ring")==0)
1269 const char *devname=linphone_core_get_ringer_device(lc);
1271 linphonec_out("Using ring device #%i (%s)\n",
1272 devname_to_index(lc,devname),devname);
1274 index=atoi(arg2); /* FIXME: handle not-a-number */
1275 devname=index_to_devname(lc,index);
1277 linphone_core_set_ringer_device(lc,devname);
1278 linphonec_out("Using ring sound device %s\n",devname);
1281 linphonec_out("No such sound device\n");
1285 return 0; /* syntax error */
1288 static int lpc_cmd_webcam(LinphoneCore *lc, char *args)
1296 if (!args) return 0; /* syntax error */
1298 /* Isolate first and second arg */
1299 while(*ptr && !isspace(*ptr)) ++ptr;
1304 while(*arg2 && isspace(*arg2)) ++arg2;
1307 if (strcmp(arg1, "list")==0)
1309 dev=linphone_core_get_video_devices(lc);
1310 for(i=0; dev[i]!=NULL; ++i){
1311 linphonec_out("%i: %s\n",i,dev[i]);
1316 if (strcmp(arg1, "use")==0 && arg2)
1318 dev=linphone_core_get_video_devices(lc);
1319 index=atoi(arg2); /* FIXME: handle not-a-number */
1320 for(i=0;dev[i]!=NULL;i++)
1322 if (i!=index) continue;
1324 linphone_core_set_video_device(lc, dev[i]);
1325 linphonec_out("Using video device %s\n",dev[i]);
1328 linphonec_out("No such video device\n");
1331 return 0; /* syntax error */
1335 lpc_cmd_staticpic(LinphoneCore *lc, char *args)
1341 if (!args) return 0; /* Syntax error */
1343 /* Isolate first and second arg */
1344 while(*ptr && !isspace(*ptr)) ++ptr;
1349 while(*arg2 && isspace(*arg2)) ++arg2;
1352 if (strcmp(arg1, "set")==0 && arg2) {
1353 linphone_core_set_static_picture(lc, arg2);
1357 if (strcmp(arg1, "fps")==0) {
1359 float fps = atof(arg2); /* FIXME: Handle not-a-float */
1360 linphone_core_set_static_picture_fps(lc, fps);
1364 fps = linphone_core_get_static_picture_fps(lc);
1365 linphonec_out("Current FPS %f\n", fps);
1370 return 0; /* Syntax error */
1373 static int lpc_cmd_pause(LinphoneCore *lc, char *args){
1375 if(linphone_core_in_call(lc))
1377 linphone_core_pause_call(lc,linphone_core_get_current_call(lc));
1380 linphonec_out("you can only pause when a call is in process\n");
1384 static int lpc_cmd_resume(LinphoneCore *lc, char *args){
1386 if(linphone_core_in_call(lc))
1388 linphonec_out("There is already a call in process pause or stop it first");
1394 int n = sscanf(args, "%li", &id);
1396 LinphoneCall *call=linphonec_get_call (id);
1398 if(linphone_core_resume_call(lc,call)==-1){
1399 linphonec_out("There was a problem to resume the call check the remote address you gave %s\n",args);
1407 const MSList *calls = linphone_core_get_calls(lc);
1408 int nbcalls=ms_list_size(calls);
1411 if(linphone_core_resume_call(lc,calls->data) < 0)
1413 linphonec_out("There was a problem to resume the unique call.\n");
1416 }else if (nbcalls==0){
1417 linphonec_out("There is no calls at this time.\n");
1420 linphonec_out("There are %i calls at this time, please specify call id as given with 'calls' command.\n");
1427 /***************************************************************************
1429 * Commands helper functions
1431 ***************************************************************************/
1435 linphonec_proxy_add(LinphoneCore *lc)
1437 bool_t enable_register=FALSE;
1438 LinphoneProxyConfig *cfg;
1440 linphonec_out("Adding new proxy setup. Hit ^D to abort.\n");
1447 char *input=linphonec_readline("Enter proxy sip address: ");
1451 linphonec_out("Aborted.\n");
1456 clean=lpc_strip_blanks(input);
1462 cfg=linphone_proxy_config_new();
1463 if (linphone_proxy_config_set_server_addr(cfg,clean)<0)
1465 linphonec_out("Invalid sip address (sip:sip.domain.tld).\n");
1467 linphone_proxy_config_destroy(cfg);
1475 * SIP Proxy identity
1479 char *input=linphonec_readline("Your identity for this proxy: ");
1483 linphonec_out("Aborted.\n");
1484 linphone_proxy_config_destroy(cfg);
1489 clean=lpc_strip_blanks(input);
1495 linphone_proxy_config_set_identity(cfg, clean);
1496 if ( ! linphone_proxy_config_get_identity (cfg))
1498 linphonec_out("Invalid identity (sip:name@sip.domain.tld).\n");
1507 * SIP Proxy enable register
1511 char *input=linphonec_readline("Do you want to register on this proxy (yes/no): ");
1515 linphonec_out("Aborted.\n");
1516 linphone_proxy_config_destroy(cfg);
1521 clean=lpc_strip_blanks(input);
1527 if ( ! strcmp(clean, "yes") ) enable_register=TRUE;
1528 else if ( ! strcmp(clean, "no") ) enable_register=FALSE;
1530 linphonec_out("Please answer with 'yes' or 'no'\n");
1534 linphone_proxy_config_enableregister(cfg, enable_register);
1540 * SIP Proxy registration expiration
1542 if ( enable_register==TRUE )
1547 char *input=linphonec_readline("Specify register expiration time"
1548 " in seconds (default is 600): ");
1551 linphonec_out("Aborted.\n");
1552 linphone_proxy_config_destroy(cfg);
1556 expires=strtol(input, (char **)NULL, 10);
1557 if ( expires == LONG_MIN || expires == LONG_MAX )
1559 linphonec_out("Invalid value: %s\n", strerror(errno));
1564 linphone_proxy_config_expires(cfg, expires);
1565 linphonec_out("Expiration: %d seconds\n", linphone_proxy_config_get_expires (cfg));
1577 char *input=linphonec_readline("Specify route if needed: ");
1581 linphonec_out("Aborted.\n");
1582 linphone_proxy_config_destroy(cfg);
1587 clean=lpc_strip_blanks(input);
1590 linphonec_out("No route specified.\n");
1594 linphone_proxy_config_set_route(cfg, clean);
1595 if ( ! linphone_proxy_config_get_route(cfg) )
1597 linphonec_out("Invalid route.\n");
1607 * Final confirmation
1614 linphonec_out("--------------------------------------------\n");
1615 linphonec_proxy_display(cfg);
1616 linphonec_out("--------------------------------------------\n");
1617 input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: ");
1621 linphonec_out("Aborted.\n");
1622 linphone_proxy_config_destroy(cfg);
1627 clean=lpc_strip_blanks(input);
1633 if ( ! strcmp(clean, "yes") ) break;
1634 else if ( ! strcmp(clean, "no") )
1636 linphonec_out("Declined.\n");
1637 linphone_proxy_config_destroy(cfg);
1642 linphonec_out("Please answer with 'yes' or 'no'\n");
1648 linphone_core_add_proxy_config(lc,cfg);
1650 /* automatically set the last entered proxy as the default one */
1651 linphone_core_set_default_proxy(lc,cfg);
1653 linphonec_out("Proxy added.\n");
1657 linphonec_proxy_display(LinphoneProxyConfig *cfg)
1659 const char *route=linphone_proxy_config_get_route(cfg);
1660 const char *identity=linphone_proxy_config_get_identity(cfg);
1661 linphonec_out("sip address: %s\nroute: %s\nidentity: %s\nregister: %s\nexpires: %i\nregistered: %s\n",
1662 linphone_proxy_config_get_addr(cfg),
1663 (route!=NULL)? route:"",
1664 (identity!=NULL)?identity:"",
1665 linphone_proxy_config_register_enabled (cfg)?"yes":"no",
1666 linphone_proxy_config_get_expires (cfg),
1667 linphone_proxy_config_is_registered(cfg) ? "yes" : "no");
1670 static void linphonec_proxy_show(LinphoneCore *lc, int index)
1674 for(elem=linphone_core_get_proxy_config_list(lc),i=0;elem!=NULL;elem=elem->next,++i){
1676 LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)elem->data;
1677 linphonec_proxy_display(cfg);
1681 linphonec_out("No proxy with index %i\n", index);
1685 linphonec_proxy_list(LinphoneCore *lc)
1687 const MSList *proxies;
1689 int def=linphone_core_get_default_proxy(lc,NULL);
1691 proxies=linphone_core_get_proxy_config_list(lc);
1692 for(n=0;proxies!=NULL;proxies=ms_list_next(proxies),n++){
1694 linphonec_out("****** Proxy %i - this is the default one - *******\n",n);
1696 linphonec_out("****** Proxy %i *******\n",n);
1697 linphonec_proxy_display((LinphoneProxyConfig*)proxies->data);
1699 if ( ! n ) linphonec_out("No proxies defined\n");
1703 linphonec_proxy_remove(LinphoneCore *lc, int index)
1705 const MSList *proxies;
1706 LinphoneProxyConfig *cfg;
1707 proxies=linphone_core_get_proxy_config_list(lc);
1708 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1710 linphonec_out("No such proxy.\n");
1713 linphone_core_remove_proxy_config(lc,cfg);
1714 linphonec_out("Proxy %s removed.\n", linphone_proxy_config_get_addr(cfg));
1718 linphonec_proxy_use(LinphoneCore *lc, int index)
1720 const MSList *proxies;
1721 LinphoneProxyConfig *cfg;
1722 proxies=linphone_core_get_proxy_config_list(lc);
1723 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1725 linphonec_out("No such proxy (try 'proxy list').");
1728 linphone_core_set_default_proxy(lc,cfg);
1733 linphonec_friend_display(LinphoneFriend *fr)
1735 LinphoneAddress *uri=linphone_address_clone(linphone_friend_get_address(fr));
1738 linphonec_out("name: %s\n", linphone_address_get_display_name(uri));
1739 linphone_address_set_display_name(uri,NULL);
1740 str=linphone_address_as_string(uri);
1741 linphonec_out("address: %s\n", str);
1745 linphonec_friend_list(LinphoneCore *lc, char *pat)
1747 const MSList *friend;
1751 pat=lpc_strip_blanks(pat);
1752 if (!*pat) pat = NULL;
1755 friend = linphone_core_get_friend_list(lc);
1756 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1759 const char *name = linphone_address_get_display_name(
1760 linphone_friend_get_address((LinphoneFriend*)friend->data));
1761 if (name && ! strstr(name, pat) ) continue;
1763 linphonec_out("****** Friend %i *******\n",n);
1764 linphonec_friend_display((LinphoneFriend*)friend->data);
1771 linphonec_friend_call(LinphoneCore *lc, unsigned int num)
1773 const MSList *friend = linphone_core_get_friend_list(lc);
1777 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1782 addr = linphone_address_as_string(linphone_friend_get_address((LinphoneFriend*)friend->data));
1783 ret=lpc_cmd_call(lc, addr);
1788 linphonec_out("No such friend %u\n", num);
1794 linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr)
1796 LinphoneFriend *newFriend;
1800 snprintf(url, PATH_MAX, "%s <%s>", name, addr);
1801 newFriend = linphone_friend_new_with_addr(url);
1802 linphone_core_add_friend(lc, newFriend);
1808 linphonec_friend_delete(LinphoneCore *lc, int num)
1810 const MSList *friend = linphone_core_get_friend_list(lc);
1813 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1817 linphone_core_remove_friend(lc, friend->data);
1825 for (i = 0 ; i < n ; i++)
1826 linphonec_friend_delete(lc, 0);
1830 linphonec_out("No such friend %u\n", num);
1835 linphonec_display_command_help(LPC_COMMAND *cmd)
1837 if ( cmd->doc ) linphonec_out ("%s\n", cmd->doc);
1838 else linphonec_out("%s\n", cmd->help);
1842 static int lpc_cmd_register(LinphoneCore *lc, char *args){
1846 LinphoneProxyConfig *cfg;
1851 /* it means that you want to register the default proxy */
1852 LinphoneProxyConfig *cfg=NULL;
1853 linphone_core_get_default_proxy(lc,&cfg);
1856 if(!linphone_proxy_config_is_registered(cfg)) {
1857 linphone_proxy_config_enable_register(cfg,TRUE);
1858 linphone_proxy_config_done(cfg);
1860 linphonec_out("default proxy already registered\n");
1863 linphonec_out("we do not have a default proxy\n");
1868 passwd[0]=proxy[0]=identity[0]='\0';
1869 sscanf(args,"%s %s %s",identity,proxy,passwd);
1870 if (proxy[0]=='\0' || identity[0]=='\0'){
1871 linphonec_out("Missing parameters, see help register\n");
1874 if (passwd[0]!='\0'){
1875 LinphoneAddress *from;
1876 LinphoneAuthInfo *info;
1877 if ((from=linphone_address_new(identity))!=NULL){
1879 snprintf(realm,sizeof(realm)-1,"\"%s\"",linphone_address_get_domain(from));
1880 info=linphone_auth_info_new(linphone_address_get_username(from),NULL,passwd,NULL,NULL);
1881 linphone_core_add_auth_info(lc,info);
1882 linphone_address_destroy(from);
1883 linphone_auth_info_destroy(info);
1886 elem=linphone_core_get_proxy_config_list(lc);
1888 cfg=(LinphoneProxyConfig*)elem->data;
1889 linphone_proxy_config_edit(cfg);
1891 else cfg=linphone_proxy_config_new();
1892 linphone_proxy_config_set_identity(cfg,identity);
1893 linphone_proxy_config_set_server_addr(cfg,proxy);
1894 linphone_proxy_config_enable_register(cfg,TRUE);
1895 if (elem) linphone_proxy_config_done(cfg);
1896 else linphone_core_add_proxy_config(lc,cfg);
1897 linphone_core_set_default_proxy(lc,cfg);
1901 static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
1902 LinphoneProxyConfig *cfg=NULL;
1903 linphone_core_get_default_proxy(lc,&cfg);
1904 if (cfg && linphone_proxy_config_is_registered(cfg)) {
1905 linphone_proxy_config_edit(cfg);
1906 linphone_proxy_config_enable_register(cfg,FALSE);
1907 linphone_proxy_config_done(cfg);
1909 linphonec_out("unregistered\n");
1914 static int lpc_cmd_duration(LinphoneCore *lc, char *args){
1915 LinphoneCallLog *cl;
1916 const MSList *elem=linphone_core_get_call_logs(lc);
1917 for(;elem!=NULL;elem=elem->next){
1918 if (elem->next==NULL){
1919 cl=(LinphoneCallLog*)elem->data;
1920 linphonec_out("%i seconds\n",cl->duration);
1926 static int lpc_cmd_status(LinphoneCore *lc, char *args)
1928 LinphoneProxyConfig *cfg;
1930 if ( ! args ) return 0;
1931 linphone_core_get_default_proxy(lc,&cfg);
1932 if (strstr(args,"register"))
1936 if (linphone_proxy_config_is_registered(cfg)){
1937 linphonec_out("registered, identity=%s duration=%i\n",
1938 linphone_proxy_config_get_identity(cfg),
1939 linphone_proxy_config_get_expires(cfg));
1940 }else if (linphone_proxy_config_register_enabled(cfg)){
1941 linphonec_out("registered=-1\n");
1942 }else linphonec_out("registered=0\n");
1944 else linphonec_out("registered=0\n");
1946 else if (strstr(args,"autoanswer"))
1948 if (cfg && linphone_proxy_config_is_registered(cfg))
1949 linphonec_out("autoanswer=%i\n",linphonec_get_autoanswer());
1950 else linphonec_out("unregistered\n");
1952 else if (strstr(args,"hook"))
1954 LinphoneCall *call=linphone_core_get_current_call (lc);
1955 LinphoneCallState call_state=LinphoneCallIdle;
1956 if (call) call_state=linphone_call_get_state(call);
1959 case LinphoneCallOutgoingInit:
1960 linphonec_out("hook=outgoing_init sip:%s\n",linphonec_get_callee());
1962 case LinphoneCallOutgoingProgress:
1963 linphonec_out("hook=dialing sip:%s\n",linphonec_get_callee());
1965 case LinphoneCallOutgoingRinging:
1966 linphonec_out("hook=ringing sip:%s\n",linphonec_get_callee());
1968 case LinphoneCallPaused:
1969 linphonec_out("hook=paused sip:%s\n",linphonec_get_callee());
1971 case LinphoneCallIdle:
1972 linphonec_out("hook=offhook\n");
1974 case LinphoneCallStreamsRunning:
1975 case LinphoneCallConnected:
1976 if (linphone_call_get_dir(call)==LinphoneCallOutgoing){
1977 linphonec_out("Call out, hook=%s duration=%i, muted=%s rtp-xmit-muted=%s\n", linphonec_get_callee(),
1978 linphone_core_get_current_call_duration(lc),
1979 linphone_core_is_mic_muted (lc) ? "yes" : "no",
1980 linphone_core_is_rtp_muted(lc) ? "yes" : "no");
1982 linphonec_out("hook=answered duration=%i %s\n" ,
1983 linphone_core_get_current_call_duration(lc), linphonec_get_caller());
1986 case LinphoneCallIncomingReceived:
1987 linphonec_out("Incoming call from %s\n",linphonec_get_caller());
1999 static int lpc_cmd_ports(LinphoneCore *lc, char *args)
2003 linphonec_out("sip port = %i\naudio rtp port = %i\nvideo rtp port = %i\n",
2004 linphone_core_get_sip_port(lc),
2005 linphone_core_get_audio_port(lc),
2006 linphone_core_get_video_port(lc));
2009 if (sscanf(args,"sip %i",&port)==1){
2010 linphonec_out("Setting sip port to %i\n",port);
2011 linphone_core_set_sip_port(lc,port);
2017 static int lpc_cmd_speak(LinphoneCore *lc, char *args){
2026 if (!args) return 0;
2027 memset(voice,0,sizeof(voice));
2028 sscanf(args,"%s63",voice);
2029 sentence=args+strlen(voice);
2030 wavfile=tempnam("/tmp/","linphonec-espeak-");
2031 snprintf(cl,sizeof(cl),"espeak -v %s -s 100 -w %s --stdin",voice,wavfile);
2034 ms_error("Could not open pipe to espeak !");
2037 fprintf(file,"%s",sentence);
2038 status=pclose(file);
2039 if (WEXITSTATUS(status)==0){
2040 linphone_core_set_play_file(lc,wavfile);
2042 linphonec_out("espeak command failed.");
2045 linphonec_out("Sorry, this command is not implemented in windows version.");
2050 static int lpc_cmd_acodec(LinphoneCore *lc, char *args){
2051 return lpc_cmd_codec(AUDIO, lc, args);
2054 static int lpc_cmd_vcodec(LinphoneCore *lc, char *args){
2055 return lpc_cmd_codec(VIDEO, lc, args);
2058 static int lpc_cmd_codec(int type, LinphoneCore *lc, char *args){
2063 if (!args) return 0;
2065 /* Isolate first and second arg */
2066 while(*ptr && !isspace(*ptr)) ++ptr;
2071 while(*arg2 && isspace(*arg2)) ++arg2;
2074 if (strcmp(arg1,"enable")==0)
2076 #ifdef HAVE_READLINE
2077 rl_inhibit_completion=1;
2079 if (!strcmp(arg2,"all")) linphonec_codec_enable(type,lc,-1);
2080 else linphonec_codec_enable(type,lc,atoi(arg2));
2081 #ifdef HAVE_READLINE
2082 rl_inhibit_completion=0;
2085 else if (strcmp(arg1,"list")==0)
2087 linphonec_codec_list(type,lc);
2089 else if (strcmp(arg1,"disable")==0)
2091 if (!strcmp(arg2,"all")) linphonec_codec_disable(type,lc,-1);
2092 else linphonec_codec_disable(type,lc,atoi(arg2));
2096 return 0; /* syntax error */
2102 static void linphonec_codec_list(int type, LinphoneCore *lc){
2105 const MSList *node=NULL;
2107 if (type == AUDIO) {
2108 node=linphone_core_get_audio_codecs(lc);
2109 } else if(type==VIDEO) {
2110 node=linphone_core_get_video_codecs(lc);
2113 for(;node!=NULL;node=ms_list_next(node)){
2114 pt=(PayloadType*)(node->data);
2115 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate,
2116 linphone_core_payload_type_enabled(lc,pt) ? "enabled" : "disabled");
2121 static void linphonec_codec_enable(int type, LinphoneCore *lc, int sel_index){
2124 const MSList *node=NULL;
2126 if (type == AUDIO) {
2127 node=linphone_core_get_audio_codecs(lc);
2128 } else if(type==VIDEO) {
2129 node=linphone_core_get_video_codecs(lc);
2132 for(;node!=NULL;node=ms_list_next(node)){
2133 if (index == sel_index || sel_index == -1) {
2134 pt=(PayloadType*)(node->data);
2135 linphone_core_enable_payload_type (lc,pt,TRUE);
2136 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "enabled");
2142 static void linphonec_codec_disable(int type, LinphoneCore *lc, int sel_index){
2145 const MSList *node=NULL;
2147 if (type == AUDIO) {
2148 node=linphone_core_get_audio_codecs(lc);
2149 } else if(type==VIDEO) {
2150 node=linphone_core_get_video_codecs(lc);
2153 for(;node!=NULL;node=ms_list_next(node)){
2154 if (index == sel_index || sel_index == -1) {
2155 pt=(PayloadType*)(node->data);
2156 linphone_core_enable_payload_type (lc,pt,FALSE);
2157 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "disabled");
2163 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){
2167 LpConfig *config=linphone_core_get_config(lc);
2169 if (!args) return 0;
2171 /* Isolate first and second arg */
2172 while(*ptr && !isspace(*ptr)) ++ptr;
2177 while(*arg2 && isspace(*arg2)) ++arg2;
2180 if (strcmp(arg1,"on")==0){
2181 int delay, tail_len, frame_size;
2184 linphone_core_enable_echo_cancellation(lc,1);
2187 n = sscanf(arg2, "%d %d %d", &delay, &tail_len, &frame_size);
2190 lp_config_set_int(config,"sound","ec_delay",delay);
2193 lp_config_set_int(config,"sound","ec_delay",delay);
2194 lp_config_set_int(config,"sound","ec_tail_len",tail_len);
2197 lp_config_set_int(config,"sound","ec_delay",delay);
2198 lp_config_set_int(config,"sound","ec_tail_len",tail_len);
2199 lp_config_set_int(config,"sound","ec_framesize",frame_size);
2203 else if (strcmp(arg1,"off")==0){
2204 linphone_core_enable_echo_cancellation(lc,0);
2206 else if (strcmp(arg1,"show")==0){
2207 linphonec_out("echo cancellation is %s; delay %d, tail length %d, frame size %d\n",
2208 linphone_core_echo_cancellation_enabled(lc) ? "on" : "off",
2209 lp_config_get_int(config,"sound","ec_delay",0),
2210 lp_config_get_int(config,"sound","ec_tail_len",0),
2211 lp_config_get_int(config,"sound","ec_framesize",0));
2220 static int lpc_cmd_echolimiter(LinphoneCore *lc, char *args){
2222 if (strcmp(args,"on")==0){
2223 linphone_core_enable_echo_limiter (lc,TRUE);
2224 }else if (strcmp(args,"off")==0){
2225 linphone_core_enable_echo_limiter (lc,FALSE);
2228 linphonec_out("Echo limiter is now %s.\n",linphone_core_echo_limiter_enabled (lc) ? "on":"off");
2232 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args)
2234 linphone_core_mute_mic(lc, 1);
2238 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args){
2239 linphone_core_mute_mic(lc, 0);
2243 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args)
2245 bool_t rtp_xmit_off=FALSE;
2249 if(strstr(args,"1"))rtp_xmit_off=TRUE;
2250 if(linphone_core_get_current_call (lc)==NULL)
2251 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_xmit_off);
2253 linphonec_out("nortp-on-audio-mute: call in progress - cannot change state\n");
2255 rtp_xmit_off=linphone_core_get_rtp_no_xmit_on_audio_mute(lc);
2256 if (rtp_xmit_off) status="off";
2258 linphonec_out("rtp transmit %s when audio muted\n",status);
2262 #ifdef VIDEO_ENABLED
2263 static int _lpc_cmd_video_window(LinphoneCore *lc, char *args, bool_t is_preview){
2264 char subcommand[64];
2267 VideoParams *params=is_preview ? &lpc_preview_params : &lpc_video_params;
2269 if (!args) return 0;
2270 err=sscanf(args,"%s %i %i",subcommand,&a,&b);
2272 if (strcmp(subcommand,"pos")==0){
2273 if (err<3) return 0;
2276 params->refresh=TRUE;
2277 }else if (strcmp(subcommand,"size")==0){
2278 if (err<3) return 0;
2281 params->refresh=TRUE;
2282 }else if (strcmp(subcommand,"show")==0){
2284 params->refresh=TRUE;
2285 if (is_preview) linphone_core_enable_video_preview (lc,TRUE);
2286 }else if (strcmp(subcommand,"hide")==0){
2288 params->refresh=TRUE;
2289 if (is_preview) linphone_core_enable_video_preview (lc,FALSE);
2290 }else if (strcmp(subcommand,"id")==0){
2292 linphonec_out("vwindow id: 0x%x\n",is_preview ? linphone_core_get_native_preview_window_id (lc) :
2293 linphone_core_get_native_video_window_id (lc));
2295 } else if (err != 2) return 0;
2298 linphone_core_set_native_preview_window_id (lc,a);
2300 linphone_core_set_native_video_window_id(lc,a);
2301 }else if (is_preview==TRUE){
2302 if (strcmp(subcommand,"integrated")==0){
2303 linphone_core_use_preview_window (lc,FALSE);
2304 }else if (strcmp(subcommand,"standalone")==0){
2305 linphone_core_use_preview_window(lc,TRUE);
2312 static int lpc_cmd_video_window(LinphoneCore *lc, char *args){
2313 return _lpc_cmd_video_window(lc, args, FALSE);
2316 static int lpc_cmd_preview_window(LinphoneCore *lc, char *args){
2317 return _lpc_cmd_video_window(lc, args, TRUE);
2321 static void lpc_display_global_state(LinphoneCore *lc){
2322 linphonec_out("Global liblinphone state\n%s\n",
2323 linphone_global_state_to_string(linphone_core_get_global_state(lc)));
2326 static void lpc_display_call_states(LinphoneCore *lc){
2330 linphonec_out("Call states\n"
2331 "Id | Destination | State\n"
2332 "---------------------------------------------------------------\n");
2333 elem=linphone_core_get_calls(lc);
2335 linphonec_out("(empty)\n");
2337 for(;elem!=NULL;elem=elem->next){
2338 call=(LinphoneCall*)elem->data;
2339 tmp=linphone_call_get_remote_address_as_string (call);
2340 linphonec_out("%-2i | %-35s | %s\n",(int)(long)linphone_call_get_user_pointer(call),
2341 tmp,linphone_call_state_to_string(linphone_call_get_state(call)));
2347 static void lpc_display_proxy_states(LinphoneCore *lc){
2349 linphonec_out("Proxy registration states\n"
2350 " Identity | State\n"
2351 "------------------------------------------------------------\n");
2352 elem=linphone_core_get_proxy_config_list (lc);
2353 if (elem==NULL) linphonec_out("(empty)\n");
2355 for(;elem!=NULL;elem=elem->next){
2356 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2357 linphonec_out("%-40s | %s\n",linphone_proxy_config_get_identity (cfg),
2358 linphone_registration_state_to_string(linphone_proxy_config_get_state(cfg)));
2363 static int lpc_cmd_states(LinphoneCore *lc, char *args){
2365 lpc_display_global_state(lc);
2366 lpc_display_call_states(lc);
2367 lpc_display_proxy_states(lc);
2370 if (strcmp(args,"global")==0){
2371 lpc_display_global_state(lc);
2374 if (strcmp(args,"proxies")==0){
2375 lpc_display_proxy_states(lc);
2378 if (strcmp(args,"calls")==0){
2379 lpc_display_call_states(lc);
2385 #ifdef VIDEO_ENABLED
2386 static int lpc_cmd_camera(LinphoneCore *lc, char *args){
2387 LinphoneCall *call=linphone_core_get_current_call(lc);
2388 bool_t activated=FALSE;
2390 if (linphone_core_video_enabled (lc)==FALSE){
2391 linphonec_out("Video is disabled, re-run linphonec with -V option.");
2396 if (strcmp(args,"on")==0)
2398 else if (strcmp(args,"off")==0)
2406 linphonec_camera_enabled=activated;
2408 if (linphonec_camera_enabled){
2409 linphonec_out("Camera is enabled. Video stream will be setup immediately for outgoing and incoming calls.\n");
2411 linphonec_out("Camera is disabled. Calls will be established with audio-only, with the possibility to later add video using 'camera on'.\n");
2414 const LinphoneCallParams *cp=linphone_call_get_current_params (call);
2416 linphone_call_enable_camera(call,activated);
2417 if ((activated && !linphone_call_params_video_enabled (cp))){
2418 /*update the call to add the video stream*/
2419 LinphoneCallParams *ncp=linphone_call_params_copy(cp);
2420 linphone_call_params_enable_video(ncp,TRUE);
2421 linphone_core_update_call(lc,call,ncp);
2422 linphone_call_params_destroy (ncp);
2423 linphonec_out("Trying to bring up video stream...\n");
2426 if (linphone_call_camera_enabled (call))
2427 linphonec_out("Camera is allowed for current call.\n");
2428 else linphonec_out("Camera is dis-allowed for current call.\n");
2433 static int lpc_cmd_snapshot(LinphoneCore *lc, char *args){
2435 if (!args) return 0;
2436 call=linphone_core_get_current_call(lc);
2438 linphone_call_take_video_snapshot(call,args);
2439 linphonec_out("Taking video snapshot in file %s\n", args);
2440 }else linphonec_out("There is no active call.\n");
2444 static int lpc_cmd_vfureq(LinphoneCore *lc, char *arg){
2446 call=linphone_core_get_current_call(lc);
2448 linphone_call_send_vfu_request(call);
2449 linphonec_out("VFU request sent\n");
2450 }else linphonec_out("There is no active call.\n");
2455 static int lpc_cmd_identify(LinphoneCore *lc, char *args){
2457 const char *remote_ua;
2459 call=linphone_core_get_current_call(lc);
2461 linphonec_out("There is currently running call. Specify call id.\n");
2465 call=linphonec_get_call(atoi(args));
2470 remote_ua=linphone_call_get_remote_user_agent(call);
2472 linphonec_out("Remote user agent string is: %s\n",remote_ua);
2477 static int lpc_cmd_ringback(LinphoneCore *lc, char *args){
2478 if (!args) return 0;
2479 if (strcmp(args,"disable")==0){
2480 linphone_core_set_remote_ringback_tone(lc,NULL);
2481 linphonec_out("Disabling ringback tone.\n");
2484 linphone_core_set_remote_ringback_tone (lc,args);
2485 linphonec_out("Using %s as ringback tone to be played to callers.",args);
2489 /***************************************************************************
2491 * Command table management funx
2493 ***************************************************************************/
2496 * Find a command given its name
2498 static LPC_COMMAND *
2499 lpc_find_command(const char *name)
2503 for (i=0; commands[i].name; ++i)
2505 if (strcmp(name, commands[i].name) == 0)
2506 return &commands[i];
2509 for (i=0; advanced_commands[i].name; ++i)
2511 if (strcmp(name, advanced_commands[i].name) == 0)
2512 return &advanced_commands[i];
2515 return (LPC_COMMAND *)NULL;
2519 /****************************************************************************
2521 * $Log: commands.c,v $
2522 * Revision 1.39 2008/07/03 15:08:34 smorlat
2523 * api cleanups, interface in progress.
2525 * Revision 1.38 2008/06/17 20:38:59 smorlat
2526 * added missing file.
2528 * Revision 1.37 2008/04/09 09:26:00 smorlat
2529 * merge various patches
2532 * Revision 1.36 2007/08/01 14:47:53 strk
2533 * * console/commands.c: Clean up commands 'nat', 'stun'
2534 * and 'firewall' to be more intuitive.
2536 * Revision 1.35 2007/06/27 09:01:25 smorlat
2537 * logging improvements.
2539 * Revision 1.34 2007/02/20 10:17:13 smorlat
2540 * linphonec friends patch2
2542 * Revision 1.31 2006/09/22 07:22:47 smorlat
2543 * linphonecore api changes.
2545 * Revision 1.30 2006/09/08 15:32:57 smorlat
2546 * support for using files instead of soundcard (used by linphonec only)
2548 * Revision 1.29 2006/08/28 14:29:07 smorlat
2551 * Revision 1.28 2006/08/21 12:49:59 smorlat
2552 * merged several little patches.
2554 * Revision 1.27 2006/07/17 18:45:00 smorlat
2555 * support for several event queues in ortp.
2556 * glib dependency removed from coreapi/ and console/
2558 * Revision 1.26 2006/04/14 15:16:36 smorlat
2559 * soundcard use did nothing !
2561 * Revision 1.25 2006/04/06 20:09:33 smorlat
2562 * add linphonec command to see and select sound devices.
2564 * Revision 1.24 2006/03/04 11:17:10 smorlat
2565 * mediastreamer2 in progress.
2567 * Revision 1.23 2006/02/20 21:14:01 strk
2568 * Handled syntax errors with 'friend' command
2570 * Revision 1.22 2006/02/20 10:20:29 strk
2571 * Added substring-based filter support for command 'friend list'
2573 * Revision 1.21 2006/02/02 15:39:18 strk
2574 * - Added 'friend list' and 'friend call' commands
2575 * - Allowed for multiple DTFM send in a single line
2576 * - Added status-specific callback (bare version)
2578 * Revision 1.20 2006/01/26 11:54:34 strk
2579 * More robust 'nat' command handler (strip blanks in args)
2581 * Revision 1.19 2006/01/26 09:48:05 strk
2582 * Added limits.h include
2584 * Revision 1.18 2006/01/26 02:18:05 strk
2585 * Added new commands 'nat use' and 'nat unuse'.
2586 * These will required a pending patch to linphonecore.c
2589 * Revision 1.17 2006/01/20 14:12:33 strk
2590 * Added linphonec_init() and linphonec_finish() functions.
2591 * Handled SIGINT and SIGTERM to invoke linphonec_finish().
2592 * Handling of auto-termination (-t) moved to linphonec_finish().
2593 * Reworked main (input read) loop to not rely on 'terminate'
2594 * and 'run' variable (dropped). configfile_name allocated on stack
2595 * using PATH_MAX limit. Changed print_usage signature to allow
2596 * for an exit_status specification.
2598 * Revision 1.16 2006/01/18 09:25:32 strk
2599 * Command completion inhibited in proxy addition and auth request prompts.
2600 * Avoided use of linphonec_readline's internal filename completion.
2602 * Revision 1.15 2006/01/14 13:29:32 strk
2603 * Reworked commands interface to use a table structure,
2604 * used by command line parser and help function.
2605 * Implemented first level of completion (commands).
2606 * Added notification of invalid "answer" and "terminate"
2607 * commands (no incoming call, no active call).
2608 * Forbidden "call" intialization when a call is already active.
2609 * Cleaned up all commands, adding more feedback and error checks.
2611 * Revision 1.14 2006/01/13 13:00:29 strk
2612 * Added linphonec.h. Code layout change (added comments, forward decl,
2613 * globals on top, copyright notices and Logs). Handled out-of-memory
2614 * condition on history management. Removed assumption on sizeof(char).
2615 * Fixed bug in authentication prompt (introduced by linphonec_readline).
2616 * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
2619 ****************************************************************************/