commands.c 69.7 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 63 64
static int lpc_cmd_terminate(LinphoneCore *, char *);
static int lpc_cmd_call_logs(LinphoneCore *, char *);
static int lpc_cmd_ipv6(LinphoneCore *, char *);
65
static int lpc_cmd_transfer(LinphoneCore *, char *);
aymeric's avatar
aymeric committed
66 67 68 69 70 71
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 *);
72 73
static int lpc_cmd_webcam(LinphoneCore *, char *);
static int lpc_cmd_staticpic(LinphoneCore *, char *);
aymeric's avatar
aymeric committed
74 75
static int lpc_cmd_play(LinphoneCore *, char *);
static int lpc_cmd_record(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
76
static int lpc_cmd_register(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
77
static int lpc_cmd_unregister(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
78
static int lpc_cmd_duration(LinphoneCore *lc, char *args);
smorlat's avatar
smorlat committed
79
static int lpc_cmd_status(LinphoneCore *lc, char *args);
80
static int lpc_cmd_ports(LinphoneCore *lc, char *args);
81
static int lpc_cmd_speak(LinphoneCore *lc, char *args);
82 83 84
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);
85
static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args);
86
static int lpc_cmd_echolimiter(LinphoneCore *lc, char *args);
87 88
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
89 90 91
static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args);
static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args);
static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args);
Simon Morlat's avatar
Simon Morlat committed
92
#ifdef VIDEO_ENABLED
93
static int lpc_cmd_camera(LinphoneCore *lc, char *args);
94
static int lpc_cmd_video_window(LinphoneCore *lc, char *args);
95
static int lpc_cmd_preview_window(LinphoneCore *lc, char *args);
96
static int lpc_cmd_snapshot(LinphoneCore *lc, char *args);
Simon Morlat's avatar
Simon Morlat committed
97
#endif
98
static int lpc_cmd_states(LinphoneCore *lc, char *args);
99
static int lpc_cmd_identify(LinphoneCore *lc, char *args);
100
static int lpc_cmd_ringback(LinphoneCore *lc, char *args);
smorlat's avatar
smorlat committed
101

aymeric's avatar
aymeric committed
102 103 104 105 106 107
/* 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
108
static void linphonec_proxy_show(LinphoneCore *lc,int index);
aymeric's avatar
aymeric committed
109 110 111 112
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);
113
#ifndef WIN32
aymeric's avatar
aymeric committed
114
static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
115
#endif
aymeric's avatar
aymeric committed
116
static int linphonec_friend_delete(LinphoneCore *lc, int num);
117
static int linphonec_friend_delete(LinphoneCore *lc, int num);
118 119 120
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);
aymeric's avatar
aymeric committed
121

smorlat's avatar
smorlat committed
122 123


aymeric's avatar
aymeric committed
124 125 126
/* Command table management */
static LPC_COMMAND *lpc_find_command(const char *name);

127 128
void linphonec_out(const char *fmt,...);

129
VideoParams lpc_video_params={-1,-1,-1,-1,0,TRUE};
130
VideoParams lpc_preview_params={-1,-1,-1,-1,0,TRUE};
131

aymeric's avatar
aymeric committed
132 133 134 135 136 137 138 139 140
/***************************************************************************
 *
 *  Global variables
 *
 ***************************************************************************/

/*
 * Commands table.
 */
141
static LPC_COMMAND commands[] = {
142
	{ "help", lpc_cmd_help, "Print commands help.",
143 144 145
		"'help <command>'\t: displays specific help for command.\n"
		"'help advanced'\t: shows advanced commands.\n"
	},
146 147
	{ "call", lpc_cmd_call, "Call a SIP uri or number",
#ifdef VIDEO_ENABLED
148 149 150 151
		"'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"
152 153 154
#else
		"'call <sip-url or number>' \t: initiate a call to the specified destination.\n"
#endif
155
		},
156
	{ "calls", lpc_cmd_calls, "Show all the current calls with their id and status.",
157
		NULL
aymeric's avatar
aymeric committed
158
		},
Simon Morlat's avatar
Simon Morlat committed
159 160 161 162
	{ "chat", lpc_cmd_chat, "Chat with a SIP uri",
		"'chat <sip-url> \"message\"' "
		": send a chat message \"message\" to the specified destination."
		},
163 164
	{ "terminate", lpc_cmd_terminate, "Terminate a call",
		"'terminate' : Terminate the current call\n"
165
		"'terminate <call id>' : Terminate the call with supplied id\n"
166 167
		"'terminate <all>' : Terminate all the current calls\n"
		},
aymeric's avatar
aymeric committed
168
	{ "answer", lpc_cmd_answer, "Answer a call",
169
		"'answer' : Answer the current incoming call\n"
170
		"'answer <call id>' : Answer the call with given id\n"
aymeric's avatar
aymeric committed
171
	},
172 173 174 175 176
	{ "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"},
177 178 179 180 181 182
	{ "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"
	},
183 184
	{ "mute", lpc_cmd_mute_mic, 
	  "Mute microphone and suspend voice transmission."},
185 186 187 188 189
#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
190 191 192 193
	{ "unmute", lpc_cmd_unmute_mic, 
		  "Unmute microphone and resume voice transmission."},
	{ "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
	
194 195
	{ "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
		"'autoanswer'       \t: show current autoanswer mode\n"
smorlat's avatar
smorlat committed
196 197
		"'autoanswer enable'\t: enable autoanswer mode\n"
		"'autoanswer disable'\t: disable autoanswer mode \n"},
aymeric's avatar
aymeric committed
198 199 200 201 202
	{ "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"
203
		"'proxy unuse' : don't use a default proxy.\n"
smorlat's avatar
smorlat committed
204 205
		"'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
206 207 208
	},
	{ "soundcard", lpc_cmd_soundcard, "Manage soundcards",
		"'soundcard list' : list all sound devices.\n"
209
		"'soundcard show' : show current sound devices configuration.\n"
aymeric's avatar
aymeric committed
210 211 212
		"'soundcard use <index>' : select a sound device.\n"
		"'soundcard use files' : use .wav files instead of soundcard\n"
	},
213 214 215 216
	{ "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
217 218 219 220 221 222 223 224 225 226 227
	{ "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
228
		"'stun <addr>' : set stun server address.\n"
aymeric's avatar
aymeric committed
229
	},
strk's avatar
strk committed
230
	{ "firewall", lpc_cmd_firewall, "Set firewall policy",
aymeric's avatar
aymeric committed
231 232 233
		"'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
234
		"'firewall stun'   : use stun server given with the 'stun' command.\n"
aymeric's avatar
aymeric committed
235
	},
236
	{ "call-logs", lpc_cmd_call_logs, "Calls history", NULL },
aymeric's avatar
aymeric committed
237 238 239 240 241 242 243 244
	{ "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"
	},
245 246 247 248
	{ "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
249 250 251 252 253 254 255
		"'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 },
256 257 258 259 260 261
	{ (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
};


static LPC_COMMAND advanced_commands[] = {
	 { "codec", lpc_cmd_acodec, "Audio codec configuration",
262 263 264 265 266 267 268
            "'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" },
269 270 271 272
	{ "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" },
273 274 275 276
	{ "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
277
	{ "nortp-on-audio-mute", lpc_cmd_rtp_no_xmit_on_audio_mute,
278 279 280
		  "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
281
#ifdef VIDEO_ENABLED
282 283 284 285
	{ "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"
286 287 288 289 290 291 292 293 294 295 296
		"'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."
297
	},
298 299 300
	{ "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"
	},
Simon Morlat's avatar
Simon Morlat committed
301
#endif
302 303 304 305 306
	{ "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"
	},
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
	{ "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" },
	{ "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"
	},
325 326 327 328
	{ "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"
	},
329 330 331 332
	{ "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"
	},
333
	{	NULL,NULL,NULL,NULL}
aymeric's avatar
aymeric committed
334 335
};

336 337


aymeric's avatar
aymeric committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
/***************************************************************************
 *
 *  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);
373
			linphone_core_play_dtmf (lc,*cl,100);
smorlat's avatar
smorlat committed
374
			ms_sleep(1); // be nice
aymeric's avatar
aymeric committed
375 376 377 378 379 380 381 382 383 384 385
			++cl;
		}

		// discard spurious trailing chars
		return 1;
	}

	/* Handle other kind of commands */
	cmd=lpc_find_command(cl);
	if ( !cmd )
	{
386
		linphonec_out("'%s': Cannot understand this.\n", cl);
aymeric's avatar
aymeric committed
387 388 389 390 391
		return 1;
	}

	if ( ! cmd->func(lc, args) )
	{
392
		linphonec_out("Syntax error.\n");
aymeric's avatar
aymeric committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
		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)
{
408
	static int index, len, adv;
aymeric's avatar
aymeric committed
409 410 411 412 413
	char *name;

	if ( ! state )
	{
		index=0;
414
		adv=0;
aymeric's avatar
aymeric committed
415 416 417 418 419 420
		len=strlen(text);
	}
	/*
 	 * Return the next name which partially matches
	 * from the commands list
	 */
421 422
	if (adv==0){
		while ((name=commands[index].name))
aymeric's avatar
aymeric committed
423
		{
424 425 426 427 428 429
			++index; /* so next call get next command */

			if (strncmp(name, text, len) == 0)
			{
				return ortp_strdup(name);
			}
aymeric's avatar
aymeric committed
430
		}
431 432
		adv=1;
		index=0;
aymeric's avatar
aymeric committed
433
	}
434 435 436 437
	if (adv==1){
		while ((name=advanced_commands[index].name))
		{
			++index; /* so next call get next command */
aymeric's avatar
aymeric committed
438

439 440 441 442 443 444
			if (strncmp(name, text, len) == 0)
			{
				return ortp_strdup(name);
			}
		}
	}
aymeric's avatar
aymeric committed
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
	return NULL;
}


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

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

	if (!arg || !*arg)
	{
463 464
		linphonec_out("Commands are:\n");
		linphonec_out("---------------------------\n");
aymeric's avatar
aymeric committed
465 466 467

		while (commands[i].help)
		{
468
			linphonec_out("%10.10s\t%s\n", commands[i].name,
aymeric's avatar
aymeric committed
469 470 471 472
				commands[i].help);
			i++;
		}
		
473
		linphonec_out("---------------------------\n");
474
		linphonec_out("Type 'help <command>' for more details or 'help advanced' to list additional commands.\n");
aymeric's avatar
aymeric committed
475 476 477 478

		return 1;
	}

479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
	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
496 497 498
	cmd=lpc_find_command(arg);
	if ( !cmd )
	{
499
		linphonec_out("No such command.\n");
aymeric's avatar
aymeric committed
500 501 502 503 504 505 506 507
		return 1;
	}

	linphonec_display_command_help(cmd);
	return 1;

}

smorlat's avatar
smorlat committed
508
static char callee_name[256]={0};
509
static char caller_name[256]={0};
smorlat's avatar
smorlat committed
510

511 512 513 514 515 516 517 518 519
static const char *get_call_status(LinphoneCall *call){
	switch(linphone_call_get_state(call)){
		case LinphoneCallPaused:
			if (linphone_call_get_refer_to (call)!=NULL){
				return "Paused (transfered)";
			}else{
				return "Paused";
			}
		break;
Simon Morlat's avatar
Simon Morlat committed
520 521 522
		case LinphoneCallPausedByRemote:
			return "Paused by remote";
		break;
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
		case LinphoneCallIncomingReceived:
			return "Pending";
		break;
		case LinphoneCallOutgoingInit:
		case LinphoneCallOutgoingProgress:
			return "Dialing out";
		break;
		case LinphoneCallOutgoingEarlyMedia:
		case LinphoneCallOutgoingRinging:
			return "Remote ringing";
		break;
		default:
			if (linphone_call_has_transfer_pending(call)){
				return "Running (transfer pending)";
			}else
				return "Running";
	}
	return "";
}

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

582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
static int 
lpc_cmd_calls(LinphoneCore *lc, char *args){
	const MSList *calls = linphone_core_get_calls(lc);
	if(calls)
	{
		const MSList *p_calls = calls;
		linphonec_out("ID\t\tDestination\t\t\t\tStatus\n---------------------------------------------------------------------\n");
		while(p_calls != NULL)			
		{
			LinphoneCall *call=(LinphoneCall*)p_calls->data;
			char *tmp=linphone_call_get_remote_address_as_string(call);
			linphonec_out("%li\t%s\t\t\t%s\r\n",
						  (long)linphone_call_get_user_pointer (call),
					tmp,
					get_call_status(call));
			p_calls = p_calls->next;
			ms_free(tmp);
		}
	}else
	{
		linphonec_out("No active call.\n");
	}
	return 1;
}


Simon Morlat's avatar
Simon Morlat committed
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
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;
}

637
const char *linphonec_get_callee(){
smorlat's avatar
smorlat committed
638 639 640
	return callee_name;
}

641 642 643 644 645 646 647 648
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
649
static int
650
lpc_cmd_transfer(LinphoneCore *lc, char *args)
aymeric's avatar
aymeric committed
651
{
652 653
	if (args){
		LinphoneCall *call;
654
		LinphoneCall *call2;
655 656 657
		const char *refer_to=NULL;
		char arg1[256]={0};
		char arg2[266]={0};
658 659
		long id2=0;
		int n=sscanf(args,"%s %s %li",arg1,arg2,&id2);
660 661
		if (n==1 || isalpha(*arg1)){
			call=linphone_core_get_current_call(lc);
662
			if (call==NULL && ms_list_size(linphone_core_get_calls(lc))==1){
663 664 665 666 667 668 669
				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;
			}
670 671
			linphone_core_transfer_call(lc, call, refer_to);
		}else if (n==2){
672 673 674 675
			long id=atoi(arg1);
			refer_to=args+strlen(arg1)+1;
			call=linphonec_get_call(id);
			if (call==NULL) return 0;
676 677 678 679 680 681 682 683 684 685 686 687
			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;
688 689 690
	}else{
		linphonec_out("Transfer command requires at least one argument\n");
		return 0;
aymeric's avatar
aymeric committed
691 692 693 694 695 696 697
	}
	return 1;
}

static int
lpc_cmd_terminate(LinphoneCore *lc, char *args)
{
698
	if (linphone_core_get_calls(lc)==NULL){
699
		linphonec_out("No active calls\n");
700 701
		return 1;
	}
702
	if (!args)
aymeric's avatar
aymeric committed
703
	{
704 705
		if ( -1 == linphone_core_terminate_call(lc, NULL) ){
			linphonec_out("Could not stop the active call.\n");
706 707
		}
		return 1;
aymeric's avatar
aymeric committed
708
	}
709
	
710 711 712 713 714 715 716 717 718 719
	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){
720
				linphonec_out("Could not stop the call with id %li\n",id);
721
			}
722 723
		}else return 0;
		return 1;
724 725 726
	}
	return 0;
	
aymeric's avatar
aymeric committed
727 728 729
}

static int
730
lpc_cmd_answer(LinphoneCore *lc, char *args){
731
	if (!args)
aymeric's avatar
aymeric committed
732
	{
733 734 735 736
		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) )
737
			{
738
				linphonec_out("Fail to accept incoming call\n");
739
			}
740 741 742 743 744
		}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;
745
		}
746 747 748 749 750 751 752 753 754 755
		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;
756 757
	}
	return 0;
aymeric's avatar
aymeric committed
758 759
}

smorlat's avatar
smorlat committed
760 761 762
static int
lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
{
763 764 765 766 767 768 769 770 771 772
	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
773 774
	if (strstr(args,"enable")){
		linphonec_set_autoanswer(TRUE);
smorlat's avatar
smorlat committed
775
		linphonec_out("Auto answer enabled.\n");
smorlat's avatar
smorlat committed
776 777
	}else if (strstr(args,"disable")){
		linphonec_set_autoanswer(FALSE);
smorlat's avatar
smorlat committed
778
		linphonec_out("Auto answer disabled.\n");
smorlat's avatar
smorlat committed
779 780 781 782
	}else return 0;
	return 1;
}

aymeric's avatar
aymeric committed
783 784 785
static int
lpc_cmd_quit(LinphoneCore *lc, char *args)
{
smorlat's avatar
smorlat committed
786
	linphonec_main_loop_exit();
aymeric's avatar
aymeric committed
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
	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
805
	use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress;
806
	linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
aymeric's avatar
aymeric committed
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825

	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
826
	use = linphone_core_get_firewall_policy(lc)==LinphonePolicyUseStun;
827
	linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
aymeric's avatar
aymeric committed
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842

	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
843
			linphone_core_set_firewall_policy(lc,LinphonePolicyNoFirewall);
aymeric's avatar
aymeric committed
844 845 846 847 848 849
		}
		else if (strcmp(args,"stun")==0)
		{
			setting = linphone_core_get_stun_server(lc);
			if ( ! setting )
			{
850
				linphonec_out("No stun server address is defined, use 'stun <address>' first\n");
aymeric's avatar
aymeric committed
851 852
				return 1;
			}
Simon Morlat's avatar
Simon Morlat committed
853
			linphone_core_set_firewall_policy(lc,LinphonePolicyUseStun);
aymeric's avatar
aymeric committed
854 855 856 857 858 859
		}
		else if (strcmp(args,"nat")==0)
		{
			setting = linphone_core_get_nat_address(lc);
			if ( ! setting )
			{
860
				linphonec_out("No nat address is defined, use 'nat <address>' first");
aymeric's avatar
aymeric committed
861 862
				return 1;
			}
Simon Morlat's avatar
Simon Morlat committed
863
			linphone_core_set_firewall_policy(lc,LinphonePolicyUseNatAddress);
aymeric's avatar
aymeric committed
864 865 866 867 868
		}
	}

	switch(linphone_core_get_firewall_policy(lc))
	{
Simon Morlat's avatar
Simon Morlat committed
869
		case LinphonePolicyNoFirewall:
870
			linphonec_out("No firewall\n");
aymeric's avatar
aymeric committed
871
			break;
Simon Morlat's avatar
Simon Morlat committed
872
		case LinphonePolicyUseStun:
873
			linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
aymeric's avatar
aymeric committed
874
			break;
Simon Morlat's avatar
Simon Morlat committed
875
		case LinphonePolicyUseNatAddress:
876
			linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
aymeric's avatar
aymeric committed
877 878 879 880 881
			break;
	}
	return 1;
}

smorlat's avatar
smorlat committed
882
#ifndef WIN32
aymeric's avatar
aymeric committed
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
/* 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
912
#endif
aymeric's avatar
aymeric committed
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932

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
933
#ifndef _WIN32_WCE		
aymeric's avatar
aymeric committed
934
		if ( errno == ERANGE ) {
935
			linphonec_out("Invalid friend number\n");
aymeric's avatar
aymeric committed
936 937
			return 0;
		}
Jehan Monnier's avatar
Jehan Monnier committed
938
#endif /*_WIN32_WCE*/
aymeric's avatar
aymeric committed
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
		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
955
#ifndef _WIN32_WCE		
aymeric's avatar
aymeric committed
956
			if ( errno == ERANGE ) {
957
				linphonec_out("Invalid friend number\n");
aymeric's avatar
aymeric committed
958 959
				return 0;
			}
Jehan Monnier's avatar
Jehan Monnier committed
960
#endif /*_WIN32_WCE*/
aymeric's avatar
aymeric committed
961 962 963 964 965 966
		}
		linphonec_friend_delete(lc, friend_num);
		return 1;
	}
	else if ( !strncmp(args, "add", 3) )
	{
smorlat's avatar
smorlat committed
967
#ifndef WIN32
aymeric's avatar
aymeric committed
968 969 970 971 972 973 974 975 976
		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
977

aymeric's avatar
aymeric committed
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
		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
993 994 995 996 997
#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
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
		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)
	{
1041
#ifdef HAVE_READLINE
aymeric's avatar
aymeric committed
1042
		rl_inhibit_completion=1;
1043
#endif
aymeric's avatar
aymeric committed
1044
		linphonec_proxy_add(lc);
1045
#ifdef HAVE_READLINE
aymeric's avatar
aymeric committed
1046
		rl_inhibit_completion=0;
1047
#endif
aymeric's avatar
aymeric committed
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
	}
	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) )
1063
				linphonec_out("Default proxy set to %d.\n", proxynum);
aymeric's avatar
aymeric committed
1064 1065 1066 1067
		}
		else
		{
			proxynum=linphone_core_get_default_proxy(lc, NULL);
1068 1069
			if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
			else linphonec_out("Current default proxy is %d.\n", proxynum);
aymeric's avatar
aymeric committed
1070
		}
smorlat's avatar
smorlat committed
1071
	}else if (strcmp(arg1, "unuse")==0){
aymeric's avatar
aymeric committed
1072
		linphone_core_set_default_proxy(lc, NULL);
1073
		linphonec_out("Use no proxy.\n");
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
	}

	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
1086
		}
1087 1088 1089 1090 1091 1092 1093
		linphonec_proxy_show(lc,proxynum);
			}
			else
			{
		linphonec_proxy_show(lc, atoi(arg2));
			}
		}
1094
		else return 0; /* syntax error */
1095 1096 1097
	}

	else
aymeric's avatar
aymeric committed
1098
	{
1099
		return 0; /* syntax error */
aymeric's avatar
aymeric committed
1100 1101 1102 1103 1104 1105 1106 1107
	}

	return 1;
}

static int
lpc_cmd_call_logs(LinphoneCore *lc, char *args)
{
smorlat's avatar
smorlat committed
1108
	const MSList *elem=linphone_core_get_call_logs(lc);
aymeric's avatar
aymeric committed
1109 1110 1111 1112
	for (;elem!=NULL;elem=ms_list_next(elem))
	{
		LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
		char *str=linphone_call_log_to_str(cl);
1113
		linphonec_out("%s\n",str);
aymeric's avatar
aymeric committed
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
		ms_free(str);
	}
	return 1;
}

static int
lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
{
	if ( ! arg1 )
	{
1124
		return 0; /* syntax error */
aymeric's avatar
aymeric committed
1125 1126 1127 1128
	}

	if (strcmp(arg1,"status")==0)
	{
1129
		linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
aymeric's avatar
aymeric committed
1130 1131 1132 1133
	}
	else if (strcmp(arg1,"enable")==0)
	{
		linphone_core_enable_ipv6(lc,TRUE);
1134
		linphonec_out("ipv6 use enabled.\n");
aymeric's avatar
aymeric committed
1135 1136 1137 1138
	}
	else if (strcmp(arg1,"disable")==0)
	{
		linphone_core_enable_ipv6(lc,FALSE);
1139
		linphonec_out("ipv6 use disabled.\n");
aymeric's avatar
aymeric committed
1140 1141 1142
	}
	else
	{
1143
		return 0; /* syntax error */
aymeric's avatar
aymeric committed
1144 1145 1146 1147
	}
	return 1;
}

1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
static int devname_to_index(LinphoneCore *lc, const char *devname){
	const char **p;
	int i;
	for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
		if (strcmp(devname,*p)==0) return i;
	}
	return -1;
}

static const char *index_to_devname(LinphoneCore *lc, int index){
	const char **p;
	int i;
	for(i=0,p=linphone_core_get_sound_devices(lc);*p!=NULL;++p,++i){
		if (i==index) return *p;
	}
	return NULL;
}