Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Functions | Variables
func_groupcount.c File Reference

Channel group related dialplan functions. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
Include dependency graph for func_groupcount.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int group_count_function_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int group_function_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int group_function_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 
static int group_list_function_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int group_match_count_function_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Channel group dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function group_count_function
 
static struct ast_custom_function group_function
 
static struct ast_custom_function group_list_function
 
static struct ast_custom_function group_match_count_function
 

Detailed Description

Channel group related dialplan functions.

Definition in file func_groupcount.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 306 of file func_groupcount.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 306 of file func_groupcount.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 306 of file func_groupcount.c.

◆ group_count_function_read()

static int group_count_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 98 of file func_groupcount.c.

100{
101 int ret = -1;
102 int count = -1;
103 char group[80] = "", category[80] = "";
104
105 if (!chan) {
106 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
107 return -1;
108 }
109
110 ast_app_group_split_group(data, group, sizeof(group), category,
111 sizeof(category));
112
113 /* If no group has been provided let's find one */
114 if (ast_strlen_zero(group)) {
115 struct ast_group_info *gi = NULL;
116
118 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
119 if (gi->chan != chan)
120 continue;
121 if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))
122 break;
123 }
124 if (gi) {
125 ast_copy_string(group, gi->group, sizeof(group));
126 if (!ast_strlen_zero(gi->category))
128 }
130 }
131
132 if ((count = ast_app_group_get_count(group, category)) == -1) {
133 ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", ast_channel_name(chan));
134 } else {
135 snprintf(buf, len, "%d", count);
136 ret = 0;
137 }
138
139 return ret;
140}
#define ast_log
Definition: astobj2.c:42
const char * ast_channel_name(const struct ast_channel *chan)
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int ast_app_group_get_count(const char *group, const char *category)
Get the current channel count of the specified group and category.
Definition: main/app.c:2230
int ast_app_group_list_unlock(void)
Unlock the group count list.
Definition: main/app.c:2341
int ast_app_group_split_group(const char *data, char *group, int group_max, char *category, int category_max)
Split a group string into group and category, returning a default category if none is provided.
Definition: main/app.c:2156
struct ast_group_info * ast_app_group_list_head(void)
Get the head of the group count list.
Definition: main/app.c:2336
int ast_app_group_list_rdlock(void)
Read Lock the group count list.
Definition: main/app.c:2331
#define LOG_NOTICE
#define LOG_WARNING
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
channel group info
Definition: channel.h:2915
struct ast_group_info::@210 group_list
char * category
Definition: channel.h:2917
char * group
Definition: channel.h:2918
struct ast_channel * chan
Definition: channel.h:2916

References ast_app_group_get_count(), ast_app_group_list_head(), ast_app_group_list_rdlock(), ast_app_group_list_unlock(), ast_app_group_split_group(), ast_channel_name(), ast_copy_string(), AST_LIST_NEXT, ast_log, ast_strlen_zero(), buf, ast_group_info::category, ast_group_info::chan, ast_group_info::group, ast_group_info::group_list, len(), LOG_NOTICE, LOG_WARNING, and NULL.

◆ group_function_read()

static int group_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 175 of file func_groupcount.c.

177{
178 int ret = -1;
179 struct ast_group_info *gi = NULL;
180
181 if (!chan) {
182 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
183 return -1;
184 }
185
187
188 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
189 if (gi->chan != chan)
190 continue;
191 if (ast_strlen_zero(data))
192 break;
193 if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
194 break;
195 }
196
197 if (gi) {
199 ret = 0;
200 }
201
203
204 return ret;
205}

References ast_app_group_list_head(), ast_app_group_list_rdlock(), ast_app_group_list_unlock(), ast_copy_string(), AST_LIST_NEXT, ast_log, ast_strlen_zero(), buf, ast_group_info::category, ast_group_info::chan, ast_group_info::group, ast_group_info::group_list, len(), LOG_WARNING, and NULL.

◆ group_function_write()

static int group_function_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

Definition at line 207 of file func_groupcount.c.

209{
210 char grpcat[256];
211
212 if (!chan) {
213 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
214 return -1;
215 }
216
217 if (!value) {
218 return -1;
219 }
220
221 if (!ast_strlen_zero(data)) {
222 snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
223 } else {
224 ast_copy_string(grpcat, value, sizeof(grpcat));
225 }
226
227 if (ast_app_group_set_channel(chan, grpcat))
229 "Setting a group requires an argument (group name)\n");
230
231 return 0;
232}
int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
Set the group for a channel, splitting the provided data into group and category, if specified.
Definition: main/app.c:2183
int value
Definition: syslog.c:37

References ast_app_group_set_channel(), ast_copy_string(), ast_log, ast_strlen_zero(), ast_group_info::chan, LOG_WARNING, and value.

◆ group_list_function_read()

static int group_list_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 240 of file func_groupcount.c.

242{
243 struct ast_group_info *gi = NULL;
244 char tmp1[1024] = "";
245 char tmp2[1024] = "";
246
247 if (!chan)
248 return -1;
249
251
252 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
253 if (gi->chan != chan)
254 continue;
255 if (!ast_strlen_zero(tmp1)) {
256 ast_copy_string(tmp2, tmp1, sizeof(tmp2));
257 if (!ast_strlen_zero(gi->category))
258 snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
259 else
260 snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
261 } else {
262 if (!ast_strlen_zero(gi->category))
263 snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
264 else
265 snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
266 }
267 }
268
270
271 ast_copy_string(buf, tmp1, len);
272
273 return 0;
274}

References ast_app_group_list_head(), ast_app_group_list_rdlock(), ast_app_group_list_unlock(), ast_copy_string(), AST_LIST_NEXT, ast_strlen_zero(), buf, ast_group_info::category, ast_group_info::chan, ast_group_info::group, ast_group_info::group_list, len(), and NULL.

◆ group_match_count_function_read()

static int group_match_count_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 148 of file func_groupcount.c.

151{
152 char group[80] = "";
153 char category[80] = "";
154
155 ast_app_group_split_group(data, group, sizeof(group), category,
156 sizeof(category));
157
158 if (!ast_strlen_zero(group)) {
159 int count;
160 count = ast_app_group_match_get_count(group, category);
161 snprintf(buf, len, "%d", count);
162 return 0;
163 }
164
165 return -1;
166}
int ast_app_group_match_get_count(const char *groupmatch, const char *category)
Get the current channel count of all groups that match the specified pattern and category.
Definition: main/app.c:2250

References ast_app_group_match_get_count(), ast_app_group_split_group(), ast_strlen_zero(), buf, and len().

◆ load_module()

static int load_module ( void  )
static

Definition at line 294 of file func_groupcount.c.

295{
296 int res = 0;
297
302
303 return res;
304}
static struct ast_custom_function group_list_function
static struct ast_custom_function group_count_function
static struct ast_custom_function group_match_count_function
static struct ast_custom_function group_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

References ast_custom_function_register, group_count_function, group_function, group_list_function, and group_match_count_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 282 of file func_groupcount.c.

283{
284 int res = 0;
285
290
291 return res;
292}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), group_count_function, group_function, group_list_function, and group_match_count_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Channel group dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 306 of file func_groupcount.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 306 of file func_groupcount.c.

◆ group_count_function

struct ast_custom_function group_count_function
static
Initial value:
= {
.name = "GROUP_COUNT",
.read_max = 12,
}
static int group_count_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)

Definition at line 142 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

◆ group_function

struct ast_custom_function group_function
static
Initial value:
= {
.name = "GROUP",
}
static int group_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int group_function_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)

Definition at line 234 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

◆ group_list_function

struct ast_custom_function group_list_function
static
Initial value:
= {
.name = "GROUP_LIST",
.write = NULL,
}
static int group_list_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)

Definition at line 276 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

◆ group_match_count_function

struct ast_custom_function group_match_count_function
static

Definition at line 168 of file func_groupcount.c.

Referenced by load_module(), and unload_module().