commands.c 35.2 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4 5 6 7
/****************************************************************************
 *
 *  $Id: commands.c,v 1.39 2008/07/03 15:08:34 smorlat Exp $
 *
 *  Copyright (C) 2006  Sandro Santilli <strk@keybit.net>
 *  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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 *
 ****************************************************************************/

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <ctype.h>
#include <unistd.h>
#include <linphonecore.h>
#include "linphonec.h"

/***************************************************************************
 *
 *  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 *);
static int lpc_cmd_answer(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
49
static int lpc_cmd_autoanswer(LinphoneCore *, char *);
aymeric's avatar
aymeric committed
50 51 52 53 54 55 56 57 58 59 60 61
static int lpc_cmd_terminate(LinphoneCore *, char *);
static int lpc_cmd_call_logs(LinphoneCore *, char *);
static int lpc_cmd_ipv6(LinphoneCore *, char *);
static int lpc_cmd_refer(LinphoneCore *, char *);
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 *);
static int lpc_cmd_play(LinphoneCore *, char *);
static int lpc_cmd_record(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
62
static int lpc_cmd_register(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
63
static int lpc_cmd_unregister(LinphoneCore *, char *);
smorlat's avatar
smorlat committed
64
static int lpc_cmd_duration(LinphoneCore *lc, char *args);
smorlat's avatar
smorlat committed
65
static int lpc_cmd_status(LinphoneCore *lc, char *args);
smorlat's avatar
smorlat committed
66

aymeric's avatar
aymeric committed
67 68 69 70 71 72
/* 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
73
static void linphonec_proxy_show(LinphoneCore *lc,int index);
aymeric's avatar
aymeric committed
74 75 76 77 78 79 80
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);
static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr);
static int linphonec_friend_delete(LinphoneCore *lc, int num);

smorlat's avatar
smorlat committed
81 82


aymeric's avatar
aymeric committed
83 84 85
/* Command table management */
static LPC_COMMAND *lpc_find_command(const char *name);

86 87 88 89
void linphonec_out(const char *fmt,...);



aymeric's avatar
aymeric committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
/***************************************************************************
 *
 *  Global variables
 *
 ***************************************************************************/

/*
 * Commands table.
 */
LPC_COMMAND commands[] = {
	{ "help", lpc_cmd_help, "Print commands help", NULL },
	{ "call", lpc_cmd_call, "Call a SIP uri",
		"'call <sip-url>' or 'c <sip-url>' "
		": initiate a call to the specified destination."
		},
	{ "terminate", lpc_cmd_terminate, "Terminate the current call",
		NULL },
	{ "answer", lpc_cmd_answer, "Answer a call",
		"Accept an incoming call."
	},
smorlat's avatar
smorlat committed
110 111 112
	{ "autoanswer", lpc_cmd_autoanswer, "Enable auto-answer mode",
		"'autoanswer enable'\t: enable autoanswer mode\n"
		"'autoanswer disable'\t: disable autoanswer mode \n"},
aymeric's avatar
aymeric committed
113 114 115 116 117 118
	{ "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"
		"'proxy unuse' : don't use a default proxy."
smorlat's avatar
smorlat committed
119 120
		"'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
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
	},
	{ "soundcard", lpc_cmd_soundcard, "Manage soundcards",
		"'soundcard list' : list all sound devices.\n"
		"'soundcard use <index>' : select a sound device.\n"
		"'soundcard use files' : use .wav files instead of soundcard\n"
	},
	{ "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."
	},
	{ "refer", lpc_cmd_refer,
		"Refer the current call to the specified destination.",
		"'refer <sip-url>' or 'r <sip-url>' "
		": refer the current call to the specified destination."
	},
	{ "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"
		"'stun <addr>' : set stun address.\n"
	},
	{ "firewall", lpc_cmd_firewall, "Set ",
		"'firewall'        : show current firewall policy.\n"
		"'firewall none'   : use direct connection.\n"
		"'firewall nat'    : use nat address given with the 'nat' command.\n"
		"'firewall stun'   : use stun server given with the 'server' command.\n"
	},
        { "call-logs", lpc_cmd_call_logs, "Calls history",
                NULL },
	{ "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"
	},
	{ "play", lpc_cmd_play, "play from a wav file",
		"This feature is available only in file mode (see 'help soundcard')\n"
		"'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 },
smorlat's avatar
smorlat committed
170
	{ "register", lpc_cmd_register, "Register in one line to a proxy" , "register <sip identity> <sip proxy> <password>"},
smorlat's avatar
smorlat committed
171
	{ "unregister", lpc_cmd_unregister, "Unregister from default proxy", NULL	},
smorlat's avatar
smorlat committed
172
	{ "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
smorlat's avatar
smorlat committed
173 174 175 176 177
	{ "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" },
					
aymeric's avatar
aymeric committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
	{ (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
};

/***************************************************************************
 *
 *  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);
			sleep(1); // be nice
			++cl;
		}

		// discard spurious trailing chars
		return 1;
	}

	/* Handle other kind of commands */
	cmd=lpc_find_command(cl);
	if ( !cmd )
	{
228
		linphonec_out("'%s': Cannot understand this.\n", cl);
aymeric's avatar
aymeric committed
229 230 231 232 233
		return 1;
	}

	if ( ! cmd->func(lc, args) )
	{
234
		linphonec_out("Syntax error.\n");
aymeric's avatar
aymeric committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
		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)
{
	static int index, len;
	char *name;

	if ( ! state )
	{
		index=0;
		len=strlen(text);
	}

	/*
 	 * Return the next name which partially matches
	 * from the commands list
	 */
	while ((name=commands[index].name))
	{
		++index; /* so next call get next command */

		if (strncmp(name, text, len) == 0)
		{
			return strdup(name);
		}
	}

	return NULL;
}


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

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

	if (!arg || !*arg)
	{
291 292
		linphonec_out("Commands are:\n");
		linphonec_out("---------------------------\n");
aymeric's avatar
aymeric committed
293 294 295

		while (commands[i].help)
		{
296
			linphonec_out("%10.10s\t%s\n", commands[i].name,
aymeric's avatar
aymeric committed
297 298 299 300
				commands[i].help);
			i++;
		}
		
301 302
		linphonec_out("---------------------------\n");
		linphonec_out("Type 'help <command>' for more details.\n");
aymeric's avatar
aymeric committed
303 304 305 306 307 308 309

		return 1;
	}

	cmd=lpc_find_command(arg);
	if ( !cmd )
	{
310
		linphonec_out("No such command.\n");
aymeric's avatar
aymeric committed
311 312 313 314 315 316 317 318
		return 1;
	}

	linphonec_display_command_help(cmd);
	return 1;

}

smorlat's avatar
smorlat committed
319 320
static char callee_name[256]={0};

aymeric's avatar
aymeric committed
321 322 323 324 325 326 327 328 329 330
static int
lpc_cmd_call(LinphoneCore *lc, char *args)
{
	if ( ! args || ! *args )
	{
		return 0;
	}

	if ( lc->call != NULL )
	{
331
		linphonec_out("Terminate current call first.\n");
aymeric's avatar
aymeric committed
332 333 334 335 336
	}
	else
	{
		if ( -1 == linphone_core_invite(lc, args) )
		{
337
			linphonec_out("Error from linphone_core_invite.\n");
aymeric's avatar
aymeric committed
338 339 340
		}
		else
		{
smorlat's avatar
smorlat committed
341
			snprintf(callee_name,sizeof(callee_name),"%s",args);
aymeric's avatar
aymeric committed
342 343 344 345 346
		}
	}
	return 1;
}

smorlat's avatar
smorlat committed
347 348 349 350
static const char *linphonec_get_callee(){
	return callee_name;
}

aymeric's avatar
aymeric committed
351 352 353 354 355 356
static int
lpc_cmd_refer(LinphoneCore *lc, char *args)
{
	if (args)
		linphone_core_refer(lc, args);
	else{
357
		linphonec_out("refer needs an argument\n");
aymeric's avatar
aymeric committed
358 359 360 361 362 363 364 365 366
	}
	return 1;
}

static int
lpc_cmd_terminate(LinphoneCore *lc, char *args)
{
	if ( -1 == linphone_core_terminate_call(lc, NULL) )
	{
367
		linphonec_out("No active call.\n");
aymeric's avatar
aymeric committed
368 369 370 371 372 373 374 375 376
	}
	return 1;
}

static int
lpc_cmd_answer(LinphoneCore *lc, char *args)
{
	if ( -1 == linphone_core_accept_call(lc, NULL) )
	{
377
		linphonec_out("No incoming call.\n");
aymeric's avatar
aymeric committed
378 379 380 381
	}
	return 1;
}

smorlat's avatar
smorlat committed
382 383 384 385 386 387 388 389 390 391 392
static int
lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
{
	if (strstr(args,"enable")){
		linphonec_set_autoanswer(TRUE);
	}else if (strstr(args,"disable")){
		linphonec_set_autoanswer(FALSE);
	}else return 0;
	return 1;
}

aymeric's avatar
aymeric committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
static int
lpc_cmd_quit(LinphoneCore *lc, char *args)
{
	linphonec_finish(EXIT_SUCCESS);
	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);
	use = linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS;
416
	linphonec_out("Nat address: %s%s\n", nat ? nat : "unspecified" , use ? "" : " (disabled - use 'firewall nat' to enable)");
aymeric's avatar
aymeric committed
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436

	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);
	use = linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_STUN;
437
	linphonec_out("Stun server: %s%s\n", stun ? stun : "unspecified" , use? "" : " (disabled - use 'firewall stun' to enable)");
aymeric's avatar
aymeric committed
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459

	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)
		{
			linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_NO_FIREWALL);
		}
		else if (strcmp(args,"stun")==0)
		{
			setting = linphone_core_get_stun_server(lc);
			if ( ! setting )
			{
460
				linphonec_out("No stun server address is defined, use 'stun <address>' first");
aymeric's avatar
aymeric committed
461 462 463 464 465 466 467 468 469
				return 1;
			}
			linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_STUN);
		}
		else if (strcmp(args,"nat")==0)
		{
			setting = linphone_core_get_nat_address(lc);
			if ( ! setting )
			{
470
				linphonec_out("No nat address is defined, use 'nat <address>' first");
aymeric's avatar
aymeric committed
471 472 473 474 475 476 477 478 479
				return 1;
			}
			linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_USE_NAT_ADDRESS);
		}
	}

	switch(linphone_core_get_firewall_policy(lc))
	{
		case LINPHONE_POLICY_NO_FIREWALL:
480
			linphonec_out("No firewall\n");
aymeric's avatar
aymeric committed
481 482
			break;
		case LINPHONE_POLICY_USE_STUN:
483
			linphonec_out("Using stun server %s to discover firewall address\n", setting ? setting : linphone_core_get_stun_server(lc));
aymeric's avatar
aymeric committed
484 485
			break;
		case LINPHONE_POLICY_USE_NAT_ADDRESS:
486
			linphonec_out("Using supplied nat address %s.\n", setting ? setting : linphone_core_get_nat_address(lc));
aymeric's avatar
aymeric committed
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
			break;
	}
	return 1;
}

/* 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;
}

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);
		if ( errno == ERANGE ) {
542
			linphonec_out("Invalid friend number\n");
aymeric's avatar
aymeric committed
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
			return 0;
		}
		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);
			if ( errno == ERANGE ) {
562
				linphonec_out("Invalid friend number\n");
aymeric's avatar
aymeric committed
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 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 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 637
				return 0;
			}
		}
		linphonec_friend_delete(lc, friend_num);
		return 1;
	}
	else if ( !strncmp(args, "add", 3) )
	{
		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;
		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);
		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)
	{
638
#ifdef HAVE_READLINE
aymeric's avatar
aymeric committed
639
		rl_inhibit_completion=1;
640
#endif
aymeric's avatar
aymeric committed
641
		linphonec_proxy_add(lc);
642
#ifdef HAVE_READLINE
aymeric's avatar
aymeric committed
643
		rl_inhibit_completion=0;
644
#endif
aymeric's avatar
aymeric committed
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
	}
	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) )
660
				linphonec_out("Default proxy set to %d.\n", proxynum);
aymeric's avatar
aymeric committed
661 662 663 664
		}
		else
		{
			proxynum=linphone_core_get_default_proxy(lc, NULL);
665 666
			if ( proxynum == -1 ) linphonec_out("No default proxy.\n");
			else linphonec_out("Current default proxy is %d.\n", proxynum);
aymeric's avatar
aymeric committed
667
		}
smorlat's avatar
smorlat committed
668
	}else if (strcmp(arg1, "unuse")==0){
aymeric's avatar
aymeric committed
669
		linphone_core_set_default_proxy(lc, NULL);
670
		linphonec_out("Use no proxy.\n");
smorlat's avatar
smorlat committed
671 672 673 674 675 676 677 678
	}else if (strcmp(arg1,"show")==0){
		if (arg2 && *arg2){
			if (strstr(arg2,"default")==0){
				proxynum=linphone_core_get_default_proxy(lc, NULL);
				linphonec_proxy_show(lc,proxynum);
			}else linphonec_proxy_show(lc,atoi(arg2));
		}
	}else
aymeric's avatar
aymeric committed
679
	{
680
		linphonec_out("Syntax error - see 'help proxy'\n");
aymeric's avatar
aymeric committed
681 682 683 684 685 686 687 688 689 690 691 692 693
	}

	return 1;
}

static int
lpc_cmd_call_logs(LinphoneCore *lc, char *args)
{
	MSList *elem=linphone_core_get_call_logs(lc);
	for (;elem!=NULL;elem=ms_list_next(elem))
	{
		LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
		char *str=linphone_call_log_to_str(cl);
694
		linphonec_out("%s\n",str);
aymeric's avatar
aymeric committed
695 696 697 698 699 700 701 702 703 704
		ms_free(str);
	}
	return 1;
}

static int
lpc_cmd_ipv6(LinphoneCore *lc, char *arg1)
{
	if ( ! arg1 )
	{
705
		linphonec_out("Syntax error - see 'help ipv6'\n");
aymeric's avatar
aymeric committed
706 707 708 709 710
		return 1;
	}

	if (strcmp(arg1,"status")==0)
	{
711
		linphonec_out("ipv6 use enabled: %s\n",linphone_core_ipv6_enabled(lc) ? "true":"false");
aymeric's avatar
aymeric committed
712 713 714 715
	}
	else if (strcmp(arg1,"enable")==0)
	{
		linphone_core_enable_ipv6(lc,TRUE);
716
		linphonec_out("ipv6 use enabled.\n");
aymeric's avatar
aymeric committed
717 718 719 720
	}
	else if (strcmp(arg1,"disable")==0)
	{
		linphone_core_enable_ipv6(lc,FALSE);
721
		linphonec_out("ipv6 use disabled.\n");
aymeric's avatar
aymeric committed
722 723 724
	}
	else
	{
725
		linphonec_out("Syntax error - see 'help ipv6'\n");
aymeric's avatar
aymeric committed
726 727 728 729 730 731 732
	}
	return 1;
}

static int lpc_cmd_soundcard(LinphoneCore *lc, char *cmd){
	int i;
	if (cmd==NULL){
733
		linphonec_out("Syntax error - see 'help soundcard'\n");
aymeric's avatar
aymeric committed
734 735 736 737 738
		return 1;
	}
	if (strcmp(cmd,"list")==0){
		const char **dev=linphone_core_get_sound_devices(lc);
		for(i=0;dev[i]!=NULL;i++){
739
			linphonec_out("%i: %s\n",i,dev[i]);
aymeric's avatar
aymeric committed
740 741 742 743 744 745 746 747 748
		}
		return 1;
	}else{
		char *tmp=alloca(strlen(cmd)+1);
		char *card=alloca(strlen(cmd)+1);
		int index;
		int n=sscanf(cmd,"%s %s",tmp,card);
		if (n==2 && strcmp(tmp,"use")==0){
			if (strcmp(card,"files")==0) {
749
				linphonec_out("Using wav files instead of soundcard.\n");
aymeric's avatar
aymeric committed
750 751 752 753 754 755 756 757 758 759
				linphone_core_use_files(lc,TRUE);
				return 1;
			}else{
				const char **dev=linphone_core_get_sound_devices(lc);
				index=atoi(card);
				for(i=0;dev[i]!=NULL;i++){
					if (i==index){
						linphone_core_set_ringer_device(lc,dev[i]);
						linphone_core_set_playback_device(lc,dev[i]);
						linphone_core_set_capture_device(lc,dev[i]);
760
						linphonec_out("Using sound device %s\n",dev[i]);
aymeric's avatar
aymeric committed
761 762 763
						return 1;
					}
				}
764
				linphonec_out("no such sound device\n");
aymeric's avatar
aymeric committed
765 766 767
				return 1;
			}
		}
768
		linphonec_out("Syntax error - see 'help soundcard'\n");
aymeric's avatar
aymeric committed
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
	}
	return 1;
}

/***************************************************************************
 *
 *  Commands helper functions
 *
 ***************************************************************************/


static void
linphonec_proxy_add(LinphoneCore *lc)
{
	bool_t enable_register=FALSE;
	LinphoneProxyConfig *cfg;

786
	linphonec_out("Adding new proxy setup. Hit ^D to abort.\n");
aymeric's avatar
aymeric committed
787 788 789 790 791 792

	/*
	 * SIP Proxy address
	 */
	while (1)
	{
793
		char *input=linphonec_readline("Enter proxy sip address: ");
aymeric's avatar
aymeric committed
794 795 796
		char *clean;

		if ( ! input ) {
797
			linphonec_out("Aborted.\n");
aymeric's avatar
aymeric committed
798 799 800 801 802 803 804 805 806 807 808 809 810
			return;
		}

		/* Strip blanks */
		clean=lpc_strip_blanks(input);
		if ( ! *clean ) {
			free(input);
			continue;
		}

		cfg=linphone_proxy_config_new();
		if (linphone_proxy_config_set_server_addr(cfg,clean)<0)
		{
811
			linphonec_out("Invalid sip address (sip:sip.domain.tld).\n");
aymeric's avatar
aymeric committed
812 813 814 815 816 817 818 819 820 821 822 823 824
			free(input);
			linphone_proxy_config_destroy(cfg);
			continue;
		}
		free(input);
		break;
	}

	/*
	 * SIP Proxy identity
	 */
	while (1)
	{
825
		char *input=linphonec_readline("Your identity for this proxy: ");
aymeric's avatar
aymeric committed
826 827 828
		char *clean;

		if ( ! input ) {
829
			linphonec_out("Aborted.\n");
aymeric's avatar
aymeric committed
830 831 832 833 834 835 836 837 838 839 840 841 842 843
			linphone_proxy_config_destroy(cfg);
			return;
		}

		/* Strip blanks */
		clean=lpc_strip_blanks(input);
		if ( ! *clean ) {
			free(input);
			continue;
		}

		linphone_proxy_config_set_identity(cfg, clean);
		if ( ! cfg->reg_identity )
		{
844
			linphonec_out("Invalid identity (sip:name@sip.domain.tld).\n");
aymeric's avatar
aymeric committed
845 846 847 848 849 850 851 852 853 854 855 856
			free(input);
			continue;
		}
		free(input);
		break;
	}

	/*
	 * SIP Proxy enable register
	 */
	while (1)
	{
857
		char *input=linphonec_readline("Do you want to register on this proxy (yes/no): ");
aymeric's avatar
aymeric committed
858 859 860
		char *clean;

		if ( ! input ) {
861
			linphonec_out("Aborted.\n");
aymeric's avatar
aymeric committed
862 863 864 865 866 867 868 869 870 871 872 873 874 875
			linphone_proxy_config_destroy(cfg);
			return;
		}

		/* Strip blanks */
		clean=lpc_strip_blanks(input);
		if ( ! *clean ) {
			free(input);
			continue;
		}

		if ( ! strcmp(clean, "yes") ) enable_register=TRUE;
		else if ( ! strcmp(clean, "no") ) enable_register=FALSE;
		else {
876
			linphonec_out("Please answer with 'yes' or 'no'\n");
aymeric's avatar
aymeric committed
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
			free(input);
			continue;
		}
		linphone_proxy_config_enableregister(cfg, enable_register);
		free(input);
		break;
	}

	/*
	 * SIP Proxy registration expiration
	 */
	if ( enable_register==TRUE )
	{
		long int expires=0;
		while (1)
		{
893
			char *input=linphonec_readline("Specify register expiration time"
aymeric's avatar
aymeric committed
894 895 896
				" in seconds (default is 600): ");

			if ( ! input ) {
897
				linphonec_out("Aborted.\n");
aymeric's avatar
aymeric committed
898 899 900 901 902 903 904
				linphone_proxy_config_destroy(cfg);
				return;
			}

			expires=strtol(input, (char **)NULL, 10);
			if ( expires == LONG_MIN || expires == LONG_MAX )
			{
905
				linphonec_out("Invalid value: %s\n", strerror(errno));
aymeric's avatar
aymeric committed
906 907 908 909 910
				free(input);
				continue;
			}

			linphone_proxy_config_expires(cfg, expires);
911
			linphonec_out("Expiration: %d seconds\n", cfg->expires);
aymeric's avatar
aymeric committed
912 913 914 915 916 917 918 919 920 921 922

			free(input);
			break;
		}
	}

	/*
	 * SIP proxy route
	 */
	while (1)
	{
923
		char *input=linphonec_readline("Specify route if needed: ");
aymeric's avatar
aymeric committed
924 925 926
		char *clean;

		if ( ! input ) {
927
			linphonec_out("Aborted.\n");
aymeric's avatar
aymeric committed
928 929 930 931 932 933 934 935
			linphone_proxy_config_destroy(cfg);
			return;
		}

		/* Strip blanks */
		clean=lpc_strip_blanks(input);
		if ( ! *clean ) {
			free(input);
936
			linphonec_out("No route specified.\n");
aymeric's avatar
aymeric committed
937 938 939 940 941 942
			break;
		}

		linphone_proxy_config_set_route(cfg, clean);
		if ( ! cfg->reg_route )
		{
943
			linphonec_out("Invalid route.\n");
aymeric's avatar
aymeric committed
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
			free(input);
			continue;
		}

		free(input);
		break;
	}

	/*
	 * Final confirmation 
	 */
	while (1)
	{
		char *input;
		char *clean;

960
		linphonec_out("--------------------------------------------\n");
aymeric's avatar
aymeric committed
961
		linphonec_proxy_display(cfg);
962
		linphonec_out("--------------------------------------------\n");
963
		input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: ");
aymeric's avatar
aymeric committed
964 965 966


		if ( ! input ) {
967
			linphonec_out("Aborted.\n");
aymeric's avatar
aymeric committed
968 969 970 971 972 973 974 975 976 977 978 979 980 981
			linphone_proxy_config_destroy(cfg);
			return;
		}

		/* Strip blanks */
		clean=lpc_strip_blanks(input);
		if ( ! *clean ) {
			free(input);
			continue;
		}

		if ( ! strcmp(clean, "yes") ) break;
		else if ( ! strcmp(clean, "no") )
		{
982
			linphonec_out("Declined.\n");
aymeric's avatar
aymeric committed
983 984 985 986 987
			linphone_proxy_config_destroy(cfg);
			free(input);
			return;
		}

988
		linphonec_out("Please answer with 'yes' or 'no'\n");
aymeric's avatar
aymeric committed
989 990 991 992 993 994 995 996 997 998
		free(input);
		continue;
	}


	linphone_core_add_proxy_config(lc,cfg);

	/* automatically set the last entered proxy as the default one */
	linphone_core_set_default_proxy(lc,cfg);

999
	linphonec_out("Proxy added.\n");
aymeric's avatar
aymeric committed
1000 1001 1002 1003 1004
}

static void
linphonec_proxy_display(LinphoneProxyConfig *cfg)
{
smorlat's avatar
smorlat committed
1005
	linphonec_out("sip address: %s\nroute: %s\nidentity: %s\nregister: %s\nexpires: %i\nregistered: %s\n",
aymeric's avatar
aymeric committed
1006 1007 1008 1009
			cfg->reg_proxy,
			(cfg->reg_route!=NULL)?cfg->reg_route:"",
			(cfg->reg_identity!=NULL)?cfg->reg_identity:"",
			(cfg->reg_sendregister)?"yes":"no",
smorlat's avatar
smorlat committed
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
			cfg->expires,
			linphone_proxy_config_is_registered(cfg) ? "yes" : "no");
}

static void linphonec_proxy_show(LinphoneCore *lc, int index){
	const MSList *elem;
	int i;
	for(elem=linphone_core_get_proxy_config_list(lc),i=0;elem!=NULL;elem=elem->next,++i){
		if (index==i){
			LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)elem->data;
			linphonec_proxy_display(cfg);
			return;
		}
	}
	linphonec_out("No proxy with index %i",index);
aymeric's avatar
aymeric committed
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
}

static void
linphonec_proxy_list(LinphoneCore *lc)
{
	const MSList *proxies;
	int n;
	int def=linphone_core_get_default_proxy(lc,NULL);
	
	proxies=linphone_core_get_proxy_config_list(lc);
	for(n=0;proxies!=NULL;proxies=ms_list_next(proxies),n++){
		if (n==def)
1037
			linphonec_out("****** Proxy %i - this is the default one - *******\n",n);
aymeric's avatar
aymeric committed
1038
		else 
1039
			linphonec_out("****** Proxy %i *******\n",n);
aymeric's avatar
aymeric committed
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
		linphonec_proxy_display((LinphoneProxyConfig*)proxies->data);
	}
}

static void
linphonec_proxy_remove(LinphoneCore *lc, int index)
{
	const MSList *proxies;
	LinphoneProxyConfig *cfg;
	proxies=linphone_core_get_proxy_config_list(lc);
	cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
	if (cfg==NULL){
1052
		linphonec_out("No such proxy.\n");
aymeric's avatar
aymeric committed
1053 1054 1055
		return;
	}
	linphone_core_remove_proxy_config(lc,cfg);
1056
	linphonec_out("Proxy %s removed.\n", cfg->reg_proxy);
aymeric's avatar
aymeric committed
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
	linphone_proxy_config_destroy(cfg);
}

static int
linphonec_proxy_use(LinphoneCore *lc, int index)
{
	const MSList *proxies;
	LinphoneProxyConfig *cfg;
	proxies=linphone_core_get_proxy_config_list(lc);
	cfg=(LinphoneProxyConfig*)ms_list_nth_data(proxies,index);
	if (cfg==NULL){
1068
		linphonec_out("No such proxy (try 'proxy list').");
aymeric's avatar
aymeric committed
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
		return 0;
	}
	linphone_core_set_default_proxy(lc,cfg);
	return 1;
}

static void
linphonec_friend_display(LinphoneFriend *fr)
{
	char *name = linphone_friend_get_name(fr);
	char *addr = linphone_friend_get_addr(fr);
	//char *url = linphone_friend_get_url(fr);

1082 1083
	linphonec_out("name: %s\n", name);
	linphonec_out("address: %s\n", addr);
aymeric's avatar
aymeric committed
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
}

static int
linphonec_friend_list(LinphoneCore *lc, char *pat)
{
	const MSList *friend;
	int n;

	if (pat) {
		pat=lpc_strip_blanks(pat);
		if (!*pat) pat = NULL;
	}

	friend = linphone_core_get_friend_list(lc);
	for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
	{
		if ( pat ) {
			char *name = linphone_friend_get_name(friend->data);
			if ( ! strstr(name, pat) ) continue;
		}
1104
		linphonec_out("****** Friend %i *******\n",n);
aymeric's avatar
aymeric committed
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
		linphonec_friend_display((LinphoneFriend*)friend->data);
	}

	return 1;
}

static int
linphonec_friend_call(LinphoneCore *lc, unsigned int num)
{
	const MSList *friend = linphone_core_get_friend_list(lc);
	unsigned int n;
	char *addr;

	for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
	{
		if ( n == num )
		{
			addr = linphone_friend_get_addr(friend->data);
			return lpc_cmd_call(lc, addr);
		}
	}
1126
	linphonec_out("No such friend %u\n", num);
aymeric's avatar
aymeric committed
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
	return 1;
}

static int
linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr)
{
	LinphoneFriend *newFriend;

	char url[PATH_MAX];

	snprintf(url, PATH_MAX, "%s <%s>", name, addr);
	newFriend = linphone_friend_new_with_addr(url);
	linphone_core_add_friend(lc, newFriend);
	return 0;
}

static int
linphonec_friend_delete(LinphoneCore *lc, int num)
{
	const MSList *friend = linphone_core_get_friend_list(lc);
	unsigned int n;

	for(n=0; friend!=NULL; friend=ms_list_next(friend), ++n )
	{
		if ( n == num )
		{
			linphone_core_remove_friend(lc, friend->data);
			return 0;
		}
	}

	if (-1 == num) 
	{
		unsigned int i;
		for (i = 0 ; i < n ; i++)
			linphonec_friend_delete(lc, 0);
		return 0;
	}

1166
	linphonec_out("No such friend %u\n", num);
aymeric's avatar
aymeric committed
1167 1168 1169 1170 1171 1172
	return 1;
}

static void
linphonec_display_command_help(LPC_COMMAND *cmd)
{
1173 1174
	if ( cmd->doc ) linphonec_out ("%s\n", cmd->doc);
	else linphonec_out("%s\n", cmd->help);
aymeric's avatar
aymeric committed
1175 1176
}

smorlat's avatar
smorlat committed
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210

static int lpc_cmd_register(LinphoneCore *lc, char *args){
	char identity[512];
	char proxy[512];
	char passwd[512];
	LinphoneProxyConfig *cfg;
	const MSList *elem;
	passwd[0]=proxy[0]=identity[0]='\0';
	sscanf(args,"%s %s %s",identity,proxy,passwd);
	if (proxy[0]=='\0' || identity[0]=='\0'){
		linphonec_out("Missing parameters, see help register\n");
		return 1;
	}
	if (passwd[0]!='\0'){
		osip_from_t *from;
		LinphoneAuthInfo *info;
		osip_from_init(&from);
		if (osip_from_parse(from,identity)==0){
			info=linphone_auth_info_new(from->url->username,NULL,passwd,NULL,NULL);
			linphone_core_add_auth_info(lc,info);
		}
		osip_from_free(from);
	}
	elem=linphone_core_get_proxy_config_list(lc);
	if (elem) {
		cfg=(LinphoneProxyConfig*)elem->data;
		linphone_proxy_config_edit(cfg);
	}
	else cfg=linphone_proxy_config_new();
	linphone_proxy_config_set_identity(cfg,identity);
	linphone_proxy_config_set_server_addr(cfg,proxy);
	linphone_proxy_config_enable_register(cfg,TRUE);
	if (elem) linphone_proxy_config_done(cfg);
	else linphone_core_add_proxy_config(lc,cfg);
smorlat's avatar
smorlat committed
1211
	linphone_core_set_default_proxy(lc,cfg);
smorlat's avatar
smorlat committed
1212 1213 1214
	return 1;
}

smorlat's avatar
smorlat committed
1215 1216 1217
static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
	LinphoneProxyConfig *cfg=NULL;
	linphone_core_get_default_proxy(lc,&cfg);
smorlat's avatar
smorlat committed
1218
	if (cfg && linphone_proxy_config_is_registered(cfg)) {
smorlat's avatar
smorlat committed
1219 1220 1221 1222 1223 1224 1225 1226 1227
		linphone_proxy_config_edit(cfg);
		linphone_proxy_config_enable_register(cfg,FALSE);
		linphone_proxy_config_done(cfg);
	}else{
		linphonec_out("unregistered\n");
	}
	return 1;
}

smorlat's avatar
smorlat committed
1228
static int lpc_cmd_duration(LinphoneCore *lc, char *args){
smorlat's avatar
smorlat committed
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239
	LinphoneCallLog *cl;
	const MSList *elem=linphone_core_get_call_logs(lc);
	for(;elem!=NULL;elem=elem->next){
		if (elem->next==NULL){
			cl=(LinphoneCallLog*)elem->data;
			linphonec_out("%i seconds\n",cl->duration);
		}
	}
	return 1;
}

smorlat's avatar
smorlat committed
1240 1241 1242 1243 1244 1245
static int lpc_cmd_status(LinphoneCore *lc, char *args){
	LinphoneProxyConfig *cfg;
	linphone_core_get_default_proxy(lc,&cfg);
	if (strstr(args,"register")){
		if (cfg){
			if (linphone_proxy_config_is_registered(cfg)){
smorlat's avatar
smorlat committed
1246
				linphonec_out("identity=%s duration=%i\n",
smorlat's avatar
smorlat committed
1247 1248 1249
					linphone_proxy_config_get_identity(cfg),
					linphone_proxy_config_get_expires(cfg));
			}else if (linphone_proxy_config_register_enabled(cfg)){
smorlat's avatar
smorlat committed
1250 1251 1252
				linphonec_out("registered=-1\n");
			}else linphonec_out("registered=0\n");
		}else linphonec_out("registered=0\n");
smorlat's avatar
smorlat committed
1253 1254
	}else if (strstr(args,"autoanswer")){
		if (cfg && linphone_proxy_config_is_registered(cfg))
smorlat's avatar
smorlat committed
1255 1256
			linphonec_out("autoanswer=%i\n",linphonec_get_autoanswer());
		else linphonec_out("unregistered\n");
smorlat's avatar
smorlat committed
1257 1258 1259
	}else if (strstr(args,"hook")){
		gstate_t call_state=linphone_core_get_state(lc,GSTATE_GROUP_CALL);
		if (!cfg || !linphone_proxy_config_is_registered(cfg)){
smorlat's avatar
smorlat committed
1260 1261
			linphonec_out("unregistered\n");
			return 1;
smorlat's avatar
smorlat committed
1262 1263 1264
		}
		switch(call_state){
			case GSTATE_CALL_OUT_INVITE:
smorlat's avatar
smorlat committed
1265
				linphonec_out("hook=dialing\n");
smorlat's avatar
smorlat committed
1266 1267
			break;
			case GSTATE_CALL_IDLE:
smorlat's avatar
smorlat committed
1268
				linphonec_out("hook=offhook\n");
smorlat's avatar
smorlat committed
1269 1270
			break;
			case GSTATE_CALL_OUT_CONNECTED:
smorlat's avatar
smorlat committed
1271
				linphonec_out("hook=%s duration=%i\n", linphonec_get_callee(),
smorlat's avatar
smorlat committed
1272 1273 1274
					linphone_core_get_current_call_duration(lc));
			break;
			case GSTATE_CALL_IN_CONNECTED:
smorlat's avatar
smorlat committed
1275
				linphonec_out("hook=answered duration=%i\n" ,
smorlat's avatar
smorlat committed
1276 1277 1278 1279 1280 1281 1282 1283 1284
					linphone_core_get_current_call_duration(lc));
			default:
				break;
		}
		
	}else return 0;
	return 1;
}

aymeric's avatar
aymeric committed
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389
/***************************************************************************
 *
 *  Command table management funx
 *
 ***************************************************************************/

/*
 * Find a command given its name
 */
static LPC_COMMAND *
lpc_find_command(const char *name)
{
	int i;

	for (i=0; commands[i].name; ++i)
	{
		if (strcmp(name, commands[i].name) == 0)
			return &commands[i];
	}

	return (LPC_COMMAND *)NULL;
}


/****************************************************************************
 *
 * $Log: commands.c,v $
 * Revision 1.39  2008/07/03 15:08:34  smorlat
 * api cleanups, interface in progress.
 *
 * Revision 1.38  2008/06/17 20:38:59  smorlat
 * added missing file.
 *
 * Revision 1.37  2008/04/09 09:26:00  smorlat
 * merge various patches
 * H264 support.
 *
 * Revision 1.36  2007/08/01 14:47:53  strk
 *         * console/commands.c: Clean up commands 'nat', 'stun'
 *           and 'firewall' to be more intuitive.
 *
 * Revision 1.35  2007/06/27 09:01:25  smorlat
 * logging improvements.
 *
 * Revision 1.34  2007/02/20 10:17:13  smorlat
 * linphonec friends patch2
 *
 * Revision 1.31  2006/09/22 07:22:47  smorlat
 * linphonecore api changes.
 *
 * Revision 1.30  2006/09/08 15:32:57  smorlat
 * support for using files instead of soundcard (used by linphonec only)
 *
 * Revision 1.29  2006/08/28 14:29:07  smorlat
 * fix bug.
 *
 * Revision 1.28  2006/08/21 12:49:59  smorlat
 * merged several little patches.
 *
 * Revision 1.27  2006/07/17 18:45:00  smorlat
 * support for several event queues in ortp.
 * glib dependency removed from coreapi/ and console/
 *
 * Revision 1.26  2006/04/14 15:16:36  smorlat
 * soundcard use did nothing !
 *
 * Revision 1.25  2006/04/06 20:09:33  smorlat
 * add linphonec command to see and select sound devices.
 *
 * Revision 1.24  2006/03/04 11:17:10  smorlat
 * mediastreamer2 in progress.
 *
 * Revision 1.23  2006/02/20 21:14:01  strk
 * Handled syntax errors with 'friend' command
 *
 * Revision 1.22  2006/02/20 10:20:29  strk
 * Added substring-based filter support for command 'friend list'
 *
 * Revision 1.21  2006/02/02 15:39:18  strk
 * - Added 'friend list' and 'friend call' commands
 * - Allowed for multiple DTFM send in a single line
 * - Added status-specific callback (bare version)
 *
 * Revision 1.20  2006/01/26 11:54:34  strk
 * More robust 'nat' command handler (strip blanks in args)
 *
 * Revision 1.19  2006/01/26 09:48:05  strk
 * Added limits.h include
 *
 * Revision 1.18  2006/01/26 02:18:05  strk
 * Added new commands 'nat use' and 'nat unuse'.
 * These will required a pending patch to linphonecore.c
 * in order to work.
 *
 * Revision 1.17  2006/01/20 14:12:33  strk
 * Added linphonec_init() and linphonec_finish() functions.
 * Handled SIGINT and SIGTERM to invoke linphonec_finish().
 * Handling of auto-termination (-t) moved to linphonec_finish().
 * Reworked main (input read) loop to not rely on 'terminate'
 * and 'run' variable (dropped). configfile_name allocated on stack
 * using PATH_MAX limit. Changed print_usage signature to allow
 * for an exit_status specification.
 *
 * Revision 1.16  2006/01/18 09:25:32  strk
 * Command completion inhibited in proxy addition and auth request prompts.
1390
 * Avoided use of linphonec_readline's internal filename completion.
aymeric's avatar
aymeric committed
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404
 *
 * Revision 1.15  2006/01/14 13:29:32  strk
 * Reworked commands interface to use a table structure,
 * used by command line parser and help function.
 * Implemented first level of completion (commands).
 * Added notification of invalid "answer" and "terminate"
 * commands (no incoming call, no active call).
 * Forbidden "call" intialization when a call is already active.
 * Cleaned up all commands, adding more feedback and error checks.
 *
 * Revision 1.14  2006/01/13 13:00:29  strk
 * Added linphonec.h. Code layout change (added comments, forward decl,
 * globals on top, copyright notices and Logs). Handled out-of-memory
 * condition on history management. Removed assumption on sizeof(char).
1405
 * Fixed bug in authentication prompt (introduced by linphonec_readline).
aymeric's avatar
aymeric committed
1406 1407 1408 1409
 * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
 *
 *
 ****************************************************************************/