[asterisk-addons-commits] murf: trunk r353 -
/trunk/res_config_mysql.c
asterisk-addons-commits at lists.digium.com
asterisk-addons-commits at lists.digium.com
Tue Mar 27 07:44:02 MST 2007
Author: murf
Date: Tue Mar 27 09:44:01 2007
New Revision: 353
URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=353
Log:
The remainder of the enhancement to the mysql interface: providing the store/destroy functionality for Realtime use, as per 8118
Modified:
trunk/res_config_mysql.c
Modified: trunk/res_config_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/res_config_mysql.c?view=diff&rev=353&r1=352&r2=353
==============================================================================
--- trunk/res_config_mysql.c (original)
+++ trunk/res_config_mysql.c Tue Mar 27 09:44:01 2007
@@ -96,7 +96,7 @@
const char *newparam, *newval;
struct ast_variable *var=NULL, *prev=NULL;
- if(!table) {
+ if (!table) {
ast_log(LOG_WARNING, "MySQL RealTime: No table specified.\n");
return NULL;
}
@@ -104,7 +104,7 @@
/* Get the first parameter and first value in our list of passed paramater/value pairs */
newparam = va_arg(ap, const char *);
newval = va_arg(ap, const char *);
- if(!newparam || !newval) {
+ if (!newparam || !newval) {
ast_log(LOG_WARNING, "MySQL RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
mysql_close(&mysql);
return NULL;
@@ -120,15 +120,21 @@
/* Create the first part of the query using the first parameter/value pairs we just extracted
If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
- if(!strchr(newparam, ' ')) op = " ="; else op = "";
+ if (!strchr(newparam, ' '))
+ op = " =";
+ else
+ op = "";
if ((valsz = strlen (newval)) * 2 + 1 > sizeof(buf))
valsz = (sizeof(buf) - 1) / 2;
mysql_real_escape_string(&mysql, buf, newval, valsz);
snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s '%s'", table, newparam, op, buf);
- while((newparam = va_arg(ap, const char *))) {
+ while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
- if(!strchr(newparam, ' ')) op = " ="; else op = "";
+ if (!strchr(newparam, ' '))
+ op = " =";
+ else
+ op = "";
if ((valsz = strlen (newval)) * 2 + 1 > sizeof(buf))
valsz = (sizeof(buf) - 1) / 2;
mysql_real_escape_string(&mysql, buf, newval, valsz);
@@ -139,7 +145,7 @@
ast_log(LOG_DEBUG, "MySQL RealTime: Retrieve SQL: %s\n", sql);
/* Execution. */
- if(mysql_real_query(&mysql, sql, strlen(sql))) {
+ if (mysql_real_query(&mysql, sql, strlen(sql))) {
ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database. Check debug for more info.\n");
ast_log(LOG_DEBUG, "MySQL RealTime: Query: %s\n", sql);
ast_log(LOG_DEBUG, "MySQL RealTime: Query Failed because: %s\n", mysql_error(&mysql));
@@ -147,17 +153,17 @@
return NULL;
}
- if((result = mysql_store_result(&mysql))) {
+ if ((result = mysql_store_result(&mysql))) {
numFields = mysql_num_fields(result);
fields = mysql_fetch_fields(result);
- while((row = mysql_fetch_row(result))) {
- for(i = 0; i < numFields; i++) {
+ while ((row = mysql_fetch_row(result))) {
+ for (i = 0; i < numFields; i++) {
stringp = row[i];
- while(stringp) {
+ while (stringp) {
chunk = strsep(&stringp, ";");
- if(chunk && !ast_strlen_zero(ast_strip(chunk))) {
- if(prev) {
+ if (chunk && !ast_strlen_zero(ast_strip(chunk))) {
+ if (prev) {
prev->next = ast_variable_new(fields[i].name, chunk);
if (prev->next) {
prev = prev->next;
@@ -197,7 +203,7 @@
struct ast_config *cfg = NULL;
struct ast_category *cat = NULL;
- if(!table) {
+ if (!table) {
ast_log(LOG_WARNING, "MySQL RealTime: No table specified.\n");
return NULL;
}
@@ -214,14 +220,14 @@
/* Get the first parameter and first value in our list of passed paramater/value pairs */
newparam = va_arg(ap, const char *);
newval = va_arg(ap, const char *);
- if(!newparam || !newval) {
+ if (!newparam || !newval) {
ast_log(LOG_WARNING, "MySQL RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
mysql_close(&mysql);
return NULL;
}
initfield = ast_strdupa(newparam);
- if(initfield && (op = strchr(initfield, ' '))) {
+ if (initfield && (op = strchr(initfield, ' '))) {
*op = '\0';
}
@@ -241,16 +247,16 @@
valsz = (sizeof(buf) - 1) / 2;
mysql_real_escape_string(&mysql, buf, newval, valsz);
snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s '%s'", table, newparam, op, buf);
- while((newparam = va_arg(ap, const char *))) {
+ while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
- if(!strchr(newparam, ' ')) op = " ="; else op = "";
+ if (!strchr(newparam, ' ')) op = " ="; else op = "";
if ((valsz = strlen (newval)) * 2 + 1 > sizeof(buf))
valsz = (sizeof(buf) - 1) / 2;
mysql_real_escape_string(&mysql, buf, newval, valsz);
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s '%s'", newparam, op, buf);
}
- if(initfield) {
+ if (initfield) {
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " ORDER BY %s", initfield);
}
@@ -259,7 +265,7 @@
ast_log(LOG_DEBUG, "MySQL RealTime: Retrieve SQL: %s\n", sql);
/* Execution. */
- if(mysql_real_query(&mysql, sql, strlen(sql))) {
+ if (mysql_real_query(&mysql, sql, strlen(sql))) {
ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database. Check debug for more info.\n");
ast_log(LOG_DEBUG, "MySQL RealTime: Query: %s\n", sql);
ast_log(LOG_DEBUG, "MySQL RealTime: Query Failed because: %s\n", mysql_error(&mysql));
@@ -267,23 +273,23 @@
return NULL;
}
- if((result = mysql_store_result(&mysql))) {
+ if ((result = mysql_store_result(&mysql))) {
numFields = mysql_num_fields(result);
fields = mysql_fetch_fields(result);
- while((row = mysql_fetch_row(result))) {
+ while ((row = mysql_fetch_row(result))) {
var = NULL;
cat = ast_category_new("");
- if(!cat) {
+ if (!cat) {
ast_log(LOG_WARNING, "Out of memory!\n");
continue;
}
- for(i = 0; i < numFields; i++) {
+ for (i = 0; i < numFields; i++) {
stringp = row[i];
- while(stringp) {
+ while (stringp) {
chunk = strsep(&stringp, ";");
- if(chunk && !ast_strlen_zero(ast_strip(chunk))) {
- if(initfield && !strcmp(initfield, fields[i].name)) {
+ if (chunk && !ast_strlen_zero(ast_strip(chunk))) {
+ if (initfield && !strcmp(initfield, fields[i].name)) {
ast_category_rename(cat, chunk);
}
var = ast_variable_new(fields[i].name, chunk);
@@ -311,7 +317,7 @@
int valsz;
const char *newparam, *newval;
- if(!table) {
+ if (!table) {
ast_log(LOG_WARNING, "MySQL RealTime: No table specified.\n");
return -1;
}
@@ -319,7 +325,7 @@
/* Get the first parameter and first value in our list of passed paramater/value pairs */
newparam = va_arg(ap, const char *);
newval = va_arg(ap, const char *);
- if(!newparam || !newval) {
+ if (!newparam || !newval) {
ast_log(LOG_WARNING, "MySQL RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
mysql_close(&mysql);
return -1;
@@ -355,7 +361,7 @@
ast_log(LOG_DEBUG,"MySQL RealTime: Update SQL: %s\n", sql);
/* Execution. */
- if(mysql_real_query(&mysql, sql, strlen(sql))) {
+ if (mysql_real_query(&mysql, sql, strlen(sql))) {
ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database. Check debug for more info.\n");
ast_log(LOG_DEBUG, "MySQL RealTime: Query: %s\n", sql);
ast_log(LOG_DEBUG, "MySQL RealTime: Query Failed because: %s\n", mysql_error(&mysql));
@@ -374,12 +380,169 @@
* -1 indicates that the query returned an error (although, if the query failed, it should have been caught above.)
*/
- if(numrows >= 0)
+ if (numrows >= 0)
return (int)numrows;
return -1;
}
-
+
+static int store_mysql(const char *database, const char *table, va_list ap)
+{
+ my_ulonglong insertid;
+ char sql[512];
+ char buf[511]; /* Keep this size uneven as it is 2n+1. */
+ char fields[512];
+ char values[512];
+ int valsz;
+ const char *newparam, *newval;
+
+ if (!table) {
+ ast_log(LOG_WARNING, "MySQL RealTime: No table specified.\n");
+ return -1;
+ }
+ /* Get the first parameter and first value in our list of passed paramater/value pairs */
+ newparam = va_arg(ap, const char *);
+ newval = va_arg(ap, const char *);
+ if (!newparam || !newval) {
+ ast_log(LOG_WARNING, "MySQL RealTime: Realtime storage requires at least 1 parameter and 1 value to search on.\n");
+ mysql_close(&mysql);
+ return -1;
+ }
+ /* Must connect to the server before anything else, as the escape function requires the mysql handle. */
+ ast_mutex_lock(&mysql_lock);
+ if (!mysql_reconnect(database)) {
+ ast_mutex_unlock(&mysql_lock);
+ return -1;
+ }
+ /* Create the first part of the query using the first parameter/value pairs we just extracted
+ If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
+ if ((valsz = strlen(newval)) * 1 + 1 > sizeof(buf))
+ valsz = (sizeof(buf) - 1) / 2;
+ if (newval) {
+ mysql_real_escape_string(&mysql, buf, newval, valsz);
+ } else {
+ buf[0] = 0;
+ }
+ snprintf(fields, sizeof(fields), "%s",newparam);
+ snprintf(values, sizeof(values), "'%s'",buf);
+ while ((newparam = va_arg(ap, const char *))) {
+ newval = va_arg(ap, const char *);
+ if (newval) {
+ if ((valsz = strlen (newval)) * 2 + 1 > sizeof(buf))
+ valsz = (sizeof(buf) - 1) / 2;
+ mysql_real_escape_string(&mysql, buf, newval, valsz);
+ } else {
+ buf[0] = 0;
+ }
+ snprintf(fields + strlen(fields), sizeof(fields), ", %s",newparam);
+ snprintf(values + strlen(values), sizeof(values), ", '%s'",buf);
+ }
+ va_end(ap);
+ snprintf(sql, sizeof(sql), "INSERT into %s (%s) values (%s)", table, fields, values);
+ ast_log(LOG_DEBUG,"MySQL RealTime: Insert SQL: %s\n", sql);
+
+ /* Execution. */
+ if (mysql_real_query(&mysql, sql, strlen(sql))) {
+ ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database. Check debug for more info.\n");
+ ast_log(LOG_DEBUG, "MySQL RealTime: Query: %s\n", sql);
+ ast_log(LOG_DEBUG, "MySQL RealTime: Query Failed because: %s\n", mysql_error(&mysql));
+ ast_mutex_unlock(&mysql_lock);
+ return -1;
+ }
+
+ insertid = mysql_insert_id(&mysql);
+ ast_mutex_unlock(&mysql_lock);
+
+ ast_log(LOG_DEBUG,"MySQL RealTime: row inserted on table: %s, id: %llu\n", table, insertid);
+
+ /* From http://dev.mysql.com/doc/mysql/en/mysql-affected-rows.html
+ * An integer greater than zero indicates the number of rows affected
+ * Zero indicates that no records were updated
+ * -1 indicates that the query returned an error (although, if the query failed, it should have been caught above.)
+ */
+ if (insertid >= 0)
+ return (int)insertid;
+
+ return -1;
+}
+
+static int destroy_mysql(const char *database, const char *table, const char *keyfield, const char *lookup, va_list ap)
+{
+ my_ulonglong numrows;
+ char sql[512];
+ char buf[511]; /* Keep this size uneven as it is 2n+1. */
+ int valsz;
+ const char *newparam, *newval;
+
+ if (!table) {
+ ast_log(LOG_WARNING, "MySQL RealTime: No table specified.\n");
+ return -1;
+ }
+
+ /* Get the first parameter and first value in our list of passed paramater/value pairs */
+ /* newparam = va_arg(ap, const char *);
+ newval = va_arg(ap, const char *);*/
+ if (ast_strlen_zero(keyfield) || ast_strlen_zero(lookup)) {
+ ast_log(LOG_WARNING, "MySQL RealTime: Realtime destroying requires at least 1 parameter and 1 value to search on.\n");
+ mysql_close(&mysql);
+ return -1;
+ }
+
+ /* Must connect to the server before anything else, as the escape function requires the mysql handle. */
+ ast_mutex_lock(&mysql_lock);
+ if (!mysql_reconnect(database)) {
+ ast_mutex_unlock(&mysql_lock);
+ return -1;
+ }
+
+ /* Create the first part of the query using the first parameter/value pairs we just extracted
+ If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
+
+ if ((valsz = strlen (lookup)) * 1 + 1 > sizeof(buf))
+ valsz = (sizeof(buf) - 1) / 2;
+ mysql_real_escape_string(&mysql, buf, lookup, valsz);
+ snprintf(sql, sizeof(sql), "DELETE FROM %s WHERE %s = '%s'", table, keyfield, buf);
+ while ((newparam = va_arg(ap, const char *))) {
+ newval = va_arg(ap, const char *);
+ if ((valsz = strlen (newval)) * 2 + 1 > sizeof(buf))
+ valsz = (sizeof(buf) - 1) / 2;
+ mysql_real_escape_string(&mysql, buf, newval, valsz);
+ snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s = '%s'", newparam, buf);
+ }
+ va_end(ap);
+ //if ((valsz = strlen (lookup)) * 1 + 1 > sizeof(buf))
+ // valsz = (sizeof(buf) - 1) / 2;
+ //mysql_real_escape_string(&mysql, buf, lookup, valsz);
+ //snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " WHERE %s = '%s'", keyfield, buf);
+
+ ast_log(LOG_DEBUG,"MySQL RealTime: Delete SQL: %s\n", sql);
+
+ /* Execution. */
+ if (mysql_real_query(&mysql, sql, strlen(sql))) {
+ ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database. Check debug for more info.\n");
+ ast_log(LOG_DEBUG, "MySQL RealTime: Query: %s\n", sql);
+ ast_log(LOG_DEBUG, "MySQL RealTime: Query Failed because: %s\n", mysql_error(&mysql));
+ ast_mutex_unlock(&mysql_lock);
+ return -1;
+ }
+
+ numrows = mysql_affected_rows(&mysql);
+ ast_mutex_unlock(&mysql_lock);
+
+ ast_log(LOG_DEBUG,"MySQL RealTime: Deleted %llu rows on table: %s\n", numrows, table);
+
+ /* From http://dev.mysql.com/doc/mysql/en/mysql-affected-rows.html
+ * An integer greater than zero indicates the number of rows affected
+ * Zero indicates that no records were updated
+ * -1 indicates that the query returned an error (although, if the query failed, it should have been caught above.)
+ */
+
+ if (numrows >= 0)
+ return (int)numrows;
+
+ return -1;
+}
+
static struct ast_config *config_mysql(const char *database, const char *table, const char *file, struct ast_config *cfg, int withcomments)
{
MYSQL_RES *result;
@@ -393,7 +556,7 @@
last[0] = '\0';
- if(!file || !strcmp(file, RES_CONFIG_MYSQL_CONF)) {
+ if (!file || !strcmp(file, RES_CONFIG_MYSQL_CONF)) {
ast_log(LOG_WARNING, "MySQL RealTime: Cannot configure myself.\n");
return NULL;
}
@@ -404,12 +567,12 @@
/* We now have our complete statement; Lets connect to the server and execute it. */
ast_mutex_lock(&mysql_lock);
- if(!mysql_reconnect(database)) {
- ast_mutex_unlock(&mysql_lock);
- return NULL;
- }
-
- if(mysql_real_query(&mysql, sql, strlen(sql))) {
+ if (!mysql_reconnect(database)) {
+ ast_mutex_unlock(&mysql_lock);
+ return NULL;
+ }
+
+ if (mysql_real_query(&mysql, sql, strlen(sql))) {
ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database. Check debug for more info.\n");
ast_log(LOG_DEBUG, "MySQL RealTime: Query: %s\n", sql);
ast_log(LOG_DEBUG, "MySQL RealTime: Query Failed because: %s\n", mysql_error(&mysql));
@@ -417,15 +580,15 @@
return NULL;
}
- if((result = mysql_store_result(&mysql))) {
+ if ((result = mysql_store_result(&mysql))) {
num_rows = mysql_num_rows(result);
ast_log(LOG_DEBUG, "MySQL RealTime: Found %llu rows.\n", num_rows);
/* There might exist a better way to access the column names other than counting,
but I believe that would require another loop that we don't need. */
- while((row = mysql_fetch_row(result))) {
- if(!strcmp(row[1], "#include")) {
+ while ((row = mysql_fetch_row(result))) {
+ if (!strcmp(row[1], "#include")) {
if (!ast_config_internal_load(row[2], cfg, 0)) {
mysql_free_result(result);
ast_mutex_unlock(&mysql_lock);
@@ -434,7 +597,7 @@
continue;
}
- if(strcmp(last, row[0]) || last_cat_metric != atoi(row[3])) {
+ if (strcmp(last, row[0]) || last_cat_metric != atoi(row[3])) {
cur_cat = ast_category_new(row[0]);
if (!cur_cat) {
ast_log(LOG_WARNING, "Out of memory!\n");
@@ -445,7 +608,8 @@
ast_category_append(cfg, cur_cat);
}
new_v = ast_variable_new(row[1], row[2]);
- ast_variable_append(cur_cat, new_v);
+ if (cur_cat)
+ ast_variable_append(cur_cat, new_v);
}
} else {
ast_log(LOG_WARNING, "MySQL RealTime: Could not find config '%s' in database.\n", file);
@@ -462,6 +626,8 @@
.load_func = config_mysql,
.realtime_func = realtime_mysql,
.realtime_multi_func = realtime_multi_mysql,
+ .store_func = store_mysql,
+ .destroy_func = destroy_mysql,
.update_func = update_mysql
};
@@ -471,13 +637,13 @@
ast_mutex_lock(&mysql_lock);
- if(!mysql_reconnect(NULL)) {
+ if (!mysql_reconnect(NULL)) {
ast_log(LOG_WARNING, "MySQL RealTime: Couldn't establish connection. Check debug.\n");
ast_log(LOG_DEBUG, "MySQL RealTime: Cannot Connect: %s\n", mysql_error(&mysql));
}
ast_config_engine_register(&mysql_engine);
- if(option_verbose) {
+ if (option_verbose) {
ast_verbose("MySQL RealTime driver loaded.\n");
}
ast_cli_register(&cli_realtime_mysql_status);
@@ -495,7 +661,7 @@
mysql_close(&mysql);
ast_cli_unregister(&cli_realtime_mysql_status);
ast_config_engine_deregister(&mysql_engine);
- if(option_verbose) {
+ if (option_verbose) {
ast_verbose("MySQL RealTime unloaded.\n");
}
@@ -516,7 +682,7 @@
connected = 0;
parse_config();
- if(!mysql_reconnect(NULL)) {
+ if (!mysql_reconnect(NULL)) {
ast_log(LOG_WARNING, "MySQL RealTime: Couldn't establish connection. Check debug.\n");
ast_log(LOG_DEBUG, "MySQL RealTime: Cannot Connect: %s\n", mysql_error(&mysql));
}
@@ -536,43 +702,43 @@
config = ast_config_load(RES_CONFIG_MYSQL_CONF);
- if(config) {
- if(!(s=ast_variable_retrieve(config, "general", "dbuser"))) {
+ if (config) {
+ if (!(s=ast_variable_retrieve(config, "general", "dbuser"))) {
ast_log(LOG_WARNING, "MySQL RealTime: No database user found, using 'asterisk' as default.\n");
strncpy(dbuser, "asterisk", sizeof(dbuser) - 1);
} else {
strncpy(dbuser, s, sizeof(dbuser) - 1);
}
- if(!(s=ast_variable_retrieve(config, "general", "dbpass"))) {
+ if (!(s=ast_variable_retrieve(config, "general", "dbpass"))) {
ast_log(LOG_WARNING, "MySQL RealTime: No database password found, using 'asterisk' as default.\n");
strncpy(dbpass, "asterisk", sizeof(dbpass) - 1);
} else {
strncpy(dbpass, s, sizeof(dbpass) - 1);
}
- if(!(s=ast_variable_retrieve(config, "general", "dbhost"))) {
+ if (!(s=ast_variable_retrieve(config, "general", "dbhost"))) {
ast_log(LOG_WARNING, "MySQL RealTime: No database host found, using localhost via socket.\n");
dbhost[0] = '\0';
} else {
strncpy(dbhost, s, sizeof(dbhost) - 1);
}
- if(!(s=ast_variable_retrieve(config, "general", "dbname"))) {
+ if (!(s=ast_variable_retrieve(config, "general", "dbname"))) {
ast_log(LOG_WARNING, "MySQL RealTime: No database name found, using 'asterisk' as default.\n");
strncpy(dbname, "asterisk", sizeof(dbname) - 1);
} else {
strncpy(dbname, s, sizeof(dbname) - 1);
}
- if(!(s=ast_variable_retrieve(config, "general", "dbport"))) {
+ if (!(s=ast_variable_retrieve(config, "general", "dbport"))) {
ast_log(LOG_WARNING, "MySQL RealTime: No database port found, using 3306 as default.\n");
dbport = 3306;
} else {
dbport = atoi(s);
}
- if(dbhost && !(s=ast_variable_retrieve(config, "general", "dbsock"))) {
+ if (dbhost && !(s=ast_variable_retrieve(config, "general", "dbsock"))) {
ast_log(LOG_WARNING, "MySQL RealTime: No database socket found, using '/tmp/mysql.sock' as default.\n");
strncpy(dbsock, "/tmp/mysql.sock", sizeof(dbsock) - 1);
} else {
@@ -581,7 +747,7 @@
}
ast_config_destroy(config);
- if(dbhost) {
+ if (dbhost) {
ast_log(LOG_DEBUG, "MySQL RealTime Host: %s\n", dbhost);
ast_log(LOG_DEBUG, "MySQL RealTime Port: %i\n", dbport);
} else {
@@ -600,7 +766,7 @@
my_bool trueval = 1;
#endif
- if(!database || ast_strlen_zero(database))
+ if (!database || ast_strlen_zero(database))
ast_copy_string(my_database, dbname, sizeof(my_database));
else
ast_copy_string(my_database, database, sizeof(my_database));
@@ -608,13 +774,13 @@
/* mutex lock should have been locked before calling this function. */
reconnect_tryagain:
- if((!connected) && (dbhost || dbsock) && dbuser && dbpass && my_database) {
- if(!mysql_init(&mysql)) {
+ if ((!connected) && (dbhost || dbsock) && dbuser && dbpass && my_database) {
+ if (!mysql_init(&mysql)) {
ast_log(LOG_WARNING, "MySQL RealTime: Insufficient memory to allocate MySQL resource.\n");
connected = 0;
return 0;
}
- if(mysql_real_connect(&mysql, dbhost, dbuser, dbpass, my_database, dbport, dbsock, 0)) {
+ if (mysql_real_connect(&mysql, dbhost, dbuser, dbpass, my_database, dbport, dbsock, 0)) {
#ifdef MYSQL_OPT_RECONNECT
/* The default is no longer to automatically reconnect on failure,
* (as of 5.0.3) so we have to set that option here. */
@@ -642,7 +808,7 @@
connected = 1;
- if(mysql_select_db(&mysql, my_database) != 0) {
+ if (mysql_select_db(&mysql, my_database) != 0) {
ast_log(LOG_WARNING, "MySQL RealTime: Unable to select database: %s. Still Connected (%d).\n", my_database, mysql_errno(&mysql));
ast_log(LOG_DEBUG, "MySQL RealTime: Database Select Failed (%d): %s\n", mysql_error(&mysql), mysql_errno(&mysql));
return 0;
@@ -658,16 +824,16 @@
char status[256], status2[100] = "";
int ctime = time(NULL) - connect_time;
- if(mysql_reconnect(NULL)) {
- if(dbhost) {
+ if (mysql_reconnect(NULL)) {
+ if (dbhost) {
snprintf(status, 255, "Connected to %s@%s, port %d", dbname, dbhost, dbport);
- } else if(dbsock) {
+ } else if (dbsock) {
snprintf(status, 255, "Connected to %s on socket file %s", dbname, dbsock);
} else {
snprintf(status, 255, "Connected to %s@%s", dbname, dbhost);
}
- if(dbuser && *dbuser) {
+ if (dbuser && *dbuser) {
snprintf(status2, 99, " with username %s", dbuser);
}
More information about the asterisk-addons-commits
mailing list