Mon Mar 12 2012 21:39:50

Asterisk developer's documentation


func_cdr.c File Reference

Call Detail Record 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 "asterisk/cdr.h"
Include dependency graph for func_cdr.c:

Go to the source code of this file.

Enumerations

enum  cdr_option_flags {
  OPT_RECURSIVE = (1 << 0), OPT_UNPARSED = (1 << 1), OPT_LAST = (1 << 2), OPT_SKIPLOCKED = (1 << 3),
  OPT_FLOAT = (1 << 4)
}

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int cdr_read (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
static int cdr_write (struct ast_channel *chan, const char *cmd, char *parse, const char *value)
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 = "Call Detail Record (CDR) dialplan function" , .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_app_option cdr_func_options [128] = { [ 'f' ] = { .flag = OPT_FLOAT }, [ 'l' ] = { .flag = OPT_LAST }, [ 'r' ] = { .flag = OPT_RECURSIVE }, [ 's' ] = { .flag = OPT_SKIPLOCKED }, [ 'u' ] = { .flag = OPT_UNPARSED },}
static struct ast_custom_function cdr_function

Detailed Description

Call Detail Record related dialplan functions.

Author:
Anthony Minessale II

Definition in file func_cdr.c.


Enumeration Type Documentation

Enumerator:
OPT_RECURSIVE 
OPT_UNPARSED 
OPT_LAST 
OPT_SKIPLOCKED 
OPT_FLOAT 

Definition at line 179 of file func_cdr.c.

                      {
   OPT_RECURSIVE = (1 << 0),
   OPT_UNPARSED = (1 << 1),
   OPT_LAST = (1 << 2),
   OPT_SKIPLOCKED = (1 << 3),
   OPT_FLOAT = (1 << 4),
};

Function Documentation

static void __reg_module ( void  ) [static]

Definition at line 328 of file func_cdr.c.

static void __unreg_module ( void  ) [static]

Definition at line 328 of file func_cdr.c.

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

Definition at line 195 of file func_cdr.c.

References ast_cdr::answer, args, AST_APP_ARG, ast_app_parse_options(), AST_CDR_FLAG_LOCKED, ast_cdr_getvar(), ast_channel_lock, ast_channel_unlock, AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_test_flag, ast_tvdiff_us(), ast_tvnow(), ast_tvzero(), ast_channel::cdr, cdr_func_options, ast_cdr::end, ast_cdr::next, OPT_FLOAT, OPT_LAST, OPT_RECURSIVE, OPT_SKIPLOCKED, OPT_UNPARSED, and ast_cdr::start.

{
   char *ret;
   struct ast_flags flags = { 0 };
   struct ast_cdr *cdr;
   AST_DECLARE_APP_ARGS(args,
              AST_APP_ARG(variable);
              AST_APP_ARG(options);
   );

   if (ast_strlen_zero(parse) || !chan)
      return -1;

   ast_channel_lock(chan);
   cdr = chan->cdr;
   if (!cdr) {
      ast_channel_unlock(chan);
      return -1;
   }

   AST_STANDARD_APP_ARGS(args, parse);

   if (!ast_strlen_zero(args.options))
      ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);

   if (ast_test_flag(&flags, OPT_LAST))
      while (cdr->next)
         cdr = cdr->next;

   if (ast_test_flag(&flags, OPT_SKIPLOCKED))
      while (ast_test_flag(cdr, AST_CDR_FLAG_LOCKED) && cdr->next)
         cdr = cdr->next;

   if (!strcasecmp("billsec", args.variable) && ast_test_flag(&flags, OPT_FLOAT)) {
      if (!ast_tvzero(cdr->answer)) {
         double hrtime;

         if(!ast_tvzero(cdr->end))
            hrtime = (double)(ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0);
         else
            hrtime = (double)(ast_tvdiff_us(ast_tvnow(), cdr->answer) / 1000000.0);

         snprintf(buf, len, "%lf", hrtime);
      } else {
         snprintf(buf, len, "%lf", 0.0);
      }
      ret = buf;
   } else if (!strcasecmp("duration", args.variable) && ast_test_flag(&flags, OPT_FLOAT)) {
         double hrtime;

         if(!ast_tvzero(cdr->end))
            hrtime = (double)(ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0);
         else
            hrtime = (double)(ast_tvdiff_us(ast_tvnow(), cdr->start) / 1000000.0);

         snprintf(buf, len, "%lf", hrtime);

      if (!ast_strlen_zero(buf)) {
         ret = buf;
      }
   } else {
      ast_cdr_getvar(cdr, args.variable, &ret, buf, len,
                ast_test_flag(&flags, OPT_RECURSIVE),
               ast_test_flag(&flags, OPT_UNPARSED));
   }

   ast_channel_unlock(chan);
   return ret ? 0 : -1;
}
static int cdr_write ( struct ast_channel chan,
const char *  cmd,
char *  parse,
const char *  value 
) [static]

Definition at line 266 of file func_cdr.c.

References args, AST_APP_ARG, ast_app_parse_options(), ast_cdr_setaccount(), ast_cdr_setamaflags(), ast_cdr_setpeeraccount(), ast_cdr_setuserfield(), ast_cdr_setvar(), ast_channel_lock, ast_channel_unlock, AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_test_flag, ast_channel::cdr, cdr_func_options, ast_cdr::next, OPT_LAST, and OPT_RECURSIVE.

{
   struct ast_cdr *cdr;
   struct ast_flags flags = { 0 };
   AST_DECLARE_APP_ARGS(args,
              AST_APP_ARG(variable);
              AST_APP_ARG(options);
   );

   if (ast_strlen_zero(parse) || !value || !chan)
      return -1;

   ast_channel_lock(chan);
   cdr = chan->cdr;
   if (!cdr) {
      ast_channel_unlock(chan);
      return -1;
   }

   AST_STANDARD_APP_ARGS(args, parse);

   if (!ast_strlen_zero(args.options))
      ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);

   if (ast_test_flag(&flags, OPT_LAST))
      while (cdr->next)
         cdr = cdr->next;

   if (!strcasecmp(args.variable, "accountcode"))  /* the 'l' flag doesn't apply to setting the accountcode, userfield, or amaflags */
      ast_cdr_setaccount(chan, value);
   else if (!strcasecmp(args.variable, "peeraccount"))
      ast_cdr_setpeeraccount(chan, value);
   else if (!strcasecmp(args.variable, "userfield"))
      ast_cdr_setuserfield(chan, value);
   else if (!strcasecmp(args.variable, "amaflags"))
      ast_cdr_setamaflags(chan, value);
   else
      ast_cdr_setvar(cdr, args.variable, value, ast_test_flag(&flags, OPT_RECURSIVE));
      /* No need to worry about the u flag, as all fields for which setting
       * 'u' would do anything are marked as readonly. */

   ast_channel_unlock(chan);
   return 0;
}
static int load_module ( void  ) [static]

Definition at line 323 of file func_cdr.c.

References ast_custom_function_register.

static int unload_module ( void  ) [static]

Definition at line 318 of file func_cdr.c.

References ast_custom_function_unregister().


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Call Detail Record (CDR) dialplan function" , .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 328 of file func_cdr.c.

Definition at line 328 of file func_cdr.c.

struct ast_app_option cdr_func_options[128] = { [ 'f' ] = { .flag = OPT_FLOAT }, [ 'l' ] = { .flag = OPT_LAST }, [ 'r' ] = { .flag = OPT_RECURSIVE }, [ 's' ] = { .flag = OPT_SKIPLOCKED }, [ 'u' ] = { .flag = OPT_UNPARSED },} [static]

Definition at line 193 of file func_cdr.c.

Referenced by cdr_read(), and cdr_write().

Initial value:
 {
   .name = "CDR",
   .read = cdr_read,
   .write = cdr_write,
}

Definition at line 312 of file func_cdr.c.