Wed Jan 8 2020 09:50:12

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 = "ac1f6a56484a8820659555499174e588" , .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 181 of file func_cdr.c.

181  {
182  OPT_RECURSIVE = (1 << 0),
183  OPT_UNPARSED = (1 << 1),
184  OPT_LAST = (1 << 2),
185  OPT_SKIPLOCKED = (1 << 3),
186  OPT_FLOAT = (1 << 4),
187 };

Function Documentation

static void __reg_module ( void  )
static

Definition at line 330 of file func_cdr.c.

static void __unreg_module ( void  )
static

Definition at line 330 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 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, cdr_func_options, ast_cdr::end, ast_cdr::next, OPT_FLOAT, OPT_LAST, OPT_RECURSIVE, OPT_SKIPLOCKED, OPT_UNPARSED, and ast_cdr::start.

199 {
200  char *ret = NULL;
201  struct ast_flags flags = { 0 };
202  struct ast_cdr *cdr;
204  AST_APP_ARG(variable);
205  AST_APP_ARG(options);
206  );
207 
208  if (ast_strlen_zero(parse) || !chan)
209  return -1;
210 
211  ast_channel_lock(chan);
212  cdr = chan->cdr;
213  if (!cdr) {
214  ast_channel_unlock(chan);
215  return -1;
216  }
217 
219 
220  if (!ast_strlen_zero(args.options))
221  ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
222 
223  if (ast_test_flag(&flags, OPT_LAST))
224  while (cdr->next)
225  cdr = cdr->next;
226 
227  if (ast_test_flag(&flags, OPT_SKIPLOCKED))
228  while (ast_test_flag(cdr, AST_CDR_FLAG_LOCKED) && cdr->next)
229  cdr = cdr->next;
230 
231  if (!strcasecmp("billsec", args.variable) && ast_test_flag(&flags, OPT_FLOAT)) {
232  if (!ast_tvzero(cdr->answer)) {
233  double hrtime;
234 
235  if(!ast_tvzero(cdr->end))
236  hrtime = (double)(ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0);
237  else
238  hrtime = (double)(ast_tvdiff_us(ast_tvnow(), cdr->answer) / 1000000.0);
239 
240  snprintf(buf, len, "%lf", hrtime);
241  } else {
242  snprintf(buf, len, "%lf", 0.0);
243  }
244  ret = buf;
245  } else if (!strcasecmp("duration", args.variable) && ast_test_flag(&flags, OPT_FLOAT)) {
246  double hrtime;
247 
248  if(!ast_tvzero(cdr->end))
249  hrtime = (double)(ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0);
250  else
251  hrtime = (double)(ast_tvdiff_us(ast_tvnow(), cdr->start) / 1000000.0);
252 
253  snprintf(buf, len, "%lf", hrtime);
254 
255  if (!ast_strlen_zero(buf)) {
256  ret = buf;
257  }
258  } else {
259  ast_cdr_getvar(cdr, args.variable, &ret, buf, len,
260  ast_test_flag(&flags, OPT_RECURSIVE),
261  ast_test_flag(&flags, OPT_UNPARSED));
262  }
263 
264  ast_channel_unlock(chan);
265  return ret ? 0 : -1;
266 }
static struct ast_app_option cdr_func_options[128]
Definition: func_cdr.c:195
#define ast_channel_lock(chan)
Definition: channel.h:2466
#define ast_test_flag(p, flag)
Definition: utils.h:63
struct ast_cdr * next
Definition: cdr.h:132
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: app.c:2101
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
unsigned int flags
Definition: utils.h:201
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:100
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
struct ast_cdr * cdr
Definition: channel.h:766
void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw)
Definition: cdr.c:264
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
struct timeval answer
Definition: cdr.h:102
Responsible for call detail data.
Definition: cdr.h:82
static struct @350 args
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_channel_unlock(chan)
Definition: channel.h:2467
struct timeval start
Definition: cdr.h:100
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
Structure used to handle boolean flags.
Definition: utils.h:200
struct timeval end
Definition: cdr.h:104
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
Definition: time.h:70
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
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, cdr_func_options, ast_cdr::next, OPT_LAST, and OPT_RECURSIVE.

270 {
271  struct ast_cdr *cdr;
272  struct ast_flags flags = { 0 };
274  AST_APP_ARG(variable);
275  AST_APP_ARG(options);
276  );
277 
278  if (ast_strlen_zero(parse) || !value || !chan)
279  return -1;
280 
281  ast_channel_lock(chan);
282  cdr = chan->cdr;
283  if (!cdr) {
284  ast_channel_unlock(chan);
285  return -1;
286  }
287 
289 
290  if (!ast_strlen_zero(args.options))
291  ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
292 
293  if (ast_test_flag(&flags, OPT_LAST))
294  while (cdr->next)
295  cdr = cdr->next;
296 
297  if (!strcasecmp(args.variable, "accountcode")) /* the 'l' flag doesn't apply to setting the accountcode, userfield, or amaflags */
298  ast_cdr_setaccount(chan, value);
299  else if (!strcasecmp(args.variable, "peeraccount"))
301  else if (!strcasecmp(args.variable, "userfield"))
303  else if (!strcasecmp(args.variable, "amaflags"))
304  ast_cdr_setamaflags(chan, value);
305  else
306  ast_cdr_setvar(cdr, args.variable, value, ast_test_flag(&flags, OPT_RECURSIVE));
307  /* No need to worry about the u flag, as all fields for which setting
308  * 'u' would do anything are marked as readonly. */
309 
310  ast_channel_unlock(chan);
311  return 0;
312 }
int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags)
Set AMA flags for channel.
Definition: cdr.c:1042
static struct ast_app_option cdr_func_options[128]
Definition: func_cdr.c:195
int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur)
Definition: cdr.c:343
#define ast_channel_lock(chan)
Definition: channel.h:2466
#define ast_test_flag(p, flag)
Definition: utils.h:63
struct ast_cdr * next
Definition: cdr.h:132
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: app.c:2101
int ast_cdr_setaccount(struct ast_channel *chan, const char *account)
Set account code, will generate AMI event.
Definition: cdr.c:990
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
unsigned int flags
Definition: utils.h:201
struct ast_cdr * cdr
Definition: channel.h:766
int value
Definition: syslog.c:39
int ast_cdr_setuserfield(struct ast_channel *chan, const char *userfield)
Set CDR user field for channel (stored in CDR)
Definition: cdr.c:1057
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
Responsible for call detail data.
Definition: cdr.h:82
static struct @350 args
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
int ast_cdr_setpeeraccount(struct ast_channel *chan, const char *account)
Set the peer account.
Definition: cdr.c:1016
Structure used to handle boolean flags.
Definition: utils.h:200
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static int load_module ( void  )
static

Definition at line 325 of file func_cdr.c.

References ast_custom_function_register.

326 {
328 }
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
static struct ast_custom_function cdr_function
Definition: func_cdr.c:314
static int unload_module ( void  )
static

Definition at line 320 of file func_cdr.c.

References ast_custom_function_unregister().

321 {
323 }
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
static struct ast_custom_function cdr_function
Definition: func_cdr.c:314

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

Definition at line 330 of file func_cdr.c.

Definition at line 330 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 195 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,
}
static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse, const char *value)
Definition: func_cdr.c:268
static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_cdr.c:197

Definition at line 314 of file func_cdr.c.