[asterisk-addons-commits] murf: trunk r409 - in /trunk: cdr_addon_mysql.c configs/cdr_mysql.conf.sample

SVN commits to the Asterisk addons project asterisk-addons-commits at lists.digium.com
Mon Jul 9 12:51:47 CDT 2007


Author: murf
Date: Mon Jul  9 12:51:46 2007
New Revision: 409

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=409
Log:
Committing 7525, a patch to add SSL connections to mysql. murf did a few adaptations

Modified:
    trunk/cdr_addon_mysql.c
    trunk/configs/cdr_mysql.conf.sample

Modified: trunk/cdr_addon_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/cdr_addon_mysql.c?view=diff&rev=409&r1=408&r2=409
==============================================================================
--- trunk/cdr_addon_mysql.c (original)
+++ trunk/cdr_addon_mysql.c Mon Jul  9 12:51:46 2007
@@ -13,6 +13,10 @@
  * Added mysql connection timeout parameter
  * Added an automatic reconnect as to not lose a cdr record
  * Cleaned up the original code to match the coding guidelines
+ *
+ * Modified Juli 2006
+ * Martin Portmann <map at infinitum.ch>
+ * Added mysql ssl support
  *
  * This program is free software, distributed under the terms of
  * the GNU General Public License.
@@ -58,14 +62,16 @@
 			   *dstchannel_field = NULL, *lastapp_field = NULL, *lastdata_field = NULL, *duration_field = NULL, *billsec_field =NULL,
 			   *disposition_field = NULL, *amaflags_field = NULL, *accountcode_field = NULL, *userfield_field = NULL, *uniqueid_field = NULL;
 
+static struct ast_str *ssl_ca = NULL, *ssl_cert = NULL, *ssl_key = NULL;
+
 static int dbport = 0;
 static int connected = 0;
 static time_t connect_time = 0;
 static int records = 0;
 static int totalrecords = 0;
 static int userfield = 0;
-static unsigned int timeout = 0;
-static unsigned int loguniqueid = 0;
+static int timeout = 0;
+static int loguniqueid = 0;
 
 AST_MUTEX_DEFINE_STATIC(mysql_lock);
 
@@ -88,11 +94,11 @@
 		char status[256], status2[100] = "";
 		int ctime = time(NULL) - connect_time;
 		if (dbport)
-			snprintf(status, 255, "Connected to %s@%s, port %d", dbname->str, hostname, dbport);
+			snprintf(status, 255, "Connected to %s@%s, port %d", dbname->str, hostname->str, dbport);
 		else if (dbsock)
-			snprintf(status, 255, "Connected to %s on socket file %s", dbname->str, dbsock);
+			snprintf(status, 255, "Connected to %s on socket file %s", dbname->str, dbsock->str);
 		else
-			snprintf(status, 255, "Connected to %s@%s", dbname->str, hostname);
+			snprintf(status, 255, "Connected to %s@%s", dbname->str, hostname->str);
 
 		if (!ast_strlen_zero(dbuser->str))
 			snprintf(status2, 99, " with username %s", dbuser->str);
@@ -152,12 +158,15 @@
 			ast_log(LOG_ERROR, "cdr_mysql: mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
 		}
 		tmp = dbsock ? dbsock->str : NULL;
-		if (mysql_real_connect(&mysql, hostname->str, dbuser->str, password->str, dbname->str, dbport, tmp, 0)) {
+		if (ssl_ca || ssl_cert || ssl_key) {
+			mysql_ssl_set (&mysql, ssl_key->str, ssl_cert->str, ssl_ca->str, NULL, NULL);
+		}
+		if (mysql_real_connect(&mysql, hostname->str, dbuser->str, password->str, dbname->str, dbport, tmp, ssl_ca ? CLIENT_SSL : 0)) {
 			connected = 1;
 			connect_time = time(NULL);
 			records = 0;
 		} else {
-			ast_log(LOG_ERROR, "cdr_mysql: cannot connect to database server %s.\n", hostname);
+			ast_log(LOG_ERROR, "cdr_mysql: cannot connect to database server %s.\n", hostname->str);
 			connected = 0;
 		}
 	} else {
@@ -330,7 +339,7 @@
 		ast_log(LOG_WARNING, "Unable to load config for mysql CDR's: %s\n", config);
 		return AST_MODULE_LOAD_SUCCESS;
 	}
-	
+
 	var = ast_variable_browse(cfg, "global");
 	if (!var) {
 		/* nothing configured */
@@ -345,6 +354,10 @@
 	res |= my_load_config_string(cfg, "global", "sock", &dbsock, NULL);
 	res |= my_load_config_string(cfg, "global", "table", &dbtable, "cdr");
 	res |= my_load_config_string(cfg, "global", "password", &password, "");
+
+	res |= my_load_config_string(cfg, "global", "ssl_ca", &ssl_ca, NULL);
+	res |= my_load_config_string(cfg, "global", "ssl_cert", &ssl_cert, NULL);
+	res |= my_load_config_string(cfg, "global", "ssl_key", &ssl_key, NULL);
 
 	res |= my_load_config_number(cfg, "global", "port", &dbport, 0);
 	res |= my_load_config_number(cfg, "global", "timeout", &timeout, 0);
@@ -405,9 +418,12 @@
 	if (timeout && mysql_options(&mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)&timeout)!=0) {
 		ast_log(LOG_ERROR, "cdr_mysql: mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
 	}
+	if (ssl_ca || ssl_cert || ssl_key) {
+		mysql_ssl_set (&mysql, ssl_key->str, ssl_cert->str, ssl_ca->str, NULL, NULL);
+	}
 	temp = dbsock ? dbsock->str : NULL;
-	if (!mysql_real_connect(&mysql, hostname->str, dbuser->str, password->str, dbname->str, dbport, temp, 0)) {
-		ast_log(LOG_ERROR, "Failed to connect to mysql database %s on %s.\n", dbname, hostname);
+	if (!mysql_real_connect(&mysql, hostname->str, dbuser->str, password->str, dbname->str, dbport, temp, ssl_ca ? CLIENT_SSL : 0)) {
+		ast_log(LOG_ERROR, "Failed to connect to mysql database %s on %s.\n", dbname->str, hostname->str);
 		connected = 0;
 		records = 0;
 	} else {

Modified: trunk/configs/cdr_mysql.conf.sample
URL: http://svn.digium.com/view/asterisk-addons/trunk/configs/cdr_mysql.conf.sample?view=diff&rev=409&r1=408&r2=409
==============================================================================
--- trunk/configs/cdr_mysql.conf.sample (original)
+++ trunk/configs/cdr_mysql.conf.sample Mon Jul  9 12:51:46 2007
@@ -40,3 +40,8 @@
 ;accountcode_field=accountcode
 ;userfield_field=userfield
 ;uniqueid_field=uniqueid
+;
+; ssl connections (optional)
+;ssl_ca=<path to CA cert>
+;ssl_cert=<path to cert>
+;ssl_key=<path to keyfile>




More information about the asterisk-addons-commits mailing list