Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:57 2009

## Asterisk developer's documentation

# func_groupcount.c File Reference

Channel group related dialplan functions. More...

`#include <stdlib.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include <sys/types.h>`
`#include "asterisk.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

static char * | group_count_function_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static char * | group_function_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static void | group_function_write (struct ast_channel *chan, char *cmd, char *data, const char *value)
static char * | group_list_function_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static char * | group_match_count_function_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)

## 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

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

Definition at line 38 of file func_groupcount.c.

References ast_app_group_get_count(), ast_app_group_split_group(), ast_log(), group, LOG_NOTICE, and ast_channel::name.

    00039 {
    00040    int count = -1;
    00041    char group[80] = "", category[80] = "";
    00042
    00043    ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
    00044
    00045    if ((count = ast_app_group_get_count(group, category)) == -1)
    00046       ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name);
    00047    else
    00048       snprintf(buf, len, "%d", count);
    00049
    00050    return buf;
    00051 }

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

Definition at line 94 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, ast_group_info::group, and list.

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

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

Definition at line 117 of file func_groupcount.c.

References ast_app_group_set_channel(), ast_log(), ast_strlen_zero(), and LOG_WARNING.

    00118 {
    00119    char grpcat[256];
    00120
    00121    if (!ast_strlen_zero(data)) {
    00122       snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
    00123    } else {
    00124       ast_copy_string(grpcat, value, sizeof(grpcat));
    00125    }
    00126
    00127    if (ast_app_group_set_channel(chan, grpcat))
    00128       ast_log(LOG_WARNING, "Setting a group requires an argument (group name)\n");
    00129 }

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

Definition at line 143 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, ast_group_info::group, and list.

    00144 {
    00145    struct ast_group_info *gi = NULL;
    00146    char tmp1[1024] = "";
    00147    char tmp2[1024] = "";
    00148
    00149    ast_app_group_list_lock();
    00150
    00151    for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, list)) {
    00152       if (gi->chan != chan)
    00153          continue;
    00154       if (!ast_strlen_zero(tmp1)) {
    00155          ast_copy_string(tmp2, tmp1, sizeof(tmp2));
    00156          if (!ast_strlen_zero(gi->category))
    00157             snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
    00158          else
    00159             snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
    00160       } else {
    00161          if (!ast_strlen_zero(gi->category))
    00162             snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
    00163          else
    00164             snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
    00165       }
    00166    }
    00167
    00168    ast_app_group_list_unlock();
    00169
    00170    ast_copy_string(buf, tmp1, len);
    00171
    00172    return buf;
    00173 }

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

Definition at line 65 of file func_groupcount.c.

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

    00066 {
    00067    int count;
    00068    char group[80] = "";
    00069    char category[80] = "";
    00070
    00071    ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
    00072
    00073    if (!ast_strlen_zero(group)) {
    00074       count = ast_app_group_match_get_count(group, category);
    00075       snprintf(buf, len, "%d", count);
    00076    }
    00077
    00078    return buf;
    00079 }

## Variable Documentation

struct ast_custom_function group_count_function`[static]`

Definition at line 56 of file func_groupcount.c.

struct ast_custom_function group_function`[static]`

Definition at line 134 of file func_groupcount.c.

struct ast_custom_function group_list_function`[static]`

Definition at line 178 of file func_groupcount.c.

struct ast_custom_function group_match_count_function`[static]`

Definition at line 84 of file func_groupcount.c.