aboutsummaryrefslogtreecommitdiffstats
path: root/cdr
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-08-16 14:48:05 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-08-16 14:48:05 +0000
commitb7fbd14cece6a0345918a946fdba5bdc3268e539 (patch)
treefcbef020d83e4b58d4c02767b399ff6820ded89e /cdr
parentc3ef7b672f25621ba670ba22955a3dfc0953c739 (diff)
New "show codecs" option and mysql feature requests from Tilghman
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1349 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr')
-rwxr-xr-xcdr/cdr_mysql.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/cdr/cdr_mysql.c b/cdr/cdr_mysql.c
index f60936133..a74756b24 100755
--- a/cdr/cdr_mysql.c
+++ b/cdr/cdr_mysql.c
@@ -37,8 +37,9 @@
static char *desc = "MySQL CDR Backend";
static char *name = "mysql";
static char *config = "cdr_mysql.conf";
-static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL;
-static int hostname_alloc = 0, dbname_alloc = 0, dbuser_alloc = 0, password_alloc = 0;
+static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *dbsock = NULL;
+static int hostname_alloc = 0, dbname_alloc = 0, dbuser_alloc = 0, password_alloc = 0, dbsock_alloc = 0;
+static int dbport = 0;
static int connected = 0;
static ast_mutex_t mysql_lock = AST_MUTEX_INITIALIZER;
@@ -61,10 +62,10 @@ static int mysql_log(struct ast_cdr *cdr)
localtime_r(&t,&tm);
strftime(timestr,128,DATE_FORMAT,&tm);
- if ((!connected) && hostname && dbuser && password && dbname) {
+ if ((!connected) && (hostname || dbsock) && dbuser && password && dbname) {
/* Attempt to connect */
mysql_init(&mysql);
- if (mysql_real_connect(&mysql, hostname, dbuser, password, dbname, 0, NULL, 0)) {
+ if (mysql_real_connect(&mysql, hostname, dbuser, password, dbname, dbport, dbsock, 0)) {
connected = 1;
} else {
ast_log(LOG_ERROR, "cdr_mysql: cannot connect to database server %s. Call will not be logged\n", hostname);
@@ -129,11 +130,17 @@ int unload_module(void)
dbuser = NULL;
dbuser_alloc = 0;
}
+ if (dbsock && dbsock_alloc) {
+ free(dbsock);
+ dbsock = NULL;
+ dbsock_alloc = 0;
+ }
if (password && password_alloc) {
free(password);
password = NULL;
password_alloc = 0;
}
+ dbport = 0;
ast_cdr_unregister(name);
return 0;
}
@@ -202,6 +209,21 @@ int load_module(void)
dbuser = "root";
}
+ tmp = ast_variable_retrieve(cfg,"global","sock");
+ if (tmp) {
+ dbsock = malloc(strlen(tmp) + 1);
+ if (dbsock != NULL) {
+ dbsock_alloc = 1;
+ strcpy(dbsock,tmp);
+ } else {
+ ast_log(LOG_ERROR,"Out of memory error.\n");
+ return -1;
+ }
+ } else {
+ ast_log(LOG_WARNING,"MySQL database sock file not specified. Assuming default\n");
+ dbsock = NULL;
+ }
+
tmp = ast_variable_retrieve(cfg,"global","password");
if (tmp) {
password = malloc(strlen(tmp) + 1);
@@ -217,9 +239,20 @@ int load_module(void)
password = "";
}
+ tmp = ast_variable_retrieve(cfg,"global","port");
+ if (tmp) {
+ if (sscanf(tmp,"%d",&dbport) < 1) {
+ ast_log(LOG_WARNING,"Invalid MySQL port number. Using default\n");
+ dbport = 0;
+ }
+ }
+
ast_destroy(cfg);
ast_log(LOG_DEBUG,"cdr_mysql: got hostname of %s\n",hostname);
+ ast_log(LOG_DEBUG,"cdr_mysql: got port of %d\n",dbport);
+ if (dbsock)
+ ast_log(LOG_DEBUG,"cdr_mysql: got sock file of %s\n",dbsock);
ast_log(LOG_DEBUG,"cdr_mysql: got user of %s\n",dbuser);
ast_log(LOG_DEBUG,"cdr_mysql: got dbname of %s\n",dbname);
ast_log(LOG_DEBUG,"cdr_mysql: got password of %s\n",password);