| 
									
										
										
										
											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  | 
					
						
							| 
									
										
										
										
											2005-05-05 05:39:33 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <sys/types.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-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-01-11 19:52:29 +00:00
										 |  |  | } cdr_option_flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_APP_OPTIONS(cdr_func_options, { | 
					
						
							|  |  |  | 	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
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | static int cdr_read(struct ast_channel *chan, char *cmd, char *parse, | 
					
						
							|  |  |  | 		    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-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-02-12 04:28:58 +00:00
										 |  |  | 	if (!chan->cdr) | 
					
						
							|  |  |  | 		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-02-12 04:28:58 +00:00
										 |  |  | 	ast_cdr_getvar(chan->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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | static int cdr_write(struct ast_channel *chan, char *cmd, char *parse, | 
					
						
							|  |  |  | 		     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); | 
					
						
							| 
									
										
										
										
											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" | 
					
						
							|  |  |  | "  integral values.\n", | 
					
						
							| 
									
										
										
										
											2005-05-05 05:39:33 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-11 03:14:05 +00:00
										 |  |  | static char *tdesc = "CDR dialplan function"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int unload_module(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	return ast_custom_function_unregister(&cdr_function); | 
					
						
							| 
									
										
										
										
											2006-02-11 03:14:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int load_module(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	return ast_custom_function_register(&cdr_function); | 
					
						
							| 
									
										
										
										
											2006-02-11 03:14:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | char *description(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return tdesc; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int usecount(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | char *key() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return ASTERISK_GPL_KEY; | 
					
						
							|  |  |  | } |