[asterisk-commits] mjordan: branch 11 r382068 - /branches/11/apps/app_confbridge.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Feb 26 09:35:08 CST 2013
Author: mjordan
Date: Tue Feb 26 09:35:05 2013
New Revision: 382068
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382068
Log:
Clean up ConfBridge commands to account for wait_marked users
When ConfBridge was refactored to better handle the concept of marked,
wait_marked, and normal users co-existing in a conference (thereby implementing
a state machine for the conference), the wait_marked users were put into their
own list of conference participants, separate from the active users. This list
is used for wait_marked users when they are waiting in a conference but no
marked user has joined; normal users may have joined at this point however.
There are several AMI/CLI commands that affect conference users that were not
checking the wait_marked users list:
* CLI/AMI commands that mute/unmute a participant. In this case, wait_marked
users have to remain in their particular state and should not be affected -
however, the commands would return "Channel not found" as opposed to the
appropriate error condition.
* CLI/AMI commands that kick a participant. An admin should always be able to
kick a participant out of the conference.
This patch fixes both sets of commands, and cleans up the CLI commands slightly
by allowing them to complete a participant name (this was supposed to have been
added, but the function call was commented out and wasn't implemented).
Review: https://reviewboard.asterisk.org/r/2346/
(closes issue AST-1114)
Reported by: John Bigelow
Tested by: John Bigelow
Modified:
branches/11/apps/app_confbridge.c
Modified: branches/11/apps/app_confbridge.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/apps/app_confbridge.c?view=diff&rev=382068&r1=382067&r2=382068
==============================================================================
--- branches/11/apps/app_confbridge.c (original)
+++ branches/11/apps/app_confbridge.c Tue Feb 26 09:35:05 2013
@@ -2071,6 +2071,32 @@
return 0;
}
+static int kick_conference_participant(struct conference_bridge *bridge, const char *channel)
+{
+ struct conference_bridge_user *participant = NULL;
+
+ ao2_lock(bridge);
+ AST_LIST_TRAVERSE(&bridge->active_list, participant, list) {
+ if (!strcasecmp(ast_channel_name(participant->chan), channel)) {
+ participant->kicked = 1;
+ ast_bridge_remove(bridge->bridge, participant->chan);
+ ao2_unlock(bridge);
+ return 0;
+ }
+ }
+ AST_LIST_TRAVERSE(&bridge->waiting_list, participant, list) {
+ if (!strcasecmp(ast_channel_name(participant->chan), channel)) {
+ participant->kicked = 1;
+ ast_bridge_remove(bridge->bridge, participant->chan);
+ ao2_unlock(bridge);
+ return 0;
+ }
+ }
+ ao2_unlock(bridge);
+
+ return -1;
+}
+
static char *complete_confbridge_name(const char *line, const char *word, int pos, int state)
{
int which = 0;
@@ -2093,11 +2119,46 @@
return res;
}
+static char *complete_confbridge_participant(const char *bridge_name, const char *line, const char *word, int pos, int state)
+{
+ int which = 0;
+ RAII_VAR(struct conference_bridge *, bridge, NULL, ao2_cleanup);
+ struct conference_bridge tmp;
+ struct conference_bridge_user *participant;
+ char *res = NULL;
+ int wordlen = strlen(word);
+
+ ast_copy_string(tmp.name, bridge_name, sizeof(tmp.name));
+ bridge = ao2_find(conference_bridges, &tmp, OBJ_POINTER);
+ if (!bridge) {
+ return NULL;
+ }
+
+ ao2_lock(bridge);
+ AST_LIST_TRAVERSE(&bridge->active_list, participant, list) {
+ if (!strncasecmp(ast_channel_name(participant->chan), word, wordlen) && ++which > state) {
+ res = ast_strdup(ast_channel_name(participant->chan));
+ ao2_unlock(bridge);
+ return res;
+ }
+ }
+
+ AST_LIST_TRAVERSE(&bridge->waiting_list, participant, list) {
+ if (!strncasecmp(ast_channel_name(participant->chan), word, wordlen) && ++which > state) {
+ res = ast_strdup(ast_channel_name(participant->chan));
+ ao2_unlock(bridge);
+ return res;
+ }
+ }
+ ao2_unlock(bridge);
+
+ return NULL;
+}
+
static char *handle_cli_confbridge_kick(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct conference_bridge *bridge = NULL;
struct conference_bridge tmp;
- struct conference_bridge_user *participant = NULL;
switch (cmd) {
case CLI_INIT:
@@ -2110,11 +2171,9 @@
if (a->pos == 2) {
return complete_confbridge_name(a->line, a->word, a->pos, a->n);
}
- /*
if (a->pos == 3) {
- return complete_confbridge_channel(a->line, a->word, a->pos, a->n);
- }
- */
+ return complete_confbridge_participant(a->argv[2], a->line, a->word, a->pos, a->n);
+ }
return NULL;
}
@@ -2128,19 +2187,12 @@
ast_cli(a->fd, "No conference bridge named '%s' found!\n", a->argv[2]);
return CLI_SUCCESS;
}
- ao2_lock(bridge);
- AST_LIST_TRAVERSE(&bridge->active_list, participant, list) {
- if (!strncmp(a->argv[3], ast_channel_name(participant->chan), strlen(ast_channel_name(participant->chan)))) {
- break;
- }
- }
- if (participant) {
- ast_cli(a->fd, "Kicking %s from confbridge %s\n", ast_channel_name(participant->chan), bridge->name);
- participant->kicked = 1;
- ast_bridge_remove(bridge->bridge, participant->chan);
- }
- ao2_unlock(bridge);
+ if (kick_conference_participant(bridge, a->argv[3])) {
+ ast_cli(a->fd, "No participant named '%s' found!\n", a->argv[3]);
+ return CLI_SUCCESS;
+ }
ao2_ref(bridge, -1);
+ ast_cli(a->fd, "Participant '%s' kicked out of conference '%s'\n", a->argv[3], a->argv[2]);
return CLI_SUCCESS;
}
@@ -2294,12 +2346,16 @@
case CLI_INIT:
e->command = "confbridge mute";
e->usage =
- "Usage: confbridge mute <conference> <channel>\n";
+ "Usage: confbridge mute <conference> <channel>\n"
+ " Mute a channel in a conference.\n";
return NULL;
case CLI_GENERATE:
if (a->pos == 2) {
return complete_confbridge_name(a->line, a->word, a->pos, a->n);
}
+ if (a->pos == 3) {
+ return complete_confbridge_participantl(a->argv[2], a->line, a->word, a->pos, a->n);
+ }
return NULL;
}
if (a->argc != 4) {
@@ -2317,12 +2373,16 @@
case CLI_INIT:
e->command = "confbridge unmute";
e->usage =
- "Usage: confbridge unmute <conference> <channel>\n";
+ "Usage: confbridge unmute <conference> <channel>\n"
+ " Unmute a channel in a conference.\n";
return NULL;
case CLI_GENERATE:
if (a->pos == 2) {
return complete_confbridge_name(a->line, a->word, a->pos, a->n);
}
+ if (a->pos == 3) {
+ return complete_confbridge_participantl(a->argv[2], a->line, a->word, a->pos, a->n);
+ }
return NULL;
}
if (a->argc != 4) {
@@ -2340,7 +2400,9 @@
case CLI_INIT:
e->command = "confbridge lock";
e->usage =
- "Usage: confbridge lock <conference>\n";
+ "Usage: confbridge lock <conference>\n"
+ " Lock a conference. While locked, no new non-admins\n"
+ " may join the conference.\n";
return NULL;
case CLI_GENERATE:
if (a->pos == 2) {
@@ -2365,7 +2427,8 @@
case CLI_INIT:
e->command = "confbridge unlock";
e->usage =
- "Usage: confbridge unlock <conference>\n";
+ "Usage: confbridge unlock <conference>\n"
+ " Unlock a previously locked conference.\n";
return NULL;
case CLI_GENERATE:
if (a->pos == 2) {
@@ -2453,7 +2516,8 @@
case CLI_INIT:
e->command = "confbridge record stop";
e->usage =
- "Usage: confbridge record stop <conference>\n";
+ "Usage: confbridge record stop <conference>\n"
+ " Stop a previously started recording.\n";
return NULL;
case CLI_GENERATE:
if (a->pos == 3) {
@@ -2702,7 +2766,6 @@
{
const char *conference = astman_get_header(m, "Conference");
const char *channel = astman_get_header(m, "Channel");
- struct conference_bridge_user *participant = NULL;
struct conference_bridge *bridge = NULL;
struct conference_bridge tmp;
int found = 0;
@@ -2715,6 +2778,7 @@
astman_send_error(s, m, "No active conferences.");
return 0;
}
+
ast_copy_string(tmp.name, conference, sizeof(tmp.name));
bridge = ao2_find(conference_bridges, &tmp, OBJ_POINTER);
if (!bridge) {
@@ -2722,16 +2786,7 @@
return 0;
}
- ao2_lock(bridge);
- AST_LIST_TRAVERSE(&bridge->active_list, participant, list) {
- if (!strcasecmp(ast_channel_name(participant->chan), channel)) {
- participant->kicked = 1;
- ast_bridge_remove(bridge->bridge, participant->chan);
- found = 1;
- break;
- }
- }
- ao2_unlock(bridge);
+ found = !kick_conference_participant(bridge, channel);
ao2_ref(bridge, -1);
if (found) {
@@ -2910,6 +2965,9 @@
ao2_lock(bridge);
if (!strncasecmp(args.type, "parties", 7)) {
AST_LIST_TRAVERSE(&bridge->active_list, participant, list) {
+ count++;
+ }
+ AST_LIST_TRAVERSE(&bridge->waiting_list, participant, list) {
count++;
}
} else if (!strncasecmp(args.type, "admins", 6)) {
More information about the asterisk-commits
mailing list