Module: sip-router
Branch: master
Commit: 9a7e99d01e1c60dae8bec62037e8321c7d671c1d
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9a7e99d…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Nov 1 20:18:36 2011 +0100
db_mysql: initialize DB API in mod_register() function
- internal buffer sql_buf initialized in this function
- renamed sql_buf to mysql_sql_buf to avoid potential conflict with
global variable in srdb1 library
---
modules/db_mysql/km_db_mysql.c | 2 +-
modules/db_mysql/km_db_mysql.h | 7 +++++++
modules/db_mysql/km_dbase.c | 26 +++++++++++++-------------
modules/db_mysql/km_dbase.h | 7 -------
modules/db_mysql/mysql_mod.c | 7 +++++++
5 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/modules/db_mysql/km_db_mysql.c b/modules/db_mysql/km_db_mysql.c
index 1f758ba..462dc60 100644
--- a/modules/db_mysql/km_db_mysql.c
+++ b/modules/db_mysql/km_db_mysql.c
@@ -90,7 +90,7 @@ struct kam_module_exports kam_exports = {
int kam_mysql_mod_init(void)
{
LM_DBG("MySQL client version is %s\n", mysql_get_client_info());
- return db_mysql_alloc_buffer();
+ return 0;
}
int db_mysql_bind_api(db_func_t *dbb)
diff --git a/modules/db_mysql/km_db_mysql.h b/modules/db_mysql/km_db_mysql.h
index 4705ca0..9fd9747 100644
--- a/modules/db_mysql/km_db_mysql.h
+++ b/modules/db_mysql/km_db_mysql.h
@@ -47,4 +47,11 @@ int db_mysql_bind_api(db_func_t *dbb);
int kam_mysql_mod_init(void);
+/**
+ * Allocate a buffer for database module
+ * No function should be called before this
+ * \return zero on success, negative value on failure
+ */
+int db_mysql_alloc_buffer(void);
+
#endif /* KM_DB_MOD_H */
diff --git a/modules/db_mysql/km_dbase.c b/modules/db_mysql/km_dbase.c
index d85fe5f..da429d6 100644
--- a/modules/db_mysql/km_dbase.c
+++ b/modules/db_mysql/km_dbase.c
@@ -50,7 +50,7 @@
#include "km_db_mysql.h"
#include "km_dbase.h"
-static char *sql_buf;
+static char *mysql_sql_buf;
/**
@@ -513,32 +513,32 @@ int db_mysql_affected_rows(const db1_con_t* _h)
return -1;
}
- ret = snprintf(sql_buf, sql_buffer_size, "insert into %.*s (",
CON_TABLE(_h)->len, CON_TABLE(_h)->s);
+ ret = snprintf(mysql_sql_buf, sql_buffer_size, "insert into %.*s (",
CON_TABLE(_h)->len, CON_TABLE(_h)->s);
if (ret < 0 || ret >= sql_buffer_size) goto error;
off = ret;
- ret = db_print_columns(sql_buf + off, sql_buffer_size - off, _k, _n);
+ ret = db_print_columns(mysql_sql_buf + off, sql_buffer_size - off, _k, _n);
if (ret < 0) return -1;
off += ret;
- ret = snprintf(sql_buf + off, sql_buffer_size - off, ") values (");
+ ret = snprintf(mysql_sql_buf + off, sql_buffer_size - off, ") values (");
if (ret < 0 || ret >= (sql_buffer_size - off)) goto error;
off += ret;
- ret = db_print_values(_h, sql_buf + off, sql_buffer_size - off, _v, _n,
db_mysql_val2str);
+ ret = db_print_values(_h, mysql_sql_buf + off, sql_buffer_size - off, _v, _n,
db_mysql_val2str);
if (ret < 0) return -1;
off += ret;
- *(sql_buf + off++) = ')';
+ *(mysql_sql_buf + off++) = ')';
- ret = snprintf(sql_buf + off, sql_buffer_size - off, " on duplicate key update
");
+ 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, sql_buf + off, sql_buffer_size - off, _k, _v, _n,
db_mysql_val2str);
+ 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 = sql_buf;
+ sql_str.s = mysql_sql_buf;
sql_str.len = off;
if (db_mysql_submit_query(_h, &sql_str) < 0) {
@@ -587,14 +587,14 @@ int db_mysql_use_table(db1_con_t* _h, const str* _t)
*/
int db_mysql_alloc_buffer(void)
{
- if (db_query_init())
+ if (db_api_init())
{
- LM_ERR("Failed to initialise db_query\n");
+ LM_ERR("Failed to initialise db api\n");
return -1;
}
- sql_buf = (char*)malloc(sql_buffer_size);
- if (sql_buf == NULL)
+ mysql_sql_buf = (char*)malloc(sql_buffer_size);
+ if (mysql_sql_buf == NULL)
return -1;
else
return 0;
diff --git a/modules/db_mysql/km_dbase.h b/modules/db_mysql/km_dbase.h
index 68e4e8e..a2b5f92 100644
--- a/modules/db_mysql/km_dbase.h
+++ b/modules/db_mysql/km_dbase.h
@@ -139,11 +139,4 @@ int db_mysql_insert_delayed(const db1_con_t* _h, const db_key_t* _k,
int db_mysql_use_table(db1_con_t* _h, const str* _t);
-/**
- * Allocate a buffer for database module
- * No function should be called before this
- * \return zero on success, negative value on failure
- */
-int db_mysql_alloc_buffer(void);
-
#endif /* KM_DBASE_H */
diff --git a/modules/db_mysql/mysql_mod.c b/modules/db_mysql/mysql_mod.c
index 127ad52..74c61af 100644
--- a/modules/db_mysql/mysql_mod.c
+++ b/modules/db_mysql/mysql_mod.c
@@ -124,6 +124,13 @@ struct module_exports exports = {
};
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+ if(db_mysql_alloc_buffer()<0)
+ return -1;
+ return 0;
+}
+
static int mysql_mod_init(void)
{
#if MYSQL_VERSION_ID >= 40101