2005-05-05 05:39:33 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
2006-02-12 04:28:58 +00:00
|
|
|
* Copyright (C) 1999-2006, Digium, Inc.
|
2005-05-05 05:39:33 +00:00
|
|
|
*
|
2005-05-05 12:48:52 +00:00
|
|
|
* Portions Copyright (C) 2005, Anthony Minessale II
|
2005-05-05 05:39:33 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
2005-05-05 05:39:33 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Call Detail Record related dialplan functions
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Anthony Minessale II
|
2007-01-24 09:05:29 +00:00
|
|
|
*
|
|
|
|
* \ingroup functions
|
2005-05-05 05:39:33 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-06 22:12:19 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
2005-06-06 22:12:19 +00:00
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
#include <stdio.h>
|
2006-06-07 18:54:56 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
#include "asterisk/module.h"
|
2005-05-05 05:39:33 +00:00
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/app.h"
|
|
|
|
#include "asterisk/cdr.h"
|
|
|
|
|
2006-01-11 19:52:29 +00:00
|
|
|
enum {
|
|
|
|
OPT_RECURSIVE = (1 << 0),
|
2006-02-23 23:12:41 +00:00
|
|
|
OPT_UNPARSED = (1 << 1),
|
2006-08-17 16:29:44 +00:00
|
|
|
OPT_LAST = (1 << 2),
|
2006-01-11 19:52:29 +00:00
|
|
|
} cdr_option_flags;
|
|
|
|
|
|
|
|
AST_APP_OPTIONS(cdr_func_options, {
|
2006-08-17 16:29:44 +00:00
|
|
|
AST_APP_OPTION('l', OPT_LAST),
|
2006-01-11 19:52:29 +00:00
|
|
|
AST_APP_OPTION('r', OPT_RECURSIVE),
|
2006-02-23 23:12:41 +00:00
|
|
|
AST_APP_OPTION('u', OPT_UNPARSED),
|
2006-01-11 19:52:29 +00:00
|
|
|
});
|
|
|
|
|
2007-01-06 00:13:33 +00:00
|
|
|
static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *buf, size_t len)
|
2005-05-05 05:39:33 +00:00
|
|
|
{
|
|
|
|
char *ret;
|
2006-02-12 04:28:58 +00:00
|
|
|
struct ast_flags flags = { 0 };
|
2006-08-17 16:29:44 +00:00
|
|
|
struct ast_cdr *cdr = chan->cdr;
|
2006-01-11 19:52:29 +00:00
|
|
|
AST_DECLARE_APP_ARGS(args,
|
2006-02-12 04:28:58 +00:00
|
|
|
AST_APP_ARG(variable);
|
|
|
|
AST_APP_ARG(options);
|
2006-01-11 19:52:29 +00:00
|
|
|
);
|
2005-05-05 05:39:33 +00:00
|
|
|
|
2006-02-12 04:28:58 +00:00
|
|
|
if (ast_strlen_zero(parse))
|
|
|
|
return -1;
|
2005-05-05 05:39:33 +00:00
|
|
|
|
2006-08-17 16:29:44 +00:00
|
|
|
if (!cdr)
|
2006-02-12 04:28:58 +00:00
|
|
|
return -1;
|
2005-05-05 05:39:33 +00:00
|
|
|
|
2006-01-11 19:52:29 +00:00
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
2006-02-12 04:28:58 +00:00
|
|
|
|
|
|
|
if (!ast_strlen_zero(args.options))
|
2006-01-11 19:52:29 +00:00
|
|
|
ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
|
2005-05-05 05:39:33 +00:00
|
|
|
|
2006-08-17 16:29:44 +00:00
|
|
|
if (ast_test_flag(&flags, OPT_LAST))
|
|
|
|
while (cdr->next)
|
|
|
|
cdr = cdr->next;
|
|
|
|
|
|
|
|
ast_cdr_getvar(cdr, args.variable, &ret, buf, len,
|
2006-02-23 23:12:41 +00:00
|
|
|
ast_test_flag(&flags, OPT_RECURSIVE),
|
|
|
|
ast_test_flag(&flags, OPT_UNPARSED));
|
2006-02-12 04:28:58 +00:00
|
|
|
|
|
|
|
return 0;
|
2005-05-05 05:39:33 +00:00
|
|
|
}
|
|
|
|
|
2007-01-06 00:13:33 +00:00
|
|
|
static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse,
|
2006-02-12 04:28:58 +00:00
|
|
|
const char *value)
|
2005-05-05 05:39:33 +00:00
|
|
|
{
|
2006-02-12 04:28:58 +00:00
|
|
|
struct ast_flags flags = { 0 };
|
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(variable);
|
|
|
|
AST_APP_ARG(options);
|
|
|
|
);
|
2005-05-05 05:39:33 +00:00
|
|
|
|
2006-02-12 04:28:58 +00:00
|
|
|
if (ast_strlen_zero(parse) || !value)
|
|
|
|
return -1;
|
2006-01-11 19:52:29 +00:00
|
|
|
|
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
2005-05-05 05:39:33 +00:00
|
|
|
|
2006-02-12 04:28:58 +00:00
|
|
|
if (!ast_strlen_zero(args.options))
|
2006-01-11 19:52:29 +00:00
|
|
|
ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
|
2005-05-05 05:39:33 +00:00
|
|
|
|
2006-01-11 19:52:29 +00:00
|
|
|
if (!strcasecmp(args.variable, "accountcode"))
|
2005-07-15 23:24:51 +00:00
|
|
|
ast_cdr_setaccount(chan, value);
|
2006-01-11 19:52:29 +00:00
|
|
|
else if (!strcasecmp(args.variable, "userfield"))
|
2005-07-15 23:24:51 +00:00
|
|
|
ast_cdr_setuserfield(chan, value);
|
2006-05-15 19:46:26 +00:00
|
|
|
else if (!strcasecmp(args.variable, "amaflags"))
|
2006-05-16 03:18:22 +00:00
|
|
|
ast_cdr_setamaflags(chan, value);
|
2005-08-03 21:34:48 +00:00
|
|
|
else if (chan->cdr)
|
2006-02-23 23:12:41 +00:00
|
|
|
ast_cdr_setvar(chan->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. */
|
2006-02-12 04:28:58 +00:00
|
|
|
|
|
|
|
return 0;
|
2005-05-05 05:39:33 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
static struct ast_custom_function cdr_function = {
|
2005-05-05 05:39:33 +00:00
|
|
|
.name = "CDR",
|
|
|
|
.synopsis = "Gets or sets a CDR variable",
|
|
|
|
.syntax = "CDR(<name>[|options])",
|
2006-02-11 03:14:05 +00:00
|
|
|
.read = cdr_read,
|
|
|
|
.write = cdr_write,
|
2006-02-23 23:12:41 +00:00
|
|
|
.desc =
|
|
|
|
"Options:\n"
|
|
|
|
" 'r' searches the entire stack of CDRs on the channel\n"
|
|
|
|
" 'u' retrieves the raw, unprocessed value\n"
|
|
|
|
" For example, 'start', 'answer', and 'end' will be retrieved as epoch\n"
|
2006-02-23 23:38:05 +00:00
|
|
|
" values, when the 'u' option is passed, but formatted as YYYY-MM-DD HH:MM:SS\n"
|
2006-02-23 23:12:41 +00:00
|
|
|
" otherwise. Similarly, disposition and amaflags will return their raw\n"
|
2006-11-27 14:47:15 +00:00
|
|
|
" integral values.\n"
|
2006-11-26 00:31:13 +00:00
|
|
|
" Here is a list of all the available cdr field names:\n"
|
2006-11-26 00:15:42 +00:00
|
|
|
" clid lastdata disposition\n"
|
|
|
|
" src start amaflags\n"
|
|
|
|
" dst answer accountcode\n"
|
|
|
|
" dcontext end uniqueid\n"
|
|
|
|
" dstchannel duration userfield\n"
|
|
|
|
" lastapp billsec channel\n"
|
|
|
|
" All of the above variables are read-only, except for accountcode,\n"
|
|
|
|
" userfield, and amaflags. You may, however, supply\n"
|
|
|
|
" a name not on the above list, and create your own\n"
|
|
|
|
" variable, whose value can be changed with this function,\n"
|
2006-11-26 00:31:13 +00:00
|
|
|
" and this variable will be stored on the cdr.\n"
|
|
|
|
" raw values for disposition:\n"
|
|
|
|
" 1 = NO ANSWER\n"
|
|
|
|
" 2 = BUSY\n"
|
|
|
|
" 3 = FAILED\n"
|
|
|
|
" 4 = ANSWERED\n"
|
|
|
|
" raw values for amaflags:\n"
|
|
|
|
" 1 = OMIT\n"
|
|
|
|
" 2 = BILLING\n"
|
|
|
|
" 3 = DOCUMENTATION\n",
|
2005-05-05 05:39:33 +00:00
|
|
|
};
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2006-02-11 03:14:05 +00:00
|
|
|
{
|
2006-02-12 04:28:58 +00:00
|
|
|
return ast_custom_function_unregister(&cdr_function);
|
2006-02-11 03:14:05 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2006-02-11 03:14:05 +00:00
|
|
|
{
|
2006-02-12 04:28:58 +00:00
|
|
|
return ast_custom_function_register(&cdr_function);
|
2006-02-11 03:14:05 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "CDR dialplan function");
|