Mon Mar 19 11:30:48 2012

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_LOAD_ORDER , .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 = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
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 293 of file func_groupcount.c.

static void __unreg_module ( void   )  [static]

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

00102 {
00103    int ret = -1;
00104    int count = -1;
00105    char group[80] = "", category[80] = "";
00106 
00107    ast_app_group_split_group(data, group, sizeof(group), category,
00108               sizeof(category));
00109 
00110    /* If no group has been provided let's find one */
00111    if (ast_strlen_zero(group)) {
00112       struct ast_group_info *gi = NULL;
00113 
00114       ast_app_group_list_rdlock();
00115       for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
00116          if (gi->chan != chan)
00117             continue;
00118          if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))
00119             break;
00120       }
00121       if (gi) {
00122          ast_copy_string(group, gi->group, sizeof(group));
00123          if (!ast_strlen_zero(gi->category))
00124             ast_copy_string(category, gi->category, sizeof(category));
00125       }
00126       ast_app_group_list_unlock();
00127    }
00128 
00129    if ((count = ast_app_group_get_count(group, category)) == -1) {
00130       ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name);
00131    } else {
00132       snprintf(buf, len, "%d", count);
00133       ret = 0;
00134    }
00135 
00136    return ret;
00137 }

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

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

00174 {
00175    int ret = -1;
00176    struct ast_group_info *gi = NULL;
00177    
00178    ast_app_group_list_rdlock();
00179    
00180    for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
00181       if (gi->chan != chan)
00182          continue;
00183       if (ast_strlen_zero(data))
00184          break;
00185       if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
00186          break;
00187    }
00188    
00189    if (gi) {
00190       ast_copy_string(buf, gi->group, len);
00191       ret = 0;
00192    }
00193    
00194    ast_app_group_list_unlock();
00195    
00196    return ret;
00197 }

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

Definition at line 199 of file func_groupcount.c.

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

00201 {
00202    char grpcat[256];
00203 
00204    if (!value) {
00205       return -1;
00206    }
00207 
00208    if (!ast_strlen_zero(data)) {
00209       snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
00210    } else {
00211       ast_copy_string(grpcat, value, sizeof(grpcat));
00212    }
00213 
00214    if (ast_app_group_set_channel(chan, grpcat))
00215       ast_log(LOG_WARNING,
00216             "Setting a group requires an argument (group name)\n");
00217 
00218    return 0;
00219 }

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

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

00229 {
00230    struct ast_group_info *gi = NULL;
00231    char tmp1[1024] = "";
00232    char tmp2[1024] = "";
00233 
00234    if (!chan)
00235       return -1;
00236 
00237    ast_app_group_list_rdlock();
00238 
00239    for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
00240       if (gi->chan != chan)
00241          continue;
00242       if (!ast_strlen_zero(tmp1)) {
00243          ast_copy_string(tmp2, tmp1, sizeof(tmp2));
00244          if (!ast_strlen_zero(gi->category))
00245             snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
00246          else
00247             snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
00248       } else {
00249          if (!ast_strlen_zero(gi->category))
00250             snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
00251          else
00252             snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
00253       }
00254    }
00255    
00256    ast_app_group_list_unlock();
00257 
00258    ast_copy_string(buf, tmp1, len);
00259 
00260    return 0;
00261 }

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

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

00148 {
00149    int count;
00150    char group[80] = "";
00151    char category[80] = "";
00152 
00153    ast_app_group_split_group(data, group, sizeof(group), category,
00154               sizeof(category));
00155 
00156    if (!ast_strlen_zero(group)) {
00157       count = ast_app_group_match_get_count(group, category);
00158       snprintf(buf, len, "%d", count);
00159       return 0;
00160    }
00161 
00162    return -1;
00163 }

static int load_module ( void   )  [static]

Definition at line 281 of file func_groupcount.c.

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

00282 {
00283    int res = 0;
00284 
00285    res |= ast_custom_function_register(&group_count_function);
00286    res |= ast_custom_function_register(&group_match_count_function);
00287    res |= ast_custom_function_register(&group_list_function);
00288    res |= ast_custom_function_register(&group_function);
00289 
00290    return res;
00291 }

static int unload_module ( void   )  [static]

Definition at line 269 of file func_groupcount.c.

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

00270 {
00271    int res = 0;
00272 
00273    res |= ast_custom_function_unregister(&group_count_function);
00274    res |= ast_custom_function_unregister(&group_match_count_function);
00275    res |= ast_custom_function_unregister(&group_list_function);
00276    res |= ast_custom_function_unregister(&group_function);
00277 
00278    return res;
00279 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 293 of file func_groupcount.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 293 of file func_groupcount.c.

struct ast_custom_function group_count_function [static]

Initial value:

 {
   .name = "GROUP_COUNT",
   .read = group_count_function_read,
   .read_max = 12,
}

Definition at line 139 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_function [static]

Initial value:

 {
   .name = "GROUP",
   .read = group_function_read,
   .write = group_function_write,
}

Definition at line 221 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_list_function [static]

Initial value:

 {
   .name = "GROUP_LIST",
   .read = group_list_function_read,
   .write = NULL,
}

Definition at line 263 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_match_count_function [static]

Definition at line 165 of file func_groupcount.c.

Referenced by load_module(), and unload_module().


Generated on Mon Mar 19 11:30:48 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7