Sat Aug 6 00:39:56 2011

Asterisk developer's documentation


func_groupcount.c File Reference

Channel group related dialplan functions. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.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, char *cmd, char *data, char *buf, size_t len)
static int group_function_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int group_function_write (struct ast_channel *chan, char *cmd, char *data, const char *value)
static int group_list_function_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int group_match_count_function_read (struct ast_channel *chan, 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 | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .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 247 of file func_groupcount.c.

static void __unreg_module ( void   )  [static]

Definition at line 247 of file func_groupcount.c.

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

Definition at line 39 of file func_groupcount.c.

References ast_app_group_get_count(), ast_app_group_list_head(), ast_app_group_list_lock(), 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, group, LOG_NOTICE, and ast_channel::name.

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

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

Definition at line 120 of file func_groupcount.c.

References ast_app_group_list_head(), ast_app_group_list_lock(), ast_app_group_list_unlock(), ast_copy_string(), AST_LIST_NEXT, ast_strlen_zero(), ast_group_info::category, ast_group_info::chan, and ast_group_info::group.

00122 {
00123    int ret = -1;
00124    struct ast_group_info *gi = NULL;
00125    
00126    ast_app_group_list_lock();
00127    
00128    for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, list)) {
00129       if (gi->chan != chan)
00130          continue;
00131       if (ast_strlen_zero(data))
00132          break;
00133       if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
00134          break;
00135    }
00136    
00137    if (gi) {
00138       ast_copy_string(buf, gi->group, len);
00139       ret = 0;
00140    }
00141    
00142    ast_app_group_list_unlock();
00143    
00144    return ret;
00145 }

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

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

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

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

Definition at line 178 of file func_groupcount.c.

References ast_app_group_list_head(), ast_app_group_list_lock(), ast_app_group_list_unlock(), ast_copy_string(), AST_LIST_NEXT, ast_strlen_zero(), ast_group_info::category, ast_group_info::chan, and ast_group_info::group.

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

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

Definition at line 88 of file func_groupcount.c.

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

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

static int load_module ( void   )  [static]

Definition at line 235 of file func_groupcount.c.

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

00236 {
00237    int res = 0;
00238 
00239    res |= ast_custom_function_register(&group_count_function);
00240    res |= ast_custom_function_register(&group_match_count_function);
00241    res |= ast_custom_function_register(&group_list_function);
00242    res |= ast_custom_function_register(&group_function);
00243 
00244    return res;
00245 }

static int unload_module ( void   )  [static]

Definition at line 223 of file func_groupcount.c.

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

00224 {
00225    int res = 0;
00226 
00227    res |= ast_custom_function_unregister(&group_count_function);
00228    res |= ast_custom_function_unregister(&group_match_count_function);
00229    res |= ast_custom_function_unregister(&group_list_function);
00230    res |= ast_custom_function_unregister(&group_function);
00231 
00232    return res;
00233 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 247 of file func_groupcount.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 247 of file func_groupcount.c.

struct ast_custom_function group_count_function [static]

Definition at line 78 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_function [static]

Definition at line 169 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_list_function [static]

Definition at line 214 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_match_count_function [static]

Definition at line 108 of file func_groupcount.c.

Referenced by load_module(), and unload_module().


Generated on Sat Aug 6 00:39:56 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7