Mon Jun 27 16:51:14 2011

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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .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 289 of file func_groupcount.c.

static void __unreg_module ( void   )  [static]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

static int load_module ( void   )  [static]

Definition at line 277 of file func_groupcount.c.

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

00278 {
00279    int res = 0;
00280 
00281    res |= ast_custom_function_register(&group_count_function);
00282    res |= ast_custom_function_register(&group_match_count_function);
00283    res |= ast_custom_function_register(&group_list_function);
00284    res |= ast_custom_function_register(&group_function);
00285 
00286    return res;
00287 }

static int unload_module ( void   )  [static]

Definition at line 265 of file func_groupcount.c.

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

00266 {
00267    int res = 0;
00268 
00269    res |= ast_custom_function_unregister(&group_count_function);
00270    res |= ast_custom_function_unregister(&group_match_count_function);
00271    res |= ast_custom_function_unregister(&group_list_function);
00272    res |= ast_custom_function_unregister(&group_function);
00273 
00274    return res;
00275 }


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

Definition at line 289 of file func_groupcount.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 289 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 135 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 217 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 259 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_match_count_function [static]

Definition at line 161 of file func_groupcount.c.

Referenced by load_module(), and unload_module().


Generated on Mon Jun 27 16:51:14 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7