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_redirect(LinphoneCore *, char *);
64 static int lpc_cmd_call_logs(LinphoneCore *, char *);
65 static int lpc_cmd_ipv6(LinphoneCore *, char *);
66 static int lpc_cmd_transfer(LinphoneCore *, char *);
67 static int lpc_cmd_quit(LinphoneCore *, char *);
68 static int lpc_cmd_nat(LinphoneCore *, char *);
69 static int lpc_cmd_stun(LinphoneCore *, char *);
70 static int lpc_cmd_firewall(LinphoneCore *, char *);
71 static int lpc_cmd_friend(LinphoneCore *, char*);
72 static int lpc_cmd_soundcard(LinphoneCore *, char *);
73 static int lpc_cmd_webcam(LinphoneCore *, char *);
74 static int lpc_cmd_staticpic(LinphoneCore *, char *);
75 static int lpc_cmd_play(LinphoneCore *, char *);
76 static int lpc_cmd_record(LinphoneCore *, char *);
77 static int lpc_cmd_register(LinphoneCore *, char *);
78 static int lpc_cmd_unregister(LinphoneCore *, char *);
79 static int lpc_cmd_duration(LinphoneCore *lc, char *args);
80 static int lpc_cmd_status(LinphoneCore *lc, char *args);
81 static int lpc_cmd_ports(LinphoneCore *lc, char *args);
82 static int lpc_cmd_param(LinphoneCore *lc, char *args);
83 static int lpc_cmd_speak(LinphoneCore *lc, char *args);
84 static int lpc_cmd_acodec(LinphoneCore *lc, char *args);
85 static int lpc_cmd_vcodec(LinphoneCore *lc, char *args);
86 static int lpc_cmd_codec(int type, LinphoneCore *lc, char *args);
87 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args);
88 static int lpc_cmd_echolimiter(LinphoneCore *lc, char *args);
89 static int lpc_cmd_pause(LinphoneCore *lc, char *args);
90 static int lpc_cmd_resume(LinphoneCore *lc, char *args);
91 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args);
92 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args);
93 static int lpc_cmd_playback_gain(LinphoneCore *lc, char *args);
94 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args);
96 static int lpc_cmd_camera(LinphoneCore *lc, char *args);
97 static int lpc_cmd_video_window(LinphoneCore *lc, char *args);
98 static int lpc_cmd_preview_window(LinphoneCore *lc, char *args);
99 static int lpc_cmd_snapshot(LinphoneCore *lc, char *args);
100 static int lpc_cmd_vfureq(LinphoneCore *lc, char *arg);
102 static int lpc_cmd_states(LinphoneCore *lc, char *args);
103 static int lpc_cmd_identify(LinphoneCore *lc, char *args);
104 static int lpc_cmd_ringback(LinphoneCore *lc, char *args);
105 static int lpc_cmd_conference(LinphoneCore *lc, char *args);
106 static int lpc_cmd_zrtp_verified(LinphoneCore *lc, char *args);
107 static int lpc_cmd_zrtp_unverified(LinphoneCore *lc, char *args);
109 /* Command handler helpers */
110 static void linphonec_proxy_add(LinphoneCore *lc);
111 static void linphonec_proxy_display(LinphoneProxyConfig *lc);
112 static void linphonec_proxy_list(LinphoneCore *lc);
113 static void linphonec_proxy_remove(LinphoneCore *lc, int index);
114 static int linphonec_proxy_use(LinphoneCore *lc, int index);
115 static void linphonec_proxy_show(LinphoneCore *lc,int index);
116 static void linphonec_friend_display(LinphoneFriend *fr);
117 static int linphonec_friend_list(LinphoneCore *lc, char *arg);
118 static void linphonec_display_command_help(LPC_COMMAND *cmd);
119 static int linphonec_friend_call(LinphoneCore *lc, unsigned int num);
121 static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
123 static int linphonec_friend_delete(LinphoneCore *lc, int num);
124 static int linphonec_friend_delete(LinphoneCore *lc, int num);
125 static void linphonec_codec_list(int type, LinphoneCore *lc);
126 static void linphonec_codec_enable(int type, LinphoneCore *lc, int index);
127 static void linphonec_codec_disable(int type, LinphoneCore *lc, int index);
128 static void lpc_display_call_states(LinphoneCore *lc);
130 /* Command table management */
131 static LPC_COMMAND *lpc_find_command(const char *name);
133 void linphonec_out(const char *fmt,...);
135 VideoParams lpc_video_params={-1,-1,-1,-1,0,TRUE};
136 VideoParams lpc_preview_params={-1,-1,-1,-1,0,TRUE};
138 /***************************************************************************
142 ***************************************************************************/
147 static LPC_COMMAND commands[] = {
148 { "help", lpc_cmd_help, "Print commands help.",
149 "'help <command>'\t: displays specific help for command.\n"
150 "'help advanced'\t: shows advanced commands.\n"
152 { "call", lpc_cmd_call, "Call a SIP uri or number",
154 "'call <sip-url or number> [options]' \t: initiate a call to the specified destination.\n"
156 "--audio-only : initiate the call without video.\n"
157 "--early-media : sends audio and video stream immediately when remote proposes early media.\n"
159 "'call <sip-url or number>' \t: initiate a call to the specified destination.\n"
162 { "calls", lpc_cmd_calls, "Show all the current calls with their id and status.",
165 { "chat", lpc_cmd_chat, "Chat with a SIP uri",
166 "'chat <sip-url> \"message\"' "
167 ": send a chat message \"message\" to the specified destination."
169 { "terminate", lpc_cmd_terminate, "Terminate a call",
170 "'terminate' : Terminate the current call\n"
171 "'terminate <call id>' : Terminate the call with supplied id\n"
172 "'terminate <all>' : Terminate all the current calls\n"
174 { "answer", lpc_cmd_answer, "Answer a call",
175 "'answer' : Answer the current incoming call\n"
176 "'answer <call id>' : Answer the call with given id\n"
178 { "pause", lpc_cmd_pause, "pause a call",
179 "'pause' : pause the current call\n"},
180 { "resume", lpc_cmd_resume, "resume a call",
181 "'resume' : resume the unique call\n"
182 "'resume <call id>' : hold off the call with given id\n"},
183 { "transfer", lpc_cmd_transfer,
184 "Transfer a call to a specified destination.",
185 "'transfer <sip-uri>' : transfers the current active call to the destination sip-uri\n"
186 "'transfer <call id> <sip-uri>': transfers the call with 'id' to the destination sip-uri\n"
187 "'transfer <call id1> --to-call <call id2>': transfers the call with 'id1' to the destination of call 'id2' (attended transfer)\n"
189 { "conference", lpc_cmd_conference, "Create and manage an audio conference.",
190 "'conference add <call id> : join the call with id 'call id' into the audio conference."
191 "'conference rm <call id> : remove the call with id 'call id' from the audio conference."
193 { "mute", lpc_cmd_mute_mic,
194 "Mute microphone and suspend voice transmission."},
196 { "camera", lpc_cmd_camera, "Send camera output for current call.",
197 "'camera on'\t: allow sending of local camera video to remote end.\n"
198 "'camera off'\t: disable sending of local camera's video to remote end.\n"},
200 { "unmute", lpc_cmd_unmute_mic,
201 "Unmute microphone and resume voice transmission."},
202 { "playbackgain", lpc_cmd_playback_gain,
203 "Adjust playback gain."},
204 { "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
206 { "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
207 "'autoanswer' \t: show current autoanswer mode\n"
208 "'autoanswer enable'\t: enable autoanswer mode\n"
209 "'autoanswer disable'\t: disable autoanswer mode��\n"},
210 { "proxy", lpc_cmd_proxy, "Manage proxies",
211 "'proxy list' : list all proxy setups.\n"
212 "'proxy add' : add a new proxy setup.\n"
213 "'proxy remove <index>' : remove proxy setup with number index.\n"
214 "'proxy use <index>' : use proxy with number index as default proxy.\n"
215 "'proxy unuse' : don't use a default proxy.\n"
216 "'proxy show <index>' : show configuration and status of the proxy numbered by index.\n"
217 "'proxy show default' : show configuration and status of the default proxy.\n"
219 { "soundcard", lpc_cmd_soundcard, "Manage soundcards",
220 "'soundcard list' : list all sound devices.\n"
221 "'soundcard show' : show current sound devices configuration.\n"
222 "'soundcard use <index>' : select a sound device.\n"
223 "'soundcard use files' : use .wav files instead of soundcard\n"
225 { "webcam", lpc_cmd_webcam, "Manage webcams",
226 "'webcam list' : list all known devices.\n"
227 "'webcam use <index>' : select a video device.\n"
229 { "ipv6", lpc_cmd_ipv6, "Use IPV6",
230 "'ipv6 status' : show ipv6 usage status.\n"
231 "'ipv6 enable' : enable the use of the ipv6 network.\n"
232 "'ipv6 disable' : do not use ipv6 network."
234 { "nat", lpc_cmd_nat, "Set nat address",
235 "'nat' : show nat settings.\n"
236 "'nat <addr>' : set nat address.\n"
238 { "stun", lpc_cmd_stun, "Set stun server address",
239 "'stun' : show stun settings.\n"
240 "'stun <addr>' : set stun server address.\n"
242 { "firewall", lpc_cmd_firewall, "Set firewall policy",
243 "'firewall' : show current firewall policy.\n"
244 "'firewall none' : use direct connection.\n"
245 "'firewall nat' : use nat address given with the 'nat' command.\n"
246 "'firewall stun' : use stun server given with the 'stun' command.\n"
247 "'firewall ice' : use ice.\n"
248 "'firewall upnp' : use uPnP IGD.\n"
250 { "call-logs", lpc_cmd_call_logs, "Calls history", NULL },
251 { "friend", lpc_cmd_friend, "Manage friends",
252 "'friend list [<pattern>]' : list friends.\n"
253 "'friend call <index>' : call a friend.\n"
254 "'friend add <name> <addr>' : add friend, <name> must be quoted to include\n"
255 " spaces, <addr> has \"sip:\" added if it isn't\n"
256 " there. Don't use '<' '>' around <addr>.\n"
257 "'friend delete <index>' : remove friend, 'all' removes all\n"
259 { "play", lpc_cmd_play, "play a wav file",
260 "This command has two roles:\n"
261 "Plays a file instead of capturing from soundcard - only available in file mode (see 'help soundcard')\n"
262 "Specifies a wav file to be played to play music to far end when putting it on hold (pause)\n"
263 "'play <wav file>' : play a wav file."
265 { "record", lpc_cmd_record, "record to a wav file",
266 "This feature is available only in file mode (see 'help soundcard')\n"
267 "'record <wav file>' : record into wav file."
269 { "quit", lpc_cmd_quit, "Exit linphonec", NULL },
270 { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
274 static LPC_COMMAND advanced_commands[] = {
275 { "codec", lpc_cmd_acodec, "Audio codec configuration",
276 "'codec list' : list audio codecs\n"
277 "'codec enable <index>' : enable available audio codec\n"
278 "'codec disable <index>' : disable audio codec" },
279 { "vcodec", lpc_cmd_vcodec, "Video codec configuration",
280 "'vcodec list' : list video codecs\n"
281 "'vcodec enable <index>' : enable available video codec\n"
282 "'vcodec disable <index>' : disable video codec" },
283 { "ec", lpc_cmd_echocancellation, "Echo cancellation",
284 "'ec on [<delay>] [<tail>] [<framesize>]' : turn EC on with given delay, tail length and framesize\n"
285 "'ec off' : turn echo cancellation (EC) off\n"
286 "'ec show' : show EC status" },
287 { "el", lpc_cmd_echolimiter, "Echo limiter",
288 "'el on turns on echo limiter (automatic half duplex, for cases where echo canceller cannot work)\n"
289 "'el off' : turn echo limiter off\n"
290 "'el show' : show echo limiter status" },
291 { "nortp-on-audio-mute", lpc_cmd_rtp_no_xmit_on_audio_mute,
292 "Set the rtp_no_xmit_on_audio_mute configuration parameter",
293 " If set to 1 then rtp transmission will be muted when\n"
294 " audio is muted , otherwise rtp is always sent."},
296 { "vwindow", lpc_cmd_video_window, "Control video display window",
297 "'vwindow show': shows video window\n"
298 "'vwindow hide': hides video window\n"
299 "'vwindow pos <x> <y>': Moves video window to x,y pixel coordinates\n"
300 "'vwindow size <width> <height>': Resizes video window\n"
301 "'vwindow id <window id>': embeds video display into supplied window id."
303 { "pwindow", lpc_cmd_preview_window, "Control local camera video display (preview window)",
304 "'pwindow show': shows the local camera video display\n"
305 "'pwindow hide': hides the local camera video display\n"
306 "'pwindow pos <x> <y>': Moves preview window to x,y pixel coordinates\n"
307 "'pwindow size <width> <height>': Resizes preview window\n"
308 "'pwindow id <window id>': embeds preview display into supplied window id.\n"
309 "'pwindow integrated': integrate preview display within the video window of current call.\n"
310 "'pwindow standalone': use standalone window for preview display."
312 { "snapshot", lpc_cmd_snapshot, "Take a snapshot of currently received video stream",
313 "'snapshot <file path>': take a snapshot and records it in jpeg format into the supplied path\n"
315 { "vfureq", lpc_cmd_vfureq, "Request the other side to send VFU for the current call"},
317 { "states", lpc_cmd_states, "Show internal states of liblinphone, registrations and calls, according to linphonecore.h definitions",
318 "'states global': shows global state of liblinphone \n"
319 "'states calls': shows state of calls\n"
320 "'states proxies': shows state of proxy configurations"
322 { "register", lpc_cmd_register, "Register in one line to a proxy" , "register <sip identity> <sip proxy> <password>"},
323 { "unregister", lpc_cmd_unregister, "Unregister from default proxy", NULL },
324 { "status", lpc_cmd_status, "Print various status information",
325 "'status register' \t: print status concerning registration\n"
326 "'status autoanswer'\t: tell whether autoanswer mode is enabled\n"
327 "'status hook' \t: print hook status\n" },
328 { "ports", lpc_cmd_ports, "Network ports configuration",
329 "'ports' \t: prints current used ports.\n"
330 "'ports sip <port number>'\t: Sets the sip port.\n" },
331 { "param", lpc_cmd_param, "parameter set or read as normally given in .linphonerc",
332 "'param <section> <parameter> [<value>]' \t: reads [sets] given parameter.\n"
333 "NOTES: - changes may become effective after (re)establishing a sip connection.\n"
334 " - upon exit, .linphonerc will reflect the updated state.\n" },
335 { "speak", lpc_cmd_speak, "Speak a sentence using espeak TTS engine",
336 "This feature is available only in file mode. (see 'help soundcard')\n"
337 "'speak <voice name> <sentence>' : speak a text using the specified espeak voice.\n"
338 "Example for english voice: 'speak default Hello my friend !'"
340 { "staticpic", lpc_cmd_staticpic, "Manage static pictures when nowebcam",
341 "'staticpic set' : Set path to picture that should be used.\n"
342 "'staticpic fps' : Get/set frames per seconds for picture emission.\n"
344 { "identify", lpc_cmd_identify, "Returns the user-agent string of far end",
345 "'identify' \t: returns remote user-agent string for current call.\n"
346 "'identify <id>' \t: returns remote user-agent string for call with supplied id.\n"
348 { "ringback", lpc_cmd_ringback, "Specifies a ringback tone to be played to remote end during incoming calls",
349 "'ringback <path of mono .wav file>'\t: Specifies a ringback tone to be played to remote end during incoming calls\n"
350 "'ringback disable'\t: Disable playing of ringback tone to callers\n"
352 { "redirect", lpc_cmd_redirect, "Redirect an incoming call",
353 "'redirect <redirect-uri>'\t: Redirect all pending incoming calls to the <redirect-uri>\n"
355 { "zrtp-set-verified", lpc_cmd_zrtp_verified,"Set ZRTP SAS verified.",
356 "'Set ZRTP SAS verified'\n"
358 { "zrtp-set-unverified", lpc_cmd_zrtp_unverified,"Set ZRTP SAS not verified.",
359 "'Set ZRTP SAS not verified'\n"
361 { NULL,NULL,NULL,NULL}
366 /***************************************************************************
370 ***************************************************************************/
373 * Main command dispatcher.
374 * WARNING: modifies second argument!
376 * Always return 1 currently.
379 linphonec_parse_command_line(LinphoneCore *lc, char *cl)
385 /* Isolate first word and args */
386 while(*ptr && !isspace(*ptr)) ++ptr;
390 /* set args to first nonblank */
392 while(*args && isspace(*args)) ++args;
396 if ( isdigit(*cl) || *cl == '#' || *cl == '*' )
398 while ( isdigit(*cl) || *cl == '#' || *cl == '*' )
400 linphone_core_send_dtmf(lc, *cl);
401 linphone_core_play_dtmf (lc,*cl,100);
402 ms_sleep(1); // be nice
406 // discard spurious trailing chars
410 /* Handle other kind of commands */
411 cmd=lpc_find_command(cl);
414 linphonec_out("'%s': Cannot understand this.\n", cl);
418 if ( ! cmd->func(lc, args) )
420 linphonec_out("Syntax error.\n");
421 linphonec_display_command_help(cmd);
428 * Generator function for command completion.
429 * STATE let us know whether to start from scratch;
430 * without any state (STATE==0), then we start at the
434 linphonec_command_generator(const char *text, int state)
436 static int index, len, adv;
446 * Return the next name which partially matches
447 * from the commands list
450 while ((name=commands[index].name))
452 ++index; /* so next call get next command */
454 if (strncmp(name, text, len) == 0)
456 return ortp_strdup(name);
463 while ((name=advanced_commands[index].name))
465 ++index; /* so next call get next command */
467 if (strncmp(name, text, len) == 0)
469 return ortp_strdup(name);
477 /***************************************************************************
481 ***************************************************************************/
484 lpc_cmd_help(LinphoneCore *lc, char *arg)
491 linphonec_out("Commands are:\n");
492 linphonec_out("---------------------------\n");
494 while (commands[i].help)
496 linphonec_out("%10.10s\t%s\n", commands[i].name,
501 linphonec_out("---------------------------\n");
502 linphonec_out("Type 'help <command>' for more details or\n");
503 linphonec_out(" 'help advanced' to list additional commands.\n");
508 if (strcmp(arg,"advanced")==0){
509 linphonec_out("Advanced commands are:\n");
510 linphonec_out("---------------------------\n");
512 while (advanced_commands[i].help)
514 linphonec_out("%10.10s\t%s\n", advanced_commands[i].name,
515 advanced_commands[i].help);
519 linphonec_out("---------------------------\n");
520 linphonec_out("Type 'help <command>' for more details.\n");
525 cmd=lpc_find_command(arg);
528 linphonec_out("No such command.\n");
532 linphonec_display_command_help(cmd);
537 static char callee_name[256]={0};
538 static char caller_name[256]={0};
542 lpc_cmd_call(LinphoneCore *lc, char *args)
544 if ( ! args || ! *args )
550 LinphoneCallParams *cp=linphone_core_create_default_call_parameters (lc);
552 if ( linphone_core_in_call(lc) )
554 linphonec_out("Terminate or hold on the current call first.\n");
557 opt1=strstr(args,"--audio-only");
558 opt2=strstr(args,"--early-media");
561 linphone_call_params_enable_video (cp,FALSE);
565 linphone_call_params_enable_early_media_sending(cp,TRUE);
567 if ( NULL == (call=linphone_core_invite_with_params(lc, args,cp)) )
569 linphonec_out("Error from linphone_core_invite.\n");
573 snprintf(callee_name,sizeof(callee_name),"%s",args);
575 linphone_call_params_destroy(cp);
581 lpc_cmd_calls(LinphoneCore *lc, char *args){
582 const MSList *calls = linphone_core_get_calls(lc);
585 lpc_display_call_states(lc);
588 linphonec_out("No active call.\n");
595 lpc_cmd_chat(LinphoneCore *lc, char *args)
603 /* Isolate first and second arg */
604 while(*ptr && !isspace(*ptr)) ++ptr;
609 while(*arg2 && isspace(*arg2)) ++arg2;
613 /* missing one parameter */
616 LinphoneChatRoom *cr = linphone_core_create_chat_room(lc,arg1);
617 linphone_chat_room_send_message(cr,arg2);
618 linphone_chat_room_destroy(cr);
623 const char *linphonec_get_callee(){
627 const char *linphonec_get_caller(){
631 void linphonec_set_caller(const char *caller){
632 snprintf(caller_name,sizeof(caller_name)-1,"%s",caller);
636 lpc_cmd_transfer(LinphoneCore *lc, char *args)
641 const char *refer_to=NULL;
645 int n=sscanf(args,"%255s %265s %li",arg1,arg2,&id2);
646 if (n==1 || isalpha(*arg1)){
647 call=linphone_core_get_current_call(lc);
648 if (call==NULL && ms_list_size(linphone_core_get_calls(lc))==1){
649 call=(LinphoneCall*)linphone_core_get_calls(lc)->data;
653 linphonec_out("No active call, please specify a call id among the ones listed by 'calls' command.\n");
656 linphone_core_transfer_call(lc, call, refer_to);
659 refer_to=args+strlen(arg1)+1;
660 call=linphonec_get_call(id);
661 if (call==NULL) return 0;
662 linphone_core_transfer_call(lc, call, refer_to);
665 call=linphonec_get_call(id);
666 call2=linphonec_get_call(id2);
667 if (call==NULL || call2==NULL) return 0;
668 if (strcmp(arg2,"--to-call")!=0){
671 linphonec_out("Performing attended transfer of call %i to call %i",id,id2);
672 linphone_core_transfer_call_to_another (lc,call,call2);
675 linphonec_out("Transfer command requires at least one argument\n");
682 lpc_cmd_terminate(LinphoneCore *lc, char *args)
684 if (linphone_core_get_calls(lc)==NULL){
685 linphonec_out("No active calls\n");
690 if ( -1 == linphone_core_terminate_call(lc, NULL) ){
691 linphonec_out("Could not stop the active call.\n");
696 if(strcmp(args,"all")==0){
697 linphonec_out("We are going to stop all the calls.\n");
698 linphone_core_terminate_all_calls(lc);
701 /*the argument is a linphonec call id */
703 LinphoneCall *call=linphonec_get_call(id);
705 if (linphone_core_terminate_call(lc,call)==-1){
706 linphonec_out("Could not stop the call with id %li\n",id);
716 lpc_cmd_redirect(LinphoneCore *lc, char *args){
720 if ((elem=linphone_core_get_calls(lc))==NULL){
721 linphonec_out("No active calls.\n");
725 LinphoneCall *call=(LinphoneCall*)elem->data;
726 if (linphone_call_get_state(call)==LinphoneCallIncomingReceived){
727 linphone_core_redirect_call(lc,call,args);
729 /*as the redirection closes the call, we need to re-check the call list that is invalidated.*/
730 elem=linphone_core_get_calls(lc);
731 }else elem=elem->next;
734 linphonec_out("There is no pending incoming call to redirect.");
740 lpc_cmd_answer(LinphoneCore *lc, char *args){
743 int nb=ms_list_size(linphone_core_get_calls(lc));
745 //if just one call is present answer the only one in passing NULL to the linphone_core_accept_call ...
746 if ( -1 == linphone_core_accept_call(lc, NULL) )
748 linphonec_out("Fail to accept incoming call\n");
751 linphonec_out("There are no calls to answer.\n");
753 linphonec_out("Multiple calls in progress, please specify call id.\n");
759 if (sscanf(args,"%li",&id)==1){
760 LinphoneCall *call=linphonec_get_call (id);
761 if (linphone_core_accept_call (lc,call)==-1){
762 linphonec_out("Fail to accept call %i\n",id);
771 lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
775 if ( linphonec_get_autoanswer() ) {
776 linphonec_out("Auto answer is enabled. Use 'autoanswer disable' to disable.\n");
778 linphonec_out("Auto answer is disabled. Use 'autoanswer enable' to enable.\n");
783 if (strstr(args,"enable")){
784 linphonec_set_autoanswer(TRUE);
785 linphonec_out("Auto answer enabled.\n");
786 }else if (strstr(args,"disable")){
787 linphonec_set_autoanswer(FALSE);
788 linphonec_out("Auto answer disabled.\n");
794 lpc_cmd_quit(LinphoneCore *lc, char *args)
796 linphonec_main_loop_exit();
801 lpc_cmd_nat(LinphoneCore *lc, char *args)
806 if ( args ) args=lpc_strip_blanks(args);
810 linphone_core_set_nat_address(lc, args);
811 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS); */
814 nat = linphone_core_get_nat_address(lc);
815 use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress;
816 linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
822 lpc_cmd_stun(LinphoneCore *lc, char *args)
827 if ( args ) args=lpc_strip_blanks(args);
831 linphone_core_set_stun_server(lc, args);
832 /* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN); */
835 stun = linphone_core_get_stun_server(lc);
836 use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseStun;
837 linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
843 lpc_cmd_firewall(LinphoneCore *lc, char *args)
845 const char* setting=NULL;
847 if ( args ) args=lpc_strip_blanks(args);
851 if (strcmp(args,"none")==0)
853 linphone_core_set_firewall_policy(lc,LinphonePolicyNoFirewall);
855 else if (strcmp(args,"upnp")==0)
857 linphone_core_set_firewall_policy(lc,LinphonePolicyUseUpnp);
859 else if (strcmp(args,"ice")==0)
861 setting = linphone_core_get_stun_server(lc);
864 linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
867 linphone_core_set_firewall_policy(lc,LinphonePolicyUseIce);
869 else if (strcmp(args,"stun")==0)
871 setting = linphone_core_get_stun_server(lc);
874 linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
877 linphone_core_set_firewall_policy(lc,LinphonePolicyUseStun);
879 else if (strcmp(args,"nat")==0)
881 setting = linphone_core_get_nat_address(lc);
884 linphonec_out("No nat address is defined, use 'nat <address>' first");
887 linphone_core_set_firewall_policy(lc,LinphonePolicyUseNatAddress);
891 switch(linphone_core_get_firewall_policy(lc))
893 case LinphonePolicyNoFirewall:
894 linphonec_out("No firewall\n");
896 case LinphonePolicyUseStun:
897 linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
899 case LinphonePolicyUseNatAddress:
900 linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
902 case LinphonePolicyUseIce:
903 linphonec_out("Using ice with stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
905 case LinphonePolicyUseUpnp:
906 linphonec_out("Using uPnP IGD protocol\n");
913 /* Helper function for processing freind names */
915 lpc_friend_name(char **args, char **name)
917 /* Use space as a terminator unless quoted */
918 if (('"' == **args) || ('\'' == **args)){
923 while ((delim != *end) && ('\0' != *end)) end++;
925 fprintf(stderr, "Mismatched quotes\n");
932 *name = strsep(args, " ");
934 if (NULL == *args) { /* Means there was no separator */
935 fprintf(stderr, "Either name or address is missing\n");
938 if (NULL == *name) return 0;
945 lpc_cmd_friend(LinphoneCore *lc, char *args)
949 if ( args ) args=lpc_strip_blanks(args);
951 if ( ! args || ! *args ) return 0;
953 if ( !strncmp(args, "list", 4) )
955 return linphonec_friend_list(lc, args+4);
958 else if ( !strncmp(args, "call", 4) )
961 if ( ! *args ) return 0;
962 friend_num = strtol(args, NULL, 10);
964 if ( errno == ERANGE ) {
965 linphonec_out("Invalid friend number\n");
968 #endif /*_WIN32_WCE*/
969 linphonec_friend_call(lc, friend_num);
972 else if ( !strncmp(args, "delete", 6) )
975 if ( ! *args ) return 0;
976 while (*args == ' ') args++;
977 if ( ! *args ) return 0;
978 if (!strncmp(args, "all", 3))
984 friend_num = strtol(args, NULL, 10);
986 if ( errno == ERANGE ) {
987 linphonec_out("Invalid friend number\n");
990 #endif /*_WIN32_WCE*/
992 linphonec_friend_delete(lc, friend_num);
995 else if ( !strncmp(args, "add", 3) )
1000 char *addr_p = addr;
1004 if ( ! *args ) return 0;
1005 while (*args == ' ') args++;
1006 if ( ! *args ) return 0;
1008 if (!lpc_friend_name(&args, &name)) return 0;
1010 while (*args == ' ') args++;
1011 if ( ! *args ) return 0;
1012 if (isdigit(*args)) {
1013 strcpy (addr, "sip:");
1014 addr_p = addr + strlen("sip:");
1016 addr_orig = strsep(&args, " ");
1017 if (1 >= strlen(addr_orig)) {
1018 fprintf(stderr, "A single-digit address is not valid\n");
1021 strcpy(addr_p, addr_orig);
1022 linphonec_friend_add(lc, name, addr);
1024 LinphoneFriend *new_friend;
1025 new_friend = linphone_friend_new_with_addr(args);
1026 linphone_core_add_friend(lc, new_friend);
1033 static int lpc_cmd_play(LinphoneCore *lc, char *args){
1034 if ( args ) args=lpc_strip_blanks(args);
1035 if ( ! args || ! *args ) return 0;
1036 linphone_core_set_play_file(lc,args);
1040 static int lpc_cmd_record(LinphoneCore *lc, char *args){
1041 if ( args ) args=lpc_strip_blanks(args);
1042 if ( ! args || ! *args ) return 0;
1043 linphone_core_set_record_file(lc,args);
1051 lpc_cmd_proxy(LinphoneCore *lc, char *args)
1058 if ( ! arg1 ) return 0;
1060 /* Isolate first and second arg */
1061 while(*ptr && !isspace(*ptr)) ++ptr;
1066 while(*arg2 && isspace(*arg2)) ++arg2;
1069 if (strcmp(arg1,"add")==0)
1071 #ifdef HAVE_READLINE
1072 rl_inhibit_completion=1;
1074 linphonec_proxy_add(lc);
1075 #ifdef HAVE_READLINE
1076 rl_inhibit_completion=0;
1079 else if (strcmp(arg1,"list")==0)
1081 linphonec_proxy_list(lc);
1083 else if (strcmp(arg1,"remove")==0)
1085 linphonec_proxy_remove(lc,atoi(arg2));
1087 else if (strcmp(arg1,"use")==0)
1089 if ( arg2 && *arg2 )
1091 proxynum=atoi(arg2);
1092 if ( linphonec_proxy_use(lc, proxynum) )
1093 linphonec_out("Default proxy set to %d.\n", proxynum);
1097 proxynum=linphone_core_get_default_proxy(lc, NULL);
1098 if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
1099 else linphonec_out("Current default proxy is %d.\n", proxynum);
1101 }else if (strcmp(arg1, "unuse")==0){
1102 linphone_core_set_default_proxy(lc, NULL);
1103 linphonec_out("Use no proxy.\n");
1106 else if (strcmp(arg1, "show")==0)
1110 if (strstr(arg2,"default"))
1112 proxynum=linphone_core_get_default_proxy(lc, NULL);
1113 if ( proxynum < 0 ) {
1114 linphonec_out("No default proxy defined\n");
1117 linphonec_proxy_show(lc,proxynum);
1121 linphonec_proxy_show(lc, atoi(arg2));
1124 else return 0; /* syntax error */
1129 return 0; /* syntax error */
1136 lpc_cmd_call_logs(LinphoneCore *lc, char *args)
1138 const MSList *elem=linphone_core_get_call_logs(lc);
1139 for (;elem!=NULL;elem=ms_list_next(elem))
1141 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
1142 char *str=linphone_call_log_to_str(cl);
1143 linphonec_out("%s\n",str);
1150 lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
1154 return 0; /* syntax error */
1157 if (strcmp(arg1,"status")==0)
1159 linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
1161 else if (strcmp(arg1,"enable")==0)
1163 linphone_core_enable_ipv6(lc,TRUE);
1164 linphonec_out("ipv6 use enabled.\n");
1166 else if (strcmp(arg1,"disable")==0)
1168 linphone_core_enable_ipv6(lc,FALSE);
1169 linphonec_out("ipv6 use disabled.\n");
1173 return 0; /* syntax error */
1178 static int devname_to_index(LinphoneCore *lc, const char *devname){
1181 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1182 if (strcmp(devname,*p)==0) return i;
1187 static const char *index_to_devname(LinphoneCore *lc, int index){
1190 for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
1191 if (i==index) return *p;
1196 static int lpc_cmd_soundcard(LinphoneCore *lc, char *args)
1204 if (!args) return 0; /* syntax error */
1206 /* Isolate first and second arg */
1207 while(*ptr && !isspace(*ptr)) ++ptr;
1212 while(*arg2 && isspace(*arg2)) ++arg2;
1215 if (strcmp(arg1, "list")==0)
1217 dev=linphone_core_get_sound_devices(lc);
1218 for(i=0; dev[i]!=NULL; ++i){
1219 linphonec_out("%i: %s\n",i,dev[i]);
1224 if (strcmp(arg1, "show")==0)
1226 linphonec_out("Ringer device: %s\n",
1227 linphone_core_get_ringer_device(lc));
1228 linphonec_out("Playback device: %s\n",
1229 linphone_core_get_playback_device(lc));
1230 linphonec_out("Capture device: %s\n",
1231 linphone_core_get_capture_device(lc));
1235 if (strcmp(arg1, "use")==0 && arg2)
1237 if (strcmp(arg2, "files")==0)
1239 linphonec_out("Using wav files instead of soundcard.\n");
1240 linphone_core_use_files(lc,TRUE);
1244 dev=linphone_core_get_sound_devices(lc);
1245 index=atoi(arg2); /* FIXME: handle not-a-number */
1246 for(i=0;dev[i]!=NULL;i++)
1248 if (i!=index) continue;
1250 linphone_core_set_ringer_device(lc,dev[i]);
1251 linphone_core_set_playback_device(lc,dev[i]);
1252 linphone_core_set_capture_device(lc,dev[i]);
1253 linphonec_out("Using sound device %s\n",dev[i]);
1256 linphonec_out("No such sound device\n");
1259 if (strcmp(arg1, "capture")==0)
1261 const char *devname=linphone_core_get_capture_device(lc);
1263 linphonec_out("Using capture device #%i (%s)\n",
1264 devname_to_index(lc,devname),devname);
1266 index=atoi(arg2); /* FIXME: handle not-a-number */
1267 devname=index_to_devname(lc,index);
1269 linphone_core_set_capture_device(lc,devname);
1270 linphonec_out("Using capture sound device %s\n",devname);
1273 linphonec_out("No such sound device\n");
1277 if (strcmp(arg1, "playback")==0)
1279 const char *devname=linphone_core_get_playback_device(lc);
1281 linphonec_out("Using playback device #%i (%s)\n",
1282 devname_to_index(lc,devname),devname);
1284 index=atoi(arg2); /* FIXME: handle not-a-number */
1285 devname=index_to_devname(lc,index);
1287 linphone_core_set_playback_device(lc,devname);
1288 linphonec_out("Using playback sound device %s\n",devname);
1291 linphonec_out("No such sound device\n");
1295 if (strcmp(arg1, "ring")==0)
1297 const char *devname=linphone_core_get_ringer_device(lc);
1299 linphonec_out("Using ring device #%i (%s)\n",
1300 devname_to_index(lc,devname),devname);
1302 index=atoi(arg2); /* FIXME: handle not-a-number */
1303 devname=index_to_devname(lc,index);
1305 linphone_core_set_ringer_device(lc,devname);
1306 linphonec_out("Using ring sound device %s\n",devname);
1309 linphonec_out("No such sound device\n");
1313 return 0; /* syntax error */
1316 static int lpc_cmd_webcam(LinphoneCore *lc, char *args)
1324 if (!args) return 0; /* syntax error */
1326 /* Isolate first and second arg */
1327 while(*ptr && !isspace(*ptr)) ++ptr;
1332 while(*arg2 && isspace(*arg2)) ++arg2;
1335 if (strcmp(arg1, "list")==0)
1337 dev=linphone_core_get_video_devices(lc);
1338 for(i=0; dev[i]!=NULL; ++i){
1339 linphonec_out("%i: %s\n",i,dev[i]);
1344 if (strcmp(arg1, "use")==0 && arg2)
1346 dev=linphone_core_get_video_devices(lc);
1347 index=atoi(arg2); /* FIXME: handle not-a-number */
1348 for(i=0;dev[i]!=NULL;i++)
1350 if (i!=index) continue;
1352 linphone_core_set_video_device(lc, dev[i]);
1353 linphonec_out("Using video device %s\n",dev[i]);
1356 linphonec_out("No such video device\n");
1359 return 0; /* syntax error */
1363 lpc_cmd_staticpic(LinphoneCore *lc, char *args)
1369 if (!args) return 0; /* Syntax error */
1371 /* Isolate first and second arg */
1372 while(*ptr && !isspace(*ptr)) ++ptr;
1377 while(*arg2 && isspace(*arg2)) ++arg2;
1380 if (strcmp(arg1, "set")==0 && arg2) {
1381 linphone_core_set_static_picture(lc, arg2);
1385 if (strcmp(arg1, "fps")==0) {
1387 float fps = atof(arg2); /* FIXME: Handle not-a-float */
1388 linphone_core_set_static_picture_fps(lc, fps);
1392 fps = linphone_core_get_static_picture_fps(lc);
1393 linphonec_out("Current FPS %f\n", fps);
1398 return 0; /* Syntax error */
1401 static int lpc_cmd_pause(LinphoneCore *lc, char *args){
1403 if(linphone_core_in_call(lc))
1405 linphone_core_pause_call(lc,linphone_core_get_current_call(lc));
1408 linphonec_out("you can only pause when a call is in process\n");
1412 static int lpc_cmd_resume(LinphoneCore *lc, char *args){
1414 if(linphone_core_in_call(lc))
1416 linphonec_out("There is already a call in process pause or stop it first");
1422 int n = sscanf(args, "%li", &id);
1424 LinphoneCall *call=linphonec_get_call (id);
1426 if(linphone_core_resume_call(lc,call)==-1){
1427 linphonec_out("There was a problem to resume the call check the remote address you gave %s\n",args);
1435 const MSList *calls = linphone_core_get_calls(lc);
1436 int nbcalls=ms_list_size(calls);
1439 if(linphone_core_resume_call(lc,calls->data) < 0)
1441 linphonec_out("There was a problem to resume the unique call.\n");
1444 }else if (nbcalls==0){
1445 linphonec_out("There is no calls at this time.\n");
1448 linphonec_out("There are %i calls at this time, please specify call id as given with 'calls' command.\n");
1455 static int lpc_cmd_conference(LinphoneCore *lc, char *args){
1457 char subcommand[32]={0};
1459 if (args==NULL) return 0;
1460 n=sscanf(args, "%31s %li", subcommand,&id);
1462 LinphoneCall *call=linphonec_get_call(id);
1463 if (call==NULL) return 1;
1464 if (strcmp(subcommand,"add")==0){
1465 linphone_core_add_to_conference(lc,call);
1467 }else if (strcmp(subcommand,"rm")==0){
1468 linphone_core_remove_from_conference(lc,call);
1470 }else if (strcmp(subcommand,"enter")==0){
1471 linphone_core_enter_conference(lc);
1473 }else if (strcmp(subcommand,"leave")==0){
1474 linphone_core_leave_conference(lc);
1481 /***************************************************************************
1483 * Commands helper functions
1485 ***************************************************************************/
1489 linphonec_proxy_add(LinphoneCore *lc)
1491 bool_t enable_register=FALSE;
1492 LinphoneProxyConfig *cfg;
1494 linphonec_out("Adding new proxy setup. Hit ^D to abort.\n");
1501 char *input=linphonec_readline("Enter proxy sip address: ");
1505 linphonec_out("Aborted.\n");
1510 clean=lpc_strip_blanks(input);
1516 cfg=linphone_proxy_config_new();
1517 if (linphone_proxy_config_set_server_addr(cfg,clean)<0)
1519 linphonec_out("Invalid sip address (sip:sip.domain.tld).\n");
1521 linphone_proxy_config_destroy(cfg);
1529 * SIP Proxy identity
1533 char *input=linphonec_readline("Your identity for this proxy: ");
1537 linphonec_out("Aborted.\n");
1538 linphone_proxy_config_destroy(cfg);
1543 clean=lpc_strip_blanks(input);
1549 linphone_proxy_config_set_identity(cfg, clean);
1550 if ( ! linphone_proxy_config_get_identity (cfg))
1552 linphonec_out("Invalid identity (sip:name@sip.domain.tld).\n");
1561 * SIP Proxy enable register
1565 char *input=linphonec_readline("Do you want to register on this proxy (yes/no): ");
1569 linphonec_out("Aborted.\n");
1570 linphone_proxy_config_destroy(cfg);
1575 clean=lpc_strip_blanks(input);
1581 if ( ! strcmp(clean, "yes") ) enable_register=TRUE;
1582 else if ( ! strcmp(clean, "no") ) enable_register=FALSE;
1584 linphonec_out("Please answer with 'yes' or 'no'\n");
1588 linphone_proxy_config_enableregister(cfg, enable_register);
1594 * SIP Proxy registration expiration
1596 if ( enable_register==TRUE )
1601 char *input=linphonec_readline("Specify register expiration time"
1602 " in seconds (default is 600): ");
1605 linphonec_out("Aborted.\n");
1606 linphone_proxy_config_destroy(cfg);
1610 expires=strtol(input, (char **)NULL, 10);
1611 if ( expires == LONG_MIN || expires == LONG_MAX )
1613 linphonec_out("Invalid value: %s\n", strerror(errno));
1618 linphone_proxy_config_expires(cfg, expires);
1619 linphonec_out("Expiration: %d seconds\n", linphone_proxy_config_get_expires (cfg));
1631 char *input=linphonec_readline("Specify route if needed: ");
1635 linphonec_out("Aborted.\n");
1636 linphone_proxy_config_destroy(cfg);
1641 clean=lpc_strip_blanks(input);
1644 linphonec_out("No route specified.\n");
1648 linphone_proxy_config_set_route(cfg, clean);
1649 if ( ! linphone_proxy_config_get_route(cfg) )
1651 linphonec_out("Invalid route.\n");
1661 * Final confirmation
1668 linphonec_out("--------------------------------------------\n");
1669 linphonec_proxy_display(cfg);
1670 linphonec_out("--------------------------------------------\n");
1671 input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: ");
1675 linphonec_out("Aborted.\n");
1676 linphone_proxy_config_destroy(cfg);
1681 clean=lpc_strip_blanks(input);
1687 if ( ! strcmp(clean, "yes") ) break;
1688 else if ( ! strcmp(clean, "no") )
1690 linphonec_out("Declined.\n");
1691 linphone_proxy_config_destroy(cfg);
1696 linphonec_out("Please answer with 'yes' or 'no'\n");
1702 linphone_core_add_proxy_config(lc,cfg);
1704 /* automatically set the last entered proxy as the default one */
1705 linphone_core_set_default_proxy(lc,cfg);
1707 linphonec_out("Proxy added.\n");
1711 linphonec_proxy_display(LinphoneProxyConfig *cfg)
1713 const char *route=linphone_proxy_config_get_route(cfg);
1714 const char *identity=linphone_proxy_config_get_identity(cfg);
1715 linphonec_out("sip address: %s\nroute: %s\nidentity: %s\nregister: %s\nexpires: %i\nregistered: %s\n",
1716 linphone_proxy_config_get_addr(cfg),
1717 (route!=NULL)? route:"",
1718 (identity!=NULL)?identity:"",
1719 linphone_proxy_config_register_enabled (cfg)?"yes":"no",
1720 linphone_proxy_config_get_expires (cfg),
1721 linphone_proxy_config_is_registered(cfg) ? "yes" : "no");
1724 static void linphonec_proxy_show(LinphoneCore *lc, int index)
1728 for(elem=linphone_core_get_proxy_config_list(lc),i=0;elem!=NULL;elem=elem->next,++i){
1730 LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)elem->data;
1731 linphonec_proxy_display(cfg);
1735 linphonec_out("No proxy with index %i\n", index);
1739 linphonec_proxy_list(LinphoneCore *lc)
1741 const MSList *proxies;
1743 int def=linphone_core_get_default_proxy(lc,NULL);
1745 proxies=linphone_core_get_proxy_config_list(lc);
1746 for(n=0;proxies!=NULL;proxies=ms_list_next(proxies),n++){
1748 linphonec_out("****** Proxy %i - this is the default one - *******\n",n);
1750 linphonec_out("****** Proxy %i *******\n",n);
1751 linphonec_proxy_display((LinphoneProxyConfig*)proxies->data);
1753 if ( ! n ) linphonec_out("No proxies defined\n");
1757 linphonec_proxy_remove(LinphoneCore *lc, int index)
1759 const MSList *proxies;
1760 LinphoneProxyConfig *cfg;
1761 proxies=linphone_core_get_proxy_config_list(lc);
1762 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1764 linphonec_out("No such proxy.\n");
1767 linphone_core_remove_proxy_config(lc,cfg);
1768 linphonec_out("Proxy %s removed.\n", linphone_proxy_config_get_addr(cfg));
1772 linphonec_proxy_use(LinphoneCore *lc, int index)
1774 const MSList *proxies;
1775 LinphoneProxyConfig *cfg;
1776 proxies=linphone_core_get_proxy_config_list(lc);
1777 cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
1779 linphonec_out("No such proxy (try 'proxy list').");
1782 linphone_core_set_default_proxy(lc,cfg);
1787 linphonec_friend_display(LinphoneFriend *fr)
1789 LinphoneAddress *uri=linphone_address_clone(linphone_friend_get_address(fr));
1792 linphonec_out("name: %s\n", linphone_address_get_display_name(uri));
1793 linphone_address_set_display_name(uri,NULL);
1794 str=linphone_address_as_string(uri);
1795 linphonec_out("address: %s\n", str);
1799 linphonec_friend_list(LinphoneCore *lc, char *pat)
1801 const MSList *friend;
1805 pat=lpc_strip_blanks(pat);
1806 if (!*pat) pat = NULL;
1809 friend = linphone_core_get_friend_list(lc);
1810 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1813 const char *name = linphone_address_get_display_name(
1814 linphone_friend_get_address((LinphoneFriend*)friend->data));
1815 if (name && ! strstr(name, pat) ) continue;
1817 linphonec_out("****** Friend %i *******\n",n);
1818 linphonec_friend_display((LinphoneFriend*)friend->data);
1825 linphonec_friend_call(LinphoneCore *lc, unsigned int num)
1827 const MSList *friend = linphone_core_get_friend_list(lc);
1831 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1836 addr = linphone_address_as_string(linphone_friend_get_address((LinphoneFriend*)friend->data));
1837 ret=lpc_cmd_call(lc, addr);
1842 linphonec_out("No such friend %u\n", num);
1848 linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr)
1850 LinphoneFriend *newFriend;
1854 snprintf(url, PATH_MAX, "%s <%s>", name, addr);
1855 newFriend = linphone_friend_new_with_addr(url);
1856 linphone_core_add_friend(lc, newFriend);
1862 linphonec_friend_delete(LinphoneCore *lc, int num)
1864 const MSList *friend = linphone_core_get_friend_list(lc);
1867 for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
1871 linphone_core_remove_friend(lc, friend->data);
1879 for (i = 0 ; i < n ; i++)
1880 linphonec_friend_delete(lc, 0);
1884 linphonec_out("No such friend %u\n", num);
1889 linphonec_display_command_help(LPC_COMMAND *cmd)
1891 if ( cmd->doc ) linphonec_out ("%s\n", cmd->doc);
1892 else linphonec_out("%s\n", cmd->help);
1896 static int lpc_cmd_register(LinphoneCore *lc, char *args){
1900 LinphoneProxyConfig *cfg;
1905 /* it means that you want to register the default proxy */
1906 LinphoneProxyConfig *cfg=NULL;
1907 linphone_core_get_default_proxy(lc,&cfg);
1910 if(!linphone_proxy_config_is_registered(cfg)) {
1911 linphone_proxy_config_enable_register(cfg,TRUE);
1912 linphone_proxy_config_done(cfg);
1914 linphonec_out("default proxy already registered\n");
1917 linphonec_out("we do not have a default proxy\n");
1922 passwd[0]=proxy[0]=identity[0]='\0';
1923 sscanf(args,"%511s %511s %511s",identity,proxy,passwd);
1924 if (proxy[0]=='\0' || identity[0]=='\0'){
1925 linphonec_out("Missing parameters, see help register\n");
1928 if (passwd[0]!='\0'){
1929 LinphoneAddress *from;
1930 LinphoneAuthInfo *info;
1931 if ((from=linphone_address_new(identity))!=NULL){
1933 snprintf(realm,sizeof(realm)-1,"\"%s\"",linphone_address_get_domain(from));
1934 info=linphone_auth_info_new(linphone_address_get_username(from),NULL,passwd,NULL,NULL);
1935 linphone_core_add_auth_info(lc,info);
1936 linphone_address_destroy(from);
1937 linphone_auth_info_destroy(info);
1940 elem=linphone_core_get_proxy_config_list(lc);
1942 cfg=(LinphoneProxyConfig*)elem->data;
1943 linphone_proxy_config_edit(cfg);
1945 else cfg=linphone_proxy_config_new();
1946 linphone_proxy_config_set_identity(cfg,identity);
1947 linphone_proxy_config_set_server_addr(cfg,proxy);
1948 linphone_proxy_config_enable_register(cfg,TRUE);
1949 if (elem) linphone_proxy_config_done(cfg);
1950 else linphone_core_add_proxy_config(lc,cfg);
1951 linphone_core_set_default_proxy(lc,cfg);
1955 static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
1956 LinphoneProxyConfig *cfg=NULL;
1957 linphone_core_get_default_proxy(lc,&cfg);
1958 if (cfg && linphone_proxy_config_is_registered(cfg)) {
1959 linphone_proxy_config_edit(cfg);
1960 linphone_proxy_config_enable_register(cfg,FALSE);
1961 linphone_proxy_config_done(cfg);
1963 linphonec_out("unregistered\n");
1968 static int lpc_cmd_duration(LinphoneCore *lc, char *args){
1969 LinphoneCallLog *cl;
1970 const MSList *elem=linphone_core_get_call_logs(lc);
1971 for(;elem!=NULL;elem=elem->next){
1972 if (elem->next==NULL){
1973 cl=(LinphoneCallLog*)elem->data;
1974 linphonec_out("%i seconds\n",linphone_call_log_get_duration(cl));
1980 static int lpc_cmd_status(LinphoneCore *lc, char *args)
1982 LinphoneProxyConfig *cfg;
1984 if ( ! args ) return 0;
1985 linphone_core_get_default_proxy(lc,&cfg);
1986 if (strstr(args,"register"))
1990 if (linphone_proxy_config_is_registered(cfg)){
1991 linphonec_out("registered, identity=%s duration=%i\n",
1992 linphone_proxy_config_get_identity(cfg),
1993 linphone_proxy_config_get_expires(cfg));
1994 }else if (linphone_proxy_config_register_enabled(cfg)){
1995 linphonec_out("registered=-1\n");
1996 }else linphonec_out("registered=0\n");
1998 else linphonec_out("registered=0\n");
2000 else if (strstr(args,"autoanswer"))
2002 if (cfg && linphone_proxy_config_is_registered(cfg))
2003 linphonec_out("autoanswer=%i\n",linphonec_get_autoanswer());
2004 else linphonec_out("unregistered\n");
2006 else if (strstr(args,"hook"))
2008 LinphoneCall *call=linphone_core_get_current_call (lc);
2009 LinphoneCallState call_state=LinphoneCallIdle;
2010 if (call) call_state=linphone_call_get_state(call);
2013 case LinphoneCallOutgoingInit:
2014 linphonec_out("hook=outgoing_init sip:%s\n",linphonec_get_callee());
2016 case LinphoneCallOutgoingProgress:
2017 linphonec_out("hook=dialing sip:%s\n",linphonec_get_callee());
2019 case LinphoneCallOutgoingRinging:
2020 linphonec_out("hook=ringing sip:%s\n",linphonec_get_callee());
2022 case LinphoneCallPaused:
2023 linphonec_out("hook=paused sip:%s\n",linphonec_get_callee());
2025 case LinphoneCallIdle:
2026 linphonec_out("hook=offhook\n");
2028 case LinphoneCallStreamsRunning:
2029 case LinphoneCallConnected:
2030 if (linphone_call_get_dir(call)==LinphoneCallOutgoing){
2031 linphonec_out("Call out, hook=%s duration=%i, muted=%s rtp-xmit-muted=%s\n", linphonec_get_callee(),
2032 linphone_core_get_current_call_duration(lc),
2033 linphone_core_is_mic_muted (lc) ? "yes" : "no",
2034 linphone_core_is_rtp_muted(lc) ? "yes" : "no");
2036 linphonec_out("hook=answered duration=%i %s\n" ,
2037 linphone_core_get_current_call_duration(lc), linphonec_get_caller());
2040 case LinphoneCallIncomingReceived:
2041 linphonec_out("Incoming call from %s\n",linphonec_get_caller());
2053 static int lpc_cmd_ports(LinphoneCore *lc, char *args)
2057 linphonec_out("sip port = %i\naudio rtp port = %i\nvideo rtp port = %i\n",
2058 linphone_core_get_sip_port(lc),
2059 linphone_core_get_audio_port(lc),
2060 linphone_core_get_video_port(lc));
2063 if (sscanf(args,"sip %i",&port)==1){
2064 linphonec_out("Setting sip port to %i\n",port);
2065 linphone_core_set_sip_port(lc,port);
2071 static int lpc_cmd_param(LinphoneCore *lc, char *args)
2073 char section[20], param[20], value[50];
2079 switch (sscanf(args,"%19s %19s %49s",section,param,value)) {
2080 // case 1 might show all current settings under a section
2082 string = lp_config_get_string(linphone_core_get_config(lc), section, param, "(undef)");
2083 linphonec_out("current value: %s\n", string);
2086 if (lp_config_get_string(linphone_core_get_config(lc), section, param, NULL) != NULL) {
2087 lp_config_set_string(linphone_core_get_config(lc), section, param, value);
2088 // no indication of existence
2089 linphonec_out("updated value: %s\n", value);
2091 linphonec_out("only update of existing variables are allowed\n");
2100 static int lpc_cmd_speak(LinphoneCore *lc, char *args){
2109 if (!args) return 0;
2110 memset(voice,0,sizeof(voice));
2111 sscanf(args,"%63s",voice);
2112 sentence=args+strlen(voice);
2113 wavfile=tempnam("/tmp/","linphonec-espeak-");
2114 snprintf(cl,sizeof(cl),"espeak -v %s -s 100 -w %s --stdin",voice,wavfile);
2117 ms_error("Could not open pipe to espeak !");
2120 fprintf(file,"%s",sentence);
2121 status=pclose(file);
2122 if (WEXITSTATUS(status)==0){
2123 linphone_core_set_play_file(lc,wavfile);
2125 linphonec_out("espeak command failed.");
2128 linphonec_out("Sorry, this command is not implemented in windows version.");
2133 static int lpc_cmd_acodec(LinphoneCore *lc, char *args){
2134 return lpc_cmd_codec(AUDIO, lc, args);
2137 static int lpc_cmd_vcodec(LinphoneCore *lc, char *args){
2138 return lpc_cmd_codec(VIDEO, lc, args);
2141 static int lpc_cmd_codec(int type, LinphoneCore *lc, char *args){
2146 if (!args) return 0;
2148 /* Isolate first and second arg */
2149 while(*ptr && !isspace(*ptr)) ++ptr;
2154 while(*arg2 && isspace(*arg2)) ++arg2;
2157 if (strcmp(arg1,"enable")==0)
2159 #ifdef HAVE_READLINE
2160 rl_inhibit_completion=1;
2162 if (!strcmp(arg2,"all")) linphonec_codec_enable(type,lc,-1);
2163 else linphonec_codec_enable(type,lc,atoi(arg2));
2164 #ifdef HAVE_READLINE
2165 rl_inhibit_completion=0;
2168 else if (strcmp(arg1,"list")==0)
2170 linphonec_codec_list(type,lc);
2172 else if (strcmp(arg1,"disable")==0)
2174 if (!strcmp(arg2,"all")) linphonec_codec_disable(type,lc,-1);
2175 else linphonec_codec_disable(type,lc,atoi(arg2));
2179 return 0; /* syntax error */
2185 static void linphonec_codec_list(int type, LinphoneCore *lc){
2188 const MSList *node=NULL;
2190 if (type == AUDIO) {
2191 node=linphone_core_get_audio_codecs(lc);
2192 } else if(type==VIDEO) {
2193 node=linphone_core_get_video_codecs(lc);
2196 for(;node!=NULL;node=ms_list_next(node)){
2197 pt=(PayloadType*)(node->data);
2198 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate,
2199 linphone_core_payload_type_enabled(lc,pt) ? "enabled" : "disabled");
2204 static void linphonec_codec_enable(int type, LinphoneCore *lc, int sel_index){
2207 const MSList *node=NULL;
2209 if (type == AUDIO) {
2210 node=linphone_core_get_audio_codecs(lc);
2211 } else if(type==VIDEO) {
2212 node=linphone_core_get_video_codecs(lc);
2215 for(;node!=NULL;node=ms_list_next(node)){
2216 if (index == sel_index || sel_index == -1) {
2217 pt=(PayloadType*)(node->data);
2218 linphone_core_enable_payload_type (lc,pt,TRUE);
2219 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "enabled");
2225 static void linphonec_codec_disable(int type, LinphoneCore *lc, int sel_index){
2228 const MSList *node=NULL;
2230 if (type == AUDIO) {
2231 node=linphone_core_get_audio_codecs(lc);
2232 } else if(type==VIDEO) {
2233 node=linphone_core_get_video_codecs(lc);
2236 for(;node!=NULL;node=ms_list_next(node)){
2237 if (index == sel_index || sel_index == -1) {
2238 pt=(PayloadType*)(node->data);
2239 linphone_core_enable_payload_type (lc,pt,FALSE);
2240 linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "disabled");
2246 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){
2250 LpConfig *config=linphone_core_get_config(lc);
2252 if (!args) return 0;
2254 /* Isolate first and second arg */
2255 while(*ptr && !isspace(*ptr)) ++ptr;
2260 while(*arg2 && isspace(*arg2)) ++arg2;
2263 if (strcmp(arg1,"on")==0){
2264 int delay, tail_len, frame_size;
2267 linphone_core_enable_echo_cancellation(lc,1);
2270 n = sscanf(arg2, "%d %d %d", &delay, &tail_len, &frame_size);
2273 lp_config_set_int(config,"sound","ec_delay",delay);
2276 lp_config_set_int(config,"sound","ec_delay",delay);
2277 lp_config_set_int(config,"sound","ec_tail_len",tail_len);
2280 lp_config_set_int(config,"sound","ec_delay",delay);
2281 lp_config_set_int(config,"sound","ec_tail_len",tail_len);
2282 lp_config_set_int(config,"sound","ec_framesize",frame_size);
2286 else if (strcmp(arg1,"off")==0){
2287 linphone_core_enable_echo_cancellation(lc,0);
2289 else if (strcmp(arg1,"show")==0){
2290 linphonec_out("echo cancellation is %s; delay %d, tail length %d, frame size %d\n",
2291 linphone_core_echo_cancellation_enabled(lc) ? "on" : "off",
2292 lp_config_get_int(config,"sound","ec_delay",0),
2293 lp_config_get_int(config,"sound","ec_tail_len",0),
2294 lp_config_get_int(config,"sound","ec_framesize",0));
2303 static int lpc_cmd_echolimiter(LinphoneCore *lc, char *args){
2305 if (strcmp(args,"on")==0){
2306 linphone_core_enable_echo_limiter (lc,TRUE);
2307 }else if (strcmp(args,"off")==0){
2308 linphone_core_enable_echo_limiter (lc,FALSE);
2311 linphonec_out("Echo limiter is now %s.\n",linphone_core_echo_limiter_enabled (lc) ? "on":"off");
2315 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args)
2317 linphone_core_mute_mic(lc, 1);
2321 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args){
2322 linphone_core_mute_mic(lc, 0);
2326 static int lpc_cmd_playback_gain(LinphoneCore *lc, char *args)
2329 linphone_core_set_playback_gain_db(lc, atof(args));
2335 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args)
2337 bool_t rtp_xmit_off=FALSE;
2341 if(strstr(args,"1"))rtp_xmit_off=TRUE;
2342 if(linphone_core_get_current_call (lc)==NULL)
2343 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_xmit_off);
2345 linphonec_out("nortp-on-audio-mute: call in progress - cannot change state\n");
2347 rtp_xmit_off=linphone_core_get_rtp_no_xmit_on_audio_mute(lc);
2348 if (rtp_xmit_off) status="off";
2350 linphonec_out("rtp transmit %s when audio muted\n",status);
2354 #ifdef VIDEO_ENABLED
2355 static int _lpc_cmd_video_window(LinphoneCore *lc, char *args, bool_t is_preview){
2356 char subcommand[64];
2359 VideoParams *params=is_preview ? &lpc_preview_params : &lpc_video_params;
2361 if (!args) return 0;
2362 err=sscanf(args,"%63s %i %i",subcommand,&a,&b);
2364 if (strcmp(subcommand,"pos")==0){
2365 if (err<3) return 0;
2368 params->refresh=TRUE;
2369 }else if (strcmp(subcommand,"size")==0){
2370 if (err<3) return 0;
2373 params->refresh=TRUE;
2374 }else if (strcmp(subcommand,"show")==0){
2376 params->refresh=TRUE;
2377 if (is_preview) linphone_core_enable_video_preview (lc,TRUE);
2378 }else if (strcmp(subcommand,"hide")==0){
2380 params->refresh=TRUE;
2381 if (is_preview) linphone_core_enable_video_preview (lc,FALSE);
2382 }else if (strcmp(subcommand,"id")==0){
2384 linphonec_out("vwindow id: 0x%x\n",is_preview ? linphone_core_get_native_preview_window_id (lc) :
2385 linphone_core_get_native_video_window_id (lc));
2387 } else if (err != 2) return 0;
2390 linphone_core_set_native_preview_window_id (lc,a);
2392 linphone_core_set_native_video_window_id(lc,a);
2393 }else if (is_preview==TRUE){
2394 if (strcmp(subcommand,"integrated")==0){
2395 linphone_core_use_preview_window (lc,FALSE);
2396 }else if (strcmp(subcommand,"standalone")==0){
2397 linphone_core_use_preview_window(lc,TRUE);
2404 static int lpc_cmd_video_window(LinphoneCore *lc, char *args){
2405 return _lpc_cmd_video_window(lc, args, FALSE);
2408 static int lpc_cmd_preview_window(LinphoneCore *lc, char *args){
2409 return _lpc_cmd_video_window(lc, args, TRUE);
2413 static void lpc_display_global_state(LinphoneCore *lc){
2414 linphonec_out("Global liblinphone state\n%s\n",
2415 linphone_global_state_to_string(linphone_core_get_global_state(lc)));
2418 static void lpc_display_call_states(LinphoneCore *lc){
2422 linphonec_out("Call states\n"
2423 "Id | Destination | State | Flags |\n"
2424 "------------------------------------------------------------------------\n");
2425 elem=linphone_core_get_calls(lc);
2427 linphonec_out("(empty)\n");
2429 for(;elem!=NULL;elem=elem->next){
2431 call=(LinphoneCall*)elem->data;
2432 bool_t in_conference=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
2433 tmp=linphone_call_get_remote_address_as_string (call);
2434 flag=in_conference ? "conferencing" : "";
2435 flag=linphone_call_has_transfer_pending(call) ? "transfer pending" : flag;
2436 linphonec_out("%-2i | %-35s | %-15s | %s\n",(int)(long)linphone_call_get_user_pointer(call),
2437 tmp,linphone_call_state_to_string(linphone_call_get_state(call))+strlen("LinphoneCall"),flag);
2443 static void lpc_display_proxy_states(LinphoneCore *lc){
2445 linphonec_out("Proxy registration states\n"
2446 " Identity | State\n"
2447 "------------------------------------------------------------\n");
2448 elem=linphone_core_get_proxy_config_list (lc);
2449 if (elem==NULL) linphonec_out("(empty)\n");
2451 for(;elem!=NULL;elem=elem->next){
2452 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2453 linphonec_out("%-40s | %s\n",linphone_proxy_config_get_identity (cfg),
2454 linphone_registration_state_to_string(linphone_proxy_config_get_state(cfg)));
2459 static int lpc_cmd_states(LinphoneCore *lc, char *args){
2461 lpc_display_global_state(lc);
2462 lpc_display_call_states(lc);
2463 lpc_display_proxy_states(lc);
2466 if (strcmp(args,"global")==0){
2467 lpc_display_global_state(lc);
2470 if (strcmp(args,"proxies")==0){
2471 lpc_display_proxy_states(lc);
2474 if (strcmp(args,"calls")==0){
2475 lpc_display_call_states(lc);
2481 #ifdef VIDEO_ENABLED
2482 static int lpc_cmd_camera(LinphoneCore *lc, char *args){
2483 LinphoneCall *call=linphone_core_get_current_call(lc);
2484 bool_t activated=FALSE;
2486 if (linphone_core_video_enabled (lc)==FALSE){
2487 linphonec_out("Video is disabled, re-run linphonec with -V option.");
2492 if (strcmp(args,"on")==0)
2494 else if (strcmp(args,"off")==0)
2502 linphonec_camera_enabled=activated;
2504 if (linphonec_camera_enabled){
2505 linphonec_out("Camera is enabled. Video stream will be setup immediately for outgoing and incoming calls.\n");
2507 linphonec_out("Camera is disabled. Calls will be established with audio-only, with the possibility to later add video using 'camera on'.\n");
2510 const LinphoneCallParams *cp=linphone_call_get_current_params (call);
2512 linphone_call_enable_camera(call,activated);
2513 if (linphone_call_get_state(call)==LinphoneCallStreamsRunning){
2514 if ((activated && !linphone_call_params_video_enabled (cp))){
2515 /*update the call to add the video stream*/
2516 LinphoneCallParams *ncp=linphone_call_params_copy(cp);
2517 linphone_call_params_enable_video(ncp,TRUE);
2518 linphone_core_update_call(lc,call,ncp);
2519 linphone_call_params_destroy (ncp);
2520 linphonec_out("Trying to bring up video stream...\n");
2524 if (linphone_call_camera_enabled (call))
2525 linphonec_out("Camera is allowed for current call.\n");
2526 else linphonec_out("Camera is dis-allowed for current call.\n");
2531 static int lpc_cmd_snapshot(LinphoneCore *lc, char *args){
2533 if (!args) return 0;
2534 call=linphone_core_get_current_call(lc);
2536 linphone_call_take_video_snapshot(call,args);
2537 linphonec_out("Taking video snapshot in file %s\n", args);
2538 }else linphonec_out("There is no active call.\n");
2542 static int lpc_cmd_vfureq(LinphoneCore *lc, char *arg){
2544 call=linphone_core_get_current_call(lc);
2546 linphone_call_send_vfu_request(call);
2547 linphonec_out("VFU request sent\n");
2548 }else linphonec_out("There is no active call.\n");
2553 static int lpc_cmd_identify(LinphoneCore *lc, char *args){
2555 const char *remote_ua;
2557 call=linphone_core_get_current_call(lc);
2559 linphonec_out("There is currently running call. Specify call id.\n");
2563 call=linphonec_get_call(atoi(args));
2568 remote_ua=linphone_call_get_remote_user_agent(call);
2570 linphonec_out("Remote user agent string is: %s\n",remote_ua);
2575 static int lpc_cmd_ringback(LinphoneCore *lc, char *args){
2576 if (!args) return 0;
2577 if (strcmp(args,"disable")==0){
2578 linphone_core_set_remote_ringback_tone(lc,NULL);
2579 linphonec_out("Disabling ringback tone.\n");
2582 linphone_core_set_remote_ringback_tone (lc,args);
2583 linphonec_out("Using %s as ringback tone to be played to callers.",args);
2587 static int zrtp_set_verified(LinphoneCore *lc, char *args, bool_t verified){
2588 LinphoneCall *call=linphone_core_get_current_call(lc);
2589 if (linphone_call_params_get_media_encryption(linphone_call_get_current_params(call))==LinphoneMediaEncryptionZRTP){
2590 linphone_call_set_authentication_token_verified(call,verified);
2594 static int lpc_cmd_zrtp_verified(LinphoneCore *lc, char *args){
2595 return zrtp_set_verified(lc,args,TRUE);
2597 static int lpc_cmd_zrtp_unverified(LinphoneCore *lc, char *args){
2598 return zrtp_set_verified(lc,args,FALSE);
2601 /***************************************************************************
2603 * Command table management funx
2605 ***************************************************************************/
2608 * Find a command given its name
2610 static LPC_COMMAND *
2611 lpc_find_command(const char *name)
2615 for (i=0; commands[i].name; ++i)
2617 if (strcmp(name, commands[i].name) == 0)
2618 return &commands[i];
2621 for (i=0; advanced_commands[i].name; ++i)
2623 if (strcmp(name, advanced_commands[i].name) == 0)
2624 return &advanced_commands[i];
2627 return (LPC_COMMAND *)NULL;
2631 /****************************************************************************
2633 * $Log: commands.c,v $
2634 * Revision 1.39 2008/07/03 15:08:34 smorlat
2635 * api cleanups, interface in progress.
2637 * Revision 1.38 2008/06/17 20:38:59 smorlat
2638 * added missing file.
2640 * Revision 1.37 2008/04/09 09:26:00 smorlat
2641 * merge various patches
2644 * Revision 1.36 2007/08/01 14:47:53 strk
2645 * * console/commands.c: Clean up commands 'nat', 'stun'
2646 * and 'firewall' to be more intuitive.
2648 * Revision 1.35 2007/06/27 09:01:25 smorlat
2649 * logging improvements.
2651 * Revision 1.34 2007/02/20 10:17:13 smorlat
2652 * linphonec friends patch2
2654 * Revision 1.31 2006/09/22 07:22:47 smorlat
2655 * linphonecore api changes.
2657 * Revision 1.30 2006/09/08 15:32:57 smorlat
2658 * support for using files instead of soundcard (used by linphonec only)
2660 * Revision 1.29 2006/08/28 14:29:07 smorlat
2663 * Revision 1.28 2006/08/21 12:49:59 smorlat
2664 * merged several little patches.
2666 * Revision 1.27 2006/07/17 18:45:00 smorlat
2667 * support for several event queues in ortp.
2668 * glib dependency removed from coreapi/ and console/
2670 * Revision 1.26 2006/04/14 15:16:36 smorlat
2671 * soundcard use did nothing !
2673 * Revision 1.25 2006/04/06 20:09:33 smorlat
2674 * add linphonec command to see and select sound devices.
2676 * Revision 1.24 2006/03/04 11:17:10 smorlat
2677 * mediastreamer2 in progress.
2679 * Revision 1.23 2006/02/20 21:14:01 strk
2680 * Handled syntax errors with 'friend' command
2682 * Revision 1.22 2006/02/20 10:20:29 strk
2683 * Added substring-based filter support for command 'friend list'
2685 * Revision 1.21 2006/02/02 15:39:18 strk
2686 * - Added 'friend list' and 'friend call' commands
2687 * - Allowed for multiple DTFM send in a single line
2688 * - Added status-specific callback (bare version)
2690 * Revision 1.20 2006/01/26 11:54:34 strk
2691 * More robust 'nat' command handler (strip blanks in args)
2693 * Revision 1.19 2006/01/26 09:48:05 strk
2694 * Added limits.h include
2696 * Revision 1.18 2006/01/26 02:18:05 strk
2697 * Added new commands 'nat use' and 'nat unuse'.
2698 * These will required a pending patch to linphonecore.c
2701 * Revision 1.17 2006/01/20 14:12:33 strk
2702 * Added linphonec_init() and linphonec_finish() functions.
2703 * Handled SIGINT and SIGTERM to invoke linphonec_finish().
2704 * Handling of auto-termination (-t) moved to linphonec_finish().
2705 * Reworked main (input read) loop to not rely on 'terminate'
2706 * and 'run' variable (dropped). configfile_name allocated on stack
2707 * using PATH_MAX limit. Changed print_usage signature to allow
2708 * for an exit_status specification.
2710 * Revision 1.16 2006/01/18 09:25:32 strk
2711 * Command completion inhibited in proxy addition and auth request prompts.
2712 * Avoided use of linphonec_readline's internal filename completion.
2714 * Revision 1.15 2006/01/14 13:29:32 strk
2715 * Reworked commands interface to use a table structure,
2716 * used by command line parser and help function.
2717 * Implemented first level of completion (commands).
2718 * Added notification of invalid "answer" and "terminate"
2719 * commands (no incoming call, no active call).
2720 * Forbidden "call" intialization when a call is already active.
2721 * Cleaned up all commands, adding more feedback and error checks.
2723 * Revision 1.14 2006/01/13 13:00:29 strk
2724 * Added linphonec.h. Code layout change (added comments, forward decl,
2725 * globals on top, copyright notices and Logs). Handled out-of-memory
2726 * condition on history management. Removed assumption on sizeof(char).
2727 * Fixed bug in authentication prompt (introduced by linphonec_readline).
2728 * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
2731 ****************************************************************************/