Mon Mar 12 2012 21:39:56

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"
Include dependency graph for func_groupcount.c:

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 = AST_BUILDOPT_SUM, .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.

{
   int ret = -1;
   int count = -1;
   char group[80] = "", category[80] = "";

   ast_app_group_split_group(data, group, sizeof(group), category,
              sizeof(category));

   /* If no group has been provided let's find one */
   if (ast_strlen_zero(group)) {
      struct ast_group_info *gi = NULL;

      ast_app_group_list_rdlock();
      for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
         if (gi->chan != chan)
            continue;
         if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))
            break;
      }
      if (gi) {
         ast_copy_string(group, gi->group, sizeof(group));
         if (!ast_strlen_zero(gi->category))
            ast_copy_string(category, gi->category, sizeof(category));
      }
      ast_app_group_list_unlock();
   }

   if ((count = ast_app_group_get_count(group, category)) == -1) {
      ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name);
   } else {
      snprintf(buf, len, "%d", count);
      ret = 0;
   }

   return ret;
}
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.

{
   int ret = -1;
   struct ast_group_info *gi = NULL;
   
   ast_app_group_list_rdlock();
   
   for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
      if (gi->chan != chan)
         continue;
      if (ast_strlen_zero(data))
         break;
      if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
         break;
   }
   
   if (gi) {
      ast_copy_string(buf, gi->group, len);
      ret = 0;
   }
   
   ast_app_group_list_unlock();
   
   return ret;
}
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(), and LOG_WARNING.

{
   char grpcat[256];

   if (!value) {
      return -1;
   }

   if (!ast_strlen_zero(data)) {
      snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
   } else {
      ast_copy_string(grpcat, value, sizeof(grpcat));
   }

   if (ast_app_group_set_channel(chan, grpcat))
      ast_log(LOG_WARNING,
            "Setting a group requires an argument (group name)\n");

   return 0;
}
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.

{
   struct ast_group_info *gi = NULL;
   char tmp1[1024] = "";
   char tmp2[1024] = "";

   if (!chan)
      return -1;

   ast_app_group_list_rdlock();

   for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
      if (gi->chan != chan)
         continue;
      if (!ast_strlen_zero(tmp1)) {
         ast_copy_string(tmp2, tmp1, sizeof(tmp2));
         if (!ast_strlen_zero(gi->category))
            snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
         else
            snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
      } else {
         if (!ast_strlen_zero(gi->category))
            snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
         else
            snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
      }
   }
   
   ast_app_group_list_unlock();

   ast_copy_string(buf, tmp1, len);

   return 0;
}
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().

{
   int count;
   char group[80] = "";
   char category[80] = "";

   ast_app_group_split_group(data, group, sizeof(group), category,
              sizeof(category));

   if (!ast_strlen_zero(group)) {
      count = ast_app_group_match_get_count(group, category);
      snprintf(buf, len, "%d", count);
      return 0;
   }

   return -1;
}
static int load_module ( void  ) [static]

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

Definition at line 293 of file func_groupcount.c.

Definition at line 293 of file func_groupcount.c.

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

Definition at line 139 of file func_groupcount.c.

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

Definition at line 221 of file func_groupcount.c.

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

Definition at line 263 of file func_groupcount.c.

Definition at line 165 of file func_groupcount.c.