#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>
#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
Include dependency graph for app_groupcount.c:
Go to the source code of this file.
Defines | |
#define | FORMAT_STRING "%-25s %-20s %-20s\n" |
Functions | |
char * | description (void) |
Provides a description of the module. | |
static int | group_check_exec (struct ast_channel *chan, void *data) |
static int | group_count_exec (struct ast_channel *chan, void *data) |
static int | group_match_count_exec (struct ast_channel *chan, void *data) |
static int | group_set_exec (struct ast_channel *chan, void *data) |
static int | group_show_channels (int fd, int argc, char *argv[]) |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static char * | app_group_check = "CheckGroup" |
static char * | app_group_count = "GetGroupCount" |
static char * | app_group_match_count = "GetGroupMatchCount" |
static char * | app_group_set = "SetGroup" |
static struct ast_cli_entry | cli_show_channels |
static char * | group_check_descrip |
static char * | group_check_synopsis = "Check the channel count of a group against a limit" |
static char * | group_count_descrip |
static char * | group_count_synopsis = "Get the channel count of a group" |
static char * | group_match_count_descrip |
static char * | group_match_count_synopsis = "Get the channel count of all groups that match a pattern" |
static char * | group_set_descrip |
static char * | group_set_synopsis = "Set the channel's group" |
LOCAL_USER_DECL | |
static char | show_channels_usage [] |
STANDARD_LOCAL_USER | |
static char * | tdesc = "Group Management Routines" |
Definition in file app_groupcount.c.
|
|
|
Provides a description of the module.
Definition at line 325 of file app_groupcount.c. References tdesc. 00326 { 00327 return tdesc; 00328 }
|
|
Definition at line 135 of file app_groupcount.c. References AST_APP_ARG, ast_app_group_get_count(), ast_app_group_split_group(), AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_WARNING, option_priority_jumping, parse(), pbx_builtin_getvar_helper(), and pbx_builtin_setvar_helper(). Referenced by load_module(). 00136 { 00137 int res = 0; 00138 int max, count; 00139 struct localuser *u; 00140 char limit[80]=""; 00141 char category[80]=""; 00142 static int deprecation_warning = 0; 00143 char *parse; 00144 int priority_jump = 0; 00145 AST_DECLARE_APP_ARGS(args, 00146 AST_APP_ARG(max); 00147 AST_APP_ARG(options); 00148 ); 00149 00150 LOCAL_USER_ADD(u); 00151 00152 if (!deprecation_warning) { 00153 ast_log(LOG_WARNING, "The CheckGroup application has been deprecated, please use a combination of the GotoIf application and the GROUP_COUNT() function.\n"); 00154 deprecation_warning = 1; 00155 } 00156 00157 if (!(parse = ast_strdupa(data))) { 00158 ast_log(LOG_WARNING, "Memory Error!\n"); 00159 LOCAL_USER_REMOVE(u); 00160 return -1; 00161 } 00162 00163 AST_STANDARD_APP_ARGS(args, parse); 00164 00165 if (args.options) { 00166 if (strchr(args.options, 'j')) 00167 priority_jump = 1; 00168 } 00169 00170 if (ast_strlen_zero(args.max)) { 00171 ast_log(LOG_WARNING, "CheckGroup requires an argument(max[@category][|options])\n"); 00172 return res; 00173 } 00174 00175 ast_app_group_split_group(args.max, limit, sizeof(limit), category, sizeof(category)); 00176 00177 if ((sscanf(limit, "%d", &max) == 1) && (max > -1)) { 00178 count = ast_app_group_get_count(pbx_builtin_getvar_helper(chan, category), category); 00179 if (count > max) { 00180 pbx_builtin_setvar_helper(chan, "CHECKGROUPSTATUS", "OVERMAX"); 00181 if (priority_jump || option_priority_jumping) { 00182 if (!ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) 00183 res = -1; 00184 } 00185 } else 00186 pbx_builtin_setvar_helper(chan, "CHECKGROUPSTATUS", "OK"); 00187 } else 00188 ast_log(LOG_WARNING, "CheckGroup requires a positive integer argument (max)\n"); 00189 00190 LOCAL_USER_REMOVE(u); 00191 return res; 00192 }
|
|
Definition at line 51 of file app_groupcount.c. References ast_app_group_get_count(), ast_app_group_split_group(), ast_log(), ast_strlen_zero(), group, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_WARNING, pbx_builtin_getvar_helper(), and pbx_builtin_setvar_helper(). Referenced by load_module(). 00052 { 00053 int res = 0; 00054 int count; 00055 struct localuser *u; 00056 char group[80] = ""; 00057 char category[80] = ""; 00058 char ret[80] = ""; 00059 char *grp; 00060 static int deprecation_warning = 0; 00061 00062 LOCAL_USER_ADD(u); 00063 00064 if (!deprecation_warning) { 00065 ast_log(LOG_WARNING, "The GetGroupCount application has been deprecated, please use the GROUP_COUNT function.\n"); 00066 deprecation_warning = 1; 00067 } 00068 00069 ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)); 00070 00071 if (ast_strlen_zero(group)) { 00072 grp = pbx_builtin_getvar_helper(chan, category); 00073 strncpy(group, grp, sizeof(group) - 1); 00074 } 00075 00076 count = ast_app_group_get_count(group, category); 00077 snprintf(ret, sizeof(ret), "%d", count); 00078 pbx_builtin_setvar_helper(chan, "GROUPCOUNT", ret); 00079 00080 LOCAL_USER_REMOVE(u); 00081 00082 return res; 00083 }
|
|
Definition at line 85 of file app_groupcount.c. References ast_app_group_match_get_count(), ast_app_group_split_group(), ast_log(), ast_strlen_zero(), group, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_WARNING, and pbx_builtin_setvar_helper(). Referenced by load_module(). 00086 { 00087 int res = 0; 00088 int count; 00089 struct localuser *u; 00090 char group[80] = ""; 00091 char category[80] = ""; 00092 char ret[80] = ""; 00093 static int deprecation_warning = 0; 00094 00095 LOCAL_USER_ADD(u); 00096 00097 if (!deprecation_warning) { 00098 ast_log(LOG_WARNING, "The GetGroupMatchCount application has been deprecated, please use the GROUP_MATCH_COUNT function.\n"); 00099 deprecation_warning = 1; 00100 } 00101 00102 ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)); 00103 00104 if (!ast_strlen_zero(group)) { 00105 count = ast_app_group_match_get_count(group, category); 00106 snprintf(ret, sizeof(ret), "%d", count); 00107 pbx_builtin_setvar_helper(chan, "GROUPCOUNT", ret); 00108 } 00109 00110 LOCAL_USER_REMOVE(u); 00111 00112 return res; 00113 }
|
|
Definition at line 115 of file app_groupcount.c. References ast_app_group_set_channel(), ast_log(), LOCAL_USER_ADD, LOCAL_USER_REMOVE, and LOG_WARNING. Referenced by load_module(). 00116 { 00117 int res = 0; 00118 struct localuser *u; 00119 static int deprecation_warning = 0; 00120 00121 LOCAL_USER_ADD(u); 00122 00123 if (!deprecation_warning) { 00124 ast_log(LOG_WARNING, "The SetGroup application has been deprecated, please use the GROUP() function.\n"); 00125 deprecation_warning = 1; 00126 } 00127 00128 if (ast_app_group_set_channel(chan, data)) 00129 ast_log(LOG_WARNING, "SetGroup requires an argument (group name)\n"); 00130 00131 LOCAL_USER_REMOVE(u); 00132 return res; 00133 }
|
|
Definition at line 194 of file app_groupcount.c. References ast_channel_walk_locked(), ast_cli(), AST_LIST_TRAVERSE, ast_mutex_unlock(), ast_var_name(), ast_var_value(), FORMAT_STRING, GROUP_CATEGORY_PREFIX, ast_channel::lock, ast_channel::name, RESULT_SHOWUSAGE, RESULT_SUCCESS, and ast_channel::varshead. 00195 { 00196 #define FORMAT_STRING "%-25s %-20s %-20s\n" 00197 00198 struct ast_channel *c = NULL; 00199 int numchans = 0; 00200 struct ast_var_t *current; 00201 struct varshead *headp; 00202 regex_t regexbuf; 00203 int havepattern = 0; 00204 00205 if (argc < 3 || argc > 4) 00206 return RESULT_SHOWUSAGE; 00207 00208 if (argc == 4) { 00209 if (regcomp(®exbuf, argv[3], REG_EXTENDED | REG_NOSUB)) 00210 return RESULT_SHOWUSAGE; 00211 havepattern = 1; 00212 } 00213 00214 ast_cli(fd, FORMAT_STRING, "Channel", "Group", "Category"); 00215 while ( (c = ast_channel_walk_locked(c)) != NULL) { 00216 headp=&c->varshead; 00217 AST_LIST_TRAVERSE(headp,current,entries) { 00218 if (!strncmp(ast_var_name(current), GROUP_CATEGORY_PREFIX "_", strlen(GROUP_CATEGORY_PREFIX) + 1)) { 00219 if (!havepattern || !regexec(®exbuf, ast_var_value(current), 0, NULL, 0)) { 00220 ast_cli(fd, FORMAT_STRING, c->name, ast_var_value(current), 00221 (ast_var_name(current) + strlen(GROUP_CATEGORY_PREFIX) + 1)); 00222 numchans++; 00223 } 00224 } else if (!strcmp(ast_var_name(current), GROUP_CATEGORY_PREFIX)) { 00225 if (!havepattern || !regexec(®exbuf, ast_var_value(current), 0, NULL, 0)) { 00226 ast_cli(fd, FORMAT_STRING, c->name, ast_var_value(current), "(default)"); 00227 numchans++; 00228 } 00229 } 00230 } 00231 numchans++; 00232 ast_mutex_unlock(&c->lock); 00233 } 00234 00235 if (havepattern) 00236 regfree(®exbuf); 00237 00238 ast_cli(fd, "%d active channel%s\n", numchans, (numchans != 1) ? "s" : ""); 00239 return RESULT_SUCCESS; 00240 #undef FORMAT_STRING 00241 }
|
|
Returns the ASTERISK_GPL_KEY. This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:
char *key(void) { return ASTERISK_GPL_KEY; }
Definition at line 337 of file app_groupcount.c. References ASTERISK_GPL_KEY. 00338 { 00339 return ASTERISK_GPL_KEY; 00340 }
|
|
|
Cleanup all module structures, sockets, etc. This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).
Definition at line 297 of file app_groupcount.c. References app_group_check, app_group_count, app_group_match_count, app_group_set, ast_cli_unregister(), ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS. 00298 { 00299 int res; 00300 00301 res = ast_cli_unregister(&cli_show_channels); 00302 res |= ast_unregister_application(app_group_count); 00303 res |= ast_unregister_application(app_group_set); 00304 res |= ast_unregister_application(app_group_check); 00305 res |= ast_unregister_application(app_group_match_count); 00306 00307 STANDARD_HANGUP_LOCALUSERS; 00308 00309 return res; 00310 }
|
|
Provides a usecount. This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.
Definition at line 330 of file app_groupcount.c. References STANDARD_USECOUNT. 00331 { 00332 int res; 00333 STANDARD_USECOUNT(res); 00334 return res; 00335 }
|
|
Definition at line 247 of file app_groupcount.c. Referenced by load_module(), and unload_module(). |
|
Definition at line 245 of file app_groupcount.c. Referenced by load_module(), and unload_module(). |
|
Definition at line 248 of file app_groupcount.c. Referenced by load_module(), and unload_module(). |
|
Definition at line 246 of file app_groupcount.c. Referenced by load_module(), and unload_module(). |
|
Initial value: { { "group", "show", "channels", NULL }, group_show_channels, "Show active channels with group(s)", show_channels_usage} Definition at line 294 of file app_groupcount.c. |
|
Definition at line 268 of file app_groupcount.c. Referenced by load_module(). |
|
Definition at line 252 of file app_groupcount.c. Referenced by load_module(). |
|
Definition at line 255 of file app_groupcount.c. Referenced by load_module(). |
|
Definition at line 250 of file app_groupcount.c. Referenced by load_module(). |
|
Definition at line 282 of file app_groupcount.c. Referenced by load_module(). |
|
Definition at line 253 of file app_groupcount.c. Referenced by load_module(). |
|
Initial value: "Usage: SetGroup(groupname[@category])\n" " Sets the channel group to the specified value. Equivalent to\n" "Set(GROUP=group). Always returns 0.\n" Definition at line 263 of file app_groupcount.c. Referenced by load_module(). |
|
Definition at line 251 of file app_groupcount.c. Referenced by load_module(). |
|
Definition at line 49 of file app_groupcount.c. |
|
Initial value: "Usage: group show channels [pattern]\n" " Lists all currently active channels with channel group(s) specified.\n Optional regular expression pattern is matched to group names for each channel.\n" Definition at line 290 of file app_groupcount.c. |
|
Definition at line 47 of file app_groupcount.c. |
|
Definition at line 243 of file app_groupcount.c. |