Wed Apr 6 11:30:04 2011

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"

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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .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

enum cdr_option_flags

Enumerator:
OPT_RECURSIVE 
OPT_UNPARSED 
OPT_LAST 
OPT_SKIPLOCKED 
OPT_FLOAT 

Definition at line 175 of file func_cdr.c.

00175                       {
00176    OPT_RECURSIVE = (1 << 0),
00177    OPT_UNPARSED = (1 << 1),
00178    OPT_LAST = (1 << 2),
00179    OPT_SKIPLOCKED = (1 << 3),
00180    OPT_FLOAT = (1 << 4),
00181 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 314 of file func_cdr.c.

static void __unreg_module ( void   )  [static]

Definition at line 314 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 191 of file func_cdr.c.

References args, AST_APP_ARG, ast_app_parse_options(), AST_CDR_FLAG_LOCKED, ast_cdr_getvar(), 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::flags, ast_flags::flags, ast_cdr::next, OPT_FLOAT, OPT_LAST, OPT_RECURSIVE, OPT_SKIPLOCKED, and OPT_UNPARSED.

00193 {
00194    char *ret;
00195    struct ast_flags flags = { 0 };
00196    struct ast_cdr *cdr = chan ? chan->cdr : NULL;
00197    AST_DECLARE_APP_ARGS(args,
00198               AST_APP_ARG(variable);
00199               AST_APP_ARG(options);
00200    );
00201 
00202    if (ast_strlen_zero(parse))
00203       return -1;
00204 
00205    if (!cdr)
00206       return -1;
00207 
00208    AST_STANDARD_APP_ARGS(args, parse);
00209 
00210    if (!ast_strlen_zero(args.options))
00211       ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
00212 
00213    if (ast_test_flag(&flags, OPT_LAST))
00214       while (cdr->next)
00215          cdr = cdr->next;
00216 
00217    if (ast_test_flag(&flags, OPT_SKIPLOCKED))
00218       while (ast_test_flag(cdr, AST_CDR_FLAG_LOCKED) && cdr->next)
00219          cdr = cdr->next;
00220 
00221    if (!strcasecmp("billsec", args.variable) && ast_test_flag(&flags, OPT_FLOAT)) {
00222       if (!ast_tvzero(cdr->answer)) {
00223          double hrtime;
00224 
00225          if(!ast_tvzero(cdr->end))
00226             hrtime = (double)(ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0);
00227          else
00228             hrtime = (double)(ast_tvdiff_us(ast_tvnow(), cdr->answer) / 1000000.0);
00229 
00230          snprintf(buf, len, "%lf", hrtime);
00231       } else {
00232          snprintf(buf, len, "%lf", 0.0);
00233       }
00234       ret = buf;
00235    } else if (!strcasecmp("duration", args.variable) && ast_test_flag(&flags, OPT_FLOAT)) {
00236          double hrtime;
00237 
00238          if(!ast_tvzero(cdr->end))
00239             hrtime = (double)(ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0);
00240          else
00241             hrtime = (double)(ast_tvdiff_us(ast_tvnow(), cdr->start) / 1000000.0);
00242 
00243          snprintf(buf, len, "%lf", hrtime);
00244 
00245       if (!ast_strlen_zero(buf)) {
00246          ret = buf;
00247       }
00248    } else {
00249       ast_cdr_getvar(cdr, args.variable, &ret, buf, len,
00250                 ast_test_flag(&flags, OPT_RECURSIVE),
00251                ast_test_flag(&flags, OPT_UNPARSED));
00252    }
00253 
00254    return ret ? 0 : -1;
00255 }

static int cdr_write ( struct ast_channel chan,
const char *  cmd,
char *  parse,
const char *  value 
) [static]

Definition at line 257 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_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_test_flag, ast_channel::cdr, cdr_func_options, ast_flags::flags, ast_cdr::next, OPT_LAST, and OPT_RECURSIVE.

00259 {
00260    struct ast_cdr *cdr = chan ? chan->cdr : NULL;
00261    struct ast_flags flags = { 0 };
00262    AST_DECLARE_APP_ARGS(args,
00263               AST_APP_ARG(variable);
00264               AST_APP_ARG(options);
00265    );
00266 
00267    if (ast_strlen_zero(parse) || !value || !chan)
00268       return -1;
00269 
00270    if (!cdr)
00271       return -1;
00272 
00273    AST_STANDARD_APP_ARGS(args, parse);
00274 
00275    if (!ast_strlen_zero(args.options))
00276       ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
00277 
00278    if (ast_test_flag(&flags, OPT_LAST))
00279       while (cdr->next)
00280          cdr = cdr->next;
00281 
00282    if (!strcasecmp(args.variable, "accountcode"))  /* the 'l' flag doesn't apply to setting the accountcode, userfield, or amaflags */
00283       ast_cdr_setaccount(chan, value);
00284    else if (!strcasecmp(args.variable, "peeraccount"))
00285       ast_cdr_setpeeraccount(chan, value);
00286    else if (!strcasecmp(args.variable, "userfield"))
00287       ast_cdr_setuserfield(chan, value);
00288    else if (!strcasecmp(args.variable, "amaflags"))
00289       ast_cdr_setamaflags(chan, value);
00290    else
00291       ast_cdr_setvar(cdr, args.variable, value, ast_test_flag(&flags, OPT_RECURSIVE));
00292       /* No need to worry about the u flag, as all fields for which setting
00293        * 'u' would do anything are marked as readonly. */
00294 
00295    return 0;
00296 }

static int load_module ( void   )  [static]

Definition at line 309 of file func_cdr.c.

References ast_custom_function_register, and cdr_function.

00310 {
00311    return ast_custom_function_register(&cdr_function);
00312 }

static int unload_module ( void   )  [static]

Definition at line 304 of file func_cdr.c.

References ast_custom_function_unregister(), and cdr_function.

00305 {
00306    return ast_custom_function_unregister(&cdr_function);
00307 }


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

Definition at line 314 of file func_cdr.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 314 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 189 of file func_cdr.c.

Referenced by cdr_read(), and cdr_write().

struct ast_custom_function cdr_function [static]

Initial value:

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

Definition at line 298 of file func_cdr.c.

Referenced by load_module(), and unload_module().


Generated on Wed Apr 6 11:30:04 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7