diff --git a/src/modules/db_mysql/db_mysql.c b/src/modules/db_mysql/db_mysql.c index a2ba56309ff..9bf939b5ceb 100644 --- a/src/modules/db_mysql/db_mysql.c +++ b/src/modules/db_mysql/db_mysql.c @@ -22,7 +22,7 @@ /** @addtogroup mysql * @{ */ - + #include "db_mysql.h" #include "km_db_mysql.h" @@ -126,9 +126,9 @@ static int mysql_mod_init(void) { #if MYSQL_VERSION_ID >= 40101 my_client_ver = mysql_get_client_version(); - if ((my_client_ver >= 50025) || - ((my_client_ver >= 40122) && - (my_client_ver < 50000))) { + if ((my_client_ver >= 50025) || + ((my_client_ver >= 40122) && + (my_client_ver < 50000))) { if (my_send_to == 0) { my_send_to= DEFAULT_MY_SEND_TO; } diff --git a/src/modules/db_mysql/db_mysql.h b/src/modules/db_mysql/db_mysql.h index f762a2c0d36..0b8512390f9 100644 --- a/src/modules/db_mysql/db_mysql.h +++ b/src/modules/db_mysql/db_mysql.h @@ -1,4 +1,4 @@ -/* +/* * MySQL module interface * * Copyright (C) 2001-2003 FhG Fokus @@ -15,8 +15,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ diff --git a/src/modules/db_mysql/km_db_mysql.c b/src/modules/db_mysql/km_db_mysql.c index 5279a8373f6..0f521265ca2 100644 --- a/src/modules/db_mysql/km_db_mysql.c +++ b/src/modules/db_mysql/km_db_mysql.c @@ -1,4 +1,4 @@ -/* +/* * MySQL module interface * * Copyright (C) 2001-2003 FhG Fokus @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -65,7 +65,7 @@ static param_export_t params[] = { {0, 0, 0} }; -struct kam_module_exports kam_exports = { +struct kam_module_exports kam_exports = { "db_mysql", DEFAULT_DLFLAGS, /* dlopen flags */ cmds, diff --git a/src/modules/db_mysql/km_db_mysql.h b/src/modules/db_mysql/km_db_mysql.h index 80afd4a542c..b79d5227926 100644 --- a/src/modules/db_mysql/km_db_mysql.h +++ b/src/modules/db_mysql/km_db_mysql.h @@ -1,4 +1,4 @@ -/* +/* * MySQL module interface * * Copyright (C) 2001-2003 FhG Fokus @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ diff --git a/src/modules/db_mysql/km_dbase.c b/src/modules/db_mysql/km_dbase.c index f19f19119a5..aa960f4963c 100644 --- a/src/modules/db_mysql/km_dbase.c +++ b/src/modules/db_mysql/km_dbase.c @@ -1,4 +1,4 @@ -/* +/* * MySQL module core functions * * Copyright (C) 2001-2003 FhG Fokus @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -68,7 +68,7 @@ static char *mysql_sql_buf; * \return zero on success, negative value on failure */ static int db_mysql_submit_query(const db1_con_t* _h, const str* _s) -{ +{ time_t t; int i, code; @@ -137,9 +137,9 @@ void db_mysql_async_exec_task(void *param) { str *p; db1_con_t* dbc; - + p = (str*)param; - + dbc = db_mysql_init(&p[0]); if(dbc==NULL) { @@ -148,7 +148,7 @@ void db_mysql_async_exec_task(void *param) } if(db_mysql_submit_query(dbc, &p[1])<0) { LM_ERR("failed to execute query [%.*s] on async worker\n", - (p[1].len>100)?100:p[1].len, p[1].s); + (p[1].len>100)?100:p[1].len, p[1].s); } db_mysql_close(dbc); } @@ -295,20 +295,20 @@ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r) */ int db_mysql_free_result(const db1_con_t* _h, db1_res_t* _r) { - if ((!_h) || (!_r)) { - LM_ERR("invalid parameter value\n"); - return -1; - } - - mysql_free_result(RES_RESULT(_r)); - RES_RESULT(_r) = 0; - pkg_free(RES_PTR(_r)); - - if (db_free_result(_r) < 0) { - LM_ERR("unable to free result structure\n"); - return -1; - } - return 0; + if ((!_h) || (!_r)) { + LM_ERR("invalid parameter value\n"); + return -1; + } + + mysql_free_result(RES_RESULT(_r)); + RES_RESULT(_r) = 0; + pkg_free(RES_PTR(_r)); + + if (db_free_result(_r) < 0) { + LM_ERR("unable to free result structure\n"); + return -1; + } + return 0; } @@ -326,8 +326,8 @@ int db_mysql_free_result(const db1_con_t* _h, db1_res_t* _r) * \return zero on success, negative value on failure */ int db_mysql_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op, - const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc, - const db_key_t _o, db1_res_t** _r) + const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc, + const db_key_t _o, db1_res_t** _r) { return db_do_query(_h, _k, _op, _v, _c, _n, _nc, _o, _r, db_mysql_val2str, db_mysql_submit_query, db_mysql_store_result); @@ -526,8 +526,8 @@ int db_mysql_delete(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o, * \param _un number of columns to update * \return zero on success, negative value on failure */ -int db_mysql_update(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o, - const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n, +int db_mysql_update(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o, + const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n, const int _un) { return db_do_update(_h, _k, _o, _v, _uk, _uv, _n, _un, db_mysql_val2str, @@ -716,8 +716,8 @@ int db_mysql_end_transaction(db1_con_t* _h) } /* Only _end_ the transaction after the raw_query. That way, if the - raw_query fails, and the calling module does an abort_transaction() - to clean-up, a ROLLBACK will be sent to the DB. */ + * raw_query fails, and the calling module does an abort_transaction() + * to clean-up, a ROLLBACK will be sent to the DB. */ CON_TRANSACTION(_h) = 0; if(db_mysql_unlock_tables(_h)<0) @@ -749,7 +749,7 @@ int db_mysql_abort_transaction(db1_con_t* _h) } /* Whether the rollback succeeds or not we need to _end_ the - transaction now or all future starts will fail */ + * transaction now or all future starts will fail */ CON_TRANSACTION(_h) = 0; if (db_mysql_raw_query(_h, &rollback_query_str, NULL) < 0) @@ -775,23 +775,23 @@ int db_mysql_abort_transaction(db1_con_t* _h) /** - * Insert a row into a specified table, update on duplicate key. - * \param _h structure representing database connection - * \param _k key names - * \param _v values of the keys - * \param _n number of key=value pairs + * Insert a row into a specified table, update on duplicate key. + * \param _h structure representing database connection + * \param _k key names + * \param _v values of the keys + * \param _n number of key=value pairs */ - int db_mysql_insert_update(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, +int db_mysql_insert_update(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n) - { +{ int off, ret; static str sql_str; - + if ((!_h) || (!_k) || (!_v) || (!_n)) { LM_ERR("invalid parameter value\n"); return -1; } - + ret = snprintf(mysql_sql_buf, sql_buffer_size, "insert into %s%.*s%s (", CON_TQUOTESZ(_h), CON_TABLE(_h)->len, CON_TABLE(_h)->s, CON_TQUOTESZ(_h)); if (ret < 0 || ret >= sql_buffer_size) goto error; @@ -809,18 +809,18 @@ int db_mysql_abort_transaction(db1_con_t* _h) off += ret; *(mysql_sql_buf + off++) = ')'; - + ret = snprintf(mysql_sql_buf + off, sql_buffer_size - off, " on duplicate key update "); if (ret < 0 || ret >= (sql_buffer_size - off)) goto error; off += ret; - + ret = db_print_set(_h, mysql_sql_buf + off, sql_buffer_size - off, _k, _v, _n, db_mysql_val2str); if (ret < 0) return -1; off += ret; - + sql_str.s = mysql_sql_buf; sql_str.len = off; - + if (db_mysql_submit_query(_h, &sql_str) < 0) { LM_ERR("error while submitting query\n"); return -2; @@ -841,7 +841,8 @@ int db_mysql_abort_transaction(db1_con_t* _h) * \param _n number of key=value pairs * \return zero on success, negative value on failure */ -int db_mysql_insert_delayed(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n) +int db_mysql_insert_delayed(const db1_con_t* _h, const db_key_t* _k, + const db_val_t* _v, const int _n) { return db_do_insert_delayed(_h, _k, _v, _n, db_mysql_val2str, db_mysql_submit_query); @@ -855,7 +856,8 @@ int db_mysql_insert_delayed(const db1_con_t* _h, const db_key_t* _k, const db_va * \param _n number of key=value pairs * \return zero on success, negative value on failure */ -int db_mysql_insert_async(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n) +int db_mysql_insert_async(const db1_con_t* _h, const db_key_t* _k, + const db_val_t* _v, const int _n) { return db_do_insert(_h, _k, _v, _n, db_mysql_val2str, db_mysql_submit_query_async); @@ -882,15 +884,15 @@ int db_mysql_use_table(db1_con_t* _h, const str* _t) */ int db_mysql_alloc_buffer(void) { - if (db_api_init()) - { - LM_ERR("Failed to initialise db api\n"); + if (db_api_init()) + { + LM_ERR("Failed to initialise db api\n"); return -1; - } + } - mysql_sql_buf = (char*)malloc(sql_buffer_size); - if (mysql_sql_buf == NULL) - return -1; - else - return 0; + mysql_sql_buf = (char*)malloc(sql_buffer_size); + if (mysql_sql_buf == NULL) + return -1; + else + return 0; } diff --git a/src/modules/db_mysql/km_dbase.h b/src/modules/db_mysql/km_dbase.h index e7c6dfe6df3..5a5f162ce93 100644 --- a/src/modules/db_mysql/km_dbase.h +++ b/src/modules/db_mysql/km_dbase.h @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -63,8 +63,8 @@ int db_mysql_free_result(const db1_con_t* _h, db1_res_t* _r); * Do a query */ int db_mysql_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op, - const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc, - const db_key_t _o, db1_res_t** _r); + const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc, + const db_key_t _o, db1_res_t** _r); /*! \brief @@ -88,13 +88,14 @@ int db_mysql_raw_query_async(const db1_con_t* _h, const str* _s); /*! \brief * Insert a row into table */ -int db_mysql_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n); +int db_mysql_insert(const db1_con_t* _h, const db_key_t* _k, + const db_val_t* _v, const int _n); /*! \brief * Delete a row from table */ -int db_mysql_delete(const db1_con_t* _h, const db_key_t* _k, const +int db_mysql_delete(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o, const db_val_t* _v, const int _n); @@ -142,7 +143,8 @@ int db_mysql_abort_transaction(db1_con_t* _h); /*! \brief * Insert a row into table, update on duplicate key */ -int db_mysql_insert_update(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, +int db_mysql_insert_update(const db1_con_t* _h, const db_key_t* _k, + const db_val_t* _v, const int _n); diff --git a/src/modules/db_mysql/km_my_con.h b/src/modules/db_mysql/km_my_con.h index ada631430bd..1c799370da9 100644 --- a/src/modules/db_mysql/km_my_con.h +++ b/src/modules/db_mysql/km_my_con.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2003 FhG Fokus * Copyright (C) 2008 1&1 Internet AG * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ diff --git a/src/modules/db_mysql/km_res.c b/src/modules/db_mysql/km_res.c index d531aba582f..19af450fab1 100644 --- a/src/modules/db_mysql/km_res.c +++ b/src/modules/db_mysql/km_res.c @@ -1,4 +1,4 @@ -/* +/* * MySQL module result related functions * * Copyright (C) 2001-2003 FhG Fokus @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -65,7 +65,7 @@ int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r) } else { LM_DBG("%d columns returned from the query\n", RES_COL_N(_r)); } - + if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) { RES_COL_N(_r) = 0; LM_ERR("could not allocate columns\n"); diff --git a/src/modules/db_mysql/km_res.h b/src/modules/db_mysql/km_res.h index 5c73bee9644..fda5d01e746 100644 --- a/src/modules/db_mysql/km_res.h +++ b/src/modules/db_mysql/km_res.h @@ -1,4 +1,4 @@ -/* +/* * MySQL module result related functions * * Copyright (C) 2001-2003 FhG Fokus @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ diff --git a/src/modules/db_mysql/km_row.c b/src/modules/db_mysql/km_row.c index 08a21370499..e5920c9eadf 100644 --- a/src/modules/db_mysql/km_row.c +++ b/src/modules/db_mysql/km_row.c @@ -1,4 +1,4 @@ -/* +/* * MySQL module row related functions * * Copyright (C) 2001-2003 FhG Fokus @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -57,12 +57,12 @@ int db_mysql_convert_row(const db1_con_t* _h, db1_res_t* _res, db_row_t* _r) LM_ERR("could not allocate row"); return -2; } - + lengths = mysql_fetch_lengths(RES_RESULT(_res)); for(i = 0; i < RES_COL_N(_res); i++) { if (db_str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]), - ((MYSQL_ROW)RES_ROW(_res))[i], lengths[i], 0) < 0) { + ((MYSQL_ROW)RES_ROW(_res))[i], lengths[i], 0) < 0) { LM_ERR("failed to convert value\n"); LM_DBG("free row at %p\n", _r); db_free_row(_r); diff --git a/src/modules/db_mysql/km_row.h b/src/modules/db_mysql/km_row.h index 231d26a2568..50ae060487c 100644 --- a/src/modules/db_mysql/km_row.h +++ b/src/modules/db_mysql/km_row.h @@ -1,4 +1,4 @@ -/* +/* * MySQL module row related functions * * Copyright (C) 2001-2003 FhG Fokus @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ diff --git a/src/modules/db_mysql/km_val.c b/src/modules/db_mysql/km_val.c index 905daa5e7ef..7f832d0ad97 100644 --- a/src/modules/db_mysql/km_val.c +++ b/src/modules/db_mysql/km_val.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2003 FhG Fokus * Copyright (C) 2008 1&1 Internet AG * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -81,7 +81,8 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le } else { old_s = _s; *_s++ = '\''; - _s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STRING(_v), l); + _s += mysql_real_escape_string(CON_CONNECTION(_c), _s, + VAL_STRING(_v), l); *_s++ = '\''; *_s = '\0'; /* FIXME */ *_len = _s - old_s; @@ -96,7 +97,8 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le } else { old_s = _s; *_s++ = '\''; - _s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STR(_v).s, VAL_STR(_v).len); + _s += mysql_real_escape_string(CON_CONNECTION(_c), _s, + VAL_STR(_v).s, VAL_STR(_v).len); *_s++ = '\''; *_s = '\0'; *_len = _s - old_s; @@ -117,7 +119,7 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le *_s = '\0'; *_len = _s - old_s; return 0; - } + } break; default: diff --git a/src/modules/db_mysql/km_val.h b/src/modules/db_mysql/km_val.h index 68cee0055c1..e68c831aabc 100644 --- a/src/modules/db_mysql/km_val.h +++ b/src/modules/db_mysql/km_val.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2003 FhG Fokus * Copyright (C) 2008 1&1 Internet AG * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ diff --git a/src/modules/db_mysql/my_cmd.c b/src/modules/db_mysql/my_cmd.c index 8502e6d3233..57fd0c51dc6 100644 --- a/src/modules/db_mysql/my_cmd.c +++ b/src/modules/db_mysql/my_cmd.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2003 FhG Fokus * Copyright (C) 2006-2007 iptelorg GmbH * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -25,7 +25,7 @@ /* the following macro will break the compile on solaris */ #if !defined (__SVR4) && !defined (__sun) - #define _XOPEN_SOURCE 4 /* bsd */ +#define _XOPEN_SOURCE 4 /* bsd */ #endif #define _XOPEN_SOURCE_EXTENDED 1 /* solaris */ #define _SVID_SOURCE 1 /* timegm */ @@ -113,7 +113,7 @@ static str strings[] = { #define APPEND_CSTR(p, cstr) do { \ - int _len = strlen(cstr); \ + int _len = strlen(cstr); \ memcpy((p), (cstr), _len); \ (p) += _len; \ } while(0) @@ -132,8 +132,8 @@ static void my_cmd_free(db_cmd_t* cmd, struct my_cmd* payload) /** Builds a DELETE SQL statement.The function builds DELETE statement where - * cmd->match specify WHERE clause. - * @param sql_cmd SQL statement as a result of this function + * cmd->match specify WHERE clause. + * @param sql_cmd SQL statement as a result of this function * @param cmd input for statement creation * @return -1 on error, 0 on success */ @@ -153,19 +153,19 @@ static int build_delete_cmd(str* sql_cmd, db_cmd_t* cmd) sql_cmd->len += strlen(fld[i].name); switch(fld[i].op) { - case DB_EQ: sql_cmd->len += strings[STR_OP_EQ].len; break; - case DB_NE: sql_cmd->len += strings[STR_OP_NE].len; break; - case DB_LT: sql_cmd->len += strings[STR_OP_LT].len; break; - case DB_GT: sql_cmd->len += strings[STR_OP_GT].len; break; - case DB_LEQ: sql_cmd->len += strings[STR_OP_LEQ].len; break; - case DB_GEQ: sql_cmd->len += strings[STR_OP_GEQ].len; break; - default: - ERR("mysql: Unsupported db_fld operator %d\n", fld[i].op); - return -1; + case DB_EQ: sql_cmd->len += strings[STR_OP_EQ].len; break; + case DB_NE: sql_cmd->len += strings[STR_OP_NE].len; break; + case DB_LT: sql_cmd->len += strings[STR_OP_LT].len; break; + case DB_GT: sql_cmd->len += strings[STR_OP_GT].len; break; + case DB_LEQ: sql_cmd->len += strings[STR_OP_LEQ].len; break; + case DB_GEQ: sql_cmd->len += strings[STR_OP_GEQ].len; break; + default: + ERR("mysql: Unsupported db_fld operator %d\n", fld[i].op); + return -1; } sql_cmd->len += strings[STR_ESC].len; - + if (!DB_FLD_LAST(fld[i + 1])) sql_cmd->len += strings[STR_AND].len; } } @@ -176,7 +176,7 @@ static int build_delete_cmd(str* sql_cmd, db_cmd_t* cmd) return -1; } p = sql_cmd->s; - + APPEND_STR(p, strings[STR_DELETE]); APPEND_STR(p, cmd->table); @@ -187,19 +187,19 @@ static int build_delete_cmd(str* sql_cmd, db_cmd_t* cmd) APPEND_CSTR(p, fld[i].name); switch(fld[i].op) { - case DB_EQ: APPEND_STR(p, strings[STR_OP_EQ]); break; - case DB_NE: APPEND_STR(p, strings[STR_OP_NE]); break; - case DB_LT: APPEND_STR(p, strings[STR_OP_LT]); break; - case DB_GT: APPEND_STR(p, strings[STR_OP_GT]); break; - case DB_LEQ: APPEND_STR(p, strings[STR_OP_LEQ]); break; - case DB_GEQ: APPEND_STR(p, strings[STR_OP_GEQ]); break; + case DB_EQ: APPEND_STR(p, strings[STR_OP_EQ]); break; + case DB_NE: APPEND_STR(p, strings[STR_OP_NE]); break; + case DB_LT: APPEND_STR(p, strings[STR_OP_LT]); break; + case DB_GT: APPEND_STR(p, strings[STR_OP_GT]); break; + case DB_LEQ: APPEND_STR(p, strings[STR_OP_LEQ]); break; + case DB_GEQ: APPEND_STR(p, strings[STR_OP_GEQ]); break; } - + APPEND_STR(p, strings[STR_ESC]); if (!DB_FLD_LAST(fld[i + 1])) APPEND_STR(p, strings[STR_AND]); } } - + *p = '\0'; return 0; } @@ -237,19 +237,19 @@ static int build_select_cmd(str* sql_cmd, db_cmd_t* cmd) sql_cmd->len += strlen(fld[i].name); switch(fld[i].op) { - case DB_EQ: sql_cmd->len += strings[STR_OP_EQ].len; break; - case DB_NE: sql_cmd->len += strings[STR_OP_NE].len; break; - case DB_LT: sql_cmd->len += strings[STR_OP_LT].len; break; - case DB_GT: sql_cmd->len += strings[STR_OP_GT].len; break; - case DB_LEQ: sql_cmd->len += strings[STR_OP_LEQ].len; break; - case DB_GEQ: sql_cmd->len += strings[STR_OP_GEQ].len; break; - default: - ERR("mysql: Unsupported db_fld operator %d\n", fld[i].op); - return -1; + case DB_EQ: sql_cmd->len += strings[STR_OP_EQ].len; break; + case DB_NE: sql_cmd->len += strings[STR_OP_NE].len; break; + case DB_LT: sql_cmd->len += strings[STR_OP_LT].len; break; + case DB_GT: sql_cmd->len += strings[STR_OP_GT].len; break; + case DB_LEQ: sql_cmd->len += strings[STR_OP_LEQ].len; break; + case DB_GEQ: sql_cmd->len += strings[STR_OP_GEQ].len; break; + default: + ERR("mysql: Unsupported db_fld operator %d\n", fld[i].op); + return -1; } sql_cmd->len += strings[STR_ESC].len; - + if (!DB_FLD_LAST(fld[i + 1])) sql_cmd->len += strings[STR_AND].len; } } @@ -260,7 +260,7 @@ static int build_select_cmd(str* sql_cmd, db_cmd_t* cmd) return -1; } p = sql_cmd->s; - + APPEND_STR(p, strings[STR_SELECT]); if (DB_FLD_EMPTY(cmd->result)) { *p++ = '*'; @@ -280,14 +280,14 @@ static int build_select_cmd(str* sql_cmd, db_cmd_t* cmd) APPEND_CSTR(p, fld[i].name); switch(fld[i].op) { - case DB_EQ: APPEND_STR(p, strings[STR_OP_EQ]); break; - case DB_NE: APPEND_STR(p, strings[STR_OP_NE]); break; - case DB_LT: APPEND_STR(p, strings[STR_OP_LT]); break; - case DB_GT: APPEND_STR(p, strings[STR_OP_GT]); break; - case DB_LEQ: APPEND_STR(p, strings[STR_OP_LEQ]); break; - case DB_GEQ: APPEND_STR(p, strings[STR_OP_GEQ]); break; + case DB_EQ: APPEND_STR(p, strings[STR_OP_EQ]); break; + case DB_NE: APPEND_STR(p, strings[STR_OP_NE]); break; + case DB_LT: APPEND_STR(p, strings[STR_OP_LT]); break; + case DB_GT: APPEND_STR(p, strings[STR_OP_GT]); break; + case DB_LEQ: APPEND_STR(p, strings[STR_OP_LEQ]); break; + case DB_GEQ: APPEND_STR(p, strings[STR_OP_GEQ]); break; } - + APPEND_STR(p, strings[STR_ESC]); if (!DB_FLD_LAST(fld[i + 1])) APPEND_STR(p, strings[STR_AND]); } @@ -319,7 +319,7 @@ static int build_replace_cmd(str* sql_cmd, db_cmd_t* cmd) if (!DB_FLD_LAST(fld[i + 1])) sql_cmd->len += 2; /* , twice */ } sql_cmd->len += strings[STR_VALUES].len; - sql_cmd->len += 1; /* ) */ + sql_cmd->len += 1; /* ) */ sql_cmd->s = pkg_malloc(sql_cmd->len + 1); if (sql_cmd->s == NULL) { @@ -327,7 +327,7 @@ static int build_replace_cmd(str* sql_cmd, db_cmd_t* cmd) return -1; } p = sql_cmd->s; - + APPEND_STR(p, strings[STR_REPLACE]); APPEND_STR(p, cmd->table); *p++ = ' '; @@ -356,7 +356,7 @@ struct string_buffer { char *s; /**< allocated memory itself */ int len; /**< used memory */ int size; /**< total size of allocated memory */ - int increment; /**< increment when realloc is necessary */ + int increment; /**< increment when realloc is necessary */ }; @@ -398,7 +398,7 @@ static inline int sb_add(struct string_buffer *sb, str *nstr) /** * Set members of str variable. - * Used for temporary str variables. + * Used for temporary str variables. */ static inline str* set_str(str *str, const char *s) { @@ -447,14 +447,14 @@ static int build_update_cmd(str* sql_cmd, db_cmd_t* cmd) rv |= sb_add(&sql_buf, set_str(&tmpstr, fld[i].name)); switch(fld[i].op) { - case DB_EQ: rv |= sb_add(&sql_buf, &strings[STR_OP_EQ]); break; - case DB_NE: rv |= sb_add(&sql_buf, &strings[STR_OP_NE]); break; - case DB_LT: rv |= sb_add(&sql_buf, &strings[STR_OP_LT]); break; - case DB_GT: rv |= sb_add(&sql_buf, &strings[STR_OP_GT]); break; - case DB_LEQ: rv |= sb_add(&sql_buf, &strings[STR_OP_LEQ]); break; - case DB_GEQ: rv |= sb_add(&sql_buf, &strings[STR_OP_GEQ]); break; + case DB_EQ: rv |= sb_add(&sql_buf, &strings[STR_OP_EQ]); break; + case DB_NE: rv |= sb_add(&sql_buf, &strings[STR_OP_NE]); break; + case DB_LT: rv |= sb_add(&sql_buf, &strings[STR_OP_LT]); break; + case DB_GT: rv |= sb_add(&sql_buf, &strings[STR_OP_GT]); break; + case DB_LEQ: rv |= sb_add(&sql_buf, &strings[STR_OP_LEQ]); break; + case DB_GEQ: rv |= sb_add(&sql_buf, &strings[STR_OP_GEQ]); break; } - + rv |= sb_add(&sql_buf, &strings[STR_ESC]); if (!DB_FLD_LAST(fld[i + 1])) rv |= sb_add(&sql_buf, &strings[STR_AND]); } @@ -477,7 +477,7 @@ static inline void update_field(MYSQL_BIND *param, db_fld_t* fld) { struct my_fld* fp; /* field payload */ struct tm* t; - + fp = DB_GET_PAYLOAD(fld); #ifndef MYSQL_FAKE_NULL @@ -486,60 +486,60 @@ static inline void update_field(MYSQL_BIND *param, db_fld_t* fld) #else if (fld->flags & DB_NULL) { switch(fld->type) { + case DB_STR: + case DB_CSTR: + param->buffer = FAKE_NULL_STR.s; + fp->length = FAKE_NULL_STR.len; + break; + case DB_INT: + *(int*)param->buffer = FAKE_NULL_INT; + break; + case DB_BLOB: + case DB_DATETIME: + case DB_NONE: + case DB_FLOAT: + case DB_DOUBLE: + case DB_BITMAP: + /* we don't have fake null value for these types */ + fp->is_null = DB_NULL; + break; + } + return; + } +#endif + switch(fld->type) { case DB_STR: - case DB_CSTR: - param->buffer = FAKE_NULL_STR.s; - fp->length = FAKE_NULL_STR.len; - break; - case DB_INT: - *(int*)param->buffer = FAKE_NULL_INT; + param->buffer = fld->v.lstr.s; + fp->length = fld->v.lstr.len; break; + case DB_BLOB: + param->buffer = fld->v.blob.s; + fp->length = fld->v.blob.len; + break; + + case DB_CSTR: + param->buffer = (char*)fld->v.cstr; + fp->length = strlen(fld->v.cstr); + break; + case DB_DATETIME: + t = gmtime(&fld->v.time); + fp->time.second = t->tm_sec; + fp->time.minute = t->tm_min; + fp->time.hour = t->tm_hour; + fp->time.day = t->tm_mday; + fp->time.month = t->tm_mon + 1; + fp->time.year = t->tm_year + 1900; + break; + case DB_NONE: + case DB_INT: case DB_FLOAT: case DB_DOUBLE: case DB_BITMAP: - /* we don't have fake null value for these types */ - fp->is_null = DB_NULL; + /* No need to do anything for these types */ break; - } - return; - } -#endif - switch(fld->type) { - case DB_STR: - param->buffer = fld->v.lstr.s; - fp->length = fld->v.lstr.len; - break; - - case DB_BLOB: - param->buffer = fld->v.blob.s; - fp->length = fld->v.blob.len; - break; - - case DB_CSTR: - param->buffer = (char*)fld->v.cstr; - fp->length = strlen(fld->v.cstr); - break; - - case DB_DATETIME: - t = gmtime(&fld->v.time); - fp->time.second = t->tm_sec; - fp->time.minute = t->tm_min; - fp->time.hour = t->tm_hour; - fp->time.day = t->tm_mday; - fp->time.month = t->tm_mon + 1; - fp->time.year = t->tm_year + 1900; - break; - - case DB_NONE: - case DB_INT: - case DB_FLOAT: - case DB_DOUBLE: - case DB_BITMAP: - /* No need to do anything for these types */ - break; } } @@ -594,73 +594,73 @@ static inline int update_result(db_fld_t* result, MYSQL_STMT* st) } switch(result[i].type) { - case DB_STR: - result[i].v.lstr.len = rp->length; + case DB_STR: + result[i].v.lstr.len = rp->length; #ifdef MYSQL_FAKE_NULL - if (STR_EQ(FAKE_NULL_STR,result[i].v.lstr)) { - result[i].flags |= DB_NULL; - } + if (STR_EQ(FAKE_NULL_STR,result[i].v.lstr)) { + result[i].flags |= DB_NULL; + } #endif - break; - - case DB_BLOB: - result[i].v.blob.len = rp->length; - break; - - case DB_CSTR: - if (rp->length < STR_BUF_SIZE) { - result[i].v.cstr[rp->length] = '\0'; - } else { - /* Truncated field but rp->length contains full size, - * zero terminated the last byte in the buffer - */ - result[i].v.cstr[STR_BUF_SIZE - 1] = '\0'; - } + break; + + case DB_BLOB: + result[i].v.blob.len = rp->length; + break; + + case DB_CSTR: + if (rp->length < STR_BUF_SIZE) { + result[i].v.cstr[rp->length] = '\0'; + } else { + /* Truncated field but rp->length contains full size, + * zero terminated the last byte in the buffer + */ + result[i].v.cstr[STR_BUF_SIZE - 1] = '\0'; + } #ifdef MYSQL_FAKE_NULL - if (strcmp(FAKE_NULL_STR.s,result[i].v.cstr)==0) { - result[i].flags |= DB_NULL; - } + if (strcmp(FAKE_NULL_STR.s,result[i].v.cstr)==0) { + result[i].flags |= DB_NULL; + } #endif - break; - - case DB_DATETIME: - memset(&t, '\0', sizeof(struct tm)); - t.tm_sec = rp->time.second; - t.tm_min = rp->time.minute; - t.tm_hour = rp->time.hour; - t.tm_mday = rp->time.day; - t.tm_mon = rp->time.month - 1; - t.tm_year = rp->time.year - 1900; - - /* Daylight saving information got lost in the database - * so let timegm to guess it. This eliminates the bug when - * contacts reloaded from the database have different time - * of expiration by one hour when daylight saving is used - */ - t.tm_isdst = -1; + break; + + case DB_DATETIME: + memset(&t, '\0', sizeof(struct tm)); + t.tm_sec = rp->time.second; + t.tm_min = rp->time.minute; + t.tm_hour = rp->time.hour; + t.tm_mday = rp->time.day; + t.tm_mon = rp->time.month - 1; + t.tm_year = rp->time.year - 1900; + + /* Daylight saving information got lost in the database + * so let timegm to guess it. This eliminates the bug when + * contacts reloaded from the database have different time + * of expiration by one hour when daylight saving is used + */ + t.tm_isdst = -1; #ifdef HAVE_TIMEGM - result[i].v.time = timegm(&t); + result[i].v.time = timegm(&t); #else - result[i].v.time = _timegm(&t); + result[i].v.time = _timegm(&t); #endif /* HAVE_TIMEGM */ - break; + break; - case DB_INT: + case DB_INT: #ifdef MYSQL_FAKE_NULL - if (FAKE_NULL_INT==result[i].v.int4) { - result[i].flags |= DB_NULL; - } - break; + if (FAKE_NULL_INT==result[i].v.int4) { + result[i].flags |= DB_NULL; + } + break; #endif - case DB_NONE: - case DB_FLOAT: - case DB_DOUBLE: - case DB_BITMAP: - /* No need to do anything for these types */ - break; + case DB_NONE: + case DB_FLOAT: + case DB_DOUBLE: + case DB_BITMAP: + /* No need to do anything for these types */ + break; } } - + return 0; } @@ -674,79 +674,79 @@ static inline int update_result(db_fld_t* result, MYSQL_STMT* st) */ static int exec_cmd_safe(db_cmd_t* cmd) { - int i, err; - db_con_t* con; - struct my_cmd* mcmd; - struct my_con* mcon; - - /* First things first: retrieve connection info - * from the currently active connection and also - * mysql payload from the database command - */ - mcmd = DB_GET_PAYLOAD(cmd); - con = cmd->ctx->con[db_payload_idx]; - mcon = DB_GET_PAYLOAD(con); - - for(i = 0; i <= my_retries; i++) { - if ((mcon->flags & MY_CONNECTED) == 0) { - /* The connection is disconnected, try to reconnect */ - if (my_con_connect(con)) { - INFO("mysql: exec_cmd_safe failed to re-connect\n"); - continue; - } - } - - /* Next check the number of resets in the database connection, if this - * number is higher than the number we keep in my_cmd structure in - * last_reset variable then the connection was reset and we need to - * upload the command again to the server before executing it, because - * the server recycles all server side information upon disconnect. + int i, err; + db_con_t* con; + struct my_cmd* mcmd; + struct my_con* mcon; + + /* First things first: retrieve connection info + * from the currently active connection and also + * mysql payload from the database command */ - if (mcon->resets > mcmd->last_reset) { - INFO("mysql: Connection reset detected, uploading command to server\n"); - err = upload_cmd(cmd); - if (err < 0) { - INFO("mysql: Error while uploading command\n"); - continue; - } else if (err > 0) { - /* DB API error, this is a serious problem such as memory - * allocation failure, bail out + mcmd = DB_GET_PAYLOAD(cmd); + con = cmd->ctx->con[db_payload_idx]; + mcon = DB_GET_PAYLOAD(con); + + for(i = 0; i <= my_retries; i++) { + if ((mcon->flags & MY_CONNECTED) == 0) { + /* The connection is disconnected, try to reconnect */ + if (my_con_connect(con)) { + INFO("mysql: exec_cmd_safe failed to re-connect\n"); + continue; + } + } + + /* Next check the number of resets in the database connection, if this + * number is higher than the number we keep in my_cmd structure in + * last_reset variable then the connection was reset and we need to + * upload the command again to the server before executing it, because + * the server recycles all server side information upon disconnect. */ - return 1; - } - } - - set_mysql_params(cmd); - err = mysql_stmt_execute(mcmd->st); - if (err == 0) { - /* The command was executed successfully, now fetch all data to - * the client if it was requested by the user */ - if (mcmd->flags & MY_FETCH_ALL) { - err = mysql_stmt_store_result(mcmd->st); - if (err) { - INFO("mysql: Error while fetching data to client.\n"); - goto error; + if (mcon->resets > mcmd->last_reset) { + INFO("mysql: Connection reset detected, uploading command to server\n"); + err = upload_cmd(cmd); + if (err < 0) { + INFO("mysql: Error while uploading command\n"); + continue; + } else if (err > 0) { + /* DB API error, this is a serious problem such as memory + * allocation failure, bail out + */ + return 1; + } + } + + set_mysql_params(cmd); + err = mysql_stmt_execute(mcmd->st); + if (err == 0) { + /* The command was executed successfully, now fetch all data to + * the client if it was requested by the user */ + if (mcmd->flags & MY_FETCH_ALL) { + err = mysql_stmt_store_result(mcmd->st); + if (err) { + INFO("mysql: Error while fetching data to client.\n"); + goto error; + } + } + return 0; + } + +error: + /* Command execution failed, log a message and try to reconnect */ + INFO("mysql: libmysql: %d, %s\n", mysql_stmt_errno(mcmd->st), + mysql_stmt_error(mcmd->st)); + INFO("mysql: Error while executing command on server, trying to reconnect\n"); + + my_con_disconnect(con); + if (my_con_connect(con)) { + INFO("mysql: Failed to reconnect server\n"); + } else { + INFO("mysql: Successfully reconnected server\n"); } - } - return 0; - } - - error: - /* Command execution failed, log a message and try to reconnect */ - INFO("mysql: libmysql: %d, %s\n", mysql_stmt_errno(mcmd->st), - mysql_stmt_error(mcmd->st)); - INFO("mysql: Error while executing command on server, trying to reconnect\n"); - - my_con_disconnect(con); - if (my_con_connect(con)) { - INFO("mysql: Failed to reconnect server\n"); - } else { - INFO("mysql: Successfully reconnected server\n"); } - } - - INFO("mysql: Failed to execute command, giving up\n"); - return -1; + + INFO("mysql: Failed to execute command, giving up\n"); + return -1; } @@ -769,7 +769,7 @@ int my_cmd_exec(db_res_t* res, db_cmd_t* cmd) static void set_field(MYSQL_BIND *bind, db_fld_t* fld) { struct my_fld* f; - + f = DB_GET_PAYLOAD(fld); bind->is_null = &f->is_null; /* We can do it for all the types here, mysql will ignore it @@ -777,42 +777,42 @@ static void set_field(MYSQL_BIND *bind, db_fld_t* fld) */ bind->length = &f->length; switch(fld->type) { - case DB_INT: - case DB_BITMAP: - bind->buffer_type = MYSQL_TYPE_LONG; - bind->buffer = &fld->v.int4; - break; - - case DB_FLOAT: - bind->buffer_type = MYSQL_TYPE_FLOAT; - bind->buffer = &fld->v.flt; - break; - - case DB_DOUBLE: - bind->buffer_type = MYSQL_TYPE_DOUBLE; - bind->buffer = &fld->v.dbl; - break; - - case DB_DATETIME: - bind->buffer_type = MYSQL_TYPE_DATETIME; - bind->buffer = &f->time; - break; - - case DB_STR: - case DB_CSTR: - bind->buffer_type = MYSQL_TYPE_VAR_STRING; - bind->buffer = ""; /* Updated on runtime */ - break; - - case DB_BLOB: - bind->buffer_type = MYSQL_TYPE_BLOB; - bind->buffer = ""; /* Updated on runtime */ - break; - - case DB_NONE: - /* Eliminates gcc warning */ - break; - + case DB_INT: + case DB_BITMAP: + bind->buffer_type = MYSQL_TYPE_LONG; + bind->buffer = &fld->v.int4; + break; + + case DB_FLOAT: + bind->buffer_type = MYSQL_TYPE_FLOAT; + bind->buffer = &fld->v.flt; + break; + + case DB_DOUBLE: + bind->buffer_type = MYSQL_TYPE_DOUBLE; + bind->buffer = &fld->v.dbl; + break; + + case DB_DATETIME: + bind->buffer_type = MYSQL_TYPE_DATETIME; + bind->buffer = &f->time; + break; + + case DB_STR: + case DB_CSTR: + bind->buffer_type = MYSQL_TYPE_VAR_STRING; + bind->buffer = ""; /* Updated on runtime */ + break; + + case DB_BLOB: + bind->buffer_type = MYSQL_TYPE_BLOB; + bind->buffer = ""; /* Updated on runtime */ + break; + + case DB_NONE: + /* Eliminates gcc warning */ + break; + } } @@ -843,7 +843,7 @@ static int bind_mysql_params(MYSQL_STMT* st, db_fld_t* params1, db_fld_t* params BUG("mysql: Number of parameters in SQL command does not match number of DB API parameters\n"); return 1; } - + my_params = (MYSQL_BIND*)pkg_malloc(sizeof(MYSQL_BIND) * (count1 + count2)); if (my_params == NULL) { ERR("mysql: No memory left\n"); @@ -863,8 +863,8 @@ static int bind_mysql_params(MYSQL_STMT* st, db_fld_t* params1, db_fld_t* params err = mysql_stmt_bind_param(st, my_params); if (err) { - ERR("mysql: libmysqlclient: %d, %s\n", - mysql_stmt_errno(st), mysql_stmt_error(st)); + ERR("mysql: libmysqlclient: %d, %s\n", + mysql_stmt_errno(st), mysql_stmt_error(st)); goto error; } @@ -873,8 +873,8 @@ static int bind_mysql_params(MYSQL_STMT* st, db_fld_t* params1, db_fld_t* params */ pkg_free(my_params); return err; - - error: + +error: if (my_params) pkg_free(my_params); return err; } @@ -896,7 +896,7 @@ static int check_result(db_cmd_t* cmd, struct my_cmd* payload) /* No error means no result set to be checked */ if (mysql_stmt_errno(payload->st) == 0) return 0; ERR("mysql: Error while getting metadata of SQL command: %d, %s\n", - mysql_stmt_errno(payload->st), mysql_stmt_error(payload->st)); + mysql_stmt_errno(payload->st), mysql_stmt_error(payload->st)); return -1; } n = mysql_num_fields(meta); @@ -930,44 +930,44 @@ static int check_result(db_cmd_t* cmd, struct my_cmd* payload) /* Now iterate through all the columns in the result set and replace * any occurrence of DB_UNKNOWN type with the type of the column * retrieved from the database and if no column name was provided then - * update it from the database as well. + * update it from the database as well. */ for(i = 0; i < cmd->result_count; i++) { fld = mysql_fetch_field_direct(meta, i); if (cmd->result[i].type != DB_NONE) continue; switch(fld->type) { - case MYSQL_TYPE_TINY: - case MYSQL_TYPE_SHORT: - case MYSQL_TYPE_INT24: - case MYSQL_TYPE_LONG: - cmd->result[i].type = DB_INT; - break; - - case MYSQL_TYPE_FLOAT: - cmd->result[i].type = DB_FLOAT; - break; - - case MYSQL_TYPE_DOUBLE: - cmd->result[i].type = DB_DOUBLE; - break; - - case MYSQL_TYPE_TIMESTAMP: - case MYSQL_TYPE_DATETIME: - cmd->result[i].type = DB_DATETIME; - break; - - case MYSQL_TYPE_STRING: - case MYSQL_TYPE_VAR_STRING: - cmd->result[i].type = DB_STR; - break; + case MYSQL_TYPE_TINY: + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_LONG: + cmd->result[i].type = DB_INT; + break; + + case MYSQL_TYPE_FLOAT: + cmd->result[i].type = DB_FLOAT; + break; + + case MYSQL_TYPE_DOUBLE: + cmd->result[i].type = DB_DOUBLE; + break; + + case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_DATETIME: + cmd->result[i].type = DB_DATETIME; + break; + + case MYSQL_TYPE_STRING: + case MYSQL_TYPE_VAR_STRING: + cmd->result[i].type = DB_STR; + break; - default: - ERR("mysql: Unsupported MySQL column type: %d, table: %s, column: %s\n", - fld->type, cmd->table.s, fld->name); - goto error; + default: + ERR("mysql: Unsupported MySQL column type: %d, table: %s, column: %s\n", + fld->type, cmd->table.s, fld->name); + goto error; } } - + if (meta) mysql_free_result(meta); return 0; @@ -998,7 +998,7 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld) return 1; } memset(result, '\0', sizeof(MYSQL_BIND) * n); - + for(i = 0; i < n; i++) { f = DB_GET_PAYLOAD(fld + i); result[i].is_null = &f->is_null; @@ -1007,69 +1007,69 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld) */ result[i].length = &f->length; switch(fld[i].type) { - case DB_INT: - case DB_BITMAP: - result[i].buffer_type = MYSQL_TYPE_LONG; - result[i].buffer = &fld[i].v.int4; - break; - - case DB_FLOAT: - result[i].buffer_type = MYSQL_TYPE_FLOAT; - result[i].buffer = &fld[i].v.flt; - break; - - case DB_DOUBLE: - result[i].buffer_type = MYSQL_TYPE_DOUBLE; - result[i].buffer = &fld[i].v.dbl; - break; - - case DB_DATETIME: - result[i].buffer_type = MYSQL_TYPE_DATETIME; - result[i].buffer = &f->time; - break; - - case DB_STR: - result[i].buffer_type = MYSQL_TYPE_VAR_STRING; - if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE); - if (f->buf.s == NULL) { - ERR("mysql: No memory left\n"); - err = 1; - goto error; - } - result[i].buffer = f->buf.s; - fld[i].v.lstr.s = f->buf.s; - result[i].buffer_length = STR_BUF_SIZE - 1; - break; - - case DB_CSTR: - result[i].buffer_type = MYSQL_TYPE_VAR_STRING; - if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE); - if (f->buf.s == NULL) { - ERR("mysql: No memory left\n"); - err = 1; - goto error; - } - result[i].buffer = f->buf.s; - fld[i].v.cstr = f->buf.s; - result[i].buffer_length = STR_BUF_SIZE - 1; - break; - - case DB_BLOB: - result[i].buffer_type = MYSQL_TYPE_BLOB; - if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE); - if (f->buf.s == NULL) { - ERR("mysql: No memory left\n"); - err = 1; - goto error; - } - result[i].buffer = f->buf.s; - fld[i].v.blob.s = f->buf.s; - result[i].buffer_length = STR_BUF_SIZE - 1; - break; - - case DB_NONE: - /* Eliminates gcc warning */ - break; + case DB_INT: + case DB_BITMAP: + result[i].buffer_type = MYSQL_TYPE_LONG; + result[i].buffer = &fld[i].v.int4; + break; + + case DB_FLOAT: + result[i].buffer_type = MYSQL_TYPE_FLOAT; + result[i].buffer = &fld[i].v.flt; + break; + + case DB_DOUBLE: + result[i].buffer_type = MYSQL_TYPE_DOUBLE; + result[i].buffer = &fld[i].v.dbl; + break; + + case DB_DATETIME: + result[i].buffer_type = MYSQL_TYPE_DATETIME; + result[i].buffer = &f->time; + break; + + case DB_STR: + result[i].buffer_type = MYSQL_TYPE_VAR_STRING; + if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE); + if (f->buf.s == NULL) { + ERR("mysql: No memory left\n"); + err = 1; + goto error; + } + result[i].buffer = f->buf.s; + fld[i].v.lstr.s = f->buf.s; + result[i].buffer_length = STR_BUF_SIZE - 1; + break; + + case DB_CSTR: + result[i].buffer_type = MYSQL_TYPE_VAR_STRING; + if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE); + if (f->buf.s == NULL) { + ERR("mysql: No memory left\n"); + err = 1; + goto error; + } + result[i].buffer = f->buf.s; + fld[i].v.cstr = f->buf.s; + result[i].buffer_length = STR_BUF_SIZE - 1; + break; + + case DB_BLOB: + result[i].buffer_type = MYSQL_TYPE_BLOB; + if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE); + if (f->buf.s == NULL) { + ERR("mysql: No memory left\n"); + err = 1; + goto error; + } + result[i].buffer = f->buf.s; + fld[i].v.blob.s = f->buf.s; + result[i].buffer_length = STR_BUF_SIZE - 1; + break; + + case DB_NONE: + /* Eliminates gcc warning */ + break; } } @@ -1085,8 +1085,8 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld) */ if (result) pkg_free(result); return 0; - - error: + +error: if (result) pkg_free(result); return err; } @@ -1099,80 +1099,80 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld) */ static int upload_cmd(db_cmd_t* cmd) { - struct my_cmd* res; - struct my_con* mcon; - int err = 0; - - res = DB_GET_PAYLOAD(cmd); - - /* FIXME: The function should take the connection as one of parameters */ - mcon = DB_GET_PAYLOAD(cmd->ctx->con[db_payload_idx]); - /* Do not upload the command if the connection is not connected */ - if ((mcon->flags & MY_CONNECTED) == 0) { - err = 1; - goto error; - } - - /* If there is a previous pre-compiled statement, close it first */ - if (res->st) mysql_stmt_close(res->st); - res->st = NULL; - - /* Create a new pre-compiled statement data structure */ - res->st = mysql_stmt_init(mcon->con); - if (res->st == NULL) { - ERR("mysql: Error while creating new MySQL_STMT data structure (no memory left)\n"); - err = 1; - goto error; - } - - /* Try to upload the command to the server */ - if (mysql_stmt_prepare(res->st, res->sql_cmd.s, res->sql_cmd.len)) { - err = mysql_stmt_errno(res->st); - ERR("mysql: libmysql: %d, %s\n", err, mysql_stmt_error(res->st)); - ERR("mysql: An error occurred while uploading command to server\n"); - } - if (err == CR_SERVER_LOST || - err == CR_SERVER_GONE_ERROR) { - /* Connection to the server was lost, mark the connection as - * disconnected. In this case mysql_stmt_prepare invalidates the - * connection internally and calling another mysql function on that - * connection would crash. To make sure that no other mysql function - * gets called unless the connection is reconnected we disconnect it - * explicitly here. This is a workaround for mysql bug #33384. */ - my_con_disconnect(cmd->ctx->con[db_payload_idx]); - } - if (err) { - /* Report mysql error to the caller */ - err = -1; - goto error; - } - - err = bind_mysql_params(res->st, cmd->vals, cmd->match); - if (err) goto error; - - if (cmd->type == DB_GET || cmd->type == DB_SQL) { - err = check_result(cmd, res); - if (err) goto error; - err = bind_result(res->st, cmd->result); + struct my_cmd* res; + struct my_con* mcon; + int err = 0; + + res = DB_GET_PAYLOAD(cmd); + + /* FIXME: The function should take the connection as one of parameters */ + mcon = DB_GET_PAYLOAD(cmd->ctx->con[db_payload_idx]); + /* Do not upload the command if the connection is not connected */ + if ((mcon->flags & MY_CONNECTED) == 0) { + err = 1; + goto error; + } + + /* If there is a previous pre-compiled statement, close it first */ + if (res->st) mysql_stmt_close(res->st); + res->st = NULL; + + /* Create a new pre-compiled statement data structure */ + res->st = mysql_stmt_init(mcon->con); + if (res->st == NULL) { + ERR("mysql: Error while creating new MySQL_STMT data structure (no memory left)\n"); + err = 1; + goto error; + } + + /* Try to upload the command to the server */ + if (mysql_stmt_prepare(res->st, res->sql_cmd.s, res->sql_cmd.len)) { + err = mysql_stmt_errno(res->st); + ERR("mysql: libmysql: %d, %s\n", err, mysql_stmt_error(res->st)); + ERR("mysql: An error occurred while uploading command to server\n"); + } + if (err == CR_SERVER_LOST || + err == CR_SERVER_GONE_ERROR) { + /* Connection to the server was lost, mark the connection as + * disconnected. In this case mysql_stmt_prepare invalidates the + * connection internally and calling another mysql function on that + * connection would crash. To make sure that no other mysql function + * gets called unless the connection is reconnected we disconnect it + * explicitly here. This is a workaround for mysql bug #33384. */ + my_con_disconnect(cmd->ctx->con[db_payload_idx]); + } + if (err) { + /* Report mysql error to the caller */ + err = -1; + goto error; + } + + err = bind_mysql_params(res->st, cmd->vals, cmd->match); if (err) goto error; - } - - res->last_reset = mcon->resets; - return 0; - + + if (cmd->type == DB_GET || cmd->type == DB_SQL) { + err = check_result(cmd, res); + if (err) goto error; + err = bind_result(res->st, cmd->result); + if (err) goto error; + } + + res->last_reset = mcon->resets; + return 0; + error: - if (res->st) { - mysql_stmt_close(res->st); - res->st = NULL; - } - return err; + if (res->st) { + mysql_stmt_close(res->st); + res->st = NULL; + } + return err; } int my_cmd(db_cmd_t* cmd) { struct my_cmd* res; - + res = (struct my_cmd*)pkg_malloc(sizeof(struct my_cmd)); if (res == NULL) { ERR("mysql: No memory left\n"); @@ -1184,36 +1184,36 @@ int my_cmd(db_cmd_t* cmd) if (db_drv_init(&res->gen, my_cmd_free) < 0) goto error; switch(cmd->type) { - case DB_PUT: - if (DB_FLD_EMPTY(cmd->vals)) { - BUG("mysql: No parameters provided for DB_PUT in context '%.*s'\n", - cmd->ctx->id.len, ZSW(cmd->ctx->id.s)); - goto error; - } - if (build_replace_cmd(&res->sql_cmd, cmd) < 0) goto error; - break; + case DB_PUT: + if (DB_FLD_EMPTY(cmd->vals)) { + BUG("mysql: No parameters provided for DB_PUT in context '%.*s'\n", + cmd->ctx->id.len, ZSW(cmd->ctx->id.s)); + goto error; + } + if (build_replace_cmd(&res->sql_cmd, cmd) < 0) goto error; + break; - case DB_DEL: - if (build_delete_cmd(&res->sql_cmd, cmd) < 0) goto error; - break; + case DB_DEL: + if (build_delete_cmd(&res->sql_cmd, cmd) < 0) goto error; + break; - case DB_GET: - if (build_select_cmd(&res->sql_cmd, cmd) < 0) goto error; - break; + case DB_GET: + if (build_select_cmd(&res->sql_cmd, cmd) < 0) goto error; + break; - case DB_UPD: - if (build_update_cmd(&res->sql_cmd, cmd) < 0) goto error; - break; + case DB_UPD: + if (build_update_cmd(&res->sql_cmd, cmd) < 0) goto error; + break; - case DB_SQL: - res->sql_cmd.s = (char*)pkg_malloc(cmd->table.len); - if (res->sql_cmd.s == NULL) { - ERR("mysql: Out of private memory\n"); - goto error; - } - memcpy(res->sql_cmd.s,cmd->table.s, cmd->table.len); - res->sql_cmd.len = cmd->table.len; - break; + case DB_SQL: + res->sql_cmd.s = (char*)pkg_malloc(cmd->table.len); + if (res->sql_cmd.s == NULL) { + ERR("mysql: Out of private memory\n"); + goto error; + } + memcpy(res->sql_cmd.s,cmd->table.s, cmd->table.len); + res->sql_cmd.len = cmd->table.len; + break; } DB_SET_PAYLOAD(cmd, res); @@ -1228,7 +1228,7 @@ int my_cmd(db_cmd_t* cmd) if (upload_cmd(cmd)) goto error; return 0; - error: +error: if (res) { DB_SET_PAYLOAD(cmd, NULL); db_drv_free(&res->gen); @@ -1244,16 +1244,16 @@ int my_cmd_first(db_res_t* res) { mcmd = DB_GET_PAYLOAD(res->cmd); switch (mcmd->next_flag) { - case -2: /* table is empty */ - return 1; - case 0: /* cursor position is 0 */ - return 0; - case 1: /* next row */ - case 2: /* EOF */ - ERR("mysql: Unbuffered queries do not support cursor reset.\n"); - return -1; - default: - return my_cmd_next(res); + case -2: /* table is empty */ + return 1; + case 0: /* cursor position is 0 */ + return 0; + case 1: /* next row */ + case 2: /* EOF */ + ERR("mysql: Unbuffered queries do not support cursor reset.\n"); + return -1; + default: + return my_cmd_next(res); } } @@ -1272,7 +1272,7 @@ int my_cmd_next(db_res_t* res) } ret = mysql_stmt_fetch(mcmd->st); - + if (ret == MYSQL_NO_DATA) { mcmd->next_flag = mcmd->next_flag<0?-2:2; return 1; @@ -1284,8 +1284,8 @@ int my_cmd_next(db_res_t* res) ERR("mysql: mysql_stmt_fetch, data truncated, fields: %d\n", res->cmd->result_count); for (i = 0; i < res->cmd->result_count; i++) { if (mcmd->st->bind[i].error /*&& mcmd->st->bind[i].buffer_length*/) { - ERR("mysql: truncation, bind %d, length: %lu, buffer_length: %lu\n", - i, *(mcmd->st->bind[i].length), mcmd->st->bind[i].buffer_length); + ERR("mysql: truncation, bind %d, length: %lu, buffer_length: %lu\n", + i, *(mcmd->st->bind[i].length), mcmd->st->bind[i].buffer_length); } } ret = 0; @@ -1326,14 +1326,14 @@ int my_getopt(db_cmd_t* cmd, char* optname, va_list ap) if (mcmd->st->last_errno != 0) { BUG("mysql: Option 'last_id' called but previous command failed, " - "check your code\n"); + "check your code\n"); return -1; } *id = mysql_stmt_insert_id(mcmd->st); if ((*id) == 0) { BUG("mysql: Option 'last_id' called but there is no auto-increment" - " column in table, SQL command: %.*s\n", STR_FMT(&mcmd->sql_cmd)); + " column in table, SQL command: %.*s\n", STR_FMT(&mcmd->sql_cmd)); return -1; } } else if (!strcasecmp("fetch_all", optname)) { @@ -1348,7 +1348,7 @@ int my_getopt(db_cmd_t* cmd, char* optname, va_list ap) } return 0; - error: +error: return -1; } diff --git a/src/modules/db_mysql/my_cmd.h b/src/modules/db_mysql/my_cmd.h index 36b1f6733f4..dea1ace69d8 100644 --- a/src/modules/db_mysql/my_cmd.h +++ b/src/modules/db_mysql/my_cmd.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2003 FhG Fokus * Copyright (C) 2006-2007 iptelorg GmbH * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ diff --git a/src/modules/db_mysql/my_con.c b/src/modules/db_mysql/my_con.c index e12201267cf..0f0238aae8f 100644 --- a/src/modules/db_mysql/my_con.c +++ b/src/modules/db_mysql/my_con.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2004 iptel.org * Copyright (C) 2006-2007 iptelorg GmbH * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -38,12 +38,12 @@ static void my_con_free(db_con_t* con, struct my_con* payload) { if (!payload) return; - + /* Delete the structure only if there are no more references * to it in the connection pool */ if (db_pool_remove((db_pool_entry_t*)payload) == 0) return; - + db_pool_entry_free(&payload->gen); if (payload->con) pkg_free(payload->con); pkg_free(payload); @@ -54,10 +54,10 @@ int my_con_connect(db_con_t* con) { struct my_con* mcon; struct my_uri* muri; - + mcon = DB_GET_PAYLOAD(con); muri = DB_GET_PAYLOAD(con->uri); - + /* Do not reconnect already connected connections */ if (mcon->flags & MY_CONNECTED) return 0; @@ -66,34 +66,34 @@ int my_con_connect(db_con_t* con) con->uri->body.len, ZSW(con->uri->body.s)); if (my_connect_to) { - if (mysql_options(mcon->con, MYSQL_OPT_CONNECT_TIMEOUT, - (char*)&my_connect_to)) + if (mysql_options(mcon->con, MYSQL_OPT_CONNECT_TIMEOUT, + (char*)&my_connect_to)) WARN("mysql: failed to set MYSQL_OPT_CONNECT_TIMEOUT\n"); } -#if MYSQL_VERSION_ID >= 40101 - if ((my_client_ver >= 50025) || - ((my_client_ver >= 40122) && - (my_client_ver < 50000))) { +#if MYSQL_VERSION_ID >= 40101 + if ((my_client_ver >= 50025) || + ((my_client_ver >= 40122) && + (my_client_ver < 50000))) { if (my_send_to) { - if (mysql_options(mcon->con, MYSQL_OPT_WRITE_TIMEOUT , - (char*)&my_send_to)) + if (mysql_options(mcon->con, MYSQL_OPT_WRITE_TIMEOUT , + (char*)&my_send_to)) WARN("mysql: failed to set MYSQL_OPT_WRITE_TIMEOUT\n"); } if (my_recv_to){ - if (mysql_options(mcon->con, MYSQL_OPT_READ_TIMEOUT , - (char*)&my_recv_to)) + if (mysql_options(mcon->con, MYSQL_OPT_READ_TIMEOUT , + (char*)&my_recv_to)) WARN("mysql: failed to set MYSQL_OPT_READ_TIMEOUT\n"); } } #endif - - if (!mysql_real_connect(mcon->con, muri->host, muri->username, - muri->password, muri->database, muri->port, 0, 0)) { + + if (!mysql_real_connect(mcon->con, muri->host, muri->username, + muri->password, muri->database, muri->port, 0, 0)) { LOG(L_ERR, "mysql: %s\n", mysql_error(mcon->con)); return -1; } - + DBG("mysql: Connection type is %s\n", mysql_get_host_info(mcon->con)); DBG("mysql: Protocol version is %d\n", mysql_get_proto_info(mcon->con)); DBG("mysql: Server version is %s\n", mysql_get_server_info(mcon->con)); @@ -167,7 +167,7 @@ int my_con(db_con_t* con) db_pool_put((struct db_pool_entry*)ptr); DBG("mysql: Connection stored in connection pool\n"); - found: +found: /* Attach driver payload to the db_con structure and set connect and * disconnect functions */ @@ -176,7 +176,7 @@ int my_con(db_con_t* con) con->disconnect = my_con_disconnect; return 0; - error: +error: if (ptr) { db_pool_entry_free(&ptr->gen); if (ptr->con) pkg_free(ptr->con); diff --git a/src/modules/db_mysql/my_con.h b/src/modules/db_mysql/my_con.h index 2d773cfadd5..ea6d5d772ed 100644 --- a/src/modules/db_mysql/my_con.h +++ b/src/modules/db_mysql/my_con.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2003 FhG Fokus * Copyright (C) 2006-2007 iptelorg GmbH * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -39,7 +39,7 @@ typedef struct my_con { MYSQL* con; unsigned int flags; - + /* We keep the number of connection resets in this variable, this * variable is incremented each time the module performs a disconnect * on the connection. This is used by my_cmd related functions to diff --git a/src/modules/db_mysql/my_fld.c b/src/modules/db_mysql/my_fld.c index fc05b73206b..a9c198f5ebc 100644 --- a/src/modules/db_mysql/my_fld.c +++ b/src/modules/db_mysql/my_fld.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2003 FhG Fokus * Copyright (C) 2006-2007 iptelorg GmbH * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -52,7 +52,7 @@ int my_fld(db_fld_t* fld, char* table) DB_SET_PAYLOAD(fld, res); return 0; - error: +error: if (res) pkg_free(res); return -1; } diff --git a/src/modules/db_mysql/my_fld.h b/src/modules/db_mysql/my_fld.h index 79a9fb15e64..4450a26d068 100644 --- a/src/modules/db_mysql/my_fld.h +++ b/src/modules/db_mysql/my_fld.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2003 FhG Fokus * Copyright (C) 2006-2007 iptelorg GmbH * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ diff --git a/src/modules/db_mysql/my_res.c b/src/modules/db_mysql/my_res.c index a523c08e873..fd1729cbd89 100644 --- a/src/modules/db_mysql/my_res.c +++ b/src/modules/db_mysql/my_res.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2003 FhG Fokus * Copyright (C) 2006-2007 iptelorg GmbH * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -37,7 +37,7 @@ void my_res_free(db_res_t* res, struct my_res* payload) mcmd = DB_GET_PAYLOAD(res->cmd); if (mcmd->st && mysql_stmt_free_result(mcmd->st)) { - ERR("mysql: Error while freeing MySQL result: %d, %s\n", + ERR("mysql: Error while freeing MySQL result: %d, %s\n", mysql_stmt_errno(mcmd->st), mysql_stmt_error(mcmd->st)); } @@ -63,8 +63,8 @@ int my_res(db_res_t* res) if (db_drv_init(&mr->gen, my_res_free) < 0) goto error; DB_SET_PAYLOAD(res, mr); return 0; - - error: + +error: if (mr) { db_drv_free(&mr->gen); pkg_free(mr); diff --git a/src/modules/db_mysql/my_res.h b/src/modules/db_mysql/my_res.h index 5546aa74834..e0ae09a2728 100644 --- a/src/modules/db_mysql/my_res.h +++ b/src/modules/db_mysql/my_res.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001-2003 FhG Fokus * Copyright (C) 2006-2007 iptelorg GmbH * @@ -14,8 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ diff --git a/src/modules/db_mysql/my_uri.c b/src/modules/db_mysql/my_uri.c index 962145bee3e..8ad5b60b615 100644 --- a/src/modules/db_mysql/my_uri.c +++ b/src/modules/db_mysql/my_uri.c @@ -1,4 +1,4 @@ -/* +/* * MySQL module interface * * Copyright (C) 2001-2003 FhG FOKUS @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -79,7 +79,7 @@ static int dupl_string(char** dst, const char* begin, const char* end) /* - * Parse mysql URI of form + * Parse mysql URI of form * //[username[:password]@]hostname[:port]/database * * Returns 0 if parsing was successful and -1 otherwise @@ -109,11 +109,11 @@ static int parse_mysql_uri(struct my_uri* res, str* uri) if (!res || !uri) { goto err; } - + if (uri->len < SHORTEST_DB_URL_LEN) { goto err; } - + st = ST_SLASH1; begin = uri->s; @@ -136,7 +136,7 @@ static int parse_mysql_uri(struct my_uri* res, str* uri) st = ST_USER_HOST; begin = uri->s + i + 1; break; - + default: goto err; } @@ -205,7 +205,7 @@ static int parse_mysql_uri(struct my_uri* res, str* uri) return 0; } break; - + case ST_DB: break; } @@ -214,7 +214,7 @@ static int parse_mysql_uri(struct my_uri* res, str* uri) if (st != ST_DB) goto err; return 0; - err: +err: if (prev_token) pkg_free(prev_token); if (res == NULL) return -1; if (res->username) { @@ -267,7 +267,7 @@ int my_uri(db_uri_t* uri) uri->cmp = my_uri_cmp; return 0; - error: +error: if (res) { db_drv_free(&res->drv); if (res) pkg_free(res); diff --git a/src/modules/db_mysql/my_uri.h b/src/modules/db_mysql/my_uri.h index 704c134e2c9..1f3509bd334 100644 --- a/src/modules/db_mysql/my_uri.h +++ b/src/modules/db_mysql/my_uri.h @@ -1,4 +1,4 @@ -/* +/* * MySQL module interface * * Copyright (C) 2001-2003 FhG FOKUS @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */