Thu Jul 9 13:41:20 2009

Asterisk developer's documentation


func_groupcount.c File Reference

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

static void __reg_module (void)
static void __unreg_module (void)
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_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Channel group dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, }
static const struct ast_module_infoast_module_info = &__mod_info
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


Detailed Description

Channel group related dialplan functions.

Definition in file func_groupcount.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 231 of file func_groupcount.c.

static void __unreg_module ( void   )  [static]

Definition at line 231 of file func_groupcount.c.

static int group_count_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 34 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, chan, ast_group_info::chan, ast_group_info::group, ast_group_info::group_list, LOG_NOTICE, and ast_channel::name.

00036 {
00037    int count = -1;
00038    char group[80] = "", category[80] = "";
00039 
00040    ast_app_group_split_group(data, group, sizeof(group), category,
00041               sizeof(category));
00042 
00043    /* If no group has been provided let's find one */
00044    if (ast_strlen_zero(group)) {
00045       struct ast_group_info *gi = NULL;
00046 
00047       ast_app_group_list_rdlock();
00048       for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
00049          if (gi->chan != chan)
00050             continue;
00051          if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))
00052             break;
00053       }
00054       if (gi) {
00055          ast_copy_string(group, gi->group, sizeof(group));
00056          if (!ast_strlen_zero(gi->category))
00057             ast_copy_string(category, gi->category, sizeof(category));
00058       }
00059       ast_app_group_list_unlock();
00060    }
00061 
00062    if ((count = ast_app_group_get_count(group, category)) == -1)
00063       ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name);
00064    else
00065       snprintf(buf, len, "%d", count);
00066 
00067    return 0;
00068 }

static int group_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 111 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, chan, ast_group_info::chan, ast_group_info::group, and ast_group_info::group_list.

00113 {
00114    struct ast_group_info *gi = NULL;
00115    
00116    ast_app_group_list_rdlock();
00117    
00118    for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
00119       if (gi->chan != chan)
00120          continue;
00121       if (ast_strlen_zero(data))
00122          break;
00123       if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
00124          break;
00125    }
00126    
00127    if (gi)
00128       ast_copy_string(buf, gi->group, len);
00129    
00130    ast_app_group_list_unlock();
00131    
00132    return 0;
00133 }

static int group_function_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
) [static]

Definition at line 135 of file func_groupcount.c.

References ast_app_group_set_channel(), ast_copy_string(), ast_log(), ast_strlen_zero(), chan, and LOG_WARNING.

00137 {
00138    char grpcat[256];
00139 
00140    if (!ast_strlen_zero(data)) {
00141       snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
00142    } else {
00143       ast_copy_string(grpcat, value, sizeof(grpcat));
00144    }
00145 
00146    if (ast_app_group_set_channel(chan, grpcat))
00147       ast_log(LOG_WARNING,
00148             "Setting a group requires an argument (group name)\n");
00149 
00150    return 0;
00151 }

static int group_list_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 162 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, chan, ast_group_info::group, and ast_group_info::group_list.

00164 {
00165    struct ast_group_info *gi = NULL;
00166    char tmp1[1024] = "";
00167    char tmp2[1024] = "";
00168 
00169    if (!chan)
00170       return -1;
00171 
00172    ast_app_group_list_rdlock();
00173 
00174    for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
00175       if (gi->chan != chan)
00176          continue;
00177       if (!ast_strlen_zero(tmp1)) {
00178          ast_copy_string(tmp2, tmp1, sizeof(tmp2));
00179          if (!ast_strlen_zero(gi->category))
00180             snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
00181          else
00182             snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
00183       } else {
00184          if (!ast_strlen_zero(gi->category))
00185             snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
00186          else
00187             snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
00188       }
00189    }
00190    
00191    ast_app_group_list_unlock();
00192 
00193    ast_copy_string(buf, tmp1, len);
00194 
00195    return 0;
00196 }

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 80 of file func_groupcount.c.

References ast_app_group_match_get_count(), ast_app_group_split_group(), and ast_strlen_zero().

00083 {
00084    int count;
00085    char group[80] = "";
00086    char category[80] = "";
00087 
00088    ast_app_group_split_group(data, group, sizeof(group), category,
00089               sizeof(category));
00090 
00091    if (!ast_strlen_zero(group)) {
00092       count = ast_app_group_match_get_count(group, category);
00093       snprintf(buf, len, "%d", count);
00094    }
00095 
00096    return 0;
00097 }

static int load_module ( void   )  [static]

Definition at line 219 of file func_groupcount.c.

References ast_custom_function_register, group_count_function, group_function, group_list_function, and group_match_count_function.

00220 {
00221    int res = 0;
00222 
00223    res |= ast_custom_function_register(&group_count_function);
00224    res |= ast_custom_function_register(&group_match_count_function);
00225    res |= ast_custom_function_register(&group_list_function);
00226    res |= ast_custom_function_register(&group_function);
00227 
00228    return res;
00229 }

static int unload_module ( void   )  [static]

Definition at line 207 of file func_groupcount.c.

References ast_custom_function_unregister(), group_count_function, group_function, group_list_function, and group_match_count_function.

00208 {
00209    int res = 0;
00210 
00211    res |= ast_custom_function_unregister(&group_count_function);
00212    res |= ast_custom_function_unregister(&group_match_count_function);
00213    res |= ast_custom_function_unregister(&group_list_function);
00214    res |= ast_custom_function_unregister(&group_function);
00215 
00216    return res;
00217 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Channel group dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static]

Definition at line 231 of file func_groupcount.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 231 of file func_groupcount.c.

struct ast_custom_function group_count_function [static]

Definition at line 70 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_function [static]

Definition at line 153 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_list_function [static]

Definition at line 198 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_match_count_function [static]

Definition at line 99 of file func_groupcount.c.

Referenced by load_module(), and unload_module().


Generated on Thu Jul 9 13:41:20 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7