Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


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"

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static 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

static void __reg_module ( void  )
static

Definition at line 308 of file func_groupcount.c.

static void __unreg_module ( void  )
static

Definition at line 308 of file func_groupcount.c.

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

Definition at line 100 of file func_groupcount.c.

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_copy_string(), AST_LIST_NEXT, ast_log(), ast_strlen_zero(), ast_group_info::category, ast_group_info::chan, ast_group_info::group, ast_group_info::group_list, LOG_NOTICE, LOG_WARNING, and ast_channel::name.

102 {
103  int ret = -1;
104  int count = -1;
105  char group[80] = "", category[80] = "";
106 
107  if (!chan) {
108  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
109  return -1;
110  }
111 
112  ast_app_group_split_group(data, group, sizeof(group), category,
113  sizeof(category));
114 
115  /* If no group has been provided let's find one */
116  if (ast_strlen_zero(group)) {
117  struct ast_group_info *gi = NULL;
118 
120  for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
121  if (gi->chan != chan)
122  continue;
123  if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))
124  break;
125  }
126  if (gi) {
127  ast_copy_string(group, gi->group, sizeof(group));
128  if (!ast_strlen_zero(gi->category))
129  ast_copy_string(category, gi->category, sizeof(category));
130  }
132  }
133 
134  if ((count = ast_app_group_get_count(group, category)) == -1) {
135  ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name);
136  } else {
137  snprintf(buf, len, "%d", count);
138  ret = 0;
139  }
140 
141  return ret;
142 }
channel group info
Definition: channel.h:2459
#define LOG_WARNING
Definition: logger.h:144
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
const char * data
Definition: channel.h:755
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: app.c:1195
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char * group
Definition: channel.h:2462
struct ast_channel * chan
Definition: channel.h:2460
struct ast_group_info * ast_app_group_list_head(void)
Get the head of the group count list.
Definition: app.c:1375
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
char * category
Definition: channel.h:2461
int ast_app_group_list_unlock(void)
Unlock the group count list.
Definition: app.c:1380
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
struct ast_group_info::@157 group_list
int ast_app_group_get_count(const char *group, const char *category)
Get the current channel count of the specified group and category.
Definition: app.c:1269
int ast_app_group_list_rdlock(void)
Read Lock the group count list.
Definition: app.c:1370
static int group_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 177 of file func_groupcount.c.

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(), ast_group_info::category, ast_group_info::chan, ast_group_info::group, ast_group_info::group_list, and LOG_WARNING.

179 {
180  int ret = -1;
181  struct ast_group_info *gi = NULL;
182 
183  if (!chan) {
184  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
185  return -1;
186  }
187 
189 
190  for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
191  if (gi->chan != chan)
192  continue;
193  if (ast_strlen_zero(data))
194  break;
195  if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
196  break;
197  }
198 
199  if (gi) {
200  ast_copy_string(buf, gi->group, len);
201  ret = 0;
202  }
203 
205 
206  return ret;
207 }
channel group info
Definition: channel.h:2459
#define LOG_WARNING
Definition: logger.h:144
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char * group
Definition: channel.h:2462
struct ast_channel * chan
Definition: channel.h:2460
struct ast_group_info * ast_app_group_list_head(void)
Get the head of the group count list.
Definition: app.c:1375
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
char * category
Definition: channel.h:2461
int ast_app_group_list_unlock(void)
Unlock the group count list.
Definition: app.c:1380
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
struct ast_group_info::@157 group_list
int ast_app_group_list_rdlock(void)
Read Lock the group count list.
Definition: app.c:1370
static int group_function_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

Definition at line 209 of file func_groupcount.c.

References ast_app_group_set_channel(), ast_copy_string(), ast_log(), ast_strlen_zero(), and LOG_WARNING.

211 {
212  char grpcat[256];
213 
214  if (!chan) {
215  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
216  return -1;
217  }
218 
219  if (!value) {
220  return -1;
221  }
222 
223  if (!ast_strlen_zero(data)) {
224  snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
225  } else {
226  ast_copy_string(grpcat, value, sizeof(grpcat));
227  }
228 
229  if (ast_app_group_set_channel(chan, grpcat))
231  "Setting a group requires an argument (group name)\n");
232 
233  return 0;
234 }
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: app.c:1222
#define LOG_WARNING
Definition: logger.h:144
int value
Definition: syslog.c:39
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static int group_list_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 242 of file func_groupcount.c.

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(), ast_group_info::category, ast_group_info::chan, ast_group_info::group, and ast_group_info::group_list.

244 {
245  struct ast_group_info *gi = NULL;
246  char tmp1[1024] = "";
247  char tmp2[1024] = "";
248 
249  if (!chan)
250  return -1;
251 
253 
254  for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
255  if (gi->chan != chan)
256  continue;
257  if (!ast_strlen_zero(tmp1)) {
258  ast_copy_string(tmp2, tmp1, sizeof(tmp2));
259  if (!ast_strlen_zero(gi->category))
260  snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
261  else
262  snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
263  } else {
264  if (!ast_strlen_zero(gi->category))
265  snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
266  else
267  snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
268  }
269  }
270 
272 
273  ast_copy_string(buf, tmp1, len);
274 
275  return 0;
276 }
channel group info
Definition: channel.h:2459
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char * group
Definition: channel.h:2462
struct ast_channel * chan
Definition: channel.h:2460
struct ast_group_info * ast_app_group_list_head(void)
Get the head of the group count list.
Definition: app.c:1375
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * category
Definition: channel.h:2461
int ast_app_group_list_unlock(void)
Unlock the group count list.
Definition: app.c:1380
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
struct ast_group_info::@157 group_list
int ast_app_group_list_rdlock(void)
Read Lock the group count list.
Definition: app.c:1370
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 150 of file func_groupcount.c.

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

153 {
154  int count;
155  char group[80] = "";
156  char category[80] = "";
157 
158  ast_app_group_split_group(data, group, sizeof(group), category,
159  sizeof(category));
160 
161  if (!ast_strlen_zero(group)) {
162  count = ast_app_group_match_get_count(group, category);
163  snprintf(buf, len, "%d", count);
164  return 0;
165  }
166 
167  return -1;
168 }
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: app.c:1289
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: app.c:1195
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * category
Definition: channel.h:2461
static int load_module ( void  )
static

Definition at line 296 of file func_groupcount.c.

References ast_custom_function_register.

297 {
298  int res = 0;
299 
304 
305  return res;
306 }
static struct ast_custom_function group_count_function
static struct ast_custom_function group_match_count_function
static struct ast_custom_function group_function
static struct ast_custom_function group_list_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
static int unload_module ( void  )
static

Definition at line 284 of file func_groupcount.c.

References ast_custom_function_unregister().

285 {
286  int res = 0;
287 
292 
293  return res;
294 }
static struct ast_custom_function group_count_function
static struct ast_custom_function group_match_count_function
static struct ast_custom_function group_function
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
static struct ast_custom_function group_list_function

Variable Documentation

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 308 of file func_groupcount.c.

Definition at line 308 of file func_groupcount.c.

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

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

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

struct ast_custom_function group_match_count_function
static

Definition at line 170 of file func_groupcount.c.