2005-05-05 05:39:33 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2005-05-05 05:39:33 +00:00
|
|
|
*
|
2006-02-12 04:28:58 +00:00
|
|
|
* Copyright (C) 1999 - 2006, Digium, Inc.
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
2005-05-05 05:39:33 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Channel group related dialplan functions
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2007-01-24 09:05:29 +00:00
|
|
|
* \ingroup functions
|
2005-05-05 05:39:33 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-14 20:28:54 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
git migration: Refactor the ASTERISK_FILE_VERSION macro
Git does not support the ability to replace a token with a version
string during check-in. While it does have support for replacing a
token on clone, this is somewhat sub-optimal: the token is replaced
with the object hash, which is not particularly easy for human
consumption. What's more, in practice, the source file version was often
not terribly useful. Generally, when triaging bugs, the overall version
of Asterisk is far more useful than an individual SVN version of a file. As a
result, this patch removes Asterisk's support for showing source file
versions.
Specifically, it does the following:
* Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and
remove passing the version in with the macro. Other facilities
than 'core show file version' make use of the file names, such as
setting a debug level only on a specific file. As such, the act of
registering source files with the Asterisk core still has use. The
macro rename now reflects the new macro purpose.
* main/asterisk:
- Refactor the file_version structure to reflect that it no longer
tracks a version field.
- Remove the "core show file version" CLI command. Without the file
version, it is no longer useful.
- Remove the ast_file_version_find function. The file version is no
longer tracked.
- Rename ast_register_file_version/ast_unregister_file_version to
ast_register_file/ast_unregister_file, respectively.
* main/manager: Remove value from the Version key of the ModuleCheck
Action. The actual key itself has not been removed, as doing so would
absolutely constitute a backwards incompatible change. However, since
the file version is no longer tracked, there is no need to attempt to
include it in the Version key.
* UPGRADE: Add notes for:
- Modification to the ModuleCheck AMI Action
- Removal of the "core show file version" CLI command
Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-12 02:38:22 +00:00
|
|
|
ASTERISK_REGISTER_FILE()
|
2006-06-07 18:54:56 +00:00
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
#include "asterisk/module.h"
|
2005-05-05 05:39:33 +00:00
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/app.h"
|
|
|
|
|
2008-11-01 21:10:07 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<function name="GROUP_COUNT" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Counts the number of channels in the specified group.
|
|
|
|
</synopsis>
|
|
|
|
<syntax argsep="@">
|
|
|
|
<parameter name="groupname">
|
|
|
|
<para>Group name.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="category">
|
|
|
|
<para>Category name</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Calculates the group count for the specified group, or uses the
|
2015-01-23 15:13:08 +00:00
|
|
|
channel's current group if not specified (and non-empty).</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
<function name="GROUP_MATCH_COUNT" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Counts the number of channels in the groups matching the specified pattern.
|
|
|
|
</synopsis>
|
|
|
|
<syntax argsep="@">
|
|
|
|
<parameter name="groupmatch" required="true">
|
|
|
|
<para>A standard regular expression used to match a group name.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="category">
|
2010-02-17 19:51:53 +00:00
|
|
|
<para>A standard regular expression used to match a category name.</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Calculates the group count for all groups that match the specified pattern.
|
2010-02-17 19:51:53 +00:00
|
|
|
Note: category matching is applied after matching based on group.
|
|
|
|
Uses standard regular expression matching on both (see regex(7)).</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
<function name="GROUP" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Gets or sets the channel group.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="category">
|
|
|
|
<para>Category name.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para><replaceable>category</replaceable> can be employed for more fine grained group management. Each channel
|
|
|
|
can only be member of exactly one group per <replaceable>category</replaceable>.</para>
|
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
<function name="GROUP_LIST" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Gets a list of the groups set on a channel.
|
|
|
|
</synopsis>
|
|
|
|
<syntax />
|
|
|
|
<description>
|
|
|
|
<para>Gets a list of the groups set on a channel.</para>
|
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
|
|
|
|
***/
|
|
|
|
|
2007-01-06 00:13:33 +00:00
|
|
|
static int group_count_function_read(struct ast_channel *chan, const char *cmd,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *data, char *buf, size_t len)
|
2005-05-05 05:39:33 +00:00
|
|
|
{
|
2008-10-06 21:09:05 +00:00
|
|
|
int ret = -1;
|
2007-04-25 19:27:42 +00:00
|
|
|
int count = -1;
|
|
|
|
char group[80] = "", category[80] = "";
|
2005-05-05 05:39:33 +00:00
|
|
|
|
2014-03-27 19:21:44 +00:00
|
|
|
if (!chan) {
|
|
|
|
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-02-12 04:28:58 +00:00
|
|
|
ast_app_group_split_group(data, group, sizeof(group), category,
|
|
|
|
sizeof(category));
|
2005-05-05 05:39:33 +00:00
|
|
|
|
2008-01-08 19:55:56 +00:00
|
|
|
/* If no group has been provided let's find one */
|
|
|
|
if (ast_strlen_zero(group)) {
|
|
|
|
struct ast_group_info *gi = NULL;
|
|
|
|
|
|
|
|
ast_app_group_list_rdlock();
|
2009-04-22 21:15:55 +00:00
|
|
|
for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
|
2008-01-08 19:55:56 +00:00
|
|
|
if (gi->chan != chan)
|
|
|
|
continue;
|
|
|
|
if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (gi) {
|
|
|
|
ast_copy_string(group, gi->group, sizeof(group));
|
2008-01-10 15:12:08 +00:00
|
|
|
if (!ast_strlen_zero(gi->category))
|
|
|
|
ast_copy_string(category, gi->category, sizeof(category));
|
2008-01-08 19:55:56 +00:00
|
|
|
}
|
|
|
|
ast_app_group_list_unlock();
|
|
|
|
}
|
|
|
|
|
2008-10-06 21:09:05 +00:00
|
|
|
if ((count = ast_app_group_get_count(group, category)) == -1) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", ast_channel_name(chan));
|
2008-10-06 21:09:05 +00:00
|
|
|
} else {
|
2007-04-25 19:27:42 +00:00
|
|
|
snprintf(buf, len, "%d", count);
|
2008-10-06 21:09:05 +00:00
|
|
|
ret = 0;
|
|
|
|
}
|
2005-05-05 05:39:33 +00:00
|
|
|
|
2008-10-06 21:09:05 +00:00
|
|
|
return ret;
|
2005-05-05 05:39:33 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
static struct ast_custom_function group_count_function = {
|
2005-05-05 05:39:33 +00:00
|
|
|
.name = "GROUP_COUNT",
|
|
|
|
.read = group_count_function_read,
|
2009-04-29 18:53:01 +00:00
|
|
|
.read_max = 12,
|
2005-05-05 05:39:33 +00:00
|
|
|
};
|
|
|
|
|
2006-02-12 04:28:58 +00:00
|
|
|
static int group_match_count_function_read(struct ast_channel *chan,
|
2007-01-06 00:13:33 +00:00
|
|
|
const char *cmd, char *data, char *buf,
|
2006-02-12 04:28:58 +00:00
|
|
|
size_t len)
|
2005-05-05 05:39:33 +00:00
|
|
|
{
|
|
|
|
char group[80] = "";
|
|
|
|
char category[80] = "";
|
|
|
|
|
2006-02-12 04:28:58 +00:00
|
|
|
ast_app_group_split_group(data, group, sizeof(group), category,
|
|
|
|
sizeof(category));
|
2005-05-05 05:39:33 +00:00
|
|
|
|
|
|
|
if (!ast_strlen_zero(group)) {
|
2012-04-17 18:57:40 +00:00
|
|
|
int count;
|
2005-05-05 05:39:33 +00:00
|
|
|
count = ast_app_group_match_get_count(group, category);
|
|
|
|
snprintf(buf, len, "%d", count);
|
2008-10-06 21:09:05 +00:00
|
|
|
return 0;
|
2005-05-05 05:39:33 +00:00
|
|
|
}
|
|
|
|
|
2008-10-06 21:09:05 +00:00
|
|
|
return -1;
|
2005-05-05 05:39:33 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
static struct ast_custom_function group_match_count_function = {
|
2005-05-05 05:39:33 +00:00
|
|
|
.name = "GROUP_MATCH_COUNT",
|
|
|
|
.read = group_match_count_function_read,
|
2009-04-29 18:53:01 +00:00
|
|
|
.read_max = 12,
|
2005-05-05 05:39:33 +00:00
|
|
|
.write = NULL,
|
|
|
|
};
|
2005-05-08 17:17:34 +00:00
|
|
|
|
2007-01-06 00:13:33 +00:00
|
|
|
static int group_function_read(struct ast_channel *chan, const char *cmd,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *data, char *buf, size_t len)
|
2005-05-08 17:17:34 +00:00
|
|
|
{
|
2008-10-06 21:09:05 +00:00
|
|
|
int ret = -1;
|
2007-04-25 19:27:42 +00:00
|
|
|
struct ast_group_info *gi = NULL;
|
2014-03-27 19:21:44 +00:00
|
|
|
|
|
|
|
if (!chan) {
|
|
|
|
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-06-13 18:23:12 +00:00
|
|
|
ast_app_group_list_rdlock();
|
2014-03-27 19:21:44 +00:00
|
|
|
|
2009-04-22 21:15:55 +00:00
|
|
|
for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
|
2007-04-25 19:27:42 +00:00
|
|
|
if (gi->chan != chan)
|
|
|
|
continue;
|
|
|
|
if (ast_strlen_zero(data))
|
|
|
|
break;
|
|
|
|
if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
|
|
|
|
break;
|
2005-05-08 17:17:34 +00:00
|
|
|
}
|
2007-04-25 19:27:42 +00:00
|
|
|
|
2008-10-06 21:09:05 +00:00
|
|
|
if (gi) {
|
2007-04-25 19:27:42 +00:00
|
|
|
ast_copy_string(buf, gi->group, len);
|
2008-10-06 21:09:05 +00:00
|
|
|
ret = 0;
|
|
|
|
}
|
2007-04-25 19:27:42 +00:00
|
|
|
|
|
|
|
ast_app_group_list_unlock();
|
|
|
|
|
2008-10-06 21:09:05 +00:00
|
|
|
return ret;
|
2005-05-08 17:17:34 +00:00
|
|
|
}
|
|
|
|
|
2007-01-06 00:13:33 +00:00
|
|
|
static int group_function_write(struct ast_channel *chan, const char *cmd,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *data, const char *value)
|
2005-05-08 17:17:34 +00:00
|
|
|
{
|
|
|
|
char grpcat[256];
|
|
|
|
|
2014-03-27 19:21:44 +00:00
|
|
|
if (!chan) {
|
|
|
|
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-12-02 15:42:54 +00:00
|
|
|
if (!value) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-11-08 01:55:31 +00:00
|
|
|
if (!ast_strlen_zero(data)) {
|
2005-07-28 21:16:02 +00:00
|
|
|
snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
|
2005-05-08 17:17:34 +00:00
|
|
|
} else {
|
|
|
|
ast_copy_string(grpcat, value, sizeof(grpcat));
|
|
|
|
}
|
|
|
|
|
2006-02-12 04:28:58 +00:00
|
|
|
if (ast_app_group_set_channel(chan, grpcat))
|
|
|
|
ast_log(LOG_WARNING,
|
|
|
|
"Setting a group requires an argument (group name)\n");
|
|
|
|
|
|
|
|
return 0;
|
2005-05-08 17:17:34 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
static struct ast_custom_function group_function = {
|
2005-05-08 17:17:34 +00:00
|
|
|
.name = "GROUP",
|
|
|
|
.read = group_function_read,
|
|
|
|
.write = group_function_write,
|
|
|
|
};
|
|
|
|
|
2007-01-06 00:13:33 +00:00
|
|
|
static int group_list_function_read(struct ast_channel *chan, const char *cmd,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *data, char *buf, size_t len)
|
2005-05-08 17:17:34 +00:00
|
|
|
{
|
2007-04-25 19:27:42 +00:00
|
|
|
struct ast_group_info *gi = NULL;
|
2005-05-08 17:17:34 +00:00
|
|
|
char tmp1[1024] = "";
|
|
|
|
char tmp2[1024] = "";
|
|
|
|
|
2007-04-19 02:51:21 +00:00
|
|
|
if (!chan)
|
|
|
|
return -1;
|
|
|
|
|
2007-06-13 18:23:12 +00:00
|
|
|
ast_app_group_list_rdlock();
|
2007-04-25 19:27:42 +00:00
|
|
|
|
2009-04-22 21:15:55 +00:00
|
|
|
for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
|
2007-04-25 19:27:42 +00:00
|
|
|
if (gi->chan != chan)
|
|
|
|
continue;
|
|
|
|
if (!ast_strlen_zero(tmp1)) {
|
|
|
|
ast_copy_string(tmp2, tmp1, sizeof(tmp2));
|
|
|
|
if (!ast_strlen_zero(gi->category))
|
|
|
|
snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
|
2007-06-14 15:25:32 +00:00
|
|
|
else
|
2007-04-25 19:27:42 +00:00
|
|
|
snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
|
|
|
|
} else {
|
|
|
|
if (!ast_strlen_zero(gi->category))
|
|
|
|
snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
|
2007-06-14 15:25:32 +00:00
|
|
|
else
|
2007-04-25 19:27:42 +00:00
|
|
|
snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
|
2005-05-08 17:17:34 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-25 19:27:42 +00:00
|
|
|
|
|
|
|
ast_app_group_list_unlock();
|
|
|
|
|
2005-05-08 17:17:34 +00:00
|
|
|
ast_copy_string(buf, tmp1, len);
|
2006-02-12 04:28:58 +00:00
|
|
|
|
|
|
|
return 0;
|
2005-05-08 17:17:34 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
static struct ast_custom_function group_list_function = {
|
2005-05-08 17:17:34 +00:00
|
|
|
.name = "GROUP_LIST",
|
|
|
|
.read = group_list_function_read,
|
|
|
|
.write = NULL,
|
|
|
|
};
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2006-02-11 03:14:05 +00:00
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
res |= ast_custom_function_unregister(&group_count_function);
|
|
|
|
res |= ast_custom_function_unregister(&group_match_count_function);
|
|
|
|
res |= ast_custom_function_unregister(&group_list_function);
|
|
|
|
res |= ast_custom_function_unregister(&group_function);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2006-02-11 03:14:05 +00:00
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
res |= ast_custom_function_register(&group_count_function);
|
|
|
|
res |= ast_custom_function_register(&group_match_count_function);
|
|
|
|
res |= ast_custom_function_register(&group_list_function);
|
|
|
|
res |= ast_custom_function_register(&group_function);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel group dialplan functions");
|