diff -u linphone-1.5.1/console/commands.c linphone-1.5.1-mod/console/commands.c --- linphone-1.5.1/console/commands.c 2006-09-22 17:22:47.000000000 +1000 +++ linphone-1.5.1-mod/console/commands.c 2007-01-25 17:46:58.517415342 +1100 @@ -68,6 +68,8 @@ 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); /* Command table management */ static LPC_COMMAND *lpc_find_command(const char *name); @@ -132,7 +134,9 @@ NULL }, { "friend", lpc_cmd_friend, "Manage friends", "'friend list []' : list friends.\n" - "'friend call : call a friend." + "'friend call : call a friend.\n" + "'friend add : add a new friend, has \"sip:\" added if it isn't there\n" + "'friend delete : 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" @@ -435,7 +439,51 @@ 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 ) { + printf("Invalid friend number\n"); + 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; + name = strsep(&args, " "); + if (NULL == 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, " "); + strcpy(addr_p, addr_orig); + linphonec_friend_add(lc, name, addr); + return 1; + } return 0; } @@ -946,6 +994,46 @@ 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) +{ + 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; + } + + printf("No such friend %u\n", num); + return 1; +} + static void linphonec_display_command_help(LPC_COMMAND *cmd) {