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 | |
AST_APP_OPTIONS (cdr_func_options,{AST_APP_OPTION('f', OPT_FLOAT), AST_APP_OPTION('l', OPT_LAST), AST_APP_OPTION('r', OPT_RECURSIVE), AST_APP_OPTION('s', OPT_SKIPLOCKED), AST_APP_OPTION('u', OPT_UNPARSED),}) | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Call Detail Record (CDR) dialplan function") | |
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_custom_function | cdr_function |
Call Detail Record related dialplan functions.
Definition in file func_cdr.c.
enum cdr_option_flags |
Definition at line 181 of file func_cdr.c.
00181 { 00182 OPT_RECURSIVE = (1 << 0), 00183 OPT_UNPARSED = (1 << 1), 00184 OPT_LAST = (1 << 2), 00185 OPT_SKIPLOCKED = (1 << 3), 00186 OPT_FLOAT = (1 << 4), 00187 };
AST_APP_OPTIONS | ( | cdr_func_options | ) |
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Call Detail Record (CDR) dialplan function" | ||||
) |
static int cdr_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 197 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, ast_cdr::end, ast_cdr::next, OPT_FLOAT, OPT_LAST, OPT_RECURSIVE, OPT_SKIPLOCKED, OPT_UNPARSED, and ast_cdr::start.
00199 { 00200 char *ret = NULL; 00201 struct ast_flags flags = { 0 }; 00202 struct ast_cdr *cdr; 00203 AST_DECLARE_APP_ARGS(args, 00204 AST_APP_ARG(variable); 00205 AST_APP_ARG(options); 00206 ); 00207 00208 if (ast_strlen_zero(parse) || !chan) 00209 return -1; 00210 00211 ast_channel_lock(chan); 00212 cdr = chan->cdr; 00213 if (!cdr) { 00214 ast_channel_unlock(chan); 00215 return -1; 00216 } 00217 00218 AST_STANDARD_APP_ARGS(args, parse); 00219 00220 if (!ast_strlen_zero(args.options)) 00221 ast_app_parse_options(cdr_func_options, &flags, NULL, args.options); 00222 00223 if (ast_test_flag(&flags, OPT_LAST)) 00224 while (cdr->next) 00225 cdr = cdr->next; 00226 00227 if (ast_test_flag(&flags, OPT_SKIPLOCKED)) 00228 while (ast_test_flag(cdr, AST_CDR_FLAG_LOCKED) && cdr->next) 00229 cdr = cdr->next; 00230 00231 if (!strcasecmp("billsec", args.variable) && ast_test_flag(&flags, OPT_FLOAT)) { 00232 if (!ast_tvzero(cdr->answer)) { 00233 double hrtime; 00234 00235 if(!ast_tvzero(cdr->end)) 00236 hrtime = (double)(ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0); 00237 else 00238 hrtime = (double)(ast_tvdiff_us(ast_tvnow(), cdr->answer) / 1000000.0); 00239 00240 snprintf(buf, len, "%lf", hrtime); 00241 } else { 00242 snprintf(buf, len, "%lf", 0.0); 00243 } 00244 ret = buf; 00245 } else if (!strcasecmp("duration", args.variable) && ast_test_flag(&flags, OPT_FLOAT)) { 00246 double hrtime; 00247 00248 if(!ast_tvzero(cdr->end)) 00249 hrtime = (double)(ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0); 00250 else 00251 hrtime = (double)(ast_tvdiff_us(ast_tvnow(), cdr->start) / 1000000.0); 00252 00253 snprintf(buf, len, "%lf", hrtime); 00254 00255 if (!ast_strlen_zero(buf)) { 00256 ret = buf; 00257 } 00258 } else { 00259 ast_cdr_getvar(cdr, args.variable, &ret, buf, len, 00260 ast_test_flag(&flags, OPT_RECURSIVE), 00261 ast_test_flag(&flags, OPT_UNPARSED)); 00262 } 00263 00264 ast_channel_unlock(chan); 00265 return ret ? 0 : -1; 00266 }
static int cdr_write | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
const char * | value | |||
) | [static] |
Definition at line 268 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, ast_cdr::next, OPT_LAST, and OPT_RECURSIVE.
00270 { 00271 struct ast_cdr *cdr; 00272 struct ast_flags flags = { 0 }; 00273 AST_DECLARE_APP_ARGS(args, 00274 AST_APP_ARG(variable); 00275 AST_APP_ARG(options); 00276 ); 00277 00278 if (ast_strlen_zero(parse) || !value || !chan) 00279 return -1; 00280 00281 ast_channel_lock(chan); 00282 cdr = chan->cdr; 00283 if (!cdr) { 00284 ast_channel_unlock(chan); 00285 return -1; 00286 } 00287 00288 AST_STANDARD_APP_ARGS(args, parse); 00289 00290 if (!ast_strlen_zero(args.options)) 00291 ast_app_parse_options(cdr_func_options, &flags, NULL, args.options); 00292 00293 if (ast_test_flag(&flags, OPT_LAST)) 00294 while (cdr->next) 00295 cdr = cdr->next; 00296 00297 if (!strcasecmp(args.variable, "accountcode")) /* the 'l' flag doesn't apply to setting the accountcode, userfield, or amaflags */ 00298 ast_cdr_setaccount(chan, value); 00299 else if (!strcasecmp(args.variable, "peeraccount")) 00300 ast_cdr_setpeeraccount(chan, value); 00301 else if (!strcasecmp(args.variable, "userfield")) 00302 ast_cdr_setuserfield(chan, value); 00303 else if (!strcasecmp(args.variable, "amaflags")) 00304 ast_cdr_setamaflags(chan, value); 00305 else 00306 ast_cdr_setvar(cdr, args.variable, value, ast_test_flag(&flags, OPT_RECURSIVE)); 00307 /* No need to worry about the u flag, as all fields for which setting 00308 * 'u' would do anything are marked as readonly. */ 00309 00310 ast_channel_unlock(chan); 00311 return 0; 00312 }
static int load_module | ( | void | ) | [static] |
Definition at line 325 of file func_cdr.c.
References ast_custom_function_register.
00326 { 00327 return ast_custom_function_register(&cdr_function); 00328 }
static int unload_module | ( | void | ) | [static] |
Definition at line 320 of file func_cdr.c.
References ast_custom_function_unregister().
00321 { 00322 return ast_custom_function_unregister(&cdr_function); 00323 }
struct ast_custom_function cdr_function [static] |
Definition at line 314 of file func_cdr.c.