| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-01-15 09:01:52 +00:00
										 |  |  |  * Copyright (C) 2003-2005, Digium, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  |  * Brian K. West <brian@bkw.org> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 08:45:11 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \file | 
					
						
							| 
									
										
										
										
											2005-10-26 13:03:17 +00:00
										 |  |  |  * \brief ODBC CDR Backend | 
					
						
							| 
									
										
										
										
											2008-11-20 17:48:58 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-26 13:03:17 +00:00
										 |  |  |  * \author Brian K. West <brian@bkw.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See also: | 
					
						
							|  |  |  |  * \arg http://www.unixodbc.org
 | 
					
						
							|  |  |  |  * \arg \ref Config_cdr | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup cdr_drivers | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-24 17:11:45 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							| 
									
										
										
										
											2010-08-23 21:33:47 +00:00
										 |  |  | 	<depend>res_odbc</depend> | 
					
						
							| 
									
										
										
										
											2006-04-24 17:11:45 +00:00
										 |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-06 21:09:59 +00:00
										 |  |  | #include "asterisk/config.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/cdr.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | #include "asterisk/res_odbc.h"
 | 
					
						
							| 
									
										
										
										
											2005-06-06 21:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | #define DATE_FORMAT "%Y-%m-%d %T"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 08:45:11 +00:00
										 |  |  | static const char name[] = "ODBC"; | 
					
						
							|  |  |  | static const char config_file[] = "cdr_odbc.conf"; | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | static char *dsn = NULL, *table = NULL; | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | enum { | 
					
						
							|  |  |  | 	CONFIG_LOGUNIQUEID =       1 << 0, | 
					
						
							|  |  |  | 	CONFIG_USEGMTIME =         1 << 1, | 
					
						
							|  |  |  | 	CONFIG_DISPOSITIONSTRING = 1 << 2, | 
					
						
							| 
									
										
										
										
											2010-06-08 23:48:17 +00:00
										 |  |  | 	CONFIG_HRTIME =            1 << 3, | 
					
						
							| 
									
										
										
										
											2010-07-25 18:21:27 +00:00
										 |  |  | 	CONFIG_REGISTERED =        1 << 4, | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | static struct ast_flags config = { 0 }; | 
					
						
							| 
									
										
										
										
											2006-04-19 18:56:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-11 21:10:45 +00:00
										 |  |  | static SQLHSTMT execute_cb(struct odbc_obj *obj, void *data) | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	struct ast_cdr *cdr = data; | 
					
						
							|  |  |  | 	SQLRETURN ODBC_res; | 
					
						
							| 
									
										
										
										
											2004-07-14 13:57:15 +00:00
										 |  |  | 	char sqlcmd[2048] = "", timestr[128]; | 
					
						
							| 
									
										
										
										
											2007-07-18 19:47:20 +00:00
										 |  |  | 	struct ast_tm tm; | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	SQLHSTMT stmt; | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	ast_localtime(&cdr->start, &tm, ast_test_flag(&config, CONFIG_USEGMTIME) ? "GMT" : NULL); | 
					
						
							| 
									
										
										
										
											2007-07-18 19:47:20 +00:00
										 |  |  | 	ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm); | 
					
						
							| 
									
										
										
										
											2008-01-10 17:38:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	if (ast_test_flag(&config, CONFIG_LOGUNIQUEID)) { | 
					
						
							| 
									
										
										
										
											2004-12-10 11:59:43 +00:00
										 |  |  | 		snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s " | 
					
						
							| 
									
										
										
										
											2003-12-24 00:04:33 +00:00
										 |  |  | 		"(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp," | 
					
						
							| 
									
										
										
										
											2004-01-11 06:01:02 +00:00
										 |  |  | 		"lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) " | 
					
						
							| 
									
										
										
										
											2008-01-11 18:30:00 +00:00
										 |  |  | 		"VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table, timestr); | 
					
						
							| 
									
										
										
										
											2004-10-05 01:05:30 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-12-10 11:59:43 +00:00
										 |  |  | 		snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s " | 
					
						
							| 
									
										
										
										
											2003-12-24 00:04:33 +00:00
										 |  |  | 		"(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata," | 
					
						
							|  |  |  | 		"duration,billsec,disposition,amaflags,accountcode) " | 
					
						
							| 
									
										
										
										
											2008-01-11 18:30:00 +00:00
										 |  |  | 		"VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?)", table, timestr); | 
					
						
							| 
									
										
										
										
											2003-12-24 00:04:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	ODBC_res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt); | 
					
						
							| 
									
										
										
										
											2003-12-24 00:04:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-05 01:05:30 +00:00
										 |  |  | 	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) { | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 		ast_verb(11, "cdr_odbc: Failure in AllocStatement %d\n", ODBC_res); | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 		SQLFreeHandle(SQL_HANDLE_STMT, stmt); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2003-12-07 17:12:39 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-10 17:38:36 +00:00
										 |  |  | 	SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->clid), 0, cdr->clid, 0, NULL); | 
					
						
							|  |  |  | 	SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->src), 0, cdr->src, 0, NULL); | 
					
						
							|  |  |  | 	SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dst), 0, cdr->dst, 0, NULL); | 
					
						
							|  |  |  | 	SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dcontext), 0, cdr->dcontext, 0, NULL); | 
					
						
							|  |  |  | 	SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->channel), 0, cdr->channel, 0, NULL); | 
					
						
							|  |  |  | 	SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dstchannel), 0, cdr->dstchannel, 0, NULL); | 
					
						
							|  |  |  | 	SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->lastapp), 0, cdr->lastapp, 0, NULL); | 
					
						
							|  |  |  | 	SQLBindParameter(stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->lastdata), 0, cdr->lastdata, 0, NULL); | 
					
						
							| 
									
										
										
										
											2010-06-08 23:48:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_test_flag(&config, CONFIG_HRTIME)) { | 
					
						
							|  |  |  | 		double hrbillsec = 0.0; | 
					
						
							|  |  |  | 		double hrduration; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!ast_tvzero(cdr->answer)) { | 
					
						
							|  |  |  | 			hrbillsec = (double) ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		hrduration = (double) ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 0, 0, &hrbillsec, 0, NULL); | 
					
						
							|  |  |  | 		SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 0, 0, &hrduration, 0, NULL); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->duration, 0, NULL); | 
					
						
							|  |  |  | 		SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->billsec, 0, NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	if (ast_test_flag(&config, CONFIG_DISPOSITIONSTRING)) | 
					
						
							| 
									
										
										
										
											2008-01-10 17:38:36 +00:00
										 |  |  | 		SQLBindParameter(stmt, 11, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(ast_cdr_disp2str(cdr->disposition)) + 1, 0, ast_cdr_disp2str(cdr->disposition), 0, NULL); | 
					
						
							| 
									
										
										
										
											2005-01-11 18:56:57 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2008-01-10 17:38:36 +00:00
										 |  |  | 		SQLBindParameter(stmt, 11, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->disposition, 0, NULL); | 
					
						
							|  |  |  | 	SQLBindParameter(stmt, 12, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->amaflags, 0, NULL); | 
					
						
							|  |  |  | 	SQLBindParameter(stmt, 13, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->accountcode), 0, cdr->accountcode, 0, NULL); | 
					
						
							| 
									
										
										
										
											2003-12-24 00:04:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	if (ast_test_flag(&config, CONFIG_LOGUNIQUEID)) { | 
					
						
							| 
									
										
										
										
											2008-01-10 17:38:36 +00:00
										 |  |  | 		SQLBindParameter(stmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->uniqueid), 0, cdr->uniqueid, 0, NULL); | 
					
						
							|  |  |  | 		SQLBindParameter(stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->userfield), 0, cdr->userfield, 0, NULL); | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-11 21:10:45 +00:00
										 |  |  | 	ODBC_res = SQLExecDirect(stmt, (unsigned char *)sqlcmd, SQL_NTS); | 
					
						
							| 
									
										
										
										
											2008-11-20 17:48:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-11 21:10:45 +00:00
										 |  |  | 	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) { | 
					
						
							|  |  |  | 		ast_verb(11, "cdr_odbc: Error in ExecDirect: %d\n", ODBC_res); | 
					
						
							|  |  |  | 		SQLFreeHandle(SQL_HANDLE_STMT, stmt); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	return stmt; | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int odbc_log(struct ast_cdr *cdr) | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	struct odbc_obj *obj = ast_odbc_request_obj(dsn, 0); | 
					
						
							|  |  |  | 	SQLHSTMT stmt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!obj) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Unable to retrieve database handle.  CDR failed.\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2004-12-10 11:59:43 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-01-15 09:01:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-11 21:10:45 +00:00
										 |  |  | 	stmt = ast_odbc_direct_execute(obj, execute_cb, cdr); | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	if (stmt) { | 
					
						
							| 
									
										
										
										
											2007-11-02 03:09:02 +00:00
										 |  |  | 		SQLLEN rows = 0; | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		SQLRowCount(stmt, &rows); | 
					
						
							|  |  |  | 		SQLFreeHandle(SQL_HANDLE_STMT, stmt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (rows == 0) | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "CDR successfully ran, but inserted 0 rows?\n"); | 
					
						
							|  |  |  | 	} else | 
					
						
							| 
									
										
										
										
											2008-03-11 21:10:45 +00:00
										 |  |  | 		ast_log(LOG_ERROR, "CDR direct execute failed\n"); | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	ast_odbc_release_obj(obj); | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | static int odbc_load_module(int reload) | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-01-04 05:11:53 +00:00
										 |  |  | 	int res = 0; | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 	struct ast_config *cfg; | 
					
						
							|  |  |  | 	struct ast_variable *var; | 
					
						
							| 
									
										
										
										
											2006-09-20 20:40:39 +00:00
										 |  |  | 	const char *tmp; | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 	do { | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 		cfg = ast_config_load(config_file, config_flags); | 
					
						
							| 
									
										
										
										
											2008-11-19 19:25:14 +00:00
										 |  |  | 		if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) { | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 			ast_log(LOG_WARNING, "cdr_odbc: Unable to load config for ODBC CDR's: %s\n", config_file); | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 			res = AST_MODULE_LOAD_DECLINE; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2008-11-20 17:48:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 		var = ast_variable_browse(cfg, "global"); | 
					
						
							|  |  |  | 		if (!var) { | 
					
						
							|  |  |  | 			/* nothing configured */ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 		if ((tmp = ast_variable_retrieve(cfg, "global", "dsn")) == NULL) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "cdr_odbc: dsn not specified.  Assuming asteriskdb\n"); | 
					
						
							|  |  |  | 			tmp = "asteriskdb"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (dsn) | 
					
						
							|  |  |  | 			ast_free(dsn); | 
					
						
							|  |  |  | 		dsn = ast_strdup(tmp); | 
					
						
							|  |  |  | 		if (dsn == NULL) { | 
					
						
							| 
									
										
										
										
											2005-01-15 09:01:52 +00:00
										 |  |  | 			res = -1; | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 		if (((tmp = ast_variable_retrieve(cfg, "global", "dispositionstring"))) && ast_true(tmp)) | 
					
						
							|  |  |  | 			ast_set_flag(&config, CONFIG_DISPOSITIONSTRING); | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 			ast_clear_flag(&config, CONFIG_DISPOSITIONSTRING); | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 		if (((tmp = ast_variable_retrieve(cfg, "global", "loguniqueid"))) && ast_true(tmp)) { | 
					
						
							|  |  |  | 			ast_set_flag(&config, CONFIG_LOGUNIQUEID); | 
					
						
							|  |  |  | 			ast_debug(1, "cdr_odbc: Logging uniqueid\n"); | 
					
						
							| 
									
										
										
										
											2004-10-05 01:05:30 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 			ast_clear_flag(&config, CONFIG_LOGUNIQUEID); | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 			ast_debug(1, "cdr_odbc: Not logging uniqueid\n"); | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 		if (((tmp = ast_variable_retrieve(cfg, "global", "usegmtime"))) && ast_true(tmp)) { | 
					
						
							|  |  |  | 			ast_set_flag(&config, CONFIG_USEGMTIME); | 
					
						
							|  |  |  | 			ast_debug(1, "cdr_odbc: Logging in GMT\n"); | 
					
						
							| 
									
										
										
										
											2005-02-04 05:52:45 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 			ast_clear_flag(&config, CONFIG_USEGMTIME); | 
					
						
							|  |  |  | 			ast_debug(1, "cdr_odbc: Logging in local time\n"); | 
					
						
							| 
									
										
										
										
											2005-02-04 05:52:45 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 23:48:17 +00:00
										 |  |  | 		if (((tmp = ast_variable_retrieve(cfg, "global", "hrtime"))) && ast_true(tmp)) { | 
					
						
							|  |  |  | 			ast_set_flag(&config, CONFIG_HRTIME); | 
					
						
							|  |  |  | 			ast_debug(1, "cdr_odbc: Logging billsec and duration fields as floats\n"); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			ast_clear_flag(&config, CONFIG_HRTIME); | 
					
						
							|  |  |  | 			ast_debug(1, "cdr_odbc: Logging billsec and duration fields as integers\n"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 		if ((tmp = ast_variable_retrieve(cfg, "global", "table")) == NULL) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "cdr_odbc: table not specified.  Assuming cdr\n"); | 
					
						
							|  |  |  | 			tmp = "cdr"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (table) | 
					
						
							|  |  |  | 			ast_free(table); | 
					
						
							|  |  |  | 		table = ast_strdup(tmp); | 
					
						
							|  |  |  | 		if (table == NULL) { | 
					
						
							|  |  |  | 			res = -1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-12-10 11:59:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 		ast_verb(3, "cdr_odbc: dsn is %s\n", dsn); | 
					
						
							|  |  |  | 		ast_verb(3, "cdr_odbc: table is %s\n", table); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-25 18:21:27 +00:00
										 |  |  | 		if (!ast_test_flag(&config, CONFIG_REGISTERED)) { | 
					
						
							|  |  |  | 			res = ast_cdr_register(name, ast_module_info->description, odbc_log); | 
					
						
							|  |  |  | 			if (res) { | 
					
						
							|  |  |  | 				ast_log(LOG_ERROR, "cdr_odbc: Unable to register ODBC CDR handling\n"); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				ast_set_flag(&config, CONFIG_REGISTERED); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-01-15 09:01:52 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 	} while (0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-25 18:21:27 +00:00
										 |  |  | 	if (ast_test_flag(&config, CONFIG_REGISTERED) && (!cfg || dsn == NULL || table == NULL)) { | 
					
						
							|  |  |  | 		ast_cdr_unregister(name); | 
					
						
							|  |  |  | 		ast_clear_flag(&config, CONFIG_REGISTERED); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID) { | 
					
						
							| 
									
										
										
										
											2006-10-23 00:33:20 +00:00
										 |  |  | 		ast_config_destroy(cfg); | 
					
						
							| 
									
										
										
										
											2010-07-25 18:21:27 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	return odbc_load_module(0); | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	ast_cdr_unregister(name); | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	if (dsn) { | 
					
						
							|  |  |  | 		ast_verb(11, "cdr_odbc: free dsn\n"); | 
					
						
							|  |  |  | 		ast_free(dsn); | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	if (table) { | 
					
						
							|  |  |  | 		ast_verb(11, "cdr_odbc: free table\n"); | 
					
						
							|  |  |  | 		ast_free(table); | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-01 22:43:46 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int reload(void) | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 	return odbc_load_module(1); | 
					
						
							| 
									
										
										
										
											2003-12-02 00:27:28 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-20 19:35:02 +00:00
										 |  |  | AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "ODBC CDR Backend", | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 		.load = load_module, | 
					
						
							|  |  |  | 		.unload = unload_module, | 
					
						
							|  |  |  | 		.reload = reload, | 
					
						
							| 
									
										
										
										
											2010-07-20 19:35:02 +00:00
										 |  |  | 		.load_pri = AST_MODPRI_CDR_DRIVER, | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	       ); |