Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
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 = ASTERISK_GPL_KEY , .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 318 of file func_groupcount.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 318 of file func_groupcount.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 318 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 110 of file func_groupcount.c.

112{
113 int ret = -1;
114 int count = -1;
115 char group[80] = "", category[80] = "";
116
117 if (!chan) {
118 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
119 return -1;
120 }
121
122 ast_app_group_split_group(data, group, sizeof(group), category,
123 sizeof(category));
124
125 /* If no group has been provided let's find one */
126 if (ast_strlen_zero(group)) {
127 struct ast_group_info *gi = NULL;
128
130 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
131 if (gi->chan != chan)
132 continue;
133 if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))
134 break;
135 }
136 if (gi) {
137 ast_copy_string(group, gi->group, sizeof(group));
138 if (!ast_strlen_zero(gi->category))
140 }
142 }
143
144 if ((count = ast_app_group_get_count(group, category)) == -1) {
145 ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", ast_channel_name(chan));
146 } else {
147 snprintf(buf, len, "%d", count);
148 ret = 0;
149 }
150
151 return ret;
152}
#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:2240
int ast_app_group_list_unlock(void)
Unlock the group count list.
Definition main/app.c:2351
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:2166
struct ast_group_info * ast_app_group_list_head(void)
Get the head of the group count list.
Definition main/app.c:2346
int ast_app_group_list_rdlock(void)
Read Lock the group count list.
Definition main/app.c:2341
#define LOG_NOTICE
#define LOG_WARNING
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
#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:2975
char * category
Definition channel.h:2977
struct ast_group_info::@223 group_list
struct ast_channel * chan
Definition channel.h:2976

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 187 of file func_groupcount.c.

189{
190 int ret = -1;
191 struct ast_group_info *gi = NULL;
192
193 if (!chan) {
194 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
195 return -1;
196 }
197
199
200 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
201 if (gi->chan != chan)
202 continue;
203 if (ast_strlen_zero(data))
204 break;
205 if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
206 break;
207 }
208
209 if (gi) {
211 ret = 0;
212 }
213
215
216 return ret;
217}

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 219 of file func_groupcount.c.

221{
222 char grpcat[256];
223
224 if (!chan) {
225 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
226 return -1;
227 }
228
229 if (!value) {
230 return -1;
231 }
232
233 if (!ast_strlen_zero(data)) {
234 snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
235 } else {
236 ast_copy_string(grpcat, value, sizeof(grpcat));
237 }
238
239 if (ast_app_group_set_channel(chan, grpcat))
241 "Setting a group requires an argument (group name)\n");
242
243 return 0;
244}
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:2193
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 252 of file func_groupcount.c.

254{
255 struct ast_group_info *gi = NULL;
256 char tmp1[1024] = "";
257 char tmp2[1024] = "";
258
259 if (!chan)
260 return -1;
261
263
264 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
265 if (gi->chan != chan)
266 continue;
267 if (!ast_strlen_zero(tmp1)) {
268 ast_copy_string(tmp2, tmp1, sizeof(tmp2));
269 if (!ast_strlen_zero(gi->category))
270 snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
271 else
272 snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
273 } else {
274 if (!ast_strlen_zero(gi->category))
275 snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
276 else
277 snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
278 }
279 }
280
282
283 ast_copy_string(buf, tmp1, len);
284
285 return 0;
286}

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 160 of file func_groupcount.c.

163{
164 char group[80] = "";
165 char category[80] = "";
166
167 ast_app_group_split_group(data, group, sizeof(group), category,
168 sizeof(category));
169
170 if (!ast_strlen_zero(group)) {
171 int count;
172 count = ast_app_group_match_get_count(group, category);
173 snprintf(buf, len, "%d", count);
174 return 0;
175 }
176
177 return -1;
178}
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:2260

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 306 of file func_groupcount.c.

307{
308 int res = 0;
309
314
315 return res;
316}
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:1562

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 294 of file func_groupcount.c.

295{
296 int res = 0;
297
302
303 return res;
304}
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 = ASTERISK_GPL_KEY , .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 318 of file func_groupcount.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 318 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 154 of file func_groupcount.c.

154 {
155 .name = "GROUP_COUNT",
157 .read_max = 12,
158};

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 246 of file func_groupcount.c.

246 {
247 .name = "GROUP",
248 .read = group_function_read,
249 .write = group_function_write,
250};

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 288 of file func_groupcount.c.

288 {
289 .name = "GROUP_LIST",
291 .write = NULL,
292};

Referenced by load_module(), and unload_module().

◆ group_match_count_function

struct ast_custom_function group_match_count_function
static

Definition at line 180 of file func_groupcount.c.

180 {
181 .name = "GROUP_MATCH_COUNT",
183 .read_max = 12,
184 .write = NULL,
185};
static int group_match_count_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)

Referenced by load_module(), and unload_module().