[asterisk-commits] dvossel: branch dvossel/hd_confbridge r311605 - /team/dvossel/hd_confbridge/a...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Mar 23 10:43:02 CDT 2011
Author: dvossel
Date: Wed Mar 23 10:42:57 2011
New Revision: 311605
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=311605
Log:
Confbridge lock and unlock AMI and CLI commands
Modified:
team/dvossel/hd_confbridge/apps/app_confbridge.c
Modified: team/dvossel/hd_confbridge/apps/app_confbridge.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/hd_confbridge/apps/app_confbridge.c?view=diff&rev=311605&r1=311604&r2=311605
==============================================================================
--- team/dvossel/hd_confbridge/apps/app_confbridge.c (original)
+++ team/dvossel/hd_confbridge/apps/app_confbridge.c Wed Mar 23 10:42:57 2011
@@ -173,7 +173,28 @@
<description>
</description>
</manager>
-
+ <manager name="ConfbridgeLock" language="en_US">
+ <synopsis>
+ Lock a Confbridge conference.
+ </synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+ <parameter name="Conference" required="true" />
+ </syntax>
+ <description>
+ </description>
+ </manager>
+ <manager name="ConfbridgeUnlock" language="en_US">
+ <synopsis>
+ Unlock a Confbridge conference.
+ </synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+ <parameter name="Conference" required="true" />
+ </syntax>
+ <description>
+ </description>
+ </manager>
***/
/*!
@@ -1573,33 +1594,78 @@
return CLI_SHOWUSAGE;
}
-static int cli_mute_unmute_helper(int mute, struct ast_cli_args *a)
+/* \internal
+ * \brief finds a conference by name and locks/unlocks.
+ *
+ * \retval 0 success
+ * \retval -1 conference not found
+ */
+static int generic_lock_unlock_helper(int lock, const char *conference)
+{
+ struct conference_bridge *bridge = NULL;
+ struct conference_bridge tmp;
+ int res = 0;
+
+ ast_copy_string(tmp.name, conference, sizeof(tmp.name));
+ bridge = ao2_find(conference_bridges, &tmp, OBJ_POINTER);
+ if (!bridge) {
+ return -1;
+ }
+ ao2_lock(bridge);
+ bridge->locked = lock;
+ ao2_unlock(bridge);
+ ao2_ref(bridge, -1);
+
+ return res;
+}
+
+/* \internal
+ * \brief finds a conference user by channel name and mutes/unmutes them.
+ *
+ * \retval 0 success
+ * \retval -1 conference not found
+ * \retval -2 user not found
+ */
+static int generic_mute_unmute_helper(int mute, const char *conference, const char *user)
{
struct conference_bridge *bridge = NULL;
struct conference_bridge tmp;
struct conference_bridge_user *participant = NULL;
-
- ast_copy_string(tmp.name, a->argv[2], sizeof(tmp.name));
+ int res = 0;
+ ast_copy_string(tmp.name, conference, sizeof(tmp.name));
bridge = ao2_find(conference_bridges, &tmp, OBJ_POINTER);
if (!bridge) {
+ return -1;
+ }
+ ao2_lock(bridge);
+ AST_LIST_TRAVERSE(&bridge->users_list, participant, list) {
+ if (!strncmp(user, participant->chan->name, strlen(participant->chan->name))) {
+ break;
+ }
+ }
+ if (participant) {
+ participant->features.mute = mute;
+ } else {
+ res = -2;;
+ }
+ ao2_unlock(bridge);
+ ao2_ref(bridge, -1);
+
+ return res;
+}
+
+static int cli_mute_unmute_helper(int mute, struct ast_cli_args *a)
+{
+ int res = generic_mute_unmute_helper(mute, a->argv[2], a->argv[3]);
+
+ if (res == -1) {
ast_cli(a->fd, "No conference bridge named '%s' found!\n", a->argv[2]);
return -1;
- }
- ao2_lock(bridge);
- AST_LIST_TRAVERSE(&bridge->users_list, participant, list) {
- if (!strncmp(a->argv[3], participant->chan->name, strlen(participant->chan->name))) {
- break;
- }
- }
- if (participant) {
- ast_cli(a->fd, "%s %s from confbridge %s\n", mute ? "Muting" : "Unmuting", participant->chan->name, bridge->name);
- participant->features.mute = mute;
- } else {
+ } else if (res == -2) {
ast_cli(a->fd, "No channel named '%s' found in conference %s\n", a->argv[3], a->argv[2]);
- }
- ao2_unlock(bridge);
- ao2_ref(bridge, -1);
-
+ return -1;
+ }
+ ast_cli(a->fd, "%s %s from confbridge %s\n", mute ? "Muting" : "Unmuting", a->argv[3], a->argv[2]);
return 0;
}
@@ -1649,11 +1715,64 @@
return CLI_SUCCESS;
}
+
+static char *handle_cli_confbridge_lock(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "confbridge lock";
+ e->usage =
+ "Usage: confbridge lock <conference>\n";
+ return NULL;
+ case CLI_GENERATE:
+ if (a->pos == 2) {
+ return complete_confbridge_name(a->line, a->word, a->pos, a->n);
+ }
+ return NULL;
+ }
+ if (a->argc != 3) {
+ return CLI_SHOWUSAGE;
+ }
+ if (generic_lock_unlock_helper(1, a->argv[2])) {
+ ast_cli(a->fd, "Conference %s is not found\n", a->argv[2]);
+ } else {
+ ast_cli(a->fd, "Conference %s is locked.\n", a->argv[2]);
+ }
+ return CLI_SUCCESS;
+}
+
+static char *handle_cli_confbridge_unlock(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "confbridge unlock";
+ e->usage =
+ "Usage: confbridge unlock <conference>\n";
+ return NULL;
+ case CLI_GENERATE:
+ if (a->pos == 2) {
+ return complete_confbridge_name(a->line, a->word, a->pos, a->n);
+ }
+ return NULL;
+ }
+ if (a->argc != 3) {
+ return CLI_SHOWUSAGE;
+ }
+ if (generic_lock_unlock_helper(0, a->argv[2])) {
+ ast_cli(a->fd, "Conference %s is not found\n", a->argv[2]);
+ } else {
+ ast_cli(a->fd, "Conference %s is unlocked.\n", a->argv[2]);
+ }
+ return CLI_SUCCESS;
+}
+
static struct ast_cli_entry cli_confbridge[] = {
AST_CLI_DEFINE(handle_cli_confbridge_list, "List conference bridges and participants."),
AST_CLI_DEFINE(handle_cli_confbridge_kick, "Kick participants out of conference bridges."),
AST_CLI_DEFINE(handle_cli_confbridge_mute, "Mute a participant."),
AST_CLI_DEFINE(handle_cli_confbridge_unmute, "Mute a participant."),
+ AST_CLI_DEFINE(handle_cli_confbridge_lock, "Lock a conference."),
+ AST_CLI_DEFINE(handle_cli_confbridge_unlock, "Unlock a conference."),
};
static struct ast_custom_function confbridge_function = {
.name = "CONFBRIDGE",
@@ -1779,42 +1898,32 @@
{
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;
+ int res = 0;
if (ast_strlen_zero(conference)) {
astman_send_error(s, m, "No Conference name provided.");
return 0;
}
+ if (ast_strlen_zero(channel)) {
+ astman_send_error(s, m, "No channel name provided.");
+ return 0;
+ }
if (!ao2_container_count(conference_bridges)) {
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) {
+
+ res = generic_mute_unmute_helper(mute, conference, channel);
+
+ if (res == -1) {
astman_send_error(s, m, "No Conference by that name found.");
return 0;
- }
-
- ao2_lock(bridge);
- AST_LIST_TRAVERSE(&bridge->users_list, participant, list) {
- if (!strcasecmp(participant->chan->name, channel)) {
- participant->features.mute = mute;
- found = 1;
- break;
- }
- }
- ao2_unlock(bridge);
- ao2_ref(bridge, -1);
-
- if (found) {
- astman_send_ack(s, m, mute ? "User muted" : "User unmuted");
- } else {
+ } else if (res == -2) {
astman_send_error(s, m, "No Channel by that name found in Conference.");
- }
+ return 0;
+ }
+
+ astman_send_ack(s, m, mute ? "User muted" : "User unmuted");
return 0;
}
@@ -1825,6 +1934,35 @@
static int action_confbridgemute(struct mansession *s, const struct message *m)
{
return action_mute_unmute_helper(s, m, 1);
+}
+
+static int action_lock_unlock_helper(struct mansession *s, const struct message *m, int lock)
+{
+ const char *conference = astman_get_header(m, "Conference");
+ int res = 0;
+
+ if (ast_strlen_zero(conference)) {
+ astman_send_error(s, m, "No Conference name provided.");
+ return 0;
+ }
+ if (!ao2_container_count(conference_bridges)) {
+ astman_send_error(s, m, "No active conferences.");
+ return 0;
+ }
+ if ((res = generic_lock_unlock_helper(lock, conference))) {
+ astman_send_error(s, m, "No Conference by that name found.");
+ return 0;
+ }
+ astman_send_ack(s, m, lock ? "Conference locked" : "Conference unlocked");
+ return 0;
+}
+static int action_confbridgeunlock(struct mansession *s, const struct message *m)
+{
+ return action_lock_unlock_helper(s, m, 0);
+}
+static int action_confbridgelock(struct mansession *s, const struct message *m)
+{
+ return action_lock_unlock_helper(s, m, 1);
}
static int action_confbridgekick(struct mansession *s, const struct message *m)
@@ -1893,6 +2031,8 @@
res |= ast_manager_unregister("ConfbridgeMute");
res |= ast_manager_unregister("ConfbridgeUnmute");
res |= ast_manager_unregister("ConfbridgeKick");
+ res |= ast_manager_unregister("ConfbridgeUnlock");
+ res |= ast_manager_unregister("ConfbridgeLock");
return res;
}
@@ -1924,9 +2064,11 @@
res |= ast_cli_register_multiple(cli_confbridge, sizeof(cli_confbridge) / sizeof(struct ast_cli_entry));
res |= ast_manager_register_xml("ConfbridgeList", EVENT_FLAG_REPORTING, action_confbridgelist);
res |= ast_manager_register_xml("ConfbridgeListRooms", EVENT_FLAG_REPORTING, action_confbridgelistrooms);
- res |= ast_manager_register_xml("ConfbridgeMute", EVENT_FLAG_REPORTING, action_confbridgemute);
- res |= ast_manager_register_xml("ConfbridgeUnmute", EVENT_FLAG_REPORTING, action_confbridgeunmute);
- res |= ast_manager_register_xml("ConfbridgeKick", EVENT_FLAG_REPORTING, action_confbridgekick);
+ res |= ast_manager_register_xml("ConfbridgeMute", EVENT_FLAG_CALL, action_confbridgemute);
+ res |= ast_manager_register_xml("ConfbridgeUnmute", EVENT_FLAG_CALL, action_confbridgeunmute);
+ res |= ast_manager_register_xml("ConfbridgeKick", EVENT_FLAG_CALL, action_confbridgekick);
+ res |= ast_manager_register_xml("ConfbridgeUnlock", EVENT_FLAG_CALL, action_confbridgeunlock);
+ res |= ast_manager_register_xml("ConfbridgeLock", EVENT_FLAG_CALL, action_confbridgelock);
conf_load_config(0);
return res;
More information about the asterisk-commits
mailing list