| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2004 - 2005 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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. | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 08:45:11 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \file | 
					
						
							| 
									
										
										
										
											2005-10-26 13:03:17 +00:00
										 |  |  |  * \brief Asterisk Call Manager CDR records. | 
					
						
							| 
									
										
										
										
											2008-11-20 17:48:58 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-26 13:03:17 +00:00
										 |  |  |  * See also | 
					
						
							|  |  |  |  * \arg \ref AstCDR | 
					
						
							|  |  |  |  * \arg \ref AstAMI | 
					
						
							|  |  |  |  * \arg \ref Config_ami | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup cdr_drivers | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-14 21:46:45 +00:00
										 |  |  | /*! \li \ref cdr_manager.c uses the configuration file \ref cdr_manager.conf
 | 
					
						
							|  |  |  |  * \addtogroup configuration_file Configuration Files | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \page cdr_manager.conf cdr_manager.conf | 
					
						
							|  |  |  |  * \verbinclude cdr_manager.conf.sample | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 20:28:54 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>core</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-21 13:27:55 +00:00
										 |  |  | /*** DOCUMENTATION
 | 
					
						
							|  |  |  | 	<managerEvent language="en_US" name="Cdr"> | 
					
						
							|  |  |  | 		<managerEventInstance class="EVENT_FLAG_CDR"> | 
					
						
							|  |  |  | 			<synopsis>Raised when a CDR is generated.</synopsis> | 
					
						
							|  |  |  | 			<syntax> | 
					
						
							|  |  |  | 				<parameter name="AccountCode"> | 
					
						
							|  |  |  | 					<para>The account code of the Party A channel.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="Source"> | 
					
						
							|  |  |  | 					<para>The Caller ID number associated with the Party A in the CDR.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="Destination"> | 
					
						
							|  |  |  | 					<para>The dialplan extension the Party A was executing.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="DestinationContext"> | 
					
						
							|  |  |  | 					<para>The dialplan context the Party A was executing.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="CallerID"> | 
					
						
							|  |  |  | 					<para>The Caller ID name associated with the Party A in the CDR.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="Channel"> | 
					
						
							|  |  |  | 					<para>The channel name of the Party A.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="DestinationChannel"> | 
					
						
							|  |  |  | 					<para>The channel name of the Party B.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="LastApplication"> | 
					
						
							|  |  |  | 					<para>The last dialplan application the Party A executed.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="LastData"> | 
					
						
							|  |  |  | 					<para> | 
					
						
							|  |  |  | 						The parameters passed to the last dialplan application the | 
					
						
							|  |  |  | 						Party A executed. | 
					
						
							|  |  |  | 					</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="StartTime"> | 
					
						
							|  |  |  | 					<para>The time the CDR was created.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="AnswerTime"> | 
					
						
							|  |  |  | 					<para> | 
					
						
							|  |  |  | 						The earliest of either the time when Party A answered, or | 
					
						
							|  |  |  | 						the start time of this CDR. | 
					
						
							|  |  |  | 					</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="EndTime"> | 
					
						
							|  |  |  | 					<para> | 
					
						
							|  |  |  | 						The time when the CDR was finished. This occurs when the | 
					
						
							|  |  |  | 						Party A hangs up or when the bridge between Party A and | 
					
						
							|  |  |  | 						Party B is broken. | 
					
						
							|  |  |  | 					</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="Duration"> | 
					
						
							|  |  |  | 					<para>The time, in seconds, of <replaceable>EndTime</replaceable> - <replaceable>StartTime</replaceable>.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="BillableSeconds"> | 
					
						
							|  |  |  | 					<para>The time, in seconds, of <replaceable>AnswerTime</replaceable> - <replaceable>StartTime</replaceable>.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="Disposition"> | 
					
						
							|  |  |  | 					<para>The final known disposition of the CDR.</para> | 
					
						
							|  |  |  | 					<enumlist> | 
					
						
							|  |  |  | 						<enum name="NO ANSWER"> | 
					
						
							|  |  |  | 							<para>The channel was not answered. This is the default disposition.</para> | 
					
						
							|  |  |  | 						</enum> | 
					
						
							|  |  |  | 						<enum name="FAILED"> | 
					
						
							|  |  |  | 							<para>The channel attempted to dial but the call failed.</para> | 
					
						
							|  |  |  | 							<note> | 
					
						
							|  |  |  | 								<para>The congestion setting in <filename>cdr.conf</filename> can result | 
					
						
							|  |  |  | 								in the <literal>AST_CAUSE_CONGESTION</literal> hang up cause or the | 
					
						
							|  |  |  | 								<literal>CONGESTION</literal> dial status to map to this disposition. | 
					
						
							|  |  |  | 								</para> | 
					
						
							|  |  |  | 							</note> | 
					
						
							|  |  |  | 						</enum> | 
					
						
							|  |  |  | 						<enum name="BUSY"> | 
					
						
							|  |  |  | 							<para>The channel attempted to dial but the remote party was busy.</para> | 
					
						
							|  |  |  | 						</enum> | 
					
						
							|  |  |  | 						<enum name="ANSWERED"> | 
					
						
							|  |  |  | 							<para>The channel was answered. The hang up cause will no longer | 
					
						
							|  |  |  | 							impact the disposition of the CDR.</para> | 
					
						
							|  |  |  | 						</enum> | 
					
						
							|  |  |  | 						<enum name="CONGESTION"> | 
					
						
							|  |  |  | 							<para>The channel attempted to dial but the remote party was congested.</para> | 
					
						
							|  |  |  | 						</enum> | 
					
						
							|  |  |  | 					</enumlist> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="AMAFlags"> | 
					
						
							|  |  |  | 					<para>A flag that informs a billing system how to treat the CDR.</para> | 
					
						
							|  |  |  | 					<enumlist> | 
					
						
							|  |  |  | 						<enum name="OMIT"> | 
					
						
							|  |  |  | 							<para>This CDR should be ignored.</para> | 
					
						
							|  |  |  | 						</enum> | 
					
						
							|  |  |  | 						<enum name="BILLING"> | 
					
						
							|  |  |  | 							<para>This CDR contains valid billing data.</para> | 
					
						
							|  |  |  | 						</enum> | 
					
						
							|  |  |  | 						<enum name="DOCUMENTATION"> | 
					
						
							|  |  |  | 							<para>This CDR is for documentation purposes.</para> | 
					
						
							|  |  |  | 						</enum> | 
					
						
							|  |  |  | 					</enumlist> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="UniqueID"> | 
					
						
							|  |  |  | 					<para>A unique identifier for the Party A channel.</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 				<parameter name="UserField"> | 
					
						
							|  |  |  | 					<para> | 
					
						
							|  |  |  | 						A user defined field set on the channels. If set on both the Party A | 
					
						
							|  |  |  | 						and Party B channel, the userfields of both are concatenated and | 
					
						
							|  |  |  | 						separated by a <literal>;</literal>. | 
					
						
							|  |  |  | 					</para> | 
					
						
							|  |  |  | 				</parameter> | 
					
						
							|  |  |  | 			</syntax> | 
					
						
							|  |  |  | 			<description> | 
					
						
							|  |  |  | 				<para> | 
					
						
							|  |  |  | 					The <replaceable>Cdr</replaceable> event is only raised when the | 
					
						
							|  |  |  | 					<filename>cdr_manager</filename> backend is loaded and registered with | 
					
						
							|  |  |  | 					the CDR engine. | 
					
						
							|  |  |  | 				</para> | 
					
						
							|  |  |  | 				<note> | 
					
						
							|  |  |  | 					<para> | 
					
						
							|  |  |  | 						This event can contain additional fields depending on the configuration | 
					
						
							|  |  |  | 						provided by <filename>cdr_manager.conf</filename>. | 
					
						
							|  |  |  | 					</para> | 
					
						
							|  |  |  | 				</note> | 
					
						
							|  |  |  | 			</description> | 
					
						
							|  |  |  | 		</managerEventInstance> | 
					
						
							|  |  |  | 	</managerEvent> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-06 21:09:59 +00:00
										 |  |  | #include <time.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/cdr.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/utils.h"
 | 
					
						
							|  |  |  | #include "asterisk/manager.h"
 | 
					
						
							|  |  |  | #include "asterisk/config.h"
 | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | #include "asterisk/pbx.h"
 | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define DATE_FORMAT 	"%Y-%m-%d %T"
 | 
					
						
							|  |  |  | #define CONF_FILE	"cdr_manager.conf"
 | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | #define CUSTOM_FIELDS_BUF_SIZE 1024
 | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 08:45:11 +00:00
										 |  |  | static const char name[] = "cdr_manager"; | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int enablecdr = 0; | 
					
						
							| 
									
										
										
										
											2009-06-20 20:56:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-15 17:34:30 +00:00
										 |  |  | static struct ast_str *customfields; | 
					
						
							| 
									
										
										
										
											2009-06-21 16:11:48 +00:00
										 |  |  | AST_RWLOCK_DEFINE_STATIC(customfields_lock); | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-21 17:36:17 +00:00
										 |  |  | static int manager_log(struct ast_cdr *cdr); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | static int load_config(int reload) | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 	char *cat = NULL; | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	struct ast_config *cfg; | 
					
						
							|  |  |  | 	struct ast_variable *v; | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; | 
					
						
							| 
									
										
										
										
											2007-09-21 17:36:17 +00:00
										 |  |  | 	int newenablecdr = 0; | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cfg = ast_config_load(CONF_FILE, config_flags); | 
					
						
							| 
									
										
										
										
											2009-06-21 16:00:23 +00:00
										 |  |  | 	if (cfg == CONFIG_STATUS_FILEUNCHANGED) { | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2009-06-21 16:00:23 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-19 19:25:14 +00:00
										 |  |  | 	if (cfg == CONFIG_STATUS_FILEINVALID) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Config file '%s' could not be parsed\n", CONF_FILE); | 
					
						
							| 
									
										
										
										
											2009-06-21 16:00:23 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2008-11-19 19:25:14 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	if (!cfg) { | 
					
						
							|  |  |  | 		/* Standard configuration */ | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n"); | 
					
						
							| 
									
										
										
										
											2013-10-27 20:04:17 +00:00
										 |  |  | 		if (enablecdr) { | 
					
						
							|  |  |  | 			ast_cdr_backend_suspend(name); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 		enablecdr = 0; | 
					
						
							| 
									
										
										
										
											2009-06-21 16:00:23 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-11-20 17:48:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 16:11:48 +00:00
										 |  |  | 	if (reload) { | 
					
						
							|  |  |  | 		ast_rwlock_wrlock(&customfields_lock); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (reload && customfields) { | 
					
						
							|  |  |  | 		ast_free(customfields); | 
					
						
							|  |  |  | 		customfields = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 	while ( (cat = ast_category_browse(cfg, cat)) ) { | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 		if (!strcasecmp(cat, "general")) { | 
					
						
							|  |  |  | 			v = ast_variable_browse(cfg, cat); | 
					
						
							|  |  |  | 			while (v) { | 
					
						
							| 
									
										
										
										
											2007-09-21 17:36:17 +00:00
										 |  |  | 				if (!strcasecmp(v->name, "enabled")) | 
					
						
							|  |  |  | 					newenablecdr = ast_true(v->value); | 
					
						
							| 
									
										
										
										
											2008-11-20 17:48:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 				v = v->next; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else if (!strcasecmp(cat, "mappings")) { | 
					
						
							|  |  |  | 			customfields = ast_str_create(CUSTOM_FIELDS_BUF_SIZE); | 
					
						
							|  |  |  | 			v = ast_variable_browse(cfg, cat); | 
					
						
							|  |  |  | 			while (v) { | 
					
						
							|  |  |  | 				if (customfields && !ast_strlen_zero(v->name) && !ast_strlen_zero(v->value)) { | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 					if ((ast_str_strlen(customfields) + strlen(v->value) + strlen(v->name) + 14) < ast_str_size(customfields)) { | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 						ast_str_append(&customfields, -1, "%s: ${CDR(%s)}\r\n", v->value, v->name); | 
					
						
							|  |  |  | 						ast_log(LOG_NOTICE, "Added mapping %s: ${CDR(%s)}\n", v->value, v->name); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						ast_log(LOG_WARNING, "No more buffer space to add other custom fields\n"); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2008-11-20 17:48:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 				v = v->next; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-11-20 17:48:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 16:11:48 +00:00
										 |  |  | 	if (reload) { | 
					
						
							|  |  |  | 		ast_rwlock_unlock(&customfields_lock); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-01-25 06:10:20 +00:00
										 |  |  | 	ast_config_destroy(cfg); | 
					
						
							| 
									
										
										
										
											2007-09-21 17:36:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-27 20:04:17 +00:00
										 |  |  | 	if (!newenablecdr) { | 
					
						
							|  |  |  | 		ast_cdr_backend_suspend(name); | 
					
						
							|  |  |  | 	} else if (newenablecdr) { | 
					
						
							|  |  |  | 		ast_cdr_backend_unsuspend(name); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-29 18:21:36 +00:00
										 |  |  | 	enablecdr = newenablecdr; | 
					
						
							| 
									
										
										
										
											2007-09-21 17:36:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 16:00:23 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int manager_log(struct ast_cdr *cdr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-18 19:47:20 +00:00
										 |  |  | 	struct ast_tm timeresult; | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	char strStartTime[80] = ""; | 
					
						
							|  |  |  | 	char strAnswerTime[80] = ""; | 
					
						
							|  |  |  | 	char strEndTime[80] = ""; | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 	char buf[CUSTOM_FIELDS_BUF_SIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	if (!enablecdr) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-18 19:47:20 +00:00
										 |  |  | 	ast_localtime(&cdr->start, &timeresult, NULL); | 
					
						
							|  |  |  | 	ast_strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult); | 
					
						
							| 
									
										
										
										
											2008-11-20 17:48:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	if (cdr->answer.tv_sec)	{ | 
					
						
							| 
									
										
										
										
											2007-07-18 19:47:20 +00:00
										 |  |  | 		ast_localtime(&cdr->answer, &timeresult, NULL); | 
					
						
							|  |  |  | 		ast_strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult); | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-18 19:47:20 +00:00
										 |  |  | 	ast_localtime(&cdr->end, &timeresult, NULL); | 
					
						
							|  |  |  | 	ast_strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult); | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 16:11:48 +00:00
										 |  |  | 	buf[0] = '\0'; | 
					
						
							|  |  |  | 	ast_rwlock_rdlock(&customfields_lock); | 
					
						
							|  |  |  | 	if (customfields && ast_str_strlen(customfields)) { | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  | 		struct ast_channel *dummy = ast_dummy_channel_alloc(); | 
					
						
							| 
									
										
										
										
											2009-05-26 12:14:14 +00:00
										 |  |  | 		if (!dummy) { | 
					
						
							|  |  |  | 			ast_log(LOG_ERROR, "Unable to allocate channel for variable substitution.\n"); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 		ast_channel_cdr_set(dummy, ast_cdr_dup(cdr)); | 
					
						
							| 
									
										
										
										
											2009-05-26 12:14:14 +00:00
										 |  |  | 		pbx_substitute_variables_helper(dummy, ast_str_buffer(customfields), buf, sizeof(buf) - 1); | 
					
						
							| 
									
										
										
										
											2011-09-26 19:40:12 +00:00
										 |  |  | 		ast_channel_unref(dummy); | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-21 16:11:48 +00:00
										 |  |  | 	ast_rwlock_unlock(&customfields_lock); | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-05 16:46:47 +00:00
										 |  |  | 	manager_event(EVENT_FLAG_CDR, "Cdr", | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	    "AccountCode: %s\r\n" | 
					
						
							|  |  |  | 	    "Source: %s\r\n" | 
					
						
							|  |  |  | 	    "Destination: %s\r\n" | 
					
						
							|  |  |  | 	    "DestinationContext: %s\r\n" | 
					
						
							|  |  |  | 	    "CallerID: %s\r\n" | 
					
						
							|  |  |  | 	    "Channel: %s\r\n" | 
					
						
							|  |  |  | 	    "DestinationChannel: %s\r\n" | 
					
						
							|  |  |  | 	    "LastApplication: %s\r\n" | 
					
						
							|  |  |  | 	    "LastData: %s\r\n" | 
					
						
							|  |  |  | 	    "StartTime: %s\r\n" | 
					
						
							|  |  |  | 	    "AnswerTime: %s\r\n" | 
					
						
							|  |  |  | 	    "EndTime: %s\r\n" | 
					
						
							| 
									
										
										
										
											2006-03-01 17:53:05 +00:00
										 |  |  | 	    "Duration: %ld\r\n" | 
					
						
							|  |  |  | 	    "BillableSeconds: %ld\r\n" | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	    "Disposition: %s\r\n" | 
					
						
							|  |  |  | 	    "AMAFlags: %s\r\n" | 
					
						
							|  |  |  | 	    "UniqueID: %s\r\n" | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 	    "UserField: %s\r\n" | 
					
						
							|  |  |  | 	    "%s", | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	    cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel, | 
					
						
							|  |  |  | 	    cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime, | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 	    cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), | 
					
						
							| 
									
										
										
										
											2013-06-17 03:00:38 +00:00
										 |  |  | 	    ast_channel_amaflags2string(cdr->amaflags), cdr->uniqueid, cdr->userfield,buf); | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-27 20:04:17 +00:00
										 |  |  | 	if (ast_cdr_unregister(name)) { | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-19 20:38:21 +00:00
										 |  |  | 	if (customfields) | 
					
						
							|  |  |  | 		ast_free(customfields); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-27 20:04:17 +00:00
										 |  |  | 	if (ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log)) { | 
					
						
							|  |  |  | 		return AST_MODULE_LOAD_DECLINE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 16:00:23 +00:00
										 |  |  | 	if (load_config(0)) { | 
					
						
							| 
									
										
										
										
											2013-10-27 20:04:17 +00:00
										 |  |  | 		ast_cdr_unregister(name); | 
					
						
							| 
									
										
										
										
											2006-08-31 21:00:20 +00:00
										 |  |  | 		return AST_MODULE_LOAD_DECLINE; | 
					
						
							| 
									
										
										
										
											2009-06-21 16:00:23 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-21 17:36:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return AST_MODULE_LOAD_SUCCESS; | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int reload(void) | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 	return load_config(1); | 
					
						
							| 
									
										
										
										
											2004-07-25 14:56:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-20 19:35:02 +00:00
										 |  |  | AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Asterisk Manager Interface CDR Backend", | 
					
						
							| 
									
										
										
										
											2015-05-04 23:57:57 -04:00
										 |  |  | 	.support_level = AST_MODULE_SUPPORT_CORE, | 
					
						
							|  |  |  | 	.load = load_module, | 
					
						
							|  |  |  | 	.unload = unload_module, | 
					
						
							|  |  |  | 	.reload = reload, | 
					
						
							|  |  |  | 	.load_pri = AST_MODPRI_CDR_DRIVER, | 
					
						
							| 
									
										
										
										
											2018-02-16 22:11:42 -05:00
										 |  |  | 	.requires = "cdr", | 
					
						
							| 
									
										
										
										
											2015-05-04 23:57:57 -04:00
										 |  |  | ); |