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 | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Channel group dialplan functions") | |
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_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 |
Channel group related dialplan functions.
Definition in file func_groupcount.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Channel group dialplan functions" | ||||
) |
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, LOG_NOTICE, and LOG_WARNING.
00102 { 00103 int ret = -1; 00104 int count = -1; 00105 char group[80] = "", category[80] = ""; 00106 00107 if (!chan) { 00108 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); 00109 return -1; 00110 } 00111 00112 ast_app_group_split_group(data, group, sizeof(group), category, 00113 sizeof(category)); 00114 00115 /* If no group has been provided let's find one */ 00116 if (ast_strlen_zero(group)) { 00117 struct ast_group_info *gi = NULL; 00118 00119 ast_app_group_list_rdlock(); 00120 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) { 00121 if (gi->chan != chan) 00122 continue; 00123 if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category))) 00124 break; 00125 } 00126 if (gi) { 00127 ast_copy_string(group, gi->group, sizeof(group)); 00128 if (!ast_strlen_zero(gi->category)) 00129 ast_copy_string(category, gi->category, sizeof(category)); 00130 } 00131 ast_app_group_list_unlock(); 00132 } 00133 00134 if ((count = ast_app_group_get_count(group, category)) == -1) { 00135 ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name); 00136 } else { 00137 snprintf(buf, len, "%d", count); 00138 ret = 0; 00139 } 00140 00141 return ret; 00142 }
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, and LOG_WARNING.
00179 { 00180 int ret = -1; 00181 struct ast_group_info *gi = NULL; 00182 00183 if (!chan) { 00184 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); 00185 return -1; 00186 } 00187 00188 ast_app_group_list_rdlock(); 00189 00190 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) { 00191 if (gi->chan != chan) 00192 continue; 00193 if (ast_strlen_zero(data)) 00194 break; 00195 if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data)) 00196 break; 00197 } 00198 00199 if (gi) { 00200 ast_copy_string(buf, gi->group, len); 00201 ret = 0; 00202 } 00203 00204 ast_app_group_list_unlock(); 00205 00206 return ret; 00207 }
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.
00211 { 00212 char grpcat[256]; 00213 00214 if (!chan) { 00215 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); 00216 return -1; 00217 } 00218 00219 if (!value) { 00220 return -1; 00221 } 00222 00223 if (!ast_strlen_zero(data)) { 00224 snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data); 00225 } else { 00226 ast_copy_string(grpcat, value, sizeof(grpcat)); 00227 } 00228 00229 if (ast_app_group_set_channel(chan, grpcat)) 00230 ast_log(LOG_WARNING, 00231 "Setting a group requires an argument (group name)\n"); 00232 00233 return 0; 00234 }
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, and ast_group_info::group.
00244 { 00245 struct ast_group_info *gi = NULL; 00246 char tmp1[1024] = ""; 00247 char tmp2[1024] = ""; 00248 00249 if (!chan) 00250 return -1; 00251 00252 ast_app_group_list_rdlock(); 00253 00254 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) { 00255 if (gi->chan != chan) 00256 continue; 00257 if (!ast_strlen_zero(tmp1)) { 00258 ast_copy_string(tmp2, tmp1, sizeof(tmp2)); 00259 if (!ast_strlen_zero(gi->category)) 00260 snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category); 00261 else 00262 snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group); 00263 } else { 00264 if (!ast_strlen_zero(gi->category)) 00265 snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category); 00266 else 00267 snprintf(tmp1, sizeof(tmp1), "%s", gi->group); 00268 } 00269 } 00270 00271 ast_app_group_list_unlock(); 00272 00273 ast_copy_string(buf, tmp1, len); 00274 00275 return 0; 00276 }
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().
00153 { 00154 int count; 00155 char group[80] = ""; 00156 char category[80] = ""; 00157 00158 ast_app_group_split_group(data, group, sizeof(group), category, 00159 sizeof(category)); 00160 00161 if (!ast_strlen_zero(group)) { 00162 count = ast_app_group_match_get_count(group, category); 00163 snprintf(buf, len, "%d", count); 00164 return 0; 00165 } 00166 00167 return -1; 00168 }
static int load_module | ( | void | ) | [static] |
Definition at line 296 of file func_groupcount.c.
References ast_custom_function_register.
00297 { 00298 int res = 0; 00299 00300 res |= ast_custom_function_register(&group_count_function); 00301 res |= ast_custom_function_register(&group_match_count_function); 00302 res |= ast_custom_function_register(&group_list_function); 00303 res |= ast_custom_function_register(&group_function); 00304 00305 return res; 00306 }
static int unload_module | ( | void | ) | [static] |
Definition at line 284 of file func_groupcount.c.
References ast_custom_function_unregister().
00285 { 00286 int res = 0; 00287 00288 res |= ast_custom_function_unregister(&group_count_function); 00289 res |= ast_custom_function_unregister(&group_match_count_function); 00290 res |= ast_custom_function_unregister(&group_list_function); 00291 res |= ast_custom_function_unregister(&group_function); 00292 00293 return res; 00294 }
struct ast_custom_function group_count_function [static] |
{ .name = "GROUP_COUNT", .read = group_count_function_read, .read_max = 12, }
Definition at line 144 of file func_groupcount.c.
struct ast_custom_function group_function [static] |
{ .name = "GROUP", .read = group_function_read, .write = group_function_write, }
Definition at line 236 of file func_groupcount.c.
struct ast_custom_function group_list_function [static] |
{ .name = "GROUP_LIST", .read = group_list_function_read, .write = NULL, }
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.