commands.c 74 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4
/****************************************************************************
 *
 *  $Id: commands.c,v 1.39 2008/07/03 15:08:34 smorlat Exp $
 *
5
 *  Copyright (C) 2006-2009  Sandro Santilli <strk@keybit.net>
aymeric's avatar
aymeric committed
6 7
 *  Copyright (C) 2004  Simon MORLAT <simon.morlat@linphone.org>
 *
8
****************************************************************************
aymeric's avatar
aymeric committed
9
 *
10 11 12 13
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
aymeric's avatar
aymeric committed
14
 *
15 16 17 18
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
aymeric's avatar
aymeric committed
19
 *
20 21 22
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
aymeric's avatar
aymeric committed
23 24 25 26 27 28
 *
 ****************************************************************************/

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
Jehan Monnier's avatar
Jehan Monnier committed
29
#ifndef _WIN32_WCE
aymeric's avatar
aymeric committed
30
#include <errno.h>
Jehan Monnier's avatar
Jehan Monnier committed
31 32
#include <unistd.h>
#endif /*_WIN32_WCE*/
aymeric's avatar
aymeric committed
33 34 35 36
#include <limits.h>
#include <ctype.h>
#include <linphonecore.h>
#include "linphonec.h"
37
#include "lpconfig.h"
aymeric's avatar
aymeric committed
38

39 40 41 42
#ifndef WIN32
#include <sys/wait.h>
#endif

43 44 45
#define AUDIO 0
#define VIDEO 1

aymeric's avatar
aymeric committed
46 47 48 49 50 51 52 53 54 55 56 57
/***************************************************************************
 *
 *  Forward declarations 
 *
 ***************************************************************************/

extern char *lpc_strip_blanks(char *input);

/* Command handlers */
static int lpc_cmd_help(LinphoneCore *, char *);
static int lpc_cmd_proxy(LinphoneCore *, char *);
static int lpc_cmd_call(LinphoneCore *, char *);
58
static int lpc_cmd_calls(LinphoneCore *, char *);
Simon Morlat's avatar
Simon Morlat committed
59
static int lpc_cmd_chat(LinphoneCore *, char *);
aymeric's avatar
aymeric committed
60
static int lpc_cmd_answer(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
61
static int lpc_cmd_autoanswer(LinphoneCore *, char *);
aymeric's avatar
aymeric committed
62
static int lpc_cmd_terminate(LinphoneCore *, char *);
63
static int lpc_cmd_redirect(LinphoneCore *, char *);
aymeric's avatar
aymeric committed
64 65
static int lpc_cmd_call_logs(LinphoneCore *, char *);
static int lpc_cmd_ipv6(LinphoneCore *, char *);
66
static int lpc_cmd_transfer(LinphoneCore *, char *);
aymeric's avatar
aymeric committed
67 68 69 70 71 72
static int lpc_cmd_quit(LinphoneCore *, char *);
static int lpc_cmd_nat(LinphoneCore *, char *);
static int lpc_cmd_stun(LinphoneCore *, char *);
static int lpc_cmd_firewall(LinphoneCore *, char *);
static int lpc_cmd_friend(LinphoneCore *, char*);
static int lpc_cmd_soundcard(LinphoneCore *, char *);
73 74
static int lpc_cmd_webcam(LinphoneCore *, char *);
static int lpc_cmd_staticpic(LinphoneCore *, char *);
aymeric's avatar
aymeric committed
75 76
static int lpc_cmd_play(LinphoneCore *, char *);
static int lpc_cmd_record(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
77
static int lpc_cmd_register(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
78
static int lpc_cmd_unregister(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
79
static int lpc_cmd_duration(LinphoneCore *lc, char *args);
smorlat's avatar
smorlat committed
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 85 86
static int lpc_cmd_acodec(LinphoneCore *lc, char *args);
static int lpc_cmd_vcodec(LinphoneCore *lc, char *args);
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 90
static int lpc_cmd_pause(LinphoneCore *lc, char *args);
static int lpc_cmd_resume(LinphoneCore *lc, char *args);
Simon Morlat's avatar
Simon Morlat committed
91 92
static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args);
static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args);
93
static int lpc_cmd_playback_gain(LinphoneCore *lc, char *args);
Simon Morlat's avatar
Simon Morlat committed
94
static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args);
Simon Morlat's avatar
Simon Morlat committed
95
#ifdef VIDEO_ENABLED
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);
Simon Morlat's avatar
Simon Morlat committed
101
#endif
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);
Simon Morlat's avatar
Simon Morlat committed
105
static int lpc_cmd_conference(LinphoneCore *lc, char *args);
Simon Morlat's avatar
Simon Morlat committed
106
static int lpc_cmd_zrtp_verified(LinphoneCore *lc, char *args);
107
static int lpc_cmd_zrtp_unverified(LinphoneCore *lc, char *args);
smorlat's avatar
smorlat committed
108

aymeric's avatar
aymeric committed
109 110 111 112 113 114
/* Command handler helpers */
static void linphonec_proxy_add(LinphoneCore *lc);
static void linphonec_proxy_display(LinphoneProxyConfig *lc);
static void linphonec_proxy_list(LinphoneCore *lc);
static void linphonec_proxy_remove(LinphoneCore *lc, int index);
static  int linphonec_proxy_use(LinphoneCore *lc, int index);
smorlat's avatar
smorlat committed
115
static void linphonec_proxy_show(LinphoneCore *lc,int index);
aymeric's avatar
aymeric committed
116 117 118 119
static void linphonec_friend_display(LinphoneFriend *fr);
static int linphonec_friend_list(LinphoneCore *lc, char *arg);
static void linphonec_display_command_help(LPC_COMMAND *cmd);
static int linphonec_friend_call(LinphoneCore *lc, unsigned int num);
120
#ifndef WIN32
aymeric's avatar
aymeric committed
121
static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
122
#endif
aymeric's avatar
aymeric committed
123
static int linphonec_friend_delete(LinphoneCore *lc, int num);
124
static int linphonec_friend_delete(LinphoneCore *lc, int num);
125 126 127
static void linphonec_codec_list(int type, LinphoneCore *lc);
static void linphonec_codec_enable(int type, LinphoneCore *lc, int index);
static void linphonec_codec_disable(int type, LinphoneCore *lc, int index);
128
static void lpc_display_call_states(LinphoneCore *lc);
smorlat's avatar
smorlat committed
129

aymeric's avatar
aymeric committed
130 131 132
/* Command table management */
static LPC_COMMAND *lpc_find_command(const char *name);

133 134
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};
137

aymeric's avatar
aymeric committed
138 139 140 141 142 143 144 145 146
/***************************************************************************
 *
 *  Global variables
 *
 ***************************************************************************/

/*
 * Commands table.
 */
147
static LPC_COMMAND commands[] = {
148
	{ "help", lpc_cmd_help, "Print commands help.",
149 150 151
		"'help <command>'\t: displays specific help for command.\n"
		"'help advanced'\t: shows advanced commands.\n"
	},
152 153
	{ "call", lpc_cmd_call, "Call a SIP uri or number",
#ifdef VIDEO_ENABLED
154 155 156 157
		"'call <sip-url or number>  [options]' \t: initiate a call to the specified destination.\n"
		"Options can be:\n"
		"--audio-only : initiate the call without video.\n"
		"--early-media : sends audio and video stream immediately when remote proposes early media.\n"
158 159 160
#else
		"'call <sip-url or number>' \t: initiate a call to the specified destination.\n"
#endif
161
		},
162
	{ "calls", lpc_cmd_calls, "Show all the current calls with their id and status.",
163
		NULL
aymeric's avatar
aymeric committed
164
		},
Simon Morlat's avatar
Simon Morlat committed
165 166 167 168
	{ "chat", lpc_cmd_chat, "Chat with a SIP uri",
		"'chat <sip-url> \"message\"' "
		": send a chat message \"message\" to the specified destination."
		},
169 170
	{ "terminate", lpc_cmd_terminate, "Terminate a call",
		"'terminate' : Terminate the current call\n"
171
		"'terminate <call id>' : Terminate the call with supplied id\n"
172 173
		"'terminate <all>' : Terminate all the current calls\n"
		},
aymeric's avatar
aymeric committed
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"
aymeric's avatar
aymeric committed
177
	},
178 179 180 181 182
	{ "pause", lpc_cmd_pause, "pause a call",
		"'pause' : pause the current call\n"},
	{ "resume", lpc_cmd_resume, "resume a call",
		"'resume' : resume the unique call\n"
		"'resume <call id>' : hold off the call with given id\n"},
183 184 185 186 187 188
	{ "transfer", lpc_cmd_transfer,
		"Transfer a call to a specified destination.",
		"'transfer <sip-uri>' : transfers the current active call to the destination sip-uri\n"
		"'transfer <call id> <sip-uri>': transfers the call with 'id' to the destination sip-uri\n"
		"'transfer <call id1> --to-call <call id2>': transfers the call with 'id1' to the destination of call 'id2' (attended transfer)\n"
	},
Simon Morlat's avatar
Simon Morlat committed
189 190 191 192
	{ "conference", lpc_cmd_conference, "Create and manage an audio conference.",
		"'conference add <call id> : join the call with id 'call id' into the audio conference."
		"'conference rm <call id> : remove the call with id 'call id' from the audio conference."
	},
193 194
	{ "mute", lpc_cmd_mute_mic, 
	  "Mute microphone and suspend voice transmission."},
195 196 197 198 199
#ifdef VIDEO_ENABLED
	{ "camera", lpc_cmd_camera, "Send camera output for current call.",
		"'camera on'\t: allow sending of local camera video to remote end.\n"
		"'camera off'\t: disable sending of local camera's video to remote end.\n"},
#endif
200 201
	{ "unmute", lpc_cmd_unmute_mic, 
		  "Unmute microphone and resume voice transmission."},
202 203
	{ "playbackgain", lpc_cmd_playback_gain, 
		  "Adjust playback gain."},
204 205
	{ "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
	
206 207
	{ "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
		"'autoanswer'       \t: show current autoanswer mode\n"
smorlat's avatar
smorlat committed
208 209
		"'autoanswer enable'\t: enable autoanswer mode\n"
		"'autoanswer disable'\t: disable autoanswer mode \n"},
aymeric's avatar
aymeric committed
210 211 212 213 214
	{ "proxy", lpc_cmd_proxy, "Manage proxies",
		"'proxy list' : list all proxy setups.\n"
		"'proxy add' : add a new proxy setup.\n"
		"'proxy remove <index>' : remove proxy setup with number index.\n"
		"'proxy use <index>' : use proxy with number index as default proxy.\n"
215
		"'proxy unuse' : don't use a default proxy.\n"
smorlat's avatar
smorlat committed
216 217
		"'proxy show <index>' : show configuration and status of the proxy numbered by index.\n"
		"'proxy show default' : show configuration and status of the default proxy.\n"
aymeric's avatar
aymeric committed
218 219 220
	},
	{ "soundcard", lpc_cmd_soundcard, "Manage soundcards",
		"'soundcard list' : list all sound devices.\n"
221
		"'soundcard show' : show current sound devices configuration.\n"
aymeric's avatar
aymeric committed
222 223 224
		"'soundcard use <index>' : select a sound device.\n"
		"'soundcard use files' : use .wav files instead of soundcard\n"
	},
225 226 227 228
	{ "webcam", lpc_cmd_webcam, "Manage webcams",
		"'webcam list' : list all known devices.\n"
		"'webcam use <index>' : select a video device.\n"
	},
aymeric's avatar
aymeric committed
229 230 231 232 233 234 235 236 237 238 239
	{ "ipv6", lpc_cmd_ipv6, "Use IPV6",
		"'ipv6 status' : show ipv6 usage status.\n"
		"'ipv6 enable' : enable the use of the ipv6 network.\n"
		"'ipv6 disable' : do not use ipv6 network."
	},
	{ "nat", lpc_cmd_nat, "Set nat address",
		"'nat'        : show nat settings.\n"
		"'nat <addr>' : set nat address.\n"
	},
	{ "stun", lpc_cmd_stun, "Set stun server address",
		"'stun'        : show stun settings.\n"
strk's avatar
strk committed
240
		"'stun <addr>' : set stun server address.\n"
aymeric's avatar
aymeric committed
241
	},
strk's avatar
strk committed
242
	{ "firewall", lpc_cmd_firewall, "Set firewall policy",
aymeric's avatar
aymeric committed
243 244 245
		"'firewall'        : show current firewall policy.\n"
		"'firewall none'   : use direct connection.\n"
		"'firewall nat'    : use nat address given with the 'nat' command.\n"
strk's avatar
strk committed
246
		"'firewall stun'   : use stun server given with the 'stun' command.\n"
aymeric's avatar
aymeric committed
247
	},
248
	{ "call-logs", lpc_cmd_call_logs, "Calls history", NULL },
aymeric's avatar
aymeric committed
249 250 251 252 253 254 255 256
	{ "friend", lpc_cmd_friend, "Manage friends",
		"'friend list [<pattern>]'    : list friends.\n"
		"'friend call <index>'        : call a friend.\n"
		"'friend add <name> <addr>'   : add friend, <name> must be quoted to include\n"
	    "                               spaces, <addr> has \"sip:\" added if it isn't\n"
	    "                               there.  Don't use '<' '>' around <addr>.\n"
		"'friend delete <index>'      : remove friend, 'all' removes all\n"
	},
257 258 259 260
	{ "play", lpc_cmd_play, "play a wav file",
		"This command has two roles:\n"
		"Plays a file instead of capturing from soundcard - only available in file mode (see 'help soundcard')\n"
		"Specifies a wav file to be played to play music to far end when putting it on hold (pause)\n"
aymeric's avatar
aymeric committed
261 262 263 264 265 266 267
		"'play <wav file>'    : play a wav file."
	},
	{ "record", lpc_cmd_record, "record to a wav file",
		"This feature is available only in file mode (see 'help soundcard')\n"
		"'record <wav file>'    : record into wav file."
	},
	{ "quit", lpc_cmd_quit, "Exit linphonec", NULL },
268 269 270 271 272 273
	{ (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
};


static LPC_COMMAND advanced_commands[] = {
	 { "codec", lpc_cmd_acodec, "Audio codec configuration",
274 275 276 277 278 279 280
            "'codec list' : list audio codecs\n"
            "'codec enable <index>' : enable available audio codec\n"
            "'codec disable <index>' : disable audio codec" },
    { "vcodec", lpc_cmd_vcodec, "Video codec configuration",
            "'vcodec list' : list video codecs\n"
            "'vcodec enable <index>' : enable available video codec\n"
            "'vcodec disable <index>' : disable video codec" },
281 282 283 284
	{ "ec", lpc_cmd_echocancellation, "Echo cancellation",
	    "'ec on [<delay>] [<tail>] [<framesize>]' : turn EC on with given delay, tail length and framesize\n"
	    "'ec off' : turn echo cancellation (EC) off\n"
	    "'ec show' : show EC status" },
285 286 287 288
	{ "el", lpc_cmd_echolimiter, "Echo limiter",
	    "'el on turns on echo limiter (automatic half duplex, for cases where echo canceller cannot work)\n"
	    "'el off' : turn echo limiter off\n"
	    "'el show' : show echo limiter status" },
Simon Morlat's avatar
Simon Morlat committed
289
	{ "nortp-on-audio-mute", lpc_cmd_rtp_no_xmit_on_audio_mute,
290 291 292
		  "Set the rtp_no_xmit_on_audio_mute configuration parameter",
		  "   If set to 1 then rtp transmission will be muted when\n"
		  "   audio is muted , otherwise rtp is always sent."}, 
Simon Morlat's avatar
Simon Morlat committed
293
#ifdef VIDEO_ENABLED
294 295 296 297
	{ "vwindow", lpc_cmd_video_window, "Control video display window",
		"'vwindow show': shows video window\n"
		"'vwindow hide': hides video window\n"
		"'vwindow pos <x> <y>': Moves video window to x,y pixel coordinates\n"
298 299 300 301 302 303 304 305 306 307 308
		"'vwindow size <width> <height>': Resizes video window\n"
		"'vwindow id <window id>': embeds video display into supplied window id."
	},
	{ "pwindow", lpc_cmd_preview_window, "Control local camera video display (preview window)",
		"'pwindow show': shows the local camera video display\n"
		"'pwindow hide': hides the local camera video display\n"
		"'pwindow pos <x> <y>': Moves preview window to x,y pixel coordinates\n"
		"'pwindow size <width> <height>': Resizes preview window\n"
		"'pwindow id <window id>': embeds preview display into supplied window id.\n"
		"'pwindow integrated': integrate preview display within the video window of current call.\n"
		"'pwindow standalone': use standalone window for preview display."
309
	},
310 311 312
	{ "snapshot", lpc_cmd_snapshot, "Take a snapshot of currently received video stream",
		"'snapshot <file path>': take a snapshot and records it in jpeg format into the supplied path\n"
	},
313
	{ "vfureq", lpc_cmd_vfureq, "Request the other side to send VFU for the current call"},
Simon Morlat's avatar
Simon Morlat committed
314
#endif
315 316 317 318 319
	{ "states", lpc_cmd_states, "Show internal states of liblinphone, registrations and calls, according to linphonecore.h definitions",
		"'states global': shows global state of liblinphone \n"
		"'states calls': shows state of calls\n"
		"'states proxies': shows state of proxy configurations"
	},
320 321 322 323 324 325 326 327 328
	{ "register", lpc_cmd_register, "Register in one line to a proxy" , "register <sip identity> <sip proxy> <password>"},
	{ "unregister", lpc_cmd_unregister, "Unregister from default proxy", NULL	},
	{ "status", lpc_cmd_status, "Print various status information", 
			"'status register'  \t: print status concerning registration\n"
			"'status autoanswer'\t: tell whether autoanswer mode is enabled\n"
			"'status hook'      \t: print hook status\n" },
	{ "ports", lpc_cmd_ports, "Network ports configuration", 
			"'ports'  \t: prints current used ports.\n"
			"'ports sip <port number>'\t: Sets the sip port.\n" },
329 330 331 332
	{ "param", lpc_cmd_param, "parameter set or read as normally given in .linphonerc",
			"'param <section> <parameter> [<value>]'  \t: reads [sets] given parameter.\n"
			"NOTES: - changes may become effective after (re)establishing a sip connection.\n"
			"       - upon exit, .linphonerc will reflect the updated state.\n" },
333 334 335 336 337 338 339 340 341
	{ "speak", lpc_cmd_speak, "Speak a sentence using espeak TTS engine",
			"This feature is available only in file mode. (see 'help soundcard')\n"
			"'speak <voice name> <sentence>'	: speak a text using the specified espeak voice.\n"
			"Example for english voice: 'speak default Hello my friend !'"
	},
	{ "staticpic", lpc_cmd_staticpic, "Manage static pictures when nowebcam",
		"'staticpic set' : Set path to picture that should be used.\n"
		"'staticpic fps' : Get/set frames per seconds for picture emission.\n"
	},
342 343 344 345
	{ "identify", lpc_cmd_identify, "Returns the user-agent string of far end",
		"'identify' \t: returns remote user-agent string for current call.\n"
		"'identify <id>' \t: returns remote user-agent string for call with supplied id.\n"
	},
346 347 348 349
	{ "ringback", lpc_cmd_ringback, "Specifies a ringback tone to be played to remote end during incoming calls",
		"'ringback <path of mono .wav file>'\t: Specifies a ringback tone to be played to remote end during incoming calls\n"
		"'ringback disable'\t: Disable playing of ringback tone to callers\n"
	},
350 351 352
	{ "redirect", lpc_cmd_redirect, "Redirect an incoming call",
		"'redirect <redirect-uri>'\t: Redirect all pending incoming calls to the <redirect-uri>\n"
	},
Simon Morlat's avatar
Simon Morlat committed
353 354 355
	{ "zrtp-set-verified", lpc_cmd_zrtp_verified,"Set ZRTP SAS verified.",
		"'Set ZRTP SAS verified'\n"
	},
356 357 358
	{ "zrtp-set-unverified", lpc_cmd_zrtp_unverified,"Set ZRTP SAS not verified.",
		"'Set ZRTP SAS not verified'\n"
	},
359
	{	NULL,NULL,NULL,NULL}
aymeric's avatar
aymeric committed
360 361
};

362 363


aymeric's avatar
aymeric committed
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
/***************************************************************************
 *
 *  Public interface 
 *
 ***************************************************************************/

/*
 * Main command dispatcher.
 * WARNING: modifies second argument!
 *
 * Always return 1 currently.
 */
int
linphonec_parse_command_line(LinphoneCore *lc, char *cl)
{
	char *ptr=cl;
	char *args=NULL;
	LPC_COMMAND *cmd;

	/* Isolate first word and args */
	while(*ptr && !isspace(*ptr)) ++ptr;
	if (*ptr)
	{
		*ptr='\0';
 		/* set args to first nonblank */
		args=ptr+1;
		while(*args && isspace(*args)) ++args;
	}

	/* Handle DTMF */
	if ( isdigit(*cl) || *cl == '#' || *cl == '*' )
	{
		while ( isdigit(*cl) || *cl == '#' || *cl == '*' )
		{
			linphone_core_send_dtmf(lc, *cl);
399
			linphone_core_play_dtmf (lc,*cl,100);
smorlat's avatar
smorlat committed
400
			ms_sleep(1); // be nice
aymeric's avatar
aymeric committed
401 402 403 404 405 406 407 408 409 410 411
			++cl;
		}

		// discard spurious trailing chars
		return 1;
	}

	/* Handle other kind of commands */
	cmd=lpc_find_command(cl);
	if ( !cmd )
	{
412
		linphonec_out("'%s': Cannot understand this.\n", cl);
aymeric's avatar
aymeric committed
413 414 415 416 417
		return 1;
	}

	if ( ! cmd->func(lc, args) )
	{
418
		linphonec_out("Syntax error.\n");
aymeric's avatar
aymeric committed
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
		linphonec_display_command_help(cmd);
	}

	return 1;
}

/*
 * Generator function for command completion.
 * STATE let us know whether to start from scratch;
 * without any state (STATE==0), then we start at the
 * top of the list.
 */
char *
linphonec_command_generator(const char *text, int state)
{
434
	static int index, len, adv;
aymeric's avatar
aymeric committed
435 436 437 438 439
	char *name;

	if ( ! state )
	{
		index=0;
440
		adv=0;
aymeric's avatar
aymeric committed
441 442 443 444 445 446
		len=strlen(text);
	}
	/*
 	 * Return the next name which partially matches
	 * from the commands list
	 */
447 448
	if (adv==0){
		while ((name=commands[index].name))
aymeric's avatar
aymeric committed
449
		{
450 451 452 453 454 455
			++index; /* so next call get next command */

			if (strncmp(name, text, len) == 0)
			{
				return ortp_strdup(name);
			}
aymeric's avatar
aymeric committed
456
		}
457 458
		adv=1;
		index=0;
aymeric's avatar
aymeric committed
459
	}
460 461 462 463
	if (adv==1){
		while ((name=advanced_commands[index].name))
		{
			++index; /* so next call get next command */
aymeric's avatar
aymeric committed
464

465 466 467 468 469 470
			if (strncmp(name, text, len) == 0)
			{
				return ortp_strdup(name);
			}
		}
	}
aymeric's avatar
aymeric committed
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
	return NULL;
}


/***************************************************************************
 *
 *  Command handlers 
 *
 ***************************************************************************/

static int
lpc_cmd_help(LinphoneCore *lc, char *arg)
{
	int i=0;
	LPC_COMMAND *cmd;

	if (!arg || !*arg)
	{
489 490
		linphonec_out("Commands are:\n");
		linphonec_out("---------------------------\n");
aymeric's avatar
aymeric committed
491 492 493

		while (commands[i].help)
		{
494
			linphonec_out("%10.10s\t%s\n", commands[i].name,
aymeric's avatar
aymeric committed
495 496 497 498
				commands[i].help);
			i++;
		}
		
499
		linphonec_out("---------------------------\n");
500 501
		linphonec_out("Type 'help <command>' for more details or\n");
		linphonec_out("     'help advanced' to list additional commands.\n");
aymeric's avatar
aymeric committed
502 503 504 505

		return 1;
	}

506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
	if (strcmp(arg,"advanced")==0){
		linphonec_out("Advanced commands are:\n");
		linphonec_out("---------------------------\n");
		i=0;
		while (advanced_commands[i].help)
		{
			linphonec_out("%10.10s\t%s\n", advanced_commands[i].name,
				advanced_commands[i].help);
			i++;
		}
		
		linphonec_out("---------------------------\n");
		linphonec_out("Type 'help <command>' for more details.\n");

		return 1;
	}
	
aymeric's avatar
aymeric committed
523 524 525
	cmd=lpc_find_command(arg);
	if ( !cmd )
	{
526
		linphonec_out("No such command.\n");
aymeric's avatar
aymeric committed
527 528 529 530 531 532 533 534
		return 1;
	}

	linphonec_display_command_help(cmd);
	return 1;

}

smorlat's avatar
smorlat committed
535
static char callee_name[256]={0};
536
static char caller_name[256]={0};
smorlat's avatar
smorlat committed
537

538

aymeric's avatar
aymeric committed
539 540 541 542 543 544 545 546
static int
lpc_cmd_call(LinphoneCore *lc, char *args)
{
	if ( ! args || ! *args )
	{
		return 0;
	}
	{
547
		LinphoneCall *call;
548
		LinphoneCallParams *cp=linphone_core_create_default_call_parameters (lc);
549
		char *opt1,*opt2;
550 551 552 553 554
		if ( linphone_core_in_call(lc) )
		{
			linphonec_out("Terminate or hold on the current call first.\n");
			return 1;
		}
555 556 557 558
		opt1=strstr(args,"--audio-only");
		opt2=strstr(args,"--early-media");
		if (opt1){
			opt1[0]='\0';
559 560
			linphone_call_params_enable_video (cp,FALSE);
		}
561 562 563 564
		if (opt2){
			opt2[0]='\0';
			linphone_call_params_enable_early_media_sending(cp,TRUE);
		}
565
		if ( NULL == (call=linphone_core_invite_with_params(lc, args,cp)) )
aymeric's avatar
aymeric committed
566
		{
567
			linphonec_out("Error from linphone_core_invite.\n");
aymeric's avatar
aymeric committed
568 569 570
		}
		else
		{
smorlat's avatar
smorlat committed
571
			snprintf(callee_name,sizeof(callee_name),"%s",args);
aymeric's avatar
aymeric committed
572
		}
573
		linphone_call_params_destroy(cp);
aymeric's avatar
aymeric committed
574 575 576 577
	}
	return 1;
}

578 579 580 581 582
static int 
lpc_cmd_calls(LinphoneCore *lc, char *args){
	const MSList *calls = linphone_core_get_calls(lc);
	if(calls)
	{
583
		lpc_display_call_states(lc);
584 585 586 587 588 589 590 591
	}else
	{
		linphonec_out("No active call.\n");
	}
	return 1;
}


Simon Morlat's avatar
Simon Morlat committed
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
static int
lpc_cmd_chat(LinphoneCore *lc, char *args)
{
	char *arg1 = args;
	char *arg2 = NULL;
	char *ptr = args;

	if (!args) return 0;

	/* Isolate first and second arg */
	while(*ptr && !isspace(*ptr)) ++ptr;
	if ( *ptr )
	{
		*ptr='\0';
		arg2=ptr+1;
		while(*arg2 && isspace(*arg2)) ++arg2;
	}
	else
	{
		/* missing one parameter */
		return 0;
	}
	LinphoneChatRoom *cr = linphone_core_create_chat_room(lc,arg1);
	linphone_chat_room_send_message(cr,arg2);
	linphone_chat_room_destroy(cr);

	return 1;
}

621
const char *linphonec_get_callee(){
smorlat's avatar
smorlat committed
622 623 624
	return callee_name;
}

625 626 627 628 629 630 631 632
const char *linphonec_get_caller(){
	return caller_name;
}

void linphonec_set_caller(const char *caller){
	snprintf(caller_name,sizeof(caller_name)-1,"%s",caller);
}

aymeric's avatar
aymeric committed
633
static int
634
lpc_cmd_transfer(LinphoneCore *lc, char *args)
aymeric's avatar
aymeric committed
635
{
636 637
	if (args){
		LinphoneCall *call;
638
		LinphoneCall *call2;
639 640 641
		const char *refer_to=NULL;
		char arg1[256]={0};
		char arg2[266]={0};
642
		long id2=0;
643
		int n=sscanf(args,"%255s %265s %li",arg1,arg2,&id2);
644 645
		if (n==1 || isalpha(*arg1)){
			call=linphone_core_get_current_call(lc);
646
			if (call==NULL && ms_list_size(linphone_core_get_calls(lc))==1){
647 648 649 650 651 652 653
				call=(LinphoneCall*)linphone_core_get_calls(lc)->data;
			}
			refer_to=args;
			if (call==NULL){
				linphonec_out("No active call, please specify a call id among the ones listed by 'calls' command.\n");
				return 0;
			}
654 655
			linphone_core_transfer_call(lc, call, refer_to);
		}else if (n==2){
656 657 658 659
			long id=atoi(arg1);
			refer_to=args+strlen(arg1)+1;
			call=linphonec_get_call(id);
			if (call==NULL) return 0;
660 661 662 663 664 665 666 667 668 669 670 671
			linphone_core_transfer_call(lc, call, refer_to);
		}else if (n==3){
			long id=atoi(arg1);
			call=linphonec_get_call(id);
			call2=linphonec_get_call(id2);
			if (call==NULL || call2==NULL) return 0;
			if (strcmp(arg2,"--to-call")!=0){
				return 0;
			}
			linphonec_out("Performing attended transfer of call %i to call %i",id,id2);
			linphone_core_transfer_call_to_another (lc,call,call2);
		}else return 0;
672 673 674
	}else{
		linphonec_out("Transfer command requires at least one argument\n");
		return 0;
aymeric's avatar
aymeric committed
675 676 677 678 679 680 681
	}
	return 1;
}

static int
lpc_cmd_terminate(LinphoneCore *lc, char *args)
{
682
	if (linphone_core_get_calls(lc)==NULL){
683
		linphonec_out("No active calls\n");
684 685
		return 1;
	}
686
	if (!args)
aymeric's avatar
aymeric committed
687
	{
688 689
		if ( -1 == linphone_core_terminate_call(lc, NULL) ){
			linphonec_out("Could not stop the active call.\n");
690 691
		}
		return 1;
aymeric's avatar
aymeric committed
692
	}
693
	
694 695 696 697 698 699 700 701 702 703
	if(strcmp(args,"all")==0){
		linphonec_out("We are going to stop all the calls.\n");
		linphone_core_terminate_all_calls(lc);
		return 1;
	}else{
		/*the argument is a linphonec call id */
		long id=atoi(args);
		LinphoneCall *call=linphonec_get_call(id);
		if (call){
			if (linphone_core_terminate_call(lc,call)==-1){
704
				linphonec_out("Could not stop the call with id %li\n",id);
705
			}
706 707
		}else return 0;
		return 1;
708 709 710
	}
	return 0;
	
aymeric's avatar
aymeric committed
711 712
}

713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
static int
lpc_cmd_redirect(LinphoneCore *lc, char *args){
	const MSList *elem;
	int didit=0;
	if (!args) return 0;
	if ((elem=linphone_core_get_calls(lc))==NULL){
		linphonec_out("No active calls.\n");
		return 1;
	}
	while(elem!=NULL){
		LinphoneCall *call=(LinphoneCall*)elem->data;
		if (linphone_call_get_state(call)==LinphoneCallIncomingReceived){
			linphone_core_redirect_call(lc,call,args);
			didit=1;
			/*as the redirection closes the call, we need to re-check the call list that is invalidated.*/
			elem=linphone_core_get_calls(lc);
		}else elem=elem->next;
	}
	if (didit==0){
		linphonec_out("There is no pending incoming call to redirect.");
	}
	return 1;
}

aymeric's avatar
aymeric committed
737
static int
738
lpc_cmd_answer(LinphoneCore *lc, char *args){
739
	if (!args)
aymeric's avatar
aymeric committed
740
	{
741 742 743 744
		int nb=ms_list_size(linphone_core_get_calls(lc));
		if (nb==1){
			//if just one call is present answer the only one in passing NULL to the linphone_core_accept_call ...
			if ( -1 == linphone_core_accept_call(lc, NULL) )
745
			{
746
				linphonec_out("Fail to accept incoming call\n");
747
			}
748 749 750 751 752
		}else if (nb==0){
			linphonec_out("There are no calls to answer.\n");
		}else{
			linphonec_out("Multiple calls in progress, please specify call id.\n");
			return 0;
753
		}
754 755 756 757 758 759 760 761 762 763
		return 1;
	}else{
		long id;
		if (sscanf(args,"%li",&id)==1){
			LinphoneCall *call=linphonec_get_call (id);
			if (linphone_core_accept_call (lc,call)==-1){
				linphonec_out("Fail to accept call %i\n",id);
			}
		}else return 0;
		return 1;
764 765
	}
	return 0;
aymeric's avatar
aymeric committed
766 767
}

smorlat's avatar
smorlat committed
768 769 770
static int
lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
{
771 772 773 774 775 776 777 778 779 780
	if ( ! args )
	{
		if ( linphonec_get_autoanswer() ) {
			linphonec_out("Auto answer is enabled. Use 'autoanswer disable' to disable.\n");
		} else {
			linphonec_out("Auto answer is disabled. Use 'autoanswer enable' to enable.\n");
		}
		return 1;
	}

smorlat's avatar
smorlat committed
781 782
	if (strstr(args,"enable")){
		linphonec_set_autoanswer(TRUE);
smorlat's avatar
smorlat committed
783
		linphonec_out("Auto answer enabled.\n");
smorlat's avatar
smorlat committed
784 785
	}else if (strstr(args,"disable")){
		linphonec_set_autoanswer(FALSE);
smorlat's avatar
smorlat committed
786
		linphonec_out("Auto answer disabled.\n");
smorlat's avatar
smorlat committed
787 788 789 790
	}else return 0;
	return 1;
}

aymeric's avatar
aymeric committed
791 792 793
static int
lpc_cmd_quit(LinphoneCore *lc, char *args)
{
smorlat's avatar
smorlat committed
794
	linphonec_main_loop_exit();
aymeric's avatar
aymeric committed
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
	return 1;
}

static int
lpc_cmd_nat(LinphoneCore *lc, char *args)
{
	bool_t use;
	const char *nat;

	if ( args ) args=lpc_strip_blanks(args);

	if ( args && *args )
	{
		linphone_core_set_nat_address(lc, args);
		/* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS); */
	}

	nat = linphone_core_get_nat_address(lc);
Simon Morlat's avatar
Simon Morlat committed
813
	use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress;
814
	linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
aymeric's avatar
aymeric committed
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833

	return 1;
}

static int
lpc_cmd_stun(LinphoneCore *lc, char *args)
{
	bool_t use;
	const char *stun;

	if ( args ) args=lpc_strip_blanks(args);

	if ( args && *args )
	{
		linphone_core_set_stun_server(lc, args);
		/* linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN); */
	}

	stun = linphone_core_get_stun_server(lc);
Simon Morlat's avatar
Simon Morlat committed
834
	use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseStun;
835
	linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
aymeric's avatar
aymeric committed
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850

	return 1;
}

static int
lpc_cmd_firewall(LinphoneCore *lc, char *args)
{
	const char* setting=NULL;

	if ( args ) args=lpc_strip_blanks(args);

	if ( args && *args )
	{
		if (strcmp(args,"none")==0)
		{
Simon Morlat's avatar
Simon Morlat committed
851
			linphone_core_set_firewall_policy(lc,LinphonePolicyNoFirewall);
aymeric's avatar
aymeric committed
852
		}
853 854 855 856 857 858 859 860 861 862
		else if (strcmp(args,"ice")==0)
		{
			setting = linphone_core_get_stun_server(lc);
			if ( ! setting )
			{
				linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
				return 1;
			}
			linphone_core_set_firewall_policy(lc,LinphonePolicyUseIce);
		}
aymeric's avatar
aymeric committed
863 864 865 866 867
		else if (strcmp(args,"stun")==0)
		{
			setting = linphone_core_get_stun_server(lc);
			if ( ! setting )
			{
868
				linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
aymeric's avatar
aymeric committed
869 870
				return 1;
			}
Simon Morlat's avatar
Simon Morlat committed
871
			linphone_core_set_firewall_policy(lc,LinphonePolicyUseStun);
aymeric's avatar
aymeric committed
872 873 874 875 876 877
		}
		else if (strcmp(args,"nat")==0)
		{
			setting = linphone_core_get_nat_address(lc);
			if ( ! setting )
			{
878
				linphonec_out("No nat address is defined, use 'nat <address>' first");
aymeric's avatar
aymeric committed
879 880
				return 1;
			}
Simon Morlat's avatar
Simon Morlat committed
881
			linphone_core_set_firewall_policy(lc,LinphonePolicyUseNatAddress);
aymeric's avatar
aymeric committed
882 883 884 885 886
		}
	}

	switch(linphone_core_get_firewall_policy(lc))
	{
Simon Morlat's avatar
Simon Morlat committed
887
		case LinphonePolicyNoFirewall:
888
			linphonec_out("No firewall\n");
aymeric's avatar
aymeric committed
889
			break;
Simon Morlat's avatar
Simon Morlat committed
890
		case LinphonePolicyUseStun:
891
			linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
aymeric's avatar
aymeric committed
892
			break;
Simon Morlat's avatar
Simon Morlat committed
893
		case LinphonePolicyUseNatAddress:
894
			linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
aymeric's avatar
aymeric committed
895
			break;
896 897 898
		case LinphonePolicyUseIce:
			linphonec_out("Using ice with stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
			break;
aymeric's avatar
aymeric committed
899 900 901 902
	}
	return 1;
}

smorlat's avatar
smorlat committed
903
#ifndef WIN32
aymeric's avatar
aymeric committed
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
/* Helper function for processing freind names */
static int
lpc_friend_name(char **args, char **name)
{
	/* Use space as a terminator unless quoted */
	if (('"' == **args) || ('\'' == **args)){
		char *end;
		char delim = **args;
		(*args)++;
		end = (*args);
		while ((delim != *end) && ('\0' != *end)) end++;
		if ('\0' == *end) {
			fprintf(stderr, "Mismatched quotes\n");
			return 0;
		}
		*name = *args;
		*end = '\0';
		*args = ++end;
	} else {
		*name = strsep(args, " ");
		
		if (NULL == *args) { /* Means there was no separator */
			fprintf(stderr, "Either name or address is missing\n");
			return 0;
		}
		if (NULL == *name) return 0;
	}
	return 1;
}
smorlat's avatar
smorlat committed
933
#endif
aymeric's avatar
aymeric committed
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953

static int
lpc_cmd_friend(LinphoneCore *lc, char *args)
{
	int friend_num;

	if ( args ) args=lpc_strip_blanks(args);

	if ( ! args || ! *args ) return 0;

	if ( !strncmp(args, "list", 4) )
	{
		return linphonec_friend_list(lc, args+4);
		return 1;
	}
	else if ( !strncmp(args, "call", 4) )
	{
		args+=4;
		if ( ! *args ) return 0;
		friend_num = strtol(args, NULL, 10);
Jehan Monnier's avatar
Jehan Monnier committed
954
#ifndef _WIN32_WCE		
aymeric's avatar
aymeric committed
955
		if ( errno == ERANGE ) {
956
			linphonec_out("Invalid friend number\n");
aymeric's avatar
aymeric committed
957 958
			return 0;
		}
Jehan Monnier's avatar
Jehan Monnier committed
959
#endif /*_WIN32_WCE*/
aymeric's avatar
aymeric committed
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
		linphonec_friend_call(lc, friend_num);
		return 1;
	}
	else if ( !strncmp(args, "delete", 6) )
	{
		args+=6;
		if ( ! *args ) return 0;
		while (*args == ' ') args++;
		if ( ! *args ) return 0;
		if (!strncmp(args, "all", 3))
		{
			friend_num = -1;
		} 
		else
		{
			friend_num = strtol(args, NULL, 10);
Jehan Monnier's avatar
Jehan Monnier committed
976
#ifndef _WIN32_WCE		
aymeric's avatar
aymeric committed
977
			if ( errno == ERANGE ) {
978
				linphonec_out("Invalid friend number\n");
aymeric's avatar
aymeric committed
979 980
				return 0;
			}
Jehan Monnier's avatar
Jehan Monnier committed
981
#endif /*_WIN32_WCE*/
aymeric's avatar
aymeric committed
982 983 984 985 986 987
		}
		linphonec_friend_delete(lc, friend_num);
		return 1;
	}
	else if ( !strncmp(args, "add", 3) )
	{
smorlat's avatar
smorlat committed
988
#ifndef WIN32
aymeric's avatar
aymeric committed
989 990 991 992 993 994 995 996 997
		char  *name;
		char  addr[80];
		char *addr_p = addr;
		char *addr_orig;

		args+=3;
		if ( ! *args ) return 0;
		while (*args == ' ') args++;
		if ( ! *args ) return 0;
smorlat's avatar
smorlat committed
998

aymeric's avatar
aymeric committed
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
		if (!lpc_friend_name(&args,  &name)) return 0;

		while (*args == ' ') args++;
		if ( ! *args ) return 0;
		if (isdigit(*args)) {
			strcpy (addr, "sip:");
			addr_p = addr + strlen("sip:");
		}
		addr_orig = strsep(&args, " ");
		if (1 >= strlen(addr_orig)) {
			fprintf(stderr, "A single-digit address is not valid\n");
			return 0;
		}
		strcpy(addr_p, addr_orig);
		linphonec_friend_add(lc, name, addr);
smorlat's avatar
smorlat committed
1014 1015 1016 1017 1018
#else
		LinphoneFriend *new_friend;
		new_friend = linphone_friend_new_with_addr(args);
		linphone_core_add_friend(lc, new_friend);
#endif
aymeric's avatar
aymeric committed
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
		return 1;
	}
	return 0;
}

static int lpc_cmd_play(LinphoneCore *lc, char *args){
	if ( args ) args=lpc_strip_blanks(args);
	if ( ! args || ! *args ) return 0;
	linphone_core_set_play_file(lc,args);
	return 1;
}

static int lpc_cmd_record(LinphoneCore *lc, char *args){
	if ( args ) args=lpc_strip_blanks(args);
	if ( ! args || ! *args ) return 0;
	linphone_core_set_record_file(lc,args);
	return 1;
}

/*
 * Modified input
 */
static int
lpc_cmd_proxy(LinphoneCore *lc, char *args)
{
	char *arg1 = args;
	char *arg2 = NULL;
	char *ptr = args;
	int proxynum;

	if ( ! arg1 ) return 0;

	/* Isolate first and second arg */
	while(*ptr && !isspace(*ptr)) ++ptr;
	if ( *ptr )
	{
		*ptr='\0';
		arg2=ptr+1;
		while(*arg2 && isspace(*arg2)) ++arg2;
	}

	if (strcmp(arg1,"add")==0)
	{
1062
#ifdef HAVE_READLINE
aymeric's avatar
aymeric committed
1063
		rl_inhibit_completion=1;
1064
#endif
aymeric's avatar
aymeric committed
1065
		linphonec_proxy_add(lc);
1066
#ifdef HAVE_READLINE
aymeric's avatar
aymeric committed
1067
		rl_inhibit_completion=0;
1068
#endif
aymeric's avatar
aymeric committed
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
	}
	else if (strcmp(arg1,"list")==0)
	{
		linphonec_proxy_list(lc);
	}
	else if (strcmp(arg1,"remove")==0)
	{
		linphonec_proxy_remove(lc,atoi(arg2));
	}
	else if (strcmp(arg1,"use")==0)
	{
		if ( arg2 && *arg2 )
		{
			proxynum=atoi(arg2);
			if ( linphonec_proxy_use(lc, proxynum) )
1084
				linphonec_out("Default proxy set to %d.\n", proxynum);
aymeric's avatar
aymeric committed
1085 1086 1087 1088
		}
		else
		{
			proxynum=linphone_core_get_default_proxy(lc, NULL);
1089 1090
			if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
			else linphonec_out("Current default proxy is %d.\n", proxynum);
aymeric's avatar
aymeric committed
1091
		}
smorlat's avatar
smorlat committed
1092
	}else if (strcmp(arg1, "unuse")==0){
aymeric's avatar
aymeric committed
1093
		linphone_core_set_default_proxy(lc, NULL);
1094
		linphonec_out("Use no proxy.\n");
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
	}

	else if (strcmp(arg1, "show")==0)
	{
		if (arg2 && *arg2)
		{
			if (strstr(arg2,"default"))
			{
		proxynum=linphone_core_get_default_proxy(lc, NULL);
		if ( proxynum < 0 ) {
			linphonec_out("No default proxy defined\n");
			return 1;
smorlat's avatar
smorlat committed
1107
		}
1108 1109 1110 1111 1112 1113 1114
		linphonec_proxy_show(lc,proxynum);
			}
			else
			{
		linphonec_proxy_show(lc, atoi(arg2));
			}
		}
1115
		else return 0; /* syntax error */
1116 1117 1118
	}

	else
aymeric's avatar
aymeric committed
1119
	{
1120
		return 0; /* syntax error */
aymeric's avatar
aymeric committed
1121 1122 1123 1124 1125