Wed Aug 18 22:34:24 2010

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 = "a9c98e5d177805051735cb5b0b16b0a0" , .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 242 of file func_groupcount.c.

static void __unreg_module ( void   )  [static]

Definition at line 242 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 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, chan, 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(), chan, and LOG_WARNING.

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

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

Definition at line 173 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.

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

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

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

00231 {
00232    int res = 0;
00233 
00234    res |= ast_custom_function_register(&group_count_function);
00235    res |= ast_custom_function_register(&group_match_count_function);
00236    res |= ast_custom_function_register(&group_list_function);
00237    res |= ast_custom_function_register(&group_function);
00238 
00239    return res;
00240 }

static int unload_module ( void   )  [static]

Definition at line 218 of file func_groupcount.c.

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

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


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

Definition at line 242 of file func_groupcount.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 242 of file func_groupcount.c.

struct ast_custom_function group_count_function [static]

Definition at line 73 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_function [static]

Definition at line 164 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_list_function [static]

Definition at line 209 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_match_count_function [static]

Definition at line 103 of file func_groupcount.c.

Referenced by load_module(), and unload_module().


Generated on Wed Aug 18 22:34:24 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7