90 static void group_destroy(
void *vgroup)
96 static int group_hash_fn(
const void *obj,
const int flags)
98 const struct group *g = obj;
102 static int group_cmp_fn(
void *obj1,
void *name2,
int flags)
104 struct group *g1 = obj1, *g2 = name2;
112 static int entry_hash_fn(
const void *obj,
const int flags)
118 static int entry_cmp_fn(
void *obj1,
void *name2,
int flags)
128 static int dialgroup_read(
struct ast_channel *chan,
const char *cmd,
char *data,
char *buf,
size_t len)
131 struct group *grhead = ao2_find(group_container, data, 0);
134 int trunc_warning = 0;
138 if (!ast_strlen_zero(cmd)) {
139 ast_log(LOG_WARNING,
"No such dialgroup '%s'\n", data);
147 while ((entry = ao2_iterator_next(&i))) {
148 int tmp = strlen(entry->name);
150 if (len - bufused > tmp + 2) {
152 buf[bufused++] =
'&';
155 }
else if (trunc_warning++ == 0) {
156 if (!ast_strlen_zero(cmd)) {
157 ast_log(LOG_WARNING,
"Dialgroup '%s' is too large. Truncating list.\n", data);
172 static int dialgroup_refreshdb(
struct ast_channel *chan,
const char *cdialgroup)
174 int len = 500, res = 0;
188 if ((res = dialgroup_read(chan,
"", dialgroup, buf, len)) < 0) {
194 if (ast_strlen_zero(buf)) {
203 static int dialgroup_write(
struct ast_channel *chan,
const char *cmd,
char *data,
const char *cvalue)
205 struct group *grhead;
207 int j, needrefresh = 1;
220 if (!(grhead = ao2_find(group_container, args.group, 0))) {
222 grhead = ao2_alloc(
sizeof(*grhead), group_destroy);
226 entry_hash_fn, NULL, entry_cmp_fn);
227 if (!grhead->entries) {
235 if (ast_strlen_zero(args.op)) {
242 entry_hash_fn, NULL, entry_cmp_fn);
243 if (!grhead->entries) {
250 if (strcasecmp(args.op,
"add") == 0) {
251 for (j = 0; j < inter.argc; j++) {
253 if ((entry = ao2_find(grhead->entries, inter.faces[j], 0))) {
257 if ((entry = ao2_alloc(
sizeof(*entry), NULL))) {
262 ast_log(LOG_WARNING,
"Unable to add '%s' to dialgroup '%s'\n", inter.faces[j], grhead->name);
265 }
else if (strncasecmp(args.op,
"del", 3) == 0) {
266 for (j = 0; j < inter.argc; j++) {
267 if ((entry = ao2_find(grhead->entries, inter.faces[j],
OBJ_UNLINK))) {
270 ast_log(LOG_WARNING,
"Interface '%s' not found in dialgroup '%s'\n", inter.faces[j], grhead->name);
274 ast_log(LOG_ERROR,
"Unrecognized operation: %s\n", args.op);
280 dialgroup_refreshdb(chan, args.group);
288 .read = dialgroup_read,
289 .write = dialgroup_write,
292 static int unload_module(
void)
299 static int load_module(
void)
305 group_hash_fn, NULL, group_cmp_fn);
306 if (group_container) {
309 for (tmp = dbtree; tmp; tmp = tmp->next) {
311 if ((ptr = strrchr(groupname,
'/'))) {
313 dialgroup_write(NULL,
"", ptr, tmp->data);
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_realloc(p, len)
A wrapper for realloc()
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Data structure associated with a custom dialplan function.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define AST_MAX_EXTENSION
Core PBX routines and definitions.
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
#define ao2_unlink(container, obj)
Remove an object from a container.
struct ast_db_entry * ast_db_gettree(const char *family, const char *keytree)
Get a list of values within the astdb tree.
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the 'nonstandard' argument separation process for an application.
Module has failed to load, may be in an inconsistent state.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
Persistent data storage (akin to *doze registry)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ast_custom_function_register(acf)
Register a custom function.
#define AST_APP_ARG(name)
Define an application argument.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
#define ao2_link(container, obj)
Add an object to a container.