summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/cdr_mysql.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/addons/cdr_mysql.c b/addons/cdr_mysql.c
index 766c1fc0a..3a0e95788 100644
--- a/addons/cdr_mysql.c
+++ b/addons/cdr_mysql.c
@@ -169,13 +169,12 @@ static void configure_connection_charset(void)
}
}
+static int my_connect_db(struct ast_config *cfg);
+
static int mysql_log(struct ast_cdr *cdr)
{
struct ast_str *sql1 = ast_str_thread_get(&sql1_buf, 1024), *sql2 = ast_str_thread_get(&sql2_buf, 1024);
int retries = 5;
-#if MYSQL_VERSION_ID >= 50013
- my_bool my_bool_true = 1;
-#endif
if (!sql1 || !sql2) {
ast_log(LOG_ERROR, "Memory error\n");
@@ -186,31 +185,30 @@ static int mysql_log(struct ast_cdr *cdr)
db_reconnect:
if (!connected) {
- /* Attempt to connect */
- mysql_init(&mysql);
- /* Add option to quickly timeout the connection */
- if (timeout && mysql_options(&mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)&timeout) != 0) {
- ast_log(LOG_ERROR, "mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
- }
-#if MYSQL_VERSION_ID >= 50013
- /* Add option for automatic reconnection */
- if (mysql_options(&mysql, MYSQL_OPT_RECONNECT, &my_bool_true) != 0) {
- ast_log(LOG_ERROR, "mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
- }
-#endif
- if (ssl_ca || ssl_cert || ssl_key) {
- mysql_ssl_set(&mysql, ssl_key ? ast_str_buffer(ssl_key) : NULL, ssl_cert ? ast_str_buffer(ssl_cert) : NULL, ssl_ca ? ast_str_buffer(ssl_ca) : NULL, NULL, NULL);
- }
+ struct ast_flags config_flags = { 0 };
+ struct ast_config *cfg = ast_config_load(config, config_flags);
+ ast_verb(3, "Not connected. Attemptint to re-establish connection to MySQL CDR database.\n");
+ if (cfg == CONFIG_STATUS_FILEMISSING) {
+ ast_log(LOG_WARNING, "Unable to load config for mysql CDR's: %s\n", config);
+ } else if (cfg == CONFIG_STATUS_FILEINVALID) {
+ ast_log(LOG_ERROR, "Unable to load configuration file '%s'\n", config);
+ } else {
+ int res;
- configure_connection_charset();
+ AST_RWLIST_WRLOCK(&columns);
+ res = my_connect_db(cfg);
+ AST_RWLIST_UNLOCK(&columns);
+ ast_config_destroy(cfg);
- if (mysql_real_connect(&mysql, ast_str_buffer(hostname), ast_str_buffer(dbuser), ast_str_buffer(password), ast_str_buffer(dbname), dbport, dbsock && ast_str_strlen(dbsock) ? ast_str_buffer(dbsock) : NULL, ssl_ca ? CLIENT_SSL : 0)) {
- connected = 1;
- connect_time = time(NULL);
- records = 0;
- } else {
- ast_log(LOG_ERROR, "Cannot connect to database server %s: (%d) %s\n", ast_str_buffer(hostname), mysql_errno(&mysql), mysql_error(&mysql));
- connected = 0;
+ if (res == AST_MODULE_LOAD_SUCCESS) {
+ connected = 1;
+ connect_time = time(NULL);
+ records = 0;
+ ast_verb(1, "Re-established connection to MySQL CDR database.\n");
+ } else {
+ ast_verb(3, "Failed to re-establish connection to MySQL CDR database.\n");
+ connected = 0;
+ }
}
} else {
/* Long connection - ping the server */