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