Wed Oct 28 11:52:35 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"

Include dependency graph for func_groupcount.c:

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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static 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 238 of file func_groupcount.c.

static void __unreg_module ( void   )  [static]

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

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

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

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

00117 {
00118    int ret = -1;
00119    struct ast_group_info *gi = NULL;
00120    
00121    ast_app_group_list_rdlock();
00122    
00123    for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_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       ret = 0;
00135    }
00136    
00137    ast_app_group_list_unlock();
00138    
00139    return ret;
00140 }

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

Definition at line 142 of file func_groupcount.c.

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

00144 {
00145    char grpcat[256];
00146 
00147    if (!ast_strlen_zero(data)) {
00148       snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
00149    } else {
00150       ast_copy_string(grpcat, value, sizeof(grpcat));
00151    }
00152 
00153    if (ast_app_group_set_channel(chan, grpcat))
00154       ast_log(LOG_WARNING,
00155             "Setting a group requires an argument (group name)\n");
00156 
00157    return 0;
00158 }

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

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

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

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

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

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

static int load_module ( void   )  [static]

Definition at line 226 of file func_groupcount.c.

References ast_custom_function_register.

00227 {
00228    int res = 0;
00229 
00230    res |= ast_custom_function_register(&group_count_function);
00231    res |= ast_custom_function_register(&group_match_count_function);
00232    res |= ast_custom_function_register(&group_list_function);
00233    res |= ast_custom_function_register(&group_function);
00234 
00235    return res;
00236 }

static int unload_module ( void   )  [static]

Definition at line 214 of file func_groupcount.c.

References ast_custom_function_unregister().

00215 {
00216    int res = 0;
00217 
00218    res |= ast_custom_function_unregister(&group_count_function);
00219    res |= ast_custom_function_unregister(&group_match_count_function);
00220    res |= ast_custom_function_unregister(&group_list_function);
00221    res |= ast_custom_function_unregister(&group_function);
00222 
00223    return res;
00224 }


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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 238 of file func_groupcount.c.

Definition at line 238 of file func_groupcount.c.

Definition at line 73 of file func_groupcount.c.

Definition at line 160 of file func_groupcount.c.

Definition at line 205 of file func_groupcount.c.

Definition at line 103 of file func_groupcount.c.


Generated on Wed Oct 28 11:52:35 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6