Fri Aug 24 02:26:05 2007

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"

Include dependency graph for func_groupcount.c:

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Channel group dialplan functions")
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_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

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Channel group dialplan functions"   
)

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

Definition at line 40 of file func_groupcount.c.

References ast_app_group_get_count(), ast_app_group_split_group(), ast_log(), group, and LOG_NOTICE.

00042 {
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 ((count = ast_app_group_get_count(group, category)) == -1)
00050       ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name);
00051    else
00052       snprintf(buf, len, "%d", count);
00053 
00054    return 0;
00055 }

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

Definition at line 98 of file func_groupcount.c.

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

00100 {
00101    struct ast_group_info *gi = NULL;
00102    
00103    ast_app_group_list_lock();
00104    
00105    for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, list)) {
00106       if (gi->chan != chan)
00107          continue;
00108       if (ast_strlen_zero(data))
00109          break;
00110       if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
00111          break;
00112    }
00113    
00114    if (gi)
00115       ast_copy_string(buf, gi->group, len);
00116    
00117    ast_app_group_list_unlock();
00118    
00119    return 0;
00120 }

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

Definition at line 122 of file func_groupcount.c.

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

00124 {
00125    char grpcat[256];
00126 
00127    if (!ast_strlen_zero(data)) {
00128       snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
00129    } else {
00130       ast_copy_string(grpcat, value, sizeof(grpcat));
00131    }
00132 
00133    if (ast_app_group_set_channel(chan, grpcat))
00134       ast_log(LOG_WARNING,
00135             "Setting a group requires an argument (group name)\n");
00136 
00137    return 0;
00138 }

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

Definition at line 149 of file func_groupcount.c.

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

00151 {
00152    struct ast_group_info *gi = NULL;
00153    char tmp1[1024] = "";
00154    char tmp2[1024] = "";
00155 
00156    if (!chan)
00157       return -1;
00158 
00159    ast_app_group_list_lock();
00160 
00161    for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, list)) {
00162       if (gi->chan != chan)
00163          continue;
00164       if (!ast_strlen_zero(tmp1)) {
00165          ast_copy_string(tmp2, tmp1, sizeof(tmp2));
00166          if (!ast_strlen_zero(gi->category))
00167             snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
00168          else
00169             snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
00170       } else {
00171          if (!ast_strlen_zero(gi->category))
00172             snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
00173          else
00174             snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
00175       }
00176    }
00177    
00178    ast_app_group_list_unlock();
00179 
00180    ast_copy_string(buf, tmp1, len);
00181 
00182    return 0;
00183 }

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

Definition at line 67 of file func_groupcount.c.

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

00070 {
00071    int count;
00072    char group[80] = "";
00073    char category[80] = "";
00074 
00075    ast_app_group_split_group(data, group, sizeof(group), category,
00076               sizeof(category));
00077 
00078    if (!ast_strlen_zero(group)) {
00079       count = ast_app_group_match_get_count(group, category);
00080       snprintf(buf, len, "%d", count);
00081    }
00082 
00083    return 0;
00084 }

static int load_module ( void   )  [static]

Definition at line 206 of file func_groupcount.c.

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

00207 {
00208    int res = 0;
00209 
00210    res |= ast_custom_function_register(&group_count_function);
00211    res |= ast_custom_function_register(&group_match_count_function);
00212    res |= ast_custom_function_register(&group_list_function);
00213    res |= ast_custom_function_register(&group_function);
00214 
00215    return res;
00216 }

static int unload_module ( void   )  [static]

Definition at line 194 of file func_groupcount.c.

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

00195 {
00196    int res = 0;
00197 
00198    res |= ast_custom_function_unregister(&group_count_function);
00199    res |= ast_custom_function_unregister(&group_match_count_function);
00200    res |= ast_custom_function_unregister(&group_list_function);
00201    res |= ast_custom_function_unregister(&group_function);
00202 
00203    return res;
00204 }


Variable Documentation

struct ast_custom_function group_count_function [static]

Definition at line 57 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_function [static]

Definition at line 140 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_list_function [static]

Definition at line 185 of file func_groupcount.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function group_match_count_function [static]

Definition at line 86 of file func_groupcount.c.

Referenced by load_module(), and unload_module().


Generated on Fri Aug 24 02:26:06 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1