#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.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 | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Channel group dialplan functions") | |
static int | group_count_function_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) |
static int | group_function_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) |
static int | group_function_write (struct ast_channel *chan, char *cmd, char *data, const char *value) |
static int | group_list_function_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) |
static int | group_match_count_function_read (struct ast_channel *chan, 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 |
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, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 40 of file func_groupcount.c.
References ast_app_group_get_count(), ast_app_group_list_head(), ast_app_group_list_lock(), ast_app_group_list_unlock(), ast_app_group_split_group(), AST_LIST_NEXT, ast_log(), ast_strlen_zero(), ast_group_info::category, ast_group_info::chan, ast_group_info::group, group, and LOG_NOTICE.
00042 { 00043 int count = -1; 00044 char group[80] = "", category[80] = ""; 00045 00046 ast_app_group_split_group(data, group, sizeof(group), category, 00047 sizeof(category)); 00048 00049 /* If no group has been provided let's find one */ 00050 if (ast_strlen_zero(group)) { 00051 struct ast_group_info *gi = NULL; 00052 00053 ast_app_group_list_lock(); 00054 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, list)) { 00055 if (gi->chan != chan) 00056 continue; 00057 if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category))) 00058 break; 00059 } 00060 if (gi) { 00061 ast_copy_string(group, gi->group, sizeof(group)); 00062 if (!ast_strlen_zero(gi->category)) 00063 ast_copy_string(category, gi->category, sizeof(category)); 00064 } 00065 ast_app_group_list_unlock(); 00066 } 00067 00068 if ((count = ast_app_group_get_count(group, category)) == -1) 00069 ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name); 00070 else 00071 snprintf(buf, len, "%d", count); 00072 00073 return 0; 00074 }
static int group_function_read | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 117 of file func_groupcount.c.
References ast_app_group_list_head(), ast_app_group_list_lock(), ast_app_group_list_unlock(), AST_LIST_NEXT, ast_strlen_zero(), ast_group_info::category, ast_group_info::chan, and ast_group_info::group.
00119 { 00120 struct ast_group_info *gi = NULL; 00121 00122 ast_app_group_list_lock(); 00123 00124 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, list)) { 00125 if (gi->chan != chan) 00126 continue; 00127 if (ast_strlen_zero(data)) 00128 break; 00129 if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data)) 00130 break; 00131 } 00132 00133 if (gi) 00134 ast_copy_string(buf, gi->group, len); 00135 00136 ast_app_group_list_unlock(); 00137 00138 return 0; 00139 }
static int group_function_write | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 141 of file func_groupcount.c.
References ast_app_group_set_channel(), ast_log(), ast_strlen_zero(), ast_group_info::chan, and LOG_WARNING.
00143 { 00144 char grpcat[256]; 00145 00146 if (!ast_strlen_zero(data)) { 00147 snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data); 00148 } else { 00149 ast_copy_string(grpcat, value, sizeof(grpcat)); 00150 } 00151 00152 if (ast_app_group_set_channel(chan, grpcat)) 00153 ast_log(LOG_WARNING, 00154 "Setting a group requires an argument (group name)\n"); 00155 00156 return 0; 00157 }
static int group_list_function_read | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 168 of file func_groupcount.c.
References ast_app_group_list_head(), ast_app_group_list_lock(), ast_app_group_list_unlock(), AST_LIST_NEXT, ast_strlen_zero(), ast_group_info::category, ast_group_info::chan, and ast_group_info::group.
00170 { 00171 struct ast_group_info *gi = NULL; 00172 char tmp1[1024] = ""; 00173 char tmp2[1024] = ""; 00174 00175 if (!chan) 00176 return -1; 00177 00178 ast_app_group_list_lock(); 00179 00180 for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, list)) { 00181 if (gi->chan != chan) 00182 continue; 00183 if (!ast_strlen_zero(tmp1)) { 00184 ast_copy_string(tmp2, tmp1, sizeof(tmp2)); 00185 if (!ast_strlen_zero(gi->category)) 00186 snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category); 00187 else 00188 snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group); 00189 } else { 00190 if (!ast_strlen_zero(gi->category)) 00191 snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category); 00192 else 00193 snprintf(tmp1, sizeof(tmp1), "%s", gi->group); 00194 } 00195 } 00196 00197 ast_app_group_list_unlock(); 00198 00199 ast_copy_string(buf, tmp1, len); 00200 00201 return 0; 00202 }
static int group_match_count_function_read | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 86 of file func_groupcount.c.
References ast_app_group_match_get_count(), ast_app_group_split_group(), ast_strlen_zero(), and group.
00089 { 00090 int count; 00091 char group[80] = ""; 00092 char category[80] = ""; 00093 00094 ast_app_group_split_group(data, group, sizeof(group), category, 00095 sizeof(category)); 00096 00097 if (!ast_strlen_zero(group)) { 00098 count = ast_app_group_match_get_count(group, category); 00099 snprintf(buf, len, "%d", count); 00100 } 00101 00102 return 0; 00103 }
static int load_module | ( | void | ) | [static] |
Definition at line 225 of file func_groupcount.c.
References ast_custom_function_register(), group_count_function, group_function, group_list_function, and group_match_count_function.
00226 { 00227 int res = 0; 00228 00229 res |= ast_custom_function_register(&group_count_function); 00230 res |= ast_custom_function_register(&group_match_count_function); 00231 res |= ast_custom_function_register(&group_list_function); 00232 res |= ast_custom_function_register(&group_function); 00233 00234 return res; 00235 }
static int unload_module | ( | void | ) | [static] |
Definition at line 213 of file func_groupcount.c.
References ast_custom_function_unregister(), group_count_function, group_function, group_list_function, and group_match_count_function.
00214 { 00215 int res = 0; 00216 00217 res |= ast_custom_function_unregister(&group_count_function); 00218 res |= ast_custom_function_unregister(&group_match_count_function); 00219 res |= ast_custom_function_unregister(&group_list_function); 00220 res |= ast_custom_function_unregister(&group_function); 00221 00222 return res; 00223 }
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 [static] |